@react-foundry/react-router-context 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2019-2025 Crown Copyright
4
+ Copyright (C) 2019-2026 Daniel A.C. Martin
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ of the Software, and to permit persons to whom the Software is furnished to do
11
+ so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ React Foundry - React-Router-Context
2
+ ====================================
3
+
4
+ A collection of React Router contexts for use in React Foundry applications.
5
+
6
+
7
+ Using this package
8
+ ------------------
9
+
10
+ First install the package into your project:
11
+
12
+ ```shell
13
+ npm install -S @react-foundry/react-router-context
14
+ ```
15
+
16
+ Then use it in your code as follows:
17
+
18
+ ```js
19
+ import type { RouterContextProvider } from '@react-foundry/react-router-context'; // Replaces import from react-router
20
+ import { userInfoContext, cspNonceContext } from '@react-foundry/react-router-context';
21
+
22
+ export const loader = async ({ context: _context }: Route.LoaderArgs) => {
23
+ const context = _context as RouterContextProvider; // Needed to get extra properties recognised
24
+
25
+ const cspNonce = context.cspNonce;
26
+ const userInfo = context.userInfo;
27
+
28
+ // Alternatively...
29
+ const cspNonceAlt = context.get(cspNonceContext);
30
+ const userInfoAlt = context.get(userInfoContext);
31
+
32
+ // ...
33
+ };
34
+ ```
35
+
36
+
37
+ Working on this package
38
+ -----------------------
39
+
40
+ Before working on this package you must install its dependencies using
41
+ the following command:
42
+
43
+ ```shell
44
+ pnpm install
45
+ ```
46
+
47
+
48
+ ### Building
49
+
50
+ Build the package by compiling the source code.
51
+
52
+ ```shell
53
+ npm run build
54
+ ```
55
+
56
+
57
+ ### Clean-up
58
+
59
+ Remove any previously built files.
60
+
61
+ ```shell
62
+ npm run clean
63
+ ```
@@ -0,0 +1,11 @@
1
+ import type { RouterContext, RouterContextProvider } from 'react-router';
2
+ import type { Maybe, UserInfo } from '@react-foundry/types';
3
+ export declare const userInfoContext: RouterContext<Maybe<UserInfo>>;
4
+ export declare const cspNonceContext: RouterContext<Maybe<string>>;
5
+ type Extras = {
6
+ cspNonce: string;
7
+ user: UserInfo;
8
+ };
9
+ export type EnhancedProvider = RouterContextProvider & Partial<Extras>;
10
+ export declare const sanitiseUserInfo: <T extends UserInfo>({ displayName, emails, expiry, groups, name, photos, roles, username }: T) => UserInfo;
11
+ export type { EnhancedProvider as RouterContextProvider };
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitiseUserInfo = exports.cspNonceContext = exports.userInfoContext = void 0;
4
+ exports.userInfoContext = 'USER_INFO';
5
+ exports.cspNonceContext = 'CSP_NONCE';
6
+ const sanitiseUserInfo = ({ displayName, emails, expiry, groups, name, photos, roles, username }) => ({
7
+ displayName,
8
+ emails,
9
+ expiry,
10
+ groups,
11
+ name,
12
+ photos,
13
+ roles,
14
+ username
15
+ });
16
+ exports.sanitiseUserInfo = sanitiseUserInfo;
package/dist/index.mjs ADDED
@@ -0,0 +1,12 @@
1
+ export const userInfoContext = 'USER_INFO';
2
+ export const cspNonceContext = 'CSP_NONCE';
3
+ export const sanitiseUserInfo = ({ displayName, emails, expiry, groups, name, photos, roles, username }) => ({
4
+ displayName,
5
+ emails,
6
+ expiry,
7
+ groups,
8
+ name,
9
+ photos,
10
+ roles,
11
+ username
12
+ });
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@react-foundry/react-router-context",
3
+ "version": "0.1.0",
4
+ "description": "A collection of React Router contexts for use in React Foundry applications.",
5
+ "main": "dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.mjs",
10
+ "require": "./dist/index.js",
11
+ "default": "./dist/index.mjs"
12
+ }
13
+ },
14
+ "files": [
15
+ "/dist"
16
+ ],
17
+ "author": "Daniel A.C. Martin <npm@daniel-martin.co.uk> (http://daniel-martin.co.uk/)",
18
+ "license": "MIT",
19
+ "engines": {
20
+ "node": ">=18.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "jest": "30.2.0",
24
+ "jest-environment-jsdom": "30.2.0",
25
+ "react-router": "7.13.0",
26
+ "ts-jest": "29.4.6",
27
+ "typescript": "5.9.3",
28
+ "@react-foundry/types": "0.1.0"
29
+ },
30
+ "scripts": {
31
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
32
+ "build": "npm run build:esm && npm run build:cjs",
33
+ "build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
34
+ "build:cjs": "tsc",
35
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
36
+ },
37
+ "module": "dist/index.mjs",
38
+ "typings": "dist/index.d.ts"
39
+ }