envshed 0.5.0 → 0.7.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 +2 -0
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +25 -6
- package/dist/api.js.map +1 -1
- package/dist/commands/branch.d.ts.map +1 -1
- package/dist/commands/branch.js +46 -12
- package/dist/commands/branch.js.map +1 -1
- package/dist/commands/branch.test.d.ts +2 -0
- package/dist/commands/branch.test.d.ts.map +1 -0
- package/dist/commands/branch.test.js +88 -0
- package/dist/commands/branch.test.js.map +1 -0
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +343 -24
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/env.test.d.ts +2 -0
- package/dist/commands/env.test.d.ts.map +1 -0
- package/dist/commands/env.test.js +169 -0
- package/dist/commands/env.test.js.map +1 -0
- package/dist/commands/envs.d.ts.map +1 -1
- package/dist/commands/envs.js +15 -9
- package/dist/commands/envs.js.map +1 -1
- package/dist/commands/envs.test.d.ts +2 -0
- package/dist/commands/envs.test.d.ts.map +1 -0
- package/dist/commands/envs.test.js +93 -0
- package/dist/commands/envs.test.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +204 -31
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/init.test.d.ts +2 -0
- package/dist/commands/init.test.d.ts.map +1 -0
- package/dist/commands/init.test.js +121 -0
- package/dist/commands/init.test.js.map +1 -0
- package/dist/commands/link.d.ts +3 -0
- package/dist/commands/link.d.ts.map +1 -0
- package/dist/commands/link.js +66 -0
- package/dist/commands/link.js.map +1 -0
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +13 -12
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/login.test.d.ts +2 -0
- package/dist/commands/login.test.d.ts.map +1 -0
- package/dist/commands/login.test.js +97 -0
- package/dist/commands/login.test.js.map +1 -0
- package/dist/commands/orgs.d.ts.map +1 -1
- package/dist/commands/orgs.js +6 -5
- package/dist/commands/orgs.js.map +1 -1
- package/dist/commands/orgs.test.d.ts +2 -0
- package/dist/commands/orgs.test.d.ts.map +1 -0
- package/dist/commands/orgs.test.js +79 -0
- package/dist/commands/orgs.test.js.map +1 -0
- package/dist/commands/projects.d.ts.map +1 -1
- package/dist/commands/projects.js +14 -8
- package/dist/commands/projects.js.map +1 -1
- package/dist/commands/projects.test.d.ts +2 -0
- package/dist/commands/projects.test.d.ts.map +1 -0
- package/dist/commands/projects.test.js +86 -0
- package/dist/commands/projects.test.js.map +1 -0
- package/dist/commands/pull.d.ts +11 -0
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +160 -74
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/pull.test.d.ts +2 -0
- package/dist/commands/pull.test.d.ts.map +1 -0
- package/dist/commands/pull.test.js +183 -0
- package/dist/commands/pull.test.js.map +1 -0
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +328 -66
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/push.test.d.ts +2 -0
- package/dist/commands/push.test.d.ts.map +1 -0
- package/dist/commands/push.test.js +163 -0
- package/dist/commands/push.test.js.map +1 -0
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +52 -12
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/run.test.d.ts +2 -0
- package/dist/commands/run.test.d.ts.map +1 -0
- package/dist/commands/run.test.js +151 -0
- package/dist/commands/run.test.js.map +1 -0
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/commands/token.js +137 -13
- package/dist/commands/token.js.map +1 -1
- package/dist/commands/token.test.d.ts +2 -0
- package/dist/commands/token.test.d.ts.map +1 -0
- package/dist/commands/token.test.js +225 -0
- package/dist/commands/token.test.js.map +1 -0
- package/dist/commands/unlink.d.ts +3 -0
- package/dist/commands/unlink.d.ts.map +1 -0
- package/dist/commands/unlink.js +56 -0
- package/dist/commands/unlink.js.map +1 -0
- package/dist/commands/whoami.d.ts.map +1 -1
- package/dist/commands/whoami.js +4 -3
- package/dist/commands/whoami.js.map +1 -1
- package/dist/commands/whoami.test.d.ts +2 -0
- package/dist/commands/whoami.test.d.ts.map +1 -0
- package/dist/commands/whoami.test.js +55 -0
- package/dist/commands/whoami.test.js.map +1 -0
- package/dist/commands/workspace.d.ts +3 -0
- package/dist/commands/workspace.d.ts.map +1 -0
- package/dist/commands/workspace.js +197 -0
- package/dist/commands/workspace.js.map +1 -0
- package/dist/commands/workspace.test.d.ts +2 -0
- package/dist/commands/workspace.test.d.ts.map +1 -0
- package/dist/commands/workspace.test.js +160 -0
- package/dist/commands/workspace.test.js.map +1 -0
- package/dist/config.d.ts +73 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +180 -3
- package/dist/config.js.map +1 -1
- package/dist/i18n.d.ts +2 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +56 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/locales/en.json +315 -0
- package/dist/locales/es.json +315 -0
- package/dist/locales/pt-BR.json +315 -0
- package/dist/test-helpers.d.ts +17 -0
- package/dist/test-helpers.d.ts.map +1 -0
- package/dist/test-helpers.js +51 -0
- package/dist/test-helpers.js.map +1 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +55 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.test.d.ts +2 -0
- package/dist/utils.test.d.ts.map +1 -0
- package/dist/utils.test.js +141 -0
- package/dist/utils.test.js.map +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import os from "os";
|
|
5
|
+
vi.mock("../api.js", () => ({
|
|
6
|
+
apiGet: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
vi.mock("../i18n.js", () => ({
|
|
9
|
+
t: (key, opts) => (opts ? `${key}:${JSON.stringify(opts)}` : key),
|
|
10
|
+
}));
|
|
11
|
+
// Use vi.hoisted to create the mock before vi.mock runs
|
|
12
|
+
const spinnerMock = vi.hoisted(() => {
|
|
13
|
+
const calls = {
|
|
14
|
+
start: vi.fn(),
|
|
15
|
+
stop: vi.fn(),
|
|
16
|
+
succeed: vi.fn(),
|
|
17
|
+
fail: vi.fn(),
|
|
18
|
+
warn: vi.fn(),
|
|
19
|
+
};
|
|
20
|
+
const spinner = {
|
|
21
|
+
start: (...args) => { calls.start(...args); return spinner; },
|
|
22
|
+
stop: (...args) => { calls.stop(...args); return spinner; },
|
|
23
|
+
succeed: (...args) => { calls.succeed(...args); return spinner; },
|
|
24
|
+
fail: (...args) => { calls.fail(...args); return spinner; },
|
|
25
|
+
warn: (...args) => { calls.warn(...args); return spinner; },
|
|
26
|
+
text: "",
|
|
27
|
+
calls,
|
|
28
|
+
};
|
|
29
|
+
return spinner;
|
|
30
|
+
});
|
|
31
|
+
vi.mock("ora", () => ({ default: () => spinnerMock }));
|
|
32
|
+
vi.mock("../config.js", () => ({
|
|
33
|
+
resolveOpts: vi.fn((opts) => ({
|
|
34
|
+
org: opts.org || "my-org",
|
|
35
|
+
project: opts.project || "my-project",
|
|
36
|
+
env: opts.env || "development",
|
|
37
|
+
})),
|
|
38
|
+
getOriginalCwd: vi.fn(() => "/tmp/test-pull"),
|
|
39
|
+
getApiUrl: vi.fn(() => "https://app.envshed.com"),
|
|
40
|
+
logContext: vi.fn(),
|
|
41
|
+
getWorkspaceContext: vi.fn(() => ({
|
|
42
|
+
mode: "single",
|
|
43
|
+
config: { org: "my-org", project: "my-project", defaultEnv: "development" },
|
|
44
|
+
configDir: "/tmp/test-pull",
|
|
45
|
+
})),
|
|
46
|
+
resolveWorkspaceOpts: vi.fn(),
|
|
47
|
+
getWorkspaceFilePath: vi.fn(),
|
|
48
|
+
getWorkspaceFileDisplay: vi.fn(),
|
|
49
|
+
getVersionCache: vi.fn(() => null),
|
|
50
|
+
saveVersionCache: vi.fn(),
|
|
51
|
+
}));
|
|
52
|
+
import { apiGet } from "../api.js";
|
|
53
|
+
import { getOriginalCwd, getVersionCache, saveVersionCache } from "../config.js";
|
|
54
|
+
describe("pull command", () => {
|
|
55
|
+
let tmpDir;
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "pull-test-"));
|
|
58
|
+
vi.mocked(getOriginalCwd).mockReturnValue(tmpDir);
|
|
59
|
+
vi.spyOn(console, "log").mockImplementation(() => { });
|
|
60
|
+
vi.spyOn(console, "error").mockImplementation(() => { });
|
|
61
|
+
vi.spyOn(process, "exit").mockImplementation(() => {
|
|
62
|
+
throw new Error("process.exit");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
function mockApiSecrets(secrets, extra = {}) {
|
|
66
|
+
vi.mocked(apiGet).mockResolvedValue({
|
|
67
|
+
json: () => Promise.resolve({ secrets, ...extra }),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
it("pulls secrets and writes to .env file", async () => {
|
|
71
|
+
mockApiSecrets({ DATABASE_URL: "postgres://localhost/db", SECRET: "abc" });
|
|
72
|
+
const { pullCommand } = await import("./pull.js");
|
|
73
|
+
// We need to attach it to a parent program so parent! works
|
|
74
|
+
const { Command } = await import("commander");
|
|
75
|
+
const program = new Command();
|
|
76
|
+
program.addCommand(pullCommand);
|
|
77
|
+
await program.parseAsync(["node", "test", "pull", "--force"], {
|
|
78
|
+
from: "node",
|
|
79
|
+
});
|
|
80
|
+
expect(apiGet).toHaveBeenCalledWith("/secrets/my-org/my-project/development");
|
|
81
|
+
expect(spinnerMock.calls.succeed).toHaveBeenCalled();
|
|
82
|
+
const envFile = path.join(tmpDir, ".env");
|
|
83
|
+
expect(fs.existsSync(envFile)).toBe(true);
|
|
84
|
+
const content = fs.readFileSync(envFile, "utf-8");
|
|
85
|
+
expect(content).toContain("DATABASE_URL=postgres://localhost/db");
|
|
86
|
+
expect(content).toContain("SECRET=abc");
|
|
87
|
+
});
|
|
88
|
+
it("writes to custom file path", async () => {
|
|
89
|
+
mockApiSecrets({ KEY: "value" });
|
|
90
|
+
const { pullCommand } = await import("./pull.js");
|
|
91
|
+
const { Command } = await import("commander");
|
|
92
|
+
const program = new Command();
|
|
93
|
+
program.addCommand(pullCommand);
|
|
94
|
+
await program.parseAsync(["node", "test", "pull", "--force", "-f", path.join(tmpDir, "custom.env")], { from: "node" });
|
|
95
|
+
expect(fs.existsSync(path.join(tmpDir, "custom.env"))).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
it("prints to stdout when --stdout is set", async () => {
|
|
98
|
+
mockApiSecrets({ KEY: "value" });
|
|
99
|
+
const { pullCommand } = await import("./pull.js");
|
|
100
|
+
const { Command } = await import("commander");
|
|
101
|
+
const program = new Command();
|
|
102
|
+
program.addCommand(pullCommand);
|
|
103
|
+
await program.parseAsync(["node", "test", "pull", "--stdout"], {
|
|
104
|
+
from: "node",
|
|
105
|
+
});
|
|
106
|
+
expect(console.log).toHaveBeenCalledWith("KEY=value");
|
|
107
|
+
// Should NOT write a file
|
|
108
|
+
expect(fs.existsSync(path.join(tmpDir, ".env"))).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
it("outputs JSON when --format json is set", async () => {
|
|
111
|
+
mockApiSecrets({ KEY: "value" });
|
|
112
|
+
const { pullCommand } = await import("./pull.js");
|
|
113
|
+
const { Command } = await import("commander");
|
|
114
|
+
const program = new Command();
|
|
115
|
+
program.addCommand(pullCommand);
|
|
116
|
+
await program.parseAsync(["node", "test", "pull", "--stdout", "--format", "json"], { from: "node" });
|
|
117
|
+
expect(console.log).toHaveBeenCalledWith(JSON.stringify({ KEY: "value" }, null, 2));
|
|
118
|
+
});
|
|
119
|
+
it("aborts when breaking changes detected (without --force)", async () => {
|
|
120
|
+
// Write existing env file with different content
|
|
121
|
+
const envFile = path.join(tmpDir, ".env");
|
|
122
|
+
fs.writeFileSync(envFile, "KEY=old-value\nGONE=bye");
|
|
123
|
+
mockApiSecrets({ KEY: "new-value" });
|
|
124
|
+
const { pullCommand } = await import("./pull.js");
|
|
125
|
+
const { Command } = await import("commander");
|
|
126
|
+
const program = new Command();
|
|
127
|
+
program.addCommand(pullCommand);
|
|
128
|
+
await expect(program.parseAsync(["node", "test", "pull"], { from: "node" })).rejects.toThrow("process.exit");
|
|
129
|
+
});
|
|
130
|
+
it("overwrites when breaking changes with --force", async () => {
|
|
131
|
+
const envFile = path.join(tmpDir, ".env");
|
|
132
|
+
fs.writeFileSync(envFile, "KEY=old-value\nGONE=bye");
|
|
133
|
+
mockApiSecrets({ KEY: "new-value" });
|
|
134
|
+
const { pullCommand } = await import("./pull.js");
|
|
135
|
+
const { Command } = await import("commander");
|
|
136
|
+
const program = new Command();
|
|
137
|
+
program.addCommand(pullCommand);
|
|
138
|
+
await program.parseAsync(["node", "test", "pull", "--force"], {
|
|
139
|
+
from: "node",
|
|
140
|
+
});
|
|
141
|
+
const content = fs.readFileSync(envFile, "utf-8");
|
|
142
|
+
expect(content).toBe("KEY=new-value");
|
|
143
|
+
});
|
|
144
|
+
it("saves version cache after pulling", async () => {
|
|
145
|
+
mockApiSecrets({ KEY: "val" }, { version: 5 });
|
|
146
|
+
const { pullCommand } = await import("./pull.js");
|
|
147
|
+
const { Command } = await import("commander");
|
|
148
|
+
const program = new Command();
|
|
149
|
+
program.addCommand(pullCommand);
|
|
150
|
+
await program.parseAsync(["node", "test", "pull", "--force"], {
|
|
151
|
+
from: "node",
|
|
152
|
+
});
|
|
153
|
+
expect(saveVersionCache).toHaveBeenCalledWith("my-org/my-project/development", 5);
|
|
154
|
+
});
|
|
155
|
+
it("warns when environment version changed since last pull", async () => {
|
|
156
|
+
vi.mocked(getVersionCache).mockReturnValue(3);
|
|
157
|
+
mockApiSecrets({ KEY: "val" }, { version: 5 });
|
|
158
|
+
const { pullCommand } = await import("./pull.js");
|
|
159
|
+
const { Command } = await import("commander");
|
|
160
|
+
const program = new Command();
|
|
161
|
+
program.addCommand(pullCommand);
|
|
162
|
+
await program.parseAsync(["node", "test", "pull", "--force"], {
|
|
163
|
+
from: "node",
|
|
164
|
+
});
|
|
165
|
+
// Should have printed a warning about env changes
|
|
166
|
+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("pull.envChanged"));
|
|
167
|
+
});
|
|
168
|
+
it("exits when org/project/env are missing", async () => {
|
|
169
|
+
const { resolveOpts } = await import("../config.js");
|
|
170
|
+
vi.mocked(resolveOpts).mockReturnValue({
|
|
171
|
+
org: undefined,
|
|
172
|
+
project: undefined,
|
|
173
|
+
env: undefined,
|
|
174
|
+
});
|
|
175
|
+
const { pullCommand } = await import("./pull.js");
|
|
176
|
+
const { Command } = await import("commander");
|
|
177
|
+
const program = new Command();
|
|
178
|
+
program.addCommand(pullCommand);
|
|
179
|
+
await expect(program.parseAsync(["node", "test", "pull"], { from: "node" })).rejects.toThrow("process.exit");
|
|
180
|
+
expect(console.error).toHaveBeenCalledWith("common.missingOrgProjectEnv");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=pull.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull.test.js","sourceRoot":"","sources":["../../src/commands/pull.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1B,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE;CAChB,CAAC,CAAC,CAAC;AACJ,EAAE,CAAC,IAAI,CAAC,YA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,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;QACrD,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC;YACrC,GAAG,EAAE,SAAS;YACd,OAAO,EAAE,SAAS;YAClB,GAAG,EAAE,SAAS;SACf,CAAC,CAAC;QAEH,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;QAClD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;QAC9B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAEhC,MAAM,MAAM,CACV,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC/D,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAElC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,oBAAoB,CACxC,6BAA6B,CAC9B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/commands/push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/commands/push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoKpC,eAAO,MAAM,WAAW,SAkOpB,CAAC"}
|
package/dist/commands/push.js
CHANGED
|
@@ -3,95 +3,357 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import ora from "ora";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const eqIndex = trimmed.indexOf("=");
|
|
15
|
-
if (eqIndex === -1)
|
|
16
|
-
continue;
|
|
17
|
-
const key = trimmed.substring(0, eqIndex).trim();
|
|
18
|
-
let value = trimmed.substring(eqIndex + 1).trim();
|
|
19
|
-
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
20
|
-
value = value.slice(1, -1);
|
|
21
|
-
}
|
|
22
|
-
if (key)
|
|
23
|
-
result[key] = value;
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
function checkForBreakingChanges(remoteSecrets, localSecrets) {
|
|
28
|
-
const modified = [];
|
|
29
|
-
const deleted = [];
|
|
30
|
-
for (const key of Object.keys(remoteSecrets)) {
|
|
31
|
-
if (!(key in localSecrets)) {
|
|
32
|
-
deleted.push(key);
|
|
33
|
-
}
|
|
34
|
-
else if (localSecrets[key] !== remoteSecrets[key]) {
|
|
35
|
-
modified.push(key);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return { modified, deleted };
|
|
39
|
-
}
|
|
40
|
-
export const pushCommand = new Command("push")
|
|
41
|
-
.description("Push secrets from a .env file")
|
|
42
|
-
.option("-o, --org <slug>", "Organization slug")
|
|
43
|
-
.option("-p, --project <slug>", "Project slug")
|
|
44
|
-
.option("-e, --env <slug>", "Environment slug")
|
|
45
|
-
.option("-f, --file <path>", "Input file path", ".env")
|
|
46
|
-
.option("--force", "Overwrite without checking for changes")
|
|
47
|
-
.action(async (opts) => {
|
|
48
|
-
const { org, project, env } = resolveOpts(opts);
|
|
49
|
-
if (!org || !project || !env) {
|
|
50
|
-
console.error("Missing --org, --project, or --env. Provide flags or create a .envshed.json file.");
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
6
|
+
import inquirer from "inquirer";
|
|
7
|
+
import { apiGet, apiPut, apiPost, apiDelete } from "../api.js";
|
|
8
|
+
import { resolveOpts, getOriginalCwd, logContext, getWorkspaceContext, resolveWorkspaceOpts, getWorkspaceFilePath, getWorkspaceFileDisplay, hasProjectConfig, } from "../config.js";
|
|
9
|
+
import { t } from "../i18n.js";
|
|
10
|
+
import { parseEnvFile, checkForBreakingChanges } from "../utils.js";
|
|
11
|
+
import { pullSingle } from "./pull.js";
|
|
12
|
+
async function pushSingle(opts) {
|
|
13
|
+
const { org, project, env, inputFile, displayFile, force, label, preRemote } = opts;
|
|
53
14
|
logContext({ org, project, env });
|
|
54
|
-
const
|
|
55
|
-
|
|
15
|
+
const spinnerText = label
|
|
16
|
+
? t("push.pushingWorkspace", { path: label })
|
|
17
|
+
: t("push.pushing");
|
|
18
|
+
const spinner = ora(spinnerText).start();
|
|
56
19
|
try {
|
|
57
20
|
if (!fs.existsSync(inputFile)) {
|
|
58
|
-
spinner.fail(
|
|
59
|
-
|
|
21
|
+
spinner.fail(t("push.fileNotFound", { file: displayFile }));
|
|
22
|
+
throw new Error("file_not_found");
|
|
60
23
|
}
|
|
61
24
|
const content = fs.readFileSync(inputFile, "utf-8");
|
|
62
25
|
const localSecrets = parseEnvFile(content);
|
|
63
26
|
const count = Object.keys(localSecrets).length;
|
|
64
27
|
if (count === 0) {
|
|
65
|
-
spinner.warn("
|
|
28
|
+
spinner.warn(t("push.noSecrets", { file: displayFile }));
|
|
66
29
|
return;
|
|
67
30
|
}
|
|
68
|
-
if (!
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
31
|
+
if (!force) {
|
|
32
|
+
let remoteSecrets = preRemote;
|
|
33
|
+
if (!remoteSecrets) {
|
|
34
|
+
spinner.text = t("push.checking");
|
|
35
|
+
const res = await apiGet(`/secrets/${org}/${project}/${env}`);
|
|
36
|
+
const data = (await res.json());
|
|
37
|
+
remoteSecrets = data.secrets;
|
|
38
|
+
}
|
|
73
39
|
if (Object.keys(remoteSecrets).length > 0) {
|
|
74
40
|
const { modified, deleted } = checkForBreakingChanges(remoteSecrets, localSecrets);
|
|
75
41
|
if (modified.length > 0 || deleted.length > 0) {
|
|
76
42
|
spinner.stop();
|
|
77
|
-
console.log(chalk.yellow("\
|
|
43
|
+
console.log(chalk.yellow("\n" + t("push.changesDetected") + "\n"));
|
|
78
44
|
for (const key of modified) {
|
|
79
|
-
console.log(chalk.cyan(` ~ ${key}`) + chalk.dim(
|
|
45
|
+
console.log(chalk.cyan(` ~ ${key}`) + chalk.dim(` ${t("push.willBeModified")}`));
|
|
80
46
|
}
|
|
81
47
|
for (const key of deleted) {
|
|
82
|
-
console.log(chalk.red(` - ${key}`) + chalk.dim(
|
|
48
|
+
console.log(chalk.red(` - ${key}`) + chalk.dim(` ${t("push.willBeKeptRemotely")}`));
|
|
49
|
+
}
|
|
50
|
+
console.log();
|
|
51
|
+
const { shouldContinue } = await inquirer.prompt([
|
|
52
|
+
{
|
|
53
|
+
type: "confirm",
|
|
54
|
+
name: "shouldContinue",
|
|
55
|
+
message: t("push.confirmOverride"),
|
|
56
|
+
default: false,
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
if (!shouldContinue) {
|
|
60
|
+
throw new Error("breaking_changes");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// In bulk mode, only push keys that actually changed to avoid
|
|
66
|
+
// overwriting values propagated by linked secrets from other workspaces
|
|
67
|
+
let secretsToPush = localSecrets;
|
|
68
|
+
if (preRemote) {
|
|
69
|
+
secretsToPush = {};
|
|
70
|
+
for (const [key, value] of Object.entries(localSecrets)) {
|
|
71
|
+
if (preRemote[key] !== value) {
|
|
72
|
+
secretsToPush[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (Object.keys(secretsToPush).length === 0) {
|
|
76
|
+
spinner.info(t("push.noChangesWorkspace", { path: label || displayFile }));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
spinner.text = label
|
|
81
|
+
? t("push.pushingWorkspace", { path: label })
|
|
82
|
+
: t("push.pushing");
|
|
83
|
+
const result = (await apiPut(`/secrets/${org}/${project}/${env}`, { secrets: secretsToPush }));
|
|
84
|
+
spinner.succeed(t("push.pushed", { count: Object.keys(secretsToPush).length, target: `${org}/${project}/${env}` }));
|
|
85
|
+
// Handle link conflicts
|
|
86
|
+
if (result.conflicts && result.conflicts.length > 0) {
|
|
87
|
+
console.log(chalk.yellow(`\n ${t("push.linkConflictsDetected", { count: result.conflicts.length })}\n`));
|
|
88
|
+
const resolutions = [];
|
|
89
|
+
for (const conflict of result.conflicts) {
|
|
90
|
+
console.log(chalk.yellow(` ${t("push.conflictKey", { key: chalk.bold(conflict.key) })}`));
|
|
91
|
+
console.log(chalk.dim(` ${t("push.conflictRemote", { project: conflict.remoteProject, env: conflict.remoteEnv })}`));
|
|
92
|
+
console.log();
|
|
93
|
+
const { action } = await inquirer.prompt([
|
|
94
|
+
{
|
|
95
|
+
type: "list",
|
|
96
|
+
name: "action",
|
|
97
|
+
message: t("push.conflictResolve", { key: conflict.key }),
|
|
98
|
+
choices: [
|
|
99
|
+
{ name: t("push.conflictKeepMine"), value: "keep_mine" },
|
|
100
|
+
{ name: t("push.conflictKeepTheirs"), value: "keep_theirs" },
|
|
101
|
+
{ name: t("push.conflictUnlink"), value: "unlink" },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
105
|
+
resolutions.push({ linkMemberId: conflict.linkMemberId, action });
|
|
106
|
+
}
|
|
107
|
+
if (resolutions.length > 0) {
|
|
108
|
+
const resolveSpinner = ora(t("push.resolvingConflicts")).start();
|
|
109
|
+
try {
|
|
110
|
+
await apiPost("/secret-links/resolve", { resolutions });
|
|
111
|
+
resolveSpinner.succeed(t("push.conflictsResolved"));
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
resolveSpinner.fail(t("push.conflictResolveFailed", { message: err.message }));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
if (spinner.isSpinning) {
|
|
121
|
+
spinner.fail(t("push.pushFailed", { message: err.message }));
|
|
122
|
+
}
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export const pushCommand = new Command("push")
|
|
127
|
+
.description(t("push.description"))
|
|
128
|
+
.option("-o, --org <slug>", t("common.orgOption"))
|
|
129
|
+
.option("-p, --project <slug>", t("common.projectOption"))
|
|
130
|
+
.option("-e, --env <slug>", t("common.envOption"))
|
|
131
|
+
.option("-f, --file <path>", t("common.inputFileOption"))
|
|
132
|
+
.option("--force", t("push.forceOption"))
|
|
133
|
+
.action(async (opts) => {
|
|
134
|
+
const program = pushCommand.parent;
|
|
135
|
+
const globalOpts = program.opts();
|
|
136
|
+
const ctx = getWorkspaceContext(globalOpts.workspace, globalOpts.all);
|
|
137
|
+
try {
|
|
138
|
+
if (ctx.mode === "single") {
|
|
139
|
+
const { org, project, env } = resolveOpts(opts);
|
|
140
|
+
if (!org || !project || !env) {
|
|
141
|
+
if (!hasProjectConfig() && (!opts.org || !opts.project || !opts.env)) {
|
|
142
|
+
console.error(chalk.red(t("common.noProjectConfig")));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
console.error(chalk.red(t("common.missingOrgProjectEnv")));
|
|
146
|
+
}
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
const inputFile = path.resolve(getOriginalCwd(), opts.file || ".env");
|
|
150
|
+
await pushSingle({
|
|
151
|
+
org,
|
|
152
|
+
project,
|
|
153
|
+
env,
|
|
154
|
+
inputFile,
|
|
155
|
+
displayFile: opts.file || ".env",
|
|
156
|
+
force: opts.force,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else if (ctx.mode === "workspace") {
|
|
160
|
+
const resolved = resolveWorkspaceOpts(ctx, opts);
|
|
161
|
+
if (!resolved.org || !resolved.project || !resolved.env) {
|
|
162
|
+
console.error(t("common.missingOrgProjectEnv"));
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
const inputFile = opts.file
|
|
166
|
+
? path.resolve(getOriginalCwd(), opts.file)
|
|
167
|
+
: getWorkspaceFilePath(ctx.configDir, ctx.workspacePath, ctx.workspace);
|
|
168
|
+
const displayFile = opts.file || getWorkspaceFileDisplay(ctx.workspacePath, ctx.workspace);
|
|
169
|
+
await pushSingle({
|
|
170
|
+
org: resolved.org,
|
|
171
|
+
project: resolved.project,
|
|
172
|
+
env: resolved.env,
|
|
173
|
+
inputFile,
|
|
174
|
+
displayFile,
|
|
175
|
+
force: opts.force,
|
|
176
|
+
label: ctx.workspacePath,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// Bulk mode: push all workspaces
|
|
181
|
+
let successCount = 0;
|
|
182
|
+
const entries = Object.entries(ctx.workspaces);
|
|
183
|
+
// Pre-fetch remote secrets for all workspaces BEFORE any push.
|
|
184
|
+
// This snapshot lets us detect which keys actually changed locally,
|
|
185
|
+
// preventing stale linked values from overwriting recently propagated ones.
|
|
186
|
+
const prefetchSpinner = ora(t("push.prefetching")).start();
|
|
187
|
+
const preRemotes = new Map();
|
|
188
|
+
for (const [wsPath, ws] of entries) {
|
|
189
|
+
const org = opts.org || ws.org || ctx.config.org;
|
|
190
|
+
const project = opts.project || ws.project;
|
|
191
|
+
const env = opts.env || ws.defaultEnv;
|
|
192
|
+
if (!org || !project || !env)
|
|
193
|
+
continue;
|
|
194
|
+
try {
|
|
195
|
+
const res = await apiGet(`/secrets/${org}/${project}/${env}`);
|
|
196
|
+
const data = (await res.json());
|
|
197
|
+
preRemotes.set(wsPath, { secrets: data.secrets, linkedKeys: data.linkedKeys || [] });
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
preRemotes.set(wsPath, { secrets: {}, linkedKeys: [] });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
prefetchSpinner.succeed(t("push.prefetchComplete"));
|
|
204
|
+
// Detect linked key conflicts: same linked key changed in 2+ workspaces with different values
|
|
205
|
+
const changedLinkedByKey = new Map();
|
|
206
|
+
for (const [wsPath, ws] of entries) {
|
|
207
|
+
const pre = preRemotes.get(wsPath);
|
|
208
|
+
if (!pre)
|
|
209
|
+
continue;
|
|
210
|
+
const inputFile = getWorkspaceFilePath(ctx.configDir, wsPath, ws);
|
|
211
|
+
if (!fs.existsSync(inputFile))
|
|
212
|
+
continue;
|
|
213
|
+
const localSecrets = parseEnvFile(fs.readFileSync(inputFile, "utf-8"));
|
|
214
|
+
for (const key of pre.linkedKeys) {
|
|
215
|
+
if (localSecrets[key] !== undefined && localSecrets[key] !== pre.secrets[key]) {
|
|
216
|
+
if (!changedLinkedByKey.has(key))
|
|
217
|
+
changedLinkedByKey.set(key, []);
|
|
218
|
+
changedLinkedByKey.get(key).push({ wsPath, localValue: localSecrets[key] });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const linkedConflicts = [];
|
|
223
|
+
for (const [key, wsEntries] of changedLinkedByKey) {
|
|
224
|
+
if (wsEntries.length < 2)
|
|
225
|
+
continue;
|
|
226
|
+
const uniqueValues = new Set(wsEntries.map((e) => e.localValue));
|
|
227
|
+
if (uniqueValues.size < 2)
|
|
228
|
+
continue;
|
|
229
|
+
linkedConflicts.push({ key, workspaces: wsEntries });
|
|
230
|
+
}
|
|
231
|
+
if (linkedConflicts.length > 0) {
|
|
232
|
+
console.log(chalk.yellow(`\n${t("push.linkedConflictDetected")}\n`));
|
|
233
|
+
for (const conflict of linkedConflicts) {
|
|
234
|
+
console.log(chalk.bold(` ${conflict.key}:`));
|
|
235
|
+
for (const entry of conflict.workspaces) {
|
|
236
|
+
const display = entry.localValue.length > 40
|
|
237
|
+
? entry.localValue.substring(0, 40) + "..."
|
|
238
|
+
: entry.localValue;
|
|
239
|
+
console.log(chalk.dim(` ${entry.wsPath}: ${display}`));
|
|
240
|
+
}
|
|
241
|
+
console.log();
|
|
242
|
+
const choices = [
|
|
243
|
+
...conflict.workspaces.map((entry) => ({
|
|
244
|
+
name: t("push.linkedConflictUseValue", { path: entry.wsPath }),
|
|
245
|
+
value: `use:${entry.wsPath}`,
|
|
246
|
+
})),
|
|
247
|
+
{ name: t("push.linkedConflictUnlink"), value: "unlink" },
|
|
248
|
+
{ name: t("push.linkedConflictAbort"), value: "abort" },
|
|
249
|
+
];
|
|
250
|
+
const { action } = await inquirer.prompt([{
|
|
251
|
+
type: "list",
|
|
252
|
+
name: "action",
|
|
253
|
+
message: t("push.linkedConflictChoose", { key: conflict.key }),
|
|
254
|
+
choices,
|
|
255
|
+
}]);
|
|
256
|
+
if (action === "abort") {
|
|
257
|
+
console.log(chalk.dim(t("push.aborted")));
|
|
258
|
+
process.exit(0);
|
|
259
|
+
}
|
|
260
|
+
if (action === "unlink") {
|
|
261
|
+
// Unlink the secret so both values can be pushed independently
|
|
262
|
+
const first = conflict.workspaces[0];
|
|
263
|
+
const ws = ctx.workspaces[first.wsPath];
|
|
264
|
+
const org = opts.org || ws?.org || ctx.config.org;
|
|
265
|
+
const project = opts.project || ws?.project;
|
|
266
|
+
const env = opts.env || ws?.defaultEnv;
|
|
267
|
+
if (org && project && env) {
|
|
268
|
+
try {
|
|
269
|
+
const unlinkSpinner = ora(t("push.unlinkingForPush", { key: conflict.key })).start();
|
|
270
|
+
await apiDelete(`/secret-links/${org}/${project}/${env}`, { key: conflict.key });
|
|
271
|
+
unlinkSpinner.succeed(t("push.unlinkedForPush", { key: conflict.key }));
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
// Continue anyway
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else if (action.startsWith("use:")) {
|
|
279
|
+
const selectedWsPath = action.substring(4);
|
|
280
|
+
// Skip this key for all other workspaces by making preRemote match local
|
|
281
|
+
for (const entry of conflict.workspaces) {
|
|
282
|
+
if (entry.wsPath !== selectedWsPath) {
|
|
283
|
+
const pre = preRemotes.get(entry.wsPath);
|
|
284
|
+
if (pre)
|
|
285
|
+
pre.secrets[conflict.key] = entry.localValue;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
console.log();
|
|
291
|
+
}
|
|
292
|
+
for (const [wsPath, ws] of entries) {
|
|
293
|
+
const org = opts.org || ws.org || ctx.config.org;
|
|
294
|
+
const project = opts.project || ws.project;
|
|
295
|
+
const env = opts.env || ws.defaultEnv;
|
|
296
|
+
if (!org || !project || !env) {
|
|
297
|
+
console.error(t("common.missingOrgProjectEnv") + ` (${wsPath})`);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
const inputFile = getWorkspaceFilePath(ctx.configDir, wsPath, ws);
|
|
302
|
+
const displayFile = getWorkspaceFileDisplay(wsPath, ws);
|
|
303
|
+
await pushSingle({
|
|
304
|
+
org,
|
|
305
|
+
project,
|
|
306
|
+
env,
|
|
307
|
+
inputFile,
|
|
308
|
+
displayFile,
|
|
309
|
+
force: opts.force,
|
|
310
|
+
label: wsPath,
|
|
311
|
+
preRemote: preRemotes.get(wsPath)?.secrets,
|
|
312
|
+
});
|
|
313
|
+
successCount++;
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
if (err.message === "breaking_changes" || err.message === "file_not_found")
|
|
317
|
+
continue;
|
|
318
|
+
console.error(chalk.red(t("push.pushFailedWorkspace", { path: wsPath, message: err.message })));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (successCount > 0) {
|
|
322
|
+
console.log(chalk.green(`\n${t("push.bulkComplete", { count: successCount })}`));
|
|
323
|
+
// Auto-pull all workspaces to sync local files with propagated changes
|
|
324
|
+
console.log(chalk.dim(`\n${t("push.syncingAfterPush")}`));
|
|
325
|
+
for (const [wsPath, ws] of entries) {
|
|
326
|
+
const org = opts.org || ws.org || ctx.config.org;
|
|
327
|
+
const project = opts.project || ws.project;
|
|
328
|
+
const env = opts.env || ws.defaultEnv;
|
|
329
|
+
if (!org || !project || !env)
|
|
330
|
+
continue;
|
|
331
|
+
try {
|
|
332
|
+
const outFile = getWorkspaceFilePath(ctx.configDir, wsPath, ws);
|
|
333
|
+
const displayFile = getWorkspaceFileDisplay(wsPath, ws);
|
|
334
|
+
await pullSingle({
|
|
335
|
+
org,
|
|
336
|
+
project,
|
|
337
|
+
env,
|
|
338
|
+
outFile,
|
|
339
|
+
displayFile,
|
|
340
|
+
stdout: false,
|
|
341
|
+
force: true,
|
|
342
|
+
format: "env",
|
|
343
|
+
label: wsPath,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
// Best-effort sync — don't fail the push if pull fails
|
|
83
348
|
}
|
|
84
|
-
console.log(chalk.dim(`\nRun with ${chalk.bold("--force")} to push anyway.\n`));
|
|
85
|
-
process.exit(1);
|
|
86
349
|
}
|
|
87
350
|
}
|
|
88
351
|
}
|
|
89
|
-
spinner.text = "Pushing secrets...";
|
|
90
|
-
await apiPut(`/secrets/${org}/${project}/${env}`, { secrets: localSecrets });
|
|
91
|
-
spinner.succeed(`Pushed ${count} secrets to ${org}/${project}/${env}`);
|
|
92
352
|
}
|
|
93
353
|
catch (err) {
|
|
94
|
-
|
|
354
|
+
if (err.message === "breaking_changes" || err.message === "file_not_found")
|
|
355
|
+
process.exit(1);
|
|
356
|
+
ora().fail(t("push.pushFailed", { message: err.message }));
|
|
95
357
|
process.exit(1);
|
|
96
358
|
}
|
|
97
359
|
});
|