@omnicar/sam-translate
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -6,7 +6,2 @@ import { IsoLocale } from '@omnicar/sam-types'; | ||
errorCallback?: (error: string) => void; | ||
notify?: boolean; | ||
notificationEndpoint?: string; | ||
notificationHeaders?: { | ||
[key: string]: string; | ||
}; | ||
cache?: boolean; | ||
@@ -13,0 +8,0 @@ cacheExpirationTime?: number; |
@@ -10,3 +10,2 @@ "use strict"; | ||
errorCallback: alert.bind(window), | ||
notify: false, | ||
useLocalStorage: true, | ||
@@ -153,3 +152,2 @@ cache: true, | ||
if (!translations) { | ||
logError("No translations were available to client"); | ||
return replaceParams(key, replacements); | ||
@@ -212,41 +210,7 @@ } | ||
} | ||
var errorCallback = configuration.errorCallback, notify = configuration.notify, notificationEndpoint = configuration.notificationEndpoint; | ||
var errorCallback = configuration.errorCallback; | ||
if (errorCallback) { | ||
errorCallback(error); | ||
} | ||
if (notify && notificationEndpoint) { | ||
reportMissingTranslation(error); | ||
} | ||
}; | ||
var reportMissingTranslation = function (error) { | ||
if (reportedMissingTranslations.has(error)) { | ||
// Only report every missing translation once | ||
return; | ||
} | ||
var notificationHeaders = configuration.notificationHeaders, notificationEndpoint = configuration.notificationEndpoint; | ||
var body = { | ||
url: window.location, | ||
time: new Date().toUTCString(), | ||
configuration: configuration, | ||
error: error, | ||
}; | ||
var headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Content-Type', 'application/json'); | ||
// Add extra headers if available | ||
if (notificationHeaders) { | ||
for (var key in notificationHeaders) { | ||
if (notificationHeaders.hasOwnProperty(key)) { | ||
var value = notificationHeaders[key]; | ||
headers.append(key, value); | ||
} | ||
} | ||
} | ||
var params = { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify(body), | ||
}; | ||
fetch(notificationEndpoint, params); | ||
reportedMissingTranslations.add(error); | ||
}; |
@@ -12,11 +12,11 @@ { | ||
"devDependencies": { | ||
"@types/jest": "^22.2.3", | ||
"@types/node": "^10.0.0", | ||
"jest": "^22.4.3", | ||
"jest-fetch-mock": "^1.5.0", | ||
"jest-localstorage-mock": "^2.2.0", | ||
"ts-jest": "^22.4.4", | ||
"tslib": "^1.9.0", | ||
"typescript": "^2.8.3", | ||
"@omnicar/sam-types": "0.0.39" | ||
"@types/jest": "23.3.10", | ||
"@types/node": "10.12.17", | ||
"jest": "23.6.0", | ||
"jest-fetch-mock": "2.1.0", | ||
"jest-localstorage-mock": "2.3.0", | ||
"ts-jest": "22.4.6", | ||
"tslib": "1.9.3", | ||
"typescript": "3.2.2", | ||
"@omnicar/sam-types": "0.0.114" | ||
}, | ||
@@ -51,3 +51,3 @@ "scripts": { | ||
}, | ||
"version": "0.0.8" | ||
"version": "0.0.9" | ||
} |
1
14383
306