@corsair-dev/cli 0.1.5 → 0.1.7
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 +28 -557
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -26,8 +26,8 @@ function getTsconfigInfo(cwd, flatPath) {
|
|
|
26
26
|
tsConfigPath = cwd ? path.join(cwd, "tsconfig.json") : path.join("tsconfig.json");
|
|
27
27
|
}
|
|
28
28
|
try {
|
|
29
|
-
const
|
|
30
|
-
return JSON.parse(stripJsonComments(
|
|
29
|
+
const text = fs.readFileSync(tsConfigPath, "utf-8");
|
|
30
|
+
return JSON.parse(stripJsonComments(text));
|
|
31
31
|
} catch (error) {
|
|
32
32
|
throw error;
|
|
33
33
|
}
|
|
@@ -421,483 +421,6 @@ var init_auth = __esm({
|
|
|
421
421
|
}
|
|
422
422
|
});
|
|
423
423
|
|
|
424
|
-
// watch-renew.ts
|
|
425
|
-
var watch_renew_exports = {};
|
|
426
|
-
__export(watch_renew_exports, {
|
|
427
|
-
runWatchRenew: () => runWatchRenew
|
|
428
|
-
});
|
|
429
|
-
import { execSync } from "child_process";
|
|
430
|
-
import * as crypto from "crypto";
|
|
431
|
-
import * as p from "@clack/prompts";
|
|
432
|
-
import {
|
|
433
|
-
CORSAIR_INTERNAL as CORSAIR_INTERNAL2,
|
|
434
|
-
createAccountKeyManager as createAccountKeyManager2,
|
|
435
|
-
createIntegrationKeyManager as createIntegrationKeyManager2
|
|
436
|
-
} from "corsair/core";
|
|
437
|
-
async function extractInternalConfig2(cwd) {
|
|
438
|
-
const instance = await getCorsairInstance({ cwd, shouldThrowOnError: true });
|
|
439
|
-
const internal = instance[CORSAIR_INTERNAL2];
|
|
440
|
-
if (!internal) {
|
|
441
|
-
throw new Error(
|
|
442
|
-
"Could not read internal config from Corsair instance. Make sure you are using the latest version of corsair."
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
return internal;
|
|
446
|
-
}
|
|
447
|
-
async function refreshAccessToken(clientId, clientSecret, refreshToken) {
|
|
448
|
-
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
449
|
-
method: "POST",
|
|
450
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
451
|
-
body: new URLSearchParams({
|
|
452
|
-
client_id: clientId,
|
|
453
|
-
client_secret: clientSecret,
|
|
454
|
-
refresh_token: refreshToken,
|
|
455
|
-
grant_type: "refresh_token"
|
|
456
|
-
})
|
|
457
|
-
});
|
|
458
|
-
if (!response.ok) {
|
|
459
|
-
const error = await response.text();
|
|
460
|
-
throw new Error(`Failed to refresh access token: ${error}`);
|
|
461
|
-
}
|
|
462
|
-
const data = await response.json();
|
|
463
|
-
return data.access_token;
|
|
464
|
-
}
|
|
465
|
-
async function renewGmailWatch(accessToken, topicName) {
|
|
466
|
-
const watchSpin = p.spinner();
|
|
467
|
-
watchSpin.start("Starting Gmail watch...");
|
|
468
|
-
const response = await fetch(`${GMAIL_API_BASE}/users/me/watch`, {
|
|
469
|
-
method: "POST",
|
|
470
|
-
headers: {
|
|
471
|
-
Authorization: `Bearer ${accessToken}`,
|
|
472
|
-
"Content-Type": "application/json"
|
|
473
|
-
},
|
|
474
|
-
body: JSON.stringify({
|
|
475
|
-
topicName,
|
|
476
|
-
labelIds: ["INBOX"]
|
|
477
|
-
})
|
|
478
|
-
});
|
|
479
|
-
if (!response.ok) {
|
|
480
|
-
const error = await response.text();
|
|
481
|
-
watchSpin.stop("Failed.");
|
|
482
|
-
p.log.error(`Gmail watch failed: ${error}`);
|
|
483
|
-
p.outro("");
|
|
484
|
-
process.exit(1);
|
|
485
|
-
}
|
|
486
|
-
const data = await response.json();
|
|
487
|
-
watchSpin.stop("Watch started.");
|
|
488
|
-
p.note(
|
|
489
|
-
`History ID: ${data.historyId}
|
|
490
|
-
Expiration: ${new Date(Number(data.expiration)).toISOString()}`,
|
|
491
|
-
"Watch Response"
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
async function renewDriveWatch(accessToken, webhookUrl) {
|
|
495
|
-
const watchSpin = p.spinner();
|
|
496
|
-
watchSpin.start("Getting start page token...");
|
|
497
|
-
const startPageTokenRes = await fetch(
|
|
498
|
-
`${DRIVE_API_BASE}/changes/startPageToken`,
|
|
499
|
-
{
|
|
500
|
-
headers: { Authorization: `Bearer ${accessToken}` }
|
|
501
|
-
}
|
|
502
|
-
);
|
|
503
|
-
if (!startPageTokenRes.ok) {
|
|
504
|
-
const error = await startPageTokenRes.text();
|
|
505
|
-
watchSpin.stop("Failed.");
|
|
506
|
-
p.log.error(`Failed to get start page token: ${error}`);
|
|
507
|
-
p.outro("");
|
|
508
|
-
process.exit(1);
|
|
509
|
-
}
|
|
510
|
-
const startPageTokenData = await startPageTokenRes.json();
|
|
511
|
-
watchSpin.message("Starting Drive watch...");
|
|
512
|
-
const channelId = crypto.randomUUID();
|
|
513
|
-
const watchRes = await fetch(
|
|
514
|
-
`${DRIVE_API_BASE}/changes/watch?pageToken=${startPageTokenData.startPageToken}`,
|
|
515
|
-
{
|
|
516
|
-
method: "POST",
|
|
517
|
-
headers: {
|
|
518
|
-
Authorization: `Bearer ${accessToken}`,
|
|
519
|
-
"Content-Type": "application/json"
|
|
520
|
-
},
|
|
521
|
-
body: JSON.stringify({
|
|
522
|
-
id: channelId,
|
|
523
|
-
type: "web_hook",
|
|
524
|
-
address: webhookUrl
|
|
525
|
-
})
|
|
526
|
-
}
|
|
527
|
-
);
|
|
528
|
-
if (!watchRes.ok) {
|
|
529
|
-
const error = await watchRes.text();
|
|
530
|
-
watchSpin.stop("Failed.");
|
|
531
|
-
p.log.error(`Drive watch failed: ${error}`);
|
|
532
|
-
p.outro("");
|
|
533
|
-
process.exit(1);
|
|
534
|
-
}
|
|
535
|
-
const data = await watchRes.json();
|
|
536
|
-
watchSpin.stop("Watch started.");
|
|
537
|
-
p.note(
|
|
538
|
-
`Channel ID: ${channelId}
|
|
539
|
-
Resource ID: ${data.resourceId}
|
|
540
|
-
Start Page Token: ${startPageTokenData.startPageToken}
|
|
541
|
-
Expiration: ${new Date(Number(data.expiration)).toISOString()}`,
|
|
542
|
-
"Watch Response"
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
async function renewCalendarWatch(accessToken, webhookUrl, calendarId) {
|
|
546
|
-
const watchSpin = p.spinner();
|
|
547
|
-
watchSpin.start("Starting Calendar watch...");
|
|
548
|
-
const channelId = crypto.randomUUID();
|
|
549
|
-
const watchRes = await fetch(
|
|
550
|
-
`${CALENDAR_API_BASE}/calendars/${encodeURIComponent(calendarId)}/events/watch`,
|
|
551
|
-
{
|
|
552
|
-
method: "POST",
|
|
553
|
-
headers: {
|
|
554
|
-
Authorization: `Bearer ${accessToken}`,
|
|
555
|
-
"Content-Type": "application/json"
|
|
556
|
-
},
|
|
557
|
-
body: JSON.stringify({
|
|
558
|
-
id: channelId,
|
|
559
|
-
type: "web_hook",
|
|
560
|
-
address: webhookUrl
|
|
561
|
-
})
|
|
562
|
-
}
|
|
563
|
-
);
|
|
564
|
-
if (!watchRes.ok) {
|
|
565
|
-
const error = await watchRes.text();
|
|
566
|
-
watchSpin.stop("Failed.");
|
|
567
|
-
p.log.error(`Calendar watch failed: ${error}`);
|
|
568
|
-
p.outro("");
|
|
569
|
-
process.exit(1);
|
|
570
|
-
}
|
|
571
|
-
const data = await watchRes.json();
|
|
572
|
-
watchSpin.stop("Watch started.");
|
|
573
|
-
p.note(
|
|
574
|
-
`Channel ID: ${channelId}
|
|
575
|
-
Resource ID: ${data.resourceId}
|
|
576
|
-
Expiration: ${new Date(Number(data.expiration)).toISOString()}`,
|
|
577
|
-
"Watch Response"
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
|
-
function copyToClipboard(text2) {
|
|
581
|
-
try {
|
|
582
|
-
const platform = process.platform;
|
|
583
|
-
if (platform === "darwin") {
|
|
584
|
-
execSync("pbcopy", { input: text2 });
|
|
585
|
-
return true;
|
|
586
|
-
} else if (platform === "linux") {
|
|
587
|
-
try {
|
|
588
|
-
execSync("xclip -selection clipboard", { input: text2 });
|
|
589
|
-
return true;
|
|
590
|
-
} catch {
|
|
591
|
-
try {
|
|
592
|
-
execSync("xsel --clipboard --input", { input: text2 });
|
|
593
|
-
return true;
|
|
594
|
-
} catch {
|
|
595
|
-
return false;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
} else if (platform === "win32") {
|
|
599
|
-
execSync("clip", { input: text2 });
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
return false;
|
|
603
|
-
} catch {
|
|
604
|
-
return false;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
async function renewSheetsWatch(webhookUrl) {
|
|
608
|
-
const appsScriptCode = `var WEBHOOK_URL = "${webhookUrl}";
|
|
609
|
-
|
|
610
|
-
function onEditTrigger(e) {
|
|
611
|
-
if (!e || !e.range) return;
|
|
612
|
-
|
|
613
|
-
var sheet = e.range.getSheet();
|
|
614
|
-
var payload = {
|
|
615
|
-
spreadsheetId: e.source.getId(),
|
|
616
|
-
sheetName: sheet.getName(),
|
|
617
|
-
range: e.range.getA1Notation(),
|
|
618
|
-
values: e.range.getValues(),
|
|
619
|
-
eventType: "rangeUpdated",
|
|
620
|
-
timestamp: new Date().toISOString()
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
UrlFetchApp.fetch(WEBHOOK_URL, {
|
|
624
|
-
method: "post",
|
|
625
|
-
contentType: "application/json",
|
|
626
|
-
payload: JSON.stringify(payload)
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
function onChangeTrigger(e) {
|
|
631
|
-
if (!e) return;
|
|
632
|
-
|
|
633
|
-
var ss = SpreadsheetApp.getActiveSpreadsheet();
|
|
634
|
-
var sheet = ss.getActiveSheet();
|
|
635
|
-
var lastRow = sheet.getLastRow();
|
|
636
|
-
var lastCol = sheet.getLastColumn();
|
|
637
|
-
if (lastRow === 0 || lastCol === 0) return;
|
|
638
|
-
|
|
639
|
-
var values = sheet.getRange(lastRow, 1, 1, lastCol).getValues();
|
|
640
|
-
|
|
641
|
-
var payload = {
|
|
642
|
-
spreadsheetId: ss.getId(),
|
|
643
|
-
sheetName: sheet.getName(),
|
|
644
|
-
range: "A" + lastRow + ":" + String.fromCharCode(64 + lastCol) + lastRow,
|
|
645
|
-
values: values,
|
|
646
|
-
eventType: "rangeUpdated",
|
|
647
|
-
timestamp: new Date().toISOString()
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
UrlFetchApp.fetch(WEBHOOK_URL, {
|
|
651
|
-
method: "post",
|
|
652
|
-
contentType: "application/json",
|
|
653
|
-
payload: JSON.stringify(payload)
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
function createTriggers() {
|
|
658
|
-
var ss = SpreadsheetApp.getActiveSpreadsheet();
|
|
659
|
-
|
|
660
|
-
ScriptApp.newTrigger("onEditTrigger").forSpreadsheet(ss).onEdit().create();
|
|
661
|
-
ScriptApp.newTrigger("onChangeTrigger").forSpreadsheet(ss).onChange().create();
|
|
662
|
-
|
|
663
|
-
Logger.log("Triggers created successfully!");
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
function removeTriggers() {
|
|
667
|
-
var triggers = ScriptApp.getProjectTriggers();
|
|
668
|
-
triggers.forEach(function(trigger) {
|
|
669
|
-
ScriptApp.deleteTrigger(trigger);
|
|
670
|
-
});
|
|
671
|
-
Logger.log("All triggers removed.");
|
|
672
|
-
}`;
|
|
673
|
-
p.log.info("Google Sheets does not have a native watch API.");
|
|
674
|
-
p.log.info(
|
|
675
|
-
"Instead, you need to set up Google Apps Script triggers in your spreadsheet."
|
|
676
|
-
);
|
|
677
|
-
p.log.info("");
|
|
678
|
-
const shouldCopy = await p.confirm({
|
|
679
|
-
message: "Copy Apps Script code to clipboard?",
|
|
680
|
-
initialValue: true
|
|
681
|
-
});
|
|
682
|
-
let copied = false;
|
|
683
|
-
if (shouldCopy) {
|
|
684
|
-
copied = copyToClipboard(appsScriptCode);
|
|
685
|
-
if (copied) {
|
|
686
|
-
p.log.success("Apps Script code copied to clipboard!");
|
|
687
|
-
} else {
|
|
688
|
-
p.log.warn("Failed to copy to clipboard. Code will be displayed below.");
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
p.log.info("");
|
|
692
|
-
p.log.info("Setup Instructions:");
|
|
693
|
-
p.log.info("1. Open your Google Sheet");
|
|
694
|
-
p.log.info("2. Go to Extensions > Apps Script");
|
|
695
|
-
p.log.info("3. Paste the code into the script editor");
|
|
696
|
-
p.log.info(
|
|
697
|
-
'4. Run the "createTriggers" function once to install the triggers'
|
|
698
|
-
);
|
|
699
|
-
p.log.info("5. Authorize the script when prompted");
|
|
700
|
-
p.log.info("");
|
|
701
|
-
if (!copied) {
|
|
702
|
-
p.log.info("Apps Script Code:");
|
|
703
|
-
p.log.info("");
|
|
704
|
-
p.log.info(appsScriptCode);
|
|
705
|
-
p.log.info("");
|
|
706
|
-
}
|
|
707
|
-
p.note(
|
|
708
|
-
`Webhook URL: ${webhookUrl}
|
|
709
|
-
|
|
710
|
-
The Apps Script code ${copied ? "has been copied to your clipboard" : "is displayed above"}. Paste it into your Google Sheet's Apps Script editor.`,
|
|
711
|
-
"Google Sheets Setup"
|
|
712
|
-
);
|
|
713
|
-
}
|
|
714
|
-
async function runWatchRenew({ cwd }) {
|
|
715
|
-
p.intro("Corsair \u2014 Google Watch Renewal");
|
|
716
|
-
const spin = p.spinner();
|
|
717
|
-
spin.start("Loading corsair instance...");
|
|
718
|
-
let internal;
|
|
719
|
-
try {
|
|
720
|
-
internal = await extractInternalConfig2(cwd);
|
|
721
|
-
} catch (error) {
|
|
722
|
-
spin.stop("Failed to load.");
|
|
723
|
-
p.log.error(error instanceof Error ? error.message : String(error));
|
|
724
|
-
p.outro("");
|
|
725
|
-
process.exit(1);
|
|
726
|
-
}
|
|
727
|
-
const { plugins, database, kek } = internal;
|
|
728
|
-
if (!database) {
|
|
729
|
-
spin.stop("Failed.");
|
|
730
|
-
p.log.error("No database adapter configured.");
|
|
731
|
-
p.outro("");
|
|
732
|
-
process.exit(1);
|
|
733
|
-
}
|
|
734
|
-
const googlePlugins = plugins.filter((pl) => {
|
|
735
|
-
const opts = pl.options;
|
|
736
|
-
return opts?.authType === "oauth_2" && GOOGLE_PLUGINS.includes(pl.id);
|
|
737
|
-
});
|
|
738
|
-
if (googlePlugins.length === 0) {
|
|
739
|
-
spin.stop("No Google OAuth2 plugins found.");
|
|
740
|
-
p.outro("");
|
|
741
|
-
process.exit(1);
|
|
742
|
-
}
|
|
743
|
-
spin.stop(
|
|
744
|
-
`Loaded. Found ${googlePlugins.length} Google plugin${googlePlugins.length === 1 ? "" : "s"}.`
|
|
745
|
-
);
|
|
746
|
-
const pluginId = await p.select({
|
|
747
|
-
message: "Select a Google integration:",
|
|
748
|
-
options: googlePlugins.map((pl) => ({
|
|
749
|
-
value: pl.id,
|
|
750
|
-
label: pl.id
|
|
751
|
-
}))
|
|
752
|
-
});
|
|
753
|
-
if (p.isCancel(pluginId)) {
|
|
754
|
-
p.cancel("Operation cancelled.");
|
|
755
|
-
process.exit(0);
|
|
756
|
-
}
|
|
757
|
-
const pluginType = pluginId;
|
|
758
|
-
if (pluginType === "googlesheets") {
|
|
759
|
-
const webhookUrl = await p.text({
|
|
760
|
-
message: "Enter webhook URL:",
|
|
761
|
-
placeholder: "https://example.com/api/webhook",
|
|
762
|
-
validate: (v) => {
|
|
763
|
-
if (!v || v.trim().length === 0) return "Webhook URL is required";
|
|
764
|
-
if (!v.startsWith("http://") && !v.startsWith("https://")) {
|
|
765
|
-
return "Webhook URL must start with http:// or https://";
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
if (p.isCancel(webhookUrl)) {
|
|
770
|
-
p.cancel("Operation cancelled.");
|
|
771
|
-
process.exit(0);
|
|
772
|
-
}
|
|
773
|
-
await renewSheetsWatch(webhookUrl);
|
|
774
|
-
p.outro("Done!");
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
const tenantId = await p.text({
|
|
778
|
-
message: "Enter tenant ID:",
|
|
779
|
-
defaultValue: "default",
|
|
780
|
-
placeholder: "default"
|
|
781
|
-
});
|
|
782
|
-
if (p.isCancel(tenantId)) {
|
|
783
|
-
p.cancel("Operation cancelled.");
|
|
784
|
-
process.exit(0);
|
|
785
|
-
}
|
|
786
|
-
const credSpin = p.spinner();
|
|
787
|
-
credSpin.start("Fetching credentials...");
|
|
788
|
-
try {
|
|
789
|
-
const integrationKm = createIntegrationKeyManager2({
|
|
790
|
-
authType: "oauth_2",
|
|
791
|
-
integrationName: pluginId,
|
|
792
|
-
kek,
|
|
793
|
-
database
|
|
794
|
-
});
|
|
795
|
-
const accountKm = createAccountKeyManager2({
|
|
796
|
-
authType: "oauth_2",
|
|
797
|
-
integrationName: pluginId,
|
|
798
|
-
tenantId,
|
|
799
|
-
kek,
|
|
800
|
-
database
|
|
801
|
-
});
|
|
802
|
-
const clientId = await integrationKm.get_client_id();
|
|
803
|
-
const clientSecret = await integrationKm.get_client_secret();
|
|
804
|
-
const refreshToken = await accountKm.get_refresh_token();
|
|
805
|
-
if (!clientId || !clientSecret || !refreshToken) {
|
|
806
|
-
credSpin.stop("Missing credentials.");
|
|
807
|
-
p.log.error(
|
|
808
|
-
'Client ID, Client Secret, and Refresh Token are required. Use "corsair auth" to set them.'
|
|
809
|
-
);
|
|
810
|
-
p.outro("");
|
|
811
|
-
process.exit(1);
|
|
812
|
-
}
|
|
813
|
-
const accessToken = await refreshAccessToken(
|
|
814
|
-
clientId,
|
|
815
|
-
clientSecret,
|
|
816
|
-
refreshToken
|
|
817
|
-
);
|
|
818
|
-
credSpin.stop("Credentials loaded.");
|
|
819
|
-
if (pluginType === "gmail") {
|
|
820
|
-
const topicName = await p.text({
|
|
821
|
-
message: "Enter Pub/Sub topic name:",
|
|
822
|
-
placeholder: "projects/my-project/topics/my-topic",
|
|
823
|
-
validate: (v) => {
|
|
824
|
-
if (!v || v.trim().length === 0) return "Topic name is required";
|
|
825
|
-
}
|
|
826
|
-
});
|
|
827
|
-
if (p.isCancel(topicName)) {
|
|
828
|
-
p.cancel("Operation cancelled.");
|
|
829
|
-
process.exit(0);
|
|
830
|
-
}
|
|
831
|
-
await renewGmailWatch(accessToken, topicName);
|
|
832
|
-
} else if (pluginType === "googledrive") {
|
|
833
|
-
const webhookUrl = await p.text({
|
|
834
|
-
message: "Enter webhook URL:",
|
|
835
|
-
placeholder: "https://example.com/api/webhook",
|
|
836
|
-
validate: (v) => {
|
|
837
|
-
if (!v || v.trim().length === 0) return "Webhook URL is required";
|
|
838
|
-
}
|
|
839
|
-
});
|
|
840
|
-
if (p.isCancel(webhookUrl)) {
|
|
841
|
-
p.cancel("Operation cancelled.");
|
|
842
|
-
process.exit(0);
|
|
843
|
-
}
|
|
844
|
-
await renewDriveWatch(accessToken, webhookUrl);
|
|
845
|
-
} else if (pluginType === "googlecalendar") {
|
|
846
|
-
const webhookUrl = await p.text({
|
|
847
|
-
message: "Enter webhook URL:",
|
|
848
|
-
placeholder: "https://example.com/api/webhook",
|
|
849
|
-
validate: (v) => {
|
|
850
|
-
if (!v || v.trim().length === 0) return "Webhook URL is required";
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
if (p.isCancel(webhookUrl)) {
|
|
854
|
-
p.cancel("Operation cancelled.");
|
|
855
|
-
process.exit(0);
|
|
856
|
-
}
|
|
857
|
-
const calendarId = await p.text({
|
|
858
|
-
message: "Enter calendar ID:",
|
|
859
|
-
defaultValue: "primary",
|
|
860
|
-
placeholder: "primary"
|
|
861
|
-
});
|
|
862
|
-
if (p.isCancel(calendarId)) {
|
|
863
|
-
p.cancel("Operation cancelled.");
|
|
864
|
-
process.exit(0);
|
|
865
|
-
}
|
|
866
|
-
await renewCalendarWatch(
|
|
867
|
-
accessToken,
|
|
868
|
-
webhookUrl,
|
|
869
|
-
calendarId
|
|
870
|
-
);
|
|
871
|
-
} else {
|
|
872
|
-
p.log.error(`Unsupported Google plugin: ${pluginType}`);
|
|
873
|
-
process.exit(1);
|
|
874
|
-
}
|
|
875
|
-
} catch (error) {
|
|
876
|
-
credSpin.stop("Failed.");
|
|
877
|
-
p.log.error(
|
|
878
|
-
`Error: ${error instanceof Error ? error.message : String(error)}`
|
|
879
|
-
);
|
|
880
|
-
process.exit(1);
|
|
881
|
-
}
|
|
882
|
-
p.outro("Done!");
|
|
883
|
-
}
|
|
884
|
-
var GMAIL_API_BASE, DRIVE_API_BASE, CALENDAR_API_BASE, GOOGLE_PLUGINS;
|
|
885
|
-
var init_watch_renew = __esm({
|
|
886
|
-
"watch-renew.ts"() {
|
|
887
|
-
"use strict";
|
|
888
|
-
init_index();
|
|
889
|
-
GMAIL_API_BASE = "https://gmail.googleapis.com/gmail/v1";
|
|
890
|
-
DRIVE_API_BASE = "https://www.googleapis.com/drive/v3";
|
|
891
|
-
CALENDAR_API_BASE = "https://www.googleapis.com/calendar/v3";
|
|
892
|
-
GOOGLE_PLUGINS = [
|
|
893
|
-
"gmail",
|
|
894
|
-
"googledrive",
|
|
895
|
-
"googlecalendar",
|
|
896
|
-
"googlesheets"
|
|
897
|
-
];
|
|
898
|
-
}
|
|
899
|
-
});
|
|
900
|
-
|
|
901
424
|
// index.ts
|
|
902
425
|
import fs2, { existsSync } from "fs";
|
|
903
426
|
import path2 from "path";
|
|
@@ -1259,47 +782,31 @@ function parseScriptArgs(args) {
|
|
|
1259
782
|
return { code, tenant };
|
|
1260
783
|
}
|
|
1261
784
|
function printHelp() {
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
console.log("");
|
|
1282
|
-
console.log(" corsair run <path> [input-json] Call an API endpoint and print the result");
|
|
1283
|
-
console.log(" corsair run slack.api.channels.list Example: no input needed");
|
|
1284
|
-
console.log(` corsair run slack.api.messages.post '{"channel":"C123","text":"hi"}'`);
|
|
1285
|
-
console.log(" corsair run <path> [input-json] --tenant=<id> Multi-tenant variant");
|
|
1286
|
-
console.log("");
|
|
1287
|
-
console.log(' corsair script --code "<js>" Run a sandboxed script with corsair injected');
|
|
1288
|
-
console.log(' corsair script --code "<js>" --tenant=<id> Multi-tenant variant');
|
|
1289
|
-
console.log(" # corsair is pre-injected; use return to output a value:");
|
|
1290
|
-
console.log(` # --code "const r = await corsair.slack.api.channels.list(); return r.channels.find(c => c.name === 'general')?.id"`);
|
|
1291
|
-
console.log("");
|
|
1292
|
-
console.log(" corsair watch-renew Renew Google webhook watch (Gmail/Drive/Calendar)");
|
|
1293
|
-
console.log(" corsair help Show this help message\n");
|
|
785
|
+
const lines = [
|
|
786
|
+
"Corsair CLI",
|
|
787
|
+
"",
|
|
788
|
+
" pnpm corsair setup Init (add -backfill to seed data)",
|
|
789
|
+
" pnpm corsair setup --<plugin> <field>=VALUE Set plugin credentials",
|
|
790
|
+
" pnpm corsair auth --plugin=<id> Start OAuth flow",
|
|
791
|
+
" pnpm corsair auth --plugin=<id> --code=<code> Exchange OAuth code for tokens",
|
|
792
|
+
" pnpm corsair auth --plugin=<id> --credentials Show credential status",
|
|
793
|
+
" pnpm corsair list [--plugin=<id>] [--type=api|webhooks|db] List endpoint paths (tip: pipe to grep to filter)",
|
|
794
|
+
" pnpm corsair schema <path> Show schema for an endpoint/webhook/DB entity",
|
|
795
|
+
' pnpm corsair script --code "<js>" [--tenant=<id>]',
|
|
796
|
+
" corsair is injected; use return to output a value.",
|
|
797
|
+
" IMPORTANT: Always filter results inline \u2014 you are the consumer of the return value, so returning full list responses wastes tokens.",
|
|
798
|
+
" Bad: return await corsair.slack.api.users.list({})",
|
|
799
|
+
" Good: return (await corsair.slack.api.users.list({})).members.find(u => u.name === 'bob')?.id",
|
|
800
|
+
...SHOW_RUN ? [
|
|
801
|
+
" run <path> [input-json] [--tenant=<id>] Call an endpoint directly"
|
|
802
|
+
] : []
|
|
803
|
+
];
|
|
804
|
+
console.log(lines.join("\n"));
|
|
1294
805
|
}
|
|
1295
806
|
async function main() {
|
|
1296
807
|
const cwd = process.cwd();
|
|
1297
808
|
const args = process.argv.slice(2);
|
|
1298
809
|
const command = args[0];
|
|
1299
|
-
if (command === "help" || command === "--help" || command === "-h") {
|
|
1300
|
-
printHelp();
|
|
1301
|
-
return;
|
|
1302
|
-
}
|
|
1303
810
|
if (command === "setup") {
|
|
1304
811
|
const { backfill, credentials } = parseSetupArgs(args.slice(1));
|
|
1305
812
|
const { setupCorsair } = await import("corsair/setup");
|
|
@@ -1317,11 +824,6 @@ async function main() {
|
|
|
1317
824
|
await runAuth2({ cwd, ...authArgs });
|
|
1318
825
|
return;
|
|
1319
826
|
}
|
|
1320
|
-
if (command === "watch-renew") {
|
|
1321
|
-
const { runWatchRenew: runWatchRenew2 } = await Promise.resolve().then(() => (init_watch_renew(), watch_renew_exports));
|
|
1322
|
-
await runWatchRenew2({ cwd });
|
|
1323
|
-
return;
|
|
1324
|
-
}
|
|
1325
827
|
if (command === "list") {
|
|
1326
828
|
const { plugin, type } = parseListArgs(args.slice(1));
|
|
1327
829
|
const instance = await getCorsairInstance({ cwd });
|
|
@@ -1334,25 +836,15 @@ async function main() {
|
|
|
1334
836
|
if (typeof result === "string") {
|
|
1335
837
|
console.log(result);
|
|
1336
838
|
} else if (Array.isArray(result)) {
|
|
1337
|
-
|
|
1338
|
-
console.log(path3);
|
|
1339
|
-
}
|
|
1340
|
-
console.log("");
|
|
1341
|
-
console.log("Run `pnpm corsair schema <path>` to get the schema for any of the above.");
|
|
839
|
+
console.log(result.join("\n"));
|
|
1342
840
|
} else if (result && typeof result === "object") {
|
|
1343
841
|
const grouped = result;
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
for (const path3 of paths) {
|
|
1347
|
-
console.log(` ${path3}`);
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
console.log("");
|
|
1351
|
-
console.log("Run `pnpm corsair schema <path>` to get the schema for any of the above.");
|
|
842
|
+
const all = Object.values(grouped).flat();
|
|
843
|
+
console.log(all.join("\n"));
|
|
1352
844
|
}
|
|
1353
845
|
return;
|
|
1354
846
|
}
|
|
1355
|
-
if (command === "run") {
|
|
847
|
+
if (SHOW_RUN && command === "run") {
|
|
1356
848
|
const { path: endpointPath, input, tenant } = parseRunArgs(args.slice(1));
|
|
1357
849
|
if (!endpointPath) {
|
|
1358
850
|
console.error("[#corsair]: Usage: corsair run <path> [input-json]");
|
|
@@ -1428,30 +920,8 @@ async function main() {
|
|
|
1428
920
|
return;
|
|
1429
921
|
}
|
|
1430
922
|
printHelp();
|
|
1431
|
-
console.log("");
|
|
1432
|
-
console.log(`[#corsair]: Looking for Corsair instance in ${cwd}...
|
|
1433
|
-
`);
|
|
1434
|
-
try {
|
|
1435
|
-
const instance = await getCorsairInstance({ cwd });
|
|
1436
|
-
console.log("[#corsair]: \u2705 Successfully loaded Corsair instance!");
|
|
1437
|
-
if (instance && typeof instance === "object" && "withTenant" in instance) {
|
|
1438
|
-
console.log(
|
|
1439
|
-
"[#corsair]: Multi-tenant setup detected (has withTenant method)"
|
|
1440
|
-
);
|
|
1441
|
-
} else {
|
|
1442
|
-
console.log("[#corsair]: Single-tenant setup detected (direct client)");
|
|
1443
|
-
}
|
|
1444
|
-
if (instance && typeof instance === "object") {
|
|
1445
|
-
console.log(
|
|
1446
|
-
`[#corsair]: Instance keys: ${Object.keys(instance).join(", ")}`
|
|
1447
|
-
);
|
|
1448
|
-
}
|
|
1449
|
-
} catch (error) {
|
|
1450
|
-
console.error("[#corsair]: Error:", error);
|
|
1451
|
-
process.exit(1);
|
|
1452
|
-
}
|
|
1453
923
|
}
|
|
1454
|
-
var possiblePaths, jitiOptions, isCorsairInstance, RESERVED_FLAGS, isMainModule;
|
|
924
|
+
var possiblePaths, jitiOptions, isCorsairInstance, RESERVED_FLAGS, SHOW_RUN, isMainModule;
|
|
1455
925
|
var init_index = __esm({
|
|
1456
926
|
"index.ts"() {
|
|
1457
927
|
init_get_tsconfig_info();
|
|
@@ -1516,6 +986,7 @@ var init_index = __esm({
|
|
|
1516
986
|
return Object.keys(object).length > 0;
|
|
1517
987
|
};
|
|
1518
988
|
RESERVED_FLAGS = /* @__PURE__ */ new Set(["backfill", "help", "h"]);
|
|
989
|
+
SHOW_RUN = false;
|
|
1519
990
|
isMainModule = import.meta.url === `file://${process.argv[1]?.replace(/\\/g, "/")}` || process.argv[1]?.includes("index.ts") || process.argv[1]?.includes("index.js") || import.meta.url.endsWith("/index.ts") || import.meta.url.endsWith("/index.js");
|
|
1520
991
|
if (isMainModule) {
|
|
1521
992
|
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corsair-dev/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@clack/prompts": "^1.0.0",
|
|
24
24
|
"c12": "^3.3.3",
|
|
25
25
|
"zod": "^3.25.76",
|
|
26
|
-
"corsair": "0.1.
|
|
26
|
+
"corsair": "0.1.50"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^29.5.14",
|