gengo-ts 1.0.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.
@@ -0,0 +1,703 @@
1
+ import { T as Tier, J as JobType, A as Attachment, C as Currency, a as JobStatus, P as PaginationOptions, R as RejectionReason, F as FollowUp, b as Comment } from './common-Bk4hl8fX.js';
2
+ export { c as CommentAuthor } from './common-Bk4hl8fX.js';
3
+
4
+ /**
5
+ * HTTP client configuration
6
+ */
7
+ interface HttpClientConfig {
8
+ publicKey: string;
9
+ privateKey: string;
10
+ sandbox?: boolean;
11
+ timeout?: number;
12
+ }
13
+ /**
14
+ * HTTP client for making authenticated requests to the Gengo API
15
+ */
16
+ declare class HttpClient {
17
+ private readonly publicKey;
18
+ private readonly privateKey;
19
+ private readonly baseUrl;
20
+ private readonly timeout;
21
+ constructor(config: HttpClientConfig);
22
+ /**
23
+ * Makes an authenticated GET request
24
+ */
25
+ get<T>(path: string, params?: object): Promise<T>;
26
+ /**
27
+ * Makes an authenticated POST request
28
+ */
29
+ post<T>(path: string, data?: object): Promise<T>;
30
+ /**
31
+ * Makes an authenticated PUT request
32
+ */
33
+ put<T>(path: string, data?: object): Promise<T>;
34
+ /**
35
+ * Makes an authenticated DELETE request
36
+ */
37
+ delete<T>(path: string): Promise<T>;
38
+ /**
39
+ * Core request method that handles authentication, serialization, and error handling
40
+ */
41
+ private request;
42
+ }
43
+
44
+ /**
45
+ * Job input payload for creating translation jobs
46
+ */
47
+ interface JobInput {
48
+ /** Original body of text to be translated */
49
+ body_src: string;
50
+ /** Source language code (IETF format) */
51
+ lc_src: string;
52
+ /** Target language code (IETF format) */
53
+ lc_tgt: string;
54
+ /** Quality level */
55
+ tier: Tier;
56
+ /** Job title for internal reference */
57
+ slug: string;
58
+ /** Job type: 'text' (default) or 'file' */
59
+ type?: JobType;
60
+ /** File identifier from quote (required if type is 'file') */
61
+ identifier?: string;
62
+ /** Glossary ID to use for translation */
63
+ glossary_id?: number;
64
+ /** Position in job group (starts at 1) */
65
+ position?: number;
66
+ /** Force new translation even if duplicate exists */
67
+ force?: boolean;
68
+ /** Instructions or context for translator */
69
+ comment?: string;
70
+ /** File attachments for context */
71
+ attachments?: Attachment[];
72
+ /** Plus services (e.g., ['translation', 'edit']) */
73
+ services?: ('translation' | 'edit')[];
74
+ /** Purpose of translation */
75
+ purpose?: string;
76
+ /** Desired tone for translation */
77
+ tone?: string;
78
+ /** Use preferred translators */
79
+ use_preferred?: boolean;
80
+ /** Callback URL for job updates */
81
+ callback_url?: string;
82
+ /** Automatically approve on completion */
83
+ auto_approve?: boolean;
84
+ /** Custom client data (max 1KB) */
85
+ custom_data?: string;
86
+ /** Maximum character limit for translation */
87
+ max_chars?: number;
88
+ /** Group jobs from same language pair (default: true) */
89
+ as_group?: boolean;
90
+ }
91
+ /**
92
+ * Job response from the API
93
+ */
94
+ interface Job {
95
+ job_id: number;
96
+ order_id: number;
97
+ body_src: string;
98
+ body_tgt: string;
99
+ lc_src: string;
100
+ lc_tgt: string;
101
+ unit_count: number;
102
+ tier: Tier;
103
+ credits: number;
104
+ status: JobStatus;
105
+ eta: number;
106
+ ctime: number;
107
+ callback_url: string;
108
+ auto_approve: boolean;
109
+ custom_data: string;
110
+ slug: string;
111
+ currency: Currency;
112
+ file_url_src?: string;
113
+ file_url_tgt?: string;
114
+ file_download_ready?: boolean;
115
+ }
116
+ /**
117
+ * Minimal job info returned in list endpoints
118
+ */
119
+ interface JobSummary {
120
+ job_id: number;
121
+ ctime: number;
122
+ }
123
+ /**
124
+ * Revision entry for a job
125
+ */
126
+ interface Revision {
127
+ rev_id: number;
128
+ ctime: string;
129
+ }
130
+ /**
131
+ * Revision details
132
+ */
133
+ interface RevisionDetail {
134
+ body_tgt: string;
135
+ ctime: string;
136
+ }
137
+ /**
138
+ * Feedback for a job
139
+ */
140
+ interface Feedback {
141
+ for_translator: string;
142
+ rating: number;
143
+ }
144
+ /**
145
+ * Action to approve a job
146
+ */
147
+ interface ApproveAction {
148
+ action: 'approve';
149
+ /** Rating 1-5 */
150
+ rating?: 1 | 2 | 3 | 4 | 5;
151
+ /** Comment for translator */
152
+ for_translator?: string;
153
+ /** Private comment for Gengo staff */
154
+ for_mygengo?: string;
155
+ /** Allow public sharing */
156
+ public?: boolean;
157
+ }
158
+ /**
159
+ * Action to request revision
160
+ */
161
+ interface ReviseAction {
162
+ action: 'revise';
163
+ /** Reason for revision request */
164
+ comment: string;
165
+ }
166
+ /**
167
+ * Action to reject a job
168
+ */
169
+ interface RejectAction {
170
+ action: 'reject';
171
+ reason: RejectionReason;
172
+ comment: string;
173
+ follow_up?: FollowUp;
174
+ }
175
+ /**
176
+ * Action to archive a job
177
+ */
178
+ interface ArchiveAction {
179
+ action: 'archive';
180
+ }
181
+ /**
182
+ * Union of all job actions
183
+ */
184
+ type JobAction = ApproveAction | ReviseAction | RejectAction | ArchiveAction;
185
+ /**
186
+ * Options for listing jobs
187
+ */
188
+ interface ListJobsOptions extends PaginationOptions {
189
+ status?: JobStatus;
190
+ }
191
+ /**
192
+ * Response from job creation
193
+ */
194
+ interface CreateJobsResponse {
195
+ order_id: number;
196
+ job_count: number;
197
+ credits_used: number;
198
+ currency: Currency;
199
+ jobs?: Record<string, Job[]>;
200
+ }
201
+ /**
202
+ * Bulk job action with job IDs
203
+ */
204
+ interface BulkApproveAction {
205
+ action: 'approve';
206
+ job_ids: Array<{
207
+ job_id: number;
208
+ rating?: 1 | 2 | 3 | 4 | 5;
209
+ for_translator?: string;
210
+ for_mygengo?: string;
211
+ public?: boolean;
212
+ }>;
213
+ }
214
+ /**
215
+ * Bulk revise action
216
+ */
217
+ interface BulkReviseAction {
218
+ action: 'revise';
219
+ job_ids: Array<{
220
+ job_id: number;
221
+ comment: string;
222
+ }>;
223
+ }
224
+ /**
225
+ * Bulk reject action
226
+ */
227
+ interface BulkRejectAction {
228
+ action: 'reject';
229
+ job_ids: Array<{
230
+ job_id: number;
231
+ reason: RejectionReason;
232
+ comment: string;
233
+ follow_up?: FollowUp;
234
+ }>;
235
+ }
236
+ /**
237
+ * Bulk archive action
238
+ */
239
+ interface BulkArchiveAction {
240
+ action: 'archive';
241
+ job_ids: number[];
242
+ }
243
+ /**
244
+ * Union of bulk job actions
245
+ */
246
+ type BulkJobAction = BulkApproveAction | BulkReviseAction | BulkRejectAction | BulkArchiveAction;
247
+
248
+ /**
249
+ * Account statistics
250
+ */
251
+ interface AccountStats {
252
+ credits_spent: number;
253
+ user_since: number;
254
+ currency: Currency;
255
+ billing_type: string;
256
+ customer_type: string;
257
+ }
258
+ /**
259
+ * Account information
260
+ */
261
+ interface AccountMe {
262
+ email: string;
263
+ full_name: string;
264
+ display_name: string;
265
+ language_code: string;
266
+ }
267
+ /**
268
+ * Account balance
269
+ */
270
+ interface AccountBalance {
271
+ credits: number;
272
+ currency: Currency;
273
+ }
274
+ /**
275
+ * Preferred translator info
276
+ */
277
+ interface PreferredTranslator {
278
+ id: number;
279
+ last_login: number;
280
+ }
281
+ /**
282
+ * Preferred translators for a language pair
283
+ */
284
+ interface PreferredTranslatorGroup {
285
+ lc_src: string;
286
+ lc_tgt: string;
287
+ tier: Tier;
288
+ translators: PreferredTranslator[];
289
+ }
290
+
291
+ /**
292
+ * Order details
293
+ */
294
+ interface Order {
295
+ order_id: string;
296
+ total_credits: string;
297
+ total_units: number;
298
+ total_jobs: string;
299
+ currency: Currency;
300
+ jobs_queued: number;
301
+ jobs_available: string[];
302
+ jobs_pending: string[];
303
+ jobs_reviewable: string[];
304
+ jobs_approved: string[];
305
+ jobs_revising: string[];
306
+ jobs_cancelled: string[];
307
+ jobs_held: string[];
308
+ }
309
+
310
+ /**
311
+ * Target language entry in glossary
312
+ */
313
+ type TargetLanguage = [number, string];
314
+ /**
315
+ * Glossary details
316
+ */
317
+ interface Glossary {
318
+ id: number;
319
+ customer_user_id: number;
320
+ source_language_id: number;
321
+ source_language_code: string;
322
+ target_languages: TargetLanguage[];
323
+ is_public: boolean;
324
+ unit_count: number;
325
+ title: string;
326
+ description: string | null;
327
+ status: number;
328
+ ctime: string;
329
+ }
330
+
331
+ /**
332
+ * Supported language
333
+ */
334
+ interface Language {
335
+ lc: string;
336
+ language: string;
337
+ localized_name: string;
338
+ unit_type: 'word' | 'character';
339
+ }
340
+ /**
341
+ * Language pair with pricing
342
+ */
343
+ interface LanguagePair {
344
+ lc_src: string;
345
+ lc_tgt: string;
346
+ tier: Tier;
347
+ unit_price: number;
348
+ currency: Currency;
349
+ }
350
+ /**
351
+ * Quote for a single job
352
+ */
353
+ interface JobQuote {
354
+ credits: number;
355
+ eta: number;
356
+ unit_count: number;
357
+ lc_src_detected?: string;
358
+ currency: Currency;
359
+ type: JobType;
360
+ custom_data?: string;
361
+ identifier?: string;
362
+ }
363
+ /**
364
+ * Quote error for a job
365
+ */
366
+ interface JobQuoteError {
367
+ err: {
368
+ code: number;
369
+ key: string;
370
+ filename?: string;
371
+ };
372
+ }
373
+ /**
374
+ * Response from quote endpoint
375
+ */
376
+ interface QuoteResponse {
377
+ jobs: Record<string, JobQuote | JobQuoteError>;
378
+ }
379
+ /**
380
+ * File job input for quotes
381
+ */
382
+ interface FileJobInput {
383
+ type: 'file';
384
+ lc_src: string;
385
+ lc_tgt: string;
386
+ tier: Tier;
387
+ file_path: string;
388
+ }
389
+ /**
390
+ * Unit count request item
391
+ */
392
+ interface UnitCountInput {
393
+ text: string;
394
+ lc: string;
395
+ }
396
+ /**
397
+ * Unit count response item
398
+ */
399
+ interface UnitCountResult {
400
+ text: string;
401
+ lc: string;
402
+ unit_type: 'word' | 'character';
403
+ unit_count: number;
404
+ }
405
+ /**
406
+ * Partial job input for quotes (only required fields)
407
+ */
408
+ type QuoteJobInput = Pick<JobInput, 'body_src' | 'lc_src' | 'lc_tgt' | 'tier'> & Partial<Pick<JobInput, 'type' | 'custom_data' | 'services' | 'slug' | 'comment' | 'callback_url'>>;
409
+
410
+ /**
411
+ * Account resource for managing account information
412
+ */
413
+ declare class AccountResource {
414
+ private readonly http;
415
+ constructor(http: HttpClient);
416
+ /**
417
+ * Retrieves account statistics such as orders made and credits spent
418
+ */
419
+ getStats(): Promise<AccountStats>;
420
+ /**
421
+ * Retrieves account information such as email and display name
422
+ */
423
+ getMe(): Promise<AccountMe>;
424
+ /**
425
+ * Retrieves account balance in credits
426
+ */
427
+ getBalance(): Promise<AccountBalance>;
428
+ /**
429
+ * Retrieves list of preferred translators set by user
430
+ */
431
+ getPreferredTranslators(): Promise<PreferredTranslatorGroup[]>;
432
+ }
433
+
434
+ /**
435
+ * Jobs payload for submission
436
+ */
437
+ interface JobsPayload {
438
+ jobs: Record<string, JobInput>;
439
+ comment?: string;
440
+ }
441
+ /**
442
+ * Jobs resource for managing translation jobs
443
+ */
444
+ declare class JobsResource {
445
+ private readonly http;
446
+ constructor(http: HttpClient);
447
+ /**
448
+ * Submits a job or group of jobs for translation
449
+ * @param jobs - Record of job keys to job inputs, or a JobsPayload with optional order comment
450
+ */
451
+ create(jobs: Record<string, JobInput> | JobsPayload): Promise<CreateJobsResponse>;
452
+ /**
453
+ * Retrieves a list of recent jobs filtered by parameters
454
+ */
455
+ list(options?: ListJobsOptions): Promise<JobSummary[]>;
456
+ /**
457
+ * Retrieves a specific job by ID
458
+ */
459
+ get(id: number | string): Promise<{
460
+ job: Job;
461
+ }>;
462
+ /**
463
+ * Retrieves multiple jobs by their IDs
464
+ * @param ids - Array of job IDs or comma-separated string
465
+ */
466
+ getMany(ids: (number | string)[] | string): Promise<{
467
+ jobs: Job[];
468
+ }>;
469
+ /**
470
+ * Updates a job (approve, revise, reject, or archive)
471
+ */
472
+ update(id: number | string, action: JobAction): Promise<void>;
473
+ /**
474
+ * Updates multiple jobs with the same action
475
+ */
476
+ updateMany(action: BulkJobAction): Promise<void>;
477
+ /**
478
+ * Cancels a job (only if not yet started by translator)
479
+ */
480
+ cancel(id: number | string): Promise<void>;
481
+ /**
482
+ * Gets list of revisions for a job
483
+ */
484
+ getRevisions(id: number | string): Promise<{
485
+ job_id: number;
486
+ revisions: Revision[];
487
+ }>;
488
+ /**
489
+ * Gets a specific revision for a job
490
+ */
491
+ getRevision(id: number | string, revisionId: number | string): Promise<{
492
+ revision: RevisionDetail;
493
+ }>;
494
+ /**
495
+ * Retrieves feedback submitted for a job
496
+ */
497
+ getFeedback(id: number | string): Promise<{
498
+ feedback: Feedback;
499
+ }>;
500
+ /**
501
+ * Retrieves the comment thread for a job
502
+ */
503
+ getComments(id: number | string): Promise<{
504
+ thread: Comment[];
505
+ }>;
506
+ /**
507
+ * Submits a new comment to the job's comment thread
508
+ */
509
+ addComment(id: number | string, body: string): Promise<void>;
510
+ }
511
+
512
+ /**
513
+ * Orders resource for managing translation orders
514
+ */
515
+ declare class OrdersResource {
516
+ private readonly http;
517
+ constructor(http: HttpClient);
518
+ /**
519
+ * Retrieves an order by ID with job status breakdown
520
+ */
521
+ get(id: number | string): Promise<{
522
+ order: Order;
523
+ }>;
524
+ /**
525
+ * Cancels all available jobs in an order
526
+ * Note: This will not cancel jobs that are already in progress
527
+ */
528
+ cancel(id: number | string): Promise<{
529
+ order: Order;
530
+ }>;
531
+ /**
532
+ * Retrieves the comment thread for an order
533
+ */
534
+ getComments(id: number | string): Promise<{
535
+ thread: Comment[];
536
+ }>;
537
+ /**
538
+ * Submits a new comment to the order's comment thread
539
+ */
540
+ addComment(id: number | string, body: string): Promise<void>;
541
+ }
542
+
543
+ /**
544
+ * Glossary resource for managing translation glossaries
545
+ */
546
+ declare class GlossaryResource {
547
+ private readonly http;
548
+ constructor(http: HttpClient);
549
+ /**
550
+ * Retrieves all glossaries belonging to the authenticated user
551
+ */
552
+ list(): Promise<Glossary[]>;
553
+ /**
554
+ * Retrieves a specific glossary by ID
555
+ */
556
+ get(id: number | string): Promise<Glossary>;
557
+ }
558
+
559
+ /**
560
+ * Service resource for language and pricing information
561
+ */
562
+ declare class ServiceResource {
563
+ private readonly http;
564
+ constructor(http: HttpClient);
565
+ /**
566
+ * Returns a list of supported languages and their language codes
567
+ */
568
+ getLanguages(): Promise<Language[]>;
569
+ /**
570
+ * Returns supported translation language pairs with pricing
571
+ * @param lcSrc - Optional source language code to filter pairs
572
+ */
573
+ getLanguagePairs(lcSrc?: string): Promise<LanguagePair[]>;
574
+ /**
575
+ * Returns credit quote and unit count for text jobs
576
+ */
577
+ getQuote(jobs: Record<string, QuoteJobInput>): Promise<QuoteResponse>;
578
+ /**
579
+ * Uploads files and returns quotes with identifiers for ordering
580
+ * Note: File upload requires multipart/form-data which is not yet implemented.
581
+ * Use the Gengo dashboard for file jobs, or implement custom file upload logic.
582
+ */
583
+ getFileQuote(_jobs: Record<string, {
584
+ type: 'file';
585
+ lc_src: string;
586
+ lc_tgt: string;
587
+ tier: string;
588
+ }>): Promise<QuoteResponse>;
589
+ }
590
+
591
+ /**
592
+ * Configuration options for the Gengo client
593
+ */
594
+ interface GengoClientConfig {
595
+ /** Your Gengo API public key */
596
+ publicKey: string;
597
+ /** Your Gengo API private key */
598
+ privateKey: string;
599
+ /** Use sandbox environment (default: false) */
600
+ sandbox?: boolean;
601
+ /** Request timeout in milliseconds (default: 30000) */
602
+ timeout?: number;
603
+ }
604
+ /**
605
+ * Gengo API client for human translation services
606
+ *
607
+ * @example
608
+ * ```typescript
609
+ * import { GengoClient } from 'gengo-ts';
610
+ *
611
+ * const client = new GengoClient({
612
+ * publicKey: 'your_public_key',
613
+ * privateKey: 'your_private_key',
614
+ * sandbox: true,
615
+ * });
616
+ *
617
+ * // Get account balance
618
+ * const balance = await client.account.getBalance();
619
+ *
620
+ * // Submit translation jobs
621
+ * const order = await client.jobs.create({
622
+ * job_1: {
623
+ * body_src: 'Hello, world!',
624
+ * lc_src: 'en',
625
+ * lc_tgt: 'ja',
626
+ * tier: 'standard',
627
+ * slug: 'greeting',
628
+ * },
629
+ * });
630
+ * ```
631
+ */
632
+ declare class GengoClient {
633
+ private readonly http;
634
+ /** Account information and statistics */
635
+ readonly account: AccountResource;
636
+ /** Translation jobs management */
637
+ readonly jobs: JobsResource;
638
+ /** Translation orders management */
639
+ readonly orders: OrdersResource;
640
+ /** Glossary management */
641
+ readonly glossary: GlossaryResource;
642
+ /** Language and pricing services */
643
+ readonly service: ServiceResource;
644
+ constructor(config: GengoClientConfig);
645
+ }
646
+
647
+ /**
648
+ * Base error class for all Gengo API errors
649
+ */
650
+ declare class GengoError extends Error {
651
+ readonly code: number;
652
+ constructor(message: string, code?: number);
653
+ }
654
+ /**
655
+ * Authentication failed (invalid API keys, missing signature, etc.)
656
+ * Error codes: 1000, 1100, 1150
657
+ */
658
+ declare class GengoAuthError extends GengoError {
659
+ constructor(message: string, code?: number);
660
+ }
661
+ /**
662
+ * Validation errors for request parameters
663
+ * Error codes: 1200-1951
664
+ */
665
+ declare class GengoValidationError extends GengoError {
666
+ constructor(message: string, code?: number);
667
+ }
668
+ /**
669
+ * Resource not found or unauthorized access
670
+ * Error codes: 2100, 2200, 2600, 2750
671
+ */
672
+ declare class GengoNotFoundError extends GengoError {
673
+ constructor(message: string, code?: number);
674
+ }
675
+ /**
676
+ * Rate limit exceeded
677
+ * HTTP status: 429
678
+ */
679
+ declare class GengoRateLimitError extends GengoError {
680
+ constructor(message?: string);
681
+ }
682
+ /**
683
+ * Insufficient credits in account
684
+ * Error code: 2700
685
+ */
686
+ declare class GengoInsufficientCreditsError extends GengoError {
687
+ constructor(message?: string);
688
+ }
689
+ /**
690
+ * Network or connection errors
691
+ */
692
+ declare class GengoNetworkError extends GengoError {
693
+ constructor(message: string, cause?: Error);
694
+ }
695
+ /**
696
+ * Job is not in the correct state for the requested action
697
+ * Error codes: 2250, 2251, 2252, 2650
698
+ */
699
+ declare class GengoJobStateError extends GengoError {
700
+ constructor(message: string, code?: number);
701
+ }
702
+
703
+ export { type AccountBalance, type AccountMe, type AccountStats, type ApproveAction, type ArchiveAction, Attachment, type BulkApproveAction, type BulkArchiveAction, type BulkJobAction, type BulkRejectAction, type BulkReviseAction, Comment, type CreateJobsResponse, Currency, type Feedback, type FileJobInput, FollowUp, GengoAuthError, GengoClient, type GengoClientConfig, GengoError, GengoInsufficientCreditsError, GengoJobStateError, GengoNetworkError, GengoNotFoundError, GengoRateLimitError, GengoValidationError, type Glossary, type Job, type JobAction, type JobInput, type JobQuote, type JobQuoteError, JobStatus, type JobSummary, JobType, type Language, type LanguagePair, type ListJobsOptions, type Order, PaginationOptions, type PreferredTranslator, type PreferredTranslatorGroup, type QuoteJobInput, type QuoteResponse, type RejectAction, RejectionReason, type ReviseAction, type Revision, type RevisionDetail, type TargetLanguage, Tier, type UnitCountInput, type UnitCountResult };