Skip to content

The open alternative to Salesforce, designed for AI.

Name the User Apps and Workspace Apps permission flags USER_APPS and WORKSPACE_APPS in the SDK (#29194)

nitin7eabf2634a60
diff --git a/packages/twenty-agent-skills/references/develop-app/layout.md b/packages/twenty-agent-skills/references/develop-app/layout.md
index e5242151fbb..997ce688aad 100644
--- a/packages/twenty-agent-skills/references/develop-app/layout.md
+++ b/packages/twenty-agent-skills/references/develop-app/layout.md
@@ -60,7 +60,7 @@ To add an entry to an app's settings menu, declare it with `defineSettingsMenuIt
The menu item points at the component, not the reverse, so one component can back several items. Declare as many as the app needs. Each renders as a tab on the app's page under Settings > Apps, after the built-in General tab, in `position` order.
-`scope` is `WORKSPACE` (configured once for the whole workspace, the default) or `USER` (configured by each member for themselves). A `USER` item renders as a tab on the app's page under the member's Settings > Apps preferences, but that page is not enabled in every workspace yet — where it is not, the item is persisted and synced but nothing displays it, so say so rather than relying on a `USER` item for a settings entry every workspace needs visible now. To store something per person, a `USER` item should use an application variable declared with `scope: 'USER'`, which `getApplicationVariable` returns with the viewing member's value unless it is secret; the component saves it with `updateMyUserApplicationVariable`, which writes the viewing member's value only (an empty value resets it to the variable's default), refuses a token with nobody behind it, and needs `SystemPermissionFlag.CONNECTED_ACCOUNTS` in the app's default role, if it declares one (and in the member's role, since the component's token is the intersection of both), and since a `USER` item replaces the generated Variables form like a `WORKSPACE` item does, it should let the member set every user variable the app needs; a variable without that scope holds one value shared by the whole workspace.
+`scope` is `WORKSPACE` (configured once for the whole workspace, the default) or `USER` (configured by each member for themselves). A `USER` item renders as a tab on the app's page under the member's Settings > Apps preferences, but that page is not enabled in every workspace yet — where it is not, the item is persisted and synced but nothing displays it, so say so rather than relying on a `USER` item for a settings entry every workspace needs visible now. To store something per person, a `USER` item should use an application variable declared with `scope: 'USER'`, which `getApplicationVariable` returns with the viewing member's value unless it is secret; the component saves it with `updateMyUserApplicationVariable`, which writes the viewing member's value only (an empty value resets it to the variable's default), refuses a token with nobody behind it, and needs `SystemPermissionFlag.USER_APPS` (`CONNECTED_ACCOUNTS` in older `twenty-sdk` versions) in the app's default role, if it declares one (and in the member's role, since the component's token is the intersection of both), and since a `USER` item replaces the generated Variables form like a `WORKSPACE` item does, it should let the member set every user variable the app needs; a variable without that scope holds one value shared by the whole workspace.
Items sort by ascending `position`, which is a decimal so an item can be slotted between two existing ones. Two items of one app cannot share a position in the same scope, and `General` is reserved for the built-in item.
diff --git a/packages/twenty-cli/src/app/bundles/README.md b/packages/twenty-cli/src/app/bundles/README.md
index 1e36f021916..dd1b800a8d3 100644
--- a/packages/twenty-cli/src/app/bundles/README.md
+++ b/packages/twenty-cli/src/app/bundles/README.md
@@ -36,8 +36,9 @@ removes snapshots owned by the current build.
shared with the other CLI app operations. The [dev session](../dev/README.md)
observes the build's inputs and retains immutable copies for remote apply.
- The define stub reads `twenty-sdk/define` from the app's installed SDK. Factories
- become no-op validators, plain-data exports retain their values, and other
- exports use proxy stubs. Runtime constants match the SDK the app uses.
+ become no-op validators, plain-data exports retain their values, including
+ non-enumerable properties, and other exports use proxy stubs. Runtime
+ constants match the SDK the app uses.
- `sharp` is optional and resolved from the app. It is not a CLI dependency.
When unavailable, cover generation warns and the build continues. Vite embeds
the backdrop PNG as a data URI so it works in the standalone package.
diff --git a/packages/twenty-cli/src/app/bundles/plugins/__tests__/stub-twenty-sdk-define.plugin.spec.ts b/packages/twenty-cli/src/app/bundles/plugins/__tests__/stub-twenty-sdk-define.plugin.spec.ts
new file mode 100644
index 00000000000..39c18f74c1b
--- /dev/null
+++ b/packages/twenty-cli/src/app/bundles/plugins/__tests__/stub-twenty-sdk-define.plugin.spec.ts
@@ -0,0 +1,102 @@
+import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { pathToFileURL } from 'node:url';
+
+import * as esbuild from 'esbuild';
+import { afterEach, describe, expect, it } from 'vitest';
+
+import {
+ buildStubModuleSource,
+ createStubTwentySdkDefinePlugin,
+} from '@/app/bundles/plugins/stub-twenty-sdk-define.plugin';
+
+const appPaths: string[] = [];
+
+afterEach(async () => {
+ await Promise.all(
+ appPaths
+ .splice(0)
+ .map((appPath) => rm(appPath, { recursive: true, force: true })),
+ );
+});
+
+const importSource = (source: string) =>
+ import(
+ `data:text/javascript;base64,${Buffer.from(source).toString('base64')}`
+ );
+
+const createAppWithSdkDefine = async (defineSource: string) => {
+ const appPath = await mkdtemp(join(tmpdir(), 'twenty-sdk-define-stub-'));
+ appPaths.push(appPath);
+ const sdkPath = join(appPath, 'node_modules/twenty-sdk');
+
+ await mkdir(sdkPath, { recursive: true });
+ await writeFile(join(appPath, 'package.json'), '{}');
+ await writeFile(
+ join(sdkPath, 'package.json'),
+ JSON.stringify({
+ name: 'twenty-sdk',
+ exports: { './define': './define.cjs' },
+ }),
+ );
+ await writeFile(join(sdkPath, 'define.cjs'), defineSource);
+
+ return appPath;
+};
+
+describe('buildStubModuleSource', () => {
+ it('keeps non-enumerable plain data properties non-enumerable', async () => {
+ const Flag = Object.defineProperty({ CURRENT: 'flag-id' }, 'DEPRECATED', {
+ value: 'flag-id',
+ });
+
+ const { Flag: stubbedFlag } = await importSource(
+ buildStubModuleSource({ Flag }),
+ );
+
+ expect(stubbedFlag.DEPRECATED).toBe('flag-id');
+ expect(Object.keys(stubbedFlag)).toEqual(['CURRENT']);
+ expect(
+ Object.getOwnPropertyDescriptor(stubbedFlag, 'DEPRECATED')?.enumerable,
+ ).toBe(false);
+ });
+
+ it('inlines enumerable values when a non-enumerable property is a function', async () => {
+ const Flag = Object.defineProperty({ CURRENT: 'flag-id' }, 'describe', {
+ value: () => 'flag',
+ });
+
+ const { Flag: stubbedFlag } = await importSource(
+ buildStubModuleSource({ Flag }),
+ );
+
+ expect(stubbedFlag.CURRENT).toBe('flag-id');
+ expect(Object.getOwnPropertyNames(stubbedFlag)).toEqual(['CURRENT']);
+ });
+
+ it('stays tree-shakeable when an aliased export is unused', async () => {
+ const appPath = await createAppWithSdkDefine(
+ `exports.defineThing = (config) => config;
+exports.Flag = Object.defineProperty({ CURRENT: 'unused-flag-id' }, 'DEPRECATED', { value: 'unused-flag-id' });`,
+ );
+ const outfile = join(appPath, 'out.mjs');
+
+ await esbuild.build({
+ stdin: {
+ contents: `import { defineThing } from 'twenty-sdk/define';
+export default defineThing({});`,
+ resolveDir: appPath,
+ },
+ bundle: true,
+ format: 'esm',
+ outfile,
+ plugins: [createStubTwentySdkDefinePlugin(appPath)],
+ });
+
+ expect(await readFile(outfile, 'utf8')).not.toContain('unused-flag-id');
+ expect((await import(pathToFileURL(outfile).href)).default).toMatchObject({
+ success: true,
+ });
+ });
+});
diff --git a/packages/twenty-cli/src/app/bundles/plugins/stub-twenty-sdk-define.plugin.ts b/packages/twenty-cli/src/app/bundles/plugins/stub-twenty-sdk-define.plugin.ts
index 0c74dec143b..e326c32c8bf 100644
--- a/packages/twenty-cli/src/app/bundles/plugins/stub-twenty-sdk-define.plugin.ts
+++ b/packages/twenty-cli/src/app/bundles/plugins/stub-twenty-sdk-define.plugin.ts
@@ -1,6 +1,6 @@
import type * as esbuild from 'esbuild';
-import { isPlainObject } from 'twenty-shared/utils';
+import { isNonEmptyArray, isPlainObject } from 'twenty-shared/utils';
import { createRequire } from 'node:module';
import { join } from 'node:path';
@@ -17,6 +17,30 @@ export const isPlainDataExport = (value: unknown): boolean =>
isPrimitive(value) ||
(isPlainObject(value) && Object.values(value).every(isPrimitive));
+const serializePlainDataExport = (value: unknown): string => {
+ const json = JSON.stringify(value);
+
+ if (!isPlainObject(value)) {
+ return json;
+ }
+
+ const nonEnumerablePrimitiveNames = Object.getOwnPropertyNames(value).filter(
+ (name) =>
+ !Object.prototype.propertyIsEnumerable.call(value, name) &&
+ isPrimitive(value[name]),
+ );
+
+ if (!isNonEmptyArray(nonEnumerablePrimitiveNames)) {
+ return json;
+ }
+
+ const nonEnumerableDescriptors = Object.fromEntries(
+ nonEnumerablePrimitiveNames.map((name) => [name, { value: value[name] }]),
+ );
+
+ return `/* @__PURE__ */ Object.defineProperties(${json}, ${JSON.stringify(nonEnumerableDescriptors)})`;
+};
+
const partitionDefineExports = (
mod: Record<string, unknown>,
): {
@@ -78,9 +102,9 @@ export const buildStubModuleSource = (
exportLines.push(`export const ${name} = __defineFactoryStub;`);
}
for (const name of stubbedExports.plainData) {
- const value = twentySdkDefine[name];
-
- exportLines.push(`export const ${name} = ${JSON.stringify(value)};`);
+ exportLines.push(
+ `export const ${name} = ${serializePlainDataExport(twentySdkDefine[name])};`,
+ );
}
for (const name of stubbedExports.any) {
exportLines.push(`export const ${name} = __anyStub;`);
diff --git a/packages/twenty-cli/src/app/manifest/manifest-build.ts b/packages/twenty-cli/src/app/manifest/manifest-build.ts
index 6fcb346a396..33778d94cee 100644
--- a/packages/twenty-cli/src/app/manifest/manifest-build.ts
+++ b/packages/twenty-cli/src/app/manifest/manifest-build.ts
@@ -13,6 +13,7 @@ import { fromRoleConfigToRoleManifest } from '@/app/manifest/utils/from-role-con
import { extractFrontComponentSharedDependencies } from '@/app/manifest/utils/extract-front-component-shared-dependencies';
import { validateConditionalAvailabilityUsage } from '@/app/manifest/utils/validate-conditional-availability-usage';
import { validateAgentRolesWithinApplicationRole } from '@/app/manifest/utils/validate-agent-roles-within-application-role';
+import { resolveAppSystemPermissionFlag } from '@/app/project/resolve-app-system-permission-flag';
import { validateViewFilterOperands } from '@/app/manifest/utils/validate-view-filter-operands';
import { getEngineVersionRange } from '@/app/manifest/get-engine-version-range';
import { type ApplicationConfig } from '@/app/manifest/types/application-config.type';
@@ -661,6 +662,7 @@ export const buildManifest = async (
objects,
permissionFlags,
defaultRoleUniversalIdentifier: resolvedDefaultRoleUniversalIdentifier,
+ systemPermissionFlag: resolveAppSystemPermissionFlag(appPath),
}),
);
}
diff --git a/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-agent-roles-within-application-role.spec.ts b/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-agent-roles-within-application-role.spec.ts
index be2c98688e7..e8ff36fd0e0 100644
--- a/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-agent-roles-within-application-role.spec.ts
+++ b/packages/twenty-cli/src/app/manifest/utils/__tests__/validate-agent-roles-within-application-role.spec.ts
@@ -119,6 +119,31 @@ describe('validateAgentRolesWithinApplicationRole', () => {
]);
});
+ it('names system flags as the app SDK does', () => {
+ const errors = validateAgentRolesWithinApplicationRole({
+ agents: [buildAgent()],
+ roles: [
+ applicationRole,
+ buildRole({
+ permissionFlagUniversalIdentifiers: [
+ SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ ],
+ }),
+ ],
+ objects: [],
+ permissionFlags: [],
+ defaultRoleUniversalIdentifier: APPLICATION_ROLE_UNIVERSAL_IDENTIFIER,
+ systemPermissionFlag: {
+ USER_APPS: SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ ...SystemPermissionFlag,
+ },
+ });
+
+ expect(errors).toEqual([
+ 'Role "Agent role" used by agent "assistant" grants more than the application role "Application role": permission flag USER_APPS. The application role must cover every permission an agent role grants.',
+ ]);
+ });
+
it('treats a custom permission flag without a permission type as a tool flag, like the server does', () => {
const customToolFlagUniversalIdentifier = 'custom-tool-flag';
diff --git a/packages/twenty-cli/src/app/manifest/utils/validate-agent-roles-within-application-role.ts b/packages/twenty-cli/src/app/manifest/utils/validate-agent-roles-within-application-role.ts
index c5ac19079e5..7b872850062 100644
--- a/packages/twenty-cli/src/app/manifest/utils/validate-agent-roles-within-application-role.ts
+++ b/packages/twenty-cli/src/app/manifest/utils/validate-agent-roles-within-application-role.ts
@@ -29,12 +29,21 @@ const OBJECT_ACTION_LABELS = {
canDestroyObjectRecords: 'destroy',
} as const;
-const SYSTEM_PERMISSION_FLAG_KEY_BY_UNIVERSAL_IDENTIFIER = Object.fromEntries(
- Object.entries(SystemPermissionFlag).map(([key, universalIdentifier]) => [
- universalIdentifier,
- key,
- ]),
-);
+const buildSystemPermissionFlagNameByUniversalIdentifier = (
+ systemPermissionFlag: Record<string, string>,
+): Map<string, string> => {
+ const nameByUniversalIdentifier = new Map<string, string>();
+
+ for (const [name, universalIdentifier] of Object.entries(
+ systemPermissionFlag,
+ )) {
+ if (!nameByUniversalIdentifier.has(universalIdentifier)) {
+ nameByUniversalIdentifier.set(universalIdentifier, name);
+ }
+ }
+
+ return nameByUniversalIdentifier;
+};
const STANDARD_OBJECT_NAME_BY_UNIVERSAL_IDENTIFIER = Object.fromEntries(
Object.entries(STANDARD_OBJECTS).map(([name, { universalIdentifier }]) => [
@@ -47,10 +56,12 @@ const describeGrant = ({
grant,
objects,
permissionFlags,
+ systemPermissionFlagNameByUniversalIdentifier,
}: {
grant: RoleManifestGrant;
objects: ObjectDescriptor[];
permissionFlags: PermissionFlagDescriptor[];
+ systemPermissionFlagNameByUniversalIdentifier: Map<string, string>;
}): string => {
const describeObject = (objectUniversalIdentifier: string) =>
objects.find(
@@ -73,9 +84,9 @@ const describeGrant = ({
flag.universalIdentifier ===
grant.permissionFlagUniversalIdentifier,
)?.key ??
- SYSTEM_PERMISSION_FLAG_KEY_BY_UNIVERSAL_IDENTIFIER[
- grant.permissionFlagUniversalIdentifier
- ] ??
+ systemPermissionFlagNameByUniversalIdentifier.get(
+ grant.permissionFlagUniversalIdentifier,
+ ) ??
grant.permissionFlagUniversalIdentifier;
return `permission flag ${flagKey}`;
@@ -159,12 +170,14 @@ const validateAgentRolesAreCoveredByApplicationRole = ({
roles,
objects,
permissionFlags,
+ systemPermissionFlagNameByUniversalIdentifier,
}: {
agentNamesByRoleUniversalIdentifier: AgentNamesByRoleUniversalIdentifier;
applicationRole: RoleManifest;
roles: RoleManifest[];
objects: ObjectDescriptor[];
permissionFlags: PermissionFlagDescriptor[];
+ systemPermissionFlagNameByUniversalIdentifier: Map<string, string>;
}): string[] => {
const toolPermissionFlagUniversalIdentifiers = permissionFlags
.filter((flag) => (flag.permissionType ?? 'tool') === 'tool')
@@ -191,7 +204,14 @@ const validateAgentRolesAreCoveredByApplicationRole = ({
}
const grantList = uncoveredGrants
- .map((grant) => describeGrant({ grant, objects, permissionFlags }))
+ .map((grant) =>
+ describeGrant({
+ grant,
+ objects,
+ permissionFlags,
+ systemPermissionFlagNameByUniversalIdentifier,
+ }),
+ )
.join(', ');
return [
@@ -207,12 +227,14 @@ export const validateAgentRolesWithinApplicationRole = ({
objects,
permissionFlags,
defaultRoleUniversalIdentifier,
+ systemPermissionFlag = SystemPermissionFlag,
}: {
agents: AgentManifest[];
roles: RoleManifest[];
objects: ObjectDescriptor[];
permissionFlags: PermissionFlagDescriptor[];
defaultRoleUniversalIdentifier: string;
+ systemPermissionFlag?: Record<string, string>;
}): string[] => {
const applicationRole = roles.find(
(role) => role.universalIdentifier === defaultRoleUniversalIdentifier,
@@ -239,6 +261,10 @@ export const validateAgentRolesWithinApplicationRole = ({
roles,
objects,
permissionFlags,
+ systemPermissionFlagNameByUniversalIdentifier:
+ buildSystemPermissionFlagNameByUniversalIdentifier(
+ systemPermissionFlag,
+ ),
})
: []),
];
diff --git a/packages/twenty-cli/src/app/project/__tests__/resolve-app-system-permission-flag.spec.ts b/packages/twenty-cli/src/app/project/__tests__/resolve-app-system-permission-flag.spec.ts
new file mode 100644
index 00000000000..1e36e761c80
--- /dev/null
+++ b/packages/twenty-cli/src/app/project/__tests__/resolve-app-system-permission-flag.spec.ts
@@ -0,0 +1,102 @@
+import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+import { afterEach, describe, expect, it } from 'vitest';
+import { SystemPermissionFlag } from 'twenty-shared/constants';
+
+import { resolveAppSystemPermissionFlag } from '@/app/project/resolve-app-system-permission-flag';
+import {
+ buildRoleEnumBindings,
+ writeDefineFile,
+} from '@/app/pull/write-define-file';
+
+const appPaths: string[] = [];
+
+afterEach(async () => {
+ await Promise.all(
+ appPaths
+ .splice(0)
+ .map((appPath) => rm(appPath, { recursive: true, force: true })),
+ );
+});
+
+const createApp = async (sdkDefineSource = '') => {
+ const appPath = await mkdtemp(join(tmpdir(), 'twenty-pull-flags-'));
+ appPaths.push(appPath);
+ await writeFile(join(appPath, 'package.json'), '{}');
+
+ const sdkPath = join(appPath, 'node_modules/twenty-sdk');
+ await mkdir(sdkPath, { recursive: true });
+ await writeFile(
+ join(sdkPath, 'package.json'),
+ JSON.stringify({
+ name: 'twenty-sdk',
+ exports: { './define': './define.cjs' },
+ }),
+ );
+ await writeFile(join(sdkPath, 'define.cjs'), sdkDefineSource);
+
+ return appPath;
+};
+
+const buildRoleFileContent = (appPath: string) =>
+ writeDefineFile({
+ definer: 'defineRole',
+ config: {
+ permissionFlagUniversalIdentifiers: [
+ SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ SystemPermissionFlag.APPLICATIONS,
+ SystemPermissionFlag.WORKFLOWS,
+ ],
+ },
+ enumBindings: buildRoleEnumBindings(
+ resolveAppSystemPermissionFlag(appPath),
+ ),
+ }).content;
+
+describe('resolveAppSystemPermissionFlag', () => {
+ it('writes the new names an app SDK defines as non-enumerable aliases', async () => {
+ const appPath = await createApp(
+ `exports.SystemPermissionFlag = Object.assign(
+ Object.defineProperties({}, {
+ USER_APPS: { value: '${SystemPermissionFlag.CONNECTED_ACCOUNTS}' },
+ WORKSPACE_APPS: { value: '${SystemPermissionFlag.APPLICATIONS}' },
+ }),
+ ${JSON.stringify(SystemPermissionFlag)},
+ );`,
+ );
+
+ const content = buildRoleFileContent(appPath);
+
+ expect(content).toContain('SystemPermissionFlag.USER_APPS');
+ expect(content).toContain('SystemPermissionFlag.WORKSPACE_APPS');
+ expect(content).toContain('SystemPermissionFlag.WORKFLOWS');
+ expect(content).not.toContain('SystemPermissionFlag.CONNECTED_ACCOUNTS');
+ expect(content).not.toContain('SystemPermissionFlag.APPLICATIONS');
+ });
+
+ it('keeps the names of an older app SDK and writes flags it lacks as identifiers', async () => {
+ const appPath = await createApp(
+ `exports.SystemPermissionFlag = ${JSON.stringify({
+ CONNECTED_ACCOUNTS: SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ APPLICATIONS: SystemPermissionFlag.APPLICATIONS,
+ })};`,
+ );
+
+ const content = buildRoleFileContent(appPath);
+
+ expect(content).toContain('SystemPermissionFlag.CONNECTED_ACCOUNTS');
+ expect(content).toContain('SystemPermissionFlag.APPLICATIONS');
+ expect(content).toContain(`'${SystemPermissionFlag.WORKFLOWS}'`);
+ });
+
+ it('writes every flag as its identifier when the app SDK does not export SystemPermissionFlag', async () => {
+ const appPath = await createApp();
+
+ expect(resolveAppSystemPermissionFlag(appPath)).toEqual({});
+ expect(buildRoleFileContent(appPath)).toContain(
+ `'${SystemPermissionFlag.CONNECTED_ACCOUNTS}'`,
+ );
+ });
+});
diff --git a/packages/twenty-cli/src/app/project/resolve-app-system-permission-flag.ts b/packages/twenty-cli/src/app/project/resolve-app-system-permission-flag.ts
new file mode 100644
index 00000000000..3dcaba0d921
--- /dev/null
+++ b/packages/twenty-cli/src/app/project/resolve-app-system-permission-flag.ts
@@ -0,0 +1,21 @@
+import { createRequire } from 'node:module';
+import { join } from 'node:path';
+
+import { isString } from '@sniptt/guards';
+import { isPlainObject } from 'twenty-shared/utils';
+
+export const resolveAppSystemPermissionFlag = (
+ appPath: string,
+): Record<string, string> => {
+ const { SystemPermissionFlag: appSystemPermissionFlag } = createRequire(
+ join(appPath, 'package.json'),
+ )('twenty-sdk/define');
+
+ return isPlainObject(appSystemPermissionFlag)
+ ? Object.fromEntries(
+ Object.getOwnPropertyNames(appSystemPermissionFlag)
+ .map((name) => [name, appSystemPermissionFlag[name]])
+ .filter((entry): entry is [string, string] => isString(entry[1])),
+ )
+ : {};
+};
diff --git a/packages/twenty-cli/src/app/pull/__tests__/build-pull-entities.spec.ts b/packages/twenty-cli/src/app/pull/__tests__/build-pull-entities.spec.ts
index 36fffcda154..d289b3e14fb 100644
--- a/packages/twenty-cli/src/app/pull/__tests__/build-pull-entities.spec.ts
+++ b/packages/twenty-cli/src/app/pull/__tests__/build-pull-entities.spec.ts
@@ -230,7 +230,7 @@ const WORKFLOW_MANIFEST: WorkflowManifest = {
describe('buildPullEntities', () => {
it('should strip the checksums the build recomputes from the application config', () => {
- const { entities } = buildPullEntities(buildManifest());
+ const { entities } = buildPullEntities({ manifest: buildManifest() });
const application = entities.find(
(entity) => entity.kind === 'application',
);
@@ -248,7 +248,7 @@ describe('buildPullEntities', () => {
it('should write an object verbatim, keeping its name field and label identifier', () => {
const manifest = buildManifest();
- const { entities } = buildPullEntities(manifest);
+ const { entities } = buildPullEntities({ manifest: manifest });
const object = entities.find((entity) => entity.kind === 'object');
expect(object?.config).toEqual(manifest.objects[0]);
@@ -258,7 +258,7 @@ describe('buildPullEntities', () => {
});
it('should name a field on a standard object after that object', () => {
- const { entities } = buildPullEntities(buildManifest());
+ const { entities } = buildPullEntities({ manifest: buildManifest() });
const field = entities.find((entity) => entity.kind === 'field');
expect(
@@ -267,8 +267,8 @@ describe('buildPullEntities', () => {
});
it('should name an index after its object and fields', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
indexes: [
{
universalIdentifier: INDEX_UID,
@@ -277,7 +277,7 @@ describe('buildPullEntities', () => {
},
],
} as unknown as Partial<Manifest>),
- );
+ });
const index = entities.find((entity) => entity.kind === 'index');
expect(
@@ -303,11 +303,11 @@ describe('buildPullEntities', () => {
],
};
- const { entities, skipped } = buildPullEntities(
- buildManifest({
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({
objects: [junctionObject],
} as unknown as Partial<Manifest>),
- );
+ });
const object = entities.find((entity) => entity.kind === 'object');
expect(skipped).toEqual([]);
@@ -315,8 +315,8 @@ describe('buildPullEntities', () => {
});
it('should skip an index whose object is not part of the export', () => {
- const { entities, skipped } = buildPullEntities(
- buildManifest({
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({
objects: [],
indexes: [
{
@@ -326,7 +326,7 @@ describe('buildPullEntities', () => {
},
],
} as unknown as Partial<Manifest>),
- );
+ });
expect(entities.some((entity) => entity.kind === 'index')).toBe(false);
expect(
@@ -336,9 +336,9 @@ describe('buildPullEntities', () => {
it('should write a view verbatim into src/views with the view enum bindings and its object as parent', () => {
const viewManifest = buildViewManifest();
- const { entities, skipped } = buildPullEntities(
- buildManifest({ views: [viewManifest] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ views: [viewManifest] }),
+ });
const view = entities.find((entity) => entity.kind === 'view');
expect(skipped).toEqual([]);
@@ -353,8 +353,8 @@ describe('buildPullEntities', () => {
});
it('should give a view on a standard object that object as parent', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
views: [
buildViewManifest({
objectUniversalIdentifier:
@@ -362,29 +362,29 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const view = entities.find((entity) => entity.kind === 'view');
expect(view?.parentName).toBe('person');
});
it('should name a view whose name has no kebab-case form after its identifier prefix', () => {
- const { entities } = buildPullEntities(
- buildManifest({ views: [buildViewManifest({ name: '!!!' })] }),
- );
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({ views: [buildViewManifest({ name: '!!!' })] }),
+ });
const view = entities.find((entity) => entity.kind === 'view');
expect(view?.fileBaseName).toBe('88888888');
});
it('should cap the file name of a view with an overlong name', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
views: [
buildViewManifest({ name: `${'Ab'.repeat(39)} ${'c'.repeat(300)}` }),
],
}),
- );
+ });
const view = entities.find((entity) => entity.kind === 'view');
expect(view?.fileBaseName).toBe(`${'ab-'.repeat(26)}ab`);
@@ -393,12 +393,12 @@ describe('buildPullEntities', () => {
it('should write a standalone view field into src/view-fields named after the manifest object and field it points to', () => {
const viewFieldManifest = buildViewFieldManifest();
- const { entities, skipped } = buildPullEntities(
- buildManifest({
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({
views: [buildViewManifest()],
viewFields: [viewFieldManifest],
}),
- );
+ });
const viewField = entities.find((entity) => entity.kind === 'viewField');
expect(skipped).toEqual([]);
@@ -413,8 +413,8 @@ describe('buildPullEntities', () => {
});
it('should name a standalone view field pointing at a manifest field on a standard object after that object', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
views: [buildViewManifest()],
viewFields: [
buildViewFieldManifest({
@@ -422,15 +422,15 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const viewField = entities.find((entity) => entity.kind === 'viewField');
expect(viewField?.fileBaseName).toBe('company-cared-for-pets');
});
it('should name a standalone view field pointing at a standard field after the standard object and field', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
views: [buildViewManifest()],
viewFields: [
buildViewFieldManifest({
@@ -439,15 +439,15 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const viewField = entities.find((entity) => entity.kind === 'viewField');
expect(viewField?.fileBaseName).toBe('person-job-title');
});
it('should name a standalone view field pointing at an unknown field after its identifier prefix', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
views: [buildViewManifest()],
viewFields: [
buildViewFieldManifest({
@@ -455,7 +455,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const viewField = entities.find((entity) => entity.kind === 'viewField');
expect(viewField?.fileBaseName).toBe('99999999');
@@ -463,9 +463,9 @@ describe('buildPullEntities', () => {
it('should write a page layout verbatim into src/page-layouts with the page layout enum bindings and its object as parent', () => {
const pageLayoutManifest = buildPageLayoutManifest();
- const { entities, skipped } = buildPullEntities(
- buildManifest({ pageLayouts: [pageLayoutManifest] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ pageLayouts: [pageLayoutManifest] }),
+ });
const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');
expect(skipped).toEqual([]);
@@ -490,8 +490,8 @@ describe('buildPullEntities', () => {
viewUniversalIdentifier: VIEW_UID,
},
};
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
pageLayouts: [
{
...pageLayoutManifest,
@@ -506,7 +506,7 @@ describe('buildPullEntities', () => {
} as unknown as Partial<PageLayoutTabManifest>),
],
}),
- );
+ });
const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');
const pageLayoutTab = entities.find(
(entity) => entity.kind === 'pageLayoutTab',
@@ -528,8 +528,8 @@ describe('buildPullEntities', () => {
});
it('should give a page layout on a standard object that object as parent', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
pageLayouts: [
buildPageLayoutManifest({
objectUniversalIdentifier:
@@ -537,7 +537,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');
expect(pageLayout?.parentName).toBe('person');
@@ -551,9 +551,9 @@ describe('buildPullEntities', () => {
name: 'Pet docs',
type: PageLayoutType.STANDALONE_PAGE,
});
- const { entities, skipped } = buildPullEntities(
- buildManifest({ pageLayouts: [standalonePageManifest] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ pageLayouts: [standalonePageManifest] }),
+ });
const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');
expect(skipped).toEqual([]);
@@ -562,11 +562,11 @@ describe('buildPullEntities', () => {
});
it('should name a page layout whose name has no kebab-case form after its identifier prefix', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
pageLayouts: [buildPageLayoutManifest({ name: '!!!' })],
}),
- );
+ });
const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');
expect(pageLayout?.fileBaseName).toBe('cccccccc');
@@ -574,9 +574,9 @@ describe('buildPullEntities', () => {
it('should write a standalone page layout tab into src/page-layout-tabs with the tab enum bindings and its standard page layout as parent', () => {
const pageLayoutTabManifest = buildPageLayoutTabManifest();
- const { entities, skipped } = buildPullEntities(
- buildManifest({ pageLayoutTabs: [pageLayoutTabManifest] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ pageLayoutTabs: [pageLayoutTabManifest] }),
+ });
const pageLayoutTab = entities.find(
(entity) => entity.kind === 'pageLayoutTab',
);
@@ -593,8 +593,8 @@ describe('buildPullEntities', () => {
});
it('should give a standalone tab on the record page of a manifest object that page as parent', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
pageLayoutTabs: [
buildPageLayoutTabManifest({
pageLayoutUniversalIdentifier:
@@ -605,7 +605,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const pageLayoutTab = entities.find(
(entity) => entity.kind === 'pageLayoutTab',
);
@@ -614,8 +614,8 @@ describe('buildPullEntities', () => {
});
it('should give a standalone tab on a page layout of the manifest that layout as parent', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
pageLayouts: [buildPageLayoutManifest()],
pageLayoutTabs: [
buildPageLayoutTabManifest({
@@ -623,7 +623,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const pageLayoutTab = entities.find(
(entity) => entity.kind === 'pageLayoutTab',
);
@@ -636,9 +636,9 @@ describe('buildPullEntities', () => {
pageLayoutUniversalIdentifier: _pageLayoutUniversalIdentifier,
...tabWithoutPageLayout
} = buildPageLayoutTabManifest();
- const { entities, skipped } = buildPullEntities(
- buildManifest({ pageLayoutTabs: [tabWithoutPageLayout] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ pageLayoutTabs: [tabWithoutPageLayout] }),
+ });
expect(entities.some((entity) => entity.kind === 'pageLayoutTab')).toBe(
false,
@@ -654,9 +654,11 @@ describe('buildPullEntities', () => {
it('should write a navigation menu item verbatim into src/navigation-menu-items with the navigation menu item enum bindings, named after the object it targets', () => {
const navigationMenuItemManifest = buildNavigationMenuItemManifest();
- const { entities, skipped } = buildPullEntities(
- buildManifest({ navigationMenuItems: [navigationMenuItemManifest] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({
+ navigationMenuItems: [navigationMenuItemManifest],
+ }),
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -677,13 +679,13 @@ describe('buildPullEntities', () => {
});
it('should prefer the name a navigation menu item carries over the object it targets', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [
buildNavigationMenuItemManifest({ name: 'Pet shelter' }),
],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -692,11 +694,11 @@ describe('buildPullEntities', () => {
});
it('should name a navigation menu item with an empty name after the object it targets', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [buildNavigationMenuItemManifest({ name: '' })],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -705,11 +707,11 @@ describe('buildPullEntities', () => {
});
it('should name a navigation menu item whose name is only whitespace after the object it targets', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [buildNavigationMenuItemManifest({ name: ' ' })],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -718,8 +720,8 @@ describe('buildPullEntities', () => {
});
it('should name a navigation menu item targeting a standard object after that object', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [
buildNavigationMenuItemManifest({
targetObjectUniversalIdentifier:
@@ -727,7 +729,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -744,12 +746,12 @@ describe('buildPullEntities', () => {
targetObjectUniversalIdentifier: PET_UID,
viewUniversalIdentifier: VIEW_UID,
});
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
views: [buildViewManifest()],
navigationMenuItems: [viewItemManifest],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -769,9 +771,9 @@ describe('buildPullEntities', () => {
viewKey: SYSTEM_VIEW_KEYS.INDEX,
}),
});
- const { entities } = buildPullEntities(
- buildManifest({ navigationMenuItems: [indexViewItemManifest] }),
- );
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({ navigationMenuItems: [indexViewItemManifest] }),
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -787,12 +789,12 @@ describe('buildPullEntities', () => {
type: NavigationMenuItemType.PAGE_LAYOUT,
pageLayoutUniversalIdentifier: PAGE_LAYOUT_UID,
});
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
pageLayouts: [buildPageLayoutManifest()],
navigationMenuItems: [pageLayoutItemManifest],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -808,9 +810,9 @@ describe('buildPullEntities', () => {
type: NavigationMenuItemType.LINK,
link: 'https://twenty.com',
});
- const { entities } = buildPullEntities(
- buildManifest({ navigationMenuItems: [linkItemManifest] }),
- );
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({ navigationMenuItems: [linkItemManifest] }),
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -828,8 +830,8 @@ describe('buildPullEntities', () => {
name: 'Care',
position: 0,
});
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [
folderManifest,
buildNavigationMenuItemManifest({
@@ -837,7 +839,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.universalIdentifier === NAVIGATION_MENU_ITEM_UID,
);
@@ -855,8 +857,8 @@ describe('buildPullEntities', () => {
name: '',
position: 0,
});
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [
folderManifest,
buildNavigationMenuItemManifest({
@@ -864,7 +866,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.universalIdentifier === NAVIGATION_MENU_ITEM_UID,
);
@@ -882,8 +884,8 @@ describe('buildPullEntities', () => {
name: '///',
position: 0,
});
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [
folderManifest,
buildNavigationMenuItemManifest({
@@ -891,7 +893,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.universalIdentifier === NAVIGATION_MENU_ITEM_UID,
);
@@ -900,15 +902,15 @@ describe('buildPullEntities', () => {
});
it('should give a navigation menu item whose folder is not part of the export no parent', () => {
- const { entities, skipped } = buildPullEntities(
- buildManifest({
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({
navigationMenuItems: [
buildNavigationMenuItemManifest({
folderUniversalIdentifier: 'a-folder-of-another-application',
}),
],
}),
- );
+ });
const navigationMenuItem = entities.find(
(entity) => entity.kind === 'navigationMenuItem',
);
@@ -918,8 +920,8 @@ describe('buildPullEntities', () => {
});
it('should write a standalone page layout widget into src/page-layout-widgets, named after its title', () => {
- const { entities, skipped } = buildPullEntities(
- buildManifest({
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({
pageLayoutWidgets: [
{
universalIdentifier: WIDGET_UID,
@@ -939,7 +941,7 @@ describe('buildPullEntities', () => {
},
],
} as unknown as Partial<Manifest>),
- );
+ });
const widget = entities.find(
(entity) => entity.kind === 'pageLayoutWidget',
);
@@ -955,9 +957,9 @@ describe('buildPullEntities', () => {
});
it('should write a workflow verbatim into src/workflows with the workflow enum bindings, named after the workflow', () => {
- const { entities, skipped } = buildPullEntities(
- buildManifest({ workflows: [WORKFLOW_MANIFEST] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ workflows: [WORKFLOW_MANIFEST] }),
+ });
const workflow = entities.find((entity) => entity.kind === 'workflow');
expect(skipped).toEqual([]);
@@ -974,9 +976,11 @@ describe('buildPullEntities', () => {
});
it('should name a workflow whose name has no kebab-case form after its identifier prefix', () => {
- const { entities } = buildPullEntities(
- buildManifest({ workflows: [{ ...WORKFLOW_MANIFEST, name: '!!!' }] }),
- );
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
+ workflows: [{ ...WORKFLOW_MANIFEST, name: '!!!' }],
+ }),
+ });
expect(
entities.find((entity) => entity.kind === 'workflow')?.fileBaseName,
@@ -997,9 +1001,9 @@ describe('buildPullEntities', () => {
label: 'Grooming Tips',
content: 'Brush first.',
};
- const { entities, skipped } = buildPullEntities(
- buildManifest({ agents: [agent], skills: [skill] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ agents: [agent], skills: [skill] }),
+ });
const pathOf = (kind: string) => {
const entity = entities.find((candidate) => candidate.kind === kind);
@@ -1039,9 +1043,9 @@ describe('buildPullEntities', () => {
pageLayoutTabs: [buildPageLayoutTabManifest()],
});
- const { entities, skipped } = buildPullEntities(
- manifestWithoutViews as unknown as Manifest,
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: manifestWithoutViews as unknown as Manifest,
+ });
expect(skipped).toEqual([]);
expect(entities.map((entity) => entity.kind)).toEqual([
@@ -1052,8 +1056,8 @@ describe('buildPullEntities', () => {
});
it('should never skip a view, a view field, a page layout or a page layout tab, even when their parent is unknown', () => {
- const { entities, skipped } = buildPullEntities(
- buildManifest({
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({
objects: [],
views: [
buildViewManifest({
@@ -1077,7 +1081,7 @@ describe('buildPullEntities', () => {
}),
],
}),
- );
+ });
const view = entities.find((entity) => entity.kind === 'view');
const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');
const pageLayoutTab = entities.find(
@@ -1105,9 +1109,9 @@ describe('buildPullEntities', () => {
label: 'Export pets',
permissionType: 'settings' as const,
};
- const { entities, skipped } = buildPullEntities(
- buildManifest({ permissionFlags: [permissionFlagManifest] }),
- );
+ const { entities, skipped } = buildPullEntities({
+ manifest: buildManifest({ permissionFlags: [permissionFlagManifest] }),
+ });
const permissionFlag = entities.find(
(entity) => entity.kind === 'permissionFlag',
);
@@ -1121,15 +1125,15 @@ describe('buildPullEntities', () => {
});
it('should write the default role with defineApplicationRole and the other roles with defineRole into src/roles under the role enum bindings', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
application: APPLICATION_WITH_SUPPORT_DEFAULT_ROLE,
roles: [
{ universalIdentifier: SUPPORT_ROLE_UID, label: 'Support' },
{ universalIdentifier: AUDITOR_ROLE_UID, label: 'Auditor' },
],
} as unknown as Partial<Manifest>),
- );
+ });
expect(
entities
@@ -1154,12 +1158,12 @@ describe('buildPullEntities', () => {
});
it('should drop the default role from the application config when that role is written', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
application: APPLICATION_WITH_SUPPORT_DEFAULT_ROLE,
roles: [{ universalIdentifier: SUPPORT_ROLE_UID, label: 'Support' }],
} as unknown as Partial<Manifest>),
- );
+ });
expect(
entities.find((entity) => entity.kind === 'application')?.config,
@@ -1171,12 +1175,12 @@ describe('buildPullEntities', () => {
});
it('should keep a default role that is not one of the written roles on the application config', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
application: APPLICATION_WITH_SUPPORT_DEFAULT_ROLE,
roles: [{ universalIdentifier: AUDITOR_ROLE_UID, label: 'Auditor' }],
} as unknown as Partial<Manifest>),
- );
+ });
expect(
entities.find((entity) => entity.kind === 'application')?.config,
@@ -1187,8 +1191,8 @@ describe('buildPullEntities', () => {
});
it('should leave out the object and field permission identifiers the build derives and keep the others', () => {
- const { entities } = buildPullEntities(
- buildManifest({
+ const { entities } = buildPullEntities({
+ manifest: buildManifest({
roles: [
{
universalIdentifier: SUPPORT_ROLE_UID,
@@ -1226,7 +1230,7 @@ describe('buildPullEntities', () => {
},
],
}),
- );
+ });
expect(entities.find((entity) => entity.kind === 'role')?.config).toEqual({
universalIdentifier: SUPPORT_ROLE_UID,
diff --git a/packages/twenty-cli/src/app/pull/__tests__/pull-application.spec.ts b/packages/twenty-cli/src/app/pull/__tests__/pull-application.spec.ts
index 763f41d5ec7..adf9e2a029b 100644
--- a/packages/twenty-cli/src/app/pull/__tests__/pull-application.spec.ts
+++ b/packages/twenty-cli/src/app/pull/__tests__/pull-application.spec.ts
@@ -11,6 +11,7 @@ import { createHash } from 'node:crypto';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { SystemPermissionFlag } from 'twenty-shared/constants';
import { generateMessageId } from 'twenty-shared/i18n';
import { collectSourceFingerprints } from '@/app/pull/collect-source-fingerprints';
@@ -1005,6 +1006,81 @@ export default defineField({
expect(await read('src/application.config.ts')).toBe(localApplication);
});
+ it('writes permission flags with the names the app SDK exports', async () => {
+ const exported = createExport();
+ const data = requireSuccess(
+ await pull({
+ ...exported,
+ manifest: {
+ ...exported.manifest,
+ roles: [
+ {
+ universalIdentifier: OTHER_IDENTIFIER,
+ label: 'Reader',
+ permissionFlagUniversalIdentifiers: [
+ SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ SystemPermissionFlag.APPLICATIONS,
+ ],
+ },
+ ],
+ },
+ }),
+ );
+ const roleWrite = data.writes.find(
+ (write) => write.universalIdentifier === OTHER_IDENTIFIER,
+ );
+
+ expect(roleWrite).toBeDefined();
+ const role = await read(roleWrite?.relativePath ?? '');
+ expect(role).toContain('SystemPermissionFlag.USER_APPS');
+ expect(role).toContain('SystemPermissionFlag.WORKSPACE_APPS');
+ });
+
+ it('does not report a role file an older pull wrote with the former flag names', async () => {
+ const exported = createExport();
+ const exportWithRole = (label: string) => ({
+ ...exported,
+ manifest: {
+ ...exported.manifest,
+ roles: [
+ {
+ universalIdentifier: OTHER_IDENTIFIER,
+ label,
+ permissionFlagUniversalIdentifiers: [
+ SystemPermissionFlag.CONNECTED_ACCOUNTS,
+ ],
+ },
+ ],
+ },
+ });
+ const pulled = requireSuccess(await pull(exportWithRole('Reader')));
+ const rolePath =
+ pulled.writes.find(
+ (write) => write.universalIdentifier === OTHER_IDENTIFIER,
+ )?.relativePath ?? '';
+ await writeFile(
+ join(appPath, rolePath),
+ (await read(rolePath)).replace(
+ 'SystemPermissionFlag.USER_APPS',
+ 'SystemPermissionFlag.CONNECTED_ACCOUNTS',
+ ),
+ );
+ await writePullBase({
+ appPath,
+ manifest: parseAppExport({
+ value: exportWithRole('Reader'),
+ universalIdentifier: APPLICATION_IDENTIFIER,
+ }).manifest,
+ target: TARGET,
+ signal: new AbortController().signal,
+ });
+
+ const changed = requireSuccess(await pull(exportWithRole('Remote reader')));
+
+ expect(changed.overwrittenLocalChanges).toEqual([]);
+ expect(await read(rolePath)).toContain("label: 'Remote reader'");
+ });
+
it('deletes a remotely removed base entity and preserves a local-only definition', async () => {
requireSuccess(await pull());
const local = (await read(OBJECT_PATH))
diff --git a/packages/twenty-cli/src/app/pull/build-pull-entities.ts b/packages/twenty-cli/src/app/pull/build-pull-entities.ts
index e13d3c0574b..fe69c4fb2a0 100644
--- a/packages/twenty-cli/src/app/pull/build-pull-entities.ts
+++ b/packages/twenty-cli/src/app/pull/build-pull-entities.ts
@@ -6,10 +6,10 @@ import {
OBJECT_ENUM_BINDINGS,
PAGE_LAYOUT_ENUM_BINDINGS,
PAGE_LAYOUT_TAB_ENUM_BINDINGS,
- ROLE_ENUM_BINDINGS,
VIEW_ENUM_BINDINGS,
VIEW_FIELD_ENUM_BINDINGS,
WORKFLOW_ENUM_BINDINGS,
+ buildRoleEnumBindings,
type EnumBinding,
} from '@/app/pull/write-define-file';
import {
@@ -21,6 +21,7 @@ import {
import { stripGraphqlTypename } from '@/app/pull/strip-graphql-typename';
import { kebabCase } from '@/app/pull/kebab-case';
import { type Manifest } from 'twenty-shared/application';
+import { SystemPermissionFlag } from 'twenty-shared/constants';
import { fromApplicationManifestToApplicationConfig } from '@/app/pull/from-application-manifest-to-application-config';
import { fromRoleManifestToRoleConfig } from '@/app/pull/from-role-manifest-to-role-config';
import { buildPullFieldFileName } from '@/app/pull/build-pull-field-file-name';
@@ -69,13 +70,15 @@ export type SkippedPullEntity = {
reason: string;
};
-export const buildPullEntities = (
- manifest: Manifest,
- sourceFileByUniversalIdentifier: ReadonlyMap<
- string,
- ScannedSourceFile
- > = new Map(),
-): { entities: PullEntity[]; skipped: SkippedPullEntity[] } => {
+export const buildPullEntities = ({
+ manifest,
+ sourceFileByUniversalIdentifier = new Map(),
+ systemPermissionFlag = SystemPermissionFlag,
+}: {
+ manifest: Manifest;
+ sourceFileByUniversalIdentifier?: ReadonlyMap<string, ScannedSourceFile>;
+ systemPermissionFlag?: Record<string, string>;
+}): { entities: PullEntity[]; skipped: SkippedPullEntity[] } => {
const applicationUniversalIdentifier =
manifest.application.universalIdentifier;
const entities: PullEntity[] = [];
@@ -228,7 +231,7 @@ export const buildPullEntities = (
roleManifest,
applicationUniversalIdentifier,
}),
- enumBindings: ROLE_ENUM_BINDINGS,
+ enumBindings: buildRoleEnumBindings(systemPermissionFlag),
defaultFolder: 'src/roles',
fileSuffix: '.role.ts',
fileBaseName: toFileBaseName({
diff --git a/packages/twenty-cli/src/app/pull/prepare-pull-entities.ts b/packages/twenty-cli/src/app/pull/prepare-pull-entities.ts
index 45ee1a4fe07..54c9caed138 100644
--- a/packages/twenty-cli/src/app/pull/prepare-pull-entities.ts
+++ b/packages/twenty-cli/src/app/pull/prepare-pull-entities.ts
@@ -10,11 +10,13 @@ export const preparePullEntities = ({
baseManifest,
scannedFiles,
unreconciledUniversalIdentifiers,
+ systemPermissionFlag,
}: {
manifest: Manifest;
baseManifest: Manifest | null;
scannedFiles: ScannedSourceFile[];
unreconciledUniversalIdentifiers?: ReadonlySet<string>;
+ systemPermissionFlag?: Record<string, string>;
}) => {
const sourceFileByUniversalIdentifier = new Map<string, ScannedSourceFile>();
@@ -27,14 +29,17 @@ export const preparePullEntities = ({
}
}
- const { entities, skipped } = buildPullEntities(
+ const { entities, skipped } = buildPullEntities({
manifest,
sourceFileByUniversalIdentifier,
- );
+ systemPermissionFlag,
+ });
const baseEntities = buildPullBaseEntities({
entities: isDefined(baseManifest)
- ? buildPullEntities(baseManifest, sourceFileByUniversalIdentifier)
- .entities
+ ? buildPullEntities({
+ manifest: baseManifest,
+ sourceFileByUniversalIdentifier,
+ }).entities
: [],
unreconciledUniversalIdentifiers,
});
diff --git a/packages/twenty-cli/src/app/pull/pull-application.ts b/packages/twenty-cli/src/app/pull/pull-application.ts
index 1b1ac4b4b01..6e923ba7eab 100644
--- a/packages/twenty-cli/src/app/pull/pull-application.ts
+++ b/packages/twenty-cli/src/app/pull/pull-application.ts
@@ -11,6 +11,7 @@ import { preserveNestedPullEntities } from '@/app/pull/preserve-nested-pull-enti
import { reconcilePullBaseManifest } from '@/app/pull/reconcile-pull-base-manifest';
import { createPullBaseWrite } from '@/app/pull/create-pull-base-write';
import { readTargetBoundPullBase } from '@/app/pull/read-target-bound-pull-base';
+import { resolveAppSystemPermissionFlag } from '@/app/project/resolve-app-system-permission-flag';
import { type PullAppOptions, type PullAppResult } from '@/app/pull/types';
import { type ToolingResult } from '@/app/types/tooling-result.type';
import { CliError } from '@/output/cli-error';
@@ -56,6 +57,7 @@ export const pullApplication = async (
baseManifest,
scannedFiles,
unreconciledUniversalIdentifiers: unreconciledBaseIdentifiers,
+ systemPermissionFlag: resolveAppSystemPermissionFlag(appPath),
});
signal?.throwIfAborted();
diff --git a/packages/twenty-cli/src/app/pull/write-define-file.ts b/packages/twenty-cli/src/app/pull/write-define-file.ts
index 4a0c95b7ef6..a275283d59b 100644
--- a/packages/twenty-cli/src/app/pull/write-define-file.ts
+++ b/packages/twenty-cli/src/app/pull/write-define-file.ts
@@ -91,7 +91,9 @@ export const INDEX_ENUM_BINDINGS: EnumBinding[] = [
{ path: ['indexType'], symbol: 'IndexType', members: IndexType },
];
-export const ROLE_ENUM_BINDINGS: EnumBinding[] = [
+export const buildRoleEnumBindings = (
+ systemPermissionFlag: Record<string, string>,
+): EnumBinding[] => [
{
path: ['rowLevelPermissionPredicateGroups', '[]', 'logicalOperator'],
symbol: 'RowLevelPermissionPredicateGroupLogicalOperator',
@@ -105,10 +107,12 @@ export const ROLE_ENUM_BINDINGS: EnumBinding[] = [
{
path: ['permissionFlagUniversalIdentifiers', '[]'],
symbol: 'SystemPermissionFlag',
- members: SystemPermissionFlag,
+ members: systemPermissionFlag,
},
];
+export const ROLE_ENUM_BINDINGS = buildRoleEnumBindings(SystemPermissionFlag);
+
const buildAggregateOperationBinding = (path: string[]): EnumBinding => ({
path,
symbol: 'AggregateOperations',
diff --git a/packages/twenty-docs/developers/extend/apps/config/application.mdx b/packages/twenty-docs/developers/extend/apps/config/application.mdx
index feb1decd449..c71513fd1e5 100644
--- a/packages/twenty-docs/developers/extend/apps/config/application.mdx
+++ b/packages/twenty-docs/developers/extend/apps/config/application.mdx
@@ -190,7 +190,7 @@ Values are strings, in the same format as `process.env` (see [Variable types](#v
`updateMyUserApplicationVariable` saves a member's own value. It takes your app's `applicationUniversalIdentifier` and writes the value of the person behind the token: the member's own session, or your app's token when a member is behind it, such as in a front component or a logic function run for a member. Your app's token can only name your own app, and a token with nobody behind it, such as in a cron job or an install hook, is refused. An empty value removes the member's own value, so they read the default again, or an empty string for a variable without one.
-It needs no `APPLICATIONS` permission, but it needs `CONNECTED_ACCOUNTS`: on the member's role, and, when your app's token makes the call, on your app's default role too, if it declares one. If your app saves user variables, add `SystemPermissionFlag.CONNECTED_ACCOUNTS` to `permissionFlagUniversalIdentifiers` in its [role](/developers/extend/apps/config/roles).
+It needs no Workspace Apps permission, but it needs User Apps: on the member's role, and, when your app's token makes the call, on your app's default role too, if it declares one. If your app saves user variables, add `SystemPermissionFlag.USER_APPS` to `permissionFlagUniversalIdentifiers` in its [role](/developers/extend/apps/config/roles).
## Default function role
diff --git a/packages/twenty-docs/developers/extend/apps/config/roles.mdx b/packages/twenty-docs/developers/extend/apps/config/roles.mdx
index 821625eafa0..8d4c8c3c2b3 100644
--- a/packages/twenty-docs/developers/extend/apps/config/roles.mdx
+++ b/packages/twenty-docs/developers/extend/apps/config/roles.mdx
@@ -50,10 +50,20 @@ export default defineRole({
canUpdateFieldValue: false,
},
],
- permissionFlagUniversalIdentifiers: [SystemPermissionFlag.APPLICATIONS],
+ permissionFlagUniversalIdentifiers: [SystemPermissionFlag.WORKSPACE_APPS],
});
```
+<Note>
+ `SystemPermissionFlag.USER_APPS` and `SystemPermissionFlag.WORKSPACE_APPS`
+ are available from `twenty-sdk` 2.54 onward; earlier versions name them
+ `CONNECTED_ACCOUNTS` and `APPLICATIONS`. The old names are deprecated aliases
+ for the same flags, and a role keeps each flag once. Enumerating
+ `SystemPermissionFlag`, for example with `Object.keys`, still lists the old
+ names. The API also reports these flags under their old keys, for example in
+ `currentUserWorkspace.permissionFlags`.
+</Note>
+
## Row-level security
Row-level permissions require the **Organization plan or above** — see
diff --git a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
index 371873463fa..9216e501121 100644
--- a/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
+++ b/packages/twenty-docs/developers/extend/apps/layout/front-components.mdx
@@ -170,12 +170,12 @@ Declare as many as you need. Twenty's own **General** item — auto-upgrade, App
<Note>
A `USER` item renders as a tab on the app's page under **Settings > App
preferences**, where only the signed-in member sees it, and only when their
- role grants the `CONNECTED_ACCOUNTS` permission. That page is not enabled in
+ role grants the User Apps permission. That page is not enabled in
every workspace yet: where it is not, a `USER` item is persisted and synced
but nothing renders it.
</Note>
-A `USER` item runs as the member viewing it. To store something per person, declare the variable with `scope: 'USER'`: `getApplicationVariable` returns the viewing member's value, and your component saves it with `updateMyUserApplicationVariable`, which writes that member's value only and needs `SystemPermissionFlag.CONNECTED_ACCOUNTS` in your app's role, if it declares one (see [Reading and updating variables at runtime](#reading-and-updating-variables-at-runtime)). Like a `WORKSPACE` item, a `USER` item replaces the generated **Variables** form, so it should let the member set every user variable your app needs. A workspace variable holds one value shared by everyone, so one member's save would overwrite another's.
+A `USER` item runs as the member viewing it. To store something per person, declare the variable with `scope: 'USER'`: `getApplicationVariable` returns the viewing member's value, and your component saves it with `updateMyUserApplicationVariable`, which writes that member's value only and needs `SystemPermissionFlag.USER_APPS` in your app's role, if it declares one (see [Reading and updating variables at runtime](#reading-and-updating-variables-at-runtime)). Like a `WORKSPACE` item, a `USER` item replaces the generated **Variables** form, so it should let the member set every user variable your app needs. A workspace variable holds one value shared by everyone, so one member's save would overwrite another's.
<Note>
`defineSettingsFrontComponent()` is deprecated in favor of
@@ -663,8 +663,8 @@ Notes:
- Your component's token is bound to your own application. `updateOneApplicationVariable` targets it, so `applicationId` is optional and naming another application is refused. Reading the `applicationVariables` of another application is refused the same way, and an application belonging to another workspace reads as not found.
- The key must be one your app declares in [`defineApplication()`](/developers/extend/apps/config/application). Writing a key that is not declared is a not found.
- Secret variables read back masked, never as the stored value. Writing them works normally.
-- Reading a variable's `value`, and writing it, need the `APPLICATIONS` settings permission on both your app's role and the signed-in person's role, since the component's token is the intersection of the two. Add `SystemPermissionFlag.APPLICATIONS` to `permissionFlagUniversalIdentifiers` in your [application role](/developers/extend/apps/config/roles).
-- A user variable (`scope: 'USER'`) is injected with the viewing member's value, unless it is secret. `updateOneApplicationVariable` refuses it: save it with `updateMyUserApplicationVariable`, as `saveMyLanguage` does above. It writes the viewing member's value only and refuses naming another application. It needs no `APPLICATIONS` permission, but it needs the `CONNECTED_ACCOUNTS` permission on the viewing member's role and on your app's role, if it declares one: add `SystemPermissionFlag.CONNECTED_ACCOUNTS` to `permissionFlagUniversalIdentifiers` in your [application role](/developers/extend/apps/config/roles). See [Workspace and user variables](/developers/extend/apps/config/application#workspace-and-user-variables).
+- Reading a variable's `value`, and writing it, need the Workspace Apps settings permission on both your app's role and the signed-in person's role, since the component's token is the intersection of the two. Add `SystemPermissionFlag.WORKSPACE_APPS` to `permissionFlagUniversalIdentifiers` in your [application role](/developers/extend/apps/config/roles).
+- A user variable (`scope: 'USER'`) is injected with the viewing member's value, unless it is secret. `updateOneApplicationVariable` refuses it: save it with `updateMyUserApplicationVariable`, as `saveMyLanguage` does above. It writes the viewing member's value only and refuses naming another application. It needs no Workspace Apps permission, but it needs the User Apps permission on the viewing member's role and on your app's role, if it declares one: add `SystemPermissionFlag.USER_APPS` to `permissionFlagUniversalIdentifiers` in your [application role](/developers/extend/apps/config/roles). See [Workspace and user variables](/developers/extend/apps/config/application#workspace-and-user-variables).
### System variables
diff --git a/packages/twenty-docs/developers/extend/apps/logic/connections.mdx b/packages/twenty-docs/developers/extend/apps/logic/connections.mdx
index 76402d289c2..bcb25765ab9 100644
--- a/packages/twenty-docs/developers/extend/apps/logic/connections.mdx
+++ b/packages/twenty-docs/developers/extend/apps/logic/connections.mdx
@@ -508,7 +508,7 @@ Each connection has one of two scopes:
The provider's `scope` decides which one its new connections get:
- `scope: 'WORKSPACE'` (the default) — the app works with connections shared with the workspace. **Add connection** in the app's workspace settings creates a workspace-shared connection.
-- `scope: 'USER'` — each member connects their own account, creating personal connections. Members add, reconnect and remove them from the app's page under **Settings > User > Apps preferences**, which requires the `CONNECTED_ACCOUNTS` (User Apps) permission. The app's workspace settings have no **Add connection** button for a `USER` provider.
+- `scope: 'USER'` — each member connects their own account, creating personal connections. Members add, reconnect and remove them from the app's page under **Settings > User > Apps preferences**, which requires the User Apps permission. The app's workspace settings have no **Add connection** button for a `USER` provider.
<Note>
**Apps preferences** is not enabled in every workspace yet: where it is not,
@@ -520,7 +520,7 @@ A provider has exactly one scope. If your app needs both a shared credential and
A connection always has its provider's scope, and a provider's scope is part of its identity: a later version cannot change the `scope` of an existing provider, and the upgrade is refused if it tries. To move a service from one scope to the other, declare a new provider with a new `universalIdentifier` and drop the old one. Upgrading then deletes the old provider and every connection made with it through the regular disconnect path (`onDisconnectLogicFunction`, token revocation, channel cleanup), and members connect again through the new provider.
-Adding or reconnecting a **Just for me** connection requires `CONNECTED_ACCOUNTS` permission, and adding or reconnecting a **Workspace shared** one requires `APPLICATIONS` permission.
+Adding or reconnecting a **Just for me** connection requires the User Apps permission, and adding or reconnecting a **Workspace shared** one requires the Workspace Apps permission.
Use the right connection for each handler:
diff --git a/packages/twenty-sdk/CHANGELOG.md b/packages/twenty-sdk/CHANGELOG.md
index 691986a3692..847d2d6f8af 100644
--- a/packages/twenty-sdk/CHANGELOG.md
+++ b/packages/twenty-sdk/CHANGELOG.md
@@ -93,10 +93,14 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
const objectMetadata = useSelectedObjectMetadata();
```
+- **`SystemPermissionFlag.USER_APPS` and `SystemPermissionFlag.WORKSPACE_APPS` in `twenty-sdk/define`.** The SDK names of the User Apps and Workspace Apps permission flags, with the same universal identifiers as `CONNECTED_ACCOUNTS` and `APPLICATIONS`. They are left out of `Object.keys`, `Object.values` and `Object.entries`, which list the same 26 names as before, so code that enumerates or filters the flags behaves as before. Only the SDK names change: the API keeps reporting these flags as `CONNECTED_ACCOUNTS` and `APPLICATIONS`, for example in `currentUserWorkspace.permissionFlags` and in command menu expressions.
+
### Deprecated
- **`enqueueJob` in `twenty-sdk/logic-function`.** Use `enqueueJobs` with a one-element `payloads` list instead. `enqueueJob` keeps working for now and will be removed in a future major version.
+- **`SystemPermissionFlag.CONNECTED_ACCOUNTS` and `SystemPermissionFlag.APPLICATIONS` in `twenty-sdk/define`.** Use `USER_APPS` and `WORKSPACE_APPS` instead. The old names keep working and stay the ones `Object.keys` and `Object.entries` return. In logic functions and front components the new names resolve only when bundled with the `twenty` CLI 2.54 or later.
+
### Changed
- **`sendInboxMessage` runs like the default API clients.** It now sends through `MetadataApiClient`, so in a logic function it acts as the person who triggered the run, who then needs the AI permission, and as your application only when nobody did; it used to always use the application's access. A GraphQL error now rejects with the server's message instead of `sendInboxMessage() failed: ...`. Its input and result are unchanged.
@@ -114,6 +118,12 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
`twenty build` now also emits a warning when `twenty-client-sdk` is still listed under `dependencies`.
+- **`defineRole` and `defineApplicationRole` keep each permission flag once in `permissionFlagUniversalIdentifiers`.** A flag listed twice, for example under its deprecated and new `SystemPermissionFlag` names, is sent once. Syncing a role with a repeated flag used to fail on the server.
+
+- **`twenty app pull` names permission flags after the app's installed `twenty-sdk`.** Role files get `SystemPermissionFlag.USER_APPS` and `SystemPermissionFlag.WORKSPACE_APPS` with `twenty-sdk` 2.54 or later, and `CONNECTED_ACCOUNTS` and `APPLICATIONS` with earlier versions. A flag the installed `SystemPermissionFlag` lacks is written as its universal identifier string.
+
+- **`twenty app build` and `twenty app dev` keep non-enumerable `twenty-sdk/define` constants in logic function and front component bundles,** so `SystemPermissionFlag.USER_APPS` and `WORKSPACE_APPS` resolve at runtime. Agent role errors also name system permission flags after the app's installed `twenty-sdk`.
+
## [2.8.0]
### Breaking Changes
diff --git a/packages/twenty-sdk/src/sdk/define/index.ts b/packages/twenty-sdk/src/sdk/define/index.ts
index d1e5bb76176..96b42f4a9bf 100644
--- a/packages/twenty-sdk/src/sdk/define/index.ts
+++ b/packages/twenty-sdk/src/sdk/define/index.ts
@@ -190,7 +190,7 @@ export {
RowLevelPermissionPredicateGroupLogicalOperator,
RowLevelPermissionPredicateOperand,
} from 'twenty-shared/types';
-export { SystemPermissionFlag } from 'twenty-shared/constants';
+export { SystemPermissionFlag } from '@/sdk/define/roles/system-permission-flag.constant';
export { defineSkill } from '@/sdk/define/skills/define-skill';
diff --git a/packages/twenty-sdk/src/sdk/define/roles/__tests__/define-role.spec.ts b/packages/twenty-sdk/src/sdk/define/roles/__tests__/define-role.spec.ts
index e080709d13d..131db0a245e 100644
--- a/packages/twenty-sdk/src/sdk/define/roles/__tests__/define-role.spec.ts
+++ b/packages/twenty-sdk/src/sdk/define/roles/__tests__/define-role.spec.ts
@@ -1,3 +1,5 @@
+import { SystemPermissionFlag as SharedSystemPermissionFlag } from 'twenty-shared/constants';
+
import { SystemPermissionFlag, defineRole } from '@/sdk/define';
describe('defineRole', () => {
@@ -47,6 +49,54 @@ describe('defineRole', () => {
expect(result.config?.permissionFlagUniversalIdentifiers).toHaveLength(2);
});
+ it('should list a permission flag once when it is listed twice', () => {
+ const result = defineRole({
+ ...validConfig,
+ permissionFlagUniversalIdentifiers: [
+ SystemPermissionFlag.UPLOAD_FILE,
+ SystemPermissionFlag.UPLOAD_FILE,
+ ],
+ });
+
+ expect(result.success).toBe(true);
+ expect(result.config.permissionFlagUniversalIdentifiers).toEqual([
+ SystemPermissionFlag.UPLOAD_FILE,
+ ]);
+ });
+
+ it.each([
+ ['CONNECTED_ACCOUNTS', 'USER_APPS'],
+ ['APPLICATIONS', 'WORKSPACE_APPS'],
+ ] as const)(
+ 'should list a flag once when deprecated %s is listed with %s',
+ (deprecatedName, replacementName) => {
+ const result = defineRole({
+ ...validConfig,
+ permissionFlagUniversalIdentifiers: [
+ SystemPermissionFlag[replacementName],
+ SystemPermissionFlag[deprecatedName],
+ ],
+ });
+
+ expect(result.success).toBe(true);
+ expect(result.config.permissionFlagUniversalIdentifiers).toEqual([
+ SystemPermissionFlag[replacementName],
+ ]);
+ },
+ );
+
+ it('should keep a role listing every SystemPermissionFlag value valid', () => {
+ const result = defineRole({
+ ...validConfig,
+ permissionFlagUniversalIdentifiers: Object.values(SystemPermissionFlag),
+ });
+
+ expect(result.success).toBe(true);
+ expect(
+ [...(result.config.permissionFlagUniversalIdentifiers ?? [])].sort(),
+ ).toEqual(Object.values(SharedSystemPermissionFlag).sort());
+ });
+
it('should return error when universalIdentifier is missing', () => {
const config = {
label: 'App User',
diff --git a/packages/twenty-sdk/src/sdk/define/roles/__tests__/system-permission-flag.constant.spec.ts b/packages/twenty-sdk/src/sdk/define/roles/__tests__/system-permission-flag.constant.spec.ts
new file mode 100644
index 00000000000..0fa8fd9414b
--- /dev/null
+++ b/packages/twenty-sdk/src/sdk/define/roles/__tests__/system-permission-flag.constant.spec.ts
@@ -0,0 +1,40 @@
+import { SystemPermissionFlag as SharedSystemPermissionFlag } from 'twenty-shared/constants';
+
+import { SystemPermissionFlag } from '@/sdk/define';
+
+describe('SystemPermissionFlag', () => {
+ it('should resolve the new and deprecated names to the same universal identifiers', () => {
+ expect(SystemPermissionFlag.USER_APPS).toBe(
+ 'e5f63b2d-5369-5df6-8f32-a8bd9e79e653',
+ );
+ expect(SystemPermissionFlag.CONNECTED_ACCOUNTS).toBe(
+ SystemPermissionFlag.USER_APPS,
+ );
+ expect(SystemPermissionFlag.WORKSPACE_APPS).toBe(
+ '9faa55f7-2606-566b-9e1d-aefbedbd0136',
+ );
+ expect(SystemPermissionFlag.APPLICATIONS).toBe(
+ SystemPermissionFlag.WORKSPACE_APPS,
+ );
+ });
+
+ it('should enumerate exactly the shared flags, as before the new names', () => {
+ expect(Object.entries(SystemPermissionFlag)).toEqual(
+ Object.entries(SharedSystemPermissionFlag),
+ );
+ });
+
+ it('should still exclude a flag filtered out by its deprecated name', () => {
+ const allButUserApps = Object.entries(SystemPermissionFlag)
+ .filter(([name]) => name !== 'CONNECTED_ACCOUNTS')
+ .map(([, universalIdentifier]) => universalIdentifier);
+
+ expect(allButUserApps).not.toContain(SystemPermissionFlag.USER_APPS);
+ });
+
+ it('should list the new names first among all own property names', () => {
+ expect(
+ Object.getOwnPropertyNames(SystemPermissionFlag).slice(0, 2),
+ ).toEqual(['USER_APPS', 'WORKSPACE_APPS']);
+ });
+});
diff --git a/packages/twenty-sdk/src/sdk/define/roles/define-role.ts b/packages/twenty-sdk/src/sdk/define/roles/define-role.ts
index 670915c0f8e..a91656a49a1 100644
--- a/packages/twenty-sdk/src/sdk/define/roles/define-role.ts
+++ b/packages/twenty-sdk/src/sdk/define/roles/define-role.ts
@@ -1,7 +1,23 @@
+import { isDefined } from 'twenty-shared/utils';
+
import { createValidationResult } from '@/sdk/define/common/utils/create-validation-result';
import { type DefineEntity } from '@/sdk/define/common/types/define-entity.type';
import { type RoleConfig } from '@/sdk/define/roles/role-config';
+const keepEachPermissionFlagOnce = <
+ TConfig extends Pick<RoleConfig, 'permissionFlagUniversalIdentifiers'>,
+>(
+ config: TConfig,
+): TConfig =>
+ isDefined(config.permissionFlagUniversalIdentifiers)
+ ? {
+ ...config,
+ permissionFlagUniversalIdentifiers: [
+ ...new Set(config.permissionFlagUniversalIdentifiers),
+ ],
+ }
+ : config;
+
export const defineRole: DefineEntity<RoleConfig> = (config) => {
const errors = [];
@@ -112,5 +128,8 @@ export const defineRole: DefineEntity<RoleConfig> = (config) => {
}
}
- return createValidationResult({ config, errors });
+ return createValidationResult({
+ config: keepEachPermissionFlagOnce(config),
+ errors,
+ });
};
diff --git a/packages/twenty-sdk/src/sdk/define/roles/system-permission-flag.constant.ts b/packages/twenty-sdk/src/sdk/define/roles/system-permission-flag.constant.ts
new file mode 100644
index 00000000000..c4b49795ed4
--- /dev/null
+++ b/packages/twenty-sdk/src/sdk/define/roles/system-permission-flag.constant.ts
@@ -0,0 +1,27 @@
+import { SystemPermissionFlag as SharedSystemPermissionFlag } from 'twenty-shared/constants';
+
+type SdkSystemPermissionFlag = Omit<
+ typeof SharedSystemPermissionFlag,
+ 'CONNECTED_ACCOUNTS' | 'APPLICATIONS'
+> & {
+ readonly USER_APPS: typeof SharedSystemPermissionFlag.CONNECTED_ACCOUNTS;
+ readonly WORKSPACE_APPS: typeof SharedSystemPermissionFlag.APPLICATIONS;
+ /** @deprecated Use `SystemPermissionFlag.USER_APPS` instead. */
+ readonly CONNECTED_ACCOUNTS: typeof SharedSystemPermissionFlag.CONNECTED_ACCOUNTS;
+ /** @deprecated Use `SystemPermissionFlag.WORKSPACE_APPS` instead. */
+ readonly APPLICATIONS: typeof SharedSystemPermissionFlag.APPLICATIONS;
+};
+
+const sdkSystemPermissionFlag: SdkSystemPermissionFlag = {
+ USER_APPS: SharedSystemPermissionFlag.CONNECTED_ACCOUNTS,
+ WORKSPACE_APPS: SharedSystemPermissionFlag.APPLICATIONS,
+ ...SharedSystemPermissionFlag,
+};
+
+export const SystemPermissionFlag = Object.defineProperties(
+ sdkSystemPermissionFlag,
+ {
+ USER_APPS: { enumerable: false },
+ WORKSPACE_APPS: { enumerable: false },
+ },
+);