i18next-http-middleware 1.3.1 → 2.1.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 +11 -0
- package/README.md +1 -0
- package/cjs/LanguageDetector.js +5 -3
- package/cjs/httpFunctions.js +2 -0
- package/cjs/languageLookups/cookie.js +3 -2
- package/lib/LanguageDetector.js +6 -3
- package/lib/httpFunctions.js +2 -0
- package/lib/languageLookups/cookie.js +3 -2
- package/package.json +9 -9
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## [v2.1.2](https://github.com/i18next/i18next-http-middleware/compare/v2.1.1...v2.1.2)
|
|
2
|
+
- fix: get whitelist from correct property
|
|
3
|
+
|
|
4
|
+
## [v2.1.1](https://github.com/i18next/i18next-http-middleware/compare/v2.1.0...v2.1.1)
|
|
5
|
+
- extend httpFunctions getQuery to handle some edge cases
|
|
6
|
+
|
|
7
|
+
## [v2.1.0](https://github.com/i18next/i18next-http-middleware/compare/v2.0.0...v2.1.0)
|
|
8
|
+
- LanguageDetector: cookie, new option: cookiePath
|
|
9
|
+
|
|
10
|
+
## [v2.0.0](https://github.com/i18next/i18next-http-middleware/compare/v1.3.1...v2.0.0)
|
|
11
|
+
- potentially BREAKING: change cookie defaults: cookieSameSite: 'strict'
|
package/README.md
CHANGED
|
@@ -298,6 +298,7 @@ As with all modules you can either pass the constructor function (class) to the
|
|
|
298
298
|
// optional expire and domain for set cookie
|
|
299
299
|
cookieExpirationDate: new Date(),
|
|
300
300
|
cookieDomain: 'myDomain',
|
|
301
|
+
cookiePath: '/my/path',
|
|
301
302
|
cookieSecure: true, // if need secure cookie
|
|
302
303
|
cookieSameSite: 'strict', // 'strict', 'lax' or 'none'
|
|
303
304
|
|
package/cjs/LanguageDetector.js
CHANGED
|
@@ -47,8 +47,10 @@ function getDefaults() {
|
|
|
47
47
|
// ['cookie']
|
|
48
48
|
// cookieExpirationDate: new Date(),
|
|
49
49
|
// cookieDomain: 'myDomain'
|
|
50
|
+
// cookiePath: '/my/path'
|
|
50
51
|
checkWhitelist: true,
|
|
51
|
-
checkForSimilarInWhitelist: false
|
|
52
|
+
checkForSimilarInWhitelist: false,
|
|
53
|
+
cookieSameSite: 'strict'
|
|
52
54
|
});
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -152,7 +154,7 @@ var LanguageDetector = /*#__PURE__*/function () {
|
|
|
152
154
|
value: function getSimilarInWhitelist(cleanedLng) {
|
|
153
155
|
var _this3 = this;
|
|
154
156
|
|
|
155
|
-
if (!this.
|
|
157
|
+
if (!this.allOptions.whitelist) return;
|
|
156
158
|
|
|
157
159
|
if (cleanedLng.includes('-')) {
|
|
158
160
|
// i.e. es-MX should check if es is in whitelist
|
|
@@ -164,7 +166,7 @@ var LanguageDetector = /*#__PURE__*/function () {
|
|
|
164
166
|
} // i.e. 'pt' should return 'pt-BR'. If multiple in whitelist with 'pt-', then use first one in whitelist
|
|
165
167
|
|
|
166
168
|
|
|
167
|
-
var similar = this.
|
|
169
|
+
var similar = this.allOptions.whitelist.find(function (whitelistLng) {
|
|
168
170
|
var cleanedWhitelistLng = _this3.services.languageUtils.formatLanguageCode(whitelistLng);
|
|
169
171
|
|
|
170
172
|
if (cleanedWhitelistLng.startsWith(cleanedLng)) return cleanedWhitelistLng;
|
package/cjs/httpFunctions.js
CHANGED
|
@@ -46,6 +46,8 @@ var getQuery = function getQuery(req) {
|
|
|
46
46
|
if (req.query) return req.query;
|
|
47
47
|
if (req.raw && req.raw.query) return req.raw.query;
|
|
48
48
|
if (req.ctx && req.ctx.queryParams) return req.ctx.queryParams;
|
|
49
|
+
var url = req.url || req.raw && req.raw.url;
|
|
50
|
+
if (url && url.indexOf('?') < 0) return {};
|
|
49
51
|
console.log('no possibility found to get query');
|
|
50
52
|
return {};
|
|
51
53
|
};
|
|
@@ -100,11 +100,12 @@ var _default = {
|
|
|
100
100
|
var cookieOptions = {
|
|
101
101
|
expires: expirationDate,
|
|
102
102
|
domain: options.cookieDomain,
|
|
103
|
+
path: options.cookiePath,
|
|
103
104
|
httpOnly: false,
|
|
104
|
-
overwrite: true
|
|
105
|
+
overwrite: true,
|
|
106
|
+
sameSite: options.cookieSameSite
|
|
105
107
|
};
|
|
106
108
|
if (options.cookieSecure) cookieOptions.secure = options.cookieSecure;
|
|
107
|
-
if (options.cookieSameSite) cookieOptions.sameSite = options.cookieSameSite;
|
|
108
109
|
var existingCookie = options.getHeader(res, 'set-cookie') || options.getHeader(res, 'Set-Cookie') || [];
|
|
109
110
|
if (typeof existingCookie === 'string') existingCookie = [existingCookie];
|
|
110
111
|
if (!Array.isArray(existingCookie)) existingCookie = [];
|
package/lib/LanguageDetector.js
CHANGED
|
@@ -18,9 +18,12 @@ function getDefaults () {
|
|
|
18
18
|
caches: false, // ['cookie']
|
|
19
19
|
// cookieExpirationDate: new Date(),
|
|
20
20
|
// cookieDomain: 'myDomain'
|
|
21
|
+
// cookiePath: '/my/path'
|
|
21
22
|
|
|
22
23
|
checkWhitelist: true,
|
|
23
|
-
checkForSimilarInWhitelist: false
|
|
24
|
+
checkForSimilarInWhitelist: false,
|
|
25
|
+
|
|
26
|
+
cookieSameSite: 'strict'
|
|
24
27
|
})
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -104,7 +107,7 @@ class LanguageDetector {
|
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
getSimilarInWhitelist (cleanedLng) {
|
|
107
|
-
if (!this.
|
|
110
|
+
if (!this.allOptions.whitelist) return
|
|
108
111
|
|
|
109
112
|
if (cleanedLng.includes('-')) {
|
|
110
113
|
// i.e. es-MX should check if es is in whitelist
|
|
@@ -119,7 +122,7 @@ class LanguageDetector {
|
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
// i.e. 'pt' should return 'pt-BR'. If multiple in whitelist with 'pt-', then use first one in whitelist
|
|
122
|
-
const similar = this.
|
|
125
|
+
const similar = this.allOptions.whitelist.find((whitelistLng) => {
|
|
123
126
|
const cleanedWhitelistLng = this.services.languageUtils.formatLanguageCode(whitelistLng)
|
|
124
127
|
if (cleanedWhitelistLng.startsWith(cleanedLng)) return cleanedWhitelistLng
|
|
125
128
|
})
|
package/lib/httpFunctions.js
CHANGED
|
@@ -26,6 +26,8 @@ export const getQuery = (req) => {
|
|
|
26
26
|
if (req.query) return req.query
|
|
27
27
|
if (req.raw && req.raw.query) return req.raw.query
|
|
28
28
|
if (req.ctx && req.ctx.queryParams) return req.ctx.queryParams
|
|
29
|
+
const url = req.url || (req.raw && req.raw.url)
|
|
30
|
+
if (url && url.indexOf('?') < 0) return {}
|
|
29
31
|
console.log('no possibility found to get query')
|
|
30
32
|
return {}
|
|
31
33
|
}
|
|
@@ -78,12 +78,13 @@ export default {
|
|
|
78
78
|
const cookieOptions = {
|
|
79
79
|
expires: expirationDate,
|
|
80
80
|
domain: options.cookieDomain,
|
|
81
|
+
path: options.cookiePath,
|
|
81
82
|
httpOnly: false,
|
|
82
|
-
overwrite: true
|
|
83
|
+
overwrite: true,
|
|
84
|
+
sameSite: options.cookieSameSite
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
if (options.cookieSecure) cookieOptions.secure = options.cookieSecure
|
|
86
|
-
if (options.cookieSameSite) cookieOptions.sameSite = options.cookieSameSite
|
|
87
88
|
|
|
88
89
|
let existingCookie = options.getHeader(res, 'set-cookie') || options.getHeader(res, 'Set-Cookie') || []
|
|
89
90
|
if (typeof existingCookie === 'string') existingCookie = [existingCookie]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18next-http-middleware",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./cjs/index.js",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"module": "./lib/index.js",
|
|
18
18
|
"dependencies": {},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/cli": "7.
|
|
21
|
-
"@babel/core": "7.
|
|
22
|
-
"@babel/preset-env": "7.
|
|
20
|
+
"@babel/cli": "7.10.1",
|
|
21
|
+
"@babel/core": "7.10.2",
|
|
22
|
+
"@babel/preset-env": "7.10.2",
|
|
23
23
|
"babel-plugin-add-module-exports": "1.0.2",
|
|
24
|
-
"eslint": "7.
|
|
24
|
+
"eslint": "7.2.0",
|
|
25
25
|
"eslint-config-standard": "14.1.1",
|
|
26
|
-
"eslint-plugin-import": "2.
|
|
26
|
+
"eslint-plugin-import": "2.21.2",
|
|
27
27
|
"eslint-plugin-node": "11.1.0",
|
|
28
28
|
"eslint-plugin-promise": "4.2.1",
|
|
29
29
|
"eslint-plugin-require-path-exists": "1.1.9",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"expect.js": "0.3.1",
|
|
32
32
|
"express": "4.17.1",
|
|
33
33
|
"fastify": "3.0.0-rc.1",
|
|
34
|
-
"i18next": "19.4.
|
|
35
|
-
"mocha": "
|
|
34
|
+
"i18next": "19.4.5",
|
|
35
|
+
"mocha": "8.0.1",
|
|
36
36
|
"supertest": "4.0.2",
|
|
37
|
-
"uglify-js": "3.9.
|
|
37
|
+
"uglify-js": "3.9.4"
|
|
38
38
|
},
|
|
39
39
|
"description": "i18next-http-middleware is a middleware to be used with Node.js web frameworks like express or Fastify and also for Deno.",
|
|
40
40
|
"keywords": [
|