@proteinjs/user-ui 1.4.2 → 1.5.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/generated/index.d.ts +0 -9
  3. package/dist/generated/index.d.ts.map +1 -1
  4. package/dist/generated/index.js +0 -9
  5. package/dist/generated/index.js.map +1 -1
  6. package/dist/src/auth/AuthApi.d.ts +12 -0
  7. package/dist/src/auth/AuthApi.d.ts.map +1 -0
  8. package/dist/src/auth/AuthApi.js +151 -0
  9. package/dist/src/auth/AuthApi.js.map +1 -0
  10. package/dist/src/auth/AuthButton.d.ts +13 -0
  11. package/dist/src/auth/AuthButton.d.ts.map +1 -0
  12. package/dist/src/auth/AuthButton.js +21 -0
  13. package/dist/src/auth/AuthButton.js.map +1 -0
  14. package/dist/src/auth/AuthFormError.d.ts +6 -0
  15. package/dist/src/auth/AuthFormError.d.ts.map +1 -0
  16. package/dist/src/auth/AuthFormError.js +18 -0
  17. package/dist/src/auth/AuthFormError.js.map +1 -0
  18. package/dist/src/auth/AuthLayout.d.ts +17 -0
  19. package/dist/src/auth/AuthLayout.d.ts.map +1 -0
  20. package/dist/src/auth/AuthLayout.js +52 -0
  21. package/dist/src/auth/AuthLayout.js.map +1 -0
  22. package/dist/src/auth/AuthMessagePanel.d.ts +13 -0
  23. package/dist/src/auth/AuthMessagePanel.d.ts.map +1 -0
  24. package/dist/src/auth/AuthMessagePanel.js +22 -0
  25. package/dist/src/auth/AuthMessagePanel.js.map +1 -0
  26. package/dist/src/auth/AuthTextField.d.ts +21 -0
  27. package/dist/src/auth/AuthTextField.d.ts.map +1 -0
  28. package/dist/src/auth/AuthTextField.js +60 -0
  29. package/dist/src/auth/AuthTextField.js.map +1 -0
  30. package/dist/src/auth/AuthValidation.d.ts +18 -0
  31. package/dist/src/auth/AuthValidation.d.ts.map +1 -0
  32. package/dist/src/auth/AuthValidation.js +38 -0
  33. package/dist/src/auth/AuthValidation.js.map +1 -0
  34. package/dist/src/pages/ForgotPassword.d.ts.map +1 -1
  35. package/dist/src/pages/ForgotPassword.js +77 -75
  36. package/dist/src/pages/ForgotPassword.js.map +1 -1
  37. package/dist/src/pages/Login.d.ts.map +1 -1
  38. package/dist/src/pages/Login.js +79 -97
  39. package/dist/src/pages/Login.js.map +1 -1
  40. package/dist/src/pages/PasswordReset.d.ts.map +1 -1
  41. package/dist/src/pages/PasswordReset.js +86 -134
  42. package/dist/src/pages/PasswordReset.js.map +1 -1
  43. package/dist/src/pages/Signup.d.ts.map +1 -1
  44. package/dist/src/pages/Signup.js +88 -148
  45. package/dist/src/pages/Signup.js.map +1 -1
  46. package/dist/test/authApi.test.d.ts +2 -0
  47. package/dist/test/authApi.test.d.ts.map +1 -0
  48. package/dist/test/authApi.test.js +188 -0
  49. package/dist/test/authApi.test.js.map +1 -0
  50. package/dist/test/authPages.test.d.ts +2 -0
  51. package/dist/test/authPages.test.d.ts.map +1 -0
  52. package/dist/test/authPages.test.js +52 -0
  53. package/dist/test/authPages.test.js.map +1 -0
  54. package/dist/test/authValidation.test.d.ts +2 -0
  55. package/dist/test/authValidation.test.d.ts.map +1 -0
  56. package/dist/test/authValidation.test.js +52 -0
  57. package/dist/test/authValidation.test.js.map +1 -0
  58. package/generated/index.ts +0 -9
  59. package/package.json +3 -3
  60. package/src/auth/AuthApi.ts +67 -0
  61. package/src/auth/AuthButton.tsx +38 -0
  62. package/src/auth/AuthFormError.tsx +15 -0
  63. package/src/auth/AuthLayout.tsx +69 -0
  64. package/src/auth/AuthMessagePanel.tsx +28 -0
  65. package/src/auth/AuthTextField.tsx +75 -0
  66. package/src/auth/AuthValidation.ts +39 -0
  67. package/src/pages/ForgotPassword.tsx +77 -56
  68. package/src/pages/Login.tsx +74 -78
  69. package/src/pages/PasswordReset.tsx +118 -124
  70. package/src/pages/Signup.tsx +117 -136
  71. package/test/authApi.test.ts +92 -0
  72. package/test/authPages.test.tsx +51 -0
  73. package/test/authValidation.test.ts +56 -0
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var AuthApi_1 = require("../src/auth/AuthApi");
40
+ var user_1 = require("@proteinjs/user");
41
+ function mockFetch(response) {
42
+ var _this = this;
43
+ var _a, _b;
44
+ var fetchMock = jest.fn().mockResolvedValue({
45
+ status: (_a = response.status) !== null && _a !== void 0 ? _a : 200,
46
+ statusText: (_b = response.statusText) !== null && _b !== void 0 ? _b : 'OK',
47
+ json: function () { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
48
+ return [2 /*return*/, (_a = response.body) !== null && _a !== void 0 ? _a : {}];
49
+ }); }); },
50
+ });
51
+ global.fetch = fetchMock;
52
+ return fetchMock;
53
+ }
54
+ afterEach(function () {
55
+ delete global.fetch;
56
+ });
57
+ describe('AuthApi.login', function () {
58
+ it('posts the credentials to the login route and resolves on success', function () { return __awaiter(void 0, void 0, void 0, function () {
59
+ var fetchMock;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ fetchMock = mockFetch({ body: {} });
64
+ return [4 /*yield*/, new AuthApi_1.AuthApi().login('ada@example.com', 'hunter22')];
65
+ case 1:
66
+ _a.sent();
67
+ expect(fetchMock).toHaveBeenCalledWith(user_1.routes.login.path, expect.objectContaining({
68
+ method: user_1.routes.login.method,
69
+ body: JSON.stringify({ email: 'ada@example.com', password: 'hunter22' }),
70
+ }));
71
+ return [2 /*return*/];
72
+ }
73
+ });
74
+ }); });
75
+ it('throws on a non-200 response', function () { return __awaiter(void 0, void 0, void 0, function () {
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0:
79
+ mockFetch({ status: 401, statusText: 'Unauthorized' });
80
+ return [4 /*yield*/, expect(new AuthApi_1.AuthApi().login('ada@example.com', 'nope')).rejects.toThrow('Unauthorized')];
81
+ case 1:
82
+ _a.sent();
83
+ return [2 /*return*/];
84
+ }
85
+ });
86
+ }); });
87
+ it('throws the server-provided error from a 200 response body', function () { return __awaiter(void 0, void 0, void 0, function () {
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ mockFetch({ body: { error: 'Incorrect email or password' } });
92
+ return [4 /*yield*/, expect(new AuthApi_1.AuthApi().login('ada@example.com', 'nope')).rejects.toThrow('Incorrect email or password')];
93
+ case 1:
94
+ _a.sent();
95
+ return [2 /*return*/];
96
+ }
97
+ });
98
+ }); });
99
+ });
100
+ describe('AuthApi.initiatePasswordReset', function () {
101
+ it('posts the email and resolves on success', function () { return __awaiter(void 0, void 0, void 0, function () {
102
+ var fetchMock;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0:
106
+ fetchMock = mockFetch({ body: {} });
107
+ return [4 /*yield*/, new AuthApi_1.AuthApi().initiatePasswordReset('ada@example.com')];
108
+ case 1:
109
+ _a.sent();
110
+ expect(fetchMock).toHaveBeenCalledWith(user_1.routes.initiatePasswordReset.path, expect.objectContaining({
111
+ method: user_1.routes.initiatePasswordReset.method,
112
+ body: JSON.stringify({ email: 'ada@example.com' }),
113
+ }));
114
+ return [2 /*return*/];
115
+ }
116
+ });
117
+ }); });
118
+ it('throws a user-readable error on failure', function () { return __awaiter(void 0, void 0, void 0, function () {
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ mockFetch({ status: 500, statusText: 'Internal Server Error' });
123
+ return [4 /*yield*/, expect(new AuthApi_1.AuthApi().initiatePasswordReset('ada@example.com')).rejects.toThrow('Failed to send the reset email. Please try again.')];
124
+ case 1:
125
+ _a.sent();
126
+ return [2 /*return*/];
127
+ }
128
+ });
129
+ }); });
130
+ });
131
+ describe('AuthApi.validateResetToken', function () {
132
+ it('returns undefined for a valid token', function () { return __awaiter(void 0, void 0, void 0, function () {
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0:
136
+ mockFetch({ body: { isValid: true } });
137
+ return [4 /*yield*/, expect(new AuthApi_1.AuthApi().validateResetToken('tok')).resolves.toBeUndefined()];
138
+ case 1:
139
+ _a.sent();
140
+ return [2 /*return*/];
141
+ }
142
+ });
143
+ }); });
144
+ it('returns the server message for an invalid token', function () { return __awaiter(void 0, void 0, void 0, function () {
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0:
148
+ mockFetch({ body: { isValid: false, message: 'Token expired' } });
149
+ return [4 /*yield*/, expect(new AuthApi_1.AuthApi().validateResetToken('tok')).resolves.toBe('Token expired')];
150
+ case 1:
151
+ _a.sent();
152
+ return [2 /*return*/];
153
+ }
154
+ });
155
+ }); });
156
+ });
157
+ describe('AuthApi.executePasswordReset', function () {
158
+ it('posts the token and new password', function () { return __awaiter(void 0, void 0, void 0, function () {
159
+ var fetchMock;
160
+ return __generator(this, function (_a) {
161
+ switch (_a.label) {
162
+ case 0:
163
+ fetchMock = mockFetch({ body: {} });
164
+ return [4 /*yield*/, new AuthApi_1.AuthApi().executePasswordReset('tok', 'hunter22')];
165
+ case 1:
166
+ _a.sent();
167
+ expect(fetchMock).toHaveBeenCalledWith(user_1.routes.executePasswordReset.path, expect.objectContaining({
168
+ method: user_1.routes.executePasswordReset.method,
169
+ body: JSON.stringify({ token: 'tok', newPassword: 'hunter22' }),
170
+ }));
171
+ return [2 /*return*/];
172
+ }
173
+ });
174
+ }); });
175
+ it('throws on a non-200 response', function () { return __awaiter(void 0, void 0, void 0, function () {
176
+ return __generator(this, function (_a) {
177
+ switch (_a.label) {
178
+ case 0:
179
+ mockFetch({ status: 400 });
180
+ return [4 /*yield*/, expect(new AuthApi_1.AuthApi().executePasswordReset('tok', 'hunter22')).rejects.toThrow('Failed to reset password')];
181
+ case 1:
182
+ _a.sent();
183
+ return [2 /*return*/];
184
+ }
185
+ });
186
+ }); });
187
+ });
188
+ //# sourceMappingURL=authApi.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authApi.test.js","sourceRoot":"","sources":["../../test/authApi.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA8C;AAC9C,wCAAyC;AAEzC,SAAS,SAAS,CAAC,QAA8D;IAAjF,iBAQC;;IAPC,IAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QAC5C,MAAM,EAAE,MAAA,QAAQ,CAAC,MAAM,mCAAI,GAAG;QAC9B,UAAU,EAAE,MAAA,QAAQ,CAAC,UAAU,mCAAI,IAAI;QACvC,IAAI,EAAE;YAAY,sBAAA,MAAA,QAAQ,CAAC,IAAI,mCAAI,EAAE,EAAA;iBAAA;KACtC,CAAC,CAAC;IACF,MAAc,CAAC,KAAK,GAAG,SAAS,CAAC;IAClC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,CAAC;IACR,OAAQ,MAAc,CAAC,KAAK,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,eAAe,EAAE;IACxB,EAAE,CAAC,kEAAkE,EAAE;;;;;oBAC/D,SAAS,GAAG,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC1C,qBAAM,IAAI,iBAAO,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAAE,UAAU,CAAC,EAAA;;oBAAxD,SAAwD,CAAC;oBACzD,MAAM,CAAC,SAAS,CAAC,CAAC,oBAAoB,CACpC,aAAM,CAAC,KAAK,CAAC,IAAI,EACjB,MAAM,CAAC,gBAAgB,CAAC;wBACtB,MAAM,EAAE,aAAM,CAAC,KAAK,CAAC,MAAM;wBAC3B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,E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E,UAAU,CAAC,EAAA;;oBAA3D,SAA2D,CAAC;oBAC5D,MAAM,CAAC,SAAS,CAAC,CAAC,oBAAoB,CACpC,aAAM,CAAC,oBAAoB,CAAC,IAAI,EAChC,MAAM,CAAC,gBAAgB,CAAC;wBACtB,MAAM,EAAE,aAAM,CAAC,oBAAoB,CAAC,MAAM;wBAC1C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;qBAChE,CAAC,CACH,CAAC;;;;SACH,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE;;;;oBACjC,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;oBAC3B,qBAAM,MAAM,CAAC,IAAI,iBAAO,EAAE,CAAC,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,EAAA;;oBAA/G,SAA+G,CAAC;;;;SACjH,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=authPages.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authPages.test.d.ts","sourceRoot":"","sources":["../../test/authPages.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var react_1 = __importDefault(require("react"));
7
+ var server_1 = require("react-dom/server");
8
+ var react_router_dom_1 = require("react-router-dom");
9
+ var Login_1 = require("../src/pages/Login");
10
+ var ForgotPassword_1 = require("../src/pages/ForgotPassword");
11
+ var PasswordReset_1 = require("../src/pages/PasswordReset");
12
+ var Signup_1 = require("../src/pages/Signup");
13
+ function render(node) {
14
+ return (0, server_1.renderToStaticMarkup)(react_1.default.createElement(react_router_dom_1.MemoryRouter, null, node));
15
+ }
16
+ describe('auth pages', function () {
17
+ it('login renders email + password fields, the submit action, and the forgot-password link', function () {
18
+ var Login = Login_1.loginPage.component;
19
+ var html = render(react_1.default.createElement(Login, { urlParams: {} }));
20
+ expect(html).toContain('Email');
21
+ expect(html).toContain('Password');
22
+ expect(html).toContain('Log in');
23
+ expect(html).toContain('href="/login/forgot-password"');
24
+ // Real submit semantics: Enter submits the form.
25
+ expect(html).toContain('type="submit"');
26
+ // Mobile keyboards + autofill: proper autocomplete tokens (HTML attribute names are
27
+ // case-insensitive; SSR emits the camelCase form).
28
+ expect(html.toLowerCase()).toContain('autocomplete="email"');
29
+ expect(html.toLowerCase()).toContain('autocomplete="current-password"');
30
+ });
31
+ it('forgot password renders the email field, the send action, and a way back to login', function () {
32
+ var ForgotPassword = ForgotPassword_1.forgotPasswordPage.component;
33
+ var html = render(react_1.default.createElement(ForgotPassword, { urlParams: {} }));
34
+ expect(html).toContain('Reset your password');
35
+ expect(html).toContain('Send reset link');
36
+ expect(html).toContain('href="/login"');
37
+ });
38
+ it('password reset without a token renders the invalid-link state, never the form', function () {
39
+ var PasswordReset = PasswordReset_1.passwordResetPage.component;
40
+ var html = render(react_1.default.createElement(PasswordReset, { urlParams: {} }));
41
+ expect(html).toContain('This reset link is invalid');
42
+ expect(html).toContain('href="/login"');
43
+ expect(html).not.toContain('New password');
44
+ });
45
+ it('signup renders its loading state before initialization resolves (no form flash)', function () {
46
+ var Signup = Signup_1.signupPage.component;
47
+ var html = render(react_1.default.createElement(Signup, { urlParams: {} }));
48
+ expect(html).toContain('Create your account');
49
+ expect(html).not.toContain('type="submit"');
50
+ });
51
+ });
52
+ //# sourceMappingURL=authPages.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authPages.test.js","sourceRoot":"","sources":["../../test/authPages.test.tsx"],"names":[],"mappings":";;;;;AAAA,gDAA0B;AAC1B,2CAAwD;AACxD,qDAAgD;AAChD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AC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+EAA+E,EAAE;QAClF,IAAM,aAAa,GAAG,iCAAiB,CAAC,SAAS,CAAC;QAClD,IAAM,IAAI,GAAG,MAAM,CAAC,8BAAC,aAAa,IAAC,SAAS,EAAE,EAAE,GAAI,CAAC,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iFAAiF,EAAE;QACpF,IAAM,MAAM,GAAG,mBAAU,CAAC,SAAS,CAAC;QACpC,IAAM,IAAI,GAAG,MAAM,CAAC,8BAAC,MAAM,IAAC,SAAS,EAAE,EAAE,GAAI,CAAC,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;QAC9C,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=authValidation.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authValidation.test.d.ts","sourceRoot":"","sources":["../../test/authValidation.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var AuthValidation_1 = require("../src/auth/AuthValidation");
15
+ var validSignup = {
16
+ name: 'Ada Lovelace',
17
+ email: 'ada@example.com',
18
+ password: 'hunter22',
19
+ confirmPassword: 'hunter22',
20
+ };
21
+ describe('AuthValidation.signup', function () {
22
+ it('accepts a complete, matching signup', function () {
23
+ expect(AuthValidation_1.AuthValidation.signup(validSignup, false)).toBeUndefined();
24
+ });
25
+ it('requires a name', function () {
26
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { name: ' ' }), false)).toBe('Please enter your name.');
27
+ });
28
+ it('requires a valid email when not invited', function () {
29
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { email: 'not-an-email' }), false)).toBe('Please enter a valid email address.');
30
+ });
31
+ it('skips the email check for invited users (the invite token carries the email)', function () {
32
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { email: '' }), true)).toBeUndefined();
33
+ });
34
+ it('requires a password', function () {
35
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { password: '', confirmPassword: '' }), false)).toBe('Please enter a password.');
36
+ });
37
+ it('rejects a mismatched password confirmation', function () {
38
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { confirmPassword: 'different' }), false)).toBe('Passwords do not match.');
39
+ });
40
+ });
41
+ describe('AuthValidation.passwordReset', function () {
42
+ it('accepts matching passwords', function () {
43
+ expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: 'hunter22', confirmPassword: 'hunter22' })).toBeUndefined();
44
+ });
45
+ it('requires a new password', function () {
46
+ expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: '', confirmPassword: '' })).toBe('Please enter a new password.');
47
+ });
48
+ it('rejects a mismatched confirmation', function () {
49
+ expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: 'hunter22', confirmPassword: 'hunter23' })).toBe('Passwords do not match.');
50
+ });
51
+ });
52
+ //# sourceMappingURL=authValidation.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authValidation.test.js","sourceRoot":"","sources":["../../test/authValidation.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6DAA4D;AAE5D,IAAM,WAAW,GAAG;IAClB,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,iBAAiB;IACxB,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,UAAU;CAC5B,CAAC;AAEF,QAAQ,CAAC,uBAAuB,EAAE;IAChC,EAAE,CAAC,qCAAqC,EAAE;QACxC,MAAM,CAAC,+BAAc,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iBAAiB,EAAE;QACpB,MAAM,CAAC,+BAAc,CAAC,MAAM,uBAAM,WAAW,KAAE,IAAI,EAAE,IAAI,KAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACvG,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE;QAC5C,MAAM,CAAC,+BAAc,CAAC,MAAM,uBAAM,WAAW,KAAE,KAAK,EAAE,cAAc,KAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAClF,qCAAqC,CACtC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8EAA8E,EAAE;QACjF,MAAM,CAAC,+BAAc,CAAC,MAAM,uBAAM,WAAW,KAAE,KAAK,EAAE,EAAE,KAAI,IAAI,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACrF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qBAAqB,EAAE;QACxB,MAAM,CAAC,+BAAc,CAAC,MAAM,uBAAM,WAAW,KAAE,QAAQ,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,KAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAC9F,0BAA0B,CAC3B,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE;QAC/C,MAAM,CAAC,+BAAc,CAAC,MAAM,uBAAM,WAAW,KAAE,eAAe,EAAE,WAAW,KAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CACzF,yBAAyB,CAC1B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,8BAA8B,EAAE;IACvC,EAAE,CAAC,4BAA4B,EAAE;QAC/B,MAAM,CAAC,+BAAc,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACjH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE;QAC5B,MAAM,CAAC,+BAAc,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IACtH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mCAAmC,EAAE;QACtC,MAAM,CAAC,+BAAc,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,IAAI,CACjG,yBAAyB,CAC1B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,19 +1,10 @@
1
1
  /** Load Dependency Source Graphs */
2
2
 
3
- import '@mui/icons-material';
4
- import '@mui/material';
5
3
  import '@proteinjs/db';
6
4
  import '@proteinjs/db-ui';
7
- import '@proteinjs/reflection';
8
5
  import '@proteinjs/server-api';
9
6
  import '@proteinjs/ui';
10
7
  import '@proteinjs/user';
11
- import '@proteinjs/util';
12
- import 'moment';
13
- import 'react';
14
- import 'react-dom';
15
- import 'react-helmet';
16
- import 'react-router-dom';
17
8
 
18
9
  /** Generate Source Graph */
19
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/user-ui",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "User ui components",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -29,7 +29,7 @@
29
29
  "@proteinjs/reflection": "^1.1.12",
30
30
  "@proteinjs/server-api": "^3.0.11",
31
31
  "@proteinjs/ui": "^4.5.0",
32
- "@proteinjs/user": "^1.7.2",
32
+ "@proteinjs/user": "^1.8.0",
33
33
  "@proteinjs/util": "^1.6.1",
34
34
  "moment": "2.29.4",
35
35
  "react": "18.2.0",
@@ -55,5 +55,5 @@
55
55
  },
56
56
  "main": "./dist/generated/index.js",
57
57
  "types": "./dist/generated/index.d.ts",
58
- "gitHead": "b859e64f927b11872dd70323a65f4ac541d27d69"
58
+ "gitHead": "ca5406c5d08120454950abcb42a54bf77531b3e0"
59
59
  }
@@ -0,0 +1,67 @@
1
+ import { routes } from '@proteinjs/user';
2
+
3
+ /**
4
+ * The auth flows' server calls, in one place so the pages hold presentation only.
5
+ * Methods resolve on success and throw an `Error` whose message is user-readable.
6
+ */
7
+ export class AuthApi {
8
+ async login(email: string, password: string): Promise<void> {
9
+ const response = await fetch(routes.login.path, {
10
+ method: routes.login.method,
11
+ body: JSON.stringify({ email, password }),
12
+ redirect: 'follow',
13
+ credentials: 'same-origin',
14
+ headers: { 'Content-Type': 'application/json' },
15
+ });
16
+ if (response.status != 200) {
17
+ throw new Error(`Failed to log in, error: ${response.statusText}`);
18
+ }
19
+
20
+ const body = await response.json();
21
+ if (body.error) {
22
+ throw new Error(body.error);
23
+ }
24
+ }
25
+
26
+ async initiatePasswordReset(email: string): Promise<void> {
27
+ const response = await fetch(routes.initiatePasswordReset.path, {
28
+ method: routes.initiatePasswordReset.method,
29
+ body: JSON.stringify({ email }),
30
+ redirect: 'follow',
31
+ credentials: 'same-origin',
32
+ headers: { 'Content-Type': 'application/json' },
33
+ });
34
+ if (response.status != 200) {
35
+ throw new Error(`Failed to send the reset email. Please try again.`);
36
+ }
37
+
38
+ const body = await response.json();
39
+ if (body.error) {
40
+ throw new Error(`Failed to send the reset email. Please try again.`);
41
+ }
42
+ }
43
+
44
+ /** Resolves with an error message when the token is invalid; undefined when it's valid. */
45
+ async validateResetToken(token: string): Promise<string | undefined> {
46
+ const response = await fetch(`${routes.validateResetToken.path}?token=${token}`, {
47
+ method: routes.validateResetToken.method,
48
+ credentials: 'same-origin',
49
+ });
50
+ const body = await response.json();
51
+ if (!body.isValid) {
52
+ return body.message || 'Invalid or expired token';
53
+ }
54
+ }
55
+
56
+ async executePasswordReset(token: string, newPassword: string): Promise<void> {
57
+ const response = await fetch(routes.executePasswordReset.path, {
58
+ method: routes.executePasswordReset.method,
59
+ body: JSON.stringify({ token, newPassword }),
60
+ credentials: 'same-origin',
61
+ headers: { 'Content-Type': 'application/json' },
62
+ });
63
+ if (response.status !== 200) {
64
+ throw new Error('Failed to reset password');
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import { Button, CircularProgress } from '@mui/material';
3
+
4
+ export interface AuthButtonProps {
5
+ children: React.ReactNode;
6
+ /** Renders a spinner and disables the button. */
7
+ busy?: boolean;
8
+ /** Defaults to 'submit' so the enclosing form submits on Enter. */
9
+ type?: 'submit' | 'button';
10
+ href?: string;
11
+ onClick?: () => void;
12
+ }
13
+
14
+ /** The auth surfaces' primary action: a full-width 48px pill in the host theme's primary color. */
15
+ export function AuthButton(props: AuthButtonProps) {
16
+ const { children, busy, type, href, onClick } = props;
17
+ return (
18
+ <Button
19
+ fullWidth
20
+ variant='contained'
21
+ color='primary'
22
+ disableElevation
23
+ type={type || 'submit'}
24
+ disabled={busy}
25
+ href={href}
26
+ onClick={onClick}
27
+ sx={{
28
+ height: 48,
29
+ borderRadius: '999px',
30
+ fontSize: '1rem',
31
+ fontWeight: 500,
32
+ textTransform: 'none',
33
+ }}
34
+ >
35
+ {busy ? <CircularProgress size={20} sx={{ color: 'inherit' }} /> : children}
36
+ </Button>
37
+ );
38
+ }
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { Typography } from '@mui/material';
3
+
4
+ /** Inline form-level error line, rendered between the fields and the primary action. */
5
+ export function AuthFormError({ message }: { message: string | undefined }) {
6
+ if (!message) {
7
+ return null;
8
+ }
9
+
10
+ return (
11
+ <Typography role='alert' sx={{ color: 'error.main', fontSize: '0.875rem', lineHeight: 1.45, mb: 2 }}>
12
+ {message}
13
+ </Typography>
14
+ );
15
+ }
@@ -0,0 +1,69 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { Box, Typography } from '@mui/material';
3
+
4
+ export interface AuthLayoutProps {
5
+ title: string;
6
+ /** Optional supporting line rendered under the title. */
7
+ subtitle?: string;
8
+ children?: ReactNode;
9
+ }
10
+
11
+ /**
12
+ * Shared shell for the logged-out auth surfaces (login, signup, forgot/reset password).
13
+ *
14
+ * A single centered column that owns its own scrolling: on phones the on-screen keyboard
15
+ * shrinks the app's dvh-sized page host, and the column scrolls instead of clipping the
16
+ * fields. All colors come from the host app's MUI theme — this package stays generic and
17
+ * the app's theme provider supplies the look.
18
+ */
19
+ export function AuthLayout(props: AuthLayoutProps) {
20
+ const { title, subtitle, children } = props;
21
+ return (
22
+ <Box
23
+ sx={{
24
+ flex: 1,
25
+ minHeight: 0,
26
+ width: '100%',
27
+ overflowY: 'auto',
28
+ WebkitOverflowScrolling: 'touch',
29
+ display: 'flex',
30
+ flexDirection: 'column',
31
+ alignItems: 'center',
32
+ backgroundColor: 'background.default',
33
+ }}
34
+ >
35
+ <Box
36
+ sx={{
37
+ width: '100%',
38
+ maxWidth: 400,
39
+ px: 3,
40
+ // Fixed share of the (dvh-sized) viewport: sits in the upper third at rest and
41
+ // collapses gracefully when the phone keyboard shrinks the viewport.
42
+ pt: 'clamp(48px, 16vh, 160px)',
43
+ pb: 6,
44
+ display: 'flex',
45
+ flexDirection: 'column',
46
+ }}
47
+ >
48
+ <Typography
49
+ component='h1'
50
+ sx={{
51
+ fontSize: '1.5rem',
52
+ fontWeight: 600,
53
+ letterSpacing: '-0.01em',
54
+ color: 'text.primary',
55
+ mb: subtitle ? 1 : 4,
56
+ }}
57
+ >
58
+ {title}
59
+ </Typography>
60
+ {subtitle && (
61
+ <Typography sx={{ fontSize: '0.875rem', lineHeight: 1.45, color: 'text.secondary', mb: 4 }}>
62
+ {subtitle}
63
+ </Typography>
64
+ )}
65
+ {children}
66
+ </Box>
67
+ </Box>
68
+ );
69
+ }
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { Box } from '@mui/material';
3
+ import { AuthLayout } from './AuthLayout';
4
+ import { AuthButton } from './AuthButton';
5
+
6
+ export interface AuthMessagePanelProps {
7
+ title: string;
8
+ body: string;
9
+ actionName: string;
10
+ actionHref: string;
11
+ }
12
+
13
+ /**
14
+ * Status states of the auth flows (link expired, reset complete, signup unavailable):
15
+ * a title, one line of body copy, and a single primary action.
16
+ */
17
+ export function AuthMessagePanel(props: AuthMessagePanelProps) {
18
+ const { title, body, actionName, actionHref } = props;
19
+ return (
20
+ <AuthLayout title={title} subtitle={body}>
21
+ <Box sx={{ mt: 1 }}>
22
+ <AuthButton type='button' href={actionHref}>
23
+ {actionName}
24
+ </AuthButton>
25
+ </Box>
26
+ </AuthLayout>
27
+ );
28
+ }