@capsule-run/sdk 0.5.0 → 0.5.1
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 +13 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -144,60 +144,49 @@ Task-level options always override these defaults.
|
|
|
144
144
|
|
|
145
145
|
Tasks can read and write files within directories specified in `allowedFiles`. Any attempt to access files outside these directories is not possible.
|
|
146
146
|
|
|
147
|
-
Node.js built-ins
|
|
147
|
+
Common Node.js built-ins are available. Use the standard `fs` module:
|
|
148
148
|
|
|
149
149
|
```typescript
|
|
150
|
-
import { task
|
|
150
|
+
import { task } from "@capsule-run/sdk";
|
|
151
|
+
import fs from "fs/promises";
|
|
151
152
|
|
|
152
153
|
export const restrictedWriter = task({
|
|
153
154
|
name: "restricted_writer",
|
|
154
155
|
allowedFiles: ["./output"]
|
|
155
156
|
}, async () => {
|
|
156
|
-
await
|
|
157
|
+
await fs.writeFile("./output/result.txt", "result");
|
|
157
158
|
});
|
|
158
159
|
|
|
159
|
-
export const main = task({ name: "main" }, async () => {
|
|
160
|
+
export const main = task({ name: "main", allowedFiles: ["./data"] }, async () => {
|
|
160
161
|
await restrictedWriter();
|
|
161
|
-
return await
|
|
162
|
+
return await fs.readFile("./data/input.txt", "utf8");
|
|
162
163
|
});
|
|
163
164
|
```
|
|
164
165
|
|
|
165
|
-
Available methods:
|
|
166
|
-
- `files.readText(path)` — Read file as string
|
|
167
|
-
- `files.readBytes(path)` — Read file as `Uint8Array`
|
|
168
|
-
- `files.writeText(path, content)` — Write string to file
|
|
169
|
-
- `files.writeBytes(path, data)` — Write bytes to file
|
|
170
|
-
- `files.list(path)` — List directory contents
|
|
171
|
-
- `files.exists(path)` — Check if file exists
|
|
172
|
-
|
|
173
166
|
### Environment Variables
|
|
174
167
|
|
|
175
|
-
Tasks can access environment variables to read configuration, API keys, or other runtime settings. Use the `env
|
|
168
|
+
Tasks can access environment variables to read configuration, API keys, or other runtime settings. Use the standard `process.env`:
|
|
176
169
|
|
|
177
170
|
```typescript
|
|
178
|
-
import { task
|
|
171
|
+
import { task } from "@capsule-run/sdk";
|
|
179
172
|
|
|
180
173
|
export const main = task({
|
|
181
174
|
name: "main",
|
|
182
175
|
envVariables: ["API_KEY"]
|
|
183
176
|
}, () => {
|
|
184
|
-
const apiKey = env.
|
|
177
|
+
const apiKey = process.env.API_KEY;
|
|
185
178
|
return { apiKeySet: apiKey !== undefined };
|
|
186
179
|
});
|
|
187
180
|
```
|
|
188
181
|
|
|
189
|
-
Available methods:
|
|
190
|
-
- `env.get(key)` — Get a specific environment variable (returns `undefined` if not found)
|
|
191
|
-
- `env.has(key)` — Check if an environment variable exists
|
|
192
|
-
- `env.getAll()` — Get all environment variables as an object
|
|
193
|
-
|
|
194
182
|
## Compatibility
|
|
195
183
|
|
|
196
184
|
✅ **Supported:**
|
|
197
|
-
- npm packages and ES modules
|
|
185
|
+
- npm packages and ES modules
|
|
186
|
+
- Common Node.js built-ins. If you have any trouble with a built-in do not hesitate to open an issue.
|
|
198
187
|
|
|
199
|
-
⚠️ **Not
|
|
200
|
-
- Node.js
|
|
188
|
+
⚠️ **Not supported:**
|
|
189
|
+
- Native Node.js addons (C++ bindings)
|
|
201
190
|
|
|
202
191
|
## Links
|
|
203
192
|
|