opencode-interrupt-plugin 0.4.39 → 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,46 +1,37 @@
1
- import https from 'https';
1
+ import { execSync } from 'child_process';
2
+ import { writeFileSync, unlinkSync } from 'fs';
2
3
  const POLAR_ORG_ID = '166f4429-84b8-4e41-9c74-eff1b8724873';
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
+ const POLAR_HOST = 'https://api.polar.sh';
6
5
  const OFFLINE_GRACE_DAYS = 7;
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,
13
- method: 'POST',
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);
34
- });
35
- req.on('timeout', () => { req.destroy(); reject(new Error('Timeout')); });
36
- req.on('error', reject);
37
- req.write(bodyStr);
38
- req.end();
39
- });
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
+ }
40
31
  }
41
32
  export async function activateLicense(key, machineLabel) {
42
33
  try {
43
- const { status, data } = await httpsPost(POLAR_ACTIVATE_PATH, { key, organization_id: POLAR_ORG_ID, label: machineLabel, conditions: { major_version: 1 } }, 8000);
34
+ const { status, data } = curlPost('/v1/customer-portal/license-keys/activate', { key, organization_id: POLAR_ORG_ID, label: machineLabel, conditions: { major_version: 1 } }, 8000);
44
35
  if (status === 200) {
45
36
  return {
46
37
  valid: true,
@@ -62,7 +53,7 @@ export async function activateLicense(key, machineLabel) {
62
53
  }
63
54
  export async function validateLicense(key, activationId) {
64
55
  try {
65
- const { status, data } = await httpsPost(POLAR_VALIDATE_PATH, { key, organization_id: POLAR_ORG_ID, activation_id: activationId, conditions: { major_version: 1 } }, 5000);
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);
66
57
  if (status === 200) {
67
58
  const isValid = data.status === 'granted';
68
59
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-interrupt-plugin",
3
- "version": "0.4.39",
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",