From 214f50c6638ae7b6f01fb28f639bcfb5e6c27fde Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 29 Nov 2023 08:39:37 +0000 Subject: [PATCH 1/3] chore(release): 1.1.1 [skip ci] # [@adobe/spacecat-shared-dynamo-v1.1.1](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-dynamo-v1.1.0...@adobe/spacecat-shared-dynamo-v1.1.1) (2023-11-29) ### Bug Fixes * typo ([9167cf3](https://github.com/adobe-rnd/spacecat-shared/commit/9167cf3ac70a998aa92aaef24e080cd8147a70e9)) --- packages/spacecat-shared-dynamo/CHANGELOG.md | 7 +++++++ packages/spacecat-shared-dynamo/package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/spacecat-shared-dynamo/CHANGELOG.md b/packages/spacecat-shared-dynamo/CHANGELOG.md index fdfb77b2..1f20959c 100644 --- a/packages/spacecat-shared-dynamo/CHANGELOG.md +++ b/packages/spacecat-shared-dynamo/CHANGELOG.md @@ -1,3 +1,10 @@ +# [@adobe/spacecat-shared-dynamo-v1.1.1](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-dynamo-v1.1.0...@adobe/spacecat-shared-dynamo-v1.1.1) (2023-11-29) + + +### Bug Fixes + +* typo ([9167cf3](https://github.com/adobe-rnd/spacecat-shared/commit/9167cf3ac70a998aa92aaef24e080cd8147a70e9)) + # [@adobe/spacecat-shared-dynamo-v1.1.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-dynamo-v1.0.0...@adobe/spacecat-shared-dynamo-v1.1.0) (2023-11-29) diff --git a/packages/spacecat-shared-dynamo/package.json b/packages/spacecat-shared-dynamo/package.json index bef51cb4..5a79b54e 100644 --- a/packages/spacecat-shared-dynamo/package.json +++ b/packages/spacecat-shared-dynamo/package.json @@ -1,6 +1,6 @@ { "name": "@adobe/spacecat-shared-dynamo", - "version": "1.1.0", + "version": "1.1.1", "description": "Shared modules of the Spacecat Services - DynamoDB client", "type": "module", "main": "src/index.js", From 4283e1418f78b8d610637b90bd504e47ae3bc8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= <1872195+solaris007@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:20:06 +0100 Subject: [PATCH 2/3] fix: key validation (#7) --- .../src/utils/guards.js | 8 +++--- .../test/modules/getItem.test.js | 2 +- .../test/modules/removeItem.test.js | 2 +- .../test/utils/guards.test.js | 28 ++++++++++--------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/spacecat-shared-dynamo/src/utils/guards.js b/packages/spacecat-shared-dynamo/src/utils/guards.js index 62b39272..11d52bcc 100644 --- a/packages/spacecat-shared-dynamo/src/utils/guards.js +++ b/packages/spacecat-shared-dynamo/src/utils/guards.js @@ -25,14 +25,14 @@ const guardTableName = (tableName) => { }; /** - * Validates that the provided key is an object and contains a partitionKey. + * Validates that the provided key is an object and contains at least one property. * * @param {object} key - The key object to validate. - * @throws {Error} If the key is not an object or does not contain a partitionKey. + * @throws {Error} If the key is not an object or does not contain at least one property. */ const guardKey = (key) => { - if (!isObject(key) || !key.partitionKey) { - throw new Error('Key must be an object with a partitionKey.'); + if (!isObject(key) || Object.keys(key).length === 0) { + throw new Error('Key must be a non-empty object.'); } }; diff --git a/packages/spacecat-shared-dynamo/test/modules/getItem.test.js b/packages/spacecat-shared-dynamo/test/modules/getItem.test.js index f89a131b..205c0101 100644 --- a/packages/spacecat-shared-dynamo/test/modules/getItem.test.js +++ b/packages/spacecat-shared-dynamo/test/modules/getItem.test.js @@ -54,7 +54,7 @@ describe('getItem', () => { await dynamoDbClient.getItem('TestTable', null); expect.fail('getItem did not throw with invalid key'); } catch (error) { - expect(error.message).to.equal('Key must be an object with a partitionKey.'); + expect(error.message).to.equal('Key must be a non-empty object.'); } }); diff --git a/packages/spacecat-shared-dynamo/test/modules/removeItem.test.js b/packages/spacecat-shared-dynamo/test/modules/removeItem.test.js index 37f94fd6..02e55166 100644 --- a/packages/spacecat-shared-dynamo/test/modules/removeItem.test.js +++ b/packages/spacecat-shared-dynamo/test/modules/removeItem.test.js @@ -54,7 +54,7 @@ describe('removeItem', () => { await dynamoDbClient.removeItem('TestTable', null); expect.fail('removeItem did not throw with invalid key'); } catch (error) { - expect(error.message).to.equal('Key must be an object with a partitionKey.'); + expect(error.message).to.equal('Key must be a non-empty object.'); } }); diff --git a/packages/spacecat-shared-dynamo/test/utils/guards.test.js b/packages/spacecat-shared-dynamo/test/utils/guards.test.js index 814b2c4d..26846b33 100644 --- a/packages/spacecat-shared-dynamo/test/utils/guards.test.js +++ b/packages/spacecat-shared-dynamo/test/utils/guards.test.js @@ -16,42 +16,44 @@ import { expect } from 'chai'; import { guardKey, guardQueryParameters, guardTableName } from '../../src/utils/guards.js'; describe('Query Parameter Guards', () => { - // Test guardTableName describe('guardTableName', () => { - it('should throw an error if tableName is empty', () => { + it('throws an error if tableName is empty', () => { expect(() => guardTableName('')).to.throw('Table name is required.'); }); - it('should not throw an error for valid tableName', () => { + it('does not throw an error for valid tableName', () => { expect(() => guardTableName('validTableName')).to.not.throw(); }); }); - // Test guardKey describe('guardKey', () => { - it('should throw an error if key is not an object', () => { - expect(() => guardKey('notAnObject')).to.throw('Key must be an object with a partitionKey.'); + it('throws an error if key is not an object', () => { + expect(() => guardKey('notAnObject')).to.throw('Key must be a non-empty object.'); }); - it('should throw an error if key does not have partitionKey', () => { - expect(() => guardKey({})).to.throw('Key must be an object with a partitionKey.'); + it('throws an error if key is an empty object', () => { + expect(() => guardKey({})).to.throw('Key must be a non-empty object.'); }); - it('should not throw an error for a valid key', () => { - expect(() => guardKey({ partitionKey: 'value' })).to.not.throw(); + it('does not throw an error for a valid key with one property', () => { + expect(() => guardKey({ somePartitionKeyField: 'value' })).to.not.throw(); + }); + + it('does not throw an error for a valid key with two properties', () => { + expect(() => guardKey({ somePartitionKeyField: 'value', someOptionalRangeKey: 'anotherValue' })).to.not.throw(); }); }); describe('guardQueryParameters', () => { - it('should throw an error if params is not an object', () => { + it('throws an error if params is not an object', () => { expect(() => guardQueryParameters('notAnObject')).to.throw('Query parameters must be an object.'); }); - it('should throw an error if any required parameter is missing', () => { + it('throws an error if any required parameter is missing', () => { expect(() => guardQueryParameters({ TableName: 'table' })).to.throw('Query parameters is missing required parameter: KeyConditionExpression'); }); - it('should not throw an error for valid params', () => { + it('does not throw an error for valid params', () => { const validParams = { TableName: 'table', KeyConditionExpression: 'expression', From 00e27b087af61e1f28b377be1c8ac42759da5962 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 29 Nov 2023 10:20:54 +0000 Subject: [PATCH 3/3] chore(release): 1.1.2 [skip ci] # [@adobe/spacecat-shared-dynamo-v1.1.2](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-dynamo-v1.1.1...@adobe/spacecat-shared-dynamo-v1.1.2) (2023-11-29) ### Bug Fixes * key validation ([#7](https://github.com/adobe-rnd/spacecat-shared/issues/7)) ([4283e14](https://github.com/adobe-rnd/spacecat-shared/commit/4283e1418f78b8d610637b90bd504e47ae3bc8ee)) --- packages/spacecat-shared-dynamo/CHANGELOG.md | 7 +++++++ packages/spacecat-shared-dynamo/package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/spacecat-shared-dynamo/CHANGELOG.md b/packages/spacecat-shared-dynamo/CHANGELOG.md index 1f20959c..20b849b4 100644 --- a/packages/spacecat-shared-dynamo/CHANGELOG.md +++ b/packages/spacecat-shared-dynamo/CHANGELOG.md @@ -1,3 +1,10 @@ +# [@adobe/spacecat-shared-dynamo-v1.1.2](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-dynamo-v1.1.1...@adobe/spacecat-shared-dynamo-v1.1.2) (2023-11-29) + + +### Bug Fixes + +* key validation ([#7](https://github.com/adobe-rnd/spacecat-shared/issues/7)) ([4283e14](https://github.com/adobe-rnd/spacecat-shared/commit/4283e1418f78b8d610637b90bd504e47ae3bc8ee)) + # [@adobe/spacecat-shared-dynamo-v1.1.1](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-dynamo-v1.1.0...@adobe/spacecat-shared-dynamo-v1.1.1) (2023-11-29) diff --git a/packages/spacecat-shared-dynamo/package.json b/packages/spacecat-shared-dynamo/package.json index 5a79b54e..3c126228 100644 --- a/packages/spacecat-shared-dynamo/package.json +++ b/packages/spacecat-shared-dynamo/package.json @@ -1,6 +1,6 @@ { "name": "@adobe/spacecat-shared-dynamo", - "version": "1.1.1", + "version": "1.1.2", "description": "Shared modules of the Spacecat Services - DynamoDB client", "type": "module", "main": "src/index.js",