@vercel/schedules 0.0.0-alpha.10 → 0.0.0-alpha.11
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 +27 -1
- package/dist/index.cjs +56 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +55 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ This schedules one invocation at 9 AM Pacific on September 16. The `at` field do
|
|
|
46
46
|
|
|
47
47
|
Schedules returned by `get()` and `list()` include the IANA timezone.
|
|
48
48
|
|
|
49
|
+
Returned targets can be queues (`{ type: 'queue', topic: string }`) or statically configured functions (`{ type: 'function', function: string }`). Check `target.type` before reading the destination. Both the local and production APIs can return function targets. The `create()` and `update()` target inputs remain queue-only (`{ topic: string }`); the SDK does not support creating dynamic function schedules.
|
|
50
|
+
|
|
49
51
|
Update schedule configuration by name and optional namespace:
|
|
50
52
|
|
|
51
53
|
```ts
|
|
@@ -80,7 +82,7 @@ export const POST = handleSchedule(async (metadata) => {
|
|
|
80
82
|
});
|
|
81
83
|
```
|
|
82
84
|
|
|
83
|
-
The handler receives metadata about the current firing.
|
|
85
|
+
The handler receives only metadata about the current firing, including `executionId` from the CloudEvent `ce-id` header and `scheduledAt` from the required `ce-vssscheduledat` header. `scheduledAt` is a `Date` representing the scheduled run time; the parser does not use `ce-time` as a fallback. The handler returns a `200` response when the callback completes successfully. Static schedules do not accept a configured payload; dynamic Queue schedules created or updated through the SDK still support `payload`.
|
|
84
86
|
|
|
85
87
|
For a custom client:
|
|
86
88
|
|
|
@@ -93,3 +95,27 @@ const schedules = new SchedulesClient();
|
|
|
93
95
|
The default client connects to the Vercel Schedules API at `https://vercel-schedules.com`. Override the endpoint with `baseUrl` or `VERCEL_SCHEDULE_BASE_URL`.
|
|
94
96
|
|
|
95
97
|
Requests are authenticated with the Vercel OIDC token from `@vercel/oidc`, or an explicit `token` option.
|
|
98
|
+
|
|
99
|
+
## Connect to the local Schedules API
|
|
100
|
+
|
|
101
|
+
The SDK uses CLI-injected local authentication only when `NODE_ENV` is `development`, `VERCEL_DEPLOYMENT_ID` is unset, and `VERCEL_SCHEDULE_DEV_API_VERSION` is `1`. An empty `VERCEL_DEPLOYMENT_ID` still counts as set and disables automatic local authentication.
|
|
102
|
+
|
|
103
|
+
A compatible CLI-hosted local API supplies these environment variables before starting your app:
|
|
104
|
+
|
|
105
|
+
| Variable | Value |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `VERCEL_SCHEDULE_BASE_URL` | Absolute HTTP(S) URL of the local API, optionally including a proxy path prefix. The URL must not include credentials, a query, or a fragment. |
|
|
108
|
+
| `VERCEL_SCHEDULE_TOKEN` | Bearer token for the local API. |
|
|
109
|
+
| `VERCEL_SCHEDULE_DEV_API_VERSION` | `1`, declaring support for the SDK's `/v1/schedules` routes. |
|
|
110
|
+
|
|
111
|
+
The endpoint precedence remains `baseUrl`, then `VERCEL_SCHEDULE_BASE_URL`, then `https://vercel-schedules.com`. Without the version marker, the existing environment URL override continues to use OIDC or an explicit token, even for a loopback URL.
|
|
112
|
+
|
|
113
|
+
An explicit `token` takes precedence over `VERCEL_SCHEDULE_TOKEN`. The injected token applies only when the effective endpoint has the same origin and normalized base path as `VERCEL_SCHEDULE_BASE_URL`. URL normalization includes default ports and trailing slashes; a different path on the same origin is a separate endpoint. A separate endpoint uses its explicit token or OIDC and ignores broken injected local configuration.
|
|
114
|
+
|
|
115
|
+
The SDK preserves the base path when appending API routes. For example, `http://localhost:3000/_vercel/schedules` sends list requests to `http://localhost:3000/_vercel/schedules/v1/schedules`. The local API supports the same `create`, `list`, `get`, `update`, `delete`, `enable`, `disable`, and `invoke` methods.
|
|
116
|
+
|
|
117
|
+
The exported `Schedules` singleton is created eagerly when the SDK module is imported. Set the environment variables **before importing** `@vercel/schedules`. Each client captures its endpoint, local token, and local configuration errors at construction; changing the environment afterward does not reconfigure that client. Create a new `SchedulesClient` to capture changed configuration.
|
|
118
|
+
|
|
119
|
+
When local mode is selected, a missing token, missing or invalid URL, or unsupported version causes requests to fail before fetching or acquiring OIDC credentials. An explicit token can replace a missing injected token. Only selected-local configuration errors are deferred until a method is called, so importing the default singleton still allows you to create a client for an independent endpoint. An invalid explicit `baseUrl` always throws during construction, as does an invalid environment base URL outside selected local mode. Local request failures and API errors do not fall back to OIDC or the cloud API.
|
|
120
|
+
|
|
121
|
+
The SDK does not probe local capabilities, start a scheduler, or create timers on import or client construction. The version marker declares API compatibility; the CLI manages the local service.
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,13 @@ var _oidc = require('@vercel/oidc');
|
|
|
5
5
|
var DEFAULT_SCHEDULES_BASE_URL = "https://vercel-schedules.com";
|
|
6
6
|
|
|
7
7
|
// src/api-client.ts
|
|
8
|
+
function trimTrailingSlashes(path) {
|
|
9
|
+
let end = path.length;
|
|
10
|
+
while (end > 0 && path[end - 1] === "/") {
|
|
11
|
+
end--;
|
|
12
|
+
}
|
|
13
|
+
return path.slice(0, end);
|
|
14
|
+
}
|
|
8
15
|
var SchedulesApiError = class extends Error {
|
|
9
16
|
constructor(status, message) {
|
|
10
17
|
super(message);
|
|
@@ -14,14 +21,50 @@ var SchedulesApiError = class extends Error {
|
|
|
14
21
|
};
|
|
15
22
|
var SchedulesApiClient = class {
|
|
16
23
|
constructor(options = {}) {
|
|
17
|
-
var _a, _b, _c;
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
25
|
+
this.token = options.token;
|
|
26
|
+
this.fetchImpl = (_a = options.fetch) != null ? _a : fetch;
|
|
27
|
+
const envBaseUrl = process.env.VERCEL_SCHEDULE_BASE_URL;
|
|
28
|
+
const devApiVersion = process.env.VERCEL_SCHEDULE_DEV_API_VERSION;
|
|
29
|
+
let advertisedBaseUrl;
|
|
30
|
+
try {
|
|
31
|
+
advertisedBaseUrl = new URL(envBaseUrl != null ? envBaseUrl : "");
|
|
32
|
+
} catch (e) {
|
|
33
|
+
}
|
|
34
|
+
const explicitBaseUrl = options.baseUrl === void 0 ? void 0 : new URL(options.baseUrl);
|
|
35
|
+
const localSelected = process.env.NODE_ENV === "development" && process.env.VERCEL_DEPLOYMENT_ID === void 0 && devApiVersion !== void 0 && (explicitBaseUrl === void 0 || advertisedBaseUrl !== void 0 && explicitBaseUrl.origin === advertisedBaseUrl.origin && trimTrailingSlashes(explicitBaseUrl.pathname) === trimTrailingSlashes(advertisedBaseUrl.pathname));
|
|
36
|
+
if (localSelected) {
|
|
37
|
+
try {
|
|
38
|
+
if (devApiVersion !== "1") {
|
|
39
|
+
throw new Error(
|
|
40
|
+
'Unsupported VERCEL_SCHEDULE_DEV_API_VERSION. This SDK supports local Schedules API version "1".'
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (!advertisedBaseUrl || !["http:", "https:"].includes(advertisedBaseUrl.protocol) || advertisedBaseUrl.username || advertisedBaseUrl.password || advertisedBaseUrl.search || advertisedBaseUrl.hash) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"Local Schedules requires VERCEL_SCHEDULE_BASE_URL to be an absolute HTTP(S) URL without credentials, a query, or a fragment."
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
this.token = (_b = options.token) != null ? _b : process.env.VERCEL_SCHEDULE_TOKEN;
|
|
49
|
+
if (!((_c = this.token) == null ? void 0 : _c.trim())) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Local Schedules requires VERCEL_SCHEDULE_TOKEN or an explicit token option."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
this.configurationError = err instanceof Error ? err : new Error(String(err));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
18
59
|
this.baseUrl = new URL(
|
|
19
|
-
(
|
|
60
|
+
(_e = (_d = options.baseUrl) != null ? _d : envBaseUrl) != null ? _e : DEFAULT_SCHEDULES_BASE_URL
|
|
20
61
|
);
|
|
21
|
-
this.
|
|
22
|
-
this.fetchImpl = (_c = options.fetch) != null ? _c : fetch;
|
|
62
|
+
this.baseUrl.pathname = `${trimTrailingSlashes(this.baseUrl.pathname)}/`;
|
|
23
63
|
}
|
|
24
64
|
async getToken() {
|
|
65
|
+
if (this.configurationError) {
|
|
66
|
+
throw this.configurationError;
|
|
67
|
+
}
|
|
25
68
|
if (this.token) {
|
|
26
69
|
return this.token;
|
|
27
70
|
}
|
|
@@ -53,11 +96,14 @@ Cause: ${cause}`
|
|
|
53
96
|
if (body !== void 0) {
|
|
54
97
|
headers.set("Content-Type", "application/json");
|
|
55
98
|
}
|
|
56
|
-
const response = await this.fetchImpl(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
const response = await this.fetchImpl(
|
|
100
|
+
new URL(path.replace(/^\/+/, ""), this.baseUrl),
|
|
101
|
+
{
|
|
102
|
+
method,
|
|
103
|
+
headers,
|
|
104
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
105
|
+
}
|
|
106
|
+
);
|
|
61
107
|
if (!response.ok) {
|
|
62
108
|
const text = await response.text();
|
|
63
109
|
throw new SchedulesApiError(response.status, text || response.statusText);
|
|
@@ -228,7 +274,7 @@ function handleSchedule(handler) {
|
|
|
228
274
|
try {
|
|
229
275
|
await handler(metadata);
|
|
230
276
|
return new Response(null, { status: 200 });
|
|
231
|
-
} catch (
|
|
277
|
+
} catch (e2) {
|
|
232
278
|
return Response.json(
|
|
233
279
|
{ error: "Schedule handler failed" },
|
|
234
280
|
{ status: 500 }
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/schedules/schedules/packages/schedules/dist/index.cjs","../src/api-client.ts","../src/constants.ts","../src/schedules.ts","../src/default-client.ts","../src/schedule-event.ts"],"names":[],"mappings":"AAAA;ACAA,oCAAmC;ADEnC;AACA;AEHO,IAAM,2BAAA,EAA6B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AACA;AKhJF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwBA;AAGC,EAAA;AACJ,IAAA;AACD,IAAA;AACD,IAAA;AACG,MAAA;AACP,IAAA;AACF,EAAA;AACF;AAES;AACD,EAAA;AACM,EAAA;AACA,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AACO,EAAA;AACT;AAGsB;AAGR,EAAA;AACA,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEM,EAAA;AACF,EAAA;AACQ,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEM,EAAA;AACF,EAAA;AACQ,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEA,EAAA;AACM,EAAA;AACA,EAAA;AACJ,IAAA;AACA,IAAA;AACF,EAAA;AACM,EAAA;AACJ,IAAA;AACA,IAAA;AACM,IAAA;AACK,IAAA;AACX,IAAA;AACQ,IAAA;AACV,EAAA;AAEW,EAAA;AACC,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AAWgB;AAGP,EAAA;AACD,IAAA;AACA,IAAA;AACF,MAAA;AACO,IAAA;AACH,MAAA;AACK,QAAA;AACT,MAAA;AACO,MAAA;AACH,QAAA;AACA,QAAA;AACJ,MAAA;AACF,IAAA;AAEI,IAAA;AACI,MAAA;AACC,MAAA;AACD,IAAA;AACC,MAAA;AACH,QAAA;AACA,QAAA;AACJ,MAAA;AACF,IAAA;AACF,EAAA;AACF;ALkGe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/schedules/schedules/packages/schedules/dist/index.cjs","sourcesContent":[null,"import { getVercelOidcToken } from '@vercel/oidc';\nimport { DEFAULT_SCHEDULES_BASE_URL } from './constants';\n\nexport interface SchedulesApiClientOptions {\n baseUrl?: string;\n token?: string;\n fetch?: typeof fetch;\n}\n\nexport class SchedulesApiError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = 'SchedulesApiError';\n this.status = status;\n }\n}\n\nexport class SchedulesApiClient {\n private readonly baseUrl: URL;\n private readonly token?: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: SchedulesApiClientOptions = {}) {\n this.baseUrl = new URL(\n options.baseUrl ??\n process.env.VERCEL_SCHEDULE_BASE_URL ??\n DEFAULT_SCHEDULES_BASE_URL,\n );\n this.token = options.token;\n this.fetchImpl = options.fetch ?? fetch;\n }\n\n protected async getToken(): Promise<string> {\n if (this.token) {\n return this.token;\n }\n\n try {\n return await getVercelOidcToken();\n } catch (err) {\n const cause = err instanceof Error ? err.message : String(err);\n const isDev = process.env.NODE_ENV === 'development';\n\n throw new Error(\n isDev\n ? 'Failed to get OIDC token for local development.\\n\\n' +\n 'To fix this, pull your environment variables with Vercel CLI:\\n' +\n ' `vercel env pull`\\n\\n' +\n `Cause: ${cause}`\n : 'Failed to get OIDC token. This usually means the function is running ' +\n 'outside of a Vercel Function environment.\\n\\n' +\n 'To fix this, either:\\n' +\n ' - Deploy to Vercel (OIDC tokens are provisioned automatically)\\n' +\n ' - Provide a token explicitly: `new Schedules({ token: \"...\" })`\\n\\n' +\n `Cause: ${cause}`,\n );\n }\n }\n\n protected async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n });\n\n if (body !== undefined) {\n headers.set('Content-Type', 'application/json');\n }\n\n const response = await this.fetchImpl(new URL(path, this.baseUrl), {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n\n if (!response.ok) {\n const text = await response.text();\n throw new SchedulesApiError(response.status, text || response.statusText);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return (await response.json()) as T;\n }\n}\n","export const DEFAULT_SCHEDULES_BASE_URL = 'https://vercel-schedules.com';\n","import { SchedulesApiClient } from './api-client';\nimport type {\n CreateScheduleParams,\n CreateScheduleResponse,\n InvokeScheduleParams,\n ListSchedulesParams,\n ListSchedulesResponse,\n Schedule,\n ScheduleIdentifier,\n UpdateScheduleParams,\n UpdateScheduleResponse,\n} from './types';\n\nfunction schedulePath(name: string, namespace?: string, suffix = ''): string {\n const searchParams = new URLSearchParams();\n\n if (namespace !== undefined) {\n searchParams.set('namespace', namespace);\n }\n\n const query = searchParams.toString();\n const path = `/v1/schedules/${encodeURIComponent(name)}${suffix}`;\n\n return query ? `${path}?${query}` : path;\n}\n\nexport class SchedulesClient extends SchedulesApiClient {\n create({\n target,\n ...params\n }: CreateScheduleParams): Promise<CreateScheduleResponse> {\n return this.request('POST', '/v1/schedules', {\n ...params,\n target: {\n type: 'queue',\n topic: target.topic,\n },\n });\n }\n\n list(params: ListSchedulesParams = {}): Promise<ListSchedulesResponse> {\n const searchParams = new URLSearchParams();\n\n if (params.namespace !== undefined) {\n searchParams.set('namespace', params.namespace);\n }\n if (params.cursor !== undefined) {\n searchParams.set('cursor', params.cursor);\n }\n if (params.limit !== undefined) {\n searchParams.set('limit', String(params.limit));\n }\n\n const query = searchParams.toString();\n const path = query ? `/v1/schedules?${query}` : '/v1/schedules';\n\n return this.request('GET', path);\n }\n\n get({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('GET', schedulePath(name, namespace));\n }\n\n update({\n name,\n namespace,\n target,\n ...params\n }: UpdateScheduleParams): Promise<UpdateScheduleResponse> {\n return this.request('PATCH', schedulePath(name, namespace), {\n ...params,\n ...(target === undefined\n ? {}\n : {\n target: {\n type: 'queue',\n topic: target.topic,\n },\n }),\n });\n }\n\n async delete({ name, namespace }: ScheduleIdentifier): Promise<void> {\n await this.request('DELETE', schedulePath(name, namespace));\n }\n\n enable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/enable'));\n }\n\n disable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/disable'));\n }\n\n async invoke({ name, namespace }: InvokeScheduleParams): Promise<void> {\n await this.request('POST', schedulePath(name, namespace, '/invoke'));\n }\n}\n","import { SchedulesClient } from './schedules';\n\nexport const schedules = new SchedulesClient();\n","/** CloudEvent type used for schedule function dispatches. */\nexport const SCHEDULE_CLOUD_EVENT_TYPE = 'com.vercel.schedule.v1beta';\nexport const CLOUD_EVENT_SPEC_VERSION_HEADER = 'ce-specversion';\nexport const CLOUD_EVENT_TYPE_HEADER = 'ce-type';\nexport const CLOUD_EVENT_SOURCE_HEADER = 'ce-source';\nexport const CLOUD_EVENT_ID_HEADER = 'ce-id';\nexport const SCHEDULE_SCHEDULED_AT_HEADER = 'ce-vssscheduledat';\nexport const SCHEDULE_ID_HEADER = 'ce-vssscheduleid';\nexport const SCHEDULE_NAME_HEADER = 'ce-vssschedulename';\nexport const SCHEDULE_NAMESPACE_HEADER = 'ce-vssnamespace';\nexport const SCHEDULE_SOURCE_HEADER = 'ce-vssschedulesource';\n\nexport interface ScheduleMetadata {\n /** Unique identifier of the schedule. */\n scheduleId: string;\n /** Unique identifier for this schedule occurrence. */\n executionId: string;\n /** Schedule name, unique within its project and namespace. */\n name: string;\n /** Namespace the schedule belongs to. */\n namespace: string;\n /**\n * Nominal scheduled time for this occurrence, based on the schedule expression.\n * Does not account for jitter. The dispatch may arrive later within the jitter window.\n */\n scheduledAt: Date;\n /** How the schedule was defined, such as `static`. */\n source: string;\n}\n\nexport type ScheduleHandler = (\n metadata: ScheduleMetadata,\n) => void | Promise<void>;\n\nexport class ScheduleEventParseError extends Error {\n cause?: unknown;\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = 'ScheduleEventParseError';\n if (options && 'cause' in options) {\n this.cause = options.cause;\n }\n }\n}\n\nfunction requiredHeader(request: Request, name: string): string {\n const value = request.headers.get(name);\n if (!value) {\n throw new ScheduleEventParseError(\n `Request is missing the ${name} header; it does not look like a schedule dispatch`,\n );\n }\n return value;\n}\n\n/** Parses schedule metadata from a binary-mode schedule CloudEvent. */\nexport async function parseScheduleEvent(\n request: Request,\n): Promise<ScheduleMetadata> {\n if (request.method !== 'POST') {\n throw new ScheduleEventParseError(\n `Schedule dispatches are POST requests, received ${request.method}`,\n );\n }\n\n const specVersion = requiredHeader(request, CLOUD_EVENT_SPEC_VERSION_HEADER);\n if (specVersion !== '1.0') {\n throw new ScheduleEventParseError(\n `Unsupported CloudEvent spec version: ${specVersion}`,\n );\n }\n\n const eventType = requiredHeader(request, CLOUD_EVENT_TYPE_HEADER);\n if (eventType !== SCHEDULE_CLOUD_EVENT_TYPE) {\n throw new ScheduleEventParseError(\n `Unsupported schedule CloudEvent type: ${eventType}`,\n );\n }\n\n requiredHeader(request, CLOUD_EVENT_SOURCE_HEADER);\n const executionId = requiredHeader(request, CLOUD_EVENT_ID_HEADER);\n const scheduledAtValue = requiredHeader(\n request,\n SCHEDULE_SCHEDULED_AT_HEADER,\n );\n const metadata: ScheduleMetadata = {\n scheduleId: requiredHeader(request, SCHEDULE_ID_HEADER),\n executionId,\n name: requiredHeader(request, SCHEDULE_NAME_HEADER),\n namespace: requiredHeader(request, SCHEDULE_NAMESPACE_HEADER),\n scheduledAt: new Date(scheduledAtValue),\n source: requiredHeader(request, SCHEDULE_SOURCE_HEADER),\n };\n\n if (Number.isNaN(metadata.scheduledAt.getTime())) {\n throw new ScheduleEventParseError(\n `Schedule scheduledAt is not a valid timestamp: ${scheduledAtValue}`,\n );\n }\n\n return metadata;\n}\n\n/**\n * Creates a web-standard route handler for schedule dispatches.\n *\n * ```ts\n * export const POST = handleSchedule(async (metadata) => {\n * console.log(metadata.name, metadata.scheduledAt);\n * });\n * ```\n */\nexport function handleSchedule(\n handler: ScheduleHandler,\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n let metadata: ScheduleMetadata;\n try {\n metadata = await parseScheduleEvent(request);\n } catch (error) {\n if (error instanceof ScheduleEventParseError) {\n return Response.json({ error: error.message }, { status: 400 });\n }\n return Response.json(\n { error: 'Failed to parse schedule dispatch' },\n { status: 500 },\n );\n }\n\n try {\n await handler(metadata);\n return new Response(null, { status: 200 });\n } catch {\n return Response.json(\n { error: 'Schedule handler failed' },\n { status: 500 },\n );\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/schedules/schedules/packages/schedules/dist/index.cjs","../src/api-client.ts","../src/constants.ts","../src/schedules.ts","../src/default-client.ts","../src/schedule-event.ts"],"names":[],"mappings":"AAAA;ACAA,oCAAmC;ADEnC;AACA;AEHO,IAAM,2BAAA,EAA6B,8BAAA;AFK1C;AACA;ACGA,SAAS,mBAAA,CAAoB,IAAA,EAAsB;AACjD,EAAA,IAAI,IAAA,EAAM,IAAA,CAAK,MAAA;AACf,EAAA,MAAA,CAAO,IAAA,EAAM,EAAA,GAAK,IAAA,CAAK,IAAA,EAAM,CAAC,EAAA,IAAM,GAAA,EAAK;AACvC,IAAA,GAAA,EAAA;AAAA,EACF;AACA,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,GAAG,CAAA;AAC1B;AAEO,IAAM,kBAAA,EAAN,MAAA,QAAgC,MAAM;AAAA,EAG3C,WAAA,CAAY,MAAA,EAAgB,OAAA,EAAiB;AAC3C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,KAAA,EAAO,mBAAA;AACZ,IAAA,IAAA,CAAK,OAAA,EAAS,MAAA;AAAA,EAChB;AACF,CAAA;AAEO,IAAM,mBAAA,EAAN,MAAyB;AAAA,EAM9B,WAAA,CAAY,QAAA,EAAqC,CAAC,CAAA,EAAG;AAjCvD,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAkCI,IAAA,IAAA,CAAK,MAAA,EAAQ,OAAA,CAAQ,KAAA;AACrB,IAAA,IAAA,CAAK,UAAA,EAAA,CAAY,GAAA,EAAA,OAAA,CAAQ,KAAA,EAAA,GAAR,KAAA,EAAA,GAAA,EAAiB,KAAA;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EAAA;AACF;AAEwB;AACA,EAAA;AACV,EAAA;AACA,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AACO,EAAA;AACT;AAGsB;AAGG,EAAA;AACX,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEoB,EAAA;AACO,EAAA;AACf,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEkB,EAAA;AACA,EAAA;AACN,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEwB,EAAA;AACJ,EAAA;AACK,EAAA;AACvB,IAAA;AACA,IAAA;AACF,EAAA;AACmC,EAAA;AACrB,IAAA;AACZ,IAAA;AACqB,IAAA;AACV,IAAA;AACW,IAAA;AACC,IAAA;AACzB,EAAA;AAE0B,EAAA;AACd,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AAYE;AAEsD,EAAA;AAChD,IAAA;AACA,IAAA;AACe,MAAA;AACH,IAAA;AACO,MAAA;AACE,QAAA;AACvB,MAAA;AACgB,MAAA;AACL,QAAA;AACK,QAAA;AAChB,MAAA;AACF,IAAA;AAEI,IAAA;AACoB,MAAA;AACF,MAAA;AACd,IAAA;AACU,MAAA;AACL,QAAA;AACK,QAAA;AAChB,MAAA;AACF,IAAA;AACF,EAAA;AACF;ALgJ6B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/schedules/schedules/packages/schedules/dist/index.cjs","sourcesContent":[null,"import { getVercelOidcToken } from '@vercel/oidc';\nimport { DEFAULT_SCHEDULES_BASE_URL } from './constants';\n\nexport interface SchedulesApiClientOptions {\n baseUrl?: string;\n token?: string;\n fetch?: typeof fetch;\n}\n\nfunction trimTrailingSlashes(path: string): string {\n let end = path.length;\n while (end > 0 && path[end - 1] === '/') {\n end--;\n }\n return path.slice(0, end);\n}\n\nexport class SchedulesApiError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = 'SchedulesApiError';\n this.status = status;\n }\n}\n\nexport class SchedulesApiClient {\n private readonly baseUrl?: URL;\n private readonly token?: string;\n private readonly fetchImpl: typeof fetch;\n private readonly configurationError?: Error;\n\n constructor(options: SchedulesApiClientOptions = {}) {\n this.token = options.token;\n this.fetchImpl = options.fetch ?? fetch;\n\n const envBaseUrl = process.env.VERCEL_SCHEDULE_BASE_URL;\n const devApiVersion = process.env.VERCEL_SCHEDULE_DEV_API_VERSION;\n let advertisedBaseUrl: URL | undefined;\n try {\n advertisedBaseUrl = new URL(envBaseUrl ?? '');\n } catch {\n // An independent explicit endpoint does not need the injected URL.\n }\n\n const explicitBaseUrl =\n options.baseUrl === undefined ? undefined : new URL(options.baseUrl);\n const localSelected =\n process.env.NODE_ENV === 'development' &&\n process.env.VERCEL_DEPLOYMENT_ID === undefined &&\n devApiVersion !== undefined &&\n (explicitBaseUrl === undefined ||\n (advertisedBaseUrl !== undefined &&\n explicitBaseUrl.origin === advertisedBaseUrl.origin &&\n trimTrailingSlashes(explicitBaseUrl.pathname) ===\n trimTrailingSlashes(advertisedBaseUrl.pathname)));\n\n if (localSelected) {\n try {\n if (devApiVersion !== '1') {\n throw new Error(\n 'Unsupported VERCEL_SCHEDULE_DEV_API_VERSION. This SDK supports local Schedules API version \"1\".',\n );\n }\n if (\n !advertisedBaseUrl ||\n !['http:', 'https:'].includes(advertisedBaseUrl.protocol) ||\n advertisedBaseUrl.username ||\n advertisedBaseUrl.password ||\n advertisedBaseUrl.search ||\n advertisedBaseUrl.hash\n ) {\n throw new Error(\n 'Local Schedules requires VERCEL_SCHEDULE_BASE_URL to be an absolute HTTP(S) URL without credentials, a query, or a fragment.',\n );\n }\n this.token = options.token ?? process.env.VERCEL_SCHEDULE_TOKEN;\n if (!this.token?.trim()) {\n throw new Error(\n 'Local Schedules requires VERCEL_SCHEDULE_TOKEN or an explicit token option.',\n );\n }\n } catch (err) {\n // Defer only selected-local configuration errors so the default\n // singleton does not prevent importing independent clients.\n this.configurationError =\n err instanceof Error ? err : new Error(String(err));\n return;\n }\n }\n\n this.baseUrl = new URL(\n options.baseUrl ?? envBaseUrl ?? DEFAULT_SCHEDULES_BASE_URL,\n );\n this.baseUrl.pathname = `${trimTrailingSlashes(this.baseUrl.pathname)}/`;\n }\n\n protected async getToken(): Promise<string> {\n if (this.configurationError) {\n throw this.configurationError;\n }\n if (this.token) {\n return this.token;\n }\n\n try {\n return await getVercelOidcToken();\n } catch (err) {\n const cause = err instanceof Error ? err.message : String(err);\n const isDev = process.env.NODE_ENV === 'development';\n\n throw new Error(\n isDev\n ? 'Failed to get OIDC token for local development.\\n\\n' +\n 'To fix this, pull your environment variables with Vercel CLI:\\n' +\n ' `vercel env pull`\\n\\n' +\n `Cause: ${cause}`\n : 'Failed to get OIDC token. This usually means the function is running ' +\n 'outside of a Vercel Function environment.\\n\\n' +\n 'To fix this, either:\\n' +\n ' - Deploy to Vercel (OIDC tokens are provisioned automatically)\\n' +\n ' - Provide a token explicitly: `new Schedules({ token: \"...\" })`\\n\\n' +\n `Cause: ${cause}`,\n );\n }\n }\n\n protected async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n });\n\n if (body !== undefined) {\n headers.set('Content-Type', 'application/json');\n }\n\n const response = await this.fetchImpl(\n new URL(path.replace(/^\\/+/, ''), this.baseUrl),\n {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n },\n );\n\n if (!response.ok) {\n const text = await response.text();\n throw new SchedulesApiError(response.status, text || response.statusText);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return (await response.json()) as T;\n }\n}\n","export const DEFAULT_SCHEDULES_BASE_URL = 'https://vercel-schedules.com';\n","import { SchedulesApiClient } from './api-client';\nimport type {\n CreateScheduleParams,\n CreateScheduleResponse,\n InvokeScheduleParams,\n ListSchedulesParams,\n ListSchedulesResponse,\n Schedule,\n ScheduleIdentifier,\n UpdateScheduleParams,\n UpdateScheduleResponse,\n} from './types';\n\nfunction schedulePath(name: string, namespace?: string, suffix = ''): string {\n const searchParams = new URLSearchParams();\n\n if (namespace !== undefined) {\n searchParams.set('namespace', namespace);\n }\n\n const query = searchParams.toString();\n const path = `/v1/schedules/${encodeURIComponent(name)}${suffix}`;\n\n return query ? `${path}?${query}` : path;\n}\n\nexport class SchedulesClient extends SchedulesApiClient {\n create({\n target,\n ...params\n }: CreateScheduleParams): Promise<CreateScheduleResponse> {\n return this.request('POST', '/v1/schedules', {\n ...params,\n target: {\n type: 'queue',\n topic: target.topic,\n },\n });\n }\n\n list(params: ListSchedulesParams = {}): Promise<ListSchedulesResponse> {\n const searchParams = new URLSearchParams();\n\n if (params.namespace !== undefined) {\n searchParams.set('namespace', params.namespace);\n }\n if (params.cursor !== undefined) {\n searchParams.set('cursor', params.cursor);\n }\n if (params.limit !== undefined) {\n searchParams.set('limit', String(params.limit));\n }\n\n const query = searchParams.toString();\n const path = query ? `/v1/schedules?${query}` : '/v1/schedules';\n\n return this.request('GET', path);\n }\n\n get({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('GET', schedulePath(name, namespace));\n }\n\n update({\n name,\n namespace,\n target,\n ...params\n }: UpdateScheduleParams): Promise<UpdateScheduleResponse> {\n return this.request('PATCH', schedulePath(name, namespace), {\n ...params,\n ...(target === undefined\n ? {}\n : {\n target: {\n type: 'queue',\n topic: target.topic,\n },\n }),\n });\n }\n\n async delete({ name, namespace }: ScheduleIdentifier): Promise<void> {\n await this.request('DELETE', schedulePath(name, namespace));\n }\n\n enable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/enable'));\n }\n\n disable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/disable'));\n }\n\n async invoke({ name, namespace }: InvokeScheduleParams): Promise<void> {\n await this.request('POST', schedulePath(name, namespace, '/invoke'));\n }\n}\n","import { SchedulesClient } from './schedules';\n\nexport const schedules = new SchedulesClient();\n","/** CloudEvent type used for schedule function dispatches. */\nexport const SCHEDULE_CLOUD_EVENT_TYPE = 'com.vercel.schedule.v1beta';\nexport const CLOUD_EVENT_SPEC_VERSION_HEADER = 'ce-specversion';\nexport const CLOUD_EVENT_TYPE_HEADER = 'ce-type';\nexport const CLOUD_EVENT_SOURCE_HEADER = 'ce-source';\nexport const CLOUD_EVENT_ID_HEADER = 'ce-id';\nexport const SCHEDULE_SCHEDULED_AT_HEADER = 'ce-vssscheduledat';\nexport const SCHEDULE_ID_HEADER = 'ce-vssscheduleid';\nexport const SCHEDULE_NAME_HEADER = 'ce-vssschedulename';\nexport const SCHEDULE_NAMESPACE_HEADER = 'ce-vssnamespace';\nexport const SCHEDULE_SOURCE_HEADER = 'ce-vssschedulesource';\n\nexport interface ScheduleMetadata {\n /** Unique identifier of the schedule. */\n scheduleId: string;\n /** Unique identifier for this schedule occurrence. */\n executionId: string;\n /** Schedule name, unique within its project and namespace. */\n name: string;\n /** Namespace the schedule belongs to. */\n namespace: string;\n /**\n * Nominal scheduled time for this occurrence, based on the schedule expression.\n * Does not account for jitter. The dispatch may arrive later within the jitter window.\n */\n scheduledAt: Date;\n /** How the schedule was defined, such as `static`. */\n source: string;\n}\n\nexport type ScheduleHandler = (\n metadata: ScheduleMetadata,\n) => void | Promise<void>;\n\nexport class ScheduleEventParseError extends Error {\n cause?: unknown;\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = 'ScheduleEventParseError';\n if (options && 'cause' in options) {\n this.cause = options.cause;\n }\n }\n}\n\nfunction requiredHeader(request: Request, name: string): string {\n const value = request.headers.get(name);\n if (!value) {\n throw new ScheduleEventParseError(\n `Request is missing the ${name} header; it does not look like a schedule dispatch`,\n );\n }\n return value;\n}\n\n/** Parses schedule metadata from a binary-mode schedule CloudEvent. */\nexport async function parseScheduleEvent(\n request: Request,\n): Promise<ScheduleMetadata> {\n if (request.method !== 'POST') {\n throw new ScheduleEventParseError(\n `Schedule dispatches are POST requests, received ${request.method}`,\n );\n }\n\n const specVersion = requiredHeader(request, CLOUD_EVENT_SPEC_VERSION_HEADER);\n if (specVersion !== '1.0') {\n throw new ScheduleEventParseError(\n `Unsupported CloudEvent spec version: ${specVersion}`,\n );\n }\n\n const eventType = requiredHeader(request, CLOUD_EVENT_TYPE_HEADER);\n if (eventType !== SCHEDULE_CLOUD_EVENT_TYPE) {\n throw new ScheduleEventParseError(\n `Unsupported schedule CloudEvent type: ${eventType}`,\n );\n }\n\n requiredHeader(request, CLOUD_EVENT_SOURCE_HEADER);\n const executionId = requiredHeader(request, CLOUD_EVENT_ID_HEADER);\n const scheduledAtValue = requiredHeader(\n request,\n SCHEDULE_SCHEDULED_AT_HEADER,\n );\n const metadata: ScheduleMetadata = {\n scheduleId: requiredHeader(request, SCHEDULE_ID_HEADER),\n executionId,\n name: requiredHeader(request, SCHEDULE_NAME_HEADER),\n namespace: requiredHeader(request, SCHEDULE_NAMESPACE_HEADER),\n scheduledAt: new Date(scheduledAtValue),\n source: requiredHeader(request, SCHEDULE_SOURCE_HEADER),\n };\n\n if (Number.isNaN(metadata.scheduledAt.getTime())) {\n throw new ScheduleEventParseError(\n `Schedule scheduledAt is not a valid timestamp: ${scheduledAtValue}`,\n );\n }\n\n return metadata;\n}\n\n/**\n * Creates a web-standard route handler for schedule dispatches.\n *\n * ```ts\n * export const POST = handleSchedule(async (metadata) => {\n * console.log(metadata.name, metadata.scheduledAt);\n * });\n * ```\n */\nexport function handleSchedule(\n handler: ScheduleHandler,\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n let metadata: ScheduleMetadata;\n try {\n metadata = await parseScheduleEvent(request);\n } catch (error) {\n if (error instanceof ScheduleEventParseError) {\n return Response.json({ error: error.message }, { status: 400 });\n }\n return Response.json(\n { error: 'Failed to parse schedule dispatch' },\n { status: 500 },\n );\n }\n\n try {\n await handler(metadata);\n return new Response(null, { status: 200 });\n } catch {\n return Response.json(\n { error: 'Schedule handler failed' },\n { status: 500 },\n );\n }\n };\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -8,9 +8,10 @@ declare class SchedulesApiError extends Error {
|
|
|
8
8
|
constructor(status: number, message: string);
|
|
9
9
|
}
|
|
10
10
|
declare class SchedulesApiClient {
|
|
11
|
-
private readonly baseUrl
|
|
11
|
+
private readonly baseUrl?;
|
|
12
12
|
private readonly token?;
|
|
13
13
|
private readonly fetchImpl;
|
|
14
|
+
private readonly configurationError?;
|
|
14
15
|
constructor(options?: SchedulesApiClientOptions);
|
|
15
16
|
protected getToken(): Promise<string>;
|
|
16
17
|
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
@@ -29,6 +30,9 @@ type ScheduleExpression = {
|
|
|
29
30
|
type ScheduleTarget = {
|
|
30
31
|
type: 'queue';
|
|
31
32
|
topic: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'function';
|
|
35
|
+
function: string;
|
|
32
36
|
};
|
|
33
37
|
type CreateScheduleTarget = {
|
|
34
38
|
topic: string;
|
|
@@ -62,7 +66,11 @@ interface CreateScheduleParams {
|
|
|
62
66
|
target: CreateScheduleTarget;
|
|
63
67
|
payload?: unknown;
|
|
64
68
|
}
|
|
65
|
-
type CreateScheduleResponse = Schedule
|
|
69
|
+
type CreateScheduleResponse = Schedule & {
|
|
70
|
+
target: Extract<ScheduleTarget, {
|
|
71
|
+
type: 'queue';
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
66
74
|
interface ScheduleIdentifier {
|
|
67
75
|
name: string;
|
|
68
76
|
namespace?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ declare class SchedulesApiError extends Error {
|
|
|
8
8
|
constructor(status: number, message: string);
|
|
9
9
|
}
|
|
10
10
|
declare class SchedulesApiClient {
|
|
11
|
-
private readonly baseUrl
|
|
11
|
+
private readonly baseUrl?;
|
|
12
12
|
private readonly token?;
|
|
13
13
|
private readonly fetchImpl;
|
|
14
|
+
private readonly configurationError?;
|
|
14
15
|
constructor(options?: SchedulesApiClientOptions);
|
|
15
16
|
protected getToken(): Promise<string>;
|
|
16
17
|
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
@@ -29,6 +30,9 @@ type ScheduleExpression = {
|
|
|
29
30
|
type ScheduleTarget = {
|
|
30
31
|
type: 'queue';
|
|
31
32
|
topic: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'function';
|
|
35
|
+
function: string;
|
|
32
36
|
};
|
|
33
37
|
type CreateScheduleTarget = {
|
|
34
38
|
topic: string;
|
|
@@ -62,7 +66,11 @@ interface CreateScheduleParams {
|
|
|
62
66
|
target: CreateScheduleTarget;
|
|
63
67
|
payload?: unknown;
|
|
64
68
|
}
|
|
65
|
-
type CreateScheduleResponse = Schedule
|
|
69
|
+
type CreateScheduleResponse = Schedule & {
|
|
70
|
+
target: Extract<ScheduleTarget, {
|
|
71
|
+
type: 'queue';
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
66
74
|
interface ScheduleIdentifier {
|
|
67
75
|
name: string;
|
|
68
76
|
namespace?: string;
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,13 @@ import { getVercelOidcToken } from "@vercel/oidc";
|
|
|
5
5
|
var DEFAULT_SCHEDULES_BASE_URL = "https://vercel-schedules.com";
|
|
6
6
|
|
|
7
7
|
// src/api-client.ts
|
|
8
|
+
function trimTrailingSlashes(path) {
|
|
9
|
+
let end = path.length;
|
|
10
|
+
while (end > 0 && path[end - 1] === "/") {
|
|
11
|
+
end--;
|
|
12
|
+
}
|
|
13
|
+
return path.slice(0, end);
|
|
14
|
+
}
|
|
8
15
|
var SchedulesApiError = class extends Error {
|
|
9
16
|
constructor(status, message) {
|
|
10
17
|
super(message);
|
|
@@ -14,14 +21,50 @@ var SchedulesApiError = class extends Error {
|
|
|
14
21
|
};
|
|
15
22
|
var SchedulesApiClient = class {
|
|
16
23
|
constructor(options = {}) {
|
|
17
|
-
var _a, _b, _c;
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
25
|
+
this.token = options.token;
|
|
26
|
+
this.fetchImpl = (_a = options.fetch) != null ? _a : fetch;
|
|
27
|
+
const envBaseUrl = process.env.VERCEL_SCHEDULE_BASE_URL;
|
|
28
|
+
const devApiVersion = process.env.VERCEL_SCHEDULE_DEV_API_VERSION;
|
|
29
|
+
let advertisedBaseUrl;
|
|
30
|
+
try {
|
|
31
|
+
advertisedBaseUrl = new URL(envBaseUrl != null ? envBaseUrl : "");
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
const explicitBaseUrl = options.baseUrl === void 0 ? void 0 : new URL(options.baseUrl);
|
|
35
|
+
const localSelected = process.env.NODE_ENV === "development" && process.env.VERCEL_DEPLOYMENT_ID === void 0 && devApiVersion !== void 0 && (explicitBaseUrl === void 0 || advertisedBaseUrl !== void 0 && explicitBaseUrl.origin === advertisedBaseUrl.origin && trimTrailingSlashes(explicitBaseUrl.pathname) === trimTrailingSlashes(advertisedBaseUrl.pathname));
|
|
36
|
+
if (localSelected) {
|
|
37
|
+
try {
|
|
38
|
+
if (devApiVersion !== "1") {
|
|
39
|
+
throw new Error(
|
|
40
|
+
'Unsupported VERCEL_SCHEDULE_DEV_API_VERSION. This SDK supports local Schedules API version "1".'
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (!advertisedBaseUrl || !["http:", "https:"].includes(advertisedBaseUrl.protocol) || advertisedBaseUrl.username || advertisedBaseUrl.password || advertisedBaseUrl.search || advertisedBaseUrl.hash) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"Local Schedules requires VERCEL_SCHEDULE_BASE_URL to be an absolute HTTP(S) URL without credentials, a query, or a fragment."
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
this.token = (_b = options.token) != null ? _b : process.env.VERCEL_SCHEDULE_TOKEN;
|
|
49
|
+
if (!((_c = this.token) == null ? void 0 : _c.trim())) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Local Schedules requires VERCEL_SCHEDULE_TOKEN or an explicit token option."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
this.configurationError = err instanceof Error ? err : new Error(String(err));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
18
59
|
this.baseUrl = new URL(
|
|
19
|
-
(
|
|
60
|
+
(_e = (_d = options.baseUrl) != null ? _d : envBaseUrl) != null ? _e : DEFAULT_SCHEDULES_BASE_URL
|
|
20
61
|
);
|
|
21
|
-
this.
|
|
22
|
-
this.fetchImpl = (_c = options.fetch) != null ? _c : fetch;
|
|
62
|
+
this.baseUrl.pathname = `${trimTrailingSlashes(this.baseUrl.pathname)}/`;
|
|
23
63
|
}
|
|
24
64
|
async getToken() {
|
|
65
|
+
if (this.configurationError) {
|
|
66
|
+
throw this.configurationError;
|
|
67
|
+
}
|
|
25
68
|
if (this.token) {
|
|
26
69
|
return this.token;
|
|
27
70
|
}
|
|
@@ -53,11 +96,14 @@ Cause: ${cause}`
|
|
|
53
96
|
if (body !== void 0) {
|
|
54
97
|
headers.set("Content-Type", "application/json");
|
|
55
98
|
}
|
|
56
|
-
const response = await this.fetchImpl(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
const response = await this.fetchImpl(
|
|
100
|
+
new URL(path.replace(/^\/+/, ""), this.baseUrl),
|
|
101
|
+
{
|
|
102
|
+
method,
|
|
103
|
+
headers,
|
|
104
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
105
|
+
}
|
|
106
|
+
);
|
|
61
107
|
if (!response.ok) {
|
|
62
108
|
const text = await response.text();
|
|
63
109
|
throw new SchedulesApiError(response.status, text || response.statusText);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api-client.ts","../src/constants.ts","../src/schedules.ts","../src/default-client.ts","../src/schedule-event.ts"],"sourcesContent":["import { getVercelOidcToken } from '@vercel/oidc';\nimport { DEFAULT_SCHEDULES_BASE_URL } from './constants';\n\nexport interface SchedulesApiClientOptions {\n baseUrl?: string;\n token?: string;\n fetch?: typeof fetch;\n}\n\nexport class SchedulesApiError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = 'SchedulesApiError';\n this.status = status;\n }\n}\n\nexport class SchedulesApiClient {\n private readonly baseUrl: URL;\n private readonly token?: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: SchedulesApiClientOptions = {}) {\n this.baseUrl = new URL(\n options.baseUrl ??\n process.env.VERCEL_SCHEDULE_BASE_URL ??\n DEFAULT_SCHEDULES_BASE_URL,\n );\n this.token = options.token;\n this.fetchImpl = options.fetch ?? fetch;\n }\n\n protected async getToken(): Promise<string> {\n if (this.token) {\n return this.token;\n }\n\n try {\n return await getVercelOidcToken();\n } catch (err) {\n const cause = err instanceof Error ? err.message : String(err);\n const isDev = process.env.NODE_ENV === 'development';\n\n throw new Error(\n isDev\n ? 'Failed to get OIDC token for local development.\\n\\n' +\n 'To fix this, pull your environment variables with Vercel CLI:\\n' +\n ' `vercel env pull`\\n\\n' +\n `Cause: ${cause}`\n : 'Failed to get OIDC token. This usually means the function is running ' +\n 'outside of a Vercel Function environment.\\n\\n' +\n 'To fix this, either:\\n' +\n ' - Deploy to Vercel (OIDC tokens are provisioned automatically)\\n' +\n ' - Provide a token explicitly: `new Schedules({ token: \"...\" })`\\n\\n' +\n `Cause: ${cause}`,\n );\n }\n }\n\n protected async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n });\n\n if (body !== undefined) {\n headers.set('Content-Type', 'application/json');\n }\n\n const response = await this.fetchImpl(new URL(path, this.baseUrl), {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n\n if (!response.ok) {\n const text = await response.text();\n throw new SchedulesApiError(response.status, text || response.statusText);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return (await response.json()) as T;\n }\n}\n","export const DEFAULT_SCHEDULES_BASE_URL = 'https://vercel-schedules.com';\n","import { SchedulesApiClient } from './api-client';\nimport type {\n CreateScheduleParams,\n CreateScheduleResponse,\n InvokeScheduleParams,\n ListSchedulesParams,\n ListSchedulesResponse,\n Schedule,\n ScheduleIdentifier,\n UpdateScheduleParams,\n UpdateScheduleResponse,\n} from './types';\n\nfunction schedulePath(name: string, namespace?: string, suffix = ''): string {\n const searchParams = new URLSearchParams();\n\n if (namespace !== undefined) {\n searchParams.set('namespace', namespace);\n }\n\n const query = searchParams.toString();\n const path = `/v1/schedules/${encodeURIComponent(name)}${suffix}`;\n\n return query ? `${path}?${query}` : path;\n}\n\nexport class SchedulesClient extends SchedulesApiClient {\n create({\n target,\n ...params\n }: CreateScheduleParams): Promise<CreateScheduleResponse> {\n return this.request('POST', '/v1/schedules', {\n ...params,\n target: {\n type: 'queue',\n topic: target.topic,\n },\n });\n }\n\n list(params: ListSchedulesParams = {}): Promise<ListSchedulesResponse> {\n const searchParams = new URLSearchParams();\n\n if (params.namespace !== undefined) {\n searchParams.set('namespace', params.namespace);\n }\n if (params.cursor !== undefined) {\n searchParams.set('cursor', params.cursor);\n }\n if (params.limit !== undefined) {\n searchParams.set('limit', String(params.limit));\n }\n\n const query = searchParams.toString();\n const path = query ? `/v1/schedules?${query}` : '/v1/schedules';\n\n return this.request('GET', path);\n }\n\n get({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('GET', schedulePath(name, namespace));\n }\n\n update({\n name,\n namespace,\n target,\n ...params\n }: UpdateScheduleParams): Promise<UpdateScheduleResponse> {\n return this.request('PATCH', schedulePath(name, namespace), {\n ...params,\n ...(target === undefined\n ? {}\n : {\n target: {\n type: 'queue',\n topic: target.topic,\n },\n }),\n });\n }\n\n async delete({ name, namespace }: ScheduleIdentifier): Promise<void> {\n await this.request('DELETE', schedulePath(name, namespace));\n }\n\n enable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/enable'));\n }\n\n disable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/disable'));\n }\n\n async invoke({ name, namespace }: InvokeScheduleParams): Promise<void> {\n await this.request('POST', schedulePath(name, namespace, '/invoke'));\n }\n}\n","import { SchedulesClient } from './schedules';\n\nexport const schedules = new SchedulesClient();\n","/** CloudEvent type used for schedule function dispatches. */\nexport const SCHEDULE_CLOUD_EVENT_TYPE = 'com.vercel.schedule.v1beta';\nexport const CLOUD_EVENT_SPEC_VERSION_HEADER = 'ce-specversion';\nexport const CLOUD_EVENT_TYPE_HEADER = 'ce-type';\nexport const CLOUD_EVENT_SOURCE_HEADER = 'ce-source';\nexport const CLOUD_EVENT_ID_HEADER = 'ce-id';\nexport const SCHEDULE_SCHEDULED_AT_HEADER = 'ce-vssscheduledat';\nexport const SCHEDULE_ID_HEADER = 'ce-vssscheduleid';\nexport const SCHEDULE_NAME_HEADER = 'ce-vssschedulename';\nexport const SCHEDULE_NAMESPACE_HEADER = 'ce-vssnamespace';\nexport const SCHEDULE_SOURCE_HEADER = 'ce-vssschedulesource';\n\nexport interface ScheduleMetadata {\n /** Unique identifier of the schedule. */\n scheduleId: string;\n /** Unique identifier for this schedule occurrence. */\n executionId: string;\n /** Schedule name, unique within its project and namespace. */\n name: string;\n /** Namespace the schedule belongs to. */\n namespace: string;\n /**\n * Nominal scheduled time for this occurrence, based on the schedule expression.\n * Does not account for jitter. The dispatch may arrive later within the jitter window.\n */\n scheduledAt: Date;\n /** How the schedule was defined, such as `static`. */\n source: string;\n}\n\nexport type ScheduleHandler = (\n metadata: ScheduleMetadata,\n) => void | Promise<void>;\n\nexport class ScheduleEventParseError extends Error {\n cause?: unknown;\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = 'ScheduleEventParseError';\n if (options && 'cause' in options) {\n this.cause = options.cause;\n }\n }\n}\n\nfunction requiredHeader(request: Request, name: string): string {\n const value = request.headers.get(name);\n if (!value) {\n throw new ScheduleEventParseError(\n `Request is missing the ${name} header; it does not look like a schedule dispatch`,\n );\n }\n return value;\n}\n\n/** Parses schedule metadata from a binary-mode schedule CloudEvent. */\nexport async function parseScheduleEvent(\n request: Request,\n): Promise<ScheduleMetadata> {\n if (request.method !== 'POST') {\n throw new ScheduleEventParseError(\n `Schedule dispatches are POST requests, received ${request.method}`,\n );\n }\n\n const specVersion = requiredHeader(request, CLOUD_EVENT_SPEC_VERSION_HEADER);\n if (specVersion !== '1.0') {\n throw new ScheduleEventParseError(\n `Unsupported CloudEvent spec version: ${specVersion}`,\n );\n }\n\n const eventType = requiredHeader(request, CLOUD_EVENT_TYPE_HEADER);\n if (eventType !== SCHEDULE_CLOUD_EVENT_TYPE) {\n throw new ScheduleEventParseError(\n `Unsupported schedule CloudEvent type: ${eventType}`,\n );\n }\n\n requiredHeader(request, CLOUD_EVENT_SOURCE_HEADER);\n const executionId = requiredHeader(request, CLOUD_EVENT_ID_HEADER);\n const scheduledAtValue = requiredHeader(\n request,\n SCHEDULE_SCHEDULED_AT_HEADER,\n );\n const metadata: ScheduleMetadata = {\n scheduleId: requiredHeader(request, SCHEDULE_ID_HEADER),\n executionId,\n name: requiredHeader(request, SCHEDULE_NAME_HEADER),\n namespace: requiredHeader(request, SCHEDULE_NAMESPACE_HEADER),\n scheduledAt: new Date(scheduledAtValue),\n source: requiredHeader(request, SCHEDULE_SOURCE_HEADER),\n };\n\n if (Number.isNaN(metadata.scheduledAt.getTime())) {\n throw new ScheduleEventParseError(\n `Schedule scheduledAt is not a valid timestamp: ${scheduledAtValue}`,\n );\n }\n\n return metadata;\n}\n\n/**\n * Creates a web-standard route handler for schedule dispatches.\n *\n * ```ts\n * export const POST = handleSchedule(async (metadata) => {\n * console.log(metadata.name, metadata.scheduledAt);\n * });\n * ```\n */\nexport function handleSchedule(\n handler: ScheduleHandler,\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n let metadata: ScheduleMetadata;\n try {\n metadata = await parseScheduleEvent(request);\n } catch (error) {\n if (error instanceof ScheduleEventParseError) {\n return Response.json({ error: error.message }, { status: 400 });\n }\n return Response.json(\n { error: 'Failed to parse schedule dispatch' },\n { status: 500 },\n );\n }\n\n try {\n await handler(metadata);\n return new Response(null, { status: 200 });\n } catch {\n return Response.json(\n { error: 'Schedule handler failed' },\n { status: 500 },\n );\n }\n };\n}\n"],"mappings":";AAAA,SAAS,0BAA0B;;;ACA5B,IAAM,6BAA6B;;;ADSnC,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAG3C,YAAY,QAAgB,SAAiB;AAC3C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAEO,IAAM,qBAAN,MAAyB;AAAA,EAK9B,YAAY,UAAqC,CAAC,GAAG;AAxBvD;AAyBI,SAAK,UAAU,IAAI;AAAA,OACjB,mBAAQ,YAAR,YACE,QAAQ,IAAI,6BADd,YAEE;AAAA,IACJ;AACA,SAAK,QAAQ,QAAQ;AACrB,SAAK,aAAY,aAAQ,UAAR,YAAiB;AAAA,EACpC;AAAA,EAEA,MAAgB,WAA4B;AAC1C,QAAI,KAAK,OAAO;AACd,aAAO,KAAK;AAAA,IACd;AAEA,QAAI;AACF,aAAO,MAAM,mBAAmB;AAAA,IAClC,SAAS,KAAK;AACZ,YAAM,QAAQ,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC7D,YAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,YAAM,IAAI;AAAA,QACR,QACI;AAAA;AAAA;AAAA;AAAA;AAAA,SAGY,KAAK,KACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAKY,KAAK;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAgB,QACd,QACA,MACA,MACY;AACZ,UAAM,UAAU,IAAI,QAAQ;AAAA,MAC1B,eAAe,UAAU,MA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e,SAAS,yBAAyB;AAAA,IAC5D,aAAa,IAAI,KAAK,gBAAgB;AAAA,IACtC,QAAQ,eAAe,SAAS,sBAAsB;AAAA,EACxD;AAEA,MAAI,OAAO,MAAM,SAAS,YAAY,QAAQ,CAAC,GAAG;AAChD,UAAM,IAAI;AAAA,MACR,kDAAkD,gBAAgB;AAAA,IACpE;AAAA,EACF;AAEA,SAAO;AACT;AAWO,SAAS,eACd,SACyC;AACzC,SAAO,OAAO,YAAwC;AACpD,QAAI;AACJ,QAAI;AACF,iBAAW,MAAM,mBAAmB,OAAO;AAAA,IAC7C,SAAS,OAAO;AACd,UAAI,iBAAiB,yBAAyB;AAC5C,eAAO,SAAS,KAAK,EAAE,OAAO,MAAM,QAAQ,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,MAChE;AACA,aAAO,SAAS;AAAA,QACd,EAAE,OAAO,oCAAoC;AAAA,QAC7C,EAAE,QAAQ,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,QAAI;AACF,YAAM,QAAQ,QAAQ;AACtB,aAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC3C,QAAQ;AACN,aAAO,SAAS;AAAA,QACd,EAAE,OAAO,0BAA0B;AAAA,QACnC,EAAE,QAAQ,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/api-client.ts","../src/constants.ts","../src/schedules.ts","../src/default-client.ts","../src/schedule-event.ts"],"sourcesContent":["import { getVercelOidcToken } from '@vercel/oidc';\nimport { DEFAULT_SCHEDULES_BASE_URL } from './constants';\n\nexport interface SchedulesApiClientOptions {\n baseUrl?: string;\n token?: string;\n fetch?: typeof fetch;\n}\n\nfunction trimTrailingSlashes(path: string): string {\n let end = path.length;\n while (end > 0 && path[end - 1] === '/') {\n end--;\n }\n return path.slice(0, end);\n}\n\nexport class SchedulesApiError extends Error {\n readonly status: number;\n\n constructor(status: number, message: string) {\n super(message);\n this.name = 'SchedulesApiError';\n this.status = status;\n }\n}\n\nexport class SchedulesApiClient {\n private readonly baseUrl?: URL;\n private readonly token?: string;\n private readonly fetchImpl: typeof fetch;\n private readonly configurationError?: Error;\n\n constructor(options: SchedulesApiClientOptions = {}) {\n this.token = options.token;\n this.fetchImpl = options.fetch ?? fetch;\n\n const envBaseUrl = process.env.VERCEL_SCHEDULE_BASE_URL;\n const devApiVersion = process.env.VERCEL_SCHEDULE_DEV_API_VERSION;\n let advertisedBaseUrl: URL | undefined;\n try {\n advertisedBaseUrl = new URL(envBaseUrl ?? '');\n } catch {\n // An independent explicit endpoint does not need the injected URL.\n }\n\n const explicitBaseUrl =\n options.baseUrl === undefined ? undefined : new URL(options.baseUrl);\n const localSelected =\n process.env.NODE_ENV === 'development' &&\n process.env.VERCEL_DEPLOYMENT_ID === undefined &&\n devApiVersion !== undefined &&\n (explicitBaseUrl === undefined ||\n (advertisedBaseUrl !== undefined &&\n explicitBaseUrl.origin === advertisedBaseUrl.origin &&\n trimTrailingSlashes(explicitBaseUrl.pathname) ===\n trimTrailingSlashes(advertisedBaseUrl.pathname)));\n\n if (localSelected) {\n try {\n if (devApiVersion !== '1') {\n throw new Error(\n 'Unsupported VERCEL_SCHEDULE_DEV_API_VERSION. This SDK supports local Schedules API version \"1\".',\n );\n }\n if (\n !advertisedBaseUrl ||\n !['http:', 'https:'].includes(advertisedBaseUrl.protocol) ||\n advertisedBaseUrl.username ||\n advertisedBaseUrl.password ||\n advertisedBaseUrl.search ||\n advertisedBaseUrl.hash\n ) {\n throw new Error(\n 'Local Schedules requires VERCEL_SCHEDULE_BASE_URL to be an absolute HTTP(S) URL without credentials, a query, or a fragment.',\n );\n }\n this.token = options.token ?? process.env.VERCEL_SCHEDULE_TOKEN;\n if (!this.token?.trim()) {\n throw new Error(\n 'Local Schedules requires VERCEL_SCHEDULE_TOKEN or an explicit token option.',\n );\n }\n } catch (err) {\n // Defer only selected-local configuration errors so the default\n // singleton does not prevent importing independent clients.\n this.configurationError =\n err instanceof Error ? err : new Error(String(err));\n return;\n }\n }\n\n this.baseUrl = new URL(\n options.baseUrl ?? envBaseUrl ?? DEFAULT_SCHEDULES_BASE_URL,\n );\n this.baseUrl.pathname = `${trimTrailingSlashes(this.baseUrl.pathname)}/`;\n }\n\n protected async getToken(): Promise<string> {\n if (this.configurationError) {\n throw this.configurationError;\n }\n if (this.token) {\n return this.token;\n }\n\n try {\n return await getVercelOidcToken();\n } catch (err) {\n const cause = err instanceof Error ? err.message : String(err);\n const isDev = process.env.NODE_ENV === 'development';\n\n throw new Error(\n isDev\n ? 'Failed to get OIDC token for local development.\\n\\n' +\n 'To fix this, pull your environment variables with Vercel CLI:\\n' +\n ' `vercel env pull`\\n\\n' +\n `Cause: ${cause}`\n : 'Failed to get OIDC token. This usually means the function is running ' +\n 'outside of a Vercel Function environment.\\n\\n' +\n 'To fix this, either:\\n' +\n ' - Deploy to Vercel (OIDC tokens are provisioned automatically)\\n' +\n ' - Provide a token explicitly: `new Schedules({ token: \"...\" })`\\n\\n' +\n `Cause: ${cause}`,\n );\n }\n }\n\n protected async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n });\n\n if (body !== undefined) {\n headers.set('Content-Type', 'application/json');\n }\n\n const response = await this.fetchImpl(\n new URL(path.replace(/^\\/+/, ''), this.baseUrl),\n {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n },\n );\n\n if (!response.ok) {\n const text = await response.text();\n throw new SchedulesApiError(response.status, text || response.statusText);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return (await response.json()) as T;\n }\n}\n","export const DEFAULT_SCHEDULES_BASE_URL = 'https://vercel-schedules.com';\n","import { SchedulesApiClient } from './api-client';\nimport type {\n CreateScheduleParams,\n CreateScheduleResponse,\n InvokeScheduleParams,\n ListSchedulesParams,\n ListSchedulesResponse,\n Schedule,\n ScheduleIdentifier,\n UpdateScheduleParams,\n UpdateScheduleResponse,\n} from './types';\n\nfunction schedulePath(name: string, namespace?: string, suffix = ''): string {\n const searchParams = new URLSearchParams();\n\n if (namespace !== undefined) {\n searchParams.set('namespace', namespace);\n }\n\n const query = searchParams.toString();\n const path = `/v1/schedules/${encodeURIComponent(name)}${suffix}`;\n\n return query ? `${path}?${query}` : path;\n}\n\nexport class SchedulesClient extends SchedulesApiClient {\n create({\n target,\n ...params\n }: CreateScheduleParams): Promise<CreateScheduleResponse> {\n return this.request('POST', '/v1/schedules', {\n ...params,\n target: {\n type: 'queue',\n topic: target.topic,\n },\n });\n }\n\n list(params: ListSchedulesParams = {}): Promise<ListSchedulesResponse> {\n const searchParams = new URLSearchParams();\n\n if (params.namespace !== undefined) {\n searchParams.set('namespace', params.namespace);\n }\n if (params.cursor !== undefined) {\n searchParams.set('cursor', params.cursor);\n }\n if (params.limit !== undefined) {\n searchParams.set('limit', String(params.limit));\n }\n\n const query = searchParams.toString();\n const path = query ? `/v1/schedules?${query}` : '/v1/schedules';\n\n return this.request('GET', path);\n }\n\n get({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('GET', schedulePath(name, namespace));\n }\n\n update({\n name,\n namespace,\n target,\n ...params\n }: UpdateScheduleParams): Promise<UpdateScheduleResponse> {\n return this.request('PATCH', schedulePath(name, namespace), {\n ...params,\n ...(target === undefined\n ? {}\n : {\n target: {\n type: 'queue',\n topic: target.topic,\n },\n }),\n });\n }\n\n async delete({ name, namespace }: ScheduleIdentifier): Promise<void> {\n await this.request('DELETE', schedulePath(name, namespace));\n }\n\n enable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/enable'));\n }\n\n disable({ name, namespace }: ScheduleIdentifier): Promise<Schedule> {\n return this.request('POST', schedulePath(name, namespace, '/disable'));\n }\n\n async invoke({ name, namespace }: InvokeScheduleParams): Promise<void> {\n await this.request('POST', schedulePath(name, namespace, '/invoke'));\n }\n}\n","import { SchedulesClient } from './schedules';\n\nexport const schedules = new SchedulesClient();\n","/** CloudEvent type used for schedule function dispatches. */\nexport const SCHEDULE_CLOUD_EVENT_TYPE = 'com.vercel.schedule.v1beta';\nexport const CLOUD_EVENT_SPEC_VERSION_HEADER = 'ce-specversion';\nexport const CLOUD_EVENT_TYPE_HEADER = 'ce-type';\nexport const CLOUD_EVENT_SOURCE_HEADER = 'ce-source';\nexport const CLOUD_EVENT_ID_HEADER = 'ce-id';\nexport const SCHEDULE_SCHEDULED_AT_HEADER = 'ce-vssscheduledat';\nexport const SCHEDULE_ID_HEADER = 'ce-vssscheduleid';\nexport const SCHEDULE_NAME_HEADER = 'ce-vssschedulename';\nexport const SCHEDULE_NAMESPACE_HEADER = 'ce-vssnamespace';\nexport const SCHEDULE_SOURCE_HEADER = 'ce-vssschedulesource';\n\nexport interface ScheduleMetadata {\n /** Unique identifier of the schedule. */\n scheduleId: string;\n /** Unique identifier for this schedule occurrence. */\n executionId: string;\n /** Schedule name, unique within its project and namespace. */\n name: string;\n /** Namespace the schedule belongs to. */\n namespace: string;\n /**\n * Nominal scheduled time for this occurrence, based on the schedule expression.\n * Does not account for jitter. The dispatch may arrive later within the jitter window.\n */\n scheduledAt: Date;\n /** How the schedule was defined, such as `static`. */\n source: string;\n}\n\nexport type ScheduleHandler = (\n metadata: ScheduleMetadata,\n) => void | Promise<void>;\n\nexport class ScheduleEventParseError extends Error {\n cause?: unknown;\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = 'ScheduleEventParseError';\n if (options && 'cause' in options) {\n this.cause = options.cause;\n }\n }\n}\n\nfunction requiredHeader(request: Request, name: string): string {\n const value = request.headers.get(name);\n if (!value) {\n throw new ScheduleEventParseError(\n `Request is missing the ${name} header; it does not look like a schedule dispatch`,\n );\n }\n return value;\n}\n\n/** Parses schedule metadata from a binary-mode schedule CloudEvent. */\nexport async function parseScheduleEvent(\n request: Request,\n): Promise<ScheduleMetadata> {\n if (request.method !== 'POST') {\n throw new ScheduleEventParseError(\n `Schedule dispatches are POST requests, received ${request.method}`,\n );\n }\n\n const specVersion = requiredHeader(request, CLOUD_EVENT_SPEC_VERSION_HEADER);\n if (specVersion !== '1.0') {\n throw new ScheduleEventParseError(\n `Unsupported CloudEvent spec version: ${specVersion}`,\n );\n }\n\n const eventType = requiredHeader(request, CLOUD_EVENT_TYPE_HEADER);\n if (eventType !== SCHEDULE_CLOUD_EVENT_TYPE) {\n throw new ScheduleEventParseError(\n `Unsupported schedule CloudEvent type: ${eventType}`,\n );\n }\n\n requiredHeader(request, CLOUD_EVENT_SOURCE_HEADER);\n const executionId = requiredHeader(request, CLOUD_EVENT_ID_HEADER);\n const scheduledAtValue = requiredHeader(\n request,\n SCHEDULE_SCHEDULED_AT_HEADER,\n );\n const metadata: ScheduleMetadata = {\n scheduleId: requiredHeader(request, SCHEDULE_ID_HEADER),\n executionId,\n name: requiredHeader(request, SCHEDULE_NAME_HEADER),\n namespace: requiredHeader(request, SCHEDULE_NAMESPACE_HEADER),\n scheduledAt: new Date(scheduledAtValue),\n source: requiredHeader(request, SCHEDULE_SOURCE_HEADER),\n };\n\n if (Number.isNaN(metadata.scheduledAt.getTime())) {\n throw new ScheduleEventParseError(\n `Schedule scheduledAt is not a valid timestamp: ${scheduledAtValue}`,\n );\n }\n\n return metadata;\n}\n\n/**\n * Creates a web-standard route handler for schedule dispatches.\n *\n * ```ts\n * export const POST = handleSchedule(async (metadata) => {\n * console.log(metadata.name, metadata.scheduledAt);\n * });\n * ```\n */\nexport function handleSchedule(\n handler: ScheduleHandler,\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n let metadata: ScheduleMetadata;\n try {\n metadata = await parseScheduleEvent(request);\n } catch (error) {\n if (error instanceof ScheduleEventParseError) {\n return Response.json({ error: error.message }, { status: 400 });\n }\n return Response.json(\n { error: 'Failed to parse schedule dispatch' },\n { status: 500 },\n );\n }\n\n try {\n await handler(metadata);\n return new Response(null, { status: 200 });\n } catch {\n return Response.json(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