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.
- package/dist/license/validator.js +30 -39
- package/package.json +1 -1
|
@@ -1,46 +1,37 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 } =
|
|
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 } =
|
|
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.
|
|
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",
|