@mastra/deployer-vercel 0.0.0-a2a-20250421213654

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/LICENSE.md ADDED
@@ -0,0 +1,46 @@
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
4
+
5
+ **Acceptance**
6
+ By using the software, you agree to all of the terms and conditions below.
7
+
8
+ **Copyright License**
9
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
10
+
11
+ **Limitations**
12
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
13
+
14
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
15
+
16
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
17
+
18
+ **Patents**
19
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
20
+
21
+ **Notices**
22
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
23
+
24
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
25
+
26
+ **No Other Rights**
27
+ These terms do not imply any licenses other than those expressly granted in these terms.
28
+
29
+ **Termination**
30
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
31
+
32
+ **No Liability**
33
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
34
+
35
+ **Definitions**
36
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
37
+
38
+ _you_ refers to the individual or entity agreeing to these terms.
39
+
40
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
41
+
42
+ _your licenses_ are all the licenses granted to you for the software under these terms.
43
+
44
+ _use_ means anything you do with the software requiring one of your licenses.
45
+
46
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # @mastra/deployer-vercel
2
+
3
+ A Vercel deployer for Mastra applications.
4
+
5
+ ## Features
6
+
7
+ - Deploy Mastra applications to Vercel
8
+ - Zero-configuration serverless deployments
9
+ - Automatic environment variable synchronization
10
+ - Support for production, preview, and development environments
11
+ - Instant global deployments with Edge Functions
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @mastra/deployer-vercel
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ The Vercel deployer is used as part of the Mastra framework:
22
+
23
+ ```typescript
24
+ import { Mastra } from '@mastra/core';
25
+ import { VercelDeployer } from '@mastra/deployer-vercel';
26
+
27
+ const deployer = new VercelDeployer({
28
+ teamSlug: 'your-team-slug',
29
+ projectName: 'your-project-name',
30
+ token: 'your-vercel-token',
31
+ });
32
+
33
+ const mastra = new Mastra({
34
+ deployer,
35
+ // ... other Mastra configuration options
36
+ });
37
+ ```
38
+
39
+ ## Configuration
40
+
41
+ ### Constructor Options
42
+
43
+ - `teamSlug` (required): Your Vercel team slug
44
+ - `projectName`: Name of your Vercel project (will be created if it doesn't exist)
45
+ - `token`: Your Vercel API token (required for authentication)
46
+
47
+ ## Project Structure
48
+
49
+ The deployer creates:
50
+
51
+ ```
52
+ your-project/
53
+ ├── vercel.json # Deployment configuration
54
+ └── index.mjs # Application entry point
55
+ ```
56
+
57
+ ### vercel.json Configuration
58
+
59
+ Default configuration:
60
+
61
+ ```json
62
+ {
63
+ "version": 2,
64
+ "installCommand": "npm install --omit=dev",
65
+ "builds": [
66
+ {
67
+ "src": "index.mjs",
68
+ "use": "@vercel/node",
69
+ "config": {
70
+ "includeFiles": ["**"]
71
+ }
72
+ }
73
+ ],
74
+ "routes": [
75
+ {
76
+ "src": "/(.*)",
77
+ "dest": "index.mjs"
78
+ }
79
+ ]
80
+ }
81
+ ```
82
+
83
+ ## Environment Variables
84
+
85
+ Environment variables are handled automatically through:
86
+
87
+ - `.env` files in your project
88
+ - Environment variables passed through the Mastra configuration
89
+ - Vercel's environment variable UI
90
+
91
+ ## Deployment Process
92
+
93
+ The deployer:
94
+
95
+ 1. Configures your project with the necessary files
96
+ 2. Deploys to Vercel using the CLI
97
+ 3. Synchronizes environment variables for future deployments
@@ -0,0 +1,22 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ export declare class VercelDeployer extends Deployer {
4
+ private teamSlug;
5
+ private projectName;
6
+ private token;
7
+ constructor({ teamSlug, projectName, token }: {
8
+ teamSlug: string;
9
+ projectName: string;
10
+ token: string;
11
+ });
12
+ writeFiles(outputDirectory: string): void;
13
+ private getProjectId;
14
+ private getTeamId;
15
+ private syncEnv;
16
+ prepare(outputDirectory: string): Promise<void>;
17
+ private getEntry;
18
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
19
+ deploy(outputDirectory: string): Promise<void>;
20
+ }
21
+
22
+ export { }
@@ -0,0 +1,22 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ export declare class VercelDeployer extends Deployer {
4
+ private teamSlug;
5
+ private projectName;
6
+ private token;
7
+ constructor({ teamSlug, projectName, token }: {
8
+ teamSlug: string;
9
+ projectName: string;
10
+ token: string;
11
+ });
12
+ writeFiles(outputDirectory: string): void;
13
+ private getProjectId;
14
+ private getTeamId;
15
+ private syncEnv;
16
+ prepare(outputDirectory: string): Promise<void>;
17
+ private getEntry;
18
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
19
+ deploy(outputDirectory: string): Promise<void>;
20
+ }
21
+
22
+ export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,177 @@
1
+ 'use strict';
2
+
3
+ var child_process = require('child_process');
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+ var process = require('process');
7
+ var deployer = require('@mastra/deployer');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n.default = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var child_process__namespace = /*#__PURE__*/_interopNamespace(child_process);
30
+ var process__default = /*#__PURE__*/_interopDefault(process);
31
+
32
+ // src/index.ts
33
+ var VercelDeployer = class extends deployer.Deployer {
34
+ teamSlug;
35
+ projectName;
36
+ token;
37
+ constructor({ teamSlug, projectName, token }) {
38
+ super({ name: "VERCEL" });
39
+ this.teamSlug = teamSlug;
40
+ this.projectName = projectName;
41
+ this.token = token;
42
+ }
43
+ writeFiles(outputDirectory) {
44
+ fs.writeFileSync(
45
+ path.join(outputDirectory, this.outputDir, "vercel.json"),
46
+ JSON.stringify(
47
+ {
48
+ version: 2,
49
+ installCommand: "npm install --omit=dev",
50
+ builds: [
51
+ {
52
+ src: "index.mjs",
53
+ use: "@vercel/node",
54
+ config: { includeFiles: ["**"] }
55
+ }
56
+ ],
57
+ routes: [
58
+ {
59
+ src: "/(.*)",
60
+ dest: "index.mjs"
61
+ }
62
+ ]
63
+ },
64
+ null,
65
+ 2
66
+ )
67
+ );
68
+ }
69
+ getProjectId({ dir }) {
70
+ const projectJsonPath = path.join(dir, "output", ".vercel", "project.json");
71
+ try {
72
+ const projectJson = JSON.parse(fs.readFileSync(projectJsonPath, "utf-8"));
73
+ return projectJson.projectId;
74
+ } catch {
75
+ throw new Error("Could not find project ID. Make sure the project has been deployed first.");
76
+ }
77
+ }
78
+ async getTeamId() {
79
+ const response = await fetch(`https://api.vercel.com/v2/teams`, {
80
+ headers: {
81
+ Authorization: `Bearer ${this.token}`
82
+ }
83
+ });
84
+ const res = await response.json();
85
+ const teams = res.teams;
86
+ return teams.find((team) => team.slug === this.teamSlug)?.id;
87
+ }
88
+ async syncEnv(envVars, { outputDirectory }) {
89
+ console.log("Syncing environment variables...");
90
+ const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
91
+ if (!key || !value) {
92
+ throw new Error(`Invalid environment variable format: ${key || value}`);
93
+ }
94
+ return {
95
+ key,
96
+ value,
97
+ target: ["production", "preview", "development"],
98
+ type: "plain"
99
+ };
100
+ });
101
+ try {
102
+ const projectId = this.getProjectId({ dir: outputDirectory });
103
+ const teamId = await this.getTeamId();
104
+ const response = await fetch(
105
+ `https://api.vercel.com/v10/projects/${projectId}/env?teamId=${teamId}&upsert=true`,
106
+ {
107
+ method: "POST",
108
+ headers: {
109
+ Authorization: `Bearer ${this.token}`,
110
+ "Content-Type": "application/json"
111
+ },
112
+ body: JSON.stringify(vercelEnvVars)
113
+ }
114
+ );
115
+ if (!response.ok) {
116
+ const error = await response.json();
117
+ throw new Error(`Failed to sync environment variables: ${error.message}`);
118
+ }
119
+ console.log("\u2713 Successfully synced environment variables");
120
+ } catch (error) {
121
+ if (error instanceof Error) {
122
+ console.error("Failed to sync environment variables:", error.message);
123
+ } else {
124
+ console.error("Failed to sync environment variables:", error);
125
+ }
126
+ throw error;
127
+ }
128
+ }
129
+ async prepare(outputDirectory) {
130
+ await super.prepare(outputDirectory);
131
+ await this.writeFiles(outputDirectory);
132
+ }
133
+ getEntry() {
134
+ return `
135
+ import { handle } from 'hono/vercel'
136
+ import { mastra } from '#mastra';
137
+ import { createHonoServer } from '#server';
138
+
139
+ const app = await createHonoServer(mastra);
140
+
141
+ export const GET = handle(app);
142
+ export const POST = handle(app);
143
+ `;
144
+ }
145
+ async bundle(entryFile, outputDirectory, toolsPaths) {
146
+ return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
147
+ }
148
+ async deploy(outputDirectory) {
149
+ const envVars = await this.loadEnvVars();
150
+ const commandArgs = [
151
+ "--scope",
152
+ this.teamSlug,
153
+ "--cwd",
154
+ path.join(outputDirectory, this.outputDir),
155
+ "--token",
156
+ this.token,
157
+ "deploy",
158
+ "--yes",
159
+ ...this.projectName ? ["--name", this.projectName] : []
160
+ ];
161
+ child_process__namespace.execSync(`npx vercel ${commandArgs.join(" ")}`, {
162
+ cwd: path.join(outputDirectory, this.outputDir),
163
+ env: {
164
+ PATH: process__default.default.env.PATH
165
+ },
166
+ stdio: "inherit"
167
+ });
168
+ this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
169
+ if (envVars.size > 0) {
170
+ await this.syncEnv(envVars, { outputDirectory });
171
+ } else {
172
+ this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
173
+ }
174
+ }
175
+ };
176
+
177
+ exports.VercelDeployer = VercelDeployer;
@@ -0,0 +1 @@
1
+ export { VercelDeployer } from './_tsup-dts-rollup.cjs';
@@ -0,0 +1 @@
1
+ export { VercelDeployer } from './_tsup-dts-rollup.js';
package/dist/index.js ADDED
@@ -0,0 +1,152 @@
1
+ import * as child_process from 'child_process';
2
+ import { writeFileSync, readFileSync } from 'fs';
3
+ import { join } from 'path';
4
+ import process from 'process';
5
+ import { Deployer } from '@mastra/deployer';
6
+
7
+ // src/index.ts
8
+ var VercelDeployer = class extends Deployer {
9
+ teamSlug;
10
+ projectName;
11
+ token;
12
+ constructor({ teamSlug, projectName, token }) {
13
+ super({ name: "VERCEL" });
14
+ this.teamSlug = teamSlug;
15
+ this.projectName = projectName;
16
+ this.token = token;
17
+ }
18
+ writeFiles(outputDirectory) {
19
+ writeFileSync(
20
+ join(outputDirectory, this.outputDir, "vercel.json"),
21
+ JSON.stringify(
22
+ {
23
+ version: 2,
24
+ installCommand: "npm install --omit=dev",
25
+ builds: [
26
+ {
27
+ src: "index.mjs",
28
+ use: "@vercel/node",
29
+ config: { includeFiles: ["**"] }
30
+ }
31
+ ],
32
+ routes: [
33
+ {
34
+ src: "/(.*)",
35
+ dest: "index.mjs"
36
+ }
37
+ ]
38
+ },
39
+ null,
40
+ 2
41
+ )
42
+ );
43
+ }
44
+ getProjectId({ dir }) {
45
+ const projectJsonPath = join(dir, "output", ".vercel", "project.json");
46
+ try {
47
+ const projectJson = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
48
+ return projectJson.projectId;
49
+ } catch {
50
+ throw new Error("Could not find project ID. Make sure the project has been deployed first.");
51
+ }
52
+ }
53
+ async getTeamId() {
54
+ const response = await fetch(`https://api.vercel.com/v2/teams`, {
55
+ headers: {
56
+ Authorization: `Bearer ${this.token}`
57
+ }
58
+ });
59
+ const res = await response.json();
60
+ const teams = res.teams;
61
+ return teams.find((team) => team.slug === this.teamSlug)?.id;
62
+ }
63
+ async syncEnv(envVars, { outputDirectory }) {
64
+ console.log("Syncing environment variables...");
65
+ const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
66
+ if (!key || !value) {
67
+ throw new Error(`Invalid environment variable format: ${key || value}`);
68
+ }
69
+ return {
70
+ key,
71
+ value,
72
+ target: ["production", "preview", "development"],
73
+ type: "plain"
74
+ };
75
+ });
76
+ try {
77
+ const projectId = this.getProjectId({ dir: outputDirectory });
78
+ const teamId = await this.getTeamId();
79
+ const response = await fetch(
80
+ `https://api.vercel.com/v10/projects/${projectId}/env?teamId=${teamId}&upsert=true`,
81
+ {
82
+ method: "POST",
83
+ headers: {
84
+ Authorization: `Bearer ${this.token}`,
85
+ "Content-Type": "application/json"
86
+ },
87
+ body: JSON.stringify(vercelEnvVars)
88
+ }
89
+ );
90
+ if (!response.ok) {
91
+ const error = await response.json();
92
+ throw new Error(`Failed to sync environment variables: ${error.message}`);
93
+ }
94
+ console.log("\u2713 Successfully synced environment variables");
95
+ } catch (error) {
96
+ if (error instanceof Error) {
97
+ console.error("Failed to sync environment variables:", error.message);
98
+ } else {
99
+ console.error("Failed to sync environment variables:", error);
100
+ }
101
+ throw error;
102
+ }
103
+ }
104
+ async prepare(outputDirectory) {
105
+ await super.prepare(outputDirectory);
106
+ await this.writeFiles(outputDirectory);
107
+ }
108
+ getEntry() {
109
+ return `
110
+ import { handle } from 'hono/vercel'
111
+ import { mastra } from '#mastra';
112
+ import { createHonoServer } from '#server';
113
+
114
+ const app = await createHonoServer(mastra);
115
+
116
+ export const GET = handle(app);
117
+ export const POST = handle(app);
118
+ `;
119
+ }
120
+ async bundle(entryFile, outputDirectory, toolsPaths) {
121
+ return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
122
+ }
123
+ async deploy(outputDirectory) {
124
+ const envVars = await this.loadEnvVars();
125
+ const commandArgs = [
126
+ "--scope",
127
+ this.teamSlug,
128
+ "--cwd",
129
+ join(outputDirectory, this.outputDir),
130
+ "--token",
131
+ this.token,
132
+ "deploy",
133
+ "--yes",
134
+ ...this.projectName ? ["--name", this.projectName] : []
135
+ ];
136
+ child_process.execSync(`npx vercel ${commandArgs.join(" ")}`, {
137
+ cwd: join(outputDirectory, this.outputDir),
138
+ env: {
139
+ PATH: process.env.PATH
140
+ },
141
+ stdio: "inherit"
142
+ });
143
+ this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
144
+ if (envVars.size > 0) {
145
+ await this.syncEnv(envVars, { outputDirectory });
146
+ } else {
147
+ this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
148
+ }
149
+ }
150
+ };
151
+
152
+ export { VercelDeployer };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@mastra/deployer-vercel",
3
+ "version": "0.0.0-a2a-20250421213654",
4
+ "description": "",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.cts",
19
+ "default": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "keywords": [],
25
+ "author": "",
26
+ "license": "Elastic-2.0",
27
+ "dependencies": {
28
+ "@rollup/plugin-virtual": "^3.0.2",
29
+ "fs-extra": "^11.3.0",
30
+ "@mastra/deployer": "0.0.0-a2a-20250421213654",
31
+ "@mastra/core": "0.0.0-a2a-20250421213654"
32
+ },
33
+ "devDependencies": {
34
+ "@microsoft/api-extractor": "^7.52.1",
35
+ "@types/node": "^20.17.27",
36
+ "eslint": "^9.23.0",
37
+ "tsup": "^8.4.0",
38
+ "typescript": "^5.8.2",
39
+ "vercel": "^39.4.2",
40
+ "vitest": "^3.0.9",
41
+ "@internal/lint": "0.0.2"
42
+ },
43
+ "scripts": {
44
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
45
+ "build:watch": "pnpm build --watch",
46
+ "test": "vitest run",
47
+ "lint": "eslint ."
48
+ }
49
+ }