@mastra/deployer-netlify 0.0.0-storage-20250225005900 → 0.0.0-trigger-playground-ui-package-20250506151043

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.
@@ -1,4 +1,6 @@
1
- Elastic License 2.0 (ELv2)
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
2
4
 
3
5
  **Acceptance**
4
6
  By using the software, you agree to all of the terms and conditions below.
package/README.md CHANGED
@@ -26,6 +26,7 @@ import { NetlifyDeployer } from '@mastra/deployer-netlify';
26
26
  const deployer = new NetlifyDeployer({
27
27
  scope: 'your-team-id',
28
28
  projectName: 'your-project-name',
29
+ token: 'your-netlify-token',
29
30
  });
30
31
 
31
32
  const mastra = new Mastra({
@@ -38,8 +39,9 @@ const mastra = new Mastra({
38
39
 
39
40
  ### Constructor Options
40
41
 
41
- - `scope` (required): Your Netlify team ID
42
+ - `scope` (required): Your Netlify team slug or ID
42
43
  - `projectName`: Name of your Netlify site (will be created if it doesn't exist)
44
+ - `token`: Your Netlify authentication token
43
45
 
44
46
  ## Project Structure
45
47
 
@@ -0,0 +1,40 @@
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
+ protected installDependencies(outputDirectory: string, rootDir?: string): Promise<void>;
33
+ deploy(outputDirectory: string): Promise<void>;
34
+ prepare(outputDirectory: string): Promise<void>;
35
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
36
+ private getEntry;
37
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
38
+ }
39
+
40
+ export { }
@@ -29,10 +29,12 @@ export declare class NetlifyDeployer extends Deployer {
29
29
  writeFiles({ dir }: {
30
30
  dir: string;
31
31
  }): void;
32
+ protected installDependencies(outputDirectory: string, rootDir?: string): Promise<void>;
32
33
  deploy(outputDirectory: string): Promise<void>;
33
34
  prepare(outputDirectory: string): Promise<void>;
34
- bundle(entryFile: string, outputDirectory: string): Promise<void>;
35
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
35
36
  private getEntry;
37
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
36
38
  }
37
39
 
38
40
  export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,204 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var deployer = require('@mastra/deployer');
6
+ var services = require('@mastra/deployer/services');
7
+ var execa = require('execa');
8
+
9
+ // src/index.ts
10
+
11
+ // src/helpers.ts
12
+ async function createNetlifySite({ 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
+ };
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 || !Array.isArray(data)) {
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 {
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.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 (!fs.existsSync(path.join(dir, "netlify/functions/api"))) {
77
+ fs.mkdirSync(path.join(dir, "netlify/functions/api"), { recursive: true });
78
+ }
79
+ fs.writeFileSync(
80
+ path.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 installDependencies(outputDirectory, rootDir = process.cwd()) {
94
+ const deps = new services.DepsService(rootDir);
95
+ deps.__setLogger(this.logger);
96
+ await deps.install({
97
+ dir: path.join(outputDirectory, this.outputDir),
98
+ architecture: {
99
+ os: ["linux"],
100
+ cpu: ["x64"],
101
+ libc: ["gnu"]
102
+ }
103
+ });
104
+ }
105
+ async deploy(outputDirectory) {
106
+ const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
107
+ const p2 = execa.execa(
108
+ "npx",
109
+ [
110
+ "netlify-cli",
111
+ "deploy",
112
+ "--site",
113
+ site.id,
114
+ "--auth",
115
+ this.token,
116
+ "--dir",
117
+ ".",
118
+ "--functions",
119
+ "./netlify/functions"
120
+ ],
121
+ {
122
+ cwd: path.join(outputDirectory, this.outputDir)
123
+ }
124
+ );
125
+ p2.stdout.pipe(process.stdout);
126
+ await p2;
127
+ }
128
+ async prepare(outputDirectory) {
129
+ await super.prepare(outputDirectory);
130
+ this.writeFiles({ dir: path.join(outputDirectory, this.outputDir) });
131
+ }
132
+ async bundle(entryFile, outputDirectory, toolsPaths) {
133
+ return this._bundle(
134
+ this.getEntry(),
135
+ entryFile,
136
+ outputDirectory,
137
+ toolsPaths,
138
+ path.join(outputDirectory, this.outputDir, "netlify", "functions", "api")
139
+ );
140
+ }
141
+ getEntry() {
142
+ return `
143
+ import { handle } from 'hono/netlify'
144
+ import { mastra } from '#mastra';
145
+ import { createHonoServer } from '#server';
146
+ import { evaluate } from '@mastra/core/eval';
147
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
148
+ import { TABLE_EVALS } from '@mastra/core/storage';
149
+ import { checkEvalStorageFields } from '@mastra/core/utils';
150
+
151
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
152
+ evaluate({
153
+ agentName,
154
+ input,
155
+ metric,
156
+ output,
157
+ runId,
158
+ globalRunId: runId,
159
+ instructions,
160
+ });
161
+ });
162
+
163
+ if (mastra.getStorage()) {
164
+ // start storage init in the background
165
+ mastra.getStorage().init();
166
+ }
167
+
168
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
169
+ const storage = mastra.getStorage();
170
+ if (storage) {
171
+ // Check for required fields
172
+ const logger = mastra?.getLogger();
173
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
174
+ if (!areFieldsValid) return;
175
+
176
+ await storage.insert({
177
+ tableName: TABLE_EVALS,
178
+ record: {
179
+ input: traceObject.input,
180
+ output: traceObject.output,
181
+ result: JSON.stringify(traceObject.result || {}),
182
+ agent_name: traceObject.agentName,
183
+ metric_name: traceObject.metricName,
184
+ instructions: traceObject.instructions,
185
+ test_info: null,
186
+ global_run_id: traceObject.globalRunId,
187
+ run_id: traceObject.runId,
188
+ created_at: new Date().toISOString(),
189
+ },
190
+ });
191
+ }
192
+ });
193
+
194
+ const app = await createHonoServer(mastra);
195
+
196
+ export default handle(app)
197
+ `;
198
+ }
199
+ async lint(entryFile, outputDirectory, toolsPaths) {
200
+ await super.lint(entryFile, outputDirectory, toolsPaths);
201
+ }
202
+ };
203
+
204
+ exports.NetlifyDeployer = NetlifyDeployer;
@@ -0,0 +1 @@
1
+ export { NetlifyDeployer } from './_tsup-dts-rollup.cjs';
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { Deployer } from '@mastra/deployer';
2
- import { execa } from 'execa';
3
1
  import { existsSync, mkdirSync, writeFileSync } from 'fs';
4
2
  import { join } from 'path';
3
+ import { Deployer } from '@mastra/deployer';
4
+ import { DepsService } from '@mastra/deployer/services';
5
+ import { execa } from 'execa';
5
6
 
6
7
  // src/index.ts
7
8
 
@@ -50,7 +51,7 @@ async function getOrCreateSite({ token, name, scope }) {
50
51
  let existingSite;
51
52
  try {
52
53
  existingSite = await findNetlifySite({ token, name, scope });
53
- } catch (e) {
54
+ } catch {
54
55
  }
55
56
  if (existingSite) {
56
57
  return existingSite;
@@ -87,6 +88,18 @@ to = "/.netlify/functions/api/:splat"
87
88
  `
88
89
  );
89
90
  }
91
+ async installDependencies(outputDirectory, rootDir = process.cwd()) {
92
+ const deps = new DepsService(rootDir);
93
+ deps.__setLogger(this.logger);
94
+ await deps.install({
95
+ dir: join(outputDirectory, this.outputDir),
96
+ architecture: {
97
+ os: ["linux"],
98
+ cpu: ["x64"],
99
+ libc: ["gnu"]
100
+ }
101
+ });
102
+ }
90
103
  async deploy(outputDirectory) {
91
104
  const site = await getOrCreateSite({ token: this.token, name: this.projectName || `mastra`, scope: this.scope });
92
105
  const p2 = execa(
@@ -114,25 +127,76 @@ to = "/.netlify/functions/api/:splat"
114
127
  await super.prepare(outputDirectory);
115
128
  this.writeFiles({ dir: join(outputDirectory, this.outputDir) });
116
129
  }
117
- async bundle(entryFile, outputDirectory) {
130
+ async bundle(entryFile, outputDirectory, toolsPaths) {
118
131
  return this._bundle(
119
132
  this.getEntry(),
120
133
  entryFile,
121
134
  outputDirectory,
135
+ toolsPaths,
122
136
  join(outputDirectory, this.outputDir, "netlify", "functions", "api")
123
137
  );
124
138
  }
125
139
  getEntry() {
126
140
  return `
127
- import { handle } from 'hono/netlify'
128
- import { mastra } from '#mastra';
129
- import { createHonoServer } from '#server';
141
+ import { handle } from 'hono/netlify'
142
+ import { mastra } from '#mastra';
143
+ import { createHonoServer } from '#server';
144
+ import { evaluate } from '@mastra/core/eval';
145
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
146
+ import { TABLE_EVALS } from '@mastra/core/storage';
147
+ import { checkEvalStorageFields } from '@mastra/core/utils';
130
148
 
131
- const app = await createHonoServer(mastra);
149
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
150
+ evaluate({
151
+ agentName,
152
+ input,
153
+ metric,
154
+ output,
155
+ runId,
156
+ globalRunId: runId,
157
+ instructions,
158
+ });
159
+ });
132
160
 
133
- export default handle(app)
161
+ if (mastra.getStorage()) {
162
+ // start storage init in the background
163
+ mastra.getStorage().init();
164
+ }
165
+
166
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
167
+ const storage = mastra.getStorage();
168
+ if (storage) {
169
+ // Check for required fields
170
+ const logger = mastra?.getLogger();
171
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
172
+ if (!areFieldsValid) return;
173
+
174
+ await storage.insert({
175
+ tableName: TABLE_EVALS,
176
+ record: {
177
+ input: traceObject.input,
178
+ output: traceObject.output,
179
+ result: JSON.stringify(traceObject.result || {}),
180
+ agent_name: traceObject.agentName,
181
+ metric_name: traceObject.metricName,
182
+ instructions: traceObject.instructions,
183
+ test_info: null,
184
+ global_run_id: traceObject.globalRunId,
185
+ run_id: traceObject.runId,
186
+ created_at: new Date().toISOString(),
187
+ },
188
+ });
189
+ }
190
+ });
191
+
192
+ const app = await createHonoServer(mastra);
193
+
194
+ export default handle(app)
134
195
  `;
135
196
  }
197
+ async lint(entryFile, outputDirectory, toolsPaths) {
198
+ await super.lint(entryFile, outputDirectory, toolsPaths);
199
+ }
136
200
  };
137
201
 
138
202
  export { NetlifyDeployer };
package/package.json CHANGED
@@ -1,39 +1,51 @@
1
1
  {
2
2
  "name": "@mastra/deployer-netlify",
3
- "version": "0.0.0-storage-20250225005900",
3
+ "version": "0.0.0-trigger-playground-ui-package-20250506151043",
4
4
  "description": "",
5
5
  "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
6
9
  "main": "dist/index.js",
7
10
  "types": "dist/index.d.ts",
8
11
  "exports": {
9
12
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
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
+ }
12
21
  },
13
22
  "./package.json": "./package.json"
14
23
  },
15
24
  "keywords": [],
16
25
  "author": "",
17
- "license": "ISC",
26
+ "license": "Elastic-2.0",
18
27
  "dependencies": {
19
28
  "@rollup/plugin-virtual": "^3.0.2",
20
29
  "date-fns": "^4.1.0",
21
- "execa": "^9.3.1",
22
- "netlify-cli": "^18.0.1",
23
- "zod": "^3.24.1",
24
- "@mastra/core": "^0.0.0-storage-20250225005900",
25
- "@mastra/deployer": "^0.0.0-storage-20250225005900"
30
+ "execa": "^9.5.2",
31
+ "netlify-cli": "^19.0.3",
32
+ "zod": "^3.24.2",
33
+ "@mastra/core": "0.0.0-trigger-playground-ui-package-20250506151043",
34
+ "@mastra/deployer": "0.0.0-trigger-playground-ui-package-20250506151043"
26
35
  },
27
36
  "devDependencies": {
28
- "@microsoft/api-extractor": "^7.49.2",
29
- "@types/node": "^22.13.1",
30
- "tsup": "^8.0.1",
31
- "typescript": "^5.7.3",
32
- "vitest": "^3.0.4"
37
+ "@microsoft/api-extractor": "^7.52.5",
38
+ "@types/node": "^20.17.27",
39
+ "eslint": "^9.23.0",
40
+ "tsup": "^8.4.0",
41
+ "typescript": "^5.8.2",
42
+ "vitest": "^3.1.2",
43
+ "@internal/lint": "0.0.0-trigger-playground-ui-package-20250506151043"
33
44
  },
34
45
  "scripts": {
35
- "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
46
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
36
47
  "build:watch": "pnpm build --watch",
37
- "test": "vitest run"
48
+ "test": "vitest run",
49
+ "lint": "eslint ."
38
50
  }
39
51
  }
@@ -1,19 +0,0 @@
1
-
2
- 
3
- > @mastra/deployer-netlify@0.1.5-alpha.1 build /Users/ward/projects/mastra/mastra/deployers/netlify
4
- > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
5
-
6
- CLI Building entry: src/index.ts
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.3.6
9
- TSC Build start
10
- TSC ⚡️ Build success in 1897ms
11
- DTS Build start
12
- CLI Target: es2022
13
- Analysis will use the bundled TypeScript version 5.7.3
14
- Writing package typings: /Users/ward/projects/mastra/mastra/deployers/netlify/dist/_tsup-dts-rollup.d.ts
15
- DTS ⚡️ Build success in 1236ms
16
- CLI Cleaning output folder
17
- ESM Build start
18
- ESM dist/index.js 3.47 KB
19
- ESM ⚡️ Build success in 67ms