UNPKG

@sirhc77/signalwire-rest-sdk

Version:

An SDK for the SignalWire REST API

1,069 lines (976 loc) 151 kB
import {isNode} from 'browser-or-node'; import axios, {AxiosInstance, AxiosRequestConfig} from 'axios'; import { Address, Brand, Campaign, CampaignPhoneNumberAssignmentOrder, GenerateChatTokenRequest, ChatNamespace, CreateAddressRequest, CreateCampaignPhoneNumberAssignmentOrderRequest, CreateCampaignRequest, CreateDomainApplicationRequest, CreateNumberGroupMemberRequest, CreateNumberGroupRequest, CreateVerifiedCallerIdRequest, DomainApplication, CreateAiAgentRequest, UpdateAiAgentRequest, AssignResourceAsDomainApplicationHandlerRequest, AssignResourceAsPhoneRouteHandlerRequest, AssignResourceAsSipEndpointHandlerRequest, CreateCallFlowRequest, UpdateCallFlowRequest, UpdateDialogflowAgentRequest, CreateFreeswitchConnectorRequest, UpdateFreeswitchConnectorRequest, ListFabricResourcesOptions, FabricNamespace, CreateRelayApplicationRequest, UpdateRelayApplicationRequest, CreateFabricSipEndpointRequest, UpdateFabricSipEndpointRequest, CreateFabricSubscriberRequest, UpdateFabricSubscriberRequest, CreateSwmlScriptRequest, UpdateSwmlScriptRequest, ListFaxLogsOptions, FaxNamespace, Headers, ListAllBrandsOptions, ListAllCampaignPhoneNumberAssignmentOrdersOptions, ListAllCampaignPhoneNumberAssignmentsOptions, ListAllDomainApplicationsOptions, ListAllPhoneNumbersOptions, ListAllVerifiedCallerIdsOptions, ListMessageLogsOptions, MessageNamespace, MfaTokenViaPhoneCallRequest, MfaTokenViaPhoneCallResponse, MfaTokenViaTextRequest, MfaTokenViaTextResponse, NumberGroup, NumberGroupMembership, PhoneNumber, PhoneNumberListing, CreateApiTokenRequest, UpdateApiTokenRequest, ProjectNamespace, PurchasePhoneNumberRequest, QueryParams, SearchForAvailablePhoneNumbersOptions, SpaceManagementNamespace, LookupNumberOptions, CreateSipEndpointRequest, ListAllSipEndpointsOptions, UpdateSipEndpointRequest, UpdateSipProfileRequest, UpdateCampaignRequest, UpdateDomainApplicationRequest, UpdateNumberGroupRequest, UpdatePhoneNumberRequest, UpdateVerifiedCallerIdRequest, ValidateVerificationCodeRequest, VerifiedCallerId, VerifyMfaTokenRequest, VerifyMfaTokenResponse, CreateVideoConferenceRequest, ListVideoConferencesOptions, RetrieveVideoConferenceOptions, UpdateVideoConferenceRequest, ListVideoLogsOptions, VideoNamespace, ListRecordingsForVideoRoomOptions, RetrieveVideoRoomRecordingOptions, ListRoomSessionsRecordingsOptions, VoiceLogsListLogsOptions, VoiceNamespace, LookupNumberResponse, SipEndpoint, SipProfile, Recording, VideoRoom, GetVideoRoomOptions, ListRoomSessionsOptions, VideoRoomSession, VideoRoomRecording, VideoRoomSessionMember, VideoRoomTokenRequest, CreateVideoRoomRequest, UpdateVideoRoomRequest, VideoRoomToken, VideoRoomStream, CreateStreamRequest, UpdateStreamRequest, VideoConference, VideoConferenceToken, VoiceLog, VideoLog, MessageLog, FaxLog, ApiToken, ChatToken, CreateFabricSubscriberTokenRequest, FabricSubscriberToken, CreateBrandRequest, CallFlowVersion, AiAgentResponse, SwmlScriptResponse, RelayApplicationResponse, FabricSipEndpointResponse, FreeswitchConnectorResponse, DialogflowAgentResponse, FabricSubscriberResponse, CallFlowResponse, FabricResourceAddress, FabricResourceResponse, CallingNamespace, CallResponse, CreateCallRequest, UpdateCallRequest, DatasphereNamespace, DatasphereDocument, CreateDocumentRequest, SearchDocumentRequest, UpdateDocumentRequest, SearchDocumentsResponse, DatasphereDocumentChunk, FabricAddress, CreateEmbedsTokenRequest, EmbedsToken, SwmlWebhookResponse, CreateSwmlWebhookRequest, UpdateSwmlWebhookRequest, LamlApplicationResponse, UpdateLamlApplicationRequest, CXMLScriptResponse, CreateCXMLScriptRequest, UpdateCXMLScriptRequest, CXMLWebhookResponse, CreateCXMLWebhookRequest, UpdateCXMLWebhookRequest, SipGatewayResponse, UpdateSipGatewayRequest, CreateSipGatewayRequest, CreateSubscriberGuestTokenRequest, SubscriberGuestToken, ExchangeRefreshTokenRequest, CreateSubscriberInviteTokenRequest, SubscriberInviteToken, SubscriberSipEndpoint, CreateSubscriberSipEndpointRequest, UpdateSubscriberSipEndpointRequest, SwmlApplicationResponse, CreateSwmlApplicationRequest, UpdateSwmlApplicationRequest, ConferenceRoomResponse, UpdateConferenceRoomRequest, CreateConferenceRoomRequest, PubSubNamespace, GeneratePubSubTokenRequest, GeneratePubSubTokenResponse } from './SignalWireRESTClientTypes'; import { convertCreateSipEndpointRequestToJSON, convertJSONToDomainApplication, convertJSONToLookupNumberResponse, convertJSONToPhoneNumber, convertJSONToRecording, convertJSONToSipEndpoint, convertJSONToVideoRoom, convertJSONToVideoRoomSession, convertJSONToVideoRoomSessionMember, convertJSONToVideoRoomRecording, convertUpdateDomainApplicationRequestToJSON, convertUpdatePhoneNumberRequestToJSON, convertUpdateSipEndpointRequestToJSON, convertJSONToVideoRoomStream, convertJSONToVideoConference, convertJSONToVideoConferenceToken, convertJSONToVoiceLog, convertJSONToVideoLog, convertJSONToMessageLog, convertJSONToFaxLog, convertJSONToCallFlowVersion, convertUpdateCallFlowRequestToJSON, convertCreateCallFlowRequestToJSON, convertJSONToAiAgentResponse, convertCreateAiAgentRequestToJSON, convertUpdateAiAgentRequestToJSON, convertJSONToSwmlScriptResponse, convertJSONToRelayApplicationResponse, convertUpdateRelayApplicationRequestToJSON, convertCreateRelayApplicationRequestToJSON, convertJSONToFabricSipEndpointResponse, convertUpdateFabricSipEndpointRequestToJSON, convertCreateFabricSipEndpointRequestToJSON, convertJSONToFreeswitchConnectorResponse, convertUpdateFreeswitchConnectorRequestToJson, convertCreateFreeswitchConnectorRequestToJson, convertJSONToDialogflowAgentResponse, convertUpdateDialogflowAgentRequestToJSON, convertJSONToFabricSubscriberResponse, convertJSONToCallFlowResponse, convertJSONToFabricResourceAddress, convertJSONToFabricResourceResponse, convertCreateCallRequestToJSON, convertJSONToCallResponse, convertUpdateCallRequestToJSON, convertJSONToDocument, convertCreateDocumentRequestToJSON, convertSearchDocumentRequestToJSON, convertJSONToSearchDocumentsResponse, convertJSONToDatasphereDocumentChunk, convertJSONToFabricAddress, convertJSONToSwmlWebhookResponse, convertCreateSwmlWebhookRequestToJSON, convertUpdateSwmlWebhookRequestToJSON, convertJSONToLamlApplicationResponse, convertUpdateLamlApplicationRequestToJSON, convertJSONToCXMLScriptResponse, convertJSONToCXMLWebhookResponse, convertCreateCXMLWebhookRequestToJSON, convertUpdateCXMLWebhookRequestToJSON, convertJSONToSipGatewayResponse, convertUpdateSipGatewayRequestToJSON, convertCreateSipGatewayRequestToJSON, convertJSONToSubscriberSipEndpoint, convertCreateSubscriberSipEndpointRequestToJSON, convertUpdateSubscriberEndpointRequestToJSON, convertJSONToSwmlApplicationResponse, convertCreateSwmlApplicationRequestToJSON, convertUpdateSwmlApplicationRequestToJSON, convertJSONToConferenceRoomResponse, convertUpdateConferenceRoomRequestToJSON, convertCreateConferenceRoomRequestToJSON, convertGeneratePubSubTokenRequestToJSON } from "./modelConverters"; import {defaultMakePagedResponse, PagedResponse} from "./PagedResponse"; import {convertSWMLToJSON} from "./swmlModelConverters"; export class SignalWireRESTClient { public readonly spaceManagement: SpaceManagementNamespace; public readonly video: VideoNamespace; public readonly message: MessageNamespace; public readonly voice: VoiceNamespace; public readonly fax: FaxNamespace; public readonly project: ProjectNamespace; public readonly chat: ChatNamespace; public readonly fabric: FabricNamespace; public readonly calling: CallingNamespace; public readonly datasphere: DatasphereNamespace; public readonly pubsub: PubSubNamespace; private readonly username: string private readonly password: string private readonly axiosInstance: AxiosInstance private readonly baseUrl: string; private readonly defaultHeaders: Headers; constructor(space: string, projectId: string, token: string, axiosConfig?: AxiosRequestConfig) { const self = this; this.baseUrl = `https://${space}`; this.username = projectId; this.password = token; this.axiosInstance = axios.create({ baseURL: this.baseUrl, ...axiosConfig }); this.defaultHeaders = { Accept: "application/json", Authorization: `Basic ${isNode ? Buffer.from(self.username + ":" + self.password).toString("base64") : btoa(self.username + ":" + self.password)}` }; this.datasphere = { documents: { listDocuments(): AsyncIterableIterator<DatasphereDocument> { return self.getRequestIterator('/api/datasphere/documents', convertJSONToDocument) }, async listDocumentsPage(url?: string): Promise<PagedResponse<DatasphereDocument>> { return self.getRequestPage('/api/datasphere/documents', convertJSONToDocument, url); }, async createDocument(request: CreateDocumentRequest): Promise<DatasphereDocument> { return self.postRequest('/api/datasphere/documents', request, convertCreateDocumentRequestToJSON, convertJSONToDocument); }, async searchDocument(request: SearchDocumentRequest): Promise<SearchDocumentsResponse> { return self.postRequest('/api/datasphere/documents/search', request, convertSearchDocumentRequestToJSON, convertJSONToSearchDocumentsResponse); }, async updateDocument(id: string, request: UpdateDocumentRequest): Promise<DatasphereDocument> { return self.patchRequest(`/api/datasphere/documents/${id}`, request, (request) => ({ tags: request.tags }), convertJSONToDocument); }, async deleteDocument(id: string): Promise<void> { return self.deleteRequest(`/api/datasphere/documents/${id}`); } }, chunks: { listChunks(documentId: string): AsyncIterableIterator<DatasphereDocumentChunk> { return self.getRequestIterator(`/api/datasphere/documents/${documentId}/chunks`, convertJSONToDatasphereDocumentChunk) }, async listChunksPage(documentId: string, url?: string): Promise<PagedResponse<DatasphereDocumentChunk>> { return self.getRequestPage(`/api/datasphere/documents/${documentId}/chunks`, convertJSONToDatasphereDocumentChunk, url); }, async retrieveChunk(documentId: string, chunkId: string): Promise<DatasphereDocumentChunk> { return self.getRequest(`/api/datasphere/documents/${documentId}/chunks/${chunkId}`, convertJSONToDatasphereDocumentChunk) }, async deleteChunk(documentId: string, chunkId: string): Promise<void> { return self.deleteRequest(`/api/datasphere/documents/${documentId}/chunks/${chunkId}`); } } } this.calling = { calls: { async createCall(request: CreateCallRequest): Promise<CallResponse> { return self.postRequest('/api/calling/calls', request, convertCreateCallRequestToJSON, convertJSONToCallResponse); }, async updateCall(request: UpdateCallRequest): Promise<CallResponse> { return self.putRequest('/api/calling/calls', request, convertUpdateCallRequestToJSON, convertJSONToCallResponse); } } }; this.spaceManagement = { multiFactorAuthentication: { async requestMfaTokenViaText(request: MfaTokenViaTextRequest): Promise<MfaTokenViaTextResponse> { return self.postRequest('/api/relay/rest/mfa/sms', request, (request) => { return { to: request.to, from: request.from, message: request.message, token_length: request.tokenLength, max_attempts: request.maxAttempts, allow_alphas: request.allowAlphas, valid_for: request.validFor, } }, (json) => ( { id: json.id, success: json.success, to: json.to, channel: json.channel } )); }, async requestMfaTokenViaPhoneCall(request: MfaTokenViaPhoneCallRequest): Promise<MfaTokenViaPhoneCallResponse> { return self.postRequest('/api/relay/rest/mfa/call', request, (request) => ({ to: request.to, from: request.from, message: request.message, token_length: request.tokenLength, max_attempts: request.maxAttempts, allow_alphas: request.allowAlphas, valid_for: request.validFor, }), (json) => ( { id: json.id, success: json.success, to: json.to, channel: json.channel } ) ); }, async verifyToken(mfaRequestId: string, request: VerifyMfaTokenRequest): Promise<VerifyMfaTokenResponse> { return self.postRequest(`/api/relay/rest/mfa/${mfaRequestId}/verify`, request, (request) => ({ token: request.token, }), (json) => ( { success: json.data.success, } )); } }, verifiedCallerIds: { async createVerifiedCallerId(request: CreateVerifiedCallerIdRequest): Promise<VerifiedCallerId> { return self.postRequest('/api/relay/rest/verified_caller_ids', request, (request) => ({ name: request.name, extension: request.extension, number: request.number, }), (json) => ({ type: json.type, id: json.id, name: json.name, extension: json.extension, number: json.number, verified: json.verified, verifiedAt: json.verified_at, status: json.status })) }, async validateVerificationCode(id: string, request: ValidateVerificationCodeRequest): Promise<VerifiedCallerId> { return self.putRequest(`/api/relay/rest/verified_caller_ids/${id}/verification`, request, (request) => ({ verification_code: request.verificationCode }), (json) => ({ type: json.type, id: json.id, name: json.name, extension: json.extension, number: json.number, verified: json.verified, verifiedAt: json.verified_at, status: json.status })); }, async redialVerificationCall(id: string): Promise<VerifiedCallerId> { return self.postEmptyRequest(`/api/relay/rest/verified_caller_ids/${id}/verification`, (json) => ({ type: json.type, id: json.id, name: json.name, extension: json.extension, number: json.number, verified: json.verified, verifiedAt: json.verified_at, status: json.status })) }, listAllVerifiedCallerIds(options?: ListAllVerifiedCallerIdsOptions): AsyncIterableIterator<VerifiedCallerId> { const params: QueryParams = {}; if (options?.filterName) { params.filter_name = options.filterName; } if (options?.filterNumber) { params.filter_number = options.filterNumber; } return self.getRequestIterator("/api/relay/rest/verified_caller_ids", (item) => ({ type: item.type, id: item.id, name: item.name, extension: item.extension, number: item.number, verified: item.verified, verifiedAt: item.verified_at, status: item.status }), params); }, async listAllVerifiedCallerIdsPage(options?: ListAllVerifiedCallerIdsOptions, url?: string): Promise<PagedResponse<VerifiedCallerId>> { const params: QueryParams = {}; if (options?.filterName) { params.filter_name = options.filterName; } if (options?.filterNumber) { params.filter_number = options.filterNumber; } return self.getRequestPage('/api/relay/rest/verified_caller_ids', (item) => ({ type: item.type, id: item.id, name: item.name, extension: item.extension, number: item.number, verified: item.verified, verifiedAt: item.verified_at, status: item.status }), url, params); }, async retrieveVerifiedCallerId(id: string): Promise<VerifiedCallerId> { return self.getRequest(`/api/relay/rest/verified_caller_ids/${id}`, (json) => ({ type: json.type, id: json.id, name: json.name, extension: json.extension, number: json.number, verified: json.verified, verifiedAt: json.verified_at, status: json.status })) }, async updateVerifiedCallerId(id: string, request: UpdateVerifiedCallerIdRequest): Promise<VerifiedCallerId> { return self.putRequest(`/api/relay/rest/verified_caller_ids/${id}`, request, (request) => ({ name: request.name, }), (json) => ({ type: json.type, id: json.id, name: json.name, extension: json.extension, number: json.number, verified: json.verified, verifiedAt: json.verified_at, status: json.status })) }, async deleteVerifiedCallerId(id: string): Promise<void> { return self.deleteRequest(`/api/relay/rest/verified_caller_ids/${id}`) } }, addresses: { listAllAddresses(): AsyncIterableIterator<Address> { return self.getRequestIterator("/api/relay/rest/addresses", (item) => ({ id: item.id, label: item.label, country: item.country, firstName: item.first_name, lastName: item.last_name, streetNumber: item.street_number, streetName: item.street_name, addressType: item.address_type, addressNumber: item.address_number, city: item.city, state: item.state, postalCode: item.postal_code, })); }, async listAllAddressesPage(url?: string): Promise<PagedResponse<Address>> { return self.getRequestPage('/api/relay/rest/addresses', (item) => ({ id: item.id, label: item.label, country: item.country, firstName: item.first_name, lastName: item.last_name, streetNumber: item.street_number, streetName: item.street_name, addressType: item.address_type, addressNumber: item.address_number, city: item.city, state: item.state, postalCode: item.postal_code }), url); }, async retrieveAddress(id: string): Promise<Address> { return self.getRequest(`/api/relay/rest/addresses/${id}`, (json) => ({ id: json.id, label: json.label, country: json.country, firstName: json.first_name, lastName: json.last_name, streetNumber: json.street_number, streetName: json.street_name, addressType: json.address_type, addressNumber: json.address_number, city: json.city, state: json.state, postalCode: json.postal_code, })); }, async deleteAddress(id: string): Promise<void> { return self.deleteRequest(`/api/relay/rest/addresses/${id}`) }, async createAddress(request: CreateAddressRequest): Promise<Address> { return self.postRequest('/api/relay/rest/addresses', request, (request) => ({ label: request.label, country: request.country, first_name: request.firstName, last_name: request.lastName, street_number: request.streetNumber, street_name: request.streetName, address_type: request.addressType, address_number: request.addressNumber, city: request.city, state: request.state, postal_code: request.postalCode }), (json) => ({ id: json.id, label: json.label, country: json.country, firstName: json.first_name, lastName: json.last_name, streetNumber: json.street_number, streetName: json.street_name, addressType: json.address_type, addressNumber: json.address_number, city: json.city, state: json.state, postalCode: json.postal_code })); } }, campaignRegistryApi: { brands: { listAllBrands(options?: ListAllBrandsOptions): AsyncIterableIterator<Brand> { const params: QueryParams = {}; if (options?.filterName) { params.filter_name = options.filterName; } if (options?.filterState) { params.filter_state = options.filterState; } return self.getRequestIterator("/api/relay/rest/registry/beta/brands", (item) => ({ id: item.id, state: item.state, name: item.name, companyName: item.company_name, contactEmail: item.contact_email, contactPhone: item.contact_phone, einIssuingCountry: item.ein_issuing_country, legalEntityType: item.legal_entity_type, ein: item.ein, companyAddress: item.company_address, companyVertical: item.company_vertical, companyWebsite: item.company_website, cspBrandReference: item.csp_brand_reference, cspSelfRegistered: item.csp_self_registered, statusCallbackUrl: item.status_callback_url, createdAt: item.created_at, updatedAt: item.updated_at }), params) }, async listAllBrandsPage(options?: ListAllBrandsOptions, url?: string): Promise<PagedResponse<Brand>> { const params: QueryParams = {}; if (options?.filterName) { params.filter_name = options.filterName; } if (options?.filterState) { params.filter_state = options.filterState; } return self.getRequestPage('/api/relay/rest/registry/beta/brands', (item) => ({ id: item.id, state: item.state, name: item.name, companyName: item.company_name, contactEmail: item.contact_email, contactPhone: item.contact_phone, einIssuingCountry: item.ein_issuing_country, legalEntityType: item.legal_entity_type, ein: item.ein, companyAddress: item.company_address, companyVertical: item.company_vertical, companyWebsite: item.company_website, cspBrandReference: item.csp_brand_reference, cspSelfRegistered: item.csp_self_registered, statusCallbackUrl: item.status_callback_url, createdAt: item.created_at, updatedAt: item.updated_at }), url, params); }, async retrieveBrand(id: string): Promise<Brand> { return self.getRequest(`/api/relay/rest/registry/beta/brands/${id}`, (json) => ({ id: json.id, state: json.state, name: json.name, companyName: json.company_name, contactEmail: json.contact_email, contactPhone: json.contact_phone, einIssuingCountry: json.ein_issuing_country, legalEntityType: json.legal_entity_type, ein: json.ein, companyAddress: json.company_address, companyVertical: json.company_vertical, companyWebsite: json.company_website, cspBrandReference: json.csp_brand_reference, cspSelfRegistered: json.csp_self_registered, statusCallbackUrl: json.status_callback_url, createdAt: json.created_at, updatedAt: json.updated_at })) }, createBrand: async function (request: CreateBrandRequest): Promise<Brand> { return self.postRequest('/api/relay/rest/registry/beta/brands', request, (request) => ({ name: request.name, company_name: request.companyName, contact_email: request.contactEmail, contact_phone: request.contactPhone, ein_issuing_country: request.einIssuingCountry, legal_entity_type: request.legalEntityType, ein: request.ein, company_address: request.companyAddress, company_vertical: request.companyVertical, company_website: request.companyWebsite, csp_brand_reference: request.cspBrandReference, csp_self_registered: request.cspSelfRegistered, status_callback_url: request.statusCallbackUrl }), (json) => ({ id: json.id, state: json.state, name: json.name, companyName: json.company_name, contactEmail: json.contact_email, contactPhone: json.contact_phone, einIssuingCountry: json.ein_issuing_country, legalEntityType: json.legal_entity_type, ein: json.ein, companyAddress: json.company_address, companyVertical: json.company_vertical, companyWebsite: json.company_website, cspBrandReference: json.csp_brand_reference, cspSelfRegistered: json.csp_self_registered, statusCallbackUrl: json.status_callback_url, createdAt: json.created_at, updatedAt: json.updated_at })) } }, campaigns: { listAllCampaigns(brandId: string): AsyncIterableIterator<Campaign> { return self.getRequestIterator(`/api/relay/rest/registry/beta/brands/${brandId}/campaigns`, (item) => ({ id: item.id, name: item.name, smsUseCase: item.sms_use_case, subUseCases: item.sub_use_cases, description: item.description, sample1: item.sample1, sample2: item.sample2, sample3: item.sample3, sample4: item.sample4, sample5: item.sample5, dynamicTemplates: item.dynamic_templates, messageFlow: item.message_flow, optInMessage: item.opt_in_message, optOutMessage: item.opt_out_message, helpMessage: item.help_message, numberPoolingRequired: item.number_pooling_required, numberPoolingPerCampaign: item.number_pooling_per_campaign, directLending: item.direct_lending, embeddedLink: item.embedded_link, embeddedPhone: item.embedded_phone, ageGatedContent: item.age_gated_content, leadGeneration: item.lead_generation, termsAndConditions: item.terms_and_conditions, createdAt: item.created_at, updatedAt: item.updated_at })); }, async listAllCampaignsPage(brandId: string, url?: string): Promise<PagedResponse<Campaign>> { return self.getRequestPage(`/api/relay/rest/registry/beta/brands/${brandId}/campaigns`, (item) => ({ id: item.id, name: item.name, smsUseCase: item.sms_use_case, subUseCases: item.sub_use_cases, description: item.description, sample1: item.sample1, sample2: item.sample2, sample3: item.sample3, sample4: item.sample4, sample5: item.sample5, dynamicTemplates: item.dynamic_templates, messageFlow: item.message_flow, optInMessage: item.opt_in_message, optOutMessage: item.opt_out_message, helpMessage: item.help_message, numberPoolingRequired: item.number_pooling_required, numberPoolingPerCampaign: item.number_pooling_per_campaign, directLending: item.direct_lending, embeddedLink: item.embedded_link, embeddedPhone: item.embedded_phone, ageGatedContent: item.age_gated_content, leadGeneration: item.lead_generation, termsAndConditions: item.terms_and_conditions, createdAt: item.created_at, updatedAt: item.updated_at }), url); }, async retrieveCampaign(campaignId: string): Promise<Campaign> { return self.getRequest(`/api/relay/rest/registry/beta/campaigns/${campaignId}`, (json) => ({ id: json.id, name: json.name, smsUseCase: json.sms_use_case, subUseCases: json.sub_use_cases, description: json.description, sample1: json.sample1, sample2: json.sample2, sample3: json.sample3, sample4: json.sample4, sample5: json.sample5, dynamicTemplates: json.dynamic_templates, messageFlow: json.message_flow, optInMessage: json.opt_in_message, optOutMessage: json.opt_out_message, helpMessage: json.help_message, numberPoolingRequired: json.number_pooling_required, numberPoolingPerCampaign: json.number_pooling_per_campaign, directLending: json.direct_lending, embeddedLink: json.embedded_link, embeddedPhone: json.embedded_phone, ageGatedContent: json.age_gated_content, leadGeneration: json.lead_generation, termsAndConditions: json.terms_and_conditions, createdAt: json.created_at, updatedAt: json.updated_at })); }, async updateCampaign(campaignId: string, request: UpdateCampaignRequest): Promise<Campaign> { return self.putRequest(`/api/relay/rest/registry/beta/campaigns/${campaignId}`, request, (request) => ({ name: request.name }), (json) => ({ id: json.id, name: json.name, smsUseCase: json.sms_use_case, subUseCases: json.sub_use_cases, description: json.description, sample1: json.sample1, sample2: json.sample2, sample3: json.sample3, sample4: json.sample4, sample5: json.sample5, dynamicTemplates: json.dynamic_templates, messageFlow: json.message_flow, optInMessage: json.opt_in_message, optOutMessage: json.opt_out_message, helpMessage: json.help_message, numberPoolingRequired: json.number_pooling_required, numberPoolingPerCampaign: json.number_pooling_per_campaign, directLending: json.direct_lending, embeddedLink: json.embedded_link, embeddedPhone: json.embedded_phone, ageGatedContent: json.age_gated_content, leadGeneration: json.lead_generation, termsAndConditions: json.terms_and_conditions, createdAt: json.created_at, updatedAt: json.updated_at })); }, async createCampaign(brandId: string, request: CreateCampaignRequest): Promise<Campaign> { return self.postRequest(`/api/relay/rest/registry/beta/brands/${brandId}/campaigns`, request, (request) => ({ name: request.name, sms_use_case: request.smsUseCase, sub_use_cases: request.subUseCases, description: request.description, sample1: request.sample1, sample2: request.sample2, sample3: request.sample3, sample4: request.sample4, sample5: request.sample5, dynamic_templates: request.dynamicTemplates, message_flow: request.messageFlow, opt_in_message: request.optInMessage, opt_out_message: request.optOutMessage, help_message: request.helpMessage, number_pooling_required: request.numberPoolingRequired, number_pooling_per_campaign: request.numberPoolingPerCampaign, direct_lending: request.directLending, embedded_link: request.embeddedLink, embedded_phone: request.embeddedPhone, age_gated_content: request.ageGatedContent, lead_generation: request.leadGeneration, terms_and_conditions: request.termsAndConditions, }), (json) => ({ id: json.id, name: json.name, smsUseCase: json.sms_use_case, subUseCases: json.sub_use_cases, description: json.description, sample1: json.sample1, sample2: json.sample2, sample3: json.sample3, sample4: json.sample4, sample5: json.sample5, dynamicTemplates: json.dynamic_templates, messageFlow: json.message_flow, optInMessage: json.opt_in_message, optOutMessage: json.opt_out_message, helpMessage: json.help_message, numberPoolingRequired: json.number_pooling_required, numberPoolingPerCampaign: json.number_pooling_per_campaign, directLending: json.direct_lending, embeddedLink: json.embedded_link, embeddedPhone: json.embedded_phone, ageGatedContent: json.age_gated_content, leadGeneration: json.lead_generation, termsAndConditions: json.terms_and_conditions, createdAt: json.created_at, updatedAt: json.updated_at })); } }, campaignNumberAssignments: { listAllPhoneNumberAssignments(campaignId: string, options?: ListAllCampaignPhoneNumberAssignmentsOptions): AsyncIterableIterator<any> { const params: QueryParams = {}; if (options?.filterState) { params.filter_state = options.filterState; } return self.getRequestIterator(`/api/relay/rest/registry/beta/campaigns/${campaignId}/numbers`, (item) => (item), params); }, async listAllPhoneNumberAssignmentsPage(campaignId: string, options?: ListAllCampaignPhoneNumberAssignmentsOptions, url?: string): Promise<PagedResponse<any>> { const params: QueryParams = {}; if (options?.filterState) { params.filter_state = options.filterState; } return self.getRequestPage(`/api/relay/rest/registry/beta/campaigns/${campaignId}/numbers`, (item) => (item), url, params); }, listAllPhoneNumberAssignmentOrders(campaignId: string, options?: ListAllCampaignPhoneNumberAssignmentOrdersOptions): AsyncIterableIterator<CampaignPhoneNumberAssignmentOrder> { const params: QueryParams = {}; if (options?.filterState) { params.filter_state = options.filterState; } return self.getRequestIterator( `/api/relay/rest/registry/beta/campaigns/${campaignId}/orders`, (item) => ({ id: item.id, state: item.state, processedAt: item.processed_at, createdAt: item.created_at, updatedAt: item.updated_at, statusCallbackUrl: item.status_callback_url }), params); }, async listAllPhoneNumberAssignmentOrdersPage(campaignId: string, options?: ListAllCampaignPhoneNumberAssignmentOrdersOptions, url?: string): Promise<PagedResponse<CampaignPhoneNumberAssignmentOrder>> { const params: QueryParams = {}; if (options?.filterState) { params.filter_state = options.filterState; } return self.getRequestPage( `/api/relay/rest/registry/beta/campaigns/${campaignId}/numbers`, (item) => ({ id: item.id, state: item.state, processedAt: item.processed_at, createdAt: item.created_at, updatedAt: item.updated_at, statusCallbackUrl: item.status_callback_url }), url, params); }, async retrievePhoneNumberAssignmentOrder(assignmentOrderId: string): Promise<CampaignPhoneNumberAssignmentOrder> { return self.getRequest(`/api/relay/rest/registry/beta/orders/${assignmentOrderId}`, (json) => ({ id: json.id, state: json.state, processedAt: json.processed_at, createdAt: json.created_at, updatedAt: json.updated_at, statusCallbackUrl: json.status_callback_url })); }, async createPhoneNumberAssignmentOrder(campaignId: string, request: CreateCampaignPhoneNumberAssignmentOrderRequest): Promise<CampaignPhoneNumberAssignmentOrder> { return self.postRequest(`/api/relay/rest/registry/beta/campaigns/${campaignId}/orders`, request, (request) => ({ phone_numbers: request.phoneNumbers, }), (json) => ({ id: json.id, state: json.state, processedAt: json.processed_at, createdAt: json.created_at, updatedAt: json.updated_at, statusCallbackUrl: json.status_callback_url })); }, async deletePhoneNumberAssignment(numberAssignmentId: string): Promise<void> { return self.deleteRequest(`/api/relay/rest/registry/beta/numbers/${numberAssignmentId}`); } }, }, domainApplications: { listAllDomainApplications(options?: ListAllDomainApplicationsOptions): AsyncIterableIterator<DomainApplication> { const params: QueryParams = {}; if (options?.filterDomain) { params.filter_domain = options.filterDomain; } if (options?.filterName) { params.filter_name = options.filterName; } return self.getRequestIterator('/api/relay/rest/domain_applications', convertJSONToDomainApplication, params); }, async listAllDomainApplicationsPage(options?: ListAllDomainApplicationsOptions, url?: string): Promise<PagedResponse<DomainApplication>> { const params: QueryParams = {}; if (options?.filterDomain) { params.filter_domain = options.filterDomain; } if (options?.filterName) { params.filter_name = options.filterName; } return self.getRequestPage('/api/relay/rest/domain_applications', convertJSONToDomainApplication, url, params); }, async retrieveDomainApplication(domainApplicationId: st