powr-sdk-api 4.19.1 → 4.19.2
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/dist/routes/posts.js +4 -0
- package/dist/utils/posts.js +8 -0
- package/dist/utils/posts.test.js +11 -0
- package/package.json +1 -1
package/dist/routes/posts.js
CHANGED
|
@@ -19,6 +19,7 @@ const {
|
|
|
19
19
|
const {
|
|
20
20
|
slugify,
|
|
21
21
|
parsePostWrite,
|
|
22
|
+
parsePublishedAt,
|
|
22
23
|
parseAuthorWrite,
|
|
23
24
|
publicAuthor,
|
|
24
25
|
publicCard,
|
|
@@ -667,6 +668,9 @@ router.patch("/:id", verifyToken, async (req, res) => {
|
|
|
667
668
|
});
|
|
668
669
|
}
|
|
669
670
|
const fields = parsePostWrite(req.body || {}, true);
|
|
671
|
+
if (access.editor && Object.prototype.hasOwnProperty.call(req.body || {}, "publishedAt")) {
|
|
672
|
+
fields.publishedAt = parsePublishedAt(req.body.publishedAt);
|
|
673
|
+
}
|
|
670
674
|
if (fields.slug && (current.slugLocked || current.status === "published")) delete fields.slug;
|
|
671
675
|
if (fields.slug && fields.slug !== current.slug) {
|
|
672
676
|
fields.slug = await uniqueSlug(db, access.projectId, fields.slug, id);
|
package/dist/utils/posts.js
CHANGED
|
@@ -28,6 +28,13 @@ function parseTags(value) {
|
|
|
28
28
|
}
|
|
29
29
|
return tags;
|
|
30
30
|
}
|
|
31
|
+
function parsePublishedAt(value) {
|
|
32
|
+
if (value == null || String(value).trim() === "") bad("Publish date is required.");
|
|
33
|
+
const date = new Date(value);
|
|
34
|
+
if (Number.isNaN(date.getTime())) bad("Publish date is not a real date.");
|
|
35
|
+
if (date.getTime() > Date.now() + 2 * 60 * 1000) bad("Publish date cannot be in the future.");
|
|
36
|
+
return date;
|
|
37
|
+
}
|
|
31
38
|
function readMinutes(markdown) {
|
|
32
39
|
const words = String(markdown || "").trim().split(/\s+/).filter(Boolean).length;
|
|
33
40
|
if (!words) return 1;
|
|
@@ -151,6 +158,7 @@ module.exports = {
|
|
|
151
158
|
ROLES,
|
|
152
159
|
slugify,
|
|
153
160
|
parseTags,
|
|
161
|
+
parsePublishedAt,
|
|
154
162
|
readMinutes,
|
|
155
163
|
parsePostWrite,
|
|
156
164
|
parseAuthorWrite,
|
package/dist/utils/posts.test.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const {
|
|
4
4
|
slugify,
|
|
5
5
|
parsePostWrite,
|
|
6
|
+
parsePublishedAt,
|
|
6
7
|
parseAuthorWrite,
|
|
7
8
|
publicCard,
|
|
8
9
|
staffPost,
|
|
@@ -53,6 +54,16 @@ describe("parsePostWrite", () => {
|
|
|
53
54
|
});
|
|
54
55
|
});
|
|
55
56
|
});
|
|
57
|
+
describe("parsePublishedAt", () => {
|
|
58
|
+
it("keeps a past date", () => {
|
|
59
|
+
expect(parsePublishedAt("2019-01-20T04:30:00.000Z").toISOString()).toBe("2019-01-20T04:30:00.000Z");
|
|
60
|
+
});
|
|
61
|
+
it("rejects a future date and a blank date", () => {
|
|
62
|
+
expect(() => parsePublishedAt("2099-01-01T00:00:00.000Z")).toThrow("Publish date cannot be in the future.");
|
|
63
|
+
expect(() => parsePublishedAt("")).toThrow("Publish date is required.");
|
|
64
|
+
expect(() => parsePublishedAt("not-a-date")).toThrow("Publish date is not a real date.");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
56
67
|
describe("readMinutes", () => {
|
|
57
68
|
it("rounds about 200 words to a minute", () => {
|
|
58
69
|
const words = new Array(400).fill("word").join(" ");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powr-sdk-api",
|
|
3
|
-
"version": "4.19.
|
|
3
|
+
"version": "4.19.2",
|
|
4
4
|
"description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|