@owlmeans/flow 0.1.18-rc.9 → 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.
Files changed (55) hide show
  1. package/README.md +20 -15
  2. package/agent-meta/manifest.json +3 -3
  3. package/agent-meta/skills/flow/SKILL.md +51 -15
  4. package/build/flows/auth/consts.d.ts +19 -0
  5. package/build/flows/auth/consts.d.ts.map +1 -0
  6. package/build/flows/auth/consts.js +146 -0
  7. package/build/flows/auth/consts.js.map +1 -0
  8. package/build/flows/index.d.ts +4 -4
  9. package/build/flows/index.d.ts.map +1 -1
  10. package/build/flows/index.js +4 -4
  11. package/build/flows/index.js.map +1 -1
  12. package/build/flows/oidc/consts.d.ts +15 -0
  13. package/build/flows/oidc/consts.d.ts.map +1 -0
  14. package/build/flows/oidc/consts.js +147 -0
  15. package/build/flows/oidc/consts.js.map +1 -0
  16. package/build/flows/oidp/consts.d.ts +13 -0
  17. package/build/flows/oidp/consts.d.ts.map +1 -0
  18. package/build/flows/oidp/consts.js +189 -0
  19. package/build/flows/oidp/consts.js.map +1 -0
  20. package/build/flows/stab/consts.d.ts +3 -0
  21. package/build/flows/stab/consts.d.ts.map +1 -0
  22. package/build/flows/stab/consts.js +16 -0
  23. package/build/flows/stab/consts.js.map +1 -0
  24. package/build/helper.js +2 -2
  25. package/build/helper.js.map +1 -1
  26. package/build/i18n/fr.json +8 -0
  27. package/build/i18n.js +10 -8
  28. package/build/i18n.js.map +1 -1
  29. package/build/state.js +4 -4
  30. package/build/state.js.map +1 -1
  31. package/build/utils/flow/types.d.ts +13 -0
  32. package/build/utils/flow/types.d.ts.map +1 -0
  33. package/build/utils/flow/types.js +2 -0
  34. package/build/utils/flow/types.js.map +1 -0
  35. package/build/utils/flow.d.ts +3 -3
  36. package/build/utils/flow.d.ts.map +1 -1
  37. package/build/utils/flow.js +61 -57
  38. package/build/utils/flow.js.map +1 -1
  39. package/build/utils/index.d.ts +1 -0
  40. package/build/utils/index.d.ts.map +1 -1
  41. package/build/utils/index.js.map +1 -1
  42. package/package.json +8 -8
  43. package/src/flows/{auth.ts → auth/consts.ts} +2 -2
  44. package/src/flows/index.ts +4 -4
  45. package/src/flows/{oidc.ts → oidc/consts.ts} +2 -2
  46. package/src/flows/{oidp.ts → oidp/consts.ts} +2 -2
  47. package/src/flows/{stab.ts → stab/consts.ts} +2 -2
  48. package/src/helper.ts +2 -2
  49. package/src/i18n/fr.json +8 -0
  50. package/src/i18n.ts +10 -8
  51. package/src/state.ts +4 -4
  52. package/src/utils/flow/types.ts +13 -0
  53. package/src/utils/flow.ts +65 -58
  54. package/src/utils/index.ts +1 -0
  55. package/build/.gitkeep +0 -0
package/src/helper.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { CommonConfig } from '@owlmeans/config'
2
- import { toConfigRecord } from '@owlmeans/config'
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
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ "_oa": {
3
+ "signup": "S’inscrire",
4
+ "signin": "Se connecter",
5
+ "new": "Créer une organisation",
6
+ "existing": "Utiliser une organisation existante"
7
+ }
8
+ }
package/src/i18n.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { addI18nLib } from '@owlmeans/i18n'
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 { serializeState, unserializeState } from './utils/flow.js'
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 serializeState = (flow: ShallowFlow, state: FlowState): string => {
7
- const flowBlock = [
8
- state.flow,
9
- flow.steps[state.step].index.toString()
10
- ]
11
- if (state.previous != null) {
12
- flowBlock.push(flow.steps[state.previous].index.toString())
13
- }
14
- const serialized: SerializedFlow = {
15
- f: flowBlock.join(FLOW_SEP),
16
- s: state.service,
17
- o: state.ok ? 1 : 0,
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
- return base64urlnopad.encode(utf8.decode(JSON.stringify(serialized)))
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
- export const unserializeState = async (token: string, flowProvider: FlowProvider): Promise<FlowState> => {
41
- const serialized: SerializedFlow = JSON.parse(utf8.encode(base64urlnopad.decode(token)))
42
- const [flowAlias, stepIndex, previousIdx] = serialized.f.split(FLOW_SEP, 3)
43
- const flow = await flowProvider(flowAlias)
44
- const step = Object.values(flow.steps).find(step => step.index === parseInt(stepIndex))
45
- if (step == null) {
46
- throw new UnknownFlowStep(stepIndex)
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
- const state: FlowState = {
51
- flow: flow.flow,
52
- step: step.step,
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
- if (serialized.m != null) {
59
- state.message = serialized.m
60
- }
64
+ if (serialized.e != null) {
65
+ state.entityId = serialized.e !== '' ? serialized.e : null
66
+ }
61
67
 
62
- if (serialized.e != null) {
63
- state.entityId = serialized.e !== '' ? serialized.e : null
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
- if (serialized.p != null && step.payloadMap != null) {
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 state
78
+ return { serializeState, unserializeState }
74
79
  }
80
+
81
+ export const flowUtils = createFlowUtils()
@@ -1,2 +1,3 @@
1
1
 
2
+ export type * from './flow/types.js'
2
3
  export * from './flow.js'
package/build/.gitkeep DELETED
File without changes