From 15c6fe29a55a137d70f8fc52a13ecefed7e0a40c Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Thu, 16 Nov 2023 13:29:26 +0530 Subject: [PATCH] chore: changes for json ingress --- .github/workflows/test-and-deploy.yml | 6 +- CHANGES.md | 4 + CONTRIBUTING.md | 2 +- LICENSE | 2 +- UPGRADE.md | 10 + package.json | 4 +- src/base/RequestClient.ts | 12 +- src/rest/Oauth.ts | 52 ---- src/rest/PreviewMessaging.ts | 13 + .../{OauthBase.ts => PreviewMessagingBase.ts} | 10 +- src/rest/Twilio.ts | 8 - src/rest/oauth/V1.ts | 74 ----- src/rest/oauth/v1/deviceCode.ts | 192 ------------- src/rest/oauth/v1/oauth.ts | 185 ------------ src/rest/oauth/v1/openidDiscovery.ts | 266 ----------------- src/rest/oauth/v1/token.ts | 204 ------------- src/rest/oauth/v1/userInfo.ts | 213 -------------- src/rest/previewMessaging/V1.ts | 46 +++ src/rest/previewMessaging/v1/broadcast.ts | 208 ++++++++++++++ src/rest/previewMessaging/v1/message.ts | 272 ++++++++++++++++++ 20 files changed, 574 insertions(+), 1209 deletions(-) delete mode 100644 src/rest/Oauth.ts create mode 100644 src/rest/PreviewMessaging.ts rename src/rest/{OauthBase.ts => PreviewMessagingBase.ts} (76%) delete mode 100644 src/rest/oauth/V1.ts delete mode 100644 src/rest/oauth/v1/deviceCode.ts delete mode 100644 src/rest/oauth/v1/oauth.ts delete mode 100644 src/rest/oauth/v1/openidDiscovery.ts delete mode 100644 src/rest/oauth/v1/token.ts delete mode 100644 src/rest/oauth/v1/userInfo.ts create mode 100644 src/rest/previewMessaging/V1.ts create mode 100644 src/rest/previewMessaging/v1/broadcast.ts create mode 100644 src/rest/previewMessaging/v1/message.ts diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 760cac0d8f..ad07a0db9a 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -17,7 +17,7 @@ jobs: timeout-minutes: 20 strategy: matrix: - node: [ 14, 16, 18, lts/* ] + node: [ 14, 16, 18 ] steps: - name: Checkout twilio-node uses: actions/checkout@v3 @@ -49,7 +49,7 @@ jobs: npm run test - name: SonarCloud Scan - if: ${{ (github.event_name == 'pull_request' || github.ref_type == 'branch') && matrix.node == 'lts/*' && !github.event.pull_request.head.repo.fork }} + if: ${{ (github.event_name == 'pull_request' || github.ref_type == 'branch') && matrix.node == '18' && !github.event.pull_request.head.repo.fork }} uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any @@ -69,7 +69,7 @@ jobs: - name: Set up Node uses: actions/setup-node@v3 with: - node-version: lts/* + node-version: 18 - run: npm install diff --git a/CHANGES.md b/CHANGES.md index 4c86cb6f19..44504c27b8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ twilio-node changelog ===================== +[2023-11-07] Version 5.0.0-rc.0 +--------------------------- +- Release Candidate preparation + [2023-11-06] Version 4.19.1 --------------------------- **Flex** diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 171e93b925..b008f1fe57 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,7 +22,7 @@ it can be. If you have questions about how to use `twilio-node`, please see our [docs](./README.md), and if you don't find the answer there, please contact -[help@twilio.com](mailto:help@twilio.com) with any issues you have. +[Twilio Support](https://www.twilio.com/help/contact) with any issues you have. ## Found an Issue? diff --git a/LICENSE b/LICENSE index ca16167a61..6485c1f845 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (C) 2023, Twilio, Inc. +Copyright (C) 2023, Twilio, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/UPGRADE.md b/UPGRADE.md index 7c8df9ba90..446d529338 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,6 +2,16 @@ _All `MAJOR` version bumps will have upgrade notes posted here._ +## [2023-10-17] 4.x.x to 5.x.x-rc.x + +--- +### Overview + +#### Twilio Node Helper Library’s major version 5.0.0-rc.x is now available. We ensured that you can upgrade to Node helper Library 5.0.0-rc.x version without any breaking changes + +Support for JSON payloads has been added in the request body + + ## [2023-01-25] 3.x.x to 4.x.x --- diff --git a/package.json b/package.json index 87814fbf9a..d18359e632 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "twilio", "description": "A Twilio helper library", - "version": "4.19.1", + "version": "5.0.0-rc.0", "author": "API Team ", "contributors": [ { @@ -20,7 +20,7 @@ "url": "https://github.com/twilio/twilio-node.git" }, "dependencies": { - "axios": "^0.26.1", + "axios": "^1.6.0", "dayjs": "^1.11.9", "https-proxy-agent": "^5.0.0", "jsonwebtoken": "^9.0.0", diff --git a/src/base/RequestClient.ts b/src/base/RequestClient.ts index 002f2866e4..a7d1c5531b 100644 --- a/src/base/RequestClient.ts +++ b/src/base/RequestClient.ts @@ -57,7 +57,7 @@ function getExponentialBackoffResponseHandler( ); const delay = Math.floor(baseDelay * Math.random()); // Full jitter backoff - return new Promise((resolve) => { + return new Promise((resolve: (value: Promise) => void) => { setTimeout(() => resolve(axios(config)), delay); }); } @@ -190,8 +190,14 @@ class RequestClient { validateStatus: (status) => status >= 100 && status < 600, }; - if (opts.data) { - options.data = qs.stringify(opts.data, { arrayFormat: "repeat" }); + if (opts.data && options.headers) { + if ( + options.headers["Content-Type"] === "application/x-www-form-urlencoded" + ) { + options.data = qs.stringify(opts.data, { arrayFormat: "repeat" }); + } else if (options.headers["Content-Type"] === "application/json") { + options.data = opts.data; + } } if (opts.params) { diff --git a/src/rest/Oauth.ts b/src/rest/Oauth.ts deleted file mode 100644 index 5e0708b239..0000000000 --- a/src/rest/Oauth.ts +++ /dev/null @@ -1,52 +0,0 @@ -import OauthBase from "./OauthBase"; -import { OauthListInstance } from "./oauth/v1/oauth"; -import { DeviceCodeListInstance } from "./oauth/v1/deviceCode"; -import { OpenidDiscoveryListInstance } from "./oauth/v1/openidDiscovery"; -import { TokenListInstance } from "./oauth/v1/token"; -import { UserInfoListInstance } from "./oauth/v1/userInfo"; - -class Oauth extends OauthBase { - /** - * @deprecated - Use v1.deviceCode instead - */ - get deviceCode(): DeviceCodeListInstance { - console.warn("deviceCode is deprecated. Use v1.deviceCode instead."); - return this.v1.deviceCode; - } - - /** - * @deprecated - Use v1.oauth instead - */ - get oauth(): OauthListInstance { - console.warn("oauth is deprecated. Use v1.oauth instead."); - return this.v1.oauth; - } - - /** - * @deprecated - Use v1.openidDiscovery instead - */ - get openidDiscovery(): OpenidDiscoveryListInstance { - console.warn( - "openidDiscovery is deprecated. Use v1.openidDiscovery instead." - ); - return this.v1.openidDiscovery; - } - - /** - * @deprecated - Use v1.token instead - */ - get token(): TokenListInstance { - console.warn("token is deprecated. Use v1.token instead."); - return this.v1.token; - } - - /** - * @deprecated - Use v1.userInfo instead - */ - get userInfo(): UserInfoListInstance { - console.warn("userInfo is deprecated. Use v1.userInfo instead."); - return this.v1.userInfo; - } -} - -export = Oauth; diff --git a/src/rest/PreviewMessaging.ts b/src/rest/PreviewMessaging.ts new file mode 100644 index 0000000000..dc598c3a77 --- /dev/null +++ b/src/rest/PreviewMessaging.ts @@ -0,0 +1,13 @@ +import PreviewMessagingBase from "./PreviewMessagingBase"; +import { MessageListInstance } from "./previewMessaging/v1/message"; + +class PreviewMessaging extends PreviewMessagingBase { + /** + * @deprecated - Use v1.messages; instead + */ + get messages(): MessageListInstance { + console.warn("messages is deprecated. Use v1.messages; instead."); + return this.v1.messages; + } +} +export = PreviewMessaging; diff --git a/src/rest/OauthBase.ts b/src/rest/PreviewMessagingBase.ts similarity index 76% rename from src/rest/OauthBase.ts rename to src/rest/PreviewMessagingBase.ts index 513dd037f3..44e88ea83a 100644 --- a/src/rest/OauthBase.ts +++ b/src/rest/PreviewMessagingBase.ts @@ -10,18 +10,18 @@ */ import Domain from "../base/Domain"; -import V1 from "./oauth/V1"; +import V1 from "./previewMessaging/V1"; -class OauthBase extends Domain { +class PreviewMessagingBase extends Domain { _v1?: V1; /** - * Initialize oauth domain + * Initialize accounts domain * * @param twilio - The twilio client */ constructor(twilio: any) { - super(twilio, "https://oauth.twilio.com"); + super(twilio, "https://preview.messaging.twilio.com"); } get v1(): V1 { @@ -30,4 +30,4 @@ class OauthBase extends Domain { } } -export = OauthBase; +export = PreviewMessagingBase; diff --git a/src/rest/Twilio.ts b/src/rest/Twilio.ts index 1a21d3a500..3543d11e94 100644 --- a/src/rest/Twilio.ts +++ b/src/rest/Twilio.ts @@ -30,7 +30,6 @@ import Microvisor from "./Microvisor"; import Monitor from "./Monitor"; import Notify from "./Notify"; import Numbers from "./Numbers"; -import Oauth from "./Oauth"; import Preview from "./Preview"; import Pricing from "./Pricing"; import Proxy from "./Proxy"; @@ -118,8 +117,6 @@ class Twilio extends Client { _notify?: Notify; /** (Twilio.Numbers) - numbers domain */ _numbers?: Numbers; - /** (Twilio.Oauth) - oauth domain */ - _oauth?: Oauth; /** (Twilio.Preview) - preview domain */ _preview?: Preview; /** (Twilio.Pricing) - pricing domain */ @@ -188,7 +185,6 @@ class Twilio extends Client { this.monitor; this.notify; this.numbers; - this.oauth; this.preview; this.pricing; this.proxy; @@ -314,10 +310,6 @@ class Twilio extends Client { get numbers(): Numbers { return this._numbers ?? (this._numbers = new (require("./Numbers"))(this)); } - /** Getter for (Twilio.Oauth) domain */ - get oauth(): Oauth { - return this._oauth ?? (this._oauth = new (require("./Oauth"))(this)); - } /** Getter for (Twilio.Preview) domain */ get preview(): Preview { return this._preview ?? (this._preview = new (require("./Preview"))(this)); diff --git a/src/rest/oauth/V1.ts b/src/rest/oauth/V1.ts deleted file mode 100644 index ab2759f368..0000000000 --- a/src/rest/oauth/V1.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Twilio - Oauth - * This is the public Twilio REST API. - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import OauthBase from "../OauthBase"; -import Version from "../../base/Version"; -import { DeviceCodeListInstance } from "./v1/deviceCode"; -import { OauthListInstance } from "./v1/oauth"; -import { OpenidDiscoveryListInstance } from "./v1/openidDiscovery"; -import { TokenListInstance } from "./v1/token"; -import { UserInfoListInstance } from "./v1/userInfo"; - -export default class V1 extends Version { - /** - * Initialize the V1 version of Oauth - * - * @param domain - The Twilio (Twilio.Oauth) domain - */ - constructor(domain: OauthBase) { - super(domain, "v1"); - } - - /** deviceCode - { Twilio.Oauth.V1.DeviceCodeListInstance } resource */ - protected _deviceCode?: DeviceCodeListInstance; - /** oauth - { Twilio.Oauth.V1.OauthListInstance } resource */ - protected _oauth?: OauthListInstance; - /** openidDiscovery - { Twilio.Oauth.V1.OpenidDiscoveryListInstance } resource */ - protected _openidDiscovery?: OpenidDiscoveryListInstance; - /** token - { Twilio.Oauth.V1.TokenListInstance } resource */ - protected _token?: TokenListInstance; - /** userInfo - { Twilio.Oauth.V1.UserInfoListInstance } resource */ - protected _userInfo?: UserInfoListInstance; - - /** Getter for deviceCode resource */ - get deviceCode(): DeviceCodeListInstance { - this._deviceCode = this._deviceCode || DeviceCodeListInstance(this); - return this._deviceCode; - } - - /** Getter for oauth resource */ - get oauth(): OauthListInstance { - this._oauth = this._oauth || OauthListInstance(this); - return this._oauth; - } - - /** Getter for openidDiscovery resource */ - get openidDiscovery(): OpenidDiscoveryListInstance { - this._openidDiscovery = - this._openidDiscovery || OpenidDiscoveryListInstance(this); - return this._openidDiscovery; - } - - /** Getter for token resource */ - get token(): TokenListInstance { - this._token = this._token || TokenListInstance(this); - return this._token; - } - - /** Getter for userInfo resource */ - get userInfo(): UserInfoListInstance { - this._userInfo = this._userInfo || UserInfoListInstance(this); - return this._userInfo; - } -} diff --git a/src/rest/oauth/v1/deviceCode.ts b/src/rest/oauth/v1/deviceCode.ts deleted file mode 100644 index da60047a46..0000000000 --- a/src/rest/oauth/v1/deviceCode.ts +++ /dev/null @@ -1,192 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Twilio - Oauth - * This is the public Twilio REST API. - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { inspect, InspectOptions } from "util"; -import V1 from "../V1"; -const deserialize = require("../../../base/deserialize"); -const serialize = require("../../../base/serialize"); -import { isValidPathParam } from "../../../base/utility"; - -/** - * Options to pass to create a DeviceCodeInstance - */ -export interface DeviceCodeListInstanceCreateOptions { - /** A 34 character string that uniquely identifies this OAuth App. */ - clientSid: string; - /** An Array of scopes for authorization request */ - scopes: Array; - /** An array of intended audiences for token requests */ - audiences?: Array; -} - -export interface DeviceCodeSolution {} - -export interface DeviceCodeListInstance { - _version: V1; - _solution: DeviceCodeSolution; - _uri: string; - - /** - * Create a DeviceCodeInstance - * - * @param params - Parameter for request - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed DeviceCodeInstance - */ - create( - params: DeviceCodeListInstanceCreateOptions, - callback?: (error: Error | null, item?: DeviceCodeInstance) => any - ): Promise; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export function DeviceCodeListInstance(version: V1): DeviceCodeListInstance { - const instance = {} as DeviceCodeListInstance; - - instance._version = version; - instance._solution = {}; - instance._uri = `/device/code`; - - instance.create = function create( - params: DeviceCodeListInstanceCreateOptions, - callback?: (error: Error | null, items: DeviceCodeInstance) => any - ): Promise { - if (params === null || params === undefined) { - throw new Error('Required parameter "params" missing.'); - } - - if (params["clientSid"] === null || params["clientSid"] === undefined) { - throw new Error("Required parameter \"params['clientSid']\" missing."); - } - - if (params["scopes"] === null || params["scopes"] === undefined) { - throw new Error("Required parameter \"params['scopes']\" missing."); - } - - let data: any = {}; - - data["ClientSid"] = params["clientSid"]; - - data["Scopes"] = serialize.map(params["scopes"], (e: string) => e); - if (params["audiences"] !== undefined) - data["Audiences"] = serialize.map(params["audiences"], (e: string) => e); - - const headers: any = {}; - headers["Content-Type"] = "application/x-www-form-urlencoded"; - - let operationVersion = version, - operationPromise = operationVersion.create({ - uri: instance._uri, - method: "post", - data, - headers, - }); - - operationPromise = operationPromise.then( - (payload) => new DeviceCodeInstance(operationVersion, payload) - ); - - operationPromise = instance._version.setPromiseCallback( - operationPromise, - callback - ); - return operationPromise; - }; - - instance.toJSON = function toJSON() { - return instance._solution; - }; - - instance[inspect.custom] = function inspectImpl( - _depth: any, - options: InspectOptions - ) { - return inspect(instance.toJSON(), options); - }; - - return instance; -} - -interface DeviceCodePayload extends DeviceCodeResource {} - -interface DeviceCodeResource { - device_code: string; - user_code: string; - verification_uri: string; - verification_uri_complete: string; - expires_in: number; - interval: number; -} - -export class DeviceCodeInstance { - constructor(protected _version: V1, payload: DeviceCodeResource) { - this.deviceCode = payload.device_code; - this.userCode = payload.user_code; - this.verificationUri = payload.verification_uri; - this.verificationUriComplete = payload.verification_uri_complete; - this.expiresIn = payload.expires_in; - this.interval = deserialize.integer(payload.interval); - } - - /** - * The device verification code. - */ - deviceCode: string; - /** - * The verification code which end user uses to verify authorization request. - */ - userCode: string; - /** - * The URI that the end user visits to verify authorization request. - */ - verificationUri: string; - /** - * The URI with user_code that the end-user alternatively visits to verify authorization request. - */ - verificationUriComplete: string; - /** - * The expiration time of the device_code and user_code in seconds. - */ - expiresIn: number; - /** - * The minimum amount of time in seconds that the client should wait between polling requests to the token endpoint. - */ - interval: number; - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return { - deviceCode: this.deviceCode, - userCode: this.userCode, - verificationUri: this.verificationUri, - verificationUriComplete: this.verificationUriComplete, - expiresIn: this.expiresIn, - interval: this.interval, - }; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} diff --git a/src/rest/oauth/v1/oauth.ts b/src/rest/oauth/v1/oauth.ts deleted file mode 100644 index 7752f30008..0000000000 --- a/src/rest/oauth/v1/oauth.ts +++ /dev/null @@ -1,185 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Twilio - Oauth - * This is the public Twilio REST API. - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { inspect, InspectOptions } from "util"; -import V1 from "../V1"; -const deserialize = require("../../../base/deserialize"); -const serialize = require("../../../base/serialize"); -import { isValidPathParam } from "../../../base/utility"; - -export interface OauthContext { - /** - * Fetch a OauthInstance - * - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed OauthInstance - */ - fetch( - callback?: (error: Error | null, item?: OauthInstance) => any - ): Promise; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export interface OauthContextSolution {} - -export class OauthContextImpl implements OauthContext { - protected _solution: OauthContextSolution; - protected _uri: string; - - constructor(protected _version: V1) { - this._solution = {}; - this._uri = `/certs`; - } - - fetch( - callback?: (error: Error | null, item?: OauthInstance) => any - ): Promise { - const instance = this; - let operationVersion = instance._version, - operationPromise = operationVersion.fetch({ - uri: instance._uri, - method: "get", - }); - - operationPromise = operationPromise.then( - (payload) => new OauthInstance(operationVersion, payload) - ); - - operationPromise = instance._version.setPromiseCallback( - operationPromise, - callback - ); - return operationPromise; - } - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return this._solution; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} - -interface OauthPayload extends OauthResource {} - -interface OauthResource { - keys: any; - url: string; -} - -export class OauthInstance { - protected _solution: OauthContextSolution; - protected _context?: OauthContext; - - constructor(protected _version: V1, payload: OauthResource) { - this.keys = payload.keys; - this.url = payload.url; - - this._solution = {}; - } - - /** - * A collection of certificates where are signed Twilio-issued tokens. - */ - keys: any; - url: string; - - private get _proxy(): OauthContext { - this._context = this._context || new OauthContextImpl(this._version); - return this._context; - } - - /** - * Fetch a OauthInstance - * - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed OauthInstance - */ - fetch( - callback?: (error: Error | null, item?: OauthInstance) => any - ): Promise { - return this._proxy.fetch(callback); - } - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return { - keys: this.keys, - url: this.url, - }; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} - -export interface OauthSolution {} - -export interface OauthListInstance { - _version: V1; - _solution: OauthSolution; - _uri: string; - - (): OauthContext; - get(): OauthContext; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export function OauthListInstance(version: V1): OauthListInstance { - const instance = (() => instance.get()) as OauthListInstance; - - instance.get = function get(): OauthContext { - return new OauthContextImpl(version); - }; - - instance._version = version; - instance._solution = {}; - instance._uri = ``; - - instance.toJSON = function toJSON() { - return instance._solution; - }; - - instance[inspect.custom] = function inspectImpl( - _depth: any, - options: InspectOptions - ) { - return inspect(instance.toJSON(), options); - }; - - return instance; -} diff --git a/src/rest/oauth/v1/openidDiscovery.ts b/src/rest/oauth/v1/openidDiscovery.ts deleted file mode 100644 index 24b8aa9a9f..0000000000 --- a/src/rest/oauth/v1/openidDiscovery.ts +++ /dev/null @@ -1,266 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Twilio - Oauth - * This is the public Twilio REST API. - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { inspect, InspectOptions } from "util"; -import V1 from "../V1"; -const deserialize = require("../../../base/deserialize"); -const serialize = require("../../../base/serialize"); -import { isValidPathParam } from "../../../base/utility"; - -export interface OpenidDiscoveryContext { - /** - * Fetch a OpenidDiscoveryInstance - * - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed OpenidDiscoveryInstance - */ - fetch( - callback?: (error: Error | null, item?: OpenidDiscoveryInstance) => any - ): Promise; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export interface OpenidDiscoveryContextSolution {} - -export class OpenidDiscoveryContextImpl implements OpenidDiscoveryContext { - protected _solution: OpenidDiscoveryContextSolution; - protected _uri: string; - - constructor(protected _version: V1) { - this._solution = {}; - this._uri = `/.well-known/openid-configuration`; - } - - fetch( - callback?: (error: Error | null, item?: OpenidDiscoveryInstance) => any - ): Promise { - const instance = this; - let operationVersion = instance._version, - operationPromise = operationVersion.fetch({ - uri: instance._uri, - method: "get", - }); - - operationPromise = operationPromise.then( - (payload) => new OpenidDiscoveryInstance(operationVersion, payload) - ); - - operationPromise = instance._version.setPromiseCallback( - operationPromise, - callback - ); - return operationPromise; - } - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return this._solution; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} - -interface OpenidDiscoveryPayload extends OpenidDiscoveryResource {} - -interface OpenidDiscoveryResource { - issuer: string; - authorization_endpoint: string; - device_authorization_endpoint: string; - token_endpoint: string; - userinfo_endpoint: string; - revocation_endpoint: string; - jwk_uri: string; - response_type_supported: Array; - subject_type_supported: Array; - id_token_signing_alg_values_supported: Array; - scopes_supported: Array; - claims_supported: Array; - url: string; -} - -export class OpenidDiscoveryInstance { - protected _solution: OpenidDiscoveryContextSolution; - protected _context?: OpenidDiscoveryContext; - - constructor(protected _version: V1, payload: OpenidDiscoveryResource) { - this.issuer = payload.issuer; - this.authorizationEndpoint = payload.authorization_endpoint; - this.deviceAuthorizationEndpoint = payload.device_authorization_endpoint; - this.tokenEndpoint = payload.token_endpoint; - this.userinfoEndpoint = payload.userinfo_endpoint; - this.revocationEndpoint = payload.revocation_endpoint; - this.jwkUri = payload.jwk_uri; - this.responseTypeSupported = payload.response_type_supported; - this.subjectTypeSupported = payload.subject_type_supported; - this.idTokenSigningAlgValuesSupported = - payload.id_token_signing_alg_values_supported; - this.scopesSupported = payload.scopes_supported; - this.claimsSupported = payload.claims_supported; - this.url = payload.url; - - this._solution = {}; - } - - /** - * The URL of the party that will create the token and sign it with its private key. - */ - issuer: string; - /** - * The endpoint that validates all authorization requests. - */ - authorizationEndpoint: string; - /** - * The endpoint that validates all device code related authorization requests. - */ - deviceAuthorizationEndpoint: string; - /** - * The URL of the token endpoint. After a client has received an authorization code, that code is presented to the token endpoint and exchanged for an identity token, an access token, and a refresh token. - */ - tokenEndpoint: string; - /** - * The URL of the user info endpoint, which returns user profile information to a client. Keep in mind that the user info endpoint returns only the information that has been requested. - */ - userinfoEndpoint: string; - /** - * The endpoint used to revoke access or refresh tokens issued by the authorization server. - */ - revocationEndpoint: string; - /** - * The URL of your JSON Web Key Set. This set is a collection of JSON Web Keys, a standard method for representing cryptographic keys in a JSON structure. - */ - jwkUri: string; - /** - * A collection of response type supported by authorization server. - */ - responseTypeSupported: Array; - /** - * A collection of subject by authorization server. - */ - subjectTypeSupported: Array; - /** - * A collection of JWS signing algorithms supported by authorization server to sign identity token. - */ - idTokenSigningAlgValuesSupported: Array; - /** - * A collection of scopes supported by authorization server for identity token - */ - scopesSupported: Array; - /** - * A collection of claims supported by authorization server for identity token - */ - claimsSupported: Array; - url: string; - - private get _proxy(): OpenidDiscoveryContext { - this._context = - this._context || new OpenidDiscoveryContextImpl(this._version); - return this._context; - } - - /** - * Fetch a OpenidDiscoveryInstance - * - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed OpenidDiscoveryInstance - */ - fetch( - callback?: (error: Error | null, item?: OpenidDiscoveryInstance) => any - ): Promise { - return this._proxy.fetch(callback); - } - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return { - issuer: this.issuer, - authorizationEndpoint: this.authorizationEndpoint, - deviceAuthorizationEndpoint: this.deviceAuthorizationEndpoint, - tokenEndpoint: this.tokenEndpoint, - userinfoEndpoint: this.userinfoEndpoint, - revocationEndpoint: this.revocationEndpoint, - jwkUri: this.jwkUri, - responseTypeSupported: this.responseTypeSupported, - subjectTypeSupported: this.subjectTypeSupported, - idTokenSigningAlgValuesSupported: this.idTokenSigningAlgValuesSupported, - scopesSupported: this.scopesSupported, - claimsSupported: this.claimsSupported, - url: this.url, - }; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} - -export interface OpenidDiscoverySolution {} - -export interface OpenidDiscoveryListInstance { - _version: V1; - _solution: OpenidDiscoverySolution; - _uri: string; - - (): OpenidDiscoveryContext; - get(): OpenidDiscoveryContext; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export function OpenidDiscoveryListInstance( - version: V1 -): OpenidDiscoveryListInstance { - const instance = (() => instance.get()) as OpenidDiscoveryListInstance; - - instance.get = function get(): OpenidDiscoveryContext { - return new OpenidDiscoveryContextImpl(version); - }; - - instance._version = version; - instance._solution = {}; - instance._uri = ``; - - instance.toJSON = function toJSON() { - return instance._solution; - }; - - instance[inspect.custom] = function inspectImpl( - _depth: any, - options: InspectOptions - ) { - return inspect(instance.toJSON(), options); - }; - - return instance; -} diff --git a/src/rest/oauth/v1/token.ts b/src/rest/oauth/v1/token.ts deleted file mode 100644 index 918bb2576b..0000000000 --- a/src/rest/oauth/v1/token.ts +++ /dev/null @@ -1,204 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Twilio - Oauth - * This is the public Twilio REST API. - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { inspect, InspectOptions } from "util"; -import V1 from "../V1"; -const deserialize = require("../../../base/deserialize"); -const serialize = require("../../../base/serialize"); -import { isValidPathParam } from "../../../base/utility"; - -/** - * Options to pass to create a TokenInstance - */ -export interface TokenListInstanceCreateOptions { - /** Grant type is a credential representing resource owner\\\'s authorization which can be used by client to obtain access token. */ - grantType: string; - /** A 34 character string that uniquely identifies this OAuth App. */ - clientSid: string; - /** The credential for confidential OAuth App. */ - clientSecret?: string; - /** JWT token related to the authorization code grant type. */ - code?: string; - /** A code which is generation cryptographically. */ - codeVerifier?: string; - /** JWT token related to the device code grant type. */ - deviceCode?: string; - /** JWT token related to the refresh token grant type. */ - refreshToken?: string; - /** The Id of the device associated with the token (refresh token). */ - deviceId?: string; -} - -export interface TokenSolution {} - -export interface TokenListInstance { - _version: V1; - _solution: TokenSolution; - _uri: string; - - /** - * Create a TokenInstance - * - * @param params - Parameter for request - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed TokenInstance - */ - create( - params: TokenListInstanceCreateOptions, - callback?: (error: Error | null, item?: TokenInstance) => any - ): Promise; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export function TokenListInstance(version: V1): TokenListInstance { - const instance = {} as TokenListInstance; - - instance._version = version; - instance._solution = {}; - instance._uri = `/token`; - - instance.create = function create( - params: TokenListInstanceCreateOptions, - callback?: (error: Error | null, items: TokenInstance) => any - ): Promise { - if (params === null || params === undefined) { - throw new Error('Required parameter "params" missing.'); - } - - if (params["grantType"] === null || params["grantType"] === undefined) { - throw new Error("Required parameter \"params['grantType']\" missing."); - } - - if (params["clientSid"] === null || params["clientSid"] === undefined) { - throw new Error("Required parameter \"params['clientSid']\" missing."); - } - - let data: any = {}; - - data["GrantType"] = params["grantType"]; - - data["ClientSid"] = params["clientSid"]; - if (params["clientSecret"] !== undefined) - data["ClientSecret"] = params["clientSecret"]; - if (params["code"] !== undefined) data["Code"] = params["code"]; - if (params["codeVerifier"] !== undefined) - data["CodeVerifier"] = params["codeVerifier"]; - if (params["deviceCode"] !== undefined) - data["DeviceCode"] = params["deviceCode"]; - if (params["refreshToken"] !== undefined) - data["RefreshToken"] = params["refreshToken"]; - if (params["deviceId"] !== undefined) data["DeviceId"] = params["deviceId"]; - - const headers: any = {}; - headers["Content-Type"] = "application/x-www-form-urlencoded"; - - let operationVersion = version, - operationPromise = operationVersion.create({ - uri: instance._uri, - method: "post", - data, - headers, - }); - - operationPromise = operationPromise.then( - (payload) => new TokenInstance(operationVersion, payload) - ); - - operationPromise = instance._version.setPromiseCallback( - operationPromise, - callback - ); - return operationPromise; - }; - - instance.toJSON = function toJSON() { - return instance._solution; - }; - - instance[inspect.custom] = function inspectImpl( - _depth: any, - options: InspectOptions - ) { - return inspect(instance.toJSON(), options); - }; - - return instance; -} - -interface TokenPayload extends TokenResource {} - -interface TokenResource { - access_token: string; - refresh_token: string; - id_token: string; - refresh_token_expires_at: Date; - access_token_expires_at: Date; -} - -export class TokenInstance { - constructor(protected _version: V1, payload: TokenResource) { - this.accessToken = payload.access_token; - this.refreshToken = payload.refresh_token; - this.idToken = payload.id_token; - this.refreshTokenExpiresAt = deserialize.iso8601DateTime( - payload.refresh_token_expires_at - ); - this.accessTokenExpiresAt = deserialize.iso8601DateTime( - payload.access_token_expires_at - ); - } - - /** - * Token which carries the necessary information to access a Twilio resource directly. - */ - accessToken: string; - /** - * Token which carries the information necessary to get a new access token. - */ - refreshToken: string; - idToken: string; - /** - * The date and time in GMT when the refresh token expires in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. - */ - refreshTokenExpiresAt: Date; - /** - * The date and time in GMT when the refresh token expires in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. - */ - accessTokenExpiresAt: Date; - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return { - accessToken: this.accessToken, - refreshToken: this.refreshToken, - idToken: this.idToken, - refreshTokenExpiresAt: this.refreshTokenExpiresAt, - accessTokenExpiresAt: this.accessTokenExpiresAt, - }; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} diff --git a/src/rest/oauth/v1/userInfo.ts b/src/rest/oauth/v1/userInfo.ts deleted file mode 100644 index 5b974309b8..0000000000 --- a/src/rest/oauth/v1/userInfo.ts +++ /dev/null @@ -1,213 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Twilio - Oauth - * This is the public Twilio REST API. - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { inspect, InspectOptions } from "util"; -import V1 from "../V1"; -const deserialize = require("../../../base/deserialize"); -const serialize = require("../../../base/serialize"); -import { isValidPathParam } from "../../../base/utility"; - -export interface UserInfoContext { - /** - * Fetch a UserInfoInstance - * - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed UserInfoInstance - */ - fetch( - callback?: (error: Error | null, item?: UserInfoInstance) => any - ): Promise; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export interface UserInfoContextSolution {} - -export class UserInfoContextImpl implements UserInfoContext { - protected _solution: UserInfoContextSolution; - protected _uri: string; - - constructor(protected _version: V1) { - this._solution = {}; - this._uri = `/userinfo`; - } - - fetch( - callback?: (error: Error | null, item?: UserInfoInstance) => any - ): Promise { - const instance = this; - let operationVersion = instance._version, - operationPromise = operationVersion.fetch({ - uri: instance._uri, - method: "get", - }); - - operationPromise = operationPromise.then( - (payload) => new UserInfoInstance(operationVersion, payload) - ); - - operationPromise = instance._version.setPromiseCallback( - operationPromise, - callback - ); - return operationPromise; - } - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return this._solution; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} - -interface UserInfoPayload extends UserInfoResource {} - -interface UserInfoResource { - user_sid: string; - first_name: string; - last_name: string; - friendly_name: string; - email: string; - url: string; -} - -export class UserInfoInstance { - protected _solution: UserInfoContextSolution; - protected _context?: UserInfoContext; - - constructor(protected _version: V1, payload: UserInfoResource) { - this.userSid = payload.user_sid; - this.firstName = payload.first_name; - this.lastName = payload.last_name; - this.friendlyName = payload.friendly_name; - this.email = payload.email; - this.url = payload.url; - - this._solution = {}; - } - - /** - * The URL of the party that will create the token and sign it with its private key. - */ - userSid: string; - /** - * The first name of the end-user. - */ - firstName: string; - /** - * The last name of the end-user. - */ - lastName: string; - /** - * The friendly name of the end-user. - */ - friendlyName: string; - /** - * The end-user\'s preferred email address. - */ - email: string; - url: string; - - private get _proxy(): UserInfoContext { - this._context = this._context || new UserInfoContextImpl(this._version); - return this._context; - } - - /** - * Fetch a UserInfoInstance - * - * @param callback - Callback to handle processed record - * - * @returns Resolves to processed UserInfoInstance - */ - fetch( - callback?: (error: Error | null, item?: UserInfoInstance) => any - ): Promise { - return this._proxy.fetch(callback); - } - - /** - * Provide a user-friendly representation - * - * @returns Object - */ - toJSON() { - return { - userSid: this.userSid, - firstName: this.firstName, - lastName: this.lastName, - friendlyName: this.friendlyName, - email: this.email, - url: this.url, - }; - } - - [inspect.custom](_depth: any, options: InspectOptions) { - return inspect(this.toJSON(), options); - } -} - -export interface UserInfoSolution {} - -export interface UserInfoListInstance { - _version: V1; - _solution: UserInfoSolution; - _uri: string; - - (): UserInfoContext; - get(): UserInfoContext; - - /** - * Provide a user-friendly representation - */ - toJSON(): any; - [inspect.custom](_depth: any, options: InspectOptions): any; -} - -export function UserInfoListInstance(version: V1): UserInfoListInstance { - const instance = (() => instance.get()) as UserInfoListInstance; - - instance.get = function get(): UserInfoContext { - return new UserInfoContextImpl(version); - }; - - instance._version = version; - instance._solution = {}; - instance._uri = ``; - - instance.toJSON = function toJSON() { - return instance._solution; - }; - - instance[inspect.custom] = function inspectImpl( - _depth: any, - options: InspectOptions - ) { - return inspect(instance.toJSON(), options); - }; - - return instance; -} diff --git a/src/rest/previewMessaging/V1.ts b/src/rest/previewMessaging/V1.ts new file mode 100644 index 0000000000..e30d2a40ca --- /dev/null +++ b/src/rest/previewMessaging/V1.ts @@ -0,0 +1,46 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Bulk Messaging and Broadcast + * Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import PreviewMessagingBase from "../PreviewMessagingBase"; +import Version from "../../base/Version"; +import { BroadcastListInstance } from "./v1/broadcast"; +import { MessageListInstance } from "./v1/message"; + +export default class V1 extends Version { + /** + * Initialize the V1 version of PreviewMessaging + * + * @param domain - The Twilio (Twilio.PreviewMessaging) domain + */ + constructor(domain: PreviewMessagingBase) { + super(domain, "v1"); + } + + /** broadcasts - { Twilio.PreviewMessaging.V1.BroadcastListInstance } resource */ + protected _broadcasts?: BroadcastListInstance; + /** messages - { Twilio.PreviewMessaging.V1.MessageListInstance } resource */ + protected _messages?: MessageListInstance; + + /** Getter for broadcasts resource */ + get broadcasts(): BroadcastListInstance { + this._broadcasts = this._broadcasts || BroadcastListInstance(this); + return this._broadcasts; + } + + /** Getter for messages resource */ + get messages(): MessageListInstance { + this._messages = this._messages || MessageListInstance(this); + return this._messages; + } +} diff --git a/src/rest/previewMessaging/v1/broadcast.ts b/src/rest/previewMessaging/v1/broadcast.ts new file mode 100644 index 0000000000..099f613895 --- /dev/null +++ b/src/rest/previewMessaging/v1/broadcast.ts @@ -0,0 +1,208 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Bulk Messaging and Broadcast + * Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + +/** + * Details on the statuses of messages sent to recipients + */ +export class MessagingV1BroadcastExecutionDetails { + /** + * Number of recipients in the Broadcast request + */ + "totalRecords"?: number; + /** + * Number of recipients with messages successfully sent to them + */ + "totalCompleted"?: number; + /** + * Number of recipients with messages unsuccessfully sent to them, producing an error + */ + "totalErrors"?: number; +} + +/** + * Options to pass to create a BroadcastInstance + */ +export interface BroadcastListInstanceCreateOptions { + /** Idempotency key provided by the client */ + xTwilioRequestKey?: string; +} + +export interface BroadcastSolution {} + +export interface BroadcastListInstance { + _version: V1; + _solution: BroadcastSolution; + _uri: string; + + /** + * Create a BroadcastInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed BroadcastInstance + */ + create( + callback?: (error: Error | null, item?: BroadcastInstance) => any + ): Promise; + /** + * Create a BroadcastInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed BroadcastInstance + */ + create( + params: BroadcastListInstanceCreateOptions, + callback?: (error: Error | null, item?: BroadcastInstance) => any + ): Promise; + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function BroadcastListInstance(version: V1): BroadcastListInstance { + const instance = {} as BroadcastListInstance; + + instance._version = version; + instance._solution = {}; + instance._uri = `/Broadcasts`; + + instance.create = function create( + params?: + | BroadcastListInstanceCreateOptions + | ((error: Error | null, items: BroadcastInstance) => any), + callback?: (error: Error | null, items: BroadcastInstance) => any + ): Promise { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + const headers: any = {}; + if (params["xTwilioRequestKey"] !== undefined) + headers["X-Twilio-Request-Key"] = params["xTwilioRequestKey"]; + + let operationVersion = version, + operationPromise = operationVersion.create({ + uri: instance._uri, + method: "post", + data, + headers, + }); + + operationPromise = operationPromise.then( + (payload) => new BroadcastInstance(operationVersion, payload) + ); + + operationPromise = instance._version.setPromiseCallback( + operationPromise, + callback + ); + return operationPromise; + }; + + instance.toJSON = function toJSON() { + return instance._solution; + }; + + instance[inspect.custom] = function inspectImpl( + _depth: any, + options: InspectOptions + ) { + return inspect(instance.toJSON(), options); + }; + + return instance; +} + +interface BroadcastPayload extends BroadcastResource {} + +interface BroadcastResource { + broadcast_sid: string; + created_date: Date; + updated_date: Date; + broadcast_status: string; + execution_details: MessagingV1BroadcastExecutionDetails; + errors_file: string; +} + +/** + * Details of a Broadcast + */ +export class BroadcastInstance { + constructor(protected _version: V1, payload: BroadcastResource) { + this.broadcastSid = payload.broadcast_sid; + this.createdDate = deserialize.iso8601DateTime(payload.created_date); + this.updatedDate = deserialize.iso8601DateTime(payload.updated_date); + this.broadcastStatus = payload.broadcast_status; + this.executionDetails = payload.execution_details; + this.errorsFile = payload.errors_file; + } + + /** + * Numeric ID indentifying individual Broadcast requests + */ + broadcastSid: string; + /** + * Timestamp of when the Broadcast was created + */ + createdDate: Date; + /** + * Timestamp of when the Broadcast was last updated + */ + updatedDate: Date; + /** + * Status of the Broadcast request. Valid values are None, Pending-Upload, Uploaded, Queued, Executing, Execution-Failure, Execution-Completed, Cancelation-Requested, and Canceled + */ + broadcastStatus: string; + executionDetails: MessagingV1BroadcastExecutionDetails; + /** + * Path to a file detailing errors from Broadcast execution + */ + errorsFile: string; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + broadcastSid: this.broadcastSid, + createdDate: this.createdDate, + updatedDate: this.updatedDate, + broadcastStatus: this.broadcastStatus, + executionDetails: this.executionDetails, + errorsFile: this.errorsFile, + }; + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} diff --git a/src/rest/previewMessaging/v1/message.ts b/src/rest/previewMessaging/v1/message.ts new file mode 100644 index 0000000000..8ba125715c --- /dev/null +++ b/src/rest/previewMessaging/v1/message.ts @@ -0,0 +1,272 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Bulk Messaging and Broadcast + * Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + +export class CreateMessagesRequest { + "messages"?: Array; + /** + * A Twilio phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format, an [alphanumeric sender ID](https://www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id), or a [Channel Endpoint address](https://www.twilio.com/docs/sms/channels#channel-addresses) that is enabled for the type of message you want to send. Phone numbers or [short codes](https://www.twilio.com/docs/sms/api/short-code) purchased from Twilio also work here. You cannot, for example, spoof messages from a private cell phone number. If you are using `messaging_service_sid`, this parameter must be empty. + */ + "from"?: string; + /** + * The SID of the [Messaging Service](https://www.twilio.com/docs/sms/services#send-a-message-with-copilot) you want to associate with the Message. Set this parameter to use the [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) you have configured and leave the `from` parameter empty. When only this parameter is set, Twilio will use your enabled Copilot Features to select the `from` phone number for delivery. + */ + "messagingServiceSid"?: string; + /** + * The text of the message you want to send. Can be up to 1,600 characters in length. + */ + "body"?: string; + /** + * The SID of the preconfigured [Content Template](https://www.twilio.com/docs/content-api/create-and-send-your-first-content-api-template#create-a-template) you want to associate with the Message. Must be used in conjuction with a preconfigured [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) When this parameter is set, Twilio will use your configured content template and the provided `ContentVariables`. This Twilio product is currently in Private Beta. + */ + "contentSid"?: string; + /** + * The URL of the media to send with the message. The media can be of type `gif`, `png`, and `jpeg` and will be formatted correctly on the recipient\'s device. The media size limit is 5MB for supported file types (JPEG, PNG, GIF) and 500KB for [other types](https://www.twilio.com/docs/sms/accepted-mime-types) of accepted media. To send more than one image in the message body, provide multiple `media_url` parameters in the POST request. You can include up to 10 `media_url` parameters per message. You can send images in an SMS message in only the US and Canada. + */ + "mediaUrl"?: Array; + /** + * The URL we should call using the \"status_callback_method\" to send status information to your application. If specified, we POST these message status changes to the URL - queued, failed, sent, delivered, or undelivered. Twilio will POST its [standard request parameters](https://www.twilio.com/docs/messaging/twiml#request-parameters) as well as some additional parameters including \"MessageSid\", \"MessageStatus\", and \"ErrorCode\". If you include this parameter with the \"messaging_service_sid\", we use this URL instead of the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/messaging/services/api). URLs must contain a valid hostname and underscores are not allowed. + */ + "statusCallback"?: string; + /** + * How long in seconds the message can remain in our outgoing message queue. After this period elapses, the message fails and we call your status callback. Can be between 1 and the default value of 14,400 seconds. After a message has been accepted by a carrier, however, we cannot guarantee that the message will not be queued after this period. We recommend that this value be at least 5 seconds. + */ + "validityPeriod"?: number; + /** + * The time at which Twilio will send the message. This parameter can be used to schedule a message to be sent at a particular time. Must be in ISO 8601 format. + */ + "sendAt"?: string; + /** + * This parameter indicates your intent to schedule a message. Pass the value `fixed` to schedule a message at a fixed time. This parameter works in conjuction with the `SendAt` parameter. + */ + "scheduleType"?: string; + /** + * Determines the usage of Click Tracking. Setting it to `true` will instruct Twilio to replace all links in the Message with a shortened version based on the associated Domain Sid and track clicks on them. If this parameter is not set on an API call, we will use the value set on the Messaging Service. If this parameter is not set and the value is not configured on the Messaging Service used this will default to `false`. + */ + "shortenUrls"?: boolean; + /** + * If set to True, Twilio will deliver the message as a single MMS message, regardless of the presence of media. + */ + "sendAsMms"?: boolean; + /** + * The maximum total price in US dollars that you will pay for the message to be delivered. Can be a decimal value that has up to 4 decimal places. All messages are queued for delivery and the message cost is checked before the message is sent. If the cost exceeds max_price, the message will fail and a status of Failed is sent to the status callback. If MaxPrice is not set, the message cost is not checked. + */ + "maxPrice"?: number; + /** + * Total number of attempts made ( including this ) to send out the message regardless of the provider used + */ + "attempt"?: number; + /** + * This parameter indicates whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be true or false. + */ + "smartEncoded"?: boolean; + /** + * This parameter allows Twilio to send SMS traffic to carriers without checking/caring whether the destination number is a mobile or a landline. + */ + "forceDelivery"?: boolean; + /** + * The SID of the application that should receive message status. We POST a message_sid parameter and a message_status parameter with a value of sent or failed to the application\'s message_status_callback. If a status_callback parameter is also passed, it will be ignored and the application\'s message_status_callback parameter will be used. + */ + "applicationSid"?: string; +} + +export class MessagingV1FailedMessageReceipt { + /** + * The recipient phone number + */ + "to"?: string; + /** + * The description of the error_code + */ + "errorMessage"?: string; + /** + * The error code associated with the message creation attempt + */ + "errorCode"?: number; +} + +export class MessagingV1Message { + /** + * The destination phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format for SMS/MMS or [Channel user address](https://www.twilio.com/docs/sms/channels#channel-addresses) for other 3rd-party channels. + */ + "to"?: string; + /** + * The text of the message you want to send. Can be up to 1,600 characters in length. Overrides the request-level body and content template if provided. + */ + "body"?: string; + /** + * Key-value pairs of variable names to substitution values. Refer to the [Twilio Content API Resources](https://www.twilio.com/docs/content-api/content-api-resources#send-a-message-with-preconfigured-content) for more details. + */ + "contentVariables"?: { [key: string]: string }; +} + +export class MessagingV1MessageReceipt { + /** + * The recipient phone number + */ + "to"?: string | null; + /** + * The unique string that identifies the resource + */ + "sid"?: string | null; +} + +/** + * Options to pass to create a MessageInstance + */ +export interface MessageListInstanceCreateOptions { + /** */ + createMessagesRequest: CreateMessagesRequest; +} + +export interface MessageSolution {} + +export interface MessageListInstance { + _version: V1; + _solution: MessageSolution; + _uri: string; + + /** + * Create a MessageInstance + * + * @param params - Body for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed MessageInstance + */ + create( + params: CreateMessagesRequest, + callback?: (error: Error | null, item?: MessageInstance) => any + ): Promise; + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function MessageListInstance(version: V1): MessageListInstance { + const instance = {} as MessageListInstance; + + instance._version = version; + instance._solution = {}; + instance._uri = `/Messages`; + + instance.create = function create( + params: CreateMessagesRequest, + callback?: (error: Error | null, items: MessageInstance) => any + ): Promise { + if (params === null || params === undefined) { + throw new Error('Required parameter "params" missing.'); + } + + let data: any = {}; + + data = params; + + const headers: any = {}; + headers["Content-Type"] = "application/json"; + + let operationVersion = version, + operationPromise = operationVersion.create({ + uri: instance._uri, + method: "post", + data, + headers, + }); + + operationPromise = operationPromise.then( + (payload) => new MessageInstance(operationVersion, payload) + ); + + operationPromise = instance._version.setPromiseCallback( + operationPromise, + callback + ); + return operationPromise; + }; + + instance.toJSON = function toJSON() { + return instance._solution; + }; + + instance[inspect.custom] = function inspectImpl( + _depth: any, + options: InspectOptions + ) { + return inspect(instance.toJSON(), options); + }; + + return instance; +} + +interface MessagePayload extends MessageResource {} + +interface MessageResource { + total_message_count: number; + success_count: number; + error_count: number; + message_receipts: Array; + failed_message_receipts: Array; +} + +export class MessageInstance { + constructor(protected _version: V1, payload: MessageResource) { + this.totalMessageCount = deserialize.integer(payload.total_message_count); + this.successCount = deserialize.integer(payload.success_count); + this.errorCount = deserialize.integer(payload.error_count); + this.messageReceipts = payload.message_receipts; + this.failedMessageReceipts = payload.failed_message_receipts; + } + + /** + * The number of Messages processed in the request, equal to the sum of success_count and error_count. + */ + totalMessageCount: number; + /** + * The number of Messages successfully created. + */ + successCount: number; + /** + * The number of Messages unsuccessfully processed in the request. + */ + errorCount: number; + messageReceipts: Array; + failedMessageReceipts: Array; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + totalMessageCount: this.totalMessageCount, + successCount: this.successCount, + errorCount: this.errorCount, + messageReceipts: this.messageReceipts, + failedMessageReceipts: this.failedMessageReceipts, + }; + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +}