@openfort/cli 0.1.7 → 0.1.9

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
@@ -98,14 +98,6 @@ openfort skills add
98
98
  | `embedded-wallet` | Configure embedded wallet (Shield) API keys |
99
99
  | `message` | Message utilities (e.g. keccak256 hashing) |
100
100
 
101
- ## Alias
102
-
103
- The CLI is also available as `of`:
104
-
105
- ```bash
106
- of accounts list
107
- ```
108
-
109
101
  ## Documentation
110
102
 
111
103
  For full documentation, visit [openfort.io/docs/overview/building-with-cli](https://www.openfort.io/docs/overview/building-with-cli).
package/dist/bin.js CHANGED
@@ -1,25 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- CREDENTIALS_PATH
4
- } from "./chunk-QJGHQ7ID.js";
3
+ CREDENTIALS_PATH,
4
+ loadEnvFile
5
+ } from "./chunk-SVNLXGFY.js";
5
6
 
6
7
  // src/bin.ts
7
- import { existsSync, readFileSync } from "fs";
8
- function loadEnvIntoProcess(filePath) {
9
- if (!existsSync(filePath)) return;
10
- const content = readFileSync(filePath, "utf-8");
11
- for (const line of content.split("\n")) {
12
- const trimmed = line.trim();
13
- if (!trimmed || trimmed.startsWith("#")) continue;
14
- const eqIndex = trimmed.indexOf("=");
15
- if (eqIndex === -1) continue;
16
- const key = trimmed.slice(0, eqIndex).trim();
17
- const value = trimmed.slice(eqIndex + 1).trim();
18
- if (!process.env[key]) {
19
- process.env[key] = value;
20
- }
8
+ for (const [key, value] of loadEnvFile(CREDENTIALS_PATH)) {
9
+ if (!process.env[key]) {
10
+ process.env[key] = value;
21
11
  }
22
12
  }
23
- loadEnvIntoProcess(CREDENTIALS_PATH);
24
13
  var { default: cli } = await import("./cli.js");
25
14
  cli.serve();
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/config.ts
4
+ import { homedir } from "os";
5
+ import { join } from "path";
6
+ import { mkdirSync } from "fs";
7
+ function getConfigDir() {
8
+ if (process.env.XDG_CONFIG_HOME) {
9
+ return join(process.env.XDG_CONFIG_HOME, "openfort");
10
+ }
11
+ if (process.platform === "win32" && process.env.APPDATA) {
12
+ return join(process.env.APPDATA, "openfort");
13
+ }
14
+ return join(homedir(), ".config", "openfort");
15
+ }
16
+ var CONFIG_DIR = getConfigDir();
17
+ var CREDENTIALS_PATH = join(CONFIG_DIR, "credentials");
18
+ function ensureConfigDir() {
19
+ mkdirSync(CONFIG_DIR, { recursive: true });
20
+ }
21
+
22
+ // src/env.ts
23
+ import { readFileSync, writeFileSync, existsSync } from "fs";
24
+ import { Errors } from "incur";
25
+ function loadEnvFile(envPath) {
26
+ const entries = /* @__PURE__ */ new Map();
27
+ if (!existsSync(envPath)) return entries;
28
+ const content = readFileSync(envPath, "utf-8");
29
+ for (const line of content.split("\n")) {
30
+ const trimmed = line.trim();
31
+ if (!trimmed || trimmed.startsWith("#")) continue;
32
+ const eqIndex = trimmed.indexOf("=");
33
+ if (eqIndex === -1) continue;
34
+ const key = trimmed.slice(0, eqIndex).trim();
35
+ const value = trimmed.slice(eqIndex + 1).trim();
36
+ entries.set(key, value);
37
+ }
38
+ return entries;
39
+ }
40
+ function writeEnvKey(envPath, key, value) {
41
+ const entries = loadEnvFile(envPath);
42
+ entries.set(key, value);
43
+ const lines = [];
44
+ for (const [k, v] of entries) {
45
+ lines.push(`${k}=${v}`);
46
+ }
47
+ writeFileSync(envPath, `${lines.join("\n")}
48
+ `);
49
+ }
50
+ function requireApiKey() {
51
+ const apiKey = process.env.OPENFORT_API_KEY;
52
+ if (!apiKey) {
53
+ throw new Errors.IncurError({
54
+ code: "MISSING_API_KEY",
55
+ message: "OPENFORT_API_KEY is required.",
56
+ hint: "Run: openfort login"
57
+ });
58
+ }
59
+ return apiKey;
60
+ }
61
+
62
+ export {
63
+ CREDENTIALS_PATH,
64
+ ensureConfigDir,
65
+ loadEnvFile,
66
+ writeEnvKey,
67
+ requireApiKey
68
+ };