corsair 0.1.67 → 0.1.68
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/chunk-AUAZUOIF.js +5 -0
- package/dist/index.js +1 -1
- package/dist/setup.d.ts +11 -18
- package/dist/setup.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-CDFPFO6N.js +0 -5
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{i as w,j as C,k as S,u as A,v as T}from"./chunk-GN4ET25A.js";import{a as _}from"./chunk-7IH5DNUL.js";import{Kysely as I}from"kysely";import{ZodBoolean as M,ZodDate as R,ZodEffects as j,ZodEnum as D,ZodNullable as E,ZodNumber as F,ZodObject as O,ZodOptional as x,ZodRecord as K,ZodString as B,ZodType as v}from"zod";var h={slack:{channels:{list:{}},users:{list:{}}},linear:{projects:{list:{}},issues:{list:{}},users:{list:{}}},github:{issues:{list:{}},repositories:{list:{}}},discord:{guilds:{list:{}},channels:{list:{}}},hubspot:{contacts:{getMany:{}},companies:{getMany:{}},deals:{getMany:{}}},gmail:{messages:{list:{}},labels:{list:{}},drafts:{list:{}},threads:{list:{}}},googlecalendar:{events:{getMany:{}}},googledrive:{files:{list:{}},folders:{list:{}},sharedDrives:{list:{}}},notion:{databases:{getManyDatabases:{}},databasePages:{getManyDatabasePages:{}},users:{getManyUsers:{}}},airtable:{bases:{getMany:{}}},todoist:{projects:{getMany:{}},tasks:{getMany:{}}},cal:{bookings:{list:{}}}};async function se(e,t){let r=[],i=s=>{r.push(s),console.log(s)},o=s=>{r.push(s),console.warn(s)},f=t?.caller??"script",d=t?.tenantId;if(!d){if(e?.withTenant)throw new Error("setupCorsair: tenantId must be a non-empty string");d="default"}let n=Z(e);if(!n)throw new Error("setupCorsair: invalid corsair instance");if(!n.database)throw new Error("setupCorsair: a database must be configured on the corsair instance");let u={...n,database:n.database},c=u.database.db;await H(c,o);let p=await J(c,u,d,i),y=await Q(p,d,i,f);if(t?.backfill){i("[corsair:setup] Starting backfill...");let s=T({plugins:n.plugins,database:c,kek:n.kek,multiTenancy:!0}).withTenant(d);await V(s,n.plugins,y,i,o),i("[corsair:setup] Backfill complete.")}return r.join(`
|
|
2
|
+
`)}function b(e){return typeof e=="object"&&e!==null}function N(e){return!b(e)||!Array.isArray(e.plugins)||typeof e.kek!="string"||typeof e.multiTenancy!="boolean"?!1:e.database===void 0?!0:b(e.database)?e.database.db instanceof I:!1}function Z(e){let t=Object.getOwnPropertyDescriptor(e,A);if(t)return N(t.value)?t.value:void 0}function L(e){return e==="oauth_2"||e==="api_key"||e==="bot_token"}function U(e){let t=e.options?.authType;return L(t)?t:void 0}function m(e,t){if(!b(e))return;let r=e[t];return typeof r=="function"?(...i)=>Reflect.apply(r,e,i):void 0}function $(e,t){return b(e)?t===0?!0:Object.values(e).every(r=>$(r,t-1)):!1}function W(e){return $(e,4)}var Y={..._};function k(e){if(e instanceof O){let t={};for(let[r,i]of Object.entries(e.shape))t[r]=i instanceof v?k(i):"unknown";return t}return e instanceof j?k(e.innerType()):e instanceof E?`${k(e.unwrap())} | null`:e instanceof x?`${k(e.unwrap())} | undefined`:e instanceof D?e.options.join(" | "):e instanceof B?"string":e instanceof F?"number":e instanceof M?"boolean":e instanceof R?"date":e instanceof K?"jsonb":"unknown"}async function H(e,t){let r=await e.introspection.getTables(),i=new Set(r.map(o=>o.name));for(let[o,f]of Object.entries(Y))i.has(o)||t(`[corsair:setup] Table "${o}" does not exist. Run your database migrations before calling setupCorsair.
|
|
3
|
+
Schema: ${JSON.stringify(k(f),null,2)}`)}async function J(e,t,r,i){let o=new Date,f=new Map;for(let d of t.plugins){let n=d.id,u=U(d),c=await e.selectFrom("corsair_integrations").selectAll().where("name","=",n).executeTakeFirst();if(!c){let l=crypto.randomUUID();await e.insertInto("corsair_integrations").values({id:l,name:n,config:{},created_at:o,updated_at:o}).execute(),c=await e.selectFrom("corsair_integrations").selectAll().where("id","=",l).executeTakeFirst(),i(`[corsair:setup] Created integration: ${n}`)}let p=u?d.authConfig?.[u]?.integration??[]:[],y=u?d.authConfig?.[u]?.account??[]:[],s=u&&c?C({authType:u,integrationName:n,kek:t.kek,database:t.database,extraIntegrationFields:p}):void 0;if(c&&!c.dek&&s&&(await s.issue_new_dek(),i(`[corsair:setup] Issued integration DEK: ${n}`)),!c)continue;let a=await e.selectFrom("corsair_accounts").selectAll().where("tenant_id","=",r).where("integration_id","=",c.id).executeTakeFirst();if(!a){let l=crypto.randomUUID();await e.insertInto("corsair_accounts").values({id:l,tenant_id:r,integration_id:c.id,config:{},created_at:o,updated_at:o}).execute(),a=await e.selectFrom("corsair_accounts").selectAll().where("id","=",l).executeTakeFirst(),i(`[corsair:setup] Created account: ${n}`)}let g=u&&a?S({authType:u,integrationName:n,tenantId:r,kek:t.kek,database:t.database,extraAccountFields:y}):void 0;a&&!a.dek&&g&&(await g.issue_new_dek(),i(`[corsair:setup] Issued account DEK: ${n}`)),u&&s&&g&&f.set(n,{pluginId:n,authType:u,integration:s,account:g,integrationFields:[...w[u].integration,...p],accountFields:[...w[u].account,...y]})}return f}var P=new Set(["webhook_signature","expires_at","scope","redirect_url"]);async function z(e,t,r,i,o,f,d,n,u){let c=[],p=[];for(let s of o){if(P.has(s))continue;let a=m(r,`get_${s}`);if(!a)continue;let g=null;try{let l=await a();g=typeof l=="string"?l:null}catch{}g||c.push(s)}for(let s of f){if(P.has(s))continue;let a=m(i,`get_${s}`);if(!a)continue;let g=null;try{let l=await a();g=typeof l=="string"?l:null}catch{}g||p.push(s)}let y=c.length===0&&p.length===0;if(y)n(`[corsair:setup] '${e}' (${t}) is configured \u2713`);else{let s=[...c,...p];if(u==="cli"){let a=s.map(g=>`${g}=VALUE`).join(" ");n(`[corsair:setup] '${e}' (${t}) needs credentials. Run:
|
|
4
|
+
corsair setup --${e} ${a}`)}else{let a=[`[corsair:setup] '${e}' (${t}) needs credentials. Call:`];for(let g of c)a.push(` await corsair.keys.${e}.set_${g}(value)`);for(let g of p){let l=d==="default"?`corsair.${e}`:`corsair.withTenant(${JSON.stringify(d)}).${e}`;a.push(` await ${l}.keys.set_${g}(value)`)}n(a.join(`
|
|
5
|
+
`))}}return y}async function Q(e,t,r,i){let o=new Set;for(let f of e.values())await z(f.pluginId,f.authType,f.integration,f.account,f.integrationFields,f.accountFields,t,r,i)&&o.add(f.pluginId);return o}async function V(e,t,r,i,o){if(!W(h)){o("[corsair:setup] Backfill config is invalid - skipping backfill.");return}let f=h,d=new Set(t.map(n=>n.id));for(let[n,u]of Object.entries(f)){if(!d.has(n))continue;if(!r.has(n)){i(`[corsair:setup] Skipping backfill for '${n}' \u2014 auth not configured.`);continue}let c=b(e)?e[n]:void 0,p=b(c)?c.api:void 0;if(p)for(let[y,s]of Object.entries(u))for(let[a,g]of Object.entries(s)){i(`[corsair:setup] Backfilling ${n} \u203A ${y}.${a}...`);try{let l=b(p)?p[y]:void 0;await m(l,a)?.(g)}catch(l){o(`[corsair:setup] ${n} \u203A ${y}.${a} failed: `+(l instanceof Error?l.message:String(l)))}}}}export{se as a};
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as I}from"./chunk-
|
|
1
|
+
import{a as I}from"./chunk-AUAZUOIF.js";import{q as m,r as k,s as b,u as y,v as W}from"./chunk-GN4ET25A.js";import"./chunk-7IH5DNUL.js";import"./chunk-2PB34FTK.js";import"./chunk-HO245J34.js";import"./chunk-ZGVIF3UY.js";import"./chunk-QAIKSQAD.js";function w(n){let r=n[y];if(!r)throw new Error("listOperations / getSchema: invalid corsair instance. Pass the value returned by createCorsair() or corsair.withTenant().");return r.plugins}function O(n,r){let o=k(w(n),r);return typeof o=="string"?o:Array.isArray(o)?o.join(`
|
|
2
2
|
`):Object.values(o).flat().join(`
|
|
3
3
|
`)}function S(n,r){return b(w(n),r)}var T=Symbol.for("corsair:internal");function B(n,r){let o=n;for(let e of r){if(!o||typeof o!="object")return null;o=o[e]}return typeof o=="function"?o:null}function x(n){return n[T]?.database}async function A(n,r){let o=new Date().toISOString(),e=await n.permissions.find_by_token(r);if(!e)return console.error("executePermission: no permission found for token."),{error:"executePermission: no permission found for token."};if(e.status!=="approved")return console.error(`executePermission: permission '${e.id}' is '${e.status}', expected 'approved'.`),{endpoint:e.endpoint,plugin:e.plugin,result:null,error:`executePermission: permission '${e.id}' is '${e.status}', expected 'approved'.`};if(e.expires_at<o){let i=x(n);return i&&await i.db.updateTable("corsair_permissions").set({status:"expired",updated_at:new Date}).where("id","=",e.id).execute(),console.error(`executePermission: permission '${e.id}' has expired.`),{error:`executePermission: permission '${e.id}' has expired.`,endpoint:e.endpoint,plugin:e.plugin,result:null}}let t=e.tenant_id??"default",g=(n.withTenant?n.withTenant(t):n)[e.plugin];if(!g?.api)return console.error(`executePermission: plugin '${e.plugin}' not found or has no API on this corsair instance.`),{error:`executePermission: plugin '${e.plugin}' not found or has no API on this corsair instance.`,plugin:e.plugin,endpoint:e.endpoint,result:null};let p=B(g.api,e.endpoint.split("."));if(!p)return console.error(`executePermission: endpoint '${e.endpoint}' not found in plugin '${e.plugin}'.`),{endpoint:e.endpoint,plugin:e.plugin,result:null,error:`executePermission: endpoint '${e.endpoint}' not found in plugin '${e.plugin}'.`};await n.permissions.set_executing(e.id);try{let i=typeof e.args=="string"?JSON.parse(e.args):e.args,u=await p(i);return await n.permissions.set_completed(e.id),{plugin:e.plugin,endpoint:e.endpoint,result:u}}catch(i){let u=i instanceof Error?i.message:String(i),d=x(n);return d&&await d.db.updateTable("corsair_permissions").set({status:"failed",error:u,updated_at:new Date}).where("id","=",e.id).execute(),{plugin:e.plugin,endpoint:e.endpoint,result:null,error:u}}}function E(n){return n!==null&&typeof n=="object"&&"match"in n&&"handler"in n&&typeof n.match=="function"&&typeof n.handler=="function"}function C(n,r,o=[]){for(let[e,t]of Object.entries(n))if(E(t)){if(t.match(r))return{webhook:t,path:[...o,e]}}else if(t&&typeof t=="object"){let s=C(t,r,[...o,e]);if(s)return s}return null}function $(n){let r={};for(let[o,e]of Object.entries(n))r[o.toLowerCase()]=Array.isArray(e)?e[0]:e;return r}function j(n){let r=n["x-goog-resource-uri"],o=n["x-goog-channel-id"];if(!r||!o)return null;let e={resourceId:n["x-goog-resource-id"]||"",resourceState:n["x-goog-resource-state"]||"",resourceUri:r,channelId:o,channelExpiration:n["x-goog-channel-expiration"]||""};return r.includes("/drive/")&&(e.kind="drive#change"),{message:{data:Buffer.from(JSON.stringify(e)).toString("base64"),messageId:n["x-goog-message-number"]||""}}}async function _(n,r,o,e){let t=$(r),s=typeof o=="string"?JSON.parse(o):o;(!s||typeof s=="object"&&Object.keys(s).length===0)&&t["x-goog-resource-uri"]&&(s=j(t)||s);let p={headers:t,body:s},i=e?.tenantId||"default",u=n.withTenant?n.withTenant(i):n,d=m;for(let l of d){let c=u[l];if(!c||!c.webhooks||c.pluginWebhookMatcher&&!c.pluginWebhookMatcher(p))continue;let f=C(c.webhooks,p);if(!f)continue;let h=f.path.join("."),R={payload:s,headers:t,rawBody:typeof o=="string"?o:JSON.stringify(o)};try{let a=await f.webhook.handler(R),P=!!Object.keys(a.returnToSender||{})?.length;return{plugin:l,action:h,body:s,response:P?{...a?.returnToSender,success:!0}:{success:!0},...a.responseHeaders&&{responseHeaders:a.responseHeaders}}}catch(a){return console.error(`Error executing webhook handler for ${l}.${h}:`,a),{plugin:l,action:h,body:s,response:{success:!1,error:a instanceof Error?a.message:"Unknown error"}}}}return{plugin:null,action:null,body:null}}export{W as createCorsair,A as executePermission,S as getSchema,O as listOperations,_ as processWebhook,I as setupCorsair};
|
package/dist/setup.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ import 'postgres';
|
|
|
8
8
|
|
|
9
9
|
interface SetupCorsairOptions {
|
|
10
10
|
/**
|
|
11
|
-
* Tenant to
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* Tenant to provision rows for. Defaults to "default".
|
|
12
|
+
* Pass a specific tenant ID to create that tenant's `corsair_accounts` rows
|
|
13
|
+
* and issue DEKs without touching other tenants.
|
|
14
14
|
*/
|
|
15
15
|
tenantId?: string;
|
|
16
16
|
/**
|
|
@@ -18,16 +18,6 @@ interface SetupCorsairOptions {
|
|
|
18
18
|
* setup/backfill.yaml to seed the local database with initial data.
|
|
19
19
|
*/
|
|
20
20
|
backfill?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Credentials to store before checking auth status.
|
|
23
|
-
* Map of pluginId → { fieldName: value }.
|
|
24
|
-
* The system automatically determines whether each field belongs to the
|
|
25
|
-
* integration level (corsair.keys.plugin) or account level (corsair.plugin.keys).
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* { github: { api_key: 'ghp_...' }, googlecalendar: { client_id: '...', client_secret: '...' } }
|
|
29
|
-
*/
|
|
30
|
-
credentials?: Record<string, Record<string, string>>;
|
|
31
21
|
/**
|
|
32
22
|
* Whether setupCorsair is being called from the CLI or from a script.
|
|
33
23
|
* Defaults to 'script'. When 'cli', missing-credential messages are printed
|
|
@@ -42,14 +32,17 @@ type SetupCorsairInstance<Plugins extends readonly CorsairPlugin[]> = CorsairSin
|
|
|
42
32
|
* 1. Checks that all required corsair_* tables exist (warns if any are missing).
|
|
43
33
|
* 2. Ensures every configured plugin has rows in `corsair_integrations` and
|
|
44
34
|
* `corsair_accounts` for the requested tenant and issues DEKs where needed.
|
|
45
|
-
* 3.
|
|
46
|
-
* 4. Checks auth status for each plugin and logs guidance for any missing credentials.
|
|
35
|
+
* 3. Checks auth status for each plugin and logs guidance for any missing credentials.
|
|
47
36
|
* When `caller` is 'cli', guidance is printed as CLI flags instead of JS calls.
|
|
48
|
-
*
|
|
37
|
+
* 4. If `{ backfill: true }`, calls the list endpoints defined in
|
|
49
38
|
* `setup/backfill.yaml` for each plugin that has auth configured.
|
|
50
39
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
40
|
+
* To set credentials, use the corsair client API directly after setup:
|
|
41
|
+
* - Integration-level (shared across all tenants): `corsair.keys.plugin.set_*(value)`
|
|
42
|
+
* - Account-level (per-tenant): `corsair.withTenant(tenantId).plugin.keys.set_*(value)`
|
|
43
|
+
*
|
|
44
|
+
* Multi-tenant corsair instances are accepted; pass `options.tenantId` to provision
|
|
45
|
+
* rows for a specific tenant instead of the default account.
|
|
53
46
|
*
|
|
54
47
|
* Returns a newline-separated string of all setup output.
|
|
55
48
|
*/
|
package/dist/setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-AUAZUOIF.js";import"./chunk-GN4ET25A.js";import"./chunk-7IH5DNUL.js";import"./chunk-2PB34FTK.js";import"./chunk-HO245J34.js";import"./chunk-ZGVIF3UY.js";import"./chunk-QAIKSQAD.js";export{o as setupCorsair};
|
package/package.json
CHANGED
package/dist/chunk-CDFPFO6N.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{i as h,j as C,k as S,u as $,v as A}from"./chunk-GN4ET25A.js";import{a as P}from"./chunk-7IH5DNUL.js";import{Kysely as T}from"kysely";import{ZodBoolean as R,ZodDate as M,ZodEffects as j,ZodEnum as v,ZodNullable as O,ZodNumber as D,ZodObject as E,ZodOptional as F,ZodRecord as x,ZodString as K,ZodType as B}from"zod";var m={slack:{channels:{list:{}},users:{list:{}}},linear:{projects:{list:{}},issues:{list:{}},users:{list:{}}},github:{issues:{list:{}},repositories:{list:{}}},discord:{guilds:{list:{}},channels:{list:{}}},hubspot:{contacts:{getMany:{}},companies:{getMany:{}},deals:{getMany:{}}},gmail:{messages:{list:{}},labels:{list:{}},drafts:{list:{}},threads:{list:{}}},googlecalendar:{events:{getMany:{}}},googledrive:{files:{list:{}},folders:{list:{}},sharedDrives:{list:{}}},notion:{databases:{getManyDatabases:{}},databasePages:{getManyDatabasePages:{}},users:{getManyUsers:{}}},airtable:{bases:{getMany:{}}},todoist:{projects:{getMany:{}},tasks:{getMany:{}}},cal:{bookings:{list:{}}}};async function se(e,t){let a=[],s=r=>{a.push(r),console.log(r)},c=r=>{a.push(r),console.warn(r)},o=t?.caller??"script",y=t?.tenantId!==void 0,n=t?.tenantId??"default";if(!n)throw new Error("setupCorsair: tenantId must be a non-empty string");let i=L(e);if(!i)throw new Error("setupCorsair: invalid corsair instance");if(!i.database)throw new Error("setupCorsair: a database must be configured on the corsair instance");let u={...i,database:i.database},f=u.database.db;await H(f,c);let p=await J(f,u,n,s);t?.credentials&&Object.keys(t.credentials).length>0&&await z(p,t.credentials,{tenantId:n,tenantIdWasProvided:y},s,c);let l=await V(p,n,s,o);if(t?.backfill){s("[corsair:setup] Starting backfill...");let r=A({plugins:i.plugins,database:f,kek:i.kek,multiTenancy:!0}).withTenant(n);await q(r,i.plugins,l,s,c),s("[corsair:setup] Backfill complete.")}return a.join(`
|
|
2
|
-
`)}function b(e){return typeof e=="object"&&e!==null}function N(e){return!b(e)||!Array.isArray(e.plugins)||typeof e.kek!="string"||typeof e.multiTenancy!="boolean"?!1:e.database===void 0?!0:b(e.database)?e.database.db instanceof T:!1}function L(e){let t=Object.getOwnPropertyDescriptor(e,$);if(t)return N(t.value)?t.value:void 0}function Z(e){return e==="oauth_2"||e==="api_key"||e==="bot_token"}function W(e){let t=e.options?.authType;return Z(t)?t:void 0}function k(e,t){if(!b(e))return;let a=e[t];return typeof a=="function"?(...s)=>Reflect.apply(a,e,s):void 0}function _(e,t){return b(e)?t===0?!0:Object.values(e).every(a=>_(a,t-1)):!1}function U(e){return _(e,4)}var Y={...P};function w(e){if(e instanceof E){let t={};for(let[a,s]of Object.entries(e.shape))t[a]=s instanceof B?w(s):"unknown";return t}return e instanceof j?w(e.innerType()):e instanceof O?`${w(e.unwrap())} | null`:e instanceof F?`${w(e.unwrap())} | undefined`:e instanceof v?e.options.join(" | "):e instanceof K?"string":e instanceof D?"number":e instanceof R?"boolean":e instanceof M?"date":e instanceof x?"jsonb":"unknown"}async function H(e,t){let a=await e.introspection.getTables(),s=new Set(a.map(c=>c.name));for(let[c,o]of Object.entries(Y))s.has(c)||t(`[corsair:setup] Table "${c}" does not exist. Run your database migrations before calling setupCorsair.
|
|
3
|
-
Schema: ${JSON.stringify(w(o),null,2)}`)}async function J(e,t,a,s){let c=new Date,o=new Map;for(let y of t.plugins){let n=y.id,i=W(y),u=await e.selectFrom("corsair_integrations").selectAll().where("name","=",n).executeTakeFirst();if(!u){let d=crypto.randomUUID();await e.insertInto("corsair_integrations").values({id:d,name:n,config:{},created_at:c,updated_at:c}).execute(),u=await e.selectFrom("corsair_integrations").selectAll().where("id","=",d).executeTakeFirst(),s(`[corsair:setup] Created integration: ${n}`)}let f=i?y.authConfig?.[i]?.integration??[]:[],p=i?y.authConfig?.[i]?.account??[]:[],l=i&&u?C({authType:i,integrationName:n,kek:t.kek,database:t.database,extraIntegrationFields:f}):void 0;if(u&&!u.dek&&l&&(await l.issue_new_dek(),s(`[corsair:setup] Issued integration DEK: ${n}`)),!u)continue;let r=await e.selectFrom("corsair_accounts").selectAll().where("tenant_id","=",a).where("integration_id","=",u.id).executeTakeFirst();if(!r){let d=crypto.randomUUID();await e.insertInto("corsair_accounts").values({id:d,tenant_id:a,integration_id:u.id,config:{},created_at:c,updated_at:c}).execute(),r=await e.selectFrom("corsair_accounts").selectAll().where("id","=",d).executeTakeFirst(),s(`[corsair:setup] Created account: ${n}`)}let g=i&&r?S({authType:i,integrationName:n,tenantId:a,kek:t.kek,database:t.database,extraAccountFields:p}):void 0;r&&!r.dek&&g&&(await g.issue_new_dek(),s(`[corsair:setup] Issued account DEK: ${n}`)),i&&l&&g&&o.set(n,{pluginId:n,authType:i,integration:l,account:g,integrationFields:[...h[i].integration,...f],accountFields:[...h[i].account,...p]})}return o}async function z(e,t,a,s,c){for(let[o,y]of Object.entries(t)){let n=e.get(o);for(let[i,u]of Object.entries(y)){let f=`set_${i}`,p=k(n?.integration,f),l=k(n?.account,f);if(p){if(a.tenantIdWasProvided)throw new Error(`[corsair:setup] '${o}.${i}' is an integration-level credential shared across all tenants. You passed tenantId="${a.tenantId}", which only scopes account-level credentials. Run setup without tenantId if you intend to change this credential globally.`);await p(u),s(`[corsair:setup] Set integration credential: ${o}.${i}`)}else l?(await l(u),s(`[corsair:setup] Set account credential: ${o}.${i}`)):c(`[corsair:setup] No setter found for '${o}.${i}' - skipping.`)}}}var I=new Set(["webhook_signature","expires_at","scope","redirect_url"]);async function Q(e,t,a,s,c,o,y,n,i){let u=[],f=[];for(let l of c){if(I.has(l))continue;let r=k(a,`get_${l}`);if(!r)continue;let g=null;try{let d=await r();g=typeof d=="string"?d:null}catch{}g||u.push(l)}for(let l of o){if(I.has(l))continue;let r=k(s,`get_${l}`);if(!r)continue;let g=null;try{let d=await r();g=typeof d=="string"?d:null}catch{}g||f.push(l)}let p=u.length===0&&f.length===0;if(p)n(`[corsair:setup] '${e}' (${t}) is configured \u2713`);else{let l=[...u,...f];if(i==="cli"){let r=l.map(g=>`${g}=VALUE`).join(" ");n(`[corsair:setup] '${e}' (${t}) needs credentials. Run:
|
|
4
|
-
corsair setup --${e} ${r}`)}else{let r=[`[corsair:setup] '${e}' (${t}) needs credentials. Call:`];for(let g of u)r.push(` await corsair.keys.${e}.set_${g}(value)`);for(let g of f){let d=y==="default"?`corsair.${e}`:`corsair.withTenant(${JSON.stringify(y)}).${e}`;r.push(` await ${d}.keys.set_${g}(value)`)}n(r.join(`
|
|
5
|
-
`))}}return p}async function V(e,t,a,s){let c=new Set;for(let o of e.values())await Q(o.pluginId,o.authType,o.integration,o.account,o.integrationFields,o.accountFields,t,a,s)&&c.add(o.pluginId);return c}async function q(e,t,a,s,c){if(!U(m)){c("[corsair:setup] Backfill config is invalid - skipping backfill.");return}let o=m,y=new Set(t.map(n=>n.id));for(let[n,i]of Object.entries(o)){if(!y.has(n))continue;if(!a.has(n)){s(`[corsair:setup] Skipping backfill for '${n}' \u2014 auth not configured.`);continue}let u=b(e)?e[n]:void 0,f=b(u)?u.api:void 0;if(f)for(let[p,l]of Object.entries(i))for(let[r,g]of Object.entries(l)){s(`[corsair:setup] Backfilling ${n} \u203A ${p}.${r}...`);try{let d=b(f)?f[p]:void 0;await k(d,r)?.(g)}catch(d){c(`[corsair:setup] ${n} \u203A ${p}.${r} failed: `+(d instanceof Error?d.message:String(d)))}}}}export{se as a};
|