Skip to content

Commit

Permalink
chore: fix header and pagination issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 committed Dec 2, 2024
1 parent 6c5ed6f commit 3bc348d
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/base/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ export default class Page<
if (keys.length === 1) {
return payload[keys[0]];
}
for (const key of keys)
if (Array.isArray(payload[key])) return payload[key];

throw new Error("Page Records cannot be deserialized");
}
Expand Down
16 changes: 10 additions & 6 deletions src/credential_provider/NoAuthCredentialProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import CredentialProvider from "./CredentialProvider";
import AuthStrategy from "../auth_strategy/AuthStrategy";
import NoAuthStrategy from "../auth_strategy/NoAuthStrategy";

export default class NoAuthCredentialProvider extends CredentialProvider {
constructor() {
super("client-credentials");
}
namespace NoAuthCredentialProvider {
export class NoAuthCredentialProvider extends CredentialProvider {
constructor() {
super("client-credentials");
}

public toAuthStrategy(): AuthStrategy {
return new NoAuthStrategy();
public toAuthStrategy(): AuthStrategy {
return new NoAuthStrategy();
}
}
}

export = NoAuthCredentialProvider;
3 changes: 2 additions & 1 deletion src/http/bearer_token/ApiTokenManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default class ApiTokenManager implements TokenManager {
}

async fetchToken(): Promise<string> {
const noAuthCredentialProvider = new NoAuthCredentialProvider();
const noAuthCredentialProvider =
new NoAuthCredentialProvider.NoAuthCredentialProvider();
const client = new Client();
client.setCredentialProvider(noAuthCredentialProvider);

Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import IVoiceResponse from "./twiml/VoiceResponse";
import IMessagingResponse from "./twiml/MessagingResponse";
import IFaxResponse from "./twiml/FaxResponse";
import IClientCredentialProvider from "./credential_provider/ClientCredentialProvider";
import INoAuthCredentialProvider from "./credential_provider/NoAuthCredentialProvider";

// Shorthand to automatically create a RestClient
function TwilioSDK(
Expand Down Expand Up @@ -51,6 +52,11 @@ namespace TwilioSDK {
export const ClientCredentialProviderBuilder =
IClientCredentialProvider.ClientCredentialProviderBuilder;

export type NoAuthCredentialProvider =
INoAuthCredentialProvider.NoAuthCredentialProvider;
export const NoAuthCredentialProvider =
INoAuthCredentialProvider.NoAuthCredentialProvider;

// Setup webhook helper functionality
export type validateBody = typeof webhooks.validateBody;
export const validateBody = webhooks.validateBody;
Expand Down
1 change: 1 addition & 0 deletions src/rest/previewIam/v1/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function AuthorizeListInstance(version: V1): AuthorizeListInstance {
if (params["state"] !== undefined) data["state"] = params["state"];

const headers: any = {};
headers["Accept"] = "application/json";

let operationVersion = version,
operationPromise = operationVersion.fetch({
Expand Down
1 change: 1 addition & 0 deletions src/rest/previewIam/v1/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function TokenListInstance(version: V1): TokenListInstance {

const headers: any = {};
headers["Content-Type"] = "application/x-www-form-urlencoded";
headers["Accept"] = "application/json";

let operationVersion = version,
operationPromise = operationVersion.create({
Expand Down
5 changes: 5 additions & 0 deletions src/rest/previewIam/versionless/organization/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ export class AccountContextImpl implements AccountContext {
fetch(
callback?: (error: Error | null, item?: AccountInstance) => any
): Promise<AccountInstance> {
const headers: any = {};
headers["Accept"] = "application/json";

const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.fetch({
uri: instance._uri,
method: "get",
headers,
});

operationPromise = operationPromise.then(
Expand Down Expand Up @@ -372,6 +376,7 @@ export function AccountListInstance(
if (params.pageToken !== undefined) data["PageToken"] = params.pageToken;

const headers: any = {};
headers["Accept"] = "application/json";

let operationVersion = version,
operationPromise = operationVersion.page({
Expand Down
13 changes: 10 additions & 3 deletions src/rest/previewIam/versionless/organization/roleAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,15 @@ export class RoleAssignmentContextImpl implements RoleAssignmentContext {
remove(
callback?: (error: Error | null, item?: boolean) => any
): Promise<boolean> {
const headers: any = {};
headers["Accept"] = "application/scim+json";

const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.remove({
uri: instance._uri,
method: "delete",
headers,
});

operationPromise = instance._version.setPromiseCallback(
Expand Down Expand Up @@ -309,7 +313,7 @@ export interface RoleAssignmentListInstance {
*/
create(
params: PublicApiCreateRoleAssignmentRequest,
headers: any,
headers?: any,
callback?: (error: Error | null, item?: RoleAssignmentInstance) => any
): Promise<RoleAssignmentInstance>;

Expand Down Expand Up @@ -415,7 +419,7 @@ export function RoleAssignmentListInstance(

instance.create = function create(
params: PublicApiCreateRoleAssignmentRequest,
headers: any,
headers?: any,
callback?: (error: Error | null, items: RoleAssignmentInstance) => any
): Promise<RoleAssignmentInstance> {
if (params === null || params === undefined) {
Expand All @@ -426,7 +430,9 @@ export function RoleAssignmentListInstance(

data = params;

headers["Content-Type"] = "application/json";
if (headers === null || headers === undefined) {
headers = {};
}

let operationVersion = version,
operationPromise = operationVersion.create({
Expand Down Expand Up @@ -475,6 +481,7 @@ export function RoleAssignmentListInstance(
if (params.pageToken !== undefined) data["PageToken"] = params.pageToken;

const headers: any = {};
headers["Accept"] = "application/json";

let operationVersion = version,
operationPromise = operationVersion.page({
Expand Down
27 changes: 20 additions & 7 deletions src/rest/previewIam/versionless/organization/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export interface UserContext {
*/
update(
params: ScimUser,
headers: any,
headers?: any,
callback?: (error: Error | null, item?: UserInstance) => any
): Promise<UserInstance>;

Expand Down Expand Up @@ -262,11 +262,15 @@ export class UserContextImpl implements UserContext {
remove(
callback?: (error: Error | null, item?: boolean) => any
): Promise<boolean> {
const headers: any = {};
headers["Accept"] = "application/scim+json";

const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.remove({
uri: instance._uri,
method: "delete",
headers,
});

operationPromise = instance._version.setPromiseCallback(
Expand All @@ -279,11 +283,15 @@ export class UserContextImpl implements UserContext {
fetch(
callback?: (error: Error | null, item?: UserInstance) => any
): Promise<UserInstance> {
const headers: any = {};
headers["Accept"] = "application/scim+json";

const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.fetch({
uri: instance._uri,
method: "get",
headers,
});

operationPromise = operationPromise.then(
Expand All @@ -305,7 +313,7 @@ export class UserContextImpl implements UserContext {

update(
params: ScimUser,
headers: any,
headers?: any,
callback?: (error: Error | null, item?: UserInstance) => any
): Promise<UserInstance> {
if (params === null || params === undefined) {
Expand All @@ -316,7 +324,9 @@ export class UserContextImpl implements UserContext {

data = params;

headers["Content-Type"] = "application/json";
if (headers === null || headers === undefined) {
headers = {};
}

const instance = this;
let operationVersion = instance._version,
Expand Down Expand Up @@ -518,7 +528,7 @@ export class UserInstance {
*/
update(
params: ScimUser,
headers: any,
headers?: any,
callback?: (error: Error | null, item?: UserInstance) => any
): Promise<UserInstance>;

Expand Down Expand Up @@ -583,7 +593,7 @@ export interface UserListInstance {
*/
create(
params: ScimUser,
headers: any,
headers?: any,
callback?: (error: Error | null, item?: UserInstance) => any
): Promise<UserInstance>;

Expand Down Expand Up @@ -683,7 +693,7 @@ export function UserListInstance(

instance.create = function create(
params: ScimUser,
headers: any,
headers?: any,
callback?: (error: Error | null, items: UserInstance) => any
): Promise<UserInstance> {
if (params === null || params === undefined) {
Expand All @@ -694,7 +704,9 @@ export function UserListInstance(

data = params;

headers["Content-Type"] = "application/json";
if (headers === null || headers === undefined) {
headers = {};
}

let operationVersion = version,
operationPromise = operationVersion.create({
Expand Down Expand Up @@ -741,6 +753,7 @@ export function UserListInstance(
if (params.pageToken !== undefined) data["PageToken"] = params.pageToken;

const headers: any = {};
headers["Accept"] = "application/scim+json";

let operationVersion = version,
operationPromise = operationVersion.page({
Expand Down

0 comments on commit 3bc348d

Please sign in to comment.