@itentialopensource/adapter-kafkav2 0.8.1 → 0.9.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ ## 0.9.0 [07-18-2023]
3
+
4
+ * Add seperate sasl props for consumer and producer
5
+
6
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!10
7
+
8
+ ---
9
+
10
+ ## 0.8.2 [07-18-2023]
11
+
12
+ * Update dependencies and add fromBeginnimg config
13
+
14
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!9
15
+
16
+ ---
17
+
2
18
  ## 0.8.1 [07-10-2023]
3
19
 
4
20
  * Revert "Merge branch 'patch/ADAPT-2647' into 'master'"
package/README.md CHANGED
@@ -277,6 +277,8 @@ The following properties are used to define the Kafka Client. These properties a
277
277
 
278
278
  | Property | Description |
279
279
  | ------- | ------- |
280
+ | consumersasl | Object, SASL authentication configuration for consumer. This is optional if you provide sasl. ex. { mechanism: 'plain', username: 'foo', password: 'bar' }|
281
+ | producersasl | Object, SASL authentication configuration for producer. This is optional if you provide sasl. ex. { mechanism: 'plain', username: 'foo', password: 'bar' }|
280
282
  | brokers | kafka broker:port list |
281
283
  | clientId | Client-id is a logical grouping of clients with a meaningful name chosen by the client application |
282
284
  | ssl | Object, options to be passed to the tls broker sockets, ex. { rejectUnauthorized: false }.|
package/adapter.js CHANGED
@@ -11,6 +11,7 @@
11
11
  /* eslint import/no-dynamic-require: warn */
12
12
  /* eslint global-require: warn */
13
13
  /* eslint no-await-in-loop: warn */
14
+ /* eslint no-promise-executor-return: warn */
14
15
 
15
16
  /* Required libraries. */
16
17
  const fs = require('fs-extra');
@@ -372,6 +373,8 @@ class Kafkav2 extends AdapterBaseCl {
372
373
  }
373
374
 
374
375
  this.KafkaClient = null;
376
+ this.KafkaProducerClient = null;
377
+ this.KafkaConsumerClient = null;
375
378
  this.producer = null;
376
379
  this.consumer = null;
377
380
  this.registryUrl = null;
@@ -446,9 +449,21 @@ class Kafkav2 extends AdapterBaseCl {
446
449
 
447
450
  this.KafkaClient = new Kafka(combinedProps);
448
451
 
449
- this.producer = this.KafkaClient.producer(this.props.producer || {});
452
+ if (this.props.client && this.props.client.producersasl) {
453
+ combinedProps.sasl = this.props.client.producersasl;
454
+ this.KafkaProducerClient = new Kafka(combinedProps);
455
+ this.producer = this.KafkaProducerClient.producer(this.props.producer || {});
456
+ } else {
457
+ this.producer = this.KafkaClient.producer(this.props.producer || {});
458
+ }
450
459
 
451
- this.consumer = this.KafkaClient.consumer(this.props.consumer || {});
460
+ if (this.props.client && this.props.client.consumersasl) {
461
+ combinedProps.sasl = this.props.client.consumersasl;
462
+ this.KafkaConsumerClient = new Kafka(combinedProps);
463
+ this.consumer = this.KafkaConsumerClient.consumer(this.props.consumer || {});
464
+ } else {
465
+ this.consumer = this.KafkaClient.consumer(this.props.consumer || {});
466
+ }
452
467
 
453
468
  const isPassingFiltering = (topic, message, filters) => {
454
469
  const topicConfig = this.topicsEvents.find((e) => e.topic === topic);
@@ -480,7 +495,7 @@ class Kafkav2 extends AdapterBaseCl {
480
495
  topics.push(this.topicsEvents[t].topic);
481
496
  }
482
497
  await this.consumer.connect();
483
- await this.consumer.subscribe({ topics, fromBeginning: true });
498
+ await this.consumer.subscribe({ topics, fromBeginning: this.props.fromBeginning || false });
484
499
 
485
500
  let isAppActive = null;
486
501
  const topicPartitions = topics.map((topic) => ({ topic }));
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-kafkav2",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Itential adapter to connect to kafka",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.35.0",
7
7
  "engineVersion": "1.40.2",
8
8
  "scripts": {
9
9
  "artifactize": "npm i && node utils/packModificationScript.js",
10
- "preinstall": "node utils/setup.js && npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions",
10
+ "preinstall": "node utils/setup.js && npm install --package-lock-only --ignore-scripts",
11
11
  "lint": "eslint . --ext .json --ext .js",
12
12
  "lint:errors": "node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js --quiet",
13
13
  "test:baseunit": "mocha test/unit/adapterBaseTestUnit.js --LOG=error",
@@ -16,8 +16,7 @@
16
16
  "test:cover": "nyc --reporter html --reporter text mocha --reporter dot test/*",
17
17
  "test": "npm run test:unit && npm run test:integration",
18
18
  "deploy": "npm publish --registry=https://registry.npmjs.org --access=public",
19
- "build": "npm run deploy",
20
- "postinstall": "patch-package"
19
+ "build": "npm run deploy"
21
20
  },
22
21
  "keywords": [
23
22
  "Itential",
@@ -43,31 +42,27 @@
43
42
  "author": "Itential",
44
43
  "homepage": "https://gitlab.com/itentialopensource/adapters/notification-messaging/adapter-kafkav2",
45
44
  "dependencies": {
46
- "ajv": "^6.12.0",
45
+ "ajv": "^8.12.0",
47
46
  "avro-schema-registry": "^2.1.0",
48
47
  "avsc": "^5.4.21",
49
- "fs-extra": "^8.1.0",
48
+ "fs-extra": "^11.1.1",
50
49
  "json-query": "^2.2.2",
51
50
  "kafkajs": "2.2.3",
52
- "package-json-validator": "^0.6.3",
53
51
  "patch-package": "^6.4.7",
54
52
  "readline-sync": "^1.4.10",
55
53
  "request": "^2.88.2",
56
54
  "uuid": "^3.0.1"
57
55
  },
58
56
  "devDependencies": {
59
- "chai": "^4.2.0",
60
- "eslint": "^7.2.0",
61
- "eslint-config-airbnb-base": "^14.2.0",
62
- "eslint-plugin-import": "^2.21.2",
63
- "eslint-plugin-json": "^2.1.1",
57
+ "chai": "^4.3.7",
58
+ "eslint": "^8.44.0",
59
+ "eslint-config-airbnb-base": "^15.0.0",
60
+ "eslint-plugin-import": "^2.27.5",
61
+ "eslint-plugin-json": "^3.1.0",
64
62
  "mocha": "^9.0.1",
65
63
  "nyc": "^15.1.0",
66
- "testdouble": "^3.16.1",
64
+ "testdouble": "^3.18.0",
67
65
  "winston": "^3.3.3"
68
66
  },
69
- "resolutions": {
70
- "minimist": "^1.2.5"
71
- },
72
67
  "private": false
73
68
  }
Binary file
@@ -16,6 +16,9 @@ const execute = require('child_process').execSync;
16
16
  const { expect } = require('chai');
17
17
  const { use } = require('chai');
18
18
  const td = require('testdouble');
19
+ const Ajv = require('ajv');
20
+
21
+ const ajv = new Ajv({ allErrors: true, unknownFormats: 'ignore' });
19
22
 
20
23
  const anything = td.matchers.anything();
21
24
 
@@ -188,19 +191,24 @@ describe('[unit] Kafka Adapter Test', () => {
188
191
  });
189
192
  it('package.json should be validated', (done) => {
190
193
  const packageDotJson = require('../../package.json');
191
- const { PJV } = require('package-json-validator');
192
- const options = {
193
- warnings: true, // show warnings
194
- recommendations: true // show recommendations
194
+ // Define the JSON schema for package.json
195
+ const packageJsonSchema = {
196
+ type: 'object',
197
+ properties: {
198
+ name: { type: 'string' },
199
+ version: { type: 'string' }
200
+ // May need to add more properties as needed
201
+ },
202
+ required: ['name', 'version']
195
203
  };
196
- const results = PJV.validate(JSON.stringify(packageDotJson), 'npm', options);
204
+ const validate = ajv.compile(packageJsonSchema);
205
+ const isValid = validate(packageDotJson);
197
206
 
198
- if (results.valid === false) {
199
- log.error('The package.json contains the following errors: ');
200
- log.error(util.inspect(results));
201
- assert.equal(true, results.valid);
207
+ if (isValid === false) {
208
+ log.error('The package.json contains errors');
209
+ assert.equal(true, isValid);
202
210
  } else {
203
- assert.equal(true, results.valid);
211
+ assert.equal(true, isValid);
204
212
  }
205
213
 
206
214
  done();