sheetlink 0.1.14 → 0.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sheetlink",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "CLI for SheetLink — sync your bank transactions to any destination",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api.js CHANGED
@@ -28,12 +28,21 @@ async function request(method, path, body = null) {
28
28
 
29
29
  if (!res.ok) {
30
30
  let detail = res.statusText;
31
+ let errorBody = null;
31
32
  try {
32
- const err = await res.json();
33
- detail = err.detail || JSON.stringify(err);
33
+ errorBody = await res.json();
34
+ detail = errorBody.detail || JSON.stringify(errorBody);
34
35
  } catch {}
35
36
 
36
37
  if (res.status === 401) {
38
+ // Structured ITEM_LOGIN_REQUIRED from backend
39
+ const detailObj = typeof detail === 'object' ? detail : (errorBody?.detail ?? null);
40
+ if (detailObj && detailObj.error_code === 'ITEM_LOGIN_REQUIRED') {
41
+ const err = new Error('ITEM_LOGIN_REQUIRED');
42
+ err.code = 'ITEM_LOGIN_REQUIRED';
43
+ err.item_id = detailObj.item_id;
44
+ throw err;
45
+ }
37
46
  console.error('Authentication failed. Run `sheetlink auth` to re-authenticate.');
38
47
  process.exit(1);
39
48
  }
@@ -23,6 +23,7 @@ export async function cmdSync(options) {
23
23
 
24
24
  // Collect items to sync
25
25
  let itemIds;
26
+ const institutionNames = {};
26
27
  if (itemId) {
27
28
  itemIds = [itemId];
28
29
  } else {
@@ -31,6 +32,9 @@ export async function cmdSync(options) {
31
32
  console.error('No connected banks found. Connect a bank at https://sheetlink.app/dashboard');
32
33
  process.exit(1);
33
34
  }
35
+ for (const item of items) {
36
+ if (item.institution_name) institutionNames[item.item_id] = item.institution_name;
37
+ }
34
38
  itemIds = items.map(i => i.item_id);
35
39
  }
36
40
 
@@ -55,7 +59,12 @@ export async function cmdSync(options) {
55
59
  process.stderr.write(`\r✓ Synced ${id} — ${result.transactions?.length ?? 0} transactions\n`);
56
60
  } catch (e) {
57
61
  clearInterval(spinner);
58
- process.stderr.write(`\r✗ ${id} ${e.message}\n`);
62
+ if (e.code === 'ITEM_LOGIN_REQUIRED') {
63
+ const name = institutionNames[id] || id;
64
+ process.stderr.write(`\r✗ ${name} — Login required. Re-authenticate at https://sheetlink.app/dashboard/banks\n`);
65
+ } else {
66
+ process.stderr.write(`\r✗ ${id} — ${e.message}\n`);
67
+ }
59
68
  }
60
69
  }
61
70