@plusscommunities/pluss-core-aws 2.0.25-beta.8 → 2.0.25-beta.9
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/helper/hqPublishing.js +16 -5
- package/package.json +1 -1
package/helper/hqPublishing.js
CHANGED
|
@@ -400,8 +400,8 @@ const cascadeHqRetract = async (hqSourceRow, tableName, options = {}) => {
|
|
|
400
400
|
* @param {string} templateId — the `Id` of the contentLibrary row.
|
|
401
401
|
* @param {string} contentLibraryTable — entity-agnostic; caller passes the
|
|
402
402
|
* table name (without prefix).
|
|
403
|
-
* @returns {Promise<boolean>} `true` if increment applied; `false`
|
|
404
|
-
*
|
|
403
|
+
* @returns {Promise<boolean>} `true` if increment applied; `false` on graceful
|
|
404
|
+
* skip (table not shipped yet, or no template with that Id exists).
|
|
405
405
|
*/
|
|
406
406
|
const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
407
407
|
if (!templateId || !contentLibraryTable) {
|
|
@@ -410,11 +410,16 @@ const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
|
410
410
|
const params = {
|
|
411
411
|
TableName: `${process.env.tablePrefix}${contentLibraryTable}`,
|
|
412
412
|
Key: { Id: templateId },
|
|
413
|
-
UpdateExpression:
|
|
414
|
-
|
|
413
|
+
UpdateExpression: "ADD UseCount :inc SET LastUsedTimestamp = :now",
|
|
414
|
+
// Guard against minting a phantom row: ADD on a missing key would CREATE
|
|
415
|
+
// it with UseCount=1. Only increment a template that actually exists; a
|
|
416
|
+
// stale/bogus TemplateId is skipped (ConditionalCheckFailed below).
|
|
417
|
+
ConditionExpression: "attribute_exists(Id)",
|
|
415
418
|
ExpressionAttributeValues: {
|
|
416
419
|
":inc": 1,
|
|
417
|
-
|
|
420
|
+
// epoch ms — the contentLibrary timestamp convention (matches
|
|
421
|
+
// UpdatedAt). Was .unix() (seconds); reconciled to .valueOf().
|
|
422
|
+
":now": moment().utc().valueOf(),
|
|
418
423
|
},
|
|
419
424
|
};
|
|
420
425
|
try {
|
|
@@ -432,6 +437,12 @@ const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
|
432
437
|
);
|
|
433
438
|
return false;
|
|
434
439
|
}
|
|
440
|
+
if (error?.code === "ConditionalCheckFailedException") {
|
|
441
|
+
// TemplateId references no existing template — skip rather than
|
|
442
|
+
// create a phantom row. Not an error; continue the stream handler.
|
|
443
|
+
log("incrementTemplateUseCount", "NoSuchTemplate", { templateId });
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
435
446
|
// Anything else is genuinely unexpected — surface it.
|
|
436
447
|
log("incrementTemplateUseCount", "Error", error);
|
|
437
448
|
throw error;
|
package/package.json
CHANGED