@mastra/deployer-netlify 0.1.0-alpha.54 → 0.1.0-alpha.55

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,13 @@
1
1
  # @mastra/deployer-netlify
2
2
 
3
+ ## 0.1.0-alpha.55
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a9345f9]
8
+ - @mastra/core@0.2.0-alpha.102
9
+ - @mastra/deployer@0.1.0-alpha.52
10
+
3
11
  ## 0.1.0-alpha.54
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,38 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ export declare function getOrCreateSite({ token, name, scope }: {
4
+ token: string;
5
+ name: string;
6
+ scope: string;
7
+ }): Promise<{
8
+ id: string | undefined;
9
+ name: string | undefined;
10
+ url: string | undefined;
11
+ adminUrl: string | undefined;
12
+ } | {
13
+ id: string;
14
+ name: string;
15
+ ssl_url: string;
16
+ url: string;
17
+ admin_url: string;
18
+ }>;
19
+
20
+ export declare class NetlifyDeployer extends Deployer {
21
+ protected scope: string;
22
+ protected projectName: string;
23
+ protected token: string;
24
+ constructor({ scope, projectName, token }: {
25
+ scope: string;
26
+ projectName: string;
27
+ token: string;
28
+ });
29
+ writeFiles({ dir }: {
30
+ dir: string;
31
+ }): void;
32
+ deploy(outputDirectory: string): Promise<void>;
33
+ prepare(outputDirectory: string): Promise<void>;
34
+ bundle(entryFile: string, outputDirectory: string): Promise<void>;
35
+ private getEntry;
36
+ }
37
+
38
+ export { }
@@ -0,0 +1 @@
1
+ export { NetlifyDeployer } from './_tsup-dts-rollup.js';
package/dist/index.js ADDED
@@ -0,0 +1,138 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+ import { execa } from 'execa';
3
+ import { existsSync, mkdirSync, writeFileSync } from 'fs';
4
+ import { join } from 'path';
5
+
6
+ // src/index.ts
7
+
8
+ // src/helpers.ts
9
+ async function createNetlifySite({ token, name, scope }) {
10
+ const response = await fetch("https://api.netlify.com/api/v1/sites", {
11
+ method: "POST",
12
+ headers: {
13
+ Authorization: `Bearer ${token}`,
14
+ "Content-Type": "application/json"
15
+ },
16
+ body: JSON.stringify({
17
+ name,
18
+ account_slug: scope,
19
+ // Optional - if not provided, creates in user's default account
20
+ force_ssl: true
21
+ // Enable HTTPS
22
+ })
23
+ });
24
+ const data = await response.json();
25
+ if (!response.ok) {
26
+ console.error(JSON.stringify(data));
27
+ throw new Error(`Failed to create site: ${data.message || "Unknown error"}`);
28
+ }
29
+ return {
30
+ id: data.id,
31
+ name: data.name,
32
+ url: data.ssl_url || data.url,
33
+ adminUrl: data.admin_url
34
+ };
35
+ }
36
+ async function findNetlifySite({ token, name, scope }) {
37
+ const response = await fetch(`https://api.netlify.com/api/v1/${scope}/sites?filter=all&name=${name}`, {
38
+ headers: {
39
+ Authorization: `Bearer ${token}`,
40
+ "Content-Type": "application/json"
41
+ }
42
+ });
43
+ const data = await response.json();
44
+ if (!response.ok || !Array.isArray(data)) {
45
+ throw new Error(`Failed to search sites: ${data.message || "Unknown error"}`);
46
+ }
47
+ return data.find((site) => site.name === name);
48
+ }
49
+ async function getOrCreateSite({ token, name, scope }) {
50
+ let existingSite;
51
+ try {
52
+ existingSite = await findNetlifySite({ token, name, scope });
53
+ } catch (e) {
54
+ }
55
+ if (existingSite) {
56
+ return existingSite;
57
+ }
58
+ return createNetlifySite({ token, name, scope });
59
+ }
60
+
61
+ // src/index.ts
62
+ var NetlifyDeployer = class extends Deployer {
63
+ scope;
64
+ projectName;
65
+ token;
66
+ constructor({ scope, projectName, token }) {
67
+ super({ name: "NETLIFY" });
68
+ this.scope = scope;
69
+ this.projectName = projectName;
70
+ this.token = token;
71
+ }
72
+ writeFiles({ dir }) {
73
+ if (!existsSync(join(dir, "netlify/functions/api"))) {
74
+ mkdirSync(join(dir, "netlify/functions/api"), { recursive: true });
75
+ }
76
+ writeFileSync(
77
+ join(dir, "netlify.toml"),
78
+ `[functions]
79
+ node_bundler = "esbuild"
80
+ directory = "netlify/functions"
81
+
82
+ [[redirects]]
83
+ force = true
84
+ from = "/*"
85
+ status = 200
86
+ to = "/.netlify/functions/api/:splat"
87
+ `
88
+ );
89
+ }
90
+ async deploy(outputDirectory) {
91
+ const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
92
+ const p2 = execa(
93
+ "npx",
94
+ [
95
+ "netlify-cli",
96
+ "deploy",
97
+ "--site",
98
+ site.id,
99
+ "--auth",
100
+ this.token,
101
+ "--dir",
102
+ ".",
103
+ "--functions",
104
+ "./netlify/functions"
105
+ ],
106
+ {
107
+ cwd: join(outputDirectory, this.outputDir)
108
+ }
109
+ );
110
+ p2.stdout.pipe(process.stdout);
111
+ await p2;
112
+ }
113
+ async prepare(outputDirectory) {
114
+ await super.prepare(outputDirectory);
115
+ this.writeFiles({ dir: join(outputDirectory, this.outputDir) });
116
+ }
117
+ async bundle(entryFile, outputDirectory) {
118
+ return this._bundle(
119
+ this.getEntry(),
120
+ entryFile,
121
+ outputDirectory,
122
+ join(outputDirectory, this.outputDir, "netlify", "functions", "api")
123
+ );
124
+ }
125
+ getEntry() {
126
+ return `
127
+ import { handle } from 'hono/netlify'
128
+ import { mastra } from '#mastra';
129
+ import { createHonoServer } from '#server';
130
+
131
+ const app = await createHonoServer(mastra);
132
+
133
+ export default handle(app)
134
+ `;
135
+ }
136
+ };
137
+
138
+ export { NetlifyDeployer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer-netlify",
3
- "version": "0.1.0-alpha.54",
3
+ "version": "0.1.0-alpha.55",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,8 +21,8 @@
21
21
  "execa": "^9.3.1",
22
22
  "netlify-cli": "^18.0.1",
23
23
  "zod": "^3.24.1",
24
- "@mastra/core": "^0.2.0-alpha.101",
25
- "@mastra/deployer": "^0.1.0-alpha.51"
24
+ "@mastra/core": "^0.2.0-alpha.102",
25
+ "@mastra/deployer": "^0.1.0-alpha.52"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@microsoft/api-extractor": "^7.49.2",