feat: rename tenant into workspace (#2553)

* feat: rename tenant into workspace

* fix: missing some files and reset not working

* fix: wrong import

* Use link in company seeds

* Use link in company seeds

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2023-11-17 11:26:33 +01:00
committed by GitHub
parent bc579d64a6
commit b86ada6d2b
239 changed files with 1603 additions and 1618 deletions

View File

@ -0,0 +1,48 @@
import { Command, CommandRunner, Option } from 'nest-commander';
import { DataSourceService } from 'src/metadata/data-source/data-source.service';
import { WorkspaceManagerService } from 'src/workspace/workspace-manager/workspace-manager.service';
// TODO: implement dry-run
interface RunWorkspaceMigrationsOptions {
workspaceId: string;
}
@Command({
name: 'workspace:sync-metadata',
description: 'Sync metadata',
})
export class SyncWorkspaceMetadataCommand extends CommandRunner {
constructor(
private readonly workspaceManagerService: WorkspaceManagerService,
private readonly dataSourceService: DataSourceService,
) {
super();
}
async run(
_passedParam: string[],
options: RunWorkspaceMigrationsOptions,
): Promise<void> {
// TODO: run in a dedicated job + run queries in a transaction.
const dataSourceMetadata =
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
options.workspaceId,
);
// TODO: This solution could be improved, using a diff for example, we should not have to delete all metadata and recreate them.
await this.workspaceManagerService.resetStandardObjectsAndFieldsMetadata(
dataSourceMetadata.id,
options.workspaceId,
);
}
@Option({
flags: '-w, --workspace-id [workspace_id]',
description: 'workspace id',
required: true,
})
parseWorkspaceId(value: string): string {
return value;
}
}

View File

@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { WorkspaceManagerModule } from 'src/workspace/workspace-manager/workspace-manager.module';
import { DataSourceModule } from 'src/metadata/data-source/data-source.module';
import { SyncWorkspaceMetadataCommand } from './sync-workspace-metadata.command';
@Module({
imports: [WorkspaceManagerModule, DataSourceModule],
providers: [SyncWorkspaceMetadataCommand],
})
export class WorkspaceManagerCommandsModule {}

View File

@ -0,0 +1,51 @@
import { EntityManager } from 'typeorm';
export const companyPrefillData = async (
entityManager: EntityManager,
schemaName: string,
) => {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.company`, [
'name',
'domainName',
'address',
'employees',
])
.orIgnore()
.values([
{
name: 'Airbnb',
domainName: 'airbnb.com',
address: 'San Francisco',
employees: 5000,
},
{
name: 'Qonto',
domainName: 'qonto.com',
address: 'San Francisco',
employees: 800,
},
{
name: 'Stripe',
domainName: 'stripe.com',
address: 'San Francisco',
employees: 8000,
},
{
name: 'Figma',
domainName: 'figma.com',
address: 'San Francisco',
employees: 800,
},
{
name: 'Notion',
domainName: 'notion.com',
address: 'San Francisco',
employees: 400,
},
])
.returning('*')
.execute();
};

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,41 @@
import { EntityManager } from 'typeorm';
export const pipelineStepPrefillData = async (
entityManager: EntityManager,
schemaName: string,
) => {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.pipelineStep`, ['name', 'color', 'position'])
.orIgnore()
.values([
{
name: 'New',
color: 'red',
position: 0,
},
{
name: 'Screening',
color: 'purple',
position: 1,
},
{
name: 'Meeting',
color: 'sky',
position: 2,
},
{
name: 'Proposal',
color: 'turquoise',
position: 3,
},
{
name: 'Customer',
color: 'yellow',
position: 4,
},
])
.returning('*')
.execute();
};

View File

@ -0,0 +1,31 @@
import { DataSource, EntityManager } from 'typeorm';
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
import { viewPrefillData } from 'src/workspace/workspace-manager/standard-objects-prefill-data/view';
import { companyPrefillData } from 'src/workspace/workspace-manager/standard-objects-prefill-data/company';
import { personPrefillData } from 'src/workspace/workspace-manager/standard-objects-prefill-data/person';
import { pipelineStepPrefillData } from 'src/workspace/workspace-manager/standard-objects-prefill-data/pipeline-step';
export const standardObjectsPrefillData = async (
workspaceDataSource: DataSource,
schemaName: string,
objectMetadata: ObjectMetadataEntity[],
) => {
const objectMetadataMap = objectMetadata.reduce((acc, object) => {
acc[object.nameSingular] = {
id: object.id,
fields: object.fields.reduce((acc, field) => {
acc[field.name] = field.id;
return acc;
}, {}),
};
return acc;
}, {});
workspaceDataSource.transaction(async (entityManager: EntityManager) => {
await companyPrefillData(entityManager, schemaName);
await personPrefillData(entityManager, schemaName);
await viewPrefillData(entityManager, schemaName, objectMetadataMap);
await pipelineStepPrefillData(entityManager, schemaName);
});
};

View File

@ -0,0 +1,278 @@
import { EntityManager } from 'typeorm';
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
export const viewPrefillData = async (
entityManager: EntityManager,
schemaName: string,
objectMetadataMap: Record<string, ObjectMetadataEntity>,
) => {
// Creating views
const createdViews = await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.view`, ['name', 'objectMetadataId', 'type'])
.orIgnore()
.values([
{
name: 'All companies',
objectMetadataId: 'company',
type: 'table',
},
{
name: 'All people',
objectMetadataId: 'person',
type: 'table',
},
{
name: 'All opportunities',
objectMetadataId: 'company',
type: 'kanban',
},
{
name: 'All Companies (V2)',
objectMetadataId: objectMetadataMap['companyV2'].id,
type: 'table',
},
{
name: 'All People (V2)',
objectMetadataId: objectMetadataMap['personV2'].id,
type: 'table',
},
{
name: 'All Opportunities (V2)',
objectMetadataId: objectMetadataMap['companyV2'].id,
type: 'kanban',
},
])
.returning('*')
.execute();
const viewIdMap = createdViews.raw.reduce((acc, view) => {
acc[view.name] = view.id;
return acc;
}, {});
// Creating viewFields
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewField`, [
'fieldMetadataId',
'viewId',
'position',
'isVisible',
'size',
])
.orIgnore()
.values([
// CompanyV2
{
fieldMetadataId: objectMetadataMap['companyV2'].fields['name'],
viewId: viewIdMap['All Companies (V2)'],
position: 0,
isVisible: true,
size: 180,
},
{
fieldMetadataId: objectMetadataMap['companyV2'].fields['domainName'],
viewId: viewIdMap['All Companies (V2)'],
position: 1,
isVisible: true,
size: 100,
},
// {
// fieldMetadataId: objectMetadataMap['companyV2'].fields['accountOwner'],
// viewId: viewIdMap['All Companies (V2)'],
// position: 2,
// isVisible: true,
// size: 150,
// },
// {
// fieldMetadataId: 'createdAt',
// viewId: viewIdMap['All Companies (V2)'],
// position: 3,
// isVisible: true,
// size: 150,
// },
{
fieldMetadataId: objectMetadataMap['companyV2'].fields['employees'],
viewId: viewIdMap['All Companies (V2)'],
position: 4,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['companyV2'].fields['linkedinUrl'],
viewId: viewIdMap['All Companies (V2)'],
position: 5,
isVisible: true,
size: 170,
},
{
fieldMetadataId: objectMetadataMap['companyV2'].fields['address'],
viewId: viewIdMap['All Companies (V2)'],
position: 6,
isVisible: true,
size: 170,
},
// PeopleV2
{
fieldMetadataId: objectMetadataMap['personV2'].fields['firstName'], // TODO: change to displayName once we have name field type
viewId: viewIdMap['All People (V2)'],
position: 0,
isVisible: true,
size: 210,
},
{
fieldMetadataId: objectMetadataMap['personV2'].fields['email'],
viewId: viewIdMap['All People (V2)'],
position: 1,
isVisible: true,
size: 150,
},
// {
// fieldMetadataId: objectMetadataMap['personV2'].fields['company'],
// viewId: viewIdMap['All People (V2)'],
// position: 2,
// isVisible: true,
// size: 150,
// },
{
fieldMetadataId: objectMetadataMap['personV2'].fields['phone'],
viewId: viewIdMap['All People (V2)'],
position: 3,
isVisible: true,
size: 150,
},
// {
// fieldMetadataId: 'createdAt',
// viewId: viewIdMap['All People (V2)'],
// position: 4,
// isVisible: true,
// size: 150,
// },
{
fieldMetadataId: objectMetadataMap['personV2'].fields['city'],
viewId: viewIdMap['All People (V2)'],
position: 5,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['personV2'].fields['jobTitle'],
viewId: viewIdMap['All People (V2)'],
position: 6,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['personV2'].fields['linkedinUrl'],
viewId: viewIdMap['All People (V2)'],
position: 7,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['personV2'].fields['xUrl'],
viewId: viewIdMap['All People (V2)'],
position: 8,
isVisible: true,
size: 150,
},
// Companies
{
fieldMetadataId: 'name',
viewId: viewIdMap['All companies'],
position: 0,
isVisible: true,
size: 180,
},
{
fieldMetadataId: 'domainName',
viewId: viewIdMap['All companies'],
position: 1,
isVisible: true,
size: 100,
},
{
fieldMetadataId: 'accountOwner',
viewId: viewIdMap['All companies'],
position: 2,
isVisible: true,
size: 150,
},
{
fieldMetadataId: 'createdAt',
viewId: viewIdMap['All companies'],
position: 3,
isVisible: true,
size: 150,
},
{
fieldMetadataId: 'employees',
viewId: viewIdMap['All companies'],
position: 4,
isVisible: true,
size: 150,
},
{
fieldMetadataId: 'linkedin',
viewId: viewIdMap['All companies'],
position: 5,
isVisible: true,
size: 170,
},
{
fieldMetadataId: 'address',
viewId: viewIdMap['All companies'],
position: 6,
isVisible: true,
size: 170,
},
// Opportunities
{
fieldMetadataId: 'amount',
viewId: viewIdMap['All opportunities'],
position: 0,
isVisible: true,
size: 180,
},
{
fieldMetadataId: 'probability',
viewId: viewIdMap['All opportunities'],
position: 1,
isVisible: true,
size: 150,
},
{
fieldMetadataId: 'closeDate',
viewId: viewIdMap['All opportunities'],
position: 2,
isVisible: true,
size: 100,
},
{
fieldMetadataId: 'company',
viewId: viewIdMap['All opportunities'],
position: 3,
isVisible: true,
size: 150,
},
{
fieldMetadataId: 'createdAt',
viewId: viewIdMap['All opportunities'],
position: 4,
isVisible: true,
size: 150,
},
{
fieldMetadataId: 'pointOfContact',
viewId: viewIdMap['All opportunities'],
position: 5,
isVisible: true,
size: 150,
},
])
.execute();
};

View File

@ -0,0 +1,57 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const activityTargetMetadata = {
nameSingular: 'activityTargetV2',
namePlural: 'activityTargetsV2',
labelSingular: 'Activity Target',
labelPlural: 'Activity Targets',
targetTableName: 'activityTarget',
description: 'An activity target',
icon: 'IconCheckbox',
isActive: true,
isSystem: true,
fields: [
{
// Relations
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'activity',
label: 'Activity',
targetColumnMap: {
value: 'activityId',
},
description: 'ActivityTarget activity',
icon: 'IconCheckbox',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'person',
label: 'Person',
targetColumnMap: {
value: 'personId',
},
description: 'ActivityTarget person',
icon: 'IconUser',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'company',
label: 'Company',
targetColumnMap: {
value: 'companyId',
},
description: 'ActivityTarget company',
icon: 'IconBuildingSkyscraper',
isNullable: true,
},
],
};
export default activityTargetMetadata;

View File

@ -0,0 +1,157 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const activityMetadata = {
nameSingular: 'activityV2',
namePlural: 'activitiesV2',
labelSingular: 'Activity',
labelPlural: 'Activities',
targetTableName: 'activity',
description: 'An activity',
icon: 'IconCheckbox',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'title',
label: 'Title',
targetColumnMap: {
value: 'title',
},
description: 'Activity title',
icon: 'IconNotes',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'body',
label: 'Body',
targetColumnMap: {
value: 'body',
},
description: 'Activity body',
icon: 'IconList',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'type',
label: 'Type',
targetColumnMap: {
value: 'type',
},
description: 'Activity type',
icon: 'IconCheckbox',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.DATE,
name: 'reminderAt',
label: 'Reminder Date',
targetColumnMap: {
value: 'reminderAt',
},
description: 'Activity reminder date',
icon: 'IconCalendarEvent',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.DATE,
name: 'dueAt',
label: 'Due Date',
targetColumnMap: {
value: 'dueAt',
},
description: 'Activity due date',
icon: 'IconCalendarEvent',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.DATE,
name: 'completedAt',
label: 'Completion Date',
targetColumnMap: {
value: 'completedAt',
},
description: 'Activity completion date',
icon: 'IconCheck',
isNullable: true,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'activityTargets',
label: 'Targets',
targetColumnMap: {},
description: 'Activity targets',
icon: 'IconCheckbox',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'attachments',
label: 'Attachments',
targetColumnMap: {},
description: 'Activity attachments',
icon: 'IconFileImport',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'comments',
label: 'Comments',
targetColumnMap: {},
description: 'Activity comments',
icon: 'IconComment',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'author',
label: 'Author',
targetColumnMap: {
value: 'authorId',
},
description:
'Activity author. This is the person who created the activity',
icon: 'IconUserCircle',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'assignee',
label: 'Assignee',
targetColumnMap: {
value: 'assigneeId',
},
description:
'Acitivity assignee. This is the workspace member assigned to the activity ',
icon: 'IconUserCircle',
isNullable: true,
},
],
};
export default activityMetadata;

View File

@ -0,0 +1,56 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const apiKeyMetadata = {
nameSingular: 'apiKeyV2',
namePlural: 'apiKeysV2',
labelSingular: 'Api Key',
labelPlural: 'Api Keys',
targetTableName: 'apiKey',
description: 'An api key',
icon: 'IconRobot',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'name',
label: 'Name',
targetColumnMap: {
value: 'name',
},
description: 'ApiKey name',
icon: 'IconLink',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.DATE,
name: 'expiresAt',
label: 'Expiration date',
targetColumnMap: {
value: 'expiresAt',
},
description: 'ApiKey expiration date',
icon: 'IconCalendar',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.DATE,
name: 'revokedAt',
label: 'Revocation date',
targetColumnMap: {
value: 'revokedAt',
},
description: 'ApiKey revocation date',
icon: 'IconCalendar',
isNullable: true,
},
],
};
export default apiKeyMetadata;

View File

@ -0,0 +1,109 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const attachmentMetadata = {
nameSingular: 'attachmentV2',
namePlural: 'attachmentsV2',
labelSingular: 'Attachment',
labelPlural: 'Attachments',
targetTableName: 'attachment',
description: 'An attachment',
icon: 'IconFileImport',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'name',
label: 'Name',
targetColumnMap: {
value: 'name',
},
description: 'Attachment name',
icon: 'IconFileUpload',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'fullPath',
label: 'Full path',
targetColumnMap: {
value: 'fullPath',
},
description: 'Attachment full path',
icon: 'IconLink',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'type',
label: 'Type',
targetColumnMap: {
value: 'type',
},
description: 'Attachment type',
icon: 'IconList',
isNullable: false,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'author',
label: 'Author',
targetColumnMap: {
value: 'authorId',
},
description: 'Attachment author',
icon: 'IconCircleUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'activity',
label: 'Activity',
targetColumnMap: {
value: 'activityId',
},
description: 'Attachment activity',
icon: 'IconNotes',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'person',
label: 'Person',
targetColumnMap: {
value: 'personId',
},
description: 'Attachment person',
icon: 'IconUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'company',
label: 'Company',
targetColumnMap: {
value: 'companyId',
},
description: 'Attachment company',
icon: 'IconBuildingSkyscraper',
isNullable: false,
},
],
};
export default attachmentMetadata;

View File

@ -0,0 +1,57 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const commentMetadata = {
nameSingular: 'commentV2',
namePlural: 'commentsV2',
labelSingular: 'Comment',
labelPlural: 'Comments',
targetTableName: 'comment',
description: 'A comment',
icon: 'IconMessageCircle',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'body',
label: 'Body',
targetColumnMap: {
value: 'body',
},
description: 'Comment body',
icon: 'IconLink',
isNullable: false,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'author',
label: 'Author',
targetColumnMap: {
value: 'authorId',
},
description: 'Comment author',
icon: 'IconCircleUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'activity',
label: 'Activity',
targetColumnMap: {
value: 'activityId',
},
description: 'Comment activity',
icon: 'IconNotes',
isNullable: false,
},
],
};
export default commentMetadata;

View File

@ -0,0 +1,194 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const companyMetadata = {
nameSingular: 'companyV2',
namePlural: 'companiesV2',
labelSingular: 'Company',
labelPlural: 'Companies',
targetTableName: 'company',
description: 'A company',
icon: 'IconBuildingSkyscraper',
isActive: true,
isSystem: false,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'name',
label: 'Name',
targetColumnMap: {
value: 'name',
},
description: 'The company name',
icon: 'IconBuildingSkyscraper',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'domainName',
label: 'Domain Name',
targetColumnMap: {
value: 'domainName',
},
description:
'The company website URL. We use this url to fetch the company icon',
icon: 'IconLink',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'address',
label: 'Address',
targetColumnMap: {
value: 'address',
},
description: 'The company address',
icon: 'IconMap',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.NUMBER,
name: 'employees',
label: 'Employees',
targetColumnMap: {
value: 'employees',
},
description: 'Number of employees in the company',
icon: 'IconUsers',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.LINK,
name: 'linkedinLink',
label: 'Linkedin',
targetColumnMap: {
value: 'linkedinLink',
},
description: 'The company Linkedin account',
icon: 'IconBrandLinkedin',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.LINK,
name: 'xLink',
label: 'X',
targetColumnMap: {
value: 'xLink',
},
description: 'The company Twitter/X account',
icon: 'IconBrandX',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.NUMBER,
name: 'annualRecurringRevenue',
label: 'ARR',
targetColumnMap: {
value: 'annualRecurringRevenue',
},
description:
'Annual Recurring Revenue: The actual or estimated annual revenue of the company',
icon: 'IconMoneybag',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.BOOLEAN,
name: 'idealCustomerProfile',
label: 'ICP',
targetColumnMap: {
value: 'idealCustomerProfile',
},
description:
'Ideal Customer Profile: Indicates whether the company is the most suitable and valuable customer for you',
icon: 'IconTarget',
isNullable: true,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'people',
label: 'People',
targetColumnMap: {},
description: 'People linked to the company.',
icon: 'IconUsers',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'accountOwner',
label: 'Account Owner',
targetColumnMap: {
value: 'accountOwnerId',
},
description:
'Your team member responsible for managing the company account',
icon: 'IconUserCircle',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'activityTargets',
label: 'Activities',
targetColumnMap: {},
description: 'Activities tied to the company',
icon: 'IconCheckbox',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'opportunities',
label: 'Opportunities',
targetColumnMap: {},
description: 'Opportunities linked to the company.',
icon: 'IconTargetArrow',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'favorites',
label: 'Favorites',
targetColumnMap: {},
description: 'Favorites linked to the company',
icon: 'IconHeart',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'attachments',
label: 'Attachments',
targetColumnMap: {},
description: 'Attachments linked to the company.',
icon: 'IconFileImport',
isNullable: true,
},
],
};
export default companyMetadata;

View File

@ -0,0 +1,70 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const favoriteMetadata = {
nameSingular: 'favoriteV2',
namePlural: 'favoritesV2',
labelSingular: 'Favorite',
labelPlural: 'Favorites',
targetTableName: 'favorite',
description: 'A favorite',
icon: 'IconHeart',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.NUMBER,
name: 'position',
label: 'Position',
targetColumnMap: {
value: 'position',
},
description: 'Favorite position',
icon: 'IconList',
isNullable: false,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'workspaceMember',
label: 'Workspace Member',
targetColumnMap: {
value: 'workspaceMemberId',
},
description: 'Favorite workspace member',
icon: 'IconCircleUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'person',
label: 'Person',
targetColumnMap: {
value: 'personId',
},
description: 'Favorite person',
icon: 'IconUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'company',
label: 'Company',
targetColumnMap: {
value: 'companyId',
},
description: 'Favorite company',
icon: 'IconBuildingSkyscraper',
isNullable: false,
},
],
};
export default favoriteMetadata;

View File

@ -0,0 +1,109 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const opportunityMetadata = {
nameSingular: 'opportunityV2',
namePlural: 'opportunitiesV2',
labelSingular: 'Opportunity',
labelPlural: 'Opportunities',
targetTableName: 'opportunity',
description: 'An opportunity',
icon: 'IconTargetArrow',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.NUMBER,
name: 'amount',
label: 'Amount',
targetColumnMap: {
value: 'amount',
},
description: 'Opportunity amount',
icon: 'IconCurrencyDollar',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.DATE,
name: 'closeDate',
label: 'Close date',
targetColumnMap: {
value: 'closeDate',
},
description: 'Opportunity close date',
icon: 'IconCalendarEvent',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'probability',
label: 'Probability',
targetColumnMap: {
value: 'probability',
},
description: 'Opportunity amount',
icon: 'IconProgressCheck',
isNullable: true,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'pipelineStep',
label: 'Pipeline Step',
targetColumnMap: {
value: 'pipelineStepId',
},
description: 'Opportunity pipeline step',
icon: 'IconKanban',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'pointOfContact',
label: 'Point of Contact',
targetColumnMap: {
value: 'pointOfContactId',
},
description: 'Opportunity point of contact',
icon: 'IconUser',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'person',
label: 'Person',
targetColumnMap: {
value: 'personId',
},
description: 'Opportunity person',
icon: 'IconUser',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'company',
label: 'Company',
targetColumnMap: {
value: 'companyId',
},
description: 'Opportunity company',
icon: 'IconBuildingSkyscraper',
isNullable: true,
},
],
};
export default opportunityMetadata;

View File

@ -0,0 +1,203 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const personMetadata = {
nameSingular: 'personV2',
namePlural: 'peopleV2',
labelSingular: 'Person',
labelPlural: 'People',
targetTableName: 'person',
description: 'A person',
icon: 'IconUser',
isActive: true,
isSystem: false,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'firstName',
label: 'First name',
targetColumnMap: {
value: 'firstName',
},
description: 'Contacts first name',
icon: 'IconUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'lastName',
label: 'Last name',
targetColumnMap: {
value: 'lastName',
},
description: 'Contacts last name',
icon: 'IconUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.EMAIL,
name: 'email',
label: 'Email',
targetColumnMap: {
value: 'email',
},
description: 'Contacts Email',
icon: 'IconMail',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.LINK,
name: 'linkedinUrl',
label: 'Linkedin',
targetColumnMap: {
value: 'linkedinUrl',
},
description: 'Contacts Linkedin account',
icon: 'IconBrandLinkedin',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.LINK,
name: 'xUrl',
label: 'X',
targetColumnMap: {
value: 'xUrl',
},
description: 'Contacts X/Twitter account',
icon: 'IconUser',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'jobTitle',
label: 'Job Title',
targetColumnMap: {
value: 'jobTitle',
},
description: 'Contacts job title',
icon: 'IconBriefcase',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'phone',
label: 'Phone',
targetColumnMap: {
value: 'phone',
},
description: 'Contacts phone number',
icon: 'IconPhone',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'city',
label: 'City',
targetColumnMap: {
value: 'city',
},
description: 'Contacts city',
icon: 'IconMap',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'avatarUrl',
label: 'Avatar',
targetColumnMap: {
value: 'avatarUrl',
},
description: 'Contacts avatar',
icon: 'IconFileUpload',
isNullable: false,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'company',
label: 'Company',
targetColumnMap: {
value: 'companyId',
},
description: 'Contacts company',
icon: 'IconBuildingSkyscraper',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'pointOfContactForOpportunities',
label: 'POC for Opportunities',
targetColumnMap: {},
description: 'Point of Contact for Opportunities',
icon: 'IconArrowTarget',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'activityTargets',
label: 'Activities',
targetColumnMap: {},
description: 'Activities tied to the contact',
icon: 'IconCheckbox',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'opportunities',
label: 'Opportunities',
targetColumnMap: {},
description: 'Opportunities linked to the contact.',
icon: 'IconTargetArrow',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'favorites',
label: 'Favorites',
targetColumnMap: {},
description: 'Favorites linked to the contact',
icon: 'IconHeart',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'attachments',
label: 'Attachments',
targetColumnMap: {},
description: 'Attachments linked to the contact.',
icon: 'IconFileImport',
isNullable: true,
},
],
};
export default personMetadata;

View File

@ -0,0 +1,68 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const pipelineStepMetadata = {
nameSingular: 'pipelineStepV2',
namePlural: 'pipelineStepsV2',
labelSingular: 'Pipeline Step',
labelPlural: 'Pipeline Steps',
targetTableName: 'pipelineStep',
description: 'A pipeline step',
icon: 'IconLayoutKanban',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'name',
label: 'Name',
targetColumnMap: {
value: 'name',
},
description: 'Pipeline Step name',
icon: 'IconCurrencyDollar',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'color',
label: 'Color',
targetColumnMap: {
value: 'color',
},
description: 'Pipeline Step color',
icon: 'IconColorSwatch',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.NUMBER,
name: 'position',
label: 'Position',
targetColumnMap: {
value: 'position',
},
description: 'Pipeline Step position',
icon: 'IconHierarchy2',
isNullable: false,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'opportunities',
label: 'Opportunities',
targetColumnMap: {},
description: 'Opportunities linked to the step.',
icon: 'IconTargetArrow',
isNullable: true,
},
],
};
export default pipelineStepMetadata;

View File

@ -0,0 +1,27 @@
import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity';
const activityRelationMetadata = [
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'activityV2',
toObjectNameSingular: 'activityTargetV2',
fromFieldMetadataName: 'activityTargets',
toFieldMetadataName: 'activity',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'activityV2',
toObjectNameSingular: 'attachmentV2',
fromFieldMetadataName: 'attachments',
toFieldMetadataName: 'activity',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'activityV2',
toObjectNameSingular: 'commentV2',
fromFieldMetadataName: 'comments',
toFieldMetadataName: 'activity',
},
];
export default activityRelationMetadata;

View File

@ -0,0 +1,41 @@
import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity';
const companyRelationMetadata = [
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'companyV2',
toObjectNameSingular: 'personV2',
fromFieldMetadataName: 'people',
toFieldMetadataName: 'company',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'companyV2',
toObjectNameSingular: 'favoriteV2',
fromFieldMetadataName: 'favorites',
toFieldMetadataName: 'company',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'companyV2',
toObjectNameSingular: 'attachmentV2',
fromFieldMetadataName: 'attachments',
toFieldMetadataName: 'company',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'companyV2',
toObjectNameSingular: 'opportunityV2',
fromFieldMetadataName: 'opportunities',
toFieldMetadataName: 'company',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'companyV2',
toObjectNameSingular: 'activityTargetV2',
fromFieldMetadataName: 'activityTargets',
toFieldMetadataName: 'company',
},
];
export default companyRelationMetadata;

View File

@ -0,0 +1,41 @@
import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity';
const personRelationMetadata = [
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'personV2',
toObjectNameSingular: 'favoriteV2',
fromFieldMetadataName: 'favorites',
toFieldMetadataName: 'person',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'personV2',
toObjectNameSingular: 'attachmentV2',
fromFieldMetadataName: 'attachments',
toFieldMetadataName: 'person',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'personV2',
toObjectNameSingular: 'opportunityV2',
fromFieldMetadataName: 'opportunities',
toFieldMetadataName: 'person',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'personV2',
toObjectNameSingular: 'opportunityV2',
fromFieldMetadataName: 'pointOfContactForOpportunities',
toFieldMetadataName: 'pointOfContact',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'personV2',
toObjectNameSingular: 'activityTargetV2',
fromFieldMetadataName: 'activityTargets',
toFieldMetadataName: 'person',
},
];
export default personRelationMetadata;

View File

@ -0,0 +1,13 @@
import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity';
const pipelineStepRelationMetadata = [
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'pipelineStepV2',
toObjectNameSingular: 'opportunityV2',
fromFieldMetadataName: 'opportunities',
toFieldMetadataName: 'pipelineStep',
},
];
export default pipelineStepRelationMetadata;

View File

@ -0,0 +1,27 @@
import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity';
const viewRelationMetadata = [
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'viewV2',
toObjectNameSingular: 'viewFieldV2',
fromFieldMetadataName: 'viewFields',
toFieldMetadataName: 'view',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'viewV2',
toObjectNameSingular: 'viewFilterV2',
fromFieldMetadataName: 'viewFilters',
toFieldMetadataName: 'view',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'viewV2',
toObjectNameSingular: 'viewSortV2',
fromFieldMetadataName: 'viewSorts',
toFieldMetadataName: 'view',
},
];
export default viewRelationMetadata;

View File

@ -0,0 +1,48 @@
import { RelationMetadataType } from 'src/metadata/relation-metadata/relation-metadata.entity';
const workspaceMemberRelationMetadata = [
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'workspaceMemberV2',
toObjectNameSingular: 'companyV2',
fromFieldMetadataName: 'accountOwnerForCompanies',
toFieldMetadataName: 'accountOwner',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'workspaceMemberV2',
toObjectNameSingular: 'favoriteV2',
fromFieldMetadataName: 'favorites',
toFieldMetadataName: 'workspaceMember',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'workspaceMemberV2',
toObjectNameSingular: 'activityV2',
fromFieldMetadataName: 'authoredActivities',
toFieldMetadataName: 'author',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'workspaceMemberV2',
toObjectNameSingular: 'activityV2',
fromFieldMetadataName: 'assignedActivities',
toFieldMetadataName: 'assignee',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'workspaceMemberV2',
toObjectNameSingular: 'commentV2',
fromFieldMetadataName: 'authoredComments',
toFieldMetadataName: 'author',
},
{
type: RelationMetadataType.ONE_TO_MANY,
fromObjectNameSingular: 'workspaceMemberV2',
toObjectNameSingular: 'attachmentV2',
fromFieldMetadataName: 'authoredAttachments',
toFieldMetadataName: 'author',
},
];
export default workspaceMemberRelationMetadata;

View File

@ -0,0 +1,78 @@
import activityTargetMetadata from 'src/workspace/workspace-manager/standard-objects/activity-target';
import activityMetadata from 'src/workspace/workspace-manager/standard-objects/activity';
import apiKeyMetadata from 'src/workspace/workspace-manager/standard-objects/api-key';
import attachmentMetadata from 'src/workspace/workspace-manager/standard-objects/attachment';
import commentMetadata from 'src/workspace/workspace-manager/standard-objects/comment';
import favoriteMetadata from 'src/workspace/workspace-manager/standard-objects/favorite';
import opportunityMetadata from 'src/workspace/workspace-manager/standard-objects/opportunity';
import personMetadata from 'src/workspace/workspace-manager/standard-objects/person';
import viewMetadata from 'src/workspace/workspace-manager/standard-objects/view';
import viewFieldMetadata from 'src/workspace/workspace-manager/standard-objects/view-field';
import viewFilterMetadata from 'src/workspace/workspace-manager/standard-objects/view-filter';
import viewSortMetadata from 'src/workspace/workspace-manager/standard-objects/view-sort';
import webhookMetadata from 'src/workspace/workspace-manager/standard-objects/webhook';
import pipelineStepMetadata from 'src/workspace/workspace-manager/standard-objects/pipeline-step';
import companyMetadata from 'src/workspace/workspace-manager/standard-objects/company';
import workspaceMemberMetadata from 'src/workspace/workspace-manager/standard-objects/workspace-member';
import {
FieldMetadataEntity,
FieldMetadataType,
} from 'src/metadata/field-metadata/field-metadata.entity';
export const standardObjectsMetadata = {
activityTargetV2: activityTargetMetadata,
activityV2: activityMetadata,
apiKeyV2: apiKeyMetadata,
attachmentV2: attachmentMetadata,
commentV2: commentMetadata,
companyV2: companyMetadata,
favoriteV2: favoriteMetadata,
opportunityV2: opportunityMetadata,
personV2: personMetadata,
pipelineStepV2: pipelineStepMetadata,
viewFieldV2: viewFieldMetadata,
viewFilterV2: viewFilterMetadata,
viewSortV2: viewSortMetadata,
viewV2: viewMetadata,
webhookV2: webhookMetadata,
workspaceMemberV2: workspaceMemberMetadata,
};
export const basicFieldsMetadata: Partial<FieldMetadataEntity>[] = [
{
name: 'id',
label: 'Id',
type: FieldMetadataType.UUID,
targetColumnMap: {
value: 'id',
},
isNullable: true,
// isSystem: true,
isCustom: false,
isActive: true,
},
{
name: 'createdAt',
label: 'Creation date',
type: FieldMetadataType.DATE,
targetColumnMap: {
value: 'createdAt',
},
icon: 'IconCalendar',
isNullable: true,
isCustom: false,
isActive: true,
},
{
name: 'updatedAt',
label: 'Update date',
type: FieldMetadataType.DATE,
targetColumnMap: {
value: 'updatedAt',
},
icon: 'IconCalendar',
isNullable: true,
isCustom: false,
isActive: true,
},
];

View File

@ -0,0 +1,15 @@
import activityRelationMetadata from 'src/workspace/workspace-manager/standard-objects/relations/activity';
import companyRelationMetadata from 'src/workspace/workspace-manager/standard-objects/relations/company';
import personRelationMetadata from 'src/workspace/workspace-manager/standard-objects/relations/person';
import pipelineStepRelationMetadata from 'src/workspace/workspace-manager/standard-objects/relations/pipeline-step';
import viewRelationMetadata from 'src/workspace/workspace-manager/standard-objects/relations/view';
import workspaceMemberRelationMetadata from 'src/workspace/workspace-manager/standard-objects/relations/workspace-member';
export const standardObjectRelationMetadata = [
...activityRelationMetadata,
...companyRelationMetadata,
...personRelationMetadata,
...pipelineStepRelationMetadata,
...viewRelationMetadata,
...workspaceMemberRelationMetadata,
];

View File

@ -0,0 +1,94 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const viewFieldMetadata = {
nameSingular: 'viewFieldV2',
namePlural: 'viewFieldsV2',
labelSingular: 'View Field',
labelPlural: 'View Fields',
targetTableName: 'viewField',
description: '(System) View Fields',
icon: 'IconTag',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'fieldMetadataId',
label: 'Field Metadata Id',
targetColumnMap: {
value: 'fieldMetadataId',
},
description: 'View Field target field',
icon: 'IconTag',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.BOOLEAN,
name: 'isVisible',
label: 'Visible',
targetColumnMap: {
value: 'isVisible',
},
description: 'View Field visibility',
icon: 'IconEye',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.NUMBER,
name: 'size',
label: 'Size',
targetColumnMap: {
value: 'size',
},
description: 'View Field size',
icon: 'IconEye',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.NUMBER,
name: 'position',
label: 'Position',
targetColumnMap: {
value: 'position',
},
description: 'View Field position',
icon: 'IconList',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'view',
label: 'View',
targetColumnMap: { value: 'viewId' },
description: 'View Field related view',
icon: 'IconLayoutCollage',
isNullable: false,
},
// Temporary hack?
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'viewId',
label: 'View Id',
targetColumnMap: {
value: 'viewId',
},
description: 'View field related view',
icon: 'IconLayoutCollage',
isNullable: false,
},
],
};
export default viewFieldMetadata;

View File

@ -0,0 +1,94 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const viewFilterMetadata = {
nameSingular: 'viewFilterV2',
namePlural: 'viewFiltersV2',
labelSingular: 'View Filter',
labelPlural: 'View Filters',
targetTableName: 'viewFilter',
description: '(System) View Filters',
icon: 'IconFilterBolt',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'fieldMetadataId',
label: 'Field Metadata Id',
targetColumnMap: {
value: 'fieldMetadataId',
},
description: 'View Filter target field',
icon: null,
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'operand',
label: 'Operand',
targetColumnMap: {
value: 'operand',
},
description: 'View Filter operand',
icon: null,
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'value',
label: 'Value',
targetColumnMap: {
value: 'value',
},
description: 'View Filter value',
icon: null,
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'displayValue',
label: 'Display Value',
targetColumnMap: {
value: 'displayValue',
},
description: 'View Filter Display Value',
icon: null,
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'view',
label: 'View',
targetColumnMap: { value: 'viewId' },
description: 'View Filter related view',
icon: 'IconLayoutCollage',
isNullable: false,
},
// Temporary hack?
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'viewId',
label: 'View Id',
targetColumnMap: {
value: 'viewId',
},
description: 'View Filter related view',
icon: 'IconLayoutCollage',
isNullable: false,
},
],
};
export default viewFilterMetadata;

View File

@ -0,0 +1,70 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const viewSortMetadata = {
nameSingular: 'viewSortV2',
namePlural: 'viewSortsV2',
labelSingular: 'View Sort',
labelPlural: 'View Sorts',
targetTableName: 'viewSort',
description: '(System) View Sorts',
icon: 'IconArrowsSort',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'fieldMetadataId',
label: 'Field Metadata Id',
targetColumnMap: {
value: 'fieldMetadataId',
},
description: 'View Sort target field',
icon: null,
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'direction',
label: 'Direction',
targetColumnMap: {
value: 'direction',
},
description: 'View Sort direction',
icon: null,
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'view',
label: 'View',
targetColumnMap: {
value: 'viewId',
},
description: 'View Sort related view',
icon: 'IconLayoutCollage',
isNullable: false,
},
// Temporary Hack?
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'viewId',
label: 'View Id',
targetColumnMap: {
value: 'viewId',
},
description: 'View Sort related view',
icon: 'IconLayoutCollage',
isNullable: false,
},
],
};
export default viewSortMetadata;

View File

@ -0,0 +1,83 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const viewMetadata = {
nameSingular: 'viewV2',
namePlural: 'viewsV2',
labelSingular: 'View',
labelPlural: 'Views',
targetTableName: 'view',
description: '(System) Views',
icon: 'IconLayoutCollage',
isActive: true,
isSystem: true,
fields: [
{
type: FieldMetadataType.TEXT,
name: 'name',
label: 'Name',
targetColumnMap: {
value: 'name',
},
description: 'View name',
icon: null,
isNullable: false,
},
{
type: FieldMetadataType.TEXT,
name: 'objectMetadataId',
label: 'Object Metadata Id',
targetColumnMap: {
value: 'objectMetadataId',
},
description: 'View target object',
icon: null,
isNullable: false,
},
{
type: FieldMetadataType.TEXT,
name: 'type',
label: 'Type',
targetColumnMap: {
value: 'type',
},
description: 'View type',
icon: null,
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'viewFields',
label: 'View Fields',
targetColumnMap: {},
description: 'View Fields',
icon: 'IconTag',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'viewSorts',
label: 'View Sorts',
targetColumnMap: {},
description: 'View Sorts',
icon: 'IconArrowsSort',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'viewFilters',
label: 'View Filters',
targetColumnMap: {},
description: 'View Filters',
icon: 'IconFilterBolt',
isNullable: true,
},
],
};
export default viewMetadata;

View File

@ -0,0 +1,43 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const webhookMetadata = {
nameSingular: 'webhookV2',
namePlural: 'webhooksV2',
labelSingular: 'Webhook',
labelPlural: 'Webhooks',
targetTableName: 'webhook',
description: 'A webhook',
icon: 'IconRobot',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'targetUrl',
label: 'Target Url',
targetColumnMap: {
value: 'targetUrl',
},
description: 'Webhook target url',
icon: 'IconLink',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'operation',
label: 'Operation',
targetColumnMap: {
value: 'operation',
},
description: 'Webhook operation',
icon: 'IconCheckbox',
isNullable: false,
},
],
};
export default webhookMetadata;

View File

@ -0,0 +1,176 @@
import { FieldMetadataType } from 'src/metadata/field-metadata/field-metadata.entity';
const workspaceMemberMetadata = {
nameSingular: 'workspaceMemberV2',
namePlural: 'workspaceMembersV2',
labelSingular: 'Workspace Member',
labelPlural: 'Workspace Members',
targetTableName: 'workspaceMember',
description: 'A workspace member',
icon: 'IconUserCircle',
isActive: true,
isSystem: true,
fields: [
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'firstName',
label: 'First name',
targetColumnMap: {
value: 'firstName',
},
description: 'Workspace member first name',
icon: 'IconCircleUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'lastName',
label: 'Last name',
targetColumnMap: {
value: 'lastName',
},
description: 'Workspace member last name',
icon: 'IconCircleUser',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.UUID,
name: 'userId',
label: 'User Id',
targetColumnMap: {
value: 'userId',
},
description: 'Associated User Id',
icon: 'IconCircleUsers',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.BOOLEAN,
name: 'allowImpersonation',
label: 'Admin Access',
targetColumnMap: {
value: 'allowImpersonation',
},
description: 'Allow Admin Access',
icon: 'IconEye',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'colorScheme',
label: 'Color Scheme',
targetColumnMap: {
value: 'colorScheme',
},
description: 'Preferred color scheme',
icon: 'IconColorSwatch',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'locale',
label: 'Language',
targetColumnMap: {
value: 'locale',
},
description: 'Preferred language',
icon: 'IconLanguage',
isNullable: false,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.TEXT,
name: 'avatarUrl',
label: 'Avatar Url',
targetColumnMap: {
value: 'avatarUrl',
},
description: 'Workspace member avatar',
icon: 'IconFileUpload',
isNullable: true,
isSystem: false,
},
// Relations
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'authoredActivities',
label: 'Authored activities',
targetColumnMap: {},
description: 'Activities created by the workspace member',
icon: 'IconCheckbox',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'assignedActivities',
label: 'Assigned activities',
targetColumnMap: {},
description: 'Activities assigned to the workspace member',
icon: 'IconCheckbox',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'favorites',
label: 'Favorites',
targetColumnMap: {},
description: 'Favorites linked to the workspace member',
icon: 'IconHeart',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'accountOwnerForCompanies',
label: 'Account Owner For Companies',
targetColumnMap: {},
description: 'Account owner for companies',
icon: 'IconBriefcase',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'authoredAttachments',
label: 'Authored attachments',
targetColumnMap: {},
description: 'Attachments created by the workspace member',
icon: 'IconFileImport',
isNullable: true,
},
{
isCustom: false,
isActive: true,
type: FieldMetadataType.RELATION,
name: 'authoredComments',
label: 'Authored comments',
targetColumnMap: {},
description: 'Authored comments',
icon: 'IconComment',
isNullable: true,
},
],
};
export default workspaceMemberMetadata;

View File

@ -0,0 +1,26 @@
import { Module } from '@nestjs/common';
import { DataSourceModule } from 'src/metadata/data-source/data-source.module';
import { FieldMetadataModule } from 'src/metadata/field-metadata/field-metadata.module';
import { ObjectMetadataModule } from 'src/metadata/object-metadata/object-metadata.module';
import { WorkspaceMigrationModule } from 'src/metadata/workspace-migration/workspace-migration.module';
import { WorkspaceMigrationRunnerModule } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.module';
import { WorkspaceDataSourceModule } from 'src/workspace/workspace-datasource/workspace-datasource.module';
import { RelationMetadataModule } from 'src/metadata/relation-metadata/relation-metadata.module';
import { WorkspaceManagerService } from './workspace-manager.service';
@Module({
imports: [
WorkspaceDataSourceModule,
WorkspaceMigrationModule,
WorkspaceMigrationRunnerModule,
ObjectMetadataModule,
FieldMetadataModule,
DataSourceModule,
RelationMetadataModule,
],
exports: [WorkspaceManagerService],
providers: [WorkspaceManagerService],
})
export class WorkspaceManagerModule {}

View File

@ -0,0 +1,265 @@
import { Injectable } from '@nestjs/common';
import { DataSourceService } from 'src/metadata/data-source/data-source.service';
import { FieldMetadataService } from 'src/metadata/field-metadata/field-metadata.service';
import { ObjectMetadataService } from 'src/metadata/object-metadata/object-metadata.service';
import { WorkspaceMigrationRunnerService } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.service';
import { WorkspaceMigrationService } from 'src/metadata/workspace-migration/workspace-migration.service';
import { standardObjectsPrefillData } from 'src/workspace/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data';
import { WorkspaceDataSourceService } from 'src/workspace/workspace-datasource/workspace-datasource.service';
import { DataSourceEntity } from 'src/metadata/data-source/data-source.entity';
import { RelationMetadataService } from 'src/metadata/relation-metadata/relation-metadata.service';
import { standardObjectRelationMetadata } from 'src/workspace/workspace-manager/standard-objects/standard-object-relation-metadata';
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
import {
FieldMetadataEntity,
FieldMetadataType,
} from 'src/metadata/field-metadata/field-metadata.entity';
import {
basicFieldsMetadata,
standardObjectsMetadata,
} from './standard-objects/standard-object-metadata';
@Injectable()
export class WorkspaceManagerService {
constructor(
private readonly workspaceDataSourceService: WorkspaceDataSourceService,
private readonly workspaceMigrationService: WorkspaceMigrationService,
private readonly workspaceMigrationRunnerService: WorkspaceMigrationRunnerService,
private readonly objectMetadataService: ObjectMetadataService,
private readonly fieldMetadataService: FieldMetadataService,
private readonly dataSourceService: DataSourceService,
private readonly relationMetadataService: RelationMetadataService,
) {}
/**
* Init a workspace by creating a new data source and running all migrations
* @param workspaceId
* @returns Promise<void>
*/
public async init(workspaceId: string): Promise<void> {
const schemaName =
await this.workspaceDataSourceService.createWorkspaceDBSchema(
workspaceId,
);
const dataSourceMetadata =
await this.dataSourceService.createDataSourceMetadata(
workspaceId,
schemaName,
);
await this.workspaceMigrationService.insertStandardMigrations(workspaceId);
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
workspaceId,
);
const createdObjectMetadata =
await this.createStandardObjectsAndFieldsMetadata(
dataSourceMetadata.id,
workspaceId,
);
await this.prefillWorkspaceWithStandardObjects(
dataSourceMetadata,
workspaceId,
createdObjectMetadata,
);
}
/**
*
* Create all standard objects and fields metadata for a given workspace
*
* @param dataSourceId
* @param workspaceId
*/
public async createStandardObjectsAndFieldsMetadata(
dataSourceId: string,
workspaceId: string,
): Promise<ObjectMetadataEntity[]> {
const createdObjectMetadata = await this.objectMetadataService.createMany(
Object.values(standardObjectsMetadata).map(
(objectMetadata: ObjectMetadataEntity) => ({
...objectMetadata,
dataSourceId,
workspaceId,
isCustom: false,
isActive: true,
fields: [...basicFieldsMetadata, ...objectMetadata.fields].map(
(field) => ({
...field,
workspaceId,
isCustom: false,
isActive: true,
}),
),
}),
),
);
await this.relationMetadataService.createMany(
Object.values(standardObjectRelationMetadata).map((relationMetadata) =>
this.createStandardObjectRelations(
workspaceId,
createdObjectMetadata,
relationMetadata,
),
),
);
return createdObjectMetadata;
}
/**
*
* @param workspaceId
* @param createdObjectMetadata
* @param relationMetadata
* @returns Partial<RelationMetadataEntity>
*/
private createStandardObjectRelations(
workspaceId: string,
createdObjectMetadata: ObjectMetadataEntity[],
relationMetadata: any,
) {
const createdObjectMetadataByNameSingular = createdObjectMetadata.reduce(
(acc, curr) => {
acc[curr.nameSingular] = curr;
return acc;
},
{},
);
const fromObjectMetadata =
createdObjectMetadataByNameSingular[
relationMetadata.fromObjectNameSingular
];
const toObjectMetadata =
createdObjectMetadataByNameSingular[
relationMetadata.toObjectNameSingular
];
if (!fromObjectMetadata) {
throw new Error(
`Could not find created object metadata with
fromObjectNameSingular: ${relationMetadata.fromObjectNameSingular}`,
);
}
if (!toObjectMetadata) {
throw new Error(
`Could not find created object metadata with
toObjectNameSingular: ${relationMetadata.toObjectNameSingular}`,
);
}
const fromFieldMetadata = createdObjectMetadataByNameSingular[
relationMetadata.fromObjectNameSingular
]?.fields.find(
(field: FieldMetadataEntity) =>
field.type === FieldMetadataType.RELATION &&
field.name === relationMetadata.fromFieldMetadataName,
);
const toFieldMetadata = createdObjectMetadataByNameSingular[
relationMetadata.toObjectNameSingular
]?.fields.find(
(field: FieldMetadataEntity) =>
field.type === FieldMetadataType.RELATION &&
field.name === relationMetadata.toFieldMetadataName,
);
if (!fromFieldMetadata) {
throw new Error(
`Could not find created field metadata with
fromFieldMetadataName: ${relationMetadata.fromFieldMetadataName}
for object: ${relationMetadata.fromObjectNameSingular}`,
);
}
if (!toFieldMetadata) {
throw new Error(
`Could not find created field metadata with
toFieldMetadataName: ${relationMetadata.toFieldMetadataName}
for object: ${relationMetadata.toObjectNameSingular}`,
);
}
return {
fromObjectMetadataId: fromObjectMetadata.id,
toObjectMetadataId: toObjectMetadata.id,
workspaceId,
relationType: relationMetadata.type,
fromFieldMetadataId: fromFieldMetadata.id,
toFieldMetadataId: toFieldMetadata.id,
};
}
/**
*
* Reset all standard objects and fields metadata for a given workspace
*
* @param dataSourceId
* @param workspaceId
*/
public async resetStandardObjectsAndFieldsMetadata(
dataSourceId: string,
workspaceId: string,
) {
await this.objectMetadataService.deleteMany({
workspaceId: { eq: workspaceId },
});
await this.createStandardObjectsAndFieldsMetadata(
dataSourceId,
workspaceId,
);
}
/**
*
* We are prefilling a few standard objects with data to make it easier for the user to get started.
*
* @param dataSourceMetadata
* @param workspaceId
*/
private async prefillWorkspaceWithStandardObjects(
dataSourceMetadata: DataSourceEntity,
workspaceId: string,
createdObjectMetadata: ObjectMetadataEntity[],
) {
const workspaceDataSource =
await this.workspaceDataSourceService.connectToWorkspaceDataSource(
workspaceId,
);
if (!workspaceDataSource) {
throw new Error('Could not connect to workspace data source');
}
standardObjectsPrefillData(
workspaceDataSource,
dataSourceMetadata.schema,
createdObjectMetadata,
);
}
/**
*
* Delete a workspace by deleting all metadata and the schema
*
* @param workspaceId
*/
public async delete(workspaceId: string): Promise<void> {
// Delete data from metadata tables
await this.fieldMetadataService.deleteFieldsMetadata(workspaceId);
await this.objectMetadataService.deleteObjectsMetadata(workspaceId);
await this.workspaceMigrationService.delete(workspaceId);
await this.dataSourceService.delete(workspaceId);
// Delete schema
await this.workspaceDataSourceService.deleteWorkspaceDBSchema(workspaceId);
}
}