firevault 0.1.1-beta.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,182 @@
1
+ # Architecture
2
+
3
+ Firevault is an undo button for Firestore: operational recovery tooling that gives Firestore projects Git-style history, change inspection, and document-level rollback.
4
+
5
+ ## Positioning
6
+
7
+ Firevault wraps existing Firestore projects. It does not replace Firebase and does not host data.
8
+
9
+ The architecture should optimize for:
10
+
11
+ - safe restores,
12
+ - readable recovery previews,
13
+ - document-level rollback,
14
+ - deterministic exports,
15
+ - Git-backed history,
16
+ - disaster recovery workflows,
17
+ - simple local operation.
18
+
19
+ ## Current Stack
20
+
21
+ - TypeScript
22
+ - Node.js
23
+ - Firebase Admin SDK
24
+ - Commander
25
+ - tsx for development execution
26
+
27
+ ## Current Project Structure
28
+
29
+ ```txt
30
+ src/
31
+ commands/
32
+ init.ts
33
+ backup.ts
34
+ config/
35
+ loadConfig.ts
36
+ firestore/
37
+ exportFirestore.ts
38
+ firebase.ts
39
+ stableStringify.ts
40
+ git/
41
+ index.ts
42
+ firevault.config.json
43
+ package.json
44
+ tsconfig.json
45
+ ```
46
+
47
+ ## Command Layer
48
+
49
+ `src/index.ts` creates the Commander program and registers commands.
50
+
51
+ Current commands:
52
+
53
+ - `firevault init`
54
+ - `firevault backup`
55
+
56
+ Expected future commands:
57
+
58
+ ```bash
59
+ firevault backup
60
+ firevault changes --last 24h
61
+ firevault diff users/abc123
62
+ firevault restore users/abc123 --from HEAD~3
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ Configuration is loaded from `firevault.config.json`.
68
+
69
+ Intended shape:
70
+
71
+ ```json
72
+ {
73
+ "projectId": "your-project-id",
74
+ "serviceAccountPath": "./serviceAccountKey.json",
75
+ "outputDir": "firestore-backups",
76
+ "collections": ["users"]
77
+ }
78
+ ```
79
+
80
+ Current implementation notes:
81
+
82
+ - `loadConfig` reads and parses `firevault.config.json`.
83
+ - Firebase initialization expects `serviceAccountPath`.
84
+ - The current `init` template should be kept aligned with the expected config shape.
85
+
86
+ ## Firebase Access
87
+
88
+ `src/firestore/firebase.ts` initializes Firebase Admin SDK from the configured service account path and returns a Firestore client.
89
+
90
+ When `FIRESTORE_EMULATOR_HOST` is set, Firebase Admin initializes with only the configured `projectId`. This lets integration tests run against the local Firestore emulator without a service account file and without contacting real Firebase.
91
+
92
+ Design constraints:
93
+
94
+ - operate only on existing Firestore projects,
95
+ - keep credentials local,
96
+ - do not introduce hosted auth or account systems,
97
+ - avoid committing service account files.
98
+
99
+ ## Emulator Tests
100
+
101
+ Firestore emulator integration tests live under `test/integration/`.
102
+
103
+ The test command:
104
+
105
+ ```bash
106
+ npm run test:emulator
107
+ ```
108
+
109
+ starts the Firestore emulator through `firebase-tools`, runs Node's built-in test runner through `tsx`, and uses temporary Git repositories and backup directories for each test. The tests seed emulator Firestore directly, drive the Firevault CLI, and clean up temporary directories where practical.
110
+
111
+ Current emulator coverage:
112
+
113
+ - backup export from emulator Firestore,
114
+ - deterministic JSON output,
115
+ - single-document `restore-firestore` overwrite into emulator Firestore,
116
+ - collection path rejection,
117
+ - `--confirm` enforcement.
118
+
119
+ ## Export Pipeline
120
+
121
+ Current backup flow:
122
+
123
+ 1. Load config.
124
+ 2. Iterate configured collections.
125
+ 3. Fetch each collection through Firebase Admin SDK.
126
+ 4. Write each document to `<outputDir>/<collection>/<documentId>.json`.
127
+ 5. Serialize document data using deterministic JSON.
128
+
129
+ The current exporter handles configured top-level collections. Subcollections, deletes, metadata, timestamps, references, and special Firestore value types need explicit design before production use.
130
+
131
+ ## Deterministic Serialization
132
+
133
+ `src/firestore/stableStringify.ts` recursively sorts object keys and writes pretty JSON.
134
+
135
+ This is foundational because Git is the history engine. Output should be stable when Firestore data has not changed.
136
+
137
+ Serialization rules should remain boring and predictable:
138
+
139
+ - sort object keys,
140
+ - preserve array order,
141
+ - write one document per file,
142
+ - avoid transient metadata unless explicitly modeled.
143
+
144
+ ## Git Boundary
145
+
146
+ Git is the storage and history engine. Firevault should wrap Git workflows rather than reimplement versioning.
147
+
148
+ Near-term Git integration should focus on:
149
+
150
+ - detecting working tree changes after backup,
151
+ - showing changed documents,
152
+ - helping users inspect diffs,
153
+ - optionally guiding commit workflows without committing automatically.
154
+
155
+ AI agents and Firevault itself must not create commits automatically unless a human explicitly performs that step outside the agent workflow.
156
+
157
+ ## Restore Boundary
158
+
159
+ Restore is safety-critical and should be introduced incrementally.
160
+
161
+ Initial restore scope:
162
+
163
+ - document-level only,
164
+ - dry-run by default,
165
+ - explicit confirmation required for writes,
166
+ - clear source revision and target document path,
167
+ - readable diff before applying changes.
168
+
169
+ Avoid early whole-database restore commands.
170
+
171
+ ## Non-Goals
172
+
173
+ Do not introduce these before the core workflow is stable:
174
+
175
+ - SaaS platform,
176
+ - hosted infrastructure,
177
+ - web dashboard,
178
+ - billing,
179
+ - auth system,
180
+ - collaboration features,
181
+ - Firebase Extensions,
182
+ - generic multi-cloud backup abstractions.
@@ -0,0 +1,18 @@
1
+ # GitHub Labels
2
+
3
+ Recommended labels for the public repository:
4
+
5
+ | Label | Purpose |
6
+ | --- | --- |
7
+ | `bug` | Incorrect behavior or regression |
8
+ | `enhancement` | Focused workflow improvement |
9
+ | `documentation` | README, docs, examples, or release notes |
10
+ | `safety` | Restore safety, confirmation, or destructive-action concerns |
11
+ | `firestore` | Firestore Admin SDK, emulator, or data model behavior |
12
+ | `git` | Git history, commit, status, or path behavior |
13
+ | `testing` | Unit, emulator, or verification work |
14
+ | `packaging` | npm, build, release, and install behavior |
15
+ | `question` | Usage questions that are not bugs |
16
+ | `good first issue` | Small, well-scoped starter tasks |
17
+
18
+ Keep labels operational and workflow-focused. Avoid broad platform labels until the project scope expands.
@@ -0,0 +1,138 @@
1
+ # Roadmap
2
+
3
+ Firevault is currently in Foundation / Phase 0. The roadmap is intentionally incremental: make the undo button for Firestore trustworthy before adding broader recovery workflows.
4
+
5
+ ## Foundation
6
+
7
+ Goal: provide a safe document-level recovery loop backed by deterministic local snapshots and Git history.
8
+
9
+ Status:
10
+
11
+ - TypeScript CLI scaffold exists.
12
+ - Commander command wiring exists.
13
+ - Config loading exists.
14
+ - Firebase Admin initialization exists.
15
+ - Stable JSON serializer exists.
16
+ - Backup command exports configured collections.
17
+ - Documents are written one file per document.
18
+ - Local Git snapshot workflow exists through separate `backup`, `commit`, and `snapshot` commands.
19
+ - File-level change inspection exists through `changes` and `changes --last <window>`.
20
+ - Document and collection history inspection exists through `history <path>`.
21
+ - Dry-run recovery inspection exists through `restore-preview <path> --from <commit>`.
22
+ - Local backup-file recovery exists through `restore-local <path> --from <commit> --confirm`.
23
+ - Single-document Firestore overwrite restore exists through `restore-firestore <path> --from <commit> --confirm`.
24
+ - Firestore emulator integration tests cover backup and document restore safety paths.
25
+ - CLI packaging runs from compiled `dist/index.js`.
26
+ - npm prerelease packaging is guarded by package file whitelisting and pack verification.
27
+ - Public GitHub release docs cover quick start, security, contributing, and issue triage.
28
+
29
+ Next work:
30
+
31
+ - Decide how to represent Firestore special value types.
32
+ - Decide how to handle subcollections.
33
+ - Add broader error handling around Firestore export failures.
34
+ - Add non-emulator unit tests for pure path and Git parsing helpers.
35
+ - Review first npm prerelease feedback before widening restore scope.
36
+ - Dogfood against real non-critical Firestore projects before expanding restore behavior.
37
+
38
+ ## MVP
39
+
40
+ Goal: make Git-style history, inspection, and rollback useful for real Firestore recovery work.
41
+
42
+ Expected capabilities:
43
+
44
+ - `firevault backup` reliably exports configured collections.
45
+ - Clear output summary after backup.
46
+ - Local Git snapshot command for backup plus scoped commit.
47
+ - Git status integration showing changed, added, and deleted backup files.
48
+ - History helpers for document and collection paths.
49
+ - Restore preview helpers for document paths.
50
+ - Local document restore into backup files only.
51
+ - Firestore document restore with explicit confirmation.
52
+ - Diff helpers for document paths.
53
+ - Document path addressing such as `users/abc123`.
54
+ - Basic change inspection workflows.
55
+ - Documentation for a safe backup cadence.
56
+
57
+ Example commands:
58
+
59
+ ```bash
60
+ firevault backup
61
+ firevault commit
62
+ firevault snapshot
63
+ firevault history users/abc123
64
+ firevault restore-preview users/abc123 --from HEAD~3
65
+ firevault restore-local users/abc123 --from HEAD~3 --confirm
66
+ firevault restore-firestore users/abc123 --from HEAD~3 --confirm
67
+ firevault diff users/abc123
68
+ firevault changes
69
+ ```
70
+
71
+ ## Semi-Production
72
+
73
+ Goal: introduce safe document-level recovery without broad destructive operations.
74
+
75
+ Expected capabilities:
76
+
77
+ - Safer document-level restore from a Git revision.
78
+ - Dry-run preview before destructive restore.
79
+ - Required confirmation for writes.
80
+ - Diff preview before restore.
81
+ - Better Firestore type handling.
82
+ - Clear failure modes and exit codes.
83
+ - Tests for restore safety behavior.
84
+ - Guidance for CI or scheduled backup jobs.
85
+
86
+ Example command:
87
+
88
+ ```bash
89
+ firevault restore users/abc123 --from HEAD~3
90
+ ```
91
+
92
+ ## Production
93
+
94
+ Goal: make Firevault dependable for teams that need disaster recovery workflows.
95
+
96
+ Expected capabilities:
97
+
98
+ - Robust recursive export design if subcollections are supported.
99
+ - Delete detection and explicit delete handling.
100
+ - Restore audit output.
101
+ - Backup validation command.
102
+ - Safer configuration validation.
103
+ - Larger collection handling with pagination and progress.
104
+ - Better handling of rate limits and transient Firebase failures.
105
+ - Release packaging and installation story.
106
+ - Security guidance for credentials and least-privilege service accounts.
107
+
108
+ ## Polished
109
+
110
+ Goal: refine the CLI experience after the core workflows are proven.
111
+
112
+ Possible capabilities:
113
+
114
+ - Better command UX and help text.
115
+ - Human-readable change summaries.
116
+ - Time-window helpers such as `firevault changes --last 24h`.
117
+ - Guided Git workflow prompts that still leave commits to humans.
118
+ - Optional machine-readable output for automation.
119
+ - Richer docs and recovery playbooks.
120
+ - AI-assisted development recovery positioning once the operational core is stable.
121
+
122
+ ## Guardrails
123
+
124
+ Do not build these during early phases:
125
+
126
+ - SaaS,
127
+ - web UI,
128
+ - hosted infrastructure,
129
+ - billing,
130
+ - auth systems,
131
+ - collaboration features,
132
+ - generalized multi-cloud backup platform.
133
+
134
+ The core workflow must remain:
135
+
136
+ ```txt
137
+ Firestore -> stable JSON files -> Git history -> safe diff/restore workflows
138
+ ```
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "firevault",
3
+ "version": "0.1.1-beta.0",
4
+ "description": "Undo button for Firestore. Git-style history, rollback, and recovery for Firestore projects.",
5
+ "keywords": [
6
+ "firebase",
7
+ "firestore",
8
+ "backup",
9
+ "restore",
10
+ "git",
11
+ "cli",
12
+ "disaster-recovery"
13
+ ],
14
+ "author": "henskjold73",
15
+ "license": "MIT",
16
+ "type": "module",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/henskjold73/firevault.git"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "docs",
25
+ "CHANGELOG.md",
26
+ "LICENSE"
27
+ ],
28
+ "bin": {
29
+ "firevault": "./dist/index.js"
30
+ },
31
+ "scripts": {
32
+ "dev": "tsx src/index.ts",
33
+ "clean": "rm -rf dist",
34
+ "build": "tsc && chmod +x dist/index.js",
35
+ "prepublishOnly": "npm run clean && npm run build && npm run test:emulator",
36
+ "test:emulator": "tsx test/integration/run-firestore-emulator.ts",
37
+ "backup": "tsx src/index.ts backup",
38
+ "commit": "tsx src/index.ts commit",
39
+ "changes": "tsx src/index.ts changes",
40
+ "history": "tsx src/index.ts history",
41
+ "restore-preview": "tsx src/index.ts restore-preview",
42
+ "restore-local": "tsx src/index.ts restore-local",
43
+ "restore-firestore": "tsx src/index.ts restore-firestore",
44
+ "snapshot": "tsx src/index.ts snapshot",
45
+ "init": "tsx src/index.ts init"
46
+ },
47
+ "dependencies": {
48
+ "commander": "^14.0.2",
49
+ "firebase-admin": "^13.5.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^24.0.0",
53
+ "firebase-tools": "^15.18.0",
54
+ "tsx": "^4.20.0",
55
+ "typescript": "^5.8.0"
56
+ }
57
+ }