Skip to content

Commit

Permalink
Merge pull request #1 from janis-commerce/JCN-497-support-array-type-…
Browse files Browse the repository at this point in the history
…attributes

[JCN-497-support-array-type-attributes] - add support to array attrib…
  • Loading branch information
jormaechea authored Feb 6, 2025
2 parents 87a3541 + 5a9da2c commit 9557ab0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ npm install --dev @aws-sdk/client-sns@3
> The event `content` will be JSON-stringified before sending
> The event `attributes` can be either Strings or Arrays. It's important to note that using other data types may cause issues or inconsistencies in the implemented filter policies. Ensure that the values provided for the attributes are always of the expected type to avoid errors in message processing.
***Note: This behavior applies from version 1.1.0 onward.***

#### Publish single event

```js
Expand All @@ -41,7 +44,7 @@ const result = await snsTrigger.publishEvent('topicName', {
},
attributes: {
source: 'user',
platform: 'mobile'
platforms: ['mobile', 'web']
}
});

Expand Down
4 changes: 2 additions & 2 deletions lib/sns-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ module.exports = class SnsTrigger {
hasAttributes = true;
Object.entries(attributes).forEach(([key, value]) => {
parsedAttributes[key] = {
DataType: 'String',
StringValue: value
DataType: Array.isArray(value) ? 'String.Array' : 'String',
StringValue: Array.isArray(value) ? JSON.stringify(value) : value
};
});
}
Expand Down
7 changes: 6 additions & 1 deletion tests/sns-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ describe('SnsTrigger', () => {
foo: 'bar'
},
attributes: {
foo: 'bar'
foo: 'bar',
arrayAttribute: ['option1', 'option2']
},
subject: 'test',
messageGroupId: 'group1',
Expand All @@ -198,6 +199,10 @@ describe('SnsTrigger', () => {
foo: {
DataType: 'String',
StringValue: 'bar'
},
arrayAttribute: {
DataType: 'String.Array',
StringValue: JSON.stringify(['option1', 'option2'])
}
},
Subject: 'test',
Expand Down

0 comments on commit 9557ab0

Please sign in to comment.