@sentroy-co/client-sdk 2.8.0 → 2.9.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.
@@ -0,0 +1,122 @@
1
+ /**
2
+ * `sentroy` — CLI entry point.
3
+ *
4
+ * Subcommand router with no third-party deps. Today only `env` exists;
5
+ * future subcommands (`mail`, `media`, etc.) hook in here.
6
+ */
7
+
8
+ import { cmdPush, cmdPull, cmdList, cmdDiff } from "./env"
9
+
10
+ const VERSION = "__VERSION__" // replaced at runtime via package.json read
11
+
12
+ interface SubCommand {
13
+ description: string
14
+ handler: (args: string[]) => Promise<void> | void
15
+ }
16
+
17
+ const ENV_SUBCOMMANDS: Record<string, SubCommand> = {
18
+ push: {
19
+ description: "Push a local .env file to the vault (full sync if --delete-missing)",
20
+ handler: cmdPush,
21
+ },
22
+ pull: {
23
+ description: "Fetch the vault scope and write to a local .env file",
24
+ handler: cmdPull,
25
+ },
26
+ list: {
27
+ description: "Print every key in the vault scope (--values to include values, --public-only)",
28
+ handler: cmdList,
29
+ },
30
+ diff: {
31
+ description: "Show what would change if you pushed the local .env file",
32
+ handler: cmdDiff,
33
+ },
34
+ }
35
+
36
+ function readPackageVersion(): string {
37
+ if (VERSION !== "__VERSION__") return VERSION
38
+ // Walk up from this file: dist/cli/index.js → dist/cli → dist → package.
39
+ try {
40
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
41
+ const { version } = require("../../package.json") as { version: string }
42
+ return version
43
+ } catch {
44
+ return "unknown"
45
+ }
46
+ }
47
+
48
+ function showHelp(): void {
49
+ const v = readPackageVersion()
50
+ process.stdout.write(
51
+ `\nsentroy ${v} — Sentroy CLI\n\n` +
52
+ `USAGE\n` +
53
+ ` sentroy <command> [args] [flags]\n\n` +
54
+ `COMMANDS\n` +
55
+ ` env push [<file>] ${ENV_SUBCOMMANDS.push.description}\n` +
56
+ ` env pull [<file>] ${ENV_SUBCOMMANDS.pull.description}\n` +
57
+ ` env list ${ENV_SUBCOMMANDS.list.description}\n` +
58
+ ` env diff [<file>] ${ENV_SUBCOMMANDS.diff.description}\n\n` +
59
+ `GLOBAL FLAGS\n` +
60
+ ` --token=stk_env_... Vault token (default: $SENTROY_ENV_API_KEY)\n` +
61
+ ` --url=https://... Sentroy core URL (default: $SENTROY_ENV_API_URL or https://sentroy.com)\n\n` +
62
+ `ENV PUSH FLAGS\n` +
63
+ ` --delete-missing Remove vault keys not present in the local file (full sync)\n` +
64
+ ` --dry-run Print the diff but do not write\n` +
65
+ ` --yes Skip the delete-confirmation prompt (CI-friendly)\n\n` +
66
+ `ENV PULL FLAGS\n` +
67
+ ` --force Overwrite the file if it already exists\n\n` +
68
+ `ENV LIST FLAGS\n` +
69
+ ` --values Include values (default: keys only)\n` +
70
+ ` --public-only Only variables marked public\n\n` +
71
+ `EXAMPLES\n` +
72
+ ` sentroy env push .env.production --delete-missing\n` +
73
+ ` sentroy env pull .env --force\n` +
74
+ ` sentroy env diff .env.production --delete-missing\n` +
75
+ ` sentroy env list --values --public-only\n\n` +
76
+ `Token scope (project + environment) is implicit — generate one in the\n` +
77
+ `Sentroy vault dashboard.\n\n`,
78
+ )
79
+ }
80
+
81
+ async function main(): Promise<void> {
82
+ const argv = process.argv.slice(2)
83
+ if (
84
+ argv.length === 0 ||
85
+ argv[0] === "-h" ||
86
+ argv[0] === "--help" ||
87
+ argv[0] === "help"
88
+ ) {
89
+ showHelp()
90
+ return
91
+ }
92
+ if (argv[0] === "-v" || argv[0] === "--version") {
93
+ process.stdout.write(`${readPackageVersion()}\n`)
94
+ return
95
+ }
96
+
97
+ const cmd = argv[0]
98
+ if (cmd === "env") {
99
+ const sub = argv[1]
100
+ const handler = sub ? ENV_SUBCOMMANDS[sub] : undefined
101
+ if (!handler) {
102
+ process.stderr.write(
103
+ `unknown env subcommand: ${sub ?? "<missing>"}\n` +
104
+ `available: ${Object.keys(ENV_SUBCOMMANDS).join(", ")}\n`,
105
+ )
106
+ process.exit(1)
107
+ }
108
+ await handler.handler(argv.slice(2))
109
+ return
110
+ }
111
+
112
+ process.stderr.write(
113
+ `unknown command: ${cmd}\nrun \`sentroy --help\` for usage.\n`,
114
+ )
115
+ process.exit(1)
116
+ }
117
+
118
+ main().catch((err: unknown) => {
119
+ const msg = err instanceof Error ? err.message : String(err)
120
+ process.stderr.write(`\n\x1b[31m✗\x1b[0m ${msg}\n`)
121
+ process.exit(1)
122
+ })