commet 0.4.1 → 0.4.3
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 +183 -177
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
));
|
|
25
25
|
|
|
26
26
|
// src/index.ts
|
|
27
|
-
var
|
|
27
|
+
var import_chalk11 = __toESM(require("chalk"));
|
|
28
28
|
var import_commander10 = require("commander");
|
|
29
29
|
|
|
30
30
|
// src/commands/info.ts
|
|
@@ -124,9 +124,9 @@ var infoCommand = new import_commander.Command("info").description("Display info
|
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
// src/commands/link.ts
|
|
127
|
-
var
|
|
127
|
+
var import_prompts = require("@inquirer/prompts");
|
|
128
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
128
129
|
var import_commander2 = require("commander");
|
|
129
|
-
var import_inquirer = __toESM(require("inquirer"));
|
|
130
130
|
var import_ora = __toESM(require("ora"));
|
|
131
131
|
|
|
132
132
|
// src/utils/api.ts
|
|
@@ -165,21 +165,38 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
// src/utils/prompt-theme.ts
|
|
169
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
170
|
+
var commetColor = import_chalk2.default.hex("#5BC0B0");
|
|
171
|
+
var promptTheme = {
|
|
172
|
+
prefix: commetColor("\u276F"),
|
|
173
|
+
style: {
|
|
174
|
+
answer: commetColor,
|
|
175
|
+
message: import_chalk2.default.bold,
|
|
176
|
+
error: import_chalk2.default.red,
|
|
177
|
+
help: import_chalk2.default.dim,
|
|
178
|
+
highlight: commetColor.bold,
|
|
179
|
+
// Selected option in mint
|
|
180
|
+
description: import_chalk2.default.dim,
|
|
181
|
+
defaultAnswer: import_chalk2.default.dim
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
168
185
|
// src/commands/link.ts
|
|
169
186
|
var linkCommand = new import_commander2.Command("link").description("Link this project to a Commet organization").action(async () => {
|
|
170
187
|
if (!authExists()) {
|
|
171
|
-
console.log(
|
|
172
|
-
console.log(
|
|
188
|
+
console.log(import_chalk3.default.red("\u2717 Not authenticated"));
|
|
189
|
+
console.log(import_chalk3.default.dim("Run `commet login` first"));
|
|
173
190
|
return;
|
|
174
191
|
}
|
|
175
192
|
if (projectConfigExists()) {
|
|
176
193
|
const config = loadProjectConfig();
|
|
177
|
-
console.log(
|
|
194
|
+
console.log(import_chalk3.default.yellow("\u26A0 This project is already linked"));
|
|
178
195
|
console.log(
|
|
179
|
-
|
|
196
|
+
import_chalk3.default.dim(`Organization: ${config?.orgName} (${config?.environment})`)
|
|
180
197
|
);
|
|
181
198
|
console.log(
|
|
182
|
-
|
|
199
|
+
import_chalk3.default.dim(
|
|
183
200
|
"\nRun `commet unlink` first if you want to change the organization"
|
|
184
201
|
)
|
|
185
202
|
);
|
|
@@ -189,7 +206,7 @@ var linkCommand = new import_commander2.Command("link").description("Link this p
|
|
|
189
206
|
const auth = loadAuth();
|
|
190
207
|
if (!auth) {
|
|
191
208
|
spinner.fail("Authentication error");
|
|
192
|
-
console.log(
|
|
209
|
+
console.log(import_chalk3.default.red("\u2717 Could not load authentication"));
|
|
193
210
|
return;
|
|
194
211
|
}
|
|
195
212
|
const baseURL = getBaseURL(auth.environment);
|
|
@@ -198,88 +215,81 @@ var linkCommand = new import_commander2.Command("link").description("Link this p
|
|
|
198
215
|
);
|
|
199
216
|
if (result.error || !result.data) {
|
|
200
217
|
spinner.fail("Failed to fetch organizations");
|
|
201
|
-
console.error(
|
|
218
|
+
console.error(import_chalk3.default.red("Error:"), result.error);
|
|
202
219
|
return;
|
|
203
220
|
}
|
|
204
221
|
const { organizations } = result.data;
|
|
205
222
|
if (organizations.length === 0) {
|
|
206
223
|
spinner.stop();
|
|
207
|
-
console.log(
|
|
224
|
+
console.log(import_chalk3.default.yellow("\u26A0 No organizations found"));
|
|
208
225
|
console.log(
|
|
209
|
-
|
|
226
|
+
import_chalk3.default.dim("Create an organization at https://billing.commet.co first")
|
|
210
227
|
);
|
|
211
228
|
return;
|
|
212
229
|
}
|
|
213
230
|
spinner.stop();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
name: "orgId",
|
|
231
|
+
let orgId;
|
|
232
|
+
try {
|
|
233
|
+
orgId = await (0, import_prompts.select)({
|
|
218
234
|
message: "Select organization:",
|
|
219
235
|
choices: organizations.map((org) => ({
|
|
220
|
-
name: `${org.name} (${org.slug})`,
|
|
236
|
+
name: `${org.name} ${import_chalk3.default.dim(`(${org.slug})`)}`,
|
|
221
237
|
value: org.id
|
|
222
|
-
}))
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
{ name: "Production", value: "production" }
|
|
231
|
-
],
|
|
232
|
-
default: "sandbox"
|
|
233
|
-
}
|
|
234
|
-
]);
|
|
235
|
-
const selectedOrg = organizations.find((org) => org.id === answers.orgId);
|
|
238
|
+
})),
|
|
239
|
+
theme: promptTheme
|
|
240
|
+
});
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.log(import_chalk3.default.yellow("\n\u26A0 Link cancelled"));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const selectedOrg = organizations.find((org) => org.id === orgId);
|
|
236
246
|
if (!selectedOrg) {
|
|
237
|
-
console.log(
|
|
247
|
+
console.log(import_chalk3.default.red("\u2717 Organization not found"));
|
|
238
248
|
return;
|
|
239
249
|
}
|
|
240
250
|
saveProjectConfig({
|
|
241
251
|
orgId: selectedOrg.id,
|
|
242
252
|
orgName: selectedOrg.name,
|
|
243
|
-
environment:
|
|
253
|
+
environment: auth.environment
|
|
244
254
|
});
|
|
245
|
-
console.log(
|
|
246
|
-
console.log(
|
|
247
|
-
console.log(
|
|
248
|
-
console.log(
|
|
255
|
+
console.log(import_chalk3.default.green("\n\u2713 Project linked successfully!"));
|
|
256
|
+
console.log(import_chalk3.default.dim("\nProject configuration:"));
|
|
257
|
+
console.log(import_chalk3.default.dim(` Organization: ${selectedOrg.name}`));
|
|
258
|
+
console.log(import_chalk3.default.dim(` Environment: ${auth.environment}`));
|
|
249
259
|
console.log(
|
|
250
|
-
|
|
260
|
+
import_chalk3.default.dim(
|
|
251
261
|
"\nNext step:\n Run `commet pull` to generate TypeScript types"
|
|
252
262
|
)
|
|
253
263
|
);
|
|
254
264
|
});
|
|
255
265
|
|
|
256
266
|
// src/commands/list.ts
|
|
257
|
-
var
|
|
267
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
258
268
|
var import_commander3 = require("commander");
|
|
259
269
|
var import_ora2 = __toESM(require("ora"));
|
|
260
270
|
var listCommand = new import_commander3.Command("list").description("List event types or seat types").argument("<type>", "Type to list (events or seats)").action(async (type) => {
|
|
261
271
|
if (type !== "events" && type !== "seats") {
|
|
262
|
-
console.log(
|
|
263
|
-
console.log(
|
|
264
|
-
console.log(
|
|
265
|
-
console.log(
|
|
272
|
+
console.log(import_chalk4.default.red('\u2717 Invalid type. Use "events" or "seats"'));
|
|
273
|
+
console.log(import_chalk4.default.dim("\nExamples:"));
|
|
274
|
+
console.log(import_chalk4.default.dim(" commet list events"));
|
|
275
|
+
console.log(import_chalk4.default.dim(" commet list seats"));
|
|
266
276
|
return;
|
|
267
277
|
}
|
|
268
278
|
if (!authExists()) {
|
|
269
|
-
console.log(
|
|
270
|
-
console.log(
|
|
279
|
+
console.log(import_chalk4.default.red("\u2717 Not authenticated"));
|
|
280
|
+
console.log(import_chalk4.default.dim("Run `commet login` first"));
|
|
271
281
|
return;
|
|
272
282
|
}
|
|
273
283
|
if (!projectConfigExists()) {
|
|
274
|
-
console.log(
|
|
284
|
+
console.log(import_chalk4.default.red("\u2717 Project not linked"));
|
|
275
285
|
console.log(
|
|
276
|
-
|
|
286
|
+
import_chalk4.default.dim("Run `commet link` first to connect to an organization")
|
|
277
287
|
);
|
|
278
288
|
return;
|
|
279
289
|
}
|
|
280
290
|
const projectConfig = loadProjectConfig();
|
|
281
291
|
if (!projectConfig) {
|
|
282
|
-
console.log(
|
|
292
|
+
console.log(import_chalk4.default.red("\u2717 Invalid project configuration"));
|
|
283
293
|
return;
|
|
284
294
|
}
|
|
285
295
|
const spinner = (0, import_ora2.default)(`Fetching ${type}...`).start();
|
|
@@ -289,49 +299,49 @@ var listCommand = new import_commander3.Command("list").description("List event
|
|
|
289
299
|
);
|
|
290
300
|
if (result.error || !result.data) {
|
|
291
301
|
spinner.fail(`Failed to fetch ${type}`);
|
|
292
|
-
console.error(
|
|
302
|
+
console.error(import_chalk4.default.red("Error:"), result.error);
|
|
293
303
|
return;
|
|
294
304
|
}
|
|
295
305
|
spinner.stop();
|
|
296
306
|
if (type === "events") {
|
|
297
307
|
const { eventTypes } = result.data;
|
|
298
308
|
if (eventTypes.length === 0) {
|
|
299
|
-
console.log(
|
|
309
|
+
console.log(import_chalk4.default.yellow("\u26A0 No event types found"));
|
|
300
310
|
console.log(
|
|
301
|
-
|
|
311
|
+
import_chalk4.default.dim("Create event types in your Commet dashboard first")
|
|
302
312
|
);
|
|
303
313
|
return;
|
|
304
314
|
}
|
|
305
|
-
console.log(
|
|
315
|
+
console.log(import_chalk4.default.bold(`
|
|
306
316
|
\u{1F4CA} Event Types (${eventTypes.length})
|
|
307
317
|
`));
|
|
308
318
|
for (const eventType of eventTypes) {
|
|
309
|
-
console.log(
|
|
310
|
-
console.log(
|
|
319
|
+
console.log(import_chalk4.default.green(`\u2022 ${eventType.code}`));
|
|
320
|
+
console.log(import_chalk4.default.dim(` ${eventType.name}`));
|
|
311
321
|
if (eventType.description) {
|
|
312
|
-
console.log(
|
|
322
|
+
console.log(import_chalk4.default.dim(` ${eventType.description}`));
|
|
313
323
|
}
|
|
314
324
|
console.log("");
|
|
315
325
|
}
|
|
316
326
|
} else {
|
|
317
327
|
const { seatTypes } = result.data;
|
|
318
328
|
if (seatTypes.length === 0) {
|
|
319
|
-
console.log(
|
|
329
|
+
console.log(import_chalk4.default.yellow("\u26A0 No seat types found"));
|
|
320
330
|
console.log(
|
|
321
|
-
|
|
331
|
+
import_chalk4.default.dim("Create seat types in your Commet dashboard first")
|
|
322
332
|
);
|
|
323
333
|
return;
|
|
324
334
|
}
|
|
325
|
-
console.log(
|
|
335
|
+
console.log(import_chalk4.default.bold(`
|
|
326
336
|
\u{1F4BA} Seat Types (${seatTypes.length})
|
|
327
337
|
`));
|
|
328
338
|
for (const seatType of seatTypes) {
|
|
329
339
|
console.log(
|
|
330
|
-
|
|
340
|
+
import_chalk4.default.green(`\u2022 ${seatType.code}${seatType.isFree ? " (Free)" : ""}`)
|
|
331
341
|
);
|
|
332
|
-
console.log(
|
|
342
|
+
console.log(import_chalk4.default.dim(` ${seatType.name}`));
|
|
333
343
|
if (seatType.description) {
|
|
334
|
-
console.log(
|
|
344
|
+
console.log(import_chalk4.default.dim(` ${seatType.description}`));
|
|
335
345
|
}
|
|
336
346
|
console.log("");
|
|
337
347
|
}
|
|
@@ -339,37 +349,43 @@ var listCommand = new import_commander3.Command("list").description("List event
|
|
|
339
349
|
});
|
|
340
350
|
|
|
341
351
|
// src/commands/login.ts
|
|
342
|
-
var
|
|
352
|
+
var import_prompts2 = require("@inquirer/prompts");
|
|
353
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
343
354
|
var import_commander4 = require("commander");
|
|
344
|
-
var import_inquirer2 = __toESM(require("inquirer"));
|
|
345
355
|
var import_open = __toESM(require("open"));
|
|
346
356
|
var import_ora3 = __toESM(require("ora"));
|
|
347
357
|
var loginCommand = new import_commander4.Command("login").description("Authenticate with Commet").action(async () => {
|
|
348
358
|
if (authExists()) {
|
|
349
359
|
const auth = loadAuth();
|
|
350
|
-
console.log(
|
|
360
|
+
console.log(import_chalk5.default.yellow("\u26A0 You are already logged in."));
|
|
351
361
|
console.log(
|
|
352
|
-
|
|
362
|
+
import_chalk5.default.dim(
|
|
353
363
|
"Run `commet logout` first if you want to login with a different account."
|
|
354
364
|
)
|
|
355
365
|
);
|
|
356
366
|
return;
|
|
357
367
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
name: "environment",
|
|
368
|
+
let environment;
|
|
369
|
+
try {
|
|
370
|
+
environment = await (0, import_prompts2.select)({
|
|
362
371
|
message: "Select environment to login:",
|
|
363
372
|
choices: [
|
|
364
373
|
{
|
|
365
|
-
name:
|
|
374
|
+
name: `Sandbox ${import_chalk5.default.dim("(Development)")}`,
|
|
366
375
|
value: "sandbox"
|
|
367
376
|
},
|
|
368
|
-
{
|
|
377
|
+
{
|
|
378
|
+
name: "Production",
|
|
379
|
+
value: "production"
|
|
380
|
+
}
|
|
369
381
|
],
|
|
370
|
-
default: "sandbox"
|
|
371
|
-
|
|
372
|
-
|
|
382
|
+
default: "sandbox",
|
|
383
|
+
theme: promptTheme
|
|
384
|
+
});
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.log(import_chalk5.default.yellow("\n\u26A0 Login cancelled"));
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
373
389
|
const spinner = (0, import_ora3.default)("Initiating login flow...").start();
|
|
374
390
|
const baseURL = getBaseURL(environment);
|
|
375
391
|
try {
|
|
@@ -383,7 +399,7 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
383
399
|
});
|
|
384
400
|
if (!deviceResponse.ok) {
|
|
385
401
|
spinner.fail("Failed to initiate login");
|
|
386
|
-
console.error(
|
|
402
|
+
console.error(import_chalk5.default.red("Error:"), await deviceResponse.text());
|
|
387
403
|
return;
|
|
388
404
|
}
|
|
389
405
|
const deviceData = await deviceResponse.json();
|
|
@@ -394,16 +410,16 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
394
410
|
interval = 5
|
|
395
411
|
} = deviceData;
|
|
396
412
|
spinner.stop();
|
|
397
|
-
console.log(
|
|
413
|
+
console.log(import_chalk5.default.bold("\n\u{1F510} Commet CLI Login\n"));
|
|
398
414
|
console.log("Visit the following URL in your browser:");
|
|
399
|
-
console.log(
|
|
415
|
+
console.log(import_chalk5.default.cyan.underline(verification_uri_complete));
|
|
400
416
|
console.log("\nOr enter this code manually:");
|
|
401
|
-
console.log(
|
|
402
|
-
console.log(
|
|
417
|
+
console.log(import_chalk5.default.bold.green(` ${user_code}`));
|
|
418
|
+
console.log(import_chalk5.default.dim("\nOpening browser...\n"));
|
|
403
419
|
try {
|
|
404
420
|
await (0, import_open.default)(verification_uri_complete);
|
|
405
421
|
} catch {
|
|
406
|
-
console.log(
|
|
422
|
+
console.log(import_chalk5.default.yellow("\u26A0 Could not open browser automatically."));
|
|
407
423
|
}
|
|
408
424
|
const pollSpinner = (0, import_ora3.default)("Waiting for authorization...").start();
|
|
409
425
|
let pollingInterval = interval;
|
|
@@ -412,7 +428,7 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
412
428
|
const poll = async () => {
|
|
413
429
|
if (attempts >= maxAttempts) {
|
|
414
430
|
pollSpinner.fail("Login timed out");
|
|
415
|
-
console.log(
|
|
431
|
+
console.log(import_chalk5.default.red("Authorization timed out. Please try again."));
|
|
416
432
|
return;
|
|
417
433
|
}
|
|
418
434
|
attempts++;
|
|
@@ -443,9 +459,9 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
443
459
|
}
|
|
444
460
|
saveAuth(authConfig);
|
|
445
461
|
pollSpinner.succeed("Successfully logged in!");
|
|
446
|
-
console.log(
|
|
462
|
+
console.log(import_chalk5.default.green("\n\u2713 Authentication complete"));
|
|
447
463
|
console.log(
|
|
448
|
-
|
|
464
|
+
import_chalk5.default.dim(
|
|
449
465
|
"\nNext steps:\n 1. Run `commet link` to connect a project\n 2. Run `commet pull` to generate types\n"
|
|
450
466
|
)
|
|
451
467
|
);
|
|
@@ -458,12 +474,12 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
458
474
|
setTimeout(() => poll(), pollingInterval * 1e3);
|
|
459
475
|
} else if (tokenData.error === "access_denied") {
|
|
460
476
|
pollSpinner.fail("Authorization denied");
|
|
461
|
-
console.log(
|
|
477
|
+
console.log(import_chalk5.default.red("\n\u2717 You denied the authorization request."));
|
|
462
478
|
return;
|
|
463
479
|
} else if (tokenData.error === "expired_token") {
|
|
464
480
|
pollSpinner.fail("Code expired");
|
|
465
481
|
console.log(
|
|
466
|
-
|
|
482
|
+
import_chalk5.default.red(
|
|
467
483
|
"\n\u2717 The authorization code expired. Please try again."
|
|
468
484
|
)
|
|
469
485
|
);
|
|
@@ -471,7 +487,7 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
471
487
|
} else {
|
|
472
488
|
pollSpinner.fail("Authorization failed");
|
|
473
489
|
console.log(
|
|
474
|
-
|
|
490
|
+
import_chalk5.default.red("\n\u2717 Error:"),
|
|
475
491
|
tokenData.error || "Unknown error"
|
|
476
492
|
);
|
|
477
493
|
return;
|
|
@@ -479,7 +495,7 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
479
495
|
} catch (error) {
|
|
480
496
|
pollSpinner.fail("Network error");
|
|
481
497
|
console.error(
|
|
482
|
-
|
|
498
|
+
import_chalk5.default.red("Error:"),
|
|
483
499
|
error instanceof Error ? error.message : "Unknown error"
|
|
484
500
|
);
|
|
485
501
|
}
|
|
@@ -488,28 +504,28 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
488
504
|
} catch (error) {
|
|
489
505
|
spinner.fail("Login failed");
|
|
490
506
|
console.error(
|
|
491
|
-
|
|
507
|
+
import_chalk5.default.red("Error:"),
|
|
492
508
|
error instanceof Error ? error.message : "Unknown error"
|
|
493
509
|
);
|
|
494
510
|
}
|
|
495
511
|
});
|
|
496
512
|
|
|
497
513
|
// src/commands/logout.ts
|
|
498
|
-
var
|
|
514
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
499
515
|
var import_commander5 = require("commander");
|
|
500
516
|
var logoutCommand = new import_commander5.Command("logout").description("Log out of Commet").action(async () => {
|
|
501
517
|
if (!authExists()) {
|
|
502
|
-
console.log(
|
|
518
|
+
console.log(import_chalk6.default.yellow("\u26A0 You are not logged in."));
|
|
503
519
|
return;
|
|
504
520
|
}
|
|
505
521
|
clearAuth();
|
|
506
|
-
console.log(
|
|
522
|
+
console.log(import_chalk6.default.green("\u2713 Successfully logged out"));
|
|
507
523
|
});
|
|
508
524
|
|
|
509
525
|
// src/commands/pull.ts
|
|
510
526
|
var fs2 = __toESM(require("fs"));
|
|
511
527
|
var path2 = __toESM(require("path"));
|
|
512
|
-
var
|
|
528
|
+
var import_chalk7 = __toESM(require("chalk"));
|
|
513
529
|
var import_commander6 = require("commander");
|
|
514
530
|
var import_ora4 = __toESM(require("ora"));
|
|
515
531
|
|
|
@@ -527,60 +543,57 @@ function generateTypes(eventTypes, seatTypes) {
|
|
|
527
543
|
// Do not edit this file manually - run 'commet pull' to update
|
|
528
544
|
|
|
529
545
|
/**
|
|
530
|
-
*
|
|
546
|
+
* Module augmentation for automatic type inference
|
|
547
|
+
*
|
|
548
|
+
* This augments the Commet SDK to automatically use your organization's
|
|
549
|
+
* specific event and seat types without requiring generic type parameters.
|
|
550
|
+
*
|
|
551
|
+
* Event types available in your organization:
|
|
531
552
|
${eventComments}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* Seat types available in your organization
|
|
553
|
+
*
|
|
554
|
+
* Seat types available in your organization:
|
|
537
555
|
${seatComments}
|
|
538
|
-
*/
|
|
539
|
-
export type CommetSeatType = ${seatTypeUnion};
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* Use these types with the Commet SDK for type-safe event and seat tracking
|
|
543
556
|
*
|
|
544
557
|
* @example
|
|
545
|
-
* import { Commet } from 'commet';
|
|
546
|
-
* import type { CommetEventType, CommetSeatType } from './.commet';
|
|
558
|
+
* import { Commet } from '@commet/node';
|
|
547
559
|
*
|
|
548
560
|
* const commet = new Commet({ apiKey: 'your-api-key' });
|
|
549
561
|
*
|
|
550
|
-
* //
|
|
551
|
-
* await commet.usage.
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* timestamp: new Date(),
|
|
562
|
+
* // \u2705 Autocomplete works automatically!
|
|
563
|
+
* await commet.usage.events.create({
|
|
564
|
+
* eventType: 'api_call', // Only accepts your event types
|
|
565
|
+
* customerId: 'cus_123'
|
|
555
566
|
* });
|
|
556
567
|
*
|
|
557
|
-
* //
|
|
558
|
-
* await commet.seats.
|
|
559
|
-
* customerId: 'cust_123',
|
|
560
|
-
* seatType: 'admin_seat', // Autocomplete works!
|
|
561
|
-
* totalSeats: 5,
|
|
562
|
-
* });
|
|
568
|
+
* // \u2705 Same for seats
|
|
569
|
+
* await commet.seats.add('cus_123', 'admin', 5);
|
|
563
570
|
*/
|
|
571
|
+
declare module '@commet/node' {
|
|
572
|
+
interface CommetGeneratedTypes {
|
|
573
|
+
eventType: ${eventTypeUnion};
|
|
574
|
+
seatType: ${seatTypeUnion};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
564
577
|
`;
|
|
565
578
|
}
|
|
566
579
|
|
|
567
580
|
// src/commands/pull.ts
|
|
568
581
|
var pullCommand = new import_commander6.Command("pull").description("Pull type definitions from Commet").option("-o, --output <file>", "Output file path", ".commet.d.ts").action(async (options) => {
|
|
569
582
|
if (!authExists()) {
|
|
570
|
-
console.log(
|
|
571
|
-
console.log(
|
|
583
|
+
console.log(import_chalk7.default.red("\u2717 Not authenticated"));
|
|
584
|
+
console.log(import_chalk7.default.dim("Run `commet login` first"));
|
|
572
585
|
return;
|
|
573
586
|
}
|
|
574
587
|
if (!projectConfigExists()) {
|
|
575
|
-
console.log(
|
|
588
|
+
console.log(import_chalk7.default.red("\u2717 Project not linked"));
|
|
576
589
|
console.log(
|
|
577
|
-
|
|
590
|
+
import_chalk7.default.dim("Run `commet link` first to connect to an organization")
|
|
578
591
|
);
|
|
579
592
|
return;
|
|
580
593
|
}
|
|
581
594
|
const projectConfig = loadProjectConfig();
|
|
582
595
|
if (!projectConfig) {
|
|
583
|
-
console.log(
|
|
596
|
+
console.log(import_chalk7.default.red("\u2717 Invalid project configuration"));
|
|
584
597
|
return;
|
|
585
598
|
}
|
|
586
599
|
const spinner = (0, import_ora4.default)("Fetching type definitions...").start();
|
|
@@ -590,7 +603,7 @@ var pullCommand = new import_commander6.Command("pull").description("Pull type d
|
|
|
590
603
|
);
|
|
591
604
|
if (result.error || !result.data) {
|
|
592
605
|
spinner.fail("Failed to fetch types");
|
|
593
|
-
console.error(
|
|
606
|
+
console.error(import_chalk7.default.red("Error:"), result.error);
|
|
594
607
|
return;
|
|
595
608
|
}
|
|
596
609
|
const { eventTypes, seatTypes } = result.data;
|
|
@@ -598,23 +611,23 @@ var pullCommand = new import_commander6.Command("pull").description("Pull type d
|
|
|
598
611
|
const outputPath = path2.resolve(process.cwd(), options.output);
|
|
599
612
|
fs2.writeFileSync(outputPath, typeDefinitions, "utf8");
|
|
600
613
|
spinner.succeed("Type definitions generated!");
|
|
601
|
-
console.log(
|
|
602
|
-
console.log(
|
|
614
|
+
console.log(import_chalk7.default.green("\n\u2713 Success"));
|
|
615
|
+
console.log(import_chalk7.default.dim("\nGenerated types:"));
|
|
603
616
|
console.log(
|
|
604
|
-
|
|
617
|
+
import_chalk7.default.dim(
|
|
605
618
|
` Event types: ${eventTypes.length > 0 ? eventTypes.map((e) => e.code).join(", ") : "none"}`
|
|
606
619
|
)
|
|
607
620
|
);
|
|
608
621
|
console.log(
|
|
609
|
-
|
|
622
|
+
import_chalk7.default.dim(
|
|
610
623
|
` Seat types: ${seatTypes.length > 0 ? seatTypes.map((s) => s.code).join(", ") : "none"}`
|
|
611
624
|
)
|
|
612
625
|
);
|
|
613
|
-
console.log(
|
|
626
|
+
console.log(import_chalk7.default.dim(`
|
|
614
627
|
Output file: ${outputPath}`));
|
|
615
628
|
if (eventTypes.length === 0 && seatTypes.length === 0) {
|
|
616
629
|
console.log(
|
|
617
|
-
|
|
630
|
+
import_chalk7.default.yellow(
|
|
618
631
|
"\n\u26A0 No types found. Create event types and seat types in your Commet dashboard."
|
|
619
632
|
)
|
|
620
633
|
);
|
|
@@ -622,20 +635,20 @@ Output file: ${outputPath}`));
|
|
|
622
635
|
});
|
|
623
636
|
|
|
624
637
|
// src/commands/switch.ts
|
|
625
|
-
var
|
|
638
|
+
var import_prompts3 = require("@inquirer/prompts");
|
|
639
|
+
var import_chalk8 = __toESM(require("chalk"));
|
|
626
640
|
var import_commander7 = require("commander");
|
|
627
|
-
var import_inquirer3 = __toESM(require("inquirer"));
|
|
628
641
|
var import_ora5 = __toESM(require("ora"));
|
|
629
642
|
var switchCommand = new import_commander7.Command("switch").description("Switch to a different organization").action(async () => {
|
|
630
643
|
if (!authExists()) {
|
|
631
|
-
console.log(
|
|
632
|
-
console.log(
|
|
644
|
+
console.log(import_chalk8.default.red("\u2717 Not authenticated"));
|
|
645
|
+
console.log(import_chalk8.default.dim("Run `commet login` first"));
|
|
633
646
|
return;
|
|
634
647
|
}
|
|
635
648
|
if (!projectConfigExists()) {
|
|
636
|
-
console.log(
|
|
649
|
+
console.log(import_chalk8.default.yellow("\u26A0 Project not linked"));
|
|
637
650
|
console.log(
|
|
638
|
-
|
|
651
|
+
import_chalk8.default.dim("Run `commet link` first to connect to an organization")
|
|
639
652
|
);
|
|
640
653
|
return;
|
|
641
654
|
}
|
|
@@ -643,7 +656,7 @@ var switchCommand = new import_commander7.Command("switch").description("Switch
|
|
|
643
656
|
const auth = loadAuth();
|
|
644
657
|
if (!auth) {
|
|
645
658
|
spinner.fail("Authentication error");
|
|
646
|
-
console.log(
|
|
659
|
+
console.log(import_chalk8.default.red("\u2717 Could not load authentication"));
|
|
647
660
|
return;
|
|
648
661
|
}
|
|
649
662
|
const baseURL = getBaseURL(auth.environment);
|
|
@@ -652,92 +665,85 @@ var switchCommand = new import_commander7.Command("switch").description("Switch
|
|
|
652
665
|
);
|
|
653
666
|
if (result.error || !result.data) {
|
|
654
667
|
spinner.fail("Failed to fetch organizations");
|
|
655
|
-
console.error(
|
|
668
|
+
console.error(import_chalk8.default.red("Error:"), result.error);
|
|
656
669
|
return;
|
|
657
670
|
}
|
|
658
671
|
const { organizations } = result.data;
|
|
659
672
|
if (organizations.length === 0) {
|
|
660
673
|
spinner.stop();
|
|
661
|
-
console.log(
|
|
674
|
+
console.log(import_chalk8.default.yellow("\u26A0 No organizations found"));
|
|
662
675
|
return;
|
|
663
676
|
}
|
|
664
677
|
spinner.stop();
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
name: "orgId",
|
|
678
|
+
let orgId;
|
|
679
|
+
try {
|
|
680
|
+
orgId = await (0, import_prompts3.select)({
|
|
669
681
|
message: "Select organization:",
|
|
670
682
|
choices: organizations.map((org) => ({
|
|
671
|
-
name: `${org.name} (${org.slug})`,
|
|
683
|
+
name: `${org.name} ${import_chalk8.default.dim(`(${org.slug})`)}`,
|
|
672
684
|
value: org.id
|
|
673
|
-
}))
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
{ name: "Production", value: "production" }
|
|
682
|
-
],
|
|
683
|
-
default: "sandbox"
|
|
684
|
-
}
|
|
685
|
-
]);
|
|
686
|
-
const selectedOrg = organizations.find((org) => org.id === answers.orgId);
|
|
685
|
+
})),
|
|
686
|
+
theme: promptTheme
|
|
687
|
+
});
|
|
688
|
+
} catch (error) {
|
|
689
|
+
console.log(import_chalk8.default.yellow("\n\u26A0 Switch cancelled"));
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
const selectedOrg = organizations.find((org) => org.id === orgId);
|
|
687
693
|
if (!selectedOrg) {
|
|
688
|
-
console.log(
|
|
694
|
+
console.log(import_chalk8.default.red("\u2717 Organization not found"));
|
|
689
695
|
return;
|
|
690
696
|
}
|
|
691
697
|
saveProjectConfig({
|
|
692
698
|
orgId: selectedOrg.id,
|
|
693
699
|
orgName: selectedOrg.name,
|
|
694
|
-
environment:
|
|
700
|
+
environment: auth.environment
|
|
695
701
|
});
|
|
696
|
-
console.log(
|
|
697
|
-
console.log(
|
|
698
|
-
console.log(
|
|
699
|
-
console.log(
|
|
702
|
+
console.log(import_chalk8.default.green("\n\u2713 Switched organization successfully!"));
|
|
703
|
+
console.log(import_chalk8.default.dim("\nNew configuration:"));
|
|
704
|
+
console.log(import_chalk8.default.dim(` Organization: ${selectedOrg.name}`));
|
|
705
|
+
console.log(import_chalk8.default.dim(` Environment: ${auth.environment}`));
|
|
700
706
|
console.log(
|
|
701
|
-
|
|
707
|
+
import_chalk8.default.dim(
|
|
702
708
|
"\nRun `commet pull` to update TypeScript types for this organization"
|
|
703
709
|
)
|
|
704
710
|
);
|
|
705
711
|
});
|
|
706
712
|
|
|
707
713
|
// src/commands/unlink.ts
|
|
708
|
-
var
|
|
714
|
+
var import_chalk9 = __toESM(require("chalk"));
|
|
709
715
|
var import_commander8 = require("commander");
|
|
710
716
|
var unlinkCommand = new import_commander8.Command("unlink").description("Unlink this project from Commet").action(async () => {
|
|
711
717
|
if (!projectConfigExists()) {
|
|
712
718
|
console.log(
|
|
713
|
-
|
|
719
|
+
import_chalk9.default.yellow("\u26A0 This project is not linked to any organization")
|
|
714
720
|
);
|
|
715
721
|
return;
|
|
716
722
|
}
|
|
717
723
|
clearProjectConfig();
|
|
718
|
-
console.log(
|
|
719
|
-
console.log(
|
|
724
|
+
console.log(import_chalk9.default.green("\u2713 Project unlinked successfully"));
|
|
725
|
+
console.log(import_chalk9.default.dim("Run `commet link` to connect to an organization"));
|
|
720
726
|
});
|
|
721
727
|
|
|
722
728
|
// src/commands/whoami.ts
|
|
723
|
-
var
|
|
729
|
+
var import_chalk10 = __toESM(require("chalk"));
|
|
724
730
|
var import_commander9 = require("commander");
|
|
725
731
|
var whoamiCommand = new import_commander9.Command("whoami").description("Display current authentication and project status").action(async () => {
|
|
726
732
|
if (!authExists()) {
|
|
727
|
-
console.log(
|
|
728
|
-
console.log(
|
|
733
|
+
console.log(import_chalk10.default.yellow("\u26A0 Not logged in"));
|
|
734
|
+
console.log(import_chalk10.default.dim("Run `commet login` to authenticate"));
|
|
729
735
|
return;
|
|
730
736
|
}
|
|
731
|
-
console.log(
|
|
737
|
+
console.log(import_chalk10.default.green("\u2713 Logged in"));
|
|
732
738
|
const projectConfig = loadProjectConfig();
|
|
733
739
|
if (projectConfig) {
|
|
734
|
-
console.log(
|
|
735
|
-
console.log(
|
|
736
|
-
console.log(
|
|
740
|
+
console.log(import_chalk10.default.bold("\nProject:"));
|
|
741
|
+
console.log(import_chalk10.default.dim("Organization:"), projectConfig.orgName);
|
|
742
|
+
console.log(import_chalk10.default.dim("Environment:"), projectConfig.environment);
|
|
737
743
|
} else {
|
|
738
|
-
console.log(
|
|
744
|
+
console.log(import_chalk10.default.yellow("\n\u26A0 No project linked"));
|
|
739
745
|
console.log(
|
|
740
|
-
|
|
746
|
+
import_chalk10.default.dim(
|
|
741
747
|
"Run `commet link` to connect this directory to an organization"
|
|
742
748
|
)
|
|
743
749
|
);
|
|
@@ -766,7 +772,7 @@ try {
|
|
|
766
772
|
if (error.message.includes("outputHelp")) {
|
|
767
773
|
process.exit(0);
|
|
768
774
|
}
|
|
769
|
-
console.error(
|
|
775
|
+
console.error(import_chalk11.default.red("Error:"), error.message);
|
|
770
776
|
}
|
|
771
777
|
process.exit(1);
|
|
772
778
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commet",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Commet CLI - Manage your billing platform from the command line",
|
|
5
5
|
"bin": {
|
|
6
6
|
"commet": "./bin/commet"
|
|
@@ -19,16 +19,15 @@
|
|
|
19
19
|
"author": "Commet Team",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@inquirer/prompts": "^7.8.6",
|
|
22
23
|
"chalk": "^5.3.0",
|
|
23
24
|
"commander": "^12.0.0",
|
|
24
|
-
"inquirer": "^9.2.0",
|
|
25
25
|
"open": "^10.0.0",
|
|
26
26
|
"ora": "^7.0.1",
|
|
27
|
-
"@commet/node": "0.
|
|
27
|
+
"@commet/node": "0.5.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@biomejs/biome": "^1.9.4",
|
|
31
|
-
"@types/inquirer": "^9.0.9",
|
|
32
31
|
"@types/node": "^20.10.0",
|
|
33
32
|
"tsup": "^8.0.1",
|
|
34
33
|
"typescript": "^5.3.3"
|