breakroom 2.0.1 → 2.0.2

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.
Files changed (2) hide show
  1. package/bin/setup.js +28 -1
  2. package/package.json +1 -1
package/bin/setup.js CHANGED
@@ -110,6 +110,33 @@ function requestJson(url) {
110
110
  });
111
111
  }
112
112
 
113
+ function postJson(url, data) {
114
+ return new Promise((resolve, reject) => {
115
+ const body = JSON.stringify(data);
116
+ const u = new URL(url);
117
+ const opts = {
118
+ hostname: u.hostname, port: u.port, path: u.pathname,
119
+ method: 'POST',
120
+ headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }
121
+ };
122
+ const req = https.request(opts, (res) => {
123
+ let respBody = '';
124
+ res.setEncoding('utf8');
125
+ res.on('data', (chunk) => { respBody += chunk; });
126
+ res.on('end', () => {
127
+ try {
128
+ resolve({ status: res.statusCode || 0, json: JSON.parse(respBody) });
129
+ } catch (err) {
130
+ reject(new Error(`Invalid response from Break Room (${res.statusCode}): ${respBody.slice(0, 160)}`));
131
+ }
132
+ });
133
+ });
134
+ req.on('error', reject);
135
+ req.write(body);
136
+ req.end();
137
+ });
138
+ }
139
+
113
140
  async function verifyLicense(licenseKey) {
114
141
  const encoded = encodeURIComponent(licenseKey);
115
142
  const response = await requestJson(`${API_ORIGIN}/breakroom/${encoded}/v1`);
@@ -421,7 +448,7 @@ async function actionRecover() {
421
448
  const email = (await ask('Enter the email you used for purchase: ')).trim().toLowerCase();
422
449
  if (!email) { console.log('Canceled.\n'); return; }
423
450
  try {
424
- const resp = await requestJson(`${API_ORIGIN}/breakroom/license/lookup/${encodeURIComponent(email)}`);
451
+ const resp = await postJson(`${API_ORIGIN}/breakroom/license/lookup`, { email });
425
452
  if (resp.status !== 200) {
426
453
  console.log(`\x1b[31mNo licenses found for ${email}.\x1b[0m`);
427
454
  console.log('Make sure you used the same email at checkout.\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "breakroom",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Paid-license proxy routing for agents that get stuck in loops.",
5
5
  "bin": {
6
6
  "breakroom": "./bin/setup.js"