From 06f7888dc66a8bf7193691cafc64e6d344c5b8ce Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Tue, 10 Dec 2024 00:14:16 +0530 Subject: [PATCH] feat: connectedAccount fix --- js/src/cli/apps.ts | 12 ++++++++---- js/src/sdk/models/connectedAccounts.ts | 14 ++++++++------ js/src/sdk/utils/errors/src/constants.ts | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/js/src/cli/apps.ts b/js/src/cli/apps.ts index e9e8dca6cbc..2c3fe1f7deb 100644 --- a/js/src/cli/apps.ts +++ b/js/src/cli/apps.ts @@ -5,10 +5,14 @@ import { Command } from "commander"; import { getOpenAPIClient } from "../sdk/utils/config"; import client from "../sdk/client/client"; -// @ts-ignore import resolvePackagePath from "resolve-package-path"; import fs from "fs"; import path from "path"; + +type ErrorWithMessage = { + message: string; +}; + export default class AppsCommand { private program: Command; @@ -34,7 +38,7 @@ export default class AppsCommand { console.log(app.key); } } catch (error) { - console.log(chalk.red((error as any).message)); + console.log(chalk.red((error as ErrorWithMessage).message)); return; } } @@ -77,7 +81,7 @@ class AppUpdateCommand { } } catch (e) { console.log(chalk.red("Error while updating constants file")); - console.log(chalk.red((e as any).message)); + console.log(chalk.red((e as ErrorWithMessage).message)); } const constantFile = fs.readFileSync(constantFilePath, "utf8"); @@ -100,7 +104,7 @@ class AppUpdateCommand { ); } catch (e) { console.log(chalk.red("Error while updating constants file")); - console.log(chalk.red((e as any).message)); + console.log(chalk.red((e as ErrorWithMessage).message)); } } diff --git a/js/src/sdk/models/connectedAccounts.ts b/js/src/sdk/models/connectedAccounts.ts index e0bdabf4509..7fd1f954af5 100644 --- a/js/src/sdk/models/connectedAccounts.ts +++ b/js/src/sdk/models/connectedAccounts.ts @@ -4,6 +4,7 @@ import { GetConnectionInfoData, GetConnectionInfoResponse, GetConnectionsData, + InitiateConnectionResponse2, } from "../client"; import client from "../client/client"; import apiClient from "../client/client"; @@ -11,6 +12,7 @@ import { BackendClient } from "./backendClient"; import { Integrations } from "./integrations"; import { Apps } from "./apps"; import { CEG } from "../utils/error"; +import { SDK_ERROR_CODES } from "../utils/errors/src/constants"; type ConnectedAccountsListData = GetConnectionsData["query"] & { appNames?: string; @@ -53,13 +55,13 @@ export class ConnectedAccounts { try { const { data: res } = await apiClient.connections.initiateConnection({ body: data, + }) as { data: InitiateConnectionResponse2 }; + + return new ConnectionRequest({ + connectionStatus: res.connectionStatus, + connectedAccountId: res.connectedAccountId, + redirectUri: res.redirectUrl ?? null }); - //@ts-ignore - return new ConnectionRequest( - res.connectionStatus, - res.connectedAccountId, - res.redirectUrl - ); } catch (error) { throw CEG.handleAllError(error); } diff --git a/js/src/sdk/utils/errors/src/constants.ts b/js/src/sdk/utils/errors/src/constants.ts index c4b8f1db799..42c4641f479 100644 --- a/js/src/sdk/utils/errors/src/constants.ts +++ b/js/src/sdk/utils/errors/src/constants.ts @@ -19,6 +19,7 @@ export const SDK_ERROR_CODES = { }, SDK: { NO_CONNECTED_ACCOUNT_FOUND: "SDK::NO_CONNECTED_ACCOUNT_FOUND", + FAILED_TO_INITIATE_CONNECTION: "SDK::FAILED_TO_INITIATE_CONNECTION", }, };