astro 4.8.7 → 4.9.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.
@@ -113,7 +113,7 @@ function createDevelopmentManifest(settings) {
113
113
  componentMetadata: /* @__PURE__ */ new Map(),
114
114
  inlinedScripts: /* @__PURE__ */ new Map(),
115
115
  i18n: i18nManifest,
116
- checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false,
116
+ checkOrigin: settings.config.security?.checkOrigin ?? false,
117
117
  rewritingEnabled: settings.config.experimental.rewriting,
118
118
  middleware(_, next) {
119
119
  return next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.8.7",
3
+ "version": "4.9.1",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -48,6 +48,10 @@
48
48
  "types": "./config.d.ts",
49
49
  "default": "./config.mjs"
50
50
  },
51
+ "./container": {
52
+ "types": "./dist/container/index.d.ts",
53
+ "default": "./dist/container/index.js"
54
+ },
51
55
  "./app": "./dist/core/app/index.js",
52
56
  "./app/node": "./dist/core/app/node.js",
53
57
  "./client/*": "./dist/runtime/client/*",
@@ -7,11 +7,33 @@ function toActionProxy(actionCallback = {}, aggregatedPath = '/_actions/') {
7
7
  return target[objKey];
8
8
  }
9
9
  const path = aggregatedPath + objKey.toString();
10
- const action = (clientParam) => actionHandler(clientParam, path);
10
+ const action = (param) => actionHandler(param, path);
11
11
  action.toString = () => path;
12
12
  action.safe = (input) => {
13
13
  return callSafely(() => action(input));
14
14
  };
15
+ action.safe.toString = () => path;
16
+
17
+ // Add progressive enhancement info for React.
18
+ action.$$FORM_ACTION = function () {
19
+ const data = new FormData();
20
+ data.set('_astroAction', action.toString());
21
+ return {
22
+ method: 'POST',
23
+ name: action.toString(),
24
+ data,
25
+ };
26
+ };
27
+ action.safe.$$FORM_ACTION = function () {
28
+ const data = new FormData();
29
+ data.set('_astroAction', action.toString());
30
+ data.set('_astroActionSafe', 'true');
31
+ return {
32
+ method: 'POST',
33
+ name: action.toString(),
34
+ data,
35
+ };
36
+ };
15
37
  // recurse to construct queries for nested object paths
16
38
  // ex. actions.user.admins.auth()
17
39
  return toActionProxy(action, path + '.');
@@ -20,24 +42,27 @@ function toActionProxy(actionCallback = {}, aggregatedPath = '/_actions/') {
20
42
  }
21
43
 
22
44
  /**
23
- * @param {*} clientParam argument passed to the action when used on the client.
24
- * @param {string} path Built path to call action on the server.
25
- * Usage: `actions.[name](clientParam)`.
45
+ * @param {*} param argument passed to the action when called server or client-side.
46
+ * @param {string} path Built path to call action by path name.
47
+ * Usage: `actions.[name](param)`.
26
48
  */
27
- async function actionHandler(clientParam, path) {
49
+ async function actionHandler(param, path) {
50
+ // When running server-side, import the action and call it.
28
51
  if (import.meta.env.SSR) {
29
- throw new ActionError({
30
- code: 'BAD_REQUEST',
31
- message:
32
- 'Action unexpectedly called on the server. If this error is unexpected, share your feedback on our RFC discussion: https://github.com/withastro/roadmap/pull/912',
33
- });
52
+ const { getAction } = await import('astro/actions/runtime/utils.js');
53
+ const action = await getAction(path);
54
+ if (!action) throw new Error(`Action not found: ${path}`);
55
+
56
+ return action(param);
34
57
  }
58
+
59
+ // When running client-side, make a fetch request to the action path.
35
60
  const headers = new Headers();
36
61
  headers.set('Accept', 'application/json');
37
- let body = clientParam;
62
+ let body = param;
38
63
  if (!(body instanceof FormData)) {
39
64
  try {
40
- body = clientParam ? JSON.stringify(clientParam) : undefined;
65
+ body = param ? JSON.stringify(param) : undefined;
41
66
  } catch (e) {
42
67
  throw new ActionError({
43
68
  code: 'BAD_REQUEST',