@dhis2/app-service-user 3.14.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 ADDED
@@ -0,0 +1,11 @@
1
+ # DHIS2 App User Service
2
+
3
+ Application User Services for [DHIS2](https://dhis2.org) applications
4
+
5
+ This library is intended for use with the [DHIS2 Application Platform](https://github.com/dhis2/app-platform).
6
+
7
+ ## Installation
8
+
9
+ This package is internal to `@dhis2/app-runtime` and generally should not be installed independently.
10
+
11
+ See [the docs](https://runtime.dhis2.nu) for more.
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useCurrentUserInfo = exports.UserProvider = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
9
+ const UserContext = /*#__PURE__*/_react.default.createContext(undefined);
10
+ const UserProvider = _ref => {
11
+ let {
12
+ userInfo,
13
+ children
14
+ } = _ref;
15
+ return /*#__PURE__*/_react.default.createElement(UserContext.Provider, {
16
+ value: userInfo
17
+ }, children);
18
+ };
19
+ exports.UserProvider = UserProvider;
20
+ const useCurrentUserInfo = () => (0, _react.useContext)(UserContext);
21
+ exports.useCurrentUserInfo = useCurrentUserInfo;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+ var _react2 = _interopRequireDefault(require("react"));
5
+ var _UserProvider = require("../UserProvider");
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
+ const mockUser = {
8
+ id: 'user123',
9
+ username: 'Test User',
10
+ firstName: 'Test',
11
+ surname: 'User',
12
+ displayName: 'Test User (from UserInfo prop)',
13
+ authorities: [],
14
+ organisationUnits: []
15
+ };
16
+ test('When a valid userInfo object is provided', () => {
17
+ const wrapper = _ref => {
18
+ let {
19
+ children
20
+ } = _ref;
21
+ return /*#__PURE__*/_react2.default.createElement(_UserProvider.UserProvider, {
22
+ userInfo: mockUser
23
+ }, children);
24
+ };
25
+ const {
26
+ result
27
+ } = (0, _react.renderHook)(() => (0, _UserProvider.useCurrentUserInfo)(), {
28
+ wrapper
29
+ });
30
+ expect(result.current).toEqual(mockUser);
31
+ });
32
+ test('When the userInfo object provided is undefined', async () => {
33
+ const wrapper = _ref2 => {
34
+ let {
35
+ children
36
+ } = _ref2;
37
+ return /*#__PURE__*/_react2.default.createElement(_UserProvider.UserProvider, {
38
+ userInfo: undefined
39
+ }, children);
40
+ };
41
+ const {
42
+ result
43
+ } = (0, _react.renderHook)(() => (0, _UserProvider.useCurrentUserInfo)(), {
44
+ wrapper
45
+ });
46
+ expect(result.current).toEqual(undefined);
47
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "UserProvider", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _UserProvider.UserProvider;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "useCurrentUserInfo", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _UserProvider.useCurrentUserInfo;
16
+ }
17
+ });
18
+ var _UserProvider = require("./UserProvider");
@@ -0,0 +1,3 @@
1
+ {
2
+ "__MANIFEST_APP_TITLE_Application title": "@dhis2/app-service-user"
3
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _d2I18n = _interopRequireDefault(require("@dhis2/d2-i18n"));
8
+ var _translations = _interopRequireDefault(require("./en/translations.json"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ //------------------------------------------------------------------------------
11
+ // <auto-generated>
12
+ // This code was generated by d2-i18n-generate.
13
+ //
14
+ // Changes to this file may cause incorrect behavior and will be lost if
15
+ // the code is regenerated.
16
+ // </auto-generated>
17
+ //------------------------------------------------------------------------------
18
+
19
+ const namespace = 'default';
20
+ _d2I18n.default.addResources('en', namespace, _translations.default);
21
+ var _default = exports.default = _d2I18n.default;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ process.on('unhandledRejection', err => {
5
+ throw err;
6
+ });
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,12 @@
1
+ import React, { useContext } from 'react';
2
+ const UserContext = /*#__PURE__*/React.createContext(undefined);
3
+ export const UserProvider = _ref => {
4
+ let {
5
+ userInfo,
6
+ children
7
+ } = _ref;
8
+ return /*#__PURE__*/React.createElement(UserContext.Provider, {
9
+ value: userInfo
10
+ }, children);
11
+ };
12
+ export const useCurrentUserInfo = () => useContext(UserContext);
@@ -0,0 +1,44 @@
1
+ import { renderHook } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { useCurrentUserInfo, UserProvider } from '../UserProvider';
4
+ const mockUser = {
5
+ id: 'user123',
6
+ username: 'Test User',
7
+ firstName: 'Test',
8
+ surname: 'User',
9
+ displayName: 'Test User (from UserInfo prop)',
10
+ authorities: [],
11
+ organisationUnits: []
12
+ };
13
+ test('When a valid userInfo object is provided', () => {
14
+ const wrapper = _ref => {
15
+ let {
16
+ children
17
+ } = _ref;
18
+ return /*#__PURE__*/React.createElement(UserProvider, {
19
+ userInfo: mockUser
20
+ }, children);
21
+ };
22
+ const {
23
+ result
24
+ } = renderHook(() => useCurrentUserInfo(), {
25
+ wrapper
26
+ });
27
+ expect(result.current).toEqual(mockUser);
28
+ });
29
+ test('When the userInfo object provided is undefined', async () => {
30
+ const wrapper = _ref2 => {
31
+ let {
32
+ children
33
+ } = _ref2;
34
+ return /*#__PURE__*/React.createElement(UserProvider, {
35
+ userInfo: undefined
36
+ }, children);
37
+ };
38
+ const {
39
+ result
40
+ } = renderHook(() => useCurrentUserInfo(), {
41
+ wrapper
42
+ });
43
+ expect(result.current).toEqual(undefined);
44
+ });
@@ -0,0 +1 @@
1
+ export { UserProvider, useCurrentUserInfo } from './UserProvider';
@@ -0,0 +1,3 @@
1
+ {
2
+ "__MANIFEST_APP_TITLE_Application title": "@dhis2/app-service-user"
3
+ }
@@ -0,0 +1,13 @@
1
+ //------------------------------------------------------------------------------
2
+ // <auto-generated>
3
+ // This code was generated by d2-i18n-generate.
4
+ //
5
+ // Changes to this file may cause incorrect behavior and will be lost if
6
+ // the code is regenerated.
7
+ // </auto-generated>
8
+ //------------------------------------------------------------------------------
9
+ import i18n from '@dhis2/d2-i18n';
10
+ import enTranslations from './en/translations.json';
11
+ const namespace = 'default';
12
+ i18n.addResources('en', namespace, enTranslations);
13
+ export default i18n;
@@ -0,0 +1,4 @@
1
+ import '@testing-library/jest-dom';
2
+ process.on('unhandledRejection', err => {
3
+ throw err;
4
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { CurrentUser } from './types';
3
+ export declare const UserProvider: ({ userInfo, children, }: {
4
+ userInfo: CurrentUser | undefined;
5
+ children: React.ReactNode;
6
+ }) => React.JSX.Element;
7
+ export declare const useCurrentUserInfo: () => CurrentUser | undefined;
@@ -0,0 +1,2 @@
1
+ export { UserProvider, useCurrentUserInfo } from './UserProvider';
2
+ export type { CurrentUser } from './types';
@@ -0,0 +1,70 @@
1
+ export interface CurrentUser {
2
+ id: string;
3
+ username: string;
4
+ displayName: string;
5
+ authorities: string[];
6
+ organisationUnits: Array<{
7
+ id: string;
8
+ }>;
9
+ name?: string;
10
+ surname?: string;
11
+ firstName?: string;
12
+ email?: string;
13
+ emailVerified?: boolean;
14
+ introduction?: string;
15
+ birthday?: string;
16
+ nationality?: string;
17
+ education?: string;
18
+ interests?: string;
19
+ whatsApp?: string;
20
+ facebookMessenger?: string;
21
+ skype?: string;
22
+ telegram?: string;
23
+ twitter?: string;
24
+ employer?: string;
25
+ languages?: string;
26
+ gender?: string;
27
+ jobTitle?: string;
28
+ created?: string;
29
+ lastUpdated?: string;
30
+ access?: {
31
+ manage: boolean;
32
+ externalize?: boolean;
33
+ write: boolean;
34
+ read: boolean;
35
+ update: boolean;
36
+ delete: boolean;
37
+ [key: string]: any;
38
+ };
39
+ settings?: {
40
+ keyDbLocale?: string;
41
+ keyMessageSmsNotification?: boolean;
42
+ keyTrackerDashboardLayout?: string;
43
+ keyStyle?: string;
44
+ keyUiLocale?: string;
45
+ keyAnalysisDisplayProperty?: string;
46
+ keyMessageEmailNotification?: boolean;
47
+ [key: string]: any;
48
+ };
49
+ userGroups?: Array<{
50
+ id: string;
51
+ }>;
52
+ userRoles?: Array<{
53
+ id: string;
54
+ }>;
55
+ dataViewOrganisationUnits?: Array<{
56
+ id: string;
57
+ }>;
58
+ teiSearchOrganisationUnits?: Array<{
59
+ id: string;
60
+ }>;
61
+ programs?: Array<string>;
62
+ dataSets?: Array<string>;
63
+ patTokens?: Array<{
64
+ id: string;
65
+ }>;
66
+ attributeValues?: Array<any>;
67
+ favorites?: Array<any>;
68
+ translations?: Array<any>;
69
+ twoFactorType?: string;
70
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@dhis2/app-service-user",
3
+ "version": "3.14.8",
4
+ "main": "./build/cjs/index.js",
5
+ "module": "./build/es/index.js",
6
+ "types": "build/types/index.d.ts",
7
+ "exports": {
8
+ "import": "./build/es/index.js",
9
+ "require": "./build/cjs/index.js",
10
+ "types": "./build/types/index.d.ts"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/dhis2/app-runtime.git",
15
+ "directory": "services/user"
16
+ },
17
+ "author": "Austin McGee <austin@dhis2.org>",
18
+ "license": "BSD-3-Clause",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "files": [
23
+ "build/**"
24
+ ],
25
+ "dependencies": {
26
+ "prop-types": "^15.7.2"
27
+ },
28
+ "peerDependencies": {
29
+ "react": "^16.8.6 || ^18",
30
+ "react-dom": "^16.8.6 || ^18"
31
+ },
32
+ "scripts": {
33
+ "clean": "rimraf ./build/*",
34
+ "build:types": "tsc --emitDeclarationOnly --outDir ./build/types",
35
+ "build:package": "d2-app-scripts build",
36
+ "build": "concurrently -n build,types \"yarn build:package\" \"yarn build:types\"",
37
+ "watch": "NODE_ENV=development concurrently -n build,types \"yarn build:package --watch\" \"yarn build:types --watch\"",
38
+ "type-check": "tsc --noEmit --allowJs --checkJs",
39
+ "type-check:watch": "yarn type-check --watch",
40
+ "test": "TZ=Etc/UTC d2-app-scripts test",
41
+ "coverage": "yarn test --coverage"
42
+ }
43
+ }