@owlmeans/flow 0.1.18-rc.7 → 0.1.18
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/README.md +20 -15
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/flow/SKILL.md +131 -27
- package/build/flows/auth/consts.d.ts +19 -0
- package/build/flows/auth/consts.d.ts.map +1 -0
- package/build/flows/auth/consts.js +146 -0
- package/build/flows/auth/consts.js.map +1 -0
- package/build/flows/index.d.ts +4 -4
- package/build/flows/index.d.ts.map +1 -1
- package/build/flows/index.js +4 -4
- package/build/flows/index.js.map +1 -1
- package/build/flows/oidc/consts.d.ts +15 -0
- package/build/flows/oidc/consts.d.ts.map +1 -0
- package/build/flows/oidc/consts.js +147 -0
- package/build/flows/oidc/consts.js.map +1 -0
- package/build/flows/oidp/consts.d.ts +13 -0
- package/build/flows/oidp/consts.d.ts.map +1 -0
- package/build/flows/oidp/consts.js +189 -0
- package/build/flows/oidp/consts.js.map +1 -0
- package/build/flows/stab/consts.d.ts +3 -0
- package/build/flows/stab/consts.d.ts.map +1 -0
- package/build/flows/stab/consts.js +16 -0
- package/build/flows/stab/consts.js.map +1 -0
- package/build/helper.js +2 -2
- package/build/helper.js.map +1 -1
- package/build/i18n/fr.json +8 -0
- package/build/i18n.js +10 -8
- package/build/i18n.js.map +1 -1
- package/build/state.js +4 -4
- package/build/state.js.map +1 -1
- package/build/utils/flow/types.d.ts +13 -0
- package/build/utils/flow/types.d.ts.map +1 -0
- package/build/utils/flow/types.js +2 -0
- package/build/utils/flow/types.js.map +1 -0
- package/build/utils/flow.d.ts +3 -3
- package/build/utils/flow.d.ts.map +1 -1
- package/build/utils/flow.js +61 -57
- package/build/utils/flow.js.map +1 -1
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js.map +1 -1
- package/package.json +8 -8
- package/src/flows/{auth.ts → auth/consts.ts} +2 -2
- package/src/flows/index.ts +4 -4
- package/src/flows/{oidc.ts → oidc/consts.ts} +2 -2
- package/src/flows/{oidp.ts → oidp/consts.ts} +2 -2
- package/src/flows/{stab.ts → stab/consts.ts} +2 -2
- package/src/helper.ts +2 -2
- package/src/i18n/fr.json +8 -0
- package/src/i18n.ts +10 -8
- package/src/state.ts +4 -4
- package/src/utils/flow/types.ts +13 -0
- package/src/utils/flow.ts +65 -58
- package/src/utils/index.ts +1 -0
- package/build/.gitkeep +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import type { ShallowFlow } from '
|
|
3
|
-
import { STD_OIDP_FLOW, TARGET_SERVICE } from '
|
|
2
|
+
import type { ShallowFlow } from '../../types.js'
|
|
3
|
+
import { STD_OIDP_FLOW, TARGET_SERVICE } from '../../consts.js'
|
|
4
4
|
|
|
5
5
|
export enum OidpAuthStep {
|
|
6
6
|
Unknown = 'unknown',
|
package/src/helper.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommonConfig } from '@owlmeans/config'
|
|
2
|
-
import {
|
|
2
|
+
import { configHelper } from '@owlmeans/config'
|
|
3
3
|
import type { FlowConfig, ShallowFlow, WithFlowConfig } from './types.js'
|
|
4
4
|
import { CFG_FLOW_PREFIX, FLOW_RECORD } from './consts.js'
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ export const flow = <C extends CommonConfig>(cfg: C, flow: ShallowFlow): C => {
|
|
|
7
7
|
if (cfg.records == null) {
|
|
8
8
|
cfg.records = []
|
|
9
9
|
}
|
|
10
|
-
cfg.records.push({ ...toConfigRecord(flow), id: `${CFG_FLOW_PREFIX}:${flow.flow}`, recordType: FLOW_RECORD })
|
|
10
|
+
cfg.records.push({ ...configHelper.toConfigRecord(flow), id: `${CFG_FLOW_PREFIX}:${flow.flow}`, recordType: FLOW_RECORD })
|
|
11
11
|
|
|
12
12
|
return cfg
|
|
13
13
|
}
|
package/src/i18n/fr.json
ADDED
package/src/i18n.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i18nHelper } from '@owlmeans/i18n'
|
|
2
2
|
|
|
3
3
|
import en from './i18n/en.json' with { type: 'json' }
|
|
4
4
|
import pl from './i18n/pl.json' with { type: 'json' }
|
|
@@ -7,11 +7,13 @@ import be from './i18n/be.json' with { type: 'json' }
|
|
|
7
7
|
import uk from './i18n/uk.json' with { type: 'json' }
|
|
8
8
|
import es from './i18n/es.json' with { type: 'json' }
|
|
9
9
|
import de from './i18n/de.json' with { type: 'json' }
|
|
10
|
+
import fr from './i18n/fr.json' with { type: 'json' }
|
|
10
11
|
|
|
11
|
-
addI18nLib('en', 'flow', en)
|
|
12
|
-
addI18nLib('pl', 'flow', pl)
|
|
13
|
-
addI18nLib('ru', 'flow', ru)
|
|
14
|
-
addI18nLib('be', 'flow', be)
|
|
15
|
-
addI18nLib('uk', 'flow', uk)
|
|
16
|
-
addI18nLib('es', 'flow', es)
|
|
17
|
-
addI18nLib('de', 'flow', de)
|
|
12
|
+
i18nHelper.addI18nLib('en', 'flow', en)
|
|
13
|
+
i18nHelper.addI18nLib('pl', 'flow', pl)
|
|
14
|
+
i18nHelper.addI18nLib('ru', 'flow', ru)
|
|
15
|
+
i18nHelper.addI18nLib('be', 'flow', be)
|
|
16
|
+
i18nHelper.addI18nLib('uk', 'flow', uk)
|
|
17
|
+
i18nHelper.addI18nLib('es', 'flow', es)
|
|
18
|
+
i18nHelper.addI18nLib('de', 'flow', de)
|
|
19
|
+
i18nHelper.addI18nLib('fr', 'flow', fr)
|
package/src/state.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FlowStepError, UnknownFlow, UnknownFlowStep, UnknownTransition } from './errors.js'
|
|
2
2
|
import type { FlowModel, FlowProvider, FlowState, ShallowFlow } from './types.js'
|
|
3
|
-
import {
|
|
3
|
+
import { flowUtils } from './utils/flow.js'
|
|
4
4
|
|
|
5
5
|
export const makeFlowModel = async (flow: string | ShallowFlow, provider?: FlowProvider): Promise<FlowModel> => {
|
|
6
6
|
let state: FlowState | null = null
|
|
@@ -17,7 +17,7 @@ export const makeFlowModel = async (flow: string | ShallowFlow, provider?: FlowP
|
|
|
17
17
|
ok: true
|
|
18
18
|
}
|
|
19
19
|
} catch {
|
|
20
|
-
state = await unserializeState(flow as string, provider)
|
|
20
|
+
state = await flowUtils.unserializeState(flow as string, provider)
|
|
21
21
|
flow = await provider(state.flow)
|
|
22
22
|
}
|
|
23
23
|
} else {
|
|
@@ -140,10 +140,10 @@ export const makeFlowModel = async (flow: string | ShallowFlow, provider?: FlowP
|
|
|
140
140
|
delete state!.payload
|
|
141
141
|
}*/
|
|
142
142
|
|
|
143
|
-
return serializeState(flow, state!)
|
|
143
|
+
return flowUtils.serializeState(flow, state!)
|
|
144
144
|
},
|
|
145
145
|
|
|
146
|
-
serialize: () => serializeState(flow, state!)
|
|
146
|
+
serialize: () => flowUtils.serializeState(flow, state!)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
return model
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FlowProvider, FlowState, ShallowFlow } from '../../types.js'
|
|
2
|
+
|
|
3
|
+
/** The compact, URL-safe wire form of a flow state. */
|
|
4
|
+
export interface FlowUtils {
|
|
5
|
+
/** The flow state as a base64url token: step indexes, service, ok flag, entity, message and mapped payload. */
|
|
6
|
+
serializeState: (flow: ShallowFlow, state: FlowState) => string
|
|
7
|
+
/**
|
|
8
|
+
* The flow state a token carries, its flow looked up through `flowProvider`.
|
|
9
|
+
*
|
|
10
|
+
* @throws {UnknownFlowStep} when the token names a step index the flow does not have
|
|
11
|
+
*/
|
|
12
|
+
unserializeState: (token: string, flowProvider: FlowProvider) => Promise<FlowState>
|
|
13
|
+
}
|
package/src/utils/flow.ts
CHANGED
|
@@ -2,73 +2,80 @@ import type { FlowProvider, FlowState, SerializedFlow, ShallowFlow } from '../ty
|
|
|
2
2
|
import { FLOW_SEP, PAYLOAD_SEP } from '../consts.js'
|
|
3
3
|
import { utf8, base64urlnopad } from '@scure/base'
|
|
4
4
|
import { UnknownFlowStep } from '../errors.js'
|
|
5
|
+
import type { FlowUtils } from './flow/types.js'
|
|
5
6
|
|
|
6
|
-
export const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (state.entityId != null) {
|
|
20
|
-
serialized.e = state.entityId
|
|
21
|
-
} else if (state.entityId === null) {
|
|
22
|
-
serialized.e = ''
|
|
23
|
-
}
|
|
24
|
-
if (state.message != null) {
|
|
25
|
-
serialized.m = state.message
|
|
26
|
-
}
|
|
27
|
-
if (state.payload != null) {
|
|
28
|
-
const step = flow.steps[state.step]
|
|
29
|
-
if (step.payloadMap != null) {
|
|
30
|
-
serialized.p = Object.entries(step.payloadMap).reduce<string[]>((list, [key, index]) => {
|
|
31
|
-
list[index] = state.payload![key] != null ? state.payload![key].toString() : ''
|
|
32
|
-
return list
|
|
33
|
-
}, Array<string>(Object.keys(step.payloadMap).length)).join(PAYLOAD_SEP)
|
|
7
|
+
export const createFlowUtils = (): FlowUtils => {
|
|
8
|
+
const serializeState = (flow: ShallowFlow, state: FlowState): string => {
|
|
9
|
+
const flowBlock = [
|
|
10
|
+
state.flow,
|
|
11
|
+
flow.steps[state.step].index.toString()
|
|
12
|
+
]
|
|
13
|
+
if (state.previous != null) {
|
|
14
|
+
flowBlock.push(flow.steps[state.previous].index.toString())
|
|
15
|
+
}
|
|
16
|
+
const serialized: SerializedFlow = {
|
|
17
|
+
f: flowBlock.join(FLOW_SEP),
|
|
18
|
+
s: state.service,
|
|
19
|
+
o: state.ok ? 1 : 0,
|
|
34
20
|
}
|
|
21
|
+
if (state.entityId != null) {
|
|
22
|
+
serialized.e = state.entityId
|
|
23
|
+
} else if (state.entityId === null) {
|
|
24
|
+
serialized.e = ''
|
|
25
|
+
}
|
|
26
|
+
if (state.message != null) {
|
|
27
|
+
serialized.m = state.message
|
|
28
|
+
}
|
|
29
|
+
if (state.payload != null) {
|
|
30
|
+
const step = flow.steps[state.step]
|
|
31
|
+
if (step.payloadMap != null) {
|
|
32
|
+
serialized.p = Object.entries(step.payloadMap).reduce<string[]>((list, [key, index]) => {
|
|
33
|
+
list[index] = state.payload![key] != null ? state.payload![key].toString() : ''
|
|
34
|
+
return list
|
|
35
|
+
}, Array<string>(Object.keys(step.payloadMap).length)).join(PAYLOAD_SEP)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return base64urlnopad.encode(utf8.decode(JSON.stringify(serialized)))
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
const unserializeState = async (token: string, flowProvider: FlowProvider): Promise<FlowState> => {
|
|
43
|
+
const serialized: SerializedFlow = JSON.parse(utf8.encode(base64urlnopad.decode(token)))
|
|
44
|
+
const [flowAlias, stepIndex, previousIdx] = serialized.f.split(FLOW_SEP, 3)
|
|
45
|
+
const flow = await flowProvider(flowAlias)
|
|
46
|
+
const step = Object.values(flow.steps).find(step => step.index === parseInt(stepIndex))
|
|
47
|
+
if (step == null) {
|
|
48
|
+
throw new UnknownFlowStep(stepIndex)
|
|
49
|
+
}
|
|
50
|
+
const previous = previousIdx != null ? Object.values(flow.steps).find(step => step.index === parseInt(previousIdx)) : undefined
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
const previous = previousIdx != null ? Object.values(flow.steps).find(step => step.index === parseInt(previousIdx)) : undefined
|
|
52
|
+
const state: FlowState = {
|
|
53
|
+
flow: flow.flow,
|
|
54
|
+
step: step.step,
|
|
55
|
+
previous: previous?.step,
|
|
56
|
+
service: serialized.s,
|
|
57
|
+
ok: serialized.o === 1,
|
|
58
|
+
}
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
previous: previous?.step,
|
|
54
|
-
service: serialized.s,
|
|
55
|
-
ok: serialized.o === 1,
|
|
56
|
-
}
|
|
60
|
+
if (serialized.m != null) {
|
|
61
|
+
state.message = serialized.m
|
|
62
|
+
}
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
if (serialized.e != null) {
|
|
65
|
+
state.entityId = serialized.e !== '' ? serialized.e : null
|
|
66
|
+
}
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
if (serialized.p != null && step.payloadMap != null) {
|
|
69
|
+
const list = serialized.p.split(PAYLOAD_SEP)
|
|
70
|
+
state.payload = Object.fromEntries(Object.entries(step.payloadMap).map(
|
|
71
|
+
([key, index]) => [key, list[index] != null ? list[index] : null]
|
|
72
|
+
))
|
|
73
|
+
}
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
const list = serialized.p.split(PAYLOAD_SEP)
|
|
68
|
-
state.payload = Object.fromEntries(Object.entries(step.payloadMap).map(
|
|
69
|
-
([key, index]) => [key, list[index] != null ? list[index] : null]
|
|
70
|
-
))
|
|
75
|
+
return state
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
return
|
|
78
|
+
return { serializeState, unserializeState }
|
|
74
79
|
}
|
|
80
|
+
|
|
81
|
+
export const flowUtils = createFlowUtils()
|
package/src/utils/index.ts
CHANGED
package/build/.gitkeep
DELETED
|
File without changes
|