@tolgee/core
Advanced tools
Comparing version 1.7.6 to 1.8.0
@@ -1,6 +0,5 @@ | ||
import { Tolgee } from './Tolgee'; | ||
import { TolgeeConfig } from './TolgeeConfig'; | ||
import { ModifierKey } from './Constants/ModifierKey'; | ||
import { TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE } from './Constants/Global'; | ||
import { TranslationData } from './DTOs/TranslationData'; | ||
export { Tolgee, TolgeeConfig, ModifierKey, TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE, TranslationData, }; | ||
export { Tolgee } from './Tolgee'; | ||
export { TolgeeConfig } from './TolgeeConfig'; | ||
export { ModifierKey } from './Constants/ModifierKey'; | ||
export { TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE } from './Constants/Global'; | ||
export * from './types/DTOs'; |
@@ -1,7 +0,6 @@ | ||
import { Tolgee } from './Tolgee'; | ||
import { TolgeeConfig } from './TolgeeConfig'; | ||
import { ModifierKey } from './Constants/ModifierKey'; | ||
import { TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE } from './Constants/Global'; | ||
import { TranslationData } from './DTOs/TranslationData'; | ||
export { Tolgee, TolgeeConfig, ModifierKey, TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE, TranslationData, }; | ||
export { Tolgee } from './Tolgee'; | ||
export { TolgeeConfig } from './TolgeeConfig'; | ||
export { ModifierKey } from './Constants/ModifierKey'; | ||
export { TOLGEE_WRAPPED_ONLY_DATA_ATTRIBUTE } from './Constants/Global'; | ||
export * from './types/DTOs'; | ||
//# sourceMappingURL=index.js.map |
@@ -113,14 +113,11 @@ var __assign = (this && this.__assign) || function () { | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!(typeof args[0] === 'object')) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, fetch(__assign(__assign({}, args[0]), { url: this.getUrl(args[0].url) })).then(function (r) { return ApiHttpService.handleErrors(r); })]; | ||
case 1: return [2 /*return*/, _b.sent()]; | ||
case 2: | ||
_a = __read(args), url = _a[0], rest = _a.slice(1); | ||
return [4 /*yield*/, fetch.apply(void 0, __spreadArray([this.getUrl(url)], __read(rest), false)).then(function (r) { | ||
return ApiHttpService.handleErrors(r); | ||
})]; | ||
case 3: return [2 /*return*/, _b.sent()]; | ||
if (typeof args[0] === 'object') { | ||
return [2 /*return*/, fetch(__assign(__assign({}, args[0]), { url: this.getUrl(args[0].url) })).then(function (r) { | ||
return ApiHttpService.handleErrors(r); | ||
})]; | ||
} | ||
_a = __read(args), url = _a[0], rest = _a.slice(1); | ||
return [2 /*return*/, fetch.apply(void 0, __spreadArray([this.getUrl(url)], __read(rest), false)).then(function (r) { | ||
return ApiHttpService.handleErrors(r); | ||
})]; | ||
}); | ||
@@ -136,8 +133,5 @@ }); | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.fetch.apply(this, __spreadArray([], __read(args), false)).then(function (res) { | ||
return res.json(); | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
return [2 /*return*/, this.fetch.apply(this, __spreadArray([], __read(args), false)).then(function (res) { | ||
return res.json(); | ||
})]; | ||
}); | ||
@@ -154,8 +148,5 @@ }); | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.fetch.apply(this, __spreadArray([url, __assign({ body: JSON.stringify(body), method: 'POST', headers: { | ||
'Content-Type': 'application/json', | ||
} }, init)], __read(rest), false))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
return [2 /*return*/, this.fetch.apply(this, __spreadArray([url, __assign({ body: JSON.stringify(body), method: 'POST', headers: { | ||
'Content-Type': 'application/json', | ||
} }, init)], __read(rest), false))]; | ||
}); | ||
@@ -172,6 +163,3 @@ }); | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.post.apply(this, __spreadArray([url, body, init], __read(rest), false)).then(function (res) { return res.json(); })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
return [2 /*return*/, this.post.apply(this, __spreadArray([url, body, init], __read(rest), false)).then(function (res) { return res.json(); })]; | ||
}); | ||
@@ -178,0 +166,0 @@ }); |
import { Properties } from '../Properties'; | ||
import { ApiHttpService } from './ApiHttpService'; | ||
import { Scope } from '../types'; | ||
import { LanguageModel } from '../types/DTOs'; | ||
export declare class CoreService { | ||
@@ -10,2 +11,3 @@ private properties; | ||
getLanguages(): Promise<Set<string>>; | ||
getLanguagesFull(): Promise<LanguageModel[]>; | ||
getScopes(): Promise<any>; | ||
@@ -12,0 +14,0 @@ isAuthorizedTo(scope: Scope): boolean; |
@@ -63,2 +63,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
CoreService.prototype.getLanguagesFull = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var languages; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.getLanguages(); | ||
return [4 /*yield*/, this.languagePromise]; | ||
case 1: | ||
languages = _a.sent(); | ||
return [2 /*return*/, languages._embedded.languages]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CoreService.prototype.getScopes = function () { | ||
@@ -71,4 +86,5 @@ return __awaiter(this, void 0, void 0, function () { | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.apiHttpService.fetchJson("api/apiKeys/scopes")]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
return [4 /*yield*/, this.apiHttpService.fetchJson("v2/api-keys/current")]; | ||
case 1: return [2 /*return*/, (_a.sent()) | ||
.scopes]; | ||
case 2: | ||
@@ -75,0 +91,0 @@ e_1 = _a.sent(); |
@@ -19,2 +19,3 @@ import { Properties } from '../Properties'; | ||
import { HighlightFunctionsInitializer } from '../highlighter/HighlightFunctionsInitializer'; | ||
import { ScreenshotService } from './ScreenshotService'; | ||
export declare class DependencyStore { | ||
@@ -26,2 +27,3 @@ properties: Properties; | ||
coreService: CoreService; | ||
screenshotService: ScreenshotService; | ||
translationService: TranslationService; | ||
@@ -28,0 +30,0 @@ textService: TextService; |
@@ -19,2 +19,3 @@ import { Properties } from '../Properties'; | ||
import { HighlightFunctionsInitializer } from '../highlighter/HighlightFunctionsInitializer'; | ||
import { ScreenshotService } from './ScreenshotService'; | ||
var DependencyStore = /** @class */ (function () { | ||
@@ -28,2 +29,3 @@ function DependencyStore(config) { | ||
this.coreService = new CoreService(this.properties, this.apiHttpService); | ||
this.screenshotService = new ScreenshotService(this.coreService, this.apiHttpService); | ||
this.translationService = new TranslationService(this.properties, this.coreService, this.apiHttpService, this.eventService); | ||
@@ -30,0 +32,0 @@ this.textService = new TextService(this.properties, this.translationService); |
import { EventEmitter } from './EventEmitter'; | ||
import { TranslationData } from '../DTOs/TranslationData'; | ||
import { TranslationData } from '../types/DTOs'; | ||
import { ElementWithMeta } from '../types'; | ||
@@ -4,0 +4,0 @@ export declare class EventService { |
@@ -1,2 +0,1 @@ | ||
import { TranslationData } from '../DTOs/TranslationData'; | ||
import { Properties } from '../Properties'; | ||
@@ -6,2 +5,11 @@ import { CoreService } from './CoreService'; | ||
import { EventService } from './EventService'; | ||
import { ComplexEditKeyDto, CreateKeyDto, KeyWithDataModel, SetTranslationsResponseModel, SetTranslationsWithKeyDto, TranslationData } from '../types/DTOs'; | ||
interface TranslationInterface { | ||
text?: string; | ||
} | ||
interface Key { | ||
id?: number; | ||
name: string; | ||
translations: Record<string, TranslationInterface>; | ||
} | ||
export declare class TranslationService { | ||
@@ -17,5 +25,8 @@ private properties; | ||
initStatic(): void; | ||
updateTranslationInCache: (data: Key) => Promise<void>; | ||
loadTranslations(lang?: string): Promise<void>; | ||
getTranslation(key: string, lang?: string, orEmpty?: boolean, defaultValue?: string): Promise<string>; | ||
setTranslations(translationData: TranslationData): Promise<any>; | ||
updateKeyComplex(id: number, data: ComplexEditKeyDto): Promise<KeyWithDataModel>; | ||
createKey(data: CreateKeyDto): Promise<KeyWithDataModel>; | ||
setTranslations(translationData: SetTranslationsWithKeyDto): Promise<SetTranslationsResponseModel>; | ||
/** | ||
@@ -29,5 +40,26 @@ * Change translations of some keys to some value temporarily. | ||
changeTranslations({ key, translations, }: TranslationData): Promise<() => void>; | ||
uploadScreenshot(key: any, data: any): Promise<Response>; | ||
getFromCacheOrFallback(key: string, lang?: string, orEmpty?: boolean, defaultValue?: string): string; | ||
getTranslationsOfKey: (key: string, languages?: Set<string>) => Promise<TranslationData>; | ||
getTranslationsOfKey: (key: string, languages?: Set<string>) => Promise<readonly [{ | ||
keyId: number; | ||
keyName: string; | ||
keyTags: { | ||
id: number; | ||
name: string; | ||
}[]; | ||
screenshotCount: number; | ||
screenshots?: { | ||
id: number; | ||
filename: string; | ||
fileUrl: string; | ||
createdAt?: string; | ||
}[]; | ||
translations: { | ||
[key: string]: { | ||
id: number; | ||
text?: string; | ||
state: "UNTRANSLATED" | "MACHINE_TRANSLATED" | "TRANSLATED" | "REVIEWED" | "NEEDS_REVIEW"; | ||
commentCount: number; | ||
}; | ||
}; | ||
}, string[]]>; | ||
private fetchTranslations; | ||
@@ -40,1 +72,2 @@ private fetchTranslationsProduction; | ||
} | ||
export {}; |
@@ -73,4 +73,4 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import { TranslationData } from '../DTOs/TranslationData'; | ||
import { ApiHttpError } from '../Errors/ApiHttpError'; | ||
import { TranslationData, } from '../types/DTOs'; | ||
var TranslationService = /** @class */ (function () { | ||
@@ -85,14 +85,36 @@ function TranslationService(properties, coreService, apiHttpService, eventService) { | ||
this.fetchPromises = {}; | ||
this.updateTranslationInCache = function (data) { return __awaiter(_this, void 0, void 0, function () { | ||
var result; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
result = {}; | ||
Object.entries(data.translations).forEach(function (_a) { | ||
var _b = __read(_a, 2), lang = _b[0], translation = _b[1]; | ||
var cachedData = _this.translationsCache.get(lang); | ||
if (cachedData) { | ||
cachedData[data.name] = translation.text; | ||
} | ||
result[lang] = translation.text; | ||
}); | ||
return [4 /*yield*/, this.eventService.TRANSLATION_CHANGED.emit(new TranslationData(data.name, result, data.id))]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
this.getTranslationsOfKey = function (key, languages) { | ||
if (languages === void 0) { languages = new Set([_this.properties.currentLanguage]); } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var languagesArray, languagesQuery, data, translationData_1, firstItem, e_1, _a; | ||
var _b, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
var languagesArray, languagesQuery, data, translationData_1, firstItem, langs, e_1, _a; | ||
var _b, _c, _d; | ||
return __generator(this, function (_e) { | ||
switch (_e.label) { | ||
case 0: | ||
this.coreService.checkScope('translations.view'); | ||
_d.label = 1; | ||
_e.label = 1; | ||
case 1: | ||
_d.trys.push([1, 3, , 7]); | ||
_e.trys.push([1, 3, , 7]); | ||
languagesArray = __spreadArray([], __read(languages), false); | ||
@@ -104,3 +126,3 @@ languagesQuery = languagesArray | ||
case 2: | ||
data = _d.sent(); | ||
data = _e.sent(); | ||
translationData_1 = languagesArray.reduce(function (acc, curr) { | ||
@@ -117,5 +139,6 @@ var _a; | ||
} | ||
return [2 /*return*/, new TranslationData(key, translationData_1, firstItem === null || firstItem === void 0 ? void 0 : firstItem.keyId)]; | ||
langs = (_d = data.selectedLanguages) === null || _d === void 0 ? void 0 : _d.map(function (l) { return l.tag; }); | ||
return [2 /*return*/, [firstItem, langs]]; | ||
case 3: | ||
e_1 = _d.sent(); | ||
e_1 = _e.sent(); | ||
if (!(e_1 instanceof ApiHttpError && | ||
@@ -132,3 +155,3 @@ e_1.response.status === 404 && | ||
_a.preferredLanguages = | ||
_d.sent(); | ||
_e.sent(); | ||
// eslint-disable-next-line no-console | ||
@@ -221,6 +244,49 @@ console.error('Requested language not found, refreshing the page!'); | ||
}; | ||
TranslationService.prototype.updateKeyComplex = function (id, data) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
this.coreService.checkScope('translations.edit'); | ||
return [4 /*yield*/, this.apiHttpService.postJson("v2/projects/keys/" + id + "/complex-update", __assign(__assign({}, data), { screenshotUploadedImageIds: ((_a = data.screenshotUploadedImageIds) === null || _a === void 0 ? void 0 : _a.length) | ||
? data.screenshotUploadedImageIds | ||
: undefined, screenshotIdsToDelete: ((_b = data.screenshotIdsToDelete) === null || _b === void 0 ? void 0 : _b.length) | ||
? data.screenshotIdsToDelete | ||
: undefined }), { method: 'put' })]; | ||
case 1: | ||
result = (_c.sent()); | ||
return [4 /*yield*/, this.updateTranslationInCache(result)]; | ||
case 2: | ||
_c.sent(); | ||
return [2 /*return*/, result]; | ||
} | ||
}); | ||
}); | ||
}; | ||
TranslationService.prototype.createKey = function (data) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
this.coreService.checkScope('keys.edit'); | ||
return [4 /*yield*/, this.apiHttpService.postJson("v2/projects/keys/create", __assign(__assign({}, data), { screenshotUploadedImageIds: ((_a = data.screenshotUploadedImageIds) === null || _a === void 0 ? void 0 : _a.length) | ||
? data.screenshotUploadedImageIds | ||
: undefined }))]; | ||
case 1: | ||
result = (_b.sent()); | ||
return [4 /*yield*/, this.updateTranslationInCache(result)]; | ||
case 2: | ||
_b.sent(); | ||
return [2 /*return*/, result]; | ||
} | ||
}); | ||
}); | ||
}; | ||
TranslationService.prototype.setTranslations = function (translationData) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -230,15 +296,10 @@ switch (_a.label) { | ||
this.coreService.checkScope('translations.edit'); | ||
return [4 /*yield*/, this.apiHttpService.postJson('v2/projects/translations', { | ||
key: translationData.key, | ||
translations: translationData.translations, | ||
return [4 /*yield*/, this.apiHttpService.postJson('v2/projects/translations', translationData)]; | ||
case 1: | ||
result = (_a.sent()); | ||
return [4 /*yield*/, this.updateTranslationInCache({ | ||
id: result.keyId, | ||
name: result.keyName, | ||
translations: result.translations, | ||
})]; | ||
case 1: | ||
result = _a.sent(); | ||
Object.keys(translationData.translations).forEach(function (lang) { | ||
var data = _this.translationsCache.get(lang); | ||
if (data) { | ||
data[translationData.key] = translationData.translations[lang]; | ||
} | ||
}); | ||
return [4 /*yield*/, this.eventService.TRANSLATION_CHANGED.emit(translationData)]; | ||
case 2: | ||
@@ -309,19 +370,2 @@ _a.sent(); | ||
}; | ||
TranslationService.prototype.uploadScreenshot = function (key, data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var formData, blob; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.coreService.checkScope('translations.edit'); | ||
formData = new FormData(); | ||
return [4 /*yield*/, fetch(data).then(function (r) { return r.blob(); })]; | ||
case 1: | ||
blob = _a.sent(); | ||
formData.append('screenshot', blob); | ||
return [2 /*return*/, this.apiHttpService.post("v2/projects/keys/" + key + "/screenshots", undefined, { headers: {}, body: formData })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
TranslationService.prototype.getFromCacheOrFallback = function (key, lang, orEmpty, defaultValue) { | ||
@@ -328,0 +372,0 @@ if (lang === void 0) { lang = this.properties.currentLanguage; } |
@@ -6,3 +6,3 @@ import { Properties } from '../Properties'; | ||
import { TranslationService } from '../services/TranslationService'; | ||
import { TranslationData } from '../DTOs/TranslationData'; | ||
import { TranslationData } from '../types/DTOs'; | ||
export declare class PluginManager { | ||
@@ -18,3 +18,3 @@ private messages; | ||
stop(): void; | ||
readonly takeScreenshot: (translationData: TranslationData) => Promise<unknown>; | ||
readonly takeScreenshot: (translationData: TranslationData) => Promise<string>; | ||
private highlightAllByKey; | ||
@@ -21,0 +21,0 @@ private unhighlightAllByKey; |
@@ -77,3 +77,3 @@ export interface TolgeeTextInputElement extends HTMLElement { | ||
}; | ||
export declare type Scope = 'translations.edit' | 'translations.view' | 'keys.edit' | 'screenshots.upload'; | ||
export declare type Scope = 'translations.edit' | 'translations.view' | 'keys.edit' | 'screenshots.upload' | 'screenshots.view' | 'screenshots.delete'; | ||
export declare type Mode = 'development' | 'production'; |
{ | ||
"name": "@tolgee/core", | ||
"version": "1.7.6", | ||
"version": "1.8.0", | ||
"description": "Library providing ability to translate messages directly in context of developed application.", | ||
@@ -28,3 +28,4 @@ "main": "index.js", | ||
"test": "jest --config ./jest.config.js", | ||
"develop": "concurrently \"rollup -c rollup.config.js -w\" \"tsc --watch\" " | ||
"develop": "concurrently \"rollup -c rollup.config.js -w\" \"tsc --watch\" ", | ||
"schema": "openapi-typescript http://localhost:8080/v3/api-docs/All%20Internal%20-%20for%20Tolgee%20Web%20application --output ./src/types/apiSchema.generated.ts" | ||
}, | ||
@@ -50,2 +51,3 @@ "author": "JanCizmar", | ||
"jest-fetch-mock": "^3.0.3", | ||
"openapi-typescript": "^4.3.0", | ||
"rollup": "^2.56.3", | ||
@@ -57,3 +59,3 @@ "rollup-plugin-terser": "7.0.2", | ||
}, | ||
"gitHead": "83b91aad9f7a06d2e044c4e7c8e027b7929d3319", | ||
"gitHead": "eb9fa7bbf18651a8ce43f8aa1afa3163866282d3", | ||
"publishConfig": { | ||
@@ -60,0 +62,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 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
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
2756256
183
23219
16
17