opencode-interrupt-plugin 0.4.38 → 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.
- package/dist/license/validator.js +46 -40
- package/package.json +1 -1
|
@@ -1,63 +1,69 @@
|
|
|
1
|
+
import https from 'https';
|
|
1
2
|
const POLAR_ORG_ID = '166f4429-84b8-4e41-9c74-eff1b8724873';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
});
|
|
9
40
|
}
|
|
10
41
|
export async function activateLicense(key, machineLabel) {
|
|
11
42
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
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();
|
|
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) {
|
|
25
45
|
return {
|
|
26
46
|
valid: true,
|
|
27
47
|
activationId: data.id,
|
|
28
48
|
email: data.license_key?.customer?.email,
|
|
29
49
|
};
|
|
30
50
|
}
|
|
31
|
-
if (
|
|
51
|
+
if (status === 403) {
|
|
32
52
|
return { valid: false, reason: 'License key activation limit reached (max 3 machines). Deactivate another machine first.' };
|
|
33
53
|
}
|
|
34
|
-
if (
|
|
54
|
+
if (status === 404) {
|
|
35
55
|
return { valid: false, reason: 'License key not found. Check your key and try again.' };
|
|
36
56
|
}
|
|
37
|
-
return { valid: false, reason: `Activation failed (status ${
|
|
57
|
+
return { valid: false, reason: `Activation failed (status ${status})` };
|
|
38
58
|
}
|
|
39
59
|
catch (err) {
|
|
40
|
-
if (err.name === 'TimeoutError') {
|
|
41
|
-
return { valid: false, reason: 'Network timeout during activation. Check your internet connection.' };
|
|
42
|
-
}
|
|
43
60
|
return { valid: false, reason: `Activation error: ${err.message}` };
|
|
44
61
|
}
|
|
45
62
|
}
|
|
46
63
|
export async function validateLicense(key, activationId) {
|
|
47
64
|
try {
|
|
48
|
-
const
|
|
49
|
-
|
|
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();
|
|
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) {
|
|
61
67
|
const isValid = data.status === 'granted';
|
|
62
68
|
return {
|
|
63
69
|
valid: isValid,
|
|
@@ -65,10 +71,10 @@ export async function validateLicense(key, activationId) {
|
|
|
65
71
|
email: data.customer?.email,
|
|
66
72
|
};
|
|
67
73
|
}
|
|
68
|
-
if (
|
|
74
|
+
if (status === 404) {
|
|
69
75
|
return { valid: false, reason: 'License key revoked or not found.' };
|
|
70
76
|
}
|
|
71
|
-
return { valid: false, reason: `Validation failed (status ${
|
|
77
|
+
return { valid: false, reason: `Validation failed (status ${status})` };
|
|
72
78
|
}
|
|
73
79
|
catch {
|
|
74
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.
|
|
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",
|