fix: Type errors related with global variable of connection

This commit is contained in:
Faruk AYDIN
2022-10-04 20:31:32 +03:00
parent 67cb57e7ac
commit dc0e03245f
5 changed files with 37 additions and 38 deletions

View File

@@ -1,12 +1,13 @@
import qs from 'qs'; import qs from 'qs';
import { IGlobalVariableForConnection } from '../../../helpers/global-variable/connection';
const verifyCredentials = async ($: any) => { const verifyCredentials = async ($: IGlobalVariableForConnection) => {
const headers = { const headers = {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}; };
const stringifiedBody = qs.stringify({ const stringifiedBody = qs.stringify({
token: $.auth.accessToken, token: $.auth.data.accessToken,
}); });
const response = await $.http.post('/auth.test', stringifiedBody, { const response = await $.http.post('/auth.test', stringifiedBody, {
@@ -24,7 +25,7 @@ const verifyCredentials = async ($: any) => {
$.auth.set({ $.auth.set({
botId, botId,
screenName, screenName,
token: $.auth.accessToken, token: $.auth.data.accessToken,
}); });
return response.data; return response.data;

View File

@@ -1,15 +1,10 @@
import createHttpClient from '../http-client'; import createHttpClient from '../http-client';
import Connection from '../../models/connection'; import Connection from '../../models/connection';
import { IJSONObject, IApp } from '@automatisch/types'; import {
import { AxiosInstance as IHttpClient } from 'axios'; IJSONObject,
IApp,
type IGlobalVariableForConnection = { IGlobalVariableForConnection,
auth: { } from '@automatisch/types';
set: (args: IJSONObject) => Promise<Connection>;
};
app: IApp;
http: IHttpClient;
};
const prepareGlobalVariableForConnection = ( const prepareGlobalVariableForConnection = (
connection: Connection, connection: Connection,
@@ -18,16 +13,14 @@ const prepareGlobalVariableForConnection = (
return { return {
auth: { auth: {
set: async (args: IJSONObject) => { set: async (args: IJSONObject) => {
const persistedConnection = await connection.$query().patchAndFetch({ return await connection.$query().patchAndFetch({
formattedData: { formattedData: {
...connection.formattedData, ...connection.formattedData,
...args, ...args,
}, },
}); });
return persistedConnection;
}, },
...connection.formattedData, data: connection.formattedData,
}, },
app: appData, app: appData,
http: createHttpClient({ baseURL: appData.baseUrl }), http: createHttpClient({ baseURL: appData.baseUrl }),

View File

@@ -1,7 +0,0 @@
import { IJSONObject } from '@automatisch/types';
declare module 'axios' {
interface AxiosResponse {
integrationError?: IJSONObject;
}
}

View File

@@ -9,23 +9,17 @@
"noImplicitAny": true, "noImplicitAny": true,
"outDir": "dist", "outDir": "dist",
"paths": { "paths": {
"*": [ "*": ["../../node_modules/*", "node_modules/*", "src/types/*"]
"../../node_modules/*",
"node_modules/*",
"src/types/*"
]
}, },
"skipLibCheck": true, "skipLibCheck": true,
"sourceMap": true, "sourceMap": true,
"target": "es2021", "target": "es2021",
"typeRoots": [ "typeRoots": [
"node_modules/@types", "node_modules/@types",
"node_modules/@automatisch/types",
"./src/types", "./src/types",
"./src/apps" "./src/apps"
] ]
}, },
"include": [ "include": ["src/**/*", "bin/**/*"]
"src/**/*",
"bin/**/*"
]
} }

View File

@@ -1,3 +1,6 @@
import type { AxiosInstance } from 'axios';
export type IHttpClient = AxiosInstance;
// Type definitions for automatisch // Type definitions for automatisch
export type IJSONValue = string | number | boolean | IJSONObject | IJSONArray; export type IJSONValue = string | number | boolean | IJSONObject | IJSONArray;
@@ -10,11 +13,11 @@ export interface IConnection {
id: string; id: string;
key: string; key: string;
data: string; data: string;
formattedData: IJSONObject; formattedData?: IJSONObject;
userId: string; userId: string;
verified: boolean; verified: boolean;
count: number; count?: number;
flowCount: number; flowCount?: number;
appData?: IApp; appData?: IApp;
createdAt: string; createdAt: string;
} }
@@ -22,7 +25,7 @@ export interface IConnection {
export interface IExecutionStep { export interface IExecutionStep {
id: string; id: string;
executionId: string; executionId: string;
stepId: IStep["id"]; stepId: IStep['id'];
step: IStep; step: IStep;
dataIn: IJSONObject; dataIn: IJSONObject;
dataOut: IJSONObject; dataOut: IJSONObject;
@@ -128,7 +131,7 @@ export interface IFieldText {
dependsOn: string[]; dependsOn: string[];
} }
type IField = IFieldDropdown | IFieldText; export type IField = IFieldDropdown | IFieldText;
export interface IAuthenticationStepField { export interface IAuthenticationStepField {
name: string; name: string;
@@ -190,4 +193,19 @@ export interface ISubstep {
export type IHttpClientParams = { export type IHttpClientParams = {
baseURL?: string; baseURL?: string;
};
export type IGlobalVariableForConnection = {
auth: {
set: (args: IJSONObject) => Promise<IConnection>;
data: IJSONObject;
};
app: IApp;
http: IHttpClient;
};
declare module 'axios' {
interface AxiosResponse {
integrationError?: IJSONObject;
}
} }