powr-sdk-api 4.18.0 → 4.18.1
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 +1 -0
- package/dist/utils/posts.js +7 -0
- package/dist/utils/posts.test.js +24 -1
- package/package.json +1 -1
package/dist/routes/posts.js
CHANGED
|
@@ -606,6 +606,7 @@ router.post("/", verifyToken, async (req, res) => {
|
|
|
606
606
|
title: fields.title,
|
|
607
607
|
description: fields.description || "",
|
|
608
608
|
coverUrl: fields.coverUrl || "",
|
|
609
|
+
sourcePdfUrl: fields.sourcePdfUrl || "",
|
|
609
610
|
bodyMd: fields.bodyMd || "",
|
|
610
611
|
tags: fields.tags || [],
|
|
611
612
|
readMinutes: fields.readMinutes || 1,
|
package/dist/utils/posts.js
CHANGED
|
@@ -60,6 +60,12 @@ function parsePostWrite(body, partial) {
|
|
|
60
60
|
if (coverUrl && !/^https:\/\//i.test(coverUrl)) bad("Cover must be an https link.");
|
|
61
61
|
out.coverUrl = coverUrl;
|
|
62
62
|
}
|
|
63
|
+
if (has("sourcePdfUrl")) {
|
|
64
|
+
const sourcePdfUrl = String(source.sourcePdfUrl || "").trim();
|
|
65
|
+
if (sourcePdfUrl && !/^https:\/\//i.test(sourcePdfUrl)) bad("The PDF must be an https link.");
|
|
66
|
+
if (sourcePdfUrl && !/\.pdf(\?|#|$)/i.test(sourcePdfUrl)) bad("The file must be a PDF.");
|
|
67
|
+
out.sourcePdfUrl = sourcePdfUrl;
|
|
68
|
+
}
|
|
63
69
|
if (Object.prototype.hasOwnProperty.call(source, "slug")) {
|
|
64
70
|
out.slug = slugify(source.slug);
|
|
65
71
|
}
|
|
@@ -123,6 +129,7 @@ function staffPost(row, author) {
|
|
|
123
129
|
status: row.status || "draft",
|
|
124
130
|
authorId: row.authorId ? String(row.authorId) : "",
|
|
125
131
|
slugLocked: !!row.slugLocked,
|
|
132
|
+
sourcePdfUrl: row.sourcePdfUrl || "",
|
|
126
133
|
createdAt: row.createdAt || null,
|
|
127
134
|
updatedAt: row.updatedAt || null
|
|
128
135
|
});
|
package/dist/utils/posts.test.js
CHANGED
|
@@ -5,6 +5,7 @@ const {
|
|
|
5
5
|
parsePostWrite,
|
|
6
6
|
parseAuthorWrite,
|
|
7
7
|
publicCard,
|
|
8
|
+
staffPost,
|
|
8
9
|
readMinutes
|
|
9
10
|
} = require("./posts");
|
|
10
11
|
describe("slugify", () => {
|
|
@@ -28,6 +29,16 @@ describe("parsePostWrite", () => {
|
|
|
28
29
|
expect(fields.tags).toEqual(["vibe", "ai"]);
|
|
29
30
|
expect(fields.readMinutes).toBe(1);
|
|
30
31
|
});
|
|
32
|
+
it("keeps a pdf link and rejects anything else", () => {
|
|
33
|
+
expect(parsePostWrite({
|
|
34
|
+
title: "Guide",
|
|
35
|
+
sourcePdfUrl: "https://cdn.example/guide.pdf"
|
|
36
|
+
}).sourcePdfUrl).toBe("https://cdn.example/guide.pdf");
|
|
37
|
+
expect(() => parsePostWrite({
|
|
38
|
+
title: "Guide",
|
|
39
|
+
sourcePdfUrl: "https://cdn.example/guide.png"
|
|
40
|
+
})).toThrow("The file must be a PDF.");
|
|
41
|
+
});
|
|
31
42
|
it("rejects a cover that is not https", () => {
|
|
32
43
|
expect(() => parsePostWrite({
|
|
33
44
|
title: "Hi",
|
|
@@ -66,13 +77,25 @@ describe("publicCard", () => {
|
|
|
66
77
|
slug: "hi",
|
|
67
78
|
title: "Hi",
|
|
68
79
|
bodyMd: "secret",
|
|
69
|
-
status: "published"
|
|
80
|
+
status: "published",
|
|
81
|
+
sourcePdfUrl: "https://cdn.example/a.pdf"
|
|
70
82
|
}, {
|
|
71
83
|
handle: "om",
|
|
72
84
|
displayName: "Om"
|
|
73
85
|
});
|
|
74
86
|
expect(card.bodyMd).toBeUndefined();
|
|
75
87
|
expect(card.status).toBeUndefined();
|
|
88
|
+
expect(card.sourcePdfUrl).toBeUndefined();
|
|
76
89
|
expect(card.author.displayName).toBe("Om");
|
|
77
90
|
});
|
|
91
|
+
it("shows the pdf only to staff", () => {
|
|
92
|
+
const row = {
|
|
93
|
+
_id: "a",
|
|
94
|
+
title: "Hi",
|
|
95
|
+
sourcePdfUrl: "https://cdn.example/a.pdf",
|
|
96
|
+
status: "in_review"
|
|
97
|
+
};
|
|
98
|
+
expect(staffPost(row, null).sourcePdfUrl).toBe("https://cdn.example/a.pdf");
|
|
99
|
+
expect(publicCard(row, null).sourcePdfUrl).toBeUndefined();
|
|
100
|
+
});
|
|
78
101
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powr-sdk-api",
|
|
3
|
-
"version": "4.18.
|
|
3
|
+
"version": "4.18.1",
|
|
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",
|