firevault 0.1.1-beta.0 → 0.1.1-beta.2

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/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.0 - Unreleased
3
+ ## 0.1.1-beta.1 - Unreleased
4
+
5
+ - Added guided `firevault init` setup with prompts for project ID, service account path, output directory, and collections.
6
+ - Added init Git safety checks, `--force`, and `--yes`.
7
+ - Added safe `.gitignore` updates for service account keys, backup output, and emulator logs.
8
+ - Ensured Firevault can still explicitly commit the configured backup directory even when it is ignored by default.
9
+ - Added a guarded local npm prerelease publish workflow using `gitversionjs`, pack verification, and forbidden-path checks.
10
+
11
+ ## 0.1.0
4
12
 
5
13
  Initial prerelease candidate for Firevault, an undo button for Firestore.
6
14
 
package/README.md CHANGED
@@ -41,7 +41,29 @@ npm install -g firevault
41
41
 
42
42
  Create a Firebase service account key for your Firestore project, save it as `serviceAccountKey.json`, and keep it out of Git.
43
43
 
44
- Create `firevault.config.json`:
44
+ Run guided setup:
45
+
46
+ ```bash
47
+ firevault init
48
+ ```
49
+
50
+ `firevault init` asks for your Firebase project ID, service account path, output directory, and collections. It also checks Git state before writing files and appends safety entries to `.gitignore`.
51
+
52
+ After you enter a project ID, Firevault prints the direct Firebase Console URL for that project's Admin SDK service account page:
53
+
54
+ ```txt
55
+ Create a Firebase service account key here:
56
+
57
+ https://console.firebase.google.com/project/your-project-id/settings/serviceaccounts/adminsdk
58
+
59
+ Download the JSON key and save it as:
60
+
61
+ ./serviceAccountKey.json
62
+ ```
63
+
64
+ Firevault does not create service accounts, open a browser, run `gcloud`, or authenticate against Firebase during setup.
65
+
66
+ Generated `firevault.config.json`:
45
67
 
46
68
  ```json
47
69
  {
@@ -176,6 +198,8 @@ serviceAccountKey.json
176
198
  firestore-backups/
177
199
  ```
178
200
 
201
+ `firevault init` adds these safety entries automatically. `firestore-backups/` is ignored by default so exported Firestore data is not committed accidentally with normal Git commands. Firevault can still commit the configured backup directory explicitly through `firevault commit` or `firevault snapshot`, and it stages only that directory.
202
+
179
203
  ## Commands
180
204
 
181
205
  ```bash
@@ -191,6 +215,8 @@ firevault restore-local users/abc123 --from HEAD~3 --confirm
191
215
  firevault restore-firestore users/abc123 --from HEAD~3 --confirm
192
216
  ```
193
217
 
218
+ `firevault init --yes` uses default values for non-interactive setup. `firevault init --force` allows setup with a dirty Git working tree and overwrites an existing config after warning.
219
+
194
220
  ## Local Development
195
221
 
196
222
  Install dependencies and run commands through the TypeScript entrypoint:
@@ -318,15 +344,36 @@ Covered emulator flows:
318
344
 
319
345
  ## Publishing
320
346
 
321
- Before publishing:
347
+ Firevault uses a local publish script for early prereleases. npm auth must already be configured before publishing; `npm whoami` should succeed for the intended npm account.
348
+
349
+ Calculate the Git-derived prerelease version:
350
+
351
+ ```bash
352
+ npm run version:calculate
353
+ ```
354
+
355
+ Verify the package without publishing:
356
+
357
+ ```bash
358
+ npm run publish:dry-run
359
+ ```
360
+
361
+ Publish the prerelease with the `next` dist-tag:
362
+
363
+ ```bash
364
+ npm run publish:next
365
+ ```
366
+
367
+ Use `npm run publish:next -- --yes` only when you intentionally want to skip the final confirmation prompt.
368
+
369
+ The publish script:
322
370
 
323
- - run `npm run build`,
324
- - run `npm run test:emulator`,
325
- - run `npm pack --dry-run` and review the file list,
326
- - verify `dist/index.js` exists and starts with `#!/usr/bin/env node`,
327
- - do not publish `serviceAccountKey.json`,
328
- - do not publish local `firestore-backups/` output,
329
- - verify logs such as `firestore-debug.log` are not included.
371
+ - requires a clean Git working tree before real publishing,
372
+ - calculates the npm prerelease version with `gitversionjs`,
373
+ - runs clean, build, and emulator tests,
374
+ - runs `npm pack --dry-run --cache /private/tmp/firevault-npm-cache`,
375
+ - rejects forbidden package contents such as `serviceAccountKey.json`, `firestore-backups/`, `firestore-debug.log`, `src/`, `test/`, `firebase.json`, `firestore.rules`, and `.env` files,
376
+ - publishes with `npm publish --access public --tag next --cache /private/tmp/firevault-npm-cache`.
330
377
 
331
378
  The package `bin` points to `./dist/index.js`, so a published or linked package must include compiled output. `prepublishOnly` currently runs clean, build, and emulator tests.
332
379
 
@@ -1,19 +1,172 @@
1
1
  import { Command } from "commander";
2
- import { writeFileSync, existsSync } from "node:fs";
2
+ import { createInterface } from "node:readline/promises";
3
+ import { stdin as input, stdout as output } from "node:process";
4
+ import { appendFileSync, existsSync, readFileSync, writeFileSync, } from "node:fs";
5
+ import { GitError, hasWorkingTreeChanges, initGitRepository, isInsideGitRepository, } from "../git/git.js";
3
6
  const defaultConfig = {
4
7
  projectId: "your-firebase-project-id",
5
8
  serviceAccountPath: "./serviceAccountKey.json",
6
9
  outputDir: "firestore-backups",
7
- collections: [],
10
+ collections: ["users"],
8
11
  };
9
- export const initCommand = new Command("init")
10
- .description("Create a firevault.config.json file")
11
- .action(() => {
12
- const configPath = "firevault.config.json";
13
- if (existsSync(configPath)) {
14
- console.log("firevault.config.json already exists.");
12
+ function validateConfig(config) {
13
+ if (config.projectId.trim() === "") {
14
+ throw new Error("Firebase project ID is required.");
15
+ }
16
+ if (config.serviceAccountPath.trim() === "") {
17
+ throw new Error("Service account path is required.");
18
+ }
19
+ if (config.outputDir.trim() === "") {
20
+ throw new Error("Output directory is required.");
21
+ }
22
+ if (config.collections.length === 0) {
23
+ throw new Error("At least one collection is required.");
24
+ }
25
+ if (config.collections.some((collection) => collection.trim() === "")) {
26
+ throw new Error("Collection names must not be empty.");
27
+ }
28
+ }
29
+ function parseCollections(value) {
30
+ return value
31
+ .split(",")
32
+ .map((collection) => collection.trim());
33
+ }
34
+ function getServiceAccountUrl(projectId) {
35
+ return `https://console.firebase.google.com/project/${encodeURIComponent(projectId)}/settings/serviceaccounts/adminsdk`;
36
+ }
37
+ function printServiceAccountGuidance(projectId, serviceAccountPath) {
38
+ console.log("");
39
+ console.log("Create a Firebase service account key here:");
40
+ console.log("");
41
+ console.log(getServiceAccountUrl(projectId));
42
+ console.log("");
43
+ console.log("Download the JSON key and save it as:");
44
+ console.log("");
45
+ console.log(serviceAccountPath);
46
+ console.log("");
47
+ }
48
+ function printMissingServiceAccountInfo(serviceAccountPath) {
49
+ if (existsSync(serviceAccountPath)) {
50
+ return;
51
+ }
52
+ console.log(`Service account file does not exist yet: ${serviceAccountPath}`);
53
+ console.log("That is expected before downloading the Firebase Admin SDK key.");
54
+ console.log(`Save the downloaded JSON key at: ${serviceAccountPath}`);
55
+ console.log("");
56
+ }
57
+ async function promptForConfig(options, rl) {
58
+ if (options.yes) {
59
+ return defaultConfig;
60
+ }
61
+ if (!rl) {
62
+ throw new Error("Prompt interface is required for interactive init.");
63
+ }
64
+ const projectId = (await rl.question("Firebase project ID: ")).trim();
65
+ if (projectId !== "") {
66
+ printServiceAccountGuidance(projectId, defaultConfig.serviceAccountPath);
67
+ }
68
+ const serviceAccountPath = (await rl.question(`Service account path (${defaultConfig.serviceAccountPath}): `)).trim() || defaultConfig.serviceAccountPath;
69
+ const outputDir = (await rl.question(`Output directory (${defaultConfig.outputDir}): `)).trim() || defaultConfig.outputDir;
70
+ const collectionsInput = (await rl.question("Collections, comma-separated: ")).trim();
71
+ return {
72
+ projectId,
73
+ serviceAccountPath,
74
+ outputDir,
75
+ collections: parseCollections(collectionsInput),
76
+ };
77
+ }
78
+ async function promptForGitInit(options, rl) {
79
+ if (options.yes) {
80
+ return true;
81
+ }
82
+ if (!rl) {
83
+ throw new Error("Prompt interface is required for interactive init.");
84
+ }
85
+ const answer = (await rl.question("This directory is not a Git repository. Run git init? (Y/n): "))
86
+ .trim()
87
+ .toLowerCase();
88
+ return answer === "" || answer === "y" || answer === "yes";
89
+ }
90
+ function ensureGitignoreEntries(entries) {
91
+ const gitignorePath = ".gitignore";
92
+ const existing = existsSync(gitignorePath)
93
+ ? readFileSync(gitignorePath, "utf-8")
94
+ : "";
95
+ const existingLines = new Set(existing
96
+ .split("\n")
97
+ .map((line) => line.trim())
98
+ .filter((line) => line !== ""));
99
+ const missingEntries = entries.filter((entry) => !existingLines.has(entry));
100
+ if (missingEntries.length === 0) {
15
101
  return;
16
102
  }
17
- writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
18
- console.log("Created firevault.config.json");
103
+ const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
104
+ appendFileSync(gitignorePath, `${prefix}${missingEntries.join("\n")}\n`);
105
+ }
106
+ export async function runInit(options) {
107
+ console.log("Firevault");
108
+ console.log("Undo button for Firestore.");
109
+ console.log("");
110
+ const configPath = "firevault.config.json";
111
+ const alreadyInGitRepository = isInsideGitRepository();
112
+ const rl = options.yes ? undefined : createInterface({ input, output });
113
+ try {
114
+ if (alreadyInGitRepository && hasWorkingTreeChanges() && !options.force) {
115
+ throw new Error("Git working tree has changes. Commit, stash, or rerun with --force before init writes files.");
116
+ }
117
+ if (existsSync(configPath) && !options.force) {
118
+ throw new Error("firevault.config.json already exists. Rerun with --force to overwrite it.");
119
+ }
120
+ const shouldInitGit = alreadyInGitRepository
121
+ ? false
122
+ : await promptForGitInit(options, rl);
123
+ const config = await promptForConfig(options, rl);
124
+ config.collections = config.collections.map((collection) => collection.trim());
125
+ validateConfig(config);
126
+ if (options.yes) {
127
+ printServiceAccountGuidance(config.projectId, config.serviceAccountPath);
128
+ }
129
+ printMissingServiceAccountInfo(config.serviceAccountPath);
130
+ if (shouldInitGit) {
131
+ initGitRepository();
132
+ console.log("Initialized Git repository.");
133
+ }
134
+ if (existsSync(configPath) && options.force) {
135
+ console.log("Warning: overwriting existing firevault.config.json.");
136
+ }
137
+ writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
138
+ ensureGitignoreEntries([
139
+ "serviceAccountKey.json",
140
+ "firestore-backups/",
141
+ "firestore-debug.log",
142
+ ]);
143
+ console.log("Created firevault.config.json.");
144
+ console.log("Updated .gitignore safety entries.");
145
+ console.log("");
146
+ console.log("Next steps:");
147
+ console.log(`1. Save your service account key at ${config.serviceAccountPath}`);
148
+ console.log("2. Run `firevault snapshot`");
149
+ console.log("3. Run `firevault changes`");
150
+ console.log("4. Run `firevault restore-preview <path> --from <commit>` before a real restore");
151
+ }
152
+ finally {
153
+ rl?.close();
154
+ }
155
+ }
156
+ export const initCommand = new Command("init")
157
+ .description("Create a guided Firevault configuration")
158
+ .option("--force", "Allow init with a dirty Git tree and overwrite existing config")
159
+ .option("--yes", "Use defaults and skip prompts")
160
+ .action(async (options) => {
161
+ try {
162
+ await runInit(options);
163
+ }
164
+ catch (error) {
165
+ if (error instanceof GitError || error instanceof Error) {
166
+ console.error(error.message);
167
+ process.exitCode = 1;
168
+ return;
169
+ }
170
+ throw error;
171
+ }
19
172
  });
package/dist/git/git.js CHANGED
@@ -23,20 +23,27 @@ function runGit(args) {
23
23
  throw new GitError("Git command failed.");
24
24
  }
25
25
  }
26
- export function assertInsideGitRepository() {
27
- let result;
26
+ export function isInsideGitRepository() {
28
27
  try {
29
- result = runGit(["rev-parse", "--is-inside-work-tree"]).trim();
28
+ return runGit(["rev-parse", "--is-inside-work-tree"]).trim() === "true";
30
29
  }
31
30
  catch {
32
- throw new GitError("Current directory is not inside a Git repository.");
31
+ return false;
33
32
  }
34
- if (result !== "true") {
33
+ }
34
+ export function assertInsideGitRepository() {
35
+ if (!isInsideGitRepository()) {
35
36
  throw new GitError("Current directory is not inside a Git repository.");
36
37
  }
37
38
  }
39
+ export function initGitRepository() {
40
+ runGit(["init"]);
41
+ }
42
+ export function hasWorkingTreeChanges() {
43
+ return runGit(["status", "--porcelain"]).trim() !== "";
44
+ }
38
45
  export function hasChangesUnder(path) {
39
- return runGit(["status", "--porcelain", "--", path]).trim() !== "";
46
+ return runGit(["status", "--porcelain", "--ignored", "--", path]).trim() !== "";
40
47
  }
41
48
  function emptyFileChanges() {
42
49
  return {
@@ -148,7 +155,7 @@ export function showFileAtCommit(commit, path) {
148
155
  }
149
156
  }
150
157
  export function stagePath(path) {
151
- runGit(["add", "--", path]);
158
+ runGit(["add", "-f", "--", path]);
152
159
  }
153
160
  export function commitPath(message, path) {
154
161
  runGit(["commit", "-m", message, "--", path]);
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import { restoreFirestoreCommand } from "./commands/restoreFirestore.js";
12
12
  const program = new Command();
13
13
  program
14
14
  .name("firevault")
15
- .description("Git-native backup, diff, and recovery tooling for Firestore.")
15
+ .description("Undo button for Firestore.")
16
16
  .version("0.1.0");
17
17
  program.addCommand(initCommand);
18
18
  program.addCommand(backupCommand);
@@ -81,7 +81,25 @@ Current implementation notes:
81
81
 
82
82
  - `loadConfig` reads and parses `firevault.config.json`.
83
83
  - Firebase initialization expects `serviceAccountPath`.
84
- - The current `init` template should be kept aligned with the expected config shape.
84
+ - `firevault init` guides setup, validates required fields, checks Git state before writing, and updates `.gitignore` without overwriting existing entries.
85
+ - `firevault init --force` allows dirty Git state and config overwrite with a warning.
86
+ - `firevault init --yes` provides a non-interactive path for tests and automation.
87
+
88
+ ## Init Safety
89
+
90
+ `firevault init` is intentionally conservative because setup writes local project files.
91
+
92
+ Behavior:
93
+
94
+ - prints the Firevault identity before prompting,
95
+ - detects whether the current directory is inside a Git repository,
96
+ - offers `git init` when no repository exists,
97
+ - prints the Firebase Console Admin SDK service account URL for the entered project ID,
98
+ - explains where to save the manually downloaded service account key,
99
+ - refuses to run in a dirty Git working tree unless `--force` is provided,
100
+ - refuses to overwrite `firevault.config.json` unless `--force` is provided,
101
+ - appends `.gitignore` safety entries without duplicating existing lines,
102
+ - never creates service accounts, opens browsers, runs `gcloud`, commits, pushes, creates GitHub repositories, contacts Firebase, or writes secrets.
85
103
 
86
104
  ## Firebase Access
87
105
 
@@ -93,7 +111,8 @@ Design constraints:
93
111
 
94
112
  - operate only on existing Firestore projects,
95
113
  - keep credentials local,
96
- - do not introduce hosted auth or account systems,
114
+ - use manually managed service account credentials,
115
+ - do not introduce credential brokerage, hosted auth, or account systems,
97
116
  - avoid committing service account files.
98
117
 
99
118
  ## Emulator Tests
@@ -116,6 +135,12 @@ Current emulator coverage:
116
135
  - collection path rejection,
117
136
  - `--confirm` enforcement.
118
137
 
138
+ ## Publishing
139
+
140
+ Prerelease publishing is intentionally local-script based for now. `scripts/publish.ts` calculates an npm-safe prerelease version from Git state with `gitversionjs`, verifies a clean working tree for real publishes, runs clean/build/emulator tests, inspects `npm pack --dry-run` contents, rejects known unsafe paths, and publishes with the `next` npm dist-tag only after explicit confirmation.
141
+
142
+ There is no GitHub Actions publishing, trusted publishing, or release automation beyond this local guard script yet.
143
+
119
144
  ## Export Pipeline
120
145
 
121
146
  Current backup flow:
package/docs/roadmap.md CHANGED
@@ -24,7 +24,9 @@ Status:
24
24
  - Firestore emulator integration tests cover backup and document restore safety paths.
25
25
  - CLI packaging runs from compiled `dist/index.js`.
26
26
  - npm prerelease packaging is guarded by package file whitelisting and pack verification.
27
+ - Local npm prerelease publishing is guarded by a `gitversionjs`-based publish script with clean-tree, build, emulator-test, pack, and forbidden-path checks.
27
28
  - Public GitHub release docs cover quick start, security, contributing, and issue triage.
29
+ - Guided `firevault init` validates setup input, checks Git state, and applies `.gitignore` safety entries.
28
30
 
29
31
  Next work:
30
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firevault",
3
- "version": "0.1.1-beta.0",
3
+ "version": "0.1.1-beta.2",
4
4
  "description": "Undo button for Firestore. Git-style history, rollback, and recovery for Firestore projects.",
5
5
  "keywords": [
6
6
  "firebase",
@@ -33,6 +33,9 @@
33
33
  "clean": "rm -rf dist",
34
34
  "build": "tsc && chmod +x dist/index.js",
35
35
  "prepublishOnly": "npm run clean && npm run build && npm run test:emulator",
36
+ "version:calculate": "tsx scripts/publish.ts --version-only",
37
+ "publish:dry-run": "tsx scripts/publish.ts --dry-run --allow-dirty",
38
+ "publish:next": "tsx scripts/publish.ts",
36
39
  "test:emulator": "tsx test/integration/run-firestore-emulator.ts",
37
40
  "backup": "tsx src/index.ts backup",
38
41
  "commit": "tsx src/index.ts commit",
@@ -51,6 +54,7 @@
51
54
  "devDependencies": {
52
55
  "@types/node": "^24.0.0",
53
56
  "firebase-tools": "^15.18.0",
57
+ "gitversionjs": "^1.0.15",
54
58
  "tsx": "^4.20.0",
55
59
  "typescript": "^5.8.0"
56
60
  }