corsair 0.1.14 → 0.1.16
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/client/index.d.ts +10 -2
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +13 -1
- package/dist/core/constants.d.ts +2 -2
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +1 -0
- package/dist/core/endpoints/bind.d.ts +17 -2
- package/dist/core/endpoints/bind.d.ts.map +1 -1
- package/dist/core/endpoints/bind.js +32 -2
- package/dist/core/endpoints/index.d.ts +28 -0
- package/dist/core/endpoints/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +8 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -0
- package/dist/core/inspect/index.d.ts +57 -0
- package/dist/core/inspect/index.d.ts.map +1 -0
- package/dist/core/inspect/index.js +150 -0
- package/dist/core/permissions/index.d.ts +29 -0
- package/dist/core/permissions/index.d.ts.map +1 -0
- package/dist/core/permissions/index.js +87 -0
- package/dist/core/plugins/index.d.ts +136 -1
- package/dist/core/plugins/index.d.ts.map +1 -1
- package/dist/core/webhooks/bind.d.ts.map +1 -1
- package/dist/core/webhooks/bind.js +6 -1
- package/dist/db/index.d.ts +65 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +28 -0
- package/dist/db/kysely/database.d.ts +2 -1
- package/dist/db/kysely/database.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/plugins/discord/index.d.ts +1 -1
- package/dist/plugins/discord/index.d.ts.map +1 -1
- package/dist/plugins/discord/index.js +30 -0
- package/dist/plugins/discord/schema/database.d.ts +2 -2
- package/dist/plugins/discord/schema/index.d.ts +2 -2
- package/dist/plugins/github/endpoints/index.d.ts +8 -8
- package/dist/plugins/github/endpoints/types.d.ts +8276 -36
- package/dist/plugins/github/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/github/endpoints/types.js +26 -0
- package/dist/plugins/github/index.d.ts +17 -1
- package/dist/plugins/github/index.d.ts.map +1 -1
- package/dist/plugins/github/index.js +82 -0
- package/dist/plugins/github/schema/database.d.ts +2 -2
- package/dist/plugins/github/schema/index.d.ts +2 -2
- package/dist/plugins/gmail/client.d.ts +7 -2
- package/dist/plugins/gmail/client.d.ts.map +1 -1
- package/dist/plugins/gmail/client.js +11 -21
- package/dist/plugins/gmail/endpoints/types.d.ts +1702 -0
- package/dist/plugins/gmail/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/gmail/endpoints/types.js +31 -0
- package/dist/plugins/gmail/index.d.ts +1 -0
- package/dist/plugins/gmail/index.d.ts.map +1 -1
- package/dist/plugins/gmail/index.js +107 -6
- package/dist/plugins/googlecalendar/client.d.ts +7 -2
- package/dist/plugins/googlecalendar/client.d.ts.map +1 -1
- package/dist/plugins/googlecalendar/client.js +11 -21
- package/dist/plugins/googlecalendar/endpoints/types.d.ts +2316 -2
- package/dist/plugins/googlecalendar/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/googlecalendar/endpoints/types.js +11 -0
- package/dist/plugins/googlecalendar/index.d.ts +1 -0
- package/dist/plugins/googlecalendar/index.d.ts.map +1 -1
- package/dist/plugins/googlecalendar/index.js +35 -6
- package/dist/plugins/googlecalendar/schema/database.d.ts +4 -4
- package/dist/plugins/googlecalendar/schema/index.d.ts +4 -4
- package/dist/plugins/googledrive/client.d.ts +7 -2
- package/dist/plugins/googledrive/client.d.ts.map +1 -1
- package/dist/plugins/googledrive/client.js +11 -21
- package/dist/plugins/googledrive/endpoints/index.d.ts +1 -1
- package/dist/plugins/googledrive/endpoints/types.d.ts +2468 -30
- package/dist/plugins/googledrive/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/googledrive/endpoints/types.js +26 -0
- package/dist/plugins/googledrive/index.d.ts +1 -0
- package/dist/plugins/googledrive/index.d.ts.map +1 -1
- package/dist/plugins/googledrive/index.js +68 -6
- package/dist/plugins/googledrive/schema/database.d.ts +8 -8
- package/dist/plugins/googledrive/schema/index.d.ts +8 -8
- package/dist/plugins/googlesheets/client.d.ts +7 -2
- package/dist/plugins/googlesheets/client.d.ts.map +1 -1
- package/dist/plugins/googlesheets/client.js +11 -21
- package/dist/plugins/googlesheets/endpoints/types.d.ts +588 -0
- package/dist/plugins/googlesheets/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/googlesheets/endpoints/types.js +15 -0
- package/dist/plugins/googlesheets/index.d.ts +1 -0
- package/dist/plugins/googlesheets/index.d.ts.map +1 -1
- package/dist/plugins/googlesheets/index.js +53 -6
- package/dist/plugins/hubspot/endpoints/index.d.ts +8 -8
- package/dist/plugins/hubspot/endpoints/types.d.ts +7307 -16
- package/dist/plugins/hubspot/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/hubspot/endpoints/types.js +39 -0
- package/dist/plugins/hubspot/index.d.ts +1 -0
- package/dist/plugins/hubspot/index.d.ts.map +1 -1
- package/dist/plugins/hubspot/index.js +88 -0
- package/dist/plugins/hubspot/schema/database.d.ts +8 -8
- package/dist/plugins/hubspot/schema/index.d.ts +8 -8
- package/dist/plugins/linear/api.test.js +55 -0
- package/dist/plugins/linear/endpoints/index.d.ts +99 -62
- package/dist/plugins/linear/endpoints/index.d.ts.map +1 -1
- package/dist/plugins/linear/endpoints/index.js +5 -0
- package/dist/plugins/linear/endpoints/types.d.ts +2529 -411
- package/dist/plugins/linear/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/linear/endpoints/types.js +44 -0
- package/dist/plugins/linear/endpoints/users.d.ts +4 -0
- package/dist/plugins/linear/endpoints/users.d.ts.map +1 -0
- package/dist/plugins/linear/endpoints/users.js +81 -0
- package/dist/plugins/linear/index.d.ts +14 -1
- package/dist/plugins/linear/index.d.ts.map +1 -1
- package/dist/plugins/linear/index.js +69 -1
- package/dist/plugins/linear/schema/database.d.ts +12 -12
- package/dist/plugins/linear/schema/database.js +2 -2
- package/dist/plugins/linear/schema/index.d.ts +12 -12
- package/dist/plugins/posthog/endpoints/index.d.ts +3 -3
- package/dist/plugins/posthog/endpoints/types.d.ts +145 -6
- package/dist/plugins/posthog/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/posthog/endpoints/types.js +10 -0
- package/dist/plugins/posthog/index.d.ts +1 -0
- package/dist/plugins/posthog/index.d.ts.map +1 -1
- package/dist/plugins/posthog/index.js +21 -0
- package/dist/plugins/posthog/schema/database.d.ts +2 -2
- package/dist/plugins/posthog/schema/index.d.ts +2 -2
- package/dist/plugins/resend/endpoints/types.d.ts +318 -0
- package/dist/plugins/resend/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/resend/endpoints/types.js +13 -0
- package/dist/plugins/resend/index.d.ts +1 -0
- package/dist/plugins/resend/index.d.ts.map +1 -1
- package/dist/plugins/resend/index.js +28 -0
- package/dist/plugins/slack/endpoints/types.d.ts +17323 -0
- package/dist/plugins/slack/endpoints/types.d.ts.map +1 -1
- package/dist/plugins/slack/endpoints/types.js +47 -0
- package/dist/plugins/slack/index.d.ts +8 -1
- package/dist/plugins/slack/index.d.ts.map +1 -1
- package/dist/plugins/slack/index.js +148 -0
- package/dist/plugins/spotify/api.test.d.ts +2 -0
- package/dist/plugins/spotify/api.test.d.ts.map +1 -0
- package/dist/plugins/spotify/api.test.js +200 -0
- package/dist/plugins/spotify/client.d.ts +17 -0
- package/dist/plugins/spotify/client.d.ts.map +1 -0
- package/dist/plugins/spotify/client.js +112 -0
- package/dist/plugins/spotify/endpoints/albums.d.ts +6 -0
- package/dist/plugins/spotify/endpoints/albums.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/albums.js +63 -0
- package/dist/plugins/spotify/endpoints/artists.d.ts +7 -0
- package/dist/plugins/spotify/endpoints/artists.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/artists.js +53 -0
- package/dist/plugins/spotify/endpoints/index.d.ts +958 -0
- package/dist/plugins/spotify/endpoints/index.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/index.js +52 -0
- package/dist/plugins/spotify/endpoints/library.d.ts +3 -0
- package/dist/plugins/spotify/endpoints/library.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/library.js +11 -0
- package/dist/plugins/spotify/endpoints/my-data.d.ts +3 -0
- package/dist/plugins/spotify/endpoints/my-data.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/my-data.js +19 -0
- package/dist/plugins/spotify/endpoints/player.d.ts +11 -0
- package/dist/plugins/spotify/endpoints/player.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/player.js +124 -0
- package/dist/plugins/spotify/endpoints/playlists.d.ts +9 -0
- package/dist/plugins/spotify/endpoints/playlists.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/playlists.js +90 -0
- package/dist/plugins/spotify/endpoints/tracks.d.ts +5 -0
- package/dist/plugins/spotify/endpoints/tracks.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/tracks.js +37 -0
- package/dist/plugins/spotify/endpoints/types.d.ts +12433 -0
- package/dist/plugins/spotify/endpoints/types.d.ts.map +1 -0
- package/dist/plugins/spotify/endpoints/types.js +572 -0
- package/dist/plugins/spotify/error-handlers.d.ts +77 -0
- package/dist/plugins/spotify/error-handlers.d.ts.map +1 -0
- package/dist/plugins/spotify/error-handlers.js +124 -0
- package/dist/plugins/spotify/index.d.ts +132 -0
- package/dist/plugins/spotify/index.d.ts.map +1 -0
- package/dist/plugins/spotify/index.js +159 -0
- package/dist/plugins/spotify/integration.test.d.ts +2 -0
- package/dist/plugins/spotify/integration.test.d.ts.map +1 -0
- package/dist/plugins/spotify/integration.test.js +448 -0
- package/dist/plugins/spotify/schema/database.d.ts +640 -0
- package/dist/plugins/spotify/schema/database.d.ts.map +1 -0
- package/dist/plugins/spotify/schema/database.js +201 -0
- package/dist/plugins/spotify/schema/index.d.ts +638 -0
- package/dist/plugins/spotify/schema/index.d.ts.map +1 -0
- package/dist/plugins/spotify/schema/index.js +12 -0
- package/dist/plugins/spotify/webhooks/example.d.ts +3 -0
- package/dist/plugins/spotify/webhooks/example.d.ts.map +1 -0
- package/dist/plugins/spotify/webhooks/example.js +31 -0
- package/dist/plugins/spotify/webhooks/index.d.ts +8 -0
- package/dist/plugins/spotify/webhooks/index.d.ts.map +1 -0
- package/dist/plugins/spotify/webhooks/index.js +5 -0
- package/dist/plugins/spotify/webhooks/types.d.ts +103 -0
- package/dist/plugins/spotify/webhooks/types.d.ts.map +1 -0
- package/dist/plugins/spotify/webhooks/types.js +82 -0
- package/dist/plugins/tavily/endpoints/index.d.ts +2 -2
- package/dist/plugins/tavily/endpoints/types.d.ts +4 -4
- package/dist/plugins/tavily/index.d.ts +2 -2
- package/dist/plugins/tavily/index.d.ts.map +1 -1
- package/dist/plugins/tavily/index.js +8 -0
- package/dist/templates/plugin/generate.js +55 -1
- package/dist/tsup.config.d.ts.map +1 -1
- package/dist/tsup.config.js +9 -1
- package/package.json +6 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ZodTypeAny } from 'zod';
|
|
2
2
|
import type { CorsairDatabase } from '../../db/kysely/database';
|
|
3
|
+
import { type CorsairInspectMethods } from '../inspect';
|
|
3
4
|
import type { CorsairPluginSchema, PluginEntityClients } from '../../db/orm';
|
|
4
5
|
import type { AccountKeyManagerFor, IntegrationKeyManagerFor, PluginAuthConfig } from '../auth/types';
|
|
5
6
|
import type { AuthTypes } from '../constants';
|
|
@@ -86,11 +87,13 @@ type InferAllIntegrationKeys<Plugins extends readonly CorsairPlugin[]> = UnionTo
|
|
|
86
87
|
type InferPluginNamespaces<Plugins extends readonly CorsairPlugin[]> = UnionToIntersection<InferPluginNamespace<Plugins[number]>>;
|
|
87
88
|
/**
|
|
88
89
|
* The main Corsair client type that provides access to all plugin APIs, entities, webhooks, and keys.
|
|
90
|
+
* Also includes get_methods() and get_schema() for agent-facing endpoint discovery.
|
|
89
91
|
*/
|
|
90
|
-
export type CorsairClient<Plugins extends readonly CorsairPlugin[]> = InferPluginNamespaces<Plugins
|
|
92
|
+
export type CorsairClient<Plugins extends readonly CorsairPlugin[]> = InferPluginNamespaces<Plugins> & CorsairInspectMethods;
|
|
91
93
|
/**
|
|
92
94
|
* Multi-tenant wrapper that provides a `withTenant` method to scope operations to a specific tenant.
|
|
93
95
|
* Also includes integration-level `keys` for managing shared secrets (OAuth2 client credentials, etc.)
|
|
96
|
+
* Inspect methods (get_methods / get_schema) are available at the root — no need to call withTenant().
|
|
94
97
|
*/
|
|
95
98
|
export type CorsairTenantWrapper<Plugins extends readonly CorsairPlugin[]> = {
|
|
96
99
|
withTenant: (tenantId: string) => CorsairClient<Plugins>;
|
|
@@ -99,7 +102,7 @@ export type CorsairTenantWrapper<Plugins extends readonly CorsairPlugin[]> = {
|
|
|
99
102
|
* Used to manage secrets shared across all tenants (e.g., OAuth2 client_id, client_secret).
|
|
100
103
|
*/
|
|
101
104
|
keys: InferAllIntegrationKeys<Plugins>;
|
|
102
|
-
};
|
|
105
|
+
} & CorsairInspectMethods;
|
|
103
106
|
/**
|
|
104
107
|
* Single-tenant client that includes both plugin APIs and integration-level keys.
|
|
105
108
|
*/
|
|
@@ -115,6 +118,11 @@ export type BuildCorsairClientOptions = {
|
|
|
115
118
|
tenantId: string | undefined;
|
|
116
119
|
kek: string | undefined;
|
|
117
120
|
rootErrorHandlers?: CorsairErrorHandler;
|
|
121
|
+
/** Approval timeout from createCorsair({ approval: ... }). Forwarded to the permission guard. */
|
|
122
|
+
approvalConfig?: {
|
|
123
|
+
timeout: string;
|
|
124
|
+
onTimeout: 'deny' | 'approve';
|
|
125
|
+
};
|
|
118
126
|
};
|
|
119
127
|
/**
|
|
120
128
|
* Builds a Corsair client instance with all plugin APIs, entities, webhooks, and account-level keys bound.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,O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G,SAAS,CAAA;KAAE,CAAC;CACpE,CAAC;AAMF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,CAAC,OAAO,SAAS,SAAS,aAAa,EAAE,EAE9C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,yBAAyB,GAChC,aAAa,CAAC,OAAO,CAAC,CAyKxB;AAMD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,CAAC,OAAO,SAAS,SAAS,aAAa,EAAE,EAE9C,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,MAAM,GACT,uBAAuB,CAAC,OAAO,CAAC,CAyBlC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createKyselyEntityClient } from '../../db/kysely/orm';
|
|
2
|
+
import { buildInspectMethods, } from '../inspect';
|
|
2
3
|
import { createAccountKeyManager, createIntegrationKeyManager, } from '../auth/key-manager';
|
|
3
4
|
import { bindEndpointsRecursively } from '../endpoints/bind';
|
|
4
5
|
import { bindWebhooksRecursively } from '../webhooks/bind';
|
|
@@ -78,7 +79,7 @@ function createEntityClient(database, getAccountId, entityTypeName, version, dat
|
|
|
78
79
|
* @returns A fully configured Corsair client with account-level keys
|
|
79
80
|
*/
|
|
80
81
|
export function buildCorsairClient(plugins, options) {
|
|
81
|
-
const { database, tenantId, kek, rootErrorHandlers } = options;
|
|
82
|
+
const { database, tenantId, kek, rootErrorHandlers, approvalConfig, } = options;
|
|
82
83
|
const apiUnsafe = {};
|
|
83
84
|
const pluginEntitiesUnsafe = {};
|
|
84
85
|
for (const plugin of plugins) {
|
|
@@ -141,6 +142,10 @@ export function buildCorsairClient(plugins, options) {
|
|
|
141
142
|
};
|
|
142
143
|
// Create bound endpoints under `api` (supports nested structures)
|
|
143
144
|
const boundTree = {};
|
|
145
|
+
// Extract permission config from plugin options.
|
|
146
|
+
// options is Record<string, unknown> — permissions is not in the base CorsairPlugin type
|
|
147
|
+
// because it's plugin-specific (typed via PluginPermissionsConfig<T> in each plugin).
|
|
148
|
+
const pluginPermsConfig = plugin.options?.permissions;
|
|
144
149
|
bindEndpointsRecursively({
|
|
145
150
|
endpoints,
|
|
146
151
|
hooks,
|
|
@@ -150,6 +155,11 @@ export function buildCorsairClient(plugins, options) {
|
|
|
150
155
|
errorHandlers: allErrorHandlers,
|
|
151
156
|
currentPath: [],
|
|
152
157
|
keyBuilder: plugin.keyBuilder,
|
|
158
|
+
permissionsConfig: pluginPermsConfig,
|
|
159
|
+
// endpointMeta is typed with plugin-specific literal keys — cast to runtime Record
|
|
160
|
+
endpointMeta: plugin.endpointMeta,
|
|
161
|
+
database,
|
|
162
|
+
approvalConfig,
|
|
153
163
|
});
|
|
154
164
|
if (Object.keys(boundTree).length > 0) {
|
|
155
165
|
apiUnsafe[plugin.id].api = boundTree;
|
|
@@ -177,8 +187,10 @@ export function buildCorsairClient(plugins, options) {
|
|
|
177
187
|
}
|
|
178
188
|
}
|
|
179
189
|
const api = apiUnsafe;
|
|
190
|
+
const inspect = buildInspectMethods(plugins);
|
|
180
191
|
return {
|
|
181
192
|
...api,
|
|
193
|
+
...inspect,
|
|
182
194
|
};
|
|
183
195
|
}
|
|
184
196
|
// ─────────────────────────────────────────────────────────────────────────────
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type AllErrors = 'RATE_LIMIT_ERROR' | 'AUTH_ERROR' | 'PERMISSION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'SERVER_ERROR' | 'VALIDATION_ERROR' | 'NOT_FOUND_ERROR' | 'BAD_REQUEST_ERROR' | 'PARSING_ERROR' | 'DEFAULT' | (string & {});
|
|
2
|
-
export declare const BaseProviders: readonly ["discord", "github", "gmail", "googlecalendar", "googledrive", "googlesheets", "hubspot", "linear", "posthog", "resend", "slack", "tavily"];
|
|
3
|
-
export type AllProviders = 'discord' | 'github' | 'gmail' | 'googlecalendar' | 'googledrive' | 'googlesheets' | 'hubspot' | 'linear' | 'posthog' | 'resend' | 'slack' | 'tavily' | (string & {});
|
|
2
|
+
export declare const BaseProviders: readonly ["discord", "github", "gmail", "googlecalendar", "googledrive", "googlesheets", "hubspot", "linear", "posthog", "resend", "slack", "spotify", "tavily"];
|
|
3
|
+
export type AllProviders = 'discord' | 'github' | 'gmail' | 'googlecalendar' | 'googledrive' | 'googlesheets' | 'hubspot' | 'linear' | 'posthog' | 'resend' | 'slack' | 'spotify' | 'tavily' | (string & {});
|
|
4
4
|
export type AuthTypes = 'oauth_2' | 'api_key' | 'bot_token';
|
|
5
5
|
export type PickAuth<T extends AuthTypes> = T;
|
|
6
6
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../core/constants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAClB,kBAAkB,GAClB,YAAY,GACZ,kBAAkB,GAClB,eAAe,GACf,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,GACf,SAAS,GACT,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAEjB,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../core/constants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAClB,kBAAkB,GAClB,YAAY,GACZ,kBAAkB,GAClB,eAAe,GACf,eAAe,GACf,cAAc,GACd,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,GACf,SAAS,GACT,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAEjB,eAAO,MAAM,aAAa,kKAchB,CAAC;AAEX,MAAM,MAAM,YAAY,GACrB,SAAS,GACT,QAAQ,GACR,OAAO,GACP,gBAAgB,GAChB,aAAa,GACb,cAAc,GACd,SAAS,GACT,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,GACP,SAAS,GACT,QAAQ,GACR,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAEjB,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAE5D,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,CAAC"}
|
package/dist/core/constants.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { CorsairDatabase } from '../../db/kysely/database';
|
|
1
2
|
import type { CorsairErrorHandler } from '../errors';
|
|
2
|
-
import type { CorsairKeyBuilderBase } from '../plugins';
|
|
3
|
+
import type { CorsairKeyBuilderBase, EndpointMetaEntry, PermissionMode, PermissionPolicy } from '../plugins';
|
|
3
4
|
/**
|
|
4
5
|
* Checks if a value is an endpoint/function (has function signature).
|
|
5
6
|
* @param value - The value to check
|
|
@@ -18,7 +19,7 @@ export declare function isEndpoint(value: unknown): value is Function;
|
|
|
18
19
|
* @param currentPath - The current path for tracking nested endpoint operations
|
|
19
20
|
* @param keyBuilder - Optional async callback to generate a key from the plugin context
|
|
20
21
|
*/
|
|
21
|
-
export declare function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId, errorHandlers, currentPath, keyBuilder, }: {
|
|
22
|
+
export declare function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId, errorHandlers, currentPath, keyBuilder, permissionsConfig, endpointMeta, database, approvalConfig, }: {
|
|
22
23
|
endpoints: Record<string, unknown>;
|
|
23
24
|
hooks: Record<string, unknown> | undefined;
|
|
24
25
|
ctx: Record<string, unknown>;
|
|
@@ -27,5 +28,19 @@ export declare function bindEndpointsRecursively({ endpoints, hooks, ctx, tree,
|
|
|
27
28
|
errorHandlers: CorsairErrorHandler;
|
|
28
29
|
currentPath: string[];
|
|
29
30
|
keyBuilder?: CorsairKeyBuilderBase;
|
|
31
|
+
/** Permission mode + per-endpoint overrides from plugin options. When set, every call is gated. */
|
|
32
|
+
permissionsConfig?: {
|
|
33
|
+
mode: PermissionMode;
|
|
34
|
+
overrides?: Record<string, PermissionPolicy>;
|
|
35
|
+
};
|
|
36
|
+
/** Risk level metadata per dot-notation endpoint path. Defaults riskLevel to 'write' when missing. */
|
|
37
|
+
endpointMeta?: Record<string, EndpointMetaEntry>;
|
|
38
|
+
/** Required for 'require_approval' to persist the approval record to the DB. */
|
|
39
|
+
database?: CorsairDatabase;
|
|
40
|
+
/** Approval timeout config from createCorsair({ approval: ... }). */
|
|
41
|
+
approvalConfig?: {
|
|
42
|
+
timeout: string;
|
|
43
|
+
onTimeout: 'deny' | 'approve';
|
|
44
|
+
};
|
|
30
45
|
}): void;
|
|
31
46
|
//# sourceMappingURL=bind.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../../core/endpoints/bind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../../core/endpoints/bind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,KAAK,EACX,qBAAqB,EAErB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,MAAM,YAAY,CAAC;AAMpB;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,EACxC,SAAS,EACT,KAAK,EACL,GAAG,EACH,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,WAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,cAAc,GACd,EAAE;IACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC3C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,mBAAmB,CAAC;IACnC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,mGAAmG;IACnG,iBAAiB,CAAC,EAAE;QACnB,IAAI,EAAE,cAAc,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;KAC7C,CAAC;IACF,sGAAsG;IACtG,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACjD,gFAAgF;IAChF,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,qEAAqE;IACrE,cAAc,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;CACpE,GAAG,IAAI,CAwJP"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { handleCorsairError } from '../errors/handler';
|
|
2
|
+
import { enforcePermission, parseDurationMs } from '../permissions';
|
|
2
3
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
4
|
// Endpoint Utilities
|
|
4
5
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -22,7 +23,7 @@ export function isEndpoint(value) {
|
|
|
22
23
|
* @param currentPath - The current path for tracking nested endpoint operations
|
|
23
24
|
* @param keyBuilder - Optional async callback to generate a key from the plugin context
|
|
24
25
|
*/
|
|
25
|
-
export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId, errorHandlers, currentPath = [], keyBuilder, }) {
|
|
26
|
+
export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId, errorHandlers, currentPath = [], keyBuilder, permissionsConfig, endpointMeta, database, approvalConfig, }) {
|
|
26
27
|
for (const [key, value] of Object.entries(endpoints)) {
|
|
27
28
|
// we have to retype this now because it's nested webhooks
|
|
28
29
|
const nodeHooks = hooks?.[key];
|
|
@@ -31,6 +32,26 @@ export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId
|
|
|
31
32
|
const endpointHooks = nodeHooks;
|
|
32
33
|
const operationPath = [...currentPath, key].join('.');
|
|
33
34
|
const boundFn = async (args) => {
|
|
35
|
+
// ── Permission guard ────────────────────────────────────────────────────────────────
|
|
36
|
+
if (permissionsConfig) {
|
|
37
|
+
const meta = endpointMeta?.[operationPath];
|
|
38
|
+
const permResult = await enforcePermission({
|
|
39
|
+
pluginId,
|
|
40
|
+
endpointPath: operationPath,
|
|
41
|
+
args,
|
|
42
|
+
mode: permissionsConfig.mode,
|
|
43
|
+
override: permissionsConfig.overrides?.[operationPath],
|
|
44
|
+
// Default to 'write' when no meta declared — conservative fallback
|
|
45
|
+
riskLevel: meta?.riskLevel ?? 'write',
|
|
46
|
+
meta,
|
|
47
|
+
db: database,
|
|
48
|
+
timeoutMs: approvalConfig
|
|
49
|
+
? parseDurationMs(approvalConfig.timeout)
|
|
50
|
+
: undefined,
|
|
51
|
+
});
|
|
52
|
+
if (permResult === 'blocked')
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
34
55
|
const call = async (attemptNumber, callCtx, callArgs) => {
|
|
35
56
|
try {
|
|
36
57
|
return await value(callCtx, callArgs);
|
|
@@ -90,7 +111,12 @@ export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId
|
|
|
90
111
|
const ctxWithKey = { ...ctx, key };
|
|
91
112
|
const beforeResult = endpointHooks.before
|
|
92
113
|
? await endpointHooks.before(ctxWithKey, args)
|
|
93
|
-
: {
|
|
114
|
+
: {
|
|
115
|
+
ctx: ctxWithKey,
|
|
116
|
+
args,
|
|
117
|
+
continue: true,
|
|
118
|
+
passToAfter: undefined,
|
|
119
|
+
};
|
|
94
120
|
if (beforeResult.continue === false)
|
|
95
121
|
return;
|
|
96
122
|
const res = await call(0, beforeResult.ctx, beforeResult.args);
|
|
@@ -112,6 +138,10 @@ export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId
|
|
|
112
138
|
errorHandlers,
|
|
113
139
|
currentPath: [...currentPath, key],
|
|
114
140
|
keyBuilder,
|
|
141
|
+
permissionsConfig,
|
|
142
|
+
endpointMeta,
|
|
143
|
+
database,
|
|
144
|
+
approvalConfig,
|
|
115
145
|
});
|
|
116
146
|
tree[key] = nestedTree;
|
|
117
147
|
}
|
|
@@ -72,5 +72,33 @@ export type EndpointTree = {
|
|
|
72
72
|
export type BindEndpoints<T extends EndpointTree> = {
|
|
73
73
|
[K in keyof T]: T[K] extends CorsairEndpoint<any, infer A, infer R> ? (args: A) => Promise<R> : T[K] extends EndpointTree ? BindEndpoints<T[K]> : never;
|
|
74
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Derives all dot-notation endpoint paths from an EndpointTree as a string literal union.
|
|
77
|
+
* Used to provide compile-time validation for permission overrides and endpoint metadata keys.
|
|
78
|
+
* Passing an invalid path to any config that accepts EndpointPathsOf<T> is a type error.
|
|
79
|
+
*
|
|
80
|
+
* Design note: The constraint on `T` is intentionally loosened to `object` (not `EndpointTree`)
|
|
81
|
+
* on the recursive call because `as const` endpoint trees have specific readonly literal keys —
|
|
82
|
+
* `{ readonly issues: { readonly list: fn } }` — which do NOT satisfy `EndpointTree`'s string
|
|
83
|
+
* index signature (`{ [key: string]: ... }`), even though the values are valid endpoints.
|
|
84
|
+
* If we recurse with `T extends EndpointTree`, TypeScript widens the subtypes and loses the
|
|
85
|
+
* literal keys we need. The outer-facing `PluginEndpointMeta<T extends EndpointTree>` and
|
|
86
|
+
* `PluginPermissionsConfig<T extends EndpointTree>` still enforce the EndpointTree constraint
|
|
87
|
+
* at the call site.
|
|
88
|
+
*
|
|
89
|
+
* Similarly, `T[K] extends Record<string, unknown>` fails for named-property objects without an
|
|
90
|
+
* index signature (a plain `{ list: fn }` does not satisfy `{ [key: string]: unknown }`), so we
|
|
91
|
+
* use `extends object` instead, which all non-primitive values satisfy.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* Given: `{ issues: { list: Endpoint, create: Endpoint }, repos: { list: Endpoint } }`
|
|
95
|
+
* Result: `'issues.list' | 'issues.create' | 'repos.list'`
|
|
96
|
+
*
|
|
97
|
+
* @template T - The endpoint tree to extract paths from (unconstrained to allow recursion through as-const types)
|
|
98
|
+
* @template Prefix - Internal accumulator for the current path prefix (do not supply manually)
|
|
99
|
+
*/
|
|
100
|
+
export type EndpointPathsOf<T, Prefix extends string = ''> = {
|
|
101
|
+
[K in keyof T & string]: T[K] extends (...args: any[]) => any ? Prefix extends '' ? K : `${Prefix}.${K}` : T[K] extends object ? EndpointPathsOf<T[K], Prefix extends '' ? K : `${Prefix}.${K}`> : never;
|
|
102
|
+
}[keyof T & string];
|
|
75
103
|
export {};
|
|
76
104
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/endpoints/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAMhE;;;;GAIG;AACH,KAAK,SAAS,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,CAAC,IAAI;IAC3C,cAAc,CAAC,GAAG,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC;CACjC,CAAC,gBAAgB,CAAC,CAAC;AAMpB;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,IAAI,GAAG,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,CAC5D,IAAI,EAAE,IAAI,KACN,OAAO,CAAC,GAAG,CAAC,CAAC;AAElB;;;GAGG;AACH,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C,EAAE,MAAM,CAAC,CAAC,GAChE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GACvB,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,GACxB,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACnB,KAAK;CACT,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI;KAC3D,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAE3D,MAAM,SAAS,EAAE,GACf,CAAC,GACD,GAAG,MAAM,IAAI,CAAC,EAAE,GACjB,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAEnB,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,SAAS,EAAE,GAAG,CAAC,GAAG,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,GAC9D,KAAK;CACT,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export type CorsairInternalConfig = {
|
|
|
7
7
|
database: CorsairDatabase | undefined;
|
|
8
8
|
kek: string;
|
|
9
9
|
multiTenancy: boolean;
|
|
10
|
+
approval?: {
|
|
11
|
+
timeout: string;
|
|
12
|
+
onTimeout: 'deny' | 'approve';
|
|
13
|
+
};
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
16
|
* Creates a Corsair integration with multi-tenancy enabled.
|
|
@@ -30,10 +34,12 @@ export declare function createCorsair<const Plugins extends readonly CorsairPlug
|
|
|
30
34
|
export type { AccountFieldNames, AccountKeyManagerFor, BaseAuthFieldConfig, BaseKeyManager, IntegrationFieldNames, IntegrationKeyManagerFor, OAuth2IntegrationCredentials, PluginAuthConfig, } from './auth';
|
|
31
35
|
export { BASE_AUTH_FIELDS, createAccountKeyManager, createIntegrationKeyManager, decryptConfig, decryptDEK, decryptWithDEK, encryptConfig, encryptDEK, encryptWithDEK, generateDEK, initializeAccountDEK, initializeIntegrationDEK, reEncryptConfig, } from './auth';
|
|
32
36
|
export type { CorsairClient, CorsairSingleTenantClient, CorsairTenantWrapper, } from './client';
|
|
37
|
+
export type { CorsairInspectMethods, EndpointSchemaResult } from './inspect';
|
|
33
38
|
export type { AllProviders, AuthTypes, BaseProviders } from './constants';
|
|
34
|
-
export type { BindEndpoints, BoundEndpointFn, BoundEndpointTree, CorsairContext, CorsairEndpoint, EndpointTree, } from './endpoints';
|
|
39
|
+
export type { BindEndpoints, BoundEndpointFn, BoundEndpointTree, CorsairContext, CorsairEndpoint, EndpointPathsOf, EndpointTree, } from './endpoints';
|
|
35
40
|
export type { CorsairErrorHandler, ErrorContext, ErrorHandler, ErrorHandlerAndMatchFunction, ErrorMatcher, RetryStrategies, RetryStrategy, } from './errors';
|
|
36
|
-
export type {
|
|
41
|
+
export type { EnforcePermissionOptions } from './permissions';
|
|
42
|
+
export type { BeforeHookResult, CorsairIntegration, CorsairKeyBuilder, CorsairKeyBuilderBase, CorsairPlugin, CorsairPluginContext, EndpointHooks, EndpointMetaEntry, EndpointRiskLevel, KeyBuilderContext, PermissionMode, PermissionPolicy, PluginEndpointMeta, PluginPermissionsConfig, WebhookHooks, } from './plugins';
|
|
37
43
|
export type { Bivariant, UnionToIntersection } from './utils';
|
|
38
44
|
export type { BindWebhooks, BoundWebhook, BoundWebhookTree, CorsairWebhook, CorsairWebhookHandler, CorsairWebhookMatcher, RawWebhookRequest, WebhookRequest, WebhookResponse, WebhookTree, } from './webhooks';
|
|
39
45
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../core/index.ts"],"names":[],"mappings":"A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Ae,EACf,WAAW,GACX,MAAM,YAAY,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createCorsairDatabase } from '../db/kysely/database';
|
|
2
2
|
import { createMissingConfigProxy } from './auth/errors';
|
|
3
3
|
import { buildCorsairClient, buildIntegrationKeys } from './client';
|
|
4
|
+
import { buildInspectMethods } from './inspect';
|
|
4
5
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
6
|
// Internal access for CLI tooling
|
|
6
7
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -23,6 +24,7 @@ export function createCorsair(config) {
|
|
|
23
24
|
database: resolvedDatabase,
|
|
24
25
|
kek: config.kek,
|
|
25
26
|
multiTenancy: !!config.multiTenancy,
|
|
27
|
+
approval: config.approval,
|
|
26
28
|
};
|
|
27
29
|
if (config.multiTenancy) {
|
|
28
30
|
return Object.assign({
|
|
@@ -35,9 +37,11 @@ export function createCorsair(config) {
|
|
|
35
37
|
tenantId,
|
|
36
38
|
kek: config.kek,
|
|
37
39
|
rootErrorHandlers: config.errorHandlers,
|
|
40
|
+
approvalConfig: config.approval,
|
|
38
41
|
});
|
|
39
42
|
},
|
|
40
43
|
keys: integrationKeys,
|
|
44
|
+
...buildInspectMethods(config.plugins),
|
|
41
45
|
}, { [CORSAIR_INTERNAL]: internalConfig });
|
|
42
46
|
}
|
|
43
47
|
const client = buildCorsairClient(config.plugins, {
|
|
@@ -45,6 +49,7 @@ export function createCorsair(config) {
|
|
|
45
49
|
tenantId: undefined,
|
|
46
50
|
kek: config.kek,
|
|
47
51
|
rootErrorHandlers: config.errorHandlers,
|
|
52
|
+
approvalConfig: config.approval,
|
|
48
53
|
});
|
|
49
54
|
return Object.assign({}, client, {
|
|
50
55
|
keys: integrationKeys,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CorsairPlugin } from '../plugins';
|
|
2
|
+
export type EndpointSchemaResult = {
|
|
3
|
+
/** Human-readable description of what this endpoint does. */
|
|
4
|
+
description?: string;
|
|
5
|
+
/** Risk classification: 'read' | 'write' | 'destructive' */
|
|
6
|
+
riskLevel?: 'read' | 'write' | 'destructive';
|
|
7
|
+
/** Whether this action cannot be undone. */
|
|
8
|
+
irreversible?: boolean;
|
|
9
|
+
/** JSON Schema representation of the input arguments object. */
|
|
10
|
+
input?: unknown;
|
|
11
|
+
/** JSON Schema representation of the response object. */
|
|
12
|
+
output?: unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Present when the requested method was not found.
|
|
15
|
+
* Lists all available full-form paths so the caller can pick a valid one.
|
|
16
|
+
*/
|
|
17
|
+
availableMethods?: Record<string, string[]>;
|
|
18
|
+
};
|
|
19
|
+
export type CorsairInspectMethods = {
|
|
20
|
+
/**
|
|
21
|
+
* Returns all available endpoint paths for every registered plugin.
|
|
22
|
+
* Keys are plugin IDs, values are arrays of full-form paths (plugin.group.method).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* corsair.get_methods()
|
|
26
|
+
* // { slack: ['slack.channels.list', 'slack.messages.post', ...], github: ['github.issues.list', ...] }
|
|
27
|
+
*/
|
|
28
|
+
get_methods(): Record<string, string[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns all available endpoint paths for a specific plugin.
|
|
31
|
+
* Paths are full-form (plugin.group.method) so they can be passed directly to get_schema().
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* corsair.get_methods('slack')
|
|
35
|
+
* // ['slack.channels.list', 'slack.channels.get', 'slack.messages.post', ...]
|
|
36
|
+
*/
|
|
37
|
+
get_methods(plugin: string): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Returns schema and metadata for a specific endpoint.
|
|
40
|
+
* Pass the full dot-path including the plugin ID: 'slack.channels.list'.
|
|
41
|
+
* If the method is not found, returns an empty result with `availableMethods` listing all valid paths.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* corsair.get_schema('slack.channels.list')
|
|
45
|
+
* // { description: '...', riskLevel: 'read', input: { type: 'object', ... }, output: { ... } }
|
|
46
|
+
*
|
|
47
|
+
* corsair.get_schema('slack.invalid')
|
|
48
|
+
* // { availableMethods: { slack: ['slack.channels.list', ...], ... } }
|
|
49
|
+
*/
|
|
50
|
+
get_schema(method: string): EndpointSchemaResult;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Creates the get_methods / get_schema functions bound to a specific plugin list.
|
|
54
|
+
* Used by both single-tenant and multi-tenant client builders.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildInspectMethods(plugins: readonly CorsairPlugin[]): CorsairInspectMethods;
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/inspect/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,YAAY,CAAC;AAqFnE,MAAM,MAAM,oBAAoB,GAAG;IAClC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;IAC7C,4CAA4C;IAC5C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gEAAgE;IAChE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,yDAAyD;IACzD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IACnC;;;;;;;OAOG;IACH,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC;;;;;;;OAOG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtC;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC;CACjD,CAAC;AAmFF;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,SAAS,aAAa,EAAE,GAC/B,qBAAqB,CASvB"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// Zod → JSON Schema Converter
|
|
3
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Zod schema to a plain JSON Schema-compatible object.
|
|
6
|
+
* Used to produce human-readable type information for get_schema().
|
|
7
|
+
*/
|
|
8
|
+
function zodToJsonSchema(schema) {
|
|
9
|
+
// Access Zod internals via a generic cast — avoids importing internal Zod types
|
|
10
|
+
const def = schema._def;
|
|
11
|
+
const typeName = def.typeName;
|
|
12
|
+
switch (typeName) {
|
|
13
|
+
case 'ZodString':
|
|
14
|
+
return { type: 'string' };
|
|
15
|
+
case 'ZodNumber':
|
|
16
|
+
return { type: 'number' };
|
|
17
|
+
case 'ZodBoolean':
|
|
18
|
+
return { type: 'boolean' };
|
|
19
|
+
case 'ZodNull':
|
|
20
|
+
return { type: 'null' };
|
|
21
|
+
case 'ZodUnknown':
|
|
22
|
+
case 'ZodAny':
|
|
23
|
+
return {};
|
|
24
|
+
case 'ZodLiteral':
|
|
25
|
+
return { const: def.value };
|
|
26
|
+
case 'ZodEnum':
|
|
27
|
+
return { enum: def.values };
|
|
28
|
+
case 'ZodOptional':
|
|
29
|
+
// Optional is reflected in the parent object's required[] array, not here
|
|
30
|
+
return zodToJsonSchema(def.innerType);
|
|
31
|
+
case 'ZodNullable': {
|
|
32
|
+
const inner = zodToJsonSchema(def.innerType);
|
|
33
|
+
return { anyOf: [inner, { type: 'null' }] };
|
|
34
|
+
}
|
|
35
|
+
case 'ZodArray':
|
|
36
|
+
return { type: 'array', items: zodToJsonSchema(def.type) };
|
|
37
|
+
case 'ZodRecord':
|
|
38
|
+
return {
|
|
39
|
+
type: 'object',
|
|
40
|
+
additionalProperties: zodToJsonSchema(def.valueType),
|
|
41
|
+
};
|
|
42
|
+
case 'ZodObject': {
|
|
43
|
+
const shape = def.shape();
|
|
44
|
+
const properties = {};
|
|
45
|
+
const required = [];
|
|
46
|
+
for (const [key, val] of Object.entries(shape)) {
|
|
47
|
+
properties[key] = zodToJsonSchema(val);
|
|
48
|
+
const fieldTypeName = val._def.typeName;
|
|
49
|
+
if (fieldTypeName !== 'ZodOptional' && fieldTypeName !== 'ZodNullable') {
|
|
50
|
+
required.push(key);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const result = { type: 'object', properties };
|
|
54
|
+
if (required.length > 0)
|
|
55
|
+
result.required = required;
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
case 'ZodUnion':
|
|
59
|
+
return { anyOf: def.options.map(zodToJsonSchema) };
|
|
60
|
+
case 'ZodIntersection':
|
|
61
|
+
return {
|
|
62
|
+
allOf: [
|
|
63
|
+
zodToJsonSchema(def.left),
|
|
64
|
+
zodToJsonSchema(def.right),
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
case 'ZodEffects':
|
|
68
|
+
// .refine(), .transform(), etc. — unwrap to the inner schema
|
|
69
|
+
return zodToJsonSchema(def.schema);
|
|
70
|
+
default:
|
|
71
|
+
return { type: (typeName ?? 'unknown').replace('Zod', '').toLowerCase() };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
75
|
+
// Endpoint Tree Walker
|
|
76
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
77
|
+
function walkEndpointTree(tree, pathParts, result) {
|
|
78
|
+
for (const [key, value] of Object.entries(tree)) {
|
|
79
|
+
const current = [...pathParts, key];
|
|
80
|
+
if (typeof value === 'function') {
|
|
81
|
+
result.push(current.join('.'));
|
|
82
|
+
}
|
|
83
|
+
else if (value !== null && typeof value === 'object') {
|
|
84
|
+
walkEndpointTree(value, current, result);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
89
|
+
// Core Functions
|
|
90
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
91
|
+
function getMethods(plugins, plugin) {
|
|
92
|
+
if (plugin !== undefined) {
|
|
93
|
+
const found = plugins.find((p) => p.id === plugin);
|
|
94
|
+
if (!found?.endpoints)
|
|
95
|
+
return [];
|
|
96
|
+
const paths = [];
|
|
97
|
+
walkEndpointTree(found.endpoints, [], paths);
|
|
98
|
+
return paths.map((path) => `${found.id}.${path}`);
|
|
99
|
+
}
|
|
100
|
+
const result = {};
|
|
101
|
+
for (const p of plugins) {
|
|
102
|
+
if (!p.endpoints)
|
|
103
|
+
continue;
|
|
104
|
+
const paths = [];
|
|
105
|
+
walkEndpointTree(p.endpoints, [], paths);
|
|
106
|
+
result[p.id] = paths.map((path) => `${p.id}.${path}`);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
function getSchema(plugins, method) {
|
|
111
|
+
const dotIndex = method.indexOf('.');
|
|
112
|
+
if (dotIndex !== -1) {
|
|
113
|
+
const pluginId = method.slice(0, dotIndex);
|
|
114
|
+
const endpointPath = method.slice(dotIndex + 1);
|
|
115
|
+
const plugin = plugins.find((p) => p.id === pluginId);
|
|
116
|
+
if (plugin) {
|
|
117
|
+
const meta = plugin.endpointMeta?.[endpointPath];
|
|
118
|
+
const schemas = plugin.endpointSchemas?.[endpointPath];
|
|
119
|
+
// Valid entry — meta or schemas found
|
|
120
|
+
if (meta || schemas) {
|
|
121
|
+
return {
|
|
122
|
+
description: meta?.description,
|
|
123
|
+
riskLevel: meta?.riskLevel,
|
|
124
|
+
irreversible: meta?.irreversible,
|
|
125
|
+
input: schemas?.input ? zodToJsonSchema(schemas.input) : undefined,
|
|
126
|
+
output: schemas?.output ? zodToJsonSchema(schemas.output) : undefined,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Invalid or unknown method — return all available methods so the caller can self-correct
|
|
132
|
+
return { availableMethods: getMethods(plugins) };
|
|
133
|
+
}
|
|
134
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
135
|
+
// Factory — binds inspect methods to a fixed plugin list
|
|
136
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
137
|
+
/**
|
|
138
|
+
* Creates the get_methods / get_schema functions bound to a specific plugin list.
|
|
139
|
+
* Used by both single-tenant and multi-tenant client builders.
|
|
140
|
+
*/
|
|
141
|
+
export function buildInspectMethods(plugins) {
|
|
142
|
+
return {
|
|
143
|
+
get_methods(plugin) {
|
|
144
|
+
return getMethods(plugins, plugin);
|
|
145
|
+
},
|
|
146
|
+
get_schema(method) {
|
|
147
|
+
return getSchema(plugins, method);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CorsairDatabase } from '../../db/kysely/database';
|
|
2
|
+
import type { EndpointMetaEntry, EndpointRiskLevel, PermissionMode, PermissionPolicy } from '../plugins';
|
|
3
|
+
/** Resolves the effective permission policy for an endpoint. The override (from permissions.overrides) takes precedence. */
|
|
4
|
+
export declare function evaluatePermission(riskLevel: EndpointRiskLevel, mode: PermissionMode, override?: PermissionPolicy): PermissionPolicy;
|
|
5
|
+
/** Parses a duration string ('30s', '10m', '1h', '2h30m', '1d') into milliseconds. */
|
|
6
|
+
export declare function parseDurationMs(duration: string): number;
|
|
7
|
+
export type EnforcePermissionOptions = {
|
|
8
|
+
pluginId: string;
|
|
9
|
+
endpointPath: string;
|
|
10
|
+
/** unknown: caller-supplied args vary per endpoint — not statically knowable here */
|
|
11
|
+
args: unknown;
|
|
12
|
+
mode: PermissionMode;
|
|
13
|
+
override?: PermissionPolicy;
|
|
14
|
+
riskLevel: EndpointRiskLevel;
|
|
15
|
+
meta?: EndpointMetaEntry;
|
|
16
|
+
/** Required to create an approval record. Without a DB, 'require_approval' falls back to deny. */
|
|
17
|
+
db?: CorsairDatabase;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Evaluates the permission policy and returns whether the action is allowed.
|
|
22
|
+
*
|
|
23
|
+
* - `'allow'` → returns 'allow', caller proceeds normally
|
|
24
|
+
* - `'deny'` → logs a blocked message, returns 'blocked'
|
|
25
|
+
* - `'require_approval'` → creates a `corsair_permissions` record, logs the token, returns 'blocked'
|
|
26
|
+
* (falls back to deny if no database is configured)
|
|
27
|
+
*/
|
|
28
|
+
export declare function enforcePermission(opts: EnforcePermissionOptions): Promise<'allow' | 'blocked'>;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/permissions/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EACX,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,MAAM,YAAY,CAAC;AAgBpB,4HAA4H;AAC5H,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,iBAAiB,EAC5B,IAAI,EAAE,cAAc,EACpB,QAAQ,CAAC,EAAE,gBAAgB,GACzB,gBAAgB,CAGlB;AAMD,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAsBxD;AAMD,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,cAAc,CAAC;IACrB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,kGAAkG;IAClG,EAAE,CAAC,EAAE,eAAe,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACtC,IAAI,EAAE,wBAAwB,GAC5B,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAkD9B"}
|