diff --git a/packages/backend/src/apps/slack2/auth/verify-credentials.ts b/packages/backend/src/apps/slack2/auth/verify-credentials.ts index 0c29c0ad..1cd195c9 100644 --- a/packages/backend/src/apps/slack2/auth/verify-credentials.ts +++ b/packages/backend/src/apps/slack2/auth/verify-credentials.ts @@ -1,12 +1,13 @@ import qs from 'qs'; +import { IGlobalVariableForConnection } from '../../../helpers/global-variable/connection'; -const verifyCredentials = async ($: any) => { +const verifyCredentials = async ($: IGlobalVariableForConnection) => { const headers = { 'Content-Type': 'application/x-www-form-urlencoded', }; const stringifiedBody = qs.stringify({ - token: $.auth.accessToken, + token: $.auth.data.accessToken, }); const response = await $.http.post('/auth.test', stringifiedBody, { @@ -24,7 +25,7 @@ const verifyCredentials = async ($: any) => { $.auth.set({ botId, screenName, - token: $.auth.accessToken, + token: $.auth.data.accessToken, }); return response.data; diff --git a/packages/backend/src/helpers/global-variable/connection.ts b/packages/backend/src/helpers/global-variable/connection.ts index 491b402e..45751283 100644 --- a/packages/backend/src/helpers/global-variable/connection.ts +++ b/packages/backend/src/helpers/global-variable/connection.ts @@ -1,15 +1,10 @@ import createHttpClient from '../http-client'; import Connection from '../../models/connection'; -import { IJSONObject, IApp } from '@automatisch/types'; -import { AxiosInstance as IHttpClient } from 'axios'; - -type IGlobalVariableForConnection = { - auth: { - set: (args: IJSONObject) => Promise; - }; - app: IApp; - http: IHttpClient; -}; +import { + IJSONObject, + IApp, + IGlobalVariableForConnection, +} from '@automatisch/types'; const prepareGlobalVariableForConnection = ( connection: Connection, @@ -18,16 +13,14 @@ const prepareGlobalVariableForConnection = ( return { auth: { set: async (args: IJSONObject) => { - const persistedConnection = await connection.$query().patchAndFetch({ + return await connection.$query().patchAndFetch({ formattedData: { ...connection.formattedData, ...args, }, }); - - return persistedConnection; }, - ...connection.formattedData, + data: connection.formattedData, }, app: appData, http: createHttpClient({ baseURL: appData.baseUrl }), diff --git a/packages/backend/src/types/axios.d.ts b/packages/backend/src/types/axios.d.ts deleted file mode 100644 index 948f46b4..00000000 --- a/packages/backend/src/types/axios.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { IJSONObject } from '@automatisch/types'; - -declare module 'axios' { - interface AxiosResponse { - integrationError?: IJSONObject; - } -} diff --git a/packages/backend/tsconfig.json b/packages/backend/tsconfig.json index 3888c0b7..0b471c36 100644 --- a/packages/backend/tsconfig.json +++ b/packages/backend/tsconfig.json @@ -9,23 +9,17 @@ "noImplicitAny": true, "outDir": "dist", "paths": { - "*": [ - "../../node_modules/*", - "node_modules/*", - "src/types/*" - ] + "*": ["../../node_modules/*", "node_modules/*", "src/types/*"] }, "skipLibCheck": true, "sourceMap": true, "target": "es2021", "typeRoots": [ "node_modules/@types", + "node_modules/@automatisch/types", "./src/types", "./src/apps" ] }, - "include": [ - "src/**/*", - "bin/**/*" - ] + "include": ["src/**/*", "bin/**/*"] } diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 0168a9fc..b9cbacae 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -1,3 +1,6 @@ +import type { AxiosInstance } from 'axios'; +export type IHttpClient = AxiosInstance; + // Type definitions for automatisch export type IJSONValue = string | number | boolean | IJSONObject | IJSONArray; @@ -10,11 +13,11 @@ export interface IConnection { id: string; key: string; data: string; - formattedData: IJSONObject; + formattedData?: IJSONObject; userId: string; verified: boolean; - count: number; - flowCount: number; + count?: number; + flowCount?: number; appData?: IApp; createdAt: string; } @@ -22,7 +25,7 @@ export interface IConnection { export interface IExecutionStep { id: string; executionId: string; - stepId: IStep["id"]; + stepId: IStep['id']; step: IStep; dataIn: IJSONObject; dataOut: IJSONObject; @@ -128,7 +131,7 @@ export interface IFieldText { dependsOn: string[]; } -type IField = IFieldDropdown | IFieldText; +export type IField = IFieldDropdown | IFieldText; export interface IAuthenticationStepField { name: string; @@ -190,4 +193,19 @@ export interface ISubstep { export type IHttpClientParams = { baseURL?: string; +}; + +export type IGlobalVariableForConnection = { + auth: { + set: (args: IJSONObject) => Promise; + data: IJSONObject; + }; + app: IApp; + http: IHttpClient; +}; + +declare module 'axios' { + interface AxiosResponse { + integrationError?: IJSONObject; + } }