corsair 0.1.21 → 0.1.23

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.
@@ -6,6 +6,7 @@ import type { AuthTypes } from '../constants';
6
6
  import type { BindEndpoints, EndpointTree } from '../endpoints';
7
7
  import type { CorsairErrorHandler } from '../errors';
8
8
  import type { CorsairInspectMethods } from '../inspect';
9
+ import type { CorsairPermissionsNamespace } from '../permissions';
9
10
  import type { CorsairPlugin } from '../plugins';
10
11
  import type { BindWebhooks, RawWebhookRequest, WebhookTree } from '../webhooks';
11
12
  /**
@@ -102,6 +103,11 @@ export type CorsairTenantWrapper<Plugins extends readonly CorsairPlugin[]> = {
102
103
  * Used to manage secrets shared across all tenants (e.g., OAuth2 client_id, client_secret).
103
104
  */
104
105
  keys: InferAllIntegrationKeys<Plugins>;
106
+ /**
107
+ * Permission management namespace. Use this to query and transition permission records.
108
+ * Available at the root regardless of multi-tenancy setting.
109
+ */
110
+ permissions: CorsairPermissionsNamespace;
105
111
  } & CorsairInspectMethods;
106
112
  /**
107
113
  * Single-tenant client that includes both plugin APIs and integration-level keys.
@@ -112,6 +118,11 @@ export type CorsairSingleTenantClient<Plugins extends readonly CorsairPlugin[]>
112
118
  * Used to manage secrets shared across all tenants (e.g., OAuth2 client_id, client_secret).
113
119
  */
114
120
  keys: InferAllIntegrationKeys<Plugins>;
121
+ /**
122
+ * Permission management namespace. Use this to query and transition permission records.
123
+ * Available at the root regardless of multi-tenancy setting.
124
+ */
125
+ permissions: CorsairPermissionsNamespace;
115
126
  };
116
127
  export type BuildCorsairClientOptions = {
117
128
  database: CorsairDatabase | undefined;
@@ -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,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,K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AuthTypes, BaseProviders } from './constants';
38
38
  export type { BindEndpoints, BoundEndpointFn, BoundEndpointTree, CorsairContext, CorsairEndpoint, EndpointPathsOf, EndpointTree, } from './endpoints';
39
39
  export type { CorsairErrorHandler, ErrorContext, ErrorHandler, ErrorHandlerAndMatchFunction, ErrorMatcher, RetryStrategies, RetryStrategy, } from './errors';
40
40
  export type { CorsairInspectMethods, EndpointSchemaResult } from './inspect';
41
- export type { EnforcePermissionOptions, EnforcePermissionResult, } from './permissions';
41
+ export type { CorsairPermissionsNamespace, EnforcePermissionOptions, EnforcePermissionResult, } from './permissions';
42
42
  export type { BeforeHookResult, CorsairIntegration, CorsairKeyBuilder, CorsairKeyBuilderBase, CorsairPlugin, CorsairPluginContext, EndpointHooks, EndpointMetaEntry, EndpointRiskLevel, KeyBuilderContext, PermissionMode, PermissionPolicy, PluginEndpointMeta, PluginPermissionsConfig, RequiredPluginEndpointMeta, RequiredPluginEndpointSchemas, RequiredPluginWebhookSchemas, WebhookHooks, } from './plugins';
43
43
  export type { Bivariant, UnionToIntersection } from './utils';
44
44
  export type { BindWebhooks, BoundWebhook, BoundWebhookTree, CorsairWebhook, CorsairWebhookHandler, CorsairWebhookMatcher, RawWebhookRequest, WebhookPathsOf, WebhookRequest, WebhookResponse, WebhookTree, } from './webhooks';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../core/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGhF,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAMnE,eAAO,MAAM,gBAAgB,eAAiC,CAAC;AAE/D,MAAM,MAAM,qBAAqB,GAAG;IACnC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC,QAAQ,EAAE,eAAe,GAAG,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AY,EACX,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,4BAA4B,EAC5B,YAAY,EACZ,eAAe,EACf,aAAa,GACb,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC7E,YAAY,EACX,2BAA2B,EAC3B,wBAAwB,EACxB,uBAAuB,GACvB,MAAM,eAAe,CAAC;AAGvB,YAAY,EACX,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC5B,YAAY,GACZ,MAAM,WAAW,CAAC;AAGnB,YAAY,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9D,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,eAAe,EACf,WAAW,GACX,MAAM,YAAY,CAAC"}
@@ -2,6 +2,7 @@ import { createCorsairDatabase } from '../db/kysely/database';
2
2
  import { createMissingConfigProxy } from './auth/errors';
3
3
  import { buildCorsairClient, buildIntegrationKeys } from './client';
4
4
  import { buildInspectMethods } from './inspect';
5
+ import { buildPermissionsNamespace } from './permissions';
5
6
  // ─────────────────────────────────────────────────────────────────────────────
6
7
  // Internal access for CLI tooling
7
8
  // ─────────────────────────────────────────────────────────────────────────────
@@ -26,6 +27,7 @@ export function createCorsair(config) {
26
27
  multiTenancy: !!config.multiTenancy,
27
28
  approval: config.approval,
28
29
  };
30
+ const permissions = buildPermissionsNamespace(resolvedDatabase);
29
31
  if (config.multiTenancy) {
30
32
  return Object.assign({
31
33
  withTenant: (tenantId) => {
@@ -41,6 +43,7 @@ export function createCorsair(config) {
41
43
  });
42
44
  },
43
45
  keys: integrationKeys,
46
+ permissions,
44
47
  ...buildInspectMethods(config.plugins),
45
48
  }, { [CORSAIR_INTERNAL]: internalConfig });
46
49
  }
@@ -53,6 +56,7 @@ export function createCorsair(config) {
53
56
  });
54
57
  return Object.assign({}, client, {
55
58
  keys: integrationKeys,
59
+ permissions,
56
60
  [CORSAIR_INTERNAL]: internalConfig,
57
61
  });
58
62
  }
@@ -1,4 +1,5 @@
1
1
  import type { CorsairPlugin } from '../plugins';
2
+ type DbFieldType = 'string' | 'number' | 'boolean' | 'date';
2
3
  export type EndpointSchemaResult = {
3
4
  /** Human-readable description of what this endpoint does. */
4
5
  description?: string;
@@ -34,6 +35,35 @@ export type WebhookSchemaResult = {
34
35
  */
35
36
  availableWebhooks?: Record<string, string[]>;
36
37
  };
38
+ export type DbSearchSchemaResult = {
39
+ /**
40
+ * What this entity type represents and how to search it.
41
+ * Pass `limit` and `offset` as numbers for pagination.
42
+ */
43
+ description: string;
44
+ /**
45
+ * Filterable fields for the search() call.
46
+ * All active filters are AND-combined. Omit a field to skip filtering on it.
47
+ *
48
+ * Each operator shorthand: passing a raw value (string/number/boolean/Date) is
49
+ * equivalent to `{ equals: value }`.
50
+ */
51
+ filters: {
52
+ /** Filter by the entity's external platform ID (e.g. a Slack channel ID). */
53
+ entity_id: {
54
+ type: 'string';
55
+ operators: string[];
56
+ };
57
+ /**
58
+ * Filter by fields inside the entity's data payload.
59
+ * Only flat primitive fields are listed — nested objects are not filterable.
60
+ */
61
+ data: Record<string, {
62
+ type: DbFieldType;
63
+ operators: string[];
64
+ }>;
65
+ };
66
+ };
37
67
  export type ListOperationsOptions = {
38
68
  /**
39
69
  * Filter to a specific plugin by its ID (e.g. 'slack', 'github').
@@ -42,24 +72,29 @@ export type ListOperationsOptions = {
42
72
  */
43
73
  plugin?: string;
44
74
  /**
45
- * Whether to list API endpoints or webhooks.
46
- * Defaults to 'api' when not provided.
75
+ * Whether to list API endpoints, webhooks, or database entities.
76
+ * - 'api' (default) lists callable API endpoint paths
77
+ * - 'webhooks' — lists receivable webhook event paths
78
+ * - 'db' — lists searchable database entity paths (one .search per entity type)
47
79
  */
48
- type?: 'api' | 'webhooks';
80
+ type?: 'api' | 'webhooks' | 'db';
49
81
  };
50
82
  export type CorsairInspectMethods = {
51
83
  /**
52
- * Lists available operations (API endpoints or webhooks) for the configured plugins.
84
+ * Lists available operations (API endpoints, webhooks, or database entities) for the configured plugins.
53
85
  *
54
86
  * - No options → all API endpoint paths across every plugin, keyed by plugin ID
55
87
  * - `{ type: 'webhooks' }` → all webhook paths across every plugin, keyed by plugin ID
88
+ * - `{ type: 'db' }` → all searchable DB entity paths across every plugin, keyed by plugin ID
56
89
  * - `{ plugin: 'slack' }` → Slack API endpoint paths as a flat array
57
90
  * - `{ plugin: 'slack', type: 'webhooks' }` → Slack webhook paths as a flat array
91
+ * - `{ plugin: 'slack', type: 'db' }` → Slack DB entity search paths as a flat array
58
92
  * - If the plugin is known but not configured, returns a plain string message.
59
93
  * - If the plugin string is completely unrecognised, returns all API endpoints (same as no options).
60
94
  *
61
95
  * API paths use the format `plugin.api.group.method` (e.g. `slack.api.messages.post`).
62
96
  * Webhook paths use the format `plugin.webhooks.group.event` (e.g. `slack.webhooks.messages.message`).
97
+ * DB paths use the format `plugin.db.entityType.search` (e.g. `slack.db.messages.search`).
63
98
  * All paths can be passed directly to `get_schema()`.
64
99
  *
65
100
  * @example
@@ -72,15 +107,19 @@ export type CorsairInspectMethods = {
72
107
  * corsair.list_operations({ plugin: 'slack', type: 'webhooks' })
73
108
  * // ['slack.webhooks.messages.message', 'slack.webhooks.channels.created', ...]
74
109
  *
110
+ * corsair.list_operations({ plugin: 'slack', type: 'db' })
111
+ * // ['slack.db.messages.search', 'slack.db.channels.search', 'slack.db.users.search', ...]
112
+ *
75
113
  * corsair.list_operations({ plugin: 'unknown' })
76
114
  * // "unknown isn't configured in the Corsair instance."
77
115
  */
78
116
  list_operations(options?: ListOperationsOptions): Record<string, string[]> | string[] | string;
79
117
  /**
80
- * Returns schema and metadata for a specific API endpoint or webhook.
118
+ * Returns schema and metadata for a specific API endpoint, webhook, or database entity search.
81
119
  * The path format determines which kind of schema is returned:
82
120
  * - API path (`plugin.api.group.method`) → `EndpointSchemaResult`
83
121
  * - Webhook path (`plugin.webhooks.group.event`) → `WebhookSchemaResult`
122
+ * - DB path (`plugin.db.entityType.search`) → `DbSearchSchemaResult`
84
123
  *
85
124
  * Casing is ignored — the path is lowercased before lookup.
86
125
  * If the path is not found, returns an object with available paths for self-correction.
@@ -92,14 +131,18 @@ export type CorsairInspectMethods = {
92
131
  * corsair.get_schema('slack.webhooks.messages.message')
93
132
  * // { description: '...', usage: '...', payload: { ... }, response: { ... } }
94
133
  *
134
+ * corsair.get_schema('slack.db.messages.search')
135
+ * // { description: '...', filters: { entity_id: { ... }, data: { text: { type: 'string', operators: [...] }, ... } } }
136
+ *
95
137
  * corsair.get_schema('slack.api.invalid')
96
138
  * // { availableMethods: { slack: ['slack.api.channels.list', ...], ... } }
97
139
  */
98
- get_schema(path: string): EndpointSchemaResult | WebhookSchemaResult;
140
+ get_schema(path: string): EndpointSchemaResult | WebhookSchemaResult | DbSearchSchemaResult;
99
141
  };
100
142
  /**
101
143
  * Creates the list_operations / get_schema functions bound to a specific plugin list.
102
144
  * Used by both single-tenant and multi-tenant client builders.
103
145
  */
104
146
  export declare function buildInspectMethods(plugins: readonly CorsairPlugin[]): CorsairInspectMethods;
147
+ export {};
105
148
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/inspect/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,YAAY,CAAC;AAqFnE,MAAM,MAAM,oBAAoB,GAAG;IAClC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,S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,EAAE,WAAW,CAAC;YAAC,SAAS,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAC;KACjE,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IACnC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,eAAe,CACd,OAAO,CAAC,EAAE,qBAAqB,GAC7B,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;IAChD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,UAAU,CACT,IAAI,EAAE,MAAM,GACV,oBAAoB,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;CACrE,CAAC;AAqYF;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,SAAS,aAAa,EAAE,GAC/B,qBAAqB,CAWvB"}
@@ -75,6 +75,89 @@ function zodToJsonSchema(schema) {
75
75
  }
76
76
  }
77
77
  // ─────────────────────────────────────────────────────────────────────────────
78
+ // DB Entity Helpers
79
+ // ─────────────────────────────────────────────────────────────────────────────
80
+ const STRING_OPERATORS = ['equals', 'contains', 'startsWith', 'endsWith', 'in'];
81
+ const NUMBER_OPERATORS = ['equals', 'gt', 'gte', 'lt', 'lte', 'in'];
82
+ const BOOLEAN_OPERATORS = ['equals'];
83
+ const DATE_OPERATORS = ['equals', 'before', 'after', 'between'];
84
+ /**
85
+ * Unwraps Optional/Nullable/Default/Effects wrappers to find the primitive leaf type.
86
+ * Returns null for complex types (objects, arrays, unions) that are not directly filterable.
87
+ */
88
+ function getSchemaLeafType(schema) {
89
+ const def = schema._def;
90
+ const typeName = def.typeName;
91
+ switch (typeName) {
92
+ case 'ZodOptional':
93
+ case 'ZodNullable':
94
+ case 'ZodDefault':
95
+ return getSchemaLeafType(def.innerType);
96
+ case 'ZodEffects':
97
+ // Covers z.coerce.date() and other transforms
98
+ return getSchemaLeafType(def.schema);
99
+ case 'ZodString':
100
+ return 'string';
101
+ case 'ZodNumber':
102
+ return 'number';
103
+ case 'ZodBoolean':
104
+ return 'boolean';
105
+ case 'ZodDate':
106
+ return 'date';
107
+ default:
108
+ return null;
109
+ }
110
+ }
111
+ /**
112
+ * Derives the filterable fields from a Zod object schema.
113
+ * Only flat primitive fields (string, number, boolean, date) are included.
114
+ * Nested objects and arrays are skipped — the ORM does not support filtering into them.
115
+ */
116
+ function buildFilterableFields(schema) {
117
+ const def = schema._def;
118
+ const typeName = def.typeName;
119
+ if (typeName === 'ZodOptional' ||
120
+ typeName === 'ZodNullable' ||
121
+ typeName === 'ZodDefault') {
122
+ return buildFilterableFields(def.innerType);
123
+ }
124
+ if (typeName === 'ZodEffects') {
125
+ return buildFilterableFields(def.schema);
126
+ }
127
+ if (typeName !== 'ZodObject')
128
+ return {};
129
+ const shape = def.shape();
130
+ const result = {};
131
+ for (const [key, fieldSchema] of Object.entries(shape)) {
132
+ const leafType = getSchemaLeafType(fieldSchema);
133
+ if (leafType === 'string') {
134
+ result[key] = { type: 'string', operators: STRING_OPERATORS };
135
+ }
136
+ else if (leafType === 'number') {
137
+ result[key] = { type: 'number', operators: NUMBER_OPERATORS };
138
+ }
139
+ else if (leafType === 'boolean') {
140
+ result[key] = { type: 'boolean', operators: BOOLEAN_OPERATORS };
141
+ }
142
+ else if (leafType === 'date') {
143
+ result[key] = { type: 'date', operators: DATE_OPERATORS };
144
+ }
145
+ // Nested objects, arrays, unions — not filterable via ORM, omit them
146
+ }
147
+ return result;
148
+ }
149
+ /**
150
+ * Case-insensitive lookup for an entity name in a schema's entities map.
151
+ * Entity names are camelCase (e.g. 'userGroups') but agent paths are lowercased.
152
+ */
153
+ function findEntityCaseInsensitive(entities, lowercasedName) {
154
+ for (const [key, schema] of Object.entries(entities)) {
155
+ if (key.toLowerCase() === lowercasedName)
156
+ return [key, schema];
157
+ }
158
+ return undefined;
159
+ }
160
+ // ─────────────────────────────────────────────────────────────────────────────
78
161
  // Endpoint Tree Walker
79
162
  // ─────────────────────────────────────────────────────────────────────────────
80
163
  function walkEndpointTree(tree, pathParts, result) {
@@ -222,13 +305,17 @@ function listOperations(plugins, options) {
222
305
  walkWebhookTree(found.webhooks, [], paths);
223
306
  return paths.map((path) => `${found.id}.webhooks.${path}`);
224
307
  }
225
- else {
226
- if (!found.endpoints)
308
+ if (type === 'db') {
309
+ const entities = found.schema?.entities;
310
+ if (!entities)
227
311
  return [];
228
- const paths = [];
229
- walkEndpointTree(found.endpoints, [], paths);
230
- return paths.map((path) => `${found.id}.api.${path.toLowerCase()}`);
312
+ return Object.keys(entities).map((entityName) => `${found.id}.db.${entityName}.search`);
231
313
  }
314
+ if (!found.endpoints)
315
+ return [];
316
+ const paths = [];
317
+ walkEndpointTree(found.endpoints, [], paths);
318
+ return paths.map((path) => `${found.id}.api.${path.toLowerCase()}`);
232
319
  }
233
320
  const result = {};
234
321
  if (type === 'webhooks') {
@@ -240,6 +327,14 @@ function listOperations(plugins, options) {
240
327
  result[p.id] = paths.map((path) => `${p.id}.webhooks.${path}`);
241
328
  }
242
329
  }
330
+ else if (type === 'db') {
331
+ for (const p of plugins) {
332
+ const entities = p.schema?.entities;
333
+ if (!entities)
334
+ continue;
335
+ result[p.id] = Object.keys(entities).map((entityName) => `${p.id}.db.${entityName}.search`);
336
+ }
337
+ }
243
338
  else {
244
339
  for (const p of plugins) {
245
340
  if (!p.endpoints)
@@ -274,6 +369,38 @@ function getSchema(plugins, path) {
274
369
  const remainder = normalised.slice(dotIndex + 1);
275
370
  const plugin = plugins.find((p) => p.id === pluginId);
276
371
  if (plugin) {
372
+ // ── DB search path: plugin.db.entityType.search ────────────────────────
373
+ if (remainder.startsWith('db.')) {
374
+ const dbPath = remainder.slice(3); // strip 'db.'
375
+ const lastDot = dbPath.lastIndexOf('.');
376
+ if (lastDot !== -1) {
377
+ const entityNameLower = dbPath.slice(0, lastDot);
378
+ const method = dbPath.slice(lastDot + 1);
379
+ const entities = plugin.schema?.entities;
380
+ if (method === 'search' && entities) {
381
+ const entry = findEntityCaseInsensitive(entities, entityNameLower);
382
+ if (entry) {
383
+ const [entityName, entitySchema] = entry;
384
+ return {
385
+ description: `Search ${pluginId} ${entityName} stored in the local database. Returns an array of matching records. Pass limit and offset (numbers) for pagination.`,
386
+ filters: {
387
+ entity_id: {
388
+ type: 'string',
389
+ operators: STRING_OPERATORS,
390
+ },
391
+ data: buildFilterableFields(entitySchema),
392
+ },
393
+ };
394
+ }
395
+ }
396
+ }
397
+ // Invalid db path — return available db operations for self-correction
398
+ return {
399
+ availableMethods: listOperations(plugins, {
400
+ type: 'db',
401
+ }),
402
+ };
403
+ }
277
404
  // ── Webhook path: plugin.webhooks.group.event ──────────────────────────
278
405
  if (remainder.startsWith('webhooks.')) {
279
406
  const webhookPathNormalised = remainder.slice(9); // strip 'webhooks.'
@@ -1,9 +1,46 @@
1
+ import type { CorsairPermission } from '../../db';
1
2
  import type { CorsairDatabase } from '../../db/kysely/database';
2
3
  import type { EndpointMetaEntry, EndpointRiskLevel, PermissionMode, PermissionPolicy } from '../plugins';
3
4
  /** Resolves the effective permission policy for an endpoint. The override (from permissions.overrides) takes precedence. */
4
5
  export declare function evaluatePermission(riskLevel: EndpointRiskLevel, mode: PermissionMode, override?: PermissionPolicy): PermissionPolicy;
5
6
  /** Parses a duration string ('30s', '10m', '1h', '2h30m', '1d') into milliseconds. */
6
7
  export declare function parseDurationMs(duration: string): number;
8
+ /**
9
+ * The `corsair.permissions` namespace available at the root of every corsair instance.
10
+ * Provides methods for querying and transitioning permission records.
11
+ *
12
+ * Status transitions exposed here are intentionally limited to safe, non-escalating states.
13
+ * Setting a record to 'approved' (which grants execution) is deliberately excluded —
14
+ * that must happen through the out-of-band review flow.
15
+ */
16
+ export type CorsairPermissionsNamespace = {
17
+ /**
18
+ * Fetches a single permission record by its ID.
19
+ * Returns undefined if no record exists or if no database is configured.
20
+ */
21
+ find_by_permission_id(id: string): Promise<CorsairPermission | undefined>;
22
+ /**
23
+ * Fetches a single permission record by its token.
24
+ * The token is the public-facing handle embedded in review URLs.
25
+ * Returns undefined if no record exists or if no database is configured.
26
+ */
27
+ find_by_token(token: string): Promise<CorsairPermission | undefined>;
28
+ /**
29
+ * Marks the permission as 'executing'. Call this when executePermission picks up
30
+ * an approved record and is about to run the endpoint.
31
+ */
32
+ set_executing(id: string): Promise<void>;
33
+ /**
34
+ * Marks the permission as 'completed'. Call this after the endpoint has finished
35
+ * executing successfully.
36
+ */
37
+ set_completed(id: string): Promise<void>;
38
+ };
39
+ /**
40
+ * Builds the `corsair.permissions` namespace for a given database instance.
41
+ * Returns no-op stubs when no database is configured.
42
+ */
43
+ export declare function buildPermissionsNamespace(db: CorsairDatabase | undefined): CorsairPermissionsNamespace;
7
44
  export type EnforcePermissionOptions = {
8
45
  pluginId: string;
9
46
  endpointPath: string;
@@ -1 +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;I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ds the `corsair.permissions` namespace for a given database instance.
47
+ * Returns no-op stubs when no database is configured.
48
+ */
49
+ export function buildPermissionsNamespace(db) {
50
+ return {
51
+ async find_by_permission_id(id) {
52
+ if (!db)
53
+ return undefined;
54
+ return db.db
55
+ .selectFrom('corsair_permissions')
56
+ .selectAll()
57
+ .where('id', '=', id)
58
+ .executeTakeFirst();
59
+ },
60
+ async find_by_token(token) {
61
+ if (!db)
62
+ return undefined;
63
+ return db.db
64
+ .selectFrom('corsair_permissions')
65
+ .selectAll()
66
+ .where('token', '=', token)
67
+ .executeTakeFirst();
68
+ },
69
+ async set_executing(id) {
70
+ if (!db)
71
+ return;
72
+ await db.db
73
+ .updateTable('corsair_permissions')
74
+ .set({ status: 'executing', updated_at: new Date() })
75
+ .where('id', '=', id)
76
+ .execute();
77
+ },
78
+ async set_completed(id) {
79
+ if (!db)
80
+ return;
81
+ await db.db
82
+ .updateTable('corsair_permissions')
83
+ .set({ status: 'completed', updated_at: new Date() })
84
+ .where('id', '=', id)
85
+ .execute();
86
+ },
87
+ };
88
+ }
45
89
  /**
46
90
  * Evaluates the permission policy and returns whether the action is allowed.
47
91
  *
@@ -80,7 +124,7 @@ export async function enforcePermission(opts) {
80
124
  .where('args', '=', argsJson)
81
125
  .where('tenant_id', '=', tenantId)
82
126
  .where('expires_at', '>', now)
83
- .where('status', 'in', ['pending', 'approved'])
127
+ .where('status', 'in', ['pending', 'approved', 'executing'])
84
128
  .orderBy('created_at', 'desc')
85
129
  .limit(1)
86
130
  .executeTakeFirst();
@@ -100,6 +144,11 @@ export async function enforcePermission(opts) {
100
144
  },
101
145
  };
102
146
  }
147
+ if (existing.status === 'executing') {
148
+ // executePermission is actively running this — let the endpoint body proceed.
149
+ // Completion is handled by executePermission itself, not via onComplete here.
150
+ return { result: 'allow' };
151
+ }
103
152
  // status === 'pending': already waiting for approval, don't create a duplicate
104
153
  console.log(`[corsair/${opts.pluginId}] '${opts.endpointPath}' blocked — approval already pending.`, `\n Action: ${description}`, `\n Permission ID: ${existing.id}`, `\n Use the token to approve or deny this request.`);
105
154
  return { result: 'blocked' };
@@ -120,33 +120,37 @@ export declare const CorsairPermissionsSchema: z.ZodObject<{
120
120
  * can scope the corsair instance correctly when executing the approved action.
121
121
  * Defaults to 'default' for single-tenant instances.
122
122
  */
123
- tenant_id: z.ZodOptional<z.ZodString>;
123
+ tenant_id: z.ZodString;
124
124
  /** Current state of the approval request */
125
- status: z.ZodDefault<z.ZodEnum<["pending", "approved", "completed", "denied", "expired"]>>;
125
+ status: z.ZodDefault<z.ZodEnum<["pending", "approved", "executing", "completed", "denied", "expired", "failed"]>>;
126
126
  /** ISO8601 timestamp — when this request becomes invalid */
127
127
  expires_at: z.ZodString;
128
+ /** Stringified error captured when status transitions to 'failed'. Null otherwise. */
129
+ error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
128
130
  }, "strip", z.ZodTypeAny, {
129
131
  id: string;
130
132
  created_at: Date;
131
133
  updated_at: Date;
132
- status: "pending" | "completed" | "approved" | "denied" | "expired";
134
+ status: "pending" | "completed" | "failed" | "approved" | "executing" | "denied" | "expired";
135
+ tenant_id: string;
133
136
  token: string;
134
137
  plugin: string;
135
138
  endpoint: string;
136
139
  args: string;
137
140
  expires_at: string;
138
- tenant_id?: string | undefined;
141
+ error?: string | null | undefined;
139
142
  }, {
140
143
  id: string;
141
144
  created_at: Date;
142
145
  updated_at: Date;
146
+ tenant_id: string;
143
147
  token: string;
144
148
  plugin: string;
145
149
  endpoint: string;
146
150
  args: string;
147
151
  expires_at: string;
148
- status?: "pending" | "completed" | "approved" | "denied" | "expired" | undefined;
149
- tenant_id?: string | undefined;
152
+ status?: "pending" | "completed" | "failed" | "approved" | "executing" | "denied" | "expired" | undefined;
153
+ error?: string | null | undefined;
150
154
  }>;
151
155
  export type CorsairPermission = z.infer<typeof CorsairPermissionsSchema>;
152
156
  export type CorsairPermissionInsert = {
@@ -158,8 +162,9 @@ export type CorsairPermissionInsert = {
158
162
  endpoint: string;
159
163
  args: string;
160
164
  tenant_id?: string;
161
- status?: 'pending' | 'approved' | 'completed' | 'denied' | 'expired';
165
+ status?: 'pending' | 'approved' | 'executing' | 'completed' | 'denied' | 'expired' | 'failed';
162
166
  expires_at: string;
167
+ error?: string | null;
163
168
  };
164
169
  export type CorsairTableName = 'corsair_integrations' | 'corsair_accounts' | 'corsair_entities' | 'corsair_events' | 'corsair_permissions' | (string & {});
165
170
  export type CorsairTableRow = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../db/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;EAYpC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAM3E,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;EAehC,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMnE,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBhC,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMlE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;EAgB9B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAM/D,eAAO,MAAM,wBAAwB;;;;IAKpC,uFAAuF;;IAEvF,uCAAuC;;IAEvC,6DAA6D;;IAE7D,6EAA6E;;IAE7E;;;;OAIG;;IAEH,4CAA4C;;IAI5C,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;EAE3D,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAA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AE,wBAAwB,CAAC;IAC/C,gBAAgB,EAAE,oBAAoB,CAAC;IACvC,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,cAAc,EAAE,kBAAkB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,gBAAgB,IACrD,CAAC,SAAS,MAAM,kBAAkB,GAC/B,kBAAkB,CAAC,CAAC,CAAC,GACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
package/dist/db/index.js CHANGED
@@ -86,11 +86,21 @@ export const CorsairPermissionsSchema = z.object({
86
86
  * can scope the corsair instance correctly when executing the approved action.
87
87
  * Defaults to 'default' for single-tenant instances.
88
88
  */
89
- tenant_id: z.string().optional(),
89
+ tenant_id: z.string(),
90
90
  /** Current state of the approval request */
91
91
  status: z
92
- .enum(['pending', 'approved', 'completed', 'denied', 'expired'])
92
+ .enum([
93
+ 'pending',
94
+ 'approved',
95
+ 'executing',
96
+ 'completed',
97
+ 'denied',
98
+ 'expired',
99
+ 'failed',
100
+ ])
93
101
  .default('pending'),
94
102
  /** ISO8601 timestamp — when this request becomes invalid */
95
103
  expires_at: z.string(),
104
+ /** Stringified error captured when status transitions to 'failed'. Null otherwise. */
105
+ error: z.string().nullable().optional(),
96
106
  });
@@ -1,21 +1,19 @@
1
- import type { CorsairDatabase } from '../db/kysely/database';
1
+ import type { CorsairPermissionsNamespace } from '../core/permissions';
2
2
  /**
3
- * A plugin namespace on the corsair instance that may have API endpoints.
3
+ * The corsair instance type for permission execution.
4
+ * Must expose the `permissions` namespace and optionally a `withTenant` method.
5
+ * The withTenant return type is intentionally broad — we only need to index into it
6
+ * by plugin name, and we cast the result to PluginWithApi at the call site.
4
7
  */
5
- type PluginWithApi = {
6
- api?: Record<string, unknown>;
7
- };
8
- /**
9
- * The corsair instance type for permission execution — a record of plugin namespaces.
10
- * Mirrors the duck-typed shape used by processWebhook.
11
- */
12
- type CorsairInstance = Record<string, PluginWithApi | undefined> & {
13
- withTenant?: (tenantId: string) => CorsairInstance;
8
+ type CorsairInstance = {
9
+ permissions: CorsairPermissionsNamespace;
10
+ withTenant?: (tenantId: string) => Record<string, unknown>;
11
+ [key: string]: unknown;
14
12
  };
15
13
  export type PermissionExecuteResult = {
16
- plugin: string;
17
- endpoint: string;
18
- result: unknown;
14
+ plugin?: string;
15
+ endpoint?: string;
16
+ result?: unknown;
19
17
  error?: string;
20
18
  };
21
19
  /**
@@ -29,19 +27,18 @@ export type PermissionExecuteResult = {
29
27
  * involvement required.
30
28
  *
31
29
  * Lifecycle:
32
- * 1. Fetches the permission record from corsair_permissions
33
- * 2. Validates the record is pending and not expired
30
+ * 1. Fetches the permission record via corsair.permissions.find_by_permission_id
31
+ * 2. Validates the record is approved (human has signed off) and not expired
34
32
  * 3. Resolves the tenant-scoped corsair instance (via withTenant if multi-tenant)
35
- * 4. Sets status to 'approved' so the bound endpoint's permission guard allows it through
33
+ * 4. Sets status to 'executing' via corsair.permissions.set_executing
36
34
  * 5. Navigates corsair[plugin].api[...endpoint path] to find the bound function
37
35
  * 6. Calls the function with the stored args (JSON-parsed)
38
- * 7. The bound function's internal onComplete callback marks the record 'completed'
39
- * 8. Returns the result, or an error object if the endpoint throws
36
+ * 7. Sets status to 'completed' via corsair.permissions.set_completed
37
+ * 8. Returns the result, or an error object if the endpoint gracefully exits
40
38
  *
41
39
  * @param corsair - The corsair instance (returned from createCorsair)
42
- * @param db - The corsair database instance
43
- * @param permissionId - The ID of the corsair_permissions record to execute
40
+ * @param token - The token embedded in the review URL for the corsair_permissions record
44
41
  */
45
- export declare function executePermission(corsair: CorsairInstance, db: CorsairDatabase, permissionId: string): Promise<PermissionExecuteResult>;
42
+ export declare function executePermission(corsair: CorsairInstance, token: string): Promise<PermissionExecuteResult>;
46
43
  export {};
47
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../permissions/index.ts"],"names":[],"mappings":"AAAA,OAAO,K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F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,iBAAiB,CACtC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,uBAAuB,CAAC,CAoHlC"}
@@ -1,3 +1,6 @@
1
+ // Internal symbol — mirrors the one exported from core/index.ts without importing it
2
+ // (avoids potential circular dependency) since Symbol.for() uses a global registry.
3
+ const CORSAIR_INTERNAL_SYMBOL = Symbol.for('corsair:internal');
1
4
  // ─────────────────────────────────────────────────────────────────────────────
2
5
  // Helpers
3
6
  // ─────────────────────────────────────────────────────────────────────────────
@@ -16,6 +19,15 @@ function resolveEndpointFn(api, pathParts) {
16
19
  ? current
17
20
  : null;
18
21
  }
22
+ /**
23
+ * Retrieves the internal database from a corsair instance via the CORSAIR_INTERNAL symbol.
24
+ * Used for terminal status transitions (expired, denied) that are not part of the
25
+ * public `corsair.permissions` API.
26
+ */
27
+ function getInternalDb(corsair) {
28
+ const internal = corsair[CORSAIR_INTERNAL_SYMBOL];
29
+ return internal?.database;
30
+ }
19
31
  // ─────────────────────────────────────────────────────────────────────────────
20
32
  // Main Function
21
33
  // ─────────────────────────────────────────────────────────────────────────────
@@ -30,77 +42,105 @@ function resolveEndpointFn(api, pathParts) {
30
42
  * involvement required.
31
43
  *
32
44
  * Lifecycle:
33
- * 1. Fetches the permission record from corsair_permissions
34
- * 2. Validates the record is pending and not expired
45
+ * 1. Fetches the permission record via corsair.permissions.find_by_permission_id
46
+ * 2. Validates the record is approved (human has signed off) and not expired
35
47
  * 3. Resolves the tenant-scoped corsair instance (via withTenant if multi-tenant)
36
- * 4. Sets status to 'approved' so the bound endpoint's permission guard allows it through
48
+ * 4. Sets status to 'executing' via corsair.permissions.set_executing
37
49
  * 5. Navigates corsair[plugin].api[...endpoint path] to find the bound function
38
50
  * 6. Calls the function with the stored args (JSON-parsed)
39
- * 7. The bound function's internal onComplete callback marks the record 'completed'
40
- * 8. Returns the result, or an error object if the endpoint throws
51
+ * 7. Sets status to 'completed' via corsair.permissions.set_completed
52
+ * 8. Returns the result, or an error object if the endpoint gracefully exits
41
53
  *
42
54
  * @param corsair - The corsair instance (returned from createCorsair)
43
- * @param db - The corsair database instance
44
- * @param permissionId - The ID of the corsair_permissions record to execute
55
+ * @param token - The token embedded in the review URL for the corsair_permissions record
45
56
  */
46
- export async function executePermission(corsair, db, permissionId) {
57
+ export async function executePermission(corsair, token) {
47
58
  const now = new Date().toISOString();
48
- const perm = await db.db
49
- .selectFrom('corsair_permissions')
50
- .selectAll()
51
- .where('id', '=', permissionId)
52
- .executeTakeFirst();
53
- if (!perm) {
54
- throw new Error(`executePermission: permission '${permissionId}' not found.`);
59
+ const permission = await corsair.permissions.find_by_token(token);
60
+ if (!permission) {
61
+ console.error(`executePermission: no permission found for token.`);
62
+ return {
63
+ error: `executePermission: no permission found for token.`,
64
+ };
55
65
  }
56
- if (perm.status !== 'pending') {
57
- throw new Error(`executePermission: permission '${permissionId}' is '${perm.status}', expected 'pending'.`);
66
+ if (permission.status !== 'approved') {
67
+ console.error(`executePermission: permission '${permission.id}' is '${permission.status}', expected 'approved'.`);
68
+ return {
69
+ endpoint: permission.endpoint,
70
+ plugin: permission.plugin,
71
+ result: null,
72
+ error: `executePermission: permission '${permission.id}' is '${permission.status}', expected 'approved'.`,
73
+ };
58
74
  }
59
- if (perm.expires_at < now) {
60
- await db.db
61
- .updateTable('corsair_permissions')
62
- .set({ status: 'expired', updated_at: new Date() })
63
- .where('id', '=', permissionId)
64
- .execute();
65
- throw new Error(`executePermission: permission '${permissionId}' has expired.`);
75
+ if (permission.expires_at < now) {
76
+ const db = getInternalDb(corsair);
77
+ if (db) {
78
+ await db.db
79
+ .updateTable('corsair_permissions')
80
+ .set({ status: 'expired', updated_at: new Date() })
81
+ .where('id', '=', permission.id)
82
+ .execute();
83
+ }
84
+ console.error(`executePermission: permission '${permission.id}' has expired.`);
85
+ return {
86
+ error: `executePermission: permission '${permission.id}' has expired.`,
87
+ endpoint: permission.endpoint,
88
+ plugin: permission.plugin,
89
+ result: null,
90
+ };
66
91
  }
67
92
  // Resolve the tenant-scoped instance. The stored tenant_id ensures the correct
68
93
  // plugin context is used for multi-tenant corsair instances.
69
- const tenantId = perm.tenant_id ?? 'default';
94
+ const tenantId = permission.tenant_id ?? 'default';
70
95
  const scopedCorsair = corsair.withTenant
71
96
  ? corsair.withTenant(tenantId)
72
97
  : corsair;
73
- const pluginNamespace = scopedCorsair[perm.plugin];
98
+ const pluginNamespace = scopedCorsair[permission.plugin];
74
99
  if (!pluginNamespace?.api) {
75
- throw new Error(`executePermission: plugin '${perm.plugin}' not found or has no API on this corsair instance.`);
100
+ console.error(`executePermission: plugin '${permission.plugin}' not found or has no API on this corsair instance.`);
101
+ return {
102
+ error: `executePermission: plugin '${permission.plugin}' not found or has no API on this corsair instance.`,
103
+ plugin: permission.plugin,
104
+ endpoint: permission.endpoint,
105
+ result: null,
106
+ };
76
107
  }
77
- const endpointFn = resolveEndpointFn(pluginNamespace.api, perm.endpoint.split('.'));
108
+ const endpointFn = resolveEndpointFn(pluginNamespace.api, permission.endpoint.split('.'));
78
109
  if (!endpointFn) {
79
- throw new Error(`executePermission: endpoint '${perm.endpoint}' not found in plugin '${perm.plugin}'.`);
110
+ console.error(`executePermission: endpoint '${permission.endpoint}' not found in plugin '${permission.plugin}'.`);
111
+ return {
112
+ endpoint: permission.endpoint,
113
+ plugin: permission.plugin,
114
+ result: null,
115
+ error: `executePermission: endpoint '${permission.endpoint}' not found in plugin '${permission.plugin}'.`,
116
+ };
80
117
  }
81
- // Mark as approved — the bound function's enforcePermission will find this record,
82
- // allow the call through, then its onComplete callback marks it 'completed'.
83
- await db.db
84
- .updateTable('corsair_permissions')
85
- .set({ status: 'approved', updated_at: new Date() })
86
- .where('id', '=', permissionId)
87
- .execute();
118
+ // Mark as executing — the bound endpoint's enforcePermission recognises this status
119
+ // and allows the call through. Completion is set explicitly below after the endpoint returns.
120
+ await corsair.permissions.set_executing(permission.id);
88
121
  try {
89
- const result = await endpointFn(JSON.parse(perm.args));
90
- return { plugin: perm.plugin, endpoint: perm.endpoint, result };
122
+ const parsedArgs = typeof permission.args === 'string'
123
+ ? JSON.parse(permission.args)
124
+ : permission.args;
125
+ const result = await endpointFn(parsedArgs);
126
+ await corsair.permissions.set_completed(permission.id);
127
+ return { plugin: permission.plugin, endpoint: permission.endpoint, result };
91
128
  }
92
129
  catch (error) {
93
- // Reset to a terminal state so the approval cannot be silently retried.
94
- await db.db
95
- .updateTable('corsair_permissions')
96
- .set({ status: 'denied', updated_at: new Date() })
97
- .where('id', '=', permissionId)
98
- .execute();
130
+ const errorMessage = error instanceof Error ? error.message : String(error);
131
+ const db = getInternalDb(corsair);
132
+ if (db) {
133
+ await db.db
134
+ .updateTable('corsair_permissions')
135
+ .set({ status: 'failed', error: errorMessage, updated_at: new Date() })
136
+ .where('id', '=', permission.id)
137
+ .execute();
138
+ }
99
139
  return {
100
- plugin: perm.plugin,
101
- endpoint: perm.endpoint,
140
+ plugin: permission.plugin,
141
+ endpoint: permission.endpoint,
102
142
  result: null,
103
- error: error instanceof Error ? error.message : String(error),
143
+ error: errorMessage,
104
144
  };
105
145
  }
106
146
  }
@@ -47,8 +47,8 @@ export declare const ResendWebhookPayloadSchema: z.ZodObject<{
47
47
  created_at: string;
48
48
  name?: string | undefined;
49
49
  status?: string | undefined;
50
- link?: string | undefined;
51
50
  error?: string | undefined;
51
+ link?: string | undefined;
52
52
  subject?: string | undefined;
53
53
  from?: string | undefined;
54
54
  to?: string[] | undefined;
@@ -65,8 +65,8 @@ export declare const ResendWebhookPayloadSchema: z.ZodObject<{
65
65
  created_at: string;
66
66
  name?: string | undefined;
67
67
  status?: string | undefined;
68
- link?: string | undefined;
69
68
  error?: string | undefined;
69
+ link?: string | undefined;
70
70
  subject?: string | undefined;
71
71
  from?: string | undefined;
72
72
  to?: string[] | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../../plugins/slack/webhooks/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAGxC,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,SAAS,CAyF5C,CAAC"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../../plugins/slack/webhooks/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAGxC,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,SAAS,CA4F5C,CAAC"}
@@ -43,7 +43,8 @@ export const message = {
43
43
  });
44
44
  corsairEntityId = entity?.id || '';
45
45
  }
46
- else if (!('subtype' in event) || event.subtype !== 'message_deleted') {
46
+ else if (!('subtype' in event) ||
47
+ event.subtype !== 'message_deleted') {
47
48
  // GenericMessageEvent, BotMessageEvent, FileShareMessageEvent, etc.
48
49
  // Skip message_deleted — the message no longer exists and we don't
49
50
  // want to create a spurious record keyed on the deletion-event timestamp.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corsair",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",