@plusscommunities/pluss-core-aws 2.0.25-beta.5 → 2.0.25-beta.6
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
|
@@ -312,8 +312,8 @@ const cascadeHqRetract = async (hqSourceRow, tableName, options = {}) => {
|
|
|
312
312
|
* @param {string} templateId — the `Id` of the contentLibrary row.
|
|
313
313
|
* @param {string} contentLibraryTable — entity-agnostic; caller passes the
|
|
314
314
|
* table name (without prefix).
|
|
315
|
-
* @returns {Promise<boolean>} `true` if increment applied; `false`
|
|
316
|
-
*
|
|
315
|
+
* @returns {Promise<boolean>} `true` if increment applied; `false` on graceful
|
|
316
|
+
* skip (table not shipped yet, or no template with that Id exists).
|
|
317
317
|
*/
|
|
318
318
|
const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
319
319
|
if (!templateId || !contentLibraryTable) {
|
|
@@ -322,11 +322,16 @@ const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
|
322
322
|
const params = {
|
|
323
323
|
TableName: `${process.env.tablePrefix}${contentLibraryTable}`,
|
|
324
324
|
Key: { Id: templateId },
|
|
325
|
-
UpdateExpression:
|
|
326
|
-
|
|
325
|
+
UpdateExpression: "ADD UseCount :inc SET LastUsedTimestamp = :now",
|
|
326
|
+
// Guard against minting a phantom row: ADD on a missing key would CREATE
|
|
327
|
+
// it with UseCount=1. Only increment a template that actually exists; a
|
|
328
|
+
// stale/bogus TemplateId is skipped (ConditionalCheckFailed below).
|
|
329
|
+
ConditionExpression: "attribute_exists(Id)",
|
|
327
330
|
ExpressionAttributeValues: {
|
|
328
331
|
":inc": 1,
|
|
329
|
-
|
|
332
|
+
// epoch ms — the contentLibrary timestamp convention (matches
|
|
333
|
+
// UpdatedAt). Was .unix() (seconds); reconciled to .valueOf().
|
|
334
|
+
":now": moment().utc().valueOf(),
|
|
330
335
|
},
|
|
331
336
|
};
|
|
332
337
|
try {
|
|
@@ -344,6 +349,12 @@ const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
|
344
349
|
);
|
|
345
350
|
return false;
|
|
346
351
|
}
|
|
352
|
+
if (error?.code === "ConditionalCheckFailedException") {
|
|
353
|
+
// TemplateId references no existing template — skip rather than
|
|
354
|
+
// create a phantom row. Not an error; continue the stream handler.
|
|
355
|
+
log("incrementTemplateUseCount", "NoSuchTemplate", { templateId });
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
347
358
|
// Anything else is genuinely unexpected — surface it.
|
|
348
359
|
log("incrementTemplateUseCount", "Error", error);
|
|
349
360
|
throw error;
|
package/package.json
CHANGED