commet 1.8.0 → 1.9.0
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/index.js +31 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var import_commander12 = require("commander");
|
|
|
30
30
|
// package.json
|
|
31
31
|
var package_default = {
|
|
32
32
|
name: "commet",
|
|
33
|
-
version: "1.
|
|
33
|
+
version: "1.9.0",
|
|
34
34
|
description: "Commet CLI - Manage your billing platform from the command line",
|
|
35
35
|
bin: {
|
|
36
36
|
commet: "./bin/commet"
|
|
@@ -165,13 +165,7 @@ function clearProjectConfig() {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
// src/utils/api.ts
|
|
168
|
-
var BASE_URL = "https://
|
|
169
|
-
function bypassHeaders() {
|
|
170
|
-
return {
|
|
171
|
-
Cookie: "_vercel_jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJiZXRhLmNvbW1ldC5jbyIsImJ5cGFzcyI6IjFERUlTcngyczA3YXFjVmhBbVhDUnhjTEdvOHNZaGFTIiwiaWF0IjoxNzc4NjkxNzMxLCJzdWIiOiJwcm90ZWN0aW9uLWJ5cGFzcy1hdXRvbWF0aW9uIn0.ONjvMguLM-7wXfTppY1cQveu9IN05x4VSblB39YpW_A",
|
|
172
|
-
Origin: "https://beta.commet.co"
|
|
173
|
-
};
|
|
174
|
-
}
|
|
168
|
+
var BASE_URL = "https://commet.co";
|
|
175
169
|
async function apiRequest(endpoint, options = {}) {
|
|
176
170
|
const auth = loadAuth();
|
|
177
171
|
if (!auth) {
|
|
@@ -182,7 +176,6 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
182
176
|
...options,
|
|
183
177
|
headers: {
|
|
184
178
|
...options.headers,
|
|
185
|
-
...bypassHeaders(),
|
|
186
179
|
Authorization: `Bearer ${auth.token}`,
|
|
187
180
|
"Content-Type": "application/json"
|
|
188
181
|
}
|
|
@@ -232,7 +225,7 @@ async function performLogin() {
|
|
|
232
225
|
try {
|
|
233
226
|
const deviceResponse = await fetch(`${BASE_URL}/api/auth/device/code`, {
|
|
234
227
|
method: "POST",
|
|
235
|
-
headers: { "Content-Type": "application/json"
|
|
228
|
+
headers: { "Content-Type": "application/json" },
|
|
236
229
|
body: JSON.stringify({
|
|
237
230
|
client_id: "commet-cli",
|
|
238
231
|
scope: "openid profile email"
|
|
@@ -271,7 +264,7 @@ async function performLogin() {
|
|
|
271
264
|
try {
|
|
272
265
|
const tokenResponse = await fetch(`${BASE_URL}/api/auth/device/token`, {
|
|
273
266
|
method: "POST",
|
|
274
|
-
headers: { "Content-Type": "application/json"
|
|
267
|
+
headers: { "Content-Type": "application/json" },
|
|
275
268
|
body: JSON.stringify({
|
|
276
269
|
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
277
270
|
device_code,
|
|
@@ -1017,7 +1010,26 @@ function isListenMessage(data) {
|
|
|
1017
1010
|
const obj = data;
|
|
1018
1011
|
return typeof obj.payload === "object" && obj.payload !== null && typeof obj.headers === "object" && obj.headers !== null;
|
|
1019
1012
|
}
|
|
1020
|
-
|
|
1013
|
+
function resolveTargetUrl(input2) {
|
|
1014
|
+
if (/^\d+$/.test(input2)) {
|
|
1015
|
+
return `http://localhost:${input2}/`;
|
|
1016
|
+
}
|
|
1017
|
+
const withProtocol = input2.startsWith("http://") || input2.startsWith("https://") ? input2 : `http://${input2}`;
|
|
1018
|
+
const parsed = new URL(withProtocol);
|
|
1019
|
+
if (!parsed.port) {
|
|
1020
|
+
throw new Error(
|
|
1021
|
+
`Missing port in "${input2}". Example: commet listen localhost:3000/webhooks`
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
if (!parsed.pathname.endsWith("/")) {
|
|
1025
|
+
parsed.pathname += "/";
|
|
1026
|
+
}
|
|
1027
|
+
return parsed.toString();
|
|
1028
|
+
}
|
|
1029
|
+
var listenCommand = new import_commander5.Command("listen").description("Forward webhook events to your local server").argument(
|
|
1030
|
+
"<url>",
|
|
1031
|
+
"URL to forward to (e.g. localhost:3000, local.commet.co:3010/webhooks, or just a port)"
|
|
1032
|
+
).option("--events <types>", "Comma-separated event types to filter").action(async (url, options) => {
|
|
1021
1033
|
const auth = loadAuth();
|
|
1022
1034
|
if (!auth) {
|
|
1023
1035
|
console.log(import_chalk7.default.red("Not authenticated. Run: commet login"));
|
|
@@ -1028,9 +1040,13 @@ var listenCommand = new import_commander5.Command("listen").description("Forward
|
|
|
1028
1040
|
console.log(import_chalk7.default.red("No project linked. Run: commet link"));
|
|
1029
1041
|
process.exit(1);
|
|
1030
1042
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1043
|
+
let targetUrl;
|
|
1044
|
+
try {
|
|
1045
|
+
targetUrl = resolveTargetUrl(url);
|
|
1046
|
+
} catch (error) {
|
|
1047
|
+
console.log(
|
|
1048
|
+
import_chalk7.default.red(error instanceof Error ? error.message : "Invalid URL")
|
|
1049
|
+
);
|
|
1034
1050
|
process.exit(1);
|
|
1035
1051
|
}
|
|
1036
1052
|
async function fetchTokenRequest() {
|
|
@@ -1104,7 +1120,6 @@ var listenCommand = new import_commander5.Command("listen").description("Forward
|
|
|
1104
1120
|
process.exit(1);
|
|
1105
1121
|
});
|
|
1106
1122
|
const channel = ably.channels.get(channelName);
|
|
1107
|
-
const targetUrl = `http://localhost:${port}${options.path}`;
|
|
1108
1123
|
console.log("");
|
|
1109
1124
|
console.log(
|
|
1110
1125
|
import_chalk7.default.green(` \u2713 Authenticated (org: ${projectConfig.orgName})`)
|