locizify 8.0.0 → 8.0.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 8.0.2
2
+
3
+ - update i18next-locize-backend
4
+
5
+ ### 8.0.1
6
+
7
+ - update i18next-locize-backend
8
+
1
9
  ### 8.0.0
2
10
 
3
11
  - update i18next-locize-backend
package/README.md CHANGED
@@ -12,7 +12,7 @@ Just drop the following line to your header to deliver your content in any langu
12
12
  id="locizify"
13
13
  projectid="[PROJECT_ID]"
14
14
  apikey="[API_KEY]"
15
- src="https://unpkg.com/locizify@^7.0.3"
15
+ src="https://unpkg.com/locizify@^8.0.0"
16
16
  autopilot="true"
17
17
  cdnType="standard"
18
18
  ></script>
@@ -22,7 +22,7 @@ Just drop the following line to your header to deliver your content in any langu
22
22
  id="locizify"
23
23
  projectid="[PROJECT_ID]"
24
24
  apikey="[API_KEY]"
25
- src="https://cdn.jsdelivr.net/npm/locizify@^7.0.3"
25
+ src="https://cdn.jsdelivr.net/npm/locizify@^8.0.0"
26
26
  autopilot="true"
27
27
  cdnType="standard"
28
28
  ></script>
@@ -71,7 +71,7 @@ Add the script to your page:
71
71
  id="locizify"
72
72
  projectid="[PROJECT_ID]"
73
73
  apikey="[API_KEY]"
74
- src="https://unpkg.com/locizify@^7.0.3"
74
+ src="https://unpkg.com/locizify@^8.0.0"
75
75
  autopilot
76
76
  cdnType="standard"
77
77
  ></script>
@@ -105,7 +105,7 @@ Add the script to your page:
105
105
  apikey="[API_KEY]"
106
106
  referencelng="[LNG]"
107
107
  fallbacklng="[LNG]"
108
- src="https://unpkg.com/locizify@^7.0.3"
108
+ src="https://unpkg.com/locizify@^8.0.0"
109
109
 
110
110
  // all custom attributes can also be prefixed with data-
111
111
  // data-projectid="[PROJECT_ID]"
@@ -136,7 +136,7 @@ Add the script to your page:
136
136
  <!DOCTYPE html>
137
137
  <html>
138
138
  <head>
139
- <script src="https://unpkg.com/locizify@^7.0.3"></script>
139
+ <script src="https://unpkg.com/locizify@^8.0.0"></script>
140
140
  <script>
141
141
  locizify.init({
142
142
  // required
@@ -7260,6 +7260,12 @@
7260
7260
  }).catch(function () {});
7261
7261
  } catch (e) {}
7262
7262
  }
7263
+ var storage = {};
7264
+ var parseMaxAge = function parseMaxAge(headerString) {
7265
+ if (!headerString) return 0;
7266
+ var matches = headerString.match(/max-age=([0-9]+)/);
7267
+ return matches ? parseInt(matches[1], 10) : 0;
7268
+ };
7263
7269
  var requestWithFetch$1 = function requestWithFetch(options, url, payload, callback) {
7264
7270
  var headers = {};
7265
7271
  if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
@@ -7285,11 +7291,13 @@
7285
7291
  status: response.status,
7286
7292
  resourceNotExisting: resourceNotExisting
7287
7293
  });
7294
+ var cacheControl = response.headers && response.headers.get('cache-control');
7288
7295
  response.text().then(function (data) {
7289
7296
  callback(null, {
7290
7297
  status: response.status,
7291
7298
  data: data,
7292
- resourceNotExisting: resourceNotExisting
7299
+ resourceNotExisting: resourceNotExisting,
7300
+ cacheControl: cacheControl
7293
7301
  });
7294
7302
  }).catch(callback);
7295
7303
  };
@@ -7330,10 +7338,12 @@
7330
7338
  resourceNotExisting: resourceNotExisting
7331
7339
  });
7332
7340
  }
7341
+ var cacheControl = x.getResponseHeader('Cache-Control');
7333
7342
  x.readyState > 3 && callback(x.status >= 400 ? x.statusText : null, {
7334
7343
  status: x.status,
7335
7344
  data: x.responseText,
7336
- resourceNotExisting: resourceNotExisting
7345
+ resourceNotExisting: resourceNotExisting,
7346
+ cacheControl: cacheControl
7337
7347
  });
7338
7348
  };
7339
7349
  x.send(JSON.stringify(payload));
@@ -7347,6 +7357,26 @@
7347
7357
  payload = undefined;
7348
7358
  }
7349
7359
  callback = callback || function () {};
7360
+ var useCacheLayer = typeof window === 'undefined' && options.useCacheLayer;
7361
+ if (useCacheLayer && !payload && !options.noCache && storage[url] && storage[url].expires > Date.now()) {
7362
+ return callback(null, storage[url].data);
7363
+ }
7364
+ var originalCallback = callback;
7365
+ callback = function callback(err, res) {
7366
+ if (useCacheLayer && !err && res && !payload && res.cacheControl) {
7367
+ var maxAge = parseMaxAge(res.cacheControl);
7368
+ if (maxAge > 0) {
7369
+ storage[url] = {
7370
+ data: res,
7371
+ expires: Date.now() + maxAge * 1000
7372
+ };
7373
+ }
7374
+ }
7375
+ originalCallback(err, res);
7376
+ };
7377
+ if (!payload && options.noCache && options.cdnType === 'standard') {
7378
+ url += (url.indexOf('?') >= 0 ? '&' : '?') + 'cache=no';
7379
+ }
7350
7380
  if (fetchApi$1) {
7351
7381
  return requestWithFetch$1(options, url, payload, callback);
7352
7382
  }
@@ -7420,7 +7450,8 @@
7420
7450
  reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,
7421
7451
  checkForProjectTimeout: 3 * 1000,
7422
7452
  storageExpiration: 60 * 60 * 1000,
7423
- writeDebounce: 5 * 1000
7453
+ writeDebounce: 5 * 1000,
7454
+ useCacheLayer: typeof window === 'undefined'
7424
7455
  }, getApiPaths(cdnType));
7425
7456
  };
7426
7457
  var hasLocalStorageSupport$1;
@@ -7661,7 +7692,7 @@
7661
7692
  this.isProjectNotExisting = true;
7662
7693
  }
7663
7694
  if (this.isProjectNotExisting) {
7664
- callback(new Error("locize project ".concat(this.options.projectId, " does not exist!")));
7695
+ callback(new Error(this.isProjectNotExistingErrorMessage));
7665
7696
  return deferred;
7666
7697
  }
7667
7698
  this.getLanguagesCalls = this.getLanguagesCalls || [];
@@ -7671,12 +7702,26 @@
7671
7702
  if (!_this3.somethingLoaded && info && info.resourceNotExisting) {
7672
7703
  _this3.isProjectNotExisting = true;
7673
7704
  _this3.storage.setProjectNotExisting(_this3.options.projectId);
7674
- var e = new Error("locize project ".concat(_this3.options.projectId, " does not exist!"));
7675
- var _clbs = _this3.getLanguagesCalls;
7676
- _this3.getLanguagesCalls = [];
7677
- return _clbs.forEach(function (clb) {
7678
- return clb(e);
7705
+ var errMsg = "locize project ".concat(_this3.options.projectId, " does not exist!");
7706
+ _this3.isProjectNotExistingErrorMessage = errMsg;
7707
+ var cdnTypeAlt = _this3.options.cdnType === 'standard' ? 'pro' : 'standard';
7708
+ var otherEndpointApiPaths = getApiPaths(cdnTypeAlt);
7709
+ var urlAlt = interpolate(otherEndpointApiPaths.getLanguagesPath, {
7710
+ projectId: _this3.options.projectId
7711
+ });
7712
+ _this3.loadUrl({}, urlAlt, function (errAlt, retAlt, infoAlt) {
7713
+ if (!errAlt && retAlt && (!infoAlt || !infoAlt.resourceNotExisting)) {
7714
+ errMsg += " It seems you're using the wrong cdnType. Your locize project is configured to use \"".concat(cdnTypeAlt, "\" but here you've configured \"").concat(_this3.options.cdnType, "\".");
7715
+ _this3.isProjectNotExistingErrorMessage = errMsg;
7716
+ }
7717
+ var e = new Error(errMsg);
7718
+ var clbs = _this3.getLanguagesCalls;
7719
+ _this3.getLanguagesCalls = [];
7720
+ clbs.forEach(function (clb) {
7721
+ return clb(e);
7722
+ });
7679
7723
  });
7724
+ return;
7680
7725
  }
7681
7726
  if (ret) {
7682
7727
  _this3.loadedLanguages = Object.keys(ret);
@@ -7816,7 +7861,7 @@
7816
7861
  this.isProjectNotExisting = true;
7817
7862
  }
7818
7863
  if (this.isProjectNotExisting) {
7819
- var err = new Error("locize project ".concat(this.options.projectId, " does not exist!"));
7864
+ var err = new Error(this.isProjectNotExistingErrorMessage);
7820
7865
  if (logger) logger.error(err.message);
7821
7866
  if (callback) callback(err);
7822
7867
  return;