Skip to content

Commit

Permalink
Merge branch 'meteor-support' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgenVatle committed Dec 2, 2023
2 parents 1538c2c + 6cd848b commit f191bd8
Show file tree
Hide file tree
Showing 28 changed files with 127 additions and 281 deletions.
121 changes: 0 additions & 121 deletions src/core/CancelablePromise.ts

This file was deleted.

45 changes: 19 additions & 26 deletions src/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import FormData from "form-data";
import { ApiError } from "./ApiError";
import type { ApiRequestOptions } from "./ApiRequestOptions";
import type { ApiResult } from "./ApiResult";
import { CancelablePromise } from "./CancelablePromise";
import type { OnCancel } from "./CancelablePromise";
import type { ChatwootAPIConfig } from "./ChatwootAPI";
import { file_upload } from "../models/file_upload";

Expand Down Expand Up @@ -213,7 +211,6 @@ const sendRequest = async <T>(
body: any,
formData: FormData | undefined,
headers: Record<string, string>,
onCancel: OnCancel
): Promise<AxiosResponse<T>> => {
const source = axios.CancelToken.source();

Expand All @@ -226,8 +223,6 @@ const sendRequest = async <T>(
cancelToken: source.token,
};

onCancel(() => source.cancel("The user aborted a request."));

try {
return await axios.request(requestConfig);
} catch (error) {
Expand Down Expand Up @@ -282,34 +277,32 @@ const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void =>
* Request method
* @param config The OpenAPI configuration object
* @param options The request options from the service
* @returns CancelablePromise<T>
* @returns Promise<T>
* @throws ApiError
*/
export const request = <T>(config: ChatwootAPIConfig, options: ApiRequestOptions): CancelablePromise<T> => {
return new CancelablePromise(async (resolve, reject, onCancel) => {
export const request = <T>(config: ChatwootAPIConfig, options: ApiRequestOptions): Promise<T> => {
return new Promise(async (resolve, reject) => {
try {
const url = getUrl(config, options);
const formData = getFormData(options);
const body = getRequestBody(options);
const headers = await getHeaders(config, options, formData);

if (!onCancel.isCancelled) {
const response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel);
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);

const result: ApiResult = {
url,
ok: isSuccess(response.status),
status: response.status,
statusText: response.statusText,
body: responseHeader ?? responseBody,
};

catchErrorCodes(options, result);

resolve(result.body);
}

const response = await sendRequest<T>(config, options, url, body, formData, headers);
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);

const result: ApiResult = {
url,
ok: isSuccess(response.status),
status: response.status,
statusText: response.statusText,
body: responseHeader ?? responseBody,
};

catchErrorCodes(options, result);

resolve(result.body);
} catch (error) {
reject(error);
}
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { ApiError } from "./core/ApiError";
export { CancelablePromise, CancelError } from "./core/CancelablePromise";
export { ChatwootAPI } from "./core/ChatwootAPI";
export type { ChatwootAPIConfig } from "./core/ChatwootAPI";

Expand Down
11 changes: 5 additions & 6 deletions src/services/AccountAgentBots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import type { agent_bot } from "../models/agent_bot";
import type { agent_bot_create_update_payload } from "../models/agent_bot_create_update_payload";

import type { CancelablePromise } from "../core/CancelablePromise";
import { ChatwootAPIConfig } from "../core/ChatwootAPI";
import { request as __request } from "../core/request";

Expand All @@ -28,7 +27,7 @@ export class AccountAgentBots {
* The numeric ID of the account
*/
accountId: number;
}): CancelablePromise<Array<agent_bot>> {
}): Promise<Array<agent_bot>> {
return __request(this.chatwootAPI, {
method: "GET",
url: "/api/v1/accounts/{account_id}/agent_bots",
Expand Down Expand Up @@ -56,7 +55,7 @@ export class AccountAgentBots {
*/
accountId: number;
data: agent_bot_create_update_payload;
}): CancelablePromise<agent_bot> {
}): Promise<agent_bot> {
return __request(this.chatwootAPI, {
method: "POST",
url: "/api/v1/accounts/{account_id}/agent_bots",
Expand Down Expand Up @@ -88,7 +87,7 @@ export class AccountAgentBots {
* The ID of the agentbot to be updated
*/
id: number;
}): CancelablePromise<agent_bot> {
}): Promise<agent_bot> {
return __request(this.chatwootAPI, {
method: "GET",
url: "/api/v1/accounts/{account_id}/agent_bots/{id}",
Expand Down Expand Up @@ -123,7 +122,7 @@ export class AccountAgentBots {
*/
id: number;
data: agent_bot_create_update_payload;
}): CancelablePromise<agent_bot> {
}): Promise<agent_bot> {
return __request(this.chatwootAPI, {
method: "PATCH",
url: "/api/v1/accounts/{account_id}/agent_bots/{id}",
Expand Down Expand Up @@ -156,7 +155,7 @@ export class AccountAgentBots {
* The ID of the agentbot to be updated
*/
id: number;
}): CancelablePromise<any> {
}): Promise<any> {
return __request(this.chatwootAPI, {
method: "DELETE",
url: "/api/v1/accounts/{account_id}/agent_bots/{id}",
Expand Down
9 changes: 4 additions & 5 deletions src/services/Agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* eslint-disable */
import type { agent } from "../models/agent";

import type { CancelablePromise } from "../core/CancelablePromise";
import { ChatwootAPIConfig } from "../core/ChatwootAPI";
import { request as __request } from "../core/request";

Expand All @@ -27,7 +26,7 @@ export class Agents {
* The numeric ID of the account
*/
accountId: number;
}): CancelablePromise<Array<agent>> {
}): Promise<Array<agent>> {
return __request(this.chatwootAPI, {
method: "GET",
url: "/api/v1/accounts/{account_id}/agents",
Expand Down Expand Up @@ -76,7 +75,7 @@ export class Agents {
*/
auto_offline?: boolean;
};
}): CancelablePromise<agent> {
}): Promise<agent> {
return __request(this.chatwootAPI, {
method: "POST",
url: "/api/v1/accounts/{account_id}/agents",
Expand Down Expand Up @@ -123,7 +122,7 @@ export class Agents {
*/
auto_offline?: boolean;
};
}): CancelablePromise<agent> {
}): Promise<agent> {
return __request(this.chatwootAPI, {
method: "PATCH",
url: "/api/v1/accounts/{account_id}/agents/{id}",
Expand Down Expand Up @@ -157,7 +156,7 @@ export class Agents {
* The ID of the agent to be deleted
*/
id: number;
}): CancelablePromise<any> {
}): Promise<any> {
return __request(this.chatwootAPI, {
method: "DELETE",
url: "/api/v1/accounts/{account_id}/agents/{id}",
Expand Down
11 changes: 5 additions & 6 deletions src/services/AutomationRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import type { automation_rule } from "../models/automation_rule";
import type { automation_rule_create_update_payload } from "../models/automation_rule_create_update_payload";

import type { CancelablePromise } from "../core/CancelablePromise";
import { ChatwootAPIConfig } from "../core/ChatwootAPI";
import { request as __request } from "../core/request";

Expand Down Expand Up @@ -33,7 +32,7 @@ export class AutomationRule {
* The page parameter
*/
page?: number;
}): CancelablePromise<Array<automation_rule>> {
}): Promise<Array<automation_rule>> {
return __request(this.chatwootAPI, {
method: "GET",
url: "/api/v1/accounts/{account_id}/automation_rules",
Expand Down Expand Up @@ -64,7 +63,7 @@ export class AutomationRule {
*/
accountId: number;
data: automation_rule_create_update_payload;
}): CancelablePromise<automation_rule> {
}): Promise<automation_rule> {
return __request(this.chatwootAPI, {
method: "POST",
url: "/api/v1/accounts/{account_id}/automation_rules",
Expand Down Expand Up @@ -96,7 +95,7 @@ export class AutomationRule {
* ID of the Automation Rule
*/
id: number;
}): CancelablePromise<automation_rule> {
}): Promise<automation_rule> {
return __request(this.chatwootAPI, {
method: "GET",
url: "/api/v1/accounts/{account_id}/automation_rules/{id}",
Expand Down Expand Up @@ -131,7 +130,7 @@ export class AutomationRule {
*/
id: number;
data: automation_rule_create_update_payload;
}): CancelablePromise<automation_rule> {
}): Promise<automation_rule> {
return __request(this.chatwootAPI, {
method: "PATCH",
url: "/api/v1/accounts/{account_id}/automation_rules/{id}",
Expand Down Expand Up @@ -165,7 +164,7 @@ export class AutomationRule {
* ID of the Automation Rule
*/
id: number;
}): CancelablePromise<any> {
}): Promise<any> {
return __request(this.chatwootAPI, {
method: "DELETE",
url: "/api/v1/accounts/{account_id}/automation_rules/{id}",
Expand Down
Loading

0 comments on commit f191bd8

Please sign in to comment.