@proteinjs/user-ui 1.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.1 (2024-04-19)
7
+
8
+ **Note:** Version bump only for package @proteinjs/user-ui
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Brent Bahry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ /** Load Dependency Source Graphs */
2
+ import '@proteinjs/reflection';
3
+ import '@proteinjs/server-api';
4
+ import '@proteinjs/ui';
5
+ import '@proteinjs/user';
6
+ import 'moment';
7
+ import 'react';
8
+ import 'react-dom';
9
+ export * from '../index';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,eAAe,CAAC;AACvB,OAAO,iBAAiB,CAAC;AACzB,OAAO,QAAQ,CAAC;AAChB,OAAO,OAAO,CAAC;AACf,OAAO,WAAW,CAAC;AAyBnB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /** Load Dependency Source Graphs */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ require("@proteinjs/reflection");
19
+ require("@proteinjs/server-api");
20
+ require("@proteinjs/ui");
21
+ require("@proteinjs/user");
22
+ require("moment");
23
+ require("react");
24
+ require("react-dom");
25
+ /** Generate Source Graph */
26
+ var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"loginPage\",\"filePath\":\"/home/runner/work/user/user/packages/ui/src/pages/Login.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/loginPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/ui/Page\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"signupPage\",\"filePath\":\"/home/runner/work/user/user/packages/ui/src/pages/Signup.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/signupPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}}],\"edges\":[{\"v\":\"@proteinjs/user-ui/loginPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"}]}";
27
+ /** Generate Source Links */
28
+ var Login_1 = require("../src/pages/Login");
29
+ var Signup_1 = require("../src/pages/Signup");
30
+ var sourceLinks = {
31
+ '@proteinjs/user-ui/loginPage': Login_1.loginPage,
32
+ '@proteinjs/user-ui/signupPage': Signup_1.signupPage,
33
+ };
34
+ /** Load Source Graph and Links */
35
+ var reflection_1 = require("@proteinjs/reflection");
36
+ reflection_1.SourceRepository.merge(sourceGraph, sourceLinks);
37
+ __exportStar(require("../index"), exports);
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,iCAA+B;AAC/B,yBAAuB;AACvB,2BAAyB;AACzB,kBAAgB;AAChB,iBAAe;AACf,qBAAmB;AAGnB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,yiDAAyiD,CAAC;AAG9jD,4BAA4B;AAE5B,4CAA+C;AAC/C,8CAAiD;AAEjD,IAAM,WAAW,GAAG;IACnB,8BAA8B,EAAE,iBAAS;IACzC,+BAA+B,EAAE,mBAAU;CAC3C,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
@@ -0,0 +1,2 @@
1
+ export * from './src/AuthenticatedPageContainer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./src/AuthenticatedPageContainer"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAiD"}
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { PageContainerProps } from '@proteinjs/ui';
3
+ export type AuthenticatedPageContainerProps = Omit<PageContainerProps, 'auth'>;
4
+ export declare function AuthenticatedPageContainer(props: AuthenticatedPageContainerProps): React.JSX.Element;
5
+ //# sourceMappingURL=AuthenticatedPageContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticatedPageContainer.d.ts","sourceRoot":"","sources":["../../src/AuthenticatedPageContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAuB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIxE,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AAE/E,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,qBAyChF"}
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ var __importDefault = (this && this.__importDefault) || function (mod) {
61
+ return (mod && mod.__esModule) ? mod : { "default": mod };
62
+ };
63
+ Object.defineProperty(exports, "__esModule", { value: true });
64
+ exports.AuthenticatedPageContainer = void 0;
65
+ var react_1 = __importDefault(require("react"));
66
+ var ui_1 = require("@proteinjs/ui");
67
+ var user_1 = require("@proteinjs/user");
68
+ var Login_1 = require("./pages/Login");
69
+ function AuthenticatedPageContainer(props) {
70
+ var _this = this;
71
+ var other = __rest(props, []);
72
+ var _a = react_1.default.useState(user_1.UserAuth.isLoggedIn()), isLoggedIn = _a[0], setIsLoggedIn = _a[1];
73
+ return (react_1.default.createElement(ui_1.PageContainer, __assign({ auth: {
74
+ isLoggedIn: isLoggedIn,
75
+ canViewPage: function (page) {
76
+ var _a, _b, _c, _d;
77
+ if ((_a = page.auth) === null || _a === void 0 ? void 0 : _a.public)
78
+ return true;
79
+ if ((_b = page.auth) === null || _b === void 0 ? void 0 : _b.allUsers)
80
+ return user_1.UserAuth.isLoggedIn();
81
+ if (!((_c = page.auth) === null || _c === void 0 ? void 0 : _c.roles))
82
+ return user_1.UserAuth.hasRole('admin');
83
+ return user_1.UserAuth.hasRoles((_d = page.auth) === null || _d === void 0 ? void 0 : _d.roles);
84
+ },
85
+ login: Login_1.loginPath,
86
+ logout: function () { return __awaiter(_this, void 0, void 0, function () {
87
+ var response;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0: return [4 /*yield*/, fetch(user_1.routes.logout.path, {
91
+ method: user_1.routes.logout.method,
92
+ redirect: 'follow',
93
+ credentials: 'same-origin',
94
+ headers: {
95
+ 'Content-Type': 'application/json'
96
+ }
97
+ })];
98
+ case 1:
99
+ response = _a.sent();
100
+ if (response.status != 200)
101
+ throw new Error("Failed to log out");
102
+ new user_1.UserRepo().setUser(user_1.guestUser);
103
+ setIsLoggedIn(false);
104
+ return [2 /*return*/, Login_1.loginPath];
105
+ }
106
+ });
107
+ }); }
108
+ } }, other)));
109
+ }
110
+ exports.AuthenticatedPageContainer = AuthenticatedPageContainer;
111
+ //# sourceMappingURL=AuthenticatedPageContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticatedPageContainer.js","sourceRoot":"","sources":["../../src/AuthenticatedPageContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAwE;AACxE,wCAAwE;AACxE,uCAA0C;AAI1C,SAAgB,0BAA0B,CAAC,KAAsC;IAAjF,iBAyCC;IAxCG,IAAW,KAAK,UAAK,KAAK,EAApB,EAAY,CAAQ,CAAC;IACrB,IAAA,KAA8B,eAAK,CAAC,QAAQ,CAAC,eAAQ,CAAC,UAAU,EAAE,CAAC,EAAlE,UAAU,QAAA,EAAE,aAAa,QAAyC,CAAC;IAE1E,OAAO,CACH,8BAAC,kBAAa,aACV,IAAI,EAAE;YACF,UAAU,YAAA;YACV,WAAW,EAAE,UAAC,IAAU;;gBACpB,IAAI,MAAA,IAAI,CAAC,IAAI,0CAAE,MAAM;oBACjB,OAAO,IAAI,CAAC;gBAEhB,IAAI,MAAA,IAAI,CAAC,IAAI,0CAAE,QAAQ;oBACnB,OAAO,eAAQ,CAAC,UAAU,EAAE,CAAC;gBAEjC,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAA;oBACjB,OAAO,eAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAErC,OAAO,eAAQ,CAAC,QAAQ,CAAC,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC,CAAC;YAC/C,CAAC;YACD,KAAK,EAAE,iBAAS;YAChB,MAAM,EAAE;;;;gCACa,qBAAM,KAAK,CAAC,aAAM,CAAC,MAAM,CAAC,IAAI,EAAE;gCAC7C,MAAM,EAAE,aAAM,CAAC,MAAM,CAAC,MAAM;gCAC5B,QAAQ,EAAE,QAAQ;gCAClB,WAAW,EAAE,aAAa;gCAC1B,OAAO,EAAE;oCACL,cAAc,EAAE,kBAAkB;iCACrC;6BACJ,CAAC,EAAA;;4BAPI,QAAQ,GAAG,SAOf;4BACF,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG;gCACtB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;4BAEzC,IAAI,eAAQ,EAAE,CAAC,OAAO,CAAC,gBAAS,CAAC,CAAC;4BAClC,aAAa,CAAC,KAAK,CAAC,CAAC;4BACrB,sBAAO,iBAAS,EAAC;;;iBACpB;SACJ,IACG,KAAK,EACX,CACL,CAAC;AACN,CAAC;AAzCD,gEAyCC"}
@@ -0,0 +1,4 @@
1
+ import { Page } from '@proteinjs/ui';
2
+ export declare const loginPath = "login";
3
+ export declare const loginPage: Page;
4
+ //# sourceMappingURL=Login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Login.d.ts","sourceRoot":"","sources":["../../../src/pages/Login.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA+D,MAAM,eAAe,CAAC;AAGlG,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,SAAS,EAAE,IAgBvB,CAAA"}
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.loginPage = exports.loginPath = void 0;
58
+ var react_1 = __importDefault(require("react"));
59
+ var ui_1 = require("@proteinjs/ui");
60
+ var user_1 = require("@proteinjs/user");
61
+ exports.loginPath = 'login';
62
+ exports.loginPage = {
63
+ name: 'Login',
64
+ path: exports.loginPath,
65
+ auth: {
66
+ public: true,
67
+ },
68
+ component: function () { return (react_1.default.createElement(ui_1.FormPage, null,
69
+ react_1.default.createElement(ui_1.Form, { name: 'Login', createFields: function () { return new LoginFields(); }, fieldLayout: ['email', 'password'], buttons: buttons }))); }
70
+ };
71
+ var LoginFields = /** @class */ (function (_super) {
72
+ __extends(LoginFields, _super);
73
+ function LoginFields() {
74
+ var _this = _super !== null && _super.apply(this, arguments) || this;
75
+ _this.email = (0, ui_1.textField)({
76
+ name: 'email'
77
+ });
78
+ _this.password = (0, ui_1.textField)({
79
+ name: 'password',
80
+ isPassword: true
81
+ });
82
+ return _this;
83
+ }
84
+ LoginFields.create = function () {
85
+ return new LoginFields();
86
+ };
87
+ return LoginFields;
88
+ }(ui_1.Fields));
89
+ var buttons = {
90
+ clear: ui_1.clearButton,
91
+ login: {
92
+ name: 'Login',
93
+ style: {
94
+ color: 'primary',
95
+ variant: 'contained',
96
+ },
97
+ onClick: function (fields, buttons) { return __awaiter(void 0, void 0, void 0, function () {
98
+ var response, body;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0: return [4 /*yield*/, fetch(user_1.routes.login.path, {
102
+ method: user_1.routes.login.method,
103
+ body: JSON.stringify({
104
+ email: fields.email.field.value,
105
+ password: fields.password.field.value
106
+ }),
107
+ redirect: 'follow',
108
+ credentials: 'same-origin',
109
+ headers: {
110
+ 'Content-Type': 'application/json'
111
+ }
112
+ })];
113
+ case 1:
114
+ response = _a.sent();
115
+ if (response.status != 200)
116
+ throw new Error("Failed to login, error: ".concat(response.statusText));
117
+ return [4 /*yield*/, response.json()];
118
+ case 2:
119
+ body = _a.sent();
120
+ if (body.error)
121
+ throw new Error(body.error);
122
+ window.location.href = '/';
123
+ return [2 /*return*/];
124
+ }
125
+ });
126
+ }); }
127
+ }
128
+ };
129
+ //# sourceMappingURL=Login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Login.js","sourceRoot":"","sources":["../../../src/pages/Login.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAkG;AAClG,wCAAwC;AAE3B,QAAA,SAAS,GAAG,OAAO,CAAC;AACpB,QAAA,SAAS,GAAS;IAC3B,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,iBAAS;IACf,IAAI,EAAE;QACF,MAAM,EAAE,IAAI;KACf;IACD,SAAS,EAAE,cAAM,OAAA,CACb,8BAAC,aAAQ;QACL,8BAAC,SAAI,IACD,IAAI,EAAC,OAAO,EACZ,YAAY,EAAE,cAAM,OAAA,IAAI,WAAW,EAAE,EAAjB,CAAiB,EACrC,WAAW,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,EAClC,OAAO,EAAE,OAAO,GAClB,CACK,CACd,EATgB,CAShB;CACJ,CAAA;AAED;IAA0B,+BAAM;IAAhC;QAAA,qEAaC;QARG,WAAK,GAAG,IAAA,cAAS,EAAc;YAC3B,IAAI,EAAE,OAAO;SAChB,CAAC,CAAC;QAEH,cAAQ,GAAG,IAAA,cAAS,EAAc;YAC9B,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;;IACP,CAAC;IAZU,kBAAM,GAAb;QACI,OAAO,IAAI,WAAW,EAAE,CAAC;IAC7B,CAAC;IAUL,kBAAC;AAAD,CAAC,AAbD,CAA0B,WAAM,GAa/B;AAED,IAAM,OAAO,GAA6B;IACzC,KAAK,EAAE,gBAAW;IAClB,KAAK,EAAE;QACN,IAAI,EAAE,OAAO;QACb,KAAK,EAAE;YACN,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,WAAW;SACpB;QACD,OAAO,EAAE,UAAO,MAAmB,EAAE,OAAiC;;;;4BACpD,qBAAM,KAAK,CAAC,aAAM,CAAC,KAAK,CAAC,IAAI,EAAE;4BACnC,MAAM,EAAE,aAAM,CAAC,KAAK,CAAC,MAAM;4BAC3B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gCACjB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK;gCAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK;6BACxC,CAAC;4BACF,QAAQ,EAAE,QAAQ;4BAClB,WAAW,EAAE,aAAa;4BAC1B,OAAO,EAAE;gCACL,cAAc,EAAE,kBAAkB;6BACrC;yBACJ,CAAC,EAAA;;wBAXL,QAAQ,GAAG,SAWN;wBACF,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG;4BACtB,MAAM,IAAI,KAAK,CAAC,kCAA2B,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;wBAEzD,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5B,IAAI,GAAG,SAAqB;wBAClC,IAAI,IAAI,CAAC,KAAK;4BACV,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBAEhC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAC;;;;aACpC;KACD;CACD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Page } from '@proteinjs/ui';
2
+ export declare const signupPage: Page;
3
+ //# sourceMappingURL=Signup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signup.d.ts","sourceRoot":"","sources":["../../../src/pages/Signup.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA+D,MAAM,eAAe,CAAC;AAGlG,eAAO,MAAM,UAAU,EAAE,IAgBxB,CAAA"}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.signupPage = void 0;
58
+ var react_1 = __importDefault(require("react"));
59
+ var ui_1 = require("@proteinjs/ui");
60
+ var user_1 = require("@proteinjs/user");
61
+ exports.signupPage = {
62
+ name: 'Sign Up',
63
+ path: 'signup',
64
+ auth: {
65
+ public: true,
66
+ },
67
+ component: function () { return (react_1.default.createElement(ui_1.FormPage, null,
68
+ react_1.default.createElement(ui_1.Form, { name: 'Sign Up', createFields: function () { return new SignupFields(); }, fieldLayout: ['name', 'email', 'password', 'confirmPassword'], buttons: buttons }))); }
69
+ };
70
+ var SignupFields = /** @class */ (function (_super) {
71
+ __extends(SignupFields, _super);
72
+ function SignupFields() {
73
+ var _this = _super !== null && _super.apply(this, arguments) || this;
74
+ _this.name = (0, ui_1.textField)({
75
+ name: 'name'
76
+ });
77
+ _this.email = (0, ui_1.textField)({
78
+ name: 'email'
79
+ });
80
+ _this.password = (0, ui_1.textField)({
81
+ name: 'password',
82
+ isPassword: true
83
+ });
84
+ _this.confirmPassword = (0, ui_1.textField)({
85
+ name: 'confirmPassword',
86
+ isPassword: true
87
+ });
88
+ return _this;
89
+ }
90
+ SignupFields.create = function () {
91
+ return new SignupFields();
92
+ };
93
+ return SignupFields;
94
+ }(ui_1.Fields));
95
+ var buttons = {
96
+ clear: ui_1.clearButton,
97
+ signup: {
98
+ name: 'Sign up',
99
+ style: {
100
+ color: 'primary',
101
+ variant: 'contained',
102
+ },
103
+ onClick: function (fields, buttons) { return __awaiter(void 0, void 0, void 0, function () {
104
+ var response, body;
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0: return [4 /*yield*/, fetch(user_1.routes.createUser.path, {
108
+ method: user_1.routes.createUser.method,
109
+ body: JSON.stringify({
110
+ name: fields.name.field.value,
111
+ email: fields.email.field.value,
112
+ password: fields.password.field.value
113
+ }),
114
+ redirect: 'follow',
115
+ credentials: 'same-origin',
116
+ headers: {
117
+ 'Content-Type': 'application/json'
118
+ }
119
+ })];
120
+ case 1:
121
+ response = _a.sent();
122
+ if (response.status != 200)
123
+ throw new Error("Failed to signup, error: ".concat(response.statusText));
124
+ return [4 /*yield*/, response.json()];
125
+ case 2:
126
+ body = _a.sent();
127
+ if (body.error)
128
+ throw new Error(body.error);
129
+ return [2 /*return*/, "Successfully created your account! Please check your email for an email confirmation."];
130
+ }
131
+ });
132
+ }); }
133
+ }
134
+ };
135
+ //# sourceMappingURL=Signup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signup.js","sourceRoot":"","sources":["../../../src/pages/Signup.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAkG;AAClG,wCAAwC;AAE3B,QAAA,UAAU,GAAS;IAC5B,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE;QACF,MAAM,EAAE,IAAI;KACf;IACD,SAAS,EAAE,cAAM,OAAA,CACb,8BAAC,aAAQ;QACL,8BAAC,SAAI,IACD,IAAI,EAAC,SAAS,EACd,YAAY,EAAE,cAAM,OAAA,IAAI,YAAY,EAAE,EAAlB,CAAkB,EACtC,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,CAAC,EAC7D,OAAO,EAAE,OAAO,GAClB,CACK,CACd,EATgB,CAShB;CACJ,CAAA;AAED;IAA2B,gCAAM;IAAjC;QAAA,qEAsBC;QAjBG,UAAI,GAAG,IAAA,cAAS,EAAe;YAC3B,IAAI,EAAE,MAAM;SACf,CAAC,CAAC;QAEH,WAAK,GAAG,IAAA,cAAS,EAAe;YAC5B,IAAI,EAAE,OAAO;SAChB,CAAC,CAAC;QAEH,cAAQ,GAAG,IAAA,cAAS,EAAe;YAC/B,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,qBAAe,GAAG,IAAA,cAAS,EAAe;YACtC,IAAI,EAAE,iBAAiB;YACvB,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;;IACP,CAAC;IArBU,mBAAM,GAAb;QACI,OAAO,IAAI,YAAY,EAAE,CAAC;IAC9B,CAAC;IAmBL,mBAAC;AAAD,CAAC,AAtBD,CAA2B,WAAM,GAsBhC;AAED,IAAM,OAAO,GAA8B;IAC1C,KAAK,EAAE,gBAAW;IAClB,MAAM,EAAE;QACP,IAAI,EAAE,SAAS;QACf,KAAK,EAAE;YACN,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,WAAW;SACpB;QACD,OAAO,EAAE,UAAO,MAAoB,EAAE,OAAkC;;;;4BACtD,qBAAM,KAAK,CAAC,aAAM,CAAC,UAAU,CAAC,IAAI,EAAE;4BACxC,MAAM,EAAE,aAAM,CAAC,UAAU,CAAC,MAAM;4BAChC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gCACjB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;gCAC7B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK;gCAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK;6BACxC,CAAC;4BACF,QAAQ,EAAE,QAAQ;4BAClB,WAAW,EAAE,aAAa;4BAC1B,OAAO,EAAE;gCACL,cAAc,EAAE,kBAAkB;6BACrC;yBACJ,CAAC,EAAA;;wBAZL,QAAQ,GAAG,SAYN;wBACF,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG;4BACtB,MAAM,IAAI,KAAK,CAAC,mCAA4B,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;wBAE1D,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5B,IAAI,GAAG,SAAqB;wBAClC,IAAI,IAAI,CAAC,KAAK;4BACV,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBAEhC,sBAAO,uFAAuF,EAAC;;;aACxG;KACD;CACD,CAAC"}
@@ -0,0 +1,34 @@
1
+ /** Load Dependency Source Graphs */
2
+
3
+ import '@proteinjs/reflection';
4
+ import '@proteinjs/server-api';
5
+ import '@proteinjs/ui';
6
+ import '@proteinjs/user';
7
+ import 'moment';
8
+ import 'react';
9
+ import 'react-dom';
10
+
11
+
12
+ /** Generate Source Graph */
13
+
14
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"loginPage\",\"filePath\":\"/home/runner/work/user/user/packages/ui/src/pages/Login.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/loginPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/ui/Page\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"signupPage\",\"filePath\":\"/home/runner/work/user/user/packages/ui/src/pages/Signup.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/signupPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}}],\"edges\":[{\"v\":\"@proteinjs/user-ui/loginPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"}]}";
15
+
16
+
17
+ /** Generate Source Links */
18
+
19
+ import { loginPage } from '../src/pages/Login';
20
+ import { signupPage } from '../src/pages/Signup';
21
+
22
+ const sourceLinks = {
23
+ '@proteinjs/user-ui/loginPage': loginPage,
24
+ '@proteinjs/user-ui/signupPage': signupPage,
25
+ };
26
+
27
+
28
+ /** Load Source Graph and Links */
29
+
30
+ import { SourceRepository } from '@proteinjs/reflection';
31
+ SourceRepository.merge(sourceGraph, sourceLinks);
32
+
33
+
34
+ export * from '../index';
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/AuthenticatedPageContainer';
package/jest.config.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ "roots": [
3
+ "<rootDir>/test"
4
+ ],
5
+ "transform": {
6
+ "^.+\\.tsx?$": "ts-jest"
7
+ },
8
+ "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
9
+ "moduleFileExtensions": [
10
+ "ts",
11
+ "tsx",
12
+ "js",
13
+ "jsx",
14
+ "json",
15
+ "node"
16
+ ],
17
+ "testEnvironment": "node"
18
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@proteinjs/user-ui",
3
+ "version": "1.0.1",
4
+ "description": "User ui components",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/proteinjs/user.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/proteinjs/user/issues"
14
+ },
15
+ "homepage": "https://github.com/proteinjs/user#readme",
16
+ "author": "Brent Bahry",
17
+ "license": "MIT",
18
+ "scripts": {
19
+ "clean": "rm -rf dist/ generated/ node_modules/ package-lock.json",
20
+ "build": "reflection-build && tsc",
21
+ "watch": "reflection-watch"
22
+ },
23
+ "dependencies": {
24
+ "@proteinjs/reflection": "1.0.2",
25
+ "@proteinjs/server-api": "1.0.2",
26
+ "@proteinjs/ui": "1.0.1",
27
+ "@proteinjs/user": "1.0.1",
28
+ "moment": "2.29.4",
29
+ "react": "18.2.0",
30
+ "react-dom": "18.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "@proteinjs/reflection-build": "1.0.5",
34
+ "@types/node": "14.0.13",
35
+ "@types/react": "18.2.23",
36
+ "@types/react-dom": "18.2.8",
37
+ "typescript": "5.2.2"
38
+ },
39
+ "main": "./dist/generated/index.js",
40
+ "types": "./dist/generated/index.d.ts",
41
+ "gitHead": "ba3ee20c97d9e01165e27d6b5ed984394fcf0825"
42
+ }
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { Page, PageContainer, PageContainerProps } from '@proteinjs/ui';
3
+ import { routes, guestUser, UserAuth, UserRepo } from '@proteinjs/user';
4
+ import { loginPath } from './pages/Login';
5
+
6
+ export type AuthenticatedPageContainerProps = Omit<PageContainerProps, 'auth'>;
7
+
8
+ export function AuthenticatedPageContainer(props: AuthenticatedPageContainerProps) {
9
+ const { ...other } = props;
10
+ const [isLoggedIn, setIsLoggedIn] = React.useState(UserAuth.isLoggedIn());
11
+
12
+ return (
13
+ <PageContainer
14
+ auth={{
15
+ isLoggedIn,
16
+ canViewPage: (page: Page) => {
17
+ if (page.auth?.public)
18
+ return true;
19
+
20
+ if (page.auth?.allUsers)
21
+ return UserAuth.isLoggedIn();
22
+
23
+ if (!page.auth?.roles)
24
+ return UserAuth.hasRole('admin');
25
+
26
+ return UserAuth.hasRoles(page.auth?.roles);
27
+ },
28
+ login: loginPath,
29
+ logout: async () => {
30
+ const response = await fetch(routes.logout.path, {
31
+ method: routes.logout.method,
32
+ redirect: 'follow',
33
+ credentials: 'same-origin',
34
+ headers: {
35
+ 'Content-Type': 'application/json'
36
+ }
37
+ });
38
+ if (response.status != 200)
39
+ throw new Error(`Failed to log out`);
40
+
41
+ new UserRepo().setUser(guestUser);
42
+ setIsLoggedIn(false);
43
+ return loginPath;
44
+ }
45
+ }}
46
+ {...other}
47
+ />
48
+ );
49
+ }
@@ -0,0 +1,70 @@
1
+ import React from 'react';
2
+ import { Page, Form, Fields, textField, FormButtons, clearButton, FormPage } from '@proteinjs/ui';
3
+ import { routes } from '@proteinjs/user'
4
+
5
+ export const loginPath = 'login';
6
+ export const loginPage: Page = {
7
+ name: 'Login',
8
+ path: loginPath,
9
+ auth: {
10
+ public: true,
11
+ },
12
+ component: () => (
13
+ <FormPage>
14
+ <Form<LoginFields, typeof buttons>
15
+ name='Login'
16
+ createFields={() => new LoginFields()}
17
+ fieldLayout={['email', 'password']}
18
+ buttons={buttons}
19
+ />
20
+ </FormPage>
21
+ )
22
+ }
23
+
24
+ class LoginFields extends Fields {
25
+ static create() {
26
+ return new LoginFields();
27
+ }
28
+
29
+ email = textField<LoginFields>({
30
+ name: 'email'
31
+ });
32
+
33
+ password = textField<LoginFields>({
34
+ name: 'password',
35
+ isPassword: true
36
+ });
37
+ }
38
+
39
+ const buttons: FormButtons<LoginFields> = {
40
+ clear: clearButton,
41
+ login: {
42
+ name: 'Login',
43
+ style: {
44
+ color: 'primary',
45
+ variant: 'contained',
46
+ },
47
+ onClick: async (fields: LoginFields, buttons: FormButtons<LoginFields>) => {
48
+ const response = await fetch(routes.login.path, {
49
+ method: routes.login.method,
50
+ body: JSON.stringify({
51
+ email: fields.email.field.value,
52
+ password: fields.password.field.value
53
+ }),
54
+ redirect: 'follow',
55
+ credentials: 'same-origin',
56
+ headers: {
57
+ 'Content-Type': 'application/json'
58
+ }
59
+ });
60
+ if (response.status != 200)
61
+ throw new Error(`Failed to login, error: ${response.statusText}`);
62
+
63
+ const body = await response.json();
64
+ if (body.error)
65
+ throw new Error(body.error);
66
+
67
+ window.location.href = '/';
68
+ }
69
+ }
70
+ };
@@ -0,0 +1,79 @@
1
+ import React from 'react';
2
+ import { Page, Form, Fields, textField, FormButtons, clearButton, FormPage } from '@proteinjs/ui';
3
+ import { routes } from '@proteinjs/user'
4
+
5
+ export const signupPage: Page = {
6
+ name: 'Sign Up',
7
+ path: 'signup',
8
+ auth: {
9
+ public: true,
10
+ },
11
+ component: () => (
12
+ <FormPage>
13
+ <Form<SignupFields, typeof buttons>
14
+ name='Sign Up'
15
+ createFields={() => new SignupFields()}
16
+ fieldLayout={['name', 'email', 'password', 'confirmPassword']}
17
+ buttons={buttons}
18
+ />
19
+ </FormPage>
20
+ )
21
+ }
22
+
23
+ class SignupFields extends Fields {
24
+ static create() {
25
+ return new SignupFields();
26
+ }
27
+
28
+ name = textField<SignupFields>({
29
+ name: 'name'
30
+ });
31
+
32
+ email = textField<SignupFields>({
33
+ name: 'email'
34
+ });
35
+
36
+ password = textField<SignupFields>({
37
+ name: 'password',
38
+ isPassword: true
39
+ });
40
+
41
+ confirmPassword = textField<SignupFields>({
42
+ name: 'confirmPassword',
43
+ isPassword: true
44
+ });
45
+ }
46
+
47
+ const buttons: FormButtons<SignupFields> = {
48
+ clear: clearButton,
49
+ signup: {
50
+ name: 'Sign up',
51
+ style: {
52
+ color: 'primary',
53
+ variant: 'contained',
54
+ },
55
+ onClick: async (fields: SignupFields, buttons: FormButtons<SignupFields>) => {
56
+ const response = await fetch(routes.createUser.path, {
57
+ method: routes.createUser.method,
58
+ body: JSON.stringify({
59
+ name: fields.name.field.value,
60
+ email: fields.email.field.value,
61
+ password: fields.password.field.value
62
+ }),
63
+ redirect: 'follow',
64
+ credentials: 'same-origin',
65
+ headers: {
66
+ 'Content-Type': 'application/json'
67
+ }
68
+ });
69
+ if (response.status != 200)
70
+ throw new Error(`Failed to signup, error: ${response.statusText}`);
71
+
72
+ const body = await response.json();
73
+ if (body.error)
74
+ throw new Error(body.error);
75
+
76
+ return `Successfully created your account! Please check your email for an email confirmation.`;
77
+ }
78
+ }
79
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "target": "es5",
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "./dist/",
10
+ "strict": true,
11
+ "noImplicitAny": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "jsx": "react"
17
+ }
18
+ }