gtx-cli 2.0.5 → 2.0.6-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/api/checkFileTranslations.d.ts +6 -0
  2. package/dist/api/checkFileTranslations.js +49 -58
  3. package/dist/api/downloadFile.d.ts +8 -1
  4. package/dist/api/downloadFile.js +20 -28
  5. package/dist/api/downloadFileBatch.d.ts +9 -9
  6. package/dist/api/downloadFileBatch.js +45 -52
  7. package/dist/api/fetchTranslations.d.ts +2 -5
  8. package/dist/api/fetchTranslations.js +7 -19
  9. package/dist/api/sendFiles.d.ts +16 -19
  10. package/dist/api/sendFiles.js +9 -31
  11. package/dist/api/sendUpdates.d.ts +6 -6
  12. package/dist/api/sendUpdates.js +10 -33
  13. package/dist/api/waitForUpdates.d.ts +1 -3
  14. package/dist/api/waitForUpdates.js +39 -45
  15. package/dist/cli/base.d.ts +3 -0
  16. package/dist/cli/base.js +13 -0
  17. package/dist/cli/react.js +13 -11
  18. package/dist/config/generateSettings.js +8 -0
  19. package/dist/config/utils.d.ts +1 -1
  20. package/dist/config/utils.js +1 -1
  21. package/dist/formats/files/translate.js +2 -2
  22. package/dist/formats/gt/save.d.ts +1 -1
  23. package/dist/react/jsx/utils/parseJsx.d.ts +2 -2
  24. package/dist/react/jsx/utils/parseJsx.js +13 -10
  25. package/dist/react/parse/createInlineUpdates.d.ts +1 -0
  26. package/dist/react/parse/createInlineUpdates.js +3 -2
  27. package/dist/translation/parse.d.ts +1 -0
  28. package/dist/translation/parse.js +4 -2
  29. package/dist/translation/stage.js +12 -1
  30. package/dist/translation/translate.js +2 -2
  31. package/dist/translation/validate.js +9 -2
  32. package/dist/types/data.d.ts +1 -2
  33. package/dist/types/index.d.ts +3 -13
  34. package/dist/utils/flattenJsonFiles.d.ts +1 -1
  35. package/dist/utils/gt.d.ts +2 -0
  36. package/dist/utils/gt.js +2 -0
  37. package/dist/utils/localizeStaticUrls.d.ts +1 -1
  38. package/package.json +6 -6
  39. package/dist/types/api.d.ts +0 -6
  40. package/dist/types/api.js +0 -1
@@ -1,3 +1,9 @@
1
+ export type CheckFileTranslationData = {
2
+ [key: string]: {
3
+ versionId: string;
4
+ fileName: string;
5
+ };
6
+ };
1
7
  /**
2
8
  * Checks the status of translations for a given version ID
3
9
  * @param apiKey - The API key for the General Translation API
@@ -3,7 +3,7 @@ import { createOraSpinner, logError } from '../console/logging.js';
3
3
  import { getLocaleProperties } from 'generaltranslation';
4
4
  import { downloadFile } from './downloadFile.js';
5
5
  import { downloadFileBatch } from './downloadFileBatch.js';
6
- import { getAuthHeaders } from '../utils/headers.js';
6
+ import { gt } from '../utils/gt.js';
7
7
  /**
8
8
  * Checks the status of translations for a given version ID
9
9
  * @param apiKey - The API key for the General Translation API
@@ -166,74 +166,65 @@ async function checkTranslationDeployment(baseUrl, projectId, apiKey, fileQueryD
166
166
  if (currentQueryData.length === 0) {
167
167
  return true;
168
168
  }
169
- const response = await fetch(`${baseUrl}/v1/project/translations/files/retrieve`, {
170
- method: 'POST',
171
- headers: {
172
- 'Content-Type': 'application/json',
173
- ...getAuthHeaders(projectId, apiKey),
174
- },
175
- body: JSON.stringify({ files: currentQueryData }),
176
- });
177
- if (response.ok) {
178
- const responseData = await response.json();
179
- const translations = responseData.translations || [];
180
- // Filter for ready translations
181
- const readyTranslations = translations.filter((translation) => translation.isReady && translation.fileName);
182
- if (readyTranslations.length > 0) {
183
- // Prepare batch download data
184
- const batchFiles = readyTranslations.map((translation) => {
185
- const locale = translation.locale;
186
- const fileName = translation.fileName;
187
- const translationId = translation.id;
188
- const outputPath = resolveOutputPath(fileName, locale);
189
- return {
190
- translationId,
191
- outputPath,
192
- fileLocale: `${fileName}:${locale}`,
193
- };
194
- });
195
- // Use batch download if there are multiple files
196
- if (batchFiles.length > 1) {
197
- const batchResult = await downloadFileBatch(baseUrl, projectId, apiKey, batchFiles.map(({ translationId, outputPath }) => ({
198
- translationId,
199
- outputPath,
200
- })));
201
- // Process results
202
- batchFiles.forEach((file) => {
203
- const { translationId, fileLocale } = file;
204
- if (batchResult.successful.includes(translationId)) {
205
- downloadStatus.downloaded.add(fileLocale);
206
- }
207
- else if (batchResult.failed.includes(translationId)) {
208
- downloadStatus.failed.add(fileLocale);
209
- }
210
- });
211
- }
212
- else if (batchFiles.length === 1) {
213
- // For a single file, use the original downloadFile method
214
- const file = batchFiles[0];
215
- const result = await downloadFile(baseUrl, projectId, apiKey, file.translationId, file.outputPath);
216
- if (result) {
217
- downloadStatus.downloaded.add(file.fileLocale);
169
+ // Check for translations
170
+ const responseData = await gt.checkFileTranslations(currentQueryData);
171
+ const translations = responseData.translations || [];
172
+ // Filter for ready translations
173
+ const readyTranslations = translations.filter((translation) => translation.isReady && translation.fileName);
174
+ if (readyTranslations.length > 0) {
175
+ // Prepare batch download data
176
+ const batchFiles = readyTranslations.map((translation) => {
177
+ const locale = translation.locale;
178
+ const fileName = translation.fileName;
179
+ const translationId = translation.id;
180
+ const outputPath = resolveOutputPath(fileName, locale);
181
+ return {
182
+ translationId,
183
+ outputPath,
184
+ fileLocale: `${fileName}:${locale}`,
185
+ };
186
+ });
187
+ // Use batch download if there are multiple files
188
+ if (batchFiles.length > 1) {
189
+ const batchResult = await downloadFileBatch(batchFiles.map(({ translationId, outputPath }) => ({
190
+ translationId,
191
+ outputPath,
192
+ })));
193
+ // Process results
194
+ batchFiles.forEach((file) => {
195
+ const { translationId, fileLocale } = file;
196
+ if (batchResult.successful.includes(translationId)) {
197
+ downloadStatus.downloaded.add(fileLocale);
218
198
  }
219
- else {
220
- downloadStatus.failed.add(file.fileLocale);
199
+ else if (batchResult.failed.includes(translationId)) {
200
+ downloadStatus.failed.add(fileLocale);
221
201
  }
202
+ });
203
+ }
204
+ else if (batchFiles.length === 1) {
205
+ // For a single file, use the original downloadFile method
206
+ const file = batchFiles[0];
207
+ const result = await downloadFile(file.translationId, file.outputPath);
208
+ if (result) {
209
+ downloadStatus.downloaded.add(file.fileLocale);
210
+ }
211
+ else {
212
+ downloadStatus.failed.add(file.fileLocale);
222
213
  }
223
214
  }
224
- // Force a refresh of the spinner display
225
- const statusText = generateStatusSuffixText(downloadStatus, fileQueryData);
226
- // Clear and reapply the suffix to force a refresh
227
- spinner.text = statusText;
228
215
  }
216
+ // Force a refresh of the spinner display
217
+ const statusText = generateStatusSuffixText(downloadStatus, fileQueryData);
218
+ // Clear and reapply the suffix to force a refresh
219
+ spinner.text = statusText;
220
+ // If all files have been downloaded, we're done
229
221
  if (downloadStatus.downloaded.size + downloadStatus.failed.size ===
230
222
  fileQueryData.length) {
231
223
  return true;
232
224
  }
233
- return false;
234
225
  }
235
226
  catch (error) {
236
227
  logError(chalk.red('Error checking translation status: ') + error);
237
- return false;
238
228
  }
229
+ return false;
239
230
  }
@@ -1 +1,8 @@
1
- export declare function downloadFile(baseUrl: string, projectId: string, apiKey: string, translationId: string, outputPath: string, maxRetries?: number, retryDelay?: number): Promise<boolean>;
1
+ /**
2
+ * Downloads a file from the API and saves it to a local directory
3
+ * @param translationId - The ID of the translation to download
4
+ * @param outputPath - The path to save the file to
5
+ * @param maxRetries - The maximum number of retries to attempt
6
+ * @param retryDelay - The delay between retries in milliseconds
7
+ */
8
+ export declare function downloadFile(translationId: string, outputPath: string, maxRetries?: number, retryDelay?: number): Promise<boolean>;
@@ -1,45 +1,37 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { logError } from '../console/logging.js';
4
- import { getAuthHeaders } from '../utils/headers.js';
5
- // Helper function to download a file
6
- export async function downloadFile(baseUrl, projectId, apiKey, translationId, outputPath, maxRetries = 3, retryDelay = 1000) {
4
+ import { gt } from '../utils/gt.js';
5
+ /**
6
+ * Downloads a file from the API and saves it to a local directory
7
+ * @param translationId - The ID of the translation to download
8
+ * @param outputPath - The path to save the file to
9
+ * @param maxRetries - The maximum number of retries to attempt
10
+ * @param retryDelay - The delay between retries in milliseconds
11
+ */
12
+ export async function downloadFile(translationId, outputPath, maxRetries = 3, retryDelay = 1000) {
7
13
  let retries = 0;
8
14
  while (retries <= maxRetries) {
9
15
  try {
10
- const downloadResponse = await fetch(`${baseUrl}/v1/project/translations/files/${translationId}/download`, {
11
- method: 'GET',
12
- headers: {
13
- ...getAuthHeaders(projectId, apiKey),
14
- },
15
- });
16
- if (downloadResponse.ok) {
17
- // Ensure the directory exists
18
- const dir = path.dirname(outputPath);
19
- if (!fs.existsSync(dir)) {
20
- fs.mkdirSync(dir, { recursive: true });
21
- }
22
- // Get the file data as an ArrayBuffer
23
- const fileData = await downloadResponse.arrayBuffer();
24
- // Write the file to disk
25
- await fs.promises.writeFile(outputPath, Buffer.from(fileData));
26
- return true;
16
+ // Get the file data as an ArrayBuffer
17
+ const fileData = await gt.downloadFile(translationId);
18
+ // Ensure the directory exists
19
+ const dir = path.dirname(outputPath);
20
+ if (!fs.existsSync(dir)) {
21
+ fs.mkdirSync(dir, { recursive: true });
27
22
  }
28
- // If we get here, the response was not OK
29
- if (retries >= maxRetries) {
30
- logError(`Failed to download file ${outputPath}. Status: ${downloadResponse.status} after ${maxRetries + 1} attempts.`);
31
- return false;
32
- }
33
- // Increment retry counter and wait before next attempt
34
- retries++;
35
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
23
+ // Write the file to disk
24
+ await fs.promises.writeFile(outputPath, Buffer.from(fileData));
25
+ return true;
36
26
  }
37
27
  catch (error) {
28
+ // If we've retried too many times, log an error and return false
38
29
  if (retries >= maxRetries) {
39
30
  logError(`Error downloading file ${outputPath} after ${maxRetries + 1} attempts: ` +
40
31
  error);
41
32
  return false;
42
33
  }
34
+ // Increment retry counter and wait before next attempt
43
35
  retries++;
44
36
  await new Promise((resolve) => setTimeout(resolve, retryDelay));
45
37
  }
@@ -1,16 +1,16 @@
1
+ export type BatchedFiles = Array<{
2
+ translationId: string;
3
+ outputPath: string;
4
+ }>;
5
+ export type DownloadFileBatchResult = {
6
+ successful: string[];
7
+ failed: string[];
8
+ };
1
9
  /**
2
10
  * Downloads multiple translation files in a single batch request
3
- * @param baseUrl - The base URL for the General Translation API
4
- * @param apiKey - The API key for the General Translation API
5
11
  * @param files - Array of files to download with their output paths
6
12
  * @param maxRetries - Maximum number of retry attempts
7
13
  * @param retryDelay - Delay between retries in milliseconds
8
14
  * @returns Object containing successful and failed file IDs
9
15
  */
10
- export declare function downloadFileBatch(baseUrl: string, projectId: string, apiKey: string, files: Array<{
11
- translationId: string;
12
- outputPath: string;
13
- }>, maxRetries?: number, retryDelay?: number): Promise<{
14
- successful: string[];
15
- failed: string[];
16
- }>;
16
+ export declare function downloadFileBatch(files: BatchedFiles, maxRetries?: number, retryDelay?: number): Promise<DownloadFileBatchResult>;
@@ -1,17 +1,15 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { logError, logWarning } from '../console/logging.js';
4
- import { getAuthHeaders } from '../utils/headers.js';
4
+ import { gt } from '../utils/gt.js';
5
5
  /**
6
6
  * Downloads multiple translation files in a single batch request
7
- * @param baseUrl - The base URL for the General Translation API
8
- * @param apiKey - The API key for the General Translation API
9
7
  * @param files - Array of files to download with their output paths
10
8
  * @param maxRetries - Maximum number of retry attempts
11
9
  * @param retryDelay - Delay between retries in milliseconds
12
10
  * @returns Object containing successful and failed file IDs
13
11
  */
14
- export async function downloadFileBatch(baseUrl, projectId, apiKey, files, maxRetries = 3, retryDelay = 1000) {
12
+ export async function downloadFileBatch(files, maxRetries = 3, retryDelay = 1000) {
15
13
  let retries = 0;
16
14
  const fileIds = files.map((file) => file.translationId);
17
15
  const result = { successful: [], failed: [] };
@@ -19,62 +17,56 @@ export async function downloadFileBatch(baseUrl, projectId, apiKey, files, maxRe
19
17
  const outputPathMap = new Map(files.map((file) => [file.translationId, file.outputPath]));
20
18
  while (retries <= maxRetries) {
21
19
  try {
22
- const response = await fetch(`${baseUrl}/v1/project/translations/files/batch-download`, {
23
- method: 'POST',
24
- headers: {
25
- 'Content-Type': 'application/json',
26
- ...getAuthHeaders(projectId, apiKey),
27
- },
28
- body: JSON.stringify({ fileIds }),
29
- });
30
- if (response.ok) {
31
- const responseData = await response.json();
32
- const downloadedFiles = responseData.files || [];
33
- // Process each file in the response
34
- for (const file of downloadedFiles) {
35
- try {
36
- const translationId = file.id;
37
- const outputPath = outputPathMap.get(translationId);
38
- if (!outputPath) {
39
- logWarning(`No output path found for file: ${translationId}`);
40
- result.failed.push(translationId);
41
- continue;
42
- }
43
- // Ensure the directory exists
44
- const dir = path.dirname(outputPath);
45
- if (!fs.existsSync(dir)) {
46
- fs.mkdirSync(dir, { recursive: true });
47
- }
48
- // Write the file to disk
49
- await fs.promises.writeFile(outputPath, file.data);
50
- result.successful.push(translationId);
20
+ // Download the files
21
+ const responseData = await gt.downloadFileBatch(fileIds);
22
+ const downloadedFiles = responseData.files || [];
23
+ // Process each file in the response
24
+ for (const file of downloadedFiles) {
25
+ try {
26
+ const translationId = file.id;
27
+ const outputPath = outputPathMap.get(translationId);
28
+ if (!outputPath) {
29
+ logWarning(`No output path found for file: ${translationId}`);
30
+ result.failed.push(translationId);
31
+ continue;
51
32
  }
52
- catch (error) {
53
- logError(`Error saving file ${file.id}: ` + error);
54
- result.failed.push(file.id);
33
+ // Ensure the directory exists
34
+ const dir = path.dirname(outputPath);
35
+ if (!fs.existsSync(dir)) {
36
+ fs.mkdirSync(dir, { recursive: true });
55
37
  }
38
+ // Write the file to disk
39
+ await fs.promises.writeFile(outputPath, file.data);
40
+ result.successful.push(translationId);
56
41
  }
57
- // Add any files that weren't in the response to the failed list
58
- const downloadedIds = new Set(downloadedFiles.map((file) => file.id));
59
- for (const fileId of fileIds) {
60
- if (!downloadedIds.has(fileId) && !result.failed.includes(fileId)) {
61
- result.failed.push(fileId);
62
- }
42
+ catch (error) {
43
+ logError(`Error saving file ${file.id}: ` + error);
44
+ result.failed.push(file.id);
63
45
  }
64
- return result;
65
46
  }
66
- // If we get here, the response was not OK
67
- if (retries >= maxRetries) {
68
- logError(`Failed to download files in batch. Status: ${response.status} after ${maxRetries + 1} attempts.`);
69
- // Mark all files as failed
70
- result.failed = [...fileIds];
71
- return result;
47
+ // Add any files that weren't in the response to the failed list
48
+ const downloadedIds = new Set(downloadedFiles.map((file) => file.id));
49
+ for (const fileId of fileIds) {
50
+ if (!downloadedIds.has(fileId) && !result.failed.includes(fileId)) {
51
+ result.failed.push(fileId);
52
+ }
72
53
  }
73
- // Increment retry counter and wait before next attempt
74
- retries++;
75
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
54
+ return result;
55
+ // // If we get here, the response was not OK
56
+ // if (retries >= maxRetries) {
57
+ // logError(
58
+ // `Failed to download files in batch. Status: ${response.status} after ${maxRetries + 1} attempts.`
59
+ // );
60
+ // // Mark all files as failed
61
+ // result.failed = [...fileIds];
62
+ // return result;
63
+ // }
64
+ // // Increment retry counter and wait before next attempt
65
+ // retries++;
66
+ // await new Promise((resolve) => setTimeout(resolve, retryDelay));
76
67
  }
77
68
  catch (error) {
69
+ // If we've retried too many times, log an error and return false
78
70
  if (retries >= maxRetries) {
79
71
  logError(`Error downloading files in batch after ${maxRetries + 1} attempts: ` +
80
72
  error);
@@ -82,6 +74,7 @@ export async function downloadFileBatch(baseUrl, projectId, apiKey, files, maxRe
82
74
  result.failed = [...fileIds];
83
75
  return result;
84
76
  }
77
+ // Increment retry counter and wait before next attempt
85
78
  retries++;
86
79
  await new Promise((resolve) => setTimeout(resolve, retryDelay));
87
80
  }
@@ -1,10 +1,7 @@
1
- import { RetrievedTranslations } from '../types/api.js';
1
+ import { RetrievedTranslations } from 'generaltranslation/types';
2
2
  /**
3
3
  * Fetches translations from the API and saves them to a local directory
4
- * @param baseUrl - The base URL for the API
5
- * @param apiKey - The API key for the API
6
- * @param versionId - The version ID of the project
7
4
  * @param translationsDir - The directory to save the translations to
8
5
  * @param fileType - The file type to save the translations as (file extension)
9
6
  */
10
- export declare function fetchTranslations(baseUrl: string, projectId: string, apiKey: string, versionId: string): Promise<RetrievedTranslations>;
7
+ export declare function fetchTranslations(versionId: string): Promise<RetrievedTranslations>;
@@ -1,30 +1,18 @@
1
1
  import chalk from 'chalk';
2
2
  import { logError } from '../console/logging.js';
3
- import { getAuthHeaders } from '../utils/headers.js';
3
+ import { gt } from '../utils/gt.js';
4
4
  /**
5
5
  * Fetches translations from the API and saves them to a local directory
6
- * @param baseUrl - The base URL for the API
7
- * @param apiKey - The API key for the API
8
- * @param versionId - The version ID of the project
9
6
  * @param translationsDir - The directory to save the translations to
10
7
  * @param fileType - The file type to save the translations as (file extension)
11
8
  */
12
- export async function fetchTranslations(baseUrl, projectId, apiKey, versionId) {
13
- // First fetch the translations from the API
14
- const response = await fetch(`${baseUrl}/v1/project/translations/info/${encodeURIComponent(versionId)}`, {
15
- method: 'GET',
16
- headers: {
17
- 'Content-Type': 'application/json',
18
- ...getAuthHeaders(projectId, apiKey),
19
- },
20
- });
21
- if (response.ok) {
22
- const data = await response.json();
23
- const translations = data.translations;
24
- return translations;
9
+ export async function fetchTranslations(versionId) {
10
+ try {
11
+ const result = await gt.fetchTranslations(versionId);
12
+ return result.translations;
25
13
  }
26
- else {
14
+ catch {
27
15
  logError(chalk.red('Failed to fetch translations'));
16
+ return [];
28
17
  }
29
- return [];
30
18
  }
@@ -1,22 +1,17 @@
1
1
  import { Settings } from '../types/index.js';
2
- import { FileFormat, DataFormat } from '../types/data.js';
3
- /**
4
- * File object structure
5
- * @param content - The content of the file
6
- * @param fileName - The name of the file
7
- * @param fileExtension - The format of the file (JSON, MDX, MD, etc.)
8
- * @param dataFormat - The format of the data within the file
9
- */
10
- export interface FileToTranslate {
11
- content: string;
12
- fileName: string;
13
- fileFormat: FileFormat;
14
- dataFormat: DataFormat;
15
- }
16
- type ApiOptions = Settings & {
2
+ import { CompletedFileTranslationData, FileToTranslate } from 'generaltranslation/types';
3
+ export type ApiOptions = Settings & {
17
4
  publish: boolean;
18
5
  wait: boolean;
19
6
  };
7
+ export type SendFilesResult = {
8
+ data: Record<string, {
9
+ fileName: string;
10
+ versionId: string;
11
+ }>;
12
+ locales: string[];
13
+ translations: CompletedFileTranslationData[];
14
+ };
20
15
  /**
21
16
  * Sends multiple files for translation to the API
22
17
  * @param files - Array of file objects to translate
@@ -24,8 +19,10 @@ type ApiOptions = Settings & {
24
19
  * @returns The translated content or version ID
25
20
  */
26
21
  export declare function sendFiles(files: FileToTranslate[], options: ApiOptions): Promise<{
27
- data: any;
28
- locales: any;
29
- translations: any;
22
+ data: Record<string, {
23
+ fileName: string;
24
+ versionId: string;
25
+ }>;
26
+ locales: string[];
27
+ translations: CompletedFileTranslationData[];
30
28
  }>;
31
- export {};
@@ -1,6 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import { createSpinner, logMessage, logSuccess } from '../console/logging.js';
3
- import { getAuthHeaders } from '../utils/headers.js';
3
+ import { gt } from '../utils/gt.js';
4
4
  /**
5
5
  * Sends multiple files for translation to the API
6
6
  * @param files - Array of file objects to translate
@@ -12,38 +12,16 @@ export async function sendFiles(files, options) {
12
12
  '\n' +
13
13
  files.map((file) => ` - ${chalk.bold(file.fileName)}`).join('\n'));
14
14
  const spinner = createSpinner('dots');
15
- spinner.start(`Sending ${files.length} file${files.length > 1 ? 's' : ''} to General Translation API...`);
15
+ spinner.start(`Sending ${files.length} file${files.length !== 1 ? 's' : ''} to General Translation API...`);
16
16
  try {
17
- // Create form data
18
- const formData = new FormData();
19
- // Add each file to the form data
20
- files.forEach((file, index) => {
21
- formData.append(`file${index}`, new Blob([file.content]), file.fileName);
22
- formData.append(`fileFormat${index}`, file.fileFormat);
23
- formData.append(`fileDataFormat${index}`, file.dataFormat);
24
- formData.append(`fileName${index}`, file.fileName);
17
+ // Send the files to the API
18
+ const responseData = await gt.enqueueFiles(files, {
19
+ publish: options.publish,
20
+ description: options.description,
21
+ sourceLocale: options.defaultLocale,
22
+ targetLocales: options.locales,
23
+ _versionId: options._versionId,
25
24
  });
26
- // Add number of files
27
- formData.append('fileCount', String(files.length));
28
- // Add other metadata
29
- formData.append('sourceLocale', options.defaultLocale);
30
- formData.append('targetLocales', JSON.stringify(options.locales));
31
- formData.append('projectId', options.projectId);
32
- formData.append('publish', String(options.publish));
33
- formData.append('versionId', options._versionId || '');
34
- formData.append('description', options.description || '');
35
- const response = await fetch(`${options.baseUrl}/v1/project/translations/files/upload`, {
36
- method: 'POST',
37
- headers: {
38
- ...getAuthHeaders(options.projectId, options.apiKey),
39
- },
40
- body: formData,
41
- });
42
- if (!response.ok) {
43
- spinner.stop(chalk.red(await response.text()));
44
- process.exit(1);
45
- }
46
- const responseData = await response.json();
47
25
  // Handle version ID response (for async processing)
48
26
  const { data, message, locales, translations } = responseData;
49
27
  spinner.stop(chalk.green('Files for translation uploaded successfully'));
@@ -1,19 +1,19 @@
1
1
  import { Settings, SupportedLibraries, Updates } from '../types/index.js';
2
2
  import { DataFormat } from '../types/data.js';
3
- type ApiOptions = Settings & {
3
+ export type ApiOptions = Settings & {
4
4
  timeout: string;
5
5
  dataFormat: DataFormat;
6
6
  description?: string;
7
7
  requireApproval?: boolean;
8
8
  };
9
+ export type SendUpdatesResult = {
10
+ versionId: string;
11
+ locales: string[];
12
+ };
9
13
  /**
10
14
  * Sends updates to the API
11
15
  * @param updates - The updates to send
12
16
  * @param options - The options for the API call
13
17
  * @returns The versionId of the updated project
14
18
  */
15
- export declare function sendUpdates(updates: Updates, options: ApiOptions, library: SupportedLibraries): Promise<{
16
- versionId: string;
17
- locales: string[];
18
- }>;
19
- export {};
19
+ export declare function sendUpdates(updates: Updates, options: ApiOptions, library: SupportedLibraries): Promise<SendUpdatesResult>;
@@ -1,8 +1,8 @@
1
1
  import chalk from 'chalk';
2
- import { createSpinner, logSuccess, logWarning } from '../console/logging.js';
2
+ import { createSpinner, logSuccess, logWarning, } from '../console/logging.js';
3
3
  import updateConfig from '../fs/config/updateConfig.js';
4
4
  import { isUsingLocalTranslations } from '../config/utils.js';
5
- import { getAuthHeaders } from '../utils/headers.js';
5
+ import { gt } from '../utils/gt.js';
6
6
  /**
7
7
  * Sends updates to the API
8
8
  * @param updates - The updates to send
@@ -10,41 +10,18 @@ import { getAuthHeaders } from '../utils/headers.js';
10
10
  * @returns The versionId of the updated project
11
11
  */
12
12
  export async function sendUpdates(updates, options, library) {
13
- const { apiKey, projectId, defaultLocale, dataFormat } = options;
14
- const globalMetadata = {
15
- ...(projectId && { projectId }),
16
- ...(defaultLocale && { sourceLocale: defaultLocale }),
17
- };
18
- // If additionalLocales is provided, additionalLocales + project.current_locales will be translated
19
- // If not, then options.locales will be translated
20
- // If neither, then project.current_locales will be translated
21
- const body = {
22
- updates,
23
- ...(options.locales && { locales: options.locales }),
24
- metadata: globalMetadata,
25
- ...(dataFormat && { dataFormat }),
26
- ...(options.version && { versionId: options.version }),
27
- ...(options.description && { description: options.description }),
28
- ...(options.requireApproval && {
29
- requireApproval: options.requireApproval,
30
- }),
31
- };
32
13
  const spinner = createSpinner('dots');
33
14
  spinner.start(`Sending ${library} updates to General Translation API...`);
34
15
  try {
35
- const response = await fetch(`${options.baseUrl}/v1/project/translations/update`, {
36
- method: 'POST',
37
- headers: {
38
- 'Content-Type': 'application/json',
39
- ...getAuthHeaders(options.projectId, options.apiKey),
40
- },
41
- body: JSON.stringify(body),
16
+ const responseData = await gt.enqueueEntries(updates, {
17
+ sourceLocale: options.defaultLocale,
18
+ targetLocales: options.locales,
19
+ dataFormat: options.dataFormat,
20
+ version: options.version,
21
+ description: options.description,
22
+ requireApproval: options.requireApproval,
42
23
  });
43
- if (!response.ok) {
44
- spinner.stop(chalk.red(await response.text()));
45
- process.exit(1);
46
- }
47
- const { versionId, message, locales, projectSettings } = await response.json();
24
+ const { versionId, message, locales, projectSettings } = responseData;
48
25
  spinner.stop(chalk.green('Sent updates'));
49
26
  logSuccess(message);
50
27
  if (isUsingLocalTranslations(options) && projectSettings.cdnEnabled) {
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * Waits for translations to be deployed to the General Translation API
3
- * @param apiKey - The API key for the General Translation API
4
- * @param baseUrl - The base URL for the General Translation API
5
3
  * @param versionId - The version ID of the project
6
4
  * @param locales - The locales to wait for
7
5
  * @param startTime - The start time of the wait
8
6
  * @param timeoutDuration - The timeout duration for the wait
9
7
  * @returns True if all translations are deployed, false otherwise
10
8
  */
11
- export declare const waitForUpdates: (projectId: string, apiKey: string, baseUrl: string, versionId: string, startTime: number, timeoutDuration: number) => Promise<boolean>;
9
+ export declare const waitForUpdates: (versionId: string, startTime: number, timeoutDuration: number) => Promise<boolean>;