@aws-lambda-powertools/kafka 0.0.0 → 2.23.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 (67) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +299 -2
  3. package/lib/cjs/constants.d.ts +10 -0
  4. package/lib/cjs/constants.d.ts.map +1 -0
  5. package/lib/cjs/constants.js +12 -0
  6. package/lib/cjs/consumer.d.ts +42 -0
  7. package/lib/cjs/consumer.d.ts.map +1 -0
  8. package/lib/cjs/consumer.js +250 -0
  9. package/lib/cjs/deserializer/avro.d.ts +9 -0
  10. package/lib/cjs/deserializer/avro.d.ts.map +1 -0
  11. package/lib/cjs/deserializer/avro.js +25 -0
  12. package/lib/cjs/deserializer/json.d.ts +9 -0
  13. package/lib/cjs/deserializer/json.d.ts.map +1 -0
  14. package/lib/cjs/deserializer/json.js +25 -0
  15. package/lib/cjs/deserializer/primitive.d.ts +10 -0
  16. package/lib/cjs/deserializer/primitive.d.ts.map +1 -0
  17. package/lib/cjs/deserializer/primitive.js +16 -0
  18. package/lib/cjs/deserializer/protobuf.d.ts +12 -0
  19. package/lib/cjs/deserializer/protobuf.d.ts.map +1 -0
  20. package/lib/cjs/deserializer/protobuf.js +80 -0
  21. package/lib/cjs/errors.d.ts +27 -0
  22. package/lib/cjs/errors.d.ts.map +1 -0
  23. package/lib/cjs/errors.js +44 -0
  24. package/lib/cjs/index.d.ts +3 -0
  25. package/lib/cjs/index.d.ts.map +1 -0
  26. package/lib/cjs/index.js +7 -0
  27. package/lib/cjs/package.json +1 -0
  28. package/lib/cjs/types/index.d.ts +2 -0
  29. package/lib/cjs/types/index.d.ts.map +1 -0
  30. package/lib/cjs/types/index.js +2 -0
  31. package/lib/cjs/types/types.d.ts +244 -0
  32. package/lib/cjs/types/types.d.ts.map +1 -0
  33. package/lib/cjs/types/types.js +2 -0
  34. package/lib/esm/constants.d.ts +10 -0
  35. package/lib/esm/constants.d.ts.map +1 -0
  36. package/lib/esm/constants.js +9 -0
  37. package/lib/esm/consumer.d.ts +42 -0
  38. package/lib/esm/consumer.d.ts.map +1 -0
  39. package/lib/esm/consumer.js +214 -0
  40. package/lib/esm/deserializer/avro.d.ts +9 -0
  41. package/lib/esm/deserializer/avro.d.ts.map +1 -0
  42. package/lib/esm/deserializer/avro.js +19 -0
  43. package/lib/esm/deserializer/json.d.ts +9 -0
  44. package/lib/esm/deserializer/json.d.ts.map +1 -0
  45. package/lib/esm/deserializer/json.js +22 -0
  46. package/lib/esm/deserializer/primitive.d.ts +10 -0
  47. package/lib/esm/deserializer/primitive.d.ts.map +1 -0
  48. package/lib/esm/deserializer/primitive.js +13 -0
  49. package/lib/esm/deserializer/protobuf.d.ts +12 -0
  50. package/lib/esm/deserializer/protobuf.d.ts.map +1 -0
  51. package/lib/esm/deserializer/protobuf.js +77 -0
  52. package/lib/esm/errors.d.ts +27 -0
  53. package/lib/esm/errors.d.ts.map +1 -0
  54. package/lib/esm/errors.js +38 -0
  55. package/lib/esm/index.d.ts +3 -0
  56. package/lib/esm/index.d.ts.map +1 -0
  57. package/lib/esm/index.js +2 -0
  58. package/lib/esm/package.json +1 -0
  59. package/lib/esm/types/index.d.ts +2 -0
  60. package/lib/esm/types/index.d.ts.map +1 -0
  61. package/lib/esm/types/index.js +1 -0
  62. package/lib/esm/types/types.d.ts +244 -0
  63. package/lib/esm/types/types.d.ts.map +1 -0
  64. package/lib/esm/types/types.js +1 -0
  65. package/package.json +77 -19
  66. package/lib/index.d.ts +0 -0
  67. package/lib/index.js +0 -3
@@ -0,0 +1,244 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { Reader } from 'protobufjs';
3
+ import type { SchemaType as SchemaTypeMap } from '../constants.js';
4
+ /**
5
+ * Union type for supported schema types (JSON, Avro, Protobuf).
6
+ */
7
+ type SchemaType = (typeof SchemaTypeMap)[keyof typeof SchemaTypeMap];
8
+ /**
9
+ * Metadata about the schema used for the field.
10
+ */
11
+ type SchemaMetadata = {
12
+ /**
13
+ * The schema type of the value (JSON, AVRO, PROTOBUF)
14
+ */
15
+ dataFormat: string;
16
+ /**
17
+ * The schema identifier
18
+ */
19
+ schemaId?: string;
20
+ };
21
+ /**
22
+ * Represents a single Kafka consumer record with generic key and value types.
23
+ */
24
+ type ConsumerRecord<K, V> = {
25
+ /**
26
+ * The deserialized key of the record
27
+ */
28
+ key: K;
29
+ /**
30
+ * The deserialized value of the record
31
+ */
32
+ value: V;
33
+ /**
34
+ * The original (raw, encoded) key as received from Kafka, or `undefined` if not present
35
+ */
36
+ originalKey?: string;
37
+ /**
38
+ * The original (raw, encoded) value as received from Kafka
39
+ */
40
+ originalValue: string;
41
+ /**
42
+ * Optional array of headers as key-value string pairs, or `null/`undefined` if not present
43
+ */
44
+ headers?: {
45
+ [k: string]: string;
46
+ }[] | null;
47
+ /**
48
+ * Optional array of original record headers
49
+ */
50
+ originalHeaders?: RecordHeader[] | null;
51
+ /**
52
+ * The topic from which the record was consumed
53
+ */
54
+ topic: string;
55
+ /**
56
+ * The partition from which the record was consumed
57
+ */
58
+ partition: number;
59
+ /**
60
+ * The offset of the record within the partition
61
+ */
62
+ offset: number;
63
+ /**
64
+ * The timestamp of the record
65
+ */
66
+ timestamp: number;
67
+ /**
68
+ * The type of timestamp (CREATE_TIME or LOG_APPEND_TIME)
69
+ */
70
+ timestampType: 'CREATE_TIME' | 'LOG_APPEND_TIME';
71
+ /**
72
+ * Metadata about the value schema
73
+ */
74
+ valueSchemaMetadata: SchemaMetadata;
75
+ /**
76
+ * Metadata about the key schema
77
+ */
78
+ keySchemaMetadata: SchemaMetadata;
79
+ };
80
+ /**
81
+ * Represents a collection of Kafka consumer records, along with MSK event metadata.
82
+ */
83
+ type ConsumerRecords<K = unknown, V = unknown> = {
84
+ /**
85
+ * Array of consumer records
86
+ */
87
+ records: Array<ConsumerRecord<K, V>>;
88
+ } & Omit<MSKEvent, 'records'>;
89
+ /**
90
+ * Union type for supported schema configurations (JSON, Avro, Protobuf).
91
+ */
92
+ type SchemaConfigValue = JsonConfig | AvroConfig | ProtobufConfig<unknown>;
93
+ /**
94
+ * Configuration for JSON schema validation.
95
+ */
96
+ type JsonConfig = {
97
+ /**
98
+ * Indicates the schema type is JSON
99
+ */
100
+ type: typeof SchemaTypeMap.JSON;
101
+ /**
102
+ * Optional {@link https://github.com/standard-schema/standard-schema | Standard Schema} for runtime validation
103
+ */
104
+ parserSchema?: StandardSchemaV1;
105
+ };
106
+ /**
107
+ * Configuration for Avro schema validation.
108
+ */
109
+ type AvroConfig = {
110
+ /**
111
+ * Indicates the schema type is Avro
112
+ */
113
+ type: typeof SchemaTypeMap.AVRO;
114
+ /**
115
+ * Avro schema definition as a string
116
+ */
117
+ schema: string;
118
+ /**
119
+ * Optional {@link https://github.com/standard-schema/standard-schema | Standard Schema} for runtime validation
120
+ */
121
+ parserSchema?: StandardSchemaV1;
122
+ };
123
+ /**
124
+ * Configuration for Protobuf schema validation.
125
+ */
126
+ type ProtobufConfig<T> = {
127
+ /**
128
+ * Indicates the schema type is Protobuf
129
+ */
130
+ type: typeof SchemaTypeMap.PROTOBUF;
131
+ /**
132
+ * Protobuf message type for decoding
133
+ */
134
+ schema: ProtobufMessage<T>;
135
+ /**
136
+ * Optional {@link https://github.com/standard-schema/standard-schema | Standard Schema} for runtime validation
137
+ */
138
+ parserSchema?: StandardSchemaV1;
139
+ };
140
+ /**
141
+ * Configuration for key and value schema validation.
142
+ */
143
+ type SchemaConfig = {
144
+ /**
145
+ * Schema type for the value.
146
+ * If not provided, the value will not be validated.
147
+ */
148
+ value: SchemaConfigValue;
149
+ /**
150
+ * Schema type for the key.
151
+ * If not provided, the key will not be validated.
152
+ */
153
+ key?: SchemaConfigValue;
154
+ };
155
+ /**
156
+ * Represents a Kafka record header as a mapping of header key to byte array.
157
+ */
158
+ type RecordHeader = {
159
+ /**
160
+ * Header key mapped to its value as an array of bytes
161
+ */
162
+ [headerKey: string]: number[];
163
+ };
164
+ /**
165
+ * Represents a single Kafka record as received from MSK.
166
+ */
167
+ type Record = {
168
+ /**
169
+ * Kafka topic name
170
+ */
171
+ topic: string;
172
+ /**
173
+ * Partition number within the topic
174
+ */
175
+ partition: number;
176
+ /**
177
+ * Offset of the record within the partition
178
+ */
179
+ offset: number;
180
+ /**
181
+ * Timestamp of the record
182
+ */
183
+ timestamp: number;
184
+ /**
185
+ * Type of timestamp (creation or log append time)
186
+ */
187
+ timestampType: 'CREATE_TIME' | 'LOG_APPEND_TIME';
188
+ /**
189
+ * Base64-encoded key of the record
190
+ */
191
+ key?: string | null;
192
+ /**
193
+ * Base64-encoded value of the record
194
+ */
195
+ value: string;
196
+ /**
197
+ * Array of record headers
198
+ */
199
+ headers: RecordHeader[] | null;
200
+ /**
201
+ * Metadata about the value schema
202
+ */
203
+ valueSchemaMetadata: SchemaMetadata;
204
+ /**
205
+ * Metadata about the key schema
206
+ */
207
+ keySchemaMetadata: SchemaMetadata;
208
+ };
209
+ /**
210
+ * AWS Lambda event structure for MSK (Managed Streaming for Kafka).
211
+ * @see {@link https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html | AWS Lambda with MSK}
212
+ */
213
+ type MSKEvent = {
214
+ /**
215
+ * Event source identifier (always 'aws:kafka')
216
+ */
217
+ eventSource: 'aws:kafka';
218
+ /**
219
+ * ARN of the Kafka event source
220
+ */
221
+ eventSourceArn: string;
222
+ /**
223
+ * Comma-separated list of Kafka bootstrap servers
224
+ */
225
+ bootstrapServers: string;
226
+ /**
227
+ * Mapping of topic names to arrays of records
228
+ */
229
+ records: {
230
+ [topic: string]: Record[];
231
+ };
232
+ };
233
+ type ProtobufMessage<T = unknown> = {
234
+ decode(reader: Reader | Uint8Array, length?: number): T;
235
+ };
236
+ type Deserializer = (input: string, schema?: unknown, schemaMetadata?: SchemaMetadata) => unknown;
237
+ type DeserializeOptions = {
238
+ value: string;
239
+ deserializer: Deserializer;
240
+ config?: SchemaConfigValue;
241
+ schemaMetadata: SchemaMetadata;
242
+ };
243
+ export type { ConsumerRecord, ConsumerRecords, Deserializer, MSKEvent, ProtobufMessage, Record, RecordHeader, SchemaType, SchemaConfig, SchemaConfigValue, SchemaMetadata, DeserializeOptions, };
244
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEnE;;GAEG;AACH,KAAK,UAAU,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAErE;;GAEG;AACH,KAAK,cAAc,GAAG;IACpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,KAAK,cAAc,CAAC,CAAC,EAAE,CAAC,IAAI;IAC1B;;OAEG;IACH,GAAG,EAAE,CAAC,CAAC;IACP;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC;IACT;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,OAAO,CAAC,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,GAAG,IAAI,CAAC;IAC3C;;OAEG;IACH,eAAe,CAAC,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IACxC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,SAAS,EAAE,MAAM,CAA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AM,CAAC;IACd,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF,YAAY,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,MAAM,EACN,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GACnB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,15 +1,12 @@
1
1
  {
2
- "name": "@aws-lambda-powertools/kafka",
3
- "version": "0.0.0",
4
- "description": "Utility to easily handle message deserialization and parsing of Kafka events in AWS Lambda functions",
5
- "author": {
6
- "name": "Amazon Web Services",
7
- "url": "https://aws.amazon.com"
8
- },
9
- "publishConfig": {
10
- "access": "public"
11
- },
12
- "license": "MIT-0",
2
+ "name": "@aws-lambda-powertools/kafka",
3
+ "version": "2.23.0",
4
+ "description": "Utility to easily handle message deserialization and parsing of Kafka events in AWS Lambda functions",
5
+ "author": {
6
+ "name": "Amazon Web Services",
7
+ "url": "https://aws.amazon.com"
8
+ },
9
+ "license": "MIT-0",
13
10
  "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme",
14
11
  "repository": {
15
12
  "type": "git",
@@ -18,13 +15,7 @@
18
15
  "bugs": {
19
16
  "url": "https://github.com/aws-powertools/powertools-lambda-typescript/issues"
20
17
  },
21
- "main": "./lib/index.js",
22
- "types": "./lib/index.d.ts",
23
- "files": [
24
- "lib"
25
- ],
26
- "dependencies": {},
27
- "keywords": [
18
+ "keywords": [
28
19
  "aws",
29
20
  "lambda",
30
21
  "powertools",
@@ -35,5 +26,72 @@
35
26
  "typescript",
36
27
  "nodejs"
37
28
  ],
38
- "devDependencies": {}
29
+ "dependencies": {
30
+ "@aws-lambda-powertools/commons": "2.23.0",
31
+ "@standard-schema/spec": "^1.0.0"
32
+ },
33
+ "peerDependencies": {
34
+ "arktype": ">=2.0.0",
35
+ "valibot": ">=1.0.0",
36
+ "zod": ">=3.24.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "zod": {
40
+ "optional": true
41
+ },
42
+ "valibot": {
43
+ "optional": true
44
+ },
45
+ "arktype": {
46
+ "optional": true
47
+ }
48
+ },
49
+ "files": [
50
+ "lib"
51
+ ],
52
+ "type": "module",
53
+ "exports": {
54
+ ".": {
55
+ "require": {
56
+ "types": "./lib/cjs/index.d.ts",
57
+ "default": "./lib/cjs/index.js"
58
+ },
59
+ "import": {
60
+ "types": "./lib/esm/index.d.ts",
61
+ "default": "./lib/esm/index.js"
62
+ }
63
+ },
64
+ "./errors": {
65
+ "require": {
66
+ "types": "./lib/cjs/errors.d.ts",
67
+ "default": "./lib/cjs/errors.js"
68
+ },
69
+ "import": {
70
+ "types": "./lib/esm/errors.d.ts",
71
+ "default": "./lib/esm/errors.js"
72
+ }
73
+ },
74
+ "./types": {
75
+ "require": {
76
+ "types": "./lib/cjs/types/index.d.ts",
77
+ "default": "./lib/cjs/types/index.js"
78
+ },
79
+ "import": {
80
+ "types": "./lib/esm/types/index.d.ts",
81
+ "default": "./lib/esm/types/index.js"
82
+ }
83
+ }
84
+ },
85
+ "typesVersions": {
86
+ "*": {
87
+ "errors": [
88
+ "lib/cjs/errors.d.ts",
89
+ "lib/esm/errors.d.ts"
90
+ ],
91
+ "types": [
92
+ "lib/cjs/types/index.d.ts",
93
+ "lib/esm/types/index.d.ts"
94
+ ]
95
+ }
96
+ }
39
97
  }
package/lib/index.d.ts DELETED
File without changes
package/lib/index.js DELETED
@@ -1,3 +0,0 @@
1
- console.log(
2
- "This is a prerelease version of @aws-lambda-powertools/kafka used to reserve the package name on npm.",
3
- );