gt 2.21.4 → 2.22.0

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 (118) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/api/collectUserEditDiffs.js +1 -1
  3. package/dist/auth/callbackPage.d.ts +1 -0
  4. package/dist/auth/callbackPage.js +77 -0
  5. package/dist/auth/callbackPage.js.map +1 -0
  6. package/dist/auth/credentialStore.d.ts +15 -0
  7. package/dist/auth/credentialStore.js +107 -0
  8. package/dist/auth/credentialStore.js.map +1 -0
  9. package/dist/auth/errors.d.ts +7 -0
  10. package/dist/auth/errors.js +23 -0
  11. package/dist/auth/errors.js.map +1 -0
  12. package/dist/auth/loopback.d.ts +9 -0
  13. package/dist/auth/loopback.js +73 -0
  14. package/dist/auth/loopback.js.map +1 -0
  15. package/dist/auth/loopback.test.d.ts +1 -0
  16. package/dist/auth/oauth.d.ts +39 -0
  17. package/dist/auth/oauth.js +260 -0
  18. package/dist/auth/oauth.js.map +1 -0
  19. package/dist/bin/bin-entry.js +2 -10
  20. package/dist/bin/bin-entry.js.map +1 -1
  21. package/dist/cli/base.d.ts +4 -8
  22. package/dist/cli/base.js +119 -60
  23. package/dist/cli/base.js.map +1 -1
  24. package/dist/cli/commands/api.js +6 -2
  25. package/dist/cli/commands/api.js.map +1 -1
  26. package/dist/cli/commands/upload.js +2 -2
  27. package/dist/cli/commands/upload.js.map +1 -1
  28. package/dist/cli/commands/utils/validation.d.ts +7 -7
  29. package/dist/cli/commands/utils/validation.js +7 -20
  30. package/dist/cli/commands/utils/validation.js.map +1 -1
  31. package/dist/config/generateSettings.js +4 -9
  32. package/dist/config/generateSettings.js.map +1 -1
  33. package/dist/config/optionPresets.js +16 -6
  34. package/dist/config/optionPresets.js.map +1 -1
  35. package/dist/config/validateSettings.d.ts +4 -2
  36. package/dist/config/validateSettings.js +9 -0
  37. package/dist/config/validateSettings.js.map +1 -1
  38. package/dist/console/index.d.ts +0 -2
  39. package/dist/console/index.js +2 -4
  40. package/dist/console/index.js.map +1 -1
  41. package/dist/console/inkPrompts.js +8 -6
  42. package/dist/console/inkPrompts.js.map +1 -1
  43. package/dist/console/inkTypes.d.ts +3 -0
  44. package/dist/console/logger.d.ts +13 -0
  45. package/dist/console/logger.js +60 -20
  46. package/dist/console/logger.js.map +1 -1
  47. package/dist/console/logging.d.ts +5 -3
  48. package/dist/console/logging.js +8 -6
  49. package/dist/console/logging.js.map +1 -1
  50. package/dist/console/promptParsing.d.ts +4 -3
  51. package/dist/console/promptParsing.js +7 -7
  52. package/dist/console/promptParsing.js.map +1 -1
  53. package/dist/formats/files/aggregateFiles.js +4 -4
  54. package/dist/formats/files/aggregateFiles.js.map +1 -1
  55. package/dist/formats/files/localeContent.js +2 -2
  56. package/dist/formats/files/localeContent.js.map +1 -1
  57. package/dist/formats/files/transformFormat.d.ts +2 -0
  58. package/dist/formats/files/transformFormat.js +8 -2
  59. package/dist/formats/files/transformFormat.js.map +1 -1
  60. package/dist/formats/json/extractJson.js +3 -3
  61. package/dist/formats/json/extractJson.js.map +1 -1
  62. package/dist/formats/json/mergeJson.js +6 -6
  63. package/dist/formats/json/mergeJson.js.map +1 -1
  64. package/dist/formats/xcstrings/mergeXcstrings.js +2 -2
  65. package/dist/formats/xcstrings/mergeXcstrings.js.map +1 -1
  66. package/dist/generated/version.d.ts +1 -1
  67. package/dist/generated/version.js +1 -1
  68. package/dist/generated/version.js.map +1 -1
  69. package/dist/git/setupMergeDrivers.js +1 -1
  70. package/dist/git/setupMergeDrivers.js.map +1 -1
  71. package/dist/index.js +2 -0
  72. package/dist/index.js.map +1 -1
  73. package/dist/main.js +2 -10
  74. package/dist/main.js.map +1 -1
  75. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +1 -1
  76. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +1 -1
  77. package/dist/react/jsx/utils/parseString.js +1 -1
  78. package/dist/react/jsx/utils/stringParsing/derivation/index.js +1 -1
  79. package/dist/setup/developmentCredentials.d.ts +8 -0
  80. package/dist/setup/developmentCredentials.js +82 -0
  81. package/dist/setup/developmentCredentials.js.map +1 -0
  82. package/dist/setup/setupViteSPA.js +1 -1
  83. package/dist/setup/setupViteSPA.js.map +1 -1
  84. package/dist/setup/userInput.d.ts +1 -0
  85. package/dist/setup/userInput.js +7 -2
  86. package/dist/setup/userInput.js.map +1 -1
  87. package/dist/translation/extractInline.js +1 -1
  88. package/dist/translation/extractInline.js.map +1 -1
  89. package/dist/types/index.d.ts +7 -2
  90. package/dist/utils/api.d.ts +146 -67
  91. package/dist/utils/api.js +5 -94
  92. package/dist/utils/api.js.map +1 -1
  93. package/dist/utils/credentials.d.ts +37 -10
  94. package/dist/utils/credentials.js +267 -58
  95. package/dist/utils/credentials.js.map +1 -1
  96. package/dist/utils/loadEnv.d.ts +2 -0
  97. package/dist/utils/loadEnv.js +24 -0
  98. package/dist/utils/loadEnv.js.map +1 -0
  99. package/dist/utils/localizeStaticUrls.js +34 -6
  100. package/dist/utils/localizeStaticUrls.js.map +1 -1
  101. package/dist/utils/processOpenApi.js +2 -2
  102. package/dist/utils/processOpenApi.js.map +1 -1
  103. package/dist/utils/reactPackageCompatibility.js +1 -1
  104. package/dist/utils/reactPackageCompatibility.js.map +1 -1
  105. package/dist/workflows/steps/PollJobsStep.js +40 -53
  106. package/dist/workflows/steps/PollJobsStep.js.map +1 -1
  107. package/dist/workflows/utils/syncFonts.js +2 -2
  108. package/dist/workflows/utils/syncFonts.js.map +1 -1
  109. package/package.json +8 -7
  110. package/dist/next/config/parseNextConfig.d.ts +0 -10
  111. package/dist/next/config/parseNextConfig.js +0 -34
  112. package/dist/next/config/parseNextConfig.js.map +0 -1
  113. package/dist/utils/fetch.d.ts +0 -11
  114. package/dist/utils/fetch.js +0 -24
  115. package/dist/utils/fetch.js.map +0 -1
  116. package/dist/utils/gt.d.ts +0 -2
  117. package/dist/utils/gt.js +0 -7
  118. package/dist/utils/gt.js.map +0 -1
@@ -1,4 +1,6 @@
1
1
  import type { CustomMapping } from '@generaltranslation/format/types';
2
+ import type { UserTokenProvider } from 'generaltranslation/api';
3
+ import type { ModelProvider } from 'generaltranslation/internal';
2
4
  import type { FileFormat } from 'generaltranslation/types';
3
5
  import { SUPPORTED_FILE_EXTENSIONS } from '../formats/files/supportedFiles.js';
4
6
  import { ParsingConfigOptions, GTParsingFlags, BaseParsingFlags, ParseFlagsByFileType } from './parsing.js';
@@ -179,6 +181,7 @@ export type Settings = {
179
181
  baseUrl: string;
180
182
  dashboardUrl: string;
181
183
  apiKey?: string;
184
+ userTokenProvider?: UserTokenProvider;
182
185
  projectId?: string;
183
186
  defaultLocale: string;
184
187
  locales: string[];
@@ -214,7 +217,7 @@ export type Settings = {
214
217
  fonts?: FontsConfig;
215
218
  framework?: SupportedFrameworks;
216
219
  options?: AdditionalOptions;
217
- modelProvider?: string;
220
+ modelProvider?: ModelProvider;
218
221
  tag?: string;
219
222
  tagMessage?: string;
220
223
  parsingOptions: ParsingConfigOptions;
@@ -253,7 +256,9 @@ export type AdditionalOptions = {
253
256
  experimentalClearLocaleDirs?: boolean;
254
257
  clearLocaleDirsExclude?: string[];
255
258
  experimentalLocalizeStaticImports?: boolean;
256
- experimentalLocalizeStaticUrls?: boolean;
259
+ experimentalLocalizeStaticUrls?: boolean | {
260
+ skipUntranslatedPages?: boolean;
261
+ };
257
262
  experimentalLocalizeRelativeAssets?: boolean;
258
263
  experimentalAddHeaderAnchorIds?: 'mintlify' | 'default';
259
264
  experimentalHideDefaultLocale?: boolean;
@@ -1,16 +1,10 @@
1
1
  import type { CustomMapping } from '@generaltranslation/format/types';
2
- import { type ApiClientConfig, type CreateProjectData, type CreateTagData, type GetBranchInfoData, type ProcessFileMovesData, type PublishFilesData, type SubmitUserEditDiffsData } from 'generaltranslation/api';
2
+ import type { ApiClientConfig } from 'generaltranslation/api';
3
3
  export declare function configureApiClient(config: ApiClientConfig & {
4
4
  customMapping?: CustomMapping;
5
5
  }): void;
6
6
  export declare const api: {
7
- queryBranchData(body: GetBranchInfoData["body"]): Promise<{
8
- branches: Array<import("@generaltranslation/api").Branch>;
9
- defaultBranch: import("@generaltranslation/api").Branch & ({
10
- [key: string]: unknown;
11
- } | null);
12
- }>;
13
- checkJobStatus(jobIds: string[]): Promise<({
7
+ checkJobStatus(jobIds: string[], signal?: AbortSignal): Promise<({
14
8
  status: "queued";
15
9
  jobId: string;
16
10
  } | {
@@ -37,22 +31,80 @@ export declare const api: {
37
31
  currentLocales: Array<string>;
38
32
  autoApprove: boolean;
39
33
  }>;
40
- publishFiles(files: PublishFilesData["body"]["files"]): Promise<{
41
- results: Array<{
42
- fileId: string;
43
- versionId: string;
44
- locale?: string;
45
- branchId: string;
34
+ resolveAliasLocale(locale: string): string;
35
+ resolveCanonicalLocale(locale: string): string;
36
+ translate: (source: import("generaltranslation/types").TranslateManyEntry, options: string | import("generaltranslation/types").TranslateOptions, timeoutMs?: number | false) => Promise<import("generaltranslation/types").TranslationResult>;
37
+ translateMany: {
38
+ (sources: import("generaltranslation/types").TranslateManyEntry[], options: string | import("generaltranslation/types").TranslateOptions, timeoutMs?: number | false): Promise<import("generaltranslation/types").TranslateManyResult>;
39
+ (sources: Record<string, import("generaltranslation/types").TranslateManyEntry>, options: string | import("generaltranslation/types").TranslateOptions, timeoutMs?: number | false): Promise<Record<string, import("generaltranslation/types").TranslationResult>>;
40
+ };
41
+ queryBranchData(body: import("@generaltranslation/api").GetBranchInfoData["body"]): Promise<{
42
+ branches: Array<import("@generaltranslation/api").Branch>;
43
+ defaultBranch: import("@generaltranslation/api").Branch & ({
44
+ [key: string]: unknown;
45
+ } | null);
46
+ }>;
47
+ createBranch(body: import("@generaltranslation/api").CreateBranchData["body"]): Promise<{
48
+ branch: import("@generaltranslation/api").Branch;
49
+ }>;
50
+ processFileMoves(moves: import("@generaltranslation/api").ProcessFileMovesData["body"]["moves"], options?: Pick<import("@generaltranslation/api").ProcessFileMovesData["body"], "branchId"> & {
51
+ timeout?: number;
52
+ }): Promise<{
53
+ results: {
54
+ oldFileId: string;
55
+ newFileId: string;
46
56
  success: boolean;
57
+ newSourceFileId?: string;
58
+ clonedTranslationsCount?: number;
47
59
  error?: string;
60
+ }[];
61
+ summary: {
62
+ total: number;
63
+ succeeded: number;
64
+ failed: number;
65
+ };
66
+ }>;
67
+ getOrphanedFiles(branchId: string, fileIds: string[], options?: {
68
+ timeout?: number;
69
+ }): Promise<{
70
+ orphanedFiles: Array<{
71
+ fileId: string;
72
+ versionId: string;
73
+ fileName: string;
48
74
  }>;
49
75
  }>;
50
- submitUserEditDiffs(body: SubmitUserEditDiffsData["body"]): Promise<{
51
- filesProcessed: number;
52
- entriesReceived: number;
76
+ setupProject(files: import("@generaltranslation/api").GenerateProjectContextData["body"]["files"], options?: Omit<import("@generaltranslation/api").GenerateProjectContextData["body"], "files"> & {
77
+ timeoutMs?: number;
78
+ }): Promise<{
79
+ status: "completed";
80
+ } | {
81
+ setupJobId: string;
82
+ status: "queued";
83
+ }>;
84
+ awaitJobs(jobIds: readonly string[], options?: import("@generaltranslation/api").AwaitJobsOptions): Promise<{
85
+ jobs: {
86
+ jobId: string;
87
+ status: import("@generaltranslation/api").GetTranslationJobInfoResponse[number]["status"];
88
+ error?: {
89
+ message: string;
90
+ };
91
+ }[];
92
+ complete: boolean;
93
+ }>;
94
+ enqueueFiles(files: import("@generaltranslation/api").EnqueueFileTranslationsData["body"]["files"], options: {
95
+ sourceLocale?: string;
96
+ targetLocales: string[];
97
+ modelProvider?: string;
98
+ force?: boolean;
99
+ timeout?: number;
100
+ }): Promise<{
101
+ jobData: {
102
+ [k: string]: any;
103
+ };
104
+ locales: string[];
53
105
  message: string;
54
- }[]>;
55
- createTag(body: CreateTagData["body"]): Promise<{
106
+ }>;
107
+ createTag(body: import("@generaltranslation/api").CreateTagData["body"]): Promise<{
56
108
  tag: {
57
109
  id: string;
58
110
  tagId: string;
@@ -61,7 +113,24 @@ export declare const api: {
61
113
  updatedAt: string;
62
114
  };
63
115
  }>;
64
- createProject(orgId: CreateProjectData["path"]["orgId"], body: CreateProjectData["body"]): Promise<{
116
+ publishFiles(files: import("@generaltranslation/api").PublishFilesData["body"]["files"]): Promise<{
117
+ results: Array<{
118
+ fileId: string;
119
+ versionId: string;
120
+ locale?: string;
121
+ branchId: string;
122
+ success: boolean;
123
+ error?: string;
124
+ }>;
125
+ }>;
126
+ submitUserEditDiffs(body: import("@generaltranslation/api").SubmitUserEditDiffsData["body"], options?: {
127
+ timeout?: number;
128
+ }): Promise<{
129
+ filesProcessed: number;
130
+ entriesReceived: number;
131
+ message: string;
132
+ }[]>;
133
+ createProject(orgId: import("@generaltranslation/api").CreateProjectData["path"]["orgId"], body: import("@generaltranslation/api").CreateProjectData["body"]): Promise<{
65
134
  project: {
66
135
  id: string;
67
136
  name: string;
@@ -69,34 +138,26 @@ export declare const api: {
69
138
  defaultLocale: string;
70
139
  };
71
140
  }>;
72
- getOrphanedFiles(branchId: string, fileIds: string[]): Promise<{
73
- orphanedFiles: Array<{
74
- fileId: string;
75
- versionId: string;
76
- fileName: string;
77
- }>;
78
- }>;
79
- processFileMoves(moves: ProcessFileMovesData["body"]["moves"], options: Pick<ProcessFileMovesData["body"], "branchId">): Promise<{
80
- results: {
81
- oldFileId: string;
82
- newFileId: string;
83
- success: boolean;
84
- newSourceFileId?: string;
85
- clonedTranslationsCount?: number;
86
- error?: string;
87
- }[];
88
- summary: {
89
- total: number;
90
- succeeded: number;
91
- failed: number;
141
+ listProjects(): Promise<{
142
+ id: string;
143
+ name: string;
144
+ orgId: string;
145
+ orgName: string;
146
+ }[]>;
147
+ listOrgs(): Promise<{
148
+ id: string;
149
+ name: string;
150
+ }[]>;
151
+ createProjectApiKey(projectId: import("@generaltranslation/api").CreateProjectApiKeyData["path"]["projectId"], body: import("@generaltranslation/api").CreateProjectApiKeyData["body"]): Promise<{
152
+ apiKey: {
153
+ id: string;
154
+ name: string;
155
+ key: string;
156
+ projectId: string;
157
+ type: "production";
92
158
  };
93
159
  }>;
94
- resolveAliasLocale(locale: string): string;
95
- resolveCanonicalLocale(locale: string): string;
96
- createBranch(body: import("@generaltranslation/api").CreateBranchData["body"]): Promise<{
97
- branch: import("@generaltranslation/api").Branch;
98
- }>;
99
- queryFileData(body: import("@generaltranslation/api").GetFileInfoData["body"]): Promise<{
160
+ queryFileData(body: import("@generaltranslation/api").GetFileInfoData["body"], timeoutMs?: number): Promise<{
100
161
  translatedFiles: {
101
162
  locale: string;
102
163
  branchId: string;
@@ -124,38 +185,46 @@ export declare const api: {
124
185
  publishedAt: string | null;
125
186
  }[];
126
187
  }>;
127
- downloadFileBatch(files: import("@generaltranslation/api").DownloadFilesData["body"]): Promise<{
188
+ querySourceFile(path: import("@generaltranslation/api").GetTranslationStatusData["path"], query?: import("@generaltranslation/api").GetTranslationStatusData["query"], timeoutMs?: number): Promise<{
189
+ translations: {
190
+ locale: string;
191
+ completedAt: string | null;
192
+ approvedAt: string | null;
193
+ publishedAt: string | null;
194
+ createdAt: string | null;
195
+ updatedAt: string | null;
196
+ }[];
197
+ sourceFile: {
198
+ sourceLocale: string;
199
+ locales: string[];
200
+ id: string;
201
+ branchId: string;
202
+ fileId: string;
203
+ versionId: string;
204
+ fileName: string;
205
+ fileFormat: import("@generaltranslation/api").FileFormat;
206
+ dataFormat: string | null;
207
+ createdAt: string;
208
+ updatedAt: string;
209
+ };
210
+ }>;
211
+ downloadFileBatch(files: import("@generaltranslation/api").DownloadFilesData["body"], options?: {
212
+ timeout?: number;
213
+ }): Promise<{
128
214
  files: import("generaltranslation/types").DownloadedFile[];
129
215
  count: number;
130
216
  pending: {
217
+ locale: string;
131
218
  branchId: string;
132
219
  fileId: string;
133
- locale: string;
134
220
  versionId: string;
135
221
  }[];
136
222
  }>;
137
- setupProject(files: import("@generaltranslation/api").GenerateProjectContextData["body"]["files"], options?: Omit<import("@generaltranslation/api").GenerateProjectContextData["body"], "files">): Promise<{
138
- status: "completed";
139
- } | {
140
- setupJobId: string;
141
- status: "queued";
142
- }>;
143
- enqueueFiles(files: import("@generaltranslation/api").EnqueueFileTranslationsData["body"]["files"], options: {
144
- sourceLocale?: string;
145
- targetLocales: string[];
146
- modelProvider?: string;
147
- force?: boolean;
148
- }): Promise<{
149
- jobData: {
150
- [k: string]: any;
151
- };
152
- locales: string[];
153
- message: string;
154
- }>;
155
223
  uploadSourceFiles(files: Array<{
156
224
  source: import("@generaltranslation/api").UploadSourceFilesData["body"]["data"][number]["source"];
157
225
  }>, options: {
158
226
  sourceLocale: string;
227
+ timeout?: number;
159
228
  }): Promise<{
160
229
  uploadedFiles: {
161
230
  branchId: string;
@@ -167,9 +236,19 @@ export declare const api: {
167
236
  locale?: string;
168
237
  }[];
169
238
  }>;
170
- awaitJobs(jobIds: readonly string[], options?: import("@generaltranslation/api").AwaitJobsOptions): Promise<import("@generaltranslation/api").AwaitJobsResult>;
239
+ uploadFonts(fonts: import("@generaltranslation/api").UploadAssetsData["body"]["assets"], options?: {
240
+ timeout?: number;
241
+ }): Promise<{
242
+ assets: {
243
+ id: string;
244
+ assetKey: string;
245
+ fileName: string;
246
+ }[];
247
+ count: number;
248
+ }>;
171
249
  uploadTranslations(files: import("@generaltranslation/api").UploadTranslationsData["body"]["data"], options: {
172
250
  sourceLocale: string;
251
+ timeout?: number;
173
252
  }): Promise<{
174
253
  uploadedFiles: {
175
254
  branchId: string;
package/dist/utils/api.js CHANGED
@@ -1,105 +1,16 @@
1
- import { createGtApiAdapter, unwrapApiResult } from "generaltranslation/internal";
2
- import { createApiClient, createProject, createTag, getBranchInfo, getOrphanedFiles, getProjectInfo, getTranslationJobInfo, processBatches, processFileMoves, publishFiles, submitUserEditDiffs } from "generaltranslation/api";
1
+ import { createGtApiAdapter } from "generaltranslation/internal";
3
2
  //#region src/utils/api.ts
4
- const { configure: configureSharedApi, getClient, getClientConfig, ...sharedApi } = createGtApiAdapter();
3
+ const { configure: configureSharedApi, getClient: _getClient, loadJobStatuses, loadProjectInfo, ...sharedApi } = createGtApiAdapter();
5
4
  function configureApiClient(config) {
6
5
  configureSharedApi(config);
7
6
  }
8
7
  const api = {
9
8
  ...sharedApi,
10
- async queryBranchData(body) {
11
- return unwrapApiResult(await getBranchInfo({
12
- body,
13
- client: getClient()
14
- }));
15
- },
16
- async checkJobStatus(jobIds) {
17
- return unwrapApiResult(await getTranslationJobInfo({
18
- body: { jobIds },
19
- client: getClient()
20
- }));
9
+ async checkJobStatus(jobIds, signal) {
10
+ return loadJobStatuses(jobIds, { signal });
21
11
  },
22
12
  async getProjectInfo(timeoutMs) {
23
- const config = getClientConfig();
24
- if (!config.projectId) throw new Error("Project ID is required to fetch project information");
25
- return unwrapApiResult(await getProjectInfo({
26
- client: createApiClient({
27
- ...config,
28
- timeoutMs
29
- }),
30
- path: { projectId: config.projectId }
31
- }));
32
- },
33
- async publishFiles(files) {
34
- return unwrapApiResult(await publishFiles({
35
- body: { files },
36
- client: getClient()
37
- }));
38
- },
39
- async submitUserEditDiffs(body) {
40
- return processBatches(body.diffs, async (diffs) => [unwrapApiResult(await submitUserEditDiffs({
41
- body: {
42
- projectId: body.projectId,
43
- diffs: diffs.map((diff) => ({
44
- ...diff,
45
- locale: sharedApi.resolveCanonicalLocale(diff.locale)
46
- }))
47
- },
48
- client: getClient()
49
- }))]);
50
- },
51
- async createTag(body) {
52
- return unwrapApiResult(await createTag({
53
- body,
54
- client: getClient()
55
- }));
56
- },
57
- async createProject(orgId, body) {
58
- return unwrapApiResult(await createProject({
59
- path: { orgId },
60
- body: {
61
- ...body,
62
- defaultLocale: sharedApi.resolveCanonicalLocale(body.defaultLocale)
63
- },
64
- client: getClient()
65
- }));
66
- },
67
- async getOrphanedFiles(branchId, fileIds) {
68
- const request = async (batch) => unwrapApiResult(await getOrphanedFiles({
69
- body: {
70
- branchId,
71
- fileIds: batch
72
- },
73
- client: getClient()
74
- }));
75
- if (fileIds.length === 0) return request([]);
76
- const results = await processBatches(fileIds, async (batch) => [await request(batch)]);
77
- const orphanedFiles = new Map(results[0].orphanedFiles.map((file) => [file.fileId, file]));
78
- for (const result of results.slice(1)) {
79
- const batchFileIds = new Set(result.orphanedFiles.map((file) => file.fileId));
80
- for (const fileId of orphanedFiles.keys()) if (!batchFileIds.has(fileId)) orphanedFiles.delete(fileId);
81
- }
82
- return { orphanedFiles: [...orphanedFiles.values()] };
83
- },
84
- async processFileMoves(moves, options) {
85
- const result = await processBatches(moves, async (batch) => {
86
- return unwrapApiResult(await processFileMoves({
87
- body: {
88
- branchId: options.branchId,
89
- moves: batch
90
- },
91
- client: getClient()
92
- })).results;
93
- });
94
- const succeeded = result.filter(({ success }) => success).length;
95
- return {
96
- results: result,
97
- summary: {
98
- total: moves.length,
99
- succeeded,
100
- failed: result.length - succeeded
101
- }
102
- };
13
+ return loadProjectInfo(void 0, timeoutMs);
103
14
  }
104
15
  };
105
16
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","names":[],"sources":["../../src/utils/api.ts"],"sourcesContent":["import type { CustomMapping } from '@generaltranslation/format/types';\nimport {\n createApiClient,\n createProject,\n createTag,\n getBranchInfo,\n getOrphanedFiles,\n getProjectInfo,\n getTranslationJobInfo,\n processBatches,\n processFileMoves,\n publishFiles,\n submitUserEditDiffs,\n type ApiClientConfig,\n type CreateProjectData,\n type CreateTagData,\n type GetBranchInfoData,\n type ProcessFileMovesData,\n type PublishFilesData,\n type SubmitUserEditDiffsData,\n} from 'generaltranslation/api';\nimport {\n createGtApiAdapter,\n unwrapApiResult,\n} from 'generaltranslation/internal';\n\nconst {\n configure: configureSharedApi,\n getClient,\n getClientConfig,\n ...sharedApi\n} = createGtApiAdapter();\n\nexport function configureApiClient(\n config: ApiClientConfig & { customMapping?: CustomMapping }\n): void {\n configureSharedApi(config);\n}\n\nexport const api = {\n ...sharedApi,\n async queryBranchData(body: GetBranchInfoData['body']) {\n return unwrapApiResult(await getBranchInfo({ body, client: getClient() }));\n },\n\n async checkJobStatus(jobIds: string[]) {\n return unwrapApiResult(\n await getTranslationJobInfo({\n body: { jobIds },\n client: getClient(),\n })\n );\n },\n\n async getProjectInfo(timeoutMs: number) {\n const config = getClientConfig();\n if (!config.projectId) {\n throw new Error('Project ID is required to fetch project information');\n }\n const projectInfoClient = createApiClient({ ...config, timeoutMs });\n return unwrapApiResult(\n await getProjectInfo({\n client: projectInfoClient,\n path: { projectId: config.projectId },\n })\n );\n },\n\n async publishFiles(files: PublishFilesData['body']['files']) {\n return unwrapApiResult(\n await publishFiles({ body: { files }, client: getClient() })\n );\n },\n\n async submitUserEditDiffs(body: SubmitUserEditDiffsData['body']) {\n return processBatches(body.diffs, async (diffs) => [\n unwrapApiResult(\n await submitUserEditDiffs({\n body: {\n projectId: body.projectId,\n diffs: diffs.map((diff) => ({\n ...diff,\n locale: sharedApi.resolveCanonicalLocale(diff.locale),\n })),\n },\n client: getClient(),\n })\n ),\n ]);\n },\n\n async createTag(body: CreateTagData['body']) {\n return unwrapApiResult(await createTag({ body, client: getClient() }));\n },\n\n async createProject(\n orgId: CreateProjectData['path']['orgId'],\n body: CreateProjectData['body']\n ) {\n return unwrapApiResult(\n await createProject({\n path: { orgId },\n body: {\n ...body,\n defaultLocale: sharedApi.resolveCanonicalLocale(body.defaultLocale),\n },\n client: getClient(),\n })\n );\n },\n\n // ponytail: duplicates core/src/translate/getOrphanedFiles.ts batching +\n // intersection; delete one copy when utils/gt.ts is removed.\n async getOrphanedFiles(branchId: string, fileIds: string[]) {\n const request = async (batch: string[]) =>\n unwrapApiResult(\n await getOrphanedFiles({\n body: { branchId, fileIds: batch },\n client: getClient(),\n })\n );\n\n if (fileIds.length === 0) return request([]);\n\n const results = await processBatches(fileIds, async (batch) => [\n await request(batch),\n ]);\n const orphanedFiles = new Map(\n results[0].orphanedFiles.map((file) => [file.fileId, file])\n );\n for (const result of results.slice(1)) {\n const batchFileIds = new Set(\n result.orphanedFiles.map((file) => file.fileId)\n );\n for (const fileId of orphanedFiles.keys()) {\n if (!batchFileIds.has(fileId)) orphanedFiles.delete(fileId);\n }\n }\n return { orphanedFiles: [...orphanedFiles.values()] };\n },\n\n async processFileMoves(\n moves: ProcessFileMovesData['body']['moves'],\n options: Pick<ProcessFileMovesData['body'], 'branchId'>\n ) {\n const result = await processBatches(moves, async (batch) => {\n const response = unwrapApiResult(\n await processFileMoves({\n body: { branchId: options.branchId, moves: batch },\n client: getClient(),\n })\n );\n return response.results;\n });\n const succeeded = result.filter(({ success }) => success).length;\n\n return {\n results: result,\n summary: {\n total: moves.length,\n succeeded,\n failed: result.length - succeeded,\n },\n };\n },\n};\n\nexport type ApiClient = typeof api;\n"],"mappings":"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"}
1
+ {"version":3,"file":"api.js","names":[],"sources":["../../src/utils/api.ts"],"sourcesContent":["import type { CustomMapping } from '@generaltranslation/format/types';\nimport type { ApiClientConfig } from 'generaltranslation/api';\nimport { createGtApiAdapter } from 'generaltranslation/internal';\n\nconst {\n configure: configureSharedApi,\n getClient: _getClient,\n loadJobStatuses,\n loadProjectInfo,\n ...sharedApi\n} = createGtApiAdapter();\n\nexport function configureApiClient(\n config: ApiClientConfig & { customMapping?: CustomMapping }\n): void {\n configureSharedApi(config);\n}\n\n// CLI keeps the raw service views: unaliased project locales and nullable\n// job errors, plus per-request cancellation for polling.\nexport const api = {\n ...sharedApi,\n\n async checkJobStatus(jobIds: string[], signal?: AbortSignal) {\n return loadJobStatuses(jobIds, { signal });\n },\n\n async getProjectInfo(timeoutMs: number) {\n return loadProjectInfo(undefined, timeoutMs);\n },\n};\n\nexport type ApiClient = typeof api;\n"],"mappings":";;AAIA,MAAM,EACJ,WAAW,oBACX,WAAW,YACX,iBACA,iBACA,GAAG,cACD,oBAAoB;AAExB,SAAgB,mBACd,QACM;AACN,oBAAmB,OAAO;;AAK5B,MAAa,MAAM;CACjB,GAAG;CAEH,MAAM,eAAe,QAAkB,QAAsB;AAC3D,SAAO,gBAAgB,QAAQ,EAAE,QAAQ,CAAC;;CAG5C,MAAM,eAAe,WAAmB;AACtC,SAAO,gBAAgB,KAAA,GAAW,UAAU;;CAE/C"}
@@ -1,16 +1,43 @@
1
1
  import { Settings, SupportedFrameworks } from '../types/index.js';
2
- type Credentials = {
3
- apiKeys: ApiKey[];
2
+ export type Credentials = {
3
+ apiKey: string;
4
4
  projectId: string;
5
5
  };
6
- type ApiKey = {
7
- key: string;
8
- type: 'development' | 'production';
6
+ /** Names of the runtime variables init writes for this framework. */
7
+ export declare function getDevelopmentEnvNames(framework?: SupportedFrameworks): {
8
+ projectId: string;
9
+ devApiKey: string;
10
+ };
11
+ /**
12
+ * Whether the project already has a runtime key: the framework's development
13
+ * key, or an explicit production key for server runtimes (gt-next, gt-node).
14
+ * Browser frameworks only read their prefixed key, so there `settings.apiKey`
15
+ * is tooling auth alone. `settings.projectId` already resolves every
16
+ * framework prefix. Login is checked separately.
17
+ */
18
+ export declare function areCredentialsSet(settings: Pick<Settings, 'projectId' | 'apiKey'>, framework?: SupportedFrameworks): boolean;
19
+ /**
20
+ * Where .env.local content lives and its mode. Follows an existing symlink so
21
+ * its referent is replaced, never the link itself; anything but a regular
22
+ * file (dangling link, directory) fails before any write.
23
+ */
24
+ declare function resolveEnvFile(envFile: string): Promise<{
25
+ target: string;
26
+ mode: number;
27
+ } | undefined>;
28
+ type GitExposure = 'no-repository' | 'tracked' | 'ignored' | 'unignored';
29
+ type CredentialsEnvFile = {
30
+ envFile: string;
31
+ existing: Awaited<ReturnType<typeof resolveEnvFile>>;
32
+ exposure: GitExposure;
9
33
  };
10
- export declare function retrieveCredentials(settings: Settings, keyType: 'development' | 'production' | 'all'): Promise<Credentials>;
11
- export declare function generateCredentialsSession(url: string, keyType: 'development' | 'production' | 'all'): Promise<{
12
- sessionId: string;
13
- }>;
14
- export declare function areCredentialsSet(): string | undefined;
34
+ /**
35
+ * Everything that must hold before credentials may be saved to .env.local,
36
+ * so callers can fail before minting a key: the path is a regular file (or a
37
+ * link to one) or absent, and neither it nor a link's referent is tracked by
38
+ * Git. A referent inside any worktree must already be ignored there; only
39
+ * .env.local itself gets an ignore rule added, by setCredentials.
40
+ */
41
+ export declare function inspectCredentialsEnvFile(cwd?: string): Promise<CredentialsEnvFile>;
15
42
  export declare function setCredentials(credentials: Credentials, framework?: SupportedFrameworks, cwd?: string): Promise<void>;
16
43
  export {};