opencode-interrupt-plugin 0.4.37 → 0.4.39

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,58 +1,69 @@
1
+ import https from 'https';
1
2
  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';
3
+ const POLAR_HOST = 'api.polar.sh';
4
+ const POLAR_ACTIVATE_PATH = '/v1/customer-portal/license-keys/activate';
5
+ const POLAR_VALIDATE_PATH = '/v1/customer-portal/license-keys/validate';
4
6
  const OFFLINE_GRACE_DAYS = 7;
5
- export async function activateLicense(key, machineLabel) {
6
- try {
7
- const response = await fetch(POLAR_ACTIVATE_URL, {
7
+ function httpsPost(path, body, timeoutMs) {
8
+ return new Promise((resolve, reject) => {
9
+ const bodyStr = JSON.stringify(body);
10
+ const req = https.request({
11
+ hostname: POLAR_HOST,
12
+ path,
8
13
  method: 'POST',
9
- headers: { 'Content-Type': 'application/json' },
10
- body: JSON.stringify({
11
- key,
12
- organization_id: POLAR_ORG_ID,
13
- label: machineLabel,
14
- conditions: { major_version: 1 },
15
- }),
16
- signal: AbortSignal.timeout(8000),
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ 'Content-Length': Buffer.byteLength(bodyStr),
17
+ },
18
+ timeout: timeoutMs,
19
+ }, (res) => {
20
+ const chunks = [];
21
+ res.on('data', (chunk) => chunks.push(chunk));
22
+ res.on('end', () => {
23
+ const raw = Buffer.concat(chunks).toString();
24
+ let data;
25
+ try {
26
+ data = JSON.parse(raw);
27
+ }
28
+ catch {
29
+ data = raw;
30
+ }
31
+ resolve({ status: res.statusCode || 0, data });
32
+ });
33
+ res.on('error', reject);
17
34
  });
18
- if (response.status === 200) {
19
- const data = await response.json();
35
+ req.on('timeout', () => { req.destroy(); reject(new Error('Timeout')); });
36
+ req.on('error', reject);
37
+ req.write(bodyStr);
38
+ req.end();
39
+ });
40
+ }
41
+ export async function activateLicense(key, machineLabel) {
42
+ try {
43
+ const { status, data } = await httpsPost(POLAR_ACTIVATE_PATH, { key, organization_id: POLAR_ORG_ID, label: machineLabel, conditions: { major_version: 1 } }, 8000);
44
+ if (status === 200) {
20
45
  return {
21
46
  valid: true,
22
47
  activationId: data.id,
23
48
  email: data.license_key?.customer?.email,
24
49
  };
25
50
  }
26
- if (response.status === 403) {
51
+ if (status === 403) {
27
52
  return { valid: false, reason: 'License key activation limit reached (max 3 machines). Deactivate another machine first.' };
28
53
  }
29
- if (response.status === 404) {
54
+ if (status === 404) {
30
55
  return { valid: false, reason: 'License key not found. Check your key and try again.' };
31
56
  }
32
- return { valid: false, reason: `Activation failed (status ${response.status})` };
57
+ return { valid: false, reason: `Activation failed (status ${status})` };
33
58
  }
34
59
  catch (err) {
35
- if (err.name === 'TimeoutError') {
36
- return { valid: false, reason: 'Network timeout during activation. Check your internet connection.' };
37
- }
38
60
  return { valid: false, reason: `Activation error: ${err.message}` };
39
61
  }
40
62
  }
41
63
  export async function validateLicense(key, activationId) {
42
64
  try {
43
- const response = await fetch(POLAR_VALIDATE_URL, {
44
- method: 'POST',
45
- headers: { 'Content-Type': 'application/json' },
46
- body: JSON.stringify({
47
- key,
48
- organization_id: POLAR_ORG_ID,
49
- activation_id: activationId,
50
- conditions: { major_version: 1 },
51
- }),
52
- signal: AbortSignal.timeout(5000),
53
- });
54
- if (response.status === 200) {
55
- const data = await response.json();
65
+ const { status, data } = await httpsPost(POLAR_VALIDATE_PATH, { key, organization_id: POLAR_ORG_ID, activation_id: activationId, conditions: { major_version: 1 } }, 5000);
66
+ if (status === 200) {
56
67
  const isValid = data.status === 'granted';
57
68
  return {
58
69
  valid: isValid,
@@ -60,10 +71,10 @@ export async function validateLicense(key, activationId) {
60
71
  email: data.customer?.email,
61
72
  };
62
73
  }
63
- if (response.status === 404) {
74
+ if (status === 404) {
64
75
  return { valid: false, reason: 'License key revoked or not found.' };
65
76
  }
66
- return { valid: false, reason: `Validation failed (status ${response.status})` };
77
+ return { valid: false, reason: `Validation failed (status ${status})` };
67
78
  }
68
79
  catch {
69
80
  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.37",
3
+ "version": "0.4.39",
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",