squidgems 0.1.1 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +48 -15
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -154,12 +154,18 @@ async function requestToken(squidId) {
154
154
  headers: { "Content-Type": "application/json" },
155
155
  body: JSON.stringify({ squid_id: squidId })
156
156
  });
157
- if (res.status === 403 || res.status === 404)
158
- return null;
157
+ if (res.status === 403) {
158
+ const body = await res.json().catch(() => ({}));
159
+ if (body.error === "subscription_expired")
160
+ return { token: null, error: "subscription_expired" };
161
+ return { token: null, error: "tombstoned" };
162
+ }
163
+ if (res.status === 404)
164
+ return { token: null };
159
165
  if (!res.ok)
160
166
  throw new Error(`Token request failed: ${res.status}`);
161
167
  const data = await res.json();
162
- return data.token;
168
+ return { token: data.token };
163
169
  }
164
170
  async function refreshToken(squidId, token) {
165
171
  const res = await fetch(`${API_BASE}/api/squid/token/refresh`, {
@@ -227,6 +233,8 @@ async function getOrCreateUserId() {
227
233
  // src/open-browser.ts
228
234
  var import_child_process = require("child_process");
229
235
  function openBrowser(url) {
236
+ if (true)
237
+ return;
230
238
  let cmd;
231
239
  let args;
232
240
  switch (process.platform) {
@@ -263,10 +271,12 @@ async function runInitClaude() {
263
271
  mergeOtelEnv(userId);
264
272
  console.log("✓ Modified ~/.claude/settings.json");
265
273
  try {
266
- const token = await requestToken(userId);
267
- if (token) {
268
- updateConfigToken(token);
274
+ const result = await requestToken(userId);
275
+ if (result.token) {
276
+ updateConfigToken(result.token);
269
277
  console.log("✓ Token cached");
278
+ } else if (result.error === "subscription_expired") {
279
+ console.warn("⚠ Your SquidGems trial has expired. Subscribe at https://squidgems.ink/settings");
270
280
  } else {
271
281
  console.warn("Warning: Could not obtain token. Run `squidgems` first to register.");
272
282
  }
@@ -367,6 +377,20 @@ async function syncInstall(localId) {
367
377
  }
368
378
 
369
379
  // src/token.ts
380
+ var import_fs4 = require("fs");
381
+ var import_crypto3 = require("crypto");
382
+ function getSquidSessionId() {
383
+ const ppid = process.ppid;
384
+ const filePath = `/tmp/squidgems-session-${ppid}.json`;
385
+ try {
386
+ const data = JSON.parse(import_fs4.readFileSync(filePath, "utf-8"));
387
+ if (data.squid_session_id)
388
+ return data.squid_session_id;
389
+ } catch {}
390
+ const squid_session_id = import_crypto3.randomUUID();
391
+ import_fs4.writeFileSync(filePath, JSON.stringify({ squid_session_id }));
392
+ return squid_session_id;
393
+ }
370
394
  function output(headers) {
371
395
  process.stdout.write(JSON.stringify(headers));
372
396
  }
@@ -377,26 +401,35 @@ async function runToken() {
377
401
  return;
378
402
  }
379
403
  const { userId, token: cachedToken } = config;
404
+ const sessionId = getSquidSessionId();
380
405
  if (cachedToken) {
381
406
  try {
382
407
  const newToken = await refreshToken(userId, cachedToken);
383
408
  if (newToken) {
384
409
  updateConfigToken(newToken);
385
- output({ X_Squid_Token: newToken, X_Squid_User_Id: userId });
410
+ output({ X_Squid_Token: newToken, X_Squid_User_Id: userId, X_Squid_Session_Id: sessionId });
386
411
  } else {
387
412
  updateConfigToken(null);
388
413
  output({});
389
414
  }
390
415
  } catch {
391
- output({ X_Squid_Token: cachedToken, X_Squid_User_Id: userId });
416
+ output({
417
+ X_Squid_Token: cachedToken,
418
+ X_Squid_User_Id: userId,
419
+ X_Squid_Session_Id: sessionId
420
+ });
392
421
  }
393
422
  return;
394
423
  }
395
424
  try {
396
- const token = await requestToken(userId);
397
- if (token) {
398
- updateConfigToken(token);
399
- output({ X_Squid_Token: token, X_Squid_User_Id: userId });
425
+ const result = await requestToken(userId);
426
+ if (result.token) {
427
+ updateConfigToken(result.token);
428
+ output({
429
+ X_Squid_Token: result.token,
430
+ X_Squid_User_Id: userId,
431
+ X_Squid_Session_Id: sessionId
432
+ });
400
433
  } else {
401
434
  output({});
402
435
  }
@@ -406,7 +439,7 @@ async function runToken() {
406
439
  }
407
440
 
408
441
  // src/uninstall.ts
409
- var import_fs4 = __toESM(require("fs"));
442
+ var import_fs5 = __toESM(require("fs"));
410
443
  var import_os3 = __toESM(require("os"));
411
444
  var import_path3 = __toESM(require("path"));
412
445
  function runUninstall() {
@@ -417,8 +450,8 @@ function runUninstall() {
417
450
  console.log("✓ Telemetry disabled in ~/.claude/settings.json");
418
451
  }
419
452
  const squidDir = import_path3.default.join(import_os3.default.homedir(), ".squidgems");
420
- if (import_fs4.default.existsSync(squidDir)) {
421
- import_fs4.default.rmSync(squidDir, { recursive: true, force: true });
453
+ if (import_fs5.default.existsSync(squidDir)) {
454
+ import_fs5.default.rmSync(squidDir, { recursive: true, force: true });
422
455
  console.log("✓ Removed ~/.squidgems");
423
456
  } else {
424
457
  console.log("~/.squidgems not found — nothing to remove.");
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "squidgems",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Track Claude Code costs, tokens, and sessions in real time",
5
5
  "private": false,
6
6
  "type": "commonjs",
7
- "license": "UNLICENSED",
7
+ "license": "MIT",
8
8
  "author": "SquidGems",
9
9
  "homepage": "https://squidgems.ink",
10
10
  "keywords": [