@aws-lambda-powertools/idempotency
Advanced tools
Comparing version 1.17.0 to 1.18.0
@@ -0,1 +1,2 @@ | ||
import type { IdempotencyRecord } from './persistence'; | ||
/** | ||
@@ -5,2 +6,4 @@ * Item attempting to be inserted into persistence store already exists and is not expired | ||
declare class IdempotencyItemAlreadyExistsError extends Error { | ||
existingRecord?: IdempotencyRecord; | ||
constructor(message?: string, existingRecord?: IdempotencyRecord); | ||
} | ||
@@ -7,0 +10,0 @@ /** |
@@ -8,2 +8,6 @@ "use strict"; | ||
class IdempotencyItemAlreadyExistsError extends Error { | ||
constructor(message, existingRecord) { | ||
super(message); | ||
this.existingRecord = existingRecord; | ||
} | ||
} | ||
@@ -10,0 +14,0 @@ exports.IdempotencyItemAlreadyExistsError = IdempotencyItemAlreadyExistsError; |
@@ -79,3 +79,4 @@ "use strict"; | ||
if (e instanceof errors_1.IdempotencyItemAlreadyExistsError) { | ||
const idempotencyRecord = await __classPrivateFieldGet(this, _IdempotencyHandler_persistenceStore, "f").getRecord(__classPrivateFieldGet(this, _IdempotencyHandler_functionPayloadToBeHashed, "f")); | ||
const idempotencyRecord = e.existingRecord || | ||
(await __classPrivateFieldGet(this, _IdempotencyHandler_persistenceStore, "f").getRecord(__classPrivateFieldGet(this, _IdempotencyHandler_functionPayloadToBeHashed, "f"))); | ||
return _a.determineResultFromIdempotencyRecord(idempotencyRecord); | ||
@@ -82,0 +83,0 @@ } |
@@ -125,3 +125,3 @@ "use strict"; | ||
if (this.getFromCache(idempotencyRecord.idempotencyKey)) { | ||
throw new errors_1.IdempotencyItemAlreadyExistsError(); | ||
throw new errors_1.IdempotencyItemAlreadyExistsError(`Failed to put record for already existing idempotency key: ${idempotencyRecord.idempotencyKey}`, idempotencyRecord); | ||
} | ||
@@ -128,0 +128,0 @@ await this._putRecord(idempotencyRecord); |
@@ -155,9 +155,18 @@ "use strict"; | ||
ConditionExpression: conditionExpression, | ||
ReturnValuesOnConditionCheckFailure: 'ALL_OLD', | ||
})); | ||
} | ||
catch (error) { | ||
if (error instanceof client_dynamodb_1.DynamoDBServiceException) { | ||
if (error.name === 'ConditionalCheckFailedException') { | ||
throw new errors_1.IdempotencyItemAlreadyExistsError(`Failed to put record for already existing idempotency key: ${record.idempotencyKey}`); | ||
} | ||
if (error instanceof client_dynamodb_1.ConditionalCheckFailedException) { | ||
const item = error.Item && (0, util_dynamodb_1.unmarshall)(error.Item); | ||
const idempotencyRecord = item && | ||
new IdempotencyRecord_1.IdempotencyRecord({ | ||
idempotencyKey: item[this.keyAttr], | ||
status: item[this.statusAttr], | ||
expiryTimestamp: item[this.expiryAttr], | ||
inProgressExpiryTimestamp: item[this.inProgressExpiryAttr], | ||
responseData: item[this.dataAttr], | ||
payloadHash: item[this.validationKeyAttr], | ||
}); | ||
throw new errors_1.IdempotencyItemAlreadyExistsError(`Failed to put record for already existing idempotency key: ${record.idempotencyKey}`, idempotencyRecord); | ||
} | ||
@@ -164,0 +173,0 @@ throw error; |
{ | ||
"name": "@aws-lambda-powertools/idempotency", | ||
"version": "1.17.0", | ||
"version": "1.18.0", | ||
"description": "The idempotency package for the Powertools for AWS Lambda (TypeScript) library. It provides options to make your Lambda functions idempotent and safe to retry.", | ||
@@ -27,3 +27,3 @@ "author": { | ||
"dependencies": { | ||
"@aws-lambda-powertools/commons": "^1.17.0", | ||
"@aws-lambda-powertools/commons": "^1.18.0", | ||
"@aws-sdk/util-base64-node": "^3.209.0", | ||
@@ -30,0 +30,0 @@ "jmespath": "^0.16.0" |
@@ -305,2 +305,3 @@ # Powertools for AWS Lambda (TypeScript) - Idempotency Utility <!-- omit in toc --> | ||
* [tecRacer GmbH & Co. KG](https://www.tecracer.com/) | ||
* [AppYourself](https://appyourself.net) | ||
@@ -307,0 +308,0 @@ ### Sharing your work |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
143825
2667
322
1