backend-manager 5.0.180 → 5.0.182
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/TODO-2.md
CHANGED
|
@@ -10,6 +10,10 @@ payments/reactivate
|
|
|
10
10
|
payments/upgrade
|
|
11
11
|
* takes a subscription id and a new plan id and upgrades the user's subscription to the new plan. this can only be done if the user has an active subscription.
|
|
12
12
|
|
|
13
|
+
---
|
|
14
|
+
GHOSTII REVAMP
|
|
15
|
+
* better logic for generating posts. better model? claude?
|
|
16
|
+
|
|
13
17
|
-------
|
|
14
18
|
UPSELL
|
|
15
19
|
* products in BEM can have an UPSELL where you link another product ID and it allows you to add it to your cart OR shows you after checkout?
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## BEM Gap: Webhook overwrites user doc with stale subscription data
|
|
2
|
+
|
|
3
|
+
### Problem
|
|
4
|
+
When a non-current subscription is cancelled on the provider (e.g. cancelling a zombie/duplicate PayPal sub), the provider fires a cancellation webhook. BEM processes it, finds the user by UID, and overwrites `subscription.*` on the user doc with the cancelled sub's data — even though the user has a different, active subscription.
|
|
5
|
+
|
|
6
|
+
### Example
|
|
7
|
+
- User has active Chargebee sub (current) + old suspended PayPal sub (zombie)
|
|
8
|
+
- We cancel the PayPal sub → PayPal fires `BILLING.SUBSCRIPTION.CANCELLED`
|
|
9
|
+
- BEM finds user by UID → sets `subscription.status = 'cancelled'`, `subscription.payment.resourceId = <old PayPal sub>`
|
|
10
|
+
- User is now broken — their active Chargebee sub is invisible
|
|
11
|
+
|
|
12
|
+
### Fix needed in `on-write.js`
|
|
13
|
+
Before writing the unified subscription data to the user doc, check:
|
|
14
|
+
```
|
|
15
|
+
if (user.subscription.payment.resourceId !== webhook.resourceId) {
|
|
16
|
+
// This webhook is for a DIFFERENT subscription than the user's current one.
|
|
17
|
+
// Update the payments-orders doc only. Do NOT touch the user doc.
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Affected file
|
|
22
|
+
`backend-manager/src/manager/events/firestore/payments-webhooks/on-write.js` — the section that writes to `users/{uid}`
|
|
23
|
+
|
|
24
|
+
### Impact
|
|
25
|
+
Without this fix, any cancellation/suspension of a non-current subscription (duplicate cleanup, provider-side cancellation of old subs) will corrupt the user doc. Currently requires manual restoration after each occurrence.
|
package/package.json
CHANGED
|
@@ -2,6 +2,11 @@ const BaseTest = require('./base-test');
|
|
|
2
2
|
const jetpack = require('fs-jetpack');
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
|
|
5
|
+
// The expected source pattern for bm_api hosting rewrite
|
|
6
|
+
// Includes /backend-manager/* routes and root-level MCP OAuth paths
|
|
7
|
+
// that Claude Chat sends directly (e.g. /authorize, /token, /.well-known/*)
|
|
8
|
+
const BM_API_SOURCE = '{/backend-manager,/backend-manager/**,/.well-known/oauth-protected-resource,/.well-known/oauth-authorization-server,/authorize,/token}';
|
|
9
|
+
|
|
5
10
|
class HostingRewritesTest extends BaseTest {
|
|
6
11
|
getName() {
|
|
7
12
|
return 'hosting rewrites have bm_api';
|
|
@@ -11,8 +16,8 @@ class HostingRewritesTest extends BaseTest {
|
|
|
11
16
|
const rewrites = this.self.firebaseJSON?.hosting?.rewrites || [];
|
|
12
17
|
const firstRewrite = rewrites[0];
|
|
13
18
|
|
|
14
|
-
// Check first rule is correct
|
|
15
|
-
const firstIsCorrect = firstRewrite?.source ===
|
|
19
|
+
// Check first rule is correct (matches current expected pattern)
|
|
20
|
+
const firstIsCorrect = firstRewrite?.source === BM_API_SOURCE && firstRewrite?.function === 'bm_api';
|
|
16
21
|
|
|
17
22
|
// Check no duplicates exist (only one bm_api rule allowed)
|
|
18
23
|
const bmApiCount = rewrites.filter(r => r.function === 'bm_api').length;
|
|
@@ -26,12 +31,12 @@ class HostingRewritesTest extends BaseTest {
|
|
|
26
31
|
// Set default
|
|
27
32
|
hosting.rewrites = hosting.rewrites || [];
|
|
28
33
|
|
|
29
|
-
// Remove any existing bm_api rewrites
|
|
34
|
+
// Remove any existing bm_api rewrites (handles legacy single-pattern rewrites too)
|
|
30
35
|
hosting.rewrites = hosting.rewrites.filter(rewrite => rewrite.function !== 'bm_api');
|
|
31
36
|
|
|
32
|
-
// Add to top
|
|
37
|
+
// Add to top with full pattern including MCP OAuth paths
|
|
33
38
|
hosting.rewrites.unshift({
|
|
34
|
-
source:
|
|
39
|
+
source: BM_API_SOURCE,
|
|
35
40
|
function: 'bm_api',
|
|
36
41
|
});
|
|
37
42
|
|
package/src/manager/index.js
CHANGED
|
@@ -793,11 +793,9 @@ Manager.prototype.setupFunctions = function (exporter, options) {
|
|
|
793
793
|
const route = self.BemRouter(req, res).resolve();
|
|
794
794
|
|
|
795
795
|
// MCP endpoint — bypass middleware, handle protocol directly
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|| route.routePath === '.well-known/oauth-authorization-server') {
|
|
800
|
-
return self._handleMcp(req, res, route.routePath);
|
|
796
|
+
const mcpRoutePath = resolveMcpRoutePath(route.routePath);
|
|
797
|
+
if (mcpRoutePath) {
|
|
798
|
+
return self._handleMcp(req, res, mcpRoutePath);
|
|
801
799
|
}
|
|
802
800
|
|
|
803
801
|
if (route.isLegacy) {
|
|
@@ -1201,4 +1199,35 @@ function requireJSON5(file, throwError) {
|
|
|
1201
1199
|
}
|
|
1202
1200
|
}
|
|
1203
1201
|
|
|
1202
|
+
/**
|
|
1203
|
+
* Check if a routePath is an MCP-related route and normalize it.
|
|
1204
|
+
* Handles /backend-manager/mcp/* paths and /.well-known/oauth-* discovery.
|
|
1205
|
+
*
|
|
1206
|
+
* @param {string} routePath - Resolved route path from BemRouter
|
|
1207
|
+
* @returns {string|null} - Normalized MCP route path, or null if not MCP
|
|
1208
|
+
*/
|
|
1209
|
+
function resolveMcpRoutePath(routePath) {
|
|
1210
|
+
// Direct MCP paths (via /backend-manager/mcp/*)
|
|
1211
|
+
if (routePath === 'mcp' || routePath.startsWith('mcp/')) {
|
|
1212
|
+
return routePath;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// OAuth discovery (via /.well-known/oauth-*)
|
|
1216
|
+
if (routePath === '.well-known/oauth-protected-resource'
|
|
1217
|
+
|| routePath === '.well-known/oauth-authorization-server') {
|
|
1218
|
+
return routePath;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
// Root-level OAuth paths — Claude Chat sends these directly
|
|
1222
|
+
// regardless of what the discovery endpoints return
|
|
1223
|
+
if (routePath === 'authorize') {
|
|
1224
|
+
return 'mcp/authorize';
|
|
1225
|
+
}
|
|
1226
|
+
if (routePath === 'token') {
|
|
1227
|
+
return 'mcp/token';
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
return null;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1204
1233
|
module.exports = Manager;
|