@openhi/constructs 0.0.105 → 0.0.107
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/lib/chunk-36UPY7YQ.mjs +529 -0
- package/lib/chunk-36UPY7YQ.mjs.map +1 -0
- package/lib/chunk-AGF3RAAZ.mjs +20 -0
- package/lib/chunk-AGF3RAAZ.mjs.map +1 -0
- package/lib/{chunk-BXEG7IOZ.mjs → chunk-AO3E22CS.mjs} +2 -2
- package/lib/{chunk-WNUH2WDZ.mjs → chunk-CHPEQRXU.mjs} +2 -2
- package/lib/chunk-JUNL76HF.mjs +428 -0
- package/lib/chunk-JUNL76HF.mjs.map +1 -0
- package/lib/chunk-L6UAP4KP.mjs +27 -0
- package/lib/chunk-L6UAP4KP.mjs.map +1 -0
- package/lib/{chunk-3QS3WKRC.mjs → chunk-LZOMFHX3.mjs} +9 -2
- package/lib/chunk-SYBADQXI.mjs +607 -0
- package/lib/chunk-SYBADQXI.mjs.map +1 -0
- package/lib/chunk-VXX4I3EF.mjs +19 -0
- package/lib/chunk-VXX4I3EF.mjs.map +1 -0
- package/lib/{chunk-36YCDLLA.mjs → chunk-VYDIGFIX.mjs} +75 -481
- package/lib/chunk-VYDIGFIX.mjs.map +1 -0
- package/lib/chunk-YU2HRNUP.mjs +33 -0
- package/lib/chunk-YU2HRNUP.mjs.map +1 -0
- package/lib/chunk-YZZDUJHI.mjs +37 -0
- package/lib/chunk-YZZDUJHI.mjs.map +1 -0
- package/lib/cors-options-lambda.handler.mjs +1 -1
- package/lib/data-store-postgres-replication.handler.mjs +1 -1
- package/lib/events-BfrkMoBD.d.mts +44 -0
- package/lib/events-BfrkMoBD.d.ts +44 -0
- package/lib/events-DPodvl07.d.mts +207 -0
- package/lib/events-DPodvl07.d.ts +207 -0
- package/lib/firehose-archive-transform.handler.mjs +1 -1
- package/lib/index.d.mts +417 -9
- package/lib/index.d.ts +663 -10
- package/lib/index.js +2398 -111
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +779 -104
- package/lib/index.mjs.map +1 -1
- package/lib/openhi-context-CaBH8SFo.d.mts +39 -0
- package/lib/openhi-context-CaBH8SFo.d.ts +39 -0
- package/lib/platform-deploy-bridge.handler.d.mts +14 -0
- package/lib/platform-deploy-bridge.handler.d.ts +14 -0
- package/lib/platform-deploy-bridge.handler.js +762 -0
- package/lib/platform-deploy-bridge.handler.js.map +1 -0
- package/lib/platform-deploy-bridge.handler.mjs +134 -0
- package/lib/platform-deploy-bridge.handler.mjs.map +1 -0
- package/lib/post-authentication.handler.mjs +1 -1
- package/lib/post-confirmation.handler.mjs +1 -1
- package/lib/pre-token-generation.handler.js +76 -31
- package/lib/pre-token-generation.handler.js.map +1 -1
- package/lib/pre-token-generation.handler.mjs +5 -3
- package/lib/pre-token-generation.handler.mjs.map +1 -1
- package/lib/provision-default-workspace.handler.js +86 -41
- package/lib/provision-default-workspace.handler.js.map +1 -1
- package/lib/provision-default-workspace.handler.mjs +6 -4
- package/lib/provision-default-workspace.handler.mjs.map +1 -1
- package/lib/rest-api-lambda.handler.js +114 -59
- package/lib/rest-api-lambda.handler.js.map +1 -1
- package/lib/rest-api-lambda.handler.mjs +40 -61
- package/lib/rest-api-lambda.handler.mjs.map +1 -1
- package/lib/seed-demo-data.handler.d.mts +107 -0
- package/lib/seed-demo-data.handler.d.ts +107 -0
- package/lib/seed-demo-data.handler.js +2037 -0
- package/lib/seed-demo-data.handler.js.map +1 -0
- package/lib/seed-demo-data.handler.mjs +23 -0
- package/lib/seed-demo-data.handler.mjs.map +1 -0
- package/lib/seed-system-data.handler.d.mts +64 -0
- package/lib/seed-system-data.handler.d.ts +64 -0
- package/lib/seed-system-data.handler.js +1631 -0
- package/lib/seed-system-data.handler.js.map +1 -0
- package/lib/seed-system-data.handler.mjs +135 -0
- package/lib/seed-system-data.handler.mjs.map +1 -0
- package/package.json +4 -2
- package/lib/chunk-36YCDLLA.mjs.map +0 -1
- /package/lib/{chunk-BXEG7IOZ.mjs.map → chunk-AO3E22CS.mjs.map} +0 -0
- /package/lib/{chunk-WNUH2WDZ.mjs.map → chunk-CHPEQRXU.mjs.map} +0 -0
- /package/lib/{chunk-3QS3WKRC.mjs.map → chunk-LZOMFHX3.mjs.map} +0 -0
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS,
|
|
3
|
+
__require
|
|
4
|
+
} from "./chunk-LZOMFHX3.mjs";
|
|
5
|
+
|
|
6
|
+
// ../workflows/lib/envelope-version.js
|
|
7
|
+
var require_envelope_version = __commonJS({
|
|
8
|
+
"../workflows/lib/envelope-version.js"(exports) {
|
|
9
|
+
"use strict";
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ENVELOPE_VERSION = void 0;
|
|
12
|
+
exports.isSupportedEnvelopeVersion = isSupportedEnvelopeVersion;
|
|
13
|
+
exports.ENVELOPE_VERSION = "1.0";
|
|
14
|
+
var ENVELOPE_VERSION_PATTERN = /^\d+\.\d+$/;
|
|
15
|
+
var MIN_SUPPORTED_MAJOR = 1;
|
|
16
|
+
var MAX_SUPPORTED_MAJOR = 1;
|
|
17
|
+
function isSupportedEnvelopeVersion(version) {
|
|
18
|
+
if (!ENVELOPE_VERSION_PATTERN.test(version)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const major = Number.parseInt(version.split(".")[0], 10);
|
|
22
|
+
return major >= MIN_SUPPORTED_MAJOR && major <= MAX_SUPPORTED_MAJOR;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// ../workflows/lib/envelope.js
|
|
28
|
+
var require_envelope = __commonJS({
|
|
29
|
+
"../workflows/lib/envelope.js"(exports) {
|
|
30
|
+
"use strict";
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.MissingActorContextError = void 0;
|
|
33
|
+
exports.isWorkflowUserActor = isWorkflowUserActor;
|
|
34
|
+
exports.isWorkflowSystemActor = isWorkflowSystemActor;
|
|
35
|
+
exports.workflowUserActorFromClaims = workflowUserActorFromClaims;
|
|
36
|
+
function isWorkflowUserActor(actor) {
|
|
37
|
+
return actor.ohi_uid !== void 0;
|
|
38
|
+
}
|
|
39
|
+
function isWorkflowSystemActor(actor) {
|
|
40
|
+
return actor.system !== void 0;
|
|
41
|
+
}
|
|
42
|
+
function workflowUserActorFromClaims(claims) {
|
|
43
|
+
if (claims.ohi_tid === void 0 || claims.ohi_wid === void 0) {
|
|
44
|
+
throw new MissingActorContextError("workflowUserActorFromClaims: ohi_tid and ohi_wid are required on the workflow user-actor; the caller's JWT is missing one or both. Use a system-actor for pre-provisioning bootstrap workflows.");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
ohi_tid: claims.ohi_tid,
|
|
48
|
+
ohi_wid: claims.ohi_wid,
|
|
49
|
+
ohi_uid: claims.ohi_uid,
|
|
50
|
+
ohi_uname: claims.ohi_uname
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var MissingActorContextError = class extends Error {
|
|
54
|
+
/** @param message - human-readable description of the missing claim. */
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = "MissingActorContextError";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.MissingActorContextError = MissingActorContextError;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ../workflows/lib/sources.js
|
|
65
|
+
var require_sources = __commonJS({
|
|
66
|
+
"../workflows/lib/sources.js"(exports) {
|
|
67
|
+
"use strict";
|
|
68
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
+
exports.DEFAULT_BUS_NAME_BY_SOURCE = exports.OPENHI_OPS_SOURCE = exports.OPENHI_DATA_SOURCE = exports.OPENHI_CONTROL_SOURCE = void 0;
|
|
70
|
+
exports.OPENHI_CONTROL_SOURCE = "openhi.control";
|
|
71
|
+
exports.OPENHI_DATA_SOURCE = "openhi.data";
|
|
72
|
+
exports.OPENHI_OPS_SOURCE = "openhi.ops";
|
|
73
|
+
exports.DEFAULT_BUS_NAME_BY_SOURCE = {
|
|
74
|
+
[exports.OPENHI_CONTROL_SOURCE]: "openhi-control-event-bus",
|
|
75
|
+
[exports.OPENHI_DATA_SOURCE]: "openhi-data-event-bus",
|
|
76
|
+
[exports.OPENHI_OPS_SOURCE]: "openhi-ops-event-bus"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// ../workflows/lib/detail-types/registry.js
|
|
82
|
+
var require_registry = __commonJS({
|
|
83
|
+
"../workflows/lib/detail-types/registry.js"(exports) {
|
|
84
|
+
"use strict";
|
|
85
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
+
exports.InvalidDetailTypeRegistrationError = void 0;
|
|
87
|
+
exports.defineDetailType = defineDetailType;
|
|
88
|
+
exports.isWellFormedDetailType = isWellFormedDetailType;
|
|
89
|
+
function defineDetailType(entry) {
|
|
90
|
+
if (!isWellFormedDetailType(entry.detailType)) {
|
|
91
|
+
throw new InvalidDetailTypeRegistrationError(`Detail-type "${entry.detailType}" does not match the platform-wide format <area>.<event>.v<integer>. See TR-016 \xA7Open Items #2.`);
|
|
92
|
+
}
|
|
93
|
+
return entry;
|
|
94
|
+
}
|
|
95
|
+
var DETAIL_TYPE_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*\.[a-z0-9]+(?:-[a-z0-9]+)*\.v\d+$/;
|
|
96
|
+
function isWellFormedDetailType(detailType) {
|
|
97
|
+
return DETAIL_TYPE_PATTERN.test(detailType);
|
|
98
|
+
}
|
|
99
|
+
var InvalidDetailTypeRegistrationError = class extends Error {
|
|
100
|
+
/** @param message - human-readable description of the violation. */
|
|
101
|
+
constructor(message) {
|
|
102
|
+
super(message);
|
|
103
|
+
this.name = "InvalidDetailTypeRegistrationError";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
exports.InvalidDetailTypeRegistrationError = InvalidDetailTypeRegistrationError;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// ../workflows/lib/detail-types/platform.js
|
|
111
|
+
var require_platform = __commonJS({
|
|
112
|
+
"../workflows/lib/detail-types/platform.js"(exports) {
|
|
113
|
+
"use strict";
|
|
114
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
115
|
+
exports.PlatformSystemDataSeededV1 = exports.PlatformDeploymentCompletedV1 = void 0;
|
|
116
|
+
var sources_1 = require_sources();
|
|
117
|
+
var registry_1 = require_registry();
|
|
118
|
+
exports.PlatformDeploymentCompletedV1 = (0, registry_1.defineDetailType)({
|
|
119
|
+
detailType: "platform.deployment-completed.v1",
|
|
120
|
+
source: sources_1.OPENHI_CONTROL_SOURCE,
|
|
121
|
+
dedupRequired: true
|
|
122
|
+
});
|
|
123
|
+
exports.PlatformSystemDataSeededV1 = (0, registry_1.defineDetailType)({
|
|
124
|
+
detailType: "platform.system-data-seeded.v1",
|
|
125
|
+
source: sources_1.OPENHI_CONTROL_SOURCE,
|
|
126
|
+
dedupRequired: true
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// ../workflows/lib/detail-types/index.js
|
|
132
|
+
var require_detail_types = __commonJS({
|
|
133
|
+
"../workflows/lib/detail-types/index.js"(exports) {
|
|
134
|
+
"use strict";
|
|
135
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
136
|
+
if (k2 === void 0) k2 = k;
|
|
137
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
138
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
139
|
+
desc = { enumerable: true, get: function() {
|
|
140
|
+
return m[k];
|
|
141
|
+
} };
|
|
142
|
+
}
|
|
143
|
+
Object.defineProperty(o, k2, desc);
|
|
144
|
+
}) : (function(o, m, k, k2) {
|
|
145
|
+
if (k2 === void 0) k2 = k;
|
|
146
|
+
o[k2] = m[k];
|
|
147
|
+
}));
|
|
148
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
149
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
|
|
150
|
+
};
|
|
151
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
152
|
+
__exportStar(require_platform(), exports);
|
|
153
|
+
__exportStar(require_registry(), exports);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// ../workflows/lib/publisher.js
|
|
158
|
+
var require_publisher = __commonJS({
|
|
159
|
+
"../workflows/lib/publisher.js"(exports) {
|
|
160
|
+
"use strict";
|
|
161
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
162
|
+
exports.WorkflowPublishError = void 0;
|
|
163
|
+
exports.workflowsClient = workflowsClient;
|
|
164
|
+
exports.publishWorkflowEvent = publishWorkflowEvent;
|
|
165
|
+
var node_crypto_1 = __require("crypto");
|
|
166
|
+
var client_eventbridge_1 = __require("@aws-sdk/client-eventbridge");
|
|
167
|
+
var envelope_version_1 = require_envelope_version();
|
|
168
|
+
var sources_1 = require_sources();
|
|
169
|
+
function workflowsClient(bridge, options = {}) {
|
|
170
|
+
return {
|
|
171
|
+
publish: (entry, payload, ctx) => publishWorkflowEvent(bridge, entry, payload, ctx, options)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async function publishWorkflowEvent(bridge, entry, payload, ctx, options = {}) {
|
|
175
|
+
const eventIdGenerator = options.eventIdGenerator ?? (() => (0, node_crypto_1.randomUUID)());
|
|
176
|
+
const correlationIdGenerator = options.correlationIdGenerator ?? (() => (0, node_crypto_1.randomUUID)());
|
|
177
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
178
|
+
const envelope = {
|
|
179
|
+
eventId: eventIdGenerator(),
|
|
180
|
+
attempt: 1,
|
|
181
|
+
correlationId: ctx.correlationId ?? correlationIdGenerator(),
|
|
182
|
+
causationId: ctx.causationId ?? null,
|
|
183
|
+
actor: ctx.actor,
|
|
184
|
+
occurredAt: now().toISOString(),
|
|
185
|
+
envelopeVersion: envelope_version_1.ENVELOPE_VERSION,
|
|
186
|
+
payload
|
|
187
|
+
};
|
|
188
|
+
const busName = options.busNameByPlane?.[entry.source] ?? sources_1.DEFAULT_BUS_NAME_BY_SOURCE[entry.source];
|
|
189
|
+
const result = await bridge.send(new client_eventbridge_1.PutEventsCommand({
|
|
190
|
+
Entries: [
|
|
191
|
+
{
|
|
192
|
+
EventBusName: busName,
|
|
193
|
+
Source: entry.source,
|
|
194
|
+
DetailType: entry.detailType,
|
|
195
|
+
Detail: JSON.stringify(envelope)
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
}));
|
|
199
|
+
if ((result.FailedEntryCount ?? 0) > 0) {
|
|
200
|
+
const first = result.Entries?.[0];
|
|
201
|
+
throw new WorkflowPublishError(`EventBridge rejected ${entry.detailType} publish on bus ${busName}: ${first?.ErrorCode ?? "unknown"} \u2014 ${first?.ErrorMessage ?? "no error message"}`);
|
|
202
|
+
}
|
|
203
|
+
return { eventId: envelope.eventId };
|
|
204
|
+
}
|
|
205
|
+
var WorkflowPublishError = class extends Error {
|
|
206
|
+
/** @param message - human-readable description of the failed publish. */
|
|
207
|
+
constructor(message) {
|
|
208
|
+
super(message);
|
|
209
|
+
this.name = "WorkflowPublishError";
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
exports.WorkflowPublishError = WorkflowPublishError;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// ../workflows/lib/consumer.js
|
|
217
|
+
var require_consumer = __commonJS({
|
|
218
|
+
"../workflows/lib/consumer.js"(exports) {
|
|
219
|
+
"use strict";
|
|
220
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
221
|
+
exports.UnsupportedEnvelopeVersionError = exports.InvalidWorkflowEventError = void 0;
|
|
222
|
+
exports.parseWorkflowEvent = parseWorkflowEvent;
|
|
223
|
+
var envelope_version_1 = require_envelope_version();
|
|
224
|
+
function parseWorkflowEvent(event, expected) {
|
|
225
|
+
if (event.source !== expected.source) {
|
|
226
|
+
throw new InvalidWorkflowEventError(`EventBridge source "${event.source}" does not match expected detail-type's source "${expected.source}".`);
|
|
227
|
+
}
|
|
228
|
+
if (event["detail-type"] !== expected.detailType) {
|
|
229
|
+
throw new InvalidWorkflowEventError(`EventBridge detail-type "${event["detail-type"]}" does not match expected "${expected.detailType}".`);
|
|
230
|
+
}
|
|
231
|
+
const candidate = asEnvelopeCandidate(event.detail);
|
|
232
|
+
if (!(0, envelope_version_1.isSupportedEnvelopeVersion)(candidate.envelopeVersion)) {
|
|
233
|
+
throw new UnsupportedEnvelopeVersionError(`Envelope version "${candidate.envelopeVersion}" is outside the SDK's supported range.`);
|
|
234
|
+
}
|
|
235
|
+
const envelope = {
|
|
236
|
+
eventId: candidate.eventId,
|
|
237
|
+
attempt: candidate.attempt,
|
|
238
|
+
correlationId: candidate.correlationId,
|
|
239
|
+
causationId: candidate.causationId,
|
|
240
|
+
actor: candidate.actor,
|
|
241
|
+
occurredAt: candidate.occurredAt,
|
|
242
|
+
envelopeVersion: candidate.envelopeVersion,
|
|
243
|
+
payload: candidate.payload
|
|
244
|
+
};
|
|
245
|
+
return {
|
|
246
|
+
envelope,
|
|
247
|
+
dedupKey: { eventId: envelope.eventId, attempt: envelope.attempt }
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function asEnvelopeCandidate(detail) {
|
|
251
|
+
if (detail === null || typeof detail !== "object") {
|
|
252
|
+
throw new InvalidWorkflowEventError("EventBridge detail is not a non-null object.");
|
|
253
|
+
}
|
|
254
|
+
const obj = detail;
|
|
255
|
+
assertString(obj, "eventId");
|
|
256
|
+
assertPositiveInteger(obj, "attempt");
|
|
257
|
+
assertString(obj, "correlationId");
|
|
258
|
+
assertCausationId(obj);
|
|
259
|
+
assertActor(obj);
|
|
260
|
+
assertString(obj, "occurredAt");
|
|
261
|
+
assertString(obj, "envelopeVersion");
|
|
262
|
+
if (!("payload" in obj)) {
|
|
263
|
+
throw new InvalidWorkflowEventError("Envelope is missing required field: payload.");
|
|
264
|
+
}
|
|
265
|
+
return obj;
|
|
266
|
+
}
|
|
267
|
+
function assertString(obj, field) {
|
|
268
|
+
const value = obj[field];
|
|
269
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
270
|
+
throw new InvalidWorkflowEventError(`Envelope field "${field}" must be a non-empty string.`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function assertPositiveInteger(obj, field) {
|
|
274
|
+
const value = obj[field];
|
|
275
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
276
|
+
throw new InvalidWorkflowEventError(`Envelope field "${field}" must be a 1-indexed integer.`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function assertCausationId(obj) {
|
|
280
|
+
if (!("causationId" in obj)) {
|
|
281
|
+
throw new InvalidWorkflowEventError("Envelope is missing required field: causationId.");
|
|
282
|
+
}
|
|
283
|
+
const value = obj.causationId;
|
|
284
|
+
if (value !== null && (typeof value !== "string" || value.length === 0)) {
|
|
285
|
+
throw new InvalidWorkflowEventError('Envelope field "causationId" must be a non-empty string or null.');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function assertActor(obj) {
|
|
289
|
+
const actor = obj.actor;
|
|
290
|
+
if (actor === null || typeof actor !== "object") {
|
|
291
|
+
throw new InvalidWorkflowEventError('Envelope field "actor" must be an object.');
|
|
292
|
+
}
|
|
293
|
+
const actorObj = actor;
|
|
294
|
+
const isUserActor = typeof actorObj.ohi_uid === "string" && typeof actorObj.ohi_uname === "string" && typeof actorObj.ohi_tid === "string" && typeof actorObj.ohi_wid === "string";
|
|
295
|
+
const isSystemActor = typeof actorObj.system === "string";
|
|
296
|
+
if (!isUserActor && !isSystemActor) {
|
|
297
|
+
throw new InvalidWorkflowEventError('Envelope field "actor" must be either a user-actor (ohi_tid, ohi_wid, ohi_uid, ohi_uname) or a system-actor ({ system: string }).');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
var InvalidWorkflowEventError = class extends Error {
|
|
301
|
+
/** @param message - human-readable description of the validation failure. */
|
|
302
|
+
constructor(message) {
|
|
303
|
+
super(message);
|
|
304
|
+
this.name = "InvalidWorkflowEventError";
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
exports.InvalidWorkflowEventError = InvalidWorkflowEventError;
|
|
308
|
+
var UnsupportedEnvelopeVersionError = class extends Error {
|
|
309
|
+
/** @param message - human-readable description of the unsupported version. */
|
|
310
|
+
constructor(message) {
|
|
311
|
+
super(message);
|
|
312
|
+
this.name = "UnsupportedEnvelopeVersionError";
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
exports.UnsupportedEnvelopeVersionError = UnsupportedEnvelopeVersionError;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// ../workflows/lib/dedup/env.js
|
|
320
|
+
var require_env = __commonJS({
|
|
321
|
+
"../workflows/lib/dedup/env.js"(exports) {
|
|
322
|
+
"use strict";
|
|
323
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
324
|
+
exports.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH = exports.WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS = exports.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR = void 0;
|
|
325
|
+
exports.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR = "OPENHI_WORKFLOW_DEDUP_TABLE_NAME";
|
|
326
|
+
exports.WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS = 14 * 24 * 60 * 60;
|
|
327
|
+
exports.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH = 64;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// ../workflows/lib/dedup/workflow-dedup-client.js
|
|
332
|
+
var require_workflow_dedup_client = __commonJS({
|
|
333
|
+
"../workflows/lib/dedup/workflow-dedup-client.js"(exports) {
|
|
334
|
+
"use strict";
|
|
335
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
336
|
+
exports.WorkflowDedupInvalidInputError = exports.WorkflowDedupTableNameMissingError = void 0;
|
|
337
|
+
exports.workflowDedupClient = workflowDedupClient;
|
|
338
|
+
exports.recordIfAbsent = recordIfAbsent;
|
|
339
|
+
exports.markFailed = markFailed;
|
|
340
|
+
exports.encodeSortKey = encodeSortKey;
|
|
341
|
+
var client_dynamodb_1 = __require("@aws-sdk/client-dynamodb");
|
|
342
|
+
var env_1 = require_env();
|
|
343
|
+
function workflowDedupClient(dynamodb, options = {}) {
|
|
344
|
+
return {
|
|
345
|
+
recordIfAbsent: (input) => recordIfAbsent(dynamodb, input, options),
|
|
346
|
+
markFailed: (input) => markFailed(dynamodb, input, options)
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
async function recordIfAbsent(dynamodb, input, options = {}) {
|
|
350
|
+
assertConsumerName(input.consumerName);
|
|
351
|
+
assertPositiveInteger(input.attempt, "attempt");
|
|
352
|
+
const ttlSeconds = input.ttlSeconds ?? options.defaultTtlSeconds ?? env_1.WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS;
|
|
353
|
+
if (!Number.isInteger(ttlSeconds) || ttlSeconds <= 0) {
|
|
354
|
+
throw new WorkflowDedupInvalidInputError(`ttlSeconds must be a positive integer; got ${ttlSeconds}.`);
|
|
355
|
+
}
|
|
356
|
+
const tableName = resolveTableName(options.tableName);
|
|
357
|
+
const now = (options.now ?? defaultNow)();
|
|
358
|
+
const sk = encodeSortKey(input.eventId, input.attempt);
|
|
359
|
+
const expiresAt = Math.floor(now.getTime() / 1e3) + ttlSeconds;
|
|
360
|
+
try {
|
|
361
|
+
await dynamodb.send(new client_dynamodb_1.PutItemCommand({
|
|
362
|
+
TableName: tableName,
|
|
363
|
+
Item: {
|
|
364
|
+
consumerName: { S: input.consumerName },
|
|
365
|
+
sk: { S: sk },
|
|
366
|
+
eventId: { S: input.eventId },
|
|
367
|
+
attempt: { N: String(input.attempt) },
|
|
368
|
+
recordedAt: { S: now.toISOString() },
|
|
369
|
+
expiresAt: { N: String(expiresAt) }
|
|
370
|
+
},
|
|
371
|
+
ConditionExpression: "attribute_not_exists(consumerName) AND attribute_not_exists(sk)"
|
|
372
|
+
}));
|
|
373
|
+
return { recorded: true };
|
|
374
|
+
} catch (err) {
|
|
375
|
+
if (err instanceof client_dynamodb_1.ConditionalCheckFailedException) {
|
|
376
|
+
return { recorded: false, alreadyProcessed: true };
|
|
377
|
+
}
|
|
378
|
+
throw err;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
async function markFailed(dynamodb, input, options = {}) {
|
|
382
|
+
assertConsumerName(input.consumerName);
|
|
383
|
+
assertPositiveInteger(input.attempt, "attempt");
|
|
384
|
+
if (input.reason.length === 0) {
|
|
385
|
+
throw new WorkflowDedupInvalidInputError("reason must be non-empty.");
|
|
386
|
+
}
|
|
387
|
+
const tableName = resolveTableName(options.tableName);
|
|
388
|
+
const now = (options.now ?? defaultNow)();
|
|
389
|
+
const sk = encodeSortKey(input.eventId, input.attempt);
|
|
390
|
+
await dynamodb.send(new client_dynamodb_1.UpdateItemCommand({
|
|
391
|
+
TableName: tableName,
|
|
392
|
+
Key: {
|
|
393
|
+
consumerName: { S: input.consumerName },
|
|
394
|
+
sk: { S: sk }
|
|
395
|
+
},
|
|
396
|
+
UpdateExpression: "SET #failed = :failed, #failureReason = :reason, #failedAt = :failedAt",
|
|
397
|
+
ExpressionAttributeNames: {
|
|
398
|
+
"#failed": "failed",
|
|
399
|
+
"#failureReason": "failureReason",
|
|
400
|
+
"#failedAt": "failedAt"
|
|
401
|
+
},
|
|
402
|
+
ExpressionAttributeValues: {
|
|
403
|
+
":failed": { BOOL: true },
|
|
404
|
+
":reason": { S: input.reason },
|
|
405
|
+
":failedAt": { S: now.toISOString() }
|
|
406
|
+
}
|
|
407
|
+
}));
|
|
408
|
+
}
|
|
409
|
+
function encodeSortKey(eventId, attempt) {
|
|
410
|
+
if (eventId.length === 0) {
|
|
411
|
+
throw new WorkflowDedupInvalidInputError("eventId must be non-empty.");
|
|
412
|
+
}
|
|
413
|
+
return `${eventId}#${attempt}`;
|
|
414
|
+
}
|
|
415
|
+
function resolveTableName(explicit) {
|
|
416
|
+
const name = explicit ?? process.env[env_1.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR];
|
|
417
|
+
if (!name) {
|
|
418
|
+
throw new WorkflowDedupTableNameMissingError(`Workflow dedup table name not set. Pass options.tableName or set ${env_1.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR}.`);
|
|
419
|
+
}
|
|
420
|
+
return name;
|
|
421
|
+
}
|
|
422
|
+
function assertConsumerName(consumerName) {
|
|
423
|
+
if (consumerName.length === 0) {
|
|
424
|
+
throw new WorkflowDedupInvalidInputError("consumerName must be non-empty.");
|
|
425
|
+
}
|
|
426
|
+
if (consumerName.length > env_1.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH) {
|
|
427
|
+
throw new WorkflowDedupInvalidInputError(`consumerName must be \u2264${env_1.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH} chars; got ${consumerName.length}.`);
|
|
428
|
+
}
|
|
429
|
+
if (/\s/.test(consumerName)) {
|
|
430
|
+
throw new WorkflowDedupInvalidInputError("consumerName must not contain whitespace.");
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function assertPositiveInteger(value, field) {
|
|
434
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
435
|
+
throw new WorkflowDedupInvalidInputError(`${field} must be a 1-indexed integer; got ${value}.`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function defaultNow() {
|
|
439
|
+
return /* @__PURE__ */ new Date();
|
|
440
|
+
}
|
|
441
|
+
var WorkflowDedupTableNameMissingError = class extends Error {
|
|
442
|
+
/** @param message - human-readable description. */
|
|
443
|
+
constructor(message) {
|
|
444
|
+
super(message);
|
|
445
|
+
this.name = "WorkflowDedupTableNameMissingError";
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
exports.WorkflowDedupTableNameMissingError = WorkflowDedupTableNameMissingError;
|
|
449
|
+
var WorkflowDedupInvalidInputError = class extends Error {
|
|
450
|
+
/** @param message - human-readable description. */
|
|
451
|
+
constructor(message) {
|
|
452
|
+
super(message);
|
|
453
|
+
this.name = "WorkflowDedupInvalidInputError";
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
exports.WorkflowDedupInvalidInputError = WorkflowDedupInvalidInputError;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// ../workflows/lib/dedup/index.js
|
|
461
|
+
var require_dedup = __commonJS({
|
|
462
|
+
"../workflows/lib/dedup/index.js"(exports) {
|
|
463
|
+
"use strict";
|
|
464
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
465
|
+
exports.workflowDedupClient = exports.recordIfAbsent = exports.markFailed = exports.encodeSortKey = exports.WorkflowDedupTableNameMissingError = exports.WorkflowDedupInvalidInputError = exports.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR = exports.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH = exports.WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS = void 0;
|
|
466
|
+
var env_1 = require_env();
|
|
467
|
+
Object.defineProperty(exports, "WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS", { enumerable: true, get: function() {
|
|
468
|
+
return env_1.WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS;
|
|
469
|
+
} });
|
|
470
|
+
Object.defineProperty(exports, "WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH", { enumerable: true, get: function() {
|
|
471
|
+
return env_1.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH;
|
|
472
|
+
} });
|
|
473
|
+
Object.defineProperty(exports, "WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR", { enumerable: true, get: function() {
|
|
474
|
+
return env_1.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR;
|
|
475
|
+
} });
|
|
476
|
+
var workflow_dedup_client_1 = require_workflow_dedup_client();
|
|
477
|
+
Object.defineProperty(exports, "WorkflowDedupInvalidInputError", { enumerable: true, get: function() {
|
|
478
|
+
return workflow_dedup_client_1.WorkflowDedupInvalidInputError;
|
|
479
|
+
} });
|
|
480
|
+
Object.defineProperty(exports, "WorkflowDedupTableNameMissingError", { enumerable: true, get: function() {
|
|
481
|
+
return workflow_dedup_client_1.WorkflowDedupTableNameMissingError;
|
|
482
|
+
} });
|
|
483
|
+
Object.defineProperty(exports, "encodeSortKey", { enumerable: true, get: function() {
|
|
484
|
+
return workflow_dedup_client_1.encodeSortKey;
|
|
485
|
+
} });
|
|
486
|
+
Object.defineProperty(exports, "markFailed", { enumerable: true, get: function() {
|
|
487
|
+
return workflow_dedup_client_1.markFailed;
|
|
488
|
+
} });
|
|
489
|
+
Object.defineProperty(exports, "recordIfAbsent", { enumerable: true, get: function() {
|
|
490
|
+
return workflow_dedup_client_1.recordIfAbsent;
|
|
491
|
+
} });
|
|
492
|
+
Object.defineProperty(exports, "workflowDedupClient", { enumerable: true, get: function() {
|
|
493
|
+
return workflow_dedup_client_1.workflowDedupClient;
|
|
494
|
+
} });
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
// ../workflows/lib/index.js
|
|
499
|
+
var require_lib = __commonJS({
|
|
500
|
+
"../workflows/lib/index.js"(exports) {
|
|
501
|
+
"use strict";
|
|
502
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
503
|
+
exports.workflowDedupClient = exports.recordIfAbsent = exports.markFailed = exports.encodeSortKey = exports.WorkflowDedupTableNameMissingError = exports.WorkflowDedupInvalidInputError = exports.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR = exports.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH = exports.WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS = exports.parseWorkflowEvent = exports.UnsupportedEnvelopeVersionError = exports.InvalidWorkflowEventError = exports.workflowsClient = exports.publishWorkflowEvent = exports.WorkflowPublishError = exports.isWellFormedDetailType = exports.defineDetailType = exports.PlatformSystemDataSeededV1 = exports.PlatformDeploymentCompletedV1 = exports.InvalidDetailTypeRegistrationError = exports.OPENHI_OPS_SOURCE = exports.OPENHI_DATA_SOURCE = exports.OPENHI_CONTROL_SOURCE = exports.DEFAULT_BUS_NAME_BY_SOURCE = exports.workflowUserActorFromClaims = exports.isWorkflowUserActor = exports.isWorkflowSystemActor = exports.MissingActorContextError = exports.isSupportedEnvelopeVersion = exports.ENVELOPE_VERSION = void 0;
|
|
504
|
+
var envelope_version_1 = require_envelope_version();
|
|
505
|
+
Object.defineProperty(exports, "ENVELOPE_VERSION", { enumerable: true, get: function() {
|
|
506
|
+
return envelope_version_1.ENVELOPE_VERSION;
|
|
507
|
+
} });
|
|
508
|
+
Object.defineProperty(exports, "isSupportedEnvelopeVersion", { enumerable: true, get: function() {
|
|
509
|
+
return envelope_version_1.isSupportedEnvelopeVersion;
|
|
510
|
+
} });
|
|
511
|
+
var envelope_1 = require_envelope();
|
|
512
|
+
Object.defineProperty(exports, "MissingActorContextError", { enumerable: true, get: function() {
|
|
513
|
+
return envelope_1.MissingActorContextError;
|
|
514
|
+
} });
|
|
515
|
+
Object.defineProperty(exports, "isWorkflowSystemActor", { enumerable: true, get: function() {
|
|
516
|
+
return envelope_1.isWorkflowSystemActor;
|
|
517
|
+
} });
|
|
518
|
+
Object.defineProperty(exports, "isWorkflowUserActor", { enumerable: true, get: function() {
|
|
519
|
+
return envelope_1.isWorkflowUserActor;
|
|
520
|
+
} });
|
|
521
|
+
Object.defineProperty(exports, "workflowUserActorFromClaims", { enumerable: true, get: function() {
|
|
522
|
+
return envelope_1.workflowUserActorFromClaims;
|
|
523
|
+
} });
|
|
524
|
+
var sources_1 = require_sources();
|
|
525
|
+
Object.defineProperty(exports, "DEFAULT_BUS_NAME_BY_SOURCE", { enumerable: true, get: function() {
|
|
526
|
+
return sources_1.DEFAULT_BUS_NAME_BY_SOURCE;
|
|
527
|
+
} });
|
|
528
|
+
Object.defineProperty(exports, "OPENHI_CONTROL_SOURCE", { enumerable: true, get: function() {
|
|
529
|
+
return sources_1.OPENHI_CONTROL_SOURCE;
|
|
530
|
+
} });
|
|
531
|
+
Object.defineProperty(exports, "OPENHI_DATA_SOURCE", { enumerable: true, get: function() {
|
|
532
|
+
return sources_1.OPENHI_DATA_SOURCE;
|
|
533
|
+
} });
|
|
534
|
+
Object.defineProperty(exports, "OPENHI_OPS_SOURCE", { enumerable: true, get: function() {
|
|
535
|
+
return sources_1.OPENHI_OPS_SOURCE;
|
|
536
|
+
} });
|
|
537
|
+
var detail_types_1 = require_detail_types();
|
|
538
|
+
Object.defineProperty(exports, "InvalidDetailTypeRegistrationError", { enumerable: true, get: function() {
|
|
539
|
+
return detail_types_1.InvalidDetailTypeRegistrationError;
|
|
540
|
+
} });
|
|
541
|
+
Object.defineProperty(exports, "PlatformDeploymentCompletedV1", { enumerable: true, get: function() {
|
|
542
|
+
return detail_types_1.PlatformDeploymentCompletedV1;
|
|
543
|
+
} });
|
|
544
|
+
Object.defineProperty(exports, "PlatformSystemDataSeededV1", { enumerable: true, get: function() {
|
|
545
|
+
return detail_types_1.PlatformSystemDataSeededV1;
|
|
546
|
+
} });
|
|
547
|
+
Object.defineProperty(exports, "defineDetailType", { enumerable: true, get: function() {
|
|
548
|
+
return detail_types_1.defineDetailType;
|
|
549
|
+
} });
|
|
550
|
+
Object.defineProperty(exports, "isWellFormedDetailType", { enumerable: true, get: function() {
|
|
551
|
+
return detail_types_1.isWellFormedDetailType;
|
|
552
|
+
} });
|
|
553
|
+
var publisher_1 = require_publisher();
|
|
554
|
+
Object.defineProperty(exports, "WorkflowPublishError", { enumerable: true, get: function() {
|
|
555
|
+
return publisher_1.WorkflowPublishError;
|
|
556
|
+
} });
|
|
557
|
+
Object.defineProperty(exports, "publishWorkflowEvent", { enumerable: true, get: function() {
|
|
558
|
+
return publisher_1.publishWorkflowEvent;
|
|
559
|
+
} });
|
|
560
|
+
Object.defineProperty(exports, "workflowsClient", { enumerable: true, get: function() {
|
|
561
|
+
return publisher_1.workflowsClient;
|
|
562
|
+
} });
|
|
563
|
+
var consumer_1 = require_consumer();
|
|
564
|
+
Object.defineProperty(exports, "InvalidWorkflowEventError", { enumerable: true, get: function() {
|
|
565
|
+
return consumer_1.InvalidWorkflowEventError;
|
|
566
|
+
} });
|
|
567
|
+
Object.defineProperty(exports, "UnsupportedEnvelopeVersionError", { enumerable: true, get: function() {
|
|
568
|
+
return consumer_1.UnsupportedEnvelopeVersionError;
|
|
569
|
+
} });
|
|
570
|
+
Object.defineProperty(exports, "parseWorkflowEvent", { enumerable: true, get: function() {
|
|
571
|
+
return consumer_1.parseWorkflowEvent;
|
|
572
|
+
} });
|
|
573
|
+
var dedup_1 = require_dedup();
|
|
574
|
+
Object.defineProperty(exports, "WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS", { enumerable: true, get: function() {
|
|
575
|
+
return dedup_1.WORKFLOW_DEDUP_DEFAULT_TTL_SECONDS;
|
|
576
|
+
} });
|
|
577
|
+
Object.defineProperty(exports, "WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH", { enumerable: true, get: function() {
|
|
578
|
+
return dedup_1.WORKFLOW_DEDUP_MAX_CONSUMER_NAME_LENGTH;
|
|
579
|
+
} });
|
|
580
|
+
Object.defineProperty(exports, "WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR", { enumerable: true, get: function() {
|
|
581
|
+
return dedup_1.WORKFLOW_DEDUP_TABLE_NAME_ENV_VAR;
|
|
582
|
+
} });
|
|
583
|
+
Object.defineProperty(exports, "WorkflowDedupInvalidInputError", { enumerable: true, get: function() {
|
|
584
|
+
return dedup_1.WorkflowDedupInvalidInputError;
|
|
585
|
+
} });
|
|
586
|
+
Object.defineProperty(exports, "WorkflowDedupTableNameMissingError", { enumerable: true, get: function() {
|
|
587
|
+
return dedup_1.WorkflowDedupTableNameMissingError;
|
|
588
|
+
} });
|
|
589
|
+
Object.defineProperty(exports, "encodeSortKey", { enumerable: true, get: function() {
|
|
590
|
+
return dedup_1.encodeSortKey;
|
|
591
|
+
} });
|
|
592
|
+
Object.defineProperty(exports, "markFailed", { enumerable: true, get: function() {
|
|
593
|
+
return dedup_1.markFailed;
|
|
594
|
+
} });
|
|
595
|
+
Object.defineProperty(exports, "recordIfAbsent", { enumerable: true, get: function() {
|
|
596
|
+
return dedup_1.recordIfAbsent;
|
|
597
|
+
} });
|
|
598
|
+
Object.defineProperty(exports, "workflowDedupClient", { enumerable: true, get: function() {
|
|
599
|
+
return dedup_1.workflowDedupClient;
|
|
600
|
+
} });
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
export {
|
|
605
|
+
require_lib
|
|
606
|
+
};
|
|
607
|
+
//# sourceMappingURL=chunk-SYBADQXI.mjs.map
|