corsair 0.1.17 → 0.1.19

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.
Files changed (199) hide show
  1. package/dist/core/client/index.d.ts +1 -1
  2. package/dist/core/client/index.d.ts.map +1 -1
  3. package/dist/core/client/index.js +2 -2
  4. package/dist/core/endpoints/bind.d.ts.map +1 -1
  5. package/dist/core/endpoints/bind.js +21 -18
  6. package/dist/core/index.d.ts +4 -4
  7. package/dist/core/index.d.ts.map +1 -1
  8. package/dist/core/inspect/index.d.ts +76 -2
  9. package/dist/core/inspect/index.d.ts.map +1 -1
  10. package/dist/core/inspect/index.js +167 -4
  11. package/dist/core/permissions/index.d.ts +20 -5
  12. package/dist/core/permissions/index.d.ts.map +1 -1
  13. package/dist/core/permissions/index.js +49 -10
  14. package/dist/core/plugins/index.d.ts +57 -2
  15. package/dist/core/plugins/index.d.ts.map +1 -1
  16. package/dist/core/webhooks/index.d.ts +23 -0
  17. package/dist/core/webhooks/index.d.ts.map +1 -1
  18. package/dist/db/index.d.ts +4 -4
  19. package/dist/db/index.d.ts.map +1 -1
  20. package/dist/db/index.js +1 -1
  21. package/dist/plugins/discord/endpoints/types.d.ts +3055 -160
  22. package/dist/plugins/discord/endpoints/types.d.ts.map +1 -1
  23. package/dist/plugins/discord/endpoints/types.js +301 -1
  24. package/dist/plugins/discord/index.d.ts +4031 -21
  25. package/dist/plugins/discord/index.d.ts.map +1 -1
  26. package/dist/plugins/discord/index.js +136 -11
  27. package/dist/plugins/discord/schema/database.d.ts +18 -18
  28. package/dist/plugins/discord/schema/index.d.ts +18 -18
  29. package/dist/plugins/discord/webhooks/index.d.ts +507 -3
  30. package/dist/plugins/discord/webhooks/index.d.ts.map +1 -1
  31. package/dist/plugins/discord/webhooks/types.d.ts +3743 -48
  32. package/dist/plugins/discord/webhooks/types.d.ts.map +1 -1
  33. package/dist/plugins/discord/webhooks/types.js +107 -0
  34. package/dist/plugins/github/endpoints/index.d.ts +380 -380
  35. package/dist/plugins/github/endpoints/types.d.ts +1034 -9274
  36. package/dist/plugins/github/endpoints/types.d.ts.map +1 -1
  37. package/dist/plugins/github/endpoints/types.js +0 -26
  38. package/dist/plugins/github/index.d.ts +9123 -7
  39. package/dist/plugins/github/index.d.ts.map +1 -1
  40. package/dist/plugins/github/index.js +121 -1
  41. package/dist/plugins/github/schema/database.d.ts +126 -126
  42. package/dist/plugins/github/schema/index.d.ts +126 -126
  43. package/dist/plugins/github/webhooks/index.d.ts +1758 -6
  44. package/dist/plugins/github/webhooks/index.d.ts.map +1 -1
  45. package/dist/plugins/github/webhooks/types.d.ts +10765 -136
  46. package/dist/plugins/github/webhooks/types.d.ts.map +1 -1
  47. package/dist/plugins/github/webhooks/types.js +202 -0
  48. package/dist/plugins/gmail/endpoints/index.d.ts +20 -20
  49. package/dist/plugins/gmail/endpoints/types.d.ts +140 -1784
  50. package/dist/plugins/gmail/endpoints/types.d.ts.map +1 -1
  51. package/dist/plugins/gmail/endpoints/types.js +12 -34
  52. package/dist/plugins/gmail/index.d.ts +1703 -3
  53. package/dist/plugins/gmail/index.d.ts.map +1 -1
  54. package/dist/plugins/gmail/index.js +112 -3
  55. package/dist/plugins/gmail/schema/database.d.ts +2 -2
  56. package/dist/plugins/gmail/schema/index.d.ts +2 -2
  57. package/dist/plugins/gmail/webhooks/index.d.ts +35 -1
  58. package/dist/plugins/gmail/webhooks/index.d.ts.map +1 -1
  59. package/dist/plugins/gmail/webhooks/types.d.ts +168 -30
  60. package/dist/plugins/gmail/webhooks/types.d.ts.map +1 -1
  61. package/dist/plugins/gmail/webhooks/types.js +49 -0
  62. package/dist/plugins/googlecalendar/endpoints/index.d.ts +5 -5
  63. package/dist/plugins/googlecalendar/endpoints/types.d.ts +10 -2324
  64. package/dist/plugins/googlecalendar/endpoints/types.d.ts.map +1 -1
  65. package/dist/plugins/googlecalendar/endpoints/types.js +0 -11
  66. package/dist/plugins/googlecalendar/index.d.ts +2338 -3
  67. package/dist/plugins/googlecalendar/index.d.ts.map +1 -1
  68. package/dist/plugins/googlecalendar/index.js +48 -6
  69. package/dist/plugins/googlecalendar/schema/database.d.ts +2 -2
  70. package/dist/plugins/googlecalendar/schema/index.d.ts +2 -2
  71. package/dist/plugins/googlecalendar/webhooks/index.d.ts +31 -1
  72. package/dist/plugins/googlecalendar/webhooks/index.d.ts.map +1 -1
  73. package/dist/plugins/googlecalendar/webhooks/types.d.ts +172 -28
  74. package/dist/plugins/googlecalendar/webhooks/types.d.ts.map +1 -1
  75. package/dist/plugins/googlecalendar/webhooks/types.js +55 -1
  76. package/dist/plugins/googledrive/endpoints/index.d.ts +18 -18
  77. package/dist/plugins/googledrive/endpoints/types.d.ts +30 -2468
  78. package/dist/plugins/googledrive/endpoints/types.d.ts.map +1 -1
  79. package/dist/plugins/googledrive/endpoints/types.js +0 -26
  80. package/dist/plugins/googledrive/index.d.ts +2470 -3
  81. package/dist/plugins/googledrive/index.d.ts.map +1 -1
  82. package/dist/plugins/googledrive/index.js +144 -15
  83. package/dist/plugins/googledrive/schema/database.d.ts +6 -6
  84. package/dist/plugins/googledrive/schema/index.d.ts +6 -6
  85. package/dist/plugins/googledrive/webhooks/index.d.ts +47 -1
  86. package/dist/plugins/googledrive/webhooks/index.d.ts.map +1 -1
  87. package/dist/plugins/googledrive/webhooks/types.d.ts +172 -34
  88. package/dist/plugins/googledrive/webhooks/types.d.ts.map +1 -1
  89. package/dist/plugins/googledrive/webhooks/types.js +64 -1
  90. package/dist/plugins/googlesheets/endpoints/index.d.ts +1 -1
  91. package/dist/plugins/googlesheets/endpoints/types.d.ts +26 -614
  92. package/dist/plugins/googlesheets/endpoints/types.d.ts.map +1 -1
  93. package/dist/plugins/googlesheets/endpoints/types.js +0 -15
  94. package/dist/plugins/googlesheets/index.d.ts +603 -3
  95. package/dist/plugins/googlesheets/index.d.ts.map +1 -1
  96. package/dist/plugins/googlesheets/index.js +68 -6
  97. package/dist/plugins/googlesheets/schema/database.d.ts +4 -4
  98. package/dist/plugins/googlesheets/schema/index.d.ts +4 -4
  99. package/dist/plugins/googlesheets/webhooks/index.d.ts +15 -1
  100. package/dist/plugins/googlesheets/webhooks/index.d.ts.map +1 -1
  101. package/dist/plugins/googlesheets/webhooks/types.d.ts +45 -10
  102. package/dist/plugins/googlesheets/webhooks/types.d.ts.map +1 -1
  103. package/dist/plugins/googlesheets/webhooks/types.js +26 -0
  104. package/dist/plugins/hubspot/endpoints/types.d.ts +0 -7291
  105. package/dist/plugins/hubspot/endpoints/types.d.ts.map +1 -1
  106. package/dist/plugins/hubspot/endpoints/types.js +0 -39
  107. package/dist/plugins/hubspot/index.d.ts +7443 -14
  108. package/dist/plugins/hubspot/index.d.ts.map +1 -1
  109. package/dist/plugins/hubspot/index.js +252 -14
  110. package/dist/plugins/hubspot/schema/database.d.ts +8 -8
  111. package/dist/plugins/hubspot/schema/index.d.ts +8 -8
  112. package/dist/plugins/hubspot/webhooks/index.d.ts +144 -12
  113. package/dist/plugins/hubspot/webhooks/index.d.ts.map +1 -1
  114. package/dist/plugins/hubspot/webhooks/types.d.ts +855 -45
  115. package/dist/plugins/hubspot/webhooks/types.d.ts.map +1 -1
  116. package/dist/plugins/hubspot/webhooks/types.js +104 -0
  117. package/dist/plugins/linear/endpoints/index.d.ts +120 -120
  118. package/dist/plugins/linear/endpoints/types.d.ts +634 -2347
  119. package/dist/plugins/linear/endpoints/types.d.ts.map +1 -1
  120. package/dist/plugins/linear/endpoints/types.js +0 -23
  121. package/dist/plugins/linear/index.d.ts +6088 -11
  122. package/dist/plugins/linear/index.d.ts.map +1 -1
  123. package/dist/plugins/linear/index.js +124 -2
  124. package/dist/plugins/linear/schema/database.d.ts +10 -10
  125. package/dist/plugins/linear/schema/index.d.ts +10 -10
  126. package/dist/plugins/linear/webhooks/index.d.ts +619 -9
  127. package/dist/plugins/linear/webhooks/index.d.ts.map +1 -1
  128. package/dist/plugins/linear/webhooks/types.d.ts +2809 -115
  129. package/dist/plugins/linear/webhooks/types.d.ts.map +1 -1
  130. package/dist/plugins/linear/webhooks/types.js +196 -0
  131. package/dist/plugins/posthog/endpoints/types.d.ts +0 -139
  132. package/dist/plugins/posthog/endpoints/types.d.ts.map +1 -1
  133. package/dist/plugins/posthog/endpoints/types.js +0 -10
  134. package/dist/plugins/posthog/index.d.ts +161 -3
  135. package/dist/plugins/posthog/index.d.ts.map +1 -1
  136. package/dist/plugins/posthog/index.js +44 -5
  137. package/dist/plugins/posthog/webhooks/index.d.ts +29 -1
  138. package/dist/plugins/posthog/webhooks/index.d.ts.map +1 -1
  139. package/dist/plugins/posthog/webhooks/types.d.ts +96 -15
  140. package/dist/plugins/posthog/webhooks/types.d.ts.map +1 -1
  141. package/dist/plugins/posthog/webhooks/types.js +25 -0
  142. package/dist/plugins/resend/endpoints/index.d.ts +6 -6
  143. package/dist/plugins/resend/endpoints/types.d.ts +18 -336
  144. package/dist/plugins/resend/endpoints/types.d.ts.map +1 -1
  145. package/dist/plugins/resend/endpoints/types.js +0 -13
  146. package/dist/plugins/resend/index.d.ts +456 -12
  147. package/dist/plugins/resend/index.d.ts.map +1 -1
  148. package/dist/plugins/resend/index.js +105 -6
  149. package/dist/plugins/resend/schema/database.d.ts +2 -2
  150. package/dist/plugins/resend/schema/index.d.ts +2 -2
  151. package/dist/plugins/resend/webhooks/index.d.ts +252 -10
  152. package/dist/plugins/resend/webhooks/index.d.ts.map +1 -1
  153. package/dist/plugins/resend/webhooks/types.d.ts +971 -70
  154. package/dist/plugins/resend/webhooks/types.d.ts.map +1 -1
  155. package/dist/plugins/resend/webhooks/types.js +185 -0
  156. package/dist/plugins/slack/endpoints/index.d.ts +8 -8
  157. package/dist/plugins/slack/endpoints/types.d.ts +16 -17339
  158. package/dist/plugins/slack/endpoints/types.d.ts.map +1 -1
  159. package/dist/plugins/slack/endpoints/types.js +0 -47
  160. package/dist/plugins/slack/index.d.ts +17553 -10
  161. package/dist/plugins/slack/index.d.ts.map +1 -1
  162. package/dist/plugins/slack/index.js +220 -2
  163. package/dist/plugins/slack/schema/database.d.ts +48 -48
  164. package/dist/plugins/slack/schema/index.d.ts +48 -48
  165. package/dist/plugins/slack/webhooks/index.d.ts +449 -8
  166. package/dist/plugins/slack/webhooks/index.d.ts.map +1 -1
  167. package/dist/plugins/slack/webhooks/types.d.ts +5461 -469
  168. package/dist/plugins/slack/webhooks/types.d.ts.map +1 -1
  169. package/dist/plugins/slack/webhooks/types.js +605 -0
  170. package/dist/plugins/spotify/api.test.js +14 -2
  171. package/dist/plugins/spotify/endpoints/albums.d.ts.map +1 -1
  172. package/dist/plugins/spotify/endpoints/artists.d.ts.map +1 -1
  173. package/dist/plugins/spotify/endpoints/index.d.ts +4 -4
  174. package/dist/plugins/spotify/endpoints/index.js +4 -4
  175. package/dist/plugins/spotify/endpoints/library.d.ts.map +1 -1
  176. package/dist/plugins/spotify/endpoints/my-data.d.ts.map +1 -1
  177. package/dist/plugins/spotify/endpoints/player.d.ts.map +1 -1
  178. package/dist/plugins/spotify/endpoints/playlists.d.ts.map +1 -1
  179. package/dist/plugins/spotify/endpoints/playlists.js +1 -1
  180. package/dist/plugins/spotify/endpoints/tracks.d.ts.map +1 -1
  181. package/dist/plugins/spotify/endpoints/types.d.ts +30 -30
  182. package/dist/plugins/spotify/endpoints/types.d.ts.map +1 -1
  183. package/dist/plugins/spotify/index.d.ts +5612 -4
  184. package/dist/plugins/spotify/index.d.ts.map +1 -1
  185. package/dist/plugins/spotify/index.js +239 -3
  186. package/dist/plugins/spotify/schema/database.d.ts +6 -6
  187. package/dist/plugins/spotify/schema/index.d.ts +6 -6
  188. package/dist/plugins/spotify/webhooks/example.d.ts.map +1 -1
  189. package/dist/plugins/spotify/webhooks/index.d.ts +17 -1
  190. package/dist/plugins/spotify/webhooks/index.d.ts.map +1 -1
  191. package/dist/plugins/spotify/webhooks/types.d.ts +50 -49
  192. package/dist/plugins/spotify/webhooks/types.d.ts.map +1 -1
  193. package/dist/plugins/spotify/webhooks/types.js +48 -31
  194. package/dist/plugins/tavily/endpoints/index.d.ts +1 -1
  195. package/dist/plugins/tavily/endpoints/types.d.ts +6 -6
  196. package/dist/plugins/tavily/index.d.ts +7 -1
  197. package/dist/plugins/tavily/index.d.ts.map +1 -1
  198. package/dist/templates/plugin/generate.js +18 -13
  199. package/package.json +1 -1
@@ -1,11 +1,11 @@
1
1
  import type { ZodTypeAny } from 'zod';
2
2
  import type { CorsairDatabase } from '../../db/kysely/database';
3
- import { type CorsairInspectMethods } from '../inspect';
4
3
  import type { CorsairPluginSchema, PluginEntityClients } from '../../db/orm';
5
4
  import type { AccountKeyManagerFor, IntegrationKeyManagerFor, PluginAuthConfig } from '../auth/types';
6
5
  import type { AuthTypes } from '../constants';
7
6
  import type { BindEndpoints, EndpointTree } from '../endpoints';
8
7
  import type { CorsairErrorHandler } from '../errors';
8
+ import type { CorsairInspectMethods } from '../inspect';
9
9
  import type { CorsairPlugin } from '../plugins';
10
10
  import type { BindWebhooks, RawWebhookRequest, WebhookTree } from '../webhooks';
11
11
  /**
@@ -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,EAEN,KAAK,qBAAqB,EAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACX,mBAAmB,EAEnB,mBAAmB,EACnB,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EACX,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAEX,aAA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IACtC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,iBAAiB,CAAC,EAAE,mBAAmB,CAAC;IACxC,iGAAiG;IACjG,cAAc,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,GAAG,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,CAoKxB;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,7 +1,7 @@
1
1
  import { createKyselyEntityClient } from '../../db/kysely/orm';
2
- import { buildInspectMethods, } from '../inspect';
3
2
  import { createAccountKeyManager, createIntegrationKeyManager, } from '../auth/key-manager';
4
3
  import { bindEndpointsRecursively } from '../endpoints/bind';
4
+ import { buildInspectMethods } from '../inspect';
5
5
  import { bindWebhooksRecursively } from '../webhooks/bind';
6
6
  // ─────────────────────────────────────────────────────────────────────────────
7
7
  // Account ID Resolver
@@ -79,7 +79,7 @@ function createEntityClient(database, getAccountId, entityTypeName, version, dat
79
79
  * @returns A fully configured Corsair client with account-level keys
80
80
  */
81
81
  export function buildCorsairClient(plugins, options) {
82
- const { database, tenantId, kek, rootErrorHandlers, approvalConfig, } = options;
82
+ const { database, tenantId, kek, rootErrorHandlers, approvalConfig } = options;
83
83
  const apiUnsafe = {};
84
84
  const pluginEntitiesUnsafe = {};
85
85
  for (const plugin of plugins) {
@@ -1 +1 @@
1
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S,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,CA2JP"}
@@ -33,9 +33,10 @@ export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId
33
33
  const operationPath = [...currentPath, key].join('.');
34
34
  const boundFn = async (args) => {
35
35
  // ── Permission guard ────────────────────────────────────────────────────────────────
36
+ let onPermissionComplete;
36
37
  if (permissionsConfig) {
37
38
  const meta = endpointMeta?.[operationPath];
38
- const permResult = await enforcePermission({
39
+ const { result: permResult, onComplete } = await enforcePermission({
39
40
  pluginId,
40
41
  endpointPath: operationPath,
41
42
  args,
@@ -51,6 +52,7 @@ export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId
51
52
  });
52
53
  if (permResult === 'blocked')
53
54
  return null;
55
+ onPermissionComplete = onComplete;
54
56
  }
55
57
  const call = async (attemptNumber, callCtx, callArgs) => {
56
58
  try {
@@ -105,24 +107,25 @@ export function bindEndpointsRecursively({ endpoints, hooks, ctx, tree, pluginId
105
107
  };
106
108
  const key = keyBuilder ? await keyBuilder(ctx, 'endpoint') : undefined;
107
109
  if (!endpointHooks?.before && !endpointHooks?.after) {
108
- return call(0, { ...ctx, key }, args);
109
- }
110
- return (async () => {
111
- const ctxWithKey = { ...ctx, key };
112
- const beforeResult = endpointHooks.before
113
- ? await endpointHooks.before(ctxWithKey, args)
114
- : {
115
- ctx: ctxWithKey,
116
- args,
117
- continue: true,
118
- passToAfter: undefined,
119
- };
120
- if (beforeResult.continue === false)
121
- return;
122
- const res = await call(0, beforeResult.ctx, beforeResult.args);
123
- await endpointHooks.after?.(beforeResult.ctx, res, beforeResult.passToAfter);
110
+ const res = await call(0, { ...ctx, key }, args);
111
+ await onPermissionComplete?.();
124
112
  return res;
125
- })();
113
+ }
114
+ const ctxWithKey = { ...ctx, key };
115
+ const beforeResult = endpointHooks.before
116
+ ? await endpointHooks.before(ctxWithKey, args)
117
+ : {
118
+ ctx: ctxWithKey,
119
+ args,
120
+ continue: true,
121
+ passToAfter: undefined,
122
+ };
123
+ if (beforeResult.continue === false)
124
+ return;
125
+ const res = await call(0, beforeResult.ctx, beforeResult.args);
126
+ await endpointHooks.after?.(beforeResult.ctx, res, beforeResult.passToAfter);
127
+ await onPermissionComplete?.();
128
+ return res;
126
129
  };
127
130
  tree[key] = boundFn;
128
131
  }
@@ -34,12 +34,12 @@ export declare function createCorsair<const Plugins extends readonly CorsairPlug
34
34
  export type { AccountFieldNames, AccountKeyManagerFor, BaseAuthFieldConfig, BaseKeyManager, IntegrationFieldNames, IntegrationKeyManagerFor, OAuth2IntegrationCredentials, PluginAuthConfig, } from './auth';
35
35
  export { BASE_AUTH_FIELDS, createAccountKeyManager, createIntegrationKeyManager, decryptConfig, decryptDEK, decryptWithDEK, encryptConfig, encryptDEK, encryptWithDEK, generateDEK, initializeAccountDEK, initializeIntegrationDEK, reEncryptConfig, } from './auth';
36
36
  export type { CorsairClient, CorsairSingleTenantClient, CorsairTenantWrapper, } from './client';
37
- export type { CorsairInspectMethods, EndpointSchemaResult } from './inspect';
38
37
  export type { AllProviders, AuthTypes, BaseProviders } from './constants';
39
38
  export type { BindEndpoints, BoundEndpointFn, BoundEndpointTree, CorsairContext, CorsairEndpoint, EndpointPathsOf, EndpointTree, } from './endpoints';
40
39
  export type { CorsairErrorHandler, ErrorContext, ErrorHandler, ErrorHandlerAndMatchFunction, ErrorMatcher, RetryStrategies, RetryStrategy, } from './errors';
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';
40
+ export type { CorsairInspectMethods, EndpointSchemaResult } from './inspect';
41
+ export type { EnforcePermissionOptions, EnforcePermissionResult } from './permissions';
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
- export type { BindWebhooks, BoundWebhook, BoundWebhookTree, CorsairWebhook, CorsairWebhookHandler, CorsairWebhookMatcher, RawWebhookRequest, WebhookRequest, WebhookResponse, WebhookTree, } from './webhooks';
44
+ export type { BindWebhooks, BoundWebhook, BoundWebhookTree, CorsairWebhook, CorsairWebhookHandler, CorsairWebhookMatcher, RawWebhookRequest, WebhookPathsOf, WebhookRequest, WebhookResponse, WebhookTree, } from './webhooks';
45
45
  //# sourceMappingURL=index.d.ts.map
@@ -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,a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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,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAGvF,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"}
@@ -16,6 +16,24 @@ export type EndpointSchemaResult = {
16
16
  */
17
17
  availableMethods?: Record<string, string[]>;
18
18
  };
19
+ export type WebhookSchemaResult = {
20
+ /** Human-readable description of what triggers this webhook. */
21
+ description?: string;
22
+ /** JSON Schema for the webhook payload — the type of `request.payload` in the before hook. */
23
+ payload?: unknown;
24
+ /** JSON Schema for the webhook response data — the type of `response.data` in the after hook. */
25
+ response?: unknown;
26
+ /**
27
+ * Ready-to-copy code example showing exactly how to configure this webhook,
28
+ * including response.data type as an inline comment.
29
+ */
30
+ usage?: string;
31
+ /**
32
+ * Present when the requested webhook path was not found.
33
+ * Lists all available webhook dot-paths per plugin so the caller can self-correct.
34
+ */
35
+ availableWebhooks?: Record<string, string[]>;
36
+ };
19
37
  export type CorsairInspectMethods = {
20
38
  /**
21
39
  * Returns all available endpoint paths for every registered plugin.
@@ -52,10 +70,66 @@ export type CorsairInspectMethods = {
52
70
  * // { availableMethods: { slack: ['slack.api.channels.list', ...], ... } }
53
71
  */
54
72
  get_schema(method: string): EndpointSchemaResult;
73
+ /**
74
+ * Returns all available webhook paths for every registered plugin.
75
+ * Keys are plugin IDs, values are arrays of full dot-paths (pluginId.group.event).
76
+ * Pass a path directly to get_webhook_schema() to get its usage example and type info.
77
+ *
78
+ * @example
79
+ * corsair.get_webhooks()
80
+ * // {
81
+ * // slack: ['slack.messages.message', 'slack.channels.created', ...],
82
+ * // googlecalendar: ['googlecalendar.onEventChanged', 'googlecalendar.onEventCreated', ...],
83
+ * // }
84
+ */
85
+ get_webhooks(): Record<string, string[]>;
86
+ /**
87
+ * Returns all available webhook paths for a specific plugin.
88
+ *
89
+ * @example
90
+ * corsair.get_webhooks('slack')
91
+ * // ['slack.messages.message', 'slack.channels.created', ...]
92
+ */
93
+ get_webhooks(plugin: string): string[];
94
+ /**
95
+ * Returns a ready-to-copy usage example plus type information for a specific webhook.
96
+ * Pass the dot-path from get_webhooks(): 'slack.messages.message'.
97
+ * Casing is ignored — the path is lowercased before lookup.
98
+ *
99
+ * The `usage` field is a complete code snippet showing how to configure this webhook
100
+ * inside the plugin options, with the response.data type embedded as an inline comment.
101
+ *
102
+ * If the webhook path is not found, returns `availableWebhooks` for self-correction.
103
+ *
104
+ * @example
105
+ * corsair.get_webhook_schema('slack.messages.message')
106
+ * // {
107
+ * // description: 'Fires when a message is posted',
108
+ * // usage: `
109
+ * // slack({
110
+ * // webhookHooks: {
111
+ * // messages: {
112
+ * // message: {
113
+ * // before(ctx, args) {
114
+ * // return { ctx, args };
115
+ * // },
116
+ * // after(ctx, response) {
117
+ * // // response.data:
118
+ * // // { "type": "object", ... }
119
+ * // },
120
+ * // },
121
+ * // },
122
+ * // },
123
+ * // })`,
124
+ * // payload: { ... },
125
+ * // response: { ... },
126
+ * // }
127
+ */
128
+ get_webhook_schema(webhook: string): WebhookSchemaResult;
55
129
  };
56
130
  /**
57
- * Creates the get_methods / get_schema functions bound to a specific plugin list.
58
- * Used by both single-tenant and multi-tenant client builders.
131
+ * Creates the get_methods / get_schema / get_webhooks / get_webhook_schema functions
132
+ * bound to a specific plugin list. Used by both single-tenant and multi-tenant client builders.
59
133
  */
60
134
  export declare function buildInspectMethods(plugins: readonly CorsairPlugin[]): CorsairInspectMethods;
61
135
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC;CACjD,CAAC;AA+GF;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,SAAS,aAAa,EAAE,GAC/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AAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACzC;;;;;;OAMG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAAC;CACzD,CAAC;AAkUF;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,SAAS,aAAa,EAAE,GAC/B,qBAAqB,CAgBvB"}
@@ -45,8 +45,10 @@ function zodToJsonSchema(schema) {
45
45
  const required = [];
46
46
  for (const [key, val] of Object.entries(shape)) {
47
47
  properties[key] = zodToJsonSchema(val);
48
- const fieldTypeName = val._def.typeName;
49
- if (fieldTypeName !== 'ZodOptional' && fieldTypeName !== 'ZodNullable') {
48
+ const fieldTypeName = val._def
49
+ .typeName;
50
+ if (fieldTypeName !== 'ZodOptional' &&
51
+ fieldTypeName !== 'ZodNullable') {
50
52
  required.push(key);
51
53
  }
52
54
  }
@@ -86,6 +88,108 @@ function walkEndpointTree(tree, pathParts, result) {
86
88
  }
87
89
  }
88
90
  // ─────────────────────────────────────────────────────────────────────────────
91
+ // Webhook Tree Helpers
92
+ // ─────────────────────────────────────────────────────────────────────────────
93
+ /**
94
+ * Returns true if a value is a webhook leaf (has both `match` and `handler` functions).
95
+ * Mirrors the isWebhook guard in core/webhooks/bind.ts without importing it.
96
+ */
97
+ function isWebhookLeaf(value) {
98
+ return (value !== null &&
99
+ typeof value === 'object' &&
100
+ 'match' in value &&
101
+ 'handler' in value &&
102
+ typeof value.match === 'function' &&
103
+ typeof value.handler === 'function');
104
+ }
105
+ /**
106
+ * Recursively collects all webhook leaf paths in a webhook tree.
107
+ * Preserves original key casing so paths can be used as object keys in webhookHooks config.
108
+ */
109
+ function walkWebhookTree(tree, pathParts, result) {
110
+ for (const [key, value] of Object.entries(tree)) {
111
+ const current = [...pathParts, key];
112
+ if (isWebhookLeaf(value)) {
113
+ result.push(current.join('.'));
114
+ }
115
+ else if (value !== null && typeof value === 'object') {
116
+ walkWebhookTree(value, current, result);
117
+ }
118
+ }
119
+ }
120
+ /**
121
+ * Walks a webhook tree with a normalised (lowercased) path and returns the original-cased
122
+ * key segments when found. Used to reconstruct the exact key names for usage examples.
123
+ * Returns null if the path does not resolve to a webhook leaf.
124
+ */
125
+ function resolveWebhookPathOriginalCase(tree, normalizedParts) {
126
+ if (normalizedParts.length === 0)
127
+ return null;
128
+ const [head, ...tail] = normalizedParts;
129
+ const entry = Object.entries(tree).find(([k]) => k.toLowerCase() === head);
130
+ if (!entry)
131
+ return null;
132
+ const [originalKey, value] = entry;
133
+ if (tail.length === 0) {
134
+ return isWebhookLeaf(value) ? [originalKey] : null;
135
+ }
136
+ if (value !== null && typeof value === 'object' && !isWebhookLeaf(value)) {
137
+ const rest = resolveWebhookPathOriginalCase(value, tail);
138
+ if (rest !== null)
139
+ return [originalKey, ...rest];
140
+ }
141
+ return null;
142
+ }
143
+ // ─────────────────────────────────────────────────────────────────────────────
144
+ // Webhook Usage Example Builder
145
+ // ─────────────────────────────────────────────────────────────────────────────
146
+ /**
147
+ * Builds a ready-to-copy code snippet showing how to configure a specific webhook.
148
+ * The response.data type (if available) is embedded as an inline comment inside the after hook.
149
+ *
150
+ * @param pluginId Plugin ID (e.g. 'slack')
151
+ * @param pathParts Original-cased path segments (e.g. ['messages', 'message'])
152
+ * @param responseSchema JSON Schema for response.data, or null if no schema registered
153
+ */
154
+ function buildWebhookUsageExample(pluginId, pathParts, responseSchema) {
155
+ const lines = [];
156
+ lines.push(`${pluginId}({`);
157
+ lines.push(` webhookHooks: {`);
158
+ // Open nested key blocks
159
+ for (let i = 0; i < pathParts.length; i++) {
160
+ const indent = ' '.repeat(i + 2);
161
+ lines.push(`${indent}${pathParts[i]}: {`);
162
+ }
163
+ // Hook body — indented one level deeper than the innermost key
164
+ const hookIndent = ' '.repeat(pathParts.length + 2);
165
+ const bodyIndent = hookIndent + ' ';
166
+ lines.push(`${hookIndent}before(ctx, args) {`);
167
+ lines.push(`${bodyIndent}return { ctx, args };`);
168
+ lines.push(`${hookIndent}},`);
169
+ lines.push(`${hookIndent}after(ctx, response) {`);
170
+ if (responseSchema !== null) {
171
+ const json = JSON.stringify(responseSchema, null, 2);
172
+ const commentLines = json
173
+ .split('\n')
174
+ .map((l, i) => i === 0
175
+ ? `${bodyIndent}// response.data: ${l}`
176
+ : `${bodyIndent}// ${l}`);
177
+ lines.push(...commentLines);
178
+ }
179
+ else {
180
+ lines.push(`${bodyIndent}// response.data: unknown (register webhookSchemas to see the type)`);
181
+ }
182
+ lines.push(`${hookIndent}},`);
183
+ // Close nested key blocks (innermost first)
184
+ for (let i = pathParts.length - 1; i >= 0; i--) {
185
+ const indent = ' '.repeat(i + 2);
186
+ lines.push(`${indent}},`);
187
+ }
188
+ lines.push(` },`);
189
+ lines.push(`})`);
190
+ return lines.join('\n');
191
+ }
192
+ // ─────────────────────────────────────────────────────────────────────────────
89
193
  // Core Functions
90
194
  // ─────────────────────────────────────────────────────────────────────────────
91
195
  function getMethods(plugins, plugin) {
@@ -107,6 +211,25 @@ function getMethods(plugins, plugin) {
107
211
  }
108
212
  return result;
109
213
  }
214
+ function getWebhooks(plugins, plugin) {
215
+ if (plugin !== undefined) {
216
+ const found = plugins.find((p) => p.id === plugin);
217
+ if (!found?.webhooks)
218
+ return [];
219
+ const paths = [];
220
+ walkWebhookTree(found.webhooks, [], paths);
221
+ return paths.map((path) => `${found.id}.${path}`);
222
+ }
223
+ const result = {};
224
+ for (const p of plugins) {
225
+ if (!p.webhooks)
226
+ continue;
227
+ const paths = [];
228
+ walkWebhookTree(p.webhooks, [], paths);
229
+ result[p.id] = paths.map((path) => `${p.id}.${path}`);
230
+ }
231
+ return result;
232
+ }
110
233
  /**
111
234
  * Case-insensitive lookup in an endpoint record (endpointMeta or endpointSchemas).
112
235
  * Keys in those records use camelCase (e.g. 'channels.getHistory') while the
@@ -151,12 +274,46 @@ function getSchema(plugins, method) {
151
274
  // Invalid or unknown method — return all available methods so the caller can self-correct
152
275
  return { availableMethods: getMethods(plugins) };
153
276
  }
277
+ function getWebhookSchema(plugins, webhook) {
278
+ // Normalise casing so the agent can call with any capitalisation
279
+ const normalised = webhook.toLowerCase();
280
+ const dotIndex = normalised.indexOf('.');
281
+ if (dotIndex !== -1) {
282
+ const pluginId = normalised.slice(0, dotIndex);
283
+ const webhookPathNormalised = normalised.slice(dotIndex + 1);
284
+ const plugin = plugins.find((p) => p.id === pluginId);
285
+ if (plugin?.webhooks) {
286
+ // Resolve original-cased key segments from the webhook tree
287
+ const originalPathParts = resolveWebhookPathOriginalCase(plugin.webhooks, webhookPathNormalised.split('.'));
288
+ if (originalPathParts !== null) {
289
+ // Look up optional schemas using original-cased path (case-insensitive fallback)
290
+ const originalPath = originalPathParts.join('.');
291
+ const schemas = findEndpointCaseInsensitive(plugin.webhookSchemas, originalPath.toLowerCase());
292
+ const responseSchema = schemas?.response
293
+ ? zodToJsonSchema(schemas.response)
294
+ : null;
295
+ return {
296
+ description: schemas?.description,
297
+ payload: schemas?.payload
298
+ ? zodToJsonSchema(schemas.payload)
299
+ : undefined,
300
+ response: responseSchema ?? undefined,
301
+ usage: buildWebhookUsageExample(pluginId, originalPathParts, responseSchema),
302
+ };
303
+ }
304
+ }
305
+ }
306
+ // Invalid or unknown webhook — return all available webhooks so the caller can self-correct
307
+ return {
308
+ availableWebhooks: getWebhooks(plugins),
309
+ };
310
+ }
154
311
  // ─────────────────────────────────────────────────────────────────────────────
155
312
  // Factory — binds inspect methods to a fixed plugin list
156
313
  // ─────────────────────────────────────────────────────────────────────────────
157
314
  /**
158
- * Creates the get_methods / get_schema functions bound to a specific plugin list.
159
- * Used by both single-tenant and multi-tenant client builders.
315
+ * Creates the get_methods / get_schema / get_webhooks / get_webhook_schema functions
316
+ * bound to a specific plugin list. Used by both single-tenant and multi-tenant client builders.
160
317
  */
161
318
  export function buildInspectMethods(plugins) {
162
319
  return {
@@ -166,5 +323,11 @@ export function buildInspectMethods(plugins) {
166
323
  get_schema(method) {
167
324
  return getSchema(plugins, method);
168
325
  },
326
+ get_webhooks(plugin) {
327
+ return getWebhooks(plugins, plugin);
328
+ },
329
+ get_webhook_schema(webhook) {
330
+ return getWebhookSchema(plugins, webhook);
331
+ },
169
332
  };
170
333
  }
@@ -17,13 +17,28 @@ export type EnforcePermissionOptions = {
17
17
  db?: CorsairDatabase;
18
18
  timeoutMs?: number;
19
19
  };
20
+ export type EnforcePermissionResult = {
21
+ result: 'allow' | 'blocked';
22
+ /**
23
+ * Called by the endpoint binding layer after the endpoint executes successfully.
24
+ * Marks the permission record as 'completed' (single-use approval consumed).
25
+ * Only present when an 'approved' record was found and the call is allowed through.
26
+ */
27
+ onComplete?: () => Promise<void>;
28
+ };
20
29
  /**
21
30
  * Evaluates the permission policy and returns whether the action is allowed.
22
31
  *
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)
32
+ * Lifecycle:
33
+ * - `'allow'` policy permits, caller proceeds normally
34
+ * - `'deny'` blocked by policy mode; no DB record created
35
+ * - `'require_approval'` checks for an existing matching permission record first:
36
+ * - `pending` (not expired) → already waiting for approval, returns 'blocked'
37
+ * - `approved` (not expired) → approved and ready; returns 'allow' + onComplete callback
38
+ * that marks the record 'completed' after the endpoint runs
39
+ * - otherwise → creates a new 'pending' record, returns 'blocked'
40
+ *
41
+ * Falls back to deny if no database is configured.
27
42
  */
28
- export declare function enforcePermission(opts: EnforcePermissionOptions): Promise<'allow' | 'blocked'>;
43
+ export declare function enforcePermission(opts: EnforcePermissionOptions): Promise<EnforcePermissionResult>;
29
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../core/permissions/index.ts"],"names":[],"mappings":"AAEA,OAAO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B,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,MAAM,MAAM,uBAAuB,GAAG;IACrC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACtC,IAAI,EAAE,wBAAwB,GAC5B,OAAO,CAAC,uBAAuB,CAAC,CA4FlC"}
@@ -45,24 +45,64 @@ export function parseDurationMs(duration) {
45
45
  /**
46
46
  * Evaluates the permission policy and returns whether the action is allowed.
47
47
  *
48
- * - `'allow'` → returns 'allow', caller proceeds normally
49
- * - `'deny'` logs a blocked message, returns 'blocked'
50
- * - `'require_approval'` creates a `corsair_permissions` record, logs the token, returns 'blocked'
51
- * (falls back to deny if no database is configured)
48
+ * Lifecycle:
49
+ * - `'allow'` policy permits, caller proceeds normally
50
+ * - `'deny'` blocked by policy mode; no DB record created
51
+ * - `'require_approval'` checks for an existing matching permission record first:
52
+ * - `pending` (not expired) → already waiting for approval, returns 'blocked'
53
+ * - `approved` (not expired) → approved and ready; returns 'allow' + onComplete callback
54
+ * that marks the record 'completed' after the endpoint runs
55
+ * - otherwise → creates a new 'pending' record, returns 'blocked'
56
+ *
57
+ * Falls back to deny if no database is configured.
52
58
  */
53
59
  export async function enforcePermission(opts) {
54
60
  const policy = evaluatePermission(opts.riskLevel, opts.mode, opts.override);
55
61
  if (policy === 'allow')
56
- return 'allow';
62
+ return { result: 'allow' };
57
63
  const irreversibleNote = opts.meta?.irreversible ? ' (irreversible)' : '';
58
64
  const description = opts.meta?.description
59
65
  ? `${opts.meta.description}${irreversibleNote}`
60
66
  : `${opts.pluginId}.${opts.endpointPath}${irreversibleNote}`;
61
67
  if (policy === 'deny' || !opts.db) {
62
68
  console.log(`[corsair/${opts.pluginId}] '${opts.endpointPath}' blocked — denied by permission mode '${opts.mode}'.`, `\n Action: ${description}`, `\n To allow this, update the permission mode or add an override in your corsair config.`);
63
- return 'blocked';
69
+ return { result: 'blocked' };
70
+ }
71
+ const argsJson = JSON.stringify(opts.args);
72
+ const now = new Date().toISOString();
73
+ // Check for an existing, non-expired permission record for this plugin + endpoint + args
74
+ const existing = await opts.db.db
75
+ .selectFrom('corsair_permissions')
76
+ .selectAll()
77
+ .where('plugin', '=', opts.pluginId)
78
+ .where('endpoint', '=', opts.endpointPath)
79
+ .where('args', '=', argsJson)
80
+ .where('expires_at', '>', now)
81
+ .where('status', 'in', ['pending', 'approved'])
82
+ .orderBy('created_at', 'desc')
83
+ .limit(1)
84
+ .executeTakeFirst();
85
+ if (existing) {
86
+ if (existing.status === 'approved') {
87
+ // Single-use: let the call through; onComplete will mark it 'completed'
88
+ const db = opts.db;
89
+ const permissionId = existing.id;
90
+ return {
91
+ result: 'allow',
92
+ onComplete: async () => {
93
+ await db.db
94
+ .updateTable('corsair_permissions')
95
+ .set({ status: 'completed', updated_at: new Date() })
96
+ .where('id', '=', permissionId)
97
+ .execute();
98
+ },
99
+ };
100
+ }
101
+ // status === 'pending': already waiting for approval, don't create a duplicate
102
+ 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.`);
103
+ return { result: 'blocked' };
64
104
  }
65
- // require_approval: create a pending record and log the token
105
+ // No existing actionable record — create a new pending approval request
66
106
  const id = uuidv4();
67
107
  const token = randomBytes(32).toString('hex');
68
108
  const timeoutMs = opts.timeoutMs ?? 10 * 60 * 1_000;
@@ -76,12 +116,11 @@ export async function enforcePermission(opts) {
76
116
  token,
77
117
  plugin: opts.pluginId,
78
118
  endpoint: opts.endpointPath,
79
- // unknown args serialized to JSON; available for inspection or re-execution
80
- args: JSON.stringify(opts.args),
119
+ args: argsJson,
81
120
  status: 'pending',
82
121
  expires_at: expiresAt,
83
122
  })
84
123
  .execute();
85
124
  console.log(`[corsair/${opts.pluginId}] '${opts.endpointPath}' blocked — approval required.`, `\n Action: ${description}`, `\n Permission ID: ${id}`, `\n Permission token: ${token}`, `\n Expires at: ${expiresAt}`, `\n Use the token to approve or deny this request.`);
86
- return 'blocked';
125
+ return { result: 'blocked' };
87
126
  }