nativ-sdk 0.1.2

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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +200 -0
  3. package/dist/cjs/client.d.ts +114 -0
  4. package/dist/cjs/client.d.ts.map +1 -0
  5. package/dist/cjs/client.js +397 -0
  6. package/dist/cjs/client.js.map +1 -0
  7. package/dist/cjs/errors.d.ts +57 -0
  8. package/dist/cjs/errors.d.ts.map +1 -0
  9. package/dist/cjs/errors.js +69 -0
  10. package/dist/cjs/errors.js.map +1 -0
  11. package/dist/cjs/index.d.ts +20 -0
  12. package/dist/cjs/index.d.ts.map +1 -0
  13. package/dist/cjs/index.js +30 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/types.d.ts +145 -0
  17. package/dist/cjs/types.d.ts.map +1 -0
  18. package/dist/cjs/types.js +153 -0
  19. package/dist/cjs/types.js.map +1 -0
  20. package/dist/cjs/version.d.ts +2 -0
  21. package/dist/cjs/version.d.ts.map +1 -0
  22. package/dist/cjs/version.js +5 -0
  23. package/dist/cjs/version.js.map +1 -0
  24. package/dist/esm/client.d.ts +114 -0
  25. package/dist/esm/client.d.ts.map +1 -0
  26. package/dist/esm/client.js +393 -0
  27. package/dist/esm/client.js.map +1 -0
  28. package/dist/esm/errors.d.ts +57 -0
  29. package/dist/esm/errors.d.ts.map +1 -0
  30. package/dist/esm/errors.js +59 -0
  31. package/dist/esm/errors.js.map +1 -0
  32. package/dist/esm/index.d.ts +20 -0
  33. package/dist/esm/index.d.ts.map +1 -0
  34. package/dist/esm/index.js +18 -0
  35. package/dist/esm/index.js.map +1 -0
  36. package/dist/esm/types.d.ts +145 -0
  37. package/dist/esm/types.d.ts.map +1 -0
  38. package/dist/esm/types.js +141 -0
  39. package/dist/esm/types.js.map +1 -0
  40. package/dist/esm/version.d.ts +2 -0
  41. package/dist/esm/version.d.ts.map +1 -0
  42. package/dist/esm/version.js +2 -0
  43. package/dist/esm/version.js.map +1 -0
  44. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nativ Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # Nativ Node.js/TypeScript SDK
2
+
3
+ The official Node.js client for the [Nativ](https://usenativ.com) AI localization platform.
4
+
5
+ Wraps the full Nativ REST API with **TypeScript types**, zero runtime dependencies (uses native `fetch`), and ESM + CommonJS dual output.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install nativ
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```typescript
16
+ import { Nativ } from "nativ";
17
+
18
+ const client = new Nativ({ apiKey: "nativ_..." }); // or set NATIV_API_KEY env var
19
+
20
+ // Translate text
21
+ const result = await client.translate("Launch your product globally", "French");
22
+ console.log(result.translatedText); // "Lancez votre produit à l'international"
23
+ console.log(result.tmMatch); // TM match details (score, source, etc.)
24
+
25
+ // Batch translate
26
+ const results = await client.translateBatch(
27
+ ["Sign up", "Log in", "Settings"],
28
+ "German",
29
+ );
30
+ for (const r of results) {
31
+ console.log(r.translatedText);
32
+ }
33
+ ```
34
+
35
+ ## Features
36
+
37
+ ### Translation
38
+
39
+ ```typescript
40
+ const result = await client.translate(
41
+ "Welcome to our platform",
42
+ "Spanish",
43
+ {
44
+ context: "SaaS onboarding email subject line",
45
+ formality: "formal",
46
+ backtranslate: true,
47
+ },
48
+ );
49
+
50
+ console.log(result.translatedText); // translated text
51
+ console.log(result.backtranslation); // back-translation for QA
52
+ console.log(result.rationale); // AI explanation of translation choices
53
+ console.log(result.tmMatch?.score); // TM match percentage
54
+ ```
55
+
56
+ ### OCR — extract text from images
57
+
58
+ ```typescript
59
+ const result = await client.extractText("screenshot.png");
60
+ console.log(result.extractedText);
61
+ ```
62
+
63
+ ### Image culturalization
64
+
65
+ ```typescript
66
+ const result = await client.culturalizeImage(
67
+ "banner_en.png",
68
+ "Soldes d'été",
69
+ "fr",
70
+ { numImages: 3 },
71
+ );
72
+ for (const img of result.images) {
73
+ // img.imageBase64 contains the generated image
74
+ }
75
+ ```
76
+
77
+ ### Cultural sensitivity inspection
78
+
79
+ ```typescript
80
+ const result = await client.inspectImage("ad_creative.jpg");
81
+ console.log(result.verdict); // "SAFE" or "NOT SAFE"
82
+ for (const issue of result.affectedCountries) {
83
+ console.log(`${issue.country}: ${issue.issue} → ${issue.suggestion}`);
84
+ }
85
+ ```
86
+
87
+ ### Translation memory
88
+
89
+ ```typescript
90
+ // Search
91
+ const matches = await client.searchTm("Sign up", {
92
+ targetLanguageCode: "fr",
93
+ });
94
+ for (const m of matches) {
95
+ console.log(`${m.score}% — ${m.sourceText} → ${m.targetText}`);
96
+ }
97
+
98
+ // Add entry
99
+ await client.addTmEntry(
100
+ "Sign up",
101
+ "S'inscrire",
102
+ "en",
103
+ "fr-FR",
104
+ { name: "onboarding CTA" },
105
+ );
106
+
107
+ // List & filter
108
+ const entries = await client.listTmEntries({
109
+ targetLanguageCode: "fr-FR",
110
+ enabledOnly: true,
111
+ });
112
+ console.log(`${entries.total} entries`);
113
+
114
+ // Stats
115
+ const stats = await client.getTmStats();
116
+ console.log(`${stats.total} total, ${stats.enabled} enabled`);
117
+ ```
118
+
119
+ ### Languages
120
+
121
+ ```typescript
122
+ const languages = await client.getLanguages();
123
+ for (const lang of languages) {
124
+ console.log(`${lang.language} (${lang.languageCode}) — formality: ${lang.formality}`);
125
+ }
126
+ ```
127
+
128
+ ### Style guides & brand voice
129
+
130
+ ```typescript
131
+ // List style guides
132
+ const guides = await client.getStyleGuides();
133
+ for (const g of guides) {
134
+ console.log(`${g.title} — ${g.isEnabled ? "enabled" : "disabled"}`);
135
+ }
136
+
137
+ // Get brand voice prompt
138
+ const voice = await client.getBrandVoice();
139
+ console.log(voice.prompt);
140
+
141
+ // Create a style guide
142
+ await client.createStyleGuide(
143
+ "Tone of Voice",
144
+ "Always use active voice. Avoid jargon.",
145
+ );
146
+ ```
147
+
148
+ ## Error handling
149
+
150
+ ```typescript
151
+ import { Nativ, InsufficientCreditsError, AuthenticationError } from "nativ";
152
+
153
+ const client = new Nativ();
154
+
155
+ try {
156
+ const result = await client.translate("Hello", "French");
157
+ } catch (e) {
158
+ if (e instanceof AuthenticationError) {
159
+ console.log("Bad API key");
160
+ } else if (e instanceof InsufficientCreditsError) {
161
+ console.log("Top up at dashboard.usenativ.com");
162
+ }
163
+ }
164
+ ```
165
+
166
+ All exceptions extend `NativError` and carry `statusCode` and `body` properties.
167
+
168
+ | Exception | HTTP | When |
169
+ |----------------------------|------|-------------------------------|
170
+ | `AuthenticationError` | 401 | Invalid or missing API key |
171
+ | `InsufficientCreditsError` | 402 | Not enough credits |
172
+ | `ValidationError` | 400 | Bad request parameters |
173
+ | `NotFoundError` | 404 | Resource not found |
174
+ | `RateLimitError` | 429 | Too many requests |
175
+ | `ServerError` | 5xx | Nativ API server error |
176
+
177
+ ## Configuration
178
+
179
+ ```typescript
180
+ const client = new Nativ({
181
+ apiKey: "nativ_...", // or NATIV_API_KEY env var
182
+ baseUrl: "https://...", // or NATIV_API_URL env var (default: api.usenativ.com)
183
+ timeout: 120_000, // request timeout in ms (default: 2 minutes)
184
+ });
185
+ ```
186
+
187
+ ## Requirements
188
+
189
+ - Node.js 18+ (uses native `fetch`)
190
+ - Zero runtime dependencies
191
+
192
+ ## Related packages
193
+
194
+ - **[nativ](https://pypi.org/project/nativ/)** (Python SDK)
195
+ - **[nativ-mcp](https://pypi.org/project/nativ-mcp/)** — MCP server for Claude, Cursor, etc.
196
+ - **[langchain-nativ](https://pypi.org/project/langchain-nativ/)** — LangChain tool
197
+
198
+ ## License
199
+
200
+ MIT
@@ -0,0 +1,114 @@
1
+ import type { BrandVoice, CulturalInspection, FileInput, ImageResult, Language, OCRResult, StyleGuide, TMEntry, TMEntryList, TMSearchMatch, TMStats, TranslateBatchOptions, TranslateOptions, Translation } from "./types.js";
2
+ export interface NativOptions {
3
+ apiKey?: string;
4
+ baseUrl?: string;
5
+ /** Request timeout in milliseconds. Default: 120 000 (2 minutes). */
6
+ timeout?: number;
7
+ }
8
+ /**
9
+ * Nativ API client.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { Nativ } from "nativ";
14
+ *
15
+ * const client = new Nativ({ apiKey: "nativ_..." });
16
+ * const result = await client.translate("Hello world", "French");
17
+ * console.log(result.translatedText);
18
+ * ```
19
+ */
20
+ export declare class Nativ {
21
+ private readonly apiKey;
22
+ private readonly baseUrl;
23
+ private readonly timeout;
24
+ constructor(options?: NativOptions);
25
+ private request;
26
+ /**
27
+ * Translate text with cultural adaptation.
28
+ *
29
+ * Uses your translation memory, brand voice, and style guides
30
+ * automatically.
31
+ */
32
+ translate(text: string, targetLanguage: string, options?: TranslateOptions): Promise<Translation>;
33
+ /**
34
+ * Translate multiple texts to the same target language.
35
+ *
36
+ * Convenience wrapper that calls {@link translate} for each text.
37
+ */
38
+ translateBatch(texts: string[], targetLanguage: string, options?: TranslateBatchOptions): Promise<Translation[]>;
39
+ /** Extract text from an image via OCR. */
40
+ extractText(image: FileInput): Promise<OCRResult>;
41
+ /** Generate a culturalized image with styled text. */
42
+ culturalizeImage(image: FileInput, text: string, languageCode: string, options?: {
43
+ outputFormat?: string;
44
+ model?: string;
45
+ numImages?: number;
46
+ }): Promise<ImageResult>;
47
+ /** Check an image for cultural sensitivity issues. */
48
+ inspectImage(image: FileInput, options?: {
49
+ countries?: string[];
50
+ }): Promise<CulturalInspection>;
51
+ /** Get all languages configured in your Nativ workspace. */
52
+ getLanguages(): Promise<Language[]>;
53
+ /** Update the formality setting for a language. */
54
+ updateLanguageFormality(mappingId: number, formality: string): Promise<boolean>;
55
+ /** Update the custom style directive for a language. */
56
+ updateLanguageCustomStyle(mappingId: number, customStyle: string | null): Promise<boolean>;
57
+ /** Fuzzy-search the translation memory. */
58
+ searchTm(query: string, options?: {
59
+ sourceLanguageCode?: string;
60
+ targetLanguageCode?: string;
61
+ minScore?: number;
62
+ limit?: number;
63
+ }): Promise<TMSearchMatch[]>;
64
+ /** List translation memory entries with optional filters. */
65
+ listTmEntries(options?: {
66
+ sourceLanguageCode?: string;
67
+ targetLanguageCode?: string;
68
+ informationSource?: string;
69
+ search?: string;
70
+ enabledOnly?: boolean;
71
+ limit?: number;
72
+ offset?: number;
73
+ }): Promise<TMEntryList>;
74
+ /** Add an entry to the translation memory. */
75
+ addTmEntry(sourceText: string, targetText: string, sourceLanguageCode: string, targetLanguageCode: string, options?: {
76
+ name?: string;
77
+ }): Promise<TMEntry>;
78
+ /** Update a translation memory entry. */
79
+ updateTmEntry(entryId: string, update: {
80
+ targetText?: string;
81
+ enabled?: boolean;
82
+ }): Promise<boolean>;
83
+ /** Delete a translation memory entry. */
84
+ deleteTmEntry(entryId: string): Promise<boolean>;
85
+ /** Get translation memory statistics. */
86
+ getTmStats(): Promise<TMStats>;
87
+ /** Get all style guides. */
88
+ getStyleGuides(): Promise<StyleGuide[]>;
89
+ /** Create a new style guide. */
90
+ createStyleGuide(title: string, content: string, options?: {
91
+ isEnabled?: boolean;
92
+ }): Promise<StyleGuide>;
93
+ /** Update an existing style guide. */
94
+ updateStyleGuide(guideId: string, update: {
95
+ title?: string;
96
+ content?: string;
97
+ isEnabled?: boolean;
98
+ }): Promise<StyleGuide>;
99
+ /** Delete a style guide. */
100
+ deleteStyleGuide(guideId: string): Promise<boolean>;
101
+ /** Get the brand voice prompt. */
102
+ getBrandVoice(): Promise<BrandVoice>;
103
+ /** Get the combined prompt (brand voice + style guides). */
104
+ getCombinedPrompt(): Promise<Record<string, unknown>>;
105
+ /** Submit feedback on a translation. */
106
+ submitFeedback(feedback: {
107
+ source?: string;
108
+ result?: string;
109
+ language?: string;
110
+ feedback?: string;
111
+ approved?: boolean;
112
+ }): Promise<Record<string, unknown>>;
113
+ }
114
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,QAAQ,EACR,SAAS,EACT,UAAU,EACV,OAAO,EACP,WAAW,EACX,aAAa,EACb,OAAO,EACP,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACZ,MAAM,YAAY,CAAC;AAiBpB,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA4FD;;;;;;;;;;;GAWG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,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