snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s

This commit is contained in:
upstream-mirror
2026-09-17 23:28:13 +05:00
commit e7da97194a
32688 changed files with 4208681 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { NORMALIZATION_RULES } from '../../constants/normalization-rules.constant';
import { evaluateRules } from '../evaluate-rules.util';
describe('evaluateRules', () => {
it('reports every rule that fired and applies them in sequence', () => {
const result = evaluateRules({
rules: NORMALIZATION_RULES,
sourceText: 'Replace `<path>` with your path',
translationText: '\\u62db `&lt;path&gt;`',
});
expect(result.fixedText).toBe('招 `<path>`');
expect(result.ruleNames).toEqual([
'escaped-unicode',
'escaped-inline-code-tags',
]);
});
it('skips source-filtered rules when the source string is unknown', () => {
const result = evaluateRules({
rules: NORMALIZATION_RULES,
sourceText: undefined,
translationText: 'Remplacez `&lt;path&gt;` par votre chemin',
});
expect(result.ruleNames).toEqual([]);
});
it('skips source-filtered rules when the source does not match', () => {
const result = evaluateRules({
rules: NORMALIZATION_RULES,
sourceText: 'Escape a literal &lt; in prose',
translationText: 'Échappez un &lt; littéral dans le texte',
});
expect(result.ruleNames).toEqual([]);
});
it('returns the translation untouched when no rule fires', () => {
const result = evaluateRules({
rules: NORMALIZATION_RULES,
sourceText: 'Replace `<path>` with your path',
translationText: 'Remplacez `<path>` par votre chemin',
});
expect(result.fixedText).toBe('Remplacez `<path>` par votre chemin');
expect(result.ruleNames).toEqual([]);
});
});

View File

@@ -0,0 +1,67 @@
import { CrowdinApiError } from '../../errors/crowdin-api.error';
import { isTranslationAlreadyPresentError } from '../is-translation-already-present-error.util';
const buildError = (body: string) => new CrowdinApiError(400, body);
const buildDetailError = (detail: { code: string; message: string }) =>
buildError(
JSON.stringify({
errors: [{ error: { key: 'translation', errors: [detail] } }],
}),
);
describe('isTranslationAlreadyPresentError', () => {
it('recognises the identical-translation error code', () => {
expect(
isTranslationAlreadyPresentError(
buildDetailError({
code: 'identicalTranslation',
message: 'Identical translation already saved',
}),
),
).toBe(true);
});
it('recognises the duplicate-translation validation error', () => {
expect(
isTranslationAlreadyPresentError(
buildDetailError({
code: 'validationError',
message:
'Duplicate translation. Please vote or approve the original.',
}),
),
).toBe(true);
});
it('does not swallow an unrelated validation error', () => {
expect(
isTranslationAlreadyPresentError(
buildDetailError({
code: 'validationError',
message: 'Translation is too long',
}),
),
).toBe(false);
});
it('does not treat another failure as present because of its wording', () => {
expect(
isTranslationAlreadyPresentError(
buildDetailError({
code: 'notFound',
message: 'String is identical to a deleted one',
}),
),
).toBe(false);
});
it('rejects a non-JSON body and any non-Crowdin error', () => {
expect(
isTranslationAlreadyPresentError(buildError('<html>502</html>')),
).toBe(false);
expect(isTranslationAlreadyPresentError(new Error('identical'))).toBe(
false,
);
});
});

View File

@@ -0,0 +1,51 @@
import { mapWithConcurrency } from '../map-with-concurrency.util';
describe('mapWithConcurrency', () => {
it('keeps results in input order regardless of completion order', async () => {
const results = await mapWithConcurrency({
items: [30, 10, 20],
limit: 3,
handler: (delay) =>
new Promise<number>((resolve) =>
setTimeout(() => resolve(delay), delay),
),
});
expect(results).toEqual([30, 10, 20]);
});
it('never runs more than `limit` handlers at once', async () => {
let running = 0;
let peak = 0;
await mapWithConcurrency({
items: Array.from({ length: 20 }, (_, index) => index),
limit: 3,
handler: async (item) => {
running++;
peak = Math.max(peak, running);
await new Promise((resolve) => setTimeout(resolve, 1));
running--;
return item;
},
});
expect(peak).toBe(3);
});
it('rejects a limit that would leave every item unhandled', async () => {
await expect(
mapWithConcurrency({ items: [1], limit: 0, handler: jest.fn() }),
).rejects.toThrow('at least 1');
});
it('returns an empty array without spawning workers', async () => {
const handler = jest.fn();
expect(await mapWithConcurrency({ items: [], limit: 5, handler })).toEqual(
[],
);
expect(handler).not.toHaveBeenCalled();
});
});

View File

@@ -0,0 +1,25 @@
import { type CrowdinContext } from '../types/crowdin-context.type';
import { crowdinRequest } from './crowdin-request.util';
import { isTranslationAlreadyPresentError } from './is-translation-already-present-error.util';
export async function addTranslation(
context: CrowdinContext,
{
stringId,
languageId,
text,
}: { stringId: number; languageId: string; text: string },
): Promise<void> {
try {
await crowdinRequest(
context,
`/projects/${context.projectId}/translations`,
{
method: 'POST',
body: JSON.stringify({ stringId, languageId, text }),
},
);
} catch (error) {
if (!isTranslationAlreadyPresentError(error)) throw error;
}
}

View File

@@ -0,0 +1,31 @@
import { CrowdinApiError } from '../errors/crowdin-api.error';
import { type CrowdinContext } from '../types/crowdin-context.type';
const CROWDIN_BASE_URL = 'https://twenty.api.crowdin.com/api/v2';
export async function crowdinRequest<T>(
{ token }: CrowdinContext,
endpoint: string,
options: RequestInit = {},
): Promise<T | undefined> {
const response = await fetch(`${CROWDIN_BASE_URL}${endpoint}`, {
...options,
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
...options.headers,
},
});
const body = await response.text();
if (!response.ok) {
if (response.status === 404) return undefined;
throw new CrowdinApiError(response.status, body);
}
if (!body) return undefined;
return JSON.parse(body) as T;
}

View File

@@ -0,0 +1,13 @@
import { type CrowdinContext } from '../types/crowdin-context.type';
import { crowdinRequest } from './crowdin-request.util';
export async function deleteTranslation(
context: CrowdinContext,
{ translationId }: { translationId: number },
): Promise<void> {
await crowdinRequest(
context,
`/projects/${context.projectId}/translations/${translationId}`,
{ method: 'DELETE' },
);
}

View File

@@ -0,0 +1,29 @@
import { type NormalizationRule } from '../types/normalization-rule.type';
export function evaluateRules({
rules,
sourceText,
translationText,
}: {
rules: NormalizationRule[];
sourceText: string | undefined;
translationText: string;
}): { fixedText: string; ruleNames: string[] } {
return rules.reduce<{ fixedText: string; ruleNames: string[] }>(
(accumulator, rule) => {
const isFilteredOut =
rule.sourceFilter !== undefined &&
(sourceText === undefined || !rule.sourceFilter(sourceText));
if (isFilteredOut || !rule.detect(accumulator.fixedText, sourceText)) {
return accumulator;
}
return {
fixedText: rule.fix(accumulator.fixedText, sourceText),
ruleNames: [...accumulator.ruleNames, rule.name],
};
},
{ fixedText: translationText, ruleNames: [] },
);
}

View File

@@ -0,0 +1,31 @@
import { type CrowdinContext } from '../types/crowdin-context.type';
import { crowdinRequest } from './crowdin-request.util';
const PAGE_SIZE = 500;
export async function fetchAllPages<TItem>(
context: CrowdinContext,
buildEndpoint: (pagination: string) => string,
): Promise<TItem[]> {
const items: TItem[] = [];
let offset = 0;
while (true) {
type PagedResponse = { data: Array<{ data: TItem }> };
const response = await crowdinRequest<PagedResponse>(
context,
buildEndpoint(`limit=${PAGE_SIZE}&offset=${offset}`),
);
if (!response || response.data.length === 0) break;
items.push(...response.data.map((item) => item.data));
if (response.data.length < PAGE_SIZE) break;
offset += PAGE_SIZE;
}
return items;
}

View File

@@ -0,0 +1,47 @@
import { type CrowdinContext } from '../types/crowdin-context.type';
import { type CrowdinTranslation } from '../types/crowdin-translation.type';
import { fetchAllPages } from './fetch-all-pages.util';
const MAX_STRING_IDS_PER_REQUEST = 50;
function chunkStringIds(stringIds: number[]): number[][] {
const batches: number[][] = [];
for (
let index = 0;
index < stringIds.length;
index += MAX_STRING_IDS_PER_REQUEST
) {
batches.push(stringIds.slice(index, index + MAX_STRING_IDS_PER_REQUEST));
}
return batches;
}
export async function fetchLanguageTranslations(
context: CrowdinContext,
{ languageId, stringIds }: { languageId: string; stringIds?: number[] },
): Promise<CrowdinTranslation[]> {
const stringIdBatches = stringIds ? chunkStringIds(stringIds) : [undefined];
const translations: Array<Partial<CrowdinTranslation>> = [];
for (const batch of stringIdBatches) {
const stringIdsFilter = batch ? `&stringIds=${batch.join(',')}` : '';
translations.push(
...(await fetchAllPages<Partial<CrowdinTranslation>>(
context,
(pagination) =>
`/projects/${context.projectId}/languages/${languageId}/translations?${pagination}${stringIdsFilter}`,
)),
);
}
return translations.filter(
(translation): translation is CrowdinTranslation =>
typeof translation.stringId === 'number' &&
typeof translation.translationId === 'number' &&
typeof translation.text === 'string',
);
}

View File

@@ -0,0 +1,26 @@
import { type CrowdinContext } from '../types/crowdin-context.type';
import { fetchAllPages } from './fetch-all-pages.util';
export async function fetchSourceStringsById(
context: CrowdinContext,
): Promise<Map<number, string>> {
type SourceString = {
id?: number;
text?: string | Record<string, string>;
};
const sourceStrings = await fetchAllPages<SourceString>(
context,
(pagination) => `/projects/${context.projectId}/strings?${pagination}`,
);
return new Map(
sourceStrings
.filter(
(sourceString): sourceString is { id: number; text: string } =>
typeof sourceString.id === 'number' &&
typeof sourceString.text === 'string',
)
.map((sourceString) => [sourceString.id, sourceString.text]),
);
}

View File

@@ -0,0 +1,15 @@
import { type CrowdinContext } from '../types/crowdin-context.type';
import { crowdinRequest } from './crowdin-request.util';
export async function fetchTargetLanguageIds(
context: CrowdinContext,
): Promise<string[]> {
type ProjectResponse = { data: { targetLanguageIds: string[] } };
const response = await crowdinRequest<ProjectResponse>(
context,
`/projects/${context.projectId}`,
);
return response?.data.targetLanguageIds ?? [];
}

View File

@@ -0,0 +1,11 @@
export function getCrowdinTokenOrThrow(): string {
const token = process.env.CROWDIN_PERSONAL_TOKEN;
if (!token) {
throw new Error(
'CROWDIN_PERSONAL_TOKEN environment variable not set. Get your token from: https://twenty.crowdin.com/u/settings#api-key',
);
}
return token;
}

View File

@@ -0,0 +1,33 @@
import { CrowdinApiError } from '../errors/crowdin-api.error';
const IDENTICAL_TRANSLATION_CODE = 'identicalTranslation';
const VALIDATION_ERROR_CODE = 'validationError';
// validationError also covers unrelated refusals, so the wording has to narrow
// it down to the one that means the text we wanted is already there.
const DUPLICATE_TRANSLATION_REGEX = /duplicate translation/i;
type CrowdinErrorBody = {
errors?: Array<{
error?: { errors?: Array<{ code?: string; message?: string }> };
}>;
};
export function isTranslationAlreadyPresentError(error: unknown): boolean {
if (!(error instanceof CrowdinApiError)) return false;
try {
const body = JSON.parse(error.body) as CrowdinErrorBody;
return (body.errors ?? []).some((entry) =>
(entry.error?.errors ?? []).some(
(detail) =>
detail.code === IDENTICAL_TRANSLATION_CODE ||
(detail.code === VALIDATION_ERROR_CODE &&
DUPLICATE_TRANSLATION_REGEX.test(detail.message ?? '')),
),
);
} catch {
return false;
}
}

View File

@@ -0,0 +1,32 @@
export async function mapWithConcurrency<TItem, TResult>({
items,
limit,
handler,
}: {
items: TItem[];
limit: number;
handler: (item: TItem) => Promise<TResult>;
}): Promise<TResult[]> {
if (limit < 1) {
throw new Error(
`mapWithConcurrency needs a limit of at least 1, got ${limit}`,
);
}
const results: TResult[] = Array.from({ length: items.length });
let cursor = 0;
const worker = async () => {
while (cursor < items.length) {
const index = cursor++;
results[index] = await handler(items[index]);
}
};
await Promise.all(
Array.from({ length: Math.min(limit, items.length) }, worker),
);
return results;
}