dineway 0.1.3 → 0.1.4
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/package.json +6 -3
- package/src/astro/routes/PluginRegistry.tsx +21 -0
- package/src/astro/routes/admin.astro +83 -0
- package/src/astro/routes/api/admin/allowed-domains/[domain].ts +112 -0
- package/src/astro/routes/api/admin/allowed-domains/index.ts +108 -0
- package/src/astro/routes/api/admin/api-tokens/[id].ts +40 -0
- package/src/astro/routes/api/admin/api-tokens/index.ts +68 -0
- package/src/astro/routes/api/admin/bylines/[id]/index.ts +87 -0
- package/src/astro/routes/api/admin/bylines/index.ts +72 -0
- package/src/astro/routes/api/admin/comments/[id]/status.ts +120 -0
- package/src/astro/routes/api/admin/comments/[id].ts +64 -0
- package/src/astro/routes/api/admin/comments/bulk.ts +42 -0
- package/src/astro/routes/api/admin/comments/counts.ts +30 -0
- package/src/astro/routes/api/admin/comments/index.ts +46 -0
- package/src/astro/routes/api/admin/hooks/exclusive/[hookName].ts +91 -0
- package/src/astro/routes/api/admin/hooks/exclusive/index.ts +51 -0
- package/src/astro/routes/api/admin/oauth-clients/[id].ts +110 -0
- package/src/astro/routes/api/admin/oauth-clients/index.ts +71 -0
- package/src/astro/routes/api/admin/plugins/[id]/disable.ts +39 -0
- package/src/astro/routes/api/admin/plugins/[id]/enable.ts +39 -0
- package/src/astro/routes/api/admin/plugins/[id]/index.ts +38 -0
- package/src/astro/routes/api/admin/plugins/[id]/uninstall.ts +48 -0
- package/src/astro/routes/api/admin/plugins/[id]/update.ts +59 -0
- package/src/astro/routes/api/admin/plugins/index.ts +32 -0
- package/src/astro/routes/api/admin/plugins/marketplace/[id]/icon.ts +62 -0
- package/src/astro/routes/api/admin/plugins/marketplace/[id]/index.ts +33 -0
- package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +64 -0
- package/src/astro/routes/api/admin/plugins/marketplace/index.ts +38 -0
- package/src/astro/routes/api/admin/plugins/updates.ts +28 -0
- package/src/astro/routes/api/admin/themes/marketplace/[id]/index.ts +33 -0
- package/src/astro/routes/api/admin/themes/marketplace/[id]/thumbnail.ts +62 -0
- package/src/astro/routes/api/admin/themes/marketplace/index.ts +45 -0
- package/src/astro/routes/api/admin/users/[id]/disable.ts +69 -0
- package/src/astro/routes/api/admin/users/[id]/enable.ts +48 -0
- package/src/astro/routes/api/admin/users/[id]/index.ts +146 -0
- package/src/astro/routes/api/admin/users/[id]/send-recovery.ts +72 -0
- package/src/astro/routes/api/admin/users/index.ts +66 -0
- package/src/astro/routes/api/auth/dev-bypass.ts +139 -0
- package/src/astro/routes/api/auth/invite/accept.ts +52 -0
- package/src/astro/routes/api/auth/invite/complete.ts +86 -0
- package/src/astro/routes/api/auth/invite/index.ts +99 -0
- package/src/astro/routes/api/auth/logout.ts +40 -0
- package/src/astro/routes/api/auth/magic-link/send.ts +89 -0
- package/src/astro/routes/api/auth/magic-link/verify.ts +71 -0
- package/src/astro/routes/api/auth/me.ts +60 -0
- package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +221 -0
- package/src/astro/routes/api/auth/oauth/[provider].ts +120 -0
- package/src/astro/routes/api/auth/passkey/[id].ts +124 -0
- package/src/astro/routes/api/auth/passkey/index.ts +54 -0
- package/src/astro/routes/api/auth/passkey/options.ts +84 -0
- package/src/astro/routes/api/auth/passkey/register/options.ts +88 -0
- package/src/astro/routes/api/auth/passkey/register/verify.ts +119 -0
- package/src/astro/routes/api/auth/passkey/verify.ts +68 -0
- package/src/astro/routes/api/auth/signup/complete.ts +87 -0
- package/src/astro/routes/api/auth/signup/request.ts +77 -0
- package/src/astro/routes/api/auth/signup/verify.ts +53 -0
- package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +311 -0
- package/src/astro/routes/api/content/[collection]/[id]/compare.ts +28 -0
- package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +54 -0
- package/src/astro/routes/api/content/[collection]/[id]/duplicate.ts +61 -0
- package/src/astro/routes/api/content/[collection]/[id]/permanent.ts +33 -0
- package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +107 -0
- package/src/astro/routes/api/content/[collection]/[id]/publish.ts +56 -0
- package/src/astro/routes/api/content/[collection]/[id]/restore.ts +54 -0
- package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +31 -0
- package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +105 -0
- package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +140 -0
- package/src/astro/routes/api/content/[collection]/[id]/translations.ts +30 -0
- package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +56 -0
- package/src/astro/routes/api/content/[collection]/[id].ts +137 -0
- package/src/astro/routes/api/content/[collection]/index.ts +59 -0
- package/src/astro/routes/api/content/[collection]/trash.ts +33 -0
- package/src/astro/routes/api/dashboard.ts +32 -0
- package/src/astro/routes/api/dev/emails.ts +36 -0
- package/src/astro/routes/api/import/probe.ts +47 -0
- package/src/astro/routes/api/import/wordpress/analyze.ts +531 -0
- package/src/astro/routes/api/import/wordpress/execute.ts +296 -0
- package/src/astro/routes/api/import/wordpress/media.ts +338 -0
- package/src/astro/routes/api/import/wordpress/prepare.ts +181 -0
- package/src/astro/routes/api/import/wordpress/rewrite-urls.ts +393 -0
- package/src/astro/routes/api/import/wordpress-plugin/analyze.ts +111 -0
- package/src/astro/routes/api/import/wordpress-plugin/callback.ts +58 -0
- package/src/astro/routes/api/import/wordpress-plugin/execute.ts +357 -0
- package/src/astro/routes/api/manifest.ts +63 -0
- package/src/astro/routes/api/mcp.ts +124 -0
- package/src/astro/routes/api/media/[id]/confirm.ts +93 -0
- package/src/astro/routes/api/media/[id].ts +145 -0
- package/src/astro/routes/api/media/file/[...key].ts +79 -0
- package/src/astro/routes/api/media/providers/[providerId]/[itemId].ts +86 -0
- package/src/astro/routes/api/media/providers/[providerId]/index.ts +111 -0
- package/src/astro/routes/api/media/providers/index.ts +30 -0
- package/src/astro/routes/api/media/upload-url.ts +137 -0
- package/src/astro/routes/api/media.ts +202 -0
- package/src/astro/routes/api/menus/[name]/items.ts +87 -0
- package/src/astro/routes/api/menus/[name]/reorder.ts +33 -0
- package/src/astro/routes/api/menus/[name].ts +65 -0
- package/src/astro/routes/api/menus/index.ts +47 -0
- package/src/astro/routes/api/oauth/authorize.ts +417 -0
- package/src/astro/routes/api/oauth/device/authorize.ts +45 -0
- package/src/astro/routes/api/oauth/device/code.ts +55 -0
- package/src/astro/routes/api/oauth/device/token.ts +69 -0
- package/src/astro/routes/api/oauth/token/refresh.ts +38 -0
- package/src/astro/routes/api/oauth/token/revoke.ts +38 -0
- package/src/astro/routes/api/oauth/token.ts +184 -0
- package/src/astro/routes/api/openapi.json.ts +32 -0
- package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +92 -0
- package/src/astro/routes/api/redirects/404s/index.ts +72 -0
- package/src/astro/routes/api/redirects/404s/summary.ts +33 -0
- package/src/astro/routes/api/redirects/[id].ts +84 -0
- package/src/astro/routes/api/redirects/index.ts +52 -0
- package/src/astro/routes/api/revisions/[revisionId]/index.ts +29 -0
- package/src/astro/routes/api/revisions/[revisionId]/restore.ts +62 -0
- package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +76 -0
- package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +52 -0
- package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +32 -0
- package/src/astro/routes/api/schema/collections/[slug]/index.ts +80 -0
- package/src/astro/routes/api/schema/collections/index.ts +47 -0
- package/src/astro/routes/api/schema/index.ts +109 -0
- package/src/astro/routes/api/schema/orphans/[slug].ts +36 -0
- package/src/astro/routes/api/schema/orphans/index.ts +26 -0
- package/src/astro/routes/api/search/enable.ts +64 -0
- package/src/astro/routes/api/search/index.ts +51 -0
- package/src/astro/routes/api/search/rebuild.ts +72 -0
- package/src/astro/routes/api/search/stats.ts +35 -0
- package/src/astro/routes/api/search/suggest.ts +49 -0
- package/src/astro/routes/api/sections/[slug].ts +84 -0
- package/src/astro/routes/api/sections/index.ts +52 -0
- package/src/astro/routes/api/settings/email.ts +150 -0
- package/src/astro/routes/api/settings.ts +67 -0
- package/src/astro/routes/api/setup/admin-verify.ts +102 -0
- package/src/astro/routes/api/setup/admin.ts +96 -0
- package/src/astro/routes/api/setup/dev-bypass.ts +200 -0
- package/src/astro/routes/api/setup/dev-reset.ts +40 -0
- package/src/astro/routes/api/setup/index.ts +127 -0
- package/src/astro/routes/api/setup/status.ts +122 -0
- package/src/astro/routes/api/snapshot.ts +76 -0
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug].ts +95 -0
- package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +69 -0
- package/src/astro/routes/api/taxonomies/index.ts +59 -0
- package/src/astro/routes/api/themes/preview.ts +78 -0
- package/src/astro/routes/api/typegen.ts +114 -0
- package/src/astro/routes/api/well-known/auth.ts +69 -0
- package/src/astro/routes/api/well-known/oauth-authorization-server.ts +45 -0
- package/src/astro/routes/api/well-known/oauth-protected-resource.ts +38 -0
- package/src/astro/routes/api/widget-areas/[name]/reorder.ts +72 -0
- package/src/astro/routes/api/widget-areas/[name]/widgets/[id].ts +127 -0
- package/src/astro/routes/api/widget-areas/[name]/widgets.ts +80 -0
- package/src/astro/routes/api/widget-areas/[name].ts +87 -0
- package/src/astro/routes/api/widget-areas/index.ts +99 -0
- package/src/astro/routes/api/widget-components.ts +22 -0
- package/src/astro/routes/robots.txt.ts +81 -0
- package/src/astro/routes/sitemap-[collection].xml.ts +104 -0
- package/src/astro/routes/sitemap.xml.ts +92 -0
- package/src/components/Break.astro +45 -0
- package/src/components/Button.astro +71 -0
- package/src/components/Buttons.astro +49 -0
- package/src/components/Code.astro +59 -0
- package/src/components/Columns.astro +59 -0
- package/src/components/CommentForm.astro +315 -0
- package/src/components/Comments.astro +232 -0
- package/src/components/Cover.astro +128 -0
- package/src/components/DinewayBodyEnd.astro +32 -0
- package/src/components/DinewayBodyStart.astro +32 -0
- package/src/components/DinewayHead.astro +53 -0
- package/src/components/DinewayImage.astro +178 -0
- package/src/components/DinewayMedia.astro +167 -0
- package/src/components/Embed.astro +128 -0
- package/src/components/File.astro +122 -0
- package/src/components/Gallery.astro +93 -0
- package/src/components/HtmlBlock.astro +33 -0
- package/src/components/Image.astro +178 -0
- package/src/components/InlineEditor.astro +27 -0
- package/src/components/InlinePortableTextEditor.tsx +1937 -0
- package/src/components/LiveSearch.astro +614 -0
- package/src/components/PortableText.astro +51 -0
- package/src/components/Pullquote.astro +51 -0
- package/src/components/Table.astro +108 -0
- package/src/components/WidgetArea.astro +22 -0
- package/src/components/WidgetRenderer.astro +72 -0
- package/src/components/index.ts +116 -0
- package/src/components/marks/Link.astro +31 -0
- package/src/components/marks/StrikeThrough.astro +7 -0
- package/src/components/marks/Subscript.astro +7 -0
- package/src/components/marks/Superscript.astro +7 -0
- package/src/components/marks/Underline.astro +7 -0
- package/src/components/widgets/Archives.astro +65 -0
- package/src/components/widgets/Categories.astro +35 -0
- package/src/components/widgets/RecentPosts.astro +51 -0
- package/src/components/widgets/Search.astro +18 -0
- package/src/components/widgets/Tags.astro +38 -0
- package/src/ui.ts +75 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widgets CRUD endpoints
|
|
3
|
+
*
|
|
4
|
+
* POST /_dineway/api/widget-areas/:name/widgets - Add widget
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { APIRoute } from "astro";
|
|
8
|
+
import { ulid } from "ulidx";
|
|
9
|
+
|
|
10
|
+
import { requirePerm } from "#api/authorize.js";
|
|
11
|
+
import { apiError, apiSuccess, handleError } from "#api/error.js";
|
|
12
|
+
import { isParseError, parseBody } from "#api/parse.js";
|
|
13
|
+
import { createWidgetBody } from "#api/schemas.js";
|
|
14
|
+
|
|
15
|
+
export const prerender = false;
|
|
16
|
+
|
|
17
|
+
export const POST: APIRoute = async ({ params, request, locals }) => {
|
|
18
|
+
const { dineway, user } = locals;
|
|
19
|
+
const db = dineway.db;
|
|
20
|
+
const { name } = params;
|
|
21
|
+
|
|
22
|
+
const denied = requirePerm(user, "widgets:manage");
|
|
23
|
+
if (denied) return denied;
|
|
24
|
+
|
|
25
|
+
if (!name) {
|
|
26
|
+
return apiError("VALIDATION_ERROR", "name is required", 400);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Get the area
|
|
31
|
+
const area = await db
|
|
32
|
+
.selectFrom("_dineway_widget_areas")
|
|
33
|
+
.select("id")
|
|
34
|
+
.where("name", "=", name)
|
|
35
|
+
.executeTakeFirst();
|
|
36
|
+
|
|
37
|
+
if (!area) {
|
|
38
|
+
return apiError("NOT_FOUND", `Widget area "${name}" not found`, 404);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const body = await parseBody(request, createWidgetBody);
|
|
42
|
+
if (isParseError(body)) return body;
|
|
43
|
+
|
|
44
|
+
// Get max sort_order
|
|
45
|
+
const maxOrder = await db
|
|
46
|
+
.selectFrom("_dineway_widgets")
|
|
47
|
+
.select(({ fn }) => fn.max("sort_order").as("maxOrder"))
|
|
48
|
+
.where("area_id", "=", area.id)
|
|
49
|
+
.executeTakeFirst();
|
|
50
|
+
|
|
51
|
+
const sortOrder = (maxOrder?.maxOrder ?? -1) + 1;
|
|
52
|
+
|
|
53
|
+
// Prepare values
|
|
54
|
+
const id = ulid();
|
|
55
|
+
await db
|
|
56
|
+
.insertInto("_dineway_widgets")
|
|
57
|
+
.values({
|
|
58
|
+
id,
|
|
59
|
+
area_id: area.id,
|
|
60
|
+
sort_order: sortOrder,
|
|
61
|
+
type: body.type,
|
|
62
|
+
title: body.title ?? null,
|
|
63
|
+
content: body.content ? JSON.stringify(body.content) : null,
|
|
64
|
+
menu_name: body.menuName ?? null,
|
|
65
|
+
component_id: body.componentId ?? null,
|
|
66
|
+
component_props: body.componentProps ? JSON.stringify(body.componentProps) : null,
|
|
67
|
+
})
|
|
68
|
+
.execute();
|
|
69
|
+
|
|
70
|
+
const widget = await db
|
|
71
|
+
.selectFrom("_dineway_widgets")
|
|
72
|
+
.selectAll()
|
|
73
|
+
.where("id", "=", id)
|
|
74
|
+
.executeTakeFirstOrThrow();
|
|
75
|
+
|
|
76
|
+
return apiSuccess(widget, 201);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return handleError(error, "Failed to create widget", "WIDGET_CREATE_ERROR");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget area by name endpoints
|
|
3
|
+
*
|
|
4
|
+
* GET /_dineway/api/widget-areas/:name - Get area with widgets
|
|
5
|
+
* DELETE /_dineway/api/widget-areas/:name - Delete area
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { APIRoute } from "astro";
|
|
9
|
+
|
|
10
|
+
import { requirePerm } from "#api/authorize.js";
|
|
11
|
+
import { apiError, apiSuccess, handleError } from "#api/error.js";
|
|
12
|
+
|
|
13
|
+
export const prerender = false;
|
|
14
|
+
|
|
15
|
+
export const GET: APIRoute = async ({ params, locals }) => {
|
|
16
|
+
const { dineway, user } = locals;
|
|
17
|
+
const db = dineway.db;
|
|
18
|
+
const { name } = params;
|
|
19
|
+
|
|
20
|
+
const denied = requirePerm(user, "widgets:read");
|
|
21
|
+
if (denied) return denied;
|
|
22
|
+
|
|
23
|
+
if (!name) {
|
|
24
|
+
return apiError("VALIDATION_ERROR", "name is required", 400);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
// Get the area
|
|
29
|
+
const area = await db
|
|
30
|
+
.selectFrom("_dineway_widget_areas")
|
|
31
|
+
.selectAll()
|
|
32
|
+
.where("name", "=", name)
|
|
33
|
+
.executeTakeFirst();
|
|
34
|
+
|
|
35
|
+
if (!area) {
|
|
36
|
+
return apiError("NOT_FOUND", `Widget area "${name}" not found`, 404);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Get widgets for this area
|
|
40
|
+
const widgets = await db
|
|
41
|
+
.selectFrom("_dineway_widgets")
|
|
42
|
+
.selectAll()
|
|
43
|
+
.where("area_id", "=", area.id)
|
|
44
|
+
.orderBy("sort_order", "asc")
|
|
45
|
+
.execute();
|
|
46
|
+
|
|
47
|
+
return apiSuccess({
|
|
48
|
+
...area,
|
|
49
|
+
widgets,
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return handleError(error, "Failed to fetch widget area", "WIDGET_AREA_GET_ERROR");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const DELETE: APIRoute = async ({ params, locals }) => {
|
|
57
|
+
const { dineway, user } = locals;
|
|
58
|
+
const db = dineway.db;
|
|
59
|
+
const { name } = params;
|
|
60
|
+
|
|
61
|
+
const denied = requirePerm(user, "widgets:manage");
|
|
62
|
+
if (denied) return denied;
|
|
63
|
+
|
|
64
|
+
if (!name) {
|
|
65
|
+
return apiError("VALIDATION_ERROR", "name is required", 400);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
// Check if area exists
|
|
70
|
+
const area = await db
|
|
71
|
+
.selectFrom("_dineway_widget_areas")
|
|
72
|
+
.select("id")
|
|
73
|
+
.where("name", "=", name)
|
|
74
|
+
.executeTakeFirst();
|
|
75
|
+
|
|
76
|
+
if (!area) {
|
|
77
|
+
return apiError("NOT_FOUND", `Widget area "${name}" not found`, 404);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Delete area (widgets cascade)
|
|
81
|
+
await db.deleteFrom("_dineway_widget_areas").where("id", "=", area.id).execute();
|
|
82
|
+
|
|
83
|
+
return apiSuccess({ deleted: true });
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return handleError(error, "Failed to delete widget area", "WIDGET_AREA_DELETE_ERROR");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget areas list and create endpoints
|
|
3
|
+
*
|
|
4
|
+
* GET /_dineway/api/widget-areas - List all widget areas
|
|
5
|
+
* POST /_dineway/api/widget-areas - Create widget area
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { APIRoute } from "astro";
|
|
9
|
+
import { ulid } from "ulidx";
|
|
10
|
+
|
|
11
|
+
import { requirePerm } from "#api/authorize.js";
|
|
12
|
+
import { apiError, apiSuccess, handleError } from "#api/error.js";
|
|
13
|
+
import { isParseError, parseBody } from "#api/parse.js";
|
|
14
|
+
import { createWidgetAreaBody } from "#api/schemas.js";
|
|
15
|
+
|
|
16
|
+
export const prerender = false;
|
|
17
|
+
|
|
18
|
+
export const GET: APIRoute = async ({ locals }) => {
|
|
19
|
+
const { dineway, user } = locals;
|
|
20
|
+
const db = dineway.db;
|
|
21
|
+
|
|
22
|
+
const denied = requirePerm(user, "widgets:read");
|
|
23
|
+
if (denied) return denied;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const areas = await db
|
|
27
|
+
.selectFrom("_dineway_widget_areas")
|
|
28
|
+
.selectAll()
|
|
29
|
+
.orderBy("name", "asc")
|
|
30
|
+
.execute();
|
|
31
|
+
|
|
32
|
+
// Get widgets for each area (needed for drag-and-drop reordering in admin UI)
|
|
33
|
+
const areasWithWidgets = await Promise.all(
|
|
34
|
+
areas.map(async (area) => {
|
|
35
|
+
const widgets = await db
|
|
36
|
+
.selectFrom("_dineway_widgets")
|
|
37
|
+
.selectAll()
|
|
38
|
+
.where("area_id", "=", area.id)
|
|
39
|
+
.orderBy("sort_order", "asc")
|
|
40
|
+
.execute();
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
...area,
|
|
44
|
+
widgets,
|
|
45
|
+
widgetCount: widgets.length,
|
|
46
|
+
};
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return apiSuccess({ items: areasWithWidgets });
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return handleError(error, "Failed to fetch widget areas", "WIDGET_AREA_LIST_ERROR");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const POST: APIRoute = async ({ request, locals }) => {
|
|
57
|
+
const { dineway, user } = locals;
|
|
58
|
+
const db = dineway.db;
|
|
59
|
+
|
|
60
|
+
const denied = requirePerm(user, "widgets:manage");
|
|
61
|
+
if (denied) return denied;
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const body = await parseBody(request, createWidgetAreaBody);
|
|
65
|
+
if (isParseError(body)) return body;
|
|
66
|
+
|
|
67
|
+
// Check if area name already exists
|
|
68
|
+
const existing = await db
|
|
69
|
+
.selectFrom("_dineway_widget_areas")
|
|
70
|
+
.select("id")
|
|
71
|
+
.where("name", "=", body.name)
|
|
72
|
+
.executeTakeFirst();
|
|
73
|
+
|
|
74
|
+
if (existing) {
|
|
75
|
+
return apiError("CONFLICT", `Widget area with name "${body.name}" already exists`, 409);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const id = ulid();
|
|
79
|
+
await db
|
|
80
|
+
.insertInto("_dineway_widget_areas")
|
|
81
|
+
.values({
|
|
82
|
+
id,
|
|
83
|
+
name: body.name,
|
|
84
|
+
label: body.label,
|
|
85
|
+
description: body.description ?? null,
|
|
86
|
+
})
|
|
87
|
+
.execute();
|
|
88
|
+
|
|
89
|
+
const area = await db
|
|
90
|
+
.selectFrom("_dineway_widget_areas")
|
|
91
|
+
.selectAll()
|
|
92
|
+
.where("id", "=", id)
|
|
93
|
+
.executeTakeFirstOrThrow();
|
|
94
|
+
|
|
95
|
+
return apiSuccess(area, 201);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return handleError(error, "Failed to create widget area", "WIDGET_AREA_CREATE_ERROR");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget components registry endpoint
|
|
3
|
+
*
|
|
4
|
+
* GET /_dineway/api/widget-components - List available widget components
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { APIRoute } from "astro";
|
|
8
|
+
|
|
9
|
+
import { apiSuccess, handleError } from "#api/error.js";
|
|
10
|
+
import { getWidgetComponents } from "#widgets/components.js";
|
|
11
|
+
|
|
12
|
+
export const prerender = false;
|
|
13
|
+
|
|
14
|
+
export const GET: APIRoute = async () => {
|
|
15
|
+
try {
|
|
16
|
+
const components = getWidgetComponents();
|
|
17
|
+
|
|
18
|
+
return apiSuccess({ items: components });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return handleError(error, "Failed to fetch widget components", "WIDGET_COMPONENTS_ERROR");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Robots.txt endpoint
|
|
3
|
+
*
|
|
4
|
+
* GET /robots.txt - Serves robots.txt with sitemap reference
|
|
5
|
+
*
|
|
6
|
+
* If a custom robots.txt is configured in SEO settings, that is returned.
|
|
7
|
+
* Otherwise generates a default that allows all crawlers and references
|
|
8
|
+
* the sitemap.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { APIRoute } from "astro";
|
|
12
|
+
|
|
13
|
+
import { getPublicOrigin } from "#api/public-url.js";
|
|
14
|
+
import { getSiteSettingsWithDb } from "#settings/index.js";
|
|
15
|
+
|
|
16
|
+
export const prerender = false;
|
|
17
|
+
|
|
18
|
+
const TRAILING_SLASH_RE = /\/$/;
|
|
19
|
+
|
|
20
|
+
export const GET: APIRoute = async ({ locals, url }) => {
|
|
21
|
+
const { dineway } = locals;
|
|
22
|
+
|
|
23
|
+
if (!dineway?.db) {
|
|
24
|
+
// Return a permissive default if CMS isn't initialized
|
|
25
|
+
return new Response("User-agent: *\nAllow: /\n", {
|
|
26
|
+
status: 200,
|
|
27
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const settings = await getSiteSettingsWithDb(dineway.db);
|
|
33
|
+
const siteUrl = (settings.url || getPublicOrigin(url, dineway?.config)).replace(
|
|
34
|
+
TRAILING_SLASH_RE,
|
|
35
|
+
"",
|
|
36
|
+
);
|
|
37
|
+
const sitemapUrl = `${siteUrl}/sitemap.xml`;
|
|
38
|
+
|
|
39
|
+
// Use custom robots.txt if configured
|
|
40
|
+
if (settings.seo?.robotsTxt) {
|
|
41
|
+
// Append sitemap directive if not already present
|
|
42
|
+
let content = settings.seo.robotsTxt;
|
|
43
|
+
if (!content.toLowerCase().includes("sitemap:")) {
|
|
44
|
+
content = `${content.trimEnd()}\n\nSitemap: ${sitemapUrl}\n`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new Response(content, {
|
|
48
|
+
status: 200,
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
51
|
+
"Cache-Control": "public, max-age=86400",
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Generate default robots.txt
|
|
57
|
+
const defaultRobots = [
|
|
58
|
+
"User-agent: *",
|
|
59
|
+
"Allow: /",
|
|
60
|
+
"",
|
|
61
|
+
"# Disallow admin and API routes",
|
|
62
|
+
"Disallow: /_dineway/",
|
|
63
|
+
"",
|
|
64
|
+
`Sitemap: ${sitemapUrl}`,
|
|
65
|
+
"",
|
|
66
|
+
].join("\n");
|
|
67
|
+
|
|
68
|
+
return new Response(defaultRobots, {
|
|
69
|
+
status: 200,
|
|
70
|
+
headers: {
|
|
71
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
72
|
+
"Cache-Control": "public, max-age=86400",
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
} catch {
|
|
76
|
+
return new Response("User-agent: *\nAllow: /\n", {
|
|
77
|
+
status: 200,
|
|
78
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-collection sitemap endpoint
|
|
3
|
+
*
|
|
4
|
+
* GET /sitemap-{collection}.xml - Sitemap for a single content collection.
|
|
5
|
+
*
|
|
6
|
+
* Uses the collection's url_pattern to build URLs. Falls back to
|
|
7
|
+
* /{collection}/{slug} when no pattern is configured.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { APIRoute } from "astro";
|
|
11
|
+
|
|
12
|
+
import { handleSitemapData } from "#api/handlers/seo.js";
|
|
13
|
+
import { getSiteSettingsWithDb } from "#settings/index.js";
|
|
14
|
+
|
|
15
|
+
export const prerender = false;
|
|
16
|
+
|
|
17
|
+
const TRAILING_SLASH_RE = /\/$/;
|
|
18
|
+
const AMP_RE = /&/g;
|
|
19
|
+
const LT_RE = /</g;
|
|
20
|
+
const GT_RE = />/g;
|
|
21
|
+
const QUOT_RE = /"/g;
|
|
22
|
+
const APOS_RE = /'/g;
|
|
23
|
+
const SLUG_PLACEHOLDER = "{slug}";
|
|
24
|
+
const ID_PLACEHOLDER = "{id}";
|
|
25
|
+
|
|
26
|
+
export const GET: APIRoute = async ({ params, locals, url }) => {
|
|
27
|
+
const { dineway } = locals;
|
|
28
|
+
const collectionSlug = params.collection;
|
|
29
|
+
|
|
30
|
+
if (!dineway?.db || !collectionSlug) {
|
|
31
|
+
return new Response("<!-- Dineway is not configured -->", {
|
|
32
|
+
status: 500,
|
|
33
|
+
headers: { "Content-Type": "application/xml" },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const settings = await getSiteSettingsWithDb(dineway.db);
|
|
39
|
+
const siteUrl = (settings.url || url.origin).replace(TRAILING_SLASH_RE, "");
|
|
40
|
+
|
|
41
|
+
const result = await handleSitemapData(dineway.db, collectionSlug);
|
|
42
|
+
|
|
43
|
+
if (!result.success || !result.data) {
|
|
44
|
+
return new Response("<!-- Failed to generate sitemap -->", {
|
|
45
|
+
status: 500,
|
|
46
|
+
headers: { "Content-Type": "application/xml" },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const col = result.data.collections[0];
|
|
51
|
+
if (!col) {
|
|
52
|
+
return new Response("<!-- Collection not found or empty -->", {
|
|
53
|
+
status: 404,
|
|
54
|
+
headers: { "Content-Type": "application/xml" },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const lines: string[] = [
|
|
59
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
60
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
for (const entry of col.entries) {
|
|
64
|
+
const slug = entry.slug || entry.id;
|
|
65
|
+
const path = col.urlPattern
|
|
66
|
+
? col.urlPattern
|
|
67
|
+
.replace(SLUG_PLACEHOLDER, encodeURIComponent(slug))
|
|
68
|
+
.replace(ID_PLACEHOLDER, encodeURIComponent(entry.id))
|
|
69
|
+
: `/${encodeURIComponent(col.collection)}/${encodeURIComponent(slug)}`;
|
|
70
|
+
|
|
71
|
+
const loc = `${siteUrl}${path}`;
|
|
72
|
+
|
|
73
|
+
lines.push(" <url>");
|
|
74
|
+
lines.push(` <loc>${escapeXml(loc)}</loc>`);
|
|
75
|
+
lines.push(` <lastmod>${escapeXml(entry.updatedAt)}</lastmod>`);
|
|
76
|
+
lines.push(" </url>");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
lines.push("</urlset>");
|
|
80
|
+
|
|
81
|
+
return new Response(lines.join("\n"), {
|
|
82
|
+
status: 200,
|
|
83
|
+
headers: {
|
|
84
|
+
"Content-Type": "application/xml; charset=utf-8",
|
|
85
|
+
"Cache-Control": "public, max-age=3600",
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
} catch {
|
|
89
|
+
return new Response("<!-- Internal error generating sitemap -->", {
|
|
90
|
+
status: 500,
|
|
91
|
+
headers: { "Content-Type": "application/xml" },
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Escape special XML characters in a string */
|
|
97
|
+
function escapeXml(str: string): string {
|
|
98
|
+
return str
|
|
99
|
+
.replace(AMP_RE, "&")
|
|
100
|
+
.replace(LT_RE, "<")
|
|
101
|
+
.replace(GT_RE, ">")
|
|
102
|
+
.replace(QUOT_RE, """)
|
|
103
|
+
.replace(APOS_RE, "'");
|
|
104
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sitemap index endpoint
|
|
3
|
+
*
|
|
4
|
+
* GET /sitemap.xml - Sitemap index listing one sitemap per collection.
|
|
5
|
+
*
|
|
6
|
+
* Each collection with published, indexable content gets its own
|
|
7
|
+
* child sitemap at /sitemap-{collection}.xml. The index includes
|
|
8
|
+
* a <lastmod> per child derived from the most recently updated entry.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { APIRoute } from "astro";
|
|
12
|
+
|
|
13
|
+
import { handleSitemapData } from "#api/handlers/seo.js";
|
|
14
|
+
import { getPublicOrigin } from "#api/public-url.js";
|
|
15
|
+
import { getSiteSettingsWithDb } from "#settings/index.js";
|
|
16
|
+
|
|
17
|
+
export const prerender = false;
|
|
18
|
+
|
|
19
|
+
const TRAILING_SLASH_RE = /\/$/;
|
|
20
|
+
const AMP_RE = /&/g;
|
|
21
|
+
const LT_RE = /</g;
|
|
22
|
+
const GT_RE = />/g;
|
|
23
|
+
const QUOT_RE = /"/g;
|
|
24
|
+
const APOS_RE = /'/g;
|
|
25
|
+
|
|
26
|
+
export const GET: APIRoute = async ({ locals, url }) => {
|
|
27
|
+
const { dineway } = locals;
|
|
28
|
+
|
|
29
|
+
if (!dineway?.db) {
|
|
30
|
+
return new Response("<!-- Dineway is not configured -->", {
|
|
31
|
+
status: 500,
|
|
32
|
+
headers: { "Content-Type": "application/xml" },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const settings = await getSiteSettingsWithDb(dineway.db);
|
|
38
|
+
const siteUrl = (settings.url || getPublicOrigin(url, dineway?.config)).replace(
|
|
39
|
+
TRAILING_SLASH_RE,
|
|
40
|
+
"",
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const result = await handleSitemapData(dineway.db);
|
|
44
|
+
|
|
45
|
+
if (!result.success || !result.data) {
|
|
46
|
+
return new Response("<!-- Failed to generate sitemap -->", {
|
|
47
|
+
status: 500,
|
|
48
|
+
headers: { "Content-Type": "application/xml" },
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { collections } = result.data;
|
|
53
|
+
|
|
54
|
+
const lines: string[] = [
|
|
55
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
56
|
+
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
for (const col of collections) {
|
|
60
|
+
const loc = `${siteUrl}/sitemap-${encodeURIComponent(col.collection)}.xml`;
|
|
61
|
+
lines.push(" <sitemap>");
|
|
62
|
+
lines.push(` <loc>${escapeXml(loc)}</loc>`);
|
|
63
|
+
lines.push(` <lastmod>${escapeXml(col.lastmod)}</lastmod>`);
|
|
64
|
+
lines.push(" </sitemap>");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
lines.push("</sitemapindex>");
|
|
68
|
+
|
|
69
|
+
return new Response(lines.join("\n"), {
|
|
70
|
+
status: 200,
|
|
71
|
+
headers: {
|
|
72
|
+
"Content-Type": "application/xml; charset=utf-8",
|
|
73
|
+
"Cache-Control": "public, max-age=3600",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
} catch {
|
|
77
|
+
return new Response("<!-- Internal error generating sitemap -->", {
|
|
78
|
+
status: 500,
|
|
79
|
+
headers: { "Content-Type": "application/xml" },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** Escape special XML characters in a string */
|
|
85
|
+
function escapeXml(str: string): string {
|
|
86
|
+
return str
|
|
87
|
+
.replace(AMP_RE, "&")
|
|
88
|
+
.replace(LT_RE, "<")
|
|
89
|
+
.replace(GT_RE, ">")
|
|
90
|
+
.replace(QUOT_RE, """)
|
|
91
|
+
.replace(APOS_RE, "'");
|
|
92
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Portable Text Break/Separator block component
|
|
4
|
+
*
|
|
5
|
+
* Renders horizontal rules and page breaks.
|
|
6
|
+
*/
|
|
7
|
+
export interface Props {
|
|
8
|
+
node: {
|
|
9
|
+
_type: "break";
|
|
10
|
+
_key: string;
|
|
11
|
+
style?: "line" | "dots" | "space";
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { node } = Astro.props;
|
|
16
|
+
const style = node?.style || "line";
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
{
|
|
20
|
+
style === "dots" ? (
|
|
21
|
+
<div class="dineway-break dineway-break-dots">• • •</div>
|
|
22
|
+
) : style === "space" ? (
|
|
23
|
+
<div class="dineway-break dineway-break-space" />
|
|
24
|
+
) : (
|
|
25
|
+
<hr class="dineway-break dineway-break-line" />
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
<style>
|
|
30
|
+
.dineway-break {
|
|
31
|
+
margin: 2rem 0;
|
|
32
|
+
}
|
|
33
|
+
.dineway-break-line {
|
|
34
|
+
border: none;
|
|
35
|
+
border-top: 1px solid #e0e0e0;
|
|
36
|
+
}
|
|
37
|
+
.dineway-break-dots {
|
|
38
|
+
text-align: center;
|
|
39
|
+
color: #999;
|
|
40
|
+
letter-spacing: 0.5em;
|
|
41
|
+
}
|
|
42
|
+
.dineway-break-space {
|
|
43
|
+
height: 2rem;
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { sanitizeHref } from "../utils/url.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Portable Text Button block component
|
|
6
|
+
*
|
|
7
|
+
* Renders a single button from WordPress imports.
|
|
8
|
+
*/
|
|
9
|
+
export interface Props {
|
|
10
|
+
node: {
|
|
11
|
+
_type: "button";
|
|
12
|
+
_key: string;
|
|
13
|
+
text: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
style?: "default" | "outline" | "fill";
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { node } = Astro.props;
|
|
20
|
+
const { text, url: rawUrl, style = "default" } = node ?? {};
|
|
21
|
+
const url = rawUrl ? sanitizeHref(rawUrl) : undefined;
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
{
|
|
25
|
+
url ? (
|
|
26
|
+
<a href={url} class:list={["dineway-button", `dineway-button--${style}`]}>
|
|
27
|
+
{text}
|
|
28
|
+
</a>
|
|
29
|
+
) : (
|
|
30
|
+
<span class:list={["dineway-button", `dineway-button--${style}`]}>{text}</span>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
<style>
|
|
35
|
+
.dineway-button {
|
|
36
|
+
display: inline-block;
|
|
37
|
+
padding: 0.75em 1.5em;
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
text-decoration: none;
|
|
40
|
+
font-weight: 500;
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
transition:
|
|
43
|
+
background-color 0.2s,
|
|
44
|
+
border-color 0.2s,
|
|
45
|
+
color 0.2s;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.dineway-button--default,
|
|
49
|
+
.dineway-button--fill {
|
|
50
|
+
background-color: var(--dineway-button-bg, #0073aa);
|
|
51
|
+
color: var(--dineway-button-color, #fff);
|
|
52
|
+
border: 2px solid var(--dineway-button-bg, #0073aa);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.dineway-button--default:hover,
|
|
56
|
+
.dineway-button--fill:hover {
|
|
57
|
+
background-color: var(--dineway-button-bg-hover, #005177);
|
|
58
|
+
border-color: var(--dineway-button-bg-hover, #005177);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.dineway-button--outline {
|
|
62
|
+
background-color: transparent;
|
|
63
|
+
color: var(--dineway-button-bg, #0073aa);
|
|
64
|
+
border: 2px solid var(--dineway-button-bg, #0073aa);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.dineway-button--outline:hover {
|
|
68
|
+
background-color: var(--dineway-button-bg, #0073aa);
|
|
69
|
+
color: var(--dineway-button-color, #fff);
|
|
70
|
+
}
|
|
71
|
+
</style>
|