@hmcts/opal-frontend-common-node 0.0.6 → 0.0.8

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 CHANGED
@@ -13,6 +13,7 @@ This is a shared Node.js library containing common middleware, configurations, a
13
13
  - [Linting and Formatting](#linting-and-formatting)
14
14
  - [Exports](#exports)
15
15
  - [Using This Library in a Node.js Application](#using-this-library-in-a-nodejs-application)
16
+ - [Switching Between Local and Published Versions](#switching-between-local-and-published-versions)
16
17
 
17
18
  ## Getting Started
18
19
 
@@ -29,34 +30,70 @@ Ensure you have the following installed:
29
30
  yarn
30
31
  ```
31
32
 
32
- ## Scripts
33
+ ## Build Process
33
34
 
34
- The following commands are available in the `package.json`:
35
+ Run the following to build the project:
35
36
 
36
- - `yarn build`
37
- Cleans the `dist/` folder, compiles TypeScript, and copies relevant files to `dist/`.
37
+ ```bash
38
+ yarn build
39
+ ```
38
40
 
39
- - `yarn clean`
40
- Removes the `dist/` directory.
41
+ The compiled output will be available in the `dist/` folder. It includes `index.js`, type declarations, and any exported modules listed in the `exports` field.
41
42
 
42
- - `yarn lint`
43
- Runs ESLint across the `src/` directory and checks formatting using Prettier.
43
+ ## Switching Between Local and Published Versions
44
44
 
45
- - `yarn prettier`
46
- Checks if files are formatted correctly.
45
+ See [opal-frontend](https://github.com/hmcts/opal-frontend) for how this library is consumed in practice.
47
46
 
48
- - `yarn prettier:fix`
49
- Automatically formats the codebase.
47
+ Use the `yarn import:local:common-node-lib` and `yarn import:published:common-node-lib` scripts in your consuming project (`opal-frontend`) to switch between local development and the published npm version of the library.
50
48
 
51
- ## Build Process
49
+ To use a published version of this library during development in another project:
50
+ 1. In the consuming project, run:
51
+ ```bash
52
+ yarn import:published:common-node-lib
53
+ ```
52
54
 
53
- Run the following to build the project:
55
+ To use a local version of this library during development in another project:
54
56
 
55
- ```bash
56
- yarn build
57
- ```
57
+ 1. Build this library:
58
+ ```bash
59
+ yarn build
60
+ ```
58
61
 
59
- The compiled output will be available in the `dist/` folder. It includes `index.js`, type declarations, and any exported modules listed in the `exports` field.
62
+ 2. In your consuming project (e.g. `opal-frontend`), ensure you have set an environment variable pointing to the local build:
63
+
64
+ ```bash
65
+ # In your shell config file (.zshrc, .bash_profile, or .bashrc)
66
+ export COMMON_NODE_LIB_PATH="[INSERT PATH TO COMMON NODE LIB DIST FOLDER]"
67
+ ```
68
+
69
+ 3. In the consuming project (e.g. `opal-frontend`), run:
70
+ ```bash
71
+ yarn import:local:common-node-lib
72
+ ```
73
+
74
+ This will remove the published version and install the local build using the path provided.
75
+
76
+ 4. To switch back to the published version:
77
+ ```bash
78
+ yarn import:published:common-node-lib
79
+ ```
80
+
81
+ This setup makes it easy to switch between development and production versions of the shared library.
82
+
83
+ ## Publish the library
84
+
85
+ Once any changes have been approved and merged into the main branch, you'll need to publish a new version of the library so that it can be consumed by other projects. To do this:
86
+
87
+ 1. Increment the version number in both the library's root `package.json`.
88
+ 2. Commit and push those changes to the main branch.
89
+ 3. On GitHub, create a new [release](https://github.com/hmcts/opal-frontend-common-node-lib/releases) and use the updated version number as a tag.
90
+ 4. When the release workflow completes, the library will be published.
91
+
92
+ After this new version of the library is published, any consuming application should remove the local or outdated version of the library and then install the published version by running:
93
+
94
+ ```bash
95
+ yarn import:published:common-node-lib
96
+ ```
60
97
 
61
98
  ## Linting and Formatting
62
99
 
@@ -91,19 +128,21 @@ import {
91
128
 
92
129
  Refer to the `exports` block in `package.json` for the full list of available modules.
93
130
 
94
- ## Using This Library in a Node.js Application
131
+ ## Commonly Used Commands
95
132
 
96
- Install the published package using:
133
+ The following commands are available in the `package.json`:
97
134
 
98
- ```bash
99
- yarn add @hmcts/opal-frontend-common-node
100
- ```
135
+ - `yarn build`
136
+ Cleans the `dist/` folder, compiles TypeScript, and copies relevant files to `dist/`.
101
137
 
102
- If consuming from a local build:
138
+ - `yarn clean`
139
+ Removes the `dist/` directory.
103
140
 
104
- ```bash
105
- yarn remove @hmcts/opal-frontend-common-node
106
- yarn add @hmcts/opal-frontend-common-node@file:../opal-frontend-common-node-lib/dist
107
- ```
141
+ - `yarn lint`
142
+ Runs ESLint across the `src/` directory and checks formatting using Prettier.
108
143
 
109
- Ensure paths reflect your actual local setup when using the `file:` specifier.
144
+ - `yarn prettier`
145
+ Checks if files are formatted correctly.
146
+
147
+ - `yarn prettier:fix`
148
+ Automatically formats the codebase.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/csrf-token/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAW,MAAM,SAAS,CAAC;AAE/C,qBAAa,SAAS;IACb,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;CA+BjH"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/csrf-token/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,SAAS;IACb,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;CA8BjH"}
@@ -10,9 +10,8 @@ export class CSRFToken {
10
10
  secure: secure,
11
11
  path: '/',
12
12
  },
13
- getTokenFromRequest: (req) => {
14
- return req.cookies[cookieName].split('|')[0] ?? null;
15
- },
13
+ getSessionIdentifier: (req) => req.session.id,
14
+ getCsrfTokenFromRequest: (req) => req.cookies[cookieName].split('|')[0] ?? null,
16
15
  });
17
16
  app.use((req, res, next) => {
18
17
  if (ignore.includes(req.url)) {
@@ -24,7 +23,7 @@ export class CSRFToken {
24
23
  });
25
24
  app.use((req, res, next) => {
26
25
  if (req.csrfToken) {
27
- req.csrfToken(true);
26
+ req.csrfToken({ overwrite: true, validateOnReuse: true });
28
27
  }
29
28
  next();
30
29
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/csrf-token/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,MAAM,OAAO,SAAS;IACb,SAAS,CAAC,GAAgB,EAAE,MAAc,EAAE,UAAkB,EAAE,QAAiB,EAAE,MAAe;QACvG,MAAM,MAAM,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAEvC,MAAM,EAAE,oBAAoB,EAAE,GAAG,UAAU,CAAC;YAC1C,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;YACvB,UAAU,EAAE,UAAU;YACtB,aAAa,EAAE;gBACb,QAAQ,EAAE,QAAQ;gBAClB,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,GAAG;aACV;YACD,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;gBAC3B,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;YACvD,CAAC;SACF,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC7B,IAAI,EAAE,CAAC;YACT,CAAC;iBAAM,CAAC;gBACN,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YACvC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,CAAC,CAAC,GAAY,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAClC,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;gBAClB,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;YACD,IAA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CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@hmcts/opal-frontend-common-node",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
+ "license": "MIT",
5
6
  "description": "Common nodejs library components for opal",
6
7
  "main": "dist/index",
7
8
  "types": "dist/index.d.ts",
@@ -23,14 +24,14 @@
23
24
  "config": "^3.3.9",
24
25
  "connect-redis": "^8.0.0",
25
26
  "cookie-parser": "^1.4.6",
26
- "csrf-csrf": "^3.0.6",
27
- "express": "^4.15.2",
27
+ "csrf-csrf": "^4.0.0",
28
+ "express": "^5.0.0",
28
29
  "express-session": "^1.17.3",
29
30
  "helmet": "^8.0.0",
30
31
  "http-proxy-middleware": "^3.0.0",
31
32
  "luxon": "^3.4.3",
32
33
  "prettier": "^3.0.3",
33
- "redis": "^4.6.11",
34
+ "redis": "^5.0.0",
34
35
  "session-file-store": "^1.5.0",
35
36
  "xml2js": "^0.6.2"
36
37
  },
@@ -41,8 +42,8 @@
41
42
  "@types/luxon": "^3.4.2",
42
43
  "@types/node": "^22.0.0",
43
44
  "@types/session-file-store": "^1.2.5",
44
- "@typescript-eslint/eslint-plugin": "8.29.1",
45
- "@typescript-eslint/parser": "8.29.1",
45
+ "@typescript-eslint/eslint-plugin": "8.32.0",
46
+ "@typescript-eslint/parser": "8.32.0",
46
47
  "eslint": "^9.0.0",
47
48
  "eslint-plugin-prettier": "^5.2.6",
48
49
  "typescript": "~5.8.0",
package/type.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import 'express';
2
-
3
- declare module 'express' {
4
- export interface Request {
5
- csrfToken?: (arg?: boolean) => string;
6
- }
7
- }