@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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +514 -0
  3. package/build/.gitkeep +0 -0
  4. package/build/consts.d.ts +10 -0
  5. package/build/consts.d.ts.map +1 -0
  6. package/build/consts.js +10 -0
  7. package/build/consts.js.map +1 -0
  8. package/build/errors.d.ts +34 -0
  9. package/build/errors.d.ts.map +1 -0
  10. package/build/errors.js +65 -0
  11. package/build/errors.js.map +1 -0
  12. package/build/flows/auth.d.ts +19 -0
  13. package/build/flows/auth.d.ts.map +1 -0
  14. package/build/flows/auth.js +146 -0
  15. package/build/flows/auth.js.map +1 -0
  16. package/build/flows/index.d.ts +5 -0
  17. package/build/flows/index.d.ts.map +1 -0
  18. package/build/flows/index.js +5 -0
  19. package/build/flows/index.js.map +1 -0
  20. package/build/flows/oidc.d.ts +14 -0
  21. package/build/flows/oidc.d.ts.map +1 -0
  22. package/build/flows/oidc.js +136 -0
  23. package/build/flows/oidc.js.map +1 -0
  24. package/build/flows/oidp.d.ts +13 -0
  25. package/build/flows/oidp.d.ts.map +1 -0
  26. package/build/flows/oidp.js +189 -0
  27. package/build/flows/oidp.js.map +1 -0
  28. package/build/flows/stab.d.ts +3 -0
  29. package/build/flows/stab.d.ts.map +1 -0
  30. package/build/flows/stab.js +16 -0
  31. package/build/flows/stab.js.map +1 -0
  32. package/build/helper.d.ts +5 -0
  33. package/build/helper.d.ts.map +1 -0
  34. package/build/helper.js +14 -0
  35. package/build/helper.js.map +1 -0
  36. package/build/i18n/en.json +8 -0
  37. package/build/i18n.d.ts +2 -0
  38. package/build/i18n.d.ts.map +1 -0
  39. package/build/i18n.js +4 -0
  40. package/build/i18n.js.map +1 -0
  41. package/build/index.d.ts +8 -0
  42. package/build/index.d.ts.map +1 -0
  43. package/build/index.js +7 -0
  44. package/build/index.js.map +1 -0
  45. package/build/state.d.ts +3 -0
  46. package/build/state.d.ts.map +1 -0
  47. package/build/state.js +118 -0
  48. package/build/state.js.map +1 -0
  49. package/build/types.d.ts +100 -0
  50. package/build/types.d.ts.map +1 -0
  51. package/build/types.js +2 -0
  52. package/build/types.js.map +1 -0
  53. package/build/utils/flow.d.ts +4 -0
  54. package/build/utils/flow.d.ts.map +1 -0
  55. package/build/utils/flow.js +65 -0
  56. package/build/utils/flow.js.map +1 -0
  57. package/build/utils/index.d.ts +2 -0
  58. package/build/utils/index.d.ts.map +1 -0
  59. package/build/utils/index.js +2 -0
  60. package/build/utils/index.js.map +1 -0
  61. package/package.json +39 -0
  62. package/src/consts.ts +18 -0
  63. package/src/errors.ts +82 -0
  64. package/src/flows/auth.ts +157 -0
  65. package/src/flows/index.ts +5 -0
  66. package/src/flows/oidc.ts +148 -0
  67. package/src/flows/oidp.ts +205 -0
  68. package/src/flows/stab.ts +17 -0
  69. package/src/helper.ts +19 -0
  70. package/src/i18n/en.json +8 -0
  71. package/src/i18n.ts +5 -0
  72. package/src/index.ts +8 -0
  73. package/src/state.ts +138 -0
  74. package/src/types.ts +103 -0
  75. package/src/utils/flow.ts +74 -0
  76. package/src/utils/index.ts +2 -0
  77. package/tsconfig.json +15 -0
  78. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,74 @@
1
+ import type { FlowProvider, FlowState, SerializedFlow, ShallowFlow } from '../types.js'
2
+ import { FLOW_SEP, PAYLOAD_SEP } from '../consts.js'
3
+ import { utf8, base64urlnopad } from '@scure/base'
4
+ import { UnknownFlowStep } from '../errors.js'
5
+
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)
34
+ }
35
+ }
36
+
37
+ return base64urlnopad.encode(utf8.decode(JSON.stringify(serialized)))
38
+ }
39
+
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
49
+
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
+ }
57
+
58
+ if (serialized.m != null) {
59
+ state.message = serialized.m
60
+ }
61
+
62
+ if (serialized.e != null) {
63
+ state.entityId = serialized.e !== '' ? serialized.e : null
64
+ }
65
+
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
+ ))
71
+ }
72
+
73
+ return state
74
+ }
@@ -0,0 +1,2 @@
1
+
2
+ export * from './flow.js'
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": [
3
+ "../tsconfig.default.json"
4
+ ],
5
+ "compilerOptions": {
6
+ "rootDir": "./src/", /* Specify the root folder within your source files. */
7
+ "outDir": "./build/", /* Specify an output folder for all emitted files. */
8
+ "moduleResolution": "Bundler"
9
+ },
10
+ "exclude": [
11
+ "./dist/**/*",
12
+ "./build/**/*",
13
+ "./*.ts"
14
+ ]
15
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/consts.ts","./src/errors.ts","./src/helper.ts","./src/i18n.ts","./src/index.ts","./src/state.ts","./src/types.ts","./src/flows/auth.ts","./src/flows/index.ts","./src/flows/oidc.ts","./src/flows/oidp.ts","./src/flows/stab.ts","./src/utils/flow.ts","./src/utils/index.ts"],"version":"5.6.3"}