futrou 2.0.22 → 2.0.23

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 CHANGED
@@ -21,6 +21,22 @@ yarn global add futrou
21
21
 
22
22
  Once installed, you can access the CLI using the `npx futrou` command.
23
23
 
24
+ ## Infrastructure as code
25
+
26
+ The npm package also exports a small JavaScript API for building `futrou.json`:
27
+
28
+ ```js
29
+ const { Config } = require('futrou');
30
+
31
+ const config = new Config({ workspace: 'acme', project: 'website' })
32
+ .serverlet({ name: 'web', image: 'nginx:latest', ram: 128, cpu: 100 });
33
+
34
+ require('fs').writeFileSync('futrou.json', config.toJson() + '\n');
35
+ ```
36
+
37
+ `toJs()` returns an ESM default-export module and `toJsonSchema()` returns the
38
+ generated Futrou JSON Schema bundled with the package.
39
+
24
40
  ## Documentation
25
41
 
26
42
  For more detailed guides on how to use the CLI, please visit [docs.futrou.com](https://docs.futrou.com).
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/config.cjs ADDED
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ const SCHEMA_URL = 'https://futrou.com/futrou.schema.json';
4
+
5
+ class Resource {
6
+ constructor(properties = {}) {
7
+ Object.assign(this, properties);
8
+ }
9
+
10
+ toJSON() {
11
+ return omitEmpty(Object.fromEntries(Object.entries(this).map(([key, value]) => [key, serialize(value)])));
12
+ }
13
+ }
14
+
15
+ class Serverlet extends Resource {}
16
+ class DNS extends Resource {}
17
+ class Proxy extends Resource {}
18
+ class Volume extends Resource {}
19
+ class Cron extends Resource {}
20
+
21
+ class Config {
22
+ constructor(properties = {}) {
23
+ this.$schema = properties.$schema || SCHEMA_URL;
24
+ this.workspace = properties.workspace;
25
+ this.project = properties.project;
26
+ this.serverlets = toResources(properties.serverlets, Serverlet);
27
+ this.dns = toResources(properties.dns, DNS);
28
+ this.proxies = toResources(properties.proxies, Proxy);
29
+ this.volumes = toResources(properties.volumes, Volume);
30
+ this.crons = toResources(properties.crons, Cron);
31
+ }
32
+
33
+ serverlet(properties) { this.serverlets.push(asResource(properties, Serverlet)); return this; }
34
+ dnsZone(properties) { this.dns.push(asResource(properties, DNS)); return this; }
35
+ proxy(properties) { this.proxies.push(asResource(properties, Proxy)); return this; }
36
+ volume(properties) { this.volumes.push(asResource(properties, Volume)); return this; }
37
+ cron(properties) { this.crons.push(asResource(properties, Cron)); return this; }
38
+
39
+ toJSON() {
40
+ return omitEmpty({
41
+ $schema: this.$schema,
42
+ workspace: this.workspace,
43
+ project: this.project,
44
+ serverlets: this.serverlets,
45
+ dns: this.dns,
46
+ proxies: this.proxies,
47
+ volumes: this.volumes,
48
+ crons: this.crons,
49
+ });
50
+ }
51
+
52
+ toJson(space = 2) { return JSON.stringify(this.toJSON(), null, space); }
53
+ toJs() { return `export default ${this.toJson(2)};\n`; }
54
+ toJsonSchema() { return require('./futrou.schema.json'); }
55
+ }
56
+
57
+ function asResource(value, Type) { return value instanceof Type ? value : new Type(value); }
58
+ function toResources(values, Type) { return (values || []).map(value => asResource(value, Type)); }
59
+ function serialize(value) {
60
+ if (value && typeof value.toJSON === 'function') return value.toJSON();
61
+ if (Array.isArray(value)) return value.map(serialize);
62
+ if (value && typeof value === 'object') return omitEmpty(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, serialize(item)])));
63
+ return value;
64
+ }
65
+ function omitEmpty(object) {
66
+ return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0)));
67
+ }
68
+
69
+ module.exports = { Config, Serverlet, DNS, Proxy, Volume, Cron, SCHEMA_URL };
@@ -0,0 +1,470 @@
1
+ {
2
+ "$id": "https://futrou.com/futrou.schema.json",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "additionalProperties": true,
5
+ "description": "Declarative Futrou project configuration.",
6
+ "properties": {
7
+ "$schema": {
8
+ "description": "URL of the Futrou JSON Schema used by editors for validation and completion.",
9
+ "format": "uri",
10
+ "type": "string"
11
+ },
12
+ "crons": {
13
+ "description": "Scheduled HTTP or code jobs for the project.",
14
+ "items": {
15
+ "additionalProperties": true,
16
+ "description": "Common Futrou API resource fields.",
17
+ "properties": {
18
+ "body": {
19
+ "type": "string"
20
+ },
21
+ "code": {
22
+ "type": "string"
23
+ },
24
+ "createdAt": {
25
+ "format": "date-time",
26
+ "type": "string"
27
+ },
28
+ "cronPlan": {},
29
+ "cronPlanId": {
30
+ "type": "string"
31
+ },
32
+ "displayName": {
33
+ "description": "Human-readable resource name.",
34
+ "maxLength": 255,
35
+ "minLength": 1,
36
+ "type": "string"
37
+ },
38
+ "domain": {
39
+ "description": "Domain name assigned to the resource.",
40
+ "maxLength": 255,
41
+ "minLength": 1,
42
+ "type": "string"
43
+ },
44
+ "enabled": {
45
+ "type": "boolean"
46
+ },
47
+ "headers": {},
48
+ "id": {
49
+ "description": "Futrou resource identifier.",
50
+ "maxLength": 255,
51
+ "minLength": 1,
52
+ "type": "string"
53
+ },
54
+ "method": {
55
+ "type": "string"
56
+ },
57
+ "name": {
58
+ "description": "Resource name.",
59
+ "maxLength": 255,
60
+ "minLength": 1,
61
+ "type": "string"
62
+ },
63
+ "project": {},
64
+ "projectId": {
65
+ "type": "string"
66
+ },
67
+ "region": {},
68
+ "regionId": {
69
+ "type": "string"
70
+ },
71
+ "schedule": {
72
+ "type": "string"
73
+ },
74
+ "startedAt": {
75
+ "format": "date-time",
76
+ "type": "string"
77
+ },
78
+ "type": {},
79
+ "updatedAt": {
80
+ "format": "date-time",
81
+ "type": "string"
82
+ },
83
+ "url": {
84
+ "format": "uri",
85
+ "type": "string"
86
+ },
87
+ "workspace": {},
88
+ "workspaceId": {
89
+ "type": "string"
90
+ }
91
+ },
92
+ "type": "object"
93
+ },
94
+ "type": "array"
95
+ },
96
+ "dns": {
97
+ "description": "DNS zones and records managed by this project.",
98
+ "items": {
99
+ "additionalProperties": true,
100
+ "description": "Common Futrou API resource fields.",
101
+ "properties": {
102
+ "displayName": {
103
+ "description": "Human-readable resource name.",
104
+ "maxLength": 255,
105
+ "minLength": 1,
106
+ "type": "string"
107
+ },
108
+ "domain": {
109
+ "description": "Domain name assigned to the resource.",
110
+ "maxLength": 255,
111
+ "minLength": 1,
112
+ "type": "string"
113
+ },
114
+ "id": {
115
+ "description": "Futrou resource identifier.",
116
+ "maxLength": 255,
117
+ "minLength": 1,
118
+ "type": "string"
119
+ },
120
+ "name": {
121
+ "description": "Resource name.",
122
+ "maxLength": 255,
123
+ "minLength": 1,
124
+ "type": "string"
125
+ },
126
+ "priority": {
127
+ "description": "DNS record priority.",
128
+ "maximum": 65535,
129
+ "minimum": 0,
130
+ "type": "integer"
131
+ },
132
+ "projectId": {
133
+ "maxLength": 255,
134
+ "minLength": 1,
135
+ "type": "string"
136
+ },
137
+ "records": {
138
+ "items": {
139
+ "additionalProperties": true,
140
+ "description": "Common Futrou API resource fields.",
141
+ "properties": {
142
+ "displayName": {
143
+ "description": "Human-readable resource name.",
144
+ "maxLength": 255,
145
+ "minLength": 1,
146
+ "type": "string"
147
+ },
148
+ "domain": {
149
+ "description": "Domain name assigned to the resource.",
150
+ "maxLength": 255,
151
+ "minLength": 1,
152
+ "type": "string"
153
+ },
154
+ "id": {
155
+ "description": "Futrou resource identifier.",
156
+ "maxLength": 255,
157
+ "minLength": 1,
158
+ "type": "string"
159
+ },
160
+ "name": {
161
+ "description": "Resource name.",
162
+ "maxLength": 255,
163
+ "minLength": 1,
164
+ "type": "string"
165
+ },
166
+ "priority": {
167
+ "maximum": 65535,
168
+ "minimum": 0,
169
+ "type": "integer"
170
+ },
171
+ "ttl": {
172
+ "maximum": 2147483647,
173
+ "minimum": 0,
174
+ "type": "integer"
175
+ },
176
+ "type": {
177
+ "type": "string"
178
+ },
179
+ "value": {
180
+ "type": "string"
181
+ }
182
+ },
183
+ "type": "object"
184
+ },
185
+ "type": "array"
186
+ },
187
+ "ttl": {
188
+ "description": "DNS time-to-live in seconds.",
189
+ "maximum": 2147483647,
190
+ "minimum": 0,
191
+ "type": "integer"
192
+ },
193
+ "workspaceId": {
194
+ "maxLength": 255,
195
+ "minLength": 1,
196
+ "type": "string"
197
+ }
198
+ },
199
+ "type": "object"
200
+ },
201
+ "type": "array"
202
+ },
203
+ "locks": {
204
+ "additionalProperties": {
205
+ "type": "string"
206
+ },
207
+ "description": "CLI-maintained opaque resource lock fingerprints.",
208
+ "type": "object"
209
+ },
210
+ "project": {
211
+ "description": "Project name or ID used as the deployment target.",
212
+ "maxLength": 255,
213
+ "minLength": 1,
214
+ "type": "string"
215
+ },
216
+ "proxies": {
217
+ "description": "HTTP, TCP, or UDP proxies managed by this project.",
218
+ "items": {
219
+ "additionalProperties": true,
220
+ "description": "Common Futrou API resource fields.",
221
+ "properties": {
222
+ "compress": {
223
+ "type": "boolean"
224
+ },
225
+ "createdAt": {
226
+ "type": "string"
227
+ },
228
+ "displayName": {
229
+ "description": "Human-readable resource name.",
230
+ "maxLength": 255,
231
+ "minLength": 1,
232
+ "type": "string"
233
+ },
234
+ "domain": {
235
+ "description": "Domain name assigned to the resource.",
236
+ "maxLength": 255,
237
+ "minLength": 1,
238
+ "type": "string"
239
+ },
240
+ "enforceHttps": {
241
+ "type": "boolean"
242
+ },
243
+ "followRedirects": {
244
+ "type": "boolean"
245
+ },
246
+ "id": {
247
+ "description": "Futrou resource identifier.",
248
+ "maxLength": 255,
249
+ "minLength": 1,
250
+ "type": "string"
251
+ },
252
+ "name": {
253
+ "description": "Resource name.",
254
+ "maxLength": 255,
255
+ "minLength": 1,
256
+ "type": "string"
257
+ },
258
+ "port": {
259
+ "description": "Public proxy port (1–65535).",
260
+ "maximum": 65535,
261
+ "minimum": 1,
262
+ "type": "integer"
263
+ },
264
+ "preserveHeaders": {
265
+ "type": "boolean"
266
+ },
267
+ "preserveHost": {
268
+ "type": "boolean"
269
+ },
270
+ "preservePath": {
271
+ "type": "boolean"
272
+ },
273
+ "preserveQuery": {
274
+ "type": "boolean"
275
+ },
276
+ "status": {
277
+ "type": "string"
278
+ },
279
+ "strategy": {
280
+ "type": "string"
281
+ },
282
+ "target": {
283
+ "minLength": 1,
284
+ "type": "string"
285
+ },
286
+ "type": {
287
+ "enum": [
288
+ "http",
289
+ "tcp",
290
+ "udp"
291
+ ],
292
+ "type": "string"
293
+ },
294
+ "updatedAt": {
295
+ "type": "string"
296
+ },
297
+ "verifyTls": {
298
+ "type": "boolean"
299
+ }
300
+ },
301
+ "type": "object"
302
+ },
303
+ "type": "array"
304
+ },
305
+ "serverlets": {
306
+ "description": "Serverlets to create or update in this project.",
307
+ "items": {
308
+ "additionalProperties": true,
309
+ "description": "Common Futrou API resource fields.",
310
+ "properties": {
311
+ "cpu": {
312
+ "description": "CPU allocation in millicores.",
313
+ "maximum": 32000,
314
+ "minimum": 10,
315
+ "type": "integer"
316
+ },
317
+ "createdAt": {
318
+ "type": "string"
319
+ },
320
+ "displayName": {
321
+ "description": "Human-readable resource name.",
322
+ "maxLength": 255,
323
+ "minLength": 1,
324
+ "type": "string"
325
+ },
326
+ "domain": {
327
+ "description": "Domain name assigned to the resource.",
328
+ "maxLength": 255,
329
+ "minLength": 1,
330
+ "type": "string"
331
+ },
332
+ "env": {},
333
+ "id": {
334
+ "description": "Futrou resource identifier.",
335
+ "maxLength": 255,
336
+ "minLength": 1,
337
+ "type": "string"
338
+ },
339
+ "image": {
340
+ "description": "Container image to run.",
341
+ "minLength": 1,
342
+ "type": "string"
343
+ },
344
+ "instances": {
345
+ "description": "Current number of serverlet instances.",
346
+ "minimum": 0,
347
+ "type": "integer"
348
+ },
349
+ "maxInstances": {
350
+ "description": "Maximum number of running instances.",
351
+ "maximum": 1000,
352
+ "minimum": 0,
353
+ "type": "integer"
354
+ },
355
+ "minInstances": {
356
+ "description": "Minimum number of running instances.",
357
+ "maximum": 1000,
358
+ "minimum": 0,
359
+ "type": "integer"
360
+ },
361
+ "name": {
362
+ "description": "Resource name.",
363
+ "maxLength": 255,
364
+ "minLength": 1,
365
+ "type": "string"
366
+ },
367
+ "networkId": {
368
+ "maxLength": 255,
369
+ "minLength": 1,
370
+ "type": "string"
371
+ },
372
+ "ports": {},
373
+ "projectId": {
374
+ "maxLength": 255,
375
+ "minLength": 1,
376
+ "type": "string"
377
+ },
378
+ "ram": {
379
+ "description": "Memory allocation in MiB.",
380
+ "maximum": 262144,
381
+ "minimum": 32,
382
+ "type": "integer"
383
+ },
384
+ "runtime": {
385
+ "maxLength": 255,
386
+ "minLength": 1,
387
+ "type": "string"
388
+ },
389
+ "scaling": {},
390
+ "serverletPlanId": {
391
+ "maxLength": 255,
392
+ "minLength": 1,
393
+ "type": "string"
394
+ },
395
+ "state": {
396
+ "maxLength": 255,
397
+ "minLength": 1,
398
+ "type": "string"
399
+ },
400
+ "updatedAt": {
401
+ "type": "string"
402
+ },
403
+ "volumes": {},
404
+ "workspaceId": {
405
+ "maxLength": 255,
406
+ "minLength": 1,
407
+ "type": "string"
408
+ }
409
+ },
410
+ "type": "object"
411
+ },
412
+ "type": "array"
413
+ },
414
+ "volumes": {
415
+ "description": "Persistent volumes available to the project.",
416
+ "items": {
417
+ "additionalProperties": true,
418
+ "description": "Common Futrou API resource fields.",
419
+ "properties": {
420
+ "createdAt": {
421
+ "type": "string"
422
+ },
423
+ "displayName": {
424
+ "description": "Human-readable resource name.",
425
+ "maxLength": 255,
426
+ "minLength": 1,
427
+ "type": "string"
428
+ },
429
+ "domain": {
430
+ "description": "Domain name assigned to the resource.",
431
+ "maxLength": 255,
432
+ "minLength": 1,
433
+ "type": "string"
434
+ },
435
+ "id": {
436
+ "description": "Futrou resource identifier.",
437
+ "maxLength": 255,
438
+ "minLength": 1,
439
+ "type": "string"
440
+ },
441
+ "name": {
442
+ "description": "Resource name.",
443
+ "maxLength": 255,
444
+ "minLength": 1,
445
+ "type": "string"
446
+ },
447
+ "sizeGb": {
448
+ "minimum": 0,
449
+ "type": "number"
450
+ },
451
+ "type": {
452
+ "type": "string"
453
+ },
454
+ "updatedAt": {
455
+ "type": "string"
456
+ }
457
+ },
458
+ "type": "object"
459
+ },
460
+ "type": "array"
461
+ },
462
+ "workspace": {
463
+ "description": "Workspace name or ID that owns this project.",
464
+ "maxLength": 255,
465
+ "minLength": 1,
466
+ "type": "string"
467
+ }
468
+ },
469
+ "type": "object"
470
+ }
package/index.d.ts CHANGED
@@ -1 +1,33 @@
1
- export {};
1
+ export const SCHEMA_URL: 'https://futrou.com/futrou.schema.json';
2
+
3
+ export interface ResourceProperties { [key: string]: unknown }
4
+
5
+ export class Serverlet { constructor(properties?: ResourceProperties); toJSON(): ResourceProperties }
6
+ export class DNS { constructor(properties?: ResourceProperties); toJSON(): ResourceProperties }
7
+ export class Proxy { constructor(properties?: ResourceProperties); toJSON(): ResourceProperties }
8
+ export class Volume { constructor(properties?: ResourceProperties); toJSON(): ResourceProperties }
9
+ export class Cron { constructor(properties?: ResourceProperties); toJSON(): ResourceProperties }
10
+
11
+ export interface ConfigProperties {
12
+ $schema?: string;
13
+ workspace?: string;
14
+ project?: string;
15
+ serverlets?: Array<Serverlet | ResourceProperties>;
16
+ dns?: Array<DNS | ResourceProperties>;
17
+ proxies?: Array<Proxy | ResourceProperties>;
18
+ volumes?: Array<Volume | ResourceProperties>;
19
+ crons?: Array<Cron | ResourceProperties>;
20
+ }
21
+
22
+ export class Config {
23
+ constructor(properties?: ConfigProperties);
24
+ serverlet(properties: Serverlet | ResourceProperties): this;
25
+ dnsZone(properties: DNS | ResourceProperties): this;
26
+ proxy(properties: Proxy | ResourceProperties): this;
27
+ volume(properties: Volume | ResourceProperties): this;
28
+ cron(properties: Cron | ResourceProperties): this;
29
+ toJSON(): ConfigProperties;
30
+ toJson(space?: number): string;
31
+ toJs(): string;
32
+ toJsonSchema(): Record<string, unknown>;
33
+ }
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "futrou",
3
3
  "productName": "Futrou CLI",
4
- "version": "2.0.22",
4
+ "version": "2.0.23",
5
5
  "description": "Futrou CLI - Deploy and manage Futrou Cloud from your terminal.",
6
- "main": "./index.cjs",
6
+ "main": "./config.cjs",
7
7
  "types": "./index.d.ts",
8
8
  "bin": {
9
9
  "futrou": "./index.cjs",
10
10
  "futrou-cli": "./index.cjs"
11
11
  },
12
+ "exports": {
13
+ ".": "./config.cjs",
14
+ "./cli": "./index.cjs",
15
+ "./futrou.schema.json": "./futrou.schema.json"
16
+ },
12
17
  "os": [
13
18
  "linux",
14
19
  "darwin",
@@ -34,4 +39,4 @@
34
39
  "type": "git",
35
40
  "url": "git+https://github.com/futrou/futrou-cli.git"
36
41
  }
37
- }
42
+ }