@mastra/deployer-netlify 0.0.0-storage-20250225005900 → 0.0.0-support-d1-client-20250701191943

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,13 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ export declare class NetlifyDeployer extends Deployer {
4
+ constructor();
5
+ protected installDependencies(outputDirectory: string, rootDir?: string): Promise<void>;
6
+ deploy(): Promise<void>;
7
+ prepare(outputDirectory: string): Promise<void>;
8
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
9
+ private getEntry;
10
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
11
+ }
12
+
13
+ export { }
@@ -1,38 +1,13 @@
1
1
  import { Deployer } from '@mastra/deployer';
2
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
3
  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>;
4
+ constructor();
5
+ protected installDependencies(outputDirectory: string, rootDir?: string): Promise<void>;
6
+ deploy(): Promise<void>;
33
7
  prepare(outputDirectory: string): Promise<void>;
34
- bundle(entryFile: string, outputDirectory: string): Promise<void>;
8
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
35
9
  private getEntry;
10
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
36
11
  }
37
12
 
38
13
  export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var process = require('process');
5
+ var deployer = require('@mastra/deployer');
6
+ var services = require('@mastra/deployer/services');
7
+ var esm = require('fs-extra/esm');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var process__default = /*#__PURE__*/_interopDefault(process);
12
+
13
+ // src/index.ts
14
+ var NetlifyDeployer = class extends deployer.Deployer {
15
+ constructor() {
16
+ super({ name: "NETLIFY" });
17
+ this.outputDir = path.join(".netlify", "v1", "functions", "api");
18
+ }
19
+ async installDependencies(outputDirectory, rootDir = process__default.default.cwd()) {
20
+ const deps = new services.DepsService(rootDir);
21
+ deps.__setLogger(this.logger);
22
+ await deps.install({
23
+ dir: path.join(outputDirectory, this.outputDir),
24
+ architecture: {
25
+ os: ["linux"],
26
+ cpu: ["x64"],
27
+ libc: ["gnu"]
28
+ }
29
+ });
30
+ }
31
+ async deploy() {
32
+ this.logger?.info("Deploying to Netlify failed. Please use the Netlify dashboard to deploy.");
33
+ }
34
+ async prepare(outputDirectory) {
35
+ await super.prepare(outputDirectory);
36
+ }
37
+ async bundle(entryFile, outputDirectory, toolsPaths) {
38
+ const result = await this._bundle(
39
+ this.getEntry(),
40
+ entryFile,
41
+ outputDirectory,
42
+ toolsPaths,
43
+ path.join(outputDirectory, this.outputDir)
44
+ );
45
+ await esm.writeJson(path.join(outputDirectory, ".netlify", "v1", "config.json"), {
46
+ redirects: [
47
+ {
48
+ force: true,
49
+ from: "/*",
50
+ to: "/.netlify/functions/api/:splat",
51
+ status: 200
52
+ }
53
+ ]
54
+ });
55
+ await esm.move(path.join(outputDirectory, ".netlify", "v1"), path.join(process__default.default.cwd(), ".netlify", "v1"), {
56
+ overwrite: true
57
+ });
58
+ return result;
59
+ }
60
+ getEntry() {
61
+ return `
62
+ import { handle } from 'hono/netlify'
63
+ import { mastra } from '#mastra';
64
+ import { createHonoServer } from '#server';
65
+ import { evaluate } from '@mastra/core/eval';
66
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
67
+ import { TABLE_EVALS } from '@mastra/core/storage';
68
+ import { checkEvalStorageFields } from '@mastra/core/utils';
69
+
70
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
71
+ evaluate({
72
+ agentName,
73
+ input,
74
+ metric,
75
+ output,
76
+ runId,
77
+ globalRunId: runId,
78
+ instructions,
79
+ });
80
+ });
81
+
82
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
83
+ const storage = mastra.getStorage();
84
+ if (storage) {
85
+ // Check for required fields
86
+ const logger = mastra.getLogger();
87
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
88
+ if (!areFieldsValid) return;
89
+
90
+ await storage.insert({
91
+ tableName: TABLE_EVALS,
92
+ record: {
93
+ input: traceObject.input,
94
+ output: traceObject.output,
95
+ result: JSON.stringify(traceObject.result || {}),
96
+ agent_name: traceObject.agentName,
97
+ metric_name: traceObject.metricName,
98
+ instructions: traceObject.instructions,
99
+ test_info: null,
100
+ global_run_id: traceObject.globalRunId,
101
+ run_id: traceObject.runId,
102
+ created_at: new Date().toISOString(),
103
+ },
104
+ });
105
+ }
106
+ });
107
+
108
+ const app = await createHonoServer(mastra);
109
+
110
+ export default handle(app)
111
+ `;
112
+ }
113
+ async lint(entryFile, outputDirectory, toolsPaths) {
114
+ await super.lint(entryFile, outputDirectory, toolsPaths);
115
+ }
116
+ };
117
+
118
+ exports.NetlifyDeployer = NetlifyDeployer;
@@ -0,0 +1 @@
1
+ export { NetlifyDeployer } from './_tsup-dts-rollup.cjs';
package/dist/index.js CHANGED
@@ -1,138 +1,112 @@
1
- import { Deployer } from '@mastra/deployer';
2
- import { execa } from 'execa';
3
- import { existsSync, mkdirSync, writeFileSync } from 'fs';
4
1
  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
- }
2
+ import process from 'process';
3
+ import { Deployer } from '@mastra/deployer';
4
+ import { DepsService } from '@mastra/deployer/services';
5
+ import { writeJson, move } from 'fs-extra/esm';
60
6
 
61
7
  // src/index.ts
62
8
  var NetlifyDeployer = class extends Deployer {
63
- scope;
64
- projectName;
65
- token;
66
- constructor({ scope, projectName, token }) {
9
+ constructor() {
67
10
  super({ name: "NETLIFY" });
68
- this.scope = scope;
69
- this.projectName = projectName;
70
- this.token = token;
11
+ this.outputDir = join(".netlify", "v1", "functions", "api");
71
12
  }
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)
13
+ async installDependencies(outputDirectory, rootDir = process.cwd()) {
14
+ const deps = new DepsService(rootDir);
15
+ deps.__setLogger(this.logger);
16
+ await deps.install({
17
+ dir: join(outputDirectory, this.outputDir),
18
+ architecture: {
19
+ os: ["linux"],
20
+ cpu: ["x64"],
21
+ libc: ["gnu"]
108
22
  }
109
- );
110
- p2.stdout.pipe(process.stdout);
111
- await p2;
23
+ });
24
+ }
25
+ async deploy() {
26
+ this.logger?.info("Deploying to Netlify failed. Please use the Netlify dashboard to deploy.");
112
27
  }
113
28
  async prepare(outputDirectory) {
114
29
  await super.prepare(outputDirectory);
115
- this.writeFiles({ dir: join(outputDirectory, this.outputDir) });
116
30
  }
117
- async bundle(entryFile, outputDirectory) {
118
- return this._bundle(
31
+ async bundle(entryFile, outputDirectory, toolsPaths) {
32
+ const result = await this._bundle(
119
33
  this.getEntry(),
120
34
  entryFile,
121
35
  outputDirectory,
122
- join(outputDirectory, this.outputDir, "netlify", "functions", "api")
36
+ toolsPaths,
37
+ join(outputDirectory, this.outputDir)
123
38
  );
39
+ await writeJson(join(outputDirectory, ".netlify", "v1", "config.json"), {
40
+ redirects: [
41
+ {
42
+ force: true,
43
+ from: "/*",
44
+ to: "/.netlify/functions/api/:splat",
45
+ status: 200
46
+ }
47
+ ]
48
+ });
49
+ await move(join(outputDirectory, ".netlify", "v1"), join(process.cwd(), ".netlify", "v1"), {
50
+ overwrite: true
51
+ });
52
+ return result;
124
53
  }
125
54
  getEntry() {
126
55
  return `
127
- import { handle } from 'hono/netlify'
128
- import { mastra } from '#mastra';
129
- import { createHonoServer } from '#server';
56
+ import { handle } from 'hono/netlify'
57
+ import { mastra } from '#mastra';
58
+ import { createHonoServer } from '#server';
59
+ import { evaluate } from '@mastra/core/eval';
60
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
61
+ import { TABLE_EVALS } from '@mastra/core/storage';
62
+ import { checkEvalStorageFields } from '@mastra/core/utils';
63
+
64
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
65
+ evaluate({
66
+ agentName,
67
+ input,
68
+ metric,
69
+ output,
70
+ runId,
71
+ globalRunId: runId,
72
+ instructions,
73
+ });
74
+ });
130
75
 
131
- const app = await createHonoServer(mastra);
76
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
77
+ const storage = mastra.getStorage();
78
+ if (storage) {
79
+ // Check for required fields
80
+ const logger = mastra.getLogger();
81
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
82
+ if (!areFieldsValid) return;
132
83
 
133
- export default handle(app)
84
+ await storage.insert({
85
+ tableName: TABLE_EVALS,
86
+ record: {
87
+ input: traceObject.input,
88
+ output: traceObject.output,
89
+ result: JSON.stringify(traceObject.result || {}),
90
+ agent_name: traceObject.agentName,
91
+ metric_name: traceObject.metricName,
92
+ instructions: traceObject.instructions,
93
+ test_info: null,
94
+ global_run_id: traceObject.globalRunId,
95
+ run_id: traceObject.runId,
96
+ created_at: new Date().toISOString(),
97
+ },
98
+ });
99
+ }
100
+ });
101
+
102
+ const app = await createHonoServer(mastra);
103
+
104
+ export default handle(app)
134
105
  `;
135
106
  }
107
+ async lint(entryFile, outputDirectory, toolsPaths) {
108
+ await super.lint(entryFile, outputDirectory, toolsPaths);
109
+ }
136
110
  };
137
111
 
138
112
  export { NetlifyDeployer };
package/package.json CHANGED
@@ -1,39 +1,55 @@
1
1
  {
2
2
  "name": "@mastra/deployer-netlify",
3
- "version": "0.0.0-storage-20250225005900",
3
+ "version": "0.0.0-support-d1-client-20250701191943",
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.6.0",
31
+ "fs-extra": "^11.3.0",
32
+ "zod": "^3.25.67",
33
+ "@mastra/deployer": "0.0.0-support-d1-client-20250701191943"
26
34
  },
27
35
  "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"
36
+ "@microsoft/api-extractor": "^7.52.8",
37
+ "@types/fs-extra": "^11.0.4",
38
+ "@types/node": "^20.19.0",
39
+ "eslint": "^9.29.0",
40
+ "tsup": "^8.5.0",
41
+ "typescript": "^5.8.3",
42
+ "vitest": "^3.2.4",
43
+ "@internal/lint": "0.0.0-support-d1-client-20250701191943",
44
+ "@mastra/core": "0.0.0-support-d1-client-20250701191943"
45
+ },
46
+ "peerDependencies": {
47
+ "@mastra/core": "0.0.0-support-d1-client-20250701191943"
33
48
  },
34
49
  "scripts": {
35
- "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
50
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
36
51
  "build:watch": "pnpm build --watch",
37
- "test": "vitest run"
52
+ "test": "vitest run",
53
+ "lint": "eslint ."
38
54
  }
39
55
  }
@@ -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