@walkeros/server-destination-aws 4.7.0-next-1790722899482 → 4.7.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.
@@ -17,19 +17,27 @@ __export(env_exports, {
17
17
  push: () => push,
18
18
  simulation: () => simulation
19
19
  });
20
+ function hasRecords(value) {
21
+ return typeof value === "object" && value !== null && "Records" in value && Array.isArray(value.Records);
22
+ }
20
23
  var MockFirehoseClient = class {
21
24
  config;
22
25
  constructor(config) {
23
26
  this.config = config;
24
27
  }
25
- async send(_command) {
28
+ async send(command) {
29
+ const input = "input" in command ? command.input : void 0;
30
+ const records = hasRecords(input) ? input.Records : [];
26
31
  return {
27
- RecordId: "mock-record-id",
28
- ResponseMetadata: {
29
- RequestId: "mock-request-id"
30
- }
32
+ FailedPutCount: 0,
33
+ Encrypted: false,
34
+ RequestResponses: records.map((_, index) => ({
35
+ RecordId: `mock-record-id-${index}`
36
+ }))
31
37
  };
32
38
  }
39
+ destroy() {
40
+ }
33
41
  };
34
42
  var MockPutRecordBatchCommand = class {
35
43
  input;
@@ -41,7 +49,6 @@ var MockPutRecordBatchCommand = class {
41
49
  }
42
50
  };
43
51
  var push = {
44
- // Environment for push operations
45
52
  AWS: {
46
53
  FirehoseClient: MockFirehoseClient,
47
54
  PutRecordBatchCommand: MockPutRecordBatchCommand
@@ -53,110 +60,122 @@ var simulation = ["call:AWS.FirehoseClient.send"];
53
60
  var step_exports = {};
54
61
  __export(step_exports, {
55
62
  firehoseRecord: () => firehoseRecord,
63
+ init: () => init,
64
+ mappedRecord: () => mappedRecord,
56
65
  orderEvent: () => orderEvent,
57
66
  userSignupEvent: () => userSignupEvent
58
67
  });
59
68
  import { getEvent } from "@walkeros/core";
60
- var firehoseRecord = {
61
- title: "Page view record",
62
- description: "A page view is sent to Kinesis Firehose as a single record with the full event JSON-stringified into the Data buffer.",
63
- in: getEvent("page view", {
64
- id: "ev-1700001000",
65
- timestamp: 1700001e3,
66
- data: { title: "Home", url: "https://example.com/" },
67
- source: { type: "express", platform: "server" }
68
- }),
69
- mapping: void 0,
69
+
70
+ // src/lib/payload.ts
71
+ import { isObject } from "@walkeros/core";
72
+
73
+ // src/firehose/lib/records.ts
74
+ function toRecordData(payload, newline = true) {
75
+ const json = JSON.stringify(payload);
76
+ if (typeof json !== "string")
77
+ throw new TypeError("The payload does not serialize to JSON.");
78
+ return Buffer.from(newline ? `${json}
79
+ ` : json);
80
+ }
81
+
82
+ // src/firehose/examples/step.ts
83
+ var STREAM = "walkeros-events";
84
+ var init = {
85
+ title: "Initialization",
86
+ description: "Init builds one FirehoseClient for the stream region with the credentials from config.credentials and a 2500 ms per-attempt timeout. Nothing is sent until the first event.",
87
+ in: {
88
+ settings: { streamName: STREAM, region: "eu-central-1" },
89
+ credentials: {
90
+ accessKeyId: "$secret.AWS_ACCESS_KEY_ID",
91
+ secretAccessKey: "$secret.AWS_SECRET_ACCESS_KEY"
92
+ }
93
+ },
70
94
  out: [
71
95
  [
72
- "client.send",
96
+ "new FirehoseClient",
73
97
  {
74
- DeliveryStreamName: "walkeros-events",
75
- Records: [
76
- {
77
- Data: Buffer.from(
78
- JSON.stringify(
79
- getEvent("page view", {
80
- id: "ev-1700001000",
81
- timestamp: 1700001e3,
82
- data: { title: "Home", url: "https://example.com/" },
83
- source: { type: "express", platform: "server" }
84
- })
85
- )
86
- )
87
- }
88
- ]
98
+ region: "eu-central-1",
99
+ credentials: {
100
+ accessKeyId: "$secret.AWS_ACCESS_KEY_ID",
101
+ secretAccessKey: "$secret.AWS_SECRET_ACCESS_KEY"
102
+ },
103
+ requestHandler: { requestTimeout: 2500, throwOnRequestTimeout: true }
89
104
  }
90
105
  ]
91
106
  ]
92
107
  };
93
- var orderEvent = {
94
- title: "Order record",
95
- description: "An order complete event is serialized and delivered to Firehose as a batch record for downstream storage.",
96
- in: getEvent("order complete", {
97
- id: "ev-1700001001",
98
- timestamp: 1700001001,
99
- data: { id: "ORD-400", total: 99.99, currency: "EUR" },
100
- source: { type: "express", platform: "server" }
101
- }),
102
- mapping: void 0,
103
- out: [
108
+ var pageEvent = getEvent("page view", {
109
+ id: "ev-1700001000",
110
+ timestamp: 1700001e3,
111
+ data: { title: "Home", url: "https://example.com/" },
112
+ source: { type: "express", platform: "server" }
113
+ });
114
+ var orderEvt = getEvent("order complete", {
115
+ id: "ev-1700001001",
116
+ timestamp: 1700001001,
117
+ data: { id: "ORD-400", total: 99.99, currency: "EUR" },
118
+ source: { type: "express", platform: "server" }
119
+ });
120
+ var signupEvt = getEvent("user signup", {
121
+ id: "ev-1700001002",
122
+ timestamp: 1700001002,
123
+ data: { plan: "pro", source: "landing-page" },
124
+ user: { id: "usr-789", email: "new@example.com" },
125
+ source: { type: "express", platform: "server" }
126
+ });
127
+ function sent(payload) {
128
+ return [
104
129
  [
105
130
  "client.send",
106
131
  {
107
- DeliveryStreamName: "walkeros-events",
108
- Records: [
109
- {
110
- Data: Buffer.from(
111
- JSON.stringify(
112
- getEvent("order complete", {
113
- id: "ev-1700001001",
114
- timestamp: 1700001001,
115
- data: { id: "ORD-400", total: 99.99, currency: "EUR" },
116
- source: { type: "express", platform: "server" }
117
- })
118
- )
119
- )
120
- }
121
- ]
132
+ DeliveryStreamName: STREAM,
133
+ Records: [{ Data: toRecordData(payload) }]
122
134
  }
123
135
  ]
124
- ]
136
+ ];
137
+ }
138
+ var firehoseRecord = {
139
+ title: "Page view record",
140
+ description: "A page view is sent to Firehose as one record: the full event as JSON followed by a newline.",
141
+ in: pageEvent,
142
+ mapping: void 0,
143
+ out: sent(pageEvent)
144
+ };
145
+ var orderEvent = {
146
+ title: "Order record",
147
+ description: "An order complete event is serialized and delivered to Firehose as one newline-terminated record.",
148
+ in: orderEvt,
149
+ mapping: void 0,
150
+ out: sent(orderEvt)
125
151
  };
126
152
  var userSignupEvent = {
127
153
  title: "User signup record",
128
154
  description: "A user signup event including user fields is streamed to Firehose as a JSON record.",
129
- in: getEvent("user signup", {
130
- id: "ev-1700001002",
131
- timestamp: 1700001002,
132
- data: { plan: "pro", source: "landing-page" },
133
- user: { id: "usr-789", email: "new@example.com" },
134
- source: { type: "express", platform: "server" }
135
- }),
155
+ in: signupEvt,
136
156
  mapping: void 0,
137
- out: [
138
- [
139
- "client.send",
140
- {
141
- DeliveryStreamName: "walkeros-events",
142
- Records: [
143
- {
144
- Data: Buffer.from(
145
- JSON.stringify(
146
- getEvent("user signup", {
147
- id: "ev-1700001002",
148
- timestamp: 1700001002,
149
- data: { plan: "pro", source: "landing-page" },
150
- user: { id: "usr-789", email: "new@example.com" },
151
- source: { type: "express", platform: "server" }
152
- })
153
- )
154
- )
155
- }
156
- ]
157
+ out: sent(signupEvt)
158
+ };
159
+ var mappedRecord = {
160
+ title: "Mapped record",
161
+ description: "A mapping that produces an object sends that object as the record instead of the full event. Keep the event id in it for deduplication.",
162
+ in: orderEvt,
163
+ mapping: {
164
+ data: {
165
+ map: {
166
+ id: "id",
167
+ name: "name",
168
+ order_id: "data.id",
169
+ total: "data.total"
157
170
  }
158
- ]
159
- ]
171
+ }
172
+ },
173
+ out: sent({
174
+ id: "ev-1700001001",
175
+ name: "order complete",
176
+ order_id: "ORD-400",
177
+ total: 99.99
178
+ })
160
179
  };
161
180
 
162
181
  // src/sns/examples/index.ts
@@ -216,6 +235,8 @@ var MockSNSClient = class {
216
235
  return { MessageId: "mock-message-id" };
217
236
  return {};
218
237
  }
238
+ destroy() {
239
+ }
219
240
  };
220
241
  var MockSTSClient = class {
221
242
  constructor(config) {
@@ -223,7 +244,12 @@ var MockSTSClient = class {
223
244
  }
224
245
  config;
225
246
  async send() {
226
- return { Account: "123456789012" };
247
+ return {
248
+ Account: "123456789012",
249
+ Arn: "arn:aws:iam::123456789012:user/walkeros"
250
+ };
251
+ }
252
+ destroy() {
227
253
  }
228
254
  };
229
255
  var push2 = {
@@ -243,17 +269,45 @@ var simulation2 = ["call:AWS.SNSClient.send"];
243
269
  var step_exports2 = {};
244
270
  __export(step_exports2, {
245
271
  attributedPublish: () => attributedPublish,
272
+ init: () => init2,
273
+ mappedMessage: () => mappedMessage,
246
274
  orderEvent: () => orderEvent2,
247
275
  pageView: () => pageView
248
276
  });
249
277
  import { getEvent as getEvent2 } from "@walkeros/core";
250
- var pageEvent = getEvent2("page view", {
278
+ var TOPIC_ARN2 = "arn:aws:sns:eu-central-1:123456789012:walkeros-events";
279
+ var FIFO_ARN = "arn:aws:sns:eu-central-1:123456789012:walkeros-events.fifo";
280
+ var init2 = {
281
+ title: "Initialization",
282
+ description: "Init builds one SNSClient in the region of the topic ARN with the credentials from config.credentials and a 2500 ms per-attempt timeout. No topic is created and nothing is sent until the first event.",
283
+ in: {
284
+ settings: { topicArn: TOPIC_ARN2 },
285
+ credentials: {
286
+ accessKeyId: "$secret.AWS_ACCESS_KEY_ID",
287
+ secretAccessKey: "$secret.AWS_SECRET_ACCESS_KEY"
288
+ }
289
+ },
290
+ out: [
291
+ [
292
+ "new SNSClient",
293
+ {
294
+ region: "eu-central-1",
295
+ credentials: {
296
+ accessKeyId: "$secret.AWS_ACCESS_KEY_ID",
297
+ secretAccessKey: "$secret.AWS_SECRET_ACCESS_KEY"
298
+ },
299
+ requestHandler: { requestTimeout: 2500, throwOnRequestTimeout: true }
300
+ }
301
+ ]
302
+ ]
303
+ };
304
+ var pageEvent2 = getEvent2("page view", {
251
305
  id: "ev-1700001000",
252
306
  timestamp: 1700001e3,
253
307
  data: { title: "Home", url: "https://example.com/" },
254
308
  source: { type: "express", platform: "server" }
255
309
  });
256
- var orderEvt = getEvent2("order complete", {
310
+ var orderEvt2 = getEvent2("order complete", {
257
311
  id: "ev-1700001001",
258
312
  timestamp: 1700001001,
259
313
  data: { id: "ORD-400", total: 99.99, currency: "EUR" },
@@ -269,30 +323,31 @@ var productViewEvt = getEvent2("product view", {
269
323
  var pageView = {
270
324
  title: "Page view publish",
271
325
  description: "A page view event is JSON-stringified and published as the Message of an SNS Publish call.",
272
- in: pageEvent,
326
+ in: pageEvent2,
273
327
  mapping: void 0,
274
328
  out: [
275
329
  [
276
330
  "client.send",
277
331
  {
278
- TopicArn: "arn:aws:sns:eu-central-1:000000000000:walkeros-events",
279
- Message: JSON.stringify(pageEvent)
332
+ TopicArn: TOPIC_ARN2,
333
+ Message: JSON.stringify(pageEvent2)
280
334
  }
281
335
  ]
282
336
  ]
283
337
  };
284
338
  var orderEvent2 = {
285
339
  title: "Order publish with FIFO group (path-resolved)",
286
- description: 'An order complete event is published with a FIFO messageGroupId resolved from the event via the mapping path "user.id". `messageGroupId` is a `Mapping.Value`, so a string path is sufficient; no literal is hard-coded.',
287
- in: orderEvt,
340
+ description: 'An order complete event is published to a FIFO topic with a messageGroupId resolved from the event via the mapping path "user.id". The deduplication id defaults to the event id.',
341
+ in: orderEvt2,
288
342
  mapping: { settings: { messageGroupId: "user.id" } },
289
343
  out: [
290
344
  [
291
345
  "client.send",
292
346
  {
293
- TopicArn: "arn:aws:sns:eu-central-1:000000000000:walkeros-events.fifo",
294
- Message: JSON.stringify(orderEvt),
295
- MessageGroupId: "usr-789"
347
+ TopicArn: FIFO_ARN,
348
+ Message: JSON.stringify(orderEvt2),
349
+ MessageGroupId: "usr-789",
350
+ MessageDeduplicationId: "ev-1700001001"
296
351
  }
297
352
  ]
298
353
  ]
@@ -313,7 +368,7 @@ var attributedPublish = {
313
368
  [
314
369
  "client.send",
315
370
  {
316
- TopicArn: "arn:aws:sns:eu-central-1:000000000000:walkeros-events",
371
+ TopicArn: TOPIC_ARN2,
317
372
  Message: JSON.stringify(productViewEvt),
318
373
  MessageAttributes: {
319
374
  schema_version: { DataType: "String", StringValue: "v4" },
@@ -323,6 +378,30 @@ var attributedPublish = {
323
378
  ]
324
379
  ]
325
380
  };
381
+ var mappedMessage = {
382
+ title: "Mapped message",
383
+ description: "A mapping that produces an object publishes that object as the Message instead of the full event. Keep the event id in it for deduplication.",
384
+ in: orderEvt2,
385
+ mapping: {
386
+ data: {
387
+ map: { id: "id", name: "name", order_id: "data.id", total: "data.total" }
388
+ }
389
+ },
390
+ out: [
391
+ [
392
+ "client.send",
393
+ {
394
+ TopicArn: TOPIC_ARN2,
395
+ Message: JSON.stringify({
396
+ id: "ev-1700001001",
397
+ name: "order complete",
398
+ order_id: "ORD-400",
399
+ total: 99.99
400
+ })
401
+ }
402
+ ]
403
+ ]
404
+ };
326
405
  export {
327
406
  env_exports as env,
328
407
  examples_exports as firehose,