@molecule/api-ai-translation-google 1.0.0 → 1.0.1
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.
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +15 -4
- package/package.json +1 -1
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,qBAAqB,EAKtB,MAAM,8BAA8B,CAAA;AAGrC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,qBAAqB,EAKtB,MAAM,8BAA8B,CAAA;AAGrC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AA8NvD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,qBAAqB,CAEpF;AAID;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,qBAUrB,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -91,9 +91,11 @@ class GoogleTranslationProvider {
|
|
|
91
91
|
*/
|
|
92
92
|
async getSupportedLanguages(_type) {
|
|
93
93
|
const url = new URL('/language/translate/v2/languages', this.baseUrl);
|
|
94
|
-
url.searchParams.set('key', this.apiKey);
|
|
95
94
|
url.searchParams.set('target', 'en');
|
|
96
|
-
const response = await this.fetchWithRetry(url.toString(), {
|
|
95
|
+
const response = await this.fetchWithRetry(url.toString(), {
|
|
96
|
+
method: 'GET',
|
|
97
|
+
headers: this.authHeaders(),
|
|
98
|
+
});
|
|
97
99
|
if (!response.ok)
|
|
98
100
|
throw await this.buildError('languages', response);
|
|
99
101
|
const data = (await response.json());
|
|
@@ -121,7 +123,6 @@ class GoogleTranslationProvider {
|
|
|
121
123
|
const callerMarkup = params.tagHandling !== undefined;
|
|
122
124
|
const masked = texts.map((text) => maskText(text, params.protect ?? [], callerMarkup));
|
|
123
125
|
const url = new URL('/language/translate/v2', this.baseUrl);
|
|
124
|
-
url.searchParams.set('key', this.apiKey);
|
|
125
126
|
const body = {
|
|
126
127
|
q: masked.map((m) => m.masked),
|
|
127
128
|
target: params.targetLang,
|
|
@@ -131,7 +132,7 @@ class GoogleTranslationProvider {
|
|
|
131
132
|
body.source = params.sourceLang;
|
|
132
133
|
const response = await this.fetchWithRetry(url.toString(), {
|
|
133
134
|
method: 'POST',
|
|
134
|
-
headers: { 'Content-Type': 'application/json' },
|
|
135
|
+
headers: { 'Content-Type': 'application/json', ...this.authHeaders() },
|
|
135
136
|
body: JSON.stringify(body),
|
|
136
137
|
});
|
|
137
138
|
if (!response.ok)
|
|
@@ -162,6 +163,16 @@ class GoogleTranslationProvider {
|
|
|
162
163
|
}
|
|
163
164
|
return response;
|
|
164
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* API-key auth headers for every request. The key rides in the
|
|
168
|
+
* `X-goog-api-key` HEADER, never the query string, so it cannot leak into
|
|
169
|
+
* access logs, proxies or error reports that record full URLs.
|
|
170
|
+
*
|
|
171
|
+
* @returns The headers carrying the API key.
|
|
172
|
+
*/
|
|
173
|
+
authHeaders() {
|
|
174
|
+
return { 'X-goog-api-key': this.apiKey };
|
|
175
|
+
}
|
|
165
176
|
/**
|
|
166
177
|
* Builds an error from a failed response, carrying the HTTP status.
|
|
167
178
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-ai-translation-google",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Google Cloud Translation provider for molecule.dev — text translation via the Google Translate API",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/api-ai-translation-google",
|
|
6
6
|
"type": "module",
|