@owlmeans/flow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +514 -0
- package/build/.gitkeep +0 -0
- package/build/consts.d.ts +10 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +10 -0
- package/build/consts.js.map +1 -0
- package/build/errors.d.ts +34 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +65 -0
- package/build/errors.js.map +1 -0
- package/build/flows/auth.d.ts +19 -0
- package/build/flows/auth.d.ts.map +1 -0
- package/build/flows/auth.js +146 -0
- package/build/flows/auth.js.map +1 -0
- package/build/flows/index.d.ts +5 -0
- package/build/flows/index.d.ts.map +1 -0
- package/build/flows/index.js +5 -0
- package/build/flows/index.js.map +1 -0
- package/build/flows/oidc.d.ts +14 -0
- package/build/flows/oidc.d.ts.map +1 -0
- package/build/flows/oidc.js +136 -0
- package/build/flows/oidc.js.map +1 -0
- package/build/flows/oidp.d.ts +13 -0
- package/build/flows/oidp.d.ts.map +1 -0
- package/build/flows/oidp.js +189 -0
- package/build/flows/oidp.js.map +1 -0
- package/build/flows/stab.d.ts +3 -0
- package/build/flows/stab.d.ts.map +1 -0
- package/build/flows/stab.js +16 -0
- package/build/flows/stab.js.map +1 -0
- package/build/helper.d.ts +5 -0
- package/build/helper.d.ts.map +1 -0
- package/build/helper.js +14 -0
- package/build/helper.js.map +1 -0
- package/build/i18n/en.json +8 -0
- package/build/i18n.d.ts +2 -0
- package/build/i18n.d.ts.map +1 -0
- package/build/i18n.js +4 -0
- package/build/i18n.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -0
- package/build/state.d.ts +3 -0
- package/build/state.d.ts.map +1 -0
- package/build/state.js +118 -0
- package/build/state.js.map +1 -0
- package/build/types.d.ts +100 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/build/utils/flow.d.ts +4 -0
- package/build/utils/flow.d.ts.map +1 -0
- package/build/utils/flow.js +65 -0
- package/build/utils/flow.js.map +1 -0
- package/build/utils/index.d.ts +2 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +2 -0
- package/build/utils/index.js.map +1 -0
- package/package.json +39 -0
- package/src/consts.ts +18 -0
- package/src/errors.ts +82 -0
- package/src/flows/auth.ts +157 -0
- package/src/flows/index.ts +5 -0
- package/src/flows/oidc.ts +148 -0
- package/src/flows/oidp.ts +205 -0
- package/src/flows/stab.ts +17 -0
- package/src/helper.ts +19 -0
- package/src/i18n/en.json +8 -0
- package/src/i18n.ts +5 -0
- package/src/index.ts +8 -0
- package/src/state.ts +138 -0
- package/src/types.ts +103 -0
- package/src/utils/flow.ts +74 -0
- package/src/utils/index.ts +2 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA"}
|
package/build/state.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAa,WAAW,EAAE,MAAM,YAAY,CAAA;AAGjF,eAAO,MAAM,aAAa,SAAgB,MAAM,GAAG,WAAW,aAAa,YAAY,KAAG,OAAO,CAAC,SAAS,CAqI1G,CAAA"}
|
package/build/state.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { FlowStepError, UnknownFlow, UnknownFlowStep, UnknownTransition } from './errors.js';
|
|
2
|
+
import { serializeState, unserializeState } from './utils/flow.js';
|
|
3
|
+
export const makeFlowModel = async (flow, provider) => {
|
|
4
|
+
let state = null;
|
|
5
|
+
if (typeof flow === 'string') {
|
|
6
|
+
if (provider == null) {
|
|
7
|
+
throw new UnknownFlow('_provider');
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
flow = await provider(flow);
|
|
11
|
+
state = {
|
|
12
|
+
flow: flow.flow,
|
|
13
|
+
step: flow.initialStep,
|
|
14
|
+
service: '',
|
|
15
|
+
ok: true
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
state = await unserializeState(flow, provider);
|
|
20
|
+
flow = await provider(state.flow);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
state = {
|
|
25
|
+
flow: flow.flow,
|
|
26
|
+
step: flow.initialStep,
|
|
27
|
+
service: '',
|
|
28
|
+
ok: true
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const model = {
|
|
32
|
+
target: service => {
|
|
33
|
+
state.service = service;
|
|
34
|
+
return model;
|
|
35
|
+
},
|
|
36
|
+
entity: entityId => {
|
|
37
|
+
state.entityId = entityId;
|
|
38
|
+
return model;
|
|
39
|
+
},
|
|
40
|
+
state: () => state,
|
|
41
|
+
setState: _state => {
|
|
42
|
+
state = _state;
|
|
43
|
+
return model;
|
|
44
|
+
},
|
|
45
|
+
payload: () => state.payload ?? {},
|
|
46
|
+
step: step => flow.steps[step ?? state.step],
|
|
47
|
+
enter: step => {
|
|
48
|
+
step = step ?? flow.initialStep;
|
|
49
|
+
const info = flow.steps[step];
|
|
50
|
+
if (info.initial !== true) {
|
|
51
|
+
throw new FlowStepError(`initial:${step}`);
|
|
52
|
+
}
|
|
53
|
+
state.step = step;
|
|
54
|
+
return model;
|
|
55
|
+
},
|
|
56
|
+
steps: enter => {
|
|
57
|
+
if (enter == null) {
|
|
58
|
+
return Object.values(flow.steps);
|
|
59
|
+
}
|
|
60
|
+
if (enter) {
|
|
61
|
+
return Object.values(flow.steps).filter(s => s.initial);
|
|
62
|
+
}
|
|
63
|
+
return Object.values(flow.steps).filter(s => !s.initial);
|
|
64
|
+
},
|
|
65
|
+
transitions: explicit => {
|
|
66
|
+
if (explicit == null) {
|
|
67
|
+
return Object.values(flow.steps[state.step].transitions);
|
|
68
|
+
}
|
|
69
|
+
if (explicit) {
|
|
70
|
+
return Object.values(flow.steps[state.step].transitions).filter(t => t.explicit);
|
|
71
|
+
}
|
|
72
|
+
return Object.values(flow.steps[state.step].transitions).filter(t => !t.explicit);
|
|
73
|
+
},
|
|
74
|
+
transition: transition => {
|
|
75
|
+
const t = flow.steps[state.step].transitions[transition];
|
|
76
|
+
if (t == null) {
|
|
77
|
+
throw new UnknownTransition(transition);
|
|
78
|
+
}
|
|
79
|
+
return t;
|
|
80
|
+
},
|
|
81
|
+
next: () => {
|
|
82
|
+
const transition = model.transitions().find(t => t.explicit !== true);
|
|
83
|
+
if (transition == null) {
|
|
84
|
+
throw new UnknownFlowStep('next');
|
|
85
|
+
}
|
|
86
|
+
return transition;
|
|
87
|
+
},
|
|
88
|
+
transit: (transition, ok, message, payload) => {
|
|
89
|
+
const t = model.transition(transition);
|
|
90
|
+
state.previous = state.step;
|
|
91
|
+
if (t.reversible !== true) {
|
|
92
|
+
delete state.previous;
|
|
93
|
+
}
|
|
94
|
+
state.step = t.step;
|
|
95
|
+
state.ok = ok;
|
|
96
|
+
if (typeof message !== 'string') {
|
|
97
|
+
payload = message;
|
|
98
|
+
message = undefined;
|
|
99
|
+
}
|
|
100
|
+
if (message != null) {
|
|
101
|
+
state.message = message;
|
|
102
|
+
}
|
|
103
|
+
else if (state.message != null) {
|
|
104
|
+
delete state.message;
|
|
105
|
+
}
|
|
106
|
+
if (payload != null) {
|
|
107
|
+
state.payload = payload;
|
|
108
|
+
}
|
|
109
|
+
else if (state.payload != null) {
|
|
110
|
+
delete state.payload;
|
|
111
|
+
}
|
|
112
|
+
return serializeState(flow, state);
|
|
113
|
+
},
|
|
114
|
+
serialize: () => serializeState(flow, state)
|
|
115
|
+
};
|
|
116
|
+
return model;
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE5F,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElE,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,IAA0B,EAAE,QAAuB,EAAsB,EAAE;IAC7G,IAAI,KAAK,GAAqB,IAAI,CAAA;IAClC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,WAAW,CAAC,WAAW,CAAC,CAAA;QACpC,CAAC;QACD,IAAI,CAAC;YACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAA;YAC3B,KAAK,GAAG;gBACN,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,IAAI,CAAC,WAAW;gBACtB,OAAO,EAAE,EAAE;gBACX,EAAE,EAAE,IAAI;aACT,CAAA;QACH,CAAC;QAAC,MAAM,CAAC;YACP,KAAK,GAAG,MAAM,gBAAgB,CAAC,IAAc,EAAE,QAAQ,CAAC,CAAA;YACxD,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,KAAK,GAAG;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,OAAO,EAAE,EAAE;YACX,EAAE,EAAE,IA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9C,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ResourceRecord } from '@owlmeans/resource';
|
|
2
|
+
import type { FLOW_RECORD } from './consts.js';
|
|
3
|
+
export interface Flow extends ShallowFlow {
|
|
4
|
+
config: FlowConfig;
|
|
5
|
+
prefabs: {
|
|
6
|
+
[step: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface ShallowFlow {
|
|
10
|
+
flow: string;
|
|
11
|
+
initialStep: string;
|
|
12
|
+
steps: {
|
|
13
|
+
[key: string]: FlowStep;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface FlowConfig {
|
|
17
|
+
queryParam?: string;
|
|
18
|
+
services?: {
|
|
19
|
+
[ref: string]: string;
|
|
20
|
+
};
|
|
21
|
+
modules?: {
|
|
22
|
+
[ref: string]: string;
|
|
23
|
+
};
|
|
24
|
+
pathes?: {
|
|
25
|
+
[ref: string]: string;
|
|
26
|
+
};
|
|
27
|
+
defaultFlow?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface FlowStep {
|
|
30
|
+
index: number;
|
|
31
|
+
step: string;
|
|
32
|
+
service: string;
|
|
33
|
+
path?: string;
|
|
34
|
+
module?: string;
|
|
35
|
+
initial?: boolean;
|
|
36
|
+
payloadMap?: {
|
|
37
|
+
[key: string]: number;
|
|
38
|
+
};
|
|
39
|
+
transitions: {
|
|
40
|
+
[key: string]: FlowTransition;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface FlowTransition {
|
|
44
|
+
transition: string;
|
|
45
|
+
step: string;
|
|
46
|
+
/**
|
|
47
|
+
* Whether user can choose this transition as one of possibilities
|
|
48
|
+
*/
|
|
49
|
+
explicit?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether user may get back
|
|
52
|
+
*/
|
|
53
|
+
reversible?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface FlowState {
|
|
56
|
+
flow: string;
|
|
57
|
+
step: string;
|
|
58
|
+
previous?: string;
|
|
59
|
+
entityId?: string | null;
|
|
60
|
+
service: string;
|
|
61
|
+
payload?: FlowPayload;
|
|
62
|
+
message?: string;
|
|
63
|
+
ok: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface FlowPayload extends Record<symbol | string, string | number | boolean | undefined | null> {
|
|
66
|
+
}
|
|
67
|
+
export interface SerializedFlow {
|
|
68
|
+
f: string;
|
|
69
|
+
e?: string;
|
|
70
|
+
s: string;
|
|
71
|
+
p?: string;
|
|
72
|
+
m?: string;
|
|
73
|
+
o: number;
|
|
74
|
+
}
|
|
75
|
+
export interface FlowModel {
|
|
76
|
+
target: (service: string) => FlowModel;
|
|
77
|
+
entity: (entityId: string) => FlowModel;
|
|
78
|
+
enter: (step?: string) => FlowModel;
|
|
79
|
+
steps: (enter?: boolean) => FlowStep[];
|
|
80
|
+
state: () => FlowState;
|
|
81
|
+
setState: (state: FlowState | null) => FlowModel;
|
|
82
|
+
payload: <T extends FlowPayload>() => T;
|
|
83
|
+
step: (step?: string) => FlowStep;
|
|
84
|
+
transitions: (explicit?: boolean) => FlowTransition[];
|
|
85
|
+
transition: (transition: string) => FlowTransition;
|
|
86
|
+
next: () => FlowTransition;
|
|
87
|
+
transit: (transition: string, ok: boolean, message?: string | FlowPayload, payload?: FlowPayload) => string;
|
|
88
|
+
serialize: () => string;
|
|
89
|
+
}
|
|
90
|
+
export interface FlowProvider {
|
|
91
|
+
(flow: string): Promise<Flow>;
|
|
92
|
+
}
|
|
93
|
+
export interface WithFlowConfig {
|
|
94
|
+
flowConfig?: FlowConfig;
|
|
95
|
+
}
|
|
96
|
+
export interface FlowConfigRecord extends ResourceRecord, ShallowFlow {
|
|
97
|
+
id: string;
|
|
98
|
+
recordType: typeof FLOW_RECORD;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|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,GAAG,IAAI,KAAK,SAAS,CAAA;IAChD,OAAO,EAAE,CAAC,CAAC,SAAS,WAAW,OAAO,CAAC,CAAA;IACvC,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,QAAQ,CAAA;IACjC,WAAW,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,cAAc,EAAE,CAAA;IACrD,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,cAAc,CAAA;IAClD,IAAI,EAAE,MAAM,cAAc,CAAA;IAC1B,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,MAAM,CAAA;IAC3G,SAAS,EAAE,MAAM,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc,EAAE,WAAW;IACnE,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,OAAO,WAAW,CAAA;CAC/B"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FlowProvider, FlowState, ShallowFlow } from '../types.js';
|
|
2
|
+
export declare const serializeState: (flow: ShallowFlow, state: FlowState) => string;
|
|
3
|
+
export declare const unserializeState: (token: string, flowProvider: FlowProvider) => Promise<FlowState>;
|
|
4
|
+
//# sourceMappingURL=flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/utils/flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAA;AAKvF,eAAO,MAAM,cAAc,SAAU,WAAW,SAAS,SAAS,KAAG,MAgCpE,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAiB,MAAM,gBAAgB,YAAY,KAAG,OAAO,CAAC,SAAS,CAkCnG,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { FLOW_SEP, PAYLOAD_SEP } from '../consts.js';
|
|
2
|
+
import { utf8, base64urlnopad } from '@scure/base';
|
|
3
|
+
import { UnknownFlowStep } from '../errors.js';
|
|
4
|
+
export const serializeState = (flow, state) => {
|
|
5
|
+
const flowBlock = [
|
|
6
|
+
state.flow,
|
|
7
|
+
flow.steps[state.step].index.toString()
|
|
8
|
+
];
|
|
9
|
+
if (state.previous != null) {
|
|
10
|
+
flowBlock.push(flow.steps[state.previous].index.toString());
|
|
11
|
+
}
|
|
12
|
+
const serialized = {
|
|
13
|
+
f: flowBlock.join(FLOW_SEP),
|
|
14
|
+
s: state.service,
|
|
15
|
+
o: state.ok ? 1 : 0,
|
|
16
|
+
};
|
|
17
|
+
if (state.entityId != null) {
|
|
18
|
+
serialized.e = state.entityId;
|
|
19
|
+
}
|
|
20
|
+
else if (state.entityId === null) {
|
|
21
|
+
serialized.e = '';
|
|
22
|
+
}
|
|
23
|
+
if (state.message != null) {
|
|
24
|
+
serialized.m = state.message;
|
|
25
|
+
}
|
|
26
|
+
if (state.payload != null) {
|
|
27
|
+
const step = flow.steps[state.step];
|
|
28
|
+
if (step.payloadMap != null) {
|
|
29
|
+
serialized.p = Object.entries(step.payloadMap).reduce((list, [key, index]) => {
|
|
30
|
+
list[index] = state.payload[key] != null ? state.payload[key].toString() : '';
|
|
31
|
+
return list;
|
|
32
|
+
}, Array(Object.keys(step.payloadMap).length)).join(PAYLOAD_SEP);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return base64urlnopad.encode(utf8.decode(JSON.stringify(serialized)));
|
|
36
|
+
};
|
|
37
|
+
export const unserializeState = async (token, flowProvider) => {
|
|
38
|
+
const serialized = JSON.parse(utf8.encode(base64urlnopad.decode(token)));
|
|
39
|
+
const [flowAlias, stepIndex, previousIdx] = serialized.f.split(FLOW_SEP, 3);
|
|
40
|
+
const flow = await flowProvider(flowAlias);
|
|
41
|
+
const step = Object.values(flow.steps).find(step => step.index === parseInt(stepIndex));
|
|
42
|
+
if (step == null) {
|
|
43
|
+
throw new UnknownFlowStep(stepIndex);
|
|
44
|
+
}
|
|
45
|
+
const previous = previousIdx != null ? Object.values(flow.steps).find(step => step.index === parseInt(previousIdx)) : undefined;
|
|
46
|
+
const state = {
|
|
47
|
+
flow: flow.flow,
|
|
48
|
+
step: step.step,
|
|
49
|
+
previous: previous?.step,
|
|
50
|
+
service: serialized.s,
|
|
51
|
+
ok: serialized.o === 1,
|
|
52
|
+
};
|
|
53
|
+
if (serialized.m != null) {
|
|
54
|
+
state.message = serialized.m;
|
|
55
|
+
}
|
|
56
|
+
if (serialized.e != null) {
|
|
57
|
+
state.entityId = serialized.e !== '' ? serialized.e : null;
|
|
58
|
+
}
|
|
59
|
+
if (serialized.p != null && step.payloadMap != null) {
|
|
60
|
+
const list = serialized.p.split(PAYLOAD_SEP);
|
|
61
|
+
state.payload = Object.fromEntries(Object.entries(step.payloadMap).map(([key, index]) => [key, list[index] != null ? list[index] : null]));
|
|
62
|
+
}
|
|
63
|
+
return state;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.js","sourceRoot":"","sources":["../../src/utils/flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,eAAe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CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAClE,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@owlmeans/flow",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc -b",
|
|
7
|
+
"dev": "sleep 162 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
|
|
8
|
+
"watch": "tsc -b -w --preserveWatchOutput --pretty"
|
|
9
|
+
},
|
|
10
|
+
"main": "build/index.js",
|
|
11
|
+
"module": "build/index.js",
|
|
12
|
+
"types": "build/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./build/index.js",
|
|
16
|
+
"require": "./build/index.js",
|
|
17
|
+
"default": "./build/index.js",
|
|
18
|
+
"module": "./build/index.js",
|
|
19
|
+
"types": "./build/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@owlmeans/auth": "^0.1.0",
|
|
24
|
+
"@owlmeans/config": "^0.1.0",
|
|
25
|
+
"@owlmeans/error": "^0.1.0",
|
|
26
|
+
"@owlmeans/i18n": "^0.1.0",
|
|
27
|
+
"@owlmeans/resource": "^0.1.0",
|
|
28
|
+
"@scure/base": "^1.1.9"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"nodemon": "^3.1.7",
|
|
32
|
+
"npm-check": "^6.0.1",
|
|
33
|
+
"typescript": "^5.6.3"
|
|
34
|
+
},
|
|
35
|
+
"private": false,
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/consts.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
export const FLOW_SEP = ':'
|
|
3
|
+
|
|
4
|
+
export const PAYLOAD_SEP = ','
|
|
5
|
+
|
|
6
|
+
export const STD_AUTH_FLOW = '_oa'
|
|
7
|
+
|
|
8
|
+
export const STD_OIDC_FLOW = '_oidc'
|
|
9
|
+
|
|
10
|
+
export const STD_STAB_FLOW = '_stb'
|
|
11
|
+
|
|
12
|
+
export const STD_OIDP_FLOW = '_oidp'
|
|
13
|
+
|
|
14
|
+
export const TARGET_SERVICE = '-'
|
|
15
|
+
|
|
16
|
+
export const CFG_FLOW_PREFIX = 'flow'
|
|
17
|
+
|
|
18
|
+
export const FLOW_RECORD = 'flow'
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import { ResilientError } from '@owlmeans/error'
|
|
3
|
+
|
|
4
|
+
export class FlowError extends ResilientError {
|
|
5
|
+
public static override typeName: string = 'FlowError'
|
|
6
|
+
|
|
7
|
+
constructor(message: string = 'error') {
|
|
8
|
+
super(FlowError.typeName, `flow:${message}`)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class FlowUnsupported extends FlowError {
|
|
13
|
+
public static override typeName: string = `${FlowError.typeName}Unsupported`
|
|
14
|
+
|
|
15
|
+
constructor(message: string = 'error') {
|
|
16
|
+
super(`unsupported:${message}`)
|
|
17
|
+
this.type = FlowUnsupported.typeName
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class FlowTargetError extends FlowError {
|
|
22
|
+
public static override typeName: string = `${FlowError.typeName}Target`
|
|
23
|
+
|
|
24
|
+
constructor(message: string = 'error') {
|
|
25
|
+
super(`target:${message}`)
|
|
26
|
+
this.type = FlowTargetError.typeName
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class UnknownFlow extends FlowError {
|
|
31
|
+
public static override typeName: string = `${FlowError.typeName}Unknown`
|
|
32
|
+
|
|
33
|
+
constructor(message: string = 'error') {
|
|
34
|
+
super(`unknown:${message}`)
|
|
35
|
+
this.type = UnknownFlow.typeName
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class FlowStepError extends FlowError {
|
|
40
|
+
public static override typeName: string = `${FlowError.typeName}Step`
|
|
41
|
+
|
|
42
|
+
constructor(message: string = 'error') {
|
|
43
|
+
super(`step:${message}`)
|
|
44
|
+
this.type = FlowStepError.typeName
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class FlowStepMissconfigured extends FlowStepError {
|
|
49
|
+
public static override typeName: string = `${FlowStepError.typeName}Missconfigured`
|
|
50
|
+
|
|
51
|
+
constructor(message: string = 'error') {
|
|
52
|
+
super(`missconfigured:${message}`)
|
|
53
|
+
this.type = FlowStepMissconfigured.typeName
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class UnknownFlowStep extends FlowStepError {
|
|
58
|
+
public static override typeName: string = `${FlowStepError.typeName}Unknown`
|
|
59
|
+
|
|
60
|
+
constructor(message: string = 'error') {
|
|
61
|
+
super(`unknown:${message}`)
|
|
62
|
+
this.type = UnknownFlowStep.typeName
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class UnknownTransition extends FlowStepError {
|
|
67
|
+
public static override typeName: string = `${FlowStepError.typeName}Transition`
|
|
68
|
+
|
|
69
|
+
constructor(message: string = 'error') {
|
|
70
|
+
super(`transition:${message}`)
|
|
71
|
+
this.type = UnknownTransition.typeName
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
ResilientError.registerErrorClass(FlowError)
|
|
76
|
+
ResilientError.registerErrorClass(FlowUnsupported)
|
|
77
|
+
ResilientError.registerErrorClass(FlowTargetError)
|
|
78
|
+
ResilientError.registerErrorClass(UnknownFlow)
|
|
79
|
+
ResilientError.registerErrorClass(FlowStepError)
|
|
80
|
+
ResilientError.registerErrorClass(FlowStepMissconfigured)
|
|
81
|
+
ResilientError.registerErrorClass(UnknownFlowStep)
|
|
82
|
+
ResilientError.registerErrorClass(UnknownTransition)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { ShallowFlow } from '../types.js'
|
|
2
|
+
import { STD_AUTH_FLOW } from '../consts.js'
|
|
3
|
+
|
|
4
|
+
export enum StdAuthStep {
|
|
5
|
+
Choice = 'choice',
|
|
6
|
+
Signup = 'signup',
|
|
7
|
+
Signin = 'signin',
|
|
8
|
+
New = 'new',
|
|
9
|
+
Existing = 'existing',
|
|
10
|
+
Payment = 'payment',
|
|
11
|
+
Success = 'success',
|
|
12
|
+
Target = 'target'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// OwlMeans Authentication Standard Flow
|
|
16
|
+
/**
|
|
17
|
+
* @TODO Actually this thing is kept here for the iteration when
|
|
18
|
+
* OwlMeans ID account may be used without owlmeans.net account.
|
|
19
|
+
*
|
|
20
|
+
* @deprecated
|
|
21
|
+
*/
|
|
22
|
+
export const stdAuthFlow: ShallowFlow = {
|
|
23
|
+
// naming - preserve space in serialized state
|
|
24
|
+
flow: STD_AUTH_FLOW,
|
|
25
|
+
initialStep: StdAuthStep.Choice,
|
|
26
|
+
|
|
27
|
+
steps: {
|
|
28
|
+
|
|
29
|
+
[StdAuthStep.Choice]: {
|
|
30
|
+
index: 0,
|
|
31
|
+
step: StdAuthStep.Choice,
|
|
32
|
+
service: '$auth',
|
|
33
|
+
initial: true,
|
|
34
|
+
module: '$auth.choice',
|
|
35
|
+
transitions: {
|
|
36
|
+
[StdAuthStep.Signup]: {
|
|
37
|
+
transition: StdAuthStep.Signup,
|
|
38
|
+
step: StdAuthStep.Signup,
|
|
39
|
+
explicit: true,
|
|
40
|
+
reversible: true
|
|
41
|
+
},
|
|
42
|
+
[StdAuthStep.Signin]: {
|
|
43
|
+
transition: StdAuthStep.Signin,
|
|
44
|
+
step: StdAuthStep.Signin,
|
|
45
|
+
explicit: true,
|
|
46
|
+
reversible: true
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
[StdAuthStep.Signup]: {
|
|
52
|
+
index: 1,
|
|
53
|
+
step: StdAuthStep.Signup,
|
|
54
|
+
service: '$auth',
|
|
55
|
+
module: '$auth.flow',
|
|
56
|
+
initial: true,
|
|
57
|
+
transitions: {
|
|
58
|
+
[StdAuthStep.New]: {
|
|
59
|
+
transition: StdAuthStep.New,
|
|
60
|
+
step: StdAuthStep.New,
|
|
61
|
+
explicit: true,
|
|
62
|
+
reversible: true,
|
|
63
|
+
},
|
|
64
|
+
[StdAuthStep.Existing]: {
|
|
65
|
+
transition: StdAuthStep.Existing,
|
|
66
|
+
step: StdAuthStep.Existing,
|
|
67
|
+
explicit: true,
|
|
68
|
+
reversible: true
|
|
69
|
+
},
|
|
70
|
+
[StdAuthStep.Signin]: {
|
|
71
|
+
transition: StdAuthStep.Signin,
|
|
72
|
+
step: StdAuthStep.Signin,
|
|
73
|
+
explicit: true,
|
|
74
|
+
reversible: true
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
[StdAuthStep.Signin]: {
|
|
80
|
+
index: 2,
|
|
81
|
+
step: StdAuthStep.Signin,
|
|
82
|
+
service: '$auth',
|
|
83
|
+
module: '$auth.flow',
|
|
84
|
+
initial: true,
|
|
85
|
+
transitions: {
|
|
86
|
+
[StdAuthStep.Target]: {
|
|
87
|
+
transition: StdAuthStep.Target,
|
|
88
|
+
step: StdAuthStep.Target,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
[StdAuthStep.New]: {
|
|
94
|
+
index: 3,
|
|
95
|
+
step: StdAuthStep.New,
|
|
96
|
+
service: '$auth',
|
|
97
|
+
module: '$auth.flow',
|
|
98
|
+
initial: true,
|
|
99
|
+
transitions: {
|
|
100
|
+
[StdAuthStep.Payment]: {
|
|
101
|
+
transition: StdAuthStep.Payment,
|
|
102
|
+
step: StdAuthStep.Payment,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
[StdAuthStep.Existing]: {
|
|
108
|
+
index: 4,
|
|
109
|
+
step: StdAuthStep.Existing,
|
|
110
|
+
service: '$auth',
|
|
111
|
+
module: '$auth.flow',
|
|
112
|
+
transitions: {
|
|
113
|
+
[StdAuthStep.Payment]: {
|
|
114
|
+
transition: StdAuthStep.Payment,
|
|
115
|
+
step: StdAuthStep.Payment,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
[StdAuthStep.Payment]: {
|
|
121
|
+
index: 5,
|
|
122
|
+
step: StdAuthStep.Payment,
|
|
123
|
+
service: '$payment',
|
|
124
|
+
module: '$payment.plan',
|
|
125
|
+
transitions: {
|
|
126
|
+
[StdAuthStep.Success]: {
|
|
127
|
+
transition: StdAuthStep.Success,
|
|
128
|
+
step: StdAuthStep.Success,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
[StdAuthStep.Success]: {
|
|
134
|
+
index: 6,
|
|
135
|
+
step: StdAuthStep.Success,
|
|
136
|
+
service: '$payment',
|
|
137
|
+
module: '$payment.success',
|
|
138
|
+
transitions: {
|
|
139
|
+
[StdAuthStep.Target]: {
|
|
140
|
+
transition: StdAuthStep.Target,
|
|
141
|
+
step: StdAuthStep.Target,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
// @TODO This doesn't work anymore
|
|
147
|
+
// The auth dispatcher will require an additional step to proceed
|
|
148
|
+
[StdAuthStep.Target]: {
|
|
149
|
+
index: 7,
|
|
150
|
+
step: StdAuthStep.Target,
|
|
151
|
+
service: '$auth',
|
|
152
|
+
module: '$dispatcher',
|
|
153
|
+
transitions: {}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
}
|