@astrojs/cloudflare 6.8.0 → 6.8.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/README.md CHANGED
@@ -75,12 +75,59 @@ It's then possible to update the preview script in your `package.json` to `"prev
75
75
 
76
76
  You can access all the Cloudflare bindings and environment variables from Astro components and API routes through `Astro.locals`.
77
77
 
78
- ```js
78
+ If you're inside an `.astro` file, you access the runtime using the `Astro.locals` global:
79
+
80
+ ```astro
79
81
  const env = Astro.locals.runtime.env;
80
82
  ```
81
83
 
84
+ From an endpoint:
85
+
86
+ ```js
87
+ // src/pages/api/someFile.js
88
+ export function get(context) {
89
+ const runtime = context.locals.runtime;
90
+
91
+ return new Response('Some body');
92
+ }
93
+ ```
94
+
82
95
  Depending on your adapter mode (advanced = worker, directory = pages), the runtime object will look a little different due to differences in the Cloudflare API.
83
96
 
97
+ If you're using the `advanced` runtime, you can type the `runtime` object as following:
98
+
99
+ ```ts
100
+ // src/env.d.ts
101
+ /// <reference types="astro/client" />
102
+ import type { AdvancedRuntime } from '@astrojs/cloudflare';
103
+
104
+ declare namespace App {
105
+ interface Locals extends AdvancedRuntime {
106
+ user: {
107
+ name: string;
108
+ surname: string;
109
+ };
110
+ }
111
+ }
112
+ ```
113
+
114
+ If you're using the `directory` runtime, you can type the `runtime` object as following:
115
+
116
+ ```ts
117
+ // src/env.d.ts
118
+ /// <reference types="astro/client" />
119
+ import type { DirectoryRuntime } from '@astrojs/cloudflare';
120
+
121
+ declare namespace App {
122
+ interface Locals extends DirectoryRuntime {
123
+ user: {
124
+ name: string;
125
+ surname: string;
126
+ };
127
+ }
128
+ }
129
+ ```
130
+
84
131
  ## Environment Variables
85
132
 
86
133
  See Cloudflare's documentation for [working with environment variables](https://developers.cloudflare.com/pages/platform/functions/bindings/#environment-variables).
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { AstroAdapter, AstroIntegration } from 'astro';
2
+ export type { AdvancedRuntime } from './server.advanced';
3
+ export type { DirectoryRuntime } from './server.directory';
2
4
  type Options = {
3
5
  mode: 'directory' | 'advanced';
4
6
  };
5
7
  export declare function getAdapter(isModeDirectory: boolean): AstroAdapter;
6
8
  export default function createIntegration(args?: Options): AstroIntegration;
7
- export {};
@@ -6,6 +6,14 @@ type Env = {
6
6
  };
7
7
  name: string;
8
8
  };
9
+ export interface AdvancedRuntime {
10
+ runtime: {
11
+ waitUntil: (promise: Promise<any>) => void;
12
+ env: Env;
13
+ cf: CFRequest['cf'];
14
+ caches: typeof caches;
15
+ };
16
+ }
9
17
  export declare function createExports(manifest: SSRManifest): {
10
18
  default: {
11
19
  fetch: (request: Request & CFRequest, env: Env, context: ExecutionContext) => Promise<Response>;
@@ -1,5 +1,13 @@
1
- import type { EventContext } from '@cloudflare/workers-types';
1
+ import type { Request as CFRequest, EventContext } from '@cloudflare/workers-types';
2
2
  import type { SSRManifest } from 'astro';
3
+ export interface DirectoryRuntime {
4
+ runtime: {
5
+ waitUntil: (promise: Promise<any>) => void;
6
+ env: EventContext<unknown, string, unknown>['env'];
7
+ cf: CFRequest['cf'];
8
+ caches: typeof caches;
9
+ };
10
+ }
3
11
  export declare function createExports(manifest: SSRManifest): {
4
12
  onRequest: (context: EventContext<unknown, string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
5
13
  manifest: SSRManifest;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/cloudflare",
3
3
  "description": "Deploy your site to Cloudflare Workers/Pages",
4
- "version": "6.8.0",
4
+ "version": "6.8.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -38,14 +38,15 @@
38
38
  "tiny-glob": "^0.2.9"
39
39
  },
40
40
  "peerDependencies": {
41
- "astro": "^2.10.6"
41
+ "astro": "^2.10.14"
42
42
  },
43
43
  "devDependencies": {
44
44
  "chai": "^4.3.7",
45
45
  "cheerio": "1.0.0-rc.12",
46
+ "kill-port": "^2.0.1",
46
47
  "mocha": "^9.2.2",
47
- "wrangler": "^2.0.23",
48
- "astro": "2.10.6",
48
+ "wrangler": "^3.5.0",
49
+ "astro": "2.10.14",
49
50
  "astro-scripts": "0.0.14"
50
51
  },
51
52
  "scripts": {