refineo-cli 0.0.6 → 0.1.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 CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/refineo-cli)](https://www.npmjs.com/package/refineo-cli)
4
4
  [![PyPI version](https://img.shields.io/pypi/v/refineo-cli)](https://pypi.org/project/refineo-cli/)
5
5
 
6
- CLI and MCP tools for [Refineo](https://refineo.app) - Transform AI-generated text into natural human writing.
6
+ CLI and MCP tools for [Refineo](https://www.refineo.app) - Transform AI-generated text into natural human writing.
7
7
 
8
8
  ## Quick Start
9
9
 
@@ -78,56 +78,61 @@ Refineo provides an MCP server for integration with Claude Desktop, Cursor, and
78
78
  | `humanize_text` | Transform AI-generated text into natural human writing |
79
79
  | `get_usage` | Check remaining quota for current billing period |
80
80
 
81
- ### Setup for Claude Desktop
81
+ ### Authentication Options
82
82
 
83
- 1. First, get your access token:
84
- ```bash
85
- refineo login
86
- cat ~/.refineo/credentials.json # Copy accessToken value
87
- ```
83
+ **Option 1: API Key (Recommended for MCP)**
88
84
 
89
- 2. Add to Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
90
- ```json
91
- {
92
- "mcpServers": {
93
- "refineo": {
94
- "url": "https://refineo.app/mcp/mcp",
95
- "headers": {
96
- "Authorization": "Bearer YOUR_ACCESS_TOKEN"
97
- }
98
- }
99
- }
100
- }
101
- ```
85
+ API keys are long-lived (7 days to 1 year) and don't require refresh. Create one at [www.refineo.app/dashboard/api-keys](https://www.refineo.app/dashboard/api-keys).
102
86
 
103
- ### Setup for Cursor
87
+ **Option 2: Bearer Token**
104
88
 
105
- Add to Cursor MCP settings:
89
+ Use the CLI to get a short-lived access token (15 minutes). Suitable for quick testing.
90
+
91
+ ### Setup for Claude Code
92
+
93
+ Run this command (replace `sk_your_api_key` with your actual key):
94
+
95
+ ```bash
96
+ claude mcp add-json refineo '{"type":"http","url":"https://www.refineo.app/mcp/mcp","headers":{"X-API-Key":"sk_your_api_key"}}'
97
+ ```
98
+
99
+ ### Setup for Claude Desktop (Native OAuth - Recommended)
100
+
101
+ 1. Open Claude Desktop → Settings → Connectors
102
+ 2. Click "Add custom connector"
103
+ 3. Enter URL: `https://www.refineo.app/mcp/mcp`
104
+ 4. Click Add → Sign in with your Refineo account
105
+
106
+ No API key needed - uses OAuth authentication.
107
+
108
+ ### Setup for Claude Desktop / Cursor (API Key)
109
+
110
+ Alternatively, use an API key with the config file:
111
+ - **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
112
+ - **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
106
113
 
107
114
  ```json
108
115
  {
109
116
  "mcpServers": {
110
117
  "refineo": {
111
- "url": "https://refineo.app/mcp/mcp",
112
- "headers": {
113
- "Authorization": "Bearer YOUR_ACCESS_TOKEN"
114
- }
118
+ "command": "npx",
119
+ "args": [
120
+ "mcp-remote",
121
+ "https://www.refineo.app/mcp/mcp",
122
+ "--header",
123
+ "X-API-Key:sk_your_api_key_here"
124
+ ]
115
125
  }
116
126
  }
117
127
  }
118
128
  ```
119
129
 
120
- ### Token Refresh
121
-
122
- Access tokens expire after 15 minutes. For long-running MCP sessions, you may need to refresh periodically:
130
+ > Requires Node.js. Uses [mcp-remote](https://github.com/geelen/mcp-remote) as a proxy.
123
131
 
124
- ```bash
125
- # Check token status
126
- refineo stats
132
+ ### Token Refresh
127
133
 
128
- # Re-login if expired
129
- refineo login
130
- ```
134
+ - **API Keys**: No refresh needed until expiry (7d-1y). Create new keys at [dashboard/api-keys](https://www.refineo.app/dashboard/api-keys).
135
+ - **Bearer Tokens**: Expire after 15 minutes. Run `refineo login` to refresh.
131
136
 
132
137
  ## Development
133
138
 
@@ -150,9 +155,10 @@ refineo login
150
155
 
151
156
  ## Links
152
157
 
153
- - [Refineo App](https://refineo.app)
154
- - [Pricing](https://refineo.app/pricing)
155
- - [Manage Connected Devices](https://refineo.app/dashboard/sessions)
158
+ - [Refineo App](https://www.refineo.app)
159
+ - [Pricing](https://www.refineo.app/pricing)
160
+ - [Manage API Keys](https://www.refineo.app/dashboard/api-keys)
161
+ - [Manage Connected Devices](https://www.refineo.app/dashboard/sessions)
156
162
 
157
163
  ## License
158
164
 
package/dist/cjs/api.js CHANGED
@@ -69,42 +69,65 @@ function getPlatformInfo() {
69
69
  if (platform === "darwin") os = "macOS";
70
70
  else if (platform === "win32") os = "Windows";
71
71
  else if (platform === "linux") os = "Linux";
72
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
72
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
73
73
  }
74
74
 
75
75
  // src/api.ts
76
76
  var USER_AGENT = getPlatformInfo();
77
+ var DEBUG = process.env.REFINEO_DEBUG === "1" || process.env.REFINEO_DEBUG === "true";
78
+ function debug(...args) {
79
+ if (DEBUG) {
80
+ console.error("[refineo-debug]", ...args);
81
+ }
82
+ }
77
83
  async function apiRequest(path, options = {}) {
78
84
  const credentials = loadCredentials();
79
85
  if (!credentials) {
80
86
  throw new Error("Not logged in. Run: refineo login");
81
87
  }
88
+ debug("Credentials loaded, email:", credentials.user.email);
89
+ debug("Token expiresAt:", credentials.expiresAt, "now:", Math.floor(Date.now() / 1e3));
82
90
  let token = credentials.accessToken;
83
91
  if (isTokenExpired(credentials)) {
92
+ debug("Token expired, refreshing...");
84
93
  const refreshed = await refreshToken(credentials.refreshToken);
85
94
  if (refreshed) {
86
95
  token = refreshed.accessToken;
96
+ debug("Token refreshed successfully");
87
97
  } else {
88
98
  throw new Error("Session expired. Run: refineo login");
89
99
  }
90
100
  }
91
- const response = await fetch(`${API_BASE_URL}${path}`, {
101
+ const url = `${API_BASE_URL}${path}`;
102
+ const headers = {
103
+ "Content-Type": "application/json",
104
+ "Authorization": `Bearer ${token}`,
105
+ "User-Agent": USER_AGENT
106
+ };
107
+ debug("Request URL:", url);
108
+ debug("Request method:", options.method || "GET");
109
+ debug("Authorization header set:", headers.Authorization.substring(0, 20) + "...");
110
+ const response = await fetch(url, {
92
111
  ...options,
93
- headers: {
94
- "Content-Type": "application/json",
95
- "Authorization": `Bearer ${token}`,
96
- "User-Agent": USER_AGENT,
97
- ...options.headers
98
- }
112
+ headers
99
113
  });
114
+ debug("Response status:", response.status);
100
115
  if (!response.ok) {
101
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
116
+ const errorText = await response.text();
117
+ debug("Error response:", errorText);
118
+ let error;
119
+ try {
120
+ error = JSON.parse(errorText);
121
+ } catch {
122
+ error = { error: errorText || "Unknown error" };
123
+ }
102
124
  throw new Error(error.message || error.error_description || error.error || `HTTP ${response.status}`);
103
125
  }
104
126
  return response.json();
105
127
  }
106
128
  async function refreshToken(refreshTokenValue) {
107
129
  try {
130
+ debug("Attempting token refresh...");
108
131
  const response = await fetch(`${API_BASE_URL}/api/auth/device/refresh`, {
109
132
  method: "POST",
110
133
  headers: {
@@ -116,7 +139,10 @@ async function refreshToken(refreshTokenValue) {
116
139
  grant_type: "refresh_token"
117
140
  })
118
141
  });
142
+ debug("Refresh response status:", response.status);
119
143
  if (!response.ok) {
144
+ const errorText = await response.text();
145
+ debug("Refresh error:", errorText);
120
146
  return null;
121
147
  }
122
148
  const data = await response.json();
@@ -128,8 +154,10 @@ async function refreshToken(refreshTokenValue) {
128
154
  user: oldCredentials?.user || { email: "", tier: "" }
129
155
  };
130
156
  saveCredentials(credentials);
157
+ debug("Token refreshed and saved");
131
158
  return credentials;
132
- } catch {
159
+ } catch (err) {
160
+ debug("Refresh exception:", err);
133
161
  return null;
134
162
  }
135
163
  }
package/dist/cjs/cli.js CHANGED
@@ -76,42 +76,65 @@ function getPlatformInfo() {
76
76
  if (platform === "darwin") os = "macOS";
77
77
  else if (platform === "win32") os = "Windows";
78
78
  else if (platform === "linux") os = "Linux";
79
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
79
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
80
80
  }
81
81
 
82
82
  // src/api.ts
83
83
  var USER_AGENT = getPlatformInfo();
84
+ var DEBUG = process.env.REFINEO_DEBUG === "1" || process.env.REFINEO_DEBUG === "true";
85
+ function debug(...args) {
86
+ if (DEBUG) {
87
+ console.error("[refineo-debug]", ...args);
88
+ }
89
+ }
84
90
  async function apiRequest(path, options = {}) {
85
91
  const credentials = loadCredentials();
86
92
  if (!credentials) {
87
93
  throw new Error("Not logged in. Run: refineo login");
88
94
  }
95
+ debug("Credentials loaded, email:", credentials.user.email);
96
+ debug("Token expiresAt:", credentials.expiresAt, "now:", Math.floor(Date.now() / 1e3));
89
97
  let token = credentials.accessToken;
90
98
  if (isTokenExpired(credentials)) {
99
+ debug("Token expired, refreshing...");
91
100
  const refreshed = await refreshToken(credentials.refreshToken);
92
101
  if (refreshed) {
93
102
  token = refreshed.accessToken;
103
+ debug("Token refreshed successfully");
94
104
  } else {
95
105
  throw new Error("Session expired. Run: refineo login");
96
106
  }
97
107
  }
98
- const response = await fetch(`${API_BASE_URL}${path}`, {
108
+ const url = `${API_BASE_URL}${path}`;
109
+ const headers = {
110
+ "Content-Type": "application/json",
111
+ "Authorization": `Bearer ${token}`,
112
+ "User-Agent": USER_AGENT
113
+ };
114
+ debug("Request URL:", url);
115
+ debug("Request method:", options.method || "GET");
116
+ debug("Authorization header set:", headers.Authorization.substring(0, 20) + "...");
117
+ const response = await fetch(url, {
99
118
  ...options,
100
- headers: {
101
- "Content-Type": "application/json",
102
- "Authorization": `Bearer ${token}`,
103
- "User-Agent": USER_AGENT,
104
- ...options.headers
105
- }
119
+ headers
106
120
  });
121
+ debug("Response status:", response.status);
107
122
  if (!response.ok) {
108
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
123
+ const errorText = await response.text();
124
+ debug("Error response:", errorText);
125
+ let error;
126
+ try {
127
+ error = JSON.parse(errorText);
128
+ } catch {
129
+ error = { error: errorText || "Unknown error" };
130
+ }
109
131
  throw new Error(error.message || error.error_description || error.error || `HTTP ${response.status}`);
110
132
  }
111
133
  return response.json();
112
134
  }
113
135
  async function refreshToken(refreshTokenValue) {
114
136
  try {
137
+ debug("Attempting token refresh...");
115
138
  const response = await fetch(`${API_BASE_URL}/api/auth/device/refresh`, {
116
139
  method: "POST",
117
140
  headers: {
@@ -123,7 +146,10 @@ async function refreshToken(refreshTokenValue) {
123
146
  grant_type: "refresh_token"
124
147
  })
125
148
  });
149
+ debug("Refresh response status:", response.status);
126
150
  if (!response.ok) {
151
+ const errorText = await response.text();
152
+ debug("Refresh error:", errorText);
127
153
  return null;
128
154
  }
129
155
  const data = await response.json();
@@ -135,8 +161,10 @@ async function refreshToken(refreshTokenValue) {
135
161
  user: oldCredentials?.user || { email: "", tier: "" }
136
162
  };
137
163
  saveCredentials(credentials);
164
+ debug("Token refreshed and saved");
138
165
  return credentials;
139
- } catch {
166
+ } catch (err) {
167
+ debug("Refresh exception:", err);
140
168
  return null;
141
169
  }
142
170
  }
@@ -451,7 +479,7 @@ ${colors.bold}Examples:${colors.reset}
451
479
  refineo stats
452
480
 
453
481
  ${colors.bold}More Info:${colors.reset}
454
- https://refineo.app/docs/cli
482
+ https://www.refineo.app/docs/cli
455
483
  `);
456
484
  }
457
485
  function versionCommand() {
@@ -77,7 +77,7 @@ function getPlatformInfo() {
77
77
  if (platform === "darwin") os = "macOS";
78
78
  else if (platform === "win32") os = "Windows";
79
79
  else if (platform === "linux") os = "Linux";
80
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
80
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
81
81
  }
82
82
  // Annotate the CommonJS export names for ESM import in node:
83
83
  0 && (module.exports = {
package/dist/cjs/index.js CHANGED
@@ -83,42 +83,65 @@ function getPlatformInfo() {
83
83
  if (platform === "darwin") os = "macOS";
84
84
  else if (platform === "win32") os = "Windows";
85
85
  else if (platform === "linux") os = "Linux";
86
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
86
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
87
87
  }
88
88
 
89
89
  // src/api.ts
90
90
  var USER_AGENT = getPlatformInfo();
91
+ var DEBUG = process.env.REFINEO_DEBUG === "1" || process.env.REFINEO_DEBUG === "true";
92
+ function debug(...args) {
93
+ if (DEBUG) {
94
+ console.error("[refineo-debug]", ...args);
95
+ }
96
+ }
91
97
  async function apiRequest(path, options = {}) {
92
98
  const credentials = loadCredentials();
93
99
  if (!credentials) {
94
100
  throw new Error("Not logged in. Run: refineo login");
95
101
  }
102
+ debug("Credentials loaded, email:", credentials.user.email);
103
+ debug("Token expiresAt:", credentials.expiresAt, "now:", Math.floor(Date.now() / 1e3));
96
104
  let token = credentials.accessToken;
97
105
  if (isTokenExpired(credentials)) {
106
+ debug("Token expired, refreshing...");
98
107
  const refreshed = await refreshToken(credentials.refreshToken);
99
108
  if (refreshed) {
100
109
  token = refreshed.accessToken;
110
+ debug("Token refreshed successfully");
101
111
  } else {
102
112
  throw new Error("Session expired. Run: refineo login");
103
113
  }
104
114
  }
105
- const response = await fetch(`${API_BASE_URL}${path}`, {
115
+ const url = `${API_BASE_URL}${path}`;
116
+ const headers = {
117
+ "Content-Type": "application/json",
118
+ "Authorization": `Bearer ${token}`,
119
+ "User-Agent": USER_AGENT
120
+ };
121
+ debug("Request URL:", url);
122
+ debug("Request method:", options.method || "GET");
123
+ debug("Authorization header set:", headers.Authorization.substring(0, 20) + "...");
124
+ const response = await fetch(url, {
106
125
  ...options,
107
- headers: {
108
- "Content-Type": "application/json",
109
- "Authorization": `Bearer ${token}`,
110
- "User-Agent": USER_AGENT,
111
- ...options.headers
112
- }
126
+ headers
113
127
  });
128
+ debug("Response status:", response.status);
114
129
  if (!response.ok) {
115
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
130
+ const errorText = await response.text();
131
+ debug("Error response:", errorText);
132
+ let error;
133
+ try {
134
+ error = JSON.parse(errorText);
135
+ } catch {
136
+ error = { error: errorText || "Unknown error" };
137
+ }
116
138
  throw new Error(error.message || error.error_description || error.error || `HTTP ${response.status}`);
117
139
  }
118
140
  return response.json();
119
141
  }
120
142
  async function refreshToken(refreshTokenValue) {
121
143
  try {
144
+ debug("Attempting token refresh...");
122
145
  const response = await fetch(`${API_BASE_URL}/api/auth/device/refresh`, {
123
146
  method: "POST",
124
147
  headers: {
@@ -130,7 +153,10 @@ async function refreshToken(refreshTokenValue) {
130
153
  grant_type: "refresh_token"
131
154
  })
132
155
  });
156
+ debug("Refresh response status:", response.status);
133
157
  if (!response.ok) {
158
+ const errorText = await response.text();
159
+ debug("Refresh error:", errorText);
134
160
  return null;
135
161
  }
136
162
  const data = await response.json();
@@ -142,8 +168,10 @@ async function refreshToken(refreshTokenValue) {
142
168
  user: oldCredentials?.user || { email: "", tier: "" }
143
169
  };
144
170
  saveCredentials(credentials);
171
+ debug("Token refreshed and saved");
145
172
  return credentials;
146
- } catch {
173
+ } catch (err) {
174
+ debug("Refresh exception:", err);
147
175
  return null;
148
176
  }
149
177
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAGlB,cAAc,EACd,UAAU,EACX,MAAM,YAAY,CAAC;AAoFpB;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAcvE;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,IAAI,GAClB,OAAO,CAAC,WAAW,CAAC,CA8DtB;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,UAAU,GAAG,UAAuB,GAC1C,OAAO,CAAC,cAAc,CAAC,CAqBzB;AAED;;GAEG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,CAoBpD"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAGlB,cAAc,EACd,UAAU,EACX,MAAM,YAAY,CAAC;AAuHpB;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAcvE;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,IAAI,GAClB,OAAO,CAAC,WAAW,CAAC,CA8DtB;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,UAAU,GAAG,UAAuB,GAC1C,OAAO,CAAC,cAAc,CAAC,CAqBzB;AAED;;GAEG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,CAoBpD"}
package/dist/esm/api.js CHANGED
@@ -40,42 +40,65 @@ function getPlatformInfo() {
40
40
  if (platform === "darwin") os = "macOS";
41
41
  else if (platform === "win32") os = "Windows";
42
42
  else if (platform === "linux") os = "Linux";
43
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
43
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
44
44
  }
45
45
 
46
46
  // src/api.ts
47
47
  var USER_AGENT = getPlatformInfo();
48
+ var DEBUG = process.env.REFINEO_DEBUG === "1" || process.env.REFINEO_DEBUG === "true";
49
+ function debug(...args) {
50
+ if (DEBUG) {
51
+ console.error("[refineo-debug]", ...args);
52
+ }
53
+ }
48
54
  async function apiRequest(path, options = {}) {
49
55
  const credentials = loadCredentials();
50
56
  if (!credentials) {
51
57
  throw new Error("Not logged in. Run: refineo login");
52
58
  }
59
+ debug("Credentials loaded, email:", credentials.user.email);
60
+ debug("Token expiresAt:", credentials.expiresAt, "now:", Math.floor(Date.now() / 1e3));
53
61
  let token = credentials.accessToken;
54
62
  if (isTokenExpired(credentials)) {
63
+ debug("Token expired, refreshing...");
55
64
  const refreshed = await refreshToken(credentials.refreshToken);
56
65
  if (refreshed) {
57
66
  token = refreshed.accessToken;
67
+ debug("Token refreshed successfully");
58
68
  } else {
59
69
  throw new Error("Session expired. Run: refineo login");
60
70
  }
61
71
  }
62
- const response = await fetch(`${API_BASE_URL}${path}`, {
72
+ const url = `${API_BASE_URL}${path}`;
73
+ const headers = {
74
+ "Content-Type": "application/json",
75
+ "Authorization": `Bearer ${token}`,
76
+ "User-Agent": USER_AGENT
77
+ };
78
+ debug("Request URL:", url);
79
+ debug("Request method:", options.method || "GET");
80
+ debug("Authorization header set:", headers.Authorization.substring(0, 20) + "...");
81
+ const response = await fetch(url, {
63
82
  ...options,
64
- headers: {
65
- "Content-Type": "application/json",
66
- "Authorization": `Bearer ${token}`,
67
- "User-Agent": USER_AGENT,
68
- ...options.headers
69
- }
83
+ headers
70
84
  });
85
+ debug("Response status:", response.status);
71
86
  if (!response.ok) {
72
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
87
+ const errorText = await response.text();
88
+ debug("Error response:", errorText);
89
+ let error;
90
+ try {
91
+ error = JSON.parse(errorText);
92
+ } catch {
93
+ error = { error: errorText || "Unknown error" };
94
+ }
73
95
  throw new Error(error.message || error.error_description || error.error || `HTTP ${response.status}`);
74
96
  }
75
97
  return response.json();
76
98
  }
77
99
  async function refreshToken(refreshTokenValue) {
78
100
  try {
101
+ debug("Attempting token refresh...");
79
102
  const response = await fetch(`${API_BASE_URL}/api/auth/device/refresh`, {
80
103
  method: "POST",
81
104
  headers: {
@@ -87,7 +110,10 @@ async function refreshToken(refreshTokenValue) {
87
110
  grant_type: "refresh_token"
88
111
  })
89
112
  });
113
+ debug("Refresh response status:", response.status);
90
114
  if (!response.ok) {
115
+ const errorText = await response.text();
116
+ debug("Refresh error:", errorText);
91
117
  return null;
92
118
  }
93
119
  const data = await response.json();
@@ -99,8 +125,10 @@ async function refreshToken(refreshTokenValue) {
99
125
  user: oldCredentials?.user || { email: "", tier: "" }
100
126
  };
101
127
  saveCredentials(credentials);
128
+ debug("Token refreshed and saved");
102
129
  return credentials;
103
- } catch {
130
+ } catch (err) {
131
+ debug("Refresh exception:", err);
104
132
  return null;
105
133
  }
106
134
  }
package/dist/esm/cli.js CHANGED
@@ -53,42 +53,65 @@ function getPlatformInfo() {
53
53
  if (platform === "darwin") os = "macOS";
54
54
  else if (platform === "win32") os = "Windows";
55
55
  else if (platform === "linux") os = "Linux";
56
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
56
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
57
57
  }
58
58
 
59
59
  // src/api.ts
60
60
  var USER_AGENT = getPlatformInfo();
61
+ var DEBUG = process.env.REFINEO_DEBUG === "1" || process.env.REFINEO_DEBUG === "true";
62
+ function debug(...args) {
63
+ if (DEBUG) {
64
+ console.error("[refineo-debug]", ...args);
65
+ }
66
+ }
61
67
  async function apiRequest(path, options = {}) {
62
68
  const credentials = loadCredentials();
63
69
  if (!credentials) {
64
70
  throw new Error("Not logged in. Run: refineo login");
65
71
  }
72
+ debug("Credentials loaded, email:", credentials.user.email);
73
+ debug("Token expiresAt:", credentials.expiresAt, "now:", Math.floor(Date.now() / 1e3));
66
74
  let token = credentials.accessToken;
67
75
  if (isTokenExpired(credentials)) {
76
+ debug("Token expired, refreshing...");
68
77
  const refreshed = await refreshToken(credentials.refreshToken);
69
78
  if (refreshed) {
70
79
  token = refreshed.accessToken;
80
+ debug("Token refreshed successfully");
71
81
  } else {
72
82
  throw new Error("Session expired. Run: refineo login");
73
83
  }
74
84
  }
75
- const response = await fetch(`${API_BASE_URL}${path}`, {
85
+ const url = `${API_BASE_URL}${path}`;
86
+ const headers = {
87
+ "Content-Type": "application/json",
88
+ "Authorization": `Bearer ${token}`,
89
+ "User-Agent": USER_AGENT
90
+ };
91
+ debug("Request URL:", url);
92
+ debug("Request method:", options.method || "GET");
93
+ debug("Authorization header set:", headers.Authorization.substring(0, 20) + "...");
94
+ const response = await fetch(url, {
76
95
  ...options,
77
- headers: {
78
- "Content-Type": "application/json",
79
- "Authorization": `Bearer ${token}`,
80
- "User-Agent": USER_AGENT,
81
- ...options.headers
82
- }
96
+ headers
83
97
  });
98
+ debug("Response status:", response.status);
84
99
  if (!response.ok) {
85
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
100
+ const errorText = await response.text();
101
+ debug("Error response:", errorText);
102
+ let error;
103
+ try {
104
+ error = JSON.parse(errorText);
105
+ } catch {
106
+ error = { error: errorText || "Unknown error" };
107
+ }
86
108
  throw new Error(error.message || error.error_description || error.error || `HTTP ${response.status}`);
87
109
  }
88
110
  return response.json();
89
111
  }
90
112
  async function refreshToken(refreshTokenValue) {
91
113
  try {
114
+ debug("Attempting token refresh...");
92
115
  const response = await fetch(`${API_BASE_URL}/api/auth/device/refresh`, {
93
116
  method: "POST",
94
117
  headers: {
@@ -100,7 +123,10 @@ async function refreshToken(refreshTokenValue) {
100
123
  grant_type: "refresh_token"
101
124
  })
102
125
  });
126
+ debug("Refresh response status:", response.status);
103
127
  if (!response.ok) {
128
+ const errorText = await response.text();
129
+ debug("Refresh error:", errorText);
104
130
  return null;
105
131
  }
106
132
  const data = await response.json();
@@ -112,8 +138,10 @@ async function refreshToken(refreshTokenValue) {
112
138
  user: oldCredentials?.user || { email: "", tier: "" }
113
139
  };
114
140
  saveCredentials(credentials);
141
+ debug("Token refreshed and saved");
115
142
  return credentials;
116
- } catch {
143
+ } catch (err) {
144
+ debug("Refresh exception:", err);
117
145
  return null;
118
146
  }
119
147
  }
@@ -428,7 +456,7 @@ ${colors.bold}Examples:${colors.reset}
428
456
  refineo stats
429
457
 
430
458
  ${colors.bold}More Info:${colors.reset}
431
- https://refineo.app/docs/cli
459
+ https://www.refineo.app/docs/cli
432
460
  `);
433
461
  }
434
462
  function versionCommand() {
@@ -48,7 +48,7 @@ function getPlatformInfo() {
48
48
  if (platform === "darwin") os = "macOS";
49
49
  else if (platform === "win32") os = "Windows";
50
50
  else if (platform === "linux") os = "Linux";
51
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
51
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
52
52
  }
53
53
  export {
54
54
  API_BASE_URL,
package/dist/esm/index.js CHANGED
@@ -48,42 +48,65 @@ function getPlatformInfo() {
48
48
  if (platform === "darwin") os = "macOS";
49
49
  else if (platform === "win32") os = "Windows";
50
50
  else if (platform === "linux") os = "Linux";
51
- return `refineo-cli-node/0.0.6 (${os}; ${arch}) Node/${nodeVersion}`;
51
+ return `refineo-cli-node/0.0.7 (${os}; ${arch}) Node/${nodeVersion}`;
52
52
  }
53
53
 
54
54
  // src/api.ts
55
55
  var USER_AGENT = getPlatformInfo();
56
+ var DEBUG = process.env.REFINEO_DEBUG === "1" || process.env.REFINEO_DEBUG === "true";
57
+ function debug(...args) {
58
+ if (DEBUG) {
59
+ console.error("[refineo-debug]", ...args);
60
+ }
61
+ }
56
62
  async function apiRequest(path, options = {}) {
57
63
  const credentials = loadCredentials();
58
64
  if (!credentials) {
59
65
  throw new Error("Not logged in. Run: refineo login");
60
66
  }
67
+ debug("Credentials loaded, email:", credentials.user.email);
68
+ debug("Token expiresAt:", credentials.expiresAt, "now:", Math.floor(Date.now() / 1e3));
61
69
  let token = credentials.accessToken;
62
70
  if (isTokenExpired(credentials)) {
71
+ debug("Token expired, refreshing...");
63
72
  const refreshed = await refreshToken(credentials.refreshToken);
64
73
  if (refreshed) {
65
74
  token = refreshed.accessToken;
75
+ debug("Token refreshed successfully");
66
76
  } else {
67
77
  throw new Error("Session expired. Run: refineo login");
68
78
  }
69
79
  }
70
- const response = await fetch(`${API_BASE_URL}${path}`, {
80
+ const url = `${API_BASE_URL}${path}`;
81
+ const headers = {
82
+ "Content-Type": "application/json",
83
+ "Authorization": `Bearer ${token}`,
84
+ "User-Agent": USER_AGENT
85
+ };
86
+ debug("Request URL:", url);
87
+ debug("Request method:", options.method || "GET");
88
+ debug("Authorization header set:", headers.Authorization.substring(0, 20) + "...");
89
+ const response = await fetch(url, {
71
90
  ...options,
72
- headers: {
73
- "Content-Type": "application/json",
74
- "Authorization": `Bearer ${token}`,
75
- "User-Agent": USER_AGENT,
76
- ...options.headers
77
- }
91
+ headers
78
92
  });
93
+ debug("Response status:", response.status);
79
94
  if (!response.ok) {
80
- const error = await response.json().catch(() => ({ error: "Unknown error" }));
95
+ const errorText = await response.text();
96
+ debug("Error response:", errorText);
97
+ let error;
98
+ try {
99
+ error = JSON.parse(errorText);
100
+ } catch {
101
+ error = { error: errorText || "Unknown error" };
102
+ }
81
103
  throw new Error(error.message || error.error_description || error.error || `HTTP ${response.status}`);
82
104
  }
83
105
  return response.json();
84
106
  }
85
107
  async function refreshToken(refreshTokenValue) {
86
108
  try {
109
+ debug("Attempting token refresh...");
87
110
  const response = await fetch(`${API_BASE_URL}/api/auth/device/refresh`, {
88
111
  method: "POST",
89
112
  headers: {
@@ -95,7 +118,10 @@ async function refreshToken(refreshTokenValue) {
95
118
  grant_type: "refresh_token"
96
119
  })
97
120
  });
121
+ debug("Refresh response status:", response.status);
98
122
  if (!response.ok) {
123
+ const errorText = await response.text();
124
+ debug("Refresh error:", errorText);
99
125
  return null;
100
126
  }
101
127
  const data = await response.json();
@@ -107,8 +133,10 @@ async function refreshToken(refreshTokenValue) {
107
133
  user: oldCredentials?.user || { email: "", tier: "" }
108
134
  };
109
135
  saveCredentials(credentials);
136
+ debug("Token refreshed and saved");
110
137
  return credentials;
111
- } catch {
138
+ } catch (err) {
139
+ debug("Refresh exception:", err);
112
140
  return null;
113
141
  }
114
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "refineo-cli",
3
- "version": "0.0.6",
3
+ "version": "0.1.1",
4
4
  "description": "Refineo AI Text Humanizer CLI - Transform AI-generated text into natural human writing",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/index.js",
@@ -44,7 +44,7 @@
44
44
  ],
45
45
  "author": "Refineo",
46
46
  "license": "MIT",
47
- "homepage": "https://refineo.app",
47
+ "homepage": "https://www.refineo.app",
48
48
  "engines": {
49
49
  "node": ">=18.0.0"
50
50
  },