@atls/react-kratos-browser-flows 0.0.1 → 0.0.2

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 (57) hide show
  1. package/dist/flows/abstract.flow.js +29 -36
  2. package/dist/flows/index.js +1 -0
  3. package/dist/flows/kratos.client.js +1 -1
  4. package/dist/flows/login.flow.js +2 -2
  5. package/dist/flows/logout.flow.js +22 -0
  6. package/dist/flows/recovery.flow.js +1 -1
  7. package/dist/flows/registration.flow.js +1 -1
  8. package/dist/flows/settings.flow.js +3 -3
  9. package/dist/flows/verification.flow.js +1 -1
  10. package/dist/providers/flows.context.js +1 -1
  11. package/dist/providers/index.js +1 -0
  12. package/dist/providers/kraots-logout-flow.provider.js +10 -0
  13. package/dist/providers/kratos-errors-flow.provider.js +1 -1
  14. package/dist/providers/kratos-flow.provider.js +11 -7
  15. package/dist/providers/kratos-login-flow.provider.js +1 -1
  16. package/dist/providers/kratos-recovery-flow.provider.js +1 -1
  17. package/dist/providers/kratos-registration-flow.provider.js +1 -1
  18. package/dist/providers/kratos-settings-flow.provider.js +1 -1
  19. package/dist/providers/kratos-verification-flow.provider.js +1 -1
  20. package/dist/providers/use-flow.hook.js +3 -3
  21. package/dist/ui/flow-error.component.js +2 -2
  22. package/dist/ui/flow-form.component.js +4 -16
  23. package/dist/ui/flow-messages.component.js +1 -1
  24. package/dist/ui/flow-node-messages.component.js +2 -2
  25. package/dist/ui/flow-node.component.js +4 -4
  26. package/dist/ui/flow-nodes-group.component.js +1 -1
  27. package/dist/ui/flow-submit.component.js +3 -3
  28. package/package.json +9 -9
  29. package/dist/flows/abstract.flow.d.ts +0 -27
  30. package/dist/flows/errors.flow.d.ts +0 -5
  31. package/dist/flows/flow.interfaces.d.ts +0 -33
  32. package/dist/flows/index.d.ts +0 -7
  33. package/dist/flows/kratos.client.d.ts +0 -4
  34. package/dist/flows/login.flow.d.ts +0 -7
  35. package/dist/flows/recovery.flow.d.ts +0 -7
  36. package/dist/flows/registration.flow.d.ts +0 -7
  37. package/dist/flows/settings.flow.d.ts +0 -7
  38. package/dist/flows/verification.flow.d.ts +0 -7
  39. package/dist/index.d.ts +0 -3
  40. package/dist/providers/flows.context.d.ts +0 -3
  41. package/dist/providers/index.d.ts +0 -8
  42. package/dist/providers/kratos-errors-flow.provider.d.ts +0 -1
  43. package/dist/providers/kratos-flow.provider.d.ts +0 -7
  44. package/dist/providers/kratos-login-flow.provider.d.ts +0 -1
  45. package/dist/providers/kratos-recovery-flow.provider.d.ts +0 -1
  46. package/dist/providers/kratos-registration-flow.provider.d.ts +0 -1
  47. package/dist/providers/kratos-settings-flow.provider.d.ts +0 -1
  48. package/dist/providers/kratos-verification-flow.provider.d.ts +0 -1
  49. package/dist/providers/use-flow.hook.d.ts +0 -2
  50. package/dist/ui/flow-error.component.d.ts +0 -13
  51. package/dist/ui/flow-form.component.d.ts +0 -4
  52. package/dist/ui/flow-messages.component.d.ts +0 -7
  53. package/dist/ui/flow-node-messages.component.d.ts +0 -8
  54. package/dist/ui/flow-node.component.d.ts +0 -23
  55. package/dist/ui/flow-nodes-group.component.d.ts +0 -21
  56. package/dist/ui/flow-submit.component.d.ts +0 -4
  57. package/dist/ui/index.d.ts +0 -7
@@ -1,18 +1,16 @@
1
1
  "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
- if (!privateMap.has(receiver)) {
4
- throw new TypeError("attempted to set private field on non-instance");
5
- }
6
- privateMap.set(receiver, value);
7
- return value;
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
8
7
  };
9
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
- if (!privateMap.has(receiver)) {
11
- throw new TypeError("attempted to get private field on non-instance");
12
- }
13
- return privateMap.get(receiver);
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
14
12
  };
15
- var _values, _state, _loading;
13
+ var _AbstractFlow_values, _AbstractFlow_state, _AbstractFlow_loading;
16
14
  Object.defineProperty(exports, "__esModule", { value: true });
17
15
  exports.AbstractFlow = void 0;
18
16
  const events_1 = require("events");
@@ -20,56 +18,51 @@ class AbstractFlow extends events_1.EventEmitter {
20
18
  constructor(client) {
21
19
  super();
22
20
  this.client = client;
23
- _values.set(this, {});
24
- _state.set(this, void 0);
25
- _loading.set(this, false);
21
+ _AbstractFlow_values.set(this, {});
22
+ _AbstractFlow_state.set(this, void 0);
23
+ _AbstractFlow_loading.set(this, false);
26
24
  this.setMaxListeners(50);
27
25
  }
28
26
  setLoading(loading) {
29
- __classPrivateFieldSet(this, _loading, loading);
27
+ __classPrivateFieldSet(this, _AbstractFlow_loading, loading, "f");
30
28
  }
31
29
  isLoading() {
32
- return __classPrivateFieldGet(this, _loading);
30
+ return __classPrivateFieldGet(this, _AbstractFlow_loading, "f");
33
31
  }
34
32
  setState(state) {
35
- __classPrivateFieldSet(this, _state, state);
33
+ __classPrivateFieldSet(this, _AbstractFlow_state, state, "f");
36
34
  }
37
35
  hasState() {
38
- return Boolean(__classPrivateFieldGet(this, _state));
36
+ return Boolean(__classPrivateFieldGet(this, _AbstractFlow_state, "f"));
39
37
  }
40
38
  getState() {
41
- return __classPrivateFieldGet(this, _state);
39
+ return __classPrivateFieldGet(this, _AbstractFlow_state, "f");
42
40
  }
43
41
  getMessages() {
44
- var _a, _b;
45
- return ((_b = (_a = __classPrivateFieldGet(this, _state)) === null || _a === void 0 ? void 0 : _a.ui) === null || _b === void 0 ? void 0 : _b.messages) || [];
42
+ return __classPrivateFieldGet(this, _AbstractFlow_state, "f")?.ui?.messages || [];
46
43
  }
47
44
  getNode(name) {
48
- var _a, _b, _c;
49
- return (_c = (_b = (_a = __classPrivateFieldGet(this, _state)) === null || _a === void 0 ? void 0 : _a.ui) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.find((node) => node.attributes.name === name);
45
+ return __classPrivateFieldGet(this, _AbstractFlow_state, "f")?.ui?.nodes?.find((node) => node.attributes.name === name);
50
46
  }
51
47
  getNodes(name) {
52
- var _a, _b, _c;
53
- return (((_c = (_b = (_a = __classPrivateFieldGet(this, _state)) === null || _a === void 0 ? void 0 : _a.ui) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.filter((node) => node.attributes.name === name)) || []);
48
+ return (__classPrivateFieldGet(this, _AbstractFlow_state, "f")?.ui?.nodes?.filter((node) => node.attributes.name === name) || []);
54
49
  }
55
50
  getNodesGroup(group) {
56
- var _a, _b, _c;
57
- return ((_c = (_b = (_a = __classPrivateFieldGet(this, _state)) === null || _a === void 0 ? void 0 : _a.ui) === null || _b === void 0 ? void 0 : _b.nodes) === null || _c === void 0 ? void 0 : _c.filter((node) => node.group === group)) || [];
51
+ return __classPrivateFieldGet(this, _AbstractFlow_state, "f")?.ui?.nodes?.filter((node) => node.group === group) || [];
58
52
  }
59
53
  getValue(name) {
60
- return __classPrivateFieldGet(this, _values)[name];
54
+ return __classPrivateFieldGet(this, _AbstractFlow_values, "f")[name];
61
55
  }
62
56
  getValues() {
63
- return __classPrivateFieldGet(this, _values);
57
+ return __classPrivateFieldGet(this, _AbstractFlow_values, "f");
64
58
  }
65
59
  setValue(name, value) {
66
- __classPrivateFieldGet(this, _values)[name] = value;
60
+ __classPrivateFieldGet(this, _AbstractFlow_values, "f")[name] = value;
67
61
  }
68
62
  setValues(state) {
69
- var _a, _b;
70
- (_b = (_a = state === null || state === void 0 ? void 0 : state.ui) === null || _a === void 0 ? void 0 : _a.nodes) === null || _b === void 0 ? void 0 : _b.forEach(({ attributes }) => {
71
- if (!__classPrivateFieldGet(this, _values)[attributes.name]) {
72
- __classPrivateFieldGet(this, _values)[attributes.name] =
63
+ state?.ui?.nodes?.forEach(({ attributes }) => {
64
+ if (!__classPrivateFieldGet(this, _AbstractFlow_values, "f")[attributes.name]) {
65
+ __classPrivateFieldGet(this, _AbstractFlow_values, "f")[attributes.name] =
73
66
  attributes.value || '';
74
67
  }
75
68
  });
@@ -79,4 +72,4 @@ class AbstractFlow extends events_1.EventEmitter {
79
72
  }
80
73
  }
81
74
  exports.AbstractFlow = AbstractFlow;
82
- _values = new WeakMap(), _state = new WeakMap(), _loading = new WeakMap();
75
+ _AbstractFlow_values = new WeakMap(), _AbstractFlow_state = new WeakMap(), _AbstractFlow_loading = new WeakMap();
@@ -17,3 +17,4 @@ __exportStar(require("./recovery.flow"), exports);
17
17
  __exportStar(require("./settings.flow"), exports);
18
18
  __exportStar(require("./errors.flow"), exports);
19
19
  __exportStar(require("./login.flow"), exports);
20
+ __exportStar(require("./logout.flow"), exports);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KratosClient = void 0;
4
4
  const kratos_client_1 = require("@ory/kratos-client");
5
5
  const kratos_client_2 = require("@ory/kratos-client");
6
- class KratosClient extends kratos_client_2.V0alpha1Api {
6
+ class KratosClient extends kratos_client_2.V0alpha2Api {
7
7
  constructor(basePath) {
8
8
  if (!basePath && typeof window !== 'undefined') {
9
9
  if (window.location.hostname === 'localhost') {
@@ -15,7 +15,7 @@ class LoginFlow extends abstract_flow_1.AbstractFlow {
15
15
  const flowId = new URL(window.location.href).searchParams.get('flow');
16
16
  const { data } = flowId
17
17
  ? await this.client.getSelfServiceLoginFlow(flowId, undefined, { withCredentials: true })
18
- : await this.client.initializeSelfServiceLoginFlowForBrowsers(false, {
18
+ : await this.client.initializeSelfServiceLoginFlowForBrowsers(false, undefined, undefined, {
19
19
  withCredentials: true,
20
20
  });
21
21
  this.setLoading(false);
@@ -44,7 +44,7 @@ class LoginFlow extends abstract_flow_1.AbstractFlow {
44
44
  body.method = method;
45
45
  }
46
46
  try {
47
- await this.client.submitSelfServiceLoginFlow(this.getState().id, body, {
47
+ await this.client.submitSelfServiceLoginFlow(this.getState().id, undefined, body, {
48
48
  withCredentials: true,
49
49
  });
50
50
  this.complete();
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogoutFlow = void 0;
4
+ const abstract_flow_1 = require("./abstract.flow");
5
+ class LogoutFlow extends abstract_flow_1.AbstractFlow {
6
+ async load() {
7
+ if (typeof window === 'undefined') {
8
+ return;
9
+ }
10
+ if (this.hasState() || this.isLoading()) {
11
+ return;
12
+ }
13
+ this.setLoading(true);
14
+ const { data } = await this.client.createSelfServiceLogoutFlowUrlForBrowsers(undefined, {
15
+ withCredentials: true,
16
+ });
17
+ await this.client.submitSelfServiceLogoutFlow(data.logout_token);
18
+ this.setLoading(false);
19
+ }
20
+ async submit() { }
21
+ }
22
+ exports.LogoutFlow = LogoutFlow;
@@ -17,7 +17,7 @@ class RecoveryFlow extends abstract_flow_1.AbstractFlow {
17
17
  ? await this.client.getSelfServiceRecoveryFlow(flowId, undefined, {
18
18
  withCredentials: true,
19
19
  })
20
- : await this.client.initializeSelfServiceRecoveryFlowForBrowsers({
20
+ : await this.client.initializeSelfServiceRecoveryFlowForBrowsers(undefined, {
21
21
  withCredentials: true,
22
22
  });
23
23
  this.setLoading(false);
@@ -17,7 +17,7 @@ class RegistrationFlow extends abstract_flow_1.AbstractFlow {
17
17
  ? await this.client.getSelfServiceRegistrationFlow(flowId, undefined, {
18
18
  withCredentials: true,
19
19
  })
20
- : await this.client.initializeSelfServiceRegistrationFlowForBrowsers({
20
+ : await this.client.initializeSelfServiceRegistrationFlowForBrowsers(undefined, {
21
21
  withCredentials: true,
22
22
  });
23
23
  this.setLoading(false);
@@ -50,9 +50,9 @@ class SettingsFlow extends abstract_flow_1.AbstractFlow {
50
50
  const { data } = await this.client.submitSelfServiceSettingsFlow(this.getState().id, undefined, body, {
51
51
  withCredentials: true,
52
52
  });
53
- this.setState(data.flow);
54
- this.setValues(data.flow);
55
- this.emit('load', data.flow);
53
+ this.setState(data);
54
+ this.setValues(data);
55
+ this.emit('load', data);
56
56
  }
57
57
  catch (error) {
58
58
  const { data, status } = error
@@ -17,7 +17,7 @@ class VerificationFlow extends abstract_flow_1.AbstractFlow {
17
17
  ? await this.client.getSelfServiceVerificationFlow(flowId, undefined, {
18
18
  withCredentials: true,
19
19
  })
20
- : await this.client.initializeSelfServiceVerificationFlowForBrowsers({
20
+ : await this.client.initializeSelfServiceVerificationFlowForBrowsers(undefined, {
21
21
  withCredentials: true,
22
22
  });
23
23
  this.setLoading(false);
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Consumer = exports.Provider = exports.Context = void 0;
4
4
  const react_1 = require("react");
5
- exports.Context = react_1.createContext(null);
5
+ exports.Context = (0, react_1.createContext)(null);
6
6
  exports.Provider = exports.Context.Provider, exports.Consumer = exports.Context.Consumer;
@@ -15,6 +15,7 @@ __exportStar(require("./kratos-verification-flow.provider"), exports);
15
15
  __exportStar(require("./kratos-recovery-flow.provider"), exports);
16
16
  __exportStar(require("./kratos-settings-flow.provider"), exports);
17
17
  __exportStar(require("./kratos-errors-flow.provider"), exports);
18
+ __exportStar(require("./kraots-logout-flow.provider"), exports);
18
19
  __exportStar(require("./kratos-login-flow.provider"), exports);
19
20
  __exportStar(require("./kratos-flow.provider"), exports);
20
21
  __exportStar(require("./use-flow.hook"), exports);
@@ -0,0 +1,10 @@
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
+ exports.KratosLogoutFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const kratos_flow_provider_1 = require("./kratos-flow.provider");
9
+ const KratosLogoutFlowProvider = (props) => react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, { ...props, name: 'logout' });
10
+ exports.KratosLogoutFlowProvider = KratosLogoutFlowProvider;
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KratosErrorsFlowProvider = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const kratos_flow_provider_1 = require("./kratos-flow.provider");
9
- const KratosErrorsFlowProvider = (props) => react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, Object.assign({}, props, { name: 'errors' }));
9
+ const KratosErrorsFlowProvider = (props) => react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, { ...props, name: 'errors' });
10
10
  exports.KratosErrorsFlowProvider = KratosErrorsFlowProvider;
@@ -6,17 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KratosFlowProvider = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const react_2 = require("react");
9
- const registration_flow_1 = require("../flows/registration.flow");
10
- const verification_flow_1 = require("../flows/verification.flow");
11
- const recovery_flow_1 = require("../flows/recovery.flow");
12
- const settings_flow_1 = require("../flows/settings.flow");
13
9
  const errors_flow_1 = require("../flows/errors.flow");
14
- const login_flow_1 = require("../flows/login.flow");
15
10
  const kratos_client_1 = require("../flows/kratos.client");
11
+ const login_flow_1 = require("../flows/login.flow");
12
+ const logout_flow_1 = require("../flows/logout.flow");
13
+ const recovery_flow_1 = require("../flows/recovery.flow");
14
+ const registration_flow_1 = require("../flows/registration.flow");
15
+ const settings_flow_1 = require("../flows/settings.flow");
16
+ const verification_flow_1 = require("../flows/verification.flow");
16
17
  const flows_context_1 = require("./flows.context");
17
18
  const KratosFlowProvider = ({ name, basePath, children }) => {
18
- const client = react_2.useMemo(() => new kratos_client_1.KratosClient(basePath), [basePath]);
19
- const flow = react_2.useMemo(() => {
19
+ const client = (0, react_2.useMemo)(() => new kratos_client_1.KratosClient(basePath), [basePath]);
20
+ const flow = (0, react_2.useMemo)(() => {
20
21
  if (name === 'login') {
21
22
  return new login_flow_1.LoginFlow(client);
22
23
  }
@@ -35,6 +36,9 @@ const KratosFlowProvider = ({ name, basePath, children }) => {
35
36
  if (name === 'errors') {
36
37
  return new errors_flow_1.ErrorsFlow(client);
37
38
  }
39
+ if (name === 'logout') {
40
+ return new logout_flow_1.LogoutFlow(client);
41
+ }
38
42
  throw new Error(`Unkown flow: ${name}`);
39
43
  }, [name, client]);
40
44
  return react_1.default.createElement(flows_context_1.Provider, { value: flow }, children);
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KratosLoginFlowProvider = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const kratos_flow_provider_1 = require("./kratos-flow.provider");
9
- const KratosLoginFlowProvider = (props) => react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, Object.assign({}, props, { name: 'login' }));
9
+ const KratosLoginFlowProvider = (props) => react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, { ...props, name: 'login' });
10
10
  exports.KratosLoginFlowProvider = KratosLoginFlowProvider;
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KratosRecoveryFlowProvider = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const kratos_flow_provider_1 = require("./kratos-flow.provider");
9
- const KratosRecoveryFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, Object.assign({}, props, { name: 'recovery' })));
9
+ const KratosRecoveryFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, { ...props, name: 'recovery' }));
10
10
  exports.KratosRecoveryFlowProvider = KratosRecoveryFlowProvider;
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KratosRegistrationFlowProvider = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const kratos_flow_provider_1 = require("./kratos-flow.provider");
9
- const KratosRegistrationFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, Object.assign({}, props, { name: 'registration' })));
9
+ const KratosRegistrationFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, { ...props, name: 'registration' }));
10
10
  exports.KratosRegistrationFlowProvider = KratosRegistrationFlowProvider;
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KratosSettingsFlowProvider = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const kratos_flow_provider_1 = require("./kratos-flow.provider");
9
- const KratosSettingsFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, Object.assign({}, props, { name: 'settings' })));
9
+ const KratosSettingsFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, { ...props, name: 'settings' }));
10
10
  exports.KratosSettingsFlowProvider = KratosSettingsFlowProvider;
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KratosVerificationFlowProvider = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const kratos_flow_provider_1 = require("./kratos-flow.provider");
9
- const KratosVerificationFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, Object.assign({}, props, { name: 'verification' })));
9
+ const KratosVerificationFlowProvider = (props) => (react_1.default.createElement(kratos_flow_provider_1.KratosFlowProvider, { ...props, name: 'verification' }));
10
10
  exports.KratosVerificationFlowProvider = KratosVerificationFlowProvider;
@@ -6,12 +6,12 @@ const react_2 = require("react");
6
6
  const react_3 = require("react");
7
7
  const flows_context_1 = require("./flows.context");
8
8
  const useFlow = () => {
9
- const flow = react_1.useContext(flows_context_1.Context);
9
+ const flow = (0, react_1.useContext)(flows_context_1.Context);
10
10
  if (!flow) {
11
11
  throw new Error('Missing <KratosFlowProvider>');
12
12
  }
13
- const [, setState] = react_3.useState(null);
14
- react_2.useEffect(() => {
13
+ const [, setState] = (0, react_3.useState)(null);
14
+ (0, react_2.useEffect)(() => {
15
15
  flow.load();
16
16
  const callback = (flowState) => {
17
17
  setState(flowState);
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowError = void 0;
4
4
  const providers_1 = require("../providers");
5
5
  const FlowError = ({ children }) => {
6
- const flow = providers_1.useFlow();
6
+ const flow = (0, providers_1.useFlow)();
7
7
  const state = flow.getState();
8
- if (typeof children === 'function' && (state === null || state === void 0 ? void 0 : state.error)) {
8
+ if (typeof children === 'function' && state?.error) {
9
9
  return children(state.error);
10
10
  }
11
11
  return null;
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -18,13 +7,12 @@ exports.FlowForm = void 0;
18
7
  const react_1 = __importDefault(require("react"));
19
8
  const react_2 = require("react");
20
9
  const providers_1 = require("../providers");
21
- const FlowForm = (_a) => {
22
- var { children } = _a, props = __rest(_a, ["children"]);
23
- const flow = providers_1.useFlow();
24
- const ui = react_2.useMemo(() => { var _a; return (_a = flow.getState()) === null || _a === void 0 ? void 0 : _a.ui; }, [flow.getState()]);
10
+ const FlowForm = ({ children, ...props }) => {
11
+ const flow = (0, providers_1.useFlow)();
12
+ const ui = (0, react_2.useMemo)(() => flow.getState()?.ui, [flow.getState()]);
25
13
  if (!ui) {
26
14
  return null;
27
15
  }
28
- return (react_1.default.createElement("form", Object.assign({}, props, { action: ui.action, method: ui.method }), children));
16
+ return (react_1.default.createElement("form", { ...props, action: ui.action, method: ui.method }, children));
29
17
  };
30
18
  exports.FlowForm = FlowForm;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowMessages = void 0;
4
4
  const providers_1 = require("../providers");
5
5
  const FlowMessages = ({ children }) => {
6
- const flow = providers_1.useFlow();
6
+ const flow = (0, providers_1.useFlow)();
7
7
  const messages = flow.getMessages();
8
8
  if (typeof children === 'function' && messages) {
9
9
  return children(messages);
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowNodeMessages = void 0;
4
4
  const providers_1 = require("../providers");
5
5
  const FlowNodeMessages = ({ name, children }) => {
6
- const flow = providers_1.useFlow();
6
+ const flow = (0, providers_1.useFlow)();
7
7
  const node = flow.getNode(name);
8
- if (typeof children === 'function' && (node === null || node === void 0 ? void 0 : node.messages)) {
8
+ if (typeof children === 'function' && node?.messages) {
9
9
  return children(node.messages);
10
10
  }
11
11
  return null;
@@ -6,10 +6,10 @@ const react_2 = require("react");
6
6
  const react_3 = require("react");
7
7
  const providers_1 = require("../providers");
8
8
  const FlowNode = ({ name, children }) => {
9
- const flow = providers_1.useFlow();
10
- const node = react_1.useMemo(() => flow.getNode(name), [name, flow, flow.getState()]);
11
- const [value = '', setValue] = react_2.useState(flow.getValue(name));
12
- const onChange = react_3.useCallback((event) => {
9
+ const flow = (0, providers_1.useFlow)();
10
+ const node = (0, react_1.useMemo)(() => flow.getNode(name), [name, flow, flow.getState()]);
11
+ const [value = '', setValue] = (0, react_2.useState)(flow.getValue(name));
12
+ const onChange = (0, react_3.useCallback)((event) => {
13
13
  if (event && event.target) {
14
14
  setValue(event.target.value);
15
15
  flow.setValue(name, event.target.value);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowNodesGroup = void 0;
4
4
  const providers_1 = require("../providers");
5
5
  const FlowNodesGroup = ({ name, children }) => {
6
- const flow = providers_1.useFlow();
6
+ const flow = (0, providers_1.useFlow)();
7
7
  const nodes = flow.getNodesGroup(name);
8
8
  if (typeof children === 'function') {
9
9
  return children(nodes);
@@ -5,12 +5,12 @@ const react_1 = require("react");
5
5
  const react_2 = require("react");
6
6
  const providers_1 = require("../providers");
7
7
  const FlowSubmit = ({ method, children }) => {
8
- const flow = providers_1.useFlow();
8
+ const flow = (0, providers_1.useFlow)();
9
9
  if (typeof children === 'function') {
10
10
  return children((mtd) => flow.submit(mtd));
11
11
  }
12
- if (react_1.isValidElement(children)) {
13
- return react_2.cloneElement(children, {
12
+ if ((0, react_1.isValidElement)(children)) {
13
+ return (0, react_2.cloneElement)(children, {
14
14
  onClick: () => {
15
15
  flow.submit(method);
16
16
  },
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@atls/react-kratos-browser-flows",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "BSD-3-Clause",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
9
9
  "scripts": {
10
- "build": "yarn app library build",
11
- "postpack": "rm -rf dist",
12
- "prepack": "yarn run build"
10
+ "build": "yarn library build",
11
+ "prepack": "yarn run build",
12
+ "postpack": "rm -rf dist"
13
13
  },
14
14
  "devDependencies": {
15
- "@testing-library/jest-dom": "^5.14.1",
16
- "@testing-library/react": "^12.1.0",
15
+ "@testing-library/jest-dom": "^5.16.2",
16
+ "@testing-library/react": "^12.1.3",
17
17
  "@types/events": "^3.0.0",
18
- "@types/react": "^17.0.20",
19
- "@types/react-dom": "^17.0.9",
18
+ "@types/react": "^17.0.39",
19
+ "@types/react-dom": "^17.0.11",
20
20
  "@types/testing-library__jest-dom": "^5.14.1",
21
21
  "axios": "^0.21.4",
22
22
  "react": "^17.0.2",
@@ -31,7 +31,7 @@
31
31
  "typings": "dist/index.d.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@ory/kratos-client": "^0.7.6-alpha.1",
34
+ "@ory/kratos-client": "^0.8.2-alpha.1",
35
35
  "events": "^3.3.0"
36
36
  },
37
37
  "typings": "dist/index.d.ts"
@@ -1,27 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { KratosClient } from './kratos.client';
4
- import type { SubmitSelfServiceFlowBody } from './flow.interfaces';
5
- import type { SelfServiceFlow } from './flow.interfaces';
6
- import type { Flow } from './flow.interfaces';
7
- export declare abstract class AbstractFlow<State extends SelfServiceFlow, Body extends SubmitSelfServiceFlowBody> extends EventEmitter implements Flow {
8
- #private;
9
- protected readonly client: KratosClient;
10
- constructor(client: KratosClient);
11
- setLoading(loading: any): void;
12
- isLoading(): boolean;
13
- setState(state: any): void;
14
- hasState(): boolean;
15
- getState(): State;
16
- getMessages(): import("@ory/kratos-client").UiText[];
17
- getNode(name: any): import("@ory/kratos-client").UiNode | undefined;
18
- getNodes(name: any): import("@ory/kratos-client").UiNode[];
19
- getNodesGroup(group: any): import("@ory/kratos-client").UiNode[];
20
- getValue(name: any): string | any;
21
- getValues(): Body;
22
- setValue(name: string, value: string): void;
23
- protected setValues(state: State): void;
24
- protected complete(href?: string): void;
25
- abstract load(): any;
26
- abstract submit(method?: string): any;
27
- }
@@ -1,5 +0,0 @@
1
- import { AbstractFlow } from './abstract.flow';
2
- export declare class ErrorsFlow extends AbstractFlow<any, any> {
3
- load(): Promise<void>;
4
- submit(): Promise<void>;
5
- }
@@ -1,33 +0,0 @@
1
- /// <reference types="node" />
2
- import type { SelfServiceRegistrationFlow } from '@ory/kratos-client';
3
- import type { SelfServiceVerificationFlow } from '@ory/kratos-client';
4
- import type { SelfServiceRecoveryFlow } from '@ory/kratos-client';
5
- import type { SelfServiceSettingsFlow } from '@ory/kratos-client';
6
- import type { SelfServiceLoginFlow } from '@ory/kratos-client';
7
- import type { SubmitSelfServiceRegistrationFlowBody } from '@ory/kratos-client';
8
- import type { SubmitSelfServiceVerificationFlowBody } from '@ory/kratos-client';
9
- import type { SubmitSelfServiceRecoveryFlowBody } from '@ory/kratos-client';
10
- import type { SubmitSelfServiceSettingsFlowBody } from '@ory/kratos-client';
11
- import type { SubmitSelfServiceLoginFlowBody } from '@ory/kratos-client';
12
- import type { UiText } from '@ory/kratos-client';
13
- import type { UiNode } from '@ory/kratos-client';
14
- import { EventEmitter } from 'events';
15
- export declare type FlowName = 'login' | 'registration' | 'recovery' | 'settings' | 'verification' | 'errors';
16
- export declare type SelfServiceFlow = SelfServiceRegistrationFlow | SelfServiceVerificationFlow | SelfServiceRecoveryFlow | SelfServiceSettingsFlow | SelfServiceLoginFlow;
17
- export declare type SubmitSelfServiceFlowBody = SubmitSelfServiceRegistrationFlowBody | SubmitSelfServiceVerificationFlowBody | SubmitSelfServiceRecoveryFlowBody | SubmitSelfServiceSettingsFlowBody | SubmitSelfServiceLoginFlowBody;
18
- export interface Flow extends EventEmitter {
19
- setLoading(loading: boolean): any;
20
- isLoading(): any;
21
- setState(state: SelfServiceFlow): any;
22
- hasState(): any;
23
- getState(): SelfServiceFlow;
24
- getMessages(): Array<UiText>;
25
- getNode(name: string): UiNode | undefined;
26
- getNodes(name: string): Array<UiNode>;
27
- getNodesGroup(group: string): Array<UiNode>;
28
- getValue(name: any): string | any;
29
- setValue(name: string, value: string): any;
30
- getValues(): SubmitSelfServiceFlowBody;
31
- load(): Promise<void>;
32
- submit(method?: string): Promise<void>;
33
- }
@@ -1,7 +0,0 @@
1
- export * from './flow.interfaces';
2
- export * from './registration.flow';
3
- export * from './verification.flow';
4
- export * from './recovery.flow';
5
- export * from './settings.flow';
6
- export * from './errors.flow';
7
- export * from './login.flow';
@@ -1,4 +0,0 @@
1
- import { V0alpha1Api } from '@ory/kratos-client';
2
- export declare class KratosClient extends V0alpha1Api {
3
- constructor(basePath?: string);
4
- }
@@ -1,7 +0,0 @@
1
- import type { SelfServiceLoginFlow } from '@ory/kratos-client';
2
- import type { SubmitSelfServiceLoginFlowBody } from '@ory/kratos-client';
3
- import { AbstractFlow } from './abstract.flow';
4
- export declare class LoginFlow extends AbstractFlow<SelfServiceLoginFlow, SubmitSelfServiceLoginFlowBody> {
5
- load(): Promise<void>;
6
- submit(method?: string): Promise<void>;
7
- }
@@ -1,7 +0,0 @@
1
- import type { SelfServiceRecoveryFlow } from '@ory/kratos-client';
2
- import type { SubmitSelfServiceRecoveryFlowBody } from '@ory/kratos-client';
3
- import { AbstractFlow } from './abstract.flow';
4
- export declare class RecoveryFlow extends AbstractFlow<SelfServiceRecoveryFlow, SubmitSelfServiceRecoveryFlowBody> {
5
- load(): Promise<void>;
6
- submit(method?: string): Promise<void>;
7
- }
@@ -1,7 +0,0 @@
1
- import type { SelfServiceRegistrationFlow } from '@ory/kratos-client';
2
- import type { SubmitSelfServiceRegistrationFlowBody } from '@ory/kratos-client';
3
- import { AbstractFlow } from './abstract.flow';
4
- export declare class RegistrationFlow extends AbstractFlow<SelfServiceRegistrationFlow, SubmitSelfServiceRegistrationFlowBody> {
5
- load(): Promise<void>;
6
- submit(method?: string): Promise<void>;
7
- }
@@ -1,7 +0,0 @@
1
- import type { SelfServiceSettingsFlow } from '@ory/kratos-client';
2
- import type { SubmitSelfServiceSettingsFlowBody } from '@ory/kratos-client';
3
- import { AbstractFlow } from './abstract.flow';
4
- export declare class SettingsFlow extends AbstractFlow<SelfServiceSettingsFlow, SubmitSelfServiceSettingsFlowBody> {
5
- load(): Promise<void>;
6
- submit(method?: string): Promise<void>;
7
- }
@@ -1,7 +0,0 @@
1
- import type { SelfServiceVerificationFlow } from '@ory/kratos-client';
2
- import type { SubmitSelfServiceVerificationFlowBody } from '@ory/kratos-client';
3
- import { AbstractFlow } from './abstract.flow';
4
- export declare class VerificationFlow extends AbstractFlow<SelfServiceVerificationFlow, SubmitSelfServiceVerificationFlowBody> {
5
- load(): Promise<void>;
6
- submit(method?: string): Promise<void>;
7
- }
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './providers';
2
- export * from './flows';
3
- export * from './ui';
@@ -1,3 +0,0 @@
1
- import { Flow } from '../flows/flow.interfaces';
2
- export declare const Context: import("react").Context<Flow | null>;
3
- export declare const Provider: import("react").Provider<Flow | null>, Consumer: import("react").Consumer<Flow | null>;
@@ -1,8 +0,0 @@
1
- export * from './kratos-registration-flow.provider';
2
- export * from './kratos-verification-flow.provider';
3
- export * from './kratos-recovery-flow.provider';
4
- export * from './kratos-settings-flow.provider';
5
- export * from './kratos-errors-flow.provider';
6
- export * from './kratos-login-flow.provider';
7
- export * from './kratos-flow.provider';
8
- export * from './use-flow.hook';
@@ -1 +0,0 @@
1
- export declare const KratosErrorsFlowProvider: (props: any) => JSX.Element;
@@ -1,7 +0,0 @@
1
- import { FC } from 'react';
2
- import { FlowName } from '../flows/flow.interfaces';
3
- export interface KratosFlowProviderProps {
4
- basePath?: string;
5
- name: FlowName;
6
- }
7
- export declare const KratosFlowProvider: FC<KratosFlowProviderProps>;
@@ -1 +0,0 @@
1
- export declare const KratosLoginFlowProvider: (props: any) => JSX.Element;
@@ -1 +0,0 @@
1
- export declare const KratosRecoveryFlowProvider: (props: any) => JSX.Element;
@@ -1 +0,0 @@
1
- export declare const KratosRegistrationFlowProvider: (props: any) => JSX.Element;
@@ -1 +0,0 @@
1
- export declare const KratosSettingsFlowProvider: (props: any) => JSX.Element;
@@ -1 +0,0 @@
1
- export declare const KratosVerificationFlowProvider: (props: any) => JSX.Element;
@@ -1,2 +0,0 @@
1
- import { Flow } from '../flows/flow.interfaces';
2
- export declare const useFlow: () => Flow;
@@ -1,13 +0,0 @@
1
- import { ReactElement } from 'react';
2
- import { FC } from 'react';
3
- interface SelfServiceErrorProps {
4
- code?: number;
5
- status?: string;
6
- reason?: string;
7
- message?: string;
8
- }
9
- export interface FlowErrorProps {
10
- children: (error: SelfServiceErrorProps) => ReactElement<any>;
11
- }
12
- export declare const FlowError: FC<FlowErrorProps>;
13
- export {};
@@ -1,4 +0,0 @@
1
- export declare const FlowForm: ({ children, ...props }: {
2
- [x: string]: any;
3
- children: any;
4
- }) => JSX.Element | null;
@@ -1,7 +0,0 @@
1
- import { UiText } from '@ory/kratos-client';
2
- import { ReactElement } from 'react';
3
- import { FC } from 'react';
4
- export interface FlowMessagesProps {
5
- children: (messages: Array<UiText>) => ReactElement<any>;
6
- }
7
- export declare const FlowMessages: FC<FlowMessagesProps>;
@@ -1,8 +0,0 @@
1
- import { UiText } from '@ory/kratos-client';
2
- import { ReactElement } from 'react';
3
- import { FC } from 'react';
4
- export interface FlowNodeMessagesProps {
5
- name: string;
6
- children: (messages: Array<UiText>) => ReactElement<any>;
7
- }
8
- export declare const FlowNodeMessages: FC<FlowNodeMessagesProps>;
@@ -1,23 +0,0 @@
1
- import { UiNode } from '@ory/kratos-client';
2
- import { ReactElement } from 'react';
3
- import { FC } from 'react';
4
- import { FormEvent } from 'react';
5
- interface FlowUiNodeAttributes {
6
- disabled: boolean;
7
- name: string;
8
- pattern?: string;
9
- required?: boolean;
10
- type: string;
11
- value?: any | null;
12
- src: string;
13
- }
14
- interface FlowUiNode extends Omit<UiNode, 'attributes'> {
15
- attributes: FlowUiNodeAttributes;
16
- }
17
- declare type OnChangeCallback = (event: FormEvent<HTMLInputElement> | string | any) => void;
18
- export interface FlowNodeProps {
19
- name: string;
20
- children: (node: FlowUiNode, value: string | any, callback: OnChangeCallback) => ReactElement<any>;
21
- }
22
- export declare const FlowNode: FC<FlowNodeProps>;
23
- export {};
@@ -1,21 +0,0 @@
1
- import { UiNode } from '@ory/kratos-client';
2
- import { ReactElement } from 'react';
3
- import { FC } from 'react';
4
- interface FlowUiNodeAttributes {
5
- disabled: boolean;
6
- name: string;
7
- pattern?: string;
8
- required?: boolean;
9
- type: string;
10
- value?: any | null;
11
- src: string;
12
- }
13
- interface FlowUiNode extends Omit<UiNode, 'attributes'> {
14
- attributes: FlowUiNodeAttributes;
15
- }
16
- export interface FlowNodesGroupProps {
17
- name: string;
18
- children: (node: Array<FlowUiNode>) => ReactElement<any>;
19
- }
20
- export declare const FlowNodesGroup: FC<FlowNodesGroupProps>;
21
- export {};
@@ -1,4 +0,0 @@
1
- export declare const FlowSubmit: ({ method, children }: {
2
- method: any;
3
- children: any;
4
- }) => any;
@@ -1,7 +0,0 @@
1
- export * from './flow-form.component';
2
- export * from './flow-node.component';
3
- export * from './flow-error.component';
4
- export * from './flow-submit.component';
5
- export * from './flow-messages.component';
6
- export * from './flow-nodes-group.component';
7
- export * from './flow-node-messages.component';