corsair 0.1.31 → 0.1.33
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/core/auth/key-manager.d.ts.map +1 -1
- package/dist/core.js +16 -3
- package/dist/index.js +48 -24
- package/dist/setup/index.d.ts +4 -1
- package/dist/setup/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-manager.d.ts","sourceRoot":"","sources":["../../../core/auth/key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAS9C,OAAO,KAAK,EAEX,oBAAoB,EAEpB,wBAAwB,EAExB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"key-manager.d.ts","sourceRoot":"","sources":["../../../core/auth/key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAS9C,OAAO,KAAK,EAEX,oBAAoB,EAEpB,wBAAwB,EAExB,MAAM,SAAS,CAAC;AAyDjB,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,SAAS,IAAI;IAC/D,QAAQ,EAAE,CAAC,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,eAAe,CAAC;IAC1B,4DAA4D;IAC5D,sBAAsB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,EAC9D,OAAO,EAAE,4BAA4B,CAAC,CAAC,CAAC,GACtC,wBAAwB,CAAC,CAAC,CAAC,CA2J7B;AAMD,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,SAAS,IAAI;IAC3D,QAAQ,EAAE,CAAC,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,eAAe,CAAC;IAC1B,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,SAAS,EAC1D,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAClC,oBAAoB,CAAC,CAAC,CAAC,CA4OzB;AAMD;;;GAGG;AACH,wBAAsB,wBAAwB,CAC7C,QAAQ,EAAE,eAAe,EACzB,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,MAAM,CAAC,CAwBjB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACzC,QAAQ,EAAE,eAAe,EACzB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,MAAM,CAAC,CAqCjB"}
|
package/dist/core.js
CHANGED
|
@@ -497,7 +497,8 @@ function createFieldAccessors(getDecryptedConfig, updateConfig, fields) {
|
|
|
497
497
|
return config[field] ?? null;
|
|
498
498
|
};
|
|
499
499
|
accessors[`set_${field}`] = async (value) => {
|
|
500
|
-
|
|
500
|
+
const normalized = [null, void 0, ""].includes(value) ? null : value;
|
|
501
|
+
await updateConfig({ [field]: normalized });
|
|
501
502
|
};
|
|
502
503
|
}
|
|
503
504
|
return accessors;
|
|
@@ -577,7 +578,13 @@ function createIntegrationKeyManager(options) {
|
|
|
577
578
|
};
|
|
578
579
|
const updateConfig = async (updates) => {
|
|
579
580
|
const dek = await getDecryptedDek();
|
|
580
|
-
|
|
581
|
+
let currentConfig;
|
|
582
|
+
try {
|
|
583
|
+
currentConfig = await getDecryptedConfig();
|
|
584
|
+
} catch (err) {
|
|
585
|
+
console.error(`[corsair] Failed to decrypt config for integration "${integrationName}", starting fresh:`, err);
|
|
586
|
+
currentConfig = {};
|
|
587
|
+
}
|
|
581
588
|
const newConfig = { ...currentConfig };
|
|
582
589
|
for (const [key, value] of Object.entries(updates)) {
|
|
583
590
|
if (value === null) {
|
|
@@ -720,7 +727,13 @@ function createAccountKeyManager(options) {
|
|
|
720
727
|
};
|
|
721
728
|
const updateConfig = async (updates) => {
|
|
722
729
|
const dek = await getDecryptedDek();
|
|
723
|
-
|
|
730
|
+
let currentConfig;
|
|
731
|
+
try {
|
|
732
|
+
currentConfig = await getDecryptedConfig();
|
|
733
|
+
} catch (err) {
|
|
734
|
+
console.error(`[corsair] Failed to decrypt config for account (tenant: "${tenantId}", integration: "${integrationName}"), starting fresh:`, err);
|
|
735
|
+
currentConfig = {};
|
|
736
|
+
}
|
|
724
737
|
const newConfig = { ...currentConfig };
|
|
725
738
|
for (const [key, value] of Object.entries(updates)) {
|
|
726
739
|
if (value === null) {
|
package/dist/index.js
CHANGED
|
@@ -509,7 +509,8 @@ function createFieldAccessors(getDecryptedConfig, updateConfig, fields) {
|
|
|
509
509
|
return config[field] ?? null;
|
|
510
510
|
};
|
|
511
511
|
accessors[`set_${field}`] = async (value) => {
|
|
512
|
-
|
|
512
|
+
const normalized = [null, void 0, ""].includes(value) ? null : value;
|
|
513
|
+
await updateConfig({ [field]: normalized });
|
|
513
514
|
};
|
|
514
515
|
}
|
|
515
516
|
return accessors;
|
|
@@ -589,7 +590,13 @@ function createIntegrationKeyManager(options) {
|
|
|
589
590
|
};
|
|
590
591
|
const updateConfig = async (updates) => {
|
|
591
592
|
const dek = await getDecryptedDek();
|
|
592
|
-
|
|
593
|
+
let currentConfig;
|
|
594
|
+
try {
|
|
595
|
+
currentConfig = await getDecryptedConfig();
|
|
596
|
+
} catch (err) {
|
|
597
|
+
console.error(`[corsair] Failed to decrypt config for integration "${integrationName}", starting fresh:`, err);
|
|
598
|
+
currentConfig = {};
|
|
599
|
+
}
|
|
593
600
|
const newConfig = { ...currentConfig };
|
|
594
601
|
for (const [key, value] of Object.entries(updates)) {
|
|
595
602
|
if (value === null) {
|
|
@@ -732,7 +739,13 @@ function createAccountKeyManager(options) {
|
|
|
732
739
|
};
|
|
733
740
|
const updateConfig = async (updates) => {
|
|
734
741
|
const dek = await getDecryptedDek();
|
|
735
|
-
|
|
742
|
+
let currentConfig;
|
|
743
|
+
try {
|
|
744
|
+
currentConfig = await getDecryptedConfig();
|
|
745
|
+
} catch (err) {
|
|
746
|
+
console.error(`[corsair] Failed to decrypt config for account (tenant: "${tenantId}", integration: "${integrationName}"), starting fresh:`, err);
|
|
747
|
+
currentConfig = {};
|
|
748
|
+
}
|
|
736
749
|
const newConfig = { ...currentConfig };
|
|
737
750
|
for (const [key, value] of Object.entries(updates)) {
|
|
738
751
|
if (value === null) {
|
|
@@ -35714,6 +35727,15 @@ var backfill_default = { "slack": { "channels": { "list": {} }, "users": { "list
|
|
|
35714
35727
|
|
|
35715
35728
|
// setup/index.ts
|
|
35716
35729
|
async function setupCorsair(corsair, options) {
|
|
35730
|
+
const messages = [];
|
|
35731
|
+
const log = (msg) => {
|
|
35732
|
+
messages.push(msg);
|
|
35733
|
+
console.log(msg);
|
|
35734
|
+
};
|
|
35735
|
+
const warn = (msg) => {
|
|
35736
|
+
messages.push(msg);
|
|
35737
|
+
console.warn(msg);
|
|
35738
|
+
};
|
|
35717
35739
|
const internal = corsair[CORSAIR_INTERNAL];
|
|
35718
35740
|
if (!internal) {
|
|
35719
35741
|
throw new Error("setupCorsair: invalid corsair instance");
|
|
@@ -35734,17 +35756,19 @@ async function setupCorsair(corsair, options) {
|
|
|
35734
35756
|
database: internal.database.db,
|
|
35735
35757
|
kek: internal.kek
|
|
35736
35758
|
});
|
|
35737
|
-
await checkTables(db);
|
|
35759
|
+
await checkTables(db, warn);
|
|
35738
35760
|
const authReadyPlugins = await ensurePluginRows(
|
|
35739
35761
|
db,
|
|
35740
35762
|
instance,
|
|
35741
|
-
internal.plugins
|
|
35763
|
+
internal.plugins,
|
|
35764
|
+
log
|
|
35742
35765
|
);
|
|
35743
35766
|
if (options?.backfill) {
|
|
35744
|
-
|
|
35745
|
-
await runBackfill(instance, internal.plugins, authReadyPlugins);
|
|
35746
|
-
|
|
35767
|
+
log("[corsair:setup] Starting backfill...");
|
|
35768
|
+
await runBackfill(instance, internal.plugins, authReadyPlugins, log, warn);
|
|
35769
|
+
log("[corsair:setup] Backfill complete.");
|
|
35747
35770
|
}
|
|
35771
|
+
return messages.join("\n");
|
|
35748
35772
|
}
|
|
35749
35773
|
var REQUIRED_TABLES = {
|
|
35750
35774
|
...TABLE_SCHEMAS
|
|
@@ -35774,12 +35798,12 @@ function describeZodSchema(schema) {
|
|
|
35774
35798
|
if (schema instanceof ZodRecord) return "Record<string, unknown>";
|
|
35775
35799
|
return "unknown";
|
|
35776
35800
|
}
|
|
35777
|
-
async function checkTables(db) {
|
|
35801
|
+
async function checkTables(db, warn) {
|
|
35778
35802
|
const existing = await db.introspection.getTables();
|
|
35779
35803
|
const existingNames = new Set(existing.map((t) => t.name));
|
|
35780
35804
|
for (const [table, schema] of Object.entries(REQUIRED_TABLES)) {
|
|
35781
35805
|
if (!existingNames.has(table)) {
|
|
35782
|
-
|
|
35806
|
+
warn(
|
|
35783
35807
|
`[corsair:setup] Table "${table}" does not exist. Run your database migrations before calling setupCorsair.
|
|
35784
35808
|
Schema: ${JSON.stringify(describeZodSchema(schema), null, 2)}`
|
|
35785
35809
|
);
|
|
@@ -35792,7 +35816,7 @@ var OPTIONAL_FIELDS = /* @__PURE__ */ new Set([
|
|
|
35792
35816
|
"scope",
|
|
35793
35817
|
"redirect_url"
|
|
35794
35818
|
]);
|
|
35795
|
-
async function checkAuthStatus(pluginId, authType, integrationKeyMgr, accountKeyMgr) {
|
|
35819
|
+
async function checkAuthStatus(pluginId, authType, integrationKeyMgr, accountKeyMgr, log) {
|
|
35796
35820
|
const missingIntegration = [];
|
|
35797
35821
|
const missingAccount = [];
|
|
35798
35822
|
for (const key of Object.keys(integrationKeyMgr)) {
|
|
@@ -35832,12 +35856,12 @@ async function checkAuthStatus(pluginId, authType, integrationKeyMgr, accountKey
|
|
|
35832
35856
|
for (const field of missingAccount) {
|
|
35833
35857
|
lines.push(` corsair.${pluginId}.keys.set_${field}(value)`);
|
|
35834
35858
|
}
|
|
35835
|
-
|
|
35859
|
+
log(lines.join("\n"));
|
|
35836
35860
|
}
|
|
35837
35861
|
return isReady;
|
|
35838
35862
|
}
|
|
35839
35863
|
var TENANT_ID = "default";
|
|
35840
|
-
async function ensurePluginRows(db, instance, plugins) {
|
|
35864
|
+
async function ensurePluginRows(db, instance, plugins, log) {
|
|
35841
35865
|
const now = /* @__PURE__ */ new Date();
|
|
35842
35866
|
const authReadyPlugins = /* @__PURE__ */ new Set();
|
|
35843
35867
|
const integrationKeys = instance.keys;
|
|
@@ -35856,12 +35880,12 @@ async function ensurePluginRows(db, instance, plugins) {
|
|
|
35856
35880
|
updated_at: now
|
|
35857
35881
|
}).execute();
|
|
35858
35882
|
integration = await db.selectFrom("corsair_integrations").selectAll().where("id", "=", id).executeTakeFirst();
|
|
35859
|
-
|
|
35883
|
+
log(`[corsair:setup] Created integration: ${pluginId}`);
|
|
35860
35884
|
}
|
|
35861
35885
|
const integrationKeyMgr = integrationKeys[pluginId];
|
|
35862
35886
|
if (integration && !integration.dek && integrationKeyMgr) {
|
|
35863
35887
|
await integrationKeyMgr.issue_new_dek();
|
|
35864
|
-
|
|
35888
|
+
log(`[corsair:setup] Issued integration DEK: ${pluginId}`);
|
|
35865
35889
|
}
|
|
35866
35890
|
if (!integration) continue;
|
|
35867
35891
|
let account = await db.selectFrom("corsair_accounts").selectAll().where("tenant_id", "=", TENANT_ID).where("integration_id", "=", integration.id).executeTakeFirst();
|
|
@@ -35876,33 +35900,34 @@ async function ensurePluginRows(db, instance, plugins) {
|
|
|
35876
35900
|
updated_at: now
|
|
35877
35901
|
}).execute();
|
|
35878
35902
|
account = await db.selectFrom("corsair_accounts").selectAll().where("id", "=", id).executeTakeFirst();
|
|
35879
|
-
|
|
35903
|
+
log(`[corsair:setup] Created account: ${pluginId}`);
|
|
35880
35904
|
}
|
|
35881
35905
|
const accountKeyMgr = pluginNamespaces[pluginId]?.keys;
|
|
35882
35906
|
if (account && !account.dek && accountKeyMgr) {
|
|
35883
35907
|
await accountKeyMgr.issue_new_dek();
|
|
35884
|
-
|
|
35908
|
+
log(`[corsair:setup] Issued account DEK: ${pluginId}`);
|
|
35885
35909
|
}
|
|
35886
35910
|
if (integrationKeyMgr && accountKeyMgr) {
|
|
35887
35911
|
const isReady = await checkAuthStatus(
|
|
35888
35912
|
pluginId,
|
|
35889
35913
|
authType,
|
|
35890
35914
|
integrationKeyMgr,
|
|
35891
|
-
accountKeyMgr
|
|
35915
|
+
accountKeyMgr,
|
|
35916
|
+
log
|
|
35892
35917
|
);
|
|
35893
35918
|
if (isReady) authReadyPlugins.add(pluginId);
|
|
35894
35919
|
}
|
|
35895
35920
|
}
|
|
35896
35921
|
return authReadyPlugins;
|
|
35897
35922
|
}
|
|
35898
|
-
async function runBackfill(instance, plugins, authReadyPlugins) {
|
|
35923
|
+
async function runBackfill(instance, plugins, authReadyPlugins, log, warn) {
|
|
35899
35924
|
const config = backfill_default;
|
|
35900
35925
|
const activePluginIds = new Set(plugins.map((p) => p.id));
|
|
35901
35926
|
const instanceRecord = instance;
|
|
35902
35927
|
for (const [pluginId, groups] of Object.entries(config)) {
|
|
35903
35928
|
if (!activePluginIds.has(pluginId)) continue;
|
|
35904
35929
|
if (!authReadyPlugins.has(pluginId)) {
|
|
35905
|
-
|
|
35930
|
+
log(
|
|
35906
35931
|
`[corsair:setup] Skipping backfill for '${pluginId}' \u2014 auth not configured.`
|
|
35907
35932
|
);
|
|
35908
35933
|
continue;
|
|
@@ -35911,15 +35936,14 @@ async function runBackfill(instance, plugins, authReadyPlugins) {
|
|
|
35911
35936
|
if (!api) continue;
|
|
35912
35937
|
for (const [group, methods] of Object.entries(groups)) {
|
|
35913
35938
|
for (const [method, params] of Object.entries(methods)) {
|
|
35914
|
-
|
|
35939
|
+
log(
|
|
35915
35940
|
`[corsair:setup] Backfilling ${pluginId} \u203A ${group}.${method}...`
|
|
35916
35941
|
);
|
|
35917
35942
|
try {
|
|
35918
35943
|
await api[group]?.[method]?.(params);
|
|
35919
35944
|
} catch (error) {
|
|
35920
|
-
|
|
35921
|
-
`[corsair:setup] ${pluginId} \u203A ${group}.${method} failed
|
|
35922
|
-
error instanceof Error ? error.message : error
|
|
35945
|
+
warn(
|
|
35946
|
+
`[corsair:setup] ${pluginId} \u203A ${group}.${method} failed: ` + (error instanceof Error ? error.message : String(error))
|
|
35923
35947
|
);
|
|
35924
35948
|
}
|
|
35925
35949
|
}
|
package/dist/setup/index.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export interface SetupCorsairOptions {
|
|
|
23
23
|
* `setup/backfill.yaml` for each plugin that has auth configured.
|
|
24
24
|
*
|
|
25
25
|
* Only single-tenant corsair instances are accepted.
|
|
26
|
+
*
|
|
27
|
+
* Returns a newline-separated string of all setup output (credential instructions, etc.).
|
|
28
|
+
* Use this when invoking from MCP tools so the agent receives the instructions.
|
|
26
29
|
*/
|
|
27
|
-
export declare function setupCorsair<const Plugins extends readonly CorsairPlugin[]>(corsair: CorsairSingleTenantClient<Plugins>, options?: SetupCorsairOptions): Promise<
|
|
30
|
+
export declare function setupCorsair<const Plugins extends readonly CorsairPlugin[]>(corsair: CorsairSingleTenantClient<Plugins>, options?: SetupCorsairOptions): Promise<string>;
|
|
28
31
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../setup/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEX,aAAa,EACb,yBAAyB,EACzB,MAAM,SAAS,CAAC;AAqBjB,MAAM,WAAW,mBAAmB;IACnC;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../setup/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEX,aAAa,EACb,yBAAyB,EACzB,MAAM,SAAS,CAAC;AAqBjB,MAAM,WAAW,mBAAmB;IACnC;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAUD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,YAAY,CACjC,KAAK,CAAC,OAAO,SAAS,SAAS,aAAa,EAAE,EAE9C,OAAO,EAAE,yBAAyB,CAAC,OAAO,CAAC,EAC3C,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,CA6DjB"}
|