Skip to content

Commit

Permalink
feat: error and types
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit committed Nov 2, 2024
1 parent e0b02ca commit 9af3781
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 247 deletions.
2 changes: 2 additions & 0 deletions js/src/sdk/models/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export class Entity {
});
} else {
const connectedAccounts = await this.connectedAccounts.list({

//@ts-ignore
user_uuid: this.id,
appNames: action.appKey,
status: 'ACTIVE'
Expand Down
64 changes: 37 additions & 27 deletions js/src/sdk/models/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ActionsListResponseDTO, ExecuteActionResDTO } from "../client";
import apiClient from "../client/client";
import { CEG } from "../utils/error";
import { BackendClient } from "./backendClient";

/**
Expand Down Expand Up @@ -155,13 +156,17 @@ export class Actions {
* @throws {ApiError} If the request fails.
*/
async get(data: { actionName: string; }) {
try{
const actions = await apiClient.actionsV1.v1GetAction({
path: {
actionId: data.actionName
}
});

return (actions.data! as unknown as any[])[0];
return (actions.data! as unknown as any[])[0];
} catch(e){
throw CEG.handleError(e)
}
}

/**
Expand All @@ -170,24 +175,26 @@ export class Actions {
* This method allows you to fetch a list of all the available actions. It supports pagination to handle large numbers of actions. The response includes an array of action objects, each containing information such as the action's name, display name, description, input parameters, expected response, associated app information, and enabled status.
*
* @param {GetListActionsData} data The data for the request.
* @returns {CancelablePromise<GetListActionsResponse>} A promise that resolves to the list of all actions.
* @returns {Promise<ActionsListResponseDTO>} A promise that resolves to the list of all actions.
* @throws {ApiError} If the request fails.
*/
list(data: GetListActionsData = {}): Promise<ActionsListResponseDTO> {
return apiClient.actionsV2.v2ListActions({
query: {
actions: data.actions,
apps: data.apps,
showAll: data.showAll,
tags: data.tags,
useCase: data.useCase as string,
filterImportantActions: data.filterImportantActions,
showEnabledOnly: data.showEnabledOnly

}
}).then(res => {
return res.data!
})
async list(data: GetListActionsData = {}): Promise<ActionsListResponseDTO> {
try {
const response = await apiClient.actionsV2.v2ListActions({
query: {
actions: data.actions,
apps: data.apps,
showAll: data.showAll,
tags: data.tags,
useCase: data.useCase as string,
filterImportantActions: data.filterImportantActions,
showEnabledOnly: data.showEnabledOnly
}
});
return response.data!;
} catch (error) {
throw CEG.handleError(error);
}
}

/**
Expand All @@ -196,17 +203,20 @@ export class Actions {
* This method allows you to trigger the execution of an action by providing its name and the necessary input parameters. The request includes the connected account ID to identify the app connection to use for the action, and the input parameters required by the action. The response provides details about the execution status and the response data returned by the action.
*
* @param {ExecuteActionData} data The data for the request.
* @returns {CancelablePromise<ExecuteActionResponse>} A promise that resolves to the execution status and response data.
* @returns {Promise<ExecuteActionResDTO>} A promise that resolves to the execution status and response data.
* @throws {ApiError} If the request fails.
*/
async execute(data: ExecuteActionData): Promise<ExecuteActionResDTO> {
const {data:res} = await apiClient.actionsV2.v2ExecuteAction({
body: data.requestBody,
path: {
actionId: data.actionName
}
})

return res!
try {
const { data: res } = await apiClient.actionsV2.v2ExecuteAction({
body: data.requestBody,
path: {
actionId: data.actionName
}
});
return res!;
} catch (error) {
throw CEG.handleError(error);
}
}
}
}
62 changes: 39 additions & 23 deletions js/src/sdk/models/activeTriggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TriggersControllerListTriggersData } from "../client";
import { TriggersControllerGetActiveTriggersData, TriggersControllerGetTriggerData } from "../client/types.gen";
import apiClient from "../client/client"
import { BackendClient } from "./backendClient";
import { CEG } from "../utils/error";

export class ActiveTriggers {

Expand All @@ -19,9 +20,13 @@ export class ActiveTriggers {
* @returns {CancelablePromise<GetActiveTriggerResponse>} A promise that resolves to the details of the active trigger.
* @throws {ApiError} If the request fails.
*/
get(data: TriggersControllerGetTriggerData) {
//@ts-ignore
return apiClient.triggers.getTrigger(data).then(res => res.data)
async get(data: TriggersControllerGetTriggerData) {
try {
const response = await apiClient.triggers.getTrigger(data);
return response.data;
} catch (error) {
throw CEG.handleError(error);
}
}

/**
Expand All @@ -33,10 +38,13 @@ export class ActiveTriggers {
* @returns {CancelablePromise<ListActiveTriggersResponse>} A promise that resolves to the list of all active triggers.
* @throws {ApiError} If the request fails.
*/
list(data: TriggersControllerGetActiveTriggersData = {}) {
return apiClient.triggers.getActiveTriggers({
query: data
}).then(res => (res.data as Record<string,string>).triggers)
async list(data: TriggersControllerGetActiveTriggersData = {}) {
try {
const response = await apiClient.triggers.getActiveTriggers({ query: data });
return (response.data as Record<string, string>).triggers;
} catch (error) {
throw CEG.handleError(error);
}
}

/**
Expand All @@ -47,23 +55,31 @@ export class ActiveTriggers {
* @returns {CancelablePromise<Record<string, any>>} A promise that resolves to the response of the enable request.
* @throws {ApiError} If the request fails.
*/
async enable(data: {triggerId: string}): Promise<boolean> {
await apiClient.triggers.switchTriggerInstanceStatus({
path: data,
body:{
enabled: true
}
})
return true
async enable(data: { triggerId: string }): Promise<boolean> {
try {
await apiClient.triggers.switchTriggerInstanceStatus({
path: data,
body: {
enabled: true
}
});
return true;
} catch (error) {
throw CEG.handleError(error);
}
}

async disable(data: {triggerId: string}) {
await apiClient.triggers.switchTriggerInstanceStatus({
path: data,
body: {
enabled: false
}
})
return true
async disable(data: { triggerId: string }) {
try {
await apiClient.triggers.switchTriggerInstanceStatus({
path: data,
body: {
enabled: false
}
});
return true;
} catch (error) {
throw CEG.handleError(error);
}
}
}
10 changes: 7 additions & 3 deletions js/src/sdk/models/backendClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ export class BackendClient {
* @throws Will throw an error if the HTTP request fails.
*/
public async getClientId(): Promise<string> {
const response = await apiClient.clientAuthService.getUserInfo();
if (response.status !== 200) {
try {
const response = await apiClient.clientAuthService.getUserInfo();
if (response.status !== 200) {
throw new Error(`HTTP Error: ${response.status}`);
}
return (response.data as unknown as Record<string, Record<string, string>>).client.id;
return (response.data as unknown as Record<string, Record<string, string>>).client.id;
} catch (error) {
throw CEG.handleError(error);
}
}

/**
Expand Down
Loading

0 comments on commit 9af3781

Please sign in to comment.