@atls/react-kratos-browser-flows 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/flows/abstract.flow.d.ts +27 -0
  2. package/dist/flows/abstract.flow.js +82 -0
  3. package/dist/flows/errors.flow.d.ts +5 -0
  4. package/dist/flows/errors.flow.js +34 -0
  5. package/dist/flows/flow.interfaces.d.ts +33 -0
  6. package/dist/flows/flow.interfaces.js +2 -0
  7. package/dist/flows/index.d.ts +7 -0
  8. package/dist/flows/index.js +19 -0
  9. package/dist/flows/kratos.client.d.ts +4 -0
  10. package/dist/flows/kratos.client.js +24 -0
  11. package/dist/flows/login.flow.d.ts +7 -0
  12. package/dist/flows/login.flow.js +63 -0
  13. package/dist/flows/recovery.flow.d.ts +7 -0
  14. package/dist/flows/recovery.flow.js +70 -0
  15. package/dist/flows/registration.flow.d.ts +7 -0
  16. package/dist/flows/registration.flow.js +68 -0
  17. package/dist/flows/settings.flow.d.ts +7 -0
  18. package/dist/flows/settings.flow.js +68 -0
  19. package/dist/flows/verification.flow.d.ts +7 -0
  20. package/dist/flows/verification.flow.js +68 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +15 -0
  23. package/dist/providers/flows.context.d.ts +3 -0
  24. package/dist/providers/flows.context.js +6 -0
  25. package/dist/providers/index.d.ts +8 -0
  26. package/dist/providers/index.js +20 -0
  27. package/dist/providers/kratos-errors-flow.provider.d.ts +1 -0
  28. package/dist/providers/kratos-errors-flow.provider.js +10 -0
  29. package/dist/providers/kratos-flow.provider.d.ts +7 -0
  30. package/dist/providers/kratos-flow.provider.js +42 -0
  31. package/dist/providers/kratos-login-flow.provider.d.ts +1 -0
  32. package/dist/providers/kratos-login-flow.provider.js +10 -0
  33. package/dist/providers/kratos-recovery-flow.provider.d.ts +1 -0
  34. package/dist/providers/kratos-recovery-flow.provider.js +10 -0
  35. package/dist/providers/kratos-registration-flow.provider.d.ts +1 -0
  36. package/dist/providers/kratos-registration-flow.provider.js +10 -0
  37. package/dist/providers/kratos-settings-flow.provider.d.ts +1 -0
  38. package/dist/providers/kratos-settings-flow.provider.js +10 -0
  39. package/dist/providers/kratos-verification-flow.provider.d.ts +1 -0
  40. package/dist/providers/kratos-verification-flow.provider.js +10 -0
  41. package/dist/providers/use-flow.hook.d.ts +2 -0
  42. package/dist/providers/use-flow.hook.js +26 -0
  43. package/dist/ui/flow-error.component.d.ts +13 -0
  44. package/dist/ui/flow-error.component.js +13 -0
  45. package/dist/ui/flow-form.component.d.ts +4 -0
  46. package/dist/ui/flow-form.component.js +30 -0
  47. package/dist/ui/flow-messages.component.d.ts +7 -0
  48. package/dist/ui/flow-messages.component.js +13 -0
  49. package/dist/ui/flow-node-messages.component.d.ts +8 -0
  50. package/dist/ui/flow-node-messages.component.js +13 -0
  51. package/dist/ui/flow-node.component.d.ts +23 -0
  52. package/dist/ui/flow-node.component.js +27 -0
  53. package/dist/ui/flow-nodes-group.component.d.ts +21 -0
  54. package/dist/ui/flow-nodes-group.component.js +13 -0
  55. package/dist/ui/flow-submit.component.d.ts +4 -0
  56. package/dist/ui/flow-submit.component.js +21 -0
  57. package/dist/ui/index.d.ts +7 -0
  58. package/dist/ui/index.js +19 -0
  59. package/package.json +38 -0
@@ -0,0 +1,27 @@
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
+ }
@@ -0,0 +1,82 @@
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;
8
+ };
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);
14
+ };
15
+ var _values, _state, _loading;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.AbstractFlow = void 0;
18
+ const events_1 = require("events");
19
+ class AbstractFlow extends events_1.EventEmitter {
20
+ constructor(client) {
21
+ super();
22
+ this.client = client;
23
+ _values.set(this, {});
24
+ _state.set(this, void 0);
25
+ _loading.set(this, false);
26
+ this.setMaxListeners(50);
27
+ }
28
+ setLoading(loading) {
29
+ __classPrivateFieldSet(this, _loading, loading);
30
+ }
31
+ isLoading() {
32
+ return __classPrivateFieldGet(this, _loading);
33
+ }
34
+ setState(state) {
35
+ __classPrivateFieldSet(this, _state, state);
36
+ }
37
+ hasState() {
38
+ return Boolean(__classPrivateFieldGet(this, _state));
39
+ }
40
+ getState() {
41
+ return __classPrivateFieldGet(this, _state);
42
+ }
43
+ 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) || [];
46
+ }
47
+ 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);
50
+ }
51
+ 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)) || []);
54
+ }
55
+ 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)) || [];
58
+ }
59
+ getValue(name) {
60
+ return __classPrivateFieldGet(this, _values)[name];
61
+ }
62
+ getValues() {
63
+ return __classPrivateFieldGet(this, _values);
64
+ }
65
+ setValue(name, value) {
66
+ __classPrivateFieldGet(this, _values)[name] = value;
67
+ }
68
+ 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] =
73
+ attributes.value || '';
74
+ }
75
+ });
76
+ }
77
+ complete(href = '/') {
78
+ window.location.href = href;
79
+ }
80
+ }
81
+ exports.AbstractFlow = AbstractFlow;
82
+ _values = new WeakMap(), _state = new WeakMap(), _loading = new WeakMap();
@@ -0,0 +1,5 @@
1
+ import { AbstractFlow } from './abstract.flow';
2
+ export declare class ErrorsFlow extends AbstractFlow<any, any> {
3
+ load(): Promise<void>;
4
+ submit(): Promise<void>;
5
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorsFlow = void 0;
4
+ const abstract_flow_1 = require("./abstract.flow");
5
+ class ErrorsFlow 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
+ try {
15
+ const flowId = new URL(window.location.href).searchParams.get('flow');
16
+ if (!flowId) {
17
+ this.complete();
18
+ }
19
+ else {
20
+ const { data } = await this.client.getSelfServiceError(flowId, { withCredentials: true });
21
+ this.setLoading(false);
22
+ this.setState(data);
23
+ this.setValues(data);
24
+ this.emit('load', data);
25
+ }
26
+ }
27
+ catch (error) {
28
+ this.setLoading(false);
29
+ this.complete();
30
+ }
31
+ }
32
+ async submit() { }
33
+ }
34
+ exports.ErrorsFlow = ErrorsFlow;
@@ -0,0 +1,33 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
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';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./flow.interfaces"), exports);
14
+ __exportStar(require("./registration.flow"), exports);
15
+ __exportStar(require("./verification.flow"), exports);
16
+ __exportStar(require("./recovery.flow"), exports);
17
+ __exportStar(require("./settings.flow"), exports);
18
+ __exportStar(require("./errors.flow"), exports);
19
+ __exportStar(require("./login.flow"), exports);
@@ -0,0 +1,4 @@
1
+ import { V0alpha1Api } from '@ory/kratos-client';
2
+ export declare class KratosClient extends V0alpha1Api {
3
+ constructor(basePath?: string);
4
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KratosClient = void 0;
4
+ const kratos_client_1 = require("@ory/kratos-client");
5
+ const kratos_client_2 = require("@ory/kratos-client");
6
+ class KratosClient extends kratos_client_2.V0alpha1Api {
7
+ constructor(basePath) {
8
+ if (!basePath && typeof window !== 'undefined') {
9
+ if (window.location.hostname === 'localhost') {
10
+ basePath = 'http://localhost:4433';
11
+ }
12
+ else if (window.location.hostname === '127.0.0.1') {
13
+ basePath = 'http://127.0.0.1:4433';
14
+ }
15
+ else if (window.location.hostname.startsWith('accounts.')) {
16
+ basePath = window.location.origin.replace('accounts.', 'identity.');
17
+ }
18
+ }
19
+ super(new kratos_client_1.Configuration({
20
+ basePath,
21
+ }));
22
+ }
23
+ }
24
+ exports.KratosClient = KratosClient;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoginFlow = void 0;
4
+ const abstract_flow_1 = require("./abstract.flow");
5
+ class LoginFlow 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
+ try {
15
+ const flowId = new URL(window.location.href).searchParams.get('flow');
16
+ const { data } = flowId
17
+ ? await this.client.getSelfServiceLoginFlow(flowId, undefined, { withCredentials: true })
18
+ : await this.client.initializeSelfServiceLoginFlowForBrowsers(false, {
19
+ withCredentials: true,
20
+ });
21
+ this.setLoading(false);
22
+ this.setState(data);
23
+ this.setValues(data);
24
+ this.emit('load', data);
25
+ }
26
+ catch (error) {
27
+ this.setLoading(false);
28
+ const { status } = error
29
+ .response;
30
+ if (status === 400) {
31
+ this.complete();
32
+ }
33
+ else if (status === 410) {
34
+ this.complete('/auth/login');
35
+ }
36
+ else {
37
+ throw error;
38
+ }
39
+ }
40
+ }
41
+ async submit(method) {
42
+ const body = this.getValues();
43
+ if (method) {
44
+ body.method = method;
45
+ }
46
+ try {
47
+ await this.client.submitSelfServiceLoginFlow(this.getState().id, body, {
48
+ withCredentials: true,
49
+ });
50
+ this.complete();
51
+ }
52
+ catch (error) {
53
+ const { data, status } = error
54
+ .response;
55
+ if (status === 400) {
56
+ this.setState(data);
57
+ this.setValues(data);
58
+ this.emit('load', data);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ exports.LoginFlow = LoginFlow;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecoveryFlow = void 0;
4
+ const abstract_flow_1 = require("./abstract.flow");
5
+ class RecoveryFlow 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
+ try {
15
+ const flowId = new URL(window.location.href).searchParams.get('flow');
16
+ const { data } = flowId
17
+ ? await this.client.getSelfServiceRecoveryFlow(flowId, undefined, {
18
+ withCredentials: true,
19
+ })
20
+ : await this.client.initializeSelfServiceRecoveryFlowForBrowsers({
21
+ withCredentials: true,
22
+ });
23
+ this.setLoading(false);
24
+ this.setState(data);
25
+ this.setValues(data);
26
+ this.emit('load', data);
27
+ }
28
+ catch (error) {
29
+ this.setLoading(false);
30
+ const { status } = error
31
+ .response;
32
+ if (status === 410) {
33
+ this.complete(window.location.pathname);
34
+ }
35
+ else if (status === 403) {
36
+ this.complete(window.location.pathname);
37
+ }
38
+ else if (status === 400) {
39
+ this.complete();
40
+ }
41
+ else {
42
+ throw error;
43
+ }
44
+ }
45
+ }
46
+ async submit(method) {
47
+ const body = this.getValues();
48
+ if (method) {
49
+ body.method = method;
50
+ }
51
+ try {
52
+ const { data } = await this.client.submitSelfServiceRecoveryFlow(this.getState().id, undefined, body, {
53
+ withCredentials: true,
54
+ });
55
+ this.setState(data);
56
+ this.setValues(data);
57
+ this.emit('load', data);
58
+ }
59
+ catch (error) {
60
+ const { data, status } = error
61
+ .response;
62
+ if (status === 400) {
63
+ this.setState(data);
64
+ this.setValues(data);
65
+ this.emit('load', data);
66
+ }
67
+ }
68
+ }
69
+ }
70
+ exports.RecoveryFlow = RecoveryFlow;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegistrationFlow = void 0;
4
+ const abstract_flow_1 = require("./abstract.flow");
5
+ class RegistrationFlow 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
+ try {
15
+ const flowId = new URL(window.location.href).searchParams.get('flow');
16
+ const { data } = flowId
17
+ ? await this.client.getSelfServiceRegistrationFlow(flowId, undefined, {
18
+ withCredentials: true,
19
+ })
20
+ : await this.client.initializeSelfServiceRegistrationFlowForBrowsers({
21
+ withCredentials: true,
22
+ });
23
+ this.setLoading(false);
24
+ this.setState(data);
25
+ this.setValues(data);
26
+ this.emit('load', data);
27
+ }
28
+ catch (error) {
29
+ this.setLoading(false);
30
+ const { status } = error
31
+ .response;
32
+ if (status === 410) {
33
+ this.complete(window.location.pathname);
34
+ }
35
+ else if (status === 403) {
36
+ this.complete(window.location.pathname);
37
+ }
38
+ else if (status === 400) {
39
+ this.complete();
40
+ }
41
+ else {
42
+ throw error;
43
+ }
44
+ }
45
+ }
46
+ async submit(method) {
47
+ const body = this.getValues();
48
+ if (method) {
49
+ body.method = method;
50
+ }
51
+ try {
52
+ await this.client.submitSelfServiceRegistrationFlow(this.getState().id, body, {
53
+ withCredentials: true,
54
+ });
55
+ this.complete();
56
+ }
57
+ catch (error) {
58
+ const { data, status } = error
59
+ .response;
60
+ if (status === 400) {
61
+ this.setState(data);
62
+ this.setValues(data);
63
+ this.emit('load', data);
64
+ }
65
+ }
66
+ }
67
+ }
68
+ exports.RegistrationFlow = RegistrationFlow;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SettingsFlow = void 0;
4
+ const abstract_flow_1 = require("./abstract.flow");
5
+ class SettingsFlow 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
+ try {
15
+ const flowId = new URL(window.location.href).searchParams.get('flow');
16
+ const { data } = flowId
17
+ ? await this.client.getSelfServiceSettingsFlow(flowId, undefined, undefined, {
18
+ withCredentials: true,
19
+ })
20
+ : await this.client.initializeSelfServiceSettingsFlowForBrowsers(undefined, {
21
+ withCredentials: true,
22
+ });
23
+ this.setLoading(false);
24
+ this.setState(data);
25
+ this.setValues(data);
26
+ this.emit('load', data);
27
+ }
28
+ catch (error) {
29
+ this.setLoading(false);
30
+ const { status } = error
31
+ .response;
32
+ if (status === 410) {
33
+ this.complete(window.location.pathname);
34
+ }
35
+ else if (status === 403) {
36
+ this.complete(window.location.pathname);
37
+ }
38
+ else {
39
+ throw error;
40
+ }
41
+ throw error;
42
+ }
43
+ }
44
+ async submit(method) {
45
+ const body = this.getValues();
46
+ if (method) {
47
+ body.method = method;
48
+ }
49
+ try {
50
+ const { data } = await this.client.submitSelfServiceSettingsFlow(this.getState().id, undefined, body, {
51
+ withCredentials: true,
52
+ });
53
+ this.setState(data.flow);
54
+ this.setValues(data.flow);
55
+ this.emit('load', data.flow);
56
+ }
57
+ catch (error) {
58
+ const { data, status } = error
59
+ .response;
60
+ if (status === 400) {
61
+ this.setState(data);
62
+ this.setValues(data);
63
+ this.emit('load', data);
64
+ }
65
+ }
66
+ }
67
+ }
68
+ exports.SettingsFlow = SettingsFlow;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VerificationFlow = void 0;
4
+ const abstract_flow_1 = require("./abstract.flow");
5
+ class VerificationFlow 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
+ try {
15
+ const flowId = new URL(window.location.href).searchParams.get('flow');
16
+ const { data } = flowId
17
+ ? await this.client.getSelfServiceVerificationFlow(flowId, undefined, {
18
+ withCredentials: true,
19
+ })
20
+ : await this.client.initializeSelfServiceVerificationFlowForBrowsers({
21
+ withCredentials: true,
22
+ });
23
+ this.setLoading(false);
24
+ this.setState(data);
25
+ this.setValues(data);
26
+ this.emit('load', data);
27
+ }
28
+ catch (error) {
29
+ this.setLoading(false);
30
+ const { status } = error
31
+ .response;
32
+ if (status === 410) {
33
+ this.complete(window.location.pathname);
34
+ }
35
+ else if (status === 403) {
36
+ this.complete(window.location.pathname);
37
+ }
38
+ else {
39
+ throw error;
40
+ }
41
+ throw error;
42
+ }
43
+ }
44
+ async submit(method) {
45
+ const body = this.getValues();
46
+ if (method) {
47
+ body.method = method;
48
+ }
49
+ try {
50
+ const { data } = await this.client.submitSelfServiceVerificationFlow(this.getState().id, undefined, body, {
51
+ withCredentials: true,
52
+ });
53
+ this.setState(data);
54
+ this.setValues(data);
55
+ this.emit('load', data);
56
+ }
57
+ catch (error) {
58
+ const { data, status } = error
59
+ .response;
60
+ if (status === 400) {
61
+ this.setState(data);
62
+ this.setValues(data);
63
+ this.emit('load', data);
64
+ }
65
+ }
66
+ }
67
+ }
68
+ exports.VerificationFlow = VerificationFlow;
@@ -0,0 +1,3 @@
1
+ export * from './providers';
2
+ export * from './flows';
3
+ export * from './ui';
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./providers"), exports);
14
+ __exportStar(require("./flows"), exports);
15
+ __exportStar(require("./ui"), exports);
@@ -0,0 +1,3 @@
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>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Consumer = exports.Provider = exports.Context = void 0;
4
+ const react_1 = require("react");
5
+ exports.Context = react_1.createContext(null);
6
+ exports.Provider = exports.Context.Provider, exports.Consumer = exports.Context.Consumer;
@@ -0,0 +1,8 @@
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';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./kratos-registration-flow.provider"), exports);
14
+ __exportStar(require("./kratos-verification-flow.provider"), exports);
15
+ __exportStar(require("./kratos-recovery-flow.provider"), exports);
16
+ __exportStar(require("./kratos-settings-flow.provider"), exports);
17
+ __exportStar(require("./kratos-errors-flow.provider"), exports);
18
+ __exportStar(require("./kratos-login-flow.provider"), exports);
19
+ __exportStar(require("./kratos-flow.provider"), exports);
20
+ __exportStar(require("./use-flow.hook"), exports);
@@ -0,0 +1 @@
1
+ export declare const KratosErrorsFlowProvider: (props: any) => JSX.Element;
@@ -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.KratosErrorsFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
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' }));
10
+ exports.KratosErrorsFlowProvider = KratosErrorsFlowProvider;
@@ -0,0 +1,7 @@
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>;
@@ -0,0 +1,42 @@
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.KratosFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
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
+ const errors_flow_1 = require("../flows/errors.flow");
14
+ const login_flow_1 = require("../flows/login.flow");
15
+ const kratos_client_1 = require("../flows/kratos.client");
16
+ const flows_context_1 = require("./flows.context");
17
+ const KratosFlowProvider = ({ name, basePath, children }) => {
18
+ const client = react_2.useMemo(() => new kratos_client_1.KratosClient(basePath), [basePath]);
19
+ const flow = react_2.useMemo(() => {
20
+ if (name === 'login') {
21
+ return new login_flow_1.LoginFlow(client);
22
+ }
23
+ if (name === 'registration') {
24
+ return new registration_flow_1.RegistrationFlow(client);
25
+ }
26
+ if (name === 'verification') {
27
+ return new verification_flow_1.VerificationFlow(client);
28
+ }
29
+ if (name === 'recovery') {
30
+ return new recovery_flow_1.RecoveryFlow(client);
31
+ }
32
+ if (name === 'settings') {
33
+ return new settings_flow_1.SettingsFlow(client);
34
+ }
35
+ if (name === 'errors') {
36
+ return new errors_flow_1.ErrorsFlow(client);
37
+ }
38
+ throw new Error(`Unkown flow: ${name}`);
39
+ }, [name, client]);
40
+ return react_1.default.createElement(flows_context_1.Provider, { value: flow }, children);
41
+ };
42
+ exports.KratosFlowProvider = KratosFlowProvider;
@@ -0,0 +1 @@
1
+ export declare const KratosLoginFlowProvider: (props: any) => JSX.Element;
@@ -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.KratosLoginFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
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' }));
10
+ exports.KratosLoginFlowProvider = KratosLoginFlowProvider;
@@ -0,0 +1 @@
1
+ export declare const KratosRecoveryFlowProvider: (props: any) => JSX.Element;
@@ -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.KratosRecoveryFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
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' })));
10
+ exports.KratosRecoveryFlowProvider = KratosRecoveryFlowProvider;
@@ -0,0 +1 @@
1
+ export declare const KratosRegistrationFlowProvider: (props: any) => JSX.Element;
@@ -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.KratosRegistrationFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
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' })));
10
+ exports.KratosRegistrationFlowProvider = KratosRegistrationFlowProvider;
@@ -0,0 +1 @@
1
+ export declare const KratosSettingsFlowProvider: (props: any) => JSX.Element;
@@ -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.KratosSettingsFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
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' })));
10
+ exports.KratosSettingsFlowProvider = KratosSettingsFlowProvider;
@@ -0,0 +1 @@
1
+ export declare const KratosVerificationFlowProvider: (props: any) => JSX.Element;
@@ -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.KratosVerificationFlowProvider = void 0;
7
+ const react_1 = __importDefault(require("react"));
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' })));
10
+ exports.KratosVerificationFlowProvider = KratosVerificationFlowProvider;
@@ -0,0 +1,2 @@
1
+ import { Flow } from '../flows/flow.interfaces';
2
+ export declare const useFlow: () => Flow;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFlow = void 0;
4
+ const react_1 = require("react");
5
+ const react_2 = require("react");
6
+ const react_3 = require("react");
7
+ const flows_context_1 = require("./flows.context");
8
+ const useFlow = () => {
9
+ const flow = react_1.useContext(flows_context_1.Context);
10
+ if (!flow) {
11
+ throw new Error('Missing <KratosFlowProvider>');
12
+ }
13
+ const [, setState] = react_3.useState(null);
14
+ react_2.useEffect(() => {
15
+ flow.load();
16
+ const callback = (flowState) => {
17
+ setState(flowState);
18
+ };
19
+ flow.on('load', callback);
20
+ return () => {
21
+ flow.off('load', callback);
22
+ };
23
+ }, [flow]);
24
+ return flow;
25
+ };
26
+ exports.useFlow = useFlow;
@@ -0,0 +1,13 @@
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 {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowError = void 0;
4
+ const providers_1 = require("../providers");
5
+ const FlowError = ({ children }) => {
6
+ const flow = providers_1.useFlow();
7
+ const state = flow.getState();
8
+ if (typeof children === 'function' && (state === null || state === void 0 ? void 0 : state.error)) {
9
+ return children(state.error);
10
+ }
11
+ return null;
12
+ };
13
+ exports.FlowError = FlowError;
@@ -0,0 +1,4 @@
1
+ export declare const FlowForm: ({ children, ...props }: {
2
+ [x: string]: any;
3
+ children: any;
4
+ }) => JSX.Element | null;
@@ -0,0 +1,30 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FlowForm = void 0;
18
+ const react_1 = __importDefault(require("react"));
19
+ const react_2 = require("react");
20
+ 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()]);
25
+ if (!ui) {
26
+ return null;
27
+ }
28
+ return (react_1.default.createElement("form", Object.assign({}, props, { action: ui.action, method: ui.method }), children));
29
+ };
30
+ exports.FlowForm = FlowForm;
@@ -0,0 +1,7 @@
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>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowMessages = void 0;
4
+ const providers_1 = require("../providers");
5
+ const FlowMessages = ({ children }) => {
6
+ const flow = providers_1.useFlow();
7
+ const messages = flow.getMessages();
8
+ if (typeof children === 'function' && messages) {
9
+ return children(messages);
10
+ }
11
+ return null;
12
+ };
13
+ exports.FlowMessages = FlowMessages;
@@ -0,0 +1,8 @@
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>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowNodeMessages = void 0;
4
+ const providers_1 = require("../providers");
5
+ const FlowNodeMessages = ({ name, children }) => {
6
+ const flow = providers_1.useFlow();
7
+ const node = flow.getNode(name);
8
+ if (typeof children === 'function' && (node === null || node === void 0 ? void 0 : node.messages)) {
9
+ return children(node.messages);
10
+ }
11
+ return null;
12
+ };
13
+ exports.FlowNodeMessages = FlowNodeMessages;
@@ -0,0 +1,23 @@
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 {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowNode = void 0;
4
+ const react_1 = require("react");
5
+ const react_2 = require("react");
6
+ const react_3 = require("react");
7
+ const providers_1 = require("../providers");
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) => {
13
+ if (event && event.target) {
14
+ setValue(event.target.value);
15
+ flow.setValue(name, event.target.value);
16
+ }
17
+ else {
18
+ setValue(event);
19
+ flow.setValue(name, event);
20
+ }
21
+ }, [name, flow, setValue]);
22
+ if (node && typeof children === 'function') {
23
+ return children(node, value, onChange);
24
+ }
25
+ return null;
26
+ };
27
+ exports.FlowNode = FlowNode;
@@ -0,0 +1,21 @@
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 {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowNodesGroup = void 0;
4
+ const providers_1 = require("../providers");
5
+ const FlowNodesGroup = ({ name, children }) => {
6
+ const flow = providers_1.useFlow();
7
+ const nodes = flow.getNodesGroup(name);
8
+ if (typeof children === 'function') {
9
+ return children(nodes);
10
+ }
11
+ return null;
12
+ };
13
+ exports.FlowNodesGroup = FlowNodesGroup;
@@ -0,0 +1,4 @@
1
+ export declare const FlowSubmit: ({ method, children }: {
2
+ method: any;
3
+ children: any;
4
+ }) => any;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowSubmit = void 0;
4
+ const react_1 = require("react");
5
+ const react_2 = require("react");
6
+ const providers_1 = require("../providers");
7
+ const FlowSubmit = ({ method, children }) => {
8
+ const flow = providers_1.useFlow();
9
+ if (typeof children === 'function') {
10
+ return children((mtd) => flow.submit(mtd));
11
+ }
12
+ if (react_1.isValidElement(children)) {
13
+ return react_2.cloneElement(children, {
14
+ onClick: () => {
15
+ flow.submit(method);
16
+ },
17
+ });
18
+ }
19
+ return null;
20
+ };
21
+ exports.FlowSubmit = FlowSubmit;
@@ -0,0 +1,7 @@
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';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./flow-form.component"), exports);
14
+ __exportStar(require("./flow-node.component"), exports);
15
+ __exportStar(require("./flow-error.component"), exports);
16
+ __exportStar(require("./flow-submit.component"), exports);
17
+ __exportStar(require("./flow-messages.component"), exports);
18
+ __exportStar(require("./flow-nodes-group.component"), exports);
19
+ __exportStar(require("./flow-node-messages.component"), exports);
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@atls/react-kratos-browser-flows",
3
+ "version": "0.0.1",
4
+ "license": "BSD-3-Clause",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "build": "yarn app library build",
11
+ "postpack": "rm -rf dist",
12
+ "prepack": "yarn run build"
13
+ },
14
+ "devDependencies": {
15
+ "@testing-library/jest-dom": "^5.14.1",
16
+ "@testing-library/react": "^12.1.0",
17
+ "@types/events": "^3.0.0",
18
+ "@types/react": "^17.0.20",
19
+ "@types/react-dom": "^17.0.9",
20
+ "@types/testing-library__jest-dom": "^5.14.1",
21
+ "axios": "^0.21.4",
22
+ "react": "^17.0.2",
23
+ "react-dom": "^17.0.2"
24
+ },
25
+ "peerDependencies": {
26
+ "react": "^17.0.1"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "main": "dist/index.js",
31
+ "typings": "dist/index.d.ts"
32
+ },
33
+ "dependencies": {
34
+ "@ory/kratos-client": "^0.7.6-alpha.1",
35
+ "events": "^3.3.0"
36
+ },
37
+ "typings": "dist/index.d.ts"
38
+ }