freestyle 0.0.4 → 0.1.44

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/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # Freestyle SDK
2
+
3
+ Learn more at [docs.freestyle.sh](https://docs.freestyle.sh)
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install freestyle-sandboxes
9
+ ```
10
+
11
+ ## CLI Usage
12
+
13
+ The Freestyle SDK includes a command-line interface for managing your Freestyle resources.
14
+
15
+ ### Setup
16
+
17
+ Set the environment variable with your API key:
18
+
19
+ ```bash
20
+ export FREESTYLE_API_KEY="your-api-key"
21
+ ```
22
+
23
+ Or create a `.env` file in your project directory:
24
+
25
+ ```
26
+ FREESTYLE_API_KEY=your-api-key
27
+ ```
28
+
29
+ ### Commands
30
+
31
+ #### Virtual Machines
32
+
33
+ ```bash
34
+ # Create a new VM
35
+ freestyle vm create --name my-vm
36
+
37
+ # Create a VM from a snapshot (for debugging)
38
+ freestyle vm create --snapshot <snapshot-id>
39
+
40
+ # Create a VM with domain
41
+ freestyle vm create --domain myapp.example.com --port 3000
42
+
43
+ # Create VM and SSH into it (auto-deletes on exit)
44
+ freestyle vm create --ssh
45
+
46
+ # Create VM from snapshot and SSH into it
47
+ freestyle vm create --snapshot <snapshot-id> --ssh
48
+
49
+ # List all VMs
50
+ freestyle vm list
51
+
52
+ # SSH into a VM
53
+ freestyle vm ssh <vmId>
54
+
55
+ # SSH into a VM and delete it on exit
56
+ freestyle vm ssh <vmId> --delete-on-exit
57
+
58
+ # Execute a command on a VM
59
+ freestyle vm exec <vmId> "ls -la"
60
+
61
+ # Delete a VM
62
+ freestyle vm delete <vmId>
63
+ ```
64
+
65
+ #### Serverless Deployments
66
+
67
+ ```bash
68
+ # Deploy from inline code
69
+ freestyle deploy --code "export default () => 'Hello World'"
70
+
71
+ # Deploy from a file
72
+ freestyle deploy --file ./my-function.js
73
+
74
+ # Deploy from a Git repository
75
+ freestyle deploy --repo <repoId>
76
+
77
+ # Add environment variables
78
+ freestyle deploy --code "..." --env API_KEY=secret --env DEBUG=true
79
+ ```
80
+
81
+ #### Serverless Runs
82
+
83
+ ```bash
84
+ # Execute a one-off function from inline code
85
+ freestyle run --code "console.log('Hello!')"
86
+
87
+ # Execute from a file
88
+ freestyle run --file ./script.js
89
+ ```
90
+
91
+ #### Utilities
92
+
93
+ ```bash
94
+ # Get help for any command
95
+ freestyle --help
96
+ freestyle vm --help
97
+ ```
98
+
99
+ ## SDK Usage
100
+
101
+ ```ts
102
+ import { freestyle } from "freestyle-sandboxes";
103
+
104
+ // Create and store code with git.
105
+ const { repoId } = await freestyle.git.repos.create({
106
+ source: {
107
+ url: "https://github.com/freestyle-sh/freestyle-base-nextjs-shadcn",
108
+ },
109
+ });
110
+
111
+ // Create a new branch from the default branch
112
+ const repo = freestyle.git.repos.ref({ repoId });
113
+ const { name, sha } = await repo.branches.create({
114
+ name: "feature/something",
115
+ });
116
+
117
+ // Create commits with files (text and binary)
118
+ const { commit } = await repo.commits.create({
119
+ message: "Add new feature",
120
+ branch: "feature/something",
121
+ files: [
122
+ { path: "README.md", content: "# My Project" },
123
+ { path: "logo.png", content: base64Image, encoding: "base64" }
124
+ ],
125
+ author: { name: "John Doe", email: "john@example.com" }
126
+ });
127
+
128
+ // Develop code with VMs.
129
+ const { vm } = await freestyle.vms.create({
130
+ gitRepos: [{ repo: repoId, path: "/repo" }],
131
+ });
132
+
133
+ await vm.fs.writeTextFile("/repo/api/hello.js", "...");
134
+
135
+ // Deploy your code to the internet.
136
+ const { deploymentId } = await freestyle.serverless.deployments.create({
137
+ repo: repoId,
138
+ });
139
+
140
+ // Verify a custom domain and point it at your deployment.
141
+ const { record } = await freestyle.domains.verifications.create({
142
+ domain: "example.com",
143
+ });
144
+
145
+ console.log(record);
146
+
147
+ await freestyle.domains.verifications.complete({
148
+ domain: "example.com",
149
+ });
150
+
151
+ await freestyle.domains.mappings.create({
152
+ domain: "example.com",
153
+ deploymentId: deploymentId,
154
+ });
155
+
156
+ // test your app with lightweight JS workers
157
+ for (let i = 0; i < 10; i++) {
158
+ freestyle.serverless.runs.create({
159
+ code: `export default () => {
160
+ fetch("https://example.com/api/hello")
161
+ .then(res => res.json())
162
+ })
163
+ `,
164
+ });
165
+ }
166
+ ```