@corsair-dev/cli 0.1.9 → 0.1.11
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/auth.d.ts +3 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/google/drive.d.ts.map +1 -1
- package/dist/google/index.d.ts.map +1 -1
- package/dist/google/sheets.d.ts.map +1 -1
- package/dist/index.js +342 -250
- package/dist/microsoft/credentials.d.ts.map +1 -1
- package/dist/microsoft/onedrive.d.ts +1 -1
- package/dist/microsoft/onedrive.d.ts.map +1 -1
- package/dist/microsoft/outlook.d.ts +1 -1
- package/dist/microsoft/outlook.d.ts.map +1 -1
- package/dist/microsoft/sharepoint.d.ts +1 -1
- package/dist/microsoft/sharepoint.d.ts.map +1 -1
- package/dist/microsoft/teams.d.ts +1 -1
- package/dist/microsoft/teams.d.ts.map +1 -1
- package/dist/subscribe-microsoft.d.ts +1 -1
- package/dist/subscribe-microsoft.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function runAuth({ cwd, pluginId: pluginIdArg, tenantId: tenantIdArg, code: codeArg, credentials: showCredentials, }: {
|
|
1
|
+
export declare function runAuth({ cwd, pluginId: pluginIdArg, tenantId: tenantIdArg, code: codeArg, credentials: showCredentials, agent: agentMode, }: {
|
|
2
2
|
cwd: string;
|
|
3
3
|
pluginId?: string;
|
|
4
4
|
tenantId?: string;
|
|
@@ -6,5 +6,7 @@ export declare function runAuth({ cwd, pluginId: pluginIdArg, tenantId: tenantId
|
|
|
6
6
|
code?: string;
|
|
7
7
|
/** Output current credential status instead of starting OAuth flow. */
|
|
8
8
|
credentials?: boolean;
|
|
9
|
+
/** When true, output instructions for an AI agent to guide the user through auth. */
|
|
10
|
+
agent?: boolean;
|
|
9
11
|
}): Promise<void>;
|
|
10
12
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../auth.ts"],"names":[],"mappings":"AAwmBA,wBAAsB,OAAO,CAAC,EAC7B,GAAG,EACH,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,eAAuB,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../auth.ts"],"names":[],"mappings":"AAwmBA,wBAAsB,OAAO,CAAC,EAC7B,GAAG,EACH,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,eAAuB,EACpC,KAAK,EAAE,SAAiB,GACxB,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qFAAqF;IACrF,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6EhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../google/drive.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,CACpC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../google/drive.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,CACpC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CA+Df"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../google/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../google/index.ts"],"names":[],"mappings":"AAsCA,wBAAsB,kBAAkB,CAAC,EACxC,GAAG,EACH,QAAQ,EAAE,mBAAmB,GAC7B,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4LhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sheets.d.ts","sourceRoot":"","sources":["../../google/sheets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sheets.d.ts","sourceRoot":"","sources":["../../google/sheets.ts"],"names":[],"mappings":"AAuEA,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8CxE"}
|
package/dist/index.js
CHANGED
|
@@ -148,7 +148,10 @@ var init_prompts = __esm({
|
|
|
148
148
|
|
|
149
149
|
// microsoft/credentials.ts
|
|
150
150
|
import * as p3 from "@clack/prompts";
|
|
151
|
-
import {
|
|
151
|
+
import {
|
|
152
|
+
createAccountKeyManager,
|
|
153
|
+
createIntegrationKeyManager
|
|
154
|
+
} from "corsair/core";
|
|
152
155
|
async function refreshMicrosoftToken(clientId, clientSecret, refreshToken) {
|
|
153
156
|
const response = await fetch(MICROSOFT_TOKEN_URL, {
|
|
154
157
|
method: "POST",
|
|
@@ -183,7 +186,13 @@ async function resolveAccessToken(integrationName, tenantId, internal) {
|
|
|
183
186
|
kek,
|
|
184
187
|
database
|
|
185
188
|
});
|
|
186
|
-
const [
|
|
189
|
+
const [
|
|
190
|
+
clientId,
|
|
191
|
+
clientSecret,
|
|
192
|
+
storedAccessToken,
|
|
193
|
+
expiresAt,
|
|
194
|
+
storedRefreshToken
|
|
195
|
+
] = await Promise.all([
|
|
187
196
|
integrationKm.get_client_id(),
|
|
188
197
|
integrationKm.get_client_secret(),
|
|
189
198
|
accountKm.get_access_token(),
|
|
@@ -288,9 +297,156 @@ var init_graph = __esm({
|
|
|
288
297
|
}
|
|
289
298
|
});
|
|
290
299
|
|
|
291
|
-
// microsoft/
|
|
300
|
+
// microsoft/onedrive.ts
|
|
292
301
|
import * as p4 from "@clack/prompts";
|
|
293
|
-
|
|
302
|
+
function buildOnedriveResource(resourceType, ids) {
|
|
303
|
+
switch (resourceType) {
|
|
304
|
+
case "personalDrive":
|
|
305
|
+
return "me/drive/root";
|
|
306
|
+
case "specificDrive":
|
|
307
|
+
return `drives/${ids.driveId}/root`;
|
|
308
|
+
case "specificFolder":
|
|
309
|
+
return `me/drive/items/${ids.itemId}`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async function runOnedriveSubscribe({
|
|
313
|
+
cwd
|
|
314
|
+
}) {
|
|
315
|
+
const { internal } = await loadInternalConfig(
|
|
316
|
+
cwd,
|
|
317
|
+
"Corsair \u2014 OneDrive Webhook Subscribe",
|
|
318
|
+
"onedrive",
|
|
319
|
+
"OneDrive"
|
|
320
|
+
);
|
|
321
|
+
const tenantId = await promptTenantId();
|
|
322
|
+
const { accessToken, accountKm } = await resolveAccessToken(
|
|
323
|
+
"onedrive",
|
|
324
|
+
tenantId,
|
|
325
|
+
internal
|
|
326
|
+
);
|
|
327
|
+
const webhookUrl = await promptWebhookUrl();
|
|
328
|
+
const selectedResourceTypes = await p4.multiselect({
|
|
329
|
+
message: "Select resources to subscribe to:",
|
|
330
|
+
options: ONEDRIVE_RESOURCE_OPTIONS,
|
|
331
|
+
required: true
|
|
332
|
+
});
|
|
333
|
+
if (p4.isCancel(selectedResourceTypes)) {
|
|
334
|
+
p4.cancel("Operation cancelled.");
|
|
335
|
+
process.exit(0);
|
|
336
|
+
}
|
|
337
|
+
const resourceConfigs = [];
|
|
338
|
+
for (const resourceType of selectedResourceTypes) {
|
|
339
|
+
const ids = {};
|
|
340
|
+
if (resourceType === "specificDrive") {
|
|
341
|
+
const driveId = await p4.text({
|
|
342
|
+
message: `[${resourceType}] Enter drive ID:`,
|
|
343
|
+
placeholder: "b!abc123...",
|
|
344
|
+
validate: (v) => {
|
|
345
|
+
if (!v || !v.trim()) return "Drive ID is required";
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
if (p4.isCancel(driveId)) {
|
|
349
|
+
p4.cancel("Operation cancelled.");
|
|
350
|
+
process.exit(0);
|
|
351
|
+
}
|
|
352
|
+
ids.driveId = driveId;
|
|
353
|
+
} else if (resourceType === "specificFolder") {
|
|
354
|
+
const itemId = await p4.text({
|
|
355
|
+
message: `[${resourceType}] Enter item/folder ID:`,
|
|
356
|
+
placeholder: "01ABC123...",
|
|
357
|
+
validate: (v) => {
|
|
358
|
+
if (!v || !v.trim()) return "Item ID is required";
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
if (p4.isCancel(itemId)) {
|
|
362
|
+
p4.cancel("Operation cancelled.");
|
|
363
|
+
process.exit(0);
|
|
364
|
+
}
|
|
365
|
+
ids.itemId = itemId;
|
|
366
|
+
}
|
|
367
|
+
resourceConfigs.push({ resourceType, ids });
|
|
368
|
+
}
|
|
369
|
+
const clientState = await promptClientState();
|
|
370
|
+
const results = [];
|
|
371
|
+
let hasError = false;
|
|
372
|
+
for (const { resourceType, ids } of resourceConfigs) {
|
|
373
|
+
const resource = buildOnedriveResource(resourceType, ids);
|
|
374
|
+
const subSpin = p4.spinner();
|
|
375
|
+
subSpin.start(`Creating subscription: ${resourceType}...`);
|
|
376
|
+
try {
|
|
377
|
+
const subscription = await createGraphSubscription(
|
|
378
|
+
accessToken,
|
|
379
|
+
webhookUrl,
|
|
380
|
+
resource,
|
|
381
|
+
"updated",
|
|
382
|
+
clientState,
|
|
383
|
+
ONEDRIVE_MAX_EXPIRY_MINUTES
|
|
384
|
+
);
|
|
385
|
+
subSpin.stop(`Created: ${resourceType}`);
|
|
386
|
+
results.push(
|
|
387
|
+
`${resourceType}
|
|
388
|
+
Resource: ${resource}
|
|
389
|
+
ID: ${subscription.id}
|
|
390
|
+
Expires: ${subscription.expirationDateTime}`
|
|
391
|
+
);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
subSpin.stop(`Failed: ${resourceType}`);
|
|
394
|
+
p4.log.error(error instanceof Error ? error.message : String(error));
|
|
395
|
+
hasError = true;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (results.length > 0) {
|
|
399
|
+
p4.note(results.join("\n\n"), "Subscriptions created");
|
|
400
|
+
}
|
|
401
|
+
await saveWebhookSignature(accountKm, clientState);
|
|
402
|
+
if (!hasError) {
|
|
403
|
+
p4.log.success("OneDrive webhook subscriptions set up successfully.");
|
|
404
|
+
} else {
|
|
405
|
+
p4.log.warn("Some subscriptions failed. Check errors above.");
|
|
406
|
+
}
|
|
407
|
+
p4.note(
|
|
408
|
+
`ClientState: ${clientState}
|
|
409
|
+
Webhook URL: ${webhookUrl}
|
|
410
|
+
|
|
411
|
+
Note: OneDrive subscriptions expire. Re-run this command to renew.`,
|
|
412
|
+
"Setup complete"
|
|
413
|
+
);
|
|
414
|
+
p4.outro("Done!");
|
|
415
|
+
}
|
|
416
|
+
var ONEDRIVE_MAX_EXPIRY_MINUTES, ONEDRIVE_RESOURCE_OPTIONS;
|
|
417
|
+
var init_onedrive = __esm({
|
|
418
|
+
"microsoft/onedrive.ts"() {
|
|
419
|
+
"use strict";
|
|
420
|
+
init_load_config();
|
|
421
|
+
init_prompts();
|
|
422
|
+
init_credentials();
|
|
423
|
+
init_graph();
|
|
424
|
+
ONEDRIVE_MAX_EXPIRY_MINUTES = 4230;
|
|
425
|
+
ONEDRIVE_RESOURCE_OPTIONS = [
|
|
426
|
+
{
|
|
427
|
+
value: "personalDrive",
|
|
428
|
+
label: "Personal Drive Root \u2014 all changes to the user's drive",
|
|
429
|
+
hint: "me/drive/root"
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
value: "specificDrive",
|
|
433
|
+
label: "Specific Drive Root \u2014 all changes to a given drive ID",
|
|
434
|
+
hint: "drives/{driveId}/root"
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
value: "specificFolder",
|
|
438
|
+
label: "Specific Folder \u2014 changes within a given item/folder",
|
|
439
|
+
hint: "me/drive/items/{itemId}"
|
|
440
|
+
}
|
|
441
|
+
];
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// microsoft/outlook.ts
|
|
446
|
+
import * as p5 from "@clack/prompts";
|
|
447
|
+
async function runOutlookSubscribe({
|
|
448
|
+
cwd
|
|
449
|
+
}) {
|
|
294
450
|
const { internal } = await loadInternalConfig(
|
|
295
451
|
cwd,
|
|
296
452
|
"Corsair \u2014 Outlook Webhook Subscribe",
|
|
@@ -304,7 +460,7 @@ async function runOutlookSubscribe({ cwd }) {
|
|
|
304
460
|
internal
|
|
305
461
|
);
|
|
306
462
|
const webhookUrl = await promptWebhookUrl();
|
|
307
|
-
const selected = await
|
|
463
|
+
const selected = await p5.multiselect({
|
|
308
464
|
message: "Select resources to subscribe to:",
|
|
309
465
|
options: Object.entries(OUTLOOK_RESOURCES).map(([value, cfg]) => ({
|
|
310
466
|
value,
|
|
@@ -313,8 +469,8 @@ async function runOutlookSubscribe({ cwd }) {
|
|
|
313
469
|
})),
|
|
314
470
|
required: true
|
|
315
471
|
});
|
|
316
|
-
if (
|
|
317
|
-
|
|
472
|
+
if (p5.isCancel(selected)) {
|
|
473
|
+
p5.cancel("Operation cancelled.");
|
|
318
474
|
process.exit(0);
|
|
319
475
|
}
|
|
320
476
|
const clientState = await promptClientState();
|
|
@@ -322,7 +478,7 @@ async function runOutlookSubscribe({ cwd }) {
|
|
|
322
478
|
let hasError = false;
|
|
323
479
|
for (const value of selected) {
|
|
324
480
|
const cfg = OUTLOOK_RESOURCES[value];
|
|
325
|
-
const subSpin =
|
|
481
|
+
const subSpin = p5.spinner();
|
|
326
482
|
subSpin.start(`Creating subscription: ${cfg.label}...`);
|
|
327
483
|
try {
|
|
328
484
|
const subscription = await createGraphSubscription(
|
|
@@ -341,27 +497,27 @@ async function runOutlookSubscribe({ cwd }) {
|
|
|
341
497
|
);
|
|
342
498
|
} catch (error) {
|
|
343
499
|
subSpin.stop(`Failed: ${cfg.label}`);
|
|
344
|
-
|
|
500
|
+
p5.log.error(error instanceof Error ? error.message : String(error));
|
|
345
501
|
hasError = true;
|
|
346
502
|
}
|
|
347
503
|
}
|
|
348
504
|
if (results.length > 0) {
|
|
349
|
-
|
|
505
|
+
p5.note(results.join("\n\n"), "Subscriptions created");
|
|
350
506
|
}
|
|
351
507
|
await saveWebhookSignature(accountKm, clientState);
|
|
352
508
|
if (!hasError) {
|
|
353
|
-
|
|
509
|
+
p5.log.success("Outlook webhook subscriptions set up successfully.");
|
|
354
510
|
} else {
|
|
355
|
-
|
|
511
|
+
p5.log.warn("Some subscriptions failed. Check errors above.");
|
|
356
512
|
}
|
|
357
|
-
|
|
513
|
+
p5.note(
|
|
358
514
|
`ClientState: ${clientState}
|
|
359
515
|
Webhook URL: ${webhookUrl}
|
|
360
516
|
|
|
361
517
|
Note: Outlook subscriptions expire. Re-run this command to renew.`,
|
|
362
518
|
"Setup complete"
|
|
363
519
|
);
|
|
364
|
-
|
|
520
|
+
p5.outro("Done!");
|
|
365
521
|
}
|
|
366
522
|
var OUTLOOK_RESOURCES;
|
|
367
523
|
var init_outlook = __esm({
|
|
@@ -410,7 +566,7 @@ var init_outlook = __esm({
|
|
|
410
566
|
});
|
|
411
567
|
|
|
412
568
|
// microsoft/sharepoint.ts
|
|
413
|
-
import * as
|
|
569
|
+
import * as p6 from "@clack/prompts";
|
|
414
570
|
function buildSiteUrl(siteId, subpath) {
|
|
415
571
|
const isHostnamePath = siteId.includes(":") && !siteId.includes(",");
|
|
416
572
|
return isHostnamePath ? `${GRAPH_API_BASE}/sites/${siteId}:/${subpath}` : `${GRAPH_API_BASE}/sites/${siteId}/${subpath}`;
|
|
@@ -439,7 +595,11 @@ async function createSharepointSubscription(accessToken, siteId, listId, notific
|
|
|
439
595
|
Authorization: `Bearer ${accessToken}`,
|
|
440
596
|
"Content-Type": "application/json"
|
|
441
597
|
},
|
|
442
|
-
body: JSON.stringify({
|
|
598
|
+
body: JSON.stringify({
|
|
599
|
+
notificationUrl,
|
|
600
|
+
expirationDateTime,
|
|
601
|
+
clientState
|
|
602
|
+
})
|
|
443
603
|
}
|
|
444
604
|
);
|
|
445
605
|
if (!response.ok) {
|
|
@@ -448,7 +608,9 @@ async function createSharepointSubscription(accessToken, siteId, listId, notific
|
|
|
448
608
|
}
|
|
449
609
|
return response.json();
|
|
450
610
|
}
|
|
451
|
-
async function runSharepointSubscribe({
|
|
611
|
+
async function runSharepointSubscribe({
|
|
612
|
+
cwd
|
|
613
|
+
}) {
|
|
452
614
|
const { internal, plugin: sharepointPlugin } = await loadInternalConfig(
|
|
453
615
|
cwd,
|
|
454
616
|
"Corsair \u2014 SharePoint Webhook Subscribe",
|
|
@@ -464,7 +626,7 @@ async function runSharepointSubscribe({ cwd }) {
|
|
|
464
626
|
const webhookUrl = await promptWebhookUrl();
|
|
465
627
|
const pluginOptions = sharepointPlugin.options;
|
|
466
628
|
const defaultSiteId = pluginOptions?.siteId ?? "";
|
|
467
|
-
const siteId = await
|
|
629
|
+
const siteId = await p6.text({
|
|
468
630
|
message: "Enter SharePoint site ID:",
|
|
469
631
|
defaultValue: defaultSiteId,
|
|
470
632
|
placeholder: "corsairdev.sharepoint.com:/sites/MySite or tenant.sharepoint.com,siteGuid,webGuid",
|
|
@@ -472,11 +634,11 @@ async function runSharepointSubscribe({ cwd }) {
|
|
|
472
634
|
if (!v || v.trim().length === 0) return "Site ID is required";
|
|
473
635
|
}
|
|
474
636
|
});
|
|
475
|
-
if (
|
|
476
|
-
|
|
637
|
+
if (p6.isCancel(siteId)) {
|
|
638
|
+
p6.cancel("Operation cancelled.");
|
|
477
639
|
process.exit(0);
|
|
478
640
|
}
|
|
479
|
-
const listSpin =
|
|
641
|
+
const listSpin = p6.spinner();
|
|
480
642
|
listSpin.start("Fetching lists from site...");
|
|
481
643
|
let siteLists = [];
|
|
482
644
|
try {
|
|
@@ -486,11 +648,11 @@ async function runSharepointSubscribe({ cwd }) {
|
|
|
486
648
|
);
|
|
487
649
|
} catch (error) {
|
|
488
650
|
listSpin.stop("Could not fetch lists.");
|
|
489
|
-
|
|
651
|
+
p6.log.warn(error instanceof Error ? error.message : String(error));
|
|
490
652
|
}
|
|
491
653
|
let listId;
|
|
492
654
|
if (siteLists.length > 0) {
|
|
493
|
-
const picked = await
|
|
655
|
+
const picked = await p6.select({
|
|
494
656
|
message: "Select a list to subscribe to:",
|
|
495
657
|
options: siteLists.map((l) => ({
|
|
496
658
|
value: l.id,
|
|
@@ -498,28 +660,28 @@ async function runSharepointSubscribe({ cwd }) {
|
|
|
498
660
|
hint: l.id
|
|
499
661
|
}))
|
|
500
662
|
});
|
|
501
|
-
if (
|
|
502
|
-
|
|
663
|
+
if (p6.isCancel(picked)) {
|
|
664
|
+
p6.cancel("Operation cancelled.");
|
|
503
665
|
process.exit(0);
|
|
504
666
|
}
|
|
505
667
|
listId = picked;
|
|
506
668
|
} else {
|
|
507
|
-
const manualId = await
|
|
669
|
+
const manualId = await p6.text({
|
|
508
670
|
message: "Enter list ID (GUID) to subscribe to:",
|
|
509
671
|
placeholder: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
|
510
672
|
validate: (v) => {
|
|
511
673
|
if (!v || v.trim().length === 0) return "List ID is required";
|
|
512
674
|
}
|
|
513
675
|
});
|
|
514
|
-
if (
|
|
515
|
-
|
|
676
|
+
if (p6.isCancel(manualId)) {
|
|
677
|
+
p6.cancel("Operation cancelled.");
|
|
516
678
|
process.exit(0);
|
|
517
679
|
}
|
|
518
680
|
listId = manualId;
|
|
519
681
|
}
|
|
520
682
|
const clientState = await promptClientState();
|
|
521
683
|
const expiryDays = SHAREPOINT_MAX_EXPIRY_DAYS;
|
|
522
|
-
const subSpin =
|
|
684
|
+
const subSpin = p6.spinner();
|
|
523
685
|
subSpin.start("Creating SharePoint webhook subscription...");
|
|
524
686
|
let subscription;
|
|
525
687
|
try {
|
|
@@ -533,13 +695,13 @@ async function runSharepointSubscribe({ cwd }) {
|
|
|
533
695
|
);
|
|
534
696
|
} catch (error) {
|
|
535
697
|
subSpin.stop("Failed.");
|
|
536
|
-
|
|
537
|
-
|
|
698
|
+
p6.log.error(error instanceof Error ? error.message : String(error));
|
|
699
|
+
p6.outro("");
|
|
538
700
|
process.exit(1);
|
|
539
701
|
}
|
|
540
702
|
subSpin.stop("Subscription created.");
|
|
541
703
|
await saveWebhookSignature(accountKm, clientState);
|
|
542
|
-
|
|
704
|
+
p6.note(
|
|
543
705
|
`Subscription ID: ${subscription.id}
|
|
544
706
|
Site ID: ${siteId}
|
|
545
707
|
List ID: ${listId}
|
|
@@ -550,7 +712,7 @@ Webhook URL: ${webhookUrl}
|
|
|
550
712
|
Note: SharePoint subscriptions expire after ${SHAREPOINT_MAX_EXPIRY_DAYS} days max. Re-run this command to renew.`,
|
|
551
713
|
"SharePoint Subscription Created"
|
|
552
714
|
);
|
|
553
|
-
|
|
715
|
+
p6.outro("Done!");
|
|
554
716
|
}
|
|
555
717
|
var SHAREPOINT_MAX_EXPIRY_DAYS;
|
|
556
718
|
var init_sharepoint = __esm({
|
|
@@ -565,7 +727,7 @@ var init_sharepoint = __esm({
|
|
|
565
727
|
});
|
|
566
728
|
|
|
567
729
|
// microsoft/teams.ts
|
|
568
|
-
import * as
|
|
730
|
+
import * as p7 from "@clack/prompts";
|
|
569
731
|
async function fetchJoinedTeams(accessToken) {
|
|
570
732
|
const response = await fetch(`${GRAPH_API_BASE}/me/joinedTeams`, {
|
|
571
733
|
headers: { Authorization: `Bearer ${accessToken}` }
|
|
@@ -601,88 +763,102 @@ async function fetchUserChats(accessToken) {
|
|
|
601
763
|
return data.value ?? [];
|
|
602
764
|
}
|
|
603
765
|
async function pickTeamId(accessToken, label) {
|
|
604
|
-
const teamsSpin =
|
|
766
|
+
const teamsSpin = p7.spinner();
|
|
605
767
|
teamsSpin.start("Fetching your teams...");
|
|
606
768
|
let teams = [];
|
|
607
769
|
try {
|
|
608
770
|
teams = await fetchJoinedTeams(accessToken);
|
|
609
|
-
teamsSpin.stop(
|
|
771
|
+
teamsSpin.stop(
|
|
772
|
+
`Found ${teams.length} team${teams.length === 1 ? "" : "s"}.`
|
|
773
|
+
);
|
|
610
774
|
} catch (error) {
|
|
611
775
|
teamsSpin.stop("Could not fetch teams.");
|
|
612
|
-
|
|
776
|
+
p7.log.warn(error instanceof Error ? error.message : String(error));
|
|
613
777
|
}
|
|
614
778
|
if (teams.length > 0) {
|
|
615
|
-
const picked = await
|
|
779
|
+
const picked = await p7.select({
|
|
616
780
|
message: `[${label}] Select a team:`,
|
|
617
|
-
options: teams.map((t) => ({
|
|
781
|
+
options: teams.map((t) => ({
|
|
782
|
+
value: t.id,
|
|
783
|
+
label: t.displayName,
|
|
784
|
+
hint: t.id
|
|
785
|
+
}))
|
|
618
786
|
});
|
|
619
|
-
if (
|
|
620
|
-
|
|
787
|
+
if (p7.isCancel(picked)) {
|
|
788
|
+
p7.cancel("Operation cancelled.");
|
|
621
789
|
process.exit(0);
|
|
622
790
|
}
|
|
623
791
|
return picked;
|
|
624
792
|
}
|
|
625
|
-
const manual = await
|
|
793
|
+
const manual = await p7.text({
|
|
626
794
|
message: `[${label}] Enter team ID:`,
|
|
627
795
|
placeholder: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
|
628
796
|
validate: (v) => {
|
|
629
797
|
if (!v || !v.trim()) return "Team ID is required";
|
|
630
798
|
}
|
|
631
799
|
});
|
|
632
|
-
if (
|
|
633
|
-
|
|
800
|
+
if (p7.isCancel(manual)) {
|
|
801
|
+
p7.cancel("Operation cancelled.");
|
|
634
802
|
process.exit(0);
|
|
635
803
|
}
|
|
636
804
|
return manual;
|
|
637
805
|
}
|
|
638
806
|
async function pickChannelId(accessToken, teamId, label) {
|
|
639
|
-
const chanSpin =
|
|
807
|
+
const chanSpin = p7.spinner();
|
|
640
808
|
chanSpin.start("Fetching channels...");
|
|
641
809
|
let channels = [];
|
|
642
810
|
try {
|
|
643
811
|
channels = await fetchTeamChannels(accessToken, teamId);
|
|
644
|
-
chanSpin.stop(
|
|
812
|
+
chanSpin.stop(
|
|
813
|
+
`Found ${channels.length} channel${channels.length === 1 ? "" : "s"}.`
|
|
814
|
+
);
|
|
645
815
|
} catch (error) {
|
|
646
816
|
chanSpin.stop("Could not fetch channels.");
|
|
647
|
-
|
|
817
|
+
p7.log.warn(error instanceof Error ? error.message : String(error));
|
|
648
818
|
}
|
|
649
819
|
if (channels.length > 0) {
|
|
650
|
-
const picked = await
|
|
820
|
+
const picked = await p7.select({
|
|
651
821
|
message: `[${label}] Select a channel:`,
|
|
652
|
-
options: channels.map((c) => ({
|
|
822
|
+
options: channels.map((c) => ({
|
|
823
|
+
value: c.id,
|
|
824
|
+
label: c.displayName,
|
|
825
|
+
hint: c.id
|
|
826
|
+
}))
|
|
653
827
|
});
|
|
654
|
-
if (
|
|
655
|
-
|
|
828
|
+
if (p7.isCancel(picked)) {
|
|
829
|
+
p7.cancel("Operation cancelled.");
|
|
656
830
|
process.exit(0);
|
|
657
831
|
}
|
|
658
832
|
return picked;
|
|
659
833
|
}
|
|
660
|
-
const manual = await
|
|
834
|
+
const manual = await p7.text({
|
|
661
835
|
message: `[${label}] Enter channel ID:`,
|
|
662
836
|
placeholder: "19:abc123@thread.skype",
|
|
663
837
|
validate: (v) => {
|
|
664
838
|
if (!v || !v.trim()) return "Channel ID is required";
|
|
665
839
|
}
|
|
666
840
|
});
|
|
667
|
-
if (
|
|
668
|
-
|
|
841
|
+
if (p7.isCancel(manual)) {
|
|
842
|
+
p7.cancel("Operation cancelled.");
|
|
669
843
|
process.exit(0);
|
|
670
844
|
}
|
|
671
845
|
return manual;
|
|
672
846
|
}
|
|
673
847
|
async function pickChatId(accessToken, label) {
|
|
674
|
-
const chatSpin =
|
|
848
|
+
const chatSpin = p7.spinner();
|
|
675
849
|
chatSpin.start("Fetching your chats...");
|
|
676
850
|
let chats = [];
|
|
677
851
|
try {
|
|
678
852
|
chats = await fetchUserChats(accessToken);
|
|
679
|
-
chatSpin.stop(
|
|
853
|
+
chatSpin.stop(
|
|
854
|
+
`Found ${chats.length} chat${chats.length === 1 ? "" : "s"}.`
|
|
855
|
+
);
|
|
680
856
|
} catch (error) {
|
|
681
857
|
chatSpin.stop("Could not fetch chats.");
|
|
682
|
-
|
|
858
|
+
p7.log.warn(error instanceof Error ? error.message : String(error));
|
|
683
859
|
}
|
|
684
860
|
if (chats.length > 0) {
|
|
685
|
-
const picked = await
|
|
861
|
+
const picked = await p7.select({
|
|
686
862
|
message: `[${label}] Select a chat:`,
|
|
687
863
|
options: chats.map((c) => ({
|
|
688
864
|
value: c.id,
|
|
@@ -690,21 +866,21 @@ async function pickChatId(accessToken, label) {
|
|
|
690
866
|
hint: c.id
|
|
691
867
|
}))
|
|
692
868
|
});
|
|
693
|
-
if (
|
|
694
|
-
|
|
869
|
+
if (p7.isCancel(picked)) {
|
|
870
|
+
p7.cancel("Operation cancelled.");
|
|
695
871
|
process.exit(0);
|
|
696
872
|
}
|
|
697
873
|
return picked;
|
|
698
874
|
}
|
|
699
|
-
const manual = await
|
|
875
|
+
const manual = await p7.text({
|
|
700
876
|
message: `[${label}] Enter chat ID:`,
|
|
701
877
|
placeholder: "19:abc123@thread.v2",
|
|
702
878
|
validate: (v) => {
|
|
703
879
|
if (!v || !v.trim()) return "Chat ID is required";
|
|
704
880
|
}
|
|
705
881
|
});
|
|
706
|
-
if (
|
|
707
|
-
|
|
882
|
+
if (p7.isCancel(manual)) {
|
|
883
|
+
p7.cancel("Operation cancelled.");
|
|
708
884
|
process.exit(0);
|
|
709
885
|
}
|
|
710
886
|
return manual;
|
|
@@ -721,7 +897,9 @@ function buildTeamsResource(resourceType, ids) {
|
|
|
721
897
|
return `teams/${ids.teamId}/members`;
|
|
722
898
|
}
|
|
723
899
|
}
|
|
724
|
-
async function runTeamsSubscribe({
|
|
900
|
+
async function runTeamsSubscribe({
|
|
901
|
+
cwd
|
|
902
|
+
}) {
|
|
725
903
|
const { internal } = await loadInternalConfig(
|
|
726
904
|
cwd,
|
|
727
905
|
"Corsair \u2014 Microsoft Teams Webhook Subscribe",
|
|
@@ -735,7 +913,7 @@ async function runTeamsSubscribe({ cwd }) {
|
|
|
735
913
|
internal
|
|
736
914
|
);
|
|
737
915
|
const webhookUrl = await promptWebhookUrl();
|
|
738
|
-
const selectedResourceTypes = await
|
|
916
|
+
const selectedResourceTypes = await p7.multiselect({
|
|
739
917
|
message: "Select resources to subscribe to:",
|
|
740
918
|
options: [
|
|
741
919
|
{
|
|
@@ -757,8 +935,8 @@ async function runTeamsSubscribe({ cwd }) {
|
|
|
757
935
|
],
|
|
758
936
|
required: true
|
|
759
937
|
});
|
|
760
|
-
if (
|
|
761
|
-
|
|
938
|
+
if (p7.isCancel(selectedResourceTypes)) {
|
|
939
|
+
p7.cancel("Operation cancelled.");
|
|
762
940
|
process.exit(0);
|
|
763
941
|
}
|
|
764
942
|
const resourceConfigs = [];
|
|
@@ -769,7 +947,11 @@ async function runTeamsSubscribe({ cwd }) {
|
|
|
769
947
|
} else {
|
|
770
948
|
ids.teamId = await pickTeamId(accessToken, resourceType);
|
|
771
949
|
if (resourceType === "channelMessage") {
|
|
772
|
-
ids.channelId = await pickChannelId(
|
|
950
|
+
ids.channelId = await pickChannelId(
|
|
951
|
+
accessToken,
|
|
952
|
+
ids.teamId,
|
|
953
|
+
resourceType
|
|
954
|
+
);
|
|
773
955
|
}
|
|
774
956
|
}
|
|
775
957
|
resourceConfigs.push({ resourceType, ids });
|
|
@@ -780,7 +962,7 @@ async function runTeamsSubscribe({ cwd }) {
|
|
|
780
962
|
for (const { resourceType, ids } of resourceConfigs) {
|
|
781
963
|
const resource = buildTeamsResource(resourceType, ids);
|
|
782
964
|
const expiryMinutes = TEAMS_MAX_EXPIRY_MINUTES[resourceType];
|
|
783
|
-
const subSpin =
|
|
965
|
+
const subSpin = p7.spinner();
|
|
784
966
|
subSpin.start(`Creating subscription: ${resourceType}...`);
|
|
785
967
|
try {
|
|
786
968
|
const subscription = await createGraphSubscription(
|
|
@@ -800,27 +982,27 @@ async function runTeamsSubscribe({ cwd }) {
|
|
|
800
982
|
);
|
|
801
983
|
} catch (error) {
|
|
802
984
|
subSpin.stop(`Failed: ${resourceType}`);
|
|
803
|
-
|
|
985
|
+
p7.log.error(error instanceof Error ? error.message : String(error));
|
|
804
986
|
hasError = true;
|
|
805
987
|
}
|
|
806
988
|
}
|
|
807
989
|
if (results.length > 0) {
|
|
808
|
-
|
|
990
|
+
p7.note(results.join("\n\n"), "Subscriptions created");
|
|
809
991
|
}
|
|
810
992
|
await saveWebhookSignature(accountKm, clientState);
|
|
811
993
|
if (!hasError) {
|
|
812
|
-
|
|
994
|
+
p7.log.success("Teams webhook subscriptions set up successfully.");
|
|
813
995
|
} else {
|
|
814
|
-
|
|
996
|
+
p7.log.warn("Some subscriptions failed. Check errors above.");
|
|
815
997
|
}
|
|
816
|
-
|
|
998
|
+
p7.note(
|
|
817
999
|
`ClientState: ${clientState}
|
|
818
1000
|
Webhook URL: ${webhookUrl}
|
|
819
1001
|
|
|
820
1002
|
Note: Teams subscriptions expire. Re-run this command to renew.`,
|
|
821
1003
|
"Setup complete"
|
|
822
1004
|
);
|
|
823
|
-
|
|
1005
|
+
p7.outro("Done!");
|
|
824
1006
|
}
|
|
825
1007
|
var TEAMS_MAX_EXPIRY_MINUTES;
|
|
826
1008
|
var init_teams = __esm({
|
|
@@ -839,149 +1021,6 @@ var init_teams = __esm({
|
|
|
839
1021
|
}
|
|
840
1022
|
});
|
|
841
1023
|
|
|
842
|
-
// microsoft/onedrive.ts
|
|
843
|
-
import * as p7 from "@clack/prompts";
|
|
844
|
-
function buildOnedriveResource(resourceType, ids) {
|
|
845
|
-
switch (resourceType) {
|
|
846
|
-
case "personalDrive":
|
|
847
|
-
return "me/drive/root";
|
|
848
|
-
case "specificDrive":
|
|
849
|
-
return `drives/${ids.driveId}/root`;
|
|
850
|
-
case "specificFolder":
|
|
851
|
-
return `me/drive/items/${ids.itemId}`;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
async function runOnedriveSubscribe({ cwd }) {
|
|
855
|
-
const { internal } = await loadInternalConfig(
|
|
856
|
-
cwd,
|
|
857
|
-
"Corsair \u2014 OneDrive Webhook Subscribe",
|
|
858
|
-
"onedrive",
|
|
859
|
-
"OneDrive"
|
|
860
|
-
);
|
|
861
|
-
const tenantId = await promptTenantId();
|
|
862
|
-
const { accessToken, accountKm } = await resolveAccessToken(
|
|
863
|
-
"onedrive",
|
|
864
|
-
tenantId,
|
|
865
|
-
internal
|
|
866
|
-
);
|
|
867
|
-
const webhookUrl = await promptWebhookUrl();
|
|
868
|
-
const selectedResourceTypes = await p7.multiselect({
|
|
869
|
-
message: "Select resources to subscribe to:",
|
|
870
|
-
options: ONEDRIVE_RESOURCE_OPTIONS,
|
|
871
|
-
required: true
|
|
872
|
-
});
|
|
873
|
-
if (p7.isCancel(selectedResourceTypes)) {
|
|
874
|
-
p7.cancel("Operation cancelled.");
|
|
875
|
-
process.exit(0);
|
|
876
|
-
}
|
|
877
|
-
const resourceConfigs = [];
|
|
878
|
-
for (const resourceType of selectedResourceTypes) {
|
|
879
|
-
const ids = {};
|
|
880
|
-
if (resourceType === "specificDrive") {
|
|
881
|
-
const driveId = await p7.text({
|
|
882
|
-
message: `[${resourceType}] Enter drive ID:`,
|
|
883
|
-
placeholder: "b!abc123...",
|
|
884
|
-
validate: (v) => {
|
|
885
|
-
if (!v || !v.trim()) return "Drive ID is required";
|
|
886
|
-
}
|
|
887
|
-
});
|
|
888
|
-
if (p7.isCancel(driveId)) {
|
|
889
|
-
p7.cancel("Operation cancelled.");
|
|
890
|
-
process.exit(0);
|
|
891
|
-
}
|
|
892
|
-
ids.driveId = driveId;
|
|
893
|
-
} else if (resourceType === "specificFolder") {
|
|
894
|
-
const itemId = await p7.text({
|
|
895
|
-
message: `[${resourceType}] Enter item/folder ID:`,
|
|
896
|
-
placeholder: "01ABC123...",
|
|
897
|
-
validate: (v) => {
|
|
898
|
-
if (!v || !v.trim()) return "Item ID is required";
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
if (p7.isCancel(itemId)) {
|
|
902
|
-
p7.cancel("Operation cancelled.");
|
|
903
|
-
process.exit(0);
|
|
904
|
-
}
|
|
905
|
-
ids.itemId = itemId;
|
|
906
|
-
}
|
|
907
|
-
resourceConfigs.push({ resourceType, ids });
|
|
908
|
-
}
|
|
909
|
-
const clientState = await promptClientState();
|
|
910
|
-
const results = [];
|
|
911
|
-
let hasError = false;
|
|
912
|
-
for (const { resourceType, ids } of resourceConfigs) {
|
|
913
|
-
const resource = buildOnedriveResource(resourceType, ids);
|
|
914
|
-
const subSpin = p7.spinner();
|
|
915
|
-
subSpin.start(`Creating subscription: ${resourceType}...`);
|
|
916
|
-
try {
|
|
917
|
-
const subscription = await createGraphSubscription(
|
|
918
|
-
accessToken,
|
|
919
|
-
webhookUrl,
|
|
920
|
-
resource,
|
|
921
|
-
"updated",
|
|
922
|
-
clientState,
|
|
923
|
-
ONEDRIVE_MAX_EXPIRY_MINUTES
|
|
924
|
-
);
|
|
925
|
-
subSpin.stop(`Created: ${resourceType}`);
|
|
926
|
-
results.push(
|
|
927
|
-
`${resourceType}
|
|
928
|
-
Resource: ${resource}
|
|
929
|
-
ID: ${subscription.id}
|
|
930
|
-
Expires: ${subscription.expirationDateTime}`
|
|
931
|
-
);
|
|
932
|
-
} catch (error) {
|
|
933
|
-
subSpin.stop(`Failed: ${resourceType}`);
|
|
934
|
-
p7.log.error(error instanceof Error ? error.message : String(error));
|
|
935
|
-
hasError = true;
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
if (results.length > 0) {
|
|
939
|
-
p7.note(results.join("\n\n"), "Subscriptions created");
|
|
940
|
-
}
|
|
941
|
-
await saveWebhookSignature(accountKm, clientState);
|
|
942
|
-
if (!hasError) {
|
|
943
|
-
p7.log.success("OneDrive webhook subscriptions set up successfully.");
|
|
944
|
-
} else {
|
|
945
|
-
p7.log.warn("Some subscriptions failed. Check errors above.");
|
|
946
|
-
}
|
|
947
|
-
p7.note(
|
|
948
|
-
`ClientState: ${clientState}
|
|
949
|
-
Webhook URL: ${webhookUrl}
|
|
950
|
-
|
|
951
|
-
Note: OneDrive subscriptions expire. Re-run this command to renew.`,
|
|
952
|
-
"Setup complete"
|
|
953
|
-
);
|
|
954
|
-
p7.outro("Done!");
|
|
955
|
-
}
|
|
956
|
-
var ONEDRIVE_MAX_EXPIRY_MINUTES, ONEDRIVE_RESOURCE_OPTIONS;
|
|
957
|
-
var init_onedrive = __esm({
|
|
958
|
-
"microsoft/onedrive.ts"() {
|
|
959
|
-
"use strict";
|
|
960
|
-
init_load_config();
|
|
961
|
-
init_prompts();
|
|
962
|
-
init_credentials();
|
|
963
|
-
init_graph();
|
|
964
|
-
ONEDRIVE_MAX_EXPIRY_MINUTES = 4230;
|
|
965
|
-
ONEDRIVE_RESOURCE_OPTIONS = [
|
|
966
|
-
{
|
|
967
|
-
value: "personalDrive",
|
|
968
|
-
label: "Personal Drive Root \u2014 all changes to the user's drive",
|
|
969
|
-
hint: "me/drive/root"
|
|
970
|
-
},
|
|
971
|
-
{
|
|
972
|
-
value: "specificDrive",
|
|
973
|
-
label: "Specific Drive Root \u2014 all changes to a given drive ID",
|
|
974
|
-
hint: "drives/{driveId}/root"
|
|
975
|
-
},
|
|
976
|
-
{
|
|
977
|
-
value: "specificFolder",
|
|
978
|
-
label: "Specific Folder \u2014 changes within a given item/folder",
|
|
979
|
-
hint: "me/drive/items/{itemId}"
|
|
980
|
-
}
|
|
981
|
-
];
|
|
982
|
-
}
|
|
983
|
-
});
|
|
984
|
-
|
|
985
1024
|
// subscribe-microsoft.ts
|
|
986
1025
|
var subscribe_microsoft_exports = {};
|
|
987
1026
|
__export(subscribe_microsoft_exports, {
|
|
@@ -993,10 +1032,10 @@ __export(subscribe_microsoft_exports, {
|
|
|
993
1032
|
var init_subscribe_microsoft = __esm({
|
|
994
1033
|
"subscribe-microsoft.ts"() {
|
|
995
1034
|
"use strict";
|
|
1035
|
+
init_onedrive();
|
|
996
1036
|
init_outlook();
|
|
997
1037
|
init_sharepoint();
|
|
998
1038
|
init_teams();
|
|
999
|
-
init_onedrive();
|
|
1000
1039
|
}
|
|
1001
1040
|
});
|
|
1002
1041
|
|
|
@@ -1052,9 +1091,12 @@ import * as p9 from "@clack/prompts";
|
|
|
1052
1091
|
async function setupDriveWatch(accessToken, webhookUrl) {
|
|
1053
1092
|
const watchSpin = p9.spinner();
|
|
1054
1093
|
watchSpin.start("Getting start page token...");
|
|
1055
|
-
const startPageTokenRes = await fetch(
|
|
1056
|
-
|
|
1057
|
-
|
|
1094
|
+
const startPageTokenRes = await fetch(
|
|
1095
|
+
`${DRIVE_API_BASE}/changes/startPageToken`,
|
|
1096
|
+
{
|
|
1097
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
1098
|
+
}
|
|
1099
|
+
);
|
|
1058
1100
|
if (!startPageTokenRes.ok) {
|
|
1059
1101
|
const error = await startPageTokenRes.text();
|
|
1060
1102
|
watchSpin.stop("Failed.");
|
|
@@ -1224,7 +1266,9 @@ async function setupSheetsWatch(webhookUrl) {
|
|
|
1224
1266
|
p11.log.info("1. Open your Google Sheet");
|
|
1225
1267
|
p11.log.info("2. Go to Extensions > Apps Script");
|
|
1226
1268
|
p11.log.info("3. Paste the code into the script editor");
|
|
1227
|
-
p11.log.info(
|
|
1269
|
+
p11.log.info(
|
|
1270
|
+
'4. Run the "createTriggers" function once to install the triggers'
|
|
1271
|
+
);
|
|
1228
1272
|
p11.log.info("5. Authorize the script when prompted");
|
|
1229
1273
|
p11.log.info("");
|
|
1230
1274
|
if (!copied) {
|
|
@@ -1315,7 +1359,11 @@ function removeTriggers() {
|
|
|
1315
1359
|
|
|
1316
1360
|
// google/index.ts
|
|
1317
1361
|
import * as p12 from "@clack/prompts";
|
|
1318
|
-
import {
|
|
1362
|
+
import {
|
|
1363
|
+
CORSAIR_INTERNAL as CORSAIR_INTERNAL2,
|
|
1364
|
+
createAccountKeyManager as createAccountKeyManager2,
|
|
1365
|
+
createIntegrationKeyManager as createIntegrationKeyManager2
|
|
1366
|
+
} from "corsair/core";
|
|
1319
1367
|
async function extractInternalConfig2(cwd) {
|
|
1320
1368
|
const instance = await getCorsairInstance({ cwd, shouldThrowOnError: true });
|
|
1321
1369
|
const internal = instance[CORSAIR_INTERNAL2];
|
|
@@ -1421,7 +1469,11 @@ async function runGoogleSubscribe({
|
|
|
1421
1469
|
p12.outro("");
|
|
1422
1470
|
process.exit(1);
|
|
1423
1471
|
}
|
|
1424
|
-
const accessToken = await refreshGoogleAccessToken(
|
|
1472
|
+
const accessToken = await refreshGoogleAccessToken(
|
|
1473
|
+
clientId,
|
|
1474
|
+
clientSecret,
|
|
1475
|
+
refreshToken
|
|
1476
|
+
);
|
|
1425
1477
|
credSpin.stop("Credentials loaded.");
|
|
1426
1478
|
if (pluginType === "gmail") {
|
|
1427
1479
|
const topicName = await p12.text({
|
|
@@ -1470,14 +1522,20 @@ async function runGoogleSubscribe({
|
|
|
1470
1522
|
p12.cancel("Operation cancelled.");
|
|
1471
1523
|
process.exit(0);
|
|
1472
1524
|
}
|
|
1473
|
-
await setupCalendarWatch(
|
|
1525
|
+
await setupCalendarWatch(
|
|
1526
|
+
accessToken,
|
|
1527
|
+
webhookUrl,
|
|
1528
|
+
calendarId
|
|
1529
|
+
);
|
|
1474
1530
|
} else {
|
|
1475
1531
|
p12.log.error(`Unsupported Google plugin: ${pluginType}`);
|
|
1476
1532
|
process.exit(1);
|
|
1477
1533
|
}
|
|
1478
1534
|
} catch (error) {
|
|
1479
1535
|
credSpin.stop("Failed.");
|
|
1480
|
-
p12.log.error(
|
|
1536
|
+
p12.log.error(
|
|
1537
|
+
`Error: ${error instanceof Error ? error.message : String(error)}`
|
|
1538
|
+
);
|
|
1481
1539
|
process.exit(1);
|
|
1482
1540
|
}
|
|
1483
1541
|
p12.outro("Done!");
|
|
@@ -1932,7 +1990,8 @@ async function runAuth({
|
|
|
1932
1990
|
pluginId: pluginIdArg,
|
|
1933
1991
|
tenantId: tenantIdArg,
|
|
1934
1992
|
code: codeArg,
|
|
1935
|
-
credentials: showCredentials = false
|
|
1993
|
+
credentials: showCredentials = false,
|
|
1994
|
+
agent: agentMode = false
|
|
1936
1995
|
}) {
|
|
1937
1996
|
let internal;
|
|
1938
1997
|
try {
|
|
@@ -1978,6 +2037,24 @@ async function runAuth({
|
|
|
1978
2037
|
});
|
|
1979
2038
|
return;
|
|
1980
2039
|
}
|
|
2040
|
+
if (agentMode) {
|
|
2041
|
+
const baseCmd = `pnpm corsair auth --plugin=${plugin.id}`;
|
|
2042
|
+
const needsQuoting = tenantIdArg && /[^a-zA-Z0-9_\-.]/.test(tenantIdArg);
|
|
2043
|
+
const tenantFlag = tenantIdArg && tenantIdArg !== "default" ? ` --tenant=${needsQuoting ? `"${tenantIdArg}"` : tenantIdArg}` : "";
|
|
2044
|
+
const cmd = `${baseCmd}${tenantFlag}`;
|
|
2045
|
+
out({
|
|
2046
|
+
status: "agent_instructions",
|
|
2047
|
+
plugin: plugin.id,
|
|
2048
|
+
tenant: tenantId,
|
|
2049
|
+
command: cmd,
|
|
2050
|
+
message: `To authenticate the '${plugin.id}' plugin, run the following command:
|
|
2051
|
+
|
|
2052
|
+
${cmd}
|
|
2053
|
+
|
|
2054
|
+
This command opens a browser and waits for an OAuth callback \u2014 it is a long-running interactive task. Either ask the user to run it in a separate terminal, or run it as a background process. Do NOT run it inline in the current session.`
|
|
2055
|
+
});
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
1981
2058
|
if (codeArg) {
|
|
1982
2059
|
await oauthWithCode(database, plugin, kek, tenantId, codeArg);
|
|
1983
2060
|
} else {
|
|
@@ -2269,11 +2346,16 @@ function parseAuthArgs(args) {
|
|
|
2269
2346
|
let code;
|
|
2270
2347
|
let credentials = false;
|
|
2271
2348
|
let webhook = false;
|
|
2349
|
+
let agent = false;
|
|
2272
2350
|
for (const arg of args) {
|
|
2273
2351
|
if (arg === "--credentials") {
|
|
2274
2352
|
credentials = true;
|
|
2275
2353
|
continue;
|
|
2276
2354
|
}
|
|
2355
|
+
if (arg === "--agent") {
|
|
2356
|
+
agent = true;
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2277
2359
|
if (arg === "--webhook") {
|
|
2278
2360
|
webhook = true;
|
|
2279
2361
|
continue;
|
|
@@ -2296,7 +2378,7 @@ function parseAuthArgs(args) {
|
|
|
2296
2378
|
}
|
|
2297
2379
|
}
|
|
2298
2380
|
}
|
|
2299
|
-
return { pluginId, tenantId, code, credentials, webhook };
|
|
2381
|
+
return { pluginId, tenantId, code, credentials, webhook, agent };
|
|
2300
2382
|
}
|
|
2301
2383
|
function parseSetupArgs(args) {
|
|
2302
2384
|
let backfill = false;
|
|
@@ -2308,11 +2390,12 @@ function parseSetupArgs(args) {
|
|
|
2308
2390
|
currentPlugin = null;
|
|
2309
2391
|
continue;
|
|
2310
2392
|
}
|
|
2393
|
+
if (arg.startsWith("--plugin=")) {
|
|
2394
|
+
currentPlugin = arg.slice("--plugin=".length);
|
|
2395
|
+
if (!credentials[currentPlugin]) credentials[currentPlugin] = {};
|
|
2396
|
+
continue;
|
|
2397
|
+
}
|
|
2311
2398
|
if (arg.startsWith("--")) {
|
|
2312
|
-
const name = arg.slice(2);
|
|
2313
|
-
if (RESERVED_FLAGS.has(name)) continue;
|
|
2314
|
-
currentPlugin = name;
|
|
2315
|
-
credentials[currentPlugin] = {};
|
|
2316
2399
|
continue;
|
|
2317
2400
|
}
|
|
2318
2401
|
if (currentPlugin && arg.includes("=")) {
|
|
@@ -2366,20 +2449,21 @@ function printHelp() {
|
|
|
2366
2449
|
const lines = [
|
|
2367
2450
|
"Corsair CLI",
|
|
2368
2451
|
"",
|
|
2369
|
-
"
|
|
2370
|
-
"
|
|
2371
|
-
"
|
|
2372
|
-
"
|
|
2373
|
-
"
|
|
2374
|
-
"
|
|
2375
|
-
"
|
|
2376
|
-
" pnpm corsair list
|
|
2377
|
-
"
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
"
|
|
2381
|
-
"
|
|
2382
|
-
"
|
|
2452
|
+
"pnpm corsair setup Init (add -backfill to seed data)",
|
|
2453
|
+
"pnpm corsair setup --plugin=<id> <field>=VALUE Set plugin credentials",
|
|
2454
|
+
"pnpm corsair auth --plugin=<id> Start OAuth flow",
|
|
2455
|
+
"pnpm corsair auth --plugin=<id> --code=<code> Exchange OAuth code for tokens",
|
|
2456
|
+
"pnpm corsair auth --plugin=<id> --agent Run this if you are an agent (specific instructions to handle pending process)",
|
|
2457
|
+
"pnpm corsair auth --plugin=<id> --credentials Show credential status",
|
|
2458
|
+
"pnpm corsair auth --plugin=<id> --webhook Set up webhook subscription",
|
|
2459
|
+
" `pnpm corsair list --type=webhooks` to see webhook plugins",
|
|
2460
|
+
"pnpm corsair list [--plugin=<id>] [--type=api|webhooks|db] List endpoint paths (tip: pipe to grep to filter)",
|
|
2461
|
+
"pnpm corsair schema <path> Show schema for an endpoint/webhook/DB entity",
|
|
2462
|
+
'pnpm corsair script --code "<js>" [--tenant=<id>]',
|
|
2463
|
+
" corsair is injected; use return to output a value.",
|
|
2464
|
+
" IMPORTANT: Always filter results inline \u2014 you are the consumer of the return value, so returning full list responses wastes tokens.",
|
|
2465
|
+
" Bad: return await corsair.slack.api.users.list({})",
|
|
2466
|
+
" Good: return (await corsair.slack.api.users.list({})).members.find(u => u.name === 'bob')?.id",
|
|
2383
2467
|
...SHOW_RUN ? [" run <path> [input-json] [--tenant=<id>] Call an endpoint directly"] : []
|
|
2384
2468
|
];
|
|
2385
2469
|
console.log(lines.join("\n"));
|
|
@@ -2478,6 +2562,12 @@ async function main() {
|
|
|
2478
2562
|
process.exit(1);
|
|
2479
2563
|
}
|
|
2480
2564
|
const result = corsair.list_operations({ plugin, type });
|
|
2565
|
+
if (type === "db") {
|
|
2566
|
+
console.log(
|
|
2567
|
+
"[#corsair]: NOTE: Every DB query listed here has both .search() and .list() methods available."
|
|
2568
|
+
);
|
|
2569
|
+
console.log("");
|
|
2570
|
+
}
|
|
2481
2571
|
if (typeof result === "string") {
|
|
2482
2572
|
console.log(result);
|
|
2483
2573
|
} else if (Array.isArray(result)) {
|
|
@@ -2578,7 +2668,7 @@ async function main() {
|
|
|
2578
2668
|
}
|
|
2579
2669
|
printHelp();
|
|
2580
2670
|
}
|
|
2581
|
-
var possiblePaths, jitiOptions, isCorsairInstance,
|
|
2671
|
+
var possiblePaths, jitiOptions, isCorsairInstance, SHOW_RUN, isMainModule;
|
|
2582
2672
|
var init_index = __esm({
|
|
2583
2673
|
"index.ts"() {
|
|
2584
2674
|
init_get_tsconfig_info();
|
|
@@ -2642,11 +2732,13 @@ var init_index = __esm({
|
|
|
2642
2732
|
}
|
|
2643
2733
|
return Object.keys(object).length > 0;
|
|
2644
2734
|
};
|
|
2645
|
-
RESERVED_FLAGS = /* @__PURE__ */ new Set(["backfill", "help", "h"]);
|
|
2646
2735
|
SHOW_RUN = false;
|
|
2647
2736
|
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");
|
|
2648
2737
|
if (isMainModule) {
|
|
2649
|
-
main()
|
|
2738
|
+
main().then(() => process.exit(0)).catch((e) => {
|
|
2739
|
+
console.error(e);
|
|
2740
|
+
process.exit(1);
|
|
2741
|
+
});
|
|
2650
2742
|
}
|
|
2651
2743
|
}
|
|
2652
2744
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../microsoft/credentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../microsoft/credentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAW1D,MAAM,MAAM,kBAAkB,GAAG;IAChC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D,CAAC;AAkCF,wBAAsB,kBAAkB,CACvC,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,qBAAqB,GAC7B,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,kBAAkB,CAAA;CAAE,CAAC,CA2FjE;AAED,wBAAsB,oBAAoB,CACzC,SAAS,EAAE;IAAE,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,EAChE,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onedrive.d.ts","sourceRoot":"","sources":["../../microsoft/onedrive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"onedrive.d.ts","sourceRoot":"","sources":["../../microsoft/onedrive.ts"],"names":[],"mappings":"AAsDA,wBAAsB,oBAAoB,CAAC,EAC1C,GAAG,GACH,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkHhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outlook.d.ts","sourceRoot":"","sources":["../../microsoft/outlook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"outlook.d.ts","sourceRoot":"","sources":["../../microsoft/outlook.ts"],"names":[],"mappings":"AAqDA,wBAAsB,mBAAmB,CAAC,EACzC,GAAG,GACH,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkFhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharepoint.d.ts","sourceRoot":"","sources":["../../microsoft/sharepoint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sharepoint.d.ts","sourceRoot":"","sources":["../../microsoft/sharepoint.ts"],"names":[],"mappings":"AA2EA,wBAAsB,sBAAsB,CAAC,EAC5C,GAAG,GACH,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkHhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"teams.d.ts","sourceRoot":"","sources":["../../microsoft/teams.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"teams.d.ts","sourceRoot":"","sources":["../../microsoft/teams.ts"],"names":[],"mappings":"AAkOA,wBAAsB,iBAAiB,CAAC,EACvC,GAAG,GACH,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoHhB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export { runOnedriveSubscribe } from './microsoft/onedrive';
|
|
1
2
|
export { runOutlookSubscribe } from './microsoft/outlook';
|
|
2
3
|
export { runSharepointSubscribe } from './microsoft/sharepoint';
|
|
3
4
|
export { runTeamsSubscribe } from './microsoft/teams';
|
|
4
|
-
export { runOnedriveSubscribe } from './microsoft/onedrive';
|
|
5
5
|
//# sourceMappingURL=subscribe-microsoft.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-microsoft.d.ts","sourceRoot":"","sources":["../subscribe-microsoft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"subscribe-microsoft.d.ts","sourceRoot":"","sources":["../subscribe-microsoft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corsair-dev/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
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.57"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^29.5.14",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dotenv": "^17.2.3",
|
|
32
32
|
"jest": "^29.7.0",
|
|
33
33
|
"jiti": "^2.6.1",
|
|
34
|
-
"ts-jest": "^29.
|
|
34
|
+
"ts-jest": "^29.4.9",
|
|
35
35
|
"ts-node": "^10.9.2",
|
|
36
36
|
"tsup": "^8.0.1",
|
|
37
37
|
"tsx": "^4.20.6",
|