@ajna-inc/workflow 0.5.17

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 (139) hide show
  1. package/build/WorkflowEvents.d.ts +35 -0
  2. package/build/WorkflowEvents.js +10 -0
  3. package/build/WorkflowEvents.js.map +1 -0
  4. package/build/WorkflowModule.d.ts +13 -0
  5. package/build/WorkflowModule.js +459 -0
  6. package/build/WorkflowModule.js.map +1 -0
  7. package/build/WorkflowModuleConfig.d.ts +33 -0
  8. package/build/WorkflowModuleConfig.js +18 -0
  9. package/build/WorkflowModuleConfig.js.map +1 -0
  10. package/build/actions/ActionRegistry.d.ts +35 -0
  11. package/build/actions/ActionRegistry.js +193 -0
  12. package/build/actions/ActionRegistry.js.map +1 -0
  13. package/build/api/WorkflowApi.d.ts +57 -0
  14. package/build/api/WorkflowApi.js +50 -0
  15. package/build/api/WorkflowApi.js.map +1 -0
  16. package/build/engine/AttributePlanner.d.ts +7 -0
  17. package/build/engine/AttributePlanner.js +81 -0
  18. package/build/engine/AttributePlanner.js.map +1 -0
  19. package/build/engine/GuardEvaluator.d.ts +11 -0
  20. package/build/engine/GuardEvaluator.js +40 -0
  21. package/build/engine/GuardEvaluator.js.map +1 -0
  22. package/build/index.d.ts +45 -0
  23. package/build/index.js +69 -0
  24. package/build/index.js.map +1 -0
  25. package/build/model/TemplateValidation.d.ts +3 -0
  26. package/build/model/TemplateValidation.js +231 -0
  27. package/build/model/TemplateValidation.js.map +1 -0
  28. package/build/model/types.d.ts +116 -0
  29. package/build/model/types.js +15 -0
  30. package/build/model/types.js.map +1 -0
  31. package/build/protocol/WorkflowMessageTypes.d.ts +15 -0
  32. package/build/protocol/WorkflowMessageTypes.js +22 -0
  33. package/build/protocol/WorkflowMessageTypes.js.map +1 -0
  34. package/build/protocol/handlers/AdvanceHandler.d.ts +12 -0
  35. package/build/protocol/handlers/AdvanceHandler.js +113 -0
  36. package/build/protocol/handlers/AdvanceHandler.js.map +1 -0
  37. package/build/protocol/handlers/CancelHandler.d.ts +12 -0
  38. package/build/protocol/handlers/CancelHandler.js +116 -0
  39. package/build/protocol/handlers/CancelHandler.js.map +1 -0
  40. package/build/protocol/handlers/CompleteHandler.d.ts +12 -0
  41. package/build/protocol/handlers/CompleteHandler.js +117 -0
  42. package/build/protocol/handlers/CompleteHandler.js.map +1 -0
  43. package/build/protocol/handlers/DiscoverHandler.d.ts +11 -0
  44. package/build/protocol/handlers/DiscoverHandler.js +71 -0
  45. package/build/protocol/handlers/DiscoverHandler.js.map +1 -0
  46. package/build/protocol/handlers/FetchTemplateHandler.d.ts +12 -0
  47. package/build/protocol/handlers/FetchTemplateHandler.js +71 -0
  48. package/build/protocol/handlers/FetchTemplateHandler.js.map +1 -0
  49. package/build/protocol/handlers/PauseHandler.d.ts +12 -0
  50. package/build/protocol/handlers/PauseHandler.js +116 -0
  51. package/build/protocol/handlers/PauseHandler.js.map +1 -0
  52. package/build/protocol/handlers/ProblemReportHandler.d.ts +6 -0
  53. package/build/protocol/handlers/ProblemReportHandler.js +28 -0
  54. package/build/protocol/handlers/ProblemReportHandler.js.map +1 -0
  55. package/build/protocol/handlers/PublishTemplateHandler.d.ts +11 -0
  56. package/build/protocol/handlers/PublishTemplateHandler.js +53 -0
  57. package/build/protocol/handlers/PublishTemplateHandler.js.map +1 -0
  58. package/build/protocol/handlers/ResumeHandler.d.ts +12 -0
  59. package/build/protocol/handlers/ResumeHandler.js +116 -0
  60. package/build/protocol/handlers/ResumeHandler.js.map +1 -0
  61. package/build/protocol/handlers/StartHandler.d.ts +12 -0
  62. package/build/protocol/handlers/StartHandler.js +211 -0
  63. package/build/protocol/handlers/StartHandler.js.map +1 -0
  64. package/build/protocol/handlers/StatusHandler.d.ts +12 -0
  65. package/build/protocol/handlers/StatusHandler.js +100 -0
  66. package/build/protocol/handlers/StatusHandler.js.map +1 -0
  67. package/build/protocol/handlers/TemplateHandler.d.ts +9 -0
  68. package/build/protocol/handlers/TemplateHandler.js +43 -0
  69. package/build/protocol/handlers/TemplateHandler.js.map +1 -0
  70. package/build/protocol/messages/AdvanceMessage.d.ts +15 -0
  71. package/build/protocol/messages/AdvanceMessage.js +33 -0
  72. package/build/protocol/messages/AdvanceMessage.js.map +1 -0
  73. package/build/protocol/messages/CancelMessage.d.ts +14 -0
  74. package/build/protocol/messages/CancelMessage.js +33 -0
  75. package/build/protocol/messages/CancelMessage.js.map +1 -0
  76. package/build/protocol/messages/CompleteMessage.d.ts +14 -0
  77. package/build/protocol/messages/CompleteMessage.js +33 -0
  78. package/build/protocol/messages/CompleteMessage.js.map +1 -0
  79. package/build/protocol/messages/DiscoverMessage.d.ts +23 -0
  80. package/build/protocol/messages/DiscoverMessage.js +33 -0
  81. package/build/protocol/messages/DiscoverMessage.js.map +1 -0
  82. package/build/protocol/messages/FetchTemplateMessage.d.ts +15 -0
  83. package/build/protocol/messages/FetchTemplateMessage.js +33 -0
  84. package/build/protocol/messages/FetchTemplateMessage.js.map +1 -0
  85. package/build/protocol/messages/PauseMessage.d.ts +14 -0
  86. package/build/protocol/messages/PauseMessage.js +33 -0
  87. package/build/protocol/messages/PauseMessage.js.map +1 -0
  88. package/build/protocol/messages/ProblemReportMessage.d.ts +15 -0
  89. package/build/protocol/messages/ProblemReportMessage.js +33 -0
  90. package/build/protocol/messages/ProblemReportMessage.js.map +1 -0
  91. package/build/protocol/messages/PublishTemplateMessage.d.ts +17 -0
  92. package/build/protocol/messages/PublishTemplateMessage.js +31 -0
  93. package/build/protocol/messages/PublishTemplateMessage.js.map +1 -0
  94. package/build/protocol/messages/ResumeMessage.d.ts +14 -0
  95. package/build/protocol/messages/ResumeMessage.js +33 -0
  96. package/build/protocol/messages/ResumeMessage.js.map +1 -0
  97. package/build/protocol/messages/StartMessage.d.ts +21 -0
  98. package/build/protocol/messages/StartMessage.js +33 -0
  99. package/build/protocol/messages/StartMessage.js.map +1 -0
  100. package/build/protocol/messages/StatusMessage.d.ts +23 -0
  101. package/build/protocol/messages/StatusMessage.js +33 -0
  102. package/build/protocol/messages/StatusMessage.js.map +1 -0
  103. package/build/protocol/messages/StatusRequestMessage.d.ts +15 -0
  104. package/build/protocol/messages/StatusRequestMessage.js +33 -0
  105. package/build/protocol/messages/StatusRequestMessage.js.map +1 -0
  106. package/build/protocol/messages/TemplateMessage.d.ts +14 -0
  107. package/build/protocol/messages/TemplateMessage.js +33 -0
  108. package/build/protocol/messages/TemplateMessage.js.map +1 -0
  109. package/build/protocol/messages/WorkflowsMessage.d.ts +22 -0
  110. package/build/protocol/messages/WorkflowsMessage.js +33 -0
  111. package/build/protocol/messages/WorkflowsMessage.js.map +1 -0
  112. package/build/queue/CommandQueue.d.ts +17 -0
  113. package/build/queue/CommandQueue.js +8 -0
  114. package/build/queue/CommandQueue.js.map +1 -0
  115. package/build/queue/PersistentCommandQueue.d.ts +50 -0
  116. package/build/queue/PersistentCommandQueue.js +265 -0
  117. package/build/queue/PersistentCommandQueue.js.map +1 -0
  118. package/build/repository/WorkflowCommandRecord.d.ts +44 -0
  119. package/build/repository/WorkflowCommandRecord.js +38 -0
  120. package/build/repository/WorkflowCommandRecord.js.map +1 -0
  121. package/build/repository/WorkflowCommandRepository.d.ts +51 -0
  122. package/build/repository/WorkflowCommandRepository.js +135 -0
  123. package/build/repository/WorkflowCommandRepository.js.map +1 -0
  124. package/build/repository/WorkflowInstanceRecord.d.ts +61 -0
  125. package/build/repository/WorkflowInstanceRecord.js +43 -0
  126. package/build/repository/WorkflowInstanceRecord.js.map +1 -0
  127. package/build/repository/WorkflowInstanceRepository.d.ts +10 -0
  128. package/build/repository/WorkflowInstanceRepository.js +52 -0
  129. package/build/repository/WorkflowInstanceRepository.js.map +1 -0
  130. package/build/repository/WorkflowTemplateRecord.d.ts +23 -0
  131. package/build/repository/WorkflowTemplateRecord.js +28 -0
  132. package/build/repository/WorkflowTemplateRecord.js.map +1 -0
  133. package/build/repository/WorkflowTemplateRepository.d.ts +6 -0
  134. package/build/repository/WorkflowTemplateRepository.js +56 -0
  135. package/build/repository/WorkflowTemplateRepository.js.map +1 -0
  136. package/build/services/WorkflowService.d.ts +75 -0
  137. package/build/services/WorkflowService.js +566 -0
  138. package/build/services/WorkflowService.js.map +1 -0
  139. package/package.json +47 -0
@@ -0,0 +1,231 @@
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.validateTemplateJson = validateTemplateJson;
7
+ exports.validateTemplateRefs = validateTemplateRefs;
8
+ const ajv_1 = __importDefault(require("ajv"));
9
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
10
+ const ajv = new ajv_1.default({ allErrors: true, strict: false });
11
+ (0, ajv_formats_1.default)(ajv);
12
+ const schema = {
13
+ type: 'object',
14
+ required: ['template_id', 'version', 'title', 'instance_policy', 'states', 'transitions', 'catalog', 'actions'],
15
+ properties: {
16
+ template_id: { type: 'string', minLength: 1 },
17
+ version: { type: 'string', minLength: 1 },
18
+ title: { type: 'string', minLength: 1 },
19
+ instance_policy: {
20
+ type: 'object',
21
+ required: ['mode'],
22
+ properties: {
23
+ mode: { enum: ['singleton_per_connection', 'multi_per_connection'] },
24
+ multiplicity_key: { type: 'string' },
25
+ },
26
+ additionalProperties: false,
27
+ },
28
+ sections: {
29
+ type: 'array',
30
+ items: {
31
+ type: 'object',
32
+ required: ['name'],
33
+ properties: { name: { type: 'string' }, order: { type: 'number' }, icon: { type: 'string' } },
34
+ additionalProperties: true,
35
+ },
36
+ },
37
+ states: {
38
+ type: 'array',
39
+ minItems: 1,
40
+ items: {
41
+ type: 'object',
42
+ required: ['name', 'type'],
43
+ properties: {
44
+ name: { type: 'string' },
45
+ type: { enum: ['start', 'normal', 'final'] },
46
+ section: { type: 'string' },
47
+ },
48
+ additionalProperties: true,
49
+ },
50
+ },
51
+ transitions: {
52
+ type: 'array',
53
+ items: {
54
+ type: 'object',
55
+ required: ['from', 'to', 'on'],
56
+ properties: {
57
+ from: { type: 'string' },
58
+ to: { type: 'string' },
59
+ on: { type: 'string' },
60
+ guard: { type: 'string' },
61
+ action: { type: 'string' },
62
+ },
63
+ additionalProperties: false,
64
+ },
65
+ },
66
+ catalog: {
67
+ type: 'object',
68
+ properties: {
69
+ credential_profiles: {
70
+ type: 'object',
71
+ additionalProperties: {
72
+ type: 'object',
73
+ required: ['cred_def_id', 'attribute_plan', 'to_ref'],
74
+ properties: {
75
+ cred_def_id: { type: 'string' },
76
+ attribute_plan: {
77
+ type: 'object',
78
+ additionalProperties: {
79
+ anyOf: [
80
+ {
81
+ type: 'object',
82
+ required: ['source', 'path'],
83
+ properties: {
84
+ source: { const: 'context' },
85
+ path: { type: 'string' },
86
+ required: { type: 'boolean' },
87
+ },
88
+ additionalProperties: false,
89
+ },
90
+ {
91
+ type: 'object',
92
+ required: ['source', 'value'],
93
+ properties: { source: { const: 'static' }, value: {}, required: { type: 'boolean' } },
94
+ additionalProperties: false,
95
+ },
96
+ {
97
+ type: 'object',
98
+ required: ['source', 'expr'],
99
+ properties: {
100
+ source: { const: 'compute' },
101
+ expr: { type: 'string' },
102
+ required: { type: 'boolean' },
103
+ },
104
+ additionalProperties: false,
105
+ },
106
+ ],
107
+ },
108
+ },
109
+ to_ref: { type: 'string' },
110
+ options: { type: 'object', additionalProperties: true },
111
+ },
112
+ additionalProperties: false,
113
+ },
114
+ },
115
+ proof_profiles: {
116
+ type: 'object',
117
+ additionalProperties: {
118
+ type: 'object',
119
+ required: ['to_ref'],
120
+ properties: {
121
+ schema_id: { type: 'string' },
122
+ cred_def_id: { type: 'string' },
123
+ requested_attributes: { type: 'array', items: { type: 'string' } },
124
+ requested_predicates: {
125
+ type: 'array',
126
+ items: {
127
+ type: 'object',
128
+ required: ['name', 'p_type', 'p_value'],
129
+ properties: { name: { type: 'string' }, p_type: { type: 'string' }, p_value: { type: 'number' } },
130
+ additionalProperties: false,
131
+ },
132
+ },
133
+ to_ref: { type: 'string' },
134
+ options: { type: 'object', additionalProperties: true },
135
+ },
136
+ additionalProperties: false,
137
+ },
138
+ },
139
+ defaults: { type: 'object' },
140
+ },
141
+ additionalProperties: true,
142
+ },
143
+ actions: {
144
+ type: 'array',
145
+ items: {
146
+ type: 'object',
147
+ required: ['key', 'typeURI'],
148
+ properties: {
149
+ key: { type: 'string' },
150
+ typeURI: { type: 'string' },
151
+ profile_ref: { type: 'string', pattern: '^(cp|pp)\\.' },
152
+ staticInput: {},
153
+ },
154
+ additionalProperties: true,
155
+ },
156
+ },
157
+ display_hints: { type: 'object' },
158
+ },
159
+ additionalProperties: false,
160
+ };
161
+ const validate = ajv.compile(schema);
162
+ function validateTemplateJson(tpl) {
163
+ const ok = validate(tpl);
164
+ if (!ok) {
165
+ const errs = (validate.errors || []);
166
+ const msg = errs.map((e) => `${e.instancePath || 'template'} ${e.message}`).join('; ');
167
+ const err = new Error(msg);
168
+ err.code = 'invalid_template';
169
+ throw err;
170
+ }
171
+ }
172
+ function validateTemplateRefs(t) {
173
+ // Structural checks beyond schema
174
+ const stateNames = new Set(t.states.map((s) => s.name));
175
+ if (![...t.states].some((s) => s.type === 'start')) {
176
+ const err = new Error('start state required');
177
+ err.code = 'invalid_template';
178
+ throw err;
179
+ }
180
+ for (const s of t.states) {
181
+ if (s.section && !t.sections?.some((sec) => sec.name === s.section)) {
182
+ const err = new Error(`state.section not found: ${s.section}`);
183
+ err.code = 'invalid_template';
184
+ throw err;
185
+ }
186
+ }
187
+ for (const tr of t.transitions) {
188
+ if (!stateNames.has(tr.from)) {
189
+ const err = new Error(`transition.from unknown: ${tr.from}`);
190
+ err.code = 'invalid_template';
191
+ throw err;
192
+ }
193
+ if (!stateNames.has(tr.to)) {
194
+ const err = new Error(`transition.to unknown: ${tr.to}`);
195
+ err.code = 'invalid_template';
196
+ throw err;
197
+ }
198
+ if (tr.action && !t.actions.some((a) => a.key === tr.action)) {
199
+ const err = new Error(`transition.action unknown: ${tr.action}`);
200
+ err.code = 'invalid_template';
201
+ throw err;
202
+ }
203
+ }
204
+ for (const a of t.actions) {
205
+ if ('profile_ref' in a) {
206
+ const pr = a.profile_ref;
207
+ if (pr.startsWith('cp.')) {
208
+ const key = pr.slice(3);
209
+ if (!t.catalog?.credential_profiles || !t.catalog.credential_profiles[key]) {
210
+ const err = new Error(`catalog.cp missing: ${key}`);
211
+ err.code = 'invalid_template';
212
+ throw err;
213
+ }
214
+ }
215
+ else if (pr.startsWith('pp.')) {
216
+ const key = pr.slice(3);
217
+ if (!t.catalog?.proof_profiles || !t.catalog.proof_profiles[key]) {
218
+ const err = new Error(`catalog.pp missing: ${key}`);
219
+ err.code = 'invalid_template';
220
+ throw err;
221
+ }
222
+ }
223
+ else if (typeof pr === 'string') {
224
+ const err = new Error(`invalid profile_ref: ${pr}`);
225
+ err.code = 'invalid_template';
226
+ throw err;
227
+ }
228
+ }
229
+ }
230
+ }
231
+ //# sourceMappingURL=TemplateValidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemplateValidation.js","sourceRoot":"","sources":["../../src/model/TemplateValidation.ts"],"names":[],"mappings":";;;;;AAgKA,oDASC;AAED,oDAwDC;AAjOD,8CAAqB;AACrB,8DAAoC;AAEpC,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;AACvD,IAAA,qBAAU,EAAC,GAAG,CAAC,CAAA;AAEf,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,CAAC;IAC/G,UAAU,EAAE;QACV,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;QAC7C,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;Q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AAM,GAAG,CAAA;gBACX,CAAC;YACH,CAAC;iBAAM,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChC,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBACvB,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,cAAc,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;oBACjE,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAClD;oBAAC,GAAiC,CAAC,IAAI,GAAG,kBAAkB,CAAA;oBAC7D,MAAM,GAAG,CAAA;gBACX,CAAC;YACH,CAAC;iBAAM,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;gBAClC,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,wBAAwB,EAAE,EAAE,CAAC,CAClD;gBAAC,GAAiC,CAAC,IAAI,GAAG,kBAAkB,CAAA;gBAC7D,MAAM,GAAG,CAAA;YACX,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,116 @@
1
+ export type InstancePolicy = {
2
+ mode: 'singleton_per_connection' | 'multi_per_connection';
3
+ multiplicity_key?: string;
4
+ };
5
+ export type SectionDef = {
6
+ name: string;
7
+ order?: number;
8
+ icon?: string;
9
+ };
10
+ export type StateDef = {
11
+ name: string;
12
+ type: 'start' | 'normal' | 'final';
13
+ section?: string;
14
+ };
15
+ export type TransitionDef = {
16
+ from: string;
17
+ to: string;
18
+ on: string;
19
+ guard?: string;
20
+ action?: string;
21
+ };
22
+ export type AttributeSpec = {
23
+ source: 'context';
24
+ path: string;
25
+ required?: boolean;
26
+ } | {
27
+ source: 'static';
28
+ value: unknown;
29
+ required?: boolean;
30
+ } | {
31
+ source: 'compute';
32
+ expr: string;
33
+ required?: boolean;
34
+ };
35
+ export type CredentialProfile = {
36
+ cred_def_id: string;
37
+ attribute_plan: Record<string, AttributeSpec>;
38
+ to_ref: string;
39
+ options?: Record<string, unknown>;
40
+ };
41
+ export type ProofProfile = {
42
+ cred_def_id?: string;
43
+ schema_id?: string;
44
+ requested_attributes?: string[];
45
+ requested_predicates?: Array<{
46
+ name: string;
47
+ p_type: string;
48
+ p_value: number;
49
+ }>;
50
+ to_ref: string;
51
+ options?: Record<string, unknown>;
52
+ };
53
+ export type Catalog = {
54
+ credential_profiles?: Record<string, CredentialProfile>;
55
+ proof_profiles?: Record<string, ProofProfile>;
56
+ defaults?: Record<string, unknown>;
57
+ };
58
+ export type ActionDef = {
59
+ key: string;
60
+ typeURI: string;
61
+ profile_ref: string;
62
+ } | {
63
+ key: string;
64
+ typeURI: string;
65
+ staticInput?: unknown;
66
+ };
67
+ export type UiItem = {
68
+ type?: string;
69
+ label?: string;
70
+ event?: string;
71
+ [key: string]: unknown;
72
+ };
73
+ export type DisplayHints = {
74
+ states?: Record<string, UiItem[]>;
75
+ };
76
+ export type WorkflowTemplate = {
77
+ template_id: string;
78
+ version: string;
79
+ title: string;
80
+ instance_policy: InstancePolicy;
81
+ sections?: SectionDef[];
82
+ states: StateDef[];
83
+ transitions: TransitionDef[];
84
+ catalog: Catalog;
85
+ actions: ActionDef[];
86
+ display_hints?: DisplayHints;
87
+ };
88
+ export type Participants = Record<string, {
89
+ did: string;
90
+ }>;
91
+ export type InstanceHistoryItem = {
92
+ ts: string;
93
+ event: string;
94
+ from: string;
95
+ to: string;
96
+ actionKey?: string;
97
+ msg_id?: string;
98
+ };
99
+ export type WorkflowInstanceData = {
100
+ instance_id: string;
101
+ template_id: string;
102
+ template_version: string;
103
+ connection_id?: string;
104
+ participants: Participants;
105
+ state: string;
106
+ section?: string;
107
+ context: Record<string, unknown>;
108
+ artifacts: Record<string, unknown>;
109
+ status: 'active' | 'paused' | 'canceled' | 'completed' | 'error';
110
+ history: InstanceHistoryItem[];
111
+ multiplicityKeyValue?: string;
112
+ idempotencyKeys?: string[];
113
+ };
114
+ export declare const findSectionForState: (tpl: WorkflowTemplate, stateName?: string) => string | undefined;
115
+ export declare const transitionsFromState: (tpl: WorkflowTemplate, state: string) => TransitionDef[];
116
+ export declare const ensureArray: <T>(arr?: T[]) => T[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureArray = exports.transitionsFromState = exports.findSectionForState = void 0;
4
+ const findSectionForState = (tpl, stateName) => {
5
+ if (!stateName)
6
+ return undefined;
7
+ const st = tpl.states.find((s) => s.name === stateName);
8
+ return st?.section;
9
+ };
10
+ exports.findSectionForState = findSectionForState;
11
+ const transitionsFromState = (tpl, state) => tpl.transitions.filter((t) => t.from === state);
12
+ exports.transitionsFromState = transitionsFromState;
13
+ const ensureArray = (arr) => (Array.isArray(arr) ? arr : []);
14
+ exports.ensureArray = ensureArray;
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/model/types.ts"],"names":[],"mappings":";;;AAoGO,MAAM,mBAAmB,GAAG,CAAC,GAAqB,EAAE,SAAkB,EAAsB,EAAE;IACnG,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAA;IAChC,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;IACvD,OAAO,EAAE,EAAE,OAAO,CAAA;AACpB,CAAC,CAAA;AAJY,QAAA,mBAAmB,uBAI/B;AAEM,MAAM,oBAAoB,GAAG,CAAC,GAAqB,EAAE,KAAa,EAAE,EAAE,CAC3E,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAA;AADpC,QAAA,oBAAoB,wBACgB;AAE1C,MAAM,WAAW,GAAG,CAAI,GAAS,EAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAApE,QAAA,WAAW,eAAyD"}
@@ -0,0 +1,15 @@
1
+ export declare const WorkflowMessageType: {
2
+ readonly PublishTemplate: "https://didcomm.org/workflow/1.0/publish-template";
3
+ readonly Start: "https://didcomm.org/workflow/1.0/start";
4
+ readonly Advance: "https://didcomm.org/workflow/1.0/advance";
5
+ readonly Status: "https://didcomm.org/workflow/1.0/status";
6
+ readonly ProblemReport: "https://didcomm.org/workflow/1.0/problem-report";
7
+ readonly Pause: "https://didcomm.org/workflow/1.0/pause";
8
+ readonly Resume: "https://didcomm.org/workflow/1.0/resume";
9
+ readonly Cancel: "https://didcomm.org/workflow/1.0/cancel";
10
+ readonly Complete: "https://didcomm.org/workflow/1.0/complete";
11
+ readonly Discover: "https://didcomm.org/workflow/1.0/discover";
12
+ readonly Workflows: "https://didcomm.org/workflow/1.0/workflows";
13
+ readonly FetchTemplate: "https://didcomm.org/workflow/1.0/fetch-template";
14
+ readonly Template: "https://didcomm.org/workflow/1.0/template";
15
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowMessageType = void 0;
4
+ exports.WorkflowMessageType = {
5
+ PublishTemplate: 'https://didcomm.org/workflow/1.0/publish-template',
6
+ // edit workflow
7
+ // discover workflows based on connection / other filters workflow unlocked discovery of workflow changes
8
+ Start: 'https://didcomm.org/workflow/1.0/start',
9
+ Advance: 'https://didcomm.org/workflow/1.0/advance',
10
+ Status: 'https://didcomm.org/workflow/1.0/status',
11
+ ProblemReport: 'https://didcomm.org/workflow/1.0/problem-report',
12
+ Pause: 'https://didcomm.org/workflow/1.0/pause',
13
+ Resume: 'https://didcomm.org/workflow/1.0/resume',
14
+ Cancel: 'https://didcomm.org/workflow/1.0/cancel',
15
+ Complete: 'https://didcomm.org/workflow/1.0/complete',
16
+ // discovery & fetch extension
17
+ Discover: 'https://didcomm.org/workflow/1.0/discover',
18
+ Workflows: 'https://didcomm.org/workflow/1.0/workflows',
19
+ FetchTemplate: 'https://didcomm.org/workflow/1.0/fetch-template',
20
+ Template: 'https://didcomm.org/workflow/1.0/template',
21
+ };
22
+ //# sourceMappingURL=WorkflowMessageTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowMessageTypes.js","sourceRoot":"","sources":["../../src/protocol/WorkflowMessageTypes.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG;IACjC,eAAe,EAAE,mDAAmD;IACpE,gBAAgB;IAChB,yGAAyG;IACzG,KAAK,EAAE,wCAAwC;IAC/C,OAAO,EAAE,0CAA0C;IACnD,MAAM,EAAE,yCAAyC;IACjD,aAAa,EAAE,iDAAiD;IAChE,KAAK,EAAE,wCAAwC;IAC/C,MAAM,EAAE,yCAAyC;IACjD,MAAM,EAAE,yCAAyC;IACjD,QAAQ,EAAE,2CAA2C;IACrD,8BAA8B;IAC9B,QAAQ,EAAE,2CAA2C;IACrD,SAAS,EAAE,4CAA4C;IACvD,aAAa,EAAE,iDAAiD;IAChE,QAAQ,EAAE,2CAA2C;CAC7C,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core';
2
+ import { OutboundMessageContext } from '@credo-ts/core';
3
+ import { WorkflowService } from '../../services/WorkflowService';
4
+ import { AdvanceMessage } from '../messages/AdvanceMessage';
5
+ import { ProblemReportMessage } from '../messages/ProblemReportMessage';
6
+ import { StatusMessage } from '../messages/StatusMessage';
7
+ export declare class AdvanceHandler implements MessageHandler {
8
+ private readonly service;
9
+ supportedMessages: (typeof AdvanceMessage)[];
10
+ constructor(service: WorkflowService);
11
+ handle(messageContext: MessageHandlerInboundMessage<AdvanceHandler>): Promise<OutboundMessageContext<StatusMessage> | OutboundMessageContext<ProblemReportMessage>>;
12
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AdvanceHandler = void 0;
13
+ const core_1 = require("@credo-ts/core");
14
+ const WorkflowModuleConfig_1 = require("../../WorkflowModuleConfig");
15
+ const CommandQueue_1 = require("../../queue/CommandQueue");
16
+ const WorkflowService_1 = require("../../services/WorkflowService");
17
+ const AdvanceMessage_1 = require("../messages/AdvanceMessage");
18
+ const ProblemReportMessage_1 = require("../messages/ProblemReportMessage");
19
+ const StatusMessage_1 = require("../messages/StatusMessage");
20
+ const WorkflowInstanceRepository_1 = require("../../repository/WorkflowInstanceRepository");
21
+ let AdvanceHandler = class AdvanceHandler {
22
+ constructor(service) {
23
+ this.service = service;
24
+ this.supportedMessages = [AdvanceMessage_1.AdvanceMessage];
25
+ }
26
+ async handle(messageContext) {
27
+ const dm = messageContext.agentContext.dependencyManager;
28
+ const logger = dm.resolve(core_1.AgentConfig).logger;
29
+ const config = dm.resolve(WorkflowModuleConfig_1.WorkflowModuleConfig);
30
+ const thid = messageContext.message.threadId || messageContext.message.id;
31
+ const { instance_id, event } = messageContext.message.body || {};
32
+ logger.info('[Workflow] advance received', { instance_id, event, thid });
33
+ // Strict correlation: thid MUST equal instance_id
34
+ try {
35
+ const _id = messageContext.message.body?.instance_id;
36
+ if (_id && thid && _id !== thid) {
37
+ throw Object.assign(new Error('threadId does not match instance_id'), { code: 'correlation_mismatch' });
38
+ }
39
+ }
40
+ catch (_e) {
41
+ void 0;
42
+ }
43
+ try {
44
+ // Enforce inbound connection matches instance binding
45
+ const inboundConnId = messageContext.connection?.id;
46
+ const instId = messageContext.message.body?.instance_id;
47
+ if (!inboundConnId || !instId) {
48
+ throw Object.assign(new Error('missing inbound connection'), { code: 'forbidden' });
49
+ }
50
+ const repo = messageContext.agentContext.dependencyManager.resolve(WorkflowInstanceRepository_1.WorkflowInstanceRepository);
51
+ const inst = await repo.getByInstanceId(messageContext.agentContext, instId);
52
+ if (!inst) {
53
+ throw Object.assign(new Error('instance not found'), { code: 'invalid_event' });
54
+ }
55
+ if (inst.connectionId && inst.connectionId !== inboundConnId) {
56
+ throw Object.assign(new Error('connection mismatch'), { code: 'forbidden' });
57
+ }
58
+ // Enqueue command for async processing (always async now)
59
+ const queue = dm.resolve(CommandQueue_1.CommandQueueService);
60
+ if (queue && typeof queue.enqueue === 'function' && typeof queue.isReady === 'function') {
61
+ const ready = await queue.isReady();
62
+ if (ready) {
63
+ await queue.enqueue(messageContext.agentContext, {
64
+ cmd: 'advance',
65
+ thid: instId,
66
+ connectionId: inboundConnId,
67
+ idempotency_key: messageContext.message.body?.idempotency_key,
68
+ payload: messageContext.message.body,
69
+ contextCorrelationId: messageContext.agentContext.contextCorrelationId,
70
+ });
71
+ // Immediate response with CURRENT state (before processing)
72
+ const status = await this.service.status(messageContext.agentContext, { instance_id: instId }, inst);
73
+ const reply = new StatusMessage_1.StatusMessage({ thid, body: status });
74
+ return new core_1.OutboundMessageContext(reply, {
75
+ agentContext: messageContext.agentContext,
76
+ inboundMessageContext: messageContext,
77
+ connection: messageContext.connection,
78
+ });
79
+ }
80
+ }
81
+ // Fallback: queue not available, process synchronously
82
+ logger.warn('[Workflow] Queue not available, processing synchronously');
83
+ const updated = await this.service.advance(messageContext.agentContext, messageContext.message.body, inst);
84
+ const status = await this.service.status(messageContext.agentContext, { instance_id: instId }, updated);
85
+ const reply = new StatusMessage_1.StatusMessage({ thid, body: status });
86
+ return new core_1.OutboundMessageContext(reply, {
87
+ agentContext: messageContext.agentContext,
88
+ inboundMessageContext: messageContext,
89
+ connection: messageContext.connection,
90
+ });
91
+ }
92
+ catch (e) {
93
+ if (config.enableProblemReport && messageContext.connection) {
94
+ const pr = new ProblemReportMessage_1.ProblemReportMessage({
95
+ thid: messageContext.message.threadId || messageContext.message.id,
96
+ body: { code: e.code || 'action_error', comment: e.message },
97
+ });
98
+ return new core_1.OutboundMessageContext(pr, {
99
+ agentContext: messageContext.agentContext,
100
+ inboundMessageContext: messageContext,
101
+ connection: messageContext.connection,
102
+ });
103
+ }
104
+ throw e;
105
+ }
106
+ }
107
+ };
108
+ exports.AdvanceHandler = AdvanceHandler;
109
+ exports.AdvanceHandler = AdvanceHandler = __decorate([
110
+ (0, core_1.injectable)(),
111
+ __metadata("design:paramtypes", [WorkflowService_1.WorkflowService])
112
+ ], AdvanceHandler);
113
+ //# sourceMappingURL=AdvanceHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdvanceHandler.js","sourceRoot":"","sources":["../../../src/protocol/handlers/AdvanceHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,yCAAgF;AAEhF,qEAAiE;AACjE,2DAA8D;AAC9D,oEAAgE;AAChE,+DAA2D;AAC3D,2EAAuE;AACvE,6DAAyD;AACzD,4FAAwF;AAGjF,IAAM,cAAc,GAApB,MAAM,cAAc;IAEzB,YAAoC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QADrD,sBAAiB,GAAG,CAAC,+BAAc,CAAC,CAAA;IACoB,CAAC;IACzD,KAAK,CAAC,MAAM,CAAC,cAA4D;QAC9E,MAAM,EAAE,GAAG,cAAc,CAAC,YAAY,CAAC,iBAAiB,CAAA;QACxD,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,kBAAW,CAAC,CAAC,MAAM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;iBAC/F,CAAC,CAAA;gBACF,OAAO,IAAI,6BAAsB,CAAC,EAAE,EAAE;oBACpC,YAAY,EAAE,cAAc,CAAC,YAAY;oBACzC,qBAAqB,EAAE,cAAc;oBACrC,UAAU,EAAE,cAAc,CAAC,UAAU;iBACtC,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;CACF,CAAA;AA3FY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,iBAAU,GAAE;qCAGkC,iCAAe;GAFjD,cAAc,CA2F1B"}
@@ -0,0 +1,12 @@
1
+ import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core';
2
+ import { OutboundMessageContext } from '@credo-ts/core';
3
+ import { WorkflowService } from '../../services/WorkflowService';
4
+ import { CancelMessage } from '../messages/CancelMessage';
5
+ import { ProblemReportMessage } from '../messages/ProblemReportMessage';
6
+ import { StatusMessage } from '../messages/StatusMessage';
7
+ export declare class CancelHandler implements MessageHandler {
8
+ private readonly service;
9
+ supportedMessages: (typeof CancelMessage)[];
10
+ constructor(service: WorkflowService);
11
+ handle(messageContext: MessageHandlerInboundMessage<CancelHandler>): Promise<OutboundMessageContext<StatusMessage> | OutboundMessageContext<ProblemReportMessage> | undefined>;
12
+ }