@kidecms/core 0.14.1 → 0.14.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.
@@ -436,7 +436,7 @@ export async function loadParentFormTitle(
436
436
  runtimeContext: RuntimeContext,
437
437
  ): Promise<string | null> {
438
438
  try {
439
- const parentForm = (await cmsRuntime.forms.findOne({ where: { _id: formId } }, runtimeContext)) as Record<
439
+ const parentForm = (await cmsRuntime.forms.findOne({ _id: formId }, runtimeContext)) as Record<
440
440
  string,
441
441
  unknown
442
442
  > | null;
@@ -33,7 +33,13 @@ export const onRequest = defineMiddleware(async (context, next) => {
33
33
  const scope: RequestScope = cfContext?.waitUntil
34
34
  ? { defer: (task) => cfContext.waitUntil!(task) }
35
35
  : { defer: () => {} };
36
- return runWithRequestScope(scope, () => handle(context, next));
36
+ return runWithRequestScope(scope, async () => {
37
+ const response = await handle(context, next);
38
+ // Draft responses must never enter the shared cache. Runs after the page
39
+ // rendered because a page-level cache.set() would re-enable caching.
40
+ if (context.url.searchParams.has("preview")) context.cache?.set(false);
41
+ return response;
42
+ });
37
43
  });
38
44
 
39
45
  const handle = async (context: APIContext, next: MiddlewareNext) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,7 +18,11 @@ const errorMessage =
18
18
  ? "Email and password are required."
19
19
  : error === "disabled"
20
20
  ? "Password login is disabled."
21
- : null;
21
+ : error === "rate-limited"
22
+ ? "Too many attempts. Try again in a few minutes."
23
+ : error
24
+ ? "Sign-in failed. Try again."
25
+ : null;
22
26
  const auth = resolveAdminAuth(config);
23
27
  ---
24
28
 
@@ -1,7 +1,7 @@
1
1
  import type { APIRoute } from "astro";
2
2
  import { cms } from "virtual:kide/api";
3
3
  import { sendFormSubmissionEmail, isEmailConfigured } from "virtual:kide/email";
4
- import { hitRateLimit, PayloadTooLargeError, readLimitedFormData } from "../../../../core";
4
+ import { hitRateLimit, PayloadTooLargeError, readLimitedFormData, safeUrl } from "../../../../core";
5
5
 
6
6
  export const prerender = false;
7
7
 
@@ -58,7 +58,7 @@ export const POST: APIRoute = async ({ request, params, redirect, clientAddress
58
58
  return redirect(buildRedirectUrl(request, null, true), 303);
59
59
  }
60
60
 
61
- const form = await cms.forms.findOne({ where: { slug } }, { _system: true });
61
+ const form = await cms.forms.findOne({ slug }, { _system: true });
62
62
  if (!form) return new Response("Form not found", { status: 404 });
63
63
 
64
64
  const fieldConfigs = Array.isArray(form.fields) ? (form.fields as FormFieldConfig[]) : [];
@@ -125,8 +125,9 @@ export const POST: APIRoute = async ({ request, params, redirect, clientAddress
125
125
  await sendFormSubmissionEmail(String(form.notificationEmail), String(form.title), data);
126
126
  }
127
127
 
128
- if (form.submitRedirect) {
129
- return redirect(String(form.submitRedirect), 303);
128
+ const submitRedirect = form.submitRedirect ? safeUrl(String(form.submitRedirect)) : null;
129
+ if (submitRedirect) {
130
+ return redirect(submitRedirect, 303);
130
131
  }
131
132
 
132
133
  return redirect(buildRedirectUrl(request, null, true), 303);