chore: introduce @automatisch/types

This commit is contained in:
Ali BARIN
2022-03-01 22:56:19 +01:00
committed by Ömer Faruk Aydın
parent bbb6f0b0ff
commit 3391578655
54 changed files with 377 additions and 297 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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,
});

View File

@@ -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: {},
});

View File

@@ -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 }
})

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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'] },

View File

@@ -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' },
},
};

View File

@@ -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 },

View File

@@ -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 },
},

View File

@@ -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);

View File

@@ -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;

View File

@@ -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>;