@mastra/deployer-netlify 0.0.1-alpha.9 → 0.1.0-alpha.35

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/CHANGELOG.md CHANGED
@@ -1,5 +1,234 @@
1
1
  # @mastra/deployer-netlify
2
2
 
3
+ ## 0.1.0-alpha.35
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [7365b6c]
8
+ - @mastra/core@0.2.0-alpha.87
9
+ - @mastra/deployer@0.1.0-alpha.33
10
+
11
+ ## 0.1.0-alpha.34
12
+
13
+ ### Minor Changes
14
+
15
+ - 5916f9d: Update deps from fixed to ^
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [6fa4bd2]
20
+ - Updated dependencies [5916f9d]
21
+ - Updated dependencies [e2e76de]
22
+ - Updated dependencies [7f24c29]
23
+ - Updated dependencies [67637ba]
24
+ - Updated dependencies [04f3171]
25
+ - @mastra/core@0.2.0-alpha.86
26
+ - @mastra/deployer@0.1.0-alpha.32
27
+
28
+ ## 0.0.1-alpha.33
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [e9d1b47]
33
+ - Updated dependencies [c5f2d50]
34
+ - @mastra/core@0.2.0-alpha.85
35
+ - @mastra/deployer@0.0.1-alpha.31
36
+
37
+ ## 0.0.1-alpha.32
38
+
39
+ ### Patch Changes
40
+
41
+ - e27fe69: Add dir to deployer
42
+ - Updated dependencies [e27fe69]
43
+ - @mastra/deployer@0.0.1-alpha.30
44
+
45
+ ## 0.0.1-alpha.31
46
+
47
+ ### Patch Changes
48
+
49
+ - 38b7f66: Update deployer logic
50
+ - Updated dependencies [2f17a5f]
51
+ - Updated dependencies [0696eeb]
52
+ - Updated dependencies [cb290ee]
53
+ - Updated dependencies [b4d7416]
54
+ - Updated dependencies [38b7f66]
55
+ - @mastra/core@0.2.0-alpha.84
56
+ - @mastra/deployer@0.0.1-alpha.29
57
+
58
+ ## 0.0.1-alpha.30
59
+
60
+ ### Patch Changes
61
+
62
+ - 9625602: Use mastra core splitted bundles in other packages
63
+ - Updated dependencies [2ab57d6]
64
+ - Updated dependencies [30322ce]
65
+ - Updated dependencies [78eec7c]
66
+ - Updated dependencies [9625602]
67
+ - Updated dependencies [8769a62]
68
+ - @mastra/deployer@0.0.1-alpha.28
69
+ - @mastra/core@0.2.0-alpha.83
70
+
71
+ ## 0.0.1-alpha.29
72
+
73
+ ### Patch Changes
74
+
75
+ - Updated dependencies [73d112c]
76
+ - Updated dependencies [ac8c61a]
77
+ - @mastra/deployer@0.0.1-alpha.27
78
+ - @mastra/core@0.1.27-alpha.82
79
+
80
+ ## 0.0.1-alpha.28
81
+
82
+ ### Patch Changes
83
+
84
+ - Updated dependencies [9fb3039]
85
+ - @mastra/core@0.1.27-alpha.81
86
+ - @mastra/deployer@0.0.1-alpha.26
87
+
88
+ ## 0.0.1-alpha.27
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies [327ece7]
93
+ - @mastra/core@0.1.27-alpha.80
94
+ - @mastra/deployer@0.0.1-alpha.25
95
+
96
+ ## 0.0.1-alpha.26
97
+
98
+ ### Patch Changes
99
+
100
+ - Updated dependencies [21fe536]
101
+ - @mastra/core@0.1.27-alpha.79
102
+ - @mastra/deployer@0.0.1-alpha.24
103
+
104
+ ## 0.0.1-alpha.25
105
+
106
+ ### Patch Changes
107
+
108
+ - Updated dependencies [88f18d7]
109
+ - @mastra/deployer@0.0.1-alpha.23
110
+
111
+ ## 0.0.1-alpha.24
112
+
113
+ ### Patch Changes
114
+
115
+ - 44c7c26: Rebuild
116
+
117
+ ## 0.0.1-alpha.23
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies [685108a]
122
+ - Updated dependencies [685108a]
123
+ - @mastra/deployer@0.0.1-alpha.22
124
+ - @mastra/core@0.1.27-alpha.78
125
+
126
+ ## 0.0.1-alpha.22
127
+
128
+ ### Patch Changes
129
+
130
+ - 2b75edf: mastra deployers tsup bundling
131
+ - Updated dependencies [8105fae]
132
+ - Updated dependencies [cfb966f]
133
+ - @mastra/core@0.1.27-alpha.77
134
+ - @mastra/deployer@0.0.1-alpha.21
135
+
136
+ ## 0.0.1-alpha.21
137
+
138
+ ### Patch Changes
139
+
140
+ - Updated dependencies [ae7bf94]
141
+ - Updated dependencies [ae7bf94]
142
+ - @mastra/deployer@0.0.1-alpha.20
143
+ - @mastra/core@0.1.27-alpha.76
144
+
145
+ ## 0.0.1-alpha.20
146
+
147
+ ### Patch Changes
148
+
149
+ - Updated dependencies [23dcb23]
150
+ - Updated dependencies [7064554]
151
+ - @mastra/core@0.1.27-alpha.75
152
+ - @mastra/deployer@0.0.1-alpha.19
153
+
154
+ ## 0.0.1-alpha.19
155
+
156
+ ### Patch Changes
157
+
158
+ - Updated dependencies [7b87567]
159
+ - @mastra/core@0.1.27-alpha.74
160
+ - @mastra/deployer@0.0.1-alpha.18
161
+
162
+ ## 0.0.1-alpha.18
163
+
164
+ ### Patch Changes
165
+
166
+ - Updated dependencies [3427b95]
167
+ - @mastra/core@0.1.27-alpha.73
168
+ - @mastra/deployer@0.0.1-alpha.17
169
+
170
+ ## 0.0.1-alpha.17
171
+
172
+ ### Patch Changes
173
+
174
+ - Updated dependencies [e4d4ede]
175
+ - Updated dependencies [06b2c0a]
176
+ - @mastra/core@0.1.27-alpha.72
177
+ - @mastra/deployer@0.0.1-alpha.16
178
+
179
+ ## 0.0.1-alpha.16
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies [d9c8dd0]
184
+ - @mastra/deployer@0.0.1-alpha.15
185
+ - @mastra/core@0.1.27-alpha.71
186
+
187
+ ## 0.0.1-alpha.15
188
+
189
+ ### Patch Changes
190
+
191
+ - Updated dependencies [ad2cd74]
192
+ - @mastra/deployer@0.0.1-alpha.14
193
+
194
+ ## 0.0.1-alpha.14
195
+
196
+ ### Patch Changes
197
+
198
+ - Updated dependencies [a1774e7]
199
+ - @mastra/deployer@0.0.1-alpha.13
200
+
201
+ ## 0.0.1-alpha.13
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [28dceab]
206
+ - @mastra/deployer@0.0.1-alpha.12
207
+
208
+ ## 0.0.1-alpha.12
209
+
210
+ ### Patch Changes
211
+
212
+ - bdaf834: publish packages
213
+ - Updated dependencies [bdaf834]
214
+ - @mastra/deployer@0.0.1-alpha.11
215
+
216
+ ## 0.0.1-alpha.11
217
+
218
+ ### Patch Changes
219
+
220
+ - Updated dependencies [dd6d87f]
221
+ - Updated dependencies [04434b6]
222
+ - @mastra/core@0.1.27-alpha.70
223
+ - @mastra/deployer@0.0.1-alpha.10
224
+
225
+ ## 0.0.1-alpha.10
226
+
227
+ ### Patch Changes
228
+
229
+ - Updated dependencies [9066f95]
230
+ - @mastra/deployer@0.0.1-alpha.9
231
+
3
232
  ## 0.0.1-alpha.9
4
233
 
5
234
  ### Patch Changes
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @mastra/deployer-netlify
2
+
3
+ A Netlify deployer for Mastra applications.
4
+
5
+ ## Features
6
+
7
+ - Deploy Mastra applications to Netlify Functions
8
+ - Automatic site creation and configuration
9
+ - Serverless function support with Edge Functions
10
+ - Zero-configuration deployments
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @mastra/deployer-netlify
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ The Netlify deployer is used as part of the Mastra framework:
21
+
22
+ ```typescript
23
+ import { Mastra } from '@mastra/core';
24
+ import { NetlifyDeployer } from '@mastra/deployer-netlify';
25
+
26
+ const deployer = new NetlifyDeployer({
27
+ scope: 'your-team-id',
28
+ projectName: 'your-project-name',
29
+ });
30
+
31
+ const mastra = new Mastra({
32
+ deployer,
33
+ // ... other Mastra configuration options
34
+ });
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ ### Constructor Options
40
+
41
+ - `scope` (required): Your Netlify team ID
42
+ - `projectName`: Name of your Netlify site (will be created if it doesn't exist)
43
+
44
+ ## Project Structure
45
+
46
+ The deployer automatically creates the following structure:
47
+
48
+ ```
49
+ your-project/
50
+ ├── netlify/
51
+ │ └── functions/
52
+ │ └── api/
53
+ └── netlify.toml
54
+ ```
55
+
56
+ ### netlify.toml Configuration
57
+
58
+ The deployer creates a `netlify.toml` with the following defaults:
59
+
60
+ ```toml
61
+ [functions]
62
+ node_bundler = "esbuild"
63
+ directory = "/netlify/functions"
64
+
65
+ [[redirects]]
66
+ force = true
67
+ from = "/*"
68
+ status = 200
69
+ to = "/.netlify/functions/api/:splat"
70
+ ```
71
+
72
+ ## Environment Variables
73
+
74
+ Environment variables are handled automatically through:
75
+
76
+ - `.env` files in your project
77
+ - Environment variables passed through the Mastra configuration
78
+ - Netlify's environment variable UI
79
+
80
+ ## Deployment Process
81
+
82
+ The deployer will:
83
+
84
+ 1. Create a new site if it doesn't exist
85
+ 2. Configure the site with your environment variables
86
+ 3. Deploy your application to Netlify Functions
package/dist/index.d.ts CHANGED
@@ -1,19 +1,21 @@
1
- import { MastraDeployer } from '@mastra/core';
2
- export declare class NetlifyDeployer extends MastraDeployer {
3
- constructor({ scope, env, projectName }: {
4
- projectName: string;
5
- env?: Record<string, any>;
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ declare class NetlifyDeployer extends Deployer {
4
+ protected scope: string;
5
+ protected projectName: string;
6
+ protected token: string;
7
+ constructor({ scope, projectName, token }: {
6
8
  scope: string;
9
+ projectName: string;
10
+ token: string;
7
11
  });
8
12
  writeFiles({ dir }: {
9
13
  dir: string;
10
14
  }): void;
11
- deploy({ dir, token }: {
12
- dir: string;
13
- token: string;
14
- }): Promise<void>;
15
- writeIndex({ dir }: {
16
- dir: string;
17
- }): void;
15
+ deploy(outputDirectory: string): Promise<void>;
16
+ prepare(outputDirectory: string): Promise<void>;
17
+ bundle(mastraDir: string, outputDirectory: string): Promise<void>;
18
+ private getEntry;
18
19
  }
19
- //# sourceMappingURL=index.d.ts.map
20
+
21
+ export { NetlifyDeployer };
package/dist/index.js CHANGED
@@ -1,8 +1,148 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+ import { getBundler } from '@mastra/deployer/build';
3
+ import virtual from '@rollup/plugin-virtual';
4
+ import { execa } from 'execa';
5
+ import { existsSync, mkdirSync, writeFileSync } from 'fs';
6
+ import { join } from 'path';
1
7
 
2
- 'use strict'
8
+ // src/index.ts
3
9
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./deployer-netlify.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./deployer-netlify.cjs.development.js')
10
+ // src/helpers.ts
11
+ async function createNetlifySite({ token, name, scope }) {
12
+ console.log(token, name, scope);
13
+ const response = await fetch("https://api.netlify.com/api/v1/sites", {
14
+ method: "POST",
15
+ headers: {
16
+ Authorization: `Bearer ${token}`,
17
+ "Content-Type": "application/json"
18
+ },
19
+ body: JSON.stringify({
20
+ name,
21
+ account_slug: scope,
22
+ // Optional - if not provided, creates in user's default account
23
+ force_ssl: true
24
+ // Enable HTTPS
25
+ })
26
+ });
27
+ const data = await response.json();
28
+ if (!response.ok) {
29
+ console.error(JSON.stringify(data));
30
+ throw new Error(`Failed to create site: ${data.message || "Unknown error"}`);
31
+ }
32
+ return {
33
+ id: data.id,
34
+ name: data.name,
35
+ url: data.ssl_url || data.url,
36
+ adminUrl: data.admin_url
37
+ };
8
38
  }
39
+ async function findNetlifySite({ token, name, scope }) {
40
+ const response = await fetch(`https://api.netlify.com/api/v1/${scope}/sites?filter=all&name=${name}`, {
41
+ headers: {
42
+ Authorization: `Bearer ${token}`,
43
+ "Content-Type": "application/json"
44
+ }
45
+ });
46
+ const data = await response.json();
47
+ if (!response.ok) {
48
+ throw new Error(`Failed to search sites: ${data.message || "Unknown error"}`);
49
+ }
50
+ return data.find((site) => site.name === name);
51
+ }
52
+ async function getOrCreateSite({ token, name, scope }) {
53
+ let existingSite;
54
+ try {
55
+ existingSite = await findNetlifySite({ token, name, scope });
56
+ } catch (e) {
57
+ }
58
+ if (existingSite) {
59
+ return existingSite;
60
+ }
61
+ return createNetlifySite({ token, name, scope });
62
+ }
63
+
64
+ // src/index.ts
65
+ var NetlifyDeployer = class extends Deployer {
66
+ scope;
67
+ projectName;
68
+ token;
69
+ constructor({ scope, projectName, token }) {
70
+ super({ name: "NETLIFY" });
71
+ this.scope = scope;
72
+ this.projectName = projectName;
73
+ this.token = token;
74
+ }
75
+ writeFiles({ dir }) {
76
+ if (!existsSync(join(dir, "netlify/functions/api"))) {
77
+ mkdirSync(join(dir, "netlify/functions/api"), { recursive: true });
78
+ }
79
+ writeFileSync(
80
+ join(dir, "netlify.toml"),
81
+ `[functions]
82
+ node_bundler = "esbuild"
83
+ directory = "netlify/functions"
84
+
85
+ [[redirects]]
86
+ force = true
87
+ from = "/*"
88
+ status = 200
89
+ to = "/.netlify/functions/api/:splat"
90
+ `
91
+ );
92
+ }
93
+ async deploy(outputDirectory) {
94
+ const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
95
+ const p2 = execa(
96
+ "npx",
97
+ [
98
+ "netlify-cli",
99
+ "deploy",
100
+ "--site",
101
+ site.id,
102
+ "--auth",
103
+ this.token,
104
+ "--dir",
105
+ ".",
106
+ "--functions",
107
+ "./netlify/functions"
108
+ ],
109
+ {
110
+ cwd: outputDirectory
111
+ }
112
+ );
113
+ p2.stdout.pipe(process.stdout);
114
+ await p2;
115
+ }
116
+ async prepare(outputDirectory) {
117
+ await super.prepare(outputDirectory);
118
+ if (!existsSync(join(outputDirectory, "netlify/functions/api"))) {
119
+ mkdirSync(join(outputDirectory, "netlify/functions/api"), { recursive: true });
120
+ }
121
+ this.writeFiles({ dir: outputDirectory });
122
+ }
123
+ async bundle(mastraDir, outputDirectory) {
124
+ const bundler = await getBundler({
125
+ input: "#entry",
126
+ external: [/^@opentelemetry\//],
127
+ plugins: [virtual({ "#entry": this.getEntry() })]
128
+ });
129
+ await bundler.write({
130
+ inlineDynamicImports: true,
131
+ file: join(outputDirectory, "netlify", "functions", "api", "index.mjs"),
132
+ format: "es"
133
+ });
134
+ }
135
+ getEntry() {
136
+ return `
137
+ import { handle } from 'hono/netlify'
138
+ import { mastra } from '#mastra';
139
+ import { createHonoServer } from '#server';
140
+
141
+ const app = await createHonoServer(mastra);
142
+
143
+ export default handle(app)
144
+ `;
145
+ }
146
+ };
147
+
148
+ export { NetlifyDeployer };
package/package.json CHANGED
@@ -1,21 +1,14 @@
1
1
  {
2
2
  "name": "@mastra/deployer-netlify",
3
- "version": "0.0.1-alpha.9",
3
+ "version": "0.1.0-alpha.35",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
- "module": "dist/deployer-netlify.esm.js",
8
7
  "types": "dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
- "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/deployer-netlify.esm.js"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
18
- }
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
19
12
  },
20
13
  "./package.json": "./package.json"
21
14
  },
@@ -23,26 +16,26 @@
23
16
  "author": "",
24
17
  "license": "ISC",
25
18
  "dependencies": {
19
+ "@rollup/plugin-virtual": "^3.0.2",
26
20
  "date-fns": "^4.1.0",
27
21
  "dotenv": "^16.3.1",
28
22
  "execa": "^9.3.1",
29
23
  "netlify-cli": "^18.0.1",
30
24
  "zod": "^3.24.1",
31
- "@mastra/core": "0.1.27-alpha.69",
32
- "@mastra/deployer": "0.0.1-alpha.8"
25
+ "@mastra/deployer": "^0.1.0-alpha.33",
26
+ "@mastra/core": "^0.2.0-alpha.87"
33
27
  },
34
28
  "devDependencies": {
35
29
  "@babel/preset-env": "^7.26.0",
36
30
  "@babel/preset-typescript": "^7.26.0",
37
31
  "@tsconfig/recommended": "^1.0.7",
38
- "@types/jsdom": "^21.1.7",
39
32
  "@types/node": "^22.9.0",
40
- "dts-cli": "^2.0.5",
41
- "vitest": "^2.1.8"
33
+ "tsup": "^8.0.1",
34
+ "vitest": "^3.0.4"
42
35
  },
43
36
  "scripts": {
44
- "build": "dts build",
45
- "build:dev": "dts watch",
37
+ "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
38
+ "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
46
39
  "test": "vitest run"
47
40
  }
48
41
  }