@gearbox-protocol/cli-utils 5.65.4 → 5.67.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/dist/Zommand.js CHANGED
@@ -27,7 +27,7 @@ export class Zommand extends Command {
27
27
  throw new Error(`expected object schema, got ${this.#schema._zod.def.type}`);
28
28
  }
29
29
  if (configFile) {
30
- let opt = new Option("--config [file]", "config file");
30
+ let opt = new Option("--config [file]", "config file (or s3 link");
31
31
  if (typeof configFile === "string") {
32
32
  opt = opt.default(configFile);
33
33
  }
@@ -16,9 +16,17 @@ export declare function resolveYamlFiles(file: string, templateData?: TemplateDa
16
16
  * Merges yaml documents, respecting .extends references.
17
17
  * Optionally, performs env-style variable substitution on the config.
18
18
  * Respects YAML anchors and aliases, and merge keys - so that they can be shared across two files
19
+ * Supports s3 links for file
19
20
  *
20
21
  * @param file
21
22
  * @param templateData
22
23
  * @returns
23
24
  */
24
25
  export declare function resolveYamlDoc(file: string, templateData?: TemplateData): Promise<YAML.Document>;
26
+ /**
27
+ * Given file and a relative file path, returns full path of the relative file
28
+ * Supports s3 links for base file
29
+ * @param file
30
+ * @param relativeFile
31
+ */
32
+ export declare function getRelativePath(baseFile: string, relativeFile: string): string;
@@ -1,5 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { dirname, resolve as pathResolve } from "node:path";
3
+ import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
3
4
  import YAML, { isPair, isScalar, isSeq } from "yaml";
4
5
  import getPromisePath from "./getPromisePath.js";
5
6
  /**
@@ -29,13 +30,14 @@ export async function resolveYamlFiles(file, templateData) {
29
30
  * Merges yaml documents, respecting .extends references.
30
31
  * Optionally, performs env-style variable substitution on the config.
31
32
  * Respects YAML anchors and aliases, and merge keys - so that they can be shared across two files
33
+ * Supports s3 links for file
32
34
  *
33
35
  * @param file
34
36
  * @param templateData
35
37
  * @returns
36
38
  */
37
39
  export async function resolveYamlDoc(file, templateData) {
38
- const content = await readFile(file, "utf-8");
40
+ const content = await loadFile(file);
39
41
  // if (templateData) {
40
42
  // const compiled = template(content);
41
43
  // content = compiled(templateData);
@@ -46,7 +48,7 @@ export async function resolveYamlDoc(file, templateData) {
46
48
  const baseFile = cfgRaw.get("extends");
47
49
  const extended = cfgRaw;
48
50
  // extends is a relative path to the base file
49
- cfgRaw = await resolveYamlDoc(pathResolve(dirname(file), baseFile), templateData);
51
+ cfgRaw = await resolveYamlDoc(getRelativePath(file, baseFile), templateData);
50
52
  YAML.visit(extended, {
51
53
  Pair(_, pair, rawPath) {
52
54
  const path = getNodesPath(rawPath);
@@ -88,3 +90,48 @@ function getNodesPath(nodes) {
88
90
  })
89
91
  .filter(Boolean);
90
92
  }
93
+ /**
94
+ * Loads file from s3 or local file system
95
+ * @param file - s3 link or local file path
96
+ * @returns file content
97
+ */
98
+ async function loadFile(file) {
99
+ if (file.startsWith("s3://")) {
100
+ return await loadS3File(file);
101
+ }
102
+ return await readFile(file, "utf-8");
103
+ }
104
+ /**
105
+ * Loads file from s3
106
+ * @param file - s3 link like s3://bucket/path/to/file.yaml
107
+ * @returns file content
108
+ */
109
+ async function loadS3File(file) {
110
+ const url = new URL(file);
111
+ const bucket = url.hostname;
112
+ const key = url.pathname.slice(1);
113
+ const s3 = new S3Client({});
114
+ const response = await s3.send(new GetObjectCommand({
115
+ Bucket: bucket,
116
+ Key: key,
117
+ }));
118
+ if (!response.Body) {
119
+ throw new Error(`file ${file} not found`);
120
+ }
121
+ return response.Body.transformToString("utf-8");
122
+ }
123
+ /**
124
+ * Given file and a relative file path, returns full path of the relative file
125
+ * Supports s3 links for base file
126
+ * @param file
127
+ * @param relativeFile
128
+ */
129
+ export function getRelativePath(baseFile, relativeFile) {
130
+ if (baseFile.startsWith("s3://")) {
131
+ const url = new URL(baseFile);
132
+ const relPathname = pathResolve(dirname(url.pathname), relativeFile);
133
+ url.pathname = relPathname;
134
+ return url.toString();
135
+ }
136
+ return pathResolve(dirname(baseFile), relativeFile);
137
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/cli-utils",
3
3
  "description": "Utils for creating cli apps",
4
- "version": "5.65.4",
4
+ "version": "5.67.0",
5
5
  "homepage": "https://gearbox.fi",
6
6
  "keywords": [
7
7
  "gearbox"
@@ -29,19 +29,20 @@
29
29
  "package:version": "yarn version"
30
30
  },
31
31
  "dependencies": {
32
- "@aws-sdk/client-secrets-manager": "^3.964.0",
33
- "@aws-sdk/client-ssm": "^3.964.0",
34
- "@gearbox-protocol/sdk": ">=12.3.13",
32
+ "@aws-sdk/client-s3": "^3.968.0",
33
+ "@aws-sdk/client-secrets-manager": "^3.968.0",
34
+ "@aws-sdk/client-ssm": "^3.968.0",
35
+ "@gearbox-protocol/sdk": ">=12.3.16",
35
36
  "abitype": "^1.2.3",
36
37
  "commander": "^14.0.2",
37
38
  "lodash-es": "^4.17.22",
38
- "viem": "^2.43.5",
39
+ "viem": "^2.44.2",
39
40
  "yaml": "^2.8.2",
40
41
  "zod": "^4.3.5"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@commander-js/extra-typings": "^14.0.0",
44
45
  "@types/lodash-es": "^4.17.12",
45
- "@types/node": "^25.0.3"
46
+ "@types/node": "^25.0.8"
46
47
  }
47
48
  }