@companieshouse/ch-node-utils 1.3.7 → 1.3.9
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/README.md +28 -5
- package/lib/constants/constants.d.ts +3 -0
- package/lib/constants/constants.js +6 -1
- package/lib/constants/constants.js.map +1 -1
- package/lib/middleware/manageLocales.middleware.js +2 -0
- package/lib/middleware/manageLocales.middleware.js.map +1 -1
- package/lib/utils/i18nCh.d.ts +2 -0
- package/lib/utils/i18nCh.js +20 -8
- package/lib/utils/i18nCh.js.map +1 -1
- package/lib/utils/locales.d.ts +1 -0
- package/lib/utils/locales.js +26 -0
- package/lib/utils/locales.js.map +1 -0
- package/package.json +3 -2
- package/templates/navbar.njk +7 -4
- /package/locales/cy/{navbar.json → ch-node-utils-navbar.json} +0 -0
- /package/locales/en/{navbar.json → ch-node-utils-navbar.json} +0 -0
package/README.md
CHANGED
|
@@ -77,10 +77,11 @@ Available as a normal npm dependency([here on npmjs](https://www.npmjs.com/packa
|
|
|
77
77
|
|`CH_NODE_UTILS_DROP_LANG_QUERY_PARAM`| It could be set to [drop the lang="xx" query param](https://github.com/companieshouse/ch-node-utils/blob/f9e5c47a86206f0b12e4e536c4c459db16747631/src/middleware/manageLocales.middleware.ts#L25) from the current URL ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L50)) |
|
|
78
78
|
|`CH_NODE_UTILS_LOG_LVL`| It could be set to ["TRACE" or "DEBUG" (case insensitive)](https://github.com/companieshouse/ch-node-utils/blob/24bc717477d21082439d1b460108cb0d60465f0f/src/utils/log.ts#L2) to dump internal info while inside ch-node-utils ([see Example](https://github.com/companieshouse/docker-chs-development/blob/842c61245adcbba02a6316847fc4f9d94c52410d/services/modules/dissolution/dissolution-web.docker-compose.yaml#L49))|
|
|
79
79
|
|
|
80
|
-
### Menu
|
|
81
|
-
A menu navigation bar component has been added to make it easier to add links pointing to new services when needed. There are two Nunjucks macros: one that adds a menu navigation bar with the provided items and another that adds a menu navigation bar with predefined items. The latter internally uses the former and at the moment contains links to the following service:
|
|
80
|
+
### Menu Navigation Bar
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
A menu navigation bar component has been added to make it easier to add links pointing to new services when needed. There are two Nunjucks macros: one that adds a menu navigation bar with the provided items and another that adds a menu navigation bar with predefined items. The latter internally uses the former and currently contains links to the following services:
|
|
83
|
+
|
|
84
|
+
- Authorised agent (conditional)
|
|
84
85
|
- Your companies
|
|
85
86
|
- Your filings
|
|
86
87
|
- Companies you follow
|
|
@@ -90,7 +91,30 @@ A menu navigation bar component has been added to make it easier to add links po
|
|
|
90
91
|
|
|
91
92
|
The "Authorised agent" menu item appears conditionally if the logged user has ACSP membership.
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
#### Usage
|
|
95
|
+
|
|
96
|
+
To use the predefined navbar, import the macro and call it with the required parameters:
|
|
97
|
+
|
|
98
|
+
```nunjucks
|
|
99
|
+
{% from "navbar.njk" import addPredefinedNavbar %}
|
|
100
|
+
|
|
101
|
+
{{ addPredefinedNavbar(userEmailAddress, chsMonitorGuiUrl, lang, displayAuthorisedAgent) }}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The macro requires the following parameters:
|
|
105
|
+
|
|
106
|
+
- `userEmailAddress`: The email address of the logged-in user
|
|
107
|
+
- `chsMonitorGuiUrl`: The URL for the "Companies you follow" link
|
|
108
|
+
- `lang`: An object containing language-specific strings for localization
|
|
109
|
+
- `displayAuthorisedAgent`: A flag for displaying the "Authorised agent" menu item. If the logged user has ACSP membership, this flag should be set to `'yes'`
|
|
110
|
+
|
|
111
|
+
#### Localization
|
|
112
|
+
|
|
113
|
+
The navbar uses translations from `@companieshouse/ch-node-utils` (this) package. To set this up:
|
|
114
|
+
|
|
115
|
+
1. Ensure the `@companieshouse/ch-node-utils` package is installed. i.e `npm i @companieshouse/ch-node-utils`
|
|
116
|
+
2. Update your i18 middleware to load and merge translations from both sources. (`@companieshouse/ch-node-utils/locales`)
|
|
117
|
+
3. Add the `@companieshouse/ch-node-utils/templates` directory to the Nunjucks loader paths.
|
|
94
118
|
|
|
95
119
|
The navbar also requires the use of styles provided in the [ch.gov.uk.css](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/stylesheets/ch.gov.uk.css) stylesheet (you can either add the provided link to the head section or include specific styles in your own stylesheet)
|
|
96
120
|
|
|
@@ -99,4 +123,3 @@ The navbar also requires the use of styles provided in the [ch.gov.uk.css](https
|
|
|
99
123
|
It also requires the [navbar.js](https://github.com/companieshouse/cdn.ch.gov.uk/blob/master/app/assets/javascripts/lib/navbar.js) script to be added to the footer to make the navbar work in mobile mode
|
|
100
124
|
|
|
101
125
|
`<script src="{{ cdnHost }}/javascripts/lib/navbar.js"></script>`
|
|
102
|
-
|
|
@@ -1 +1,4 @@
|
|
|
1
1
|
export declare const QUERY_PAR_LANG = "lang";
|
|
2
|
+
export declare const NODE_MODULES_LOCALES_PATH = "node_modules/@companieshouse/ch-node-utils/locales";
|
|
3
|
+
export declare const SHARED_NAVBAR_NAMESPACE = "ch-node-utils-navbar";
|
|
4
|
+
export declare const SHARED_NUNJUCKS_TRANSLATION_NAMESPACES: Set<string>;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QUERY_PAR_LANG = void 0;
|
|
3
|
+
exports.SHARED_NUNJUCKS_TRANSLATION_NAMESPACES = exports.SHARED_NAVBAR_NAMESPACE = exports.NODE_MODULES_LOCALES_PATH = exports.QUERY_PAR_LANG = void 0;
|
|
4
4
|
exports.QUERY_PAR_LANG = "lang";
|
|
5
|
+
exports.NODE_MODULES_LOCALES_PATH = 'node_modules/@companieshouse/ch-node-utils/locales';
|
|
6
|
+
exports.SHARED_NAVBAR_NAMESPACE = "ch-node-utils-navbar";
|
|
7
|
+
exports.SHARED_NUNJUCKS_TRANSLATION_NAMESPACES = new Set([
|
|
8
|
+
exports.SHARED_NAVBAR_NAMESPACE
|
|
9
|
+
]);
|
|
5
10
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,MAAM,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,MAAM,CAAA;AACvB,QAAA,yBAAyB,GAAG,oDAAoD,CAAC;AACjF,QAAA,uBAAuB,GAAG,sBAAsB,CAAA;AAChD,QAAA,sCAAsC,GAAG,IAAI,GAAG,CAAC;IAC5D,+BAAuB;CACxB,CAAC,CAAC"}
|
|
@@ -6,7 +6,9 @@ const constants_1 = require("../constants/constants");
|
|
|
6
6
|
const locales_service_1 = tslib_1.__importDefault(require("../services/locales/locales.service"));
|
|
7
7
|
const languageNames_1 = tslib_1.__importDefault(require("../utils/languageNames"));
|
|
8
8
|
const log_1 = tslib_1.__importDefault(require("../utils/log"));
|
|
9
|
+
const locales_1 = require("../utils/locales");
|
|
9
10
|
function LocalesMiddleware() {
|
|
11
|
+
(0, locales_1.copyLocales)();
|
|
10
12
|
return (req, res, next) => {
|
|
11
13
|
var _a;
|
|
12
14
|
(0, log_1.default)("---------- LocalesMiddleware ------------");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manageLocales.middleware.js","sourceRoot":"","sources":["../../src/middleware/manageLocales.middleware.ts"],"names":[],"mappings":";;;;AACA,sDAAuD;AACvD,kGAAiE;AACjE,mFAAoD;AACpD,+DAA+B;
|
|
1
|
+
{"version":3,"file":"manageLocales.middleware.js","sourceRoot":"","sources":["../../src/middleware/manageLocales.middleware.ts"],"names":[],"mappings":";;;;AACA,sDAAuD;AACvD,kGAAiE;AACjE,m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C,gCAAgC,0BAAc,2BAA2B,UAAU,GAAG,CAAC,CAAA;QAC9F,CAAC;QAED,GAAG,CAAC,GAAG,GAAG,UAAU,CAAA;QACpB,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,GAAG,GAAG,CAAC,QAAQ,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,UAAU,EAAE,CAAA;QAG3E,GAAG,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAA;QAC1B,GAAG,CAAC,MAAM,CAAC,aAAa,GAAG,IAAI,CAAA;QAC/B,GAAG,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAA;QAE1B,OAAO,IAAI,EAAE,CAAA;IAChB,CAAC,CAAA;AACJ,CAAC;AAvCD,8CAuCC"}
|
package/lib/utils/i18nCh.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export default class i18nCh {
|
|
|
6
6
|
private constructor();
|
|
7
7
|
static getInstance(localesFolder?: string, nameSpaces?: string[], lang?: string): i18nCh;
|
|
8
8
|
private loadAllNamespaces;
|
|
9
|
+
private loadNamespacesFromPath;
|
|
9
10
|
private changeLanguage;
|
|
10
11
|
resolveNamespacesKeys(lang: string, vars?: any): any;
|
|
11
12
|
resolveSingleKey(key: string, lang: string, vars?: any): string;
|
|
12
13
|
loadNamespaces(nameSpaces?: string[]): void;
|
|
14
|
+
getResourceBundle(lng: string, ns: string): any;
|
|
13
15
|
}
|
package/lib/utils/i18nCh.js
CHANGED
|
@@ -6,6 +6,7 @@ const i18next_fs_backend_1 = tslib_1.__importDefault(require("i18next-fs-backend
|
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
const fs_1 = tslib_1.__importStar(require("fs"));
|
|
8
8
|
const log_1 = tslib_1.__importDefault(require("./log"));
|
|
9
|
+
const constants_1 = require("../constants/constants");
|
|
9
10
|
class i18nCh {
|
|
10
11
|
constructor(localesFolder = "", nameSpaces = [], lang = "en") {
|
|
11
12
|
this.nameSpaces = [];
|
|
@@ -47,15 +48,23 @@ class i18nCh {
|
|
|
47
48
|
return i18nCh.instance;
|
|
48
49
|
}
|
|
49
50
|
loadAllNamespaces() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
if (!this.localesFolder) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
const projectRootNamespaces = this.loadNamespacesFromPath(path_1.default.join(this.localesFolder, "en"));
|
|
55
|
+
const nodeModulesNamespaces = this.loadNamespacesFromPath(path_1.default.join(constants_1.NODE_MODULES_LOCALES_PATH, "en"));
|
|
56
|
+
return [...new Set([...projectRootNamespaces, ...nodeModulesNamespaces])];
|
|
57
|
+
}
|
|
58
|
+
loadNamespacesFromPath(folderPath) {
|
|
59
|
+
try {
|
|
60
|
+
return fs_1.default.readdirSync(folderPath)
|
|
61
|
+
.filter(file => path_1.default.extname(file) === ".json")
|
|
62
|
+
.map(file => path_1.default.basename(file, ".json"));
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
(0, log_1.default)(`Error reading directory ${folderPath}: ${error}`);
|
|
66
|
+
return [];
|
|
57
67
|
}
|
|
58
|
-
return jsonFiles;
|
|
59
68
|
}
|
|
60
69
|
changeLanguage(lang) {
|
|
61
70
|
this.i18nInst.changeLanguage(lang, (err) => {
|
|
@@ -109,6 +118,9 @@ class i18nCh {
|
|
|
109
118
|
});
|
|
110
119
|
}
|
|
111
120
|
}
|
|
121
|
+
getResourceBundle(lng, ns) {
|
|
122
|
+
return this.i18nInst.getResourceBundle(lng, ns);
|
|
123
|
+
}
|
|
112
124
|
}
|
|
113
125
|
exports.default = i18nCh;
|
|
114
126
|
//# sourceMappingURL=i18nCh.js.map
|
package/lib/utils/i18nCh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18nCh.js","sourceRoot":"","sources":["../../src/utils/i18nCh.ts"],"names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CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC;CAEH;AA/ID,yBA+IC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyLocales(): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyLocales = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const constants_1 = require("../constants/constants");
|
|
7
|
+
const log_1 = tslib_1.__importDefault(require("./log"));
|
|
8
|
+
function copyLocales() {
|
|
9
|
+
const sources = [constants_1.NODE_MODULES_LOCALES_PATH, `../${constants_1.NODE_MODULES_LOCALES_PATH}`];
|
|
10
|
+
const targets = ["../locales", "./locales"];
|
|
11
|
+
const copied = sources.some(src => targets.some(target => {
|
|
12
|
+
try {
|
|
13
|
+
fs_1.default.cpSync(src, target, { recursive: true });
|
|
14
|
+
(0, log_1.default)(`Locales copied from ${src} to ${target}`);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch (_) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
if (!copied) {
|
|
22
|
+
(0, log_1.default)("Unable to copy locales from any source to any target");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.copyLocales = copyLocales;
|
|
26
|
+
//# sourceMappingURL=locales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.js","sourceRoot":"","sources":["../../src/utils/locales.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,sDAAmE;AACnE,wDAAwB;AAExB,SAAgB,WAAW;IACzB,MAAM,OAAO,GAAG,CAAC,qCAAyB,EAAE,MAAM,qCAAyB,EAAE,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAC9B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACpB,IAAI,CAAC;YACH,YAAE,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5C,IAAA,aAAG,EAAC,uBAAuB,GAAG,OAAO,MAAM,EAAE,CAAC,CAAC;YAC/C,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CACL,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,IAAA,aAAG,EAAC,sDAAsD,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAnBD,kCAmBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@companieshouse/ch-node-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"author": "companieshouse",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"express": "^4.18.3",
|
|
41
41
|
"i18next": "^23.10.1",
|
|
42
42
|
"i18next-fs-backend": "^2.3.1",
|
|
43
|
-
"iso-639-1": "^3.1.2"
|
|
43
|
+
"iso-639-1": "^3.1.2",
|
|
44
|
+
"tslib": "^2.3.0"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/express": "^4.17.21",
|
package/templates/navbar.njk
CHANGED
|
@@ -26,8 +26,9 @@ It receives:
|
|
|
26
26
|
- href: the URL of the page the menu item will point to
|
|
27
27
|
- displayText: the text to display in the anchor
|
|
28
28
|
- userDisplayText: a text identifying the logged user, e.g. email address or name
|
|
29
|
+
- lang: an object containing language-specific strings for localization
|
|
29
30
|
#}
|
|
30
|
-
{% macro addNavbar(signInHref, menuItems, userDisplayText) %}
|
|
31
|
+
{% macro addNavbar(signInHref, menuItems, userDisplayText, lang) %}
|
|
31
32
|
<div class="js-toggle-nav" id="global-nav">
|
|
32
33
|
<nav role="navigation" class="content" aria-label="{{ lang.mainNavbar or 'The main navigation bar' }}">
|
|
33
34
|
{% if userDisplayText %}
|
|
@@ -57,8 +58,10 @@ A macro that adds a menu navigation bar with predefined items.
|
|
|
57
58
|
It receives:
|
|
58
59
|
- userDisplayText: a text identifying the logged user, e.g. email address or name
|
|
59
60
|
- chsMonitorGuiUrl: the URL for the 'Companies you follow' link
|
|
61
|
+
- lang: an object containing language-specific strings for localization
|
|
62
|
+
- displayAuthorisedAgent: a flag indicating whether to display the 'Authorised agent' menu item
|
|
60
63
|
#}
|
|
61
|
-
{% macro addPredefinedNavbar(userDisplayText, chsMonitorGuiUrl) %}
|
|
64
|
+
{% macro addPredefinedNavbar(userDisplayText, chsMonitorGuiUrl, lang, displayAuthorisedAgent) %}
|
|
62
65
|
{% set menuItems = [
|
|
63
66
|
{ id: "authorised-agent", href: "/authorised-agent", displayText: lang.authorisedAgent or "Authorised agent" } if displayAuthorisedAgent === "yes",
|
|
64
67
|
{ id: "your-companies", href: "/your-companies", displayText: lang.yourCompanies or "Your companies" },
|
|
@@ -69,6 +72,6 @@ It receives:
|
|
|
69
72
|
{ id: "user-signout", href: "/signout", displayText: lang.signOut or "Sign out" }
|
|
70
73
|
] | reject("falsy") %}
|
|
71
74
|
|
|
72
|
-
{{ addNavbar("/signin", menuItems, userDisplayText) }}
|
|
75
|
+
{{ addNavbar("/signin", menuItems, userDisplayText, lang) }}
|
|
73
76
|
|
|
74
|
-
{% endmacro %}
|
|
77
|
+
{% endmacro %}
|
|
File without changes
|
|
File without changes
|