hereya-cli 0.37.2 → 0.38.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 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.37.2 linux-x64 node-v22.16.0
23
+ hereya-cli/0.38.0 linux-x64 node-v22.16.0
24
24
  $ hereya --help [COMMAND]
25
25
  USAGE
26
26
  $ hereya COMMAND
@@ -88,7 +88,7 @@ EXAMPLES
88
88
  $ hereya add cloudy/docker_postgres
89
89
  ```
90
90
 
91
- _See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/add/index.ts)_
91
+ _See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/add/index.ts)_
92
92
 
93
93
  ## `hereya bootstrap INFRASTRUCTURETYPE`
94
94
 
@@ -113,7 +113,7 @@ EXAMPLES
113
113
  $ hereya bootstrap local
114
114
  ```
115
115
 
116
- _See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/bootstrap/index.ts)_
116
+ _See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/bootstrap/index.ts)_
117
117
 
118
118
  ## `hereya config export-backend [FILE]`
119
119
 
@@ -135,7 +135,7 @@ EXAMPLES
135
135
  $ hereya config export-backend ./path/to/export.json
136
136
  ```
137
137
 
138
- _See code: [src/commands/config/export-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/config/export-backend/index.ts)_
138
+ _See code: [src/commands/config/export-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/config/export-backend/index.ts)_
139
139
 
140
140
  ## `hereya config get-backend`
141
141
 
@@ -152,7 +152,7 @@ EXAMPLES
152
152
  $ hereya config get-backend
153
153
  ```
154
154
 
155
- _See code: [src/commands/config/get-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/config/get-backend/index.ts)_
155
+ _See code: [src/commands/config/get-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/config/get-backend/index.ts)_
156
156
 
157
157
  ## `hereya config import-backend FILE`
158
158
 
@@ -172,7 +172,7 @@ EXAMPLES
172
172
  $ hereya config import-backend ./path/to/cloud-backend.json
173
173
  ```
174
174
 
175
- _See code: [src/commands/config/import-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/config/import-backend/index.ts)_
175
+ _See code: [src/commands/config/import-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/config/import-backend/index.ts)_
176
176
 
177
177
  ## `hereya config use-backend TYPE`
178
178
 
@@ -194,7 +194,7 @@ EXAMPLES
194
194
  $ hereya config use-backend local
195
195
  ```
196
196
 
197
- _See code: [src/commands/config/use-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/config/use-backend/index.ts)_
197
+ _See code: [src/commands/config/use-backend/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/config/use-backend/index.ts)_
198
198
 
199
199
  ## `hereya deploy`
200
200
 
@@ -219,7 +219,7 @@ EXAMPLES
219
219
  $ hereya deploy
220
220
  ```
221
221
 
222
- _See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/deploy/index.ts)_
222
+ _See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/deploy/index.ts)_
223
223
 
224
224
  ## `hereya down`
225
225
 
@@ -246,7 +246,7 @@ EXAMPLES
246
246
  $ hereya down
247
247
  ```
248
248
 
249
- _See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/down/index.ts)_
249
+ _See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/down/index.ts)_
250
250
 
251
251
  ## `hereya env [NAME]`
252
252
 
@@ -277,7 +277,7 @@ EXAMPLES
277
277
  $ hereya env -w dev -l
278
278
  ```
279
279
 
280
- _See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/env/index.ts)_
280
+ _See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/env/index.ts)_
281
281
 
282
282
  ## `hereya env set [NAME]`
283
283
 
@@ -304,7 +304,7 @@ EXAMPLES
304
304
  $ hereya env set FOO -v bar -w dev
305
305
  ```
306
306
 
307
- _See code: [src/commands/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/env/set/index.ts)_
307
+ _See code: [src/commands/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/env/set/index.ts)_
308
308
 
309
309
  ## `hereya help [COMMAND]`
310
310
 
@@ -350,7 +350,7 @@ EXAMPLES
350
350
  $ hereya init myProject -w=defaultWorkspace --chdir=./myProject
351
351
  ```
352
352
 
353
- _See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/init/index.ts)_
353
+ _See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/init/index.ts)_
354
354
 
355
355
  ## `hereya login [URL]`
356
356
 
@@ -374,7 +374,7 @@ EXAMPLES
374
374
  $ hereya login http://localhost:5173
375
375
  ```
376
376
 
377
- _See code: [src/commands/login/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/login/index.ts)_
377
+ _See code: [src/commands/login/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/login/index.ts)_
378
378
 
379
379
  ## `hereya logout`
380
380
 
@@ -391,7 +391,7 @@ EXAMPLES
391
391
  $ hereya logout
392
392
  ```
393
393
 
394
- _See code: [src/commands/logout/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/logout/index.ts)_
394
+ _See code: [src/commands/logout/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/logout/index.ts)_
395
395
 
396
396
  ## `hereya remove PACKAGE`
397
397
 
@@ -418,7 +418,7 @@ EXAMPLES
418
418
  $ hereya remove cloudy/docker_postgres
419
419
  ```
420
420
 
421
- _See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/remove/index.ts)_
421
+ _See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/remove/index.ts)_
422
422
 
423
423
  ## `hereya run CMD`
424
424
 
@@ -444,7 +444,7 @@ EXAMPLES
444
444
  $ hereya run -w uat -- node index.js
445
445
  ```
446
446
 
447
- _See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/run/index.ts)_
447
+ _See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/run/index.ts)_
448
448
 
449
449
  ## `hereya unbootstrap INFRASTRUCTURETYPE`
450
450
 
@@ -469,7 +469,7 @@ EXAMPLES
469
469
  $ hereya unbootstrap local
470
470
  ```
471
471
 
472
- _See code: [src/commands/unbootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/unbootstrap/index.ts)_
472
+ _See code: [src/commands/unbootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/unbootstrap/index.ts)_
473
473
 
474
474
  ## `hereya undeploy`
475
475
 
@@ -494,7 +494,7 @@ EXAMPLES
494
494
  $ hereya undeploy
495
495
  ```
496
496
 
497
- _See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/undeploy/index.ts)_
497
+ _See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/undeploy/index.ts)_
498
498
 
499
499
  ## `hereya up`
500
500
 
@@ -521,7 +521,7 @@ EXAMPLES
521
521
  $ hereya up
522
522
  ```
523
523
 
524
- _See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/up/index.ts)_
524
+ _See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/up/index.ts)_
525
525
 
526
526
  ## `hereya workspace create NAME`
527
527
 
@@ -544,7 +544,7 @@ EXAMPLES
544
544
  $ hereya workspace create dev
545
545
  ```
546
546
 
547
- _See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/create/index.ts)_
547
+ _See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/create/index.ts)_
548
548
 
549
549
  ## `hereya workspace delete NAME`
550
550
 
@@ -564,7 +564,7 @@ EXAMPLES
564
564
  $ hereya workspace delete dev
565
565
  ```
566
566
 
567
- _See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/delete/index.ts)_
567
+ _See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/delete/index.ts)_
568
568
 
569
569
  ## `hereya workspace env [NAME]`
570
570
 
@@ -590,7 +590,7 @@ EXAMPLES
590
590
  $ hereya workspace env myEnv -w dev
591
591
  ```
592
592
 
593
- _See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/env/index.ts)_
593
+ _See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/env/index.ts)_
594
594
 
595
595
  ## `hereya workspace env set`
596
596
 
@@ -614,7 +614,7 @@ EXAMPLES
614
614
  $ hereya workspace env set -w my-workspace -n myVar -v my-value -i aws -s
615
615
  ```
616
616
 
617
- _See code: [src/commands/workspace/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/env/set/index.ts)_
617
+ _See code: [src/commands/workspace/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/env/set/index.ts)_
618
618
 
619
619
  ## `hereya workspace env unset`
620
620
 
@@ -635,7 +635,7 @@ EXAMPLES
635
635
  $ hereya workspace env unset -w my-workspace -n myVar
636
636
  ```
637
637
 
638
- _See code: [src/commands/workspace/env/unset/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/env/unset/index.ts)_
638
+ _See code: [src/commands/workspace/env/unset/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/env/unset/index.ts)_
639
639
 
640
640
  ## `hereya workspace install PACKAGE`
641
641
 
@@ -662,7 +662,7 @@ EXAMPLES
662
662
  $ hereya workspace install hereya/aws-cognito
663
663
  ```
664
664
 
665
- _See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/install/index.ts)_
665
+ _See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/install/index.ts)_
666
666
 
667
667
  ## `hereya workspace list`
668
668
 
@@ -679,7 +679,7 @@ EXAMPLES
679
679
  $ hereya workspace list
680
680
  ```
681
681
 
682
- _See code: [src/commands/workspace/list/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/list/index.ts)_
682
+ _See code: [src/commands/workspace/list/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/list/index.ts)_
683
683
 
684
684
  ## `hereya workspace uninstall PACKAGE`
685
685
 
@@ -706,5 +706,5 @@ EXAMPLES
706
706
  $ hereya workspace uninstall hereya/aws-cognito
707
707
  ```
708
708
 
709
- _See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.37.2/src/commands/workspace/uninstall/index.ts)_
709
+ _See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.38.0/src/commands/workspace/uninstall/index.ts)_
710
710
  <!-- commandsstop -->
@@ -14,3 +14,11 @@ export declare function registerDevice(url: string): Promise<{
14
14
  error: string;
15
15
  success: false;
16
16
  }>;
17
+ export declare function refreshToken(url: string, refreshToken: string): Promise<{
18
+ accessToken: string;
19
+ refreshToken: string;
20
+ success: true;
21
+ } | {
22
+ error: string;
23
+ success: false;
24
+ }>;
@@ -147,3 +147,23 @@ async function waitForAuthorizationCode(port) {
147
147
  });
148
148
  });
149
149
  }
150
+ export async function refreshToken(url, refreshToken) {
151
+ const response = await fetch(`${url}/auth/refresh`, {
152
+ headers: {
153
+ Authorization: `Bearer ${refreshToken}`,
154
+ },
155
+ method: 'POST',
156
+ });
157
+ if (!response.ok) {
158
+ return {
159
+ error: `Failed to refresh token: ${JSON.stringify(await response.json())}`,
160
+ success: false,
161
+ };
162
+ }
163
+ const result = (await response.json());
164
+ return {
165
+ accessToken: result.data.accessToken,
166
+ refreshToken: result.data.refreshToken,
167
+ success: true,
168
+ };
169
+ }
@@ -1,10 +1,24 @@
1
1
  import { getAwsConfig } from '../infrastructure/aws-config.js';
2
2
  import { CloudBackend } from './cloud/cloud-backend.js';
3
- import { getCloudCredentials, loadBackendConfig } from './config.js';
3
+ import { refreshToken } from './cloud/login.js';
4
+ import { getCloudCredentials, loadBackendConfig, saveCloudCredentials } from './config.js';
4
5
  import { LocalFileBackend } from './local.js';
5
6
  import { S3FileBackend } from './s3.js';
6
7
  let backend;
7
8
  let currentBackendType;
9
+ function isTokenExpired(token) {
10
+ try {
11
+ const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
12
+ const expirationTime = payload.exp * 1000; // Convert to milliseconds
13
+ const currentTime = Date.now();
14
+ // Refresh token if it expires in less than 1 hour
15
+ return currentTime > expirationTime - 1 * 60 * 60 * 1000;
16
+ }
17
+ catch {
18
+ // If we can't decode the token, assume it's expired
19
+ return true;
20
+ }
21
+ }
8
22
  export async function getBackend(type) {
9
23
  if (backend) {
10
24
  return backend;
@@ -20,10 +34,26 @@ export async function getBackend(type) {
20
34
  if (!credentials) {
21
35
  throw new Error('Cloud credentials not found. Please run `hereya login` first.');
22
36
  }
37
+ let { accessToken, refreshToken: refreshTokenValue } = credentials;
38
+ // Check if token is expired and refresh if necessary
39
+ if (isTokenExpired(accessToken)) {
40
+ const refreshResult = await refreshToken(backendConfig.cloud.url, refreshTokenValue);
41
+ if (!refreshResult.success) {
42
+ throw new Error('Failed to refresh token. Please run `hereya login` again.');
43
+ }
44
+ accessToken = refreshResult.accessToken;
45
+ refreshTokenValue = refreshResult.refreshToken;
46
+ await saveCloudCredentials({
47
+ accessToken,
48
+ clientId: backendConfig.cloud.clientId,
49
+ refreshToken: refreshTokenValue,
50
+ url: backendConfig.cloud.url,
51
+ });
52
+ }
23
53
  backend = new CloudBackend({
24
- accessToken: credentials.accessToken,
54
+ accessToken,
25
55
  clientId: backendConfig.cloud.clientId,
26
- refreshToken: credentials.refreshToken,
56
+ refreshToken: refreshTokenValue,
27
57
  url: backendConfig.cloud.url,
28
58
  });
29
59
  break;
@@ -978,31 +978,6 @@
978
978
  "index.js"
979
979
  ]
980
980
  },
981
- "workspace:list": {
982
- "aliases": [],
983
- "args": {},
984
- "description": "List workspaces.",
985
- "examples": [
986
- "<%= config.bin %> <%= command.id %>"
987
- ],
988
- "flags": {},
989
- "hasDynamicHelp": false,
990
- "hiddenAliases": [],
991
- "id": "workspace:list",
992
- "pluginAlias": "hereya-cli",
993
- "pluginName": "hereya-cli",
994
- "pluginType": "core",
995
- "strict": true,
996
- "enableJsonFlag": false,
997
- "isESM": true,
998
- "relativePath": [
999
- "dist",
1000
- "commands",
1001
- "workspace",
1002
- "list",
1003
- "index.js"
1004
- ]
1005
- },
1006
981
  "workspace:uninstall": {
1007
982
  "aliases": [],
1008
983
  "args": {
@@ -1067,6 +1042,31 @@
1067
1042
  "index.js"
1068
1043
  ]
1069
1044
  },
1045
+ "workspace:list": {
1046
+ "aliases": [],
1047
+ "args": {},
1048
+ "description": "List workspaces.",
1049
+ "examples": [
1050
+ "<%= config.bin %> <%= command.id %>"
1051
+ ],
1052
+ "flags": {},
1053
+ "hasDynamicHelp": false,
1054
+ "hiddenAliases": [],
1055
+ "id": "workspace:list",
1056
+ "pluginAlias": "hereya-cli",
1057
+ "pluginName": "hereya-cli",
1058
+ "pluginType": "core",
1059
+ "strict": true,
1060
+ "enableJsonFlag": false,
1061
+ "isESM": true,
1062
+ "relativePath": [
1063
+ "dist",
1064
+ "commands",
1065
+ "workspace",
1066
+ "list",
1067
+ "index.js"
1068
+ ]
1069
+ },
1070
1070
  "workspace:env:set": {
1071
1071
  "aliases": [],
1072
1072
  "args": {},
@@ -1183,5 +1183,5 @@
1183
1183
  ]
1184
1184
  }
1185
1185
  },
1186
- "version": "0.37.2"
1186
+ "version": "0.38.0"
1187
1187
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hereya-cli",
3
3
  "description": "Infrastructure as Package",
4
- "version": "0.37.2",
4
+ "version": "0.38.0",
5
5
  "author": "Hereya Developers",
6
6
  "bin": {
7
7
  "hereya": "./bin/run.js"
@@ -34,6 +34,7 @@
34
34
  "@oclif/prettier-config": "^0.2.1",
35
35
  "@oclif/test": "^4.1.9",
36
36
  "@types/chai": "^5.0.1",
37
+ "@types/jsonwebtoken": "^9.0.9",
37
38
  "@types/mocha": "^10.0.10",
38
39
  "@types/mock-fs": "^4.13.4",
39
40
  "@types/node": "^22",
@@ -44,6 +45,7 @@
44
45
  "eslint-config-oclif": "^6.0.10",
45
46
  "eslint-config-prettier": "^10.0.1",
46
47
  "eslint-plugin-chai-friendly": "^1.0.1",
48
+ "jsonwebtoken": "^9.0.2",
47
49
  "mocha": "^11.1.0",
48
50
  "mock-fs": "^5.5.0",
49
51
  "nock": "^14.0.3",