@plusscommunities/pluss-core-aws 2.0.25-beta.4 → 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 +22 -11
- package/package.json +1 -1
package/helper/hqPublishing.js
CHANGED
|
@@ -22,6 +22,7 @@ const moment = require("moment");
|
|
|
22
22
|
const indexQueryRecursive = require("../db/common/indexQueryRecursive");
|
|
23
23
|
const updateRef = require("../db/common/updateRef");
|
|
24
24
|
const editRef = require("../db/common/editRef");
|
|
25
|
+
const { log } = require("./index");
|
|
25
26
|
|
|
26
27
|
// Raw DocumentClient for atomic-increment operations that editRef can't do
|
|
27
28
|
// safely under concurrent stream-handler invocations.
|
|
@@ -311,8 +312,8 @@ const cascadeHqRetract = async (hqSourceRow, tableName, options = {}) => {
|
|
|
311
312
|
* @param {string} templateId — the `Id` of the contentLibrary row.
|
|
312
313
|
* @param {string} contentLibraryTable — entity-agnostic; caller passes the
|
|
313
314
|
* table name (without prefix).
|
|
314
|
-
* @returns {Promise<boolean>} `true` if increment applied; `false`
|
|
315
|
-
*
|
|
315
|
+
* @returns {Promise<boolean>} `true` if increment applied; `false` on graceful
|
|
316
|
+
* skip (table not shipped yet, or no template with that Id exists).
|
|
316
317
|
*/
|
|
317
318
|
const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
318
319
|
if (!templateId || !contentLibraryTable) {
|
|
@@ -321,11 +322,16 @@ const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
|
321
322
|
const params = {
|
|
322
323
|
TableName: `${process.env.tablePrefix}${contentLibraryTable}`,
|
|
323
324
|
Key: { Id: templateId },
|
|
324
|
-
UpdateExpression:
|
|
325
|
-
|
|
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)",
|
|
326
330
|
ExpressionAttributeValues: {
|
|
327
331
|
":inc": 1,
|
|
328
|
-
|
|
332
|
+
// epoch ms — the contentLibrary timestamp convention (matches
|
|
333
|
+
// UpdatedAt). Was .unix() (seconds); reconciled to .valueOf().
|
|
334
|
+
":now": moment().utc().valueOf(),
|
|
329
335
|
},
|
|
330
336
|
};
|
|
331
337
|
try {
|
|
@@ -336,16 +342,21 @@ const incrementTemplateUseCount = async (templateId, contentLibraryTable) => {
|
|
|
336
342
|
// Graceful degradation while Story C (contentLibrary table) is
|
|
337
343
|
// unshipped — see AC-B.3. Not an error; the rest of the stream
|
|
338
344
|
// handler should continue.
|
|
339
|
-
|
|
340
|
-
"incrementTemplateUseCount
|
|
345
|
+
log(
|
|
346
|
+
"incrementTemplateUseCount",
|
|
347
|
+
"TableNotFound",
|
|
348
|
+
"contentLibrary table not found — skipped",
|
|
341
349
|
);
|
|
342
350
|
return false;
|
|
343
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
|
+
}
|
|
344
358
|
// Anything else is genuinely unexpected — surface it.
|
|
345
|
-
|
|
346
|
-
"incrementTemplateUseCount: unexpected error",
|
|
347
|
-
error,
|
|
348
|
-
);
|
|
359
|
+
log("incrementTemplateUseCount", "Error", error);
|
|
349
360
|
throw error;
|
|
350
361
|
}
|
|
351
362
|
};
|
package/package.json
CHANGED