Skip to content

Commit 19909a9

Browse files
committed
fix: tests and builds correctly
1 parent f7daad5 commit 19909a9

File tree

10 files changed

+69
-2542
lines changed

10 files changed

+69
-2542
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@ jobs:
55
build:
66
name: Build
77
runs-on: ubuntu-latest
8-
env:
9-
AWS_ACCESS_KEY_ID: foo
10-
AWS_SECRET_ACCESS_KEY: bar
118
steps:
12-
- uses: actions/checkout@v2
13-
14-
- name: install
15-
run: yarn
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-node@v4
11+
with:
12+
node-version: 22
13+
- name: build
14+
run: npm install
1615

1716
- name: build
18-
run: yarn run build
17+
run: node --run build
1918

2019
- name: run localstack
21-
run: docker-compose build
20+
run: docker compose build
2221

2322
- name: run localstack
24-
run: docker-compose up -d
23+
run: docker compose up -d
2524

2625
- name: wait for localstack
2726
run: ./scripts/wait-for-url.js http://localhost:4566 && sleep 5
2827

2928
- name: test
30-
run: yarn test
29+
run: node test

.github/workflows/publish.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
Publish:
1313
name: Publish
1414
runs-on: ubuntu-latest
15-
if: github.ref == 'refs/heads/master'
15+
if: github.ref == 'refs/heads/main'
1616
env:
1717
AWS_ACCESS_KEY_ID: foo
1818
AWS_SECRET_ACCESS_KEY: bar
@@ -25,7 +25,7 @@ jobs:
2525

2626
- uses: actions/setup-node@v1
2727
with:
28-
node-version: 12
28+
node-version: 22
2929
registry-url: https://registry.npmjs.org/
3030

3131
- name: Install node modules
@@ -35,10 +35,10 @@ jobs:
3535
run: yarn build
3636

3737
- name: run localstack
38-
run: docker-compose build
38+
run: docker compose build
3939

4040
- name: run localstack
41-
run: docker-compose up -d
41+
run: docker compose up -d
4242

4343
- name: wait for localstack
4444
run: ./scripts/wait-for-url.js http://localhost:4566 && sleep 5
@@ -48,8 +48,8 @@ jobs:
4848

4949
- name: Configure CI Git User
5050
run: |
51-
git config --global user.name '@aspecto-system'
52-
git config --global user.email '[email protected]'
51+
git config --global user.email "[email protected]"
52+
git config --global user.name "UI release bot"
5353
5454
- name: Update yarn commit message
5555
run: yarn config set version-git-message "chore(release) - publish v%s"

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
![Build](https://github.com/aspecto-io/sns-sqs-big-payload/workflows/Build/badge.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![TypeScript](https://badgen.net/npm/types/env-var)](http://www.typescriptlang.org/) [![NPM version](https://img.shields.io/npm/v/sns-sqs-big-payload.svg)](https://www.npmjs.com/package/sns-sqs-big-payload)
1+
![Build](https://github.com/5app/sns-sqs-big-payload/workflows/Build/badge.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![TypeScript](https://badgen.net/npm/types/env-var)](http://www.typescriptlang.org/) [![NPM version](https://img.shields.io/npm/v/@5app/sns-sqs-big-payload.svg)](https://www.npmjs.com/package/@5app/sns-sqs-big-payload)
22

33
# sns-sqs-big-payload
44

55
SQS/SNS producer/consumer library. Provides an ability to pass payloads though s3.
66

77
## Motivation
88

9-
[Aspecto](https://www.aspecto.io/?utm_source=github&utm_medium=sqs-sns-big-payload&utm_campaign=readme-p1&utm_content=v1) helps modern development teams solve production issues before they evolve. We collect real production data and perform deep API analysis over it to autogenerate tests and monitor services stability. As a result, we often need to handle large payloads which can't be used with SQS & SNS due to the hard size limit. This library was developed to overcome this challenge - it enables you to manage Amazon SNS & SQS message payloads with Amazon S3 when dealing with payloads larger than 256KB. Key functionality includes:
9+
> From Original Author...
10+
> [Aspecto](https://www.aspecto.io/?utm_source=github&utm_medium=sqs-sns-big-payload&utm_campaign=readme-p1&utm_content=v1) helps modern development teams solve production issues before they evolve. We collect real production data and perform deep API analysis over it to autogenerate tests and monitor services stability. As a result, we often need to handle large payloads which can't be used with SQS & SNS due to the hard size limit. This library was developed to overcome this challenge - it enables you to manage Amazon SNS & SQS message payloads with Amazon S3 when dealing with payloads larger than 256KB. Key functionality includes:
1011
1112
- Controlling whether message payloads are always stored in Amazon S3 or only when a message's size exceeds 256KB.
1213
- Send a message that references a single message object stored in an Amazon S3 bucket.
@@ -16,13 +17,9 @@ SQS/SNS producer/consumer library. Provides an ability to pass payloads though s
1617
## Installation
1718

1819
```
19-
npm install sns-sqs-big-payload
20+
npm install @5app/sns-sqs-big-payload
2021
```
2122

22-
Important:
23-
24-
> Make sure you also have `aws-sdk` installed, because it's listed as a peer dependency, so won't be installed automatically.
25-
2623
## Usage
2724

2825
The library exports 3 clients:
@@ -36,7 +33,7 @@ All 3 clients are under the same repository since they share a similar contract
3633
### SNS Producer
3734

3835
```ts
39-
import { SnsProducer } from 'sns-sqs-big-payload';
36+
import { SnsProducer } from '@5app/sns-sqs-big-payload';
4037

4138
const snsProducer = SnsProducer.create({
4239
topicArn: '<topic-arn>',
@@ -58,7 +55,7 @@ await snsProducer.sendJSON({
5855
### SQS Producer
5956

6057
```ts
61-
import { SqsProducer } from 'sns-sqs-big-payload';
58+
import { SqsProducer } from '@5app/sns-sqs-big-payload';
6259

6360
const sqsProducer = SqsProducer.create({
6461
queueUrl: '...',
@@ -80,7 +77,7 @@ await sqsProducer.sendJSON({
8077
### SQS Consumer
8178

8279
```ts
83-
import { SqsConsumer, SqsConsumerEvents } from 'sns-sqs-big-payload';
80+
import { SqsConsumer, SqsConsumerEvents } from '@5app/sns-sqs-big-payload';
8481

8582
const sqsConsumer = SqsConsumer.create({
8683
queueUrl: '...',
@@ -149,7 +146,7 @@ export AWS_ACCESS_KEY_ID=...
149146
If you need to specify your credentials manually, you can use a pre-configured instance of the [AWS SQS](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html) client:
150147

151148
```ts
152-
import { SqsConsumer } from 'sns-sqs-big-payload';
149+
import { SqsConsumer } from '@5app/sns-sqs-big-payload';
153150
import * as aws from 'aws-sdk';
154151

155152
aws.config.update({
@@ -224,7 +221,7 @@ Since this library heavily relies on AWS APIs, it is less relevant to run an iso
224221
To run localstack on mac:
225222

226223
```sh
227-
TMPDIR=/private$TMPDIR docker-compose up
224+
TMPDIR=/private$TMPDIR docker compose up
228225
```
229226

230227
To run unit tests:

docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ version: '2.1'
33
services:
44
localstack:
55
container_name: '${LOCALSTACK_DOCKER_NAME-localstack_main}'
6-
image: localstack/localstack:0.12.5
6+
image: localstack/localstack:3.3
77
ports:
8-
- '4566:4566'
9-
- '${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}'
8+
- '127.0.0.1:4566:4566' # LocalStack Gateway
9+
- '127.0.0.1:4510-4559:4510-4559' # external services port range
1010
environment:
1111
- SERVICES=${SERVICES- }
1212
- DEBUG=${DEBUG- }
1313
- DATA_DIR=${DATA_DIR- }
14-
- PORT_WEB_UI=${PORT_WEB_UI- }
1514
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
1615
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
1716
- DOCKER_HOST=unix:///var/run/docker.sock

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
{
2-
"name": "sns-sqs-big-payload",
2+
"name": "@5app/sns-sqs-big-payload",
33
"version": "0.1.4",
44
"license": "Apache-2.0",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"test": "jest",
9-
"build": "yarn clean && tsc",
9+
"build": "node --run clean && tsc",
1010
"clean": "rm -rf ./dist/*",
11-
"prepublishOnly": "yarn build"
11+
"prepublishOnly": "node --run build"
1212
},
1313
"dependencies": {
14-
"@aws-sdk/client-s3": "^3.591.0",
15-
"@aws-sdk/client-sns": "^3.590.0",
16-
"@aws-sdk/client-sqs": "^3.590.0",
17-
"@aws-sdk/lib-storage": "^3.591.0",
18-
"@smithy/smithy-client": "^3.1.1",
19-
"uuid": "^7.0.2"
14+
"@aws-sdk/client-s3": "^3.758.0",
15+
"@aws-sdk/client-sns": "^3.758.0",
16+
"@aws-sdk/client-sqs": "^3.758.0",
17+
"@aws-sdk/lib-storage": "^3.758.0",
18+
"@smithy/smithy-client": "^4.1.6",
19+
"uuid": "^11.1.0"
2020
},
2121
"devDependencies": {
22-
"@types/jest": "^29.4.0",
23-
"@types/node": "^13.13.52",
22+
"@tsconfig/node22": "^22.0.0",
23+
"@types/jest": "^29.5.14",
24+
"@types/node": "^22.13.9",
2425
"jest": "^29.7.0",
25-
"ts-jest": "^29.0.5",
26-
"typescript": "4.4.4"
26+
"ts-jest": "^29.2.6",
27+
"typescript": "^5.8.2"
2728
},
2829
"repository": {
2930
"type": "git",
30-
"url": "https://github.com/aspecto-io/sns-sqs-big-payload"
31+
"url": "https://github.com/5app/sns-sqs-big-payload"
3132
},
3233
"bugs": {
33-
"url": "https://github.com/aspecto-io/sns-sqs-big-payload/issues"
34+
"url": "https://github.com/5app/sns-sqs-big-payload/issues"
3435
},
35-
"homepage": "https://github.com/aspecto-io/sns-sqs-big-payload",
36+
"homepage": "https://github.com/5app/sns-sqs-big-payload",
3637
"prepublish": "tsc",
3738
"jest": {
3839
"preset": "ts-jest",

src/sqs-consumer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class SqsConsumer {
276276
Bucket: s3PayloadMeta.Bucket,
277277
Key: s3PayloadMeta.Key,
278278
});
279-
return { rawPayload: s3Response.Body, s3PayloadMeta };
279+
return { rawPayload: await s3Response.Body.transformToString(), s3PayloadMeta };
280280
} catch (err) {
281281
this.events.emit(SqsConsumerEvents.s3PayloadError, {
282282
err,

src/util.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { MessageAttributeMap } from 'aws-sdk/clients/sns';
1+
import { type SendMessageRequest } from '@aws-sdk/client-sqs';
22
import { S3PayloadMeta, PayloadMeta, SqsExtendedPayloadMeta } from './types';
33
import { AMAZON_EXTENDED_CLIENT_PAYLOAD_OFFLOADING_REFERENCE, SQS_LARGE_PAYLOAD_SIZE_ATTRIBUTE } from './constants';
44

5-
export function createExtendedCompatibilityAttributeMap(msgSize: number): MessageAttributeMap {
6-
const result = {};
7-
result[SQS_LARGE_PAYLOAD_SIZE_ATTRIBUTE] = {
8-
StringValue: '' + msgSize,
9-
DataType: 'Number',
10-
};
11-
return result;
5+
export function createExtendedCompatibilityAttributeMap(msgSize: number): SendMessageRequest["MessageAttributes"] {
6+
return {
7+
[SQS_LARGE_PAYLOAD_SIZE_ATTRIBUTE] : {
8+
StringValue: '' + msgSize,
9+
DataType: 'Number',
10+
}
11+
}
1212
}
1313

1414
export function buildS3Payload(s3PayloadMeta: S3PayloadMeta): string {

tests/sns-sqs.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ import {
99
SqsMessage,
1010
} from '../src';
1111

12+
import { describe, it, expect, beforeEach, afterEach, beforeAll } from '@jest/globals';
13+
1214
import { S3 } from '@aws-sdk/client-s3';
1315
import { SNS } from '@aws-sdk/client-sns';
14-
import { SQS } from '@aws-sdk/client-sqs';
16+
import { SQS, GetQueueAttributesCommand } from '@aws-sdk/client-sqs';
1517
import { v4 as uuid } from 'uuid';
1618
import { S3PayloadMeta } from '../src/types';
1719

1820
// Real AWS services (for dev testing)
1921
// const TEST_TOPIC_ARN = 'arn:aws:sns:eu-west-1:731241200085:test-sns-producer';
2022
// const TEST_REGION = 'eu-west-1';
23+
process.env.AWS_ACCESS_KEY_ID='test';
24+
process.env.AWS_SECRET_ACCESS_KEY='test';
25+
2126

2227
// Localstack AWS services
2328
const QUEUE_NAME = 'test-consumer-producer';
@@ -61,12 +66,17 @@ async function initAws() {
6166
await sqs.createQueue({ QueueName: QUEUE_NAME }),
6267
await sqs.createQueue({ QueueName: QUEUE_2_NAME }),
6368
]);
69+
6470
testQueueUrl = res[1].QueueUrl || 'error';
6571
testQueue2Url = res[2].QueueUrl || 'error';
72+
73+
const getQueueAttributesCommand = new GetQueueAttributesCommand({ QueueUrl: testQueueUrl, AttributeNames: ['QueueArn']})
74+
const getQueueAttributesResponse = await sqs.send(getQueueAttributesCommand);
75+
6676
await sns.subscribe({
6777
Protocol: 'sqs',
6878
TopicArn: TEST_TOPIC_ARN,
69-
Endpoint: testQueueUrl,
79+
Endpoint: getQueueAttributesResponse?.Attributes?.QueueArn,
7080
});
7181
}
7282

@@ -187,7 +197,7 @@ async function receiveMessages(
187197
clearTimeout(timeoutId);
188198
});
189199

190-
sqsConsumer.on(SqsConsumerEvents.processingError, () => {
200+
sqsConsumer.on(SqsConsumerEvents.processingError, (e) => {
191201
sqsConsumer.stop();
192202
clearTimeout(timeoutId);
193203
resolve([]);

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2+
"extends": "@tsconfig/node22/tsconfig.json",
23
"compilerOptions": {
3-
"target": "ES2017",
4+
"target": "esnext",
45
"lib": ["ES2017"],
56
"rootDir": "./src",
67
"outDir": "dist",

0 commit comments

Comments
 (0)