opencode-interrupt-plugin 0.4.38 → 0.4.40

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.
@@ -1,63 +1,60 @@
1
+ import { execSync } from 'child_process';
2
+ import { writeFileSync, unlinkSync } from 'fs';
1
3
  const POLAR_ORG_ID = '166f4429-84b8-4e41-9c74-eff1b8724873';
2
- const POLAR_VALIDATE_URL = 'https://api.polar.sh/v1/customer-portal/license-keys/validate';
3
- const POLAR_ACTIVATE_URL = 'https://api.polar.sh/v1/customer-portal/license-keys/activate';
4
+ const POLAR_HOST = 'https://api.polar.sh';
4
5
  const OFFLINE_GRACE_DAYS = 7;
5
- async function timeoutSignal(ms) {
6
- const ctrl = new AbortController();
7
- setTimeout(() => ctrl.abort(), ms);
8
- return ctrl.signal;
6
+ const TMP_BODY = '/tmp/polar-request-body.json';
7
+ function curlPost(path, body, timeoutMs) {
8
+ const connectTimeout = Math.ceil(timeoutMs / 1000);
9
+ writeFileSync(TMP_BODY, JSON.stringify(body), 'utf-8');
10
+ const cmd = `curl -s -w '\n%{http_code}' -X POST -H 'Content-Type: application/json' -d @${TMP_BODY} --connect-timeout ${connectTimeout} --max-time ${connectTimeout} '${POLAR_HOST}${path}'`;
11
+ try {
12
+ const output = execSync(cmd, { encoding: 'utf-8', timeout: timeoutMs + 2000 });
13
+ const parts = output.trim().split('\n');
14
+ const statusCode = parseInt(parts.pop() || '0', 10);
15
+ const raw = parts.join('\n');
16
+ let data;
17
+ try {
18
+ data = JSON.parse(raw);
19
+ }
20
+ catch {
21
+ data = raw;
22
+ }
23
+ return { status: statusCode, data };
24
+ }
25
+ finally {
26
+ try {
27
+ unlinkSync(TMP_BODY);
28
+ }
29
+ catch { /* ignore */ }
30
+ }
9
31
  }
10
32
  export async function activateLicense(key, machineLabel) {
11
33
  try {
12
- const response = await fetch(POLAR_ACTIVATE_URL, {
13
- method: 'POST',
14
- headers: { 'Content-Type': 'application/json' },
15
- body: JSON.stringify({
16
- key,
17
- organization_id: POLAR_ORG_ID,
18
- label: machineLabel,
19
- conditions: { major_version: 1 },
20
- }),
21
- signal: await timeoutSignal(8000),
22
- });
23
- if (response.status === 200) {
24
- const data = await response.json();
34
+ const { status, data } = curlPost('/v1/customer-portal/license-keys/activate', { key, organization_id: POLAR_ORG_ID, label: machineLabel, conditions: { major_version: 1 } }, 8000);
35
+ if (status === 200) {
25
36
  return {
26
37
  valid: true,
27
38
  activationId: data.id,
28
39
  email: data.license_key?.customer?.email,
29
40
  };
30
41
  }
31
- if (response.status === 403) {
42
+ if (status === 403) {
32
43
  return { valid: false, reason: 'License key activation limit reached (max 3 machines). Deactivate another machine first.' };
33
44
  }
34
- if (response.status === 404) {
45
+ if (status === 404) {
35
46
  return { valid: false, reason: 'License key not found. Check your key and try again.' };
36
47
  }
37
- return { valid: false, reason: `Activation failed (status ${response.status})` };
48
+ return { valid: false, reason: `Activation failed (status ${status})` };
38
49
  }
39
50
  catch (err) {
40
- if (err.name === 'TimeoutError') {
41
- return { valid: false, reason: 'Network timeout during activation. Check your internet connection.' };
42
- }
43
51
  return { valid: false, reason: `Activation error: ${err.message}` };
44
52
  }
45
53
  }
46
54
  export async function validateLicense(key, activationId) {
47
55
  try {
48
- const response = await fetch(POLAR_VALIDATE_URL, {
49
- method: 'POST',
50
- headers: { 'Content-Type': 'application/json' },
51
- body: JSON.stringify({
52
- key,
53
- organization_id: POLAR_ORG_ID,
54
- activation_id: activationId,
55
- conditions: { major_version: 1 },
56
- }),
57
- signal: await timeoutSignal(5000),
58
- });
59
- if (response.status === 200) {
60
- const data = await response.json();
56
+ const { status, data } = curlPost('/v1/customer-portal/license-keys/validate', { key, organization_id: POLAR_ORG_ID, activation_id: activationId, conditions: { major_version: 1 } }, 5000);
57
+ if (status === 200) {
61
58
  const isValid = data.status === 'granted';
62
59
  return {
63
60
  valid: isValid,
@@ -65,10 +62,10 @@ export async function validateLicense(key, activationId) {
65
62
  email: data.customer?.email,
66
63
  };
67
64
  }
68
- if (response.status === 404) {
65
+ if (status === 404) {
69
66
  return { valid: false, reason: 'License key revoked or not found.' };
70
67
  }
71
- return { valid: false, reason: `Validation failed (status ${response.status})` };
68
+ return { valid: false, reason: `Validation failed (status ${status})` };
72
69
  }
73
70
  catch {
74
71
  return { valid: false, reason: 'OFFLINE' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-interrupt-plugin",
3
- "version": "0.4.38",
3
+ "version": "0.4.40",
4
4
  "description": "Streaming TTS + voice interruption for OpenCode. Speaks responses as they arrive and detects when you talk over it.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",