From 8625ab79a6d40a7bd5f350ce164d0c161f8c7145 Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:41:33 +0100 Subject: [PATCH] DEVEXP-344: Promote usage of services (#44) --- README.md | 26 +++++++---- examples/simple-examples/package.json | 14 +++--- examples/simple-examples/src/config.ts | 46 +++++++++++++++++-- .../src/conversation/app/create.ts | 11 +++-- .../src/conversation/app/delete.ts | 6 +-- .../src/conversation/app/get.ts | 11 +++-- .../src/conversation/app/list.ts | 6 +-- .../src/conversation/app/update.ts | 9 ++-- .../src/conversation/capability/lookup.ts | 11 +++-- .../src/conversation/contact/create.ts | 6 +-- .../src/conversation/contact/delete.ts | 6 +-- .../src/conversation/contact/get.ts | 6 +-- .../conversation/contact/getChannelProfile.ts | 6 +-- .../src/conversation/contact/list.ts | 8 ++-- .../src/conversation/contact/merge.ts | 10 ++-- .../src/conversation/contact/update.ts | 11 +++-- .../src/conversation/conversation/create.ts | 6 +-- .../src/conversation/conversation/delete.ts | 6 +-- .../src/conversation/conversation/get.ts | 6 +-- .../conversation/conversation/injectEvent.ts | 6 +-- .../conversation/injectMessage.ts | 6 +-- .../src/conversation/conversation/list.ts | 8 ++-- .../conversation/conversation/listRecent.ts | 8 ++-- .../src/conversation/conversation/stop.ts | 6 +-- .../src/conversation/conversation/update.ts | 6 +-- .../src/conversation/events/delete.ts | 6 +-- .../src/conversation/events/get.ts | 6 +-- .../src/conversation/events/list.ts | 8 ++-- .../src/conversation/events/send.ts | 6 +-- .../events/sendAgentJoinedEvent.ts | 6 +-- .../conversation/events/sendAgentLeftEvent.ts | 6 +-- .../events/sendCommentReplyEvent.ts | 6 +-- .../events/sendComposingEndEvent.ts | 6 +-- .../conversation/events/sendComposingEvent.ts | 6 +-- .../conversation/events/sendGenericEvent.ts | 6 +-- .../src/conversation/messages/delete.ts | 6 +-- .../src/conversation/messages/get.ts | 6 +-- .../src/conversation/messages/list.ts | 8 ++-- .../src/conversation/messages/send.ts | 6 +-- .../conversation/messages/sendCardMessage.ts | 6 +-- .../messages/sendCarouselMessage.ts | 6 +-- .../messages/sendChoiceMessage.ts | 6 +-- .../messages/sendContactInfoMessage.ts | 6 +-- .../conversation/messages/sendListMessage.ts | 6 +-- .../messages/sendLocationMessage.ts | 6 +-- .../conversation/messages/sendMediaMessage.ts | 6 +-- .../messages/sendTemplateMessage.ts | 6 +-- .../conversation/messages/sendTextMessage.ts | 6 +-- .../src/conversation/messages/update.ts | 6 +-- .../src/conversation/templates-v1/create.ts | 6 +-- .../src/conversation/templates-v1/delete.ts | 6 +-- .../src/conversation/templates-v1/get.ts | 6 +-- .../src/conversation/templates-v1/list.ts | 6 +-- .../src/conversation/templates-v1/update.ts | 6 +-- .../src/conversation/templates-v2/create.ts | 6 +-- .../src/conversation/templates-v2/delete.ts | 6 +-- .../src/conversation/templates-v2/get.ts | 6 +-- .../templates-v2/list-translations.ts | 8 ++-- .../src/conversation/templates-v2/list.ts | 6 +-- .../src/conversation/templates-v2/update.ts | 8 ++-- .../src/conversation/transcoding/transcode.ts | 8 ++-- .../src/conversation/webhooks/create.ts | 6 +-- .../src/conversation/webhooks/delete.ts | 6 +-- .../src/conversation/webhooks/get.ts | 6 +-- .../src/conversation/webhooks/list.ts | 6 +-- .../src/conversation/webhooks/update.ts | 6 +-- .../simple-examples/src/fax/emails/add.ts | 6 +-- .../simple-examples/src/fax/emails/delete.ts | 6 +-- .../simple-examples/src/fax/emails/list.ts | 8 ++-- .../src/fax/emails/listNumbers.ts | 8 ++-- .../simple-examples/src/fax/emails/update.ts | 6 +-- .../src/fax/faxes/deleteContent.ts | 6 +-- .../src/fax/faxes/downloadContent.ts | 6 +-- examples/simple-examples/src/fax/faxes/get.ts | 6 +-- .../simple-examples/src/fax/faxes/list.ts | 8 ++-- .../simple-examples/src/fax/faxes/send.ts | 6 +-- .../src/fax/services/create.ts | 6 +-- .../src/fax/services/delete.ts | 6 +-- .../simple-examples/src/fax/services/get.ts | 6 +-- .../simple-examples/src/fax/services/list.ts | 8 ++-- .../src/fax/services/listEmailsForNumber.ts | 8 ++-- .../src/fax/services/listNumbers.ts | 8 ++-- .../src/fax/services/update.ts | 6 +-- .../simple-examples/src/numbers/active/get.ts | 11 +++-- .../src/numbers/active/list.ts | 8 ++-- .../src/numbers/active/release.ts | 11 +++-- .../src/numbers/active/update.ts | 6 +-- .../numbers/available/checkAvailability.ts | 11 +++-- .../src/numbers/available/list.ts | 6 +-- .../src/numbers/available/rent.ts | 9 ++-- .../src/numbers/available/rentAny.ts | 6 +-- .../src/numbers/callbacks/get.ts | 6 +-- .../src/numbers/callbacks/update.ts | 11 +++-- .../src/numbers/regions/list.ts | 6 +-- .../simple-examples/src/sms/batches/cancel.ts | 11 +++-- .../src/sms/batches/delivery-feedback.ts | 10 ++-- .../src/sms/batches/dry-run.ts | 6 +-- .../simple-examples/src/sms/batches/get.ts | 11 +++-- .../simple-examples/src/sms/batches/list.ts | 8 ++-- .../src/sms/batches/replace.ts | 6 +-- .../simple-examples/src/sms/batches/send.ts | 6 +-- .../src/sms/batches/sendBinaryMessage.ts | 6 +-- .../src/sms/batches/sendMediaMessage.ts | 6 +-- .../src/sms/batches/sendTextMessage.ts | 6 +-- .../simple-examples/src/sms/batches/update.ts | 6 +-- .../src/sms/delivery-reports/getByBatchId.ts | 11 +++-- .../src/sms/delivery-reports/getForNumber.ts | 6 +-- .../src/sms/delivery-reports/list.ts | 8 ++-- .../sms/groups/create/create.sinch-client.ts | 7 --- .../groups/create/create.sinch-sms-client.ts | 7 --- .../src/sms/groups/create/create.ts | 6 +-- .../groups/create/create.with-projectId.ts | 7 +++ .../create/create.with-servicePlanId.ts | 7 +++ .../sms/groups/delete/delete.sinch-client.ts | 7 --- .../groups/delete/delete.sinch-sms-client.ts | 7 --- .../src/sms/groups/delete/delete.ts | 6 +-- .../groups/delete/delete.with-projectId.ts | 7 +++ .../delete/delete.with-servicePlanId.ts | 7 +++ .../src/sms/groups/get/get.sinch-client.ts | 7 --- .../sms/groups/get/get.sinch-sms-client.ts | 7 --- .../simple-examples/src/sms/groups/get/get.ts | 6 +-- .../src/sms/groups/get/get.with-projectId.ts | 7 +++ .../sms/groups/get/get.with-servicePlanId.ts | 7 +++ .../getPhoneNumbers.sinch-client.ts | 7 --- .../getPhoneNumbers.sinch-sms-client.ts | 7 --- .../groups/getPhoneNumbers/getPhoneNumbers.ts | 6 +-- .../getPhoneNumbers.with-projectId.ts | 7 +++ .../getPhoneNumbers.with-servicePlanId.ts | 7 +++ .../src/sms/groups/list/list.sinch-client.ts | 7 --- .../sms/groups/list/list.sinch-sms-client.ts | 7 --- .../src/sms/groups/list/list.ts | 11 +++-- .../sms/groups/list/list.with-projectId.ts | 7 +++ .../groups/list/list.with-servicePlanId.ts | 7 +++ .../groups/replace/replace.sinch-client.ts | 7 --- .../replace/replace.sinch-sms-client.ts | 7 --- .../src/sms/groups/replace/replace.ts | 6 +-- .../groups/replace/replace.with-projectId.ts | 7 +++ .../replace/replace.with-servicePlanId.ts | 7 +++ .../sms/groups/update/update.sinch-client.ts | 7 --- .../groups/update/update.sinch-sms-client.ts | 7 --- .../src/sms/groups/update/update.ts | 6 +-- .../groups/update/update.with-projectId.ts | 7 +++ .../update/update.with-servicePlanId.ts | 7 +++ .../simple-examples/src/sms/inbounds/get.ts | 6 +-- .../simple-examples/src/sms/inbounds/list.ts | 13 ++++-- .../verification-status/verification-by-id.ts | 6 +-- .../verification-by-identity.ts | 6 +-- .../verification-by-reference.ts | 6 +-- .../callout/report-with-id_callout.ts | 6 +-- .../callout/report-with-identity_callout.ts | 6 +-- .../verifications/callout/start-callout.ts | 6 +-- .../flashcall/report-with-id_flashcall.ts | 6 +-- .../report-with-identity_flashcall.ts | 6 +-- .../flashcall/start-flashcall.ts | 6 +-- .../verifications/seamless/start-seamless.ts | 6 +-- .../verifications/sms/report-with-id_sms.ts | 6 +-- .../sms/report-with-identity_sms.ts | 6 +-- .../verifications/sms/start-sms.ts | 6 +-- .../src/voice/applications/assignNumbers.ts | 10 ++-- .../src/voice/applications/getCallbackURLs.ts | 6 +-- .../src/voice/applications/getNumbers.ts | 6 +-- .../src/voice/applications/queryNumber.ts | 11 +++-- .../src/voice/applications/unassignNumber.ts | 10 ++-- .../voice/applications/updateCallbackURLs.ts | 6 +-- .../src/voice/callouts/conference.ts | 8 ++-- .../src/voice/callouts/custom.ts | 6 +-- .../simple-examples/src/voice/callouts/tts.ts | 8 ++-- .../simple-examples/src/voice/calls/get.ts | 8 ++-- .../src/voice/calls/manageWithCallLeg.ts | 8 ++-- .../simple-examples/src/voice/calls/update.ts | 8 ++-- .../src/voice/conferences/get.ts | 8 ++-- .../src/voice/conferences/kickAll.ts | 8 ++-- .../src/voice/conferences/kickParticipant.ts | 8 ++-- .../voice/conferences/manageParticipant.ts | 8 ++-- packages/conversation/README.md | 41 +++++++++++------ packages/fax/README.md | 16 +++++-- packages/numbers/README.md | 23 ++++++---- packages/sdk-client/README.md | 1 + packages/sdk-core/README.md | 27 +++++------ packages/sms/README.md | 44 ++++++++++-------- packages/verification/README.md | 30 +++++++----- packages/voice/README.md | 28 ++++++----- 182 files changed, 832 insertions(+), 664 deletions(-) delete mode 100644 examples/simple-examples/src/sms/groups/create/create.sinch-client.ts delete mode 100644 examples/simple-examples/src/sms/groups/create/create.sinch-sms-client.ts create mode 100644 examples/simple-examples/src/sms/groups/create/create.with-projectId.ts create mode 100644 examples/simple-examples/src/sms/groups/create/create.with-servicePlanId.ts delete mode 100644 examples/simple-examples/src/sms/groups/delete/delete.sinch-client.ts delete mode 100644 examples/simple-examples/src/sms/groups/delete/delete.sinch-sms-client.ts create mode 100644 examples/simple-examples/src/sms/groups/delete/delete.with-projectId.ts create mode 100644 examples/simple-examples/src/sms/groups/delete/delete.with-servicePlanId.ts delete mode 100644 examples/simple-examples/src/sms/groups/get/get.sinch-client.ts delete mode 100644 examples/simple-examples/src/sms/groups/get/get.sinch-sms-client.ts create mode 100644 examples/simple-examples/src/sms/groups/get/get.with-projectId.ts create mode 100644 examples/simple-examples/src/sms/groups/get/get.with-servicePlanId.ts delete mode 100644 examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-client.ts delete mode 100644 examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-sms-client.ts create mode 100644 examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-projectId.ts create mode 100644 examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-servicePlanId.ts delete mode 100644 examples/simple-examples/src/sms/groups/list/list.sinch-client.ts delete mode 100644 examples/simple-examples/src/sms/groups/list/list.sinch-sms-client.ts create mode 100644 examples/simple-examples/src/sms/groups/list/list.with-projectId.ts create mode 100644 examples/simple-examples/src/sms/groups/list/list.with-servicePlanId.ts delete mode 100644 examples/simple-examples/src/sms/groups/replace/replace.sinch-client.ts delete mode 100644 examples/simple-examples/src/sms/groups/replace/replace.sinch-sms-client.ts create mode 100644 examples/simple-examples/src/sms/groups/replace/replace.with-projectId.ts create mode 100644 examples/simple-examples/src/sms/groups/replace/replace.with-servicePlanId.ts delete mode 100644 examples/simple-examples/src/sms/groups/update/update.sinch-client.ts delete mode 100644 examples/simple-examples/src/sms/groups/update/update.sinch-sms-client.ts create mode 100644 examples/simple-examples/src/sms/groups/update/update.with-projectId.ts create mode 100644 examples/simple-examples/src/sms/groups/update/update.with-servicePlanId.ts diff --git a/README.md b/README.md index de94d3bd..41d598bf 100644 --- a/README.md +++ b/README.md @@ -94,12 +94,27 @@ where `sinchClientParameters` is an object containing the properties required to - `keySecret` - (For the SMS API, `region` is optional. Default is `US`). +From this client, you have access to all the SDK services supporting the Sinch APIs: +```typescript +import { + SinchClient, +} from '@sinch/sdk-core'; + +const sinch = new SinchClient(sinchClientParameters); +const conversationService = sinch.conversation; +const faxService = sinch.fax; +const numbersService = sinch.numbers; +const smsService = sinch.sms; +const verificationService = sinch.verification; +const voiceService = sinch.voice; +``` + ### Promises All the methods that interact with the Sinch APIs use Promises. ```typescript -const response: SendSMSResponse = await sinchClient.sms.batches.send({ +const response: SendSMSResponse = await smsService.batches.send({ sendSMSRequestBody: { to: [ '+12223334444', @@ -128,14 +143,8 @@ Here is the list of the Sinch products and their level of support by the Node.js | Messaging | SMS API | ✅ | | | Conversation API | ✅ | | | Fax API | 🚧 | -| | RCS API | ❌ | -| | MMS API | ❌ | -| | Provisioning API | ❌ | | Voice and Video | Voice API | ✅ | -| | Elastic SIP Trunking | ❌ | | Numbers & Connectivity | Numbers API | ✅ | -| | Brand and Campaign Registration API | ❌ | -| | Number Lookup API | ❌ | | Verification | Verification API | ✅ | ### Packages @@ -143,10 +152,11 @@ Here is the list of the Sinch products and their level of support by the Node.js The Sinch Node.js SDK is packaged in the following way: - [`@sinch/sdk-core`](./packages/sdk-core): package defining the `SinchClient` class and wrapping all the other packages. - [`@sinch/sms`](./packages/sms): package that contains SMS services: Batches, Delivery reports, Inbounds, Groups and Webhooks callbacks. - - `@sinch/conversation`: IN-PROGRESS + - [`@sinch/conversation`](./packages/conversation): package that contains Conversation services: App, Capability, Contact, Conversation, Events, Messages, Templates V1 and V2, Transcoding, Webhooks management and Webhooks callbacks. - [`@sinch/voice`](./packages/voice): package that contains the Voice services: Callouts, Calls, Conferences, Applications management and Webhooks callbacks. - [`@sinch/numbers`](./packages/numbers): package that contains the Numbers services: Available number, Active number, Available regions, Callbacks management and Webhooks callbacks. - [`@sinch/verification`](./packages/verification): package that contains the Verification services: Verification start and report, Verification status and Webhooks callbacks. + - [`@sinch/fax`](./packages/fax): package that contains the Fax services: Services, Faxes and Faxes-on-emails - [`@sinch/sdk-client`](./packages/sdk-client): package included by all the other ones that contains the API client classes and helpers. ## Examples diff --git a/examples/simple-examples/package.json b/examples/simple-examples/package.json index 4430bc64..dc2e0cd6 100644 --- a/examples/simple-examples/package.json +++ b/examples/simple-examples/package.json @@ -99,13 +99,13 @@ "numbers:active:release": "ts-node src/numbers/active/release.ts", "numbers:callback:get": "ts-node src/numbers/callbacks/get.ts", "numbers:callback:update": "ts-node src/numbers/callbacks/update.ts", - "sms:groups:list": "ts-node src/sms/groups/list/list.sinch-client.ts", - "sms:groups:create": "ts-node src/sms/groups/create/create.sinch-client.ts", - "sms:groups:get": "ts-node src/sms/groups/get/get.sinch-client.ts", - "sms:groups:getPhoneNumbers": "ts-node src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-client.ts", - "sms:groups:replace": "ts-node src/sms/groups/replace/replace.sinch-client.ts", - "sms:groups:update": "ts-node src/sms/groups/update/update.sinch-client.ts", - "sms:groups:delete": "ts-node src/sms/groups/delete/delete.sinch-client.ts", + "sms:groups:list": "ts-node src/sms/groups/list/list.with-projectId.ts", + "sms:groups:create": "ts-node src/sms/groups/create/create.with-projectId.ts", + "sms:groups:get": "ts-node src/sms/groups/get/get.with-projectId.ts", + "sms:groups:getPhoneNumbers": "ts-node src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-projectId.ts", + "sms:groups:replace": "ts-node src/sms/groups/replace/replace.with-projectId.ts", + "sms:groups:update": "ts-node src/sms/groups/update/update.with-projectId.ts", + "sms:groups:delete": "ts-node src/sms/groups/delete/delete.with-projectId.ts", "sms:batches:send": "ts-node src/sms/batches/send.ts", "sms:batches:sendTextMessage": "ts-node src/sms/batches/sendTextMessage.ts", "sms:batches:sendBinaryMessage": "ts-node src/sms/batches/sendBinaryMessage.ts", diff --git a/examples/simple-examples/src/config.ts b/examples/simple-examples/src/config.ts index db4052fe..d82f17db 100644 --- a/examples/simple-examples/src/config.ts +++ b/examples/simple-examples/src/config.ts @@ -1,26 +1,64 @@ -import { getRegion, SinchClient, Region } from '@sinch/sdk-core'; +import { + getRegion, + SinchClient, + Region, + ConversationService, + FaxService, + NumbersService, + SmsService, + VerificationService, + VoiceService, +} from '@sinch/sdk-core'; require('dotenv').config(); -export const initClient = () => { +const initClient = (): Pick => { const keyId = process.env.SINCH_KEY_ID || ''; const keySecret = process.env.SINCH_KEY_SECRET || ''; const projectId = process.env.SINCH_PROJECT_ID || ''; return new SinchClient({ projectId, keyId, keySecret }); }; -export const initSmsClient = () => { +export const initConversationService = (): ConversationService => { + return initClient().conversation; +}; + +export const initFaxService = (): FaxService => { + return initClient().fax; +}; + +export const initNumbersService = (): NumbersService => { + return initClient().numbers; +}; + +export const initSmsServiceWithProjectId = (): SmsService => { + return initClient().sms; +}; + +const initSmsClient = (): Pick => { const servicePlanId = process.env.SINCH_SERVICE_PLAN_ID || ''; const apiToken = process.env.SINCH_API_TOKEN || ''; const region = getRegion(process.env.SMS_REGION) || Region.UNITED_STATES; return new SinchClient({ servicePlanId, apiToken, region }); }; -export const initApplicationClient = () => { +export const initSmsServiceWithServicePlanId = (): SmsService => { + return initSmsClient().sms; +}; + +const initApplicationClient = (): Pick => { const applicationKey = process.env.SINCH_APPLICATION_KEY || ''; const applicationSecret = process.env.SINCH_APPLICATION_SECRET || ''; return new SinchClient({ applicationKey, applicationSecret }); }; +export const initVerificationService = (): VerificationService => { + return initApplicationClient().verification; +}; + +export const initVoiceService = (): VoiceService => { + return initApplicationClient().voice; +}; + export const getPrintFormat = (args: string[]): 'pretty' | 'full' => { const params = args.slice(2); if (params.length > 0 && params[0] === 'pretty') { diff --git a/examples/simple-examples/src/conversation/app/create.ts b/examples/simple-examples/src/conversation/app/create.ts index fbf487b8..d0240dbe 100644 --- a/examples/simple-examples/src/conversation/app/create.ts +++ b/examples/simple-examples/src/conversation/app/create.ts @@ -1,5 +1,10 @@ import { CreateAppRequestData } from '@sinch/sdk-core'; -import { getMessengerTokenFormConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { + getMessengerTokenFormConfig, + getPrintFormat, + initConversationService, + printFullResponse, +} from '../../config'; (async () => { console.log('*****************'); @@ -27,8 +32,8 @@ import { getMessengerTokenFormConfig, getPrintFormat, initClient, printFullRespo }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.app.create(requestData); + const conversationService = initConversationService(); + const response = await conversationService.app.create(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/app/delete.ts b/examples/simple-examples/src/conversation/app/delete.ts index 15414354..4569f055 100644 --- a/examples/simple-examples/src/conversation/app/delete.ts +++ b/examples/simple-examples/src/conversation/app/delete.ts @@ -1,5 +1,5 @@ import { DeleteAppRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*****************'); @@ -12,8 +12,8 @@ import { getAppIdFromConfig, initClient, printFullResponse } from '../../config' app_id: appId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.app.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.app.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/app/get.ts b/examples/simple-examples/src/conversation/app/get.ts index 8667fe0a..1aa02c31 100644 --- a/examples/simple-examples/src/conversation/app/get.ts +++ b/examples/simple-examples/src/conversation/app/get.ts @@ -1,5 +1,10 @@ import { GetAppRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { + getAppIdFromConfig, + getPrintFormat, + initConversationService, + printFullResponse, +} from '../../config'; (async () => { console.log('**************'); @@ -12,8 +17,8 @@ import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } fro app_id: appId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.app.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.app.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/app/list.ts b/examples/simple-examples/src/conversation/app/list.ts index c51d83a9..6c1edcbb 100644 --- a/examples/simple-examples/src/conversation/app/list.ts +++ b/examples/simple-examples/src/conversation/app/list.ts @@ -1,5 +1,5 @@ import { ListAppsRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************'); @@ -8,8 +8,8 @@ import { getPrintFormat, initClient, printFullResponse } from '../../config'; const requestData: ListAppsRequestData= {}; - const sinchClient = initClient(); - const response = await sinchClient.conversation.app.list(requestData); + const conversationService = initConversationService(); + const response = await conversationService.app.list(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/app/update.ts b/examples/simple-examples/src/conversation/app/update.ts index b121ad58..200d751f 100644 --- a/examples/simple-examples/src/conversation/app/update.ts +++ b/examples/simple-examples/src/conversation/app/update.ts @@ -1,8 +1,9 @@ import { UpdateAppRequestData } from '@sinch/sdk-core'; import { - getAppIdFromConfig, getMessengerTokenFormConfig, + getAppIdFromConfig, + getMessengerTokenFormConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -31,8 +32,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.app.update(requestData); + const conversationService = initConversationService(); + const response = await conversationService.app.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/capability/lookup.ts b/examples/simple-examples/src/conversation/capability/lookup.ts index 549a5ef7..1cd6dfd7 100644 --- a/examples/simple-examples/src/conversation/capability/lookup.ts +++ b/examples/simple-examples/src/conversation/capability/lookup.ts @@ -1,5 +1,10 @@ import { ContactId, LookupCapabilityRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { + getAppIdFromConfig, + getContactIdFromConfig, + initConversationService, + printFullResponse, +} from '../../config'; (async () => { console.log('******************************'); @@ -19,8 +24,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.capability.lookup(requestData); + const conversationService = initConversationService(); + const response = await conversationService.capability.lookup(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/contact/create.ts b/examples/simple-examples/src/conversation/contact/create.ts index 0b81d29a..0b84fa2f 100644 --- a/examples/simple-examples/src/conversation/contact/create.ts +++ b/examples/simple-examples/src/conversation/contact/create.ts @@ -4,7 +4,7 @@ import { getMessengerUserIdFromConfig, getPhoneNumberFromConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -36,8 +36,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.contact.create(requestData); + const conversationService = initConversationService(); + const response = await conversationService.contact.create(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/contact/delete.ts b/examples/simple-examples/src/conversation/contact/delete.ts index 6fbad08a..e4674884 100644 --- a/examples/simple-examples/src/conversation/contact/delete.ts +++ b/examples/simple-examples/src/conversation/contact/delete.ts @@ -1,5 +1,5 @@ import { DeleteContactRequestData } from '@sinch/sdk-core'; -import { getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*************************'); @@ -12,8 +12,8 @@ import { getContactIdFromConfig, initClient, printFullResponse } from '../../con contact_id: contactId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.contact.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.contact.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/contact/get.ts b/examples/simple-examples/src/conversation/contact/get.ts index 4978c478..9fa13090 100644 --- a/examples/simple-examples/src/conversation/contact/get.ts +++ b/examples/simple-examples/src/conversation/contact/get.ts @@ -1,5 +1,5 @@ import { GetContactRequestData } from '@sinch/sdk-core'; -import { getContactIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getContactIdFromConfig, getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('**********************'); @@ -12,8 +12,8 @@ import { getContactIdFromConfig, getPrintFormat, initClient, printFullResponse } contact_id: contactId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.contact.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.contact.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/contact/getChannelProfile.ts b/examples/simple-examples/src/conversation/contact/getChannelProfile.ts index 24098155..e58a6c12 100644 --- a/examples/simple-examples/src/conversation/contact/getChannelProfile.ts +++ b/examples/simple-examples/src/conversation/contact/getChannelProfile.ts @@ -2,7 +2,7 @@ import { GetChannelProfileRequestData, IdentifiedBy } from '@sinch/sdk-core'; import { getAppIdFromConfig, getMessengerUserIdFromConfig, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -31,8 +31,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.contact.getChannelProfile(requestData); + const conversationService = initConversationService(); + const response = await conversationService.contact.getChannelProfile(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/contact/list.ts b/examples/simple-examples/src/conversation/contact/list.ts index 3e83a3e4..788ad5d7 100644 --- a/examples/simple-examples/src/conversation/contact/list.ts +++ b/examples/simple-examples/src/conversation/contact/list.ts @@ -1,5 +1,5 @@ import { Contact, ListContactsRequestData, PageResult } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initConversationService, printFullResponse } from '../../config'; const populateContactsList = ( contactPage: PageResult, @@ -21,12 +21,12 @@ const populateContactsList = ( page_size: 2, }; - const sinchClient = initClient(); + const conversationService = initConversationService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.conversation.contact.list(requestData); + let response = await conversationService.contact.list(requestData); const contactList: Contact[] = []; const contactDetailsList: string[] = []; @@ -55,7 +55,7 @@ const populateContactsList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const contact of sinchClient.conversation.contact.list(requestData)) { + for await (const contact of conversationService.contact.list(requestData)) { if (printFormat === 'pretty') { console.log(`${contact.id} - ${contact.display_name}`); } else { diff --git a/examples/simple-examples/src/conversation/contact/merge.ts b/examples/simple-examples/src/conversation/contact/merge.ts index 9035853c..82186980 100644 --- a/examples/simple-examples/src/conversation/contact/merge.ts +++ b/examples/simple-examples/src/conversation/contact/merge.ts @@ -2,7 +2,7 @@ import { CreateContactRequestData, MergeContactRequestData } from '@sinch/sdk-co import { getPhoneNumberFromConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -43,9 +43,9 @@ import { }, }; - const sinchClient = initClient(); - const sourceContact = await sinchClient.conversation.contact.create(sourceContactRequestData); - const destinationContact = await sinchClient.conversation.contact.create(destinationContactRequestData); + const conversationService = initConversationService(); + const sourceContact = await conversationService.contact.create(sourceContactRequestData); + const destinationContact = await conversationService.contact.create(destinationContactRequestData); if (sourceContact.id && destinationContact.id) { const requestData: MergeContactRequestData = { @@ -56,7 +56,7 @@ import { }, }; - const response = await sinchClient.conversation.contact.mergeContact(requestData); + const response = await conversationService.contact.mergeContact(requestData); const printFormat = getPrintFormat(process.argv); if (printFormat === 'pretty') { diff --git a/examples/simple-examples/src/conversation/contact/update.ts b/examples/simple-examples/src/conversation/contact/update.ts index f5c763ed..7c69a4d0 100644 --- a/examples/simple-examples/src/conversation/contact/update.ts +++ b/examples/simple-examples/src/conversation/contact/update.ts @@ -1,4 +1,9 @@ -import { getContactIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { + getContactIdFromConfig, + getPrintFormat, + initConversationService, + printFullResponse, +} from '../../config'; import { UpdateContactRequestData } from '@sinch/sdk-core'; (async () => { @@ -18,8 +23,8 @@ import { UpdateContactRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.contact.update(requestData); + const conversationService = initConversationService(); + const response = await conversationService.contact.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/conversation/create.ts b/examples/simple-examples/src/conversation/conversation/create.ts index 4e1c993c..d555aada 100644 --- a/examples/simple-examples/src/conversation/conversation/create.ts +++ b/examples/simple-examples/src/conversation/conversation/create.ts @@ -3,7 +3,7 @@ import { getAppIdFromConfig, getContactIdFromConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -31,8 +31,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.conversation.create(requestData); + const conversationService = initConversationService(); + const response = await conversationService.conversation.create(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/conversation/delete.ts b/examples/simple-examples/src/conversation/conversation/delete.ts index bea76e55..1f63c669 100644 --- a/examples/simple-examples/src/conversation/conversation/delete.ts +++ b/examples/simple-examples/src/conversation/conversation/delete.ts @@ -1,5 +1,5 @@ import { DeleteConversationRequestData } from '@sinch/sdk-core'; -import { getConversationIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getConversationIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { @@ -13,8 +13,8 @@ import { getConversationIdFromConfig, initClient, printFullResponse } from '../. conversation_id: conversationId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.conversation.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.conversation.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/conversation/get.ts b/examples/simple-examples/src/conversation/conversation/get.ts index 7bcd5eec..e24fea29 100644 --- a/examples/simple-examples/src/conversation/conversation/get.ts +++ b/examples/simple-examples/src/conversation/conversation/get.ts @@ -2,7 +2,7 @@ import { GetConversationRequestData } from '@sinch/sdk-core'; import { getConversationIdFromConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -17,8 +17,8 @@ import { conversation_id: conversationId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.conversation.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.conversation.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/conversation/injectEvent.ts b/examples/simple-examples/src/conversation/conversation/injectEvent.ts index 4af09178..9cbf4f02 100644 --- a/examples/simple-examples/src/conversation/conversation/injectEvent.ts +++ b/examples/simple-examples/src/conversation/conversation/injectEvent.ts @@ -2,7 +2,7 @@ import { InjectEventRequestData } from '@sinch/sdk-core'; import { getContactIdFromConfig, getConversationIdFromConfig, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -27,8 +27,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.conversation.injectEvent(requestData); + const conversationService = initConversationService(); + const response = await conversationService.conversation.injectEvent(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/conversation/injectMessage.ts b/examples/simple-examples/src/conversation/conversation/injectMessage.ts index 5a34d5f8..97435c7e 100644 --- a/examples/simple-examples/src/conversation/conversation/injectMessage.ts +++ b/examples/simple-examples/src/conversation/conversation/injectMessage.ts @@ -3,7 +3,7 @@ import { getAppIdFromConfig, getContactIdFromConfig, getConversationIdFromConfig, getMessengerUserIdFromConfig, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -37,8 +37,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.conversation.injectMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.conversation.injectMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/conversation/list.ts b/examples/simple-examples/src/conversation/conversation/list.ts index 5aefa536..7abf34c7 100644 --- a/examples/simple-examples/src/conversation/conversation/list.ts +++ b/examples/simple-examples/src/conversation/conversation/list.ts @@ -1,5 +1,5 @@ import { Conversation, ListConversationsRequestData, PageResult } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getPrintFormat, initConversationService, printFullResponse } from '../../config'; const populateConversationsList = ( conversationPage: PageResult, @@ -24,12 +24,12 @@ const populateConversationsList = ( app_id: appId, }; - const sinchClient = initClient(); + const conversationService = initConversationService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.conversation.conversation.list(requestData); + let response = await conversationService.conversation.list(requestData); const conversationList: Conversation[] = []; const conversationDetailsList: string[] = []; @@ -58,7 +58,7 @@ const populateConversationsList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const conversation of sinchClient.conversation.conversation.list(requestData)) { + for await (const conversation of conversationService.conversation.list(requestData)) { if (printFormat === 'pretty') { console.log(`${conversation.id} - ${conversation.active_channel}`); } else { diff --git a/examples/simple-examples/src/conversation/conversation/listRecent.ts b/examples/simple-examples/src/conversation/conversation/listRecent.ts index f2fdd738..445edc07 100644 --- a/examples/simple-examples/src/conversation/conversation/listRecent.ts +++ b/examples/simple-examples/src/conversation/conversation/listRecent.ts @@ -3,7 +3,7 @@ import { ListRecentConversationsRequestData, PageResult, } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getPrintFormat, initConversationService, printFullResponse } from '../../config'; const populateConversationsList = ( conversationPage: PageResult, @@ -29,12 +29,12 @@ const populateConversationsList = ( order: 'ASC', }; - const sinchClient = initClient(); + const conversationService = initConversationService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.conversation.conversation.listRecent(requestData); + let response = await conversationService.conversation.listRecent(requestData); const conversationList: ConversationRecentMessage[] = []; const conversationDetailsList: string[] = []; @@ -63,7 +63,7 @@ const populateConversationsList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const recentConversation of sinchClient.conversation.conversation.listRecent(requestData)) { + for await (const recentConversation of conversationService.conversation.listRecent(requestData)) { if (printFormat === 'pretty') { console.log(`${recentConversation.conversation?.id} - ${recentConversation.conversation?.active_channel}\n - Latest message: ${recentConversation.last_message?.accept_time}`); } else { diff --git a/examples/simple-examples/src/conversation/conversation/stop.ts b/examples/simple-examples/src/conversation/conversation/stop.ts index 606c56c1..420dff5d 100644 --- a/examples/simple-examples/src/conversation/conversation/stop.ts +++ b/examples/simple-examples/src/conversation/conversation/stop.ts @@ -1,5 +1,5 @@ import { StopActiveConversationRequestData } from '@sinch/sdk-core'; -import { getConversationIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getConversationIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { @@ -13,8 +13,8 @@ import { getConversationIdFromConfig, initClient, printFullResponse } from '../. conversation_id: conversationId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.conversation.stopActive(requestData); + const conversationService = initConversationService(); + const response = await conversationService.conversation.stopActive(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/conversation/update.ts b/examples/simple-examples/src/conversation/conversation/update.ts index 81d12b51..04a64f78 100644 --- a/examples/simple-examples/src/conversation/conversation/update.ts +++ b/examples/simple-examples/src/conversation/conversation/update.ts @@ -1,7 +1,7 @@ import { getConversationIdFromConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; import { UpdateConversationRequestData } from '@sinch/sdk-core'; @@ -22,8 +22,8 @@ import { UpdateConversationRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.conversation.update(requestData); + const conversationService = initConversationService(); + const response = await conversationService.conversation.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/events/delete.ts b/examples/simple-examples/src/conversation/events/delete.ts index 8bf353f1..ae2d3e62 100644 --- a/examples/simple-examples/src/conversation/events/delete.ts +++ b/examples/simple-examples/src/conversation/events/delete.ts @@ -1,5 +1,5 @@ import { DeleteEventRequestData } from '@sinch/sdk-core'; -import { getEventIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getEventIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { @@ -13,8 +13,8 @@ import { getEventIdFromConfig, initClient, printFullResponse } from '../../confi event_id: eventId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/get.ts b/examples/simple-examples/src/conversation/events/get.ts index 2a04eb0e..3af8bc9c 100644 --- a/examples/simple-examples/src/conversation/events/get.ts +++ b/examples/simple-examples/src/conversation/events/get.ts @@ -1,5 +1,5 @@ import { GetEventRequestData } from '@sinch/sdk-core'; -import { getEventIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getEventIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*******************'); @@ -12,8 +12,8 @@ import { getEventIdFromConfig, initClient, printFullResponse } from '../../confi event_id: eventId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.get(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/list.ts b/examples/simple-examples/src/conversation/events/list.ts index b5f90209..215f7d6b 100644 --- a/examples/simple-examples/src/conversation/events/list.ts +++ b/examples/simple-examples/src/conversation/events/list.ts @@ -3,7 +3,7 @@ import { getContactIdFromConfig, getConversationIdFromConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -31,12 +31,12 @@ const populateEventsList = ( conversation_id: conversationId, }; - const sinchClient = initClient(); + const conversationService = initConversationService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.conversation.events.list(requestData); + let response = await conversationService.events.list(requestData); const eventsList: ConversationEvent[] = []; const eventsDetailsList: string[] = []; @@ -65,7 +65,7 @@ const populateEventsList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const event of sinchClient.conversation.events.list(requestData)) { + for await (const event of conversationService.events.list(requestData)) { if (printFormat === 'pretty') { console.log(`${event.id} - ${event.accept_time}`); } else { diff --git a/examples/simple-examples/src/conversation/events/send.ts b/examples/simple-examples/src/conversation/events/send.ts index 767296a3..cb7b91b1 100644 --- a/examples/simple-examples/src/conversation/events/send.ts +++ b/examples/simple-examples/src/conversation/events/send.ts @@ -1,5 +1,5 @@ import { ContactId, SendEventRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************'); @@ -25,8 +25,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.send(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.send(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/sendAgentJoinedEvent.ts b/examples/simple-examples/src/conversation/events/sendAgentJoinedEvent.ts index 3baf50dc..ed2fd594 100644 --- a/examples/simple-examples/src/conversation/events/sendAgentJoinedEvent.ts +++ b/examples/simple-examples/src/conversation/events/sendAgentJoinedEvent.ts @@ -1,5 +1,5 @@ import { ContactId, SendAgentJoinedEventRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************'); @@ -26,8 +26,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.sendAgentJoinedEvent(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.sendAgentJoinedEvent(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/sendAgentLeftEvent.ts b/examples/simple-examples/src/conversation/events/sendAgentLeftEvent.ts index 3c4d9973..a7877f5a 100644 --- a/examples/simple-examples/src/conversation/events/sendAgentLeftEvent.ts +++ b/examples/simple-examples/src/conversation/events/sendAgentLeftEvent.ts @@ -1,5 +1,5 @@ import { ContactId, SendAgentLeftEventRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************'); @@ -26,8 +26,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.sendAgentLeftEvent(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.sendAgentLeftEvent(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/sendCommentReplyEvent.ts b/examples/simple-examples/src/conversation/events/sendCommentReplyEvent.ts index b8acb586..c49822a3 100644 --- a/examples/simple-examples/src/conversation/events/sendCommentReplyEvent.ts +++ b/examples/simple-examples/src/conversation/events/sendCommentReplyEvent.ts @@ -1,5 +1,5 @@ import { ContactId, SendCommentReplyEventRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************'); @@ -23,8 +23,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.sendCommentReplyEvent(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.sendCommentReplyEvent(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/sendComposingEndEvent.ts b/examples/simple-examples/src/conversation/events/sendComposingEndEvent.ts index 7ecc8907..6055c3d9 100644 --- a/examples/simple-examples/src/conversation/events/sendComposingEndEvent.ts +++ b/examples/simple-examples/src/conversation/events/sendComposingEndEvent.ts @@ -1,5 +1,5 @@ import { ContactId, SendComposingEndEventRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************'); @@ -21,8 +21,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.sendComposingEndEvent(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.sendComposingEndEvent(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/sendComposingEvent.ts b/examples/simple-examples/src/conversation/events/sendComposingEvent.ts index bef2d5f6..3f8bf4ff 100644 --- a/examples/simple-examples/src/conversation/events/sendComposingEvent.ts +++ b/examples/simple-examples/src/conversation/events/sendComposingEvent.ts @@ -1,5 +1,5 @@ import { ContactId, SendComposingEventRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************'); @@ -21,8 +21,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.sendComposingEvent(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.sendComposingEvent(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/events/sendGenericEvent.ts b/examples/simple-examples/src/conversation/events/sendGenericEvent.ts index 28b08b49..033ec212 100644 --- a/examples/simple-examples/src/conversation/events/sendGenericEvent.ts +++ b/examples/simple-examples/src/conversation/events/sendGenericEvent.ts @@ -1,5 +1,5 @@ import { ContactId, SendGenericEventRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************'); @@ -25,8 +25,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.events.sendGenericEvent(requestData); + const conversationService = initConversationService(); + const response = await conversationService.events.sendGenericEvent(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/delete.ts b/examples/simple-examples/src/conversation/messages/delete.ts index e2f0fb8d..562bbc36 100644 --- a/examples/simple-examples/src/conversation/messages/delete.ts +++ b/examples/simple-examples/src/conversation/messages/delete.ts @@ -1,5 +1,5 @@ import { DeleteMessageRequestData } from '@sinch/sdk-core'; -import { getMessageIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getMessageIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { @@ -13,8 +13,8 @@ import { getMessageIdFromConfig, initClient, printFullResponse } from '../../con message_id: messageId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/get.ts b/examples/simple-examples/src/conversation/messages/get.ts index ddbbad18..e5008c69 100644 --- a/examples/simple-examples/src/conversation/messages/get.ts +++ b/examples/simple-examples/src/conversation/messages/get.ts @@ -1,5 +1,5 @@ import { GetMessageRequestData } from '@sinch/sdk-core'; -import { getMessageIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getMessageIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('***********************'); @@ -12,8 +12,8 @@ import { getMessageIdFromConfig, initClient, printFullResponse } from '../../con message_id: messageId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.get(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/list.ts b/examples/simple-examples/src/conversation/messages/list.ts index b6faf157..2e5ff970 100644 --- a/examples/simple-examples/src/conversation/messages/list.ts +++ b/examples/simple-examples/src/conversation/messages/list.ts @@ -3,7 +3,7 @@ import { getAppIdFromConfig, getContactIdFromConfig, getConversationIdFromConfig, getPrintFormat, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -34,12 +34,12 @@ const populateMessagesList = ( channel: 'MESSENGER', }; - const sinchClient = initClient(); + const conversationService = initConversationService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.conversation.messages.list(requestData); + let response = await conversationService.messages.list(requestData); const messageList: ConversationMessage[] = []; const messagesDetailsList: string[] = []; @@ -68,7 +68,7 @@ const populateMessagesList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const message of sinchClient.conversation.messages.list(requestData)) { + for await (const message of conversationService.messages.list(requestData)) { if (printFormat === 'pretty') { console.log(`${message.id} - ${message.accept_time}`); } else { diff --git a/examples/simple-examples/src/conversation/messages/send.ts b/examples/simple-examples/src/conversation/messages/send.ts index fee7337b..31bc6461 100644 --- a/examples/simple-examples/src/conversation/messages/send.ts +++ b/examples/simple-examples/src/conversation/messages/send.ts @@ -1,5 +1,5 @@ import { ContactId, SendMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('************************'); @@ -27,8 +27,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.send(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.send(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendCardMessage.ts b/examples/simple-examples/src/conversation/messages/sendCardMessage.ts index b393ccf3..1e489fd6 100644 --- a/examples/simple-examples/src/conversation/messages/sendCardMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendCardMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendCardMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -29,8 +29,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendCardMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendCardMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendCarouselMessage.ts b/examples/simple-examples/src/conversation/messages/sendCarouselMessage.ts index 4a525d85..068be6b5 100644 --- a/examples/simple-examples/src/conversation/messages/sendCarouselMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendCarouselMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendCarouselMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************************'); @@ -38,8 +38,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendCarouselMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendCarouselMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendChoiceMessage.ts b/examples/simple-examples/src/conversation/messages/sendChoiceMessage.ts index af46a421..a4f624ea 100644 --- a/examples/simple-examples/src/conversation/messages/sendChoiceMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendChoiceMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendChoiceMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('******************************'); @@ -43,8 +43,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendChoiceMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendChoiceMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendContactInfoMessage.ts b/examples/simple-examples/src/conversation/messages/sendContactInfoMessage.ts index 966446ae..ea2523df 100644 --- a/examples/simple-examples/src/conversation/messages/sendContactInfoMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendContactInfoMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendContactInfoMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('***********************************'); @@ -41,8 +41,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendContactInfoMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendContactInfoMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendListMessage.ts b/examples/simple-examples/src/conversation/messages/sendListMessage.ts index be5df7df..288db425 100644 --- a/examples/simple-examples/src/conversation/messages/sendListMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendListMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendListMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -54,8 +54,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendListMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendListMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendLocationMessage.ts b/examples/simple-examples/src/conversation/messages/sendLocationMessage.ts index acea382c..ce766b85 100644 --- a/examples/simple-examples/src/conversation/messages/sendLocationMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendLocationMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendLocationMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************************'); @@ -32,8 +32,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendLocationMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendLocationMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendMediaMessage.ts b/examples/simple-examples/src/conversation/messages/sendMediaMessage.ts index c90f683e..5273b8fa 100644 --- a/examples/simple-examples/src/conversation/messages/sendMediaMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendMediaMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendMediaMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*****************************'); @@ -27,8 +27,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendMediaMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendMediaMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendTemplateMessage.ts b/examples/simple-examples/src/conversation/messages/sendTemplateMessage.ts index b968aea6..18d6f74e 100644 --- a/examples/simple-examples/src/conversation/messages/sendTemplateMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendTemplateMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendTemplateMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************************'); @@ -31,8 +31,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendTemplateMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendTemplateMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/sendTextMessage.ts b/examples/simple-examples/src/conversation/messages/sendTextMessage.ts index 0c8fa2f5..9d26d3ef 100644 --- a/examples/simple-examples/src/conversation/messages/sendTextMessage.ts +++ b/examples/simple-examples/src/conversation/messages/sendTextMessage.ts @@ -1,5 +1,5 @@ import { ContactId, SendTextMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getContactIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -27,8 +27,8 @@ import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullRespon }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.sendTextMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.sendTextMessage(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/messages/update.ts b/examples/simple-examples/src/conversation/messages/update.ts index 88c96267..db1edf6d 100644 --- a/examples/simple-examples/src/conversation/messages/update.ts +++ b/examples/simple-examples/src/conversation/messages/update.ts @@ -1,7 +1,7 @@ import { UpdateMessageRequestData } from '@sinch/sdk-core'; import { getMessageIdFromConfig, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -19,8 +19,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.messages.update(requestData); + const conversationService = initConversationService(); + const response = await conversationService.messages.update(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/templates-v1/create.ts b/examples/simple-examples/src/conversation/templates-v1/create.ts index b3d7bf04..5b35c3b3 100644 --- a/examples/simple-examples/src/conversation/templates-v1/create.ts +++ b/examples/simple-examples/src/conversation/templates-v1/create.ts @@ -1,5 +1,5 @@ import { CreateTemplateRequestData, templateV1Helper } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -23,8 +23,8 @@ import { getPrintFormat, initClient, printFullResponse } from '../../config'; }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV1.create(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV1.create(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v1/delete.ts b/examples/simple-examples/src/conversation/templates-v1/delete.ts index ee9ddc4e..bac2005a 100644 --- a/examples/simple-examples/src/conversation/templates-v1/delete.ts +++ b/examples/simple-examples/src/conversation/templates-v1/delete.ts @@ -1,5 +1,5 @@ import { DeleteTemplateRequestData } from '@sinch/sdk-core'; -import { getTemplateIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -12,8 +12,8 @@ import { getTemplateIdFromConfig, initClient, printFullResponse } from '../../co template_id: templateId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV1.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV1.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/templates-v1/get.ts b/examples/simple-examples/src/conversation/templates-v1/get.ts index 2896d2b0..79de40b7 100644 --- a/examples/simple-examples/src/conversation/templates-v1/get.ts +++ b/examples/simple-examples/src/conversation/templates-v1/get.ts @@ -1,5 +1,5 @@ import { GetTemplateRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*************************'); @@ -12,8 +12,8 @@ import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse template_id: templateId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV1.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV1.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v1/list.ts b/examples/simple-examples/src/conversation/templates-v1/list.ts index 9ae7929b..bfe6c3e8 100644 --- a/examples/simple-examples/src/conversation/templates-v1/list.ts +++ b/examples/simple-examples/src/conversation/templates-v1/list.ts @@ -1,5 +1,5 @@ import { ListTemplatesRequestData, V1Template } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('***************************'); @@ -10,8 +10,8 @@ import { getPrintFormat, initClient, printFullResponse } from '../../config'; const requestData: ListTemplatesRequestData = { }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV1.list(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV1.list(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v1/update.ts b/examples/simple-examples/src/conversation/templates-v1/update.ts index ce92e93d..6f07558f 100644 --- a/examples/simple-examples/src/conversation/templates-v1/update.ts +++ b/examples/simple-examples/src/conversation/templates-v1/update.ts @@ -1,5 +1,5 @@ import { templateV1Helper, UpdateTemplateRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -40,8 +40,8 @@ import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV1.update(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV1.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v2/create.ts b/examples/simple-examples/src/conversation/templates-v2/create.ts index 4f695d70..818ab5c6 100644 --- a/examples/simple-examples/src/conversation/templates-v2/create.ts +++ b/examples/simple-examples/src/conversation/templates-v2/create.ts @@ -1,5 +1,5 @@ import { templateV2Helper, V2CreateTemplateRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*******************************'); @@ -22,8 +22,8 @@ import { getPrintFormat, initClient, printFullResponse } from '../../config'; }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV2.create(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV2.create(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v2/delete.ts b/examples/simple-examples/src/conversation/templates-v2/delete.ts index 43a000dd..cdb75187 100644 --- a/examples/simple-examples/src/conversation/templates-v2/delete.ts +++ b/examples/simple-examples/src/conversation/templates-v2/delete.ts @@ -1,5 +1,5 @@ import { V2DeleteTemplateRequestData } from '@sinch/sdk-core'; -import { getTemplateIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*******************************'); @@ -12,8 +12,8 @@ import { getTemplateIdFromConfig, initClient, printFullResponse } from '../../co template_id: templateId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV2.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV2.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/templates-v2/get.ts b/examples/simple-examples/src/conversation/templates-v2/get.ts index bce45b57..eacf91c7 100644 --- a/examples/simple-examples/src/conversation/templates-v2/get.ts +++ b/examples/simple-examples/src/conversation/templates-v2/get.ts @@ -1,5 +1,5 @@ import { V2GetTemplateRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -12,8 +12,8 @@ import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse template_id: templateId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV2.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV2.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v2/list-translations.ts b/examples/simple-examples/src/conversation/templates-v2/list-translations.ts index 7153cdf4..ba0839ac 100644 --- a/examples/simple-examples/src/conversation/templates-v2/list-translations.ts +++ b/examples/simple-examples/src/conversation/templates-v2/list-translations.ts @@ -1,5 +1,5 @@ import { templateV2Helper, V2ListTranslationsRequestData, V2TemplateTranslation } from '@sinch/sdk-core'; -import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*********************************'); @@ -8,9 +8,9 @@ import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse const templateId = getTemplateIdFromConfig(); - const sinchClient = initClient(); + const conversationService = initConversationService(); - const templateV2Response = await sinchClient.conversation.templatesV2.get({ + const templateV2Response = await conversationService.templatesV2.get({ template_id: templateId, }); @@ -28,7 +28,7 @@ import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse translation_version: 'latest', // translation.version, }; - const response = await sinchClient.conversation.templatesV2.listTranslations(requestData); + const response = await conversationService.templatesV2.listTranslations(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v2/list.ts b/examples/simple-examples/src/conversation/templates-v2/list.ts index 3ae6dfeb..836ad2d5 100644 --- a/examples/simple-examples/src/conversation/templates-v2/list.ts +++ b/examples/simple-examples/src/conversation/templates-v2/list.ts @@ -1,5 +1,5 @@ import { V2ListTemplatesRequestData, V2TemplateResponse } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('******************************'); @@ -10,8 +10,8 @@ import { getPrintFormat, initClient, printFullResponse } from '../../config'; const requestData: V2ListTemplatesRequestData = { }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.templatesV2.list(requestData); + const conversationService = initConversationService(); + const response = await conversationService.templatesV2.list(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/templates-v2/update.ts b/examples/simple-examples/src/conversation/templates-v2/update.ts index a459a6a9..367c8c8d 100644 --- a/examples/simple-examples/src/conversation/templates-v2/update.ts +++ b/examples/simple-examples/src/conversation/templates-v2/update.ts @@ -1,5 +1,5 @@ import { templateV2Helper, V2TemplateTranslation, V2UpdateTemplateRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*******************************'); @@ -8,8 +8,8 @@ import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse const templateId = getTemplateIdFromConfig(); - const sinchClient = initClient(); - const templateV2Response = await sinchClient.conversation.templatesV2.get({ + const conversationService = initConversationService(); + const templateV2Response = await conversationService.templatesV2.get({ template_id: templateId, }); @@ -39,7 +39,7 @@ import { getPrintFormat, getTemplateIdFromConfig, initClient, printFullResponse }, }; - const response = await sinchClient.conversation.templatesV2.update(requestData); + const response = await conversationService.templatesV2.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/transcoding/transcode.ts b/examples/simple-examples/src/conversation/transcoding/transcode.ts index a51cdcdd..2a4a3eb5 100644 --- a/examples/simple-examples/src/conversation/transcoding/transcode.ts +++ b/examples/simple-examples/src/conversation/transcoding/transcode.ts @@ -1,5 +1,5 @@ -import { ConversationChannel, TranscodeMessageRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { TranscodeMessageRequestData } from '@sinch/sdk-core'; +import { getAppIdFromConfig, getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('********************************'); @@ -29,8 +29,8 @@ import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } fro }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.transcoding.transcodeMessage(requestData); + const conversationService = initConversationService(); + const response = await conversationService.transcoding.transcodeMessage(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/webhooks/create.ts b/examples/simple-examples/src/conversation/webhooks/create.ts index b5789d10..07bde2b5 100644 --- a/examples/simple-examples/src/conversation/webhooks/create.ts +++ b/examples/simple-examples/src/conversation/webhooks/create.ts @@ -2,7 +2,7 @@ import { CreateWebhookRequestData } from '@sinch/sdk-core'; import { getAppIdFromConfig, getPrintFormat, getWebhookTargetFromConfig, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -32,8 +32,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.webhooks.create(requestData); + const conversationService = initConversationService(); + const response = await conversationService.webhooks.create(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/webhooks/delete.ts b/examples/simple-examples/src/conversation/webhooks/delete.ts index 66b692cf..3a4ec830 100644 --- a/examples/simple-examples/src/conversation/webhooks/delete.ts +++ b/examples/simple-examples/src/conversation/webhooks/delete.ts @@ -1,5 +1,5 @@ import { DeleteWebhookRequestData } from '@sinch/sdk-core'; -import { getWebhookIdFromConfig, initClient, printFullResponse } from '../../config'; +import { getWebhookIdFromConfig, initConversationService, printFullResponse } from '../../config'; (async () => { @@ -13,8 +13,8 @@ import { getWebhookIdFromConfig, initClient, printFullResponse } from '../../con webhook_id: webhookId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.webhooks.delete(requestData); + const conversationService = initConversationService(); + const response = await conversationService.webhooks.delete(requestData); printFullResponse(response); diff --git a/examples/simple-examples/src/conversation/webhooks/get.ts b/examples/simple-examples/src/conversation/webhooks/get.ts index 2ce54894..3f34bd49 100644 --- a/examples/simple-examples/src/conversation/webhooks/get.ts +++ b/examples/simple-examples/src/conversation/webhooks/get.ts @@ -2,7 +2,7 @@ import { GetWebhookRequestData } from '@sinch/sdk-core'; import { getPrintFormat, getWebhookIdFromConfig, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -17,8 +17,8 @@ import { webhook_id: webhookId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.webhooks.get(requestData); + const conversationService = initConversationService(); + const response = await conversationService.webhooks.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/webhooks/list.ts b/examples/simple-examples/src/conversation/webhooks/list.ts index 3df1d1ae..f64d2bed 100644 --- a/examples/simple-examples/src/conversation/webhooks/list.ts +++ b/examples/simple-examples/src/conversation/webhooks/list.ts @@ -1,5 +1,5 @@ import { ListWebhooksRequestData } from '@sinch/sdk-core'; -import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getAppIdFromConfig, getPrintFormat, initConversationService, printFullResponse } from '../../config'; (async () => { console.log('*************************'); @@ -12,8 +12,8 @@ import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } fro app_id: appId, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.webhooks.list(requestData); + const conversationService = initConversationService(); + const response = await conversationService.webhooks.list(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/conversation/webhooks/update.ts b/examples/simple-examples/src/conversation/webhooks/update.ts index be113477..76b5ca49 100644 --- a/examples/simple-examples/src/conversation/webhooks/update.ts +++ b/examples/simple-examples/src/conversation/webhooks/update.ts @@ -2,7 +2,7 @@ import { UpdateWebhookRequestData } from '@sinch/sdk-core'; import { getAppIdFromConfig, getPrintFormat, getWebhookIdFromConfig, - initClient, + initConversationService, printFullResponse, } from '../../config'; @@ -30,8 +30,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.conversation.webhooks.update(requestData); + const conversationService = initConversationService(); + const response = await conversationService.webhooks.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/fax/emails/add.ts b/examples/simple-examples/src/fax/emails/add.ts index 0b738e6c..d08c97b0 100644 --- a/examples/simple-examples/src/fax/emails/add.ts +++ b/examples/simple-examples/src/fax/emails/add.ts @@ -3,7 +3,7 @@ import { getFaxEmailFromConfig, getPhoneNumberFromConfig, getPrintFormat, - initClient, + initFaxService, printFullResponse, } from '../../config'; @@ -24,8 +24,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.fax.emails.addToNumbers(requestData); + const faxService = initFaxService(); + const response = await faxService.emails.addToNumbers(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/fax/emails/delete.ts b/examples/simple-examples/src/fax/emails/delete.ts index 157b955b..f445facb 100644 --- a/examples/simple-examples/src/fax/emails/delete.ts +++ b/examples/simple-examples/src/fax/emails/delete.ts @@ -1,5 +1,5 @@ import { DeleteEmailRequestData } from '@sinch/sdk-core'; -import { getFaxEmailFromConfig, initClient } from '../../config'; +import { getFaxEmailFromConfig, initFaxService } from '../../config'; (async () => { console.log('***************'); @@ -12,8 +12,8 @@ import { getFaxEmailFromConfig, initClient } from '../../config'; email, }; - const sinchClient = initClient(); - await sinchClient.fax.emails.delete(requestData); + const faxService = initFaxService(); + await faxService.emails.delete(requestData); console.log(`The email '${requestData.email}' has been successfully removed`); })(); diff --git a/examples/simple-examples/src/fax/emails/list.ts b/examples/simple-examples/src/fax/emails/list.ts index 6f599f73..86f971e4 100644 --- a/examples/simple-examples/src/fax/emails/list.ts +++ b/examples/simple-examples/src/fax/emails/list.ts @@ -1,5 +1,5 @@ import { Email, ListEmailsForProjectRequestData, PageResult } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initFaxService, printFullResponse } from '../../config'; const populateEmailsList = ( emailsPage: PageResult, @@ -21,12 +21,12 @@ const populateEmailsList = ( pageSize: 2, }; - const sinchClient = initClient(); + const faxService = initFaxService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.fax.emails.list(requestData); + let response = await faxService.emails.list(requestData); // Init data structure to hold the response content const fullEmailsList: Email[] = []; @@ -57,7 +57,7 @@ const populateEmailsList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const email of sinchClient.fax.emails.list(requestData)) { + for await (const email of faxService.emails.list(requestData)) { if (printFormat === 'pretty') { console.log(`Email '${email.email}' - Phone numbers: '${email.phoneNumbers?.join(', ')}'`); } else { diff --git a/examples/simple-examples/src/fax/emails/listNumbers.ts b/examples/simple-examples/src/fax/emails/listNumbers.ts index 5bd77638..18e7303f 100644 --- a/examples/simple-examples/src/fax/emails/listNumbers.ts +++ b/examples/simple-examples/src/fax/emails/listNumbers.ts @@ -3,7 +3,7 @@ import { PageResult, ServicePhoneNumber, } from '@sinch/sdk-core'; -import { getFaxEmailFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getFaxEmailFromConfig, getPrintFormat, initFaxService, printFullResponse } from '../../config'; const populateServiceNumbersList = ( serviceNumbersPage: PageResult, @@ -28,12 +28,12 @@ const populateServiceNumbersList = ( pageSize: 2, }; - const sinchClient = initClient(); + const faxService = initFaxService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.fax.emails.listNumbers(requestData); + let response = await faxService.emails.listNumbers(requestData); // Init data structure to hold the response content const fullServiceNumbersList: ServicePhoneNumber[] = []; @@ -64,7 +64,7 @@ const populateServiceNumbersList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const number of sinchClient.fax.emails.listNumbers(requestData)) { + for await (const number of faxService.emails.listNumbers(requestData)) { if (printFormat === 'pretty') { console.log(`Phone numbers: '${number.phoneNumber}'`); } else { diff --git a/examples/simple-examples/src/fax/emails/update.ts b/examples/simple-examples/src/fax/emails/update.ts index 2d3c7520..1df0b669 100644 --- a/examples/simple-examples/src/fax/emails/update.ts +++ b/examples/simple-examples/src/fax/emails/update.ts @@ -3,7 +3,7 @@ import { getFaxEmailFromConfig, getPhoneNumberFromConfig, getPrintFormat, - initClient, + initFaxService, printFullResponse, } from '../../config'; @@ -25,8 +25,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.fax.emails.update(requestData); + const faxService = initFaxService(); + const response = await faxService.emails.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/fax/faxes/deleteContent.ts b/examples/simple-examples/src/fax/faxes/deleteContent.ts index 875c7668..2257f967 100644 --- a/examples/simple-examples/src/fax/faxes/deleteContent.ts +++ b/examples/simple-examples/src/fax/faxes/deleteContent.ts @@ -1,5 +1,5 @@ import { DeleteFaxContentRequestData } from '@sinch/sdk-core'; -import { getFaxIdFromConfig, initClient } from '../../config'; +import { getFaxIdFromConfig, initFaxService } from '../../config'; (async () => { console.log('************************'); @@ -12,8 +12,8 @@ import { getFaxIdFromConfig, initClient } from '../../config'; id: faxId, }; - const sinchClient = initClient(); - await sinchClient.fax.faxes.deleteContent(requestData); + const faxService = initFaxService(); + await faxService.faxes.deleteContent(requestData); console.log(`The content of the fax with the id '${requestData.id}' has been successfully removed from storage`); })(); diff --git a/examples/simple-examples/src/fax/faxes/downloadContent.ts b/examples/simple-examples/src/fax/faxes/downloadContent.ts index b54610eb..ec5e0c49 100644 --- a/examples/simple-examples/src/fax/faxes/downloadContent.ts +++ b/examples/simple-examples/src/fax/faxes/downloadContent.ts @@ -1,5 +1,5 @@ import { DownloadFaxContentRequestData } from '@sinch/sdk-core'; -import { getFaxIdFromConfig, initClient } from '../../config'; +import { getFaxIdFromConfig, initFaxService } from '../../config'; import * as fs from 'fs'; import * as path from 'path'; @@ -15,8 +15,8 @@ import * as path from 'path'; fileFormat: 'pdf', }; - const sinchClient = initClient(); - const response = await sinchClient.fax.faxes.downloadContent(requestData); + const faxService = initFaxService(); + const response = await faxService.faxes.downloadContent(requestData); const filePath = path.join('./fax-pdf', response.fileName); fs.writeFileSync(filePath, response.buffer); diff --git a/examples/simple-examples/src/fax/faxes/get.ts b/examples/simple-examples/src/fax/faxes/get.ts index 303b867e..f0b6b48e 100644 --- a/examples/simple-examples/src/fax/faxes/get.ts +++ b/examples/simple-examples/src/fax/faxes/get.ts @@ -1,5 +1,5 @@ import { GetFaxRequestData } from '@sinch/sdk-core'; -import { getFaxIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getFaxIdFromConfig, getPrintFormat, initFaxService, printFullResponse } from '../../config'; (async () => { console.log('*******************'); @@ -12,8 +12,8 @@ import { getFaxIdFromConfig, getPrintFormat, initClient, printFullResponse } fro id: faxId, }; - const sinchClient = initClient(); - const response = await sinchClient.fax.faxes.get(requestData); + const faxService = initFaxService(); + const response = await faxService.faxes.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/fax/faxes/list.ts b/examples/simple-examples/src/fax/faxes/list.ts index 949cb946..00c9251a 100644 --- a/examples/simple-examples/src/fax/faxes/list.ts +++ b/examples/simple-examples/src/fax/faxes/list.ts @@ -1,5 +1,5 @@ import { Fax, ListFaxesRequestData, PageResult } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initFaxService, printFullResponse } from '../../config'; const populateFaxesList = ( faxPage: PageResult, @@ -21,12 +21,12 @@ const populateFaxesList = ( pageSize: 2, }; - const sinchClient = initClient(); + const faxService = initFaxService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.fax.faxes.list(requestData); + let response = await faxService.faxes.list(requestData); // Init data structure to hold the response content const fullFaxesList: Fax[] = []; @@ -57,7 +57,7 @@ const populateFaxesList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const fax of sinchClient.fax.faxes.list(requestData)) { + for await (const fax of faxService.faxes.list(requestData)) { if (printFormat === 'pretty') { console.log(`Fax ID: '${fax.id}' - Created at: '${fax.createTime}' - Status: '${fax.status}'`); } else { diff --git a/examples/simple-examples/src/fax/faxes/send.ts b/examples/simple-examples/src/fax/faxes/send.ts index 93da7602..e8212df7 100644 --- a/examples/simple-examples/src/fax/faxes/send.ts +++ b/examples/simple-examples/src/fax/faxes/send.ts @@ -3,7 +3,7 @@ import { getFaxCallbackUrlFromConfig, getPhoneNumberFromConfig, getPrintFormat, - initClient, + initFaxService, printFullResponse, } from '../../config'; @@ -26,8 +26,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.fax.faxes.send(requestData); + const faxService = initFaxService(); + const response = await faxService.faxes.send(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/fax/services/create.ts b/examples/simple-examples/src/fax/services/create.ts index 2c88a9b4..feda7eb4 100644 --- a/examples/simple-examples/src/fax/services/create.ts +++ b/examples/simple-examples/src/fax/services/create.ts @@ -1,5 +1,5 @@ import { CreateServiceRequestData } from '@sinch/sdk-core'; -import { getPhoneNumberFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPhoneNumberFromConfig, getPrintFormat, initFaxService, printFullResponse } from '../../config'; (async () => { console.log('*****************'); @@ -23,8 +23,8 @@ import { getPhoneNumberFromConfig, getPrintFormat, initClient, printFullResponse }, }; - const sinchClient = initClient(); - const response = await sinchClient.fax.services.create(requestData); + const faxService = initFaxService(); + const response = await faxService.services.create(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/fax/services/delete.ts b/examples/simple-examples/src/fax/services/delete.ts index 40f0c83e..9f552344 100644 --- a/examples/simple-examples/src/fax/services/delete.ts +++ b/examples/simple-examples/src/fax/services/delete.ts @@ -1,5 +1,5 @@ import { DeleteServiceRequestData } from '@sinch/sdk-core'; -import { getFaxServiceIdFromConfig, initClient } from '../../config'; +import { getFaxServiceIdFromConfig, initFaxService } from '../../config'; (async () => { console.log('*****************'); @@ -12,8 +12,8 @@ import { getFaxServiceIdFromConfig, initClient } from '../../config'; serviceId, }; - const sinchClient = initClient(); - await sinchClient.fax.services.delete(requestData); + const faxService = initFaxService(); + await faxService.services.delete(requestData); console.log(`The service with the id '${requestData.serviceId}' has been successfully removed`); })(); diff --git a/examples/simple-examples/src/fax/services/get.ts b/examples/simple-examples/src/fax/services/get.ts index 38c78979..f2323182 100644 --- a/examples/simple-examples/src/fax/services/get.ts +++ b/examples/simple-examples/src/fax/services/get.ts @@ -1,5 +1,5 @@ import { GetServiceRequestData } from '@sinch/sdk-core'; -import { getFaxServiceIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getFaxServiceIdFromConfig, getPrintFormat, initFaxService, printFullResponse } from '../../config'; (async () => { console.log('**************'); @@ -12,8 +12,8 @@ import { getFaxServiceIdFromConfig, getPrintFormat, initClient, printFullRespons serviceId, }; - const sinchClient = initClient(); - const response = await sinchClient.fax.services.get(requestData); + const faxService = initFaxService(); + const response = await faxService.services.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/fax/services/list.ts b/examples/simple-examples/src/fax/services/list.ts index baff2dc4..09d8ca89 100644 --- a/examples/simple-examples/src/fax/services/list.ts +++ b/examples/simple-examples/src/fax/services/list.ts @@ -1,5 +1,5 @@ import { ListServicesRequestData, PageResult, ServiceResponse } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initFaxService, printFullResponse } from '../../config'; const populateServicesList = ( servicesPage: PageResult, @@ -21,12 +21,12 @@ const populateServicesList = ( pageSize: 2, }; - const sinchClient = initClient(); + const faxService = initFaxService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.fax.services.list(requestData); + let response = await faxService.services.list(requestData); // Init data structure to hold the response content const fullServicesList: ServiceResponse[] = []; @@ -57,7 +57,7 @@ const populateServicesList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const service of sinchClient.fax.services.list(requestData)) { + for await (const service of faxService.services.list(requestData)) { if (printFormat === 'pretty') { console.log(`Service ID: '${service.id} - Service name: '${service.name}'`); } else { diff --git a/examples/simple-examples/src/fax/services/listEmailsForNumber.ts b/examples/simple-examples/src/fax/services/listEmailsForNumber.ts index cbc02c5e..8176cc25 100644 --- a/examples/simple-examples/src/fax/services/listEmailsForNumber.ts +++ b/examples/simple-examples/src/fax/services/listEmailsForNumber.ts @@ -3,7 +3,7 @@ import { getFaxServiceIdFromConfig, getPhoneNumberFromConfig, getPrintFormat, - initClient, + initFaxService, printFullResponse, } from '../../config'; @@ -21,12 +21,12 @@ import { pageSize: 2, }; - const sinchClient = initClient(); + const faxService = initFaxService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.fax.services.listEmailsForNumber(requestData); + let response = await faxService.services.listEmailsForNumber(requestData); // Init data structure to hold the response content const emailsList: string[] = []; @@ -55,7 +55,7 @@ import { // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const email of sinchClient.fax.services.listEmailsForNumber(requestData)) { + for await (const email of faxService.services.listEmailsForNumber(requestData)) { if (printFormat === 'pretty') { console.log(`Email: '${email}'`); } else { diff --git a/examples/simple-examples/src/fax/services/listNumbers.ts b/examples/simple-examples/src/fax/services/listNumbers.ts index 08d1c4a3..8c6ce68d 100644 --- a/examples/simple-examples/src/fax/services/listNumbers.ts +++ b/examples/simple-examples/src/fax/services/listNumbers.ts @@ -1,5 +1,5 @@ import { ListNumbersForServiceRequestData, PageResult, ServicePhoneNumber } from '@sinch/sdk-core'; -import { getFaxServiceIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getFaxServiceIdFromConfig, getPrintFormat, initFaxService, printFullResponse } from '../../config'; const populateNumbersList = ( numbersPage: PageResult, @@ -24,12 +24,12 @@ const populateNumbersList = ( pageSize: 2, }; - const sinchClient = initClient(); + const faxService = initFaxService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.fax.services.listNumbers(requestData); + let response = await faxService.services.listNumbers(requestData); // Init data structure to hold the response content const fullNumbersList: ServicePhoneNumber[] = []; @@ -60,7 +60,7 @@ const populateNumbersList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const servicePhoneNumber of sinchClient.fax.services.listNumbers(requestData)) { + for await (const servicePhoneNumber of faxService.services.listNumbers(requestData)) { if (printFormat === 'pretty') { console.log(`Phone number: '${servicePhoneNumber.phoneNumber} - Service ID: '${servicePhoneNumber.serviceId}'`); } else { diff --git a/examples/simple-examples/src/fax/services/update.ts b/examples/simple-examples/src/fax/services/update.ts index e1a61106..6d796f92 100644 --- a/examples/simple-examples/src/fax/services/update.ts +++ b/examples/simple-examples/src/fax/services/update.ts @@ -3,7 +3,7 @@ import { getFaxCallbackUrlFromConfig, getFaxServiceIdFromConfig, getPrintFormat, - initClient, + initFaxService, printFullResponse, } from '../../config'; @@ -32,8 +32,8 @@ import { }, }; - const sinchClient = initClient(); - const response = await sinchClient.fax.services.update(requestData); + const faxService = initFaxService(); + const response = await faxService.services.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/active/get.ts b/examples/simple-examples/src/numbers/active/get.ts index 131aa814..da1b54ad 100644 --- a/examples/simple-examples/src/numbers/active/get.ts +++ b/examples/simple-examples/src/numbers/active/get.ts @@ -1,4 +1,9 @@ -import { getPhoneNumberFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { + getPhoneNumberFromConfig, + getPrintFormat, + initNumbersService, + printFullResponse, +} from '../../config'; import { GetActiveNumberRequestData } from '@sinch/sdk-core'; (async () => { @@ -12,10 +17,10 @@ import { GetActiveNumberRequestData } from '@sinch/sdk-core'; phoneNumber, }; - const sinchClient = initClient(); + const numbersService = initNumbersService(); let response; try { - response = await sinchClient.numbers.activeNumber.get(requestData); + response = await numbersService.activeNumber.get(requestData); } catch (error) { console.error(`ERROR: The phone number ${requestData.phoneNumber} is not active`); throw error; diff --git a/examples/simple-examples/src/numbers/active/list.ts b/examples/simple-examples/src/numbers/active/list.ts index 9c4d54a8..35501dee 100644 --- a/examples/simple-examples/src/numbers/active/list.ts +++ b/examples/simple-examples/src/numbers/active/list.ts @@ -1,4 +1,4 @@ -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initNumbersService, printFullResponse } from '../../config'; import { ActiveNumber, ListActiveNumbersRequestData, PageResult } from '@sinch/sdk-core'; const populateActiveNumbersList = ( @@ -25,12 +25,12 @@ const populateActiveNumbersList = ( pageSize: 2, }; - const sinchClient = initClient(); + const numbersService = initNumbersService(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.numbers.activeNumber.list(requestData); + let response = await numbersService.activeNumber.list(requestData); const activeNumbersList: ActiveNumber[] = []; const phoneNumbersList: (string | undefined)[] = []; @@ -59,7 +59,7 @@ const populateActiveNumbersList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const activeNumber of sinchClient.numbers.activeNumber.list(requestData)) { + for await (const activeNumber of numbersService.activeNumber.list(requestData)) { if (printFormat === 'pretty') { console.log(activeNumber.phoneNumber); } else { diff --git a/examples/simple-examples/src/numbers/active/release.ts b/examples/simple-examples/src/numbers/active/release.ts index 4ca17422..ed71c25d 100644 --- a/examples/simple-examples/src/numbers/active/release.ts +++ b/examples/simple-examples/src/numbers/active/release.ts @@ -1,4 +1,9 @@ -import { getPhoneNumberFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { + getPhoneNumberFromConfig, + getPrintFormat, + initNumbersService, + printFullResponse, +} from '../../config'; import { ReleaseNumberRequestData } from '@sinch/sdk-core'; (async () => { @@ -12,8 +17,8 @@ import { ReleaseNumberRequestData } from '@sinch/sdk-core'; phoneNumber, }; - const sinchClient = initClient(); - const response = await sinchClient.numbers.activeNumber.release(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.activeNumber.release(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/active/update.ts b/examples/simple-examples/src/numbers/active/update.ts index 44f340f0..3360d456 100644 --- a/examples/simple-examples/src/numbers/active/update.ts +++ b/examples/simple-examples/src/numbers/active/update.ts @@ -3,7 +3,7 @@ import { getPhoneNumberFromConfig, getPrintFormat, getServicePlanIdFromConfig, - initClient, + initNumbersService, printFullResponse, } from '../../config'; import { UpdateActiveNumberRequestData } from '@sinch/sdk-core'; @@ -28,8 +28,8 @@ import { UpdateActiveNumberRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initClient(); - const response = await sinchClient.numbers.activeNumber.update(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.activeNumber.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/available/checkAvailability.ts b/examples/simple-examples/src/numbers/available/checkAvailability.ts index 6ab0f0bc..57581c58 100644 --- a/examples/simple-examples/src/numbers/available/checkAvailability.ts +++ b/examples/simple-examples/src/numbers/available/checkAvailability.ts @@ -1,4 +1,9 @@ -import { getPhoneNumberFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { + getPhoneNumberFromConfig, + getPrintFormat, + initNumbersService, + printFullResponse, +} from '../../config'; import { GetAvailableNumberRequestData } from '@sinch/sdk-core'; (async () => { @@ -13,10 +18,10 @@ import { GetAvailableNumberRequestData } from '@sinch/sdk-core'; phoneNumber, }; - const sinchClient = initClient(); + const numbersService = initNumbersService(); let response; try { - response = await sinchClient.numbers.availableNumber.checkAvailability(requestData); + response = await numbersService.availableNumber.checkAvailability(requestData); } catch (error) { console.error(`ERROR: the phone number ${requestData.phoneNumber} is not available`); } diff --git a/examples/simple-examples/src/numbers/available/list.ts b/examples/simple-examples/src/numbers/available/list.ts index f42adbb8..c5b5ffb2 100644 --- a/examples/simple-examples/src/numbers/available/list.ts +++ b/examples/simple-examples/src/numbers/available/list.ts @@ -1,4 +1,4 @@ -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initNumbersService, printFullResponse } from '../../config'; import { ListAvailableNumbersRequestData } from '@sinch/sdk-core'; (async () => { @@ -12,8 +12,8 @@ import { ListAvailableNumbersRequestData } from '@sinch/sdk-core'; capabilities: ['SMS', 'VOICE'], }; - const sinchClient = initClient(); - const response = await sinchClient.numbers.availableNumber.list(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.availableNumber.list(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/available/rent.ts b/examples/simple-examples/src/numbers/available/rent.ts index 3b70c5fc..2e23cde6 100644 --- a/examples/simple-examples/src/numbers/available/rent.ts +++ b/examples/simple-examples/src/numbers/available/rent.ts @@ -3,8 +3,9 @@ import { getPhoneNumberFromConfig, getPrintFormat, readServicePlanId, - initClient, - printFullResponse, getNumberCallbackUrlFromConfig, + printFullResponse, + getNumberCallbackUrlFromConfig, + initNumbersService, } from '../../config'; import { RentNumberRequest, @@ -39,8 +40,8 @@ import { rentNumberRequestBody: rentNumberRequest, }; - const sinchClient = initClient(); - const response = await sinchClient.numbers.availableNumber.rent(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.availableNumber.rent(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/available/rentAny.ts b/examples/simple-examples/src/numbers/available/rentAny.ts index 21c27f8a..c2f085de 100644 --- a/examples/simple-examples/src/numbers/available/rentAny.ts +++ b/examples/simple-examples/src/numbers/available/rentAny.ts @@ -1,7 +1,7 @@ import { getNumberCallbackUrlFromConfig, getPrintFormat, - initClient, + initNumbersService, printFullResponse, readApplicationKey, readServicePlanId, @@ -47,8 +47,8 @@ import { rentAnyNumberRequestBody: rentAnyNumberRequest, }; - const sinchClient = initClient(); - const response = await sinchClient.numbers.availableNumber.rentAny(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.availableNumber.rentAny(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/callbacks/get.ts b/examples/simple-examples/src/numbers/callbacks/get.ts index 714d4cad..7ff55540 100644 --- a/examples/simple-examples/src/numbers/callbacks/get.ts +++ b/examples/simple-examples/src/numbers/callbacks/get.ts @@ -1,5 +1,5 @@ import { GetCallbackConfigurationRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initNumbersService, printFullResponse } from '../../config'; (async () => { console.log('****************************'); @@ -8,8 +8,8 @@ import { getPrintFormat, initClient, printFullResponse } from '../../config'; const requestData: GetCallbackConfigurationRequestData = {}; - const sinchClient = initClient(); - const response = await sinchClient.numbers.callbacks.get(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.callbacks.get(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/callbacks/update.ts b/examples/simple-examples/src/numbers/callbacks/update.ts index 09568897..b8b63c7b 100644 --- a/examples/simple-examples/src/numbers/callbacks/update.ts +++ b/examples/simple-examples/src/numbers/callbacks/update.ts @@ -1,5 +1,10 @@ import { UpdateCallbackConfigurationRequestData } from '@sinch/sdk-core'; -import { getHmacSecretFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; +import { + getHmacSecretFromConfig, + getPrintFormat, + initNumbersService, + printFullResponse, +} from '../../config'; import * as process from 'process'; (async () => { @@ -15,8 +20,8 @@ import * as process from 'process'; }, }; - const sinchClient = initClient(); - const response = await sinchClient.numbers.callbacks.update(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.callbacks.update(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/numbers/regions/list.ts b/examples/simple-examples/src/numbers/regions/list.ts index d1c4bc79..506ce29b 100644 --- a/examples/simple-examples/src/numbers/regions/list.ts +++ b/examples/simple-examples/src/numbers/regions/list.ts @@ -1,5 +1,5 @@ import { ListAvailableRegionsRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, initClient, printFullResponse } from '../../config'; +import { getPrintFormat, initNumbersService, printFullResponse } from '../../config'; (async () => { console.log('**************************************'); @@ -10,8 +10,8 @@ import { getPrintFormat, initClient, printFullResponse } from '../../config'; types: ['LOCAL','MOBILE'], }; - const sinchClient = initClient(); - const response = await sinchClient.numbers.availableRegions.list(requestData); + const numbersService = initNumbersService(); + const response = await numbersService.availableRegions.list(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/sms/batches/cancel.ts b/examples/simple-examples/src/sms/batches/cancel.ts index ae622747..d8a032ea 100644 --- a/examples/simple-examples/src/sms/batches/cancel.ts +++ b/examples/simple-examples/src/sms/batches/cancel.ts @@ -1,4 +1,9 @@ -import { getBatchIdFromConfig, getPrintFormat, initSmsClient, printFullResponse } from '../../config'; +import { + getBatchIdFromConfig, + getPrintFormat, + initSmsServiceWithServicePlanId, + printFullResponse, +} from '../../config'; import { CancelBatchMessageRequestData } from '@sinch/sdk-core'; (async () => { @@ -12,10 +17,10 @@ import { CancelBatchMessageRequestData } from '@sinch/sdk-core'; batch_id: batchIdInTheFuture, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.batches.cancel(requestData); + response = await smsService.batches.cancel(requestData); } catch (error) { console.error(`ERROR: The batch could not be canceled`); throw error; diff --git a/examples/simple-examples/src/sms/batches/delivery-feedback.ts b/examples/simple-examples/src/sms/batches/delivery-feedback.ts index 46d33353..77f62f67 100644 --- a/examples/simple-examples/src/sms/batches/delivery-feedback.ts +++ b/examples/simple-examples/src/sms/batches/delivery-feedback.ts @@ -1,4 +1,8 @@ -import { getBatchIdFromConfig, getRecipientPhoneNumberFromConfig, initSmsClient } from '../../config'; +import { + getBatchIdFromConfig, + getRecipientPhoneNumberFromConfig, + initSmsServiceWithServicePlanId, +} from '../../config'; import { DeliveryFeedbackRequestData } from '@sinch/sdk-core'; (async () => { @@ -18,10 +22,10 @@ import { DeliveryFeedbackRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); try { - await sinchClient.sms.batches.sendDeliveryFeedback(requestData); + await smsService.batches.sendDeliveryFeedback(requestData); } catch (error) { console.error(`ERROR: The delivery feedback could not be sent.`); throw error; diff --git a/examples/simple-examples/src/sms/batches/dry-run.ts b/examples/simple-examples/src/sms/batches/dry-run.ts index 9c9eda08..25cae327 100644 --- a/examples/simple-examples/src/sms/batches/dry-run.ts +++ b/examples/simple-examples/src/sms/batches/dry-run.ts @@ -2,7 +2,7 @@ import { getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; import { DryRunRequestData } from '@sinch/sdk-core'; @@ -33,10 +33,10 @@ import { DryRunRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.batches.dryRun(requestData); + response = await smsService.batches.dryRun(requestData); } catch (error) { console.error(`ERROR: The dry run couldn't be performed`); throw error; diff --git a/examples/simple-examples/src/sms/batches/get.ts b/examples/simple-examples/src/sms/batches/get.ts index a78db523..552a10d1 100644 --- a/examples/simple-examples/src/sms/batches/get.ts +++ b/examples/simple-examples/src/sms/batches/get.ts @@ -1,4 +1,9 @@ -import { getPrintFormat, getBatchIdFromConfig, initSmsClient, printFullResponse } from '../../config'; +import { + getPrintFormat, + getBatchIdFromConfig, + printFullResponse, + initSmsServiceWithServicePlanId, +} from '../../config'; import { GetBatchMessageRequestData } from '@sinch/sdk-core'; (async () => { @@ -12,10 +17,10 @@ import { GetBatchMessageRequestData } from '@sinch/sdk-core'; batch_id: batchId, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.batches.get(requestData); + response = await smsService.batches.get(requestData); } catch (error) { console.error(`ERROR: Impossible to retrieve the batch ${requestData.batch_id}`); throw error; diff --git a/examples/simple-examples/src/sms/batches/list.ts b/examples/simple-examples/src/sms/batches/list.ts index 5f70de6b..c2214711 100644 --- a/examples/simple-examples/src/sms/batches/list.ts +++ b/examples/simple-examples/src/sms/batches/list.ts @@ -1,4 +1,4 @@ -import { getPrintFormat, initSmsClient, printFullResponse } from '../../config'; +import { getPrintFormat, initSmsServiceWithServicePlanId, printFullResponse } from '../../config'; import { ListBatchesRequestData, PageResult } from '@sinch/sdk-core'; import { SendSMSResponse } from '@sinch/sms/src'; @@ -27,12 +27,12 @@ const populateBatchesList = ( page_size: 2, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- - let response = await sinchClient.sms.batches.list(requestData); + let response = await smsService.batches.list(requestData); const fullBatchesList: SendSMSResponse[] = []; const batchesList: string[] = []; @@ -61,7 +61,7 @@ const populateBatchesList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const batch of sinchClient.sms.batches.list(requestData)) { + for await (const batch of smsService.batches.list(requestData)) { if (printFormat === 'pretty') { console.log(`Batch ID: ${batch.id} - Type: ${batch.type} - From: ${batch.from}`); } else { diff --git a/examples/simple-examples/src/sms/batches/replace.ts b/examples/simple-examples/src/sms/batches/replace.ts index 679a4ab0..41aec5a2 100644 --- a/examples/simple-examples/src/sms/batches/replace.ts +++ b/examples/simple-examples/src/sms/batches/replace.ts @@ -2,7 +2,7 @@ import { getBatchIdFromConfig, getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; import { BinaryRequest, ReplaceBatchMessageRequestData, textToHex } from '@sinch/sdk-core'; @@ -31,10 +31,10 @@ import { BinaryRequest, ReplaceBatchMessageRequestData, textToHex } from '@sinch } as BinaryRequest, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.batches.replace(requestData); + response = await smsService.batches.replace(requestData); } catch (error) { console.error(`ERROR: The batch could not be updated`); throw error; diff --git a/examples/simple-examples/src/sms/batches/send.ts b/examples/simple-examples/src/sms/batches/send.ts index 464d2e77..49f02dd0 100644 --- a/examples/simple-examples/src/sms/batches/send.ts +++ b/examples/simple-examples/src/sms/batches/send.ts @@ -2,7 +2,7 @@ import { getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; import { SendSMSRequestData } from '@sinch/sdk-core'; @@ -37,10 +37,10 @@ import { SendSMSRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.batches.send(requestData); + response = await smsService.batches.send(requestData); } catch (error) { console.error(`ERROR: The SMS could not be sent`); throw error; diff --git a/examples/simple-examples/src/sms/batches/sendBinaryMessage.ts b/examples/simple-examples/src/sms/batches/sendBinaryMessage.ts index d0b3f5b5..9b9e1823 100644 --- a/examples/simple-examples/src/sms/batches/sendBinaryMessage.ts +++ b/examples/simple-examples/src/sms/batches/sendBinaryMessage.ts @@ -3,7 +3,7 @@ import { getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; @@ -28,8 +28,8 @@ import { }, }; - const sinchClient = initSmsClient(); - const response = await sinchClient.sms.batches.sendBinaryMessage(requestData); + const smsService = initSmsServiceWithServicePlanId(); + const response = await smsService.batches.sendBinaryMessage(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/sms/batches/sendMediaMessage.ts b/examples/simple-examples/src/sms/batches/sendMediaMessage.ts index 5ec6cca8..5187a046 100644 --- a/examples/simple-examples/src/sms/batches/sendMediaMessage.ts +++ b/examples/simple-examples/src/sms/batches/sendMediaMessage.ts @@ -3,7 +3,7 @@ import { getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; @@ -37,8 +37,8 @@ import { }, }; - const sinchClient = initSmsClient(); - const response = await sinchClient.sms.batches.sendMediaMessage(requestData); + const smsService = initSmsServiceWithServicePlanId(); + const response = await smsService.batches.sendMediaMessage(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/sms/batches/sendTextMessage.ts b/examples/simple-examples/src/sms/batches/sendTextMessage.ts index f7ebbd18..efb97f8e 100644 --- a/examples/simple-examples/src/sms/batches/sendTextMessage.ts +++ b/examples/simple-examples/src/sms/batches/sendTextMessage.ts @@ -3,7 +3,7 @@ import { getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; @@ -33,8 +33,8 @@ import { }, }; - const sinchClient = initSmsClient(); - const response = await sinchClient.sms.batches.sendTextMessage(requestData); + const smsService = initSmsServiceWithServicePlanId(); + const response = await smsService.batches.sendTextMessage(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/sms/batches/update.ts b/examples/simple-examples/src/sms/batches/update.ts index 02d85040..763e6bc3 100644 --- a/examples/simple-examples/src/sms/batches/update.ts +++ b/examples/simple-examples/src/sms/batches/update.ts @@ -2,7 +2,7 @@ import { getBatchIdFromConfig, getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; import { ApiUpdateTextMtMessage, UpdateBatchMessageRequestData } from '@sinch/sdk-core'; @@ -32,10 +32,10 @@ import { ApiUpdateTextMtMessage, UpdateBatchMessageRequestData } from '@sinch/sd } as ApiUpdateTextMtMessage, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.batches.update(requestData); + response = await smsService.batches.update(requestData); } catch (error) { console.error(`ERROR: The batch could not be updated`); throw error; diff --git a/examples/simple-examples/src/sms/delivery-reports/getByBatchId.ts b/examples/simple-examples/src/sms/delivery-reports/getByBatchId.ts index 21a2eb38..b9ce3255 100644 --- a/examples/simple-examples/src/sms/delivery-reports/getByBatchId.ts +++ b/examples/simple-examples/src/sms/delivery-reports/getByBatchId.ts @@ -1,4 +1,9 @@ -import { getBatchIdFromConfig, getPrintFormat, initSmsClient, printFullResponse } from '../../config'; +import { + getBatchIdFromConfig, + getPrintFormat, + initSmsServiceWithServicePlanId, + printFullResponse, +} from '../../config'; import { GetDeliveryReportByBatchIdRequestData, MessageDeliveryStatus } from '@sinch/sdk-core'; (async () => { @@ -12,10 +17,10 @@ import { GetDeliveryReportByBatchIdRequestData, MessageDeliveryStatus } from '@s batch_id: batchId, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.deliveryReports.get(requestData); + response = await smsService.deliveryReports.get(requestData); } catch (error) { console.error(`ERROR: Impossible to retrieve the delivery report by batch ID ${requestData.batch_id}`); throw error; diff --git a/examples/simple-examples/src/sms/delivery-reports/getForNumber.ts b/examples/simple-examples/src/sms/delivery-reports/getForNumber.ts index 708c1981..66d333a2 100644 --- a/examples/simple-examples/src/sms/delivery-reports/getForNumber.ts +++ b/examples/simple-examples/src/sms/delivery-reports/getForNumber.ts @@ -2,7 +2,7 @@ import { getBatchIdFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; import { GetDeliveryReportByPhoneNumberRequestData } from '@sinch/sdk-core'; @@ -20,10 +20,10 @@ import { GetDeliveryReportByPhoneNumberRequestData } from '@sinch/sdk-core'; recipient_msisdn: recipientPhoneNumber, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.deliveryReports.getForNumber(requestData); + response = await smsService.deliveryReports.getForNumber(requestData); } catch (error) { console.error(`ERROR: Impossible to retrieve the delivery report by batch ID ${requestData.batch_id} for the recipient ${requestData.recipient_msisdn}`); throw error; diff --git a/examples/simple-examples/src/sms/delivery-reports/list.ts b/examples/simple-examples/src/sms/delivery-reports/list.ts index 9c894bd0..0c2045f8 100644 --- a/examples/simple-examples/src/sms/delivery-reports/list.ts +++ b/examples/simple-examples/src/sms/delivery-reports/list.ts @@ -1,4 +1,4 @@ -import { getPrintFormat, initSmsClient, printFullResponse } from '../../config'; +import { getPrintFormat, initSmsServiceWithServicePlanId, printFullResponse } from '../../config'; import { ListDeliveryReportsRequestData, PageResult, @@ -29,14 +29,14 @@ const populateDeliveryReportsList = ( start_date: oneWeekAgo, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- let response; try { - response = await sinchClient.sms.deliveryReports.list(requestData); + response = await smsService.deliveryReports.list(requestData); } catch (error) { console.error(`ERROR: Impossible to get the list of delivery reports starting at ${requestData.start_date}`); throw error; @@ -69,7 +69,7 @@ const populateDeliveryReportsList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const deliveryReport of sinchClient.sms.deliveryReports.list(requestData)) { + for await (const deliveryReport of smsService.deliveryReports.list(requestData)) { if (printFormat === 'pretty') { console.log(`Delivery support status: ${deliveryReport.status} - Type: ${deliveryReport.type} - Batch ID: ${deliveryReport.batch_id}`); } else { diff --git a/examples/simple-examples/src/sms/groups/create/create.sinch-client.ts b/examples/simple-examples/src/sms/groups/create/create.sinch-client.ts deleted file mode 100644 index 06acddd1..00000000 --- a/examples/simple-examples/src/sms/groups/create/create.sinch-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initClient } from '../../../config'; -import { create } from './create'; - -(async () => { - const sinchClient = initClient(); - await create(sinchClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/create/create.sinch-sms-client.ts b/examples/simple-examples/src/sms/groups/create/create.sinch-sms-client.ts deleted file mode 100644 index b2800840..00000000 --- a/examples/simple-examples/src/sms/groups/create/create.sinch-sms-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initSmsClient } from '../../../config'; -import { create } from './create'; - -(async () => { - const sinchSmsClient = initSmsClient(); - await create(sinchSmsClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/create/create.ts b/examples/simple-examples/src/sms/groups/create/create.ts index 9c71cd6c..ac74e48e 100644 --- a/examples/simple-examples/src/sms/groups/create/create.ts +++ b/examples/simple-examples/src/sms/groups/create/create.ts @@ -1,7 +1,7 @@ -import { CreateGroupRequestData, SinchClient } from '@sinch/sdk-core'; +import { CreateGroupRequestData, SmsService } from '@sinch/sdk-core'; import { getPrintFormat, printFullResponse } from '../../../config'; -export const create = async(sinchClient: SinchClient) => { +export const create = async(smsService: SmsService) => { console.log('***************'); console.log('* CreateGroup *'); console.log('***************'); @@ -19,7 +19,7 @@ export const create = async(sinchClient: SinchClient) => { let response; try { - response = await sinchClient.sms.groups.create(requestData); + response = await smsService.groups.create(requestData); } catch (error) { console.error('ERROR: Impossible to create a new group'); throw error; diff --git a/examples/simple-examples/src/sms/groups/create/create.with-projectId.ts b/examples/simple-examples/src/sms/groups/create/create.with-projectId.ts new file mode 100644 index 00000000..4d363a54 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/create/create.with-projectId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithProjectId } from '../../../config'; +import { create } from './create'; + +(async () => { + const smsServiceWithProjectId = initSmsServiceWithProjectId(); + await create(smsServiceWithProjectId); +})(); diff --git a/examples/simple-examples/src/sms/groups/create/create.with-servicePlanId.ts b/examples/simple-examples/src/sms/groups/create/create.with-servicePlanId.ts new file mode 100644 index 00000000..efd6aeca --- /dev/null +++ b/examples/simple-examples/src/sms/groups/create/create.with-servicePlanId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithServicePlanId } from '../../../config'; +import { create } from './create'; + +(async () => { + const smsServiceWithServicePlanId = initSmsServiceWithServicePlanId(); + await create(smsServiceWithServicePlanId); +})(); diff --git a/examples/simple-examples/src/sms/groups/delete/delete.sinch-client.ts b/examples/simple-examples/src/sms/groups/delete/delete.sinch-client.ts deleted file mode 100644 index c1436850..00000000 --- a/examples/simple-examples/src/sms/groups/delete/delete.sinch-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initClient } from '../../../config'; -import { deleteGroup } from './delete'; - -(async () => { - const sinchClient = initClient(); - await deleteGroup(sinchClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/delete/delete.sinch-sms-client.ts b/examples/simple-examples/src/sms/groups/delete/delete.sinch-sms-client.ts deleted file mode 100644 index bce74da6..00000000 --- a/examples/simple-examples/src/sms/groups/delete/delete.sinch-sms-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initSmsClient } from '../../../config'; -import { deleteGroup } from './delete'; - -(async () => { - const sinchSmsClient = initSmsClient(); - await deleteGroup(sinchSmsClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/delete/delete.ts b/examples/simple-examples/src/sms/groups/delete/delete.ts index 4ce6bf90..f2c71c03 100644 --- a/examples/simple-examples/src/sms/groups/delete/delete.ts +++ b/examples/simple-examples/src/sms/groups/delete/delete.ts @@ -1,7 +1,7 @@ -import { SinchClient, DeleteGroupRequestData } from '@sinch/sdk-core'; +import { DeleteGroupRequestData, SmsService } from '@sinch/sdk-core'; import { getGroupIdFromConfig } from '../../../config'; -export const deleteGroup = async(sinchClient: SinchClient) => { +export const deleteGroup = async(smsService: SmsService) => { console.log('***************'); console.log('* deleteGroup *'); console.log('***************'); @@ -13,7 +13,7 @@ export const deleteGroup = async(sinchClient: SinchClient) => { }; try { - await sinchClient.sms.groups.delete(requestData); + await smsService.groups.delete(requestData); } catch (error) { console.error(`ERROR: Impossible to delete the group ${requestData.group_id}`); throw error; diff --git a/examples/simple-examples/src/sms/groups/delete/delete.with-projectId.ts b/examples/simple-examples/src/sms/groups/delete/delete.with-projectId.ts new file mode 100644 index 00000000..cbe1f893 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/delete/delete.with-projectId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithProjectId } from '../../../config'; +import { deleteGroup } from './delete'; + +(async () => { + const smsServiceWithProjectId = initSmsServiceWithProjectId(); + await deleteGroup(smsServiceWithProjectId); +})(); diff --git a/examples/simple-examples/src/sms/groups/delete/delete.with-servicePlanId.ts b/examples/simple-examples/src/sms/groups/delete/delete.with-servicePlanId.ts new file mode 100644 index 00000000..a32f4f55 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/delete/delete.with-servicePlanId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithServicePlanId } from '../../../config'; +import { deleteGroup } from './delete'; + +(async () => { + const smsServiceWithServicePlanId = initSmsServiceWithServicePlanId(); + await deleteGroup(smsServiceWithServicePlanId); +})(); diff --git a/examples/simple-examples/src/sms/groups/get/get.sinch-client.ts b/examples/simple-examples/src/sms/groups/get/get.sinch-client.ts deleted file mode 100644 index 8d8afba3..00000000 --- a/examples/simple-examples/src/sms/groups/get/get.sinch-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initClient } from '../../../config'; -import { get } from './get'; - -(async () => { - const sinchClient = initClient(); - await get(sinchClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/get/get.sinch-sms-client.ts b/examples/simple-examples/src/sms/groups/get/get.sinch-sms-client.ts deleted file mode 100644 index 07d24b73..00000000 --- a/examples/simple-examples/src/sms/groups/get/get.sinch-sms-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initSmsClient } from '../../../config'; -import { get } from './get'; - -(async () => { - const sinchSmsClient = initSmsClient(); - await get(sinchSmsClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/get/get.ts b/examples/simple-examples/src/sms/groups/get/get.ts index e3df132a..7d0353f6 100644 --- a/examples/simple-examples/src/sms/groups/get/get.ts +++ b/examples/simple-examples/src/sms/groups/get/get.ts @@ -1,7 +1,7 @@ -import { SinchClient, GetGroupRequestData } from '@sinch/sdk-core'; +import { GetGroupRequestData, SmsService } from '@sinch/sdk-core'; import { getGroupIdFromConfig, getPrintFormat, printFullResponse } from '../../../config'; -export const get = async(sinchClient: SinchClient) => { +export const get = async(smsService: SmsService) => { console.log('*****************'); console.log('* RetrieveGroup *'); console.log('*****************'); @@ -14,7 +14,7 @@ export const get = async(sinchClient: SinchClient) => { let response; try { - response = await sinchClient.sms.groups.get(requestData); + response = await smsService.groups.get(requestData); } catch (error) { console.error(`ERROR: Impossible to get the group ${requestData.group_id}`); throw error; diff --git a/examples/simple-examples/src/sms/groups/get/get.with-projectId.ts b/examples/simple-examples/src/sms/groups/get/get.with-projectId.ts new file mode 100644 index 00000000..4fcb8041 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/get/get.with-projectId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithProjectId } from '../../../config'; +import { get } from './get'; + +(async () => { + const smsServiceWithProjectId = initSmsServiceWithProjectId(); + await get(smsServiceWithProjectId); +})(); diff --git a/examples/simple-examples/src/sms/groups/get/get.with-servicePlanId.ts b/examples/simple-examples/src/sms/groups/get/get.with-servicePlanId.ts new file mode 100644 index 00000000..efe5b72a --- /dev/null +++ b/examples/simple-examples/src/sms/groups/get/get.with-servicePlanId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithServicePlanId } from '../../../config'; +import { get } from './get'; + +(async () => { + const smsServiceWithServicePlanId = initSmsServiceWithServicePlanId(); + await get(smsServiceWithServicePlanId); +})(); diff --git a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-client.ts b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-client.ts deleted file mode 100644 index 8728e4d6..00000000 --- a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initClient } from '../../../config'; -import { getPhoneNumbers } from './getPhoneNumbers'; - -(async () => { - const sinchClient = initClient(); - await getPhoneNumbers(sinchClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-sms-client.ts b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-sms-client.ts deleted file mode 100644 index ad85a497..00000000 --- a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.sinch-sms-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initSmsClient } from '../../../config'; -import { getPhoneNumbers } from './getPhoneNumbers'; - -(async () => { - const sinchSmsClient = initSmsClient(); - await getPhoneNumbers(sinchSmsClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.ts b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.ts index 69e6c4f1..48a2c043 100644 --- a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.ts +++ b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.ts @@ -1,7 +1,7 @@ -import { ListMembersRequestData, SinchClient } from '@sinch/sdk-core'; +import { ListMembersRequestData, SmsService } from '@sinch/sdk-core'; import { getGroupIdFromConfig, getPrintFormat, printFullResponse } from '../../../config'; -export const getPhoneNumbers = async(sinchClient: SinchClient) => { +export const getPhoneNumbers = async(smsService: SmsService) => { console.log('**************'); console.log('* GetMembers *'); console.log('**************'); @@ -14,7 +14,7 @@ export const getPhoneNumbers = async(sinchClient: SinchClient) => { let response; try { - response = await sinchClient.sms.groups.listMembers(requestData); + response = await smsService.groups.listMembers(requestData); } catch (error) { console.error(`ERROR: Impossible to get the numbers of the group ${requestData.group_id}`); throw error; diff --git a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-projectId.ts b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-projectId.ts new file mode 100644 index 00000000..71eaeeea --- /dev/null +++ b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-projectId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithProjectId } from '../../../config'; +import { getPhoneNumbers } from './getPhoneNumbers'; + +(async () => { + const smsServiceWithProjectId = initSmsServiceWithProjectId(); + await getPhoneNumbers(smsServiceWithProjectId); +})(); diff --git a/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-servicePlanId.ts b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-servicePlanId.ts new file mode 100644 index 00000000..50e9ff66 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/getPhoneNumbers/getPhoneNumbers.with-servicePlanId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithServicePlanId } from '../../../config'; +import { getPhoneNumbers } from './getPhoneNumbers'; + +(async () => { + const smsServiceWithServicePlanId = initSmsServiceWithServicePlanId(); + await getPhoneNumbers(smsServiceWithServicePlanId); +})(); diff --git a/examples/simple-examples/src/sms/groups/list/list.sinch-client.ts b/examples/simple-examples/src/sms/groups/list/list.sinch-client.ts deleted file mode 100644 index 44af8fcd..00000000 --- a/examples/simple-examples/src/sms/groups/list/list.sinch-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initClient } from '../../../config'; -import { list } from './list'; - -(async () => { - const sinchClient = initClient(); - await list(sinchClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/list/list.sinch-sms-client.ts b/examples/simple-examples/src/sms/groups/list/list.sinch-sms-client.ts deleted file mode 100644 index 0454f295..00000000 --- a/examples/simple-examples/src/sms/groups/list/list.sinch-sms-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initSmsClient } from '../../../config'; -import { list } from './list'; - -(async () => { - const sinchSmsClient = initSmsClient(); - await list(sinchSmsClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/list/list.ts b/examples/simple-examples/src/sms/groups/list/list.ts index 106e22fe..a7b220f8 100644 --- a/examples/simple-examples/src/sms/groups/list/list.ts +++ b/examples/simple-examples/src/sms/groups/list/list.ts @@ -1,7 +1,8 @@ import { - SinchClient, CreateGroupResponse, - ListGroupsRequestData, PageResult, + ListGroupsRequestData, + PageResult, + SmsService, } from '@sinch/sdk-core'; import { getPrintFormat, printFullResponse } from '../../../config'; @@ -18,7 +19,7 @@ const populateGroupsList = ( }); }; -export const list = async(sinchClient: SinchClient) => { +export const list = async(smsService: SmsService) => { console.log('**************'); console.log('* ListGroups *'); console.log('**************'); @@ -32,7 +33,7 @@ export const list = async(sinchClient: SinchClient) => { // ---------------------------------------------- let response; try { - response = await sinchClient.sms.groups.list(requestData); + response = await smsService.groups.list(requestData); } catch (error) { console.error(`ERROR: Impossible to list the groups associated to your service plan id`); throw error; @@ -67,7 +68,7 @@ export const list = async(sinchClient: SinchClient) => { // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const group of sinchClient.sms.groups.list(requestData)) { + for await (const group of smsService.groups.list(requestData)) { if (printFormat === 'pretty') { console.log(`Group ID: ${group.id} - Group name: ${group.name}`); } else { diff --git a/examples/simple-examples/src/sms/groups/list/list.with-projectId.ts b/examples/simple-examples/src/sms/groups/list/list.with-projectId.ts new file mode 100644 index 00000000..3850b9fb --- /dev/null +++ b/examples/simple-examples/src/sms/groups/list/list.with-projectId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithProjectId } from '../../../config'; +import { list } from './list'; + +(async () => { + const smsServiceWithProjectId = initSmsServiceWithProjectId(); + await list(smsServiceWithProjectId); +})(); diff --git a/examples/simple-examples/src/sms/groups/list/list.with-servicePlanId.ts b/examples/simple-examples/src/sms/groups/list/list.with-servicePlanId.ts new file mode 100644 index 00000000..d3ae76e5 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/list/list.with-servicePlanId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithServicePlanId } from '../../../config'; +import { list } from './list'; + +(async () => { + const smsServiceWithServicePlanId = initSmsServiceWithServicePlanId(); + await list(smsServiceWithServicePlanId); +})(); diff --git a/examples/simple-examples/src/sms/groups/replace/replace.sinch-client.ts b/examples/simple-examples/src/sms/groups/replace/replace.sinch-client.ts deleted file mode 100644 index a39215ba..00000000 --- a/examples/simple-examples/src/sms/groups/replace/replace.sinch-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initClient } from '../../../config'; -import { replace } from './replace'; - -(async () => { - const sinchClient = initClient(); - await replace(sinchClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/replace/replace.sinch-sms-client.ts b/examples/simple-examples/src/sms/groups/replace/replace.sinch-sms-client.ts deleted file mode 100644 index bcdffe06..00000000 --- a/examples/simple-examples/src/sms/groups/replace/replace.sinch-sms-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initSmsClient } from '../../../config'; -import { replace } from './replace'; - -(async () => { - const sinchSmsClient = initSmsClient(); - await replace(sinchSmsClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/replace/replace.ts b/examples/simple-examples/src/sms/groups/replace/replace.ts index 9bd16445..7c01a246 100644 --- a/examples/simple-examples/src/sms/groups/replace/replace.ts +++ b/examples/simple-examples/src/sms/groups/replace/replace.ts @@ -1,7 +1,7 @@ -import { ReplaceGroupRequestData, SinchClient } from '@sinch/sdk-core'; +import { ReplaceGroupRequestData, SmsService } from '@sinch/sdk-core'; import { getGroupIdFromConfig, getPrintFormat, printFullResponse } from '../../../config'; -export const replace = async(sinchClient: SinchClient) => { +export const replace = async(smsService: SmsService) => { console.log('****************'); console.log('* ReplaceGroup *'); console.log('****************'); @@ -20,7 +20,7 @@ export const replace = async(sinchClient: SinchClient) => { let response; try { - response = await sinchClient.sms.groups.replace(requestData); + response = await smsService.groups.replace(requestData); } catch (error) { console.error(`ERROR: Impossible to replace the group ${requestData.group_id}`); throw error; diff --git a/examples/simple-examples/src/sms/groups/replace/replace.with-projectId.ts b/examples/simple-examples/src/sms/groups/replace/replace.with-projectId.ts new file mode 100644 index 00000000..4677b04c --- /dev/null +++ b/examples/simple-examples/src/sms/groups/replace/replace.with-projectId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithProjectId } from '../../../config'; +import { replace } from './replace'; + +(async () => { + const smsServiceWithProjectId = initSmsServiceWithProjectId(); + await replace(smsServiceWithProjectId); +})(); diff --git a/examples/simple-examples/src/sms/groups/replace/replace.with-servicePlanId.ts b/examples/simple-examples/src/sms/groups/replace/replace.with-servicePlanId.ts new file mode 100644 index 00000000..5688dea2 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/replace/replace.with-servicePlanId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithServicePlanId } from '../../../config'; +import { replace } from './replace'; + +(async () => { + const smsServiceWithServicePlanId = initSmsServiceWithServicePlanId(); + await replace(smsServiceWithServicePlanId); +})(); diff --git a/examples/simple-examples/src/sms/groups/update/update.sinch-client.ts b/examples/simple-examples/src/sms/groups/update/update.sinch-client.ts deleted file mode 100644 index d2e85eef..00000000 --- a/examples/simple-examples/src/sms/groups/update/update.sinch-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initClient } from '../../../config'; -import { update } from './update'; - -(async () => { - const sinchClient = initClient(); - await update(sinchClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/update/update.sinch-sms-client.ts b/examples/simple-examples/src/sms/groups/update/update.sinch-sms-client.ts deleted file mode 100644 index 9b9bd30d..00000000 --- a/examples/simple-examples/src/sms/groups/update/update.sinch-sms-client.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { initSmsClient } from '../../../config'; -import { update } from './update'; - -(async () => { - const sinchSmsClient = initSmsClient(); - await update(sinchSmsClient); -})(); diff --git a/examples/simple-examples/src/sms/groups/update/update.ts b/examples/simple-examples/src/sms/groups/update/update.ts index b5430d56..94ce6534 100644 --- a/examples/simple-examples/src/sms/groups/update/update.ts +++ b/examples/simple-examples/src/sms/groups/update/update.ts @@ -1,7 +1,7 @@ -import { SinchClient, UpdateGroupRequestData } from '@sinch/sdk-core'; +import { SmsService, UpdateGroupRequestData } from '@sinch/sdk-core'; import { getGroupIdFromConfig, getPrintFormat, printFullResponse } from '../../../config'; -export const update = async(sinchClient: SinchClient) => { +export const update = async(smsService: SmsService) => { console.log('***************'); console.log('* UpdateGroup *'); console.log('***************'); @@ -21,7 +21,7 @@ export const update = async(sinchClient: SinchClient) => { let response; try { - response = await sinchClient.sms.groups.update(requestData); + response = await smsService.groups.update(requestData); } catch (error) { console.error(`ERROR: Impossible to update the group ${requestData.group_id}`); throw error; diff --git a/examples/simple-examples/src/sms/groups/update/update.with-projectId.ts b/examples/simple-examples/src/sms/groups/update/update.with-projectId.ts new file mode 100644 index 00000000..37ded403 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/update/update.with-projectId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithProjectId } from '../../../config'; +import { update } from './update'; + +(async () => { + const smsServiceWithProjectId = initSmsServiceWithProjectId(); + await update(smsServiceWithProjectId); +})(); diff --git a/examples/simple-examples/src/sms/groups/update/update.with-servicePlanId.ts b/examples/simple-examples/src/sms/groups/update/update.with-servicePlanId.ts new file mode 100644 index 00000000..e10b4388 --- /dev/null +++ b/examples/simple-examples/src/sms/groups/update/update.with-servicePlanId.ts @@ -0,0 +1,7 @@ +import { initSmsServiceWithServicePlanId } from '../../../config'; +import { update } from './update'; + +(async () => { + const smsServiceWithServicePlanId = initSmsServiceWithServicePlanId(); + await update(smsServiceWithServicePlanId); +})(); diff --git a/examples/simple-examples/src/sms/inbounds/get.ts b/examples/simple-examples/src/sms/inbounds/get.ts index 347e8387..6d8e06bb 100644 --- a/examples/simple-examples/src/sms/inbounds/get.ts +++ b/examples/simple-examples/src/sms/inbounds/get.ts @@ -1,7 +1,7 @@ import { getInboundIdFromConfig, getPrintFormat, - initSmsClient, + initSmsServiceWithServicePlanId, printFullResponse, } from '../../config'; import { GetInboundMessageRequestData } from '@sinch/sdk-core'; @@ -17,10 +17,10 @@ import { GetInboundMessageRequestData } from '@sinch/sdk-core'; inbound_id: inboundId, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); let response; try { - response = await sinchClient.sms.inbounds.get(requestData); + response = await smsService.inbounds.get(requestData); } catch (error) { console.error(`ERROR: Impossible to retrieve the inbound message ${requestData.inbound_id}`); throw error; diff --git a/examples/simple-examples/src/sms/inbounds/list.ts b/examples/simple-examples/src/sms/inbounds/list.ts index abf78b2d..a36d09ab 100644 --- a/examples/simple-examples/src/sms/inbounds/list.ts +++ b/examples/simple-examples/src/sms/inbounds/list.ts @@ -1,4 +1,9 @@ -import { getPrintFormat, getRecipientPhoneNumberFromConfig, initSmsClient, printFullResponse } from '../../config'; +import { + getPrintFormat, + getRecipientPhoneNumberFromConfig, + initSmsServiceWithServicePlanId, + printFullResponse, +} from '../../config'; import { InboundMessageResponse, ListInboundMessagesRequestData, @@ -31,14 +36,14 @@ const populateInboundMessagesList = ( to: recipientPhoneNumber, }; - const sinchClient = initSmsClient(); + const smsService = initSmsServiceWithServicePlanId(); // ---------------------------------------------- // Method 1: Fetch the data page by page manually // ---------------------------------------------- let response; try { - response = await sinchClient.sms.inbounds.list(requestData); + response = await smsService.inbounds.list(requestData); } catch (error) { console.error(`ERROR: Impossible to get the list the inbound messages for the numbers ${requestData.to}`); throw error; @@ -75,7 +80,7 @@ const populateInboundMessagesList = ( // --------------------------------------------------------------------- // Method 2: Use the iterator and fetch data on more pages automatically // --------------------------------------------------------------------- - for await (const inboundMessage of sinchClient.sms.inbounds.list(requestData)) { + for await (const inboundMessage of smsService.inbounds.list(requestData)) { if (printFormat === 'pretty') { console.log(`Inbound message ID: ${inboundMessage.id} - Type: ${inboundMessage.type} - From: ${inboundMessage.from}`); } else { diff --git a/examples/simple-examples/src/verification/verification-status/verification-by-id.ts b/examples/simple-examples/src/verification/verification-status/verification-by-id.ts index 641af7ab..19d3f509 100644 --- a/examples/simple-examples/src/verification/verification-status/verification-by-id.ts +++ b/examples/simple-examples/src/verification/verification-status/verification-by-id.ts @@ -2,7 +2,7 @@ import { VerificationStatusByIdRequestData } from '@sinch/sdk-core'; import { getPrintFormat, getVerificationIdFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../config'; @@ -17,8 +17,8 @@ import { id: verificationId, }; - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verificationStatus.getById(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verificationStatus.getById(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verification-status/verification-by-identity.ts b/examples/simple-examples/src/verification/verification-status/verification-by-identity.ts index fea34159..9965fa50 100644 --- a/examples/simple-examples/src/verification/verification-status/verification-by-identity.ts +++ b/examples/simple-examples/src/verification/verification-status/verification-by-identity.ts @@ -1,5 +1,5 @@ import { VerificationStatusByIdentityRequestData } from '@sinch/sdk-core'; -import { getPrintFormat, getVerificationIdentityFromConfig, initApplicationClient, printFullResponse } from '../../config'; +import { getPrintFormat, getVerificationIdentityFromConfig, initVerificationService, printFullResponse } from '../../config'; (async () => { console.log('********************************'); @@ -13,8 +13,8 @@ import { getPrintFormat, getVerificationIdentityFromConfig, initApplicationClien method: 'sms', }; - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verificationStatus.getByIdentity(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verificationStatus.getByIdentity(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verification-status/verification-by-reference.ts b/examples/simple-examples/src/verification/verification-status/verification-by-reference.ts index 04a81d04..3abee010 100644 --- a/examples/simple-examples/src/verification/verification-status/verification-by-reference.ts +++ b/examples/simple-examples/src/verification/verification-status/verification-by-reference.ts @@ -2,7 +2,7 @@ import { VerificationStatusByReferenceRequestData } from '@sinch/sdk-core'; import { getPrintFormat, getVerificationReferenceFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../config'; @@ -17,8 +17,8 @@ import { reference: verificationReference, }; - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verificationStatus.getByReference(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verificationStatus.getByReference(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/callout/report-with-id_callout.ts b/examples/simple-examples/src/verification/verifications/callout/report-with-id_callout.ts index e167fe20..84640a79 100644 --- a/examples/simple-examples/src/verification/verifications/callout/report-with-id_callout.ts +++ b/examples/simple-examples/src/verification/verifications/callout/report-with-id_callout.ts @@ -3,7 +3,7 @@ import { getPrintFormat, getVerificationCodeFromConfig, getVerificationIdFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { const requestData = verificationsHelper.buildReportCalloutVerificationByIdRequest( verificationId, verificationCode); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.reportCalloutById(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportCalloutById(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/callout/report-with-identity_callout.ts b/examples/simple-examples/src/verification/verifications/callout/report-with-identity_callout.ts index 18d9102b..2bab3852 100644 --- a/examples/simple-examples/src/verification/verifications/callout/report-with-identity_callout.ts +++ b/examples/simple-examples/src/verification/verifications/callout/report-with-identity_callout.ts @@ -2,7 +2,7 @@ import { verificationsHelper } from '@sinch/sdk-core'; import { getPrintFormat, getVerificationCodeFromConfig, - getVerificationIdentityFromConfig, initApplicationClient, printFullResponse, + getVerificationIdentityFromConfig, initVerificationService, printFullResponse, } from '../../../config'; (async () => { @@ -16,8 +16,8 @@ import { const requestData = verificationsHelper.buildReportCalloutVerificationByIdentityRequest( verificationIdentity, verificationCode); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.reportCalloutByIdentity(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportCalloutByIdentity(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/callout/start-callout.ts b/examples/simple-examples/src/verification/verifications/callout/start-callout.ts index eba0ff8b..8a4c0d2e 100644 --- a/examples/simple-examples/src/verification/verifications/callout/start-callout.ts +++ b/examples/simple-examples/src/verification/verifications/callout/start-callout.ts @@ -2,7 +2,7 @@ import { verificationsHelper } from '@sinch/sdk-core'; import { getPrintFormat, getVerificationIdentityFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { `test-reference-for-callout-verification_${verificationIdentity}`, ); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.startCallout(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.startCallout(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/flashcall/report-with-id_flashcall.ts b/examples/simple-examples/src/verification/verifications/flashcall/report-with-id_flashcall.ts index 31e8fac6..6992a046 100644 --- a/examples/simple-examples/src/verification/verifications/flashcall/report-with-id_flashcall.ts +++ b/examples/simple-examples/src/verification/verifications/flashcall/report-with-id_flashcall.ts @@ -3,7 +3,7 @@ import { getPrintFormat, getVerificationCliFromConfig, getVerificationIdFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { const requestData = verificationsHelper.buildReportFlashCallVerificationByIdRequest( verificationId, verificationCli); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.reportFlashCallById(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportFlashCallById(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/flashcall/report-with-identity_flashcall.ts b/examples/simple-examples/src/verification/verifications/flashcall/report-with-identity_flashcall.ts index 8cca9e77..9b9e52ce 100644 --- a/examples/simple-examples/src/verification/verifications/flashcall/report-with-identity_flashcall.ts +++ b/examples/simple-examples/src/verification/verifications/flashcall/report-with-identity_flashcall.ts @@ -3,7 +3,7 @@ import { getPrintFormat, getVerificationCliFromConfig, getVerificationIdentityFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { const requestData = verificationsHelper.buildReportFlashCallVerificationByIdentityRequest( verificationIdentity, verificationCli); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.reportFlashCallByIdentity(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportFlashCallByIdentity(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts b/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts index c44bd8f0..fb66dc0f 100644 --- a/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts +++ b/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts @@ -2,7 +2,7 @@ import { verificationsHelper } from '@sinch/sdk-core'; import { getPrintFormat, getVerificationIdentityFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -19,8 +19,8 @@ import { 20, ); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.startFlashCall(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.startFlashCall(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts b/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts index e5ddb67c..7a590279 100644 --- a/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts +++ b/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts @@ -2,7 +2,7 @@ import { verificationsHelper } from '@sinch/sdk-core'; import { getPrintFormat, getVerificationIdentityFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { `test-reference-for-seamless-verification_${verificationIdentity}`, ); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.startSeamless(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.startSeamless(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/sms/report-with-id_sms.ts b/examples/simple-examples/src/verification/verifications/sms/report-with-id_sms.ts index 5ff9a501..c8205d38 100644 --- a/examples/simple-examples/src/verification/verifications/sms/report-with-id_sms.ts +++ b/examples/simple-examples/src/verification/verifications/sms/report-with-id_sms.ts @@ -3,7 +3,7 @@ import { getPrintFormat, getVerificationCodeFromConfig, getVerificationIdFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { const requestData = verificationsHelper.buildReportSmsVerificationByIdRequest( verificationId, verificationCode); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.reportSmsById(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportSmsById(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/sms/report-with-identity_sms.ts b/examples/simple-examples/src/verification/verifications/sms/report-with-identity_sms.ts index 4676548b..89160f60 100644 --- a/examples/simple-examples/src/verification/verifications/sms/report-with-identity_sms.ts +++ b/examples/simple-examples/src/verification/verifications/sms/report-with-identity_sms.ts @@ -3,7 +3,7 @@ import { getPrintFormat, getVerificationCodeFromConfig, getVerificationIdentityFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { const requestData = verificationsHelper.buildReportSmsVerificationByIdentityRequest( verificationIdentity, verificationCode); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.reportSmsByIdentity(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.reportSmsByIdentity(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/verification/verifications/sms/start-sms.ts b/examples/simple-examples/src/verification/verifications/sms/start-sms.ts index c47f27f9..a432bec5 100644 --- a/examples/simple-examples/src/verification/verifications/sms/start-sms.ts +++ b/examples/simple-examples/src/verification/verifications/sms/start-sms.ts @@ -2,7 +2,7 @@ import { verificationsHelper } from '@sinch/sdk-core'; import { getPrintFormat, getVerificationIdentityFromConfig, - initApplicationClient, + initVerificationService, printFullResponse, } from '../../../config'; @@ -18,8 +18,8 @@ import { `test-reference-for-sms-verification_${verificationIdentity}`, ); - const sinchClient = initApplicationClient(); - const response = await sinchClient.verification.verifications.startSms(requestData); + const verificationService = initVerificationService(); + const response = await verificationService.verifications.startSms(requestData); const printFormat = getPrintFormat(process.argv); diff --git a/examples/simple-examples/src/voice/applications/assignNumbers.ts b/examples/simple-examples/src/voice/applications/assignNumbers.ts index c326af94..4faa0c43 100644 --- a/examples/simple-examples/src/voice/applications/assignNumbers.ts +++ b/examples/simple-examples/src/voice/applications/assignNumbers.ts @@ -1,4 +1,8 @@ -import { getApplicationKeyFromConfig, getPhoneNumberFromConfig, initApplicationClient } from '../../config'; +import { + getApplicationKeyFromConfig, + getPhoneNumberFromConfig, + initVoiceService, +} from '../../config'; import { AssignNumbersRequestData } from '@sinch/sdk-core'; (async () => { @@ -17,9 +21,9 @@ import { AssignNumbersRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); + const voiceService = initVoiceService(); try { - await sinchClient.voice.applications.assignNumbers(requestData); + await voiceService.applications.assignNumbers(requestData); } catch (error) { console.log(`Impossible to assign the numbers '${requestData.assignNumbersRequestBody?.numbers}' to the application '${requestData.assignNumbersRequestBody?.applicationkey}'`); throw error; diff --git a/examples/simple-examples/src/voice/applications/getCallbackURLs.ts b/examples/simple-examples/src/voice/applications/getCallbackURLs.ts index f8fedeec..d739829e 100644 --- a/examples/simple-examples/src/voice/applications/getCallbackURLs.ts +++ b/examples/simple-examples/src/voice/applications/getCallbackURLs.ts @@ -1,7 +1,7 @@ import { getApplicationKeyFromConfig, getPrintFormat, - initApplicationClient, + initVoiceService, printFullResponse, } from '../../config'; import { GetCallbackURLsRequestData } from '@sinch/sdk-core'; @@ -17,10 +17,10 @@ import { GetCallbackURLsRequestData } from '@sinch/sdk-core'; applicationkey: applicationKey, }; - const sinchClient = initApplicationClient(); + const voiceService = initVoiceService(); let response; try { - response = await sinchClient.voice.applications.getCallbackURLs(requestData); + response = await voiceService.applications.getCallbackURLs(requestData); } catch (error) { console.log(`Impossible to retrieve the callback URLs for the application '${requestData.applicationkey}'`); throw error; diff --git a/examples/simple-examples/src/voice/applications/getNumbers.ts b/examples/simple-examples/src/voice/applications/getNumbers.ts index 79047da2..a5be6348 100644 --- a/examples/simple-examples/src/voice/applications/getNumbers.ts +++ b/examples/simple-examples/src/voice/applications/getNumbers.ts @@ -1,4 +1,4 @@ -import { getPrintFormat, initApplicationClient, printFullResponse } from '../../config'; +import { getPrintFormat, initVoiceService, printFullResponse } from '../../config'; import { GetNumbersRequestData } from '@sinch/sdk-core'; (async () => { @@ -8,10 +8,10 @@ import { GetNumbersRequestData } from '@sinch/sdk-core'; const requestData: GetNumbersRequestData = {}; - const sinchClient = initApplicationClient(); + const voiceService = initVoiceService(); let response; try { - response = await sinchClient.voice.applications.listNumbers(requestData); + response = await voiceService.applications.listNumbers(requestData); } catch (error) { console.log(`Impossible to get information about your numbers`); throw error; diff --git a/examples/simple-examples/src/voice/applications/queryNumber.ts b/examples/simple-examples/src/voice/applications/queryNumber.ts index afe78c55..9b0517ba 100644 --- a/examples/simple-examples/src/voice/applications/queryNumber.ts +++ b/examples/simple-examples/src/voice/applications/queryNumber.ts @@ -1,4 +1,9 @@ -import { getPhoneNumberFromConfig, getPrintFormat, initApplicationClient, printFullResponse } from '../../config'; +import { + getPhoneNumberFromConfig, + getPrintFormat, + initVoiceService, + printFullResponse, +} from '../../config'; import { QueryNumberRequestData } from '@sinch/sdk-core'; (async () => { @@ -12,10 +17,10 @@ import { QueryNumberRequestData } from '@sinch/sdk-core'; number: phoneNumber, }; - const sinchClient = initApplicationClient(); + const voiceService = initVoiceService(); let response; try { - response = await sinchClient.voice.applications.queryNumber(requestData); + response = await voiceService.applications.queryNumber(requestData); } catch (error) { console.log(`Impossible to get information about the number ${requestData.number}`); throw error; diff --git a/examples/simple-examples/src/voice/applications/unassignNumber.ts b/examples/simple-examples/src/voice/applications/unassignNumber.ts index a4a78399..bfb528fb 100644 --- a/examples/simple-examples/src/voice/applications/unassignNumber.ts +++ b/examples/simple-examples/src/voice/applications/unassignNumber.ts @@ -1,4 +1,8 @@ -import { getApplicationKeyFromConfig, getPhoneNumberFromConfig, initApplicationClient } from '../../config'; +import { + getApplicationKeyFromConfig, + getPhoneNumberFromConfig, + initVoiceService, +} from '../../config'; import { UnassignNumberRequestData } from '@sinch/sdk-core'; (async () => { @@ -17,9 +21,9 @@ import { UnassignNumberRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); + const voiceService = initVoiceService(); try { - await sinchClient.voice.applications.unassignNumber(requestData); + await voiceService.applications.unassignNumber(requestData); } catch (error) { console.log(`Impossible to unassign the number '${requestData.unassignNumbersRequestBody?.number}' from the application '${requestData.unassignNumbersRequestBody?.applicationkey}'`); throw error; diff --git a/examples/simple-examples/src/voice/applications/updateCallbackURLs.ts b/examples/simple-examples/src/voice/applications/updateCallbackURLs.ts index f1ff4b65..5bc15f53 100644 --- a/examples/simple-examples/src/voice/applications/updateCallbackURLs.ts +++ b/examples/simple-examples/src/voice/applications/updateCallbackURLs.ts @@ -1,6 +1,6 @@ import { getApplicationKeyFromConfig, - initApplicationClient, + initVoiceService, } from '../../config'; import { UpdateCallbackURLsRequestData } from '@sinch/sdk-core'; @@ -21,9 +21,9 @@ import { UpdateCallbackURLsRequestData } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); + const voiceService = initVoiceService(); try { - await sinchClient.voice.applications.updateCallbackURLs(requestData); + await voiceService.applications.updateCallbackURLs(requestData); } catch (error) { console.log(`Impossible to update the callback URLs for the application '${requestData.applicationkey}'`); throw error; diff --git a/examples/simple-examples/src/voice/callouts/conference.ts b/examples/simple-examples/src/voice/callouts/conference.ts index 829cce8b..23b92786 100644 --- a/examples/simple-examples/src/voice/callouts/conference.ts +++ b/examples/simple-examples/src/voice/callouts/conference.ts @@ -2,7 +2,7 @@ import { getConferenceIdFromConfig, getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initApplicationClient, + initVoiceService, printFullResponse, } from '../../config'; import { ConferenceCalloutRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -31,11 +31,11 @@ import { ConferenceCalloutRequestData, VoiceRegion } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); let response; try { - response = await sinchClient.voice.callouts.conference(requestData); + response = await voiceService.callouts.conference(requestData); } catch (error) { console.log(`Impossible to make a Conference callout to '${requestData.conferenceCalloutRequestBody?.conferenceCallout.destination.endpoint}'`); throw error; diff --git a/examples/simple-examples/src/voice/callouts/custom.ts b/examples/simple-examples/src/voice/callouts/custom.ts index 9e7e96e9..cee0b33d 100644 --- a/examples/simple-examples/src/voice/callouts/custom.ts +++ b/examples/simple-examples/src/voice/callouts/custom.ts @@ -3,7 +3,7 @@ import { getPrintFormat, getRecipientPhoneNumberFromConfig, getVoiceCallBackUrl, - initApplicationClient, + initVoiceService, printFullResponse, } from '../../config'; import { @@ -79,10 +79,10 @@ import { }, }; - const sinchClient = initApplicationClient(); + const voiceService = initVoiceService(); let response; try { - response = await sinchClient.voice.callouts.custom(requestData); + response = await voiceService.callouts.custom(requestData); } catch (error) { console.log(`Impossible to make a Custom callout to '${requestData.customCalloutRequestBody?.customCallout.destination?.endpoint}'`); throw error; diff --git a/examples/simple-examples/src/voice/callouts/tts.ts b/examples/simple-examples/src/voice/callouts/tts.ts index 4d78d28b..ac6c92ce 100644 --- a/examples/simple-examples/src/voice/callouts/tts.ts +++ b/examples/simple-examples/src/voice/callouts/tts.ts @@ -2,7 +2,7 @@ import { getPhoneNumberFromConfig, getPrintFormat, getRecipientPhoneNumberFromConfig, - initApplicationClient, + initVoiceService, printFullResponse, } from '../../config'; import { TtsCalloutRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -30,11 +30,11 @@ import { TtsCalloutRequestData, VoiceRegion } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); let response; try { - response = await sinchClient.voice.callouts.tts(requestData); + response = await voiceService.callouts.tts(requestData); } catch (error) { console.log(`Impossible to make a TTS callout to '${requestData.ttsCalloutRequestBody?.ttsCallout.destination.endpoint}'`); throw error; diff --git a/examples/simple-examples/src/voice/calls/get.ts b/examples/simple-examples/src/voice/calls/get.ts index c298b6c1..492d0213 100644 --- a/examples/simple-examples/src/voice/calls/get.ts +++ b/examples/simple-examples/src/voice/calls/get.ts @@ -1,7 +1,7 @@ import { getCallIdFromConfig, getPrintFormat, - initApplicationClient, + initVoiceService, printFullResponse, } from '../../config'; import { GetCallResultRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -17,11 +17,11 @@ import { GetCallResultRequestData, VoiceRegion } from '@sinch/sdk-core'; callId, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); let response; try { - response = await sinchClient.voice.calls.get(requestData); + response = await voiceService.calls.get(requestData); } catch (error) { console.log(`Impossible get information about call Id ${requestData.callId}`); throw error; diff --git a/examples/simple-examples/src/voice/calls/manageWithCallLeg.ts b/examples/simple-examples/src/voice/calls/manageWithCallLeg.ts index 5dcdc1e0..3ec32f1c 100644 --- a/examples/simple-examples/src/voice/calls/manageWithCallLeg.ts +++ b/examples/simple-examples/src/voice/calls/manageWithCallLeg.ts @@ -1,6 +1,6 @@ import { getCallIdFromConfig, - initApplicationClient, + initVoiceService, } from '../../config'; import { ManageWithCallLegRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -27,10 +27,10 @@ import { ManageWithCallLegRequestData, VoiceRegion } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); try { - await sinchClient.voice.calls.manageWithCallLeg(requestData); + await voiceService.calls.manageWithCallLeg(requestData); } catch (error) { console.log(`Impossible manage with call leg the call Id ${requestData.callId}`); throw error; diff --git a/examples/simple-examples/src/voice/calls/update.ts b/examples/simple-examples/src/voice/calls/update.ts index 7776b78a..53697296 100644 --- a/examples/simple-examples/src/voice/calls/update.ts +++ b/examples/simple-examples/src/voice/calls/update.ts @@ -1,6 +1,6 @@ import { getCallIdFromConfig, - initApplicationClient, + initVoiceService, } from '../../config'; import { UpdateCallRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -38,10 +38,10 @@ import { UpdateCallRequestData, VoiceRegion } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); try { - await sinchClient.voice.calls.update(requestData); + await voiceService.calls.update(requestData); } catch (error) { console.log(`Impossible update the call Id '${requestData.callId}'`); throw error; diff --git a/examples/simple-examples/src/voice/conferences/get.ts b/examples/simple-examples/src/voice/conferences/get.ts index 6d3cf59f..c84d31d3 100644 --- a/examples/simple-examples/src/voice/conferences/get.ts +++ b/examples/simple-examples/src/voice/conferences/get.ts @@ -1,7 +1,7 @@ import { getConferenceIdFromConfig, getPrintFormat, - initApplicationClient, + initVoiceService, printFullResponse, } from '../../config'; import { GetConferenceInfoRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -17,11 +17,11 @@ import { GetConferenceInfoRequestData, VoiceRegion } from '@sinch/sdk-core'; conferenceId, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); let response; try { - response = await sinchClient.voice.conferences.get(requestData); + response = await voiceService.conferences.get(requestData); } catch (error) { console.log(`Impossible get information about conference Id '${requestData.conferenceId}'`); throw error; diff --git a/examples/simple-examples/src/voice/conferences/kickAll.ts b/examples/simple-examples/src/voice/conferences/kickAll.ts index 0579da60..24d20a0c 100644 --- a/examples/simple-examples/src/voice/conferences/kickAll.ts +++ b/examples/simple-examples/src/voice/conferences/kickAll.ts @@ -1,6 +1,6 @@ import { getConferenceIdFromConfig, - initApplicationClient, + initVoiceService, } from '../../config'; import { KickAllRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -15,10 +15,10 @@ import { KickAllRequestData, VoiceRegion } from '@sinch/sdk-core'; conferenceId, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); try { - await sinchClient.voice.conferences.kickAll(requestData); + await voiceService.conferences.kickAll(requestData); } catch (error) { console.log(`Impossible kick all participants from conference id '${requestData.conferenceId}'`); throw error; diff --git a/examples/simple-examples/src/voice/conferences/kickParticipant.ts b/examples/simple-examples/src/voice/conferences/kickParticipant.ts index 106d0b37..96c7277e 100644 --- a/examples/simple-examples/src/voice/conferences/kickParticipant.ts +++ b/examples/simple-examples/src/voice/conferences/kickParticipant.ts @@ -1,7 +1,7 @@ import { getCallIdFromConfig, getConferenceIdFromConfig, - initApplicationClient, + initVoiceService, } from '../../config'; import { KickParticipantRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -18,10 +18,10 @@ import { KickParticipantRequestData, VoiceRegion } from '@sinch/sdk-core'; callId, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); try { - await sinchClient.voice.conferences.kickParticipant(requestData); + await voiceService.conferences.kickParticipant(requestData); } catch (error) { console.log(`Impossible kick the participant '${requestData.callId}' from conference id '${requestData.conferenceId}'`); throw error; diff --git a/examples/simple-examples/src/voice/conferences/manageParticipant.ts b/examples/simple-examples/src/voice/conferences/manageParticipant.ts index b3e6c187..4d15a201 100644 --- a/examples/simple-examples/src/voice/conferences/manageParticipant.ts +++ b/examples/simple-examples/src/voice/conferences/manageParticipant.ts @@ -1,7 +1,7 @@ import { getCallIdFromConfig, getConferenceIdFromConfig, - initApplicationClient, + initVoiceService, } from '../../config'; import { ManageParticipantRequestData, VoiceRegion } from '@sinch/sdk-core'; @@ -22,10 +22,10 @@ import { ManageParticipantRequestData, VoiceRegion } from '@sinch/sdk-core'; }, }; - const sinchClient = initApplicationClient(); - sinchClient.voice.setRegion(VoiceRegion.EUROPE); + const voiceService = initVoiceService(); + voiceService.setRegion(VoiceRegion.EUROPE); try { - await sinchClient.voice.conferences.manageParticipant(requestData); + await voiceService.conferences.manageParticipant(requestData); } catch (error) { console.log(`Impossible manage the participant '${requestData.callId}' with conference id '${requestData.conferenceId}'`); throw error; diff --git a/packages/conversation/README.md b/packages/conversation/README.md index a93d8989..8bf8f926 100644 --- a/packages/conversation/README.md +++ b/packages/conversation/README.md @@ -38,18 +38,24 @@ If you are using this SDK as part of the Sinch SDK (`@sinch/sdk-core`) you can a ```typescript import { + ConversationService, SinchClient, - SinchClientParameters, + UnifiedCredentials, + SendMessageRequestData, + SendMessageResponse, } from '@sinch/sdk-core'; -const credentials: SinchClientParameters = { +const credentials: UnifiedCredentials = { projectId: 'PROJECT_ID', keyId: 'KEY_ID', keySecret: 'KEY_SECRET', }; +// Access the 'conversation' service registered on the Sinch Client const sinch = new SinchClient(credentials); +const conversationService: ConversationService = sinch.conversation; +// Build the request data const requestData: SendMessageRequestData = { sendMessageRequestBody: { app_id: 'CONVERSATION_APP_ID', @@ -61,12 +67,15 @@ const requestData: SendMessageRequestData = { recipient: { contact_id: 'CONTACT_ID', }, + channel_priority_order: [ + 'WHASAPP', + ], }, }; -// Access the 'conversation' domain registered on the Sinch Client +// Use the 'conversation' service registered on the Sinch client const result: SendMessageResponse - = await sinch.conversation.messages.send(requestData); + = await conversationService.messages.send(requestData); ``` ### Standalone @@ -75,21 +84,24 @@ The SDK can be used standalone if you need to use only the Conversation APIs. ```typescript import { - SinchClientParameters, + UnifiedCredentials, } from '@sinch/sdk-client'; import { - + ConversationService, + SendMessageRequestData, + SendMessageResponse, } from '@sinch/conversation'; -const credentials: SinchClientParameters = { +const credentials: UnifiedCredentials = { projectId: 'PROJECT_ID', keyId: 'KEY_ID', keySecret: 'KEY_SECRET', }; // Declare the 'conversation' service in a standalone way -const conversation = new Conversation(options); +const conversationService = new ConversationService(options); +// Build the request data const requestData: SendMessageRequestData = { sendMessageRequestBody: { app_id: 'CONVERSATION_APP_ID', @@ -101,30 +113,33 @@ const requestData: SendMessageRequestData = { recipient: { contact_id: 'CONTACT_ID', }, + channel_priority_order: [ + 'WHASAPP', + ], }, }; -// Use the standalone declaration of the 'conversation' domain +// Use the standalone declaration of the 'conversation' service const result: SendMessageResponse - = await conversation.messages.send(requestData); + = await conversationService.messages.send(requestData); ``` ## Promises -All the methods that interact with the Sinch APIs use Promises. You can use `await` in an `async` method to wait for the response or you can resolve them yourself with `then()` / `catch()`. +All the methods that interact with the Sinch APIs use Promises. You can use `await` in an `async` method to wait for the response, or you can resolve them yourself with `then()` / `catch()`. ```typescript // Method 1: Wait for the Promise to complete let result: SendMessageResponse; try { - result = await sinch.conversation.messages.send(requestData); + result = await conversationService.messages.send(requestData); console.log(`Message sent successfully. Message Id: ${result.id}`); } catch (error: any) { console.error(`ERROR ${error.statusCode}: `); } // Method 2: Resolve the promise -sinch.conversation.messages.send(requestData) +conversationService.messages.send(requestData) .then(response => console.log(`Message sent successfully. Message Id: ${result.id}`)) .catch(error => console.error(`ERROR ${error.statusCode}: `)); ``` diff --git a/packages/fax/README.md b/packages/fax/README.md index 5e200b18..667c9e54 100644 --- a/packages/fax/README.md +++ b/packages/fax/README.md @@ -38,6 +38,7 @@ If you are using this SDK as part of the Sinch SDK (`@sinch/sdk-core`) you can a ```typescript import { + FaxService, SendFaxRequestData, SinchClient, UnifiedCredentials, @@ -49,8 +50,11 @@ const credentials: UnifiedCredentials = { keySecret: 'KEY_SECRET', }; +// Access the 'fax' service registered on the Sinch Client const sinch = new SinchClient(credentials); +const faxService: FaxService = sinch.fax; +// Build the request data const requestData: SendFaxRequestData = { sendFaxRequestBody: { to: '+12015555555', @@ -59,8 +63,8 @@ const requestData: SendFaxRequestData = { }, }; -// Access the 'fax' domain registered on the Sinch Client -const response = await sinchClient.fax.faxes.send(requestData); +// Use the 'fax' service registered on the Sinch client +const response = await faxService.faxes.send(requestData); ``` ### Standalone @@ -72,6 +76,7 @@ import { UnifiedCredentials, } from '@sinch/sdk-client'; import { + FaxService, SendFaxRequestData, } from '@sinch/fax'; @@ -81,9 +86,10 @@ const credentials: UnifiedCredentials = { keySecret: 'KEY_SECRET', }; -// Declare the 'fax' controller in a standalone way +// Declare the 'fax' service in a standalone way const faxService = new FaxService(credentials); +// Build the request data const requestData: SendFaxRequestData = { sendFaxRequestBody: { to: '+12015555555', @@ -104,14 +110,14 @@ All the methods that interact with the Sinch APIs use Promises. You can use `awa // Method 1: Wait for the Promise to complete (you need to be in an 'async' method) let sendFaxResult: Fax; try { - sendFaxResult = await sinch.fax.faxes.send(requestData); + sendFaxResult = await faxService.faxes.send(requestData); console.log(`Fax successfully created at '${sendFaxResult.createTime}'. Status = '${sendFaxResult.status}`); } catch (error: any) { console.error(`ERROR ${error.statusCode}: Impossible to crete the fax sent to ${requestdata.to}.`); } // Method 2: Resolve the promise -sinch.fax.faxes.send(requestData) +faxService.faxes.send(requestData) .then(response => console.log(`Fax successfully created at '${sendFaxResult.createTime}'. Status = '${sendFaxResult.status}`)) .catch(error => console.error(`ERROR ${error.statusCode}: Impossible to crete the fax sent to ${requestdata.to}.`)); ``` diff --git a/packages/numbers/README.md b/packages/numbers/README.md index c2232458..b987d8f6 100644 --- a/packages/numbers/README.md +++ b/packages/numbers/README.md @@ -40,6 +40,7 @@ If you are using this SDK as part of the Sinch SDK (`@sinch/sdk-core`) you can a import { AvailableNumber, GetAvailableNumberRequestData, + NumbersService, SinchClient, UnifiedCredentials, } from '@sinch/sdk-core'; @@ -50,15 +51,18 @@ const credentials: UnifiedCredentials = { keySecret: 'KEY_SECRET', }; +// Access the 'numbers' service registered on the Sinch Client const sinch = new SinchClient(credentials); +const numbersService: NumbersService = sinch.numbers; +// Build the request data const requestData: GetAvailableNumberRequestData = { phoneNumber: '+17813334444', }; -// Access the 'numbers' domain registered on the Sinch Client +// Use the 'numbers' service registered on the Sinch client const availabilityResult: AvailableNumber - = await sinch.numbers.availableNumber.checkAvailability(requestData); + = await numbersService.availableNumber.checkAvailability(requestData); ``` ### Standalone @@ -72,7 +76,7 @@ import { import { AvailableNumber, GetAvailableNumberRequestData, - Numbers, + NumbersService, } from '@sinch/numbers'; const credentials: UnifiedCredentials = { @@ -81,16 +85,17 @@ const credentials: UnifiedCredentials = { keySecret: 'KEY_SECRET', }; -// Declare the 'numbers' controller in a standalone way -const numbers = new Numbers(credentials); +// Declare the 'numbers' service in a standalone way +const numbersService = new NumbersService(credentials); +// Build the request data const requestData: GetAvailableNumberRequestData = { phoneNumber: '+17813334444', }; -// Use the standalone declaration of the 'numbers' controller +// Use the standalone declaration of the 'numbers' service const availabilityResult: AvailableNumber - = await numbers.availableNumber.checkAvailability(requestData); + = await numbersService.availableNumber.checkAvailability(requestData); ``` ## Promises @@ -101,14 +106,14 @@ All the methods that interact with the Sinch APIs use Promises. You can use `awa // Method 1: Wait for the Promise to complete (you need to be in an 'async' method) let availabilityResult: AvailableNumber; try { - availabilityResult = await sinch.numbers.availableNumber.checkAvailability(requestData); + availabilityResult = await numbersService.availableNumber.checkAvailability(requestData); console.log(`Phone number: ${availabilityResult.phoneNumber} - Type: ${availabilityResult.type}`); } catch (error: any) { console.error(`ERROR ${error.statusCode}: the phone number ${requestData.phoneNumber} is not available`); } // Method 2: Resolve the promise -sinch.numbers.availableNumber.checkAvailability(requestData) +numbersService.availableNumber.checkAvailability(requestData) .then(response => console.log(`Phone number: ${response.phoneNumber} - Type: ${response.type}`)) .catch(error => console.error(`ERROR ${error.statusCode}: the phone number ${requestData.phoneNumber} is not available`)); ``` diff --git a/packages/sdk-client/README.md b/packages/sdk-client/README.md index 1b287bd9..2fe6ec02 100644 --- a/packages/sdk-client/README.md +++ b/packages/sdk-client/README.md @@ -104,6 +104,7 @@ const myResponse = await myApi.myApiOperation(); | Plugin name | Description | |-------------|-----------------------------------------------------------------------------------------------------------------------------------------------| | exception | Check the response content and converts it into an error if empty or if the status is not `ok`.
**Added by default to the ApiFetchClient** | +| timezone | Patch some response properties which are identified as returned without a timezone by the server | ## Contact Developer Experience team: [devexp@sinch.com](mailto:devexp@sinch.com) diff --git a/packages/sdk-core/README.md b/packages/sdk-core/README.md index 9a7b2186..8149b862 100644 --- a/packages/sdk-core/README.md +++ b/packages/sdk-core/README.md @@ -21,7 +21,7 @@ yarn add @sinch/sdk-core ## Usage -The `@sinch/sdk-core` package contains the entry point for a SDK user: the `SinchClient` class. It will use the information given in parameters to initialize the right plugins for the right APIs. +The `@sinch/sdk-core` package contains the entry point for an SDK user: the `SinchClient` class. It will use the information given in parameters to initialize the right plugins for the right APIs. As there are different authentication schemes, the initialization method will depend on which one is used by the API. @@ -31,13 +31,14 @@ As there are different authentication schemes, the initialization method will de import { SinchClient } from '@sinch/sdk-core'; // The credentials can be found on the Account dashboard: https://dashboard.sinch.com/account/access-keys -const sinch = new SinchClient({ +const sinch: Pick = new SinchClient({ projectId: 'my-project-id', keyId: 'my-key-id', keySecret: 'my-key-secret', }); +const numbersService = sinch.numbers; -const response = await sinch.numbers.availableRegions.list({ +const response = await numbersService.availableRegions.list({ types: 'LOCAL', }); ``` @@ -48,16 +49,17 @@ The initialization method above will work for the APIs that supports the authent If you want to use the SMS API on the other regions (or US and EU too, it will work), you'll need other credentials in order to give to the Client the `servicePlanId` and the associated `apiToken`. ```typescript -import { SinchSmsClient } from '@sinch/sdk-core'; +import { SinchClient } from '@sinch/sdk-core'; // The credentials can be found on the Service APIs dashboard: https://dashboard.sinch.com/sms/api/services -const sinch = new SinchClient({ +const sinch: Pick = new SinchClient({ servicePlanId: 'my-service-plan-id', apiToken: 'my-key-id', region: 'my-region', // Optional, can be 'us', 'eu', 'br', 'au', 'ca'. Default is 'us' }); +const smsService = sinch.sms; -const response = await sinch.sms.batches.get({ +const response = await smsService.batches.get({ batch_id: '01HF28S9AABBBCCCCY92BJB569', }); ``` @@ -72,18 +74,19 @@ import { SinchClient } from '@sinch/sdk-core'; // The credentials can be found on the Verification or Voice dashboard: // https://dashboard.sinch.com/verification/apps or // https://dashboard.sinch.com/voice/apps -const sinch = new SinchClient({ +const sinch: Pick = new SinchClient({ applicationId: 'my-application-key', applicationSecret: 'my-application-secret', }); +const verificationService = sinch.verification; -const response = await sinch.verification.verificationStatus.getById({ +const response = await verificationService.verificationStatus.getById({ id: '018bfc3e-1234-5678-1234-ebdb3fd6d30f', }); ``` ## Examples -You can find an example of each request in the [../../examples/simple-examples](../../examples/simple-examples/) folder. +You can find an example of each request in the [../../examples/simple-examples](../../examples/simple-examples) folder. ## Contact Developer Experience team: [devexp@sinch.com](mailto:devexp@sinch.com) @@ -97,12 +100,6 @@ Here is the list of the Sinch API and there level of support by the Node.js SDK: | Messaging | SMS API | ✅ | | | Conversation API | ✅ | | | Fax API | 🚧 | -| | RCS API | ❌ | -| | MMS API | ❌ | -| | Provisioning API | ❌ | | Voice and Video | Voice API | ✅ | -| | Elastic SIP Trunking | ❌ | | Numbers & Connectivity | Numbers API | ✅ | -| | Brand and Campaign Registration API | ❌ | -| | Number Lookup API | ❌ | | Verification | Verification API | ✅ | diff --git a/packages/sms/README.md b/packages/sms/README.md index 1d7d57e0..4c363d82 100644 --- a/packages/sms/README.md +++ b/packages/sms/README.md @@ -45,8 +45,8 @@ If you are using this SDK as part of the Sinch SDK (`@sinch/sdk-core`) you can a import { SendSMSRequestData, SendSMSResponse, + SmsService, SinchClient, - SinchSmsClient, ServicePlanIdCredentials, UnifiedCredentials, Region, @@ -58,15 +58,20 @@ const credentialsWithProjectId: UnifiedCredentials = { keySecret: 'KEY_SECRET', region: Region.UNITED_STATES, // Optional, default is 'us'. Only other possibility is 'eu' }; -const sinchWithProjectId = new SinchClient(credentialsWithProjectId); +// Access the 'sms' service registered on the Sinch Client +const sinchClientCreatedWithProjectId = new SinchClient(credentialsWithProjectId); +const smsServiceWithProjectId: SmsService = sinchClientCreatedWithProjectId.sms; const credentialsWithServicePlanId: ServicePlanIdCredentials = { servicePlanId: 'SERVICE_PLAN_ID', apiToken: 'API_TOKEN', region: Region.UNITED_STATES, // Optional, default is 'us'. Other possibilities are 'eu', 'br', 'au' and 'ca' }; -const sinchWithServicePlanId = new SinchClient(credentialsWithServicePlanId); +// Access the 'sms' service registered on the Sinch Client +const sinchClientCreatedWithServicePlanId = new SinchClient(credentialsWithServicePlanId); +const smsServiceWithServicePlanId: SmsService = sinchClientCreatedWithServicePlanId.sms; +// Build the request data const requestData: SendSMSRequestData = { sendSMSRequestBody: { to: [ @@ -85,23 +90,21 @@ const requestData: SendSMSRequestData = { }, }; -// Access the 'sms' domain registered on the Sinch Client +// Use the 'sms' service registered on the Sinch client // The request will be authenticated with OAuth2 and sent to https://zt.us.sms.api.sinch.com const availabilityResult_1: SendSMSResponse - = await sinchWithProjectId.sms.batches.send(requestData); + = await smsServiceWithProjectId.batches.send(requestData); -// Access the 'sms' domain registered on the Sinch Client +// Use the 'sms' service registered on the Sinch client // The request will be authenticated with the API Token and sent to https://us.sms.api.sinch.com const availabilityResult_2: SendSMSResponse - = await sinchWithServicePlanId.sms.batches.send(requestData); + = await smsServiceWithServicePlanId.batches.send(requestData); ``` ### Standalone The SDK can be used standalone if you need to use only the SMS APIs. As for a usage with the Sinch Client, you can choose to use the `projectId` or `servicePlanId` credentials. -#### With the Oauth2TokenRequest plugin - ```typescript import { Region, @@ -111,7 +114,7 @@ import { import { SendSMSRequestData, SendSMSResponse, - Sms, + SmsService, } from '@sinch/sms'; const credentialsWithProjectId: UnifiedCredentials = { @@ -120,28 +123,29 @@ const credentialsWithProjectId: UnifiedCredentials = { keySecret: 'KEY_SECRET', region: Region.UNITED_STATES, // Optional, default is 'us'. Only other possibility is 'eu' }; -// Declare the 'sms' controller in a standalone way -const smsWithProjectId = new Sms(credentialsWithProjectId); +// Declare the 'sms' service in a standalone way +const smsServiceWithProjectId = new SmsService(credentialsWithProjectId); const credentialsWithServicePlanId: ServicePlanIdCredentials = { servicePlanId: 'SERVICE_PLAN_ID', apiToken: 'API_TOKEN', region: Region.UNITED_STATES, // Optional, default is 'us'. Other possibilities are 'eu', 'br', 'au' and 'ca' }; -// Declare the 'sms' controller in a standalone way -const smsWithServicePlanId = new Sms(credentialsWithServicePlanId); +// Declare the 'sms' service in a standalone way +const smsServiceWithServicePlanId = new SmsService(credentialsWithServicePlanId); +// Build the request data const requestData: SendSMSRequestData = { // some request parameters }; -// Use the standalone declaration of the 'sms' controller +// Use the standalone declaration of the 'sms' service // The request will be authenticated with OAuth2 and sent to https://zt.us.sms.api.sinch.com -const response_1: SendSMSResponse = await smsWithProjectId.batches.send(requestData); +const response_1: SendSMSResponse = await smsServiceWithProjectId.batches.send(requestData); -// Use the standalone declaration of the 'sms' controller +// Use the standalone declaration of the 'sms' service // The request will be authenticated with the API Token and sent to https://us.sms.api.sinch.com -const response_2: SendSMSResponse = await smsWithServicePlanId.batches.send(requestData); +const response_2: SendSMSResponse = await smsServiceWithServicePlanId.batches.send(requestData); ``` ## Promises @@ -152,14 +156,14 @@ All the methods that interact with the Sinch APIs use Promises. You can use `awa // Method 1: Wait for the Promise to complete (you need to be in an 'async' method) let batchResponse: SendSMSResponse; try { - batchResponse = await sinch.sms.batches.send(requestData); + batchResponse = await smsService.batches.send(requestData); console.log(`The SMS has been sent successfully: batch id = ${batchResponse.id}`); } catch (error: any) { console.error(`ERROR ${error.statusCode}: the SMS could not be sent`); } // Method 2: Resolve the promise -sinch.sms.batches.send(requestData) +smsService.batches.send(requestData) .then(response => console.log(`The SMS has been sent successfully: batch id = ${response.id}`)) .catch(error => console.error(`ERROR ${error.statusCode}: the SMS could not be sent`)); ``` diff --git a/packages/verification/README.md b/packages/verification/README.md index 6cd44fbd..f602cdfa 100644 --- a/packages/verification/README.md +++ b/packages/verification/README.md @@ -36,19 +36,24 @@ The `Verification` API uses the Application Signed Request to authenticate again If you are using this SDK as part of the Sinch SDK (`@sinch/sdk-core`) you can access it as the `verification` property of the client that you would have instantiated. ```typescript -import { +import { InitiateVerificationResponse, StartVerificationRequestData, SinchClient, - ApplicationCredentials, + ApplicationCredentials, + VerificationService, } from '@sinch/sdk-core'; const credentials: ApplicationCredentials = { applicationKey: 'APPLICATION_ID', applicationSecret: 'APPLICATION_SECRET', }; + +// Access the 'verification' service registered on the Sinch Client const sinch = new SinchClient(credentials); +const verificationService: VerificationService = sinch.verification; +// Build the request data const requestData: StartVerificationRequestData = { initiateVerificationRequestBody: { identity: { @@ -59,9 +64,9 @@ const requestData: StartVerificationRequestData = { }, }; -// Access the 'verification' controller registered on the Sinch Client -const verificationInitResponse: InitiateVerificationResponse - = await sinch.verification.verifications.start(requestData); +// Use the 'verification' service registered on the Sinch client +const verificationInitResponse: InitiateVerificationResponse + = await verificationService.verifications.start(requestData); ``` ### Standalone @@ -75,7 +80,7 @@ import { import { InitiateVerificationResponse, StartVerificationRequestData, - Verification, + VerificationService, } from '@sinch/verification'; const credentials: ApplicationCredentials = { @@ -83,9 +88,10 @@ const credentials: ApplicationCredentials = { applicationSecret: 'APPLICATION_SECRET', }; -// Declare the 'verification' controller in a standalone way -const verification = new Verification(credentials); +// Declare the 'verification' service in a standalone way +const verificationService = new VerificationService(credentials); +// Build the request data const requestData: StartVerificationRequestData = { initiateVerificationRequestBody: { identity: { @@ -96,9 +102,9 @@ const requestData: StartVerificationRequestData = { }, }; -// Use the standalone declaration of the 'verification' controller +// Use the standalone declaration of the 'verification' service const verificationInitResponse: InitiateVerificationResponse - = await verification.verifications.start(requestData); + = await verificationService.verifications.start(requestData); ``` ## Promises @@ -109,14 +115,14 @@ All the methods that interact with the Sinch APIs use Promises. You can use `awa // Method 1: Wait for the Promise to complete (you need to be in an 'async' method) let verificationInitResponse: InitiateVerificationResponse; try { - verificationInitResponse = await sinch.verification.verifications.start(requestData); + verificationInitResponse = await verificationService.verifications.start(requestData); console.log(`Verification ID = ${verificationInitResponse.id}`); } catch (error: any) { console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.initiateVerificationRequestBody.identity.endpoint}`); } // Method 2: Resolve the promise -sinch.verification.verifications.start(requestData) +verificationService.verifications.start(requestData) .then(response => console.log(`Verification ID = ${response.id}`)) .catch(error => console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.initiateVerificationRequestBody.identity.endpoint}`)); ``` diff --git a/packages/voice/README.md b/packages/voice/README.md index e7c3d97c..9d8a75a6 100644 --- a/packages/voice/README.md +++ b/packages/voice/README.md @@ -41,15 +41,20 @@ import { TtsCalloutRequestData, GetCalloutResponseObj, SinchClient, - ApplicationCredentials, + ApplicationCredentials, + VoiceService, } from '@sinch/sdk-core'; const credentials: ApplicationCredentials = { applicationKey: 'APPLICATION_ID', applicationSecret: 'APPLICATION_SECRET', }; + +// Access the 'voice' service registered on the Sinch Client const sinch = new SinchClient(credentials); +const voiceService: VoiceService = sinch.voice; +// Build the request data const requestData: TtsCalloutRequestData = { ttsCalloutRequestBody: { method: 'ttsCallout', @@ -65,9 +70,9 @@ const requestData: TtsCalloutRequestData = { }, }; -// Access the 'voice' controller registered on the Sinch Client -const calloutResponse: GetCalloutResponseObj - = await sinch.voice.callouts.tts(requestData); +// Use the 'voice' service registered on the Sinch client +const calloutResponse: GetCalloutResponseObj + = await voiceService.callouts.tts(requestData); ``` ### Standalone @@ -81,7 +86,7 @@ import { import { TtsCalloutRequestData, GetCalloutResponseObj, - Voice, + VoiceService, } from '@sinch/voice'; const credentials: ApplicationCredentials = { @@ -89,9 +94,10 @@ const credentials: ApplicationCredentials = { applicationSecret: 'APPLICATION_SECRET', }; -// Declare the 'voice' controller in a standalone way -const voice = new Voice(credentials); +// Declare the 'voice' service in a standalone way +const voiceService = new VoiceService(credentials); +// Build the request data const requestData: TtsCalloutRequestData = { ttsCalloutRequestBody: { method: 'ttsCallout', @@ -107,9 +113,9 @@ const requestData: TtsCalloutRequestData = { }, }; -// Use the standalone declaration of the 'voice' controller +// Use the standalone declaration of the 'voice' service const calloutResponse: GetCalloutResponseObj - = await voice.callouts.tts(requestData); + = await voiceService.callouts.tts(requestData); ``` ## Promises @@ -120,14 +126,14 @@ All the methods that interact with the Sinch APIs use Promises. You can use `awa // Method 1: Wait for the Promise to complete (you need to be in an 'async' method) let calloutResponse: GetCalloutResponseObj; try { - calloutResponse = await sinch.voice.callouts.tts(requestData); + calloutResponse = await voiceService.callouts.tts(requestData); console.log(`callId = ${calloutResponse.callId}`); } catch (error: any) { console.error(`ERROR ${error.statusCode}: Impossible to make a TTS callout to the number ${requestData.ttsCalloutRequestBody.ttsCallout.destination.endpoint}`); } // Method 2: Resolve the promise -sinch.voice.callouts.tts(requestData) +voiceService.callouts.tts(requestData) .then(response => console.log(`callId = ${response.callId}`)) .catch(error => console.error(`ERROR ${error.statusCode}: Impossible to make a TTS call out to the number ${requestData.ttsCalloutRequestBody.ttsCallout.destination.endpoint}`)); ```