corsair 0.1.27 → 0.1.28
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 +62 -7
- package/dist/setup/index.d.ts +3 -2
- package/dist/setup/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30614,10 +30614,10 @@ async function setupCorsair(corsair, options) {
|
|
|
30614
30614
|
kek: internal.kek
|
|
30615
30615
|
});
|
|
30616
30616
|
await checkTables(db);
|
|
30617
|
-
await ensurePluginRows(db, instance, internal.plugins);
|
|
30617
|
+
const authReadyPlugins = await ensurePluginRows(db, instance, internal.plugins);
|
|
30618
30618
|
if (options?.backfill) {
|
|
30619
30619
|
console.log("[corsair:setup] Starting backfill...");
|
|
30620
|
-
await runBackfill(instance, internal.plugins);
|
|
30620
|
+
await runBackfill(instance, internal.plugins, authReadyPlugins);
|
|
30621
30621
|
console.log("[corsair:setup] Backfill complete.");
|
|
30622
30622
|
}
|
|
30623
30623
|
}
|
|
@@ -30639,13 +30639,57 @@ async function checkTables(db) {
|
|
|
30639
30639
|
}
|
|
30640
30640
|
}
|
|
30641
30641
|
}
|
|
30642
|
+
var OPTIONAL_FIELDS = /* @__PURE__ */ new Set([
|
|
30643
|
+
"webhook_signature",
|
|
30644
|
+
"expires_at",
|
|
30645
|
+
"scope",
|
|
30646
|
+
"redirect_url"
|
|
30647
|
+
]);
|
|
30648
|
+
async function checkAuthStatus(pluginId, authType, integrationKeyMgr, accountKeyMgr) {
|
|
30649
|
+
const missingIntegration = [];
|
|
30650
|
+
const missingAccount = [];
|
|
30651
|
+
for (const key of Object.keys(integrationKeyMgr)) {
|
|
30652
|
+
if (!key.startsWith("set_")) continue;
|
|
30653
|
+
const field = key.slice(4);
|
|
30654
|
+
if (OPTIONAL_FIELDS.has(field)) continue;
|
|
30655
|
+
const getter = integrationKeyMgr[`get_${field}`];
|
|
30656
|
+
if (!getter) continue;
|
|
30657
|
+
const value = await getter();
|
|
30658
|
+
if (!value) missingIntegration.push(field);
|
|
30659
|
+
}
|
|
30660
|
+
for (const key of Object.keys(accountKeyMgr)) {
|
|
30661
|
+
if (!key.startsWith("set_")) continue;
|
|
30662
|
+
const field = key.slice(4);
|
|
30663
|
+
if (OPTIONAL_FIELDS.has(field)) continue;
|
|
30664
|
+
const getter = accountKeyMgr[`get_${field}`];
|
|
30665
|
+
if (!getter) continue;
|
|
30666
|
+
const value = await getter();
|
|
30667
|
+
if (!value) missingAccount.push(field);
|
|
30668
|
+
}
|
|
30669
|
+
const isReady = missingIntegration.length === 0 && missingAccount.length === 0;
|
|
30670
|
+
if (!isReady) {
|
|
30671
|
+
const lines = [
|
|
30672
|
+
`[corsair:setup] '${pluginId}' (${authType}) needs credentials. Call:`
|
|
30673
|
+
];
|
|
30674
|
+
for (const field of missingIntegration) {
|
|
30675
|
+
lines.push(` corsair.keys.${pluginId}.set_${field}(value)`);
|
|
30676
|
+
}
|
|
30677
|
+
for (const field of missingAccount) {
|
|
30678
|
+
lines.push(` corsair.${pluginId}.keys.set_${field}(value)`);
|
|
30679
|
+
}
|
|
30680
|
+
console.log(lines.join("\n"));
|
|
30681
|
+
}
|
|
30682
|
+
return isReady;
|
|
30683
|
+
}
|
|
30642
30684
|
var TENANT_ID = "default";
|
|
30643
30685
|
async function ensurePluginRows(db, instance, plugins) {
|
|
30644
30686
|
const now = /* @__PURE__ */ new Date();
|
|
30687
|
+
const authReadyPlugins = /* @__PURE__ */ new Set();
|
|
30645
30688
|
const integrationKeys = instance.keys;
|
|
30646
30689
|
const pluginNamespaces = instance;
|
|
30647
30690
|
for (const plugin of plugins) {
|
|
30648
30691
|
const pluginId = plugin.id;
|
|
30692
|
+
const authType = plugin.options?.authType ?? "unknown";
|
|
30649
30693
|
let integration = await db.selectFrom("corsair_integrations").selectAll().where("name", "=", pluginId).executeTakeFirst();
|
|
30650
30694
|
if (!integration) {
|
|
30651
30695
|
const id = crypto.randomUUID();
|
|
@@ -30653,8 +30697,9 @@ async function ensurePluginRows(db, instance, plugins) {
|
|
|
30653
30697
|
integration = await db.selectFrom("corsair_integrations").selectAll().where("id", "=", id).executeTakeFirst();
|
|
30654
30698
|
console.log(`[corsair:setup] Created integration: ${pluginId}`);
|
|
30655
30699
|
}
|
|
30656
|
-
|
|
30657
|
-
|
|
30700
|
+
const integrationKeyMgr = integrationKeys[pluginId];
|
|
30701
|
+
if (integration && !integration.dek && integrationKeyMgr) {
|
|
30702
|
+
await integrationKeyMgr.issue_new_dek();
|
|
30658
30703
|
console.log(`[corsair:setup] Issued integration DEK: ${pluginId}`);
|
|
30659
30704
|
}
|
|
30660
30705
|
if (!integration) continue;
|
|
@@ -30672,18 +30717,28 @@ async function ensurePluginRows(db, instance, plugins) {
|
|
|
30672
30717
|
account = await db.selectFrom("corsair_accounts").selectAll().where("id", "=", id).executeTakeFirst();
|
|
30673
30718
|
console.log(`[corsair:setup] Created account: ${pluginId}`);
|
|
30674
30719
|
}
|
|
30675
|
-
|
|
30676
|
-
|
|
30720
|
+
const accountKeyMgr = pluginNamespaces[pluginId]?.keys;
|
|
30721
|
+
if (account && !account.dek && accountKeyMgr) {
|
|
30722
|
+
await accountKeyMgr.issue_new_dek();
|
|
30677
30723
|
console.log(`[corsair:setup] Issued account DEK: ${pluginId}`);
|
|
30678
30724
|
}
|
|
30725
|
+
if (integrationKeyMgr && accountKeyMgr) {
|
|
30726
|
+
const isReady = await checkAuthStatus(pluginId, authType, integrationKeyMgr, accountKeyMgr);
|
|
30727
|
+
if (isReady) authReadyPlugins.add(pluginId);
|
|
30728
|
+
}
|
|
30679
30729
|
}
|
|
30730
|
+
return authReadyPlugins;
|
|
30680
30731
|
}
|
|
30681
|
-
async function runBackfill(instance, plugins) {
|
|
30732
|
+
async function runBackfill(instance, plugins, authReadyPlugins) {
|
|
30682
30733
|
const config = backfill_default;
|
|
30683
30734
|
const activePluginIds = new Set(plugins.map((p) => p.id));
|
|
30684
30735
|
const instanceRecord = instance;
|
|
30685
30736
|
for (const [pluginId, groups] of Object.entries(config)) {
|
|
30686
30737
|
if (!activePluginIds.has(pluginId)) continue;
|
|
30738
|
+
if (!authReadyPlugins.has(pluginId)) {
|
|
30739
|
+
console.log(`[corsair:setup] Skipping backfill for '${pluginId}' \u2014 auth not configured.`);
|
|
30740
|
+
continue;
|
|
30741
|
+
}
|
|
30687
30742
|
const api = instanceRecord[pluginId]?.api;
|
|
30688
30743
|
if (!api) continue;
|
|
30689
30744
|
for (const [group, methods] of Object.entries(groups)) {
|
package/dist/setup/index.d.ts
CHANGED
|
@@ -18,8 +18,9 @@ export interface SetupCorsairOptions {
|
|
|
18
18
|
* 2. Ensures every configured plugin has rows in `corsair_integrations` and
|
|
19
19
|
* `corsair_accounts` (tenant_id = 'default').
|
|
20
20
|
* 3. Issues DEKs for any plugin that does not yet have one at either level.
|
|
21
|
-
* 4.
|
|
22
|
-
*
|
|
21
|
+
* 4. Checks auth status for each plugin and logs guidance for any missing credentials.
|
|
22
|
+
* 5. If `{ backfill: true }`, calls the list endpoints defined in
|
|
23
|
+
* `setup/backfill.yaml` for each plugin that has auth configured.
|
|
23
24
|
*
|
|
24
25
|
* Only single-tenant corsair instances are accepted.
|
|
25
26
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../setup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../setup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,aAAa,EAClB,KAAK,yBAAyB,EAC9B,MAAM,SAAS,CAAC;AAiBjB,MAAM,WAAW,mBAAmB;IACnC;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,aAAa,EAAE,EAChF,OAAO,EAAE,yBAAyB,CAAC,OAAO,CAAC,EAC3C,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA6Cf"}
|