@1mill/cloudevents 0.11.0 → 2.0.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 (52) hide show
  1. package/README.md +76 -51
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/index.modern.js +2 -0
  5. package/dist/index.modern.js.map +1 -0
  6. package/dist/index.module.js +2 -0
  7. package/dist/index.module.js.map +1 -0
  8. package/dist/index.umd.js +2 -0
  9. package/dist/index.umd.js.map +1 -0
  10. package/package.json +21 -8
  11. package/src/index.js +71 -0
  12. package/.editorconfig +0 -21
  13. package/index.js +0 -6
  14. package/v3/createCloudevent.js +0 -51
  15. package/v3/createEventStream.js +0 -36
  16. package/v3/enrichCloudevent.js +0 -15
  17. package/v3/index.js +0 -16
  18. package/v3/isEnriched.js +0 -5
  19. package/v3/kafka/convertFrom.js +0 -6
  20. package/v3/kafka/convertTo.js +0 -12
  21. package/v3/kafka/createAuthentication.js +0 -19
  22. package/v3/kafka/createEmit.js +0 -33
  23. package/v3/kafka/createListen.js +0 -75
  24. package/v3/kafka/index.js +0 -28
  25. package/v3/lambda/handler.js +0 -29
  26. package/v3/lambda/index.js +0 -7
  27. package/v3/lib/constants.js +0 -14
  28. package/v4/createCloudevent.js +0 -47
  29. package/v4/createEventStream.js +0 -36
  30. package/v4/index.js +0 -12
  31. package/v4/kafka/convertFrom.js +0 -6
  32. package/v4/kafka/convertTo.js +0 -12
  33. package/v4/kafka/createAuthentication.js +0 -19
  34. package/v4/kafka/createEmit.js +0 -33
  35. package/v4/kafka/createListen.js +0 -64
  36. package/v4/kafka/index.js +0 -28
  37. package/v4/lambda/handler.js +0 -9
  38. package/v4/lambda/index.js +0 -7
  39. package/v4/lib/constants.js +0 -14
  40. package/v5/createCloudevent.js +0 -47
  41. package/v5/createCloudeventStream.js +0 -42
  42. package/v5/index.js +0 -12
  43. package/v5/kafka/convertFrom.js +0 -6
  44. package/v5/kafka/convertTo.js +0 -12
  45. package/v5/kafka/createAuthentication.js +0 -19
  46. package/v5/kafka/createEmit.js +0 -33
  47. package/v5/kafka/createListen.js +0 -73
  48. package/v5/kafka/index.js +0 -28
  49. package/v5/lambda/handler.js +0 -9
  50. package/v5/lambda/index.js +0 -7
  51. package/v5/lib/constants.js +0 -14
  52. package/v6/index.js +0 -41
@@ -1,73 +0,0 @@
1
- const { ERROR_TYPES, SIGNAL_TRAPS } = require('../lib/constants')
2
- const { Kafka } = require('kafkajs')
3
- const { convertFrom } = require('./convertFrom')
4
- const { createAuthentication } = require('./createAuthentication')
5
-
6
- const createListen = ({
7
- id,
8
- mechanism,
9
- password,
10
- urls,
11
- username,
12
- }) => {
13
- const authentication = createAuthentication({
14
- mechanism,
15
- password,
16
- username,
17
- })
18
- const kafka = new Kafka({
19
- ...authentication,
20
- brokers: urls,
21
- clientId: id,
22
- })
23
-
24
- const listen = async ({ handler, types }) => {
25
- const consumer = kafka.consumer({ groupId: id });
26
- await consumer.connect()
27
-
28
- const promises = types.map(type => {
29
- consumer.subscribe({
30
- fromBeginning: type.fromBeginning || false,
31
- topic: type.type || type,
32
- })
33
- })
34
- await Promise.all(promises)
35
-
36
- await consumer.run({
37
- eachMessage: async (event) => {
38
- try {
39
- const { cloudevent } = convertFrom({ event })
40
- await handler({ cloudevent })
41
- } catch (err) {
42
- console.error(err)
43
- }
44
- }
45
- })
46
-
47
- // Before server stop, close subscription connections to kafka
48
- ERROR_TYPES.map(errorType => {
49
- process.on(errorType, async (err) => {
50
- try {
51
- console.log(`process.on ${errorType}`)
52
- console.error(err)
53
- await consumer.disconnect()
54
- process.exit(0)
55
- } catch (_err) {
56
- process.exit(1)
57
- }
58
- })
59
- })
60
- SIGNAL_TRAPS.map(signalTrap => {
61
- process.once(signalTrap, async () => {
62
- try {
63
- await consumer.disconnect()
64
- } finally {
65
- process.kill(process.pid, signalTrap)
66
- }
67
- })
68
- })
69
- }
70
- return { listen }
71
- }
72
-
73
- module.exports = { createListen }
package/v5/kafka/index.js DELETED
@@ -1,28 +0,0 @@
1
- const { createEmit } = require('./createEmit')
2
- const { createListen } = require('./createListen')
3
-
4
- const createInstance = ({
5
- id,
6
- mechanism,
7
- password,
8
- urls,
9
- username,
10
- }) => {
11
- const { emit } = createEmit({
12
- id,
13
- mechanism,
14
- password,
15
- urls,
16
- username,
17
- })
18
- const { listen } = createListen({
19
- id,
20
- mechanism,
21
- password,
22
- urls,
23
- username,
24
- });
25
- return { emit, listen }
26
- }
27
-
28
- module.exports = { createInstance }
@@ -1,9 +0,0 @@
1
- const handler = (func) => {
2
- return async (event, _context, _callback) => {
3
- const cloudevent = event
4
- const payload = await func({ cloudevent })
5
- return payload // * Returned to AWS invoker if 'RequestResponse' type
6
- }
7
- }
8
-
9
- module.exports = { handler }
@@ -1,7 +0,0 @@
1
- const { handler } = require('./handler');
2
-
3
- const createInstance = ({}) => {
4
- return { handler }
5
- }
6
-
7
- module.exports = { createInstance }
@@ -1,14 +0,0 @@
1
- const PROTOCOL_KAFKA = 'kafka'
2
- const PROTOCOL_LAMBDA = 'lambda'
3
-
4
- const ERROR_TYPES = ['unhandledRejection', 'uncaughtException']
5
- const SIGNAL_TRAPS = ['SIGTERM', 'SIGINT', 'SIGUSR2']
6
-
7
- module.exports = {
8
- // Supported protocols
9
- PROTOCOL_KAFKA,
10
- PROTOCOL_LAMBDA,
11
- // Other constants
12
- ERROR_TYPES,
13
- SIGNAL_TRAPS,
14
- };
package/v6/index.js DELETED
@@ -1,41 +0,0 @@
1
- const createCloudevent = ({
2
- data,
3
- datacontenttype,
4
- dataschema,
5
- id,
6
- originid,
7
- originsource,
8
- origintype,
9
- source,
10
- specversion = '1.0',
11
- subject,
12
- type,
13
- }) => {
14
- if (!id) { throw new Error('Cloudevent "id" is as required') }
15
- if (!source) { throw new Error('Cloudevent "source" is as required') }
16
- if (!type) { throw new Error('Cloudevent "type" is as required') }
17
-
18
- const cloudevent = {
19
- // * Defined in cloudevents specification
20
- // Required defaults
21
- id,
22
- source,
23
- specversion,
24
- time: new Date().toUTCString(),
25
- type,
26
-
27
- // Optional data
28
- data,
29
- datacontenttype,
30
- dataschema,
31
- subject,
32
-
33
- // * In-house attribute extensions
34
- originid: originid || id,
35
- originsource: originsource || source,
36
- origintype: origintype || type,
37
- }
38
- return cloudevent
39
- }
40
-
41
- module.exports = { v6: { createCloudevent } }