@vercel/schedules 0.0.0-alpha.0 → 0.0.0-alpha.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.
- package/README.md +17 -2
- package/dist/index.cjs +120 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -2
- package/dist/index.d.ts +87 -2
- package/dist/index.js +120 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -5,7 +5,22 @@ npm install @vercel/schedules
|
|
|
5
5
|
```
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
import {
|
|
8
|
+
import { Schedules } from '@vercel/schedules';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
await Schedules.create({
|
|
11
|
+
target: { topic: 'scheduled-cleanup' },
|
|
12
|
+
expression: { type: 'cron', cron: '0 * * * *' },
|
|
13
|
+
});
|
|
11
14
|
```
|
|
15
|
+
|
|
16
|
+
For a custom client:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { SchedulesClient } from '@vercel/schedules';
|
|
20
|
+
|
|
21
|
+
const schedules = new SchedulesClient({ baseUrl: 'https://vss-server.vercel.sh' });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The default client uses `https://vss-server.vercel.sh`, overridable via `VERCEL_SCHEDULE_BASE_URL`.
|
|
25
|
+
|
|
26
|
+
Requests are authenticated with the Vercel OIDC token from `@vercel/oidc`, or an explicit `token` option.
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,123 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/
|
|
2
|
-
|
|
3
|
-
console.log("hello world");
|
|
4
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/api-client.ts
|
|
2
|
+
var _oidc = require('@vercel/oidc');
|
|
5
3
|
|
|
4
|
+
// src/constants.ts
|
|
5
|
+
var DEFAULT_SCHEDULES_BASE_URL = "https://vss-server.vercel.sh";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/api-client.ts
|
|
8
|
+
var SchedulesApiError = class extends Error {
|
|
9
|
+
constructor(status, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "SchedulesApiError";
|
|
12
|
+
this.status = status;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var SchedulesApiClient = class {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
this.baseUrl = new URL(
|
|
19
|
+
(_b = (_a = options.baseUrl) != null ? _a : process.env.VERCEL_SCHEDULE_BASE_URL) != null ? _b : DEFAULT_SCHEDULES_BASE_URL
|
|
20
|
+
);
|
|
21
|
+
this.token = options.token;
|
|
22
|
+
this.fetchImpl = (_c = options.fetch) != null ? _c : fetch;
|
|
23
|
+
}
|
|
24
|
+
async getToken() {
|
|
25
|
+
if (this.token) {
|
|
26
|
+
return this.token;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return await _oidc.getVercelOidcToken.call(void 0, );
|
|
30
|
+
} catch (err) {
|
|
31
|
+
const cause = err instanceof Error ? err.message : String(err);
|
|
32
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
33
|
+
throw new Error(
|
|
34
|
+
isDev ? `Failed to get OIDC token for local development.
|
|
35
|
+
|
|
36
|
+
To fix this, pull your environment variables with Vercel CLI:
|
|
37
|
+
\`vercel env pull\`
|
|
38
|
+
|
|
39
|
+
Cause: ${cause}` : `Failed to get OIDC token. This usually means the function is running outside of a Vercel Function environment.
|
|
40
|
+
|
|
41
|
+
To fix this, either:
|
|
42
|
+
- Deploy to Vercel (OIDC tokens are provisioned automatically)
|
|
43
|
+
- Provide a token explicitly: \`new Schedules({ token: "..." })\`
|
|
44
|
+
|
|
45
|
+
Cause: ${cause}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async request(method, path, body) {
|
|
50
|
+
const headers = new Headers({
|
|
51
|
+
Authorization: `Bearer ${await this.getToken()}`
|
|
52
|
+
});
|
|
53
|
+
if (body !== void 0) {
|
|
54
|
+
headers.set("Content-Type", "application/json");
|
|
55
|
+
}
|
|
56
|
+
const response = await this.fetchImpl(new URL(path, this.baseUrl), {
|
|
57
|
+
method,
|
|
58
|
+
headers,
|
|
59
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const text = await response.text();
|
|
63
|
+
throw new SchedulesApiError(response.status, text || response.statusText);
|
|
64
|
+
}
|
|
65
|
+
if (response.status === 204) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
return await response.json();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/schedules.ts
|
|
73
|
+
var SchedulesClient = class extends SchedulesApiClient {
|
|
74
|
+
create({
|
|
75
|
+
target,
|
|
76
|
+
...params
|
|
77
|
+
}) {
|
|
78
|
+
return this.request("POST", "/v1/schedules", {
|
|
79
|
+
...params,
|
|
80
|
+
target: {
|
|
81
|
+
type: "queue",
|
|
82
|
+
topic: target.topic
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
list(params = {}) {
|
|
87
|
+
const searchParams = new URLSearchParams();
|
|
88
|
+
if (params.namespace !== void 0) {
|
|
89
|
+
searchParams.set("namespace", params.namespace);
|
|
90
|
+
}
|
|
91
|
+
if (params.cursor !== void 0) {
|
|
92
|
+
searchParams.set("cursor", params.cursor);
|
|
93
|
+
}
|
|
94
|
+
if (params.limit !== void 0) {
|
|
95
|
+
searchParams.set("limit", String(params.limit));
|
|
96
|
+
}
|
|
97
|
+
const query = searchParams.toString();
|
|
98
|
+
const path = query ? `/v1/schedules?${query}` : "/v1/schedules";
|
|
99
|
+
return this.request("GET", path);
|
|
100
|
+
}
|
|
101
|
+
get(scheduleId) {
|
|
102
|
+
return this.request(
|
|
103
|
+
"GET",
|
|
104
|
+
`/v1/schedules/${encodeURIComponent(scheduleId)}`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
delete(scheduleId) {
|
|
108
|
+
return this.request(
|
|
109
|
+
"DELETE",
|
|
110
|
+
`/v1/schedules/${encodeURIComponent(scheduleId)}`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/default-client.ts
|
|
116
|
+
var schedules = new SchedulesClient();
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
exports.DEFAULT_SCHEDULES_BASE_URL = DEFAULT_SCHEDULES_BASE_URL; exports.Schedules = schedules; exports.SchedulesApiError = SchedulesApiError; exports.SchedulesClient = SchedulesClient;
|
|
8
123
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/schedules/schedules/packages/schedules/dist/index.cjs","../src/
|
|
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"],"names":[],"mappings":"AAAA;ACAA,oCAAmC;ADEnC;AACA;AEHO,IAAM,2BAAA,EAA6B,8BAAA;AFK1C;AACA;ACGO,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,EAK9B,WAAA,CAAY,QAAA,EAAqC,CAAC,CAAA,EAAG;AAxBvD,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAyBI,IAA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A;AAEQ,IAAA;AACV,EAAA;AACF;ADrBe;AACA;AG7DF;AACJ,EAAA;AACL,IAAA;AACG,IAAA;AACqD,EAAA;AACjD,IAAA;AACF,MAAA;AACK,MAAA;AACA,QAAA;AACC,QAAA;AACT,MAAA;AACD,IAAA;AACH,EAAA;AAEK,EAAA;AACG,IAAA;AAEK,IAAA;AACT,MAAA;AACF,IAAA;AACW,IAAA;AACT,MAAA;AACF,IAAA;AACW,IAAA;AACT,MAAA;AACF,IAAA;AAEM,IAAA;AACA,IAAA;AAEC,IAAA;AACT,EAAA;AAEI,EAAA;AACK,IAAA;AACL,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAEO,EAAA;AACE,IAAA;AACL,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AACF;AHyDe;AACA;AIhHF;AJkHE;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://vss-server.vercel.sh';\n","import { SchedulesApiClient } from './api-client';\nimport type {\n CreateScheduleParams,\n CreateScheduleResponse,\n DeleteScheduleResponse,\n ListSchedulesParams,\n ListSchedulesResponse,\n Schedule,\n} from './types';\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(scheduleId: string): Promise<Schedule> {\n return this.request(\n 'GET',\n `/v1/schedules/${encodeURIComponent(scheduleId)}`,\n );\n }\n\n delete(scheduleId: string): Promise<DeleteScheduleResponse> {\n return this.request(\n 'DELETE',\n `/v1/schedules/${encodeURIComponent(scheduleId)}`,\n );\n }\n}\n","import { SchedulesClient } from './schedules';\n\nexport const schedules = new SchedulesClient();\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
interface SchedulesApiClientOptions {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
token?: string;
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
}
|
|
6
|
+
declare class SchedulesApiError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
constructor(status: number, message: string);
|
|
9
|
+
}
|
|
10
|
+
declare class SchedulesApiClient {
|
|
11
|
+
private readonly baseUrl;
|
|
12
|
+
private readonly token?;
|
|
13
|
+
private readonly fetchImpl;
|
|
14
|
+
constructor(options?: SchedulesApiClientOptions);
|
|
15
|
+
protected getToken(): Promise<string>;
|
|
16
|
+
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
17
|
+
}
|
|
2
18
|
|
|
3
|
-
|
|
19
|
+
declare const DEFAULT_SCHEDULES_BASE_URL = "https://vss-server.vercel.sh";
|
|
20
|
+
|
|
21
|
+
type ScheduleExpression = {
|
|
22
|
+
type: 'cron';
|
|
23
|
+
cron: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'single';
|
|
26
|
+
at: string;
|
|
27
|
+
};
|
|
28
|
+
type ScheduleTarget = {
|
|
29
|
+
type: 'queue';
|
|
30
|
+
topic: string;
|
|
31
|
+
};
|
|
32
|
+
type CreateScheduleTarget = {
|
|
33
|
+
topic: string;
|
|
34
|
+
};
|
|
35
|
+
type ScheduleState = 'active' | 'inactive';
|
|
36
|
+
type ScheduleSource = 'static' | 'dynamic';
|
|
37
|
+
interface Schedule {
|
|
38
|
+
scheduleId: string;
|
|
39
|
+
ownerId: string;
|
|
40
|
+
projectId: string;
|
|
41
|
+
trackId: string;
|
|
42
|
+
name: string;
|
|
43
|
+
namespace: string;
|
|
44
|
+
expression: ScheduleExpression;
|
|
45
|
+
jitter?: number;
|
|
46
|
+
target: ScheduleTarget;
|
|
47
|
+
state: ScheduleState;
|
|
48
|
+
stateOverride?: {
|
|
49
|
+
state: ScheduleState;
|
|
50
|
+
until: number;
|
|
51
|
+
};
|
|
52
|
+
source: ScheduleSource;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
updatedAt: number;
|
|
55
|
+
}
|
|
56
|
+
interface CreateScheduleParams {
|
|
57
|
+
name?: string;
|
|
58
|
+
namespace?: string;
|
|
59
|
+
expression: ScheduleExpression;
|
|
60
|
+
jitter?: number;
|
|
61
|
+
target: CreateScheduleTarget;
|
|
62
|
+
}
|
|
63
|
+
interface CreateScheduleResponse {
|
|
64
|
+
scheduleId: string;
|
|
65
|
+
}
|
|
66
|
+
interface DeleteScheduleResponse {
|
|
67
|
+
scheduleId: string;
|
|
68
|
+
}
|
|
69
|
+
interface ListSchedulesParams {
|
|
70
|
+
namespace?: string;
|
|
71
|
+
cursor?: string;
|
|
72
|
+
limit?: number;
|
|
73
|
+
}
|
|
74
|
+
interface ListSchedulesResponse {
|
|
75
|
+
data: Schedule[];
|
|
76
|
+
cursor: string | null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare class SchedulesClient extends SchedulesApiClient {
|
|
80
|
+
create({ target, ...params }: CreateScheduleParams): Promise<CreateScheduleResponse>;
|
|
81
|
+
list(params?: ListSchedulesParams): Promise<ListSchedulesResponse>;
|
|
82
|
+
get(scheduleId: string): Promise<Schedule>;
|
|
83
|
+
delete(scheduleId: string): Promise<DeleteScheduleResponse>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare const schedules: SchedulesClient;
|
|
87
|
+
|
|
88
|
+
export { type CreateScheduleParams, type CreateScheduleResponse, type CreateScheduleTarget, DEFAULT_SCHEDULES_BASE_URL, type DeleteScheduleResponse, type ListSchedulesParams, type ListSchedulesResponse, type Schedule, type ScheduleExpression, type ScheduleSource, type ScheduleState, type ScheduleTarget, schedules as Schedules, type SchedulesApiClientOptions, SchedulesApiError, SchedulesClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
interface SchedulesApiClientOptions {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
token?: string;
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
}
|
|
6
|
+
declare class SchedulesApiError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
constructor(status: number, message: string);
|
|
9
|
+
}
|
|
10
|
+
declare class SchedulesApiClient {
|
|
11
|
+
private readonly baseUrl;
|
|
12
|
+
private readonly token?;
|
|
13
|
+
private readonly fetchImpl;
|
|
14
|
+
constructor(options?: SchedulesApiClientOptions);
|
|
15
|
+
protected getToken(): Promise<string>;
|
|
16
|
+
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
17
|
+
}
|
|
2
18
|
|
|
3
|
-
|
|
19
|
+
declare const DEFAULT_SCHEDULES_BASE_URL = "https://vss-server.vercel.sh";
|
|
20
|
+
|
|
21
|
+
type ScheduleExpression = {
|
|
22
|
+
type: 'cron';
|
|
23
|
+
cron: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'single';
|
|
26
|
+
at: string;
|
|
27
|
+
};
|
|
28
|
+
type ScheduleTarget = {
|
|
29
|
+
type: 'queue';
|
|
30
|
+
topic: string;
|
|
31
|
+
};
|
|
32
|
+
type CreateScheduleTarget = {
|
|
33
|
+
topic: string;
|
|
34
|
+
};
|
|
35
|
+
type ScheduleState = 'active' | 'inactive';
|
|
36
|
+
type ScheduleSource = 'static' | 'dynamic';
|
|
37
|
+
interface Schedule {
|
|
38
|
+
scheduleId: string;
|
|
39
|
+
ownerId: string;
|
|
40
|
+
projectId: string;
|
|
41
|
+
trackId: string;
|
|
42
|
+
name: string;
|
|
43
|
+
namespace: string;
|
|
44
|
+
expression: ScheduleExpression;
|
|
45
|
+
jitter?: number;
|
|
46
|
+
target: ScheduleTarget;
|
|
47
|
+
state: ScheduleState;
|
|
48
|
+
stateOverride?: {
|
|
49
|
+
state: ScheduleState;
|
|
50
|
+
until: number;
|
|
51
|
+
};
|
|
52
|
+
source: ScheduleSource;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
updatedAt: number;
|
|
55
|
+
}
|
|
56
|
+
interface CreateScheduleParams {
|
|
57
|
+
name?: string;
|
|
58
|
+
namespace?: string;
|
|
59
|
+
expression: ScheduleExpression;
|
|
60
|
+
jitter?: number;
|
|
61
|
+
target: CreateScheduleTarget;
|
|
62
|
+
}
|
|
63
|
+
interface CreateScheduleResponse {
|
|
64
|
+
scheduleId: string;
|
|
65
|
+
}
|
|
66
|
+
interface DeleteScheduleResponse {
|
|
67
|
+
scheduleId: string;
|
|
68
|
+
}
|
|
69
|
+
interface ListSchedulesParams {
|
|
70
|
+
namespace?: string;
|
|
71
|
+
cursor?: string;
|
|
72
|
+
limit?: number;
|
|
73
|
+
}
|
|
74
|
+
interface ListSchedulesResponse {
|
|
75
|
+
data: Schedule[];
|
|
76
|
+
cursor: string | null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare class SchedulesClient extends SchedulesApiClient {
|
|
80
|
+
create({ target, ...params }: CreateScheduleParams): Promise<CreateScheduleResponse>;
|
|
81
|
+
list(params?: ListSchedulesParams): Promise<ListSchedulesResponse>;
|
|
82
|
+
get(scheduleId: string): Promise<Schedule>;
|
|
83
|
+
delete(scheduleId: string): Promise<DeleteScheduleResponse>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare const schedules: SchedulesClient;
|
|
87
|
+
|
|
88
|
+
export { type CreateScheduleParams, type CreateScheduleResponse, type CreateScheduleTarget, DEFAULT_SCHEDULES_BASE_URL, type DeleteScheduleResponse, type ListSchedulesParams, type ListSchedulesResponse, type Schedule, type ScheduleExpression, type ScheduleSource, type ScheduleState, type ScheduleTarget, schedules as Schedules, type SchedulesApiClientOptions, SchedulesApiError, SchedulesClient };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,123 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/api-client.ts
|
|
2
|
+
import { getVercelOidcToken } from "@vercel/oidc";
|
|
3
|
+
|
|
4
|
+
// src/constants.ts
|
|
5
|
+
var DEFAULT_SCHEDULES_BASE_URL = "https://vss-server.vercel.sh";
|
|
6
|
+
|
|
7
|
+
// src/api-client.ts
|
|
8
|
+
var SchedulesApiError = class extends Error {
|
|
9
|
+
constructor(status, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "SchedulesApiError";
|
|
12
|
+
this.status = status;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var SchedulesApiClient = class {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
this.baseUrl = new URL(
|
|
19
|
+
(_b = (_a = options.baseUrl) != null ? _a : process.env.VERCEL_SCHEDULE_BASE_URL) != null ? _b : DEFAULT_SCHEDULES_BASE_URL
|
|
20
|
+
);
|
|
21
|
+
this.token = options.token;
|
|
22
|
+
this.fetchImpl = (_c = options.fetch) != null ? _c : fetch;
|
|
23
|
+
}
|
|
24
|
+
async getToken() {
|
|
25
|
+
if (this.token) {
|
|
26
|
+
return this.token;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return await getVercelOidcToken();
|
|
30
|
+
} catch (err) {
|
|
31
|
+
const cause = err instanceof Error ? err.message : String(err);
|
|
32
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
33
|
+
throw new Error(
|
|
34
|
+
isDev ? `Failed to get OIDC token for local development.
|
|
35
|
+
|
|
36
|
+
To fix this, pull your environment variables with Vercel CLI:
|
|
37
|
+
\`vercel env pull\`
|
|
38
|
+
|
|
39
|
+
Cause: ${cause}` : `Failed to get OIDC token. This usually means the function is running outside of a Vercel Function environment.
|
|
40
|
+
|
|
41
|
+
To fix this, either:
|
|
42
|
+
- Deploy to Vercel (OIDC tokens are provisioned automatically)
|
|
43
|
+
- Provide a token explicitly: \`new Schedules({ token: "..." })\`
|
|
44
|
+
|
|
45
|
+
Cause: ${cause}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async request(method, path, body) {
|
|
50
|
+
const headers = new Headers({
|
|
51
|
+
Authorization: `Bearer ${await this.getToken()}`
|
|
52
|
+
});
|
|
53
|
+
if (body !== void 0) {
|
|
54
|
+
headers.set("Content-Type", "application/json");
|
|
55
|
+
}
|
|
56
|
+
const response = await this.fetchImpl(new URL(path, this.baseUrl), {
|
|
57
|
+
method,
|
|
58
|
+
headers,
|
|
59
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const text = await response.text();
|
|
63
|
+
throw new SchedulesApiError(response.status, text || response.statusText);
|
|
64
|
+
}
|
|
65
|
+
if (response.status === 204) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
return await response.json();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/schedules.ts
|
|
73
|
+
var SchedulesClient = class extends SchedulesApiClient {
|
|
74
|
+
create({
|
|
75
|
+
target,
|
|
76
|
+
...params
|
|
77
|
+
}) {
|
|
78
|
+
return this.request("POST", "/v1/schedules", {
|
|
79
|
+
...params,
|
|
80
|
+
target: {
|
|
81
|
+
type: "queue",
|
|
82
|
+
topic: target.topic
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
list(params = {}) {
|
|
87
|
+
const searchParams = new URLSearchParams();
|
|
88
|
+
if (params.namespace !== void 0) {
|
|
89
|
+
searchParams.set("namespace", params.namespace);
|
|
90
|
+
}
|
|
91
|
+
if (params.cursor !== void 0) {
|
|
92
|
+
searchParams.set("cursor", params.cursor);
|
|
93
|
+
}
|
|
94
|
+
if (params.limit !== void 0) {
|
|
95
|
+
searchParams.set("limit", String(params.limit));
|
|
96
|
+
}
|
|
97
|
+
const query = searchParams.toString();
|
|
98
|
+
const path = query ? `/v1/schedules?${query}` : "/v1/schedules";
|
|
99
|
+
return this.request("GET", path);
|
|
100
|
+
}
|
|
101
|
+
get(scheduleId) {
|
|
102
|
+
return this.request(
|
|
103
|
+
"GET",
|
|
104
|
+
`/v1/schedules/${encodeURIComponent(scheduleId)}`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
delete(scheduleId) {
|
|
108
|
+
return this.request(
|
|
109
|
+
"DELETE",
|
|
110
|
+
`/v1/schedules/${encodeURIComponent(scheduleId)}`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/default-client.ts
|
|
116
|
+
var schedules = new SchedulesClient();
|
|
5
117
|
export {
|
|
6
|
-
|
|
118
|
+
DEFAULT_SCHEDULES_BASE_URL,
|
|
119
|
+
schedules as Schedules,
|
|
120
|
+
SchedulesApiError,
|
|
121
|
+
SchedulesClient
|
|
7
122
|
};
|
|
8
123
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/api-client.ts","../src/constants.ts","../src/schedules.ts","../src/default-client.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://vss-server.vercel.sh';\n","import { SchedulesApiClient } from './api-client';\nimport type {\n CreateScheduleParams,\n CreateScheduleResponse,\n DeleteScheduleResponse,\n ListSchedulesParams,\n ListSchedulesResponse,\n Schedule,\n} from './types';\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(scheduleId: string): Promise<Schedule> {\n return this.request(\n 'GET',\n `/v1/schedules/${encodeURIComponent(scheduleId)}`,\n );\n }\n\n delete(scheduleId: string): Promise<DeleteScheduleResponse> {\n return this.request(\n 'DELETE',\n `/v1/schedules/${encodeURIComponent(scheduleId)}`,\n );\n }\n}\n","import { SchedulesClient } from './schedules';\n\nexport const schedules = new SchedulesClient();\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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C,QAAI,OAAO,cAAc,QAAW;AAClC,mBAAa,IAAI,aAAa,OAAO,SAAS;AAAA,IAChD;AACA,QAAI,OAAO,WAAW,QAAW;AAC/B,mBAAa,IAAI,UAAU,OAAO,MAAM;AAAA,IAC1C;AACA,QAAI,OAAO,UAAU,QAAW;AAC9B,mBAAa,IAAI,SAAS,OAAO,OAAO,KAAK,CAAC;AAAA,IAChD;AAEA,UAAM,QAAQ,aAAa,SAAS;AACpC,UAAM,OAAO,QAAQ,iBAAiB,KAAK,KAAK;AAEhD,WAAO,KAAK,QAAQ,OAAO,IAAI;AAAA,EACjC;AAAA,EAEA,IAAI,YAAuC;AACzC,WAAO,KAAK;AAAA,MACV;AAAA,MACA,iBAAiB,mBAAmB,UAAU,CAAC;AAAA,IACjD;AAAA,EACF;AAAA,EAEA,OAAO,YAAqD;AAC1D,WAAO,KAAK;AAAA,MACV;AAAA,MACA,iBAAiB,mBAAmB,UAAU,CAAC;AAAA,IACjD;AAAA,EACF;AACF;;;ACtDO,IAAM,YAAY,IAAI,gBAAgB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/schedules",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
"tsup": "8.5.1",
|
|
37
37
|
"tsconfig": "0.0.0"
|
|
38
38
|
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@vercel/oidc": "^3.0.5"
|
|
41
|
+
},
|
|
39
42
|
"engines": {
|
|
40
43
|
"node": ">=20.0.0"
|
|
41
44
|
},
|