From f0c0a515a6b62834536925b1b7fe08103d2ac055 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Wed, 20 Nov 2024 12:59:47 +0530 Subject: [PATCH] chore: run prettier --- src/auth_strategy/AuthStrategy.ts | 12 +- src/auth_strategy/BasicAuthStrategy.ts | 32 ++--- src/auth_strategy/NoAuthStrategy.ts | 18 +-- src/auth_strategy/TokenAuthStrategy.ts | 101 +++++++-------- src/base/BaseTwilio.ts | 37 +++--- src/base/RequestClient.ts | 11 +- .../ClientCredentialProvider.ts | 86 ++++++------- src/credential_provider/CredentialProvider.ts | 10 +- .../NoAuthCredentialProvider.ts | 12 +- src/http/bearer_token/ApiTokenManager.ts | 43 ++++--- src/http/bearer_token/TokenManager.ts | 2 +- src/index.ts | 6 +- src/rest/PreviewIam.ts | 37 +++--- src/rest/Twilio.ts | 5 +- src/rest/previewIam/V1.ts | 1 - src/rest/previewIam/v1/authorize.ts | 97 ++++++++------- src/rest/previewIam/v1/token.ts | 115 +++++++++--------- 17 files changed, 320 insertions(+), 305 deletions(-) diff --git a/src/auth_strategy/AuthStrategy.ts b/src/auth_strategy/AuthStrategy.ts index 54449c1af..ac140f02c 100644 --- a/src/auth_strategy/AuthStrategy.ts +++ b/src/auth_strategy/AuthStrategy.ts @@ -1,8 +1,8 @@ export default abstract class AuthStrategy { - private authType: string; - protected constructor(authType: string) { - this.authType = authType; - } - abstract getAuthString(): Promise; - abstract requiresAuthentication(): boolean; + private authType: string; + protected constructor(authType: string) { + this.authType = authType; + } + abstract getAuthString(): Promise; + abstract requiresAuthentication(): boolean; } diff --git a/src/auth_strategy/BasicAuthStrategy.ts b/src/auth_strategy/BasicAuthStrategy.ts index 58ea3cd03..ecee933fb 100644 --- a/src/auth_strategy/BasicAuthStrategy.ts +++ b/src/auth_strategy/BasicAuthStrategy.ts @@ -1,23 +1,23 @@ import AuthStrategy from "./AuthStrategy"; export default class BasicAuthStrategy extends AuthStrategy { - private username: string; - private password: string; + private username: string; + private password: string; - constructor(username: string, password: string) { - super("basic"); - this.username = username; - this.password = password; - } + constructor(username: string, password: string) { + super("basic"); + this.username = username; + this.password = password; + } - getAuthString(): Promise { - const auth = Buffer.from(this.username + ":" + this.password).toString( - "base64" - ); - return Promise.resolve(`Basic ${auth}`); - } + getAuthString(): Promise { + const auth = Buffer.from(this.username + ":" + this.password).toString( + "base64" + ); + return Promise.resolve(`Basic ${auth}`); + } - requiresAuthentication(): boolean { - return true; - } + requiresAuthentication(): boolean { + return true; + } } diff --git a/src/auth_strategy/NoAuthStrategy.ts b/src/auth_strategy/NoAuthStrategy.ts index 08cef3685..069a8844a 100644 --- a/src/auth_strategy/NoAuthStrategy.ts +++ b/src/auth_strategy/NoAuthStrategy.ts @@ -1,15 +1,15 @@ import AuthStrategy from "./AuthStrategy"; export default class NoAuthStrategy extends AuthStrategy { - constructor() { - super("noauth"); - } + constructor() { + super("noauth"); + } - getAuthString(): Promise { - return Promise.resolve(""); - } + getAuthString(): Promise { + return Promise.resolve(""); + } - requiresAuthentication(): boolean { - return false; - } + requiresAuthentication(): boolean { + return false; + } } diff --git a/src/auth_strategy/TokenAuthStrategy.ts b/src/auth_strategy/TokenAuthStrategy.ts index a9a423b0a..0d9a79388 100644 --- a/src/auth_strategy/TokenAuthStrategy.ts +++ b/src/auth_strategy/TokenAuthStrategy.ts @@ -1,64 +1,67 @@ import AuthStrategy from "./AuthStrategy"; import TokenManager from "../http/bearer_token/TokenManager"; -import jwt, { JwtPayload } from 'jsonwebtoken'; +import jwt, { JwtPayload } from "jsonwebtoken"; export default class TokenAuthStrategy extends AuthStrategy { - private token: string; - private tokenManager: TokenManager; + private token: string; + private tokenManager: TokenManager; - constructor(tokenManager: TokenManager) { - super("token"); - this.token = ""; - this.tokenManager = tokenManager; - } + constructor(tokenManager: TokenManager) { + super("token"); + this.token = ""; + this.tokenManager = tokenManager; + } - async getAuthString(): Promise { - return this.fetchToken().then(token => { - this.token = token; - return `Bearer ${this.token}`; - }).catch( - error => { - throw new Error(`Failed to fetch access token: ${error}`); - } - ); - } + async getAuthString(): Promise { + return this.fetchToken() + .then((token) => { + this.token = token; + return `Bearer ${this.token}`; + }) + .catch((error) => { + throw new Error(`Failed to fetch access token: ${error}`); + }); + } - requiresAuthentication(): boolean { - return true; - } + requiresAuthentication(): boolean { + return true; + } - async fetchToken(): Promise { - if (this.token == null || this.token.length === 0 || this.isTokenExpired(this.token)) { - return this.tokenManager.fetchToken(); - } - return this.token; + async fetchToken(): Promise { + if ( + this.token == null || + this.token.length === 0 || + this.isTokenExpired(this.token) + ) { + return this.tokenManager.fetchToken(); } + return this.token; + } - /** - * Function to check if the token is expired with a buffer of 30 seconds. - * @param token - The JWT token as a string. - * @returns Boolean indicating if the token is expired. - */ - isTokenExpired(token: string): boolean { - try { - // Decode the token without verifying the signature, as we only want to read the expiration for this check - const decoded = jwt.decode(token) as JwtPayload; + /** + * Function to check if the token is expired with a buffer of 30 seconds. + * @param token - The JWT token as a string. + * @returns Boolean indicating if the token is expired. + */ + isTokenExpired(token: string): boolean { + try { + // Decode the token without verifying the signature, as we only want to read the expiration for this check + const decoded = jwt.decode(token) as JwtPayload; - if (!decoded || !decoded.exp) { - // If the token doesn't have an expiration, consider it expired - return true; - } + if (!decoded || !decoded.exp) { + // If the token doesn't have an expiration, consider it expired + return true; + } - const expiresAt = decoded.exp * 1000; - const bufferMilliseconds = 30 * 1000; - const bufferExpiresAt = expiresAt - bufferMilliseconds; + const expiresAt = decoded.exp * 1000; + const bufferMilliseconds = 30 * 1000; + const bufferExpiresAt = expiresAt - bufferMilliseconds; - // Return true if the current time is after the expiration time with buffer - return Date.now() > bufferExpiresAt; - } catch (error) { - // If there's an error decoding the token, consider it expired - return true; - } + // Return true if the current time is after the expiration time with buffer + return Date.now() > bufferExpiresAt; + } catch (error) { + // If there's an error decoding the token, consider it expired + return true; } - + } } diff --git a/src/base/BaseTwilio.ts b/src/base/BaseTwilio.ts index eea063cbe..82d16f9b6 100644 --- a/src/base/BaseTwilio.ts +++ b/src/base/BaseTwilio.ts @@ -107,19 +107,19 @@ namespace Twilio { constructor(username?: string, password?: string, opts?: ClientOpts) { this.setOpts(opts); this.username = - username ?? - this.env?.TWILIO_ACCOUNT_SID ?? - process.env.TWILIO_ACCOUNT_SID ?? - (() => { - throw new Error("username is required"); - })(); + username ?? + this.env?.TWILIO_ACCOUNT_SID ?? + process.env.TWILIO_ACCOUNT_SID ?? + (() => { + throw new Error("username is required"); + })(); this.password = - password ?? - this.env?.TWILIO_AUTH_TOKEN ?? - process.env.TWILIO_AUTH_TOKEN ?? - (() => { - throw new Error("password is required"); - })(); + password ?? + this.env?.TWILIO_AUTH_TOKEN ?? + process.env.TWILIO_AUTH_TOKEN ?? + (() => { + throw new Error("password is required"); + })(); this.accountSid = ""; this.setAccountSid(this.opts?.accountSid || this.username); this.invalidateOAuth(); @@ -161,8 +161,8 @@ namespace Twilio { if (this.accountSid && !this.accountSid?.startsWith("AC")) { const apiKeyMsg = this.accountSid?.startsWith("SK") - ? ". The given SID indicates an API Key which requires the accountSid to be passed as an additional option" - : ""; + ? ". The given SID indicates an API Key which requires the accountSid to be passed as an additional option" + : ""; throw new Error("accountSid must start with AC" + apiKeyMsg); } @@ -175,12 +175,12 @@ namespace Twilio { } invalidateBasicAuth() { - this.username = undefined; - this.password = undefined; + this.username = undefined; + this.password = undefined; } invalidateOAuth() { - this.credentialProvider = undefined; + this.credentialProvider = undefined; } get httpClient() { @@ -225,7 +225,8 @@ namespace Twilio { const username = opts.username || this.username; const password = opts.password || this.password; - const authStrategy = opts.authStrategy || this.credentialProvider?.toAuthStrategy(); + const authStrategy = + opts.authStrategy || this.credentialProvider?.toAuthStrategy(); const headers = opts.headers || {}; diff --git a/src/base/RequestClient.ts b/src/base/RequestClient.ts index c7da5b7f0..4fb29bb53 100644 --- a/src/base/RequestClient.ts +++ b/src/base/RequestClient.ts @@ -1,11 +1,14 @@ -import {HttpMethod} from "../interfaces"; -import axios, {AxiosInstance, AxiosRequestConfig, AxiosResponse} from "axios"; +import { HttpMethod } from "../interfaces"; +import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; import * as fs from "fs"; import HttpsProxyAgent from "https-proxy-agent"; import qs from "qs"; import * as https from "https"; import Response from "../http/response"; -import Request, {Headers, RequestOptions as LastRequestOptions,} from "../http/request"; +import Request, { + Headers, + RequestOptions as LastRequestOptions, +} from "../http/request"; import AuthStrategy from "../auth_strategy/AuthStrategy"; const DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"; @@ -179,7 +182,7 @@ class RequestClient { "base64" ); headers.Authorization = "Basic " + auth; - } else if(opts.authStrategy) { + } else if (opts.authStrategy) { headers.Authorization = await opts.authStrategy.getAuthString(); } diff --git a/src/credential_provider/ClientCredentialProvider.ts b/src/credential_provider/ClientCredentialProvider.ts index 3a78c3cb5..c1253b090 100644 --- a/src/credential_provider/ClientCredentialProvider.ts +++ b/src/credential_provider/ClientCredentialProvider.ts @@ -5,60 +5,62 @@ import ApiTokenManager from "../http/bearer_token/ApiTokenManager"; import TokenAuthStrategy from "../auth_strategy/TokenAuthStrategy"; class ClientCredentialProvider extends CredentialProvider { - grantType: string; - clientId: string; - clientSecret: string; - tokenManager: TokenManager | null; + grantType: string; + clientId: string; + clientSecret: string; + tokenManager: TokenManager | null; - constructor() { - super("client-credentials"); - this.grantType = "client_credentials"; - this.clientId = ""; - this.clientSecret = ""; - this.tokenManager = null; - } + constructor() { + super("client-credentials"); + this.grantType = "client_credentials"; + this.clientId = ""; + this.clientSecret = ""; + this.tokenManager = null; + } - public toAuthStrategy(): AuthStrategy { - if (this.tokenManager == null) { - this.tokenManager = new ApiTokenManager({ - grantType: this.grantType, - clientId: this.clientId, - clientSecret: this.clientSecret, - }); - } - return new TokenAuthStrategy(this.tokenManager); + public toAuthStrategy(): AuthStrategy { + if (this.tokenManager == null) { + this.tokenManager = new ApiTokenManager({ + grantType: this.grantType, + clientId: this.clientId, + clientSecret: this.clientSecret, + }); } + return new TokenAuthStrategy(this.tokenManager); + } } namespace ClientCredentialProvider { - export class ClientCredentialProviderBuilder { - private readonly instance: ClientCredentialProvider; + export class ClientCredentialProviderBuilder { + private readonly instance: ClientCredentialProvider; - constructor() { - this.instance = new ClientCredentialProvider(); - } + constructor() { + this.instance = new ClientCredentialProvider(); + } - public setClientId(clientId: string): ClientCredentialProviderBuilder { - this.instance.clientId = clientId; - return this; - } + public setClientId(clientId: string): ClientCredentialProviderBuilder { + this.instance.clientId = clientId; + return this; + } - public setClientSecret(clientSecret: string): ClientCredentialProviderBuilder { - this.instance.clientSecret = clientSecret; - return this; - } + public setClientSecret( + clientSecret: string + ): ClientCredentialProviderBuilder { + this.instance.clientSecret = clientSecret; + return this; + } - public setTokenManager(tokenManager: TokenManager): ClientCredentialProviderBuilder { - this.instance.tokenManager = tokenManager; - return this; - } + public setTokenManager( + tokenManager: TokenManager + ): ClientCredentialProviderBuilder { + this.instance.tokenManager = tokenManager; + return this; + } - public build(): ClientCredentialProvider { - return this.instance; - } + public build(): ClientCredentialProvider { + return this.instance; } + } } export = ClientCredentialProvider; - - diff --git a/src/credential_provider/CredentialProvider.ts b/src/credential_provider/CredentialProvider.ts index 394abf017..fc5a747d4 100644 --- a/src/credential_provider/CredentialProvider.ts +++ b/src/credential_provider/CredentialProvider.ts @@ -1,9 +1,9 @@ import AuthStrategy from "../auth_strategy/AuthStrategy"; export default abstract class CredentialProvider { - private authType: string; - protected constructor(authType: string) { - this.authType = authType; - } - abstract toAuthStrategy(): AuthStrategy; + private authType: string; + protected constructor(authType: string) { + this.authType = authType; + } + abstract toAuthStrategy(): AuthStrategy; } diff --git a/src/credential_provider/NoAuthCredentialProvider.ts b/src/credential_provider/NoAuthCredentialProvider.ts index c9364ea25..337bd66a8 100644 --- a/src/credential_provider/NoAuthCredentialProvider.ts +++ b/src/credential_provider/NoAuthCredentialProvider.ts @@ -3,11 +3,11 @@ import AuthStrategy from "../auth_strategy/AuthStrategy"; import NoAuthStrategy from "../auth_strategy/NoAuthStrategy"; export default class NoAuthCredentialProvider extends CredentialProvider { - constructor() { - super("client-credentials"); - } + constructor() { + super("client-credentials"); + } - public toAuthStrategy(): AuthStrategy { - return new NoAuthStrategy(); - } + public toAuthStrategy(): AuthStrategy { + return new NoAuthStrategy(); + } } diff --git a/src/http/bearer_token/ApiTokenManager.ts b/src/http/bearer_token/ApiTokenManager.ts index 8542fc7b4..afb7715b7 100644 --- a/src/http/bearer_token/ApiTokenManager.ts +++ b/src/http/bearer_token/ApiTokenManager.ts @@ -1,28 +1,35 @@ import TokenManager from "./TokenManager"; -import {TokenListInstance, TokenListInstanceCreateOptions} from "../../rest/previewIam/v1/token"; +import { + TokenListInstance, + TokenListInstanceCreateOptions, +} from "../../rest/previewIam/v1/token"; import PreviewIamBase from "../../rest/PreviewIamBase"; import V1 from "../../rest/previewIam/V1"; import NoAuthCredentialProvider from "../../credential_provider/NoAuthCredentialProvider"; -import {Client} from "../../base/BaseTwilio"; +import { Client } from "../../base/BaseTwilio"; export default class ApiTokenManager implements TokenManager { - private params: TokenListInstanceCreateOptions; + private params: TokenListInstanceCreateOptions; - constructor(params: TokenListInstanceCreateOptions) { - this.params = params; - } + constructor(params: TokenListInstanceCreateOptions) { + this.params = params; + } - async fetchToken(): Promise { - const noAuthCredentialProvider = new NoAuthCredentialProvider(); - const client = new Client(); - client.setCredentialProvider(noAuthCredentialProvider); - - const tokenListInstance = TokenListInstance(new V1(new PreviewIamBase(client))); - return tokenListInstance.create(this.params).then(token => { - return token.accessToken; - }).catch(error => { - throw new Error(`Failed to fetch access token: ${error}`); - }); - } + async fetchToken(): Promise { + const noAuthCredentialProvider = new NoAuthCredentialProvider(); + const client = new Client(); + client.setCredentialProvider(noAuthCredentialProvider); + const tokenListInstance = TokenListInstance( + new V1(new PreviewIamBase(client)) + ); + return tokenListInstance + .create(this.params) + .then((token) => { + return token.accessToken; + }) + .catch((error) => { + throw new Error(`Failed to fetch access token: ${error}`); + }); + } } diff --git a/src/http/bearer_token/TokenManager.ts b/src/http/bearer_token/TokenManager.ts index ee532f224..4fa904f8c 100644 --- a/src/http/bearer_token/TokenManager.ts +++ b/src/http/bearer_token/TokenManager.ts @@ -1,3 +1,3 @@ export default abstract class TokenManager { - abstract fetchToken(): Promise ; + abstract fetchToken(): Promise; } diff --git a/src/index.ts b/src/index.ts index b2a1fe9ff..c1d3a82dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,8 +46,10 @@ namespace TwilioSDK { export type RequestClient = IRequestClient; export const RequestClient = IRequestClient; - export type ClientCredentialProviderBuilder = IClientCredentialProvider.ClientCredentialProviderBuilder; - export const ClientCredentialProviderBuilder = IClientCredentialProvider.ClientCredentialProviderBuilder; + export type ClientCredentialProviderBuilder = + IClientCredentialProvider.ClientCredentialProviderBuilder; + export const ClientCredentialProviderBuilder = + IClientCredentialProvider.ClientCredentialProviderBuilder; // Setup webhook helper functionality export type validateBody = typeof webhooks.validateBody; diff --git a/src/rest/PreviewIam.ts b/src/rest/PreviewIam.ts index ef0f292a2..3648b1065 100644 --- a/src/rest/PreviewIam.ts +++ b/src/rest/PreviewIam.ts @@ -1,28 +1,23 @@ -import { TokenListInstance} from "./previewIam/v1/token"; -import { AuthorizeListInstance} from "./previewIam/v1/authorize"; +import { TokenListInstance } from "./previewIam/v1/token"; +import { AuthorizeListInstance } from "./previewIam/v1/authorize"; import PreviewIamBase from "./PreviewIamBase"; class PreviewIam extends PreviewIamBase { + /** + * @deprecated - Use v1.tokens instead + */ + get tokens(): TokenListInstance { + console.warn("tokens is deprecated. Use v1.tokens instead."); + return this.v1.token; + } - /** - * @deprecated - Use v1.tokens instead - */ - get tokens(): TokenListInstance { - console.warn( - "tokens is deprecated. Use v1.tokens instead." - ); - return this.v1.token; - } - - /** - * @deprecated - Use v1.authorize instead - */ - get authorize(): AuthorizeListInstance { - console.warn( - "authorize is deprecated. Use v1.authorize instead." - ); - return this.v1.authorize; - } + /** + * @deprecated - Use v1.authorize instead + */ + get authorize(): AuthorizeListInstance { + console.warn("authorize is deprecated. Use v1.authorize instead."); + return this.v1.authorize; + } } export = PreviewIam; diff --git a/src/rest/Twilio.ts b/src/rest/Twilio.ts index 219f7daff..49cf4824a 100644 --- a/src/rest/Twilio.ts +++ b/src/rest/Twilio.ts @@ -340,7 +340,10 @@ class Twilio extends Client { } /** Getter for (Twilio.PreviewIam) domain */ get previewIam(): Preview { - return this._previewIam ?? (this._previewIam = new (require("./PreviewIam"))(this)); + return ( + this._previewIam ?? + (this._previewIam = new (require("./PreviewIam"))(this)) + ); } /** Getter for (Twilio.Pricing) domain */ get pricing(): Pricing { diff --git a/src/rest/previewIam/V1.ts b/src/rest/previewIam/V1.ts index 32cd1a520..6a27dc820 100644 --- a/src/rest/previewIam/V1.ts +++ b/src/rest/previewIam/V1.ts @@ -43,5 +43,4 @@ export default class V1 extends Version { this._token = this._token || TokenListInstance(this); return this._token; } - } diff --git a/src/rest/previewIam/v1/authorize.ts b/src/rest/previewIam/v1/authorize.ts index 2fb738e54..0564f7808 100644 --- a/src/rest/previewIam/v1/authorize.ts +++ b/src/rest/previewIam/v1/authorize.ts @@ -12,42 +12,35 @@ * 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 fetch a AuthorizeInstance */ export interface AuthorizeListInstanceFetchOptions { /** Response Type */ - "responseType"?: string; + responseType?: string; /** The Client Identifier */ - "clientId"?: string; + clientId?: string; /** The url to which response will be redirected to */ - "redirectUri"?: string; + redirectUri?: string; /** The scope of the access request */ - "scope"?: string; + scope?: string; /** An opaque value which can be used to maintain state between the request and callback */ - "state"?: string; + state?: string; } - -export interface AuthorizeSolution { -} +export interface AuthorizeSolution {} export interface AuthorizeListInstance { _version: V1; _solution: AuthorizeSolution; _uri: string; - - /** * Fetch a AuthorizeInstance * @@ -55,7 +48,9 @@ export interface AuthorizeListInstance { * * @returns Resolves to processed AuthorizeInstance */ - fetch(callback?: (error: Error | null, item?: AuthorizeInstance) => any): Promise; + fetch( + callback?: (error: Error | null, item?: AuthorizeInstance) => any + ): Promise; /** * Fetch a AuthorizeInstance * @@ -64,8 +59,10 @@ export interface AuthorizeListInstance { * * @returns Resolves to processed AuthorizeInstance */ - fetch(params: AuthorizeListInstanceFetchOptions, callback?: (error: Error | null, item?: AuthorizeInstance) => any): Promise; - + fetch( + params: AuthorizeListInstanceFetchOptions, + callback?: (error: Error | null, item?: AuthorizeInstance) => any + ): Promise; /** * Provide a user-friendly representation @@ -78,10 +75,15 @@ export function AuthorizeListInstance(version: V1): AuthorizeListInstance { const instance = {} as AuthorizeListInstance; instance._version = version; - instance._solution = { }; + instance._solution = {}; instance._uri = `/authorize`; - instance.fetch = function fetch(params?: AuthorizeListInstanceFetchOptions | ((error: Error | null, items: AuthorizeInstance) => any), callback?: (error: Error | null, items: AuthorizeInstance) => any): Promise { + instance.fetch = function fetch( + params?: + | AuthorizeListInstanceFetchOptions + | ((error: Error | null, items: AuthorizeInstance) => any), + callback?: (error: Error | null, items: AuthorizeInstance) => any + ): Promise { if (params instanceof Function) { callback = params; params = {}; @@ -91,41 +93,46 @@ export function AuthorizeListInstance(version: V1): AuthorizeListInstance { let data: any = {}; - if (params["responseType"] !== undefined) - data["response_type"] = params["responseType"]; + if (params["responseType"] !== undefined) + data["response_type"] = params["responseType"]; if (params["clientId"] !== undefined) - data["client_id"] = params["clientId"]; + data["client_id"] = params["clientId"]; if (params["redirectUri"] !== undefined) - data["redirect_uri"] = params["redirectUri"]; - if (params["scope"] !== undefined) - data["scope"] = params["scope"]; - if (params["state"] !== undefined) - data["state"] = params["state"]; - - - + data["redirect_uri"] = params["redirectUri"]; + if (params["scope"] !== undefined) data["scope"] = params["scope"]; + if (params["state"] !== undefined) data["state"] = params["state"]; const headers: any = {}; let operationVersion = version, - operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", params: data, headers }); - - operationPromise = operationPromise.then(payload => new AuthorizeInstance(operationVersion, payload)); - - - operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + operationPromise = operationVersion.fetch({ + uri: instance._uri, + method: "get", + params: data, + headers, + }); + + operationPromise = operationPromise.then( + (payload) => new AuthorizeInstance(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) { + instance[inspect.custom] = function inspectImpl( + _depth: any, + options: InspectOptions + ) { return inspect(instance.toJSON(), options); - } + }; return instance; } @@ -137,10 +144,8 @@ interface AuthorizeResource { } export class AuthorizeInstance { - constructor(protected _version: V1, payload: AuthorizeResource) { - this.redirectTo = (payload.redirect_to); - + this.redirectTo = payload.redirect_to; } /** @@ -156,12 +161,10 @@ export class AuthorizeInstance { toJSON() { return { redirectTo: this.redirectTo, - } + }; } [inspect.custom](_depth: any, options: InspectOptions) { return inspect(this.toJSON(), options); } } - - diff --git a/src/rest/previewIam/v1/token.ts b/src/rest/previewIam/v1/token.ts index 1ad99cb2b..d9ffc86ef 100644 --- a/src/rest/previewIam/v1/token.ts +++ b/src/rest/previewIam/v1/token.ts @@ -12,48 +12,41 @@ * 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; + grantType: string; /** A 34 character string that uniquely identifies this OAuth App. */ - "clientId": string; + clientId: string; /** The credential for confidential OAuth App. */ - "clientSecret"?: string; + clientSecret?: string; /** JWT token related to the authorization code grant type. */ - "code"?: string; + code?: string; /** The redirect uri */ - "redirectUri"?: string; + redirectUri?: string; /** The targeted audience uri */ - "audience"?: string; + audience?: string; /** JWT token related to refresh access token. */ - "refreshToken"?: string; + refreshToken?: string; /** The scope of token */ - "scope"?: string; + scope?: string; } - -export interface TokenSolution { -} +export interface TokenSolution {} export interface TokenListInstance { _version: V1; _solution: TokenSolution; _uri: string; - - /** * Create a TokenInstance * @@ -62,8 +55,10 @@ export interface TokenListInstance { * * @returns Resolves to processed TokenInstance */ - create(params: TokenListInstanceCreateOptions, callback?: (error: Error | null, item?: TokenInstance) => any): Promise; - + create( + params: TokenListInstanceCreateOptions, + callback?: (error: Error | null, item?: TokenInstance) => any + ): Promise; /** * Provide a user-friendly representation @@ -76,66 +71,72 @@ export function TokenListInstance(version: V1): TokenListInstance { const instance = {} as TokenListInstance; instance._version = version; - instance._solution = { }; + instance._solution = {}; instance._uri = `/token`; - instance.create = function create(params: TokenListInstanceCreateOptions, callback?: (error: Error | null, items: TokenInstance) => any): Promise { + 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.'); + throw new Error("Required parameter \"params['grantType']\" missing."); } if (params["clientId"] === null || params["clientId"] === undefined) { - throw new Error('Required parameter "params[\'clientId\']" missing.'); + throw new Error("Required parameter \"params['clientId']\" missing."); } let data: any = {}; - - data["grant_type"] = params["grantType"]; - + data["client_id"] = params["clientId"]; if (params["clientSecret"] !== undefined) - data["client_secret"] = params["clientSecret"]; - if (params["code"] !== undefined) - data["code"] = params["code"]; + data["client_secret"] = params["clientSecret"]; + if (params["code"] !== undefined) data["code"] = params["code"]; if (params["redirectUri"] !== undefined) - data["redirect_uri"] = params["redirectUri"]; - if (params["audience"] !== undefined) - data["audience"] = params["audience"]; + data["redirect_uri"] = params["redirectUri"]; + if (params["audience"] !== undefined) data["audience"] = params["audience"]; if (params["refreshToken"] !== undefined) - data["refresh_token"] = params["refreshToken"]; - if (params["scope"] !== undefined) - data["scope"] = params["scope"]; - - + data["refresh_token"] = params["refreshToken"]; + if (params["scope"] !== undefined) data["scope"] = params["scope"]; const headers: any = {}; - headers["Content-Type"] = "application/x-www-form-urlencoded" + 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); + 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) { + instance[inspect.custom] = function inspectImpl( + _depth: any, + options: InspectOptions + ) { return inspect(instance.toJSON(), options); - } + }; return instance; } @@ -151,14 +152,12 @@ interface TokenResource { } 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.tokenType = (payload.token_type); - this.expiresIn = (payload.expires_in); - + this.accessToken = payload.access_token; + this.refreshToken = payload.refresh_token; + this.idToken = payload.id_token; + this.tokenType = payload.token_type; + this.expiresIn = payload.expires_in; } /** @@ -191,12 +190,10 @@ export class TokenInstance { idToken: this.idToken, tokenType: this.tokenType, expiresIn: this.expiresIn, - } + }; } [inspect.custom](_depth: any, options: InspectOptions) { return inspect(this.toJSON(), options); } } - -