mirror of
https://github.com/makeplane/plane.git
synced 2026-07-14 14:31:37 +02:00
* `silo` refactoring changes (#2304) * add sdk and services for workspace connection and import jobs * rename service * move worker folder to root + remove controller folder * remove controller folder * add external api service in silo * fix params in service * fix params in service * fix services + remove projectid in job endpoints * chore: added generic config types for job store (#2158) * chore: made import job as generic * chore: added generic parameter inside the job service * chore: added generic parameter inside the job service * feat: remove projectId from jobs endpoint * chore: modified job store for new services * chore: revert go.mod.sum * chore: spaces * gitlab auth callback * github controllers update with plane api * create api client fix * base integration importer store * remove junk store * silo external api token middleware + plane api to generate user tokens * add ahmac permission method in apiserver + ahmac sign flow on silo * remove junk * getapi client remove unwanted options * modify api route for silo access + github gitlab and slack controller clean up * types modify + jira importer cleanup * fix: nodemon setup * make getAPIClient as a singleton * chore: added new definitions in base-import-worker * chore: modified jira migrator to adhere to the modified types * feat: modified base migrator to adhere new types * chore: modified jira-server-migrator to adhere new changes * chore: modified asana importer to adhere to new types * fix: migrated importer controllers for new schema * fix: build * chore: asana and linear controller * feat: updated job controller for new schema changes * chore: added permissions * integrations api migrations changes (#2193) * chore: added workspace_slug inside job data * replaced ahmac with hmac implementation * add new service base api view for microservices * fix: apiserver changes and base view * feat: added changes to services * feat: modified engine controller for using api services * feat: modified UI stores for modified jira importer * remove-log * resolve hmac issue + silo endpoint url fixes * add silo target access token rotation in get * integration ui migration changes * revert changes in il8n * fix crud for api * fix crud for api * fix: batch lock config * fix silo bundler issue (#2233) * chore: combined common dashboard components for silo (#2166) * chore: added new types to job store * feat: updated job store dependencies for new params * feat: created common components for importers dashboard * feat: modified jira importer to comply with new common components * feat: modified jira server dashboard to comply with the new component changes * feat: modified asana to comply with the common dashboard changes * fix: linear to comply with the new changes * reset job store * feat: migrated importers to new schema * fix: removed unused code * fix: base job importer model and serializer * fix-lint-errors --------- Co-authored-by: Saurabh Kumar <70131915+Saurabhkmr98@users.noreply.github.com> * fix api serialisers * fix: stabilized all integrations and jira importer * fix: linear, asana and jira-server importers * fix: reinstantiated hmac permission * chore: removed the db folder for silo * feat: added types for integration config * feat: added check for supported integration in silo and web * feat: added self hosted and cloud message differences * add en translations for importers and jira importer (#2264) * feat: Added language support for integrations (#2277) * feat: added translations for github, slack and gitlab integrations * fix: slack integration project modal * fix: gitlab organization disconnect * fix: silo build fixes * feat: added more language to integration language support * fix: review * feat: modified caddy and compose for silo selfhosted changes (#2276) * silo - fixes for keys and integrations form reset (#2283) * fix hardcoded values for integration importer keys * reset state after integration form submit * fix missing key integration * fix gitlab connection update * fix: added slack images being updated while creating issues (#2288) Co-authored-by: Saurabh Kumar <70131915+Saurabhkmr98@users.noreply.github.com> * silo - fix integration lang support (#2291) * fix hardcoded values for integration importer keys * reset state after integration form submit * fix missing translation key integration * fix gitlab connection update * fix integration lang support * fix integration lang support --------- Co-authored-by: Saurabhkmr98 <saurabhkapur73@gmail.com> Co-authored-by: Saurabh Kumar <70131915+Saurabhkmr98@users.noreply.github.com> * [SILO-71] flatfile importer v1 (#2156) * feat: initialized CSV importer * feat: added flatfile components * feat: setup workbook and listener for csv importer * feat: added store structure for flatfile importer * chore: translated csv importer to flatfile importer * feat: setup listener * fix: event listener for creating agent * feat: added flatfile importer skeleton * feat: added flatfile etl logic for pulling and transforming data * feat: added flatfile controller and migrator * feat: curated flatfile root store and importer UI * feat: initialized flatfile migrator * fix: flatfile * feat: added transformers for cycles and issues * feat: added mapping and transformation for flatfile * feat: added assignee field for fixing migrator bugs * fix:build * feat: added metrics inside the data import task' * fix:workbook * feat: added validation of email and date for flatfile * add sdk and services for workspace connection and import jobs * rename service * move worker folder to root + remove controller folder * remove controller folder * feat: added modules and issue types inside flatfile * fix: build * fix:response-handler * fix:errors * fix:deleted-file * fix: readded jobs route * add external api service in silo * fix params in service * fix params in service * fix services + remove projectid in job endpoints * chore: added generic config types for job store (#2158) * chore: made import job as generic * chore: added generic parameter inside the job service * chore: added generic parameter inside the job service * feat: remove projectId from jobs endpoint * chore: modified job store for new services * chore: revert go.mod.sum * chore: spaces * gitlab auth callback * github controllers update with plane api * create api client fix * base integration importer store * remove junk store * silo external api token middleware + plane api to generate user tokens * add ahmac permission method in apiserver + ahmac sign flow on silo * remove junk * getapi client remove unwanted options * modify api route for silo access + github gitlab and slack controller clean up * types modify + jira importer cleanup * fix: nodemon setup * make getAPIClient as a singleton * chore: added new definitions in base-import-worker * chore: modified jira migrator to adhere to the modified types * feat: modified base migrator to adhere new types * chore: modified jira-server-migrator to adhere new changes * chore: modified asana importer to adhere to new types * fix: migrated importer controllers for new schema * fix: build * chore: asana and linear controller * feat: updated job controller for new schema changes * chore: added permissions * integrations api migrations changes (#2193) * chore: added workspace_slug inside job data * replaced ahmac with hmac implementation * add new service base api view for microservices * fix: apiserver changes and base view * feat: added changes to services * feat: modified engine controller for using api services * feat: modified UI stores for modified jira importer * remove-log * resolve hmac issue + silo endpoint url fixes * add silo target access token rotation in get * integration ui migration changes * revert changes in il8n * fix crud for api * fix crud for api * fix: batch lock config * fix silo bundler issue (#2233) * chore: combined common dashboard components for silo (#2166) * chore: added new types to job store * feat: updated job store dependencies for new params * feat: created common components for importers dashboard * feat: modified jira importer to comply with new common components * feat: modified jira server dashboard to comply with the new component changes * feat: modified asana to comply with the common dashboard changes * fix: linear to comply with the new changes * reset job store * feat: migrated importers to new schema * fix: removed unused code * fix: base job importer model and serializer * fix-lint-errors --------- Co-authored-by: Saurabh Kumar <70131915+Saurabhkmr98@users.noreply.github.com> * fix api serialisers * fix: stabilized all integrations and jira importer * fix: linear, asana and jira-server importers * fix: reinstantiated hmac permission * chore: removed the db folder for silo * feat: added types for integration config * feat: added check for supported integration in silo and web * feat: added self hosted and cloud message differences * add en translations for importers and jira importer (#2264) * feat: Added language support for integrations (#2277) * feat: added translations for github, slack and gitlab integrations * fix: slack integration project modal * fix: gitlab organization disconnect * fix: silo build fixes * feat: added more language to integration language support * fix: review * feat: modified caddy and compose for silo selfhosted changes (#2276) * silo - fixes for keys and integrations form reset (#2283) * fix hardcoded values for integration importer keys * reset state after integration form submit * fix missing key integration * fix gitlab connection update * fix: added slack images being updated while creating issues (#2288) Co-authored-by: Saurabh Kumar <70131915+Saurabhkmr98@users.noreply.github.com> * silo - fix integration lang support (#2291) * fix hardcoded values for integration importer keys * reset state after integration form submit * fix missing translation key integration * fix gitlab connection update * fix integration lang support * fix integration lang support * feat: added controllers as default exports * feat: modified flatfile worker and controller to adhere new changes * feat: modified flatfile importer to ahere silo api migration * fix: source project and workspace hide props --------- Co-authored-by: Saurabhkmr98 <saurabhkapur73@gmail.com> Co-authored-by: Saurabh Kumar <70131915+Saurabhkmr98@users.noreply.github.com> * add fuzzy find in state and priority mapping (#2310) Co-authored-by: Saurabhkmr98 <saurabhkapur73@gmail.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com> * fix: build * chore: moved flatfile agent to external * chore:build-fixes * fix: credential breaking for slack * fix: credential route for api * SILO - chore: Importers translation (#2352) * add en translations for importers and jira importer * add en translations for all the importers * add importers language translation changes * chore silo importer translation * chore silo importer translation * fix: env removing trailing slashes * fix: trailing slashed env * fix duplicate entity connection issue (#2362) --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
250 lines
8.6 KiB
TypeScript
250 lines
8.6 KiB
TypeScript
/* eslint-disable no-useless-catch */
|
|
|
|
import set from "lodash/set";
|
|
import unset from "lodash/unset";
|
|
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
|
import { computedFn } from "mobx-utils";
|
|
import { SILO_BASE_PATH, SILO_BASE_URL } from "@plane/constants";
|
|
// plane web services
|
|
import { GithubEntityService } from "@/plane-web/services/integrations/github";
|
|
// plane web store
|
|
import { IGithubStore } from "@/plane-web/store/integrations";
|
|
// plane web types
|
|
import { TGithubEntityConnection } from "@/plane-web/types/integrations";
|
|
import { E_INTEGRATION_KEYS } from "@plane/etl/core";
|
|
|
|
export interface IGithubEntityStore {
|
|
// store instances
|
|
entityMap: Record<string, Record<string, Record<string, TGithubEntityConnection>>>; // workspaceId -> workspaceConnectionId -> entityId -> entity
|
|
// computed
|
|
entityIds: string[];
|
|
// computed functions
|
|
entityById: (entityId: string) => TGithubEntityConnection | undefined;
|
|
// actions
|
|
fetchEntities: () => Promise<TGithubEntityConnection[] | undefined>;
|
|
fetchEntity: (entityId: string) => Promise<TGithubEntityConnection | undefined>;
|
|
createEntity: (entity: Partial<TGithubEntityConnection>) => Promise<TGithubEntityConnection | undefined>;
|
|
updateEntity: (
|
|
entityId: string,
|
|
entity: Partial<TGithubEntityConnection>
|
|
) => Promise<TGithubEntityConnection | undefined>;
|
|
deleteEntity: (entityId: string) => Promise<void | undefined>;
|
|
}
|
|
|
|
export class GithubEntityStore implements IGithubEntityStore {
|
|
// observables
|
|
entityMap: Record<string, Record<string, Record<string, TGithubEntityConnection>>> = {}; // workspaceId -> workspaceConnectionId -> entityId -> entity
|
|
// service
|
|
private service: GithubEntityService;
|
|
|
|
constructor(protected store: IGithubStore) {
|
|
makeObservable(this, {
|
|
// observables
|
|
entityMap: observable,
|
|
// computed
|
|
entityIds: computed,
|
|
// actions
|
|
fetchEntities: action,
|
|
fetchEntity: action,
|
|
createEntity: action,
|
|
updateEntity: action,
|
|
deleteEntity: action,
|
|
});
|
|
|
|
this.service = new GithubEntityService(encodeURI(SILO_BASE_URL + SILO_BASE_PATH));
|
|
}
|
|
|
|
// computed
|
|
/**
|
|
* @description get entity ids
|
|
* @returns { string[] }
|
|
*/
|
|
get entityIds(): string[] {
|
|
const workspaceId = this.store.workspace?.id || undefined;
|
|
const workspaceConnectionId = this.store.auth.workspaceConnectionIds[0] || undefined;
|
|
if (!workspaceId || !workspaceConnectionId || !this.entityMap?.[workspaceId]?.[workspaceConnectionId]) return [];
|
|
|
|
return Object.keys(this.entityMap[workspaceId][workspaceConnectionId]);
|
|
}
|
|
|
|
// computed functions
|
|
/**
|
|
* @description get entity by id
|
|
* @param { string } entityId
|
|
* @returns { TGithubEntityConnection | undefined }
|
|
*/
|
|
entityById = computedFn((entityId: string): TGithubEntityConnection | undefined => {
|
|
const workspaceId = this.store.workspace?.id || undefined;
|
|
const workspaceConnectionId = this.store.auth.workspaceConnectionIds[0] || undefined;
|
|
if (!workspaceId || !workspaceConnectionId || !entityId || !this.entityMap?.[workspaceId]?.[workspaceConnectionId])
|
|
return undefined;
|
|
|
|
return this.entityMap[workspaceId][workspaceConnectionId][entityId];
|
|
});
|
|
|
|
// actions
|
|
/**
|
|
* @description fetch entities
|
|
* @returns { Promise<TGithubEntityConnection[] | undefined> }
|
|
*/
|
|
fetchEntities = async (): Promise<TGithubEntityConnection[] | undefined> => {
|
|
try {
|
|
const workspaceId = this.store.workspace?.id || undefined;
|
|
const workspaceConnectionId = this.store.auth.workspaceConnectionIds[0] || undefined;
|
|
if (!workspaceId || !workspaceConnectionId) return;
|
|
|
|
const response = await this.service.fetchEntityConnections(workspaceId, workspaceConnectionId);
|
|
|
|
if (response) {
|
|
runInAction(() => {
|
|
response.forEach((data) => {
|
|
set(this.entityMap, [workspaceId, workspaceConnectionId, data.id], data);
|
|
});
|
|
});
|
|
}
|
|
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @description fetch entity
|
|
* @param { string } entityId
|
|
* @returns { Promise<TGithubEntityConnection | undefined> }
|
|
*/
|
|
fetchEntity = async (entityId: string): Promise<TGithubEntityConnection | undefined> => {
|
|
try {
|
|
const workspaceId = this.store.workspace?.id || undefined;
|
|
const workspaceConnectionId = this.store.auth.workspaceConnectionIds[0] || undefined;
|
|
if (!workspaceId || !workspaceConnectionId || !entityId) return;
|
|
|
|
const response = await this.service.fetchEntityConnection(workspaceId, workspaceConnectionId, entityId);
|
|
|
|
if (response) {
|
|
runInAction(() => {
|
|
set(this.entityMap, [workspaceId, workspaceConnectionId, response.id], response);
|
|
});
|
|
}
|
|
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @description create entity
|
|
* @param { Partial<TGithubEntityConnection> } entity
|
|
* @returns { Promise<TGithubEntityConnection | undefined> }
|
|
*/
|
|
createEntity = async (entity: Partial<TGithubEntityConnection>): Promise<TGithubEntityConnection | undefined> => {
|
|
try {
|
|
const workspaceId = this.store.workspace?.id || undefined;
|
|
const workspaceSlug = this.store.workspace?.slug || undefined;
|
|
const workspaceConnectionId = this.store.auth.workspaceConnectionIds[0] || undefined;
|
|
if (!workspaceId || !workspaceSlug || !workspaceConnectionId) return;
|
|
|
|
const githubRepoId = entity?.entity_id || undefined;
|
|
if (!githubRepoId) return;
|
|
|
|
const githubRepo = this.store.data.githubRepositoryById(githubRepoId) || undefined;
|
|
if (!githubRepo) return;
|
|
|
|
const payload: Partial<TGithubEntityConnection> = {
|
|
workspace_id: workspaceId,
|
|
workspace_slug: workspaceSlug,
|
|
project_id: entity.project_id,
|
|
workspace_connection_id: workspaceConnectionId,
|
|
entity_id: entity.entity_id,
|
|
entity_type: E_INTEGRATION_KEYS.GITHUB,
|
|
entity_slug: githubRepo.full_name,
|
|
entity_data: githubRepo,
|
|
config: entity.config,
|
|
};
|
|
|
|
const response = await this.service.createEntityConnection(workspaceId, workspaceConnectionId, payload);
|
|
|
|
if (response) {
|
|
runInAction(() => {
|
|
set(this.entityMap, [workspaceId, workspaceConnectionId, response.id], response);
|
|
});
|
|
}
|
|
|
|
await this.fetchEntities();
|
|
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @description update entity
|
|
* @param { string } entityId
|
|
* @param { Partial<TGithubEntityConnection> } entity
|
|
* @returns { Promise<TGithubEntityConnection | undefined> }
|
|
*/
|
|
updateEntity = async (
|
|
entityId: string,
|
|
entity: Partial<TGithubEntityConnection>
|
|
): Promise<TGithubEntityConnection | undefined> => {
|
|
try {
|
|
const workspaceId = this.store.workspace?.id || undefined;
|
|
const workspaceSlug = this.store.workspace?.slug || undefined;
|
|
const workspaceConnectionId = this.store.auth.workspaceConnectionIds[0] || undefined;
|
|
if (!workspaceId || !workspaceSlug || !workspaceConnectionId || !entityId) return;
|
|
|
|
const githubRepoId = entity?.entity_id || undefined;
|
|
if (!githubRepoId) return;
|
|
|
|
const githubRepo = this.store.data.githubRepositoryById(githubRepoId) || undefined;
|
|
if (!githubRepo) return;
|
|
|
|
const payload: Partial<TGithubEntityConnection> = {
|
|
workspace_id: workspaceId,
|
|
workspace_slug: workspaceSlug,
|
|
project_id: entity.project_id,
|
|
workspace_connection_id: workspaceConnectionId,
|
|
entity_id: entity.entity_id,
|
|
entity_slug: githubRepo.full_name,
|
|
entity_data: githubRepo,
|
|
config: entity.config,
|
|
};
|
|
|
|
const response = await this.service.updateEntityConnection(workspaceId, workspaceConnectionId, entityId, payload);
|
|
|
|
if (response) {
|
|
runInAction(() => {
|
|
set(this.entityMap, [workspaceId, workspaceConnectionId, response.id], response);
|
|
});
|
|
}
|
|
|
|
return response;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @description delete entity
|
|
* @param { string } entityId
|
|
* @returns { Promise<void | undefined> }
|
|
*/
|
|
deleteEntity = async (entityId: string): Promise<void | undefined> => {
|
|
try {
|
|
const workspaceId = this.store.workspace?.id || undefined;
|
|
const workspaceConnectionId = this.store.auth.workspaceConnectionIds[0] || undefined;
|
|
if (!workspaceId || !workspaceConnectionId || !entityId) return;
|
|
|
|
await this.service.deleteEntityConnection(workspaceId, workspaceConnectionId, entityId);
|
|
unset(this.entityMap, [workspaceId, workspaceConnectionId, entityId]);
|
|
|
|
return;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
}
|