ac-support-connector 1.0.0 → 1.0.1

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,3 +1,13 @@
1
+ <a name="1.0.1"></a>
2
+
3
+ ## [1.0.1](https://github.com/admiralcloud/ac-support-connector/compare/v1.0.0..v1.0.1) (2024-08-27 14:05:03)
4
+
5
+
6
+ ### Bug Fix
7
+
8
+ * **Connector:** Use ac-sqs | MP | [42dd23f9dde355204eb77a5f546cb2f12a8bb700](https://github.com/admiralcloud/ac-support-connector/commit/42dd23f9dde355204eb77a5f546cb2f12a8bb700)
9
+ Use our ac-sqs package
10
+ Related issues: [undefined/undefined#master](undefined/browse/master)
1
11
  <a name="1.0.0"></a>
2
12
 
3
13
  # [1.0.0](https://github.com/admiralcloud/ac-support-connector/compare/v0.1.1..v1.0.0) (2024-08-26 07:17:38)
package/index.js CHANGED
@@ -1,49 +1,44 @@
1
- const { SQSClient, SendMessageCommand } = require('@aws-sdk/client-sqs')
2
1
  const { STSClient, GetCallerIdentityCommand } = require('@aws-sdk/client-sts')
3
- const { fromIni } = require("@aws-sdk/credential-providers")
4
-
5
- const getLength = require('utf8-byte-length')
6
-
7
2
  const NodeCache = require('node-cache')
8
3
 
4
+ const ACSQS = require('ac-sqs')
5
+
9
6
  const functionName = 'ac-support-connector'.padEnd(20)
10
7
 
11
8
  module.exports = {
12
9
 
13
10
  aws: {},
14
11
 
15
- init: async function({ serviceName, instanceId, sqsQueue, redisInstance, region = 'eu-central-1', profile = process.env['profile'], debug } = {}) {
12
+ init: async function({ serviceName, instanceId, sqsQueue = 'AC-SupportQueue', bucket, redisInstance, region = 'eu-central-1', profile = process.env['profile'], debug } = {}) {
16
13
 
17
- if (!debug) {
18
- const awsConfig = {
19
- region
20
- }
21
- // credentials are determined from role.
22
- // But you can also use a set profile
23
- if (profile) {
24
- console.error('%s | Using AWS profile | %s', functionName, profile)
25
- awsConfig.credentials = fromIni({ profile })
26
- }
14
+ this.sqsQueue = sqsQueue
15
+ this.serviceName = serviceName || 'SupportConnector'
16
+ this.instanceId = instanceId
17
+ this.redisInstance = redisInstance
18
+ this.cache = new NodeCache()
19
+ this.debugMode = debug
27
20
 
28
- // determine accountId
21
+ if (!debug) {
29
22
  const client = new STSClient(awsConfig)
30
23
  const command = new GetCallerIdentityCommand()
31
24
  const response = await client.send(command)
32
25
  const accountId = response?.Account
33
-
34
- this.aws = {
35
- sqs: new SQSClient(awsConfig),
36
- region,
37
- accountId
26
+ const sqsParams = {
27
+ account: accountId,
28
+ availableLists: [{
29
+ name: sqsQueue,
30
+ fifo: true
31
+ }]
32
+ }
33
+ if (profile) sqsParams.profile = profile // Optional AWS profile, see below
34
+ if (bucket) {
35
+ sqsParams.useS3 = {
36
+ enabled: true,
37
+ bucket
38
+ }
38
39
  }
40
+ this.acsqs = new ACSQS(sqsParams)
39
41
  }
40
-
41
- this.serviceName = serviceName || 'SupportConnector'
42
- this.instanceId = instanceId
43
- this.sqsQueue = sqsQueue || 'AC-SupportQueue'
44
- this.redisInstance = redisInstance
45
- this.cache = new NodeCache()
46
- this.debugMode = debug
47
42
  },
48
43
 
49
44
 
@@ -83,25 +78,11 @@ module.exports = {
83
78
  message,
84
79
  }
85
80
 
86
- const maxSize = 256 * 1024 // 256kb
87
- const recordLength = getLength(JSON.stringify(messagePayload))
88
- // throw an error if the payload is too big
89
- if (recordLength > maxSize) {
90
- // text must be truncated
91
- throw new Error('maxPayloadExceeded')
92
- }
93
-
94
81
  if (process.env.NODE_ENV === 'test') {
95
82
  return messagePayload
96
83
  }
97
-
98
- const awsInput = {
99
- QueueUrl: `https://sqs.${this.aws.region}.amazonaws.com/${this.aws.accountId}/${this.sqsQueue}`,
100
- MessageBody: JSON.stringify(messagePayload)
101
- }
102
- const command = new SendMessageCommand(awsInput)
103
84
  try {
104
- const response = await this.aws.sqs.send(command)
85
+ await this.acsqs.sendSQSMessage({ name: this.sqsQueue, message: JSON.stringify(messagePayload) })
105
86
  if (this.debugMode) console.warn(response)
106
87
  }
107
88
  catch(e) {
package/package.json CHANGED
@@ -3,13 +3,10 @@
3
3
  "author": "Mark Poepping (https://www.admiralcloud.com)",
4
4
  "license": "MIT",
5
5
  "repository": "admiralcloud/ac-support-connector",
6
- "version": "1.0.0",
6
+ "version": "1.0.1",
7
7
  "dependencies": {
8
- "@aws-sdk/client-sqs": "^3.637.0",
9
- "@aws-sdk/client-sts": "^3.637.0",
10
- "@aws-sdk/credential-providers": "^3.637.0",
11
- "node-cache": "^5.1.2",
12
- "utf8-byte-length": "^1.0.5"
8
+ "ac-sqs": "^2.0.4",
9
+ "node-cache": "^5.1.2"
13
10
  },
14
11
  "devDependencies": {
15
12
  "ac-semantic-release": "^0.4.2",
package/test/test.js CHANGED
@@ -25,7 +25,7 @@ describe('Basic tests', () => {
25
25
  expect(response.message[0]).to.have.property('content', params.text)
26
26
  })
27
27
 
28
- it('Check truncated payload > 256KB - should throw an error', async() => {
28
+ it('Check truncated payload > 256KB - should not throw an error', async() => {
29
29
  let params = {
30
30
  subject: 'Failed',
31
31
  message: [{
@@ -34,14 +34,11 @@ describe('Basic tests', () => {
34
34
  }]
35
35
  }
36
36
 
37
- try {
38
- await supCon.createMessage(params)
39
- expect.fail('Expected function to throw an error, but it did not')
40
- }
41
- catch (error) {
42
- expect(error).to.be.an('error')
43
- expect(error.message).to.include('maxPayloadExceeded')
44
- }
37
+ let response = await supCon.createMessage(params)
38
+ expect(response).to.have.property('subject', params.subject)
39
+ expect(response).to.have.property('message').that.is.an('array').with.lengthOf.at.least(1);
40
+ expect(response.message[0]).to.have.property('type', 'text')
41
+ expect(response.message[0]).to.have.property('content', string1001)
45
42
  })
46
43
  })
47
44