chub-dev 0.1.0 → 0.1.2-beta.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 (139) hide show
  1. package/README.md +55 -0
  2. package/bin/chub-mcp +2 -0
  3. package/dist/airtable/docs/database/javascript/DOC.md +1437 -0
  4. package/dist/airtable/docs/database/python/DOC.md +1735 -0
  5. package/dist/amplitude/docs/analytics/javascript/DOC.md +1282 -0
  6. package/dist/amplitude/docs/analytics/python/DOC.md +1199 -0
  7. package/dist/anthropic/docs/claude-api/javascript/DOC.md +503 -0
  8. package/dist/anthropic/docs/claude-api/python/DOC.md +389 -0
  9. package/dist/asana/docs/tasks/DOC.md +1396 -0
  10. package/dist/assemblyai/docs/transcription/DOC.md +1043 -0
  11. package/dist/atlassian/docs/confluence/javascript/DOC.md +1347 -0
  12. package/dist/atlassian/docs/confluence/python/DOC.md +1604 -0
  13. package/dist/auth0/docs/identity/javascript/DOC.md +968 -0
  14. package/dist/auth0/docs/identity/python/DOC.md +1199 -0
  15. package/dist/aws/docs/s3/javascript/DOC.md +1773 -0
  16. package/dist/aws/docs/s3/python/DOC.md +1807 -0
  17. package/dist/binance/docs/trading/javascript/DOC.md +1315 -0
  18. package/dist/binance/docs/trading/python/DOC.md +1454 -0
  19. package/dist/braintree/docs/gateway/javascript/DOC.md +1278 -0
  20. package/dist/braintree/docs/gateway/python/DOC.md +1179 -0
  21. package/dist/chromadb/docs/embeddings-db/javascript/DOC.md +1263 -0
  22. package/dist/chromadb/docs/embeddings-db/python/DOC.md +1707 -0
  23. package/dist/clerk/docs/auth/javascript/DOC.md +1220 -0
  24. package/dist/clerk/docs/auth/python/DOC.md +274 -0
  25. package/dist/cloudflare/docs/workers/javascript/DOC.md +918 -0
  26. package/dist/cloudflare/docs/workers/python/DOC.md +994 -0
  27. package/dist/cockroachdb/docs/distributed-db/DOC.md +1500 -0
  28. package/dist/cohere/docs/llm/DOC.md +1335 -0
  29. package/dist/datadog/docs/monitoring/javascript/DOC.md +1740 -0
  30. package/dist/datadog/docs/monitoring/python/DOC.md +1815 -0
  31. package/dist/deepgram/docs/speech/javascript/DOC.md +885 -0
  32. package/dist/deepgram/docs/speech/python/DOC.md +685 -0
  33. package/dist/deepl/docs/translation/javascript/DOC.md +887 -0
  34. package/dist/deepl/docs/translation/python/DOC.md +944 -0
  35. package/dist/deepseek/docs/llm/DOC.md +1220 -0
  36. package/dist/directus/docs/headless-cms/javascript/DOC.md +1128 -0
  37. package/dist/directus/docs/headless-cms/python/DOC.md +1276 -0
  38. package/dist/discord/docs/bot/javascript/DOC.md +1090 -0
  39. package/dist/discord/docs/bot/python/DOC.md +1130 -0
  40. package/dist/elasticsearch/docs/search/DOC.md +1634 -0
  41. package/dist/elevenlabs/docs/text-to-speech/javascript/DOC.md +336 -0
  42. package/dist/elevenlabs/docs/text-to-speech/python/DOC.md +552 -0
  43. package/dist/firebase/docs/auth/DOC.md +1015 -0
  44. package/dist/gemini/docs/genai/javascript/DOC.md +691 -0
  45. package/dist/gemini/docs/genai/python/DOC.md +555 -0
  46. package/dist/github/docs/octokit/DOC.md +1560 -0
  47. package/dist/google/docs/bigquery/javascript/DOC.md +1688 -0
  48. package/dist/google/docs/bigquery/python/DOC.md +1503 -0
  49. package/dist/hubspot/docs/crm/javascript/DOC.md +1805 -0
  50. package/dist/hubspot/docs/crm/python/DOC.md +2033 -0
  51. package/dist/huggingface/docs/transformers/DOC.md +948 -0
  52. package/dist/intercom/docs/messaging/javascript/DOC.md +1844 -0
  53. package/dist/intercom/docs/messaging/python/DOC.md +1797 -0
  54. package/dist/jira/docs/issues/javascript/DOC.md +1420 -0
  55. package/dist/jira/docs/issues/python/DOC.md +1492 -0
  56. package/dist/kafka/docs/streaming/javascript/DOC.md +1671 -0
  57. package/dist/kafka/docs/streaming/python/DOC.md +1464 -0
  58. package/dist/landingai-ade/docs/api/DOC.md +620 -0
  59. package/dist/landingai-ade/docs/sdk/python/DOC.md +489 -0
  60. package/dist/landingai-ade/docs/sdk/typescript/DOC.md +542 -0
  61. package/dist/landingai-ade/skills/SKILL.md +489 -0
  62. package/dist/launchdarkly/docs/feature-flags/javascript/DOC.md +1191 -0
  63. package/dist/launchdarkly/docs/feature-flags/python/DOC.md +1671 -0
  64. package/dist/linear/docs/tracker/DOC.md +1554 -0
  65. package/dist/livekit/docs/realtime/javascript/DOC.md +303 -0
  66. package/dist/livekit/docs/realtime/python/DOC.md +163 -0
  67. package/dist/mailchimp/docs/marketing/DOC.md +1420 -0
  68. package/dist/meilisearch/docs/search/DOC.md +1241 -0
  69. package/dist/microsoft/docs/onedrive/javascript/DOC.md +1421 -0
  70. package/dist/microsoft/docs/onedrive/python/DOC.md +1549 -0
  71. package/dist/mongodb/docs/atlas/DOC.md +2041 -0
  72. package/dist/notion/docs/workspace-api/javascript/DOC.md +1435 -0
  73. package/dist/notion/docs/workspace-api/python/DOC.md +1400 -0
  74. package/dist/okta/docs/identity/javascript/DOC.md +1171 -0
  75. package/dist/okta/docs/identity/python/DOC.md +1401 -0
  76. package/dist/openai/docs/chat/javascript/DOC.md +407 -0
  77. package/dist/openai/docs/chat/python/DOC.md +568 -0
  78. package/dist/paypal/docs/checkout/DOC.md +278 -0
  79. package/dist/pinecone/docs/sdk/javascript/DOC.md +984 -0
  80. package/dist/pinecone/docs/sdk/python/DOC.md +1395 -0
  81. package/dist/plaid/docs/banking/javascript/DOC.md +1163 -0
  82. package/dist/plaid/docs/banking/python/DOC.md +1203 -0
  83. package/dist/playwright-community/skills/login-flows/SKILL.md +108 -0
  84. package/dist/postmark/docs/transactional-email/DOC.md +1168 -0
  85. package/dist/prisma/docs/orm/javascript/DOC.md +1419 -0
  86. package/dist/prisma/docs/orm/python/DOC.md +1317 -0
  87. package/dist/qdrant/docs/vector-search/javascript/DOC.md +1221 -0
  88. package/dist/qdrant/docs/vector-search/python/DOC.md +1653 -0
  89. package/dist/rabbitmq/docs/message-queue/javascript/DOC.md +1193 -0
  90. package/dist/rabbitmq/docs/message-queue/python/DOC.md +1243 -0
  91. package/dist/razorpay/docs/payments/javascript/DOC.md +1219 -0
  92. package/dist/razorpay/docs/payments/python/DOC.md +1330 -0
  93. package/dist/redis/docs/key-value/javascript/DOC.md +1851 -0
  94. package/dist/redis/docs/key-value/python/DOC.md +2054 -0
  95. package/dist/registry.json +2817 -0
  96. package/dist/replicate/docs/model-hosting/DOC.md +1318 -0
  97. package/dist/resend/docs/email/DOC.md +1271 -0
  98. package/dist/salesforce/docs/crm/javascript/DOC.md +1241 -0
  99. package/dist/salesforce/docs/crm/python/DOC.md +1183 -0
  100. package/dist/search-index.json +1 -0
  101. package/dist/sendgrid/docs/email-api/javascript/DOC.md +371 -0
  102. package/dist/sendgrid/docs/email-api/python/DOC.md +656 -0
  103. package/dist/sentry/docs/error-tracking/javascript/DOC.md +1073 -0
  104. package/dist/sentry/docs/error-tracking/python/DOC.md +1309 -0
  105. package/dist/shopify/docs/storefront/DOC.md +457 -0
  106. package/dist/slack/docs/workspace/javascript/DOC.md +933 -0
  107. package/dist/slack/docs/workspace/python/DOC.md +271 -0
  108. package/dist/square/docs/payments/javascript/DOC.md +1855 -0
  109. package/dist/square/docs/payments/python/DOC.md +1728 -0
  110. package/dist/stripe/docs/api/DOC.md +1727 -0
  111. package/dist/stripe/docs/payments/DOC.md +1726 -0
  112. package/dist/stytch/docs/auth/javascript/DOC.md +1813 -0
  113. package/dist/stytch/docs/auth/python/DOC.md +1962 -0
  114. package/dist/supabase/docs/client/DOC.md +1606 -0
  115. package/dist/twilio/docs/messaging/python/DOC.md +469 -0
  116. package/dist/twilio/docs/messaging/typescript/DOC.md +946 -0
  117. package/dist/vercel/docs/platform/DOC.md +1940 -0
  118. package/dist/weaviate/docs/vector-db/javascript/DOC.md +1268 -0
  119. package/dist/weaviate/docs/vector-db/python/DOC.md +1388 -0
  120. package/dist/zendesk/docs/support/javascript/DOC.md +2150 -0
  121. package/dist/zendesk/docs/support/python/DOC.md +2297 -0
  122. package/package.json +22 -6
  123. package/skills/get-api-docs/SKILL.md +84 -0
  124. package/src/commands/annotate.js +83 -0
  125. package/src/commands/build.js +12 -1
  126. package/src/commands/feedback.js +150 -0
  127. package/src/commands/get.js +83 -42
  128. package/src/commands/search.js +7 -0
  129. package/src/index.js +43 -17
  130. package/src/lib/analytics.js +90 -0
  131. package/src/lib/annotations.js +57 -0
  132. package/src/lib/bm25.js +170 -0
  133. package/src/lib/cache.js +69 -6
  134. package/src/lib/config.js +8 -3
  135. package/src/lib/identity.js +99 -0
  136. package/src/lib/registry.js +103 -20
  137. package/src/lib/telemetry.js +86 -0
  138. package/src/mcp/server.js +177 -0
  139. package/src/mcp/tools.js +251 -0
@@ -0,0 +1,887 @@
1
+ ---
2
+ name: translation
3
+ description: "DeepL API client for JavaScript/TypeScript with text and document translation, glossary management, and language detection"
4
+ metadata:
5
+ languages: "javascript"
6
+ versions: "1.21.0"
7
+ updated-on: "2026-03-02"
8
+ source: maintainer
9
+ tags: "deepl,translation,language,localization,api"
10
+ ---
11
+
12
+ # DeepL API Coding Guidelines (JavaScript/TypeScript)
13
+
14
+ You are a DeepL API coding expert. Help me with writing code using the DeepL API calling the official libraries and SDKs.
15
+
16
+ ## Golden Rule: Use the Correct and Current SDK
17
+
18
+ Always use the official DeepL Node.js SDK for all DeepL API interactions. Do not use unofficial or deprecated libraries.
19
+
20
+ - **Library Name:** DeepL Node.js Client Library
21
+ - **NPM Package:** `deepl-node`
22
+ - **Current Version:** 1.21.0
23
+ - **Deprecated/Unofficial Packages:** `deepl`, `deepl-api`, `deepl-translate`
24
+
25
+ **Installation:**
26
+
27
+ ```bash
28
+ # Correct
29
+ npm install deepl-node
30
+
31
+ # Incorrect - unofficial packages
32
+ npm install deepl
33
+ npm install deepl-api
34
+ ```
35
+
36
+ **Import Patterns:**
37
+
38
+ ```javascript
39
+ // Correct - ES6 import
40
+ import * as deepl from 'deepl-node';
41
+
42
+ // Correct - CommonJS
43
+ const deepl = require('deepl-node');
44
+
45
+ // Incorrect
46
+ import DeepL from 'deepl';
47
+ import { translate } from 'deepl-api';
48
+ ```
49
+
50
+ ## Initialization and API Key
51
+
52
+ The DeepL library requires creating a `DeepLClient` instance with your authentication key for all API calls.
53
+
54
+ ### Getting an API Key
55
+
56
+ Create a DeepL API account to receive your authentication key. With a DeepL API Free account, you can translate up to 500,000 characters per month for free.
57
+
58
+ ### Basic Initialization
59
+
60
+ ```javascript
61
+ import * as deepl from 'deepl-node';
62
+
63
+ // Initialize with API key
64
+ const authKey = 'your-api-key-here'; // Replace with your actual key
65
+ const translator = new deepl.DeepLClient(authKey);
66
+ ```
67
+
68
+ ### Environment Variable Configuration
69
+
70
+ In production, always fetch the authentication key from environment variables:
71
+
72
+ ```javascript
73
+ import * as deepl from 'deepl-node';
74
+
75
+ const authKey = process.env.DEEPL_AUTH_KEY;
76
+ const translator = new deepl.DeepLClient(authKey);
77
+ ```
78
+
79
+ ### CommonJS Initialization
80
+
81
+ ```javascript
82
+ const deepl = require('deepl-node');
83
+
84
+ const authKey = process.env.DEEPL_AUTH_KEY;
85
+ const translator = new deepl.DeepLClient(authKey);
86
+ ```
87
+
88
+ ## Text Translation
89
+
90
+ ### Basic Translation
91
+
92
+ Translate a single text string from one language to another:
93
+
94
+ ```javascript
95
+ import * as deepl from 'deepl-node';
96
+
97
+ const authKey = process.env.DEEPL_AUTH_KEY;
98
+ const translator = new deepl.DeepLClient(authKey);
99
+
100
+ const result = await translator.translateText('Hello, world!', null, 'fr');
101
+ console.log(result.text); // 'Bonjour, le monde !'
102
+ ```
103
+
104
+ The `translateText` method signature:
105
+ - First parameter: text to translate (string or array of strings)
106
+ - Second parameter: source language (null for auto-detection, or language code like 'en')
107
+ - Third parameter: target language (required, e.g., 'fr', 'de', 'es')
108
+ - Fourth parameter (optional): options object
109
+
110
+ ### Auto-Detection of Source Language
111
+
112
+ Use `null` as the source language to automatically detect it:
113
+
114
+ ```javascript
115
+ const result = await translator.translateText('Hello, world!', null, 'de');
116
+ console.log(result.text); // 'Hallo, Welt!'
117
+ console.log(result.detectedSourceLang); // 'EN'
118
+ ```
119
+
120
+ ### Specifying Source Language
121
+
122
+ ```javascript
123
+ const result = await translator.translateText('Hello, world!', 'en', 'es');
124
+ console.log(result.text); // '¡Hola, mundo!'
125
+ ```
126
+
127
+ ### Multiple Texts Translation
128
+
129
+ Translate multiple texts in a single API call:
130
+
131
+ ```javascript
132
+ const texts = [
133
+ 'Hello, world!',
134
+ 'How are you?',
135
+ 'Good morning'
136
+ ];
137
+
138
+ const results = await translator.translateText(texts, null, 'ja');
139
+ results.forEach(result => {
140
+ console.log(result.text);
141
+ });
142
+ // 'こんにちは、世界!'
143
+ // 'お元気ですか?'
144
+ // 'おはようございます'
145
+ ```
146
+
147
+ ### TextResult Properties
148
+
149
+ Each translation result contains:
150
+
151
+ ```javascript
152
+ const result = await translator.translateText('Hello', null, 'de');
153
+
154
+ console.log(result.text); // Translated text: 'Hallo'
155
+ console.log(result.detectedSourceLang); // Source language: 'EN'
156
+ console.log(result.billedCharacters); // Characters charged
157
+ console.log(result.modelTypeUsed); // Model type if specified
158
+ ```
159
+
160
+ ## Translation Options
161
+
162
+ ### Formality Control
163
+
164
+ Control the formality level of translations for supported languages (DE, FR, IT, ES, NL, PL, PT-BR, PT-PT, JA, RU):
165
+
166
+ ```javascript
167
+ // Informal translation
168
+ const informal = await translator.translateText(
169
+ 'How are you?',
170
+ null,
171
+ 'de',
172
+ { formality: 'less' }
173
+ );
174
+ console.log(informal.text); // 'Wie geht es dir?'
175
+
176
+ // Formal translation
177
+ const formal = await translator.translateText(
178
+ 'How are you?',
179
+ null,
180
+ 'de',
181
+ { formality: 'more' }
182
+ );
183
+ console.log(formal.text); // 'Wie geht es Ihnen?'
184
+ ```
185
+
186
+ Formality options:
187
+ - `'less'` - informal language
188
+ - `'more'` - formal language
189
+ - `'default'` - standard formality
190
+ - `'prefer_less'` - informal if available, otherwise default
191
+ - `'prefer_more'` - formal if available, otherwise default
192
+
193
+ ### Context Parameter
194
+
195
+ Provide additional context to improve translation accuracy (not translated, not billed):
196
+
197
+ ```javascript
198
+ const result = await translator.translateText(
199
+ 'bank',
200
+ 'en',
201
+ 'de',
202
+ { context: 'financial institution' }
203
+ );
204
+ console.log(result.text); // 'Bank' (financial context)
205
+
206
+ const result2 = await translator.translateText(
207
+ 'bank',
208
+ 'en',
209
+ 'de',
210
+ { context: 'riverside' }
211
+ );
212
+ console.log(result2.text); // 'Ufer' (riverbank)
213
+ ```
214
+
215
+ ### Sentence Splitting Options
216
+
217
+ Control how text is split into sentences:
218
+
219
+ ```javascript
220
+ // Split by newlines and punctuation (default)
221
+ const result1 = await translator.translateText(
222
+ 'First sentence. Second sentence.',
223
+ null,
224
+ 'de',
225
+ { splitSentences: 'on' }
226
+ );
227
+
228
+ // No splitting
229
+ const result2 = await translator.translateText(
230
+ 'First sentence. Second sentence.',
231
+ null,
232
+ 'de',
233
+ { splitSentences: 'off' }
234
+ );
235
+
236
+ // Split by punctuation only (not newlines)
237
+ const result3 = await translator.translateText(
238
+ 'First sentence.\nSecond sentence.',
239
+ null,
240
+ 'de',
241
+ { splitSentences: 'nonewlines' }
242
+ );
243
+ ```
244
+
245
+ ### Preserve Formatting
246
+
247
+ Prevent automatic format correction:
248
+
249
+ ```javascript
250
+ const result = await translator.translateText(
251
+ 'Hello, world!',
252
+ null,
253
+ 'de',
254
+ { preserveFormatting: true }
255
+ );
256
+ // Preserves extra spaces
257
+ ```
258
+
259
+ ### Model Type Selection
260
+
261
+ Choose between quality-optimized and latency-optimized models:
262
+
263
+ ```javascript
264
+ // Quality-optimized (higher quality, slower)
265
+ const qualityResult = await translator.translateText(
266
+ 'Complex technical document',
267
+ 'en',
268
+ 'de',
269
+ { modelType: 'quality_optimized' }
270
+ );
271
+
272
+ // Latency-optimized (faster, still high quality)
273
+ const fastResult = await translator.translateText(
274
+ 'Simple message',
275
+ 'en',
276
+ 'de',
277
+ { modelType: 'latency_optimized' }
278
+ );
279
+
280
+ // Use best available
281
+ const result = await translator.translateText(
282
+ 'Text here',
283
+ 'en',
284
+ 'de',
285
+ { modelType: 'prefer_quality_optimized' }
286
+ );
287
+ ```
288
+
289
+ ### HTML and XML Tag Handling
290
+
291
+ Parse and preserve markup tags:
292
+
293
+ ```javascript
294
+ // HTML tag handling
295
+ const htmlResult = await translator.translateText(
296
+ '<p>Hello, <strong>world</strong>!</p>',
297
+ null,
298
+ 'de',
299
+ { tagHandling: 'html' }
300
+ );
301
+ console.log(htmlResult.text); // '<p>Hallo, <strong>Welt</strong>!</p>'
302
+
303
+ // XML tag handling
304
+ const xmlResult = await translator.translateText(
305
+ '<text>Hello, <emphasis>world</emphasis>!</text>',
306
+ null,
307
+ 'de',
308
+ { tagHandling: 'xml' }
309
+ );
310
+ ```
311
+
312
+ ### XML-Specific Options
313
+
314
+ Advanced XML handling options:
315
+
316
+ ```javascript
317
+ const result = await translator.translateText(
318
+ '<root><p>First paragraph</p><ignore>Do not translate</ignore></root>',
319
+ 'en',
320
+ 'de',
321
+ {
322
+ tagHandling: 'xml',
323
+ outlineDetection: false, // Disable automatic tag detection
324
+ splittingTags: ['p', 'div'], // Tags that split sentences
325
+ nonSplittingTags: ['span'], // Tags that don't split sentences
326
+ ignoreTags: ['ignore', 'code'] // Tags with untranslated content
327
+ }
328
+ );
329
+ ```
330
+
331
+ ## Document Translation
332
+
333
+ ### Basic Document Translation
334
+
335
+ Translate entire documents while preserving formatting:
336
+
337
+ ```javascript
338
+ import * as deepl from 'deepl-node';
339
+
340
+ const authKey = process.env.DEEPL_AUTH_KEY;
341
+ const translator = new deepl.DeepLClient(authKey);
342
+
343
+ // Translate document from file path to file path
344
+ await translator.translateDocument(
345
+ 'input.docx',
346
+ 'output.docx',
347
+ 'en',
348
+ 'de'
349
+ );
350
+ ```
351
+
352
+ ### Document Translation with Options
353
+
354
+ ```javascript
355
+ await translator.translateDocument(
356
+ 'Manual.docx',
357
+ 'Anleitung.docx',
358
+ 'en',
359
+ 'de',
360
+ {
361
+ formality: 'more',
362
+ glossary: 'glossary-id-here'
363
+ }
364
+ );
365
+ ```
366
+
367
+ ### Supported Document Formats
368
+
369
+ DeepL supports various document formats:
370
+ - **Text documents:** docx, pptx, pdf, htm, html, txt
371
+ - **Spreadsheets:** xlsx
372
+ - **Others:** Check DeepL API documentation for complete list
373
+
374
+ ### Document Translation Input/Output Formats
375
+
376
+ Documents can be provided as:
377
+ - File paths (strings)
378
+ - Streams or FileHandles
379
+ - Buffers (requires `filename` option)
380
+
381
+ ```javascript
382
+ // Using file paths
383
+ await translator.translateDocument(
384
+ 'input.pdf',
385
+ 'output.pdf',
386
+ 'en',
387
+ 'fr'
388
+ );
389
+
390
+ // Using streams
391
+ import * as fs from 'fs';
392
+
393
+ const inputStream = fs.createReadStream('input.docx');
394
+ const outputStream = fs.createWriteStream('output.docx');
395
+
396
+ await translator.translateDocument(
397
+ inputStream,
398
+ outputStream,
399
+ 'en',
400
+ 'de',
401
+ { filename: 'input.docx' }
402
+ );
403
+
404
+ // Using buffer
405
+ const buffer = fs.readFileSync('input.docx');
406
+ await translator.translateDocument(
407
+ buffer,
408
+ 'output.docx',
409
+ 'en',
410
+ 'es',
411
+ { filename: 'document.docx' }
412
+ );
413
+ ```
414
+
415
+ ### Document Minification
416
+
417
+ Reduce document size by compressing embedded media (supports docx, pptx):
418
+
419
+ ```javascript
420
+ await translator.translateDocument(
421
+ 'large_presentation.pptx',
422
+ 'output.pptx',
423
+ 'en',
424
+ 'de',
425
+ { enableDocumentMinification: true }
426
+ );
427
+ ```
428
+
429
+ Supported media types for minification: png, jpg, jpeg, emf, bmp, tiff, wdp, svg, gif, mp4, asf, avi, m4v, mpg, mpeg, wmv, mov, aiff, au, mid, midi, mp3, m4a, wav, wma
430
+
431
+ **Note:** Requires 2x file size temporary disk space.
432
+
433
+ ### Document Translation Error Handling
434
+
435
+ Handle errors and retrieve document handle for recovery:
436
+
437
+ ```javascript
438
+ try {
439
+ await translator.translateDocument(
440
+ 'Manual.docx',
441
+ 'Anleitung.docx',
442
+ 'en',
443
+ 'de'
444
+ );
445
+ } catch (error) {
446
+ if (error.documentHandle) {
447
+ const { documentId, documentKey } = error.documentHandle;
448
+ console.log(`Document ID: ${documentId}`);
449
+ console.log(`Document Key: ${documentKey}`);
450
+ // Use these to check status or download later
451
+ } else {
452
+ console.error('Translation failed:', error.message);
453
+ }
454
+ }
455
+ ```
456
+
457
+ ### Lower-Level Document Translation Methods
458
+
459
+ For advanced control over the document translation process:
460
+
461
+ ```javascript
462
+ // Upload document
463
+ const handle = await translator.uploadDocument(
464
+ 'input.docx',
465
+ 'en',
466
+ 'de'
467
+ );
468
+
469
+ // Check translation status
470
+ const status = await translator.getDocumentStatus(handle);
471
+ console.log(`Status: ${status.status}`);
472
+ console.log(`Billed characters: ${status.billedCharacters}`);
473
+
474
+ // Wait until translation is complete
475
+ await translator.isDocumentTranslationComplete(handle);
476
+
477
+ // Download translated document
478
+ await translator.downloadDocument(handle, 'output.docx');
479
+ ```
480
+
481
+ ### Polling Document Status
482
+
483
+ ```javascript
484
+ const handle = await translator.uploadDocument('input.pdf', 'en', 'fr');
485
+
486
+ // Poll until complete
487
+ while (true) {
488
+ const status = await translator.getDocumentStatus(handle);
489
+
490
+ if (status.status === 'done') {
491
+ await translator.downloadDocument(handle, 'output.pdf');
492
+ break;
493
+ } else if (status.status === 'error') {
494
+ throw new Error('Document translation failed');
495
+ }
496
+
497
+ // Wait before checking again
498
+ await new Promise(resolve => setTimeout(resolve, 5000));
499
+ }
500
+ ```
501
+
502
+ ## Glossaries
503
+
504
+ Glossaries allow you to specify custom translations for specific terms and phrases.
505
+
506
+ ### Creating Multilingual Glossaries
507
+
508
+ ```javascript
509
+ import * as deepl from 'deepl-node';
510
+
511
+ const authKey = process.env.DEEPL_AUTH_KEY;
512
+ const translator = new deepl.DeepLClient(authKey);
513
+
514
+ // Create glossary entries
515
+ const entries = new deepl.GlossaryEntries({
516
+ entries: {
517
+ 'artist': 'Maler',
518
+ 'prize': 'Gewinn'
519
+ }
520
+ });
521
+
522
+ // Create glossary
523
+ const glossary = await translator.createMultilingualGlossary(
524
+ 'My glossary',
525
+ [{
526
+ sourceLangCode: 'en',
527
+ targetLangCode: 'de',
528
+ entries: entries
529
+ }]
530
+ );
531
+
532
+ console.log(`Glossary ID: ${glossary.glossaryId}`);
533
+ console.log(`Created: ${glossary.creationTime}`);
534
+ ```
535
+
536
+ ### Creating Glossary from CSV
537
+
538
+ ```javascript
539
+ const fs = require('fs').promises;
540
+
541
+ // Read CSV file
542
+ const csvContent = await fs.readFile('glossary.csv', 'utf-8');
543
+
544
+ // CSV format:
545
+ // source,target
546
+ // artist,Maler
547
+ // prize,Gewinn
548
+
549
+ const glossary = await translator.createMultilingualGlossaryWithCsv(
550
+ 'CSV Glossary',
551
+ 'en',
552
+ 'de',
553
+ csvContent
554
+ );
555
+ ```
556
+
557
+ ### Listing Glossaries
558
+
559
+ ```javascript
560
+ const glossaries = await translator.listMultilingualGlossaries();
561
+
562
+ glossaries.forEach(g => {
563
+ console.log(`Name: ${g.name}`);
564
+ console.log(`ID: ${g.glossaryId}`);
565
+ console.log(`Created: ${g.creationTime}`);
566
+
567
+ g.dictionaries.forEach(dict => {
568
+ console.log(` ${dict.sourceLang} -> ${dict.targetLang}: ${dict.entryCount} entries`);
569
+ });
570
+ });
571
+ ```
572
+
573
+ ### Finding Specific Glossary
574
+
575
+ ```javascript
576
+ const glossaries = await translator.listMultilingualGlossaries();
577
+ const myGlossary = glossaries.find(g => g.name === 'My glossary');
578
+
579
+ if (myGlossary) {
580
+ console.log(`Found glossary: ${myGlossary.glossaryId}`);
581
+ }
582
+ ```
583
+
584
+ ### Using Glossaries in Translation
585
+
586
+ ```javascript
587
+ // Using glossary ID
588
+ const result = await translator.translateText(
589
+ 'The artist won the prize',
590
+ 'en',
591
+ 'de',
592
+ { glossary: 'glossary-id-here' }
593
+ );
594
+
595
+ // Using glossary object
596
+ const glossaries = await translator.listMultilingualGlossaries();
597
+ const myGlossary = glossaries[0];
598
+
599
+ const result2 = await translator.translateText(
600
+ 'The artist won the prize',
601
+ 'en',
602
+ 'de',
603
+ { glossary: myGlossary }
604
+ );
605
+
606
+ console.log(result2.text); // Uses custom translations from glossary
607
+ ```
608
+
609
+ ### Deleting Glossaries
610
+
611
+ ```javascript
612
+ // Delete by glossary object
613
+ const glossaries = await translator.listMultilingualGlossaries();
614
+ const glossaryToDelete = glossaries.find(g => g.name === 'Old glossary');
615
+ await translator.deleteMultilingualGlossary(glossaryToDelete.glossaryId);
616
+
617
+ // Delete by ID
618
+ await translator.deleteMultilingualGlossary('glossary-id-here');
619
+ ```
620
+
621
+ ### Glossary Supported Languages
622
+
623
+ Check which language pairs support glossaries:
624
+
625
+ ```javascript
626
+ const glossaryLanguages = await translator.getGlossaryLanguages();
627
+
628
+ glossaryLanguages.forEach(langPair => {
629
+ console.log(`${langPair.sourceLang} -> ${langPair.targetLang}`);
630
+ });
631
+ ```
632
+
633
+ ## Language Detection and Information
634
+
635
+ ### Detecting Language
636
+
637
+ Detect the language of a text without translating:
638
+
639
+ ```javascript
640
+ const detectedLang = await translator.detectLanguage('Bonjour, comment allez-vous?');
641
+ console.log(detectedLang); // 'fr'
642
+
643
+ // Detect from array of texts
644
+ const texts = ['Hello', 'Bonjour', 'Hola'];
645
+ const languages = await translator.detectLanguage(texts);
646
+ languages.forEach((lang, i) => {
647
+ console.log(`"${texts[i]}" is ${lang}`);
648
+ });
649
+ // "Hello" is en
650
+ // "Bonjour" is fr
651
+ // "Hola" is es
652
+ ```
653
+
654
+ ### Getting Supported Languages
655
+
656
+ ```javascript
657
+ // Get all target languages
658
+ const targetLanguages = await translator.getTargetLanguages();
659
+ targetLanguages.forEach(lang => {
660
+ console.log(`${lang.code}: ${lang.name}`);
661
+ if (lang.supportsFormality) {
662
+ console.log(' Supports formality');
663
+ }
664
+ });
665
+
666
+ // Get all source languages
667
+ const sourceLanguages = await translator.getSourceLanguages();
668
+ sourceLanguages.forEach(lang => {
669
+ console.log(`${lang.code}: ${lang.name}`);
670
+ });
671
+ ```
672
+
673
+ Language object properties:
674
+ - `code` - ISO 639-1 language code (e.g., 'en', 'de', 'fr')
675
+ - `name` - Display name (e.g., 'English', 'German', 'French')
676
+ - `supportsFormality` - Boolean (target languages only)
677
+
678
+ ## Usage Monitoring
679
+
680
+ ### Checking Account Usage
681
+
682
+ Monitor your character usage and account limits:
683
+
684
+ ```javascript
685
+ const usage = await translator.getUsage();
686
+
687
+ console.log(`Characters used: ${usage.character.count}`);
688
+ console.log(`Character limit: ${usage.character.limit}`);
689
+ console.log(`Document count: ${usage.document.count}`);
690
+ console.log(`Document limit: ${usage.document.limit}`);
691
+
692
+ // Calculate remaining characters
693
+ const remaining = usage.character.limit - usage.character.count;
694
+ console.log(`Remaining characters: ${remaining}`);
695
+ ```
696
+
697
+ ### Account Tiers
698
+
699
+ - **DeepL API Free:** 500,000 characters/month, up to 2 active API keys
700
+ - **DeepL API Pro:** Pay-as-you-go, up to 25 active API keys, cost control limits
701
+
702
+ ## Error Handling
703
+
704
+ ### Common Error Patterns
705
+
706
+ ```javascript
707
+ try {
708
+ const result = await translator.translateText('Hello', null, 'de');
709
+ console.log(result.text);
710
+ } catch (error) {
711
+ if (error.code === 403) {
712
+ console.error('Authentication failed. Check your API key.');
713
+ } else if (error.code === 456) {
714
+ console.error('Quota exceeded. Monthly character limit reached.');
715
+ } else if (error.code === 400) {
716
+ console.error('Bad request. Check parameters.');
717
+ } else {
718
+ console.error('Translation error:', error.message);
719
+ }
720
+ }
721
+ ```
722
+
723
+ ### Document Translation Errors
724
+
725
+ ```javascript
726
+ try {
727
+ await translator.translateDocument('in.docx', 'out.docx', 'en', 'de');
728
+ } catch (error) {
729
+ if (error.documentHandle) {
730
+ // Document was uploaded but translation failed
731
+ const { documentId, documentKey } = error.documentHandle;
732
+ console.log('Can retry with document ID:', documentId);
733
+ } else {
734
+ // Upload or other error
735
+ console.error('Error:', error.message);
736
+ }
737
+ }
738
+ ```
739
+
740
+ ## TypeScript Support
741
+
742
+ The deepl-node library includes full TypeScript type definitions:
743
+
744
+ ```typescript
745
+ import * as deepl from 'deepl-node';
746
+
747
+ const authKey: string = process.env.DEEPL_AUTH_KEY!;
748
+ const translator: deepl.DeepLClient = new deepl.DeepLClient(authKey);
749
+
750
+ async function translateText() {
751
+ const targetLang: deepl.TargetLanguageCode = 'de';
752
+ const result: deepl.TextResult = await translator.translateText(
753
+ 'Hello, world!',
754
+ null,
755
+ targetLang
756
+ );
757
+
758
+ console.log(result.text);
759
+ console.log(result.detectedSourceLang);
760
+ }
761
+
762
+ translateText();
763
+ ```
764
+
765
+ ### Type Definitions
766
+
767
+ ```typescript
768
+ // Language codes
769
+ type SourceLanguageCode = 'en' | 'de' | 'fr' | 'es' | 'it' | 'ja' | 'ko' | ...;
770
+ type TargetLanguageCode = 'en-US' | 'en-GB' | 'de' | 'fr' | 'es' | ...;
771
+
772
+ // Formality options
773
+ type Formality = 'less' | 'more' | 'default' | 'prefer_less' | 'prefer_more';
774
+
775
+ // Model types
776
+ type ModelType = 'quality_optimized' | 'latency_optimized' | 'prefer_quality_optimized';
777
+
778
+ // Translation result
779
+ interface TextResult {
780
+ text: string;
781
+ detectedSourceLang: string;
782
+ billedCharacters?: number;
783
+ modelTypeUsed?: string;
784
+ }
785
+ ```
786
+
787
+ ## Advanced Configuration
788
+
789
+ ### Custom Server URL
790
+
791
+ For DeepL API Pro plans with custom endpoints:
792
+
793
+ ```javascript
794
+ const translator = new deepl.DeepLClient(authKey, {
795
+ serverUrl: 'https://api.deepl.com' // Pro endpoint
796
+ // or 'https://api-free.deepl.com' for Free endpoint
797
+ });
798
+ ```
799
+
800
+ ### HTTP Options
801
+
802
+ Configure timeout and other HTTP options:
803
+
804
+ ```javascript
805
+ const translator = new deepl.DeepLClient(authKey, {
806
+ maxRetries: 5,
807
+ minTimeout: 10000 // 10 seconds
808
+ });
809
+ ```
810
+
811
+ ## Promise Handling
812
+
813
+ All methods return Promises and support both async/await and .then()/.catch():
814
+
815
+ ```javascript
816
+ // Async/await (recommended)
817
+ async function translate() {
818
+ const result = await translator.translateText('Hello', null, 'fr');
819
+ console.log(result.text);
820
+ }
821
+
822
+ // Promise chaining
823
+ translator.translateText('Hello', null, 'fr')
824
+ .then(result => {
825
+ console.log(result.text);
826
+ })
827
+ .catch(error => {
828
+ console.error('Translation failed:', error);
829
+ });
830
+ ```
831
+
832
+ ## Complete Translation Example
833
+
834
+ ```javascript
835
+ import * as deepl from 'deepl-node';
836
+
837
+ const authKey = process.env.DEEPL_AUTH_KEY;
838
+ const translator = new deepl.DeepLClient(authKey);
839
+
840
+ async function completeExample() {
841
+ try {
842
+ // 1. Check usage
843
+ const usage = await translator.getUsage();
844
+ console.log(`Remaining: ${usage.character.limit - usage.character.count} characters`);
845
+
846
+ // 2. Get supported languages
847
+ const targetLangs = await translator.getTargetLanguages();
848
+ const germanLang = targetLangs.find(l => l.code === 'de');
849
+ console.log(`German supports formality: ${germanLang.supportsFormality}`);
850
+
851
+ // 3. Translate with options
852
+ const result = await translator.translateText(
853
+ 'How are you doing today?',
854
+ null,
855
+ 'de',
856
+ { formality: 'more' }
857
+ );
858
+ console.log(`Translation: ${result.text}`);
859
+ console.log(`Detected source: ${result.detectedSourceLang}`);
860
+
861
+ // 4. Translate document
862
+ await translator.translateDocument(
863
+ 'document.pdf',
864
+ 'dokument.pdf',
865
+ 'en',
866
+ 'de',
867
+ { formality: 'more' }
868
+ );
869
+
870
+ console.log('Translation complete!');
871
+ } catch (error) {
872
+ console.error('Error:', error.message);
873
+ }
874
+ }
875
+
876
+ completeExample();
877
+ ```
878
+
879
+ ## Node.js Version Support
880
+
881
+ The deepl-node package supports Node.js versions 12, 14, 16, 17, 18, 20, 22, and 24.
882
+
883
+ ## Additional Resources
884
+
885
+ - Official Documentation: https://www.deepl.com/docs-api/
886
+ - GitHub Repository: https://github.com/DeepLcom/deepl-node
887
+ - NPM Package: https://www.npmjs.com/package/deepl-node