refactor: Use generateAuthUrl method instead of createAuthData

This commit is contained in:
Faruk AYDIN
2022-11-10 18:50:36 +01:00
parent 10e2794ff9
commit 81c41ef5ee
21 changed files with 42 additions and 50 deletions

View File

@@ -2,7 +2,7 @@ import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
import scopes from '../common/scopes'; import scopes from '../common/scopes';
export default async function createAuthData($: IGlobalVariable) { export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find( const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl' (field: IField) => field.key == 'oAuthRedirectUrl'
); );

View File

@@ -1,9 +1,8 @@
import createAuthData from './create-auth-data'; import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials'; import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified'; import isStillVerified from './is-still-verified';
export default { export default {
generateAuthUrl: true,
fields: [ fields: [
{ {
key: 'oAuthRedirectUrl', key: 'oAuthRedirectUrl',
@@ -56,7 +55,7 @@ export default {
}, },
], ],
createAuthData, generateAuthUrl,
verifyCredentials, verifyCredentials,
isStillVerified, isStillVerified,
}; };

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types'; import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
export default async function createAuthData($: IGlobalVariable) { export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find( const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl' (field: IField) => field.key == 'oAuthRedirectUrl'
); );

View File

@@ -1,9 +1,8 @@
import createAuthData from './create-auth-data'; import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials'; import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified'; import isStillVerified from './is-still-verified';
export default { export default {
generateAuthUrl: true,
fields: [ fields: [
{ {
key: 'oAuthRedirectUrl', key: 'oAuthRedirectUrl',
@@ -43,8 +42,7 @@ export default {
clickToCopy: false, clickToCopy: false,
}, },
], ],
generateAuthUrl,
createAuthData,
verifyCredentials, verifyCredentials,
isStillVerified, isStillVerified,
}; };

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types'; import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
export default async function createAuthData($: IGlobalVariable) { export default async function generateAuthUrl($: IGlobalVariable) {
const scopes = ['read:org', 'repo', 'user']; const scopes = ['read:org', 'repo', 'user'];
const oauthRedirectUrlField = $.app.auth.fields.find( const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl' (field: IField) => field.key == 'oAuthRedirectUrl'

View File

@@ -1,9 +1,8 @@
import createAuthData from './create-auth-data'; import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials'; import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified'; import isStillVerified from './is-still-verified';
export default { export default {
generateAuthUrl: true,
fields: [ fields: [
{ {
key: 'oAuthRedirectUrl', key: 'oAuthRedirectUrl',
@@ -44,7 +43,7 @@ export default {
}, },
], ],
createAuthData, generateAuthUrl,
verifyCredentials, verifyCredentials,
isStillVerified, isStillVerified,
}; };

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types'; import { IField, IGlobalVariable } from '@automatisch/types';
import qs from 'qs'; import qs from 'qs';
export default async function createAuthData($: IGlobalVariable) { export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find( const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl' (field: IField) => field.key == 'oAuthRedirectUrl'
); );

View File

@@ -1,9 +1,8 @@
import createAuthData from './create-auth-data'; import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials'; import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified'; import isStillVerified from './is-still-verified';
export default { export default {
generateAuthUrl: true,
fields: [ fields: [
{ {
key: 'oAuthRedirectUrl', key: 'oAuthRedirectUrl',
@@ -62,7 +61,7 @@ export default {
}, },
], ],
createAuthData, generateAuthUrl,
verifyCredentials, verifyCredentials,
isStillVerified, isStillVerified,
}; };

View File

@@ -42,7 +42,7 @@ const userScopes = [
'users:read.email', 'users:read.email',
]; ];
export default async function createAuthData($: IGlobalVariable) { export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find( const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl' (field: IField) => field.key == 'oAuthRedirectUrl'
); );

View File

@@ -1,9 +1,8 @@
import createAuthData from './create-auth-data'; import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials'; import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified'; import isStillVerified from './is-still-verified';
export default { export default {
generateAuthUrl: true,
fields: [ fields: [
{ {
key: 'oAuthRedirectUrl', key: 'oAuthRedirectUrl',
@@ -41,7 +40,7 @@ export default {
}, },
], ],
createAuthData, generateAuthUrl,
verifyCredentials, verifyCredentials,
isStillVerified, isStillVerified,
}; };

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types'; import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
export default async function createAuthData($: IGlobalVariable) { export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find( const oauthRedirectUrlField = $.app.auth.fields.find(
(field: IField) => field.key == 'oAuthRedirectUrl' (field: IField) => field.key == 'oAuthRedirectUrl'
); );

View File

@@ -1,9 +1,8 @@
import createAuthData from './create-auth-data'; import generateAuthUrl from './generate-auth-url';
import verifyCredentials from './verify-credentials'; import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified'; import isStillVerified from './is-still-verified';
export default { export default {
generateAuthUrl: true,
fields: [ fields: [
{ {
key: 'oAuthRedirectUrl', key: 'oAuthRedirectUrl',
@@ -41,7 +40,7 @@ export default {
}, },
], ],
createAuthData, generateAuthUrl,
verifyCredentials, verifyCredentials,
isStillVerified, isStillVerified,
}; };

View File

@@ -1,7 +1,7 @@
import { IJSONObject } from '@automatisch/types'; import { IJSONObject } from '@automatisch/types';
import BaseError from './base'; import BaseError from './base';
export default class CreateAuthDataError extends BaseError { export default class GenerateAuthUrlError extends BaseError {
constructor(error: IJSONObject) { constructor(error: IJSONObject) {
const computedError = const computedError =
((error.response as IJSONObject)?.data as IJSONObject) || ((error.response as IJSONObject)?.data as IJSONObject) ||

View File

@@ -1,5 +1,5 @@
import createConnection from './mutations/create-connection'; import createConnection from './mutations/create-connection';
import createAuthData from './mutations/create-auth-data'; import generateAuthUrl from './mutations/generate-auth-url';
import updateConnection from './mutations/update-connection'; import updateConnection from './mutations/update-connection';
import resetConnection from './mutations/reset-connection'; import resetConnection from './mutations/reset-connection';
import verifyConnection from './mutations/verify-connection'; import verifyConnection from './mutations/verify-connection';
@@ -17,7 +17,7 @@ import login from './mutations/login';
const mutationResolvers = { const mutationResolvers = {
createConnection, createConnection,
createAuthData, generateAuthUrl,
updateConnection, updateConnection,
resetConnection, resetConnection,
verifyConnection, verifyConnection,

View File

@@ -2,7 +2,7 @@ import Context from '../../types/express/context';
import axios from 'axios'; import axios from 'axios';
import globalVariable from '../../helpers/global-variable'; import globalVariable from '../../helpers/global-variable';
import App from '../../models/app'; import App from '../../models/app';
import CreateAuthDataError from '../../errors/create-auth-data'; import GenerateAuthUrlError from '../../errors/generate-auth-url';
type Params = { type Params = {
input: { input: {
@@ -10,7 +10,7 @@ type Params = {
}; };
}; };
const createAuthData = async ( const generateAuthUrl = async (
_parent: unknown, _parent: unknown,
params: Params, params: Params,
context: Context context: Context
@@ -32,13 +32,13 @@ const createAuthData = async (
const $ = await globalVariable({ connection, app }); const $ = await globalVariable({ connection, app });
try { try {
await authInstance.createAuthData($); await authInstance.generateAuthUrl($);
await axios.get(connection.formattedData.url as string); await axios.get(connection.formattedData.url as string);
} catch (error) { } catch (error) {
throw new CreateAuthDataError(error); throw new GenerateAuthUrlError(error);
} }
return connection.formattedData; return connection.formattedData;
}; };
export default createAuthData; export default generateAuthUrl;

View File

@@ -30,7 +30,7 @@ type Query {
type Mutation { type Mutation {
createConnection(input: CreateConnectionInput): Connection createConnection(input: CreateConnectionInput): Connection
createAuthData(input: CreateAuthDataInput): AuthLink generateAuthUrl(input: GenerateAuthUrlInput): AuthLink
updateConnection(input: UpdateConnectionInput): Connection updateConnection(input: UpdateConnectionInput): Connection
resetConnection(input: ResetConnectionInput): Connection resetConnection(input: ResetConnectionInput): Connection
verifyConnection(input: VerifyConnectionInput): Connection verifyConnection(input: VerifyConnectionInput): Connection
@@ -225,7 +225,7 @@ input CreateConnectionInput {
formattedData: JSONObject! formattedData: JSONObject!
} }
input CreateAuthDataInput { input GenerateAuthUrlInput {
id: String! id: String!
} }

View File

@@ -54,7 +54,7 @@ const authenticationStepsWithAuthUrl = [
}, },
{ {
type: 'mutation' as const, type: 'mutation' as const,
name: 'createAuthData', name: 'generateAuthUrl',
arguments: [ arguments: [
{ {
name: 'id', name: 'id',
@@ -68,7 +68,7 @@ const authenticationStepsWithAuthUrl = [
arguments: [ arguments: [
{ {
name: 'url', name: 'url',
value: '{createAuthData.url}', value: '{generateAuthUrl.url}',
}, },
], ],
}, },

View File

@@ -178,10 +178,9 @@ export interface IData {
} }
export interface IAuth { export interface IAuth {
createAuthData?($: IGlobalVariable): Promise<void>; generateAuthUrl?($: IGlobalVariable): Promise<void>;
verifyCredentials($: IGlobalVariable): Promise<any>; verifyCredentials($: IGlobalVariable): Promise<any>;
isStillVerified($: IGlobalVariable): Promise<boolean>; isStillVerified($: IGlobalVariable): Promise<boolean>;
generateAuthUrl?: boolean;
fields: IField[]; fields: IField[];
authenticationSteps?: IAuthenticationStep[]; authenticationSteps?: IAuthenticationStep[];
reconnectionSteps?: IAuthenticationStep[]; reconnectionSteps?: IAuthenticationStep[];

View File

@@ -1,9 +0,0 @@
import { gql } from '@apollo/client';
export const CREATE_AUTH_DATA = gql`
mutation CreateAuthData($input: CreateAuthDataInput) {
createAuthData(input: $input) {
url
}
}
`;

View File

@@ -0,0 +1,9 @@
import { gql } from '@apollo/client';
export const GENERATE_AUTH_URL = gql`
mutation generateAuthUrl($input: GenerateAuthUrlInput) {
generateAuthUrl(input: $input) {
url
}
}
`;

View File

@@ -3,7 +3,7 @@ import { UPDATE_CONNECTION } from './update-connection';
import { VERIFY_CONNECTION } from './verify-connection'; import { VERIFY_CONNECTION } from './verify-connection';
import { RESET_CONNECTION } from './reset-connection'; import { RESET_CONNECTION } from './reset-connection';
import { DELETE_CONNECTION } from './delete-connection'; import { DELETE_CONNECTION } from './delete-connection';
import { CREATE_AUTH_DATA } from './create-auth-data'; import { GENERATE_AUTH_URL } from './generate-auth-url';
type Mutations = { type Mutations = {
[key: string]: any; [key: string]: any;
@@ -15,7 +15,7 @@ const mutations: Mutations = {
verifyConnection: VERIFY_CONNECTION, verifyConnection: VERIFY_CONNECTION,
resetConnection: RESET_CONNECTION, resetConnection: RESET_CONNECTION,
deleteConnection: DELETE_CONNECTION, deleteConnection: DELETE_CONNECTION,
createAuthData: CREATE_AUTH_DATA, generateAuthUrl: GENERATE_AUTH_URL,
}; };
export default mutations; export default mutations;