@tolgee/core
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -8,2 +8,3 @@ import { Properties } from '../Properties'; | ||
constructor(properties: Properties); | ||
private static handleErrors; | ||
fetch(...args: ArgumentTypes<typeof fetch>): Promise<Response>; | ||
@@ -13,5 +14,4 @@ fetchJson(...args: ArgumentTypes<typeof fetch>): Promise<any>; | ||
postJson(url: any, body: any, init?: FetchArgumentTypes[1], ...rest: Tail<Tail<FetchArgumentTypes>>): Promise<any>; | ||
private static handleErrors; | ||
private getUrl; | ||
} | ||
export {}; |
@@ -74,2 +74,29 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
ApiHttpService.handleErrors = function (response) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var error, data, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!(response.status >= 400)) return [3 /*break*/, 5]; | ||
error = new ApiHttpError(response); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, response.json()]; | ||
case 2: | ||
data = _a.sent(); | ||
error.code = data.code; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
// eslint-disable-next-line no-console | ||
console.warn('Tolgee server responded with invalid status code.'); | ||
return [3 /*break*/, 4]; | ||
case 4: throw error; | ||
case 5: return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ApiHttpService.prototype.fetch = function () { | ||
@@ -146,31 +173,5 @@ var args = []; | ||
}; | ||
ApiHttpService.handleErrors = function (response) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var error, data, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!(response.status >= 400)) return [3 /*break*/, 5]; | ||
error = new ApiHttpError(response); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, response.json()]; | ||
case 2: | ||
data = _a.sent(); | ||
error.code = data.code; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
// eslint-disable-next-line no-console | ||
console.warn('Tolgee server responded with invalid status code.'); | ||
return [3 /*break*/, 4]; | ||
case 4: throw error; | ||
case 5: return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ApiHttpService.prototype.getUrl = function (path) { | ||
return this.properties.config.apiUrl + "/uaa/" + path + "?ak=" + this.properties.config.apiKey; | ||
var querySeparator = path.indexOf('?') < 0 ? '?' : '&'; | ||
return this.properties.config.apiUrl + "/" + path + querySeparator + "ak=" + this.properties.config.apiKey; | ||
}; | ||
@@ -177,0 +178,0 @@ return ApiHttpService; |
@@ -49,3 +49,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
if (!(this.languagePromise instanceof Promise)) { | ||
this.languagePromise = this.apiHttpService.fetchJson("languages"); | ||
this.languagePromise = this.apiHttpService.fetchJson("v2/projects/languages?size=1000"); | ||
} | ||
@@ -55,3 +55,3 @@ _a = Set.bind; | ||
case 1: | ||
languages = new (_a.apply(Set, [void 0, _b.sent()]))(); | ||
languages = new (_a.apply(Set, [void 0, (_b.sent())._embedded.languages.map(function (l) { return l.tag; })]))(); | ||
this.properties.preferredLanguages = new Set(Array.from(this.properties.preferredLanguages).filter(function (l) { | ||
@@ -72,3 +72,3 @@ return languages.has(l); | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.apiHttpService.fetchJson("scopes")]; | ||
return [4 /*yield*/, this.apiHttpService.fetchJson("api/apiKeys/scopes")]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
@@ -75,0 +75,0 @@ case 2: |
@@ -0,1 +1,12 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -53,2 +64,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
@@ -80,16 +96,32 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var data, e_1, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
var languagesArray, languagesQuery, data, translationData_1, fetchedData, e_1, _a; | ||
var _b, _c, _d, _e, _f, _g; | ||
return __generator(this, function (_h) { | ||
switch (_h.label) { | ||
case 0: | ||
this.coreService.checkScope('translations.view'); | ||
_b.label = 1; | ||
_h.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 6]); | ||
return [4 /*yield*/, this.apiHttpService.postJson("keyTranslations/" + Array.from(languages).join(','), { key: key })]; | ||
_h.trys.push([1, 3, , 6]); | ||
languagesArray = __spreadArray([], __read(languages)); | ||
languagesQuery = languagesArray | ||
.map(function (l) { return "languages=" + l; }) | ||
.join('&'); | ||
return [4 /*yield*/, this.apiHttpService.fetchJson("v2/projects/translations?" + languagesQuery + "&filterKeyName=" + encodeURIComponent(key))]; | ||
case 2: | ||
data = _b.sent(); | ||
return [2 /*return*/, new TranslationData(key, data)]; | ||
data = _h.sent(); | ||
translationData_1 = languagesArray.reduce(function (acc, curr) { | ||
var _a; | ||
return (__assign(__assign({}, acc), (_a = {}, _a[curr] = '', _a))); | ||
}, {}); | ||
fetchedData = (_d = (_c = (_b = data._embedded) === null || _b === void 0 ? void 0 : _b.keys) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.translations; | ||
if (fetchedData) { | ||
Object.entries((_g = (_f = (_e = data._embedded) === null || _e === void 0 ? void 0 : _e.keys) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.translations).forEach(function (_a) { | ||
var _b = __read(_a, 2), language = _b[0], translation = _b[1]; | ||
return (translationData_1[language] = translation.text); | ||
}); | ||
} | ||
return [2 /*return*/, new TranslationData(key, translationData_1)]; | ||
case 3: | ||
e_1 = _b.sent(); | ||
e_1 = _h.sent(); | ||
if (!(e_1 instanceof ApiHttpError)) return [3 /*break*/, 5]; | ||
@@ -102,3 +134,3 @@ if (!(e_1.response.status === 404)) return [3 /*break*/, 5]; | ||
_a.preferredLanguages = | ||
_b.sent(); | ||
_h.sent(); | ||
// eslint-disable-next-line no-console | ||
@@ -195,3 +227,3 @@ console.error('Requested language not found, refreshing the page!'); | ||
this.coreService.checkScope('translations.edit'); | ||
return [4 /*yield*/, this.apiHttpService.post('', translationData)]; | ||
return [4 /*yield*/, this.apiHttpService.post('v2/projects/translations', translationData)]; | ||
case 1: | ||
@@ -314,3 +346,3 @@ _a.sent(); | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.apiHttpService.fetchJson("" + language)]; | ||
return [4 /*yield*/, this.apiHttpService.fetchJson("v2/projects/translations/" + language)]; | ||
case 2: | ||
@@ -317,0 +349,0 @@ data = _a.sent(); |
{ | ||
"name": "@tolgee/core", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Library providing ability to translate messages directly in context of developed application.", | ||
@@ -54,3 +54,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "fac1fca3d2e50d831492937242697bd001a341df", | ||
"gitHead": "c5ad93d44050e649e1557f0bff67633ae521c0b4", | ||
"publishConfig": { | ||
@@ -57,0 +57,0 @@ "access": "public" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1324920
12267
3