@react-foundry/user-info 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,88 @@
1
+ React Foundry - User Info
2
+ =========================
3
+
4
+ A React context (with hook) for providing information on the user.
5
+
6
+ This is useful for:
7
+ - referring to the user by name
8
+ - letting them know that they are logged in
9
+ - communicating to them what they are allowed to do on the system with
10
+ their current permissions / roles
11
+
12
+ > **Note:** This is _NOT_ a security enforcing function; security should
13
+ > be enforced on the server-side in API endpoints and GraphQL
14
+ > resolvers.
15
+
16
+
17
+ Using this package
18
+ ------------------
19
+
20
+ First install the package into your project:
21
+
22
+ ```shell
23
+ npm install -S @react-foundry/user-info
24
+ ```
25
+
26
+ Then use it in your code as follows:
27
+
28
+ ```js
29
+ import React, { createElement as h } from 'react';
30
+ import { UserInfoContext, useUserInfo } from '@react-foundry/user-info';
31
+
32
+ const dummyUserInfo = {
33
+ username: 'DummyUser',
34
+ groups: ['DummyGroup'],
35
+ roles: ['DummyRole']
36
+ };
37
+
38
+ export const MyConsumer = props => {
39
+ const { username } = useUserInfo();
40
+
41
+ return (
42
+ <p>Welcome {username}.</p>
43
+ );
44
+ };
45
+
46
+ export const MyComponent = props => (
47
+ <UserInfo.Provider value={dummyUserInfo}>
48
+ <MyConsumer />
49
+ </UserInfo.Provider>
50
+ );
51
+
52
+ export default MyComponent;
53
+ ```
54
+
55
+ (Most users will only need to use the hook as the context has already
56
+ been set up for them.)
57
+
58
+
59
+ Working on this package
60
+ -----------------------
61
+
62
+ Before working on this package you must install its dependencies using
63
+ the following command:
64
+
65
+ ```shell
66
+ pnpm install
67
+ ```
68
+
69
+
70
+ ### Testing
71
+
72
+ ```shell
73
+ npm test
74
+ ```
75
+
76
+
77
+ ### Building
78
+
79
+ ```shell
80
+ npm run build
81
+ ```
82
+
83
+
84
+ ### Clean-up
85
+
86
+ ```shell
87
+ npm run clean
88
+ ```
@@ -0,0 +1,6 @@
1
+ import type { Maybe, UserInfo } from '@react-foundry/types';
2
+ import { Context } from 'react';
3
+ export declare const UserInfoContext: Context<Maybe<UserInfo>>;
4
+ export declare const useUserInfo: () => Maybe<UserInfo>;
5
+ export default UserInfoContext;
6
+ export type { UserInfo };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useUserInfo = exports.UserInfoContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.UserInfoContext = (0, react_1.createContext)(undefined);
6
+ const useUserInfo = () => ((0, react_1.useContext)(exports.UserInfoContext));
7
+ exports.useUserInfo = useUserInfo;
8
+ exports.default = exports.UserInfoContext;
@@ -0,0 +1,4 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const UserInfoContext = createContext(undefined);
3
+ export const useUserInfo = () => (useContext(UserInfoContext));
4
+ export default UserInfoContext;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@react-foundry/user-info",
3
+ "version": "0.1.0",
4
+ "description": "A React context for providing information on the user.",
5
+ "main": "dist/UserInfo.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/UserInfo.d.ts",
9
+ "import": "./dist/UserInfo.mjs",
10
+ "require": "./dist/UserInfo.js",
11
+ "default": "./dist/UserInfo.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
+ "keywords": [
20
+ "react-components"
21
+ ],
22
+ "peerDependencies": {
23
+ "react": "^19.2.3"
24
+ },
25
+ "devDependencies": {
26
+ "@types/react": "19.2.9",
27
+ "jest": "30.2.0",
28
+ "jest-environment-jsdom": "30.2.0",
29
+ "ts-jest": "29.4.6",
30
+ "typescript": "5.9.3",
31
+ "@react-foundry/component-test-helpers": "0.1.0",
32
+ "@react-foundry/types": "0.1.0"
33
+ },
34
+ "scripts": {
35
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
36
+ "build": "npm run build:esm && npm run build:cjs",
37
+ "build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
38
+ "build:cjs": "tsc",
39
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
40
+ },
41
+ "module": "dist/UserInfo.mjs",
42
+ "typings": "dist/UserInfo.d.ts"
43
+ }