@littlebearapps/platform-consumer-sdk 1.0.0 → 1.0.1
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 +37 -0
- package/package.json +1 -1
- package/src/proxy.ts +13 -4
package/README.md
CHANGED
|
@@ -301,6 +301,43 @@ The hierarchy checks in order: **global** (kill switch) > **project** > **featur
|
|
|
301
301
|
|
|
302
302
|
Budget limits and circuit breaker thresholds are stored in KV (`PLATFORM_CACHE`) under the `CONFIG:FEATURE:` prefix. They're synced from `budgets.yaml` via the Admin SDK's sync script.
|
|
303
303
|
|
|
304
|
+
Requires a Platform backend — scaffold one with [`@littlebearapps/platform-admin-sdk`](https://www.npmjs.com/package/@littlebearapps/platform-admin-sdk).
|
|
305
|
+
|
|
306
|
+
## Updating
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
npm update @littlebearapps/platform-consumer-sdk
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
The Consumer SDK is a **pure library** with zero side effects on update. No database migrations, no KV writes, no config changes. New features are additive and backward compatible within the same major version.
|
|
313
|
+
|
|
314
|
+
## Feature ID Convention
|
|
315
|
+
|
|
316
|
+
Feature IDs follow the format `project:category:feature`:
|
|
317
|
+
|
|
318
|
+
| Example | Project | Category | Feature |
|
|
319
|
+
|---------|---------|----------|---------|
|
|
320
|
+
| `scout:ocr:process` | Scout | OCR | Process scans |
|
|
321
|
+
| `brand-copilot:scanner:github` | Brand Copilot | Scanner | GitHub scanner |
|
|
322
|
+
| `myapp:api:main` | My App | API | Main handler |
|
|
323
|
+
| `myapp:cron:daily-sync` | My App | Cron | Daily sync job |
|
|
324
|
+
|
|
325
|
+
Register each feature ID in your `budgets.yaml` to set daily limits and circuit breaker thresholds.
|
|
326
|
+
|
|
327
|
+
## Troubleshooting
|
|
328
|
+
|
|
329
|
+
**`ReferenceError: PLATFORM_CACHE is not defined`**
|
|
330
|
+
Add the KV binding to your `wrangler.jsonc`. See [Required Bindings](#required-bindings).
|
|
331
|
+
|
|
332
|
+
**Metrics not appearing in Platform dashboard**
|
|
333
|
+
Check that `TELEMETRY_QUEUE` is bound and the queue exists. Telemetry is silently dropped if the queue binding is missing.
|
|
334
|
+
|
|
335
|
+
**`CircuitBreakerError` on every request**
|
|
336
|
+
A circuit breaker is stuck in STOP state. Check KV for `CONFIG:FEATURE:{featureId}:STATUS`. Reset with `wrangler kv key put CONFIG:FEATURE:{featureId}:STATUS GO --namespace-id YOUR_KV_ID`.
|
|
337
|
+
|
|
338
|
+
**Feature usage not tracked**
|
|
339
|
+
Verify the feature ID is registered in `budgets.yaml` and you've run `npm run sync:config` to push it to KV.
|
|
340
|
+
|
|
304
341
|
## License
|
|
305
342
|
|
|
306
343
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@littlebearapps/platform-consumer-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Platform Consumer SDK — automatic metric collection, circuit breaking, and cost protection for Cloudflare Workers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
package/src/proxy.ts
CHANGED
|
@@ -590,8 +590,12 @@ function createDOStubProxy(
|
|
|
590
590
|
};
|
|
591
591
|
}
|
|
592
592
|
|
|
593
|
-
// Pass through: id, name
|
|
594
|
-
|
|
593
|
+
// Pass through: id, name — bind to preserve `this` context
|
|
594
|
+
const value = Reflect.get(target, prop);
|
|
595
|
+
if (typeof value === 'function') {
|
|
596
|
+
return value.bind(target);
|
|
597
|
+
}
|
|
598
|
+
return value;
|
|
595
599
|
},
|
|
596
600
|
});
|
|
597
601
|
}
|
|
@@ -614,8 +618,13 @@ export function createDOProxy(
|
|
|
614
618
|
};
|
|
615
619
|
}
|
|
616
620
|
|
|
617
|
-
// Pass through ID methods
|
|
618
|
-
|
|
621
|
+
// Pass through ID methods — bind to preserve `this` context for
|
|
622
|
+
// native Cloudflare methods (idFromName, idFromString, newUniqueId)
|
|
623
|
+
const value = Reflect.get(target, prop);
|
|
624
|
+
if (typeof value === 'function') {
|
|
625
|
+
return value.bind(target);
|
|
626
|
+
}
|
|
627
|
+
return value;
|
|
619
628
|
},
|
|
620
629
|
});
|
|
621
630
|
}
|