qarpeo 0.1.30 → 0.1.31
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/chunks/wrangler.mjs +1 -1
- package/dist/runtime/app/composables/cms.mjs +2 -2
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/index.get.mjs +13 -3
- package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/references.get.mjs +1 -1
- package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/cms/collections/[id].put.mjs +1 -1
- package/dist/runtime/server/routes/cms/collections/index.get.mjs +4 -1
- package/dist/runtime/server/routes/cms/collections/index.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/components/index.get.mjs +2 -0
- package/dist/runtime/server/routes/cms/export.post.mjs +13 -5
- package/dist/runtime/server/routes/cms/search.get.mjs +10 -4
- package/dist/runtime/server/routes/cms/sync.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/checkout.post.mjs +2 -2
- package/dist/runtime/server/routes/payments/pause.post.mjs +6 -5
- package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/usage.post.mjs +16 -11
- package/dist/runtime/server/routes/payments/webhook.post.d.ts +1 -0
- package/dist/runtime/server/utils/bots.mjs +1 -0
- package/dist/runtime/server/utils/cms/common.d.ts +4 -2
- package/dist/runtime/server/utils/cms/common.mjs +2 -5
- package/dist/runtime/server/utils/cms/git.mjs +6 -2
- package/dist/runtime/server/utils/cms-events.mjs +3 -2
- package/dist/runtime/server/utils/cms.mjs +3 -1
- package/dist/runtime/server/utils/crypto.d.ts +2 -0
- package/dist/runtime/server/utils/crypto.mjs +10 -0
- package/dist/runtime/server/utils/domains.mjs +2 -1
- package/dist/runtime/server/utils/mail.mjs +2 -0
- package/dist/runtime/server/utils/notifications.mjs +1 -3
- package/dist/runtime/server/utils/payments.d.ts +1 -0
- package/dist/runtime/server/utils/payments.mjs +40 -13
- package/dist/runtime/server/utils/sso.mjs +4 -2
- package/dist/runtime/server/utils/turnstile.mjs +2 -1
- package/package.json +1 -1
package/dist/chunks/wrangler.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
9
9
|
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
|
10
10
|
import { defu } from 'defu';
|
|
11
11
|
|
|
12
|
-
const version = "0.1.
|
|
12
|
+
const version = "0.1.31";
|
|
13
13
|
|
|
14
14
|
function scanSchemaExports(schemaFiles) {
|
|
15
15
|
const types = [];
|
|
@@ -156,8 +156,8 @@ export function queryCollection(collection) {
|
|
|
156
156
|
return builder;
|
|
157
157
|
},
|
|
158
158
|
order(field, direction = "ASC") {
|
|
159
|
-
_orderField = field;
|
|
160
|
-
_orderDirection = direction;
|
|
159
|
+
_orderField = String(field || "").replace(/[^a-zA-Z0-9_]/g, "") || "published_at";
|
|
160
|
+
_orderDirection = String(direction).trim().toUpperCase() === "DESC" ? "DESC" : "ASC";
|
|
161
161
|
return builder;
|
|
162
162
|
},
|
|
163
163
|
select(...fields) {
|
|
@@ -4,7 +4,7 @@ import { generatePreviewToken, getCMSConfig } from "../../../../utils/cms.mjs";
|
|
|
4
4
|
import { requireAuth } from "../../../../utils/context.mjs";
|
|
5
5
|
export default defineEventHandler(async (event) => {
|
|
6
6
|
const config = getCMSConfig(event);
|
|
7
|
-
await requireAuth(event, { role: config.roles });
|
|
7
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
8
8
|
const collection = getRouterParam(event, "collection");
|
|
9
9
|
const id = getRouterParam(event, "id");
|
|
10
10
|
const db = getD1Binding("DB", event);
|
|
@@ -3,7 +3,7 @@ import { publishCMSEntry, getCMSConfig } from "../../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const collection = getRouterParam(event, "collection");
|
|
8
8
|
if (config.collections[collection]?.mode === "file") {
|
|
9
9
|
throw createError({
|
|
@@ -3,7 +3,7 @@ import { submitCMSEntryForReview, rejectCMSEntryReview, getCMSConfig } from "../
|
|
|
3
3
|
import { requireAuth } from "../../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const collection = getRouterParam(event, "collection");
|
|
8
8
|
if (config.collections[collection]?.mode === "file") {
|
|
9
9
|
throw createError({
|
|
@@ -3,7 +3,7 @@ import { deleteCMSEntry, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const collection = getRouterParam(event, "collection");
|
|
8
8
|
if (config.collections[collection]?.mode === "file") {
|
|
9
9
|
throw createError({
|
|
@@ -3,7 +3,7 @@ import { updateCMSEntry, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const collection = getRouterParam(event, "collection");
|
|
8
8
|
if (config.collections[collection]?.mode === "file") {
|
|
9
9
|
throw createError({
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam, getQuery } from "nuxt/server";
|
|
2
|
-
import { queryCMSEntries } from "../../../utils/cms.mjs";
|
|
2
|
+
import { getCMSConfig, queryCMSEntries } from "../../../utils/cms.mjs";
|
|
3
|
+
import { getAuthContext } from "../../../utils/context.mjs";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const collection = getRouterParam(event, "collection");
|
|
5
6
|
const q = getQuery(event);
|
|
7
|
+
const auth = await getAuthContext(event);
|
|
8
|
+
const config = getCMSConfig(event);
|
|
9
|
+
const isEditor = auth?.user && (!config.roles || Array.isArray(config.roles) && config.roles.some((r) => r === auth.role) || auth.isAdmin);
|
|
10
|
+
const VALID_STATUSES = /* @__PURE__ */ new Set(["published", "draft", "archived", "all"]);
|
|
11
|
+
const rawStatus = q.status?.toLowerCase();
|
|
12
|
+
let status = "published";
|
|
13
|
+
if (isEditor && rawStatus && VALID_STATUSES.has(rawStatus)) {
|
|
14
|
+
status = rawStatus;
|
|
15
|
+
}
|
|
6
16
|
const opts = {
|
|
7
17
|
page: q.page ? Number(q.page) : 1,
|
|
8
|
-
limit: q.limit ? Number(q.limit) : 10,
|
|
18
|
+
limit: Math.min(100, Math.max(1, q.limit ? Number(q.limit) : 10)),
|
|
9
19
|
sort: q.sort || "published_at:desc",
|
|
10
|
-
status
|
|
20
|
+
status,
|
|
11
21
|
tag: q.tag,
|
|
12
22
|
fields: q.fields
|
|
13
23
|
};
|
|
@@ -3,7 +3,7 @@ import { createCMSEntry, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
const { user } = await requireAuth(event, { role: config.roles });
|
|
6
|
+
const { user } = await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const collection = getRouterParam(event, "collection");
|
|
8
8
|
if (config.collections[collection]?.mode === "file") {
|
|
9
9
|
throw createError({
|
|
@@ -3,7 +3,7 @@ import { getCMSConfig, getCollectionFields, queryCMSEntries } from "../../../uti
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const collection = getRouterParam(event, "collection");
|
|
8
8
|
const q = getQuery(event);
|
|
9
9
|
const fieldName = q.field;
|
|
@@ -3,7 +3,7 @@ import { deleteCMSCollection, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const id = getRouterParam(event, "id");
|
|
8
8
|
await deleteCMSCollection(event, id);
|
|
9
9
|
return { ok: true };
|
|
@@ -3,7 +3,7 @@ import { updateCMSCollection, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const id = getRouterParam(event, "id");
|
|
8
8
|
const body = await readBody(event);
|
|
9
9
|
await updateCMSCollection(event, id, body || {});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { defineEventHandler } from "nuxt/server";
|
|
2
|
-
import { listCMSCollections } from "../../../utils/cms.mjs";
|
|
2
|
+
import { getCMSConfig, listCMSCollections } from "../../../utils/cms.mjs";
|
|
3
|
+
import { requireAuth } from "../../../utils/context.mjs";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
5
|
+
const config = getCMSConfig(event);
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
4
7
|
const collections = await listCMSCollections(event);
|
|
5
8
|
return { collections };
|
|
6
9
|
});
|
|
@@ -3,7 +3,7 @@ import { createCMSCollection, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
const body = await readBody(event);
|
|
8
8
|
if (!body?.id || !body?.name) {
|
|
9
9
|
throw createError({ statusCode: 400, message: "id and name are required" });
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { defineEventHandler } from "nuxt/server";
|
|
2
2
|
import { getCMSConfig } from "../../../utils/cms.mjs";
|
|
3
|
+
import { requireAuth } from "../../../utils/context.mjs";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const config = getCMSConfig(event);
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
5
7
|
const components = config.components ?? {};
|
|
6
8
|
return {
|
|
7
9
|
components: Object.entries(components).map(([id, def]) => ({
|
|
@@ -4,12 +4,15 @@ import { getCMSConfig, formatFrontmatter, computeContentHash } from "../../utils
|
|
|
4
4
|
import { requireAuth } from "../../utils/context.mjs";
|
|
5
5
|
export default defineEventHandler(async (event) => {
|
|
6
6
|
const config = getCMSConfig(event);
|
|
7
|
-
await requireAuth(event, { role: config.roles });
|
|
8
|
-
let writeFile, mkdir;
|
|
7
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
8
|
+
let writeFile, mkdir, resolvePath, dirname;
|
|
9
9
|
try {
|
|
10
10
|
const fs = await import("node:fs/promises");
|
|
11
|
+
const path = await import("node:path");
|
|
11
12
|
writeFile = fs.writeFile;
|
|
12
13
|
mkdir = fs.mkdir;
|
|
14
|
+
resolvePath = path.resolve;
|
|
15
|
+
dirname = path.dirname;
|
|
13
16
|
} catch {
|
|
14
17
|
return {
|
|
15
18
|
ok: false,
|
|
@@ -20,15 +23,20 @@ export default defineEventHandler(async (event) => {
|
|
|
20
23
|
const rows = await db.prepare("SELECT * FROM _qarpeo_cms_entries ORDER BY collection_id, slug").all();
|
|
21
24
|
const entries = rows.results || [];
|
|
22
25
|
let exported = 0;
|
|
26
|
+
const baseContentDir = resolvePath(config.contentDir || "content");
|
|
23
27
|
for (const entry of entries) {
|
|
24
28
|
const collectionId = entry.collection_id;
|
|
25
29
|
const slug = entry.slug;
|
|
26
|
-
const
|
|
30
|
+
const safeCollectionId = String(collectionId || "").replace(/[^a-zA-Z0-9_-]/g, "");
|
|
31
|
+
const safeSlug = String(slug || "").split("/").map((part) => part.replace(/[^a-zA-Z0-9_-]/g, "")).filter((part) => Boolean(part) && part !== ".." && part !== ".").join("/");
|
|
32
|
+
if (!safeCollectionId || !safeSlug) continue;
|
|
33
|
+
const dir = resolvePath(baseContentDir, safeCollectionId);
|
|
34
|
+
const filePath = resolvePath(dir, `${safeSlug}.md`);
|
|
35
|
+
if (!filePath.startsWith(baseContentDir)) continue;
|
|
27
36
|
try {
|
|
28
|
-
await mkdir(
|
|
37
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
29
38
|
} catch {
|
|
30
39
|
}
|
|
31
|
-
const filePath = `${dir}/${slug}.md`;
|
|
32
40
|
let metadata = {};
|
|
33
41
|
try {
|
|
34
42
|
metadata = JSON.parse(entry.metadata_json || "{}");
|
|
@@ -17,15 +17,21 @@ export default defineEventHandler(async (event) => {
|
|
|
17
17
|
}
|
|
18
18
|
const auth = await getAuthContext(event);
|
|
19
19
|
const config = getCMSConfig(event);
|
|
20
|
-
const isEditor = auth?.user && (config.roles.some((r) => r === auth.role) || auth.isAdmin);
|
|
20
|
+
const isEditor = auth?.user && (!config.roles || Array.isArray(config.roles) && config.roles.some((r) => r === auth.role) || auth.isAdmin);
|
|
21
21
|
const db = getD1Binding("DB", event);
|
|
22
22
|
const conditions = [];
|
|
23
23
|
const binds = [];
|
|
24
|
+
const VALID_STATUSES = /* @__PURE__ */ new Set(["published", "draft", "archived"]);
|
|
24
25
|
if (!isEditor) {
|
|
25
26
|
conditions.push("status = 'published'");
|
|
26
|
-
} else if (query.status) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
} else if (query.status && query.status !== "all") {
|
|
28
|
+
const rawStatus = String(query.status).toLowerCase();
|
|
29
|
+
if (VALID_STATUSES.has(rawStatus)) {
|
|
30
|
+
conditions.push("status = ?");
|
|
31
|
+
binds.push(rawStatus);
|
|
32
|
+
} else {
|
|
33
|
+
conditions.push("status = 'published'");
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
if (collection) {
|
|
31
37
|
conditions.push("collection_id = ?");
|
|
@@ -3,7 +3,7 @@ import { getCMSConfig, seedCollectionsFromConfig, syncLocalContentFiles } from "
|
|
|
3
3
|
import { requireAuth } from "../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
await requireAuth(event, { role: config.roles });
|
|
6
|
+
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
7
7
|
await seedCollectionsFromConfig(event, config.collections);
|
|
8
8
|
const syncResult = await syncLocalContentFiles(
|
|
9
9
|
event,
|
|
@@ -7,8 +7,8 @@ const CheckoutBodySchema = z.object({
|
|
|
7
7
|
mode: z.enum(["subscription", "payment", "setup"]).optional(),
|
|
8
8
|
trialDays: z.number().int().nonnegative().optional(),
|
|
9
9
|
customerEmail: z.string().email().optional(),
|
|
10
|
-
successUrl: z.string().
|
|
11
|
-
cancelUrl: z.string().
|
|
10
|
+
successUrl: z.string().optional(),
|
|
11
|
+
cancelUrl: z.string().optional(),
|
|
12
12
|
metadata: z.record(z.string(), z.string()).optional()
|
|
13
13
|
});
|
|
14
14
|
export default defineEventHandler(async (event) => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defineEventHandler,
|
|
1
|
+
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { pauseSubscription } from "../../utils/payments.mjs";
|
|
4
|
+
const PauseBodySchema = z.object({
|
|
5
|
+
subscriptionId: z.string().min(1, "subscriptionId is required")
|
|
6
|
+
});
|
|
3
7
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
const body = await
|
|
5
|
-
if (!body.subscriptionId) {
|
|
6
|
-
throw createError({ statusCode: 400, message: "subscriptionId is required" });
|
|
7
|
-
}
|
|
8
|
+
const body = await readValidatedBody(event, (b) => PauseBodySchema.parse(b));
|
|
8
9
|
return pauseSubscription(event, body.subscriptionId);
|
|
9
10
|
});
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { createCustomerPortalSession } from "../../utils/payments.mjs";
|
|
4
4
|
const PortalBodySchema = z.object({
|
|
5
|
-
returnUrl: z.string().
|
|
5
|
+
returnUrl: z.string().optional()
|
|
6
6
|
});
|
|
7
7
|
export default defineEventHandler(async (event) => {
|
|
8
8
|
const body = await readValidatedBody(event, (b) => PortalBodySchema.parse(b));
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { defineEventHandler,
|
|
1
|
+
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { reportUsage } from "../../utils/payments.mjs";
|
|
4
|
+
const UsageBodySchema = z.object({
|
|
5
|
+
eventName: z.string().min(1, "eventName is required"),
|
|
6
|
+
quantity: z.number().int().positive().optional().default(1),
|
|
7
|
+
action: z.enum(["increment", "set"]).optional().default("increment"),
|
|
8
|
+
userId: z.string().optional(),
|
|
9
|
+
orgId: z.string().optional(),
|
|
10
|
+
customerId: z.string().optional(),
|
|
11
|
+
subscriptionId: z.string().optional(),
|
|
12
|
+
metadata: z.record(z.string(), z.string()).optional(),
|
|
13
|
+
timestamp: z.number().int().positive().optional()
|
|
14
|
+
});
|
|
3
15
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
const body = await
|
|
5
|
-
if (!body || !body.eventName) {
|
|
6
|
-
throw createError({
|
|
7
|
-
statusCode: 400,
|
|
8
|
-
statusMessage: "Bad Request",
|
|
9
|
-
message: "Missing required property: eventName"
|
|
10
|
-
});
|
|
11
|
-
}
|
|
16
|
+
const body = await readValidatedBody(event, (b) => UsageBodySchema.parse(b));
|
|
12
17
|
const result = await reportUsage(event, {
|
|
13
18
|
eventName: body.eventName,
|
|
14
|
-
quantity:
|
|
15
|
-
action: body.action
|
|
19
|
+
quantity: body.quantity,
|
|
20
|
+
action: body.action,
|
|
16
21
|
userId: body.userId,
|
|
17
22
|
orgId: body.orgId,
|
|
18
23
|
customerId: body.customerId,
|
|
@@ -180,6 +180,7 @@ export async function sendWhatsAppMessage(accessToken, phoneNumberId, to, text)
|
|
|
180
180
|
"Content-Type": "application/json",
|
|
181
181
|
Authorization: `Bearer ${accessToken}`
|
|
182
182
|
},
|
|
183
|
+
signal: AbortSignal.timeout(8e3),
|
|
183
184
|
body: JSON.stringify({
|
|
184
185
|
messaging_product: "whatsapp",
|
|
185
186
|
recipient_type: "individual",
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { type RequestEvent } from "nuxt/server";
|
|
2
2
|
import type { CMSOptions, CMSCollectionConfig, CMSGitHubConfig, CMSDeployTriggerConfig, CMSApprovalConfig } from "../../../../types";
|
|
3
|
+
import { nanoid } from "../crypto";
|
|
4
|
+
export { nanoid };
|
|
3
5
|
export declare function getCMSDb(event?: RequestEvent): any;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function getCMSConfig(event?: RequestEvent): Omit<Required<CMSOptions>, "github" | "deploy" | "approval" | "exclude" | "webhookSecret"> & {
|
|
6
|
+
export declare function getCMSConfig(event?: RequestEvent): Omit<Required<CMSOptions>, "github" | "deploy" | "approval" | "exclude" | "webhookSecret" | "roles"> & {
|
|
6
7
|
collections: Record<string, CMSCollectionConfig>;
|
|
7
8
|
github?: CMSGitHubConfig;
|
|
8
9
|
deploy?: CMSDeployTriggerConfig;
|
|
9
10
|
approval?: boolean | CMSApprovalConfig;
|
|
10
11
|
exclude?: string | string[];
|
|
11
12
|
webhookSecret?: string;
|
|
13
|
+
roles: string[];
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
16
|
* Resolves the effective approval workflow configuration for a collection. Returns null if approval
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "nuxt/server";
|
|
2
2
|
import { getD1Binding } from "../../../db.mjs";
|
|
3
|
+
import { nanoid } from "../crypto.mjs";
|
|
4
|
+
export { nanoid };
|
|
3
5
|
export function getCMSDb(event) {
|
|
4
6
|
try {
|
|
5
7
|
return getD1Binding("DB", event);
|
|
@@ -7,11 +9,6 @@ export function getCMSDb(event) {
|
|
|
7
9
|
return null;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
|
-
export function nanoid(size = 21) {
|
|
11
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
12
|
-
const bytes = crypto.getRandomValues(new Uint8Array(size));
|
|
13
|
-
return Array.from(bytes, (b) => chars[b % chars.length]).join("");
|
|
14
|
-
}
|
|
15
12
|
export function getCMSConfig(event) {
|
|
16
13
|
const rc = useRuntimeConfig(event);
|
|
17
14
|
const cfg = rc?.qarpeo?.cms || {};
|
|
@@ -93,7 +93,7 @@ export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
|
93
93
|
try {
|
|
94
94
|
const checkRes = await fetch(
|
|
95
95
|
`https://api.github.com/repos/${owner}/${repoName}/contents/${gitPath}?ref=${baseBranch}`,
|
|
96
|
-
{ headers }
|
|
96
|
+
{ headers, signal: AbortSignal.timeout(1e4) }
|
|
97
97
|
);
|
|
98
98
|
if (checkRes.ok) {
|
|
99
99
|
const checkData = await checkRes.json();
|
|
@@ -107,7 +107,7 @@ export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
|
107
107
|
try {
|
|
108
108
|
const refRes = await fetch(
|
|
109
109
|
`https://api.github.com/repos/${owner}/${repoName}/git/ref/heads/${ghConfig.prBase || baseBranch}`,
|
|
110
|
-
{ headers }
|
|
110
|
+
{ headers, signal: AbortSignal.timeout(1e4) }
|
|
111
111
|
);
|
|
112
112
|
if (refRes.ok) {
|
|
113
113
|
const refData = await refRes.json();
|
|
@@ -118,6 +118,7 @@ export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
|
118
118
|
{
|
|
119
119
|
method: "POST",
|
|
120
120
|
headers,
|
|
121
|
+
signal: AbortSignal.timeout(1e4),
|
|
121
122
|
body: JSON.stringify({
|
|
122
123
|
ref: `refs/heads/${newBranch}`,
|
|
123
124
|
sha: baseSha
|
|
@@ -139,6 +140,7 @@ export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
|
139
140
|
{
|
|
140
141
|
method: "DELETE",
|
|
141
142
|
headers,
|
|
143
|
+
signal: AbortSignal.timeout(1e4),
|
|
142
144
|
body: JSON.stringify({
|
|
143
145
|
message: commitMsg,
|
|
144
146
|
sha: existingSha,
|
|
@@ -161,6 +163,7 @@ export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
|
161
163
|
{
|
|
162
164
|
method: "PUT",
|
|
163
165
|
headers,
|
|
166
|
+
signal: AbortSignal.timeout(1e4),
|
|
164
167
|
body: JSON.stringify({
|
|
165
168
|
message: commitMsg,
|
|
166
169
|
content: base64Content,
|
|
@@ -185,6 +188,7 @@ export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
|
185
188
|
const prRes = await fetch(`https://api.github.com/repos/${owner}/${repoName}/pulls`, {
|
|
186
189
|
method: "POST",
|
|
187
190
|
headers,
|
|
191
|
+
signal: AbortSignal.timeout(1e4),
|
|
188
192
|
body: JSON.stringify({
|
|
189
193
|
title: commitMsg,
|
|
190
194
|
head: targetBranch,
|
|
@@ -39,7 +39,7 @@ export async function fireCMSWebhooks(config, collectionId, event, entry) {
|
|
|
39
39
|
console.warn("[qarpeo] webhook signature error:", e);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
fetch(hook.url, { method: "POST", headers, body: bodyStr }).catch((e) => {
|
|
42
|
+
fetch(hook.url, { method: "POST", headers, body: bodyStr, signal: AbortSignal.timeout(8e3) }).catch((e) => {
|
|
43
43
|
console.warn(`[qarpeo] webhook POST to ${hook.url} failed:`, e);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -51,7 +51,7 @@ export async function fireCMSDeployTrigger(config, collectionId, _event) {
|
|
|
51
51
|
const trigger = deploy.trigger ?? "on-publish";
|
|
52
52
|
if (trigger !== "on-publish") return;
|
|
53
53
|
if (deploy.hookUrl) {
|
|
54
|
-
fetch(deploy.hookUrl, { method: "POST" }).catch((e) => {
|
|
54
|
+
fetch(deploy.hookUrl, { method: "POST", signal: AbortSignal.timeout(8e3) }).catch((e) => {
|
|
55
55
|
console.warn("[qarpeo] deploy hook POST failed:", e);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -72,6 +72,7 @@ export async function fireCMSDeployTrigger(config, collectionId, _event) {
|
|
|
72
72
|
"Content-Type": "application/json",
|
|
73
73
|
"User-Agent": "qarpeo-cms"
|
|
74
74
|
},
|
|
75
|
+
signal: AbortSignal.timeout(8e3),
|
|
75
76
|
body: JSON.stringify({ ref })
|
|
76
77
|
}).catch((e) => {
|
|
77
78
|
console.warn("[qarpeo] GitHub workflow dispatch failed:", e);
|
|
@@ -3002,7 +3002,9 @@ export function queryCollection(event, collection) {
|
|
|
3002
3002
|
return builder;
|
|
3003
3003
|
},
|
|
3004
3004
|
order(field, direction = "ASC") {
|
|
3005
|
-
|
|
3005
|
+
const sanitizedField = String(field || "").replace(/[^a-zA-Z0-9_]/g, "");
|
|
3006
|
+
const dir = String(direction).trim().toUpperCase() === "DESC" ? "desc" : "asc";
|
|
3007
|
+
_sort = `${sanitizedField || "published_at"}:${dir}`;
|
|
3006
3008
|
return builder;
|
|
3007
3009
|
},
|
|
3008
3010
|
where(field, value) {
|
|
@@ -9,6 +9,8 @@ import type { RequestEvent } from "nuxt/server";
|
|
|
9
9
|
export declare function timingSafeEqualString(a: string, b: string): boolean;
|
|
10
10
|
/** Alias for timingSafeEqualString */
|
|
11
11
|
export declare const constantTimeEqual: typeof timingSafeEqualString;
|
|
12
|
+
/** Generates a cryptographically secure URL-friendly unique identifier using Web Crypto. */
|
|
13
|
+
export declare function nanoid(size?: number): string;
|
|
12
14
|
/**
|
|
13
15
|
* Encrypts a sensitive string (e.g. an OAuth access/refresh token) with AES-256-GCM. The returned
|
|
14
16
|
* value is prefixed with `enc:` followed by the hex-encoded `iv ‖ ciphertext` so legacy plaintext
|
|
@@ -17,6 +17,16 @@ export function timingSafeEqualString(a, b) {
|
|
|
17
17
|
return diff === 0;
|
|
18
18
|
}
|
|
19
19
|
export const constantTimeEqual = timingSafeEqualString;
|
|
20
|
+
const NANOID_CHARS = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLFGQZbfghjklqvwyzrict";
|
|
21
|
+
export function nanoid(size = 21) {
|
|
22
|
+
const bytes = new Uint8Array(size);
|
|
23
|
+
crypto.getRandomValues(bytes);
|
|
24
|
+
let id = "";
|
|
25
|
+
for (let i = 0; i < size; i++) {
|
|
26
|
+
id += NANOID_CHARS[bytes[i] & 63];
|
|
27
|
+
}
|
|
28
|
+
return id;
|
|
29
|
+
}
|
|
20
30
|
const ENC_PREFIX = "enc:";
|
|
21
31
|
function resolveTokenSecret(event) {
|
|
22
32
|
return getSessionSecret(event);
|
|
@@ -71,6 +71,7 @@ export async function deliverMailDirect(options, event) {
|
|
|
71
71
|
}
|
|
72
72
|
const res = await fetch("https://api.resend.com/emails", {
|
|
73
73
|
method: "POST",
|
|
74
|
+
signal: AbortSignal.timeout(8e3),
|
|
74
75
|
headers: {
|
|
75
76
|
Authorization: `Bearer ${apiKey}`,
|
|
76
77
|
"Content-Type": "application/json"
|
|
@@ -101,6 +102,7 @@ export async function deliverMailDirect(options, event) {
|
|
|
101
102
|
}
|
|
102
103
|
const res = await fetch("https://api.postmarkapp.com/email", {
|
|
103
104
|
method: "POST",
|
|
105
|
+
signal: AbortSignal.timeout(8e3),
|
|
104
106
|
headers: {
|
|
105
107
|
"X-Postmark-Server-Token": apiKey,
|
|
106
108
|
"Content-Type": "application/json"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getCloudflareEnv } from "../../bindings.mjs";
|
|
2
2
|
import { sendMail } from "./mail.mjs";
|
|
3
|
+
import { nanoid } from "./crypto.mjs";
|
|
3
4
|
import { signVapidHeader, encryptWebPushPayload } from "./vapid.mjs";
|
|
4
5
|
function getD1(event) {
|
|
5
6
|
const env = getCloudflareEnv(event);
|
|
@@ -14,9 +15,6 @@ function getTable() {
|
|
|
14
15
|
function getPushTable() {
|
|
15
16
|
return "_qarpeo_push_subscriptions";
|
|
16
17
|
}
|
|
17
|
-
function nanoid() {
|
|
18
|
-
return crypto.randomUUID().replace(/-/g, "");
|
|
19
|
-
}
|
|
20
18
|
function parseChannels(raw) {
|
|
21
19
|
try {
|
|
22
20
|
return JSON.parse(raw);
|
|
@@ -17,6 +17,7 @@ export declare function verifyPaddleSignature(rawBody: string, signatureHeader:
|
|
|
17
17
|
export declare function processPaymentWebhook(event: RequestEvent, rawBody: string): Promise<{
|
|
18
18
|
success: boolean;
|
|
19
19
|
eventType?: string;
|
|
20
|
+
error?: string;
|
|
20
21
|
} | {
|
|
21
22
|
received: true;
|
|
22
23
|
skipped: true;
|
|
@@ -3,16 +3,12 @@ import { createError, useRuntimeConfig, getRequestHeader } from "nuxt/server";
|
|
|
3
3
|
import { getD1Binding } from "../../db.mjs";
|
|
4
4
|
import { getQarpeoConfig } from "./config.mjs";
|
|
5
5
|
import { getAuthContext } from "./context.mjs";
|
|
6
|
+
import { nanoid } from "./crypto.mjs";
|
|
6
7
|
const STRIPE_API_VERSION = "2024-06-20";
|
|
7
8
|
function getPaymentsDb(event) {
|
|
8
9
|
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
9
10
|
return getD1Binding(bindingName, event);
|
|
10
11
|
}
|
|
11
|
-
function nanoid(size = 21) {
|
|
12
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
13
|
-
const bytes = crypto.getRandomValues(new Uint8Array(size));
|
|
14
|
-
return Array.from(bytes, (b) => chars[b % chars.length]).join("");
|
|
15
|
-
}
|
|
16
12
|
export function getPaymentsConfig(event) {
|
|
17
13
|
const cfg = getQarpeoConfig(event).payments || {};
|
|
18
14
|
const cfEnv = event?.context?.cloudflare?.env || globalThis.__qarpeo_env__ || {};
|
|
@@ -208,11 +204,8 @@ export async function processPaymentWebhook(event, rawBody) {
|
|
|
208
204
|
isValid = await verifyPolarSignature(rawBody, sig, config.webhookSecret);
|
|
209
205
|
}
|
|
210
206
|
if (!isValid) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
statusMessage: "Bad Request",
|
|
214
|
-
message: "Invalid webhook signature"
|
|
215
|
-
});
|
|
207
|
+
console.warn(`[qarpeo:payments] Invalid webhook signature from provider: ${provider}`);
|
|
208
|
+
return { success: false, error: "invalid_signature" };
|
|
216
209
|
}
|
|
217
210
|
let payload;
|
|
218
211
|
try {
|
|
@@ -585,8 +578,16 @@ export async function createCheckoutSession(event, options) {
|
|
|
585
578
|
});
|
|
586
579
|
}
|
|
587
580
|
const siteUrl = useRuntimeConfig().public?.siteUrl || "http://localhost:3000";
|
|
588
|
-
const successUrl =
|
|
589
|
-
|
|
581
|
+
const successUrl = safeReturnUrl(
|
|
582
|
+
options.successUrl || config.checkoutUrls?.success,
|
|
583
|
+
siteUrl,
|
|
584
|
+
"/?checkout=success"
|
|
585
|
+
);
|
|
586
|
+
const cancelUrl = safeReturnUrl(
|
|
587
|
+
options.cancelUrl || config.checkoutUrls?.cancel,
|
|
588
|
+
siteUrl,
|
|
589
|
+
"/?checkout=cancelled"
|
|
590
|
+
);
|
|
590
591
|
const metadata = {
|
|
591
592
|
planId,
|
|
592
593
|
...options.metadata
|
|
@@ -633,6 +634,7 @@ export async function createCheckoutSession(event, options) {
|
|
|
633
634
|
}
|
|
634
635
|
const res = await fetch("https://api.stripe.com/v1/checkout/sessions", {
|
|
635
636
|
method: "POST",
|
|
637
|
+
signal: AbortSignal.timeout(1e4),
|
|
636
638
|
headers: {
|
|
637
639
|
Authorization: `Bearer ${config.secretKey}`,
|
|
638
640
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -653,6 +655,25 @@ export async function createCheckoutSession(event, options) {
|
|
|
653
655
|
message: `Checkout not implemented for provider ${config.provider}`
|
|
654
656
|
});
|
|
655
657
|
}
|
|
658
|
+
function safeReturnUrl(url, siteUrl, fallbackPath = "/") {
|
|
659
|
+
const cleanSiteUrl = siteUrl.replace(/\/+$/, "");
|
|
660
|
+
const fallback = `${cleanSiteUrl}${fallbackPath.startsWith("/") ? fallbackPath : "/" + fallbackPath}`;
|
|
661
|
+
if (typeof url !== "string" || !url.trim()) return fallback;
|
|
662
|
+
const trimmed = url.trim();
|
|
663
|
+
if (trimmed.startsWith("/") && !trimmed.startsWith("//") && !trimmed.startsWith("/\\") && !trimmed.startsWith("\\")) {
|
|
664
|
+
if (/[\r\n\0]/.test(trimmed)) return fallback;
|
|
665
|
+
return `${cleanSiteUrl}${trimmed}`;
|
|
666
|
+
}
|
|
667
|
+
try {
|
|
668
|
+
const parsed = new URL(trimmed);
|
|
669
|
+
const site = new URL(cleanSiteUrl);
|
|
670
|
+
if (parsed.origin === site.origin) {
|
|
671
|
+
return parsed.toString();
|
|
672
|
+
}
|
|
673
|
+
} catch {
|
|
674
|
+
}
|
|
675
|
+
return fallback;
|
|
676
|
+
}
|
|
656
677
|
export async function createCustomerPortalSession(event, options) {
|
|
657
678
|
await ensurePaymentsTables(event);
|
|
658
679
|
const db = getPaymentsDb(event);
|
|
@@ -670,13 +691,14 @@ export async function createCustomerPortalSession(event, options) {
|
|
|
670
691
|
throw createError({ statusCode: 404, message: "No customer account found for this user" });
|
|
671
692
|
}
|
|
672
693
|
const siteUrl = useRuntimeConfig().public?.siteUrl || "http://localhost:3000";
|
|
673
|
-
const returnUrl = options?.returnUrl || config.portalReturnUrl
|
|
694
|
+
const returnUrl = safeReturnUrl(options?.returnUrl || config.portalReturnUrl, siteUrl, "/");
|
|
674
695
|
if (config.provider === "stripe") {
|
|
675
696
|
const params = new URLSearchParams();
|
|
676
697
|
params.set("customer", cust.customer_id);
|
|
677
698
|
params.set("return_url", returnUrl);
|
|
678
699
|
const res = await fetch("https://api.stripe.com/v1/billing_portal/sessions", {
|
|
679
700
|
method: "POST",
|
|
701
|
+
signal: AbortSignal.timeout(1e4),
|
|
680
702
|
headers: {
|
|
681
703
|
Authorization: `Bearer ${config.secretKey}`,
|
|
682
704
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -720,6 +742,7 @@ export async function cancelSubscription(event, subscriptionId) {
|
|
|
720
742
|
params.set("cancel_at_period_end", "true");
|
|
721
743
|
const res = await fetch(`https://api.stripe.com/v1/subscriptions/${subscriptionId}`, {
|
|
722
744
|
method: "POST",
|
|
745
|
+
signal: AbortSignal.timeout(1e4),
|
|
723
746
|
headers: {
|
|
724
747
|
Authorization: `Bearer ${config.secretKey}`,
|
|
725
748
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -762,6 +785,7 @@ export async function pauseSubscription(event, subscriptionId) {
|
|
|
762
785
|
params.set("pause_collection[resumes_at]", "");
|
|
763
786
|
const res = await fetch(`https://api.stripe.com/v1/subscriptions/${subscriptionId}`, {
|
|
764
787
|
method: "POST",
|
|
788
|
+
signal: AbortSignal.timeout(1e4),
|
|
765
789
|
headers: {
|
|
766
790
|
Authorization: `Bearer ${config.secretKey}`,
|
|
767
791
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -804,6 +828,7 @@ export async function changePlan(event, subscriptionId, newPriceId) {
|
|
|
804
828
|
}
|
|
805
829
|
const getRes = await fetch(`https://api.stripe.com/v1/subscriptions/${subscriptionId}`, {
|
|
806
830
|
method: "GET",
|
|
831
|
+
signal: AbortSignal.timeout(1e4),
|
|
807
832
|
headers: {
|
|
808
833
|
Authorization: `Bearer ${config.secretKey}`,
|
|
809
834
|
"Stripe-Version": STRIPE_API_VERSION
|
|
@@ -827,6 +852,7 @@ export async function changePlan(event, subscriptionId, newPriceId) {
|
|
|
827
852
|
params.set("proration_behavior", "create_prorations");
|
|
828
853
|
const res = await fetch(`https://api.stripe.com/v1/subscriptions/${subscriptionId}`, {
|
|
829
854
|
method: "POST",
|
|
855
|
+
signal: AbortSignal.timeout(1e4),
|
|
830
856
|
headers: {
|
|
831
857
|
Authorization: `Bearer ${config.secretKey}`,
|
|
832
858
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -989,6 +1015,7 @@ export async function reportUsage(event, options) {
|
|
|
989
1015
|
params.set("timestamp", String(Math.floor(timestamp / 1e3)));
|
|
990
1016
|
const res = await fetch("https://api.stripe.com/v1/billing/meter_events", {
|
|
991
1017
|
method: "POST",
|
|
1018
|
+
signal: AbortSignal.timeout(1e4),
|
|
992
1019
|
headers: {
|
|
993
1020
|
Authorization: `Bearer ${config.secretKey}`,
|
|
994
1021
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
@@ -207,7 +207,8 @@ export async function exchangeOIDCCode(options) {
|
|
|
207
207
|
const tokenRes = await fetch(options.tokenUrl, {
|
|
208
208
|
method: "POST",
|
|
209
209
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
210
|
-
body: body.toString()
|
|
210
|
+
body: body.toString(),
|
|
211
|
+
signal: AbortSignal.timeout(8e3)
|
|
211
212
|
});
|
|
212
213
|
if (!tokenRes.ok) {
|
|
213
214
|
const errText = await tokenRes.text();
|
|
@@ -222,7 +223,8 @@ export async function exchangeOIDCCode(options) {
|
|
|
222
223
|
let profileData = {};
|
|
223
224
|
if (options.userinfoUrl && accessToken) {
|
|
224
225
|
const userinfoRes = await fetch(options.userinfoUrl, {
|
|
225
|
-
headers: { Authorization: `Bearer ${accessToken}` }
|
|
226
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
227
|
+
signal: AbortSignal.timeout(8e3)
|
|
226
228
|
});
|
|
227
229
|
if (userinfoRes.ok) {
|
|
228
230
|
profileData = await userinfoRes.json();
|
|
@@ -40,7 +40,8 @@ export async function verifyTurnstileToken(event, token, remoteIp) {
|
|
|
40
40
|
try {
|
|
41
41
|
const res = await fetch("https://challenges.cloudflare.com/turnstile/v0/siteverify", {
|
|
42
42
|
method: "POST",
|
|
43
|
-
body: formData
|
|
43
|
+
body: formData,
|
|
44
|
+
signal: AbortSignal.timeout(8e3)
|
|
44
45
|
});
|
|
45
46
|
const outcome = await res.json();
|
|
46
47
|
return {
|