fix: Integration and auth problems wrt slack and twitter

This commit is contained in:
Faruk AYDIN
2022-10-07 16:05:13 +03:00
parent 2862953136
commit 11ef2ac4bc
8 changed files with 104 additions and 90 deletions

View File

@@ -1,4 +1,4 @@
import { IGlobalVariable } from '@automatisch/types';
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
type FindMessageOptions = {
query: string;
@@ -8,6 +8,11 @@ type FindMessageOptions = {
};
const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
const message: {
data?: IJSONObject;
error?: IJSONObject;
} = {};
const headers = {
Authorization: `Bearer ${$.auth.data.accessToken}`,
};
@@ -24,20 +29,20 @@ const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
params,
});
if (response.integrationError) {
message.error = response.integrationError;
return message;
}
const data = response.data;
if (!data.ok) {
if (data.error === 'missing_scope') {
throw new Error(
`Error occured while finding messages; ${data.error}: ${data.needed}`
);
}
throw new Error(`Error occured while finding messages; ${data.error}`);
message.error = data;
return message;
}
const messages = data.messages.matches;
const message = messages?.[0];
message.data = messages?.[0];
return message;
};

View File

@@ -19,11 +19,16 @@ export default {
},
});
if (response.integrationError || response.data.ok === 'false') {
if (response.integrationError) {
channels.error = response.integrationError;
return channels;
}
if (response.data.ok === 'false') {
channels.error = response.data.error;
return channels;
}
channels.data = response.data.channels.map((channel: IJSONObject) => {
return {
value: channel.id,

View File

@@ -25,7 +25,7 @@ const createAuthData = async (
return null;
}
const authInstance = (await import(`../../apps/${connection.key}2/auth`))
const authInstance = (await import(`../../apps/${connection.key}/auth`))
.default;
const app = await App.findOneByKey(connection.key);

View File

@@ -104,14 +104,18 @@ type App {
authDocUrl: String
primaryColor: String
supportsConnections: Boolean
fields: [Field]
authenticationSteps: [AuthenticationStep]
reconnectionSteps: [ReconnectionStep]
auth: AppAuth
triggers: [Trigger]
actions: [Action]
connections: [Connection]
}
type AppAuth {
fields: [Field]
authenticationSteps: [AuthenticationStep]
reconnectionSteps: [ReconnectionStep]
}
enum ArgumentEnumType {
integer
string

View File

@@ -2,19 +2,21 @@ import type { IApp } from '@automatisch/types';
import appConfig from '../config/app';
const appInfoConverter = (rawAppData: IApp) => {
const stringifiedRawAppData = JSON.stringify(rawAppData);
let computedRawData = stringifiedRawAppData.replace(
rawAppData.iconUrl = rawAppData.iconUrl.replace(
'{BASE_URL}',
appConfig.baseUrl
);
computedRawData = computedRawData.replace(
'{WEB_APP_URL}',
appConfig.webAppUrl
);
const computedJSONData: IApp = JSON.parse(computedRawData);
return computedJSONData;
if (rawAppData.auth?.fields) {
rawAppData.auth.fields = rawAppData.auth.fields.map((field) => {
return {
...field,
value: field.value?.replace('{WEB_APP_URL}', appConfig.webAppUrl),
};
});
}
return rawAppData;
};
export default appInfoConverter;

View File

@@ -10,16 +10,14 @@ class App {
// Temporaryly restrict the apps we expose until
// their actions/triggers are implemented!
static temporaryList = [
'slack',
'twitter',
'scheduler'
];
static temporaryList = ['slack', 'twitter', 'scheduler'];
static async findAll(name?: string, stripFuncs = true): Promise<IApp[]> {
if (!name)
return Promise.all(
this.temporaryList.map(async (name) => await this.findOneByName(name, stripFuncs))
this.temporaryList.map(
async (name) => await this.findOneByName(name, stripFuncs)
)
);
return Promise.all(
@@ -32,16 +30,12 @@ class App {
static async findOneByName(name: string, stripFuncs = false): Promise<IApp> {
const rawAppData = await getApp(name.toLocaleLowerCase(), stripFuncs);
if (!stripFuncs) return rawAppData;
return appInfoConverter(rawAppData);
}
static async findOneByKey(key: string, stripFuncs = false): Promise<IApp> {
const rawAppData = await getApp(key, stripFuncs);
if (!stripFuncs) return rawAppData;
return appInfoConverter(rawAppData);
}
}

View File

@@ -10,42 +10,44 @@ export const GET_APP = gql`
authDocUrl
primaryColor
supportsConnections
fields {
key
label
type
required
readOnly
value
description
docUrl
clickToCopy
}
authenticationSteps {
step
type
name
arguments {
name
value
auth {
fields {
key
label
type
properties {
required
readOnly
value
description
docUrl
clickToCopy
}
authenticationSteps {
step
type
name
arguments {
name
value
type
properties {
name
value
}
}
}
}
reconnectionSteps {
step
type
name
arguments {
name
value
reconnectionSteps {
step
type
properties {
name
arguments {
name
value
type
properties {
name
value
}
}
}
}

View File

@@ -10,43 +10,45 @@ export const GET_APPS = gql`
primaryColor
connectionCount
supportsConnections
fields {
key
label
type
required
readOnly
value
placeholder
description
docUrl
clickToCopy
}
authenticationSteps {
step
type
name
arguments {
name
value
auth {
fields {
key
label
type
properties {
required
readOnly
value
placeholder
description
docUrl
clickToCopy
}
authenticationSteps {
step
type
name
arguments {
name
value
type
properties {
name
value
}
}
}
}
reconnectionSteps {
step
type
name
arguments {
name
value
reconnectionSteps {
step
type
properties {
name
arguments {
name
value
type
properties {
name
value
}
}
}
}