hereya-cli 0.33.0 → 0.35.0
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 +64 -23
- package/dist/backend/cloud/cloud-backend.d.ts +27 -0
- package/dist/backend/cloud/cloud-backend.js +334 -0
- package/dist/backend/cloud/login.d.ts +16 -0
- package/dist/backend/cloud/login.js +145 -0
- package/dist/backend/cloud/logout.d.ts +9 -0
- package/dist/backend/cloud/logout.js +12 -0
- package/dist/backend/cloud/utils.d.ts +3 -0
- package/dist/backend/cloud/utils.js +6 -0
- package/dist/backend/common.d.ts +3 -0
- package/dist/backend/config.d.ts +30 -3
- package/dist/backend/config.js +36 -2
- package/dist/backend/file.js +2 -2
- package/dist/backend/index.d.ts +3 -1
- package/dist/backend/index.js +26 -3
- package/dist/backend/secrets.d.ts +5 -0
- package/dist/backend/secrets.js +66 -0
- package/dist/commands/bootstrap/index.js +15 -7
- package/dist/commands/init/index.js +1 -1
- package/dist/commands/login/index.d.ts +9 -0
- package/dist/commands/login/index.js +27 -0
- package/dist/commands/logout/index.d.ts +6 -0
- package/dist/commands/logout/index.js +23 -0
- package/dist/commands/unbootstrap/index.js +12 -1
- package/dist/executor/local.js +3 -1
- package/dist/infrastructure/aws-config.js +16 -5
- package/dist/infrastructure/aws.js +8 -23
- package/oclif.manifest.json +56 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g hereya-cli
|
|
|
20
20
|
$ hereya COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ hereya (--version)
|
|
23
|
-
hereya-cli/0.
|
|
23
|
+
hereya-cli/0.35.0 linux-x64 node-v22.15.0
|
|
24
24
|
$ hereya --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ hereya COMMAND
|
|
@@ -39,6 +39,8 @@ USAGE
|
|
|
39
39
|
* [`hereya env set [NAME]`](#hereya-env-set-name)
|
|
40
40
|
* [`hereya help [COMMAND]`](#hereya-help-command)
|
|
41
41
|
* [`hereya init PROJECT`](#hereya-init-project)
|
|
42
|
+
* [`hereya login URL`](#hereya-login-url)
|
|
43
|
+
* [`hereya logout`](#hereya-logout)
|
|
42
44
|
* [`hereya remove PACKAGE`](#hereya-remove-package)
|
|
43
45
|
* [`hereya run CMD`](#hereya-run-cmd)
|
|
44
46
|
* [`hereya unbootstrap INFRASTRUCTURETYPE`](#hereya-unbootstrap-infrastructuretype)
|
|
@@ -84,7 +86,7 @@ EXAMPLES
|
|
|
84
86
|
$ hereya add cloudy/docker_postgres
|
|
85
87
|
```
|
|
86
88
|
|
|
87
|
-
_See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
89
|
+
_See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/add/index.ts)_
|
|
88
90
|
|
|
89
91
|
## `hereya bootstrap INFRASTRUCTURETYPE`
|
|
90
92
|
|
|
@@ -109,7 +111,7 @@ EXAMPLES
|
|
|
109
111
|
$ hereya bootstrap local
|
|
110
112
|
```
|
|
111
113
|
|
|
112
|
-
_See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
114
|
+
_See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/bootstrap/index.ts)_
|
|
113
115
|
|
|
114
116
|
## `hereya config get-backend`
|
|
115
117
|
|
|
@@ -126,7 +128,7 @@ EXAMPLES
|
|
|
126
128
|
$ hereya config get-backend
|
|
127
129
|
```
|
|
128
130
|
|
|
129
|
-
_See code: [src/commands/config/get-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
131
|
+
_See code: [src/commands/config/get-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/config/get-backend/index.ts)_
|
|
130
132
|
|
|
131
133
|
## `hereya config use-backend TYPE`
|
|
132
134
|
|
|
@@ -148,7 +150,7 @@ EXAMPLES
|
|
|
148
150
|
$ hereya config use-backend local
|
|
149
151
|
```
|
|
150
152
|
|
|
151
|
-
_See code: [src/commands/config/use-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
153
|
+
_See code: [src/commands/config/use-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/config/use-backend/index.ts)_
|
|
152
154
|
|
|
153
155
|
## `hereya deploy`
|
|
154
156
|
|
|
@@ -173,7 +175,7 @@ EXAMPLES
|
|
|
173
175
|
$ hereya deploy
|
|
174
176
|
```
|
|
175
177
|
|
|
176
|
-
_See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
178
|
+
_See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/deploy/index.ts)_
|
|
177
179
|
|
|
178
180
|
## `hereya down`
|
|
179
181
|
|
|
@@ -200,7 +202,7 @@ EXAMPLES
|
|
|
200
202
|
$ hereya down
|
|
201
203
|
```
|
|
202
204
|
|
|
203
|
-
_See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
205
|
+
_See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/down/index.ts)_
|
|
204
206
|
|
|
205
207
|
## `hereya env [NAME]`
|
|
206
208
|
|
|
@@ -231,7 +233,7 @@ EXAMPLES
|
|
|
231
233
|
$ hereya env -w dev -l
|
|
232
234
|
```
|
|
233
235
|
|
|
234
|
-
_See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
236
|
+
_See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/env/index.ts)_
|
|
235
237
|
|
|
236
238
|
## `hereya env set [NAME]`
|
|
237
239
|
|
|
@@ -258,7 +260,7 @@ EXAMPLES
|
|
|
258
260
|
$ hereya env set FOO -v bar -w dev
|
|
259
261
|
```
|
|
260
262
|
|
|
261
|
-
_See code: [src/commands/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
263
|
+
_See code: [src/commands/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/env/set/index.ts)_
|
|
262
264
|
|
|
263
265
|
## `hereya help [COMMAND]`
|
|
264
266
|
|
|
@@ -304,7 +306,46 @@ EXAMPLES
|
|
|
304
306
|
$ hereya init myProject -w=defaultWorkspace --chdir=./myProject
|
|
305
307
|
```
|
|
306
308
|
|
|
307
|
-
_See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
309
|
+
_See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/init/index.ts)_
|
|
310
|
+
|
|
311
|
+
## `hereya login URL`
|
|
312
|
+
|
|
313
|
+
Login to the Hereya Cloud backend
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
USAGE
|
|
317
|
+
$ hereya login URL
|
|
318
|
+
|
|
319
|
+
ARGUMENTS
|
|
320
|
+
URL URL of the Hereya Cloud backend
|
|
321
|
+
|
|
322
|
+
DESCRIPTION
|
|
323
|
+
Login to the Hereya Cloud backend
|
|
324
|
+
|
|
325
|
+
EXAMPLES
|
|
326
|
+
$ hereya login https://cloud.hereya.dev
|
|
327
|
+
|
|
328
|
+
$ hereya login http://localhost:5173
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
_See code: [src/commands/login/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/login/index.ts)_
|
|
332
|
+
|
|
333
|
+
## `hereya logout`
|
|
334
|
+
|
|
335
|
+
Logout from Hereya Cloud
|
|
336
|
+
|
|
337
|
+
```
|
|
338
|
+
USAGE
|
|
339
|
+
$ hereya logout
|
|
340
|
+
|
|
341
|
+
DESCRIPTION
|
|
342
|
+
Logout from Hereya Cloud
|
|
343
|
+
|
|
344
|
+
EXAMPLES
|
|
345
|
+
$ hereya logout
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
_See code: [src/commands/logout/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/logout/index.ts)_
|
|
308
349
|
|
|
309
350
|
## `hereya remove PACKAGE`
|
|
310
351
|
|
|
@@ -331,7 +372,7 @@ EXAMPLES
|
|
|
331
372
|
$ hereya remove cloudy/docker_postgres
|
|
332
373
|
```
|
|
333
374
|
|
|
334
|
-
_See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
375
|
+
_See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/remove/index.ts)_
|
|
335
376
|
|
|
336
377
|
## `hereya run CMD`
|
|
337
378
|
|
|
@@ -357,7 +398,7 @@ EXAMPLES
|
|
|
357
398
|
$ hereya run -w uat -- node index.js
|
|
358
399
|
```
|
|
359
400
|
|
|
360
|
-
_See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
401
|
+
_See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/run/index.ts)_
|
|
361
402
|
|
|
362
403
|
## `hereya unbootstrap INFRASTRUCTURETYPE`
|
|
363
404
|
|
|
@@ -382,7 +423,7 @@ EXAMPLES
|
|
|
382
423
|
$ hereya unbootstrap local
|
|
383
424
|
```
|
|
384
425
|
|
|
385
|
-
_See code: [src/commands/unbootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
426
|
+
_See code: [src/commands/unbootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/unbootstrap/index.ts)_
|
|
386
427
|
|
|
387
428
|
## `hereya undeploy`
|
|
388
429
|
|
|
@@ -407,7 +448,7 @@ EXAMPLES
|
|
|
407
448
|
$ hereya undeploy
|
|
408
449
|
```
|
|
409
450
|
|
|
410
|
-
_See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
451
|
+
_See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/undeploy/index.ts)_
|
|
411
452
|
|
|
412
453
|
## `hereya up`
|
|
413
454
|
|
|
@@ -434,7 +475,7 @@ EXAMPLES
|
|
|
434
475
|
$ hereya up
|
|
435
476
|
```
|
|
436
477
|
|
|
437
|
-
_See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
478
|
+
_See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/up/index.ts)_
|
|
438
479
|
|
|
439
480
|
## `hereya workspace create NAME`
|
|
440
481
|
|
|
@@ -457,7 +498,7 @@ EXAMPLES
|
|
|
457
498
|
$ hereya workspace create dev
|
|
458
499
|
```
|
|
459
500
|
|
|
460
|
-
_See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
501
|
+
_See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/create/index.ts)_
|
|
461
502
|
|
|
462
503
|
## `hereya workspace delete NAME`
|
|
463
504
|
|
|
@@ -477,7 +518,7 @@ EXAMPLES
|
|
|
477
518
|
$ hereya workspace delete dev
|
|
478
519
|
```
|
|
479
520
|
|
|
480
|
-
_See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
521
|
+
_See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/delete/index.ts)_
|
|
481
522
|
|
|
482
523
|
## `hereya workspace env [NAME]`
|
|
483
524
|
|
|
@@ -503,7 +544,7 @@ EXAMPLES
|
|
|
503
544
|
$ hereya workspace env myEnv -w dev
|
|
504
545
|
```
|
|
505
546
|
|
|
506
|
-
_See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
547
|
+
_See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/env/index.ts)_
|
|
507
548
|
|
|
508
549
|
## `hereya workspace env set`
|
|
509
550
|
|
|
@@ -527,7 +568,7 @@ EXAMPLES
|
|
|
527
568
|
$ hereya workspace env set -w my-workspace -n myVar -v my-value -i aws -s
|
|
528
569
|
```
|
|
529
570
|
|
|
530
|
-
_See code: [src/commands/workspace/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
571
|
+
_See code: [src/commands/workspace/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/env/set/index.ts)_
|
|
531
572
|
|
|
532
573
|
## `hereya workspace env unset`
|
|
533
574
|
|
|
@@ -548,7 +589,7 @@ EXAMPLES
|
|
|
548
589
|
$ hereya workspace env unset -w my-workspace -n myVar
|
|
549
590
|
```
|
|
550
591
|
|
|
551
|
-
_See code: [src/commands/workspace/env/unset/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
592
|
+
_See code: [src/commands/workspace/env/unset/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/env/unset/index.ts)_
|
|
552
593
|
|
|
553
594
|
## `hereya workspace install PACKAGE`
|
|
554
595
|
|
|
@@ -575,7 +616,7 @@ EXAMPLES
|
|
|
575
616
|
$ hereya workspace install hereya/aws-cognito
|
|
576
617
|
```
|
|
577
618
|
|
|
578
|
-
_See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
619
|
+
_See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/install/index.ts)_
|
|
579
620
|
|
|
580
621
|
## `hereya workspace list`
|
|
581
622
|
|
|
@@ -592,7 +633,7 @@ EXAMPLES
|
|
|
592
633
|
$ hereya workspace list
|
|
593
634
|
```
|
|
594
635
|
|
|
595
|
-
_See code: [src/commands/workspace/list/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
636
|
+
_See code: [src/commands/workspace/list/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/list/index.ts)_
|
|
596
637
|
|
|
597
638
|
## `hereya workspace uninstall PACKAGE`
|
|
598
639
|
|
|
@@ -619,5 +660,5 @@ EXAMPLES
|
|
|
619
660
|
$ hereya workspace uninstall hereya/aws-cognito
|
|
620
661
|
```
|
|
621
662
|
|
|
622
|
-
_See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.
|
|
663
|
+
_See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.35.0/src/commands/workspace/uninstall/index.ts)_
|
|
623
664
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Config } from '../../lib/config/common.js';
|
|
2
|
+
import { AddPackageToWorkspaceInput, AddPackageToWorkspaceOutput, Backend, CreateWorkspaceInput, CreateWorkspaceOutput, DeleteWorkspaceInput, DeleteWorkspaceOutput, GetProvisioningIdInput, GetProvisioningIdOutput, GetStateInput, GetStateOutput, GetWorkspaceEnvInput, GetWorkspaceEnvOutput, GetWorkspaceOutput, InitProjectInput, InitProjectOutput, RemovePackageFromWorkspaceInput, RemovePackageFromWorkspaceOutput, SetEnvVarInput, SetEnvVarOutput, UnsetEnvVarInput, UnsetEnvVarOutput } from '../common.js';
|
|
3
|
+
interface CloudBackendConfig {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
clientId: string;
|
|
6
|
+
refreshToken: string;
|
|
7
|
+
url: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class CloudBackend implements Backend {
|
|
10
|
+
private readonly config;
|
|
11
|
+
constructor(config: CloudBackendConfig);
|
|
12
|
+
addPackageToWorkspace(input: AddPackageToWorkspaceInput): Promise<AddPackageToWorkspaceOutput>;
|
|
13
|
+
createWorkspace(input: CreateWorkspaceInput): Promise<CreateWorkspaceOutput>;
|
|
14
|
+
deleteWorkspace(input: DeleteWorkspaceInput): Promise<DeleteWorkspaceOutput>;
|
|
15
|
+
getProvisioningId(input: GetProvisioningIdInput): Promise<GetProvisioningIdOutput>;
|
|
16
|
+
getState(input: GetStateInput): Promise<GetStateOutput>;
|
|
17
|
+
getWorkspace(name: string): Promise<GetWorkspaceOutput>;
|
|
18
|
+
getWorkspaceEnv(input: GetWorkspaceEnvInput): Promise<GetWorkspaceEnvOutput>;
|
|
19
|
+
init(input: InitProjectInput): Promise<InitProjectOutput>;
|
|
20
|
+
listWorkspaces(): Promise<string[]>;
|
|
21
|
+
removePackageFromWorkspace(input: RemovePackageFromWorkspaceInput): Promise<RemovePackageFromWorkspaceOutput>;
|
|
22
|
+
saveState(config: Config, workspace?: string): Promise<void>;
|
|
23
|
+
setEnvVar(input: SetEnvVarInput): Promise<SetEnvVarOutput>;
|
|
24
|
+
unsetEnvVar(input: UnsetEnvVarInput): Promise<UnsetEnvVarOutput>;
|
|
25
|
+
private convertWorkspace;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
export class CloudBackend {
|
|
2
|
+
config;
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
}
|
|
6
|
+
async addPackageToWorkspace(input) {
|
|
7
|
+
const formData = new FormData();
|
|
8
|
+
formData.append('package', input.package);
|
|
9
|
+
formData.append('infra', input.infra);
|
|
10
|
+
formData.append('env', JSON.stringify(input.env));
|
|
11
|
+
if (input.parameters) {
|
|
12
|
+
formData.append('parameters', JSON.stringify(input.parameters));
|
|
13
|
+
}
|
|
14
|
+
const response = await fetch(`${this.config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/packages`, {
|
|
15
|
+
body: formData,
|
|
16
|
+
headers: {
|
|
17
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
18
|
+
},
|
|
19
|
+
method: 'POST',
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
return {
|
|
23
|
+
reason: JSON.stringify(await response.json()),
|
|
24
|
+
success: false,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const result = await response.json();
|
|
28
|
+
return {
|
|
29
|
+
success: true,
|
|
30
|
+
workspace: this.convertWorkspace(result.workspace),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async createWorkspace(input) {
|
|
34
|
+
const formData = new FormData();
|
|
35
|
+
formData.append('name', input.name);
|
|
36
|
+
if (input.mirrorOf) {
|
|
37
|
+
formData.append('mirrorOf', input.mirrorOf);
|
|
38
|
+
}
|
|
39
|
+
const response = await fetch(`${this.config.url}/api/workspaces`, {
|
|
40
|
+
body: formData,
|
|
41
|
+
headers: {
|
|
42
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
43
|
+
},
|
|
44
|
+
method: 'POST',
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
return {
|
|
48
|
+
reason: JSON.stringify(await response.json()),
|
|
49
|
+
success: false,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const result = await response.json();
|
|
53
|
+
return {
|
|
54
|
+
isNew: true,
|
|
55
|
+
success: true,
|
|
56
|
+
workspace: {
|
|
57
|
+
id: result.workspace.id,
|
|
58
|
+
name: result.workspace.name,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async deleteWorkspace(input) {
|
|
63
|
+
const response = await fetch(`${this.config.url}/api/workspaces/${encodeURIComponent(input.name)}`, {
|
|
64
|
+
headers: {
|
|
65
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
66
|
+
},
|
|
67
|
+
method: 'DELETE',
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
return {
|
|
71
|
+
reason: JSON.stringify(await response.json()),
|
|
72
|
+
success: false,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async getProvisioningId(input) {
|
|
80
|
+
const formData = new FormData();
|
|
81
|
+
formData.append('packageCanonicalName', input.packageCanonicalName);
|
|
82
|
+
formData.append('logicalId', input.logicalId);
|
|
83
|
+
if (input.project) {
|
|
84
|
+
formData.append('project', input.project);
|
|
85
|
+
}
|
|
86
|
+
if (input.workspace) {
|
|
87
|
+
formData.append('workspace', input.workspace);
|
|
88
|
+
}
|
|
89
|
+
const response = await fetch(`${this.config.url}/api/provisioning-id`, {
|
|
90
|
+
body: formData,
|
|
91
|
+
headers: {
|
|
92
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
93
|
+
},
|
|
94
|
+
method: 'POST',
|
|
95
|
+
});
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
return {
|
|
98
|
+
reason: JSON.stringify(await response.json()),
|
|
99
|
+
success: false,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const result = await response.json();
|
|
103
|
+
return {
|
|
104
|
+
id: result.provisioningId.id,
|
|
105
|
+
success: true,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async getState(input) {
|
|
109
|
+
const url = new URL(`${this.config.url}/api/projects/${encodeURIComponent(input.project)}/state`);
|
|
110
|
+
url.searchParams.append('workspace', input.workspace);
|
|
111
|
+
const response = await fetch(url, {
|
|
112
|
+
headers: {
|
|
113
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
114
|
+
},
|
|
115
|
+
method: 'GET',
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
return {
|
|
119
|
+
found: false,
|
|
120
|
+
reason: JSON.stringify(await response.json()),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const result = await response.json();
|
|
124
|
+
if (!result.success) {
|
|
125
|
+
return {
|
|
126
|
+
found: false,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const deploy = {};
|
|
130
|
+
for (const item of result.config.deploy) {
|
|
131
|
+
deploy[item.name] = { version: item.version };
|
|
132
|
+
}
|
|
133
|
+
const packages = {};
|
|
134
|
+
for (const item of result.config.packages) {
|
|
135
|
+
packages[item.name] = { version: item.version };
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
config: {
|
|
139
|
+
deploy,
|
|
140
|
+
packages,
|
|
141
|
+
project: input.project,
|
|
142
|
+
workspace: input.workspace,
|
|
143
|
+
},
|
|
144
|
+
found: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
async getWorkspace(name) {
|
|
148
|
+
const response = await fetch(`${this.config.url}/api/workspaces/${encodeURIComponent(name)}`, {
|
|
149
|
+
headers: {
|
|
150
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
151
|
+
},
|
|
152
|
+
method: 'GET',
|
|
153
|
+
});
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
const error = await response.json();
|
|
156
|
+
return {
|
|
157
|
+
error: JSON.stringify(error),
|
|
158
|
+
found: true,
|
|
159
|
+
hasError: true,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const result = await response.json();
|
|
163
|
+
return {
|
|
164
|
+
found: true,
|
|
165
|
+
hasError: false,
|
|
166
|
+
workspace: this.convertWorkspace(result.workspace),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async getWorkspaceEnv(input) {
|
|
170
|
+
const workspace$ = await this.getWorkspace(input.workspace);
|
|
171
|
+
if (!workspace$.found) {
|
|
172
|
+
return {
|
|
173
|
+
reason: `Workspace ${input.workspace} not found`,
|
|
174
|
+
success: false,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (workspace$.hasError) {
|
|
178
|
+
return {
|
|
179
|
+
reason: workspace$.error,
|
|
180
|
+
success: false,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
env: workspace$.workspace.env ?? {},
|
|
185
|
+
success: true,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
async init(input) {
|
|
189
|
+
const formData = new FormData();
|
|
190
|
+
formData.append('name', input.project);
|
|
191
|
+
formData.append('workspace', input.workspace);
|
|
192
|
+
const response = await fetch(`${this.config.url}/api/projects`, {
|
|
193
|
+
body: formData,
|
|
194
|
+
headers: {
|
|
195
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
196
|
+
},
|
|
197
|
+
method: 'POST',
|
|
198
|
+
});
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
throw new Error(JSON.stringify(await response.json()));
|
|
201
|
+
}
|
|
202
|
+
const result = await response.json();
|
|
203
|
+
return {
|
|
204
|
+
project: {
|
|
205
|
+
id: result.project.id,
|
|
206
|
+
name: result.project.name,
|
|
207
|
+
},
|
|
208
|
+
workspace: {
|
|
209
|
+
id: result.project.defaultWorkspace.id,
|
|
210
|
+
name: result.project.defaultWorkspace.name,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async listWorkspaces() {
|
|
215
|
+
const response = await fetch(`${this.config.url}/api/workspaces`, {
|
|
216
|
+
headers: {
|
|
217
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
218
|
+
},
|
|
219
|
+
method: 'GET',
|
|
220
|
+
});
|
|
221
|
+
if (!response.ok) {
|
|
222
|
+
throw new Error(JSON.stringify(await response.json()));
|
|
223
|
+
}
|
|
224
|
+
const result = await response.json();
|
|
225
|
+
return result.workspaces.map((workspace) => workspace.name);
|
|
226
|
+
}
|
|
227
|
+
async removePackageFromWorkspace(input) {
|
|
228
|
+
const response = await fetch(`${this.config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/packages/${encodeURIComponent(input.package)}`, {
|
|
229
|
+
headers: {
|
|
230
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
231
|
+
},
|
|
232
|
+
method: 'DELETE',
|
|
233
|
+
});
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
return {
|
|
236
|
+
reason: JSON.stringify(await response.json()),
|
|
237
|
+
success: false,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
const result = await response.json();
|
|
241
|
+
return {
|
|
242
|
+
success: true,
|
|
243
|
+
workspace: this.convertWorkspace(result.workspace),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
async saveState(config, workspace) {
|
|
247
|
+
const formData = new FormData();
|
|
248
|
+
if (workspace) {
|
|
249
|
+
formData.append('workspace', workspace);
|
|
250
|
+
}
|
|
251
|
+
if (config.deploy) {
|
|
252
|
+
const deployArray = Object.entries(config.deploy).map(([name, { version }]) => ({ name, version })).sort((a, b) => a.name.localeCompare(b.name));
|
|
253
|
+
formData.append('deploy', JSON.stringify(deployArray));
|
|
254
|
+
}
|
|
255
|
+
if (config.packages) {
|
|
256
|
+
const packagesArray = Object.entries(config.packages).map(([name, { version }]) => ({ name, version })).sort((a, b) => a.name.localeCompare(b.name));
|
|
257
|
+
formData.append('packages', JSON.stringify(packagesArray));
|
|
258
|
+
}
|
|
259
|
+
const response = await fetch(`${this.config.url}/api/projects/${encodeURIComponent(config.project)}/state`, {
|
|
260
|
+
body: formData,
|
|
261
|
+
headers: {
|
|
262
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
263
|
+
},
|
|
264
|
+
method: 'POST',
|
|
265
|
+
});
|
|
266
|
+
if (!response.ok) {
|
|
267
|
+
throw new Error(JSON.stringify(await response.json()));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async setEnvVar(input) {
|
|
271
|
+
const formData = new FormData();
|
|
272
|
+
formData.append('key', input.name);
|
|
273
|
+
formData.append('value', input.value);
|
|
274
|
+
formData.append('infrastructure', input.infrastructure);
|
|
275
|
+
const response = await fetch(`${this.config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/env`, {
|
|
276
|
+
body: formData,
|
|
277
|
+
headers: {
|
|
278
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
279
|
+
},
|
|
280
|
+
method: 'POST',
|
|
281
|
+
});
|
|
282
|
+
if (!response.ok) {
|
|
283
|
+
return {
|
|
284
|
+
reason: JSON.stringify(await response.json()),
|
|
285
|
+
success: false,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
success: true,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
async unsetEnvVar(input) {
|
|
293
|
+
const response = await fetch(`${this.config.url}/api/workspaces/${encodeURIComponent(input.workspace)}/env/${encodeURIComponent(input.name)}`, {
|
|
294
|
+
headers: {
|
|
295
|
+
'Authorization': `Bearer ${this.config.accessToken}`,
|
|
296
|
+
},
|
|
297
|
+
method: 'DELETE',
|
|
298
|
+
});
|
|
299
|
+
if (!response.ok) {
|
|
300
|
+
return {
|
|
301
|
+
reason: JSON.stringify(await response.json()),
|
|
302
|
+
success: false,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
success: true,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
convertWorkspace(workspace) {
|
|
310
|
+
const env = {};
|
|
311
|
+
for (const pkg of workspace.packages) {
|
|
312
|
+
for (const e of pkg.env) {
|
|
313
|
+
env[e.key] = `${e.infrastructure}:${e.value}`;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
for (const e of workspace.env) {
|
|
317
|
+
env[e.key] = `${e.infrastructure}:${e.value}`;
|
|
318
|
+
}
|
|
319
|
+
const packages = {};
|
|
320
|
+
for (const pkg of workspace.packages) {
|
|
321
|
+
packages[pkg.name] = {
|
|
322
|
+
parameters: pkg.parameters,
|
|
323
|
+
version: pkg.version,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
env,
|
|
328
|
+
id: workspace.id,
|
|
329
|
+
mirrorOf: workspace.mirrorOf?.name,
|
|
330
|
+
name: workspace.name,
|
|
331
|
+
packages,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function loginToCloudBackend(url: string): Promise<{
|
|
2
|
+
accessToken: string;
|
|
3
|
+
clientId: string;
|
|
4
|
+
refreshToken: string;
|
|
5
|
+
success: true;
|
|
6
|
+
} | {
|
|
7
|
+
error: string;
|
|
8
|
+
success: false;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function registerDevice(url: string): Promise<{
|
|
11
|
+
clientId: string;
|
|
12
|
+
success: true;
|
|
13
|
+
} | {
|
|
14
|
+
error: string;
|
|
15
|
+
success: false;
|
|
16
|
+
}>;
|