big-spender 0.3.0 → 0.6.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.
- package/README.md +142 -16
- package/dist/collector.mjs +740 -91
- package/dist/history.js +6 -2
- package/dist/install.d.ts +1 -1
- package/dist/install.js +23 -5
- package/dist/limits.d.ts +48 -0
- package/dist/limits.js +140 -0
- package/dist/page.d.ts +2 -1
- package/dist/page.js +29 -2
- package/dist/push.d.ts +1 -1
- package/dist/push.js +32 -6
- package/dist/schema.d.ts +40 -1
- package/dist/schema.js +24 -5
- package/dist/serve.js +7 -1
- package/dist/server/index.d.ts +5 -1
- package/dist/server/index.js +12 -1
- package/dist/server/ingest.js +9 -2
- package/dist/summary.js +4 -3
- package/package.json +1 -1
- package/templates/env.example +3 -0
package/dist/server/ingest.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
2
|
-
import { usageSnapshotSchema } from '../schema.js';
|
|
2
|
+
import { CURSOR_DEVICE_ID, usageSnapshotSchema } from '../schema.js';
|
|
3
3
|
// Collectors POST one device's full snapshot here (optionally gzip-encoded).
|
|
4
4
|
const MAX_BODY_BYTES = 2 * 1024 * 1024;
|
|
5
5
|
const MAX_DECODED_BYTES = 16 * 1024 * 1024;
|
|
@@ -80,7 +80,14 @@ export function createIngest({ store, token, onStored }) {
|
|
|
80
80
|
.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`);
|
|
81
81
|
return Response.json({ error: 'invalid snapshot', issues }, { status: 422 });
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
// Checked here, not in the schema: a stored file from before the reservation must still load.
|
|
84
|
+
const snap = parsed.data;
|
|
85
|
+
if (snap.deviceId === CURSOR_DEVICE_ID &&
|
|
86
|
+
(snap.pricingSource !== 'cursor' || snap.hourly.some((r) => r.provider !== 'cursor'))) {
|
|
87
|
+
const issues = [`deviceId: "${CURSOR_DEVICE_ID}" is reserved for Cursor usage`];
|
|
88
|
+
return Response.json({ error: 'invalid snapshot', issues }, { status: 422 });
|
|
89
|
+
}
|
|
90
|
+
const result = await store.save(snap);
|
|
84
91
|
if (result === 'stored')
|
|
85
92
|
onStored();
|
|
86
93
|
return Response.json({
|
package/dist/summary.js
CHANGED
|
@@ -119,10 +119,11 @@ function summarizeRange(range, snapshots, now, resolved) {
|
|
|
119
119
|
// that has usage inside this window, so an offline device's old sessions drop out.
|
|
120
120
|
if (counts) {
|
|
121
121
|
for (const id of active) {
|
|
122
|
-
|
|
122
|
+
const n = counts[id];
|
|
123
|
+
if (!n)
|
|
123
124
|
continue;
|
|
124
|
-
sessions +=
|
|
125
|
-
provider(id).sessions +=
|
|
125
|
+
sessions += n;
|
|
126
|
+
provider(id).sessions += n;
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
}
|
package/package.json
CHANGED
package/templates/env.example
CHANGED
|
@@ -7,3 +7,6 @@ BIG_SPENDER_DEVICE_ID=
|
|
|
7
7
|
BIG_SPENDER_INGEST_URL=
|
|
8
8
|
# Same value as BIG_SPENDER_INGEST_TOKEN on the server.
|
|
9
9
|
BIG_SPENDER_INGEST_TOKEN=
|
|
10
|
+
# Optional, on one machine only: a Cursor user API key. The collector then reads the account's
|
|
11
|
+
# usage from Cursor's API and sends it as the device "cursor". Set by `big-spender install --cursor`.
|
|
12
|
+
# BIG_SPENDER_CURSOR_API_KEY=
|