backend-manager 5.0.194 → 5.0.195
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 +6 -0
- package/CLAUDE.md +45 -45
- package/README.md +11 -11
- package/package.json +1 -1
- package/src/manager/libraries/disposable-domains.json +1 -0
- package/src/manager/routes/payments/cancel/post.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
|
14
14
|
- `Fixed` for any bug fixes.
|
|
15
15
|
- `Security` in case of vulnerabilities.
|
|
16
16
|
|
|
17
|
+
# [5.0.195] - 2026-04-10
|
|
18
|
+
### Fixed
|
|
19
|
+
- 24-hour cancellation guard in `payments/cancel` was comparing `Date.now()` (milliseconds) against `startDateUNIX` (seconds), producing an "age" of ~56 years for every subscription — guard never fired and users could cancel brand-new subscriptions. Now multiplies `startDateUNIX` by 1000 before subtraction.
|
|
20
|
+
### Changed
|
|
21
|
+
- Standardized CLI examples in `CLAUDE.md` and `README.md` to use `npx mgr` instead of the deprecated `npx bm` alias
|
|
22
|
+
|
|
17
23
|
# [5.0.194] - 2026-04-08
|
|
18
24
|
### Fixed
|
|
19
25
|
- Fix email template data merge: caller's `settings.data` is now deep-merged at root of template data tree, removing the broken `data.` prefix indirection that caused empty order confirmation emails since 5.0.185
|
package/CLAUDE.md
CHANGED
|
@@ -600,30 +600,30 @@ The `POST /admin/post` route creates blog posts via GitHub's API. It handles ima
|
|
|
600
600
|
### Running Tests
|
|
601
601
|
```bash
|
|
602
602
|
# Option 1: Two terminals
|
|
603
|
-
npx
|
|
604
|
-
npx
|
|
603
|
+
npx mgr emulator # Terminal 1 - keeps emulator running
|
|
604
|
+
npx mgr test # Terminal 2 - runs tests
|
|
605
605
|
|
|
606
606
|
# Option 2: Single command (auto-starts emulator)
|
|
607
|
-
npx
|
|
607
|
+
npx mgr test
|
|
608
608
|
```
|
|
609
609
|
|
|
610
610
|
### Log Files
|
|
611
611
|
BEM CLI commands automatically save all output to log files in `functions/` while still streaming to the console:
|
|
612
|
-
- **`functions/serve.log`** — Output from `npx
|
|
612
|
+
- **`functions/serve.log`** — Output from `npx mgr serve` (Firebase serve)
|
|
613
613
|
- **`functions/emulator.log`** — Full emulator output (Firebase emulator + Cloud Functions logs)
|
|
614
614
|
- **`functions/test.log`** — Test runner output (when running against an existing emulator)
|
|
615
|
-
- **`functions/logs.log`** — Cloud Function logs from `npx
|
|
615
|
+
- **`functions/logs.log`** — Cloud Function logs from `npx mgr logs:read` or `npx mgr logs:tail` (raw JSON for `read`, streaming text for `tail`)
|
|
616
616
|
|
|
617
|
-
When `npx
|
|
617
|
+
When `npx mgr test` starts its own emulator, logs go to `emulator.log` (since it delegates to the emulator command). When running against an already-running emulator, logs go to `test.log`.
|
|
618
618
|
|
|
619
619
|
These files are overwritten on each run and are gitignored (`*.log`). Use them to search for errors, debug webhook pipelines, or review full function output after a test run.
|
|
620
620
|
|
|
621
621
|
### Filtering Tests
|
|
622
622
|
```bash
|
|
623
|
-
npx
|
|
624
|
-
npx
|
|
625
|
-
npx
|
|
626
|
-
npx
|
|
623
|
+
npx mgr test rules/ # Run rules tests (both BEM and project)
|
|
624
|
+
npx mgr test bem:rules/ # Only BEM's rules tests
|
|
625
|
+
npx mgr test project:rules/ # Only project's rules tests
|
|
626
|
+
npx mgr test user/ admin/ # Multiple paths
|
|
627
627
|
```
|
|
628
628
|
|
|
629
629
|
### Test Locations
|
|
@@ -716,7 +716,7 @@ assert.fail(message) // Explicit fail
|
|
|
716
716
|
|
|
717
717
|
## Stripe Webhook Forwarding
|
|
718
718
|
|
|
719
|
-
BEM auto-starts Stripe CLI webhook forwarding when running `npx
|
|
719
|
+
BEM auto-starts Stripe CLI webhook forwarding when running `npx mgr serve` or `npx mgr emulator`. This forwards Stripe test webhooks to the local server so the full payment pipeline works end-to-end during development.
|
|
720
720
|
|
|
721
721
|
**Requirements:**
|
|
722
722
|
- `STRIPE_SECRET_KEY` set in `functions/.env`
|
|
@@ -725,7 +725,7 @@ BEM auto-starts Stripe CLI webhook forwarding when running `npx bm serve` or `np
|
|
|
725
725
|
|
|
726
726
|
**Standalone usage:**
|
|
727
727
|
```bash
|
|
728
|
-
npx
|
|
728
|
+
npx mgr stripe
|
|
729
729
|
```
|
|
730
730
|
|
|
731
731
|
If any prerequisite is missing, webhook forwarding is silently skipped with an info message.
|
|
@@ -736,28 +736,28 @@ The forwarding URL is: `http://localhost:{hostingPort}/backend-manager/payments/
|
|
|
736
736
|
|
|
737
737
|
Quick commands for reading/writing Firestore and managing Auth users directly from the terminal. Works in any BEM consumer project (requires `functions/service-account.json` for production, or `--emulator` for local).
|
|
738
738
|
|
|
739
|
-
**IMPORTANT: All CLI commands (`npx mgr ...`
|
|
739
|
+
**IMPORTANT: All CLI commands (`npx mgr ...`) MUST be run from the consumer project's `functions/` subdirectory** (e.g., `cd /path/to/my-project/functions && npx mgr ...`). The `mgr` binary lives in `functions/node_modules/.bin/` — running from the project root or any other directory will fail.
|
|
740
740
|
|
|
741
741
|
### Firestore Commands
|
|
742
742
|
|
|
743
743
|
```bash
|
|
744
|
-
npx
|
|
745
|
-
npx
|
|
746
|
-
npx
|
|
747
|
-
npx
|
|
744
|
+
npx mgr firestore:get <path> # Read a document
|
|
745
|
+
npx mgr firestore:set <path> '<json>' # Write/merge a document
|
|
746
|
+
npx mgr firestore:set <path> '<json>' --no-merge # Overwrite a document entirely
|
|
747
|
+
npx mgr firestore:query <collection> # Query a collection (default limit 25)
|
|
748
748
|
--where "field==value" # Filter (repeatable for AND)
|
|
749
749
|
--orderBy "field:desc" # Sort
|
|
750
750
|
--limit N # Limit results
|
|
751
|
-
npx
|
|
751
|
+
npx mgr firestore:delete <path> # Delete a document (prompts for confirmation)
|
|
752
752
|
```
|
|
753
753
|
|
|
754
754
|
### Auth Commands
|
|
755
755
|
|
|
756
756
|
```bash
|
|
757
|
-
npx
|
|
758
|
-
npx
|
|
759
|
-
npx
|
|
760
|
-
npx
|
|
757
|
+
npx mgr auth:get <uid-or-email> # Get user by UID or email (auto-detected via @)
|
|
758
|
+
npx mgr auth:list [--limit N] [--page-token T] # List users (default 100)
|
|
759
|
+
npx mgr auth:delete <uid-or-email> # Delete user (prompts for confirmation)
|
|
760
|
+
npx mgr auth:set-claims <uid-or-email> '<json>' # Set custom claims
|
|
761
761
|
```
|
|
762
762
|
|
|
763
763
|
### Logs Commands
|
|
@@ -765,21 +765,21 @@ npx bm auth:set-claims <uid-or-email> '<json>' # Set custom claims
|
|
|
765
765
|
Fetch or stream Cloud Function logs from Google Cloud Logging. Requires `gcloud` CLI installed and authenticated. Auto-resolves the project ID from `service-account.json`, `.firebaserc`, or `GCLOUD_PROJECT`.
|
|
766
766
|
|
|
767
767
|
```bash
|
|
768
|
-
npx
|
|
769
|
-
npx
|
|
770
|
-
npx
|
|
771
|
-
npx
|
|
772
|
-
npx
|
|
773
|
-
npx
|
|
774
|
-
npx
|
|
775
|
-
npx
|
|
776
|
-
npx
|
|
777
|
-
npx
|
|
768
|
+
npx mgr logs:read # Read last 1h of logs (default: 300 entries, newest first)
|
|
769
|
+
npx mgr logs:read --fn bm_api # Filter by function name
|
|
770
|
+
npx mgr logs:read --fn bm_api --severity ERROR # Filter by severity (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
771
|
+
npx mgr logs:read --since 2d --limit 100 # Custom time range and limit
|
|
772
|
+
npx mgr logs:read --search "72.134.242.25" # Search textPayload for a string (IP, email, error, etc.)
|
|
773
|
+
npx mgr logs:read --fn bm_authBeforeCreate --search "ian@example.com" --since 7d # Combined filters
|
|
774
|
+
npx mgr logs:read --order asc # Oldest first (default: desc/newest first)
|
|
775
|
+
npx mgr logs:read --filter 'jsonPayload.level="error"' # Raw gcloud filter passthrough
|
|
776
|
+
npx mgr logs:tail # Stream live logs
|
|
777
|
+
npx mgr logs:tail --fn bm_paymentsWebhookOnWrite # Stream filtered live logs
|
|
778
778
|
```
|
|
779
779
|
|
|
780
780
|
Both commands save output to `functions/logs.log` (overwritten on each run). `logs:read` saves raw JSON; `logs:tail` streams text.
|
|
781
781
|
|
|
782
|
-
**Cloud Logs vs Local Logs:** These commands query **production** Google Cloud Logging. For **local/dev** logs, read `functions/serve.log` (from `npx
|
|
782
|
+
**Cloud Logs vs Local Logs:** These commands query **production** Google Cloud Logging. For **local/dev** logs, read `functions/serve.log` (from `npx mgr serve`) or `functions/emulator.log` (from `npx mgr test`) directly — they are plain text files, not gcloud.
|
|
783
783
|
|
|
784
784
|
| Flag | Description | Default | Commands |
|
|
785
785
|
|------|-------------|---------|----------|
|
|
@@ -834,22 +834,22 @@ The `--fn` flag uses the **deployed Cloud Function name**, not the route path.
|
|
|
834
834
|
|
|
835
835
|
```bash
|
|
836
836
|
# Read a user document from production
|
|
837
|
-
npx
|
|
837
|
+
npx mgr firestore:get users/abc123
|
|
838
838
|
|
|
839
839
|
# Write to emulator
|
|
840
|
-
npx
|
|
840
|
+
npx mgr firestore:set users/test123 '{"name":"Test User"}' --emulator
|
|
841
841
|
|
|
842
842
|
# Query with filters
|
|
843
|
-
npx
|
|
843
|
+
npx mgr firestore:query users --where "subscription.status==active" --limit 10
|
|
844
844
|
|
|
845
845
|
# Look up auth user by email
|
|
846
|
-
npx
|
|
846
|
+
npx mgr auth:get user@example.com
|
|
847
847
|
|
|
848
848
|
# Set admin claims
|
|
849
|
-
npx
|
|
849
|
+
npx mgr auth:set-claims user@example.com '{"admin":true}'
|
|
850
850
|
|
|
851
851
|
# Delete from emulator (no confirmation needed)
|
|
852
|
-
npx
|
|
852
|
+
npx mgr firestore:delete users/test123 --emulator
|
|
853
853
|
```
|
|
854
854
|
|
|
855
855
|
## Usage & Rate Limiting
|
|
@@ -1366,7 +1366,7 @@ Campaigns reference segments by SSOT key: `segments: ['subscription_free']`. Aut
|
|
|
1366
1366
|
|
|
1367
1367
|
### Seed Campaigns
|
|
1368
1368
|
|
|
1369
|
-
Created by `npx
|
|
1369
|
+
Created by `npx mgr setup` (idempotent, enforced fields checked every run):
|
|
1370
1370
|
|
|
1371
1371
|
| ID | Type | Description |
|
|
1372
1372
|
|----|------|-------------|
|
|
@@ -1419,7 +1419,7 @@ marketing: {
|
|
|
1419
1419
|
|
|
1420
1420
|
8. **Increment usage before update** - Call `usage.increment()` then `usage.update()`
|
|
1421
1421
|
|
|
1422
|
-
9. **Add Firestore composite indexes for new compound queries** - Any new Firestore query using multiple `.where()` clauses or `.where()` + `.orderBy()` requires a composite index. Add it to `src/cli/commands/setup-tests/helpers/required-indexes.js` (the SSOT). Consumer projects pick these up via `npx
|
|
1422
|
+
9. **Add Firestore composite indexes for new compound queries** - Any new Firestore query using multiple `.where()` clauses or `.where()` + `.orderBy()` requires a composite index. Add it to `src/cli/commands/setup-tests/helpers/required-indexes.js` (the SSOT). Consumer projects pick these up via `npx mgr setup`, which syncs them into `firestore.indexes.json`. Without the index, the query will crash with `FAILED_PRECONDITION` in production.
|
|
1423
1423
|
|
|
1424
1424
|
## Key Files Reference
|
|
1425
1425
|
|
|
@@ -1463,7 +1463,7 @@ marketing: {
|
|
|
1463
1463
|
```javascript
|
|
1464
1464
|
assistant.isDevelopment() // true when ENVIRONMENT !== 'production' or in emulator
|
|
1465
1465
|
assistant.isProduction() // true when ENVIRONMENT === 'production'
|
|
1466
|
-
assistant.isTesting() // true when running tests (via npx
|
|
1466
|
+
assistant.isTesting() // true when running tests (via npx mgr test)
|
|
1467
1467
|
```
|
|
1468
1468
|
|
|
1469
1469
|
## Model Context Protocol (MCP)
|
|
@@ -1473,7 +1473,7 @@ BEM includes a built-in MCP server that exposes BEM routes as tools for Claude C
|
|
|
1473
1473
|
### Architecture
|
|
1474
1474
|
|
|
1475
1475
|
Two transport modes:
|
|
1476
|
-
- **Stdio** (local): `npx
|
|
1476
|
+
- **Stdio** (local): `npx mgr mcp` — for Claude Code / Claude Desktop
|
|
1477
1477
|
- **Streamable HTTP** (remote): `POST /backend-manager/mcp` — for Claude Chat (stateless, Firebase Functions compatible)
|
|
1478
1478
|
|
|
1479
1479
|
### Available Tools (19)
|
|
@@ -1507,7 +1507,7 @@ Two transport modes:
|
|
|
1507
1507
|
|
|
1508
1508
|
### Hosting Rewrites
|
|
1509
1509
|
|
|
1510
|
-
The `npx
|
|
1510
|
+
The `npx mgr setup` command automatically adds required Firebase Hosting rewrites for MCP OAuth:
|
|
1511
1511
|
```json
|
|
1512
1512
|
{
|
|
1513
1513
|
"source": "{/backend-manager,/backend-manager/**,/.well-known/oauth-protected-resource,/.well-known/oauth-authorization-server,/authorize,/token}",
|
|
@@ -1518,7 +1518,7 @@ The `npx bm setup` command automatically adds required Firebase Hosting rewrites
|
|
|
1518
1518
|
### CLI Usage
|
|
1519
1519
|
|
|
1520
1520
|
```bash
|
|
1521
|
-
npx
|
|
1521
|
+
npx mgr mcp # Start stdio MCP server (for Claude Code)
|
|
1522
1522
|
```
|
|
1523
1523
|
|
|
1524
1524
|
### Claude Code Configuration
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ module.exports = function (assistant) {
|
|
|
89
89
|
Run the setup command:
|
|
90
90
|
|
|
91
91
|
```bash
|
|
92
|
-
npx
|
|
92
|
+
npx mgr setup
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
## Initialization Options
|
|
@@ -802,28 +802,28 @@ BEM includes an integration test framework that runs against the Firebase emulat
|
|
|
802
802
|
|
|
803
803
|
```bash
|
|
804
804
|
# Option 1: Two terminals (recommended for development)
|
|
805
|
-
npx
|
|
806
|
-
npx
|
|
805
|
+
npx mgr emulator # Terminal 1 - keeps emulator running
|
|
806
|
+
npx mgr test # Terminal 2 - runs tests
|
|
807
807
|
|
|
808
808
|
# Option 2: Single command (auto-starts emulator, shuts down after)
|
|
809
|
-
npx
|
|
809
|
+
npx mgr test
|
|
810
810
|
```
|
|
811
811
|
|
|
812
812
|
### Filtering Tests
|
|
813
813
|
|
|
814
814
|
```bash
|
|
815
|
-
npx
|
|
816
|
-
npx
|
|
817
|
-
npx
|
|
818
|
-
npx
|
|
815
|
+
npx mgr test rules/ # Run rules tests (both BEM and project)
|
|
816
|
+
npx mgr test bem:rules/ # Only BEM's rules tests
|
|
817
|
+
npx mgr test project:rules/ # Only project's rules tests
|
|
818
|
+
npx mgr test user/ admin/ # Multiple paths
|
|
819
819
|
```
|
|
820
820
|
|
|
821
821
|
### Log Files
|
|
822
822
|
|
|
823
823
|
BEM CLI commands automatically save output to log files in the project directory:
|
|
824
|
-
- **`emulator.log`** — Full emulator + Cloud Functions output (`npx
|
|
825
|
-
- **`test.log`** — Test runner output (`npx
|
|
826
|
-
- **`logs.log`** — Cloud Function logs (`npx
|
|
824
|
+
- **`emulator.log`** — Full emulator + Cloud Functions output (`npx mgr emulator`)
|
|
825
|
+
- **`test.log`** — Test runner output (`npx mgr test`, when running against an existing emulator)
|
|
826
|
+
- **`logs.log`** — Cloud Function logs (`npx mgr logs:read` or `npx mgr logs:tail`)
|
|
827
827
|
|
|
828
828
|
Logs are overwritten on each run. Use them to debug failing tests or review function output.
|
|
829
829
|
|
package/package.json
CHANGED
|
@@ -35,7 +35,7 @@ module.exports = async ({ assistant, user, settings }) => {
|
|
|
35
35
|
// Guard: subscription younger than 24 hours
|
|
36
36
|
const startDateUNIX = subscription.payment?.startDate?.timestampUNIX;
|
|
37
37
|
if (startDateUNIX) {
|
|
38
|
-
const ageMs = Date.now() - startDateUNIX;
|
|
38
|
+
const ageMs = Date.now() - (startDateUNIX * 1000);
|
|
39
39
|
const twentyFourHoursMs = 24 * 60 * 60 * 1000;
|
|
40
40
|
if (ageMs < twentyFourHoursMs) {
|
|
41
41
|
assistant.log(`Cancel rejected: uid=${uid}, subscription is only ${Math.round(ageMs / 1000 / 60)} minutes old`);
|