fix: Integration and auth problems wrt slack and twitter
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
@@ -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,
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ export const GET_APP = gql`
|
||||
authDocUrl
|
||||
primaryColor
|
||||
supportsConnections
|
||||
auth {
|
||||
fields {
|
||||
key
|
||||
label
|
||||
@@ -49,6 +50,7 @@ export const GET_APP = gql`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
connections {
|
||||
id
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ export const GET_APPS = gql`
|
||||
primaryColor
|
||||
connectionCount
|
||||
supportsConnections
|
||||
auth {
|
||||
fields {
|
||||
key
|
||||
label
|
||||
@@ -50,6 +51,7 @@ export const GET_APPS = gql`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
triggers {
|
||||
name
|
||||
key
|
||||
|
Reference in New Issue
Block a user