@sveltejs/adapter-vercel 2.2.1 → 2.3.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
@@ -2,8 +2,6 @@
2
2
 
3
3
  A SvelteKit adapter that creates a Vercel app.
4
4
 
5
- If you're using [adapter-auto](https://kit.svelte.dev/docs/adapter-auto), you don't need to install this unless you need to specify Vercel-specific options, since it's already included.
6
-
7
5
  ## Docs
8
6
 
9
7
  [Docs](https://kit.svelte.dev/docs/adapter-vercel)
package/files/edge.js CHANGED
@@ -8,12 +8,16 @@ const initialized = server.init({
8
8
 
9
9
  /**
10
10
  * @param {Request} request
11
+ * @param {import('../index.js').RequestContext} context
11
12
  */
12
- export default async (request) => {
13
+ export default async (request, context) => {
13
14
  await initialized;
14
15
  return server.respond(request, {
15
16
  getClientAddress() {
16
17
  return /** @type {string} */ (request.headers.get('x-forwarded-for'));
18
+ },
19
+ platform: {
20
+ context
17
21
  }
18
22
  });
19
23
  };
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Adapter } from '@sveltejs/kit';
2
+ import './ambient.js';
2
3
 
3
4
  export default function plugin(config?: Config): Adapter;
4
5
 
@@ -77,3 +78,59 @@ export interface EdgeConfig {
77
78
  }
78
79
 
79
80
  export type Config = EdgeConfig | ServerlessConfig;
81
+
82
+ // we copy the RequestContext interface from `@vercel/edge` because that package can't co-exist with `@types/node`.
83
+ // see https://github.com/sveltejs/kit/pull/9280#issuecomment-1452110035
84
+
85
+ /**
86
+ * An extension to the standard `Request` object that is passed to every Edge Function.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import type { RequestContext } from '@vercel/edge';
91
+ *
92
+ * export default async function handler(request: Request, ctx: RequestContext): Promise<Response> {
93
+ * // ctx is the RequestContext
94
+ * }
95
+ * ```
96
+ */
97
+ export interface RequestContext {
98
+ /**
99
+ * A method that can be used to keep the function running after a response has been sent.
100
+ * This is useful when you have an async task that you want to keep running even after the
101
+ * response has been sent and the request has ended.
102
+ *
103
+ * @example
104
+ *
105
+ * <caption>Sending an internal error to an error tracking service</caption>
106
+ *
107
+ * ```ts
108
+ * import type { RequestContext } from '@vercel/edge';
109
+ *
110
+ * export async function handleRequest(request: Request, ctx: RequestContext): Promise<Response> {
111
+ * try {
112
+ * return await myFunctionThatReturnsResponse();
113
+ * } catch (e) {
114
+ * ctx.waitUntil((async () => {
115
+ * // report this error to your error tracking service
116
+ * await fetch('https://my-error-tracking-service.com', {
117
+ * method: 'POST',
118
+ * body: JSON.stringify({
119
+ * stack: e.stack,
120
+ * message: e.message,
121
+ * name: e.name,
122
+ * url: request.url,
123
+ * }),
124
+ * });
125
+ * })());
126
+ * return new Response('Internal Server Error', { status: 500 });
127
+ * }
128
+ * }
129
+ * ```
130
+ */
131
+ waitUntil(
132
+ /**
133
+ * A promise that will be kept alive until it resolves or rejects.
134
+ */ promise: Promise<unknown>
135
+ ): void;
136
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -29,7 +29,7 @@
29
29
  "devDependencies": {
30
30
  "@types/node": "^16.18.6",
31
31
  "typescript": "^4.9.4",
32
- "@sveltejs/kit": "^1.9.2"
32
+ "@sveltejs/kit": "^1.11.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@sveltejs/kit": "^1.5.0"