@webiny/app-admin-cognito 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f

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/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import React from "react";
2
2
  import { AuthOptions } from "@aws-amplify/auth/lib-esm/types";
3
3
  import ApolloClient from "apollo-client";
4
- export interface Props {
4
+ export interface AuthenticationProps {
5
5
  children: React.ReactNode;
6
6
  }
7
- export interface Config extends AuthOptions {
7
+ export interface AuthenticationFactoryConfig extends AuthOptions {
8
8
  onError?(error: Error): void;
9
9
  getIdentityData(params: {
10
10
  client: ApolloClient<any>;
@@ -15,4 +15,8 @@ export interface Config extends AuthOptions {
15
15
  [key: string]: any;
16
16
  }>;
17
17
  }
18
- export declare const createAuthentication: ({ getIdentityData, onError, ...config }: Config) => (props: Props) => JSX.Element;
18
+ interface AuthenticationFactory {
19
+ (params: AuthenticationFactoryConfig): React.FC<AuthenticationProps>;
20
+ }
21
+ export declare const createAuthentication: AuthenticationFactory;
22
+ export {};
package/index.js CHANGED
@@ -1,168 +1,169 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
3
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createAuthentication = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+ var _react = _interopRequireWildcard(require("react"));
15
+ var _auth = require("@aws-amplify/auth");
16
+ var _reactHooks = require("@apollo/react-hooks");
17
+ var _apolloLinkContext = require("apollo-link-context");
18
+ var _plugins = require("@webiny/plugins");
19
+ var _ApolloLinkPlugin = require("@webiny/app/plugins/ApolloLinkPlugin");
20
+ var _Authenticator = require("@webiny/app-cognito-authenticator/Authenticator");
21
+ var _SignIn = _interopRequireDefault(require("./views/SignIn"));
22
+ var _RequireNewPassword = _interopRequireDefault(require("./views/RequireNewPassword"));
23
+ var _ForgotPassword = _interopRequireDefault(require("./views/ForgotPassword"));
24
+ var _SetNewPassword = _interopRequireDefault(require("./views/SetNewPassword"));
25
+ var _SignedIn = _interopRequireDefault(require("./views/SignedIn"));
26
+ var _appSecurity = require("@webiny/app-security");
27
+ var _config = require("@webiny/app/config");
28
+ var _LoggingIn = _interopRequireDefault(require("./views/LoggingIn"));
4
29
  var _excluded = ["getIdentityData", "onError"],
5
- _excluded2 = ["id", "displayName", "type", "permissions"];
6
- import _regeneratorRuntime from "@babel/runtime/regenerator";
7
- import React, { useCallback, useEffect } from "react";
8
- import { Auth } from "@aws-amplify/auth";
9
- import { useApolloClient } from "@apollo/react-hooks";
10
- import { setContext } from "apollo-link-context";
11
- import { plugins } from "@webiny/plugins";
12
- import { ApolloLinkPlugin } from "@webiny/app/plugins/ApolloLinkPlugin";
13
- import { Authenticator } from "@webiny/app-cognito-authenticator/Authenticator";
14
- import CheckingUser from "./views/CheckingUser";
15
- import SignIn from "./views/SignIn";
16
- import RequireNewPassword from "./views/RequireNewPassword";
17
- import ForgotPassword from "./views/ForgotPassword";
18
- import SetNewPassword from "./views/SetNewPassword";
19
- import SignedIn from "./views/SignedIn";
20
- import { useSecurity } from "@webiny/app-security";
21
-
30
+ _excluded2 = ["id", "displayName", "type", "permissions"];
22
31
  var createApolloLinkPlugin = function createApolloLinkPlugin() {
23
- return new ApolloLinkPlugin(function () {
24
- return setContext( /*#__PURE__*/function () {
25
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_, _ref) {
32
+ return new _ApolloLinkPlugin.ApolloLinkPlugin(function () {
33
+ return (0, _apolloLinkContext.setContext)( /*#__PURE__*/function () {
34
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(_, _ref) {
26
35
  var headers, user, idToken;
27
- return _regeneratorRuntime.wrap(function _callee$(_context) {
28
- while (1) {
29
- switch (_context.prev = _context.next) {
30
- case 0:
31
- headers = _ref.headers;
32
- _context.next = 3;
33
- return Auth.currentSession();
34
-
35
- case 3:
36
- user = _context.sent;
37
- idToken = user.getIdToken();
38
-
39
- if (idToken) {
40
- _context.next = 7;
41
- break;
42
- }
43
-
44
- return _context.abrupt("return", {
45
- headers: headers
46
- });
47
-
48
- case 7:
49
- if (!(headers && headers.Authorization)) {
50
- _context.next = 9;
51
- break;
52
- }
53
-
54
- return _context.abrupt("return", {
55
- headers: headers
56
- });
57
-
58
- case 9:
59
- return _context.abrupt("return", {
60
- headers: _objectSpread(_objectSpread({}, headers), {}, {
61
- Authorization: "Bearer ".concat(idToken.getJwtToken())
62
- })
63
- });
64
-
65
- case 10:
66
- case "end":
67
- return _context.stop();
68
- }
36
+ return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
37
+ while (1) switch (_context.prev = _context.next) {
38
+ case 0:
39
+ headers = _ref.headers;
40
+ _context.next = 3;
41
+ return _auth.Auth.currentSession();
42
+ case 3:
43
+ user = _context.sent;
44
+ idToken = user.getIdToken();
45
+ if (idToken) {
46
+ _context.next = 7;
47
+ break;
48
+ }
49
+ return _context.abrupt("return", {
50
+ headers: headers
51
+ });
52
+ case 7:
53
+ if (!(headers && headers.Authorization)) {
54
+ _context.next = 9;
55
+ break;
56
+ }
57
+ return _context.abrupt("return", {
58
+ headers: headers
59
+ });
60
+ case 9:
61
+ return _context.abrupt("return", {
62
+ headers: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, headers), {}, {
63
+ Authorization: "Bearer ".concat(idToken.getJwtToken())
64
+ })
65
+ });
66
+ case 10:
67
+ case "end":
68
+ return _context.stop();
69
69
  }
70
70
  }, _callee);
71
71
  }));
72
-
73
72
  return function (_x, _x2) {
74
73
  return _ref2.apply(this, arguments);
75
74
  };
76
75
  }());
77
76
  });
78
77
  };
79
-
80
78
  var defaultOptions = {
81
- region: process.env.REACT_APP_USER_POOL_REGION,
82
- userPoolId: process.env.REACT_APP_USER_POOL_ID,
83
- userPoolWebClientId: process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID
79
+ region: _config.config.getKey("USER_POOL_REGION", process.env.REACT_APP_USER_POOL_REGION),
80
+ userPoolId: _config.config.getKey("USER_POOL_ID", process.env.REACT_APP_USER_POOL_ID),
81
+ userPoolWebClientId: _config.config.getKey("USER_POOL_WEB_CLIENT_ID", process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID)
84
82
  };
85
- export var createAuthentication = function createAuthentication(_ref3) {
83
+ var createAuthentication = function createAuthentication(_ref3) {
86
84
  var getIdentityData = _ref3.getIdentityData,
87
- onError = _ref3.onError,
88
- config = _objectWithoutProperties(_ref3, _excluded);
89
-
85
+ onError = _ref3.onError,
86
+ config = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
87
+ /**
88
+ * TODO @ts-refactor
89
+ */
90
+ // @ts-ignore
90
91
  Object.keys(config).forEach(function (key) {
91
92
  return config[key] === undefined && delete config[key];
92
93
  });
93
- Auth.configure(_objectSpread(_objectSpread({}, defaultOptions), config));
94
-
94
+ _auth.Auth.configure((0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaultOptions), config));
95
95
  var Authentication = function Authentication(props) {
96
96
  var children = props.children;
97
-
98
- var _useSecurity = useSecurity(),
99
- setIdentity = _useSecurity.setIdentity;
100
-
101
- var client = useApolloClient();
102
- var onToken = useCallback( /*#__PURE__*/function () {
103
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(token) {
97
+ var _useState = (0, _react.useState)(false),
98
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
99
+ loadingIdentity = _useState2[0],
100
+ setLoadingIdentity = _useState2[1];
101
+ var _useSecurity = (0, _appSecurity.useSecurity)(),
102
+ setIdentity = _useSecurity.setIdentity;
103
+ var client = (0, _reactHooks.useApolloClient)();
104
+ var onToken = (0, _react.useCallback)( /*#__PURE__*/function () {
105
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2(token) {
104
106
  var payload, logout, _yield$getIdentityDat, id, displayName, type, permissions, data;
105
-
106
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
107
- while (1) {
108
- switch (_context2.prev = _context2.next) {
109
- case 0:
110
- payload = token.payload, logout = token.logout;
111
- _context2.prev = 1;
112
- _context2.next = 4;
113
- return getIdentityData({
114
- client: client,
115
- payload: payload
116
- });
117
-
118
- case 4:
119
- _yield$getIdentityDat = _context2.sent;
120
- id = _yield$getIdentityDat.id;
121
- displayName = _yield$getIdentityDat.displayName;
122
- type = _yield$getIdentityDat.type;
123
- permissions = _yield$getIdentityDat.permissions;
124
- data = _objectWithoutProperties(_yield$getIdentityDat, _excluded2);
125
- setIdentity(_objectSpread(_objectSpread({
126
- id: id,
127
- displayName: displayName,
128
- type: type,
129
- permissions: permissions
130
- }, data), {}, {
131
- logout: logout
132
- }));
133
- _context2.next = 17;
134
- break;
135
-
136
- case 13:
137
- _context2.prev = 13;
138
- _context2.t0 = _context2["catch"](1);
139
- console.log("ERROR", _context2.t0);
140
-
141
- if (typeof onError === "function") {
142
- onError(_context2.t0);
143
- } else {
144
- console.error(_context2.t0);
107
+ return (0, _regeneratorRuntime2.default)().wrap(function _callee2$(_context2) {
108
+ while (1) switch (_context2.prev = _context2.next) {
109
+ case 0:
110
+ payload = token.payload, logout = token.logout;
111
+ setLoadingIdentity(true);
112
+ _context2.prev = 2;
113
+ _context2.next = 5;
114
+ return getIdentityData({
115
+ client: client,
116
+ payload: payload
117
+ });
118
+ case 5:
119
+ _yield$getIdentityDat = _context2.sent;
120
+ id = _yield$getIdentityDat.id;
121
+ displayName = _yield$getIdentityDat.displayName;
122
+ type = _yield$getIdentityDat.type;
123
+ permissions = _yield$getIdentityDat.permissions;
124
+ data = (0, _objectWithoutProperties2.default)(_yield$getIdentityDat, _excluded2);
125
+ setIdentity((0, _objectSpread2.default)((0, _objectSpread2.default)({
126
+ id: id,
127
+ displayName: displayName,
128
+ type: type,
129
+ permissions: permissions
130
+ }, data), {}, {
131
+ logout: logout || function () {
132
+ return void 0;
145
133
  }
146
-
147
- case 17:
148
- case "end":
149
- return _context2.stop();
150
- }
134
+ }));
135
+ _context2.next = 18;
136
+ break;
137
+ case 14:
138
+ _context2.prev = 14;
139
+ _context2.t0 = _context2["catch"](2);
140
+ console.log("ERROR", _context2.t0);
141
+ if (typeof onError === "function") {
142
+ onError(_context2.t0);
143
+ } else {
144
+ console.error(_context2.t0);
145
+ }
146
+ case 18:
147
+ _context2.prev = 18;
148
+ setLoadingIdentity(false);
149
+ return _context2.finish(18);
150
+ case 21:
151
+ case "end":
152
+ return _context2.stop();
151
153
  }
152
- }, _callee2, null, [[1, 13]]);
154
+ }, _callee2, null, [[2, 14, 18, 21]]);
153
155
  }));
154
-
155
156
  return function (_x3) {
156
157
  return _ref4.apply(this, arguments);
157
158
  };
158
159
  }(), []);
159
- useEffect(function () {
160
- plugins.register(createApolloLinkPlugin());
160
+ (0, _react.useEffect)(function () {
161
+ _plugins.plugins.register(createApolloLinkPlugin());
161
162
  }, []);
162
- return /*#__PURE__*/React.createElement(Authenticator, {
163
+ return /*#__PURE__*/_react.default.createElement(_Authenticator.Authenticator, {
163
164
  onToken: onToken
164
- }, /*#__PURE__*/React.createElement(CheckingUser, null), /*#__PURE__*/React.createElement(SignIn, null), /*#__PURE__*/React.createElement(RequireNewPassword, null), /*#__PURE__*/React.createElement(ForgotPassword, null), /*#__PURE__*/React.createElement(SetNewPassword, null), /*#__PURE__*/React.createElement(SignedIn, null, children));
165
+ }, loadingIdentity ? /*#__PURE__*/_react.default.createElement(_LoggingIn.default, null) : /*#__PURE__*/_react.default.createElement(_SignIn.default, null), /*#__PURE__*/_react.default.createElement(_RequireNewPassword.default, null), /*#__PURE__*/_react.default.createElement(_ForgotPassword.default, null), /*#__PURE__*/_react.default.createElement(_SetNewPassword.default, null), /*#__PURE__*/_react.default.createElement(_SignedIn.default, null, children));
165
166
  };
166
-
167
167
  return Authentication;
168
- };
168
+ };
169
+ exports.createAuthentication = createAuthentication;
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createApolloLinkPlugin","ApolloLinkPlugin","setContext","_","headers","Auth","currentSession","user","idToken","getIdToken","Authorization","getJwtToken","defaultOptions","region","appConfig","getKey","process","env","REACT_APP_USER_POOL_REGION","userPoolId","REACT_APP_USER_POOL_ID","userPoolWebClientId","REACT_APP_USER_POOL_WEB_CLIENT_ID","createAuthentication","getIdentityData","onError","config","Object","keys","forEach","key","undefined","configure","Authentication","props","children","useState","loadingIdentity","setLoadingIdentity","useSecurity","setIdentity","client","useApolloClient","onToken","useCallback","token","payload","logout","id","displayName","type","permissions","data","console","log","error","useEffect","plugins","register"],"sources":["index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useState } from \"react\";\nimport { Auth } from \"@aws-amplify/auth\";\nimport { AuthOptions } from \"@aws-amplify/auth/lib-esm/types\";\nimport ApolloClient from \"apollo-client\";\nimport { useApolloClient } from \"@apollo/react-hooks\";\nimport { setContext } from \"apollo-link-context\";\nimport { plugins } from \"@webiny/plugins\";\nimport { ApolloLinkPlugin } from \"@webiny/app/plugins/ApolloLinkPlugin\";\nimport { CognitoIdToken } from \"@webiny/app-cognito-authenticator/types\";\nimport { Authenticator } from \"@webiny/app-cognito-authenticator/Authenticator\";\nimport SignIn from \"~/views/SignIn\";\nimport RequireNewPassword from \"~/views/RequireNewPassword\";\nimport ForgotPassword from \"~/views/ForgotPassword\";\nimport SetNewPassword from \"~/views/SetNewPassword\";\nimport SignedIn from \"~/views/SignedIn\";\nimport { useSecurity } from \"@webiny/app-security\";\nimport { config as appConfig } from \"@webiny/app/config\";\nimport LoggingIn from \"~/views/LoggingIn\";\n\nconst createApolloLinkPlugin = (): ApolloLinkPlugin => {\n return new ApolloLinkPlugin(() => {\n return setContext(async (_, { headers }) => {\n const user = await Auth.currentSession();\n const idToken = user.getIdToken();\n\n if (!idToken) {\n return { headers };\n }\n\n // If \"Authorization\" header is already set, don't overwrite it.\n if (headers && headers.Authorization) {\n return { headers };\n }\n\n return {\n headers: {\n ...headers,\n Authorization: `Bearer ${idToken.getJwtToken()}`\n }\n };\n });\n });\n};\n\nconst defaultOptions = {\n region: appConfig.getKey(\"USER_POOL_REGION\", process.env.REACT_APP_USER_POOL_REGION),\n userPoolId: appConfig.getKey(\"USER_POOL_ID\", process.env.REACT_APP_USER_POOL_ID),\n userPoolWebClientId: appConfig.getKey(\n \"USER_POOL_WEB_CLIENT_ID\",\n process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID\n )\n};\n\nexport interface AuthenticationProps {\n children: React.ReactNode;\n}\n\nexport interface AuthenticationFactoryConfig extends AuthOptions {\n onError?(error: Error): void;\n getIdentityData(params: {\n client: ApolloClient<any>;\n payload: { [key: string]: any };\n }): Promise<{ [key: string]: any }>;\n}\n\ninterface AuthenticationFactory {\n (params: AuthenticationFactoryConfig): React.FC<AuthenticationProps>;\n}\nexport const createAuthentication: AuthenticationFactory = ({\n getIdentityData,\n onError,\n ...config\n}) => {\n /**\n * TODO @ts-refactor\n */\n // @ts-ignore\n Object.keys(config).forEach(key => config[key] === undefined && delete config[key]);\n Auth.configure({ ...defaultOptions, ...config });\n\n const Authentication: React.FC<AuthenticationProps> = props => {\n const { children } = props;\n const [loadingIdentity, setLoadingIdentity] = useState(false);\n const { setIdentity } = useSecurity();\n const client = useApolloClient();\n\n const onToken = useCallback(async (token: CognitoIdToken) => {\n const { payload, logout } = token;\n\n setLoadingIdentity(true);\n\n try {\n const { id, displayName, type, permissions, ...data } = await getIdentityData({\n client,\n payload\n });\n\n setIdentity({\n id,\n displayName,\n type,\n permissions,\n ...data,\n logout:\n logout ||\n (() => {\n return void 0;\n })\n });\n } catch (err) {\n console.log(\"ERROR\", err);\n if (typeof onError === \"function\") {\n onError(err);\n } else {\n console.error(err);\n }\n } finally {\n setLoadingIdentity(false);\n }\n }, []);\n\n useEffect(() => {\n plugins.register(createApolloLinkPlugin());\n }, []);\n\n return (\n <Authenticator onToken={onToken}>\n {loadingIdentity ? <LoggingIn /> : <SignIn />}\n <RequireNewPassword />\n <ForgotPassword />\n <SetNewPassword />\n <SignedIn>{children}</SignedIn>\n </Authenticator>\n );\n };\n\n return Authentication;\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAGA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAA0C;EAAA;AAE1C,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAsB,GAA2B;EACnD,OAAO,IAAIC,kCAAgB,CAAC,YAAM;IAC9B,OAAO,IAAAC,6BAAU;MAAA,mGAAC,iBAAOC,CAAC;QAAA;QAAA;UAAA;YAAA;cAAIC,OAAO,QAAPA,OAAO;cAAA;cAAA,OACdC,UAAI,CAACC,cAAc,EAAE;YAAA;cAAlCC,IAAI;cACJC,OAAO,GAAGD,IAAI,CAACE,UAAU,EAAE;cAAA,IAE5BD,OAAO;gBAAA;gBAAA;cAAA;cAAA,iCACD;gBAAEJ,OAAO,EAAPA;cAAQ,CAAC;YAAA;cAAA,MAIlBA,OAAO,IAAIA,OAAO,CAACM,aAAa;gBAAA;gBAAA;cAAA;cAAA,iCACzB;gBAAEN,OAAO,EAAPA;cAAQ,CAAC;YAAA;cAAA,iCAGf;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BAAkB,OAAG,eACtB,6BAAC,uBAAc,OAAG,eAClB,6BAAC,uBAAc,OAAG,eAClB,6BAAC,iBAAQ,QAAEF,QAAQ,CAAY,CACnB;EAExB,CAAC;EAED,OAAOF,cAAc;AACzB,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/app-admin-cognito",
3
- "version": "0.0.0-mt-2",
3
+ "version": "0.0.0-unstable.085ff6572f",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,35 +13,36 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "@apollo/react-hooks": "3.1.5",
16
- "@aws-amplify/auth": "4.3.10",
17
- "@emotion/styled": "10.0.27",
18
- "@webiny/app": "0.0.0-mt-2",
19
- "@webiny/app-cognito-authenticator": "0.0.0-mt-2",
20
- "@webiny/app-security": "0.0.0-mt-2",
21
- "@webiny/form": "0.0.0-mt-2",
22
- "@webiny/plugins": "0.0.0-mt-2",
23
- "@webiny/ui": "0.0.0-mt-2",
24
- "@webiny/validation": "0.0.0-mt-2",
16
+ "@aws-amplify/auth": "5.1.9",
17
+ "@emotion/styled": "11.10.6",
18
+ "@webiny/app": "0.0.0-unstable.085ff6572f",
19
+ "@webiny/app-admin": "0.0.0-unstable.085ff6572f",
20
+ "@webiny/app-cognito-authenticator": "0.0.0-unstable.085ff6572f",
21
+ "@webiny/app-security": "0.0.0-unstable.085ff6572f",
22
+ "@webiny/form": "0.0.0-unstable.085ff6572f",
23
+ "@webiny/plugins": "0.0.0-unstable.085ff6572f",
24
+ "@webiny/ui": "0.0.0-unstable.085ff6572f",
25
+ "@webiny/validation": "0.0.0-unstable.085ff6572f",
25
26
  "apollo-client": "2.6.10",
26
27
  "apollo-link-context": "1.0.20",
27
28
  "emotion": "10.0.27",
28
- "react": "16.14.0",
29
- "react-dom": "16.14.0"
29
+ "react": "17.0.2",
30
+ "react-dom": "17.0.2"
30
31
  },
31
32
  "devDependencies": {
32
- "@babel/cli": "^7.5.5",
33
- "@babel/core": "^7.5.5",
34
- "@babel/plugin-proposal-class-properties": "^7.5.5",
35
- "@babel/plugin-proposal-throw-expressions": "^7.7.4",
36
- "@babel/preset-env": "^7.5.5",
37
- "@babel/preset-react": "^7.0.0",
38
- "@babel/preset-typescript": "^7.8.3",
39
- "@webiny/cli": "^0.0.0-mt-2",
40
- "@webiny/project-utils": "^0.0.0-mt-2",
41
- "babel-plugin-lodash": "^3.3.4",
42
- "rimraf": "^3.0.2",
43
- "ttypescript": "^1.5.12",
44
- "typescript": "^4.1.3"
33
+ "@babel/cli": "7.20.7",
34
+ "@babel/core": "7.20.12",
35
+ "@babel/plugin-proposal-class-properties": "7.18.6",
36
+ "@babel/plugin-proposal-throw-expressions": "7.18.6",
37
+ "@babel/preset-env": "7.20.2",
38
+ "@babel/preset-react": "7.18.6",
39
+ "@babel/preset-typescript": "7.18.6",
40
+ "@webiny/cli": "0.0.0-unstable.085ff6572f",
41
+ "@webiny/project-utils": "0.0.0-unstable.085ff6572f",
42
+ "babel-plugin-lodash": "3.3.4",
43
+ "rimraf": "3.0.2",
44
+ "ttypescript": "1.5.15",
45
+ "typescript": "4.7.4"
45
46
  },
46
47
  "publishConfig": {
47
48
  "access": "public",
@@ -58,5 +59,5 @@
58
59
  ]
59
60
  }
60
61
  },
61
- "gitHead": "3c0dcfb3c22c9f83107fdb97b25014cd03d9db7d"
62
+ "gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
62
63
  }
package/types.js CHANGED
@@ -0,0 +1 @@
1
+ "use strict";
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":[""],"mappings":""}
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- declare const ForgotPassword: () => JSX.Element;
1
+ import * as React from "react";
2
+ declare const ForgotPassword: React.FC;
3
3
  export default ForgotPassword;
@@ -1,41 +1,43 @@
1
- import * as React from "react";
2
- import { Form } from "@webiny/form";
3
- import { validation } from "@webiny/validation";
4
- import { ButtonPrimary, ButtonDefault } from "@webiny/ui/Button";
5
- import { Input } from "@webiny/ui/Input";
6
- import { Grid, Cell } from "@webiny/ui/Grid";
7
- import { Typography } from "@webiny/ui/Typography";
8
- import { Alert } from "@webiny/ui/Alert";
9
- import { Elevation } from "@webiny/ui/Elevation";
10
- import StateContainer from "./StateContainer";
11
- import { alignRight, InnerContent, Title } from "./StyledComponents";
12
- import { CircularProgress } from "@webiny/ui/Progress";
13
- import { useAuthenticator } from "@webiny/app-cognito-authenticator/hooks/useAuthenticator";
14
- import { useForgotPassword } from "@webiny/app-cognito-authenticator/hooks/useForgotPassword";
1
+ "use strict";
15
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _form = require("@webiny/form");
11
+ var _validation = require("@webiny/validation");
12
+ var _Button = require("@webiny/ui/Button");
13
+ var _Input = require("@webiny/ui/Input");
14
+ var _Grid = require("@webiny/ui/Grid");
15
+ var _Typography = require("@webiny/ui/Typography");
16
+ var _Alert = require("@webiny/ui/Alert");
17
+ var _Elevation = require("@webiny/ui/Elevation");
18
+ var _StateContainer = _interopRequireDefault(require("./StateContainer"));
19
+ var _StyledComponents = require("./StyledComponents");
20
+ var _Progress = require("@webiny/ui/Progress");
21
+ var _useAuthenticator2 = require("@webiny/app-cognito-authenticator/hooks/useAuthenticator");
22
+ var _useForgotPassword2 = require("@webiny/app-cognito-authenticator/hooks/useForgotPassword");
16
23
  var ForgotPassword = function ForgotPassword() {
17
- var _useAuthenticator = useAuthenticator(),
18
- checkingUser = _useAuthenticator.checkingUser,
19
- authData = _useAuthenticator.authData,
20
- changeState = _useAuthenticator.changeState;
21
-
22
- var _useForgotPassword = useForgotPassword(),
23
- loading = _useForgotPassword.loading,
24
- codeSent = _useForgotPassword.codeSent,
25
- shouldRender = _useForgotPassword.shouldRender,
26
- setPassword = _useForgotPassword.setPassword,
27
- requestCode = _useForgotPassword.requestCode,
28
- error = _useForgotPassword.error;
29
-
30
- if (!shouldRender || checkingUser) {
24
+ var _useAuthenticator = (0, _useAuthenticator2.useAuthenticator)(),
25
+ authData = _useAuthenticator.authData,
26
+ changeState = _useAuthenticator.changeState;
27
+ var _useForgotPassword = (0, _useForgotPassword2.useForgotPassword)(),
28
+ loading = _useForgotPassword.loading,
29
+ codeSent = _useForgotPassword.codeSent,
30
+ shouldRender = _useForgotPassword.shouldRender,
31
+ setPassword = _useForgotPassword.setPassword,
32
+ requestCode = _useForgotPassword.requestCode,
33
+ error = _useForgotPassword.error;
34
+ if (!shouldRender) {
31
35
  return null;
32
36
  }
33
-
34
37
  var _ref = authData || {},
35
- _ref$username = _ref.username,
36
- username = _ref$username === void 0 ? "" : _ref$username;
37
-
38
- return /*#__PURE__*/React.createElement(StateContainer, null, /*#__PURE__*/React.createElement(Form, {
38
+ _ref$username = _ref.username,
39
+ username = _ref$username === void 0 ? "" : _ref$username;
40
+ return /*#__PURE__*/React.createElement(_StateContainer.default, null, /*#__PURE__*/React.createElement(_form.Form, {
39
41
  data: {
40
42
  username: username
41
43
  },
@@ -50,51 +52,56 @@ var ForgotPassword = function ForgotPassword() {
50
52
  submitOnEnter: true
51
53
  }, function (_ref3) {
52
54
  var Bind = _ref3.Bind,
53
- submit = _ref3.submit,
54
- data = _ref3.data;
55
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Elevation, {
55
+ submit = _ref3.submit,
56
+ data = _ref3.data;
57
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Elevation.Elevation, {
56
58
  z: 2
57
- }, /*#__PURE__*/React.createElement(InnerContent, null, loading && /*#__PURE__*/React.createElement(CircularProgress, null), /*#__PURE__*/React.createElement(Title, null, /*#__PURE__*/React.createElement("h1", null, /*#__PURE__*/React.createElement(Typography, {
59
+ }, /*#__PURE__*/React.createElement(_StyledComponents.InnerContent, null, loading && /*#__PURE__*/React.createElement(_Progress.CircularProgress, null), /*#__PURE__*/React.createElement(_StyledComponents.Title, null, /*#__PURE__*/React.createElement("h1", null, /*#__PURE__*/React.createElement(_Typography.Typography, {
58
60
  use: "headline4"
59
- }, "Password Recovery")), /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement(Typography, {
60
- use: "subtitle2"
61
- }, "request a password reset code"))), error && /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
61
+ }, "Password Recovery")), /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement(_Typography.Typography, {
62
+ use: "body2"
63
+ }, "request a password reset code"))), error && /*#__PURE__*/React.createElement(_Grid.Grid, null, /*#__PURE__*/React.createElement(_Grid.Cell, {
62
64
  span: 12
63
- }, /*#__PURE__*/React.createElement(Alert, {
65
+ }, /*#__PURE__*/React.createElement(_Alert.Alert, {
64
66
  title: "Something went wrong",
65
67
  type: "danger"
66
- }, error))), !codeSent ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
68
+ }, error))), !codeSent ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Grid.Grid, null, /*#__PURE__*/React.createElement(_Grid.Cell, {
67
69
  span: 12
68
70
  }, /*#__PURE__*/React.createElement(Bind, {
69
71
  name: "username",
70
- validators: validation.create("required"),
72
+ validators: _validation.validation.create("required"),
71
73
  beforeChange: function beforeChange(val, cb) {
72
74
  return cb(val.toLowerCase());
73
75
  }
74
- }, /*#__PURE__*/React.createElement(Input, {
76
+ }, /*#__PURE__*/React.createElement(_Input.Input, {
75
77
  label: "Email",
76
78
  description: "A reset code will be sent to your email."
77
- })))), /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
79
+ })))), /*#__PURE__*/React.createElement(_Grid.Grid, null, /*#__PURE__*/React.createElement(_Grid.Cell, {
78
80
  span: 12,
79
- className: alignRight
80
- }, /*#__PURE__*/React.createElement(ButtonPrimary, {
81
- onClick: submit
82
- }, "Send me the code")))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
81
+ className: _StyledComponents.alignRight
82
+ }, /*#__PURE__*/React.createElement(_Button.ButtonPrimary, {
83
+ onClick: function onClick(ev) {
84
+ submit(ev);
85
+ },
86
+ "data-testid": "send-code"
87
+ }, "Send me the code")))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Grid.Grid, null, /*#__PURE__*/React.createElement(_Grid.Cell, {
83
88
  span: 12
84
- }, /*#__PURE__*/React.createElement(Typography, {
89
+ }, /*#__PURE__*/React.createElement(_Typography.Typography, {
85
90
  use: "body1"
86
- }, "We have sent you a code to reset your password!", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), "Click the \"Resend code\" button below to resend the code in case you haven't received it the first time."))), /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
91
+ }, "We have sent you a code to reset your password!", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), "Click the \"Resend code\" button below to resend the code in case you haven't received it the first time."))), /*#__PURE__*/React.createElement(_Grid.Grid, null, /*#__PURE__*/React.createElement(_Grid.Cell, {
87
92
  span: 12,
88
- className: alignRight
89
- }, /*#__PURE__*/React.createElement(ButtonDefault, {
93
+ className: _StyledComponents.alignRight
94
+ }, /*#__PURE__*/React.createElement(_Button.ButtonDefault, {
90
95
  onClick: function onClick() {
91
- return requestCode({
96
+ requestCode({
92
97
  username: data.username
93
98
  });
94
99
  }
95
- }, "Resend code"), /*#__PURE__*/React.createElement(ButtonPrimary, {
96
- onClick: submit
97
- }, "I got the code!")))))), /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
100
+ }, "Resend code"), /*#__PURE__*/React.createElement(_Button.ButtonPrimary, {
101
+ onClick: function onClick(ev) {
102
+ submit(ev);
103
+ }
104
+ }, "I got the code!")))))), /*#__PURE__*/React.createElement(_Grid.Grid, null, /*#__PURE__*/React.createElement(_Grid.Cell, {
98
105
  span: 12,
99
106
  style: {
100
107
  textAlign: "center"
@@ -107,5 +114,5 @@ var ForgotPassword = function ForgotPassword() {
107
114
  }, "Sign in"))));
108
115
  }));
109
116
  };
110
-
111
- export default ForgotPassword;
117
+ var _default = ForgotPassword;
118
+ exports.default = _default;