refactor(web): remove typescript

This commit is contained in:
Ali BARIN
2024-02-27 15:23:23 +00:00
parent 636870a075
commit b3ae2d2748
337 changed files with 2067 additions and 4997 deletions

View File

@@ -1,9 +1,4 @@
import { InMemoryCache } from '@apollo/client';
interface IRef {
__ref: string;
}
const cache = new InMemoryCache({
typePolicies: {
App: {
@@ -19,28 +14,24 @@ const cache = new InMemoryCache({
__typename: 'App',
key: appKey,
});
cache.modify({
id: appCacheId,
fields: {
connections: (existingConnections) => {
const existingConnectionIndex = existingConnections.findIndex(
(connection: IRef) => {
(connection) => {
return connection.__ref === verifiedConnection.__ref;
}
);
const connectionExists = existingConnectionIndex !== -1;
// newly created and verified connection
if (!connectionExists) {
return [verifiedConnection, ...existingConnections];
}
return existingConnections;
},
},
});
return verifiedConnection;
},
},
@@ -48,5 +39,4 @@ const cache = new InMemoryCache({
},
},
});
export default cache;

View File

@@ -2,12 +2,6 @@ import { ApolloClient } from '@apollo/client';
import cache from './cache';
import createLink from './link';
import appConfig from 'config/app';
type CreateClientOptions = {
onError?: (message: string) => void;
token?: string | null;
};
const client = new ApolloClient({
cache,
link: createLink({ uri: appConfig.graphqlUrl }),
@@ -17,16 +11,10 @@ const client = new ApolloClient({
},
},
});
export function mutateAndGetClient(
options: CreateClientOptions
): typeof client {
export function mutateAndGetClient(options) {
const { onError, token } = options;
const link = createLink({ uri: appConfig.graphqlUrl, token, onError });
client.setLink(link);
return client;
}
export default client;

View File

@@ -1,69 +1,46 @@
import { HttpLink, from } from '@apollo/client';
import type { ApolloLink } from '@apollo/client';
import { onError } from '@apollo/client/link/error';
import { setItem } from 'helpers/storage';
import * as URLS from 'config/urls';
type CreateLinkOptions = {
uri: string;
token?: string | null;
onError?: (message: string) => void;
};
const createHttpLink = (
options: Pick<CreateLinkOptions, 'uri' | 'token'>
): ApolloLink => {
const createHttpLink = (options) => {
const { uri, token } = options;
const headers = {
authorization: token,
};
return new HttpLink({ uri, headers });
};
const NOT_AUTHORISED = 'Not Authorised!';
const createErrorLink = (callback: CreateLinkOptions['onError']): ApolloLink =>
const createErrorLink = (callback) =>
onError(({ graphQLErrors, networkError, operation }) => {
const context = operation.getContext();
const autoSnackbar = context.autoSnackbar ?? true;
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) => {
if (autoSnackbar) {
callback?.(message);
}
console.error(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
);
if (message === NOT_AUTHORISED) {
setItem('token', '');
if (window.location.pathname !== URLS.LOGIN) {
window.location.href = URLS.LOGIN;
}
}
});
if (networkError) {
if (autoSnackbar) {
callback?.(networkError.toString());
}
console.error(`[Network error]: ${networkError}`);
}
});
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => { };
const createLink = (options: CreateLinkOptions): ApolloLink => {
const noop = () => {};
const createLink = (options) => {
const { uri, onError = noop, token } = options;
const httpOptions = { uri, token };
return from([createErrorLink(onError), createHttpLink(httpOptions)]);
};
export default createLink;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const CREATE_APP_AUTH_CLIENT = gql`
mutation CreateAppAuthClient($input: CreateAppAuthClientInput) {
createAppAuthClient(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const CREATE_APP_CONFIG = gql`
mutation CreateAppConfig($input: CreateAppConfigInput) {
createAppConfig(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const CREATE_CONNECTION = gql`
mutation CreateConnection($input: CreateConnectionInput) {
createConnection(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const CREATE_FLOW = gql`
mutation CreateFlow($input: CreateFlowInput) {
createFlow(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const CREATE_ROLE = gql`
mutation CreateRole($input: CreateRoleInput) {
createRole(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const CREATE_STEP = gql`
mutation CreateStep($input: CreateStepInput) {
createStep(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const CREATE_USER = gql`
mutation CreateUser($input: CreateUserInput) {
createUser(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const DELETE_CONNECTION = gql`
mutation DeleteConnection($input: DeleteConnectionInput) {
deleteConnection(input: $input)

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const DELETE_CURRENT_USER = gql`
mutation DeleteCurrentUser {
deleteCurrentUser

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const DELETE_FLOW = gql`
mutation DeleteFlow($input: DeleteFlowInput) {
deleteFlow(input: $input)

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const DELETE_ROLE = gql`
mutation DeleteRole($input: DeleteRoleInput) {
deleteRole(input: $input)

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const DELETE_STEP = gql`
mutation DeleteStep($input: DeleteStepInput) {
deleteStep(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const DELETE_USER = gql`
mutation DeleteUser($input: DeleteUserInput) {
deleteUser(input: $input)

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const DUPLICATE_FLOW = gql`
mutation DuplicateFlow($input: DuplicateFlowInput) {
duplicateFlow(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const EXECUTE_FLOW = gql`
mutation ExecuteFlow($input: ExecuteFlowInput) {
executeFlow(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const FORGOT_PASSWORD = gql`
mutation ForgotPassword($input: ForgotPasswordInput) {
forgotPassword(input: $input)

View File

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

View File

@@ -4,12 +4,7 @@ import { VERIFY_CONNECTION } from './verify-connection';
import { RESET_CONNECTION } from './reset-connection';
import { DELETE_CONNECTION } from './delete-connection';
import { GENERATE_AUTH_URL } from './generate-auth-url';
type Mutations = {
[key: string]: any;
};
const mutations: Mutations = {
const mutations = {
createConnection: CREATE_CONNECTION,
updateConnection: UPDATE_CONNECTION,
verifyConnection: VERIFY_CONNECTION,
@@ -17,5 +12,4 @@ const mutations: Mutations = {
deleteConnection: DELETE_CONNECTION,
generateAuthUrl: GENERATE_AUTH_URL,
};
export default mutations;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const LOGIN = gql`
mutation Login($input: LoginInput) {
login(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const REGISTER_USER = gql`
mutation RegisterUser($input: RegisterUserInput) {
registerUser(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const RESET_CONNECTION = gql`
mutation ResetConnection($input: ResetConnectionInput) {
resetConnection(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const RESET_PASSWORD = gql`
mutation ResetPassword($input: ResetPasswordInput) {
resetPassword(input: $input)

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_APP_AUTH_CLIENT = gql`
mutation UpdateAppAuthClient($input: UpdateAppAuthClientInput) {
updateAppAuthClient(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_APP_CONFIG = gql`
mutation UpdateAppConfig($input: UpdateAppConfigInput) {
updateAppConfig(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_CONFIG = gql`
mutation UpdateConfig($input: JSONObject) {
updateConfig(input: $input)

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_CONNECTION = gql`
mutation UpdateConnection($input: UpdateConnectionInput) {
updateConnection(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_CURRENT_USER = gql`
mutation UpdateCurrentUser($input: UpdateCurrentUserInput) {
updateCurrentUser(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_FLOW_STATUS = gql`
mutation UpdateFlowStatus($input: UpdateFlowStatusInput) {
updateFlowStatus(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_FLOW = gql`
mutation UpdateFlow($input: UpdateFlowInput) {
updateFlow(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_ROLE = gql`
mutation UpdateRole($input: UpdateRoleInput) {
updateRole(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_STEP = gql`
mutation UpdateStep($input: UpdateStepInput) {
updateStep(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPDATE_USER = gql`
mutation UpdateUser($input: UpdateUserInput) {
updateUser(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPSERT_SAML_AUTH_PROVIDER = gql`
mutation UpsertSamlAuthProvider($input: UpsertSamlAuthProviderInput) {
upsertSamlAuthProvider(input: $input) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const UPSERT_SAML_AUTH_PROVIDERS_ROLE_MAPPINGS = gql`
mutation UpsertSamlAuthProvidersRoleMappings(
$input: UpsertSamlAuthProvidersRoleMappingsInput

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const VERIFY_CONNECTION = gql`
mutation VerifyConnection($input: VerifyConnectionInput) {
verifyConnection(input: $input) {

View File

@@ -0,0 +1,32 @@
const makeEmptyData = () => {
return {
edges: [],
pageInfo: {
currentPage: 1,
totalPages: 1,
},
};
};
function offsetLimitPagination(keyArgs = false) {
return {
keyArgs,
merge(existing, incoming, { args }) {
if (!existing) {
existing = makeEmptyData();
}
if (!incoming || incoming === null) return existing;
const existingEdges = existing?.edges || [];
const incomingEdges = incoming.edges || [];
if (args) {
const newEdges = [...existingEdges, ...incomingEdges];
return {
pageInfo: incoming.pageInfo,
edges: newEdges,
};
} else {
return existing;
}
},
};
}
export default offsetLimitPagination;

View File

@@ -1,70 +0,0 @@
import type { FieldPolicy, Reference } from '@apollo/client';
type KeyArgs = FieldPolicy<unknown>['keyArgs'];
export type TEdge<TNode> =
| {
node: TNode;
}
| Reference;
export type TPageInfo = {
currentPage: number;
totalPages: number;
};
export type TExisting<TNode> = Readonly<{
edges: TEdge<TNode>[];
pageInfo: TPageInfo;
}>;
export type TIncoming<TNode> = {
edges: TEdge<TNode>[];
pageInfo: TPageInfo;
};
export type CustomFieldPolicy<TNode> = FieldPolicy<
TExisting<TNode> | null,
TIncoming<TNode> | null,
TIncoming<TNode> | null
>;
const makeEmptyData = <TNode>(): TExisting<TNode> => {
return {
edges: [],
pageInfo: {
currentPage: 1,
totalPages: 1,
},
};
};
function offsetLimitPagination<TNode = Reference>(
keyArgs: KeyArgs = false
): CustomFieldPolicy<TNode> {
return {
keyArgs,
merge(existing, incoming, { args }) {
if (!existing) {
existing = makeEmptyData<TNode>();
}
if (!incoming || incoming === null) return existing;
const existingEdges = existing?.edges || [];
const incomingEdges = incoming.edges || [];
if (args) {
const newEdges = [...existingEdges, ...incomingEdges];
return {
pageInfo: incoming.pageInfo,
edges: newEdges,
};
} else {
return existing;
}
},
};
}
export default offsetLimitPagination;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_APP_AUTH_CLIENT = gql`
query GetAppAuthClient($id: String!) {
getAppAuthClient(id: $id) {
@@ -10,4 +9,3 @@ export const GET_APP_AUTH_CLIENT = gql`
}
}
`;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_APP_AUTH_CLIENTS = gql`
query GetAppAuthClients($appKey: String!, $active: Boolean) {
getAppAuthClients(appKey: $appKey, active: $active) {
@@ -10,4 +9,3 @@ export const GET_APP_AUTH_CLIENTS = gql`
}
}
`;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_APP_CONFIG = gql`
query GetAppConfig($key: String!) {
getAppConfig(key: $key) {
@@ -13,4 +12,3 @@ export const GET_APP_CONFIG = gql`
}
}
`;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_APP_CONNECTIONS = gql`
query GetAppConnections($key: String!) {
getApp(key: $key) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_APP = gql`
query GetApp($key: String!) {
getApp(key: $key) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_APPS = gql`
query GetApps(
$name: String

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_AUTOMATISCH_INFO = gql`
query GetAutomatischInfo {
getAutomatischInfo {
@@ -8,4 +7,3 @@ export const GET_AUTOMATISCH_INFO = gql`
}
}
`;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_BILLING_AND_USAGE = gql`
query GetBillingAndUsage {
getBillingAndUsage {
@@ -36,4 +35,3 @@ export const GET_BILLING_AND_USAGE = gql`
}
}
`;

View File

@@ -1,8 +1,6 @@
import { gql } from '@apollo/client';
export const GET_CONFIG = gql`
query GetConfig($keys: [String]) {
getConfig(keys: $keys)
}
`;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_CONNECTED_APPS = gql`
query GetConnectedApps($name: String) {
getConnectedApps(name: $name) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_CURRENT_USER = gql`
query GetCurrentUser {
getCurrentUser {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_DYNAMIC_DATA = gql`
query GetDynamicData(
$stepId: String!

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_DYNAMIC_FIELDS = gql`
query GetDynamicFields(
$stepId: String!

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_EXECUTION_STEPS = gql`
query GetExecutionSteps($executionId: String!, $limit: Int!, $offset: Int!) {
getExecutionSteps(

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_EXECUTION = gql`
query GetExecution($executionId: String!) {
getExecution(executionId: $executionId) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_EXECUTIONS = gql`
query GetExecutions($limit: Int!, $offset: Int!) {
getExecutions(limit: $limit, offset: $offset) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_FLOW = gql`
query GetFlow($id: String!) {
getFlow(id: $id) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_FLOWS = gql`
query GetFlows(
$limit: Int!

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_INVOICES = gql`
query GetInvoices {
getInvoices {
@@ -11,4 +10,3 @@ export const GET_INVOICES = gql`
}
}
`;

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_NOTIFICATIONS = gql`
query GetNotifications {
getNotifications {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_PADDLE_INFO = gql`
query GetPaddleInfo {
getPaddleInfo {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_PAYMENT_PLANS = gql`
query GetPaymentPlans {
getPaymentPlans {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_PERMISSION_CATALOG = gql`
query GetPermissionCatalog {
getPermissionCatalog {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_ROLE = gql`
query GetRole($id: String!) {
getRole(id: $id) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_ROLES = gql`
query GetRoles {
getRoles {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_SAML_AUTH_PROVIDER_ROLE_MAPPINGS = gql`
query GetSamlAuthProviderRoleMappings($id: String!) {
getSamlAuthProviderRoleMappings(id: $id) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_SAML_AUTH_PROVIDER = gql`
query GetSamlAuthProvider {
getSamlAuthProvider {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_STEP_WITH_TEST_EXECUTIONS = gql`
query GetStepWithTestExecutions($stepId: String!) {
getStepWithTestExecutions(stepId: $stepId) {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_SUBSCRIPTION_STATUS = gql`
query GetSubscriptionStatus {
getSubscriptionStatus {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_TRIAL_STATUS = gql`
query GetTrialStatus {
getTrialStatus {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const GET_USER = gql`
query GetUser($id: String!) {
getUser(id: $id) {

View File

@@ -1,14 +1,7 @@
import { gql } from '@apollo/client';
export const GET_USERS = gql`
query GetUsers(
$limit: Int!
$offset: Int!
) {
getUsers(
limit: $limit
offset: $offset
) {
query GetUsers($limit: Int!, $offset: Int!) {
getUsers(limit: $limit, offset: $offset) {
pageInfo {
currentPage
totalPages

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const HEALTHCHECK = gql`
query Healthcheck {
healthcheck {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const LIST_SAML_AUTH_PROVIDERS = gql`
query ListSamlAuthProviders {
listSamlAuthProviders {

View File

@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
export const TEST_CONNECTION = gql`
query TestConnection($id: String!) {
testConnection(id: $id) {