chore: introduce @automatisch/types
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
bbb6f0b0ff
commit
3391578655
@@ -18,7 +18,6 @@
|
||||
"dependencies": {
|
||||
"@automatisch/web": "0.1.0",
|
||||
"@octokit/oauth-methods": "^1.2.6",
|
||||
"@types/lodash.get": "^4.4.6",
|
||||
"axios": "0.24.0",
|
||||
"bcrypt": "^5.0.1",
|
||||
"cors": "^2.8.5",
|
||||
@@ -66,11 +65,13 @@
|
||||
"url": "https://github.com/automatisch/automatisch/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@automatisch/types": "0.1.0",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/crypto-js": "^4.0.2",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/http-errors": "^1.8.1",
|
||||
"@types/lodash.get": "^4.4.6",
|
||||
"@types/morgan": "^1.9.3",
|
||||
"@types/node": "^16.10.2",
|
||||
"@types/nodemailer": "^6.4.4",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { IField } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import Field from '../../types/field';
|
||||
|
||||
export default class Authentication {
|
||||
appData: any;
|
||||
@@ -18,7 +18,7 @@ export default class Authentication {
|
||||
|
||||
get oauthRedirectUrl() {
|
||||
return this.appData.fields.find(
|
||||
(field: Field) => field.key == 'oAuthRedirectUrl'
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
).value;
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,15 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IField,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import { google as GoogleApi } from 'googleapis';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
import Field from '../../types/field';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: OAuth2Client;
|
||||
|
||||
scopes: string[] = [
|
||||
@@ -17,7 +19,7 @@ export default class Authentication implements AuthenticationInterface {
|
||||
'profile',
|
||||
];
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.appData = appData;
|
||||
this.connectionData = connectionData;
|
||||
|
||||
@@ -32,7 +34,7 @@ export default class Authentication implements AuthenticationInterface {
|
||||
|
||||
get oauthRedirectUrl() {
|
||||
return this.appData.fields.find(
|
||||
(field: Field) => field.key == 'oAuthRedirectUrl'
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
).value;
|
||||
}
|
||||
|
||||
|
@@ -1,16 +1,18 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IField,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import FlickrApi from 'flickr-sdk';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import Field from '../../types/field';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: typeof FlickrApi;
|
||||
oauthClient: typeof FlickrApi;
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.oauthClient = new FlickrApi.OAuth(
|
||||
connectionData.consumerKey,
|
||||
connectionData.consumerSecret
|
||||
@@ -33,7 +35,7 @@ export default class Authentication implements AuthenticationInterface {
|
||||
|
||||
async createAuthData() {
|
||||
const appFields = this.appData.fields.find(
|
||||
(field: Field) => field.key == 'oAuthRedirectUrl'
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const callbackUrl = appFields.value;
|
||||
|
||||
|
@@ -1,16 +1,18 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IField,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import {
|
||||
getWebFlowAuthorizationUrl,
|
||||
exchangeWebFlowCode,
|
||||
checkToken,
|
||||
} from '@octokit/oauth-methods';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import Field from '../../types/field';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
scopes: string[] = ['repo'];
|
||||
client: {
|
||||
getWebFlowAuthorizationUrl: typeof getWebFlowAuthorizationUrl;
|
||||
@@ -18,7 +20,7 @@ export default class Authentication implements AuthenticationInterface {
|
||||
checkToken: typeof checkToken;
|
||||
};
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.connectionData = connectionData;
|
||||
this.appData = appData;
|
||||
|
||||
@@ -31,7 +33,7 @@ export default class Authentication implements AuthenticationInterface {
|
||||
|
||||
get oauthRedirectUrl(): string {
|
||||
return this.appData.fields.find(
|
||||
(field: Field) => field.key == 'oAuthRedirectUrl'
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
).value;
|
||||
}
|
||||
|
||||
|
@@ -1,14 +1,17 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IField,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import { Client } from 'pg';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: Client;
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.client = new Client({
|
||||
host: connectionData.host as string,
|
||||
port: connectionData.port as number,
|
||||
|
@@ -1,13 +1,16 @@
|
||||
import nodemailer, { Transporter, TransportOptions } from 'nodemailer';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
|
||||
export default class Authentication {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: Transporter;
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.client = nodemailer.createTransport({
|
||||
host: connectionData.host,
|
||||
port: connectionData.port,
|
||||
|
@@ -1,14 +1,16 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import TwilioApi from 'twilio';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: TwilioApi.Twilio;
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.client = TwilioApi(
|
||||
connectionData.accountSid as string,
|
||||
connectionData.authToken as string
|
||||
|
@@ -1,9 +1,11 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IField,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import TwitchApi, { TwitchJsOptions } from 'twitch-js';
|
||||
import fetchUtil from 'twitch-js/lib/utils/fetch';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import Field from '../../types/field';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
type TwitchTokenResponse = {
|
||||
accessToken: string;
|
||||
@@ -12,12 +14,12 @@ type TwitchTokenResponse = {
|
||||
tokenType: string;
|
||||
};
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: TwitchApi;
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.connectionData = connectionData;
|
||||
this.appData = appData;
|
||||
|
||||
@@ -36,7 +38,7 @@ export default class Authentication implements AuthenticationInterface {
|
||||
|
||||
get oauthRedirectUrl() {
|
||||
return this.appData.fields.find(
|
||||
(field: Field) => field.key == 'oAuthRedirectUrl'
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
).value;
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,17 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IField,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import TwitterApi, { TwitterApiTokens } from 'twitter-api-v2';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import Field from '../../types/field';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: TwitterApi;
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.appData = appData;
|
||||
this.connectionData = connectionData;
|
||||
|
||||
@@ -25,7 +27,7 @@ export default class Authentication implements AuthenticationInterface {
|
||||
|
||||
async createAuthData() {
|
||||
const appFields = this.appData.fields.find(
|
||||
(field: Field) => field.key == 'oAuthRedirectUrl'
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const callbackUrl = appFields.value;
|
||||
|
||||
|
@@ -1,13 +1,15 @@
|
||||
import AuthenticationInterface from '../../types/interfaces/authentication-interface';
|
||||
import type {
|
||||
IAuthentication,
|
||||
IApp,
|
||||
IField,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import AppInfo from '../../types/app-info';
|
||||
import Field from '../../types/field';
|
||||
import JSONObject from '../../types/interfaces/json-object';
|
||||
|
||||
export default class Authentication implements AuthenticationInterface {
|
||||
appData: AppInfo;
|
||||
connectionData: JSONObject;
|
||||
export default class Authentication implements IAuthentication {
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: AxiosInstance = axios.create({
|
||||
baseURL: 'https://api.typeform.com',
|
||||
});
|
||||
@@ -22,14 +24,14 @@ export default class Authentication implements AuthenticationInterface {
|
||||
'workspaces:read',
|
||||
];
|
||||
|
||||
constructor(appData: AppInfo, connectionData: JSONObject) {
|
||||
constructor(appData: IApp, connectionData: IJSONObject) {
|
||||
this.connectionData = connectionData;
|
||||
this.appData = appData;
|
||||
}
|
||||
|
||||
get oauthRedirectUrl() {
|
||||
return this.appData.fields.find(
|
||||
(field: Field) => field.key == 'oAuthRedirectUrl'
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
).value;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import Step from '../../models/step';
|
||||
import flowType, { flowInputType } from '../types/flow';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import { StepType } from '../../types/step';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
@@ -21,7 +20,7 @@ const createFlowResolver = async (
|
||||
|
||||
await Step.query().insert({
|
||||
flowId: flow.id,
|
||||
type: StepType.Trigger,
|
||||
type: 'trigger',
|
||||
position: 1,
|
||||
appKey,
|
||||
});
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { GraphQLNonNull } from 'graphql';
|
||||
import stepType, { stepInputType } from '../types/step';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import { StepType } from '../../types/step';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
@@ -42,7 +41,7 @@ const createStepResolver = async (
|
||||
const step = await flow.$relatedQuery('steps').insertAndFetch({
|
||||
key: input.key,
|
||||
appKey: input.appKey,
|
||||
type: StepType.Action,
|
||||
type: 'action',
|
||||
position: previousStep.position + 1,
|
||||
parameters: {},
|
||||
});
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import type { IApp } from '@automatisch/types';
|
||||
import { GraphQLEnumType } from 'graphql';
|
||||
import App from '../../models/app';
|
||||
import appInfoType from '../../types/app-info'
|
||||
|
||||
const apps = App.findAll();
|
||||
const availableAppEnumValues: any = {}
|
||||
|
||||
apps.forEach((app: appInfoType) => {
|
||||
apps.forEach((app: IApp) => {
|
||||
availableAppEnumValues[app.key] = { value: app.key }
|
||||
})
|
||||
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import AppInfoType from '../types/app-info';
|
||||
import type { IApp } from '@automatisch/types';
|
||||
import appConfig from '../config/app';
|
||||
|
||||
const appInfoConverter = (rawAppData: string) => {
|
||||
let computedRawData = rawAppData.replace('{BASE_URL}', appConfig.baseUrl);
|
||||
computedRawData = computedRawData.replace('{WEB_APP_URL}', appConfig.webAppUrl);
|
||||
|
||||
const computedJSONData: AppInfoType = JSON.parse(computedRawData)
|
||||
const computedJSONData: IApp = JSON.parse(computedRawData)
|
||||
return computedJSONData;
|
||||
}
|
||||
|
||||
|
@@ -6,10 +6,10 @@ import User from './user';
|
||||
import appConfig from '../config/app';
|
||||
|
||||
class Connection extends Base {
|
||||
id!: number;
|
||||
id!: string;
|
||||
key!: string;
|
||||
data!: any;
|
||||
userId!: number;
|
||||
userId!: string;
|
||||
verified: boolean;
|
||||
count: number;
|
||||
|
||||
|
@@ -4,8 +4,8 @@ import Step from './step';
|
||||
|
||||
class ExecutionStep extends Base {
|
||||
id!: string;
|
||||
executionId!: number;
|
||||
stepId!: number;
|
||||
executionId!: string;
|
||||
stepId!: string;
|
||||
dataIn!: any;
|
||||
dataOut!: any;
|
||||
status: string;
|
||||
@@ -17,8 +17,8 @@ class ExecutionStep extends Base {
|
||||
|
||||
properties: {
|
||||
id: { type: 'string' },
|
||||
executionId: { type: 'integer' },
|
||||
stepId: { type: 'integer' },
|
||||
executionId: { type: 'string' },
|
||||
stepId: { type: 'string' },
|
||||
dataIn: { type: 'object' },
|
||||
dataOut: { type: 'object' },
|
||||
status: { type: 'string', enum: ['success', 'failure'] },
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { ModelOptions, QueryContext, ValidationError } from 'objection';
|
||||
import { ValidationError } from 'objection';
|
||||
import Base from './base';
|
||||
import Step from './step';
|
||||
|
||||
class Flow extends Base {
|
||||
id!: string;
|
||||
name: string;
|
||||
userId!: number;
|
||||
userId!: string;
|
||||
active: boolean;
|
||||
steps?: [Step];
|
||||
|
||||
@@ -17,7 +17,7 @@ class Flow extends Base {
|
||||
properties: {
|
||||
id: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
userId: { type: 'integer' },
|
||||
userId: { type: 'string' },
|
||||
active: { type: 'boolean' },
|
||||
},
|
||||
};
|
||||
|
@@ -2,14 +2,14 @@ import Base from './base';
|
||||
import Flow from './flow';
|
||||
import Connection from './connection';
|
||||
import ExecutionStep from './execution-step';
|
||||
import { StepType } from '../types/step';
|
||||
import type { IStep } from '@automatisch/types';
|
||||
|
||||
class Step extends Base {
|
||||
id!: number;
|
||||
id!: string;
|
||||
flowId!: string;
|
||||
key: string;
|
||||
appKey: string;
|
||||
type!: StepType;
|
||||
type!: IStep["type"];
|
||||
connectionId?: string;
|
||||
status: string;
|
||||
position: number;
|
||||
@@ -25,7 +25,7 @@ class Step extends Base {
|
||||
required: ['type'],
|
||||
|
||||
properties: {
|
||||
id: { type: 'integer' },
|
||||
id: { type: 'string' },
|
||||
flowId: { type: 'string' },
|
||||
key: { type: ['string', 'null'] },
|
||||
appKey: { type: ['string', 'null'], minLength: 1, maxLength: 255 },
|
||||
|
@@ -6,7 +6,7 @@ import Step from './step';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
class User extends Base {
|
||||
id!: number;
|
||||
id!: string;
|
||||
email!: string;
|
||||
password!: string;
|
||||
connections?: [Connection];
|
||||
@@ -20,7 +20,7 @@ class User extends Base {
|
||||
required: ['email', 'password'],
|
||||
|
||||
properties: {
|
||||
id: { type: 'integer' },
|
||||
id: { type: 'string' },
|
||||
email: { type: 'string', format: 'email', minLength: 1, maxLength: 255 },
|
||||
password: { type: 'string', minLength: 1, maxLength: 255 },
|
||||
},
|
||||
|
@@ -4,7 +4,6 @@ import Flow from '../models/flow';
|
||||
import Step from '../models/step';
|
||||
import Execution from '../models/execution';
|
||||
import ExecutionStep from '../models/execution-step';
|
||||
import { StepType } from '../types/step';
|
||||
|
||||
type ExecutionSteps = Record<string, ExecutionStep>;
|
||||
|
||||
@@ -44,7 +43,7 @@ class Processor {
|
||||
parameters: rawParameters = {},
|
||||
id
|
||||
} = step;
|
||||
const isTrigger = type === StepType.Trigger;
|
||||
const isTrigger = type === 'trigger';
|
||||
const AppClass = (await import(`../apps/${appKey}`)).default;
|
||||
const computedParameters = Processor.computeParameters(rawParameters, priorExecutionSteps);
|
||||
const appInstance = new AppClass(appData, connection.data, computedParameters);
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import AuthenticationStepField from '../types/authentication-step-field';
|
||||
import type { IAuthenticationStepField } from '@automatisch/types';
|
||||
|
||||
type AuthenticationStep = {
|
||||
step: number,
|
||||
type: string,
|
||||
name: string,
|
||||
fields: AuthenticationStepField[];
|
||||
fields: IAuthenticationStepField[];
|
||||
}
|
||||
|
||||
export default AuthenticationStep;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import appInfoType from '../../types/app-info';
|
||||
import type { IApp } from '@automatisch/types';
|
||||
import JSONObject from './json-object';
|
||||
|
||||
export default interface AuthenticationInterface {
|
||||
appData: appInfoType;
|
||||
connectionData: JSONObject;
|
||||
appData: IApp;
|
||||
connectionData: IJSONObject;
|
||||
client: unknown;
|
||||
verifyCredentials(): Promise<JSONObject>;
|
||||
isStillVerified(): Promise<boolean>;
|
||||
|
@@ -9,9 +9,18 @@
|
||||
"outDir": "dist",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"*": ["node_modules/*", "src/types/*"]
|
||||
"*": [
|
||||
"node_modules/*",
|
||||
"src/types/*"
|
||||
]
|
||||
},
|
||||
"typeRoots": ["node_modules/@types", "./src/types", "./src/apps/*/types"]
|
||||
"typeRoots": [
|
||||
"node_modules/@types",
|
||||
"./src/types",
|
||||
"./src/apps/*/types"
|
||||
]
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user