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 scopes from '../common/scopes';
export default async function createAuthData($: IGlobalVariable) {
export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(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 isStillVerified from './is-still-verified';
export default {
generateAuthUrl: true,
fields: [
{
key: 'oAuthRedirectUrl',
@@ -56,7 +55,7 @@ export default {
},
],
createAuthData,
generateAuthUrl,
verifyCredentials,
isStillVerified,
};

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url';
export default async function createAuthData($: IGlobalVariable) {
export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(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 isStillVerified from './is-still-verified';
export default {
generateAuthUrl: true,
fields: [
{
key: 'oAuthRedirectUrl',
@@ -43,8 +42,7 @@ export default {
clickToCopy: false,
},
],
createAuthData,
generateAuthUrl,
verifyCredentials,
isStillVerified,
};

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url';
export default async function createAuthData($: IGlobalVariable) {
export default async function generateAuthUrl($: IGlobalVariable) {
const scopes = ['read:org', 'repo', 'user'];
const oauthRedirectUrlField = $.app.auth.fields.find(
(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 isStillVerified from './is-still-verified';
export default {
generateAuthUrl: true,
fields: [
{
key: 'oAuthRedirectUrl',
@@ -44,7 +43,7 @@ export default {
},
],
createAuthData,
generateAuthUrl,
verifyCredentials,
isStillVerified,
};

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types';
import qs from 'qs';
export default async function createAuthData($: IGlobalVariable) {
export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(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 isStillVerified from './is-still-verified';
export default {
generateAuthUrl: true,
fields: [
{
key: 'oAuthRedirectUrl',
@@ -62,7 +61,7 @@ export default {
},
],
createAuthData,
generateAuthUrl,
verifyCredentials,
isStillVerified,
};

View File

@@ -42,7 +42,7 @@ const userScopes = [
'users:read.email',
];
export default async function createAuthData($: IGlobalVariable) {
export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(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 isStillVerified from './is-still-verified';
export default {
generateAuthUrl: true,
fields: [
{
key: 'oAuthRedirectUrl',
@@ -41,7 +40,7 @@ export default {
},
],
createAuthData,
generateAuthUrl,
verifyCredentials,
isStillVerified,
};

View File

@@ -1,7 +1,7 @@
import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url';
export default async function createAuthData($: IGlobalVariable) {
export default async function generateAuthUrl($: IGlobalVariable) {
const oauthRedirectUrlField = $.app.auth.fields.find(
(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 isStillVerified from './is-still-verified';
export default {
generateAuthUrl: true,
fields: [
{
key: 'oAuthRedirectUrl',
@@ -41,7 +40,7 @@ export default {
},
],
createAuthData,
generateAuthUrl,
verifyCredentials,
isStillVerified,
};

View File

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

View File

@@ -1,5 +1,5 @@
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 resetConnection from './mutations/reset-connection';
import verifyConnection from './mutations/verify-connection';
@@ -17,7 +17,7 @@ import login from './mutations/login';
const mutationResolvers = {
createConnection,
createAuthData,
generateAuthUrl,
updateConnection,
resetConnection,
verifyConnection,

View File

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

View File

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

View File

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

View File

@@ -178,10 +178,9 @@ export interface IData {
}
export interface IAuth {
createAuthData?($: IGlobalVariable): Promise<void>;
generateAuthUrl?($: IGlobalVariable): Promise<void>;
verifyCredentials($: IGlobalVariable): Promise<any>;
isStillVerified($: IGlobalVariable): Promise<boolean>;
generateAuthUrl?: boolean;
fields: IField[];
authenticationSteps?: 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 { RESET_CONNECTION } from './reset-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 = {
[key: string]: any;
@@ -15,7 +15,7 @@ const mutations: Mutations = {
verifyConnection: VERIFY_CONNECTION,
resetConnection: RESET_CONNECTION,
deleteConnection: DELETE_CONNECTION,
createAuthData: CREATE_AUTH_DATA,
generateAuthUrl: GENERATE_AUTH_URL,
};
export default mutations;