corsair 0.1.3 → 0.1.5
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/auth/key-manager.d.ts +5 -5
- package/dist/core/auth/key-manager.d.ts.map +1 -1
- package/dist/core/auth/key-manager.js +85 -67
- package/dist/core/client/index.d.ts +3 -3
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +29 -218
- package/dist/core/constants.d.ts +2 -2
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +4 -0
- package/dist/core/endpoints/index.d.ts +2 -2
- package/dist/core/endpoints/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +10 -6
- package/dist/core/plugins/index.d.ts +3 -3
- package/dist/core/plugins/index.d.ts.map +1 -1
- package/dist/db/index.d.ts +70 -8
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +20 -4
- package/dist/db/kysely/database.d.ts +21 -0
- package/dist/db/kysely/database.d.ts.map +1 -0
- package/dist/db/kysely/database.js +33 -0
- package/dist/db/kysely/orm.d.ts +6 -0
- package/dist/db/kysely/orm.d.ts.map +1 -0
- package/dist/db/kysely/orm.js +334 -0
- package/dist/db/kysely/postgres.d.ts +5 -0
- package/dist/db/kysely/postgres.d.ts.map +1 -0
- package/dist/db/kysely/postgres.js +20 -0
- package/dist/db/kysely/sqlite.d.ts +22 -0
- package/dist/db/kysely/sqlite.d.ts.map +1 -0
- package/dist/db/kysely/sqlite.js +38 -0
- package/dist/db/orm.d.ts +375 -32
- package/dist/db/orm.d.ts.map +1 -1
- package/dist/db/orm.js +176 -332
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/plugins/github/endpoints/index.d.ts +130 -130
- package/dist/plugins/github/endpoints/types.d.ts +574 -574
- package/dist/plugins/github/endpoints/types.js +29 -29
- package/dist/plugins/github/integration.test.js +50 -76
- package/dist/plugins/github/schema/database.d.ts +121 -121
- package/dist/plugins/github/schema/database.js +17 -17
- package/dist/plugins/github/schema/index.d.ts +121 -121
- package/dist/plugins/gmail/api.test.js +1 -1
- package/dist/plugins/gmail/endpoints/drafts.d.ts.map +1 -1
- package/dist/plugins/gmail/endpoints/drafts.js +2 -2
- package/dist/plugins/gmail/endpoints/index.d.ts.map +1 -1
- package/dist/plugins/gmail/endpoints/labels.js +2 -2
- package/dist/plugins/gmail/endpoints/messages.d.ts.map +1 -1
- package/dist/plugins/gmail/endpoints/messages.js +22 -13
- package/dist/plugins/gmail/endpoints/threads.d.ts.map +1 -1
- package/dist/plugins/gmail/endpoints/threads.js +11 -7
- package/dist/plugins/gmail/endpoints/types.d.ts +128 -128
- package/dist/plugins/gmail/endpoints/types.js +1 -1
- package/dist/plugins/gmail/index.d.ts +4 -3
- package/dist/plugins/gmail/index.d.ts.map +1 -1
- package/dist/plugins/gmail/index.js +1 -1
- package/dist/plugins/gmail/integration.test.js +33 -29
- package/dist/plugins/gmail/schema/database.d.ts +14 -14
- package/dist/plugins/gmail/schema/database.js +4 -4
- package/dist/plugins/gmail/schema/index.d.ts +67 -49
- package/dist/plugins/gmail/schema/index.d.ts.map +1 -1
- package/dist/plugins/gmail/schema/index.js +7 -0
- package/dist/plugins/gmail/webhooks/index.d.ts +3 -64
- package/dist/plugins/gmail/webhooks/index.d.ts.map +1 -1
- package/dist/plugins/gmail/webhooks/messages.d.ts +4 -76
- package/dist/plugins/gmail/webhooks/messages.d.ts.map +1 -1
- package/dist/plugins/gmail/webhooks/messages.js +4 -49
- package/dist/plugins/gmail/webhooks/types.d.ts +3 -0
- package/dist/plugins/gmail/webhooks/types.d.ts.map +1 -1
- package/dist/plugins/gmail/webhooks/types.js +19 -1
- package/dist/plugins/googlecalendar/api.test.d.ts +2 -0
- package/dist/plugins/googlecalendar/api.test.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/api.test.js +134 -0
- package/dist/plugins/googlecalendar/client.d.ts +16 -0
- package/dist/plugins/googlecalendar/client.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/client.js +81 -0
- package/dist/plugins/googlecalendar/endpoints/calendar.d.ts +3 -0
- package/dist/plugins/googlecalendar/endpoints/calendar.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/endpoints/calendar.js +17 -0
- package/dist/plugins/googlecalendar/endpoints/events.d.ts +7 -0
- package/dist/plugins/googlecalendar/endpoints/events.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/endpoints/events.js +136 -0
- package/dist/plugins/googlecalendar/endpoints/index.d.ts +62 -0
- package/dist/plugins/googlecalendar/endpoints/index.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/endpoints/index.js +13 -0
- package/dist/plugins/googlecalendar/endpoints/types.d.ts +1525 -0
- package/dist/plugins/googlecalendar/endpoints/types.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/endpoints/types.js +120 -0
- package/dist/plugins/googlecalendar/index.d.ts +159 -0
- package/dist/plugins/googlecalendar/index.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/index.js +67 -0
- package/dist/plugins/googlecalendar/integration.test.d.ts +2 -0
- package/dist/plugins/googlecalendar/integration.test.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/integration.test.js +149 -0
- package/dist/plugins/googlecalendar/schema/database.d.ts +333 -0
- package/dist/plugins/googlecalendar/schema/database.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/schema/database.js +78 -0
- package/dist/plugins/googlecalendar/schema/index.d.ts +335 -0
- package/dist/plugins/googlecalendar/schema/index.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/schema/index.js +8 -0
- package/dist/plugins/googlecalendar/types.d.ts +182 -0
- package/dist/plugins/googlecalendar/types.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/webhooks/events.d.ts +7 -0
- package/dist/plugins/googlecalendar/webhooks/events.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/webhooks/events.js +310 -0
- package/dist/plugins/googlecalendar/webhooks/index.d.ts +24 -0
- package/dist/plugins/googlecalendar/webhooks/index.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/webhooks/index.js +9 -0
- package/dist/plugins/googlecalendar/webhooks/types.d.ts +71 -0
- package/dist/plugins/googlecalendar/webhooks/types.d.ts.map +1 -0
- package/dist/plugins/googlecalendar/webhooks/types.js +34 -0
- package/dist/plugins/googledrive/api.test.d.ts +2 -0
- package/dist/plugins/googledrive/api.test.d.ts.map +1 -0
- package/dist/plugins/googledrive/api.test.js +473 -0
- package/dist/plugins/googledrive/client.d.ts +16 -0
- package/dist/plugins/googledrive/client.d.ts.map +1 -0
- package/dist/plugins/googledrive/client.js +81 -0
- package/dist/plugins/googledrive/endpoints/files.d.ts +12 -0
- package/dist/plugins/googledrive/endpoints/files.d.ts.map +1 -0
- package/dist/plugins/googledrive/endpoints/files.js +245 -0
- package/dist/plugins/googledrive/endpoints/folders.d.ts +7 -0
- package/dist/plugins/googledrive/endpoints/folders.d.ts.map +1 -0
- package/dist/plugins/googledrive/endpoints/folders.js +130 -0
- package/dist/plugins/googledrive/endpoints/index.d.ts +193 -0
- package/dist/plugins/googledrive/endpoints/index.d.ts.map +1 -0
- package/dist/plugins/googledrive/endpoints/index.js +34 -0
- package/dist/plugins/googledrive/endpoints/search.d.ts +3 -0
- package/dist/plugins/googledrive/endpoints/search.d.ts.map +1 -0
- package/dist/plugins/googledrive/endpoints/search.js +49 -0
- package/dist/plugins/googledrive/endpoints/sharedDrives.d.ts +7 -0
- package/dist/plugins/googledrive/endpoints/sharedDrives.d.ts.map +1 -0
- package/dist/plugins/googledrive/endpoints/sharedDrives.js +124 -0
- package/dist/plugins/googledrive/endpoints/types.d.ts +1895 -0
- package/dist/plugins/googledrive/endpoints/types.d.ts.map +1 -0
- package/dist/plugins/googledrive/endpoints/types.js +102 -0
- package/dist/plugins/googledrive/index.d.ts +410 -0
- package/dist/plugins/googledrive/index.d.ts.map +1 -0
- package/dist/plugins/googledrive/index.js +83 -0
- package/dist/plugins/googledrive/integration.test.d.ts +2 -0
- package/dist/plugins/googledrive/integration.test.d.ts.map +1 -0
- package/dist/plugins/googledrive/integration.test.js +139 -0
- package/dist/plugins/googledrive/schema/database.d.ts +545 -0
- package/dist/plugins/googledrive/schema/database.d.ts.map +1 -0
- package/dist/plugins/googledrive/schema/database.js +121 -0
- package/dist/plugins/googledrive/schema/index.d.ts +546 -0
- package/dist/plugins/googledrive/schema/index.d.ts.map +1 -0
- package/dist/plugins/googledrive/schema/index.js +9 -0
- package/dist/plugins/googledrive/types.d.ts +288 -0
- package/dist/plugins/googledrive/types.d.ts.map +1 -0
- package/dist/plugins/googledrive/types.js +1 -0
- package/dist/plugins/googledrive/webhooks/changes.d.ts +4 -0
- package/dist/plugins/googledrive/webhooks/changes.d.ts.map +1 -0
- package/dist/plugins/googledrive/webhooks/changes.js +230 -0
- package/dist/plugins/googledrive/webhooks/index.d.ts +12 -0
- package/dist/plugins/googledrive/webhooks/index.d.ts.map +1 -0
- package/dist/plugins/googledrive/webhooks/index.js +6 -0
- package/dist/plugins/googledrive/webhooks/types.d.ts +49 -0
- package/dist/plugins/googledrive/webhooks/types.d.ts.map +1 -0
- package/dist/plugins/googledrive/webhooks/types.js +19 -0
- package/dist/plugins/googlesheets/api.test.d.ts +2 -0
- package/dist/plugins/googlesheets/api.test.d.ts.map +1 -0
- package/dist/plugins/googlesheets/api.test.js +344 -0
- package/dist/plugins/googlesheets/client.d.ts +16 -0
- package/dist/plugins/googlesheets/client.d.ts.map +1 -0
- package/dist/plugins/googlesheets/client.js +81 -0
- package/dist/plugins/googlesheets/endpoints/index.d.ts +68 -0
- package/dist/plugins/googlesheets/endpoints/index.d.ts.map +1 -0
- package/dist/plugins/googlesheets/endpoints/index.js +17 -0
- package/dist/plugins/googlesheets/endpoints/sheets.d.ts +10 -0
- package/dist/plugins/googlesheets/endpoints/sheets.d.ts.map +1 -0
- package/dist/plugins/googlesheets/endpoints/sheets.js +167 -0
- package/dist/plugins/googlesheets/endpoints/spreadsheets.d.ts +4 -0
- package/dist/plugins/googlesheets/endpoints/spreadsheets.d.ts.map +1 -0
- package/dist/plugins/googlesheets/endpoints/spreadsheets.js +46 -0
- package/dist/plugins/googlesheets/endpoints/types.d.ts +409 -0
- package/dist/plugins/googlesheets/endpoints/types.d.ts.map +1 -0
- package/dist/plugins/googlesheets/endpoints/types.js +56 -0
- package/dist/plugins/googlesheets/index.d.ts +166 -0
- package/dist/plugins/googlesheets/index.d.ts.map +1 -0
- package/dist/plugins/googlesheets/index.js +71 -0
- package/dist/plugins/googlesheets/integration.test.d.ts +2 -0
- package/dist/plugins/googlesheets/integration.test.d.ts.map +1 -0
- package/dist/plugins/googlesheets/integration.test.js +106 -0
- package/dist/plugins/googlesheets/schema/database.d.ts +62 -0
- package/dist/plugins/googlesheets/schema/database.d.ts.map +1 -0
- package/dist/plugins/googlesheets/schema/database.js +22 -0
- package/dist/plugins/googlesheets/schema/index.d.ts +63 -0
- package/dist/plugins/googlesheets/schema/index.d.ts.map +1 -0
- package/dist/plugins/googlesheets/schema/index.js +9 -0
- package/dist/plugins/googlesheets/types.d.ts +687 -0
- package/dist/plugins/googlesheets/types.d.ts.map +1 -0
- package/dist/plugins/googlesheets/types.js +1 -0
- package/dist/plugins/googlesheets/webhooks/index.d.ts +16 -0
- package/dist/plugins/googlesheets/webhooks/index.d.ts.map +1 -0
- package/dist/plugins/googlesheets/webhooks/index.js +7 -0
- package/dist/plugins/googlesheets/webhooks/rows.d.ts +5 -0
- package/dist/plugins/googlesheets/webhooks/rows.d.ts.map +1 -0
- package/dist/plugins/googlesheets/webhooks/rows.js +134 -0
- package/dist/plugins/googlesheets/webhooks/types.d.ts +48 -0
- package/dist/plugins/googlesheets/webhooks/types.d.ts.map +1 -0
- package/dist/plugins/googlesheets/webhooks/types.js +10 -0
- package/dist/plugins/hubspot/endpoints/index.d.ts +100 -100
- package/dist/plugins/hubspot/endpoints/types.d.ts +300 -300
- package/dist/plugins/hubspot/endpoints/types.js +8 -8
- package/dist/plugins/hubspot/integration.test.js +56 -96
- package/dist/plugins/hubspot/schema/database.d.ts +24 -24
- package/dist/plugins/hubspot/schema/database.js +8 -8
- package/dist/plugins/hubspot/schema/index.d.ts +24 -24
- package/dist/plugins/index.d.ts +3 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/linear/endpoints/comments.js +4 -4
- package/dist/plugins/linear/endpoints/index.d.ts +44 -44
- package/dist/plugins/linear/endpoints/projects.js +4 -4
- package/dist/plugins/linear/endpoints/teams.js +4 -4
- package/dist/plugins/linear/endpoints/types.d.ts +756 -756
- package/dist/plugins/linear/endpoints/types.js +76 -76
- package/dist/plugins/linear/integration.test.js +39 -50
- package/dist/plugins/linear/schema/database.d.ts +75 -75
- package/dist/plugins/linear/schema/database.js +25 -25
- package/dist/plugins/linear/schema/index.d.ts +75 -75
- package/dist/plugins/linear/webhooks/comments.d.ts.map +1 -1
- package/dist/plugins/linear/webhooks/comments.js +6 -4
- package/dist/plugins/linear/webhooks/issues.d.ts.map +1 -1
- package/dist/plugins/linear/webhooks/issues.js +26 -4
- package/dist/plugins/linear/webhooks/projects.d.ts.map +1 -1
- package/dist/plugins/linear/webhooks/projects.js +12 -4
- package/dist/plugins/posthog/integration.test.js +15 -17
- package/dist/plugins/posthog/schema/database.d.ts +3 -3
- package/dist/plugins/posthog/schema/database.js +1 -1
- package/dist/plugins/posthog/schema/index.d.ts +3 -3
- package/dist/plugins/resend/endpoints/index.d.ts +6 -6
- package/dist/plugins/resend/endpoints/types.d.ts +28 -28
- package/dist/plugins/resend/endpoints/types.js +3 -3
- package/dist/plugins/resend/integration.test.js +21 -26
- package/dist/plugins/resend/schema/database.d.ts +6 -6
- package/dist/plugins/resend/schema/database.js +2 -2
- package/dist/plugins/resend/schema/index.d.ts +6 -6
- package/dist/plugins/resend/webhooks/domains.d.ts.map +1 -1
- package/dist/plugins/resend/webhooks/domains.js +2 -0
- package/dist/plugins/resend/webhooks/emails.d.ts.map +1 -1
- package/dist/plugins/resend/webhooks/emails.js +2 -0
- package/dist/plugins/slack/integration.test.js +23 -29
- package/dist/plugins/slack/schema/database.d.ts +8 -8
- package/dist/plugins/slack/schema/database.js +2 -2
- package/dist/plugins/slack/schema/index.d.ts +8 -8
- package/dist/plugins/slack/webhooks/reactions.js +1 -1
- package/dist/plugins/utils/events.d.ts +3 -3
- package/dist/plugins/utils/events.d.ts.map +1 -1
- package/dist/plugins/utils/events.js +15 -12
- package/dist/tests/hooks.test.js +8 -8
- package/dist/tests/plugins-test-utils.d.ts +3 -1
- package/dist/tests/plugins-test-utils.d.ts.map +1 -1
- package/dist/tests/plugins-test-utils.js +12 -11
- package/dist/tests/setup-db.d.ts +4 -3
- package/dist/tests/setup-db.d.ts.map +1 -1
- package/dist/tests/setup-db.js +11 -120
- package/dist/tsup.config.d.ts.map +1 -1
- package/dist/tsup.config.js +0 -4
- package/package.json +4 -70
- package/dist/adapters/drizzle/index.d.ts +0 -2
- package/dist/adapters/drizzle/index.d.ts.map +0 -1
- package/dist/adapters/drizzle/index.js +0 -1
- package/dist/adapters/drizzle/postgres.d.ts +0 -34
- package/dist/adapters/drizzle/postgres.d.ts.map +0 -1
- package/dist/adapters/drizzle/postgres.js +0 -227
- package/dist/adapters/index.d.ts +0 -9
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -5
- package/dist/adapters/kysely/index.d.ts +0 -2
- package/dist/adapters/kysely/index.d.ts.map +0 -1
- package/dist/adapters/kysely/index.js +0 -1
- package/dist/adapters/kysely/postgres.d.ts +0 -19
- package/dist/adapters/kysely/postgres.d.ts.map +0 -1
- package/dist/adapters/kysely/postgres.js +0 -138
- package/dist/adapters/prisma/index.d.ts +0 -2
- package/dist/adapters/prisma/index.d.ts.map +0 -1
- package/dist/adapters/prisma/index.js +0 -1
- package/dist/adapters/prisma/postgres.d.ts +0 -17
- package/dist/adapters/prisma/postgres.d.ts.map +0 -1
- package/dist/adapters/prisma/postgres.js +0 -176
- package/dist/adapters/tenant.d.ts +0 -13
- package/dist/adapters/tenant.d.ts.map +0 -1
- package/dist/adapters/tenant.js +0 -95
- package/dist/adapters/types.d.ts +0 -162
- package/dist/adapters/types.d.ts.map +0 -1
- package/dist/tests/drizzle-adapter.test.d.ts +0 -2
- package/dist/tests/drizzle-adapter.test.d.ts.map +0 -1
- package/dist/tests/drizzle-adapter.test.js +0 -534
- package/dist/tests/multi-tenancy.test.d.ts +0 -2
- package/dist/tests/multi-tenancy.test.d.ts.map +0 -1
- package/dist/tests/multi-tenancy.test.js +0 -277
- /package/dist/{adapters → plugins/googlecalendar}/types.js +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CorsairDatabase } from '../../db/kysely/database';
|
|
2
2
|
import type { AuthTypes } from '../constants';
|
|
3
3
|
import type { AccountKeyManagerFor, IntegrationKeyManagerFor } from './types';
|
|
4
4
|
export type IntegrationKeyManagerOptions<T extends AuthTypes> = {
|
|
5
5
|
authType: T;
|
|
6
6
|
integrationName: string;
|
|
7
7
|
kek: string;
|
|
8
|
-
database:
|
|
8
|
+
database: CorsairDatabase;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Creates an integration-level key manager for the given auth type.
|
|
@@ -20,7 +20,7 @@ export type AccountKeyManagerOptions<T extends AuthTypes> = {
|
|
|
20
20
|
integrationName: string;
|
|
21
21
|
tenantId: string;
|
|
22
22
|
kek: string;
|
|
23
|
-
database:
|
|
23
|
+
database: CorsairDatabase;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
26
|
* Creates an account-level key manager for the given auth type.
|
|
@@ -34,10 +34,10 @@ export declare function createAccountKeyManager<T extends AuthTypes>(options: Ac
|
|
|
34
34
|
* Initializes an integration with a new DEK.
|
|
35
35
|
* Call this when creating a new integration or when setting up encryption for the first time.
|
|
36
36
|
*/
|
|
37
|
-
export declare function initializeIntegrationDEK(database:
|
|
37
|
+
export declare function initializeIntegrationDEK(database: CorsairDatabase, integrationName: string, kek: string): Promise<string>;
|
|
38
38
|
/**
|
|
39
39
|
* Initializes an account with a new DEK.
|
|
40
40
|
* Call this when creating a new account or when setting up encryption for the first time.
|
|
41
41
|
*/
|
|
42
|
-
export declare function initializeAccountDEK(database:
|
|
42
|
+
export declare function initializeAccountDEK(database: CorsairDatabase, integrationName: string, tenantId: string, kek: string): Promise<string>;
|
|
43
43
|
//# sourceMappingURL=key-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-manager.d.ts","sourceRoot":"","sources":["../../../core/auth/key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"key-manager.d.ts","sourceRoot":"","sources":["../../../core/auth/key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,OAAO,KAAK,EAEX,oBAAoB,EAEpB,wBAAwB,EACxB,MAAM,SAAS,CAAC;AAkBjB,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,SAAS,IAAI;IAC/D,QAAQ,EAAE,CAAC,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,SAAS,EAC9D,OAAO,EAAE,4BAA4B,CAAC,CAAC,CAAC,GACtC,wBAAwB,CAAC,CAAC,CAAC,CAwE7B;AAMD,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,SAAS,IAAI;IAC3D,QAAQ,EAAE,CAAC,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,SAAS,EAC1D,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAClC,oBAAoB,CAAC,CAAC,CAAC,CAuGzB;AAMD;;;GAGG;AACH,wBAAsB,wBAAwB,CAC7C,QAAQ,EAAE,eAAe,EACzB,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,MAAM,CAAC,CAwBjB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACzC,QAAQ,EAAE,eAAe,EACzB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,MAAM,CAAC,CAqCjB"}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { encryptDEK, generateDEK } from './encryption';
|
|
2
2
|
import { createApiKeyAccountKeyManager, createApiKeyIntegrationKeyManager, createBotTokenAccountKeyManager, createBotTokenIntegrationKeyManager, createOAuth2AccountKeyManager, createOAuth2IntegrationKeyManager, } from './methods';
|
|
3
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
// Integration Key Manager Factory
|
|
5
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
+
const parseConfig = (config) => {
|
|
7
|
+
if (!config)
|
|
8
|
+
return {};
|
|
9
|
+
if (typeof config === 'string') {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(config);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return config;
|
|
18
|
+
};
|
|
3
19
|
/**
|
|
4
20
|
* Creates an integration-level key manager for the given auth type.
|
|
5
21
|
* The returned manager has methods based on the auth type:
|
|
@@ -17,31 +33,32 @@ export function createIntegrationKeyManager(options) {
|
|
|
17
33
|
getIntegration: async () => {
|
|
18
34
|
if (cachedIntegration)
|
|
19
35
|
return cachedIntegration;
|
|
20
|
-
const integration = await database.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
const integration = await database.db
|
|
37
|
+
.selectFrom('corsair_integrations')
|
|
38
|
+
.selectAll()
|
|
39
|
+
.where('name', '=', integrationName)
|
|
40
|
+
.executeTakeFirst();
|
|
24
41
|
if (!integration) {
|
|
25
42
|
throw new Error(`Integration "${integrationName}" not found. Make sure to create the integration first.`);
|
|
26
43
|
}
|
|
27
44
|
cachedIntegration = {
|
|
28
45
|
id: integration.id,
|
|
29
|
-
config: (integration.config
|
|
46
|
+
config: parseConfig(integration.config),
|
|
30
47
|
dek: integration.dek ?? null,
|
|
31
48
|
};
|
|
32
49
|
return cachedIntegration;
|
|
33
50
|
},
|
|
34
51
|
updateIntegration: async (data) => {
|
|
35
52
|
const integration = await ctx.getIntegration();
|
|
36
|
-
await database.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
data: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
await database.db
|
|
54
|
+
.updateTable('corsair_integrations')
|
|
55
|
+
.set({
|
|
56
|
+
...(data.config !== undefined ? { config: data.config } : {}),
|
|
57
|
+
...(data.dek !== undefined ? { dek: data.dek } : {}),
|
|
58
|
+
updated_at: new Date(),
|
|
59
|
+
})
|
|
60
|
+
.where('id', '=', integration.id)
|
|
61
|
+
.execute();
|
|
45
62
|
// Invalidate cache
|
|
46
63
|
cachedIntegration = null;
|
|
47
64
|
},
|
|
@@ -74,16 +91,17 @@ export function createAccountKeyManager(options) {
|
|
|
74
91
|
const getIntegration = async () => {
|
|
75
92
|
if (cachedIntegration)
|
|
76
93
|
return cachedIntegration;
|
|
77
|
-
const integration = await database.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
const integration = await database.db
|
|
95
|
+
.selectFrom('corsair_integrations')
|
|
96
|
+
.selectAll()
|
|
97
|
+
.where('name', '=', integrationName)
|
|
98
|
+
.executeTakeFirst();
|
|
81
99
|
if (!integration) {
|
|
82
100
|
throw new Error(`Integration "${integrationName}" not found. Make sure to create the integration first.`);
|
|
83
101
|
}
|
|
84
102
|
cachedIntegration = {
|
|
85
103
|
id: integration.id,
|
|
86
|
-
config: (integration.config
|
|
104
|
+
config: parseConfig(integration.config),
|
|
87
105
|
dek: integration.dek ?? null,
|
|
88
106
|
};
|
|
89
107
|
return cachedIntegration;
|
|
@@ -97,34 +115,33 @@ export function createAccountKeyManager(options) {
|
|
|
97
115
|
if (cachedAccount)
|
|
98
116
|
return cachedAccount;
|
|
99
117
|
const integration = await getIntegration();
|
|
100
|
-
const account = await database.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
118
|
+
const account = await database.db
|
|
119
|
+
.selectFrom('corsair_accounts')
|
|
120
|
+
.selectAll()
|
|
121
|
+
.where('tenant_id', '=', tenantId)
|
|
122
|
+
.where('integration_id', '=', integration.id)
|
|
123
|
+
.executeTakeFirst();
|
|
107
124
|
if (!account) {
|
|
108
125
|
throw new Error(`Account not found for tenant "${tenantId}" and integration "${integrationName}". Make sure to create the account first.`);
|
|
109
126
|
}
|
|
110
127
|
cachedAccount = {
|
|
111
128
|
id: account.id,
|
|
112
|
-
config: (account.config
|
|
129
|
+
config: parseConfig(account.config),
|
|
113
130
|
dek: account.dek ?? null,
|
|
114
131
|
};
|
|
115
132
|
return cachedAccount;
|
|
116
133
|
},
|
|
117
134
|
updateAccount: async (data) => {
|
|
118
135
|
const account = await ctx.getAccount();
|
|
119
|
-
await database.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
data: {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
await database.db
|
|
137
|
+
.updateTable('corsair_accounts')
|
|
138
|
+
.set({
|
|
139
|
+
...(data.config !== undefined ? { config: data.config } : {}),
|
|
140
|
+
...(data.dek !== undefined ? { dek: data.dek } : {}),
|
|
141
|
+
updated_at: new Date(),
|
|
142
|
+
})
|
|
143
|
+
.where('id', '=', account.id)
|
|
144
|
+
.execute();
|
|
128
145
|
// Invalidate cache
|
|
129
146
|
cachedAccount = null;
|
|
130
147
|
},
|
|
@@ -149,23 +166,24 @@ export function createAccountKeyManager(options) {
|
|
|
149
166
|
* Call this when creating a new integration or when setting up encryption for the first time.
|
|
150
167
|
*/
|
|
151
168
|
export async function initializeIntegrationDEK(database, integrationName, kek) {
|
|
152
|
-
const integration = await database.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
169
|
+
const integration = await database.db
|
|
170
|
+
.selectFrom('corsair_integrations')
|
|
171
|
+
.selectAll()
|
|
172
|
+
.where('name', '=', integrationName)
|
|
173
|
+
.executeTakeFirst();
|
|
156
174
|
if (!integration) {
|
|
157
175
|
throw new Error(`Integration "${integrationName}" not found.`);
|
|
158
176
|
}
|
|
159
177
|
const dek = generateDEK();
|
|
160
178
|
const encryptedDek = await encryptDEK(dek, kek);
|
|
161
|
-
await database.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
await database.db
|
|
180
|
+
.updateTable('corsair_integrations')
|
|
181
|
+
.set({
|
|
182
|
+
dek: encryptedDek,
|
|
183
|
+
updated_at: new Date(),
|
|
184
|
+
})
|
|
185
|
+
.where('id', '=', integration.id)
|
|
186
|
+
.execute();
|
|
169
187
|
return dek;
|
|
170
188
|
}
|
|
171
189
|
/**
|
|
@@ -173,32 +191,32 @@ export async function initializeIntegrationDEK(database, integrationName, kek) {
|
|
|
173
191
|
* Call this when creating a new account or when setting up encryption for the first time.
|
|
174
192
|
*/
|
|
175
193
|
export async function initializeAccountDEK(database, integrationName, tenantId, kek) {
|
|
176
|
-
const integration = await database.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
194
|
+
const integration = await database.db
|
|
195
|
+
.selectFrom('corsair_integrations')
|
|
196
|
+
.selectAll()
|
|
197
|
+
.where('name', '=', integrationName)
|
|
198
|
+
.executeTakeFirst();
|
|
180
199
|
if (!integration) {
|
|
181
200
|
throw new Error(`Integration "${integrationName}" not found.`);
|
|
182
201
|
}
|
|
183
|
-
const account = await database.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
202
|
+
const account = await database.db
|
|
203
|
+
.selectFrom('corsair_accounts')
|
|
204
|
+
.selectAll()
|
|
205
|
+
.where('tenant_id', '=', tenantId)
|
|
206
|
+
.where('integration_id', '=', integration.id)
|
|
207
|
+
.executeTakeFirst();
|
|
190
208
|
if (!account) {
|
|
191
209
|
throw new Error(`Account not found for tenant "${tenantId}" and integration "${integrationName}".`);
|
|
192
210
|
}
|
|
193
211
|
const dek = generateDEK();
|
|
194
212
|
const encryptedDek = await encryptDEK(dek, kek);
|
|
195
|
-
await database.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
213
|
+
await database.db
|
|
214
|
+
.updateTable('corsair_accounts')
|
|
215
|
+
.set({
|
|
216
|
+
dek: encryptedDek,
|
|
217
|
+
updated_at: new Date(),
|
|
218
|
+
})
|
|
219
|
+
.where('id', '=', account.id)
|
|
220
|
+
.execute();
|
|
203
221
|
return dek;
|
|
204
222
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ZodTypeAny } from 'zod';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CorsairDatabase } from '../../db/kysely/database';
|
|
3
3
|
import type { CorsairPluginSchema, PluginEntityClients } from '../../db/orm';
|
|
4
4
|
import type { AccountKeyManagerFor, IntegrationKeyManagerFor } from '../auth/types';
|
|
5
5
|
import type { AuthTypes } from '../constants';
|
|
@@ -105,7 +105,7 @@ export type CorsairSingleTenantClient<Plugins extends readonly CorsairPlugin[]>
|
|
|
105
105
|
keys: InferAllIntegrationKeys<Plugins>;
|
|
106
106
|
};
|
|
107
107
|
export type BuildCorsairClientOptions = {
|
|
108
|
-
database:
|
|
108
|
+
database: CorsairDatabase | undefined;
|
|
109
109
|
tenantId: string | undefined;
|
|
110
110
|
kek: string | undefined;
|
|
111
111
|
rootErrorHandlers?: CorsairErrorHandler;
|
|
@@ -125,6 +125,6 @@ export declare function buildCorsairClient<const Plugins extends readonly Corsai
|
|
|
125
125
|
* @param kek - Key Encryption Key for envelope encryption
|
|
126
126
|
* @returns An object with key managers for each plugin
|
|
127
127
|
*/
|
|
128
|
-
export declare function buildIntegrationKeys<const Plugins extends readonly CorsairPlugin[]>(plugins: Plugins, database:
|
|
128
|
+
export declare function buildIntegrationKeys<const Plugins extends readonly CorsairPlugin[]>(plugins: Plugins, database: CorsairDatabase, kek: string): InferAllIntegrationKeys<Plugins>;
|
|
129
129
|
export {};
|
|
130
130
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;
|
|
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,KAAK,EACX,mBAAmB,EAEnB,mBAAmB,EACnB,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EACX,oBAAoB,EACpB,wBAAwB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA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,CAAC,OAAO,SAAS,SAAS,aAAa,EAAE,EAE9C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,yBAAyB,GAChC,aAAa,CAAC,OAAO,CAAC,CA2IxB;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,CAmBlC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createKyselyEntityClient } from '../../db/kysely/orm';
|
|
2
2
|
import { createAccountKeyManager, createIntegrationKeyManager, } from '../auth/key-manager';
|
|
3
3
|
import { bindEndpointsRecursively } from '../endpoints/bind';
|
|
4
|
-
import { generateUUID } from '../utils';
|
|
5
4
|
import { bindWebhooksRecursively } from '../webhooks/bind';
|
|
6
5
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
7
6
|
// Account ID Resolver
|
|
@@ -19,21 +18,21 @@ function createAccountIdResolver(database, integrationName, tenantId) {
|
|
|
19
18
|
throw new Error('Database not configured');
|
|
20
19
|
}
|
|
21
20
|
// Find the integration by name
|
|
22
|
-
const integration = await database.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const integration = await database.db
|
|
22
|
+
.selectFrom('corsair_integrations')
|
|
23
|
+
.selectAll()
|
|
24
|
+
.where('name', '=', integrationName)
|
|
25
|
+
.executeTakeFirst();
|
|
26
26
|
if (!integration) {
|
|
27
27
|
throw new Error(`Integration "${integrationName}" not found. Make sure to create the integration first.`);
|
|
28
28
|
}
|
|
29
29
|
// Find the account for this tenant and integration
|
|
30
|
-
const account = await database.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
30
|
+
const account = await database.db
|
|
31
|
+
.selectFrom('corsair_accounts')
|
|
32
|
+
.selectAll()
|
|
33
|
+
.where('tenant_id', '=', tenantId)
|
|
34
|
+
.where('integration_id', '=', integration.id)
|
|
35
|
+
.executeTakeFirst();
|
|
37
36
|
if (!account) {
|
|
38
37
|
throw new Error(`Account not found for tenant "${tenantId}" and integration "${integrationName}". Make sure to create the account first.`);
|
|
39
38
|
}
|
|
@@ -41,22 +40,6 @@ function createAccountIdResolver(database, integrationName, tenantId) {
|
|
|
41
40
|
return cachedAccountId;
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Attempts to parse a value as JSON if it's a string, otherwise returns the value unchanged.
|
|
46
|
-
* @param value - The value to parse
|
|
47
|
-
* @returns The parsed value or the original value if parsing fails
|
|
48
|
-
*/
|
|
49
|
-
function parseJsonLike(value) {
|
|
50
|
-
if (typeof value === 'string') {
|
|
51
|
-
try {
|
|
52
|
-
return JSON.parse(value);
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return value;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
43
|
/**
|
|
61
44
|
* Creates an entity client for a specific plugin and entity type with database operations.
|
|
62
45
|
* The client lazily resolves the account ID when operations are performed.
|
|
@@ -68,194 +51,21 @@ function parseJsonLike(value) {
|
|
|
68
51
|
* @returns An entity client with CRUD operations
|
|
69
52
|
*/
|
|
70
53
|
function createEntityClient(database, getAccountId, entityTypeName, version, dataSchema) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return [
|
|
74
|
-
{ field: 'account_id', value: accountId },
|
|
75
|
-
{ field: 'entity_type', value: entityTypeName },
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
function parseRow(row) {
|
|
79
|
-
const data = parseJsonLike(row.data);
|
|
80
|
-
return { ...row, data: dataSchema.parse(data) };
|
|
54
|
+
if (database) {
|
|
55
|
+
return createKyselyEntityClient(database.db, getAccountId, entityTypeName, version, dataSchema);
|
|
81
56
|
}
|
|
82
57
|
return {
|
|
83
|
-
findByEntityId: async (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
...baseWhere(accountId),
|
|
91
|
-
{ field: 'entity_id', value: entityId },
|
|
92
|
-
],
|
|
93
|
-
});
|
|
94
|
-
return row ? parseRow(row) : null;
|
|
95
|
-
},
|
|
96
|
-
findById: async (id) => {
|
|
97
|
-
if (!database)
|
|
98
|
-
return null;
|
|
99
|
-
const accountId = await getAccountId();
|
|
100
|
-
const row = await database.findOne({
|
|
101
|
-
table: tableName,
|
|
102
|
-
where: [...baseWhere(accountId), { field: 'id', value: id }],
|
|
103
|
-
});
|
|
104
|
-
return row ? parseRow(row) : null;
|
|
105
|
-
},
|
|
106
|
-
findManyByEntityIds: async (entityIds) => {
|
|
107
|
-
if (!database || entityIds.length === 0)
|
|
108
|
-
return [];
|
|
109
|
-
const accountId = await getAccountId();
|
|
110
|
-
const rows = await database.findMany({
|
|
111
|
-
table: tableName,
|
|
112
|
-
where: [
|
|
113
|
-
...baseWhere(accountId),
|
|
114
|
-
{ field: 'entity_id', operator: 'in', value: entityIds },
|
|
115
|
-
],
|
|
116
|
-
});
|
|
117
|
-
return rows.map(parseRow);
|
|
118
|
-
},
|
|
119
|
-
list: async (options) => {
|
|
120
|
-
if (!database)
|
|
121
|
-
return [];
|
|
122
|
-
const accountId = await getAccountId();
|
|
123
|
-
const rows = await database.findMany({
|
|
124
|
-
table: tableName,
|
|
125
|
-
where: baseWhere(accountId),
|
|
126
|
-
limit: options?.limit ?? 100,
|
|
127
|
-
offset: options?.offset ?? 0,
|
|
128
|
-
});
|
|
129
|
-
return rows.map(parseRow);
|
|
130
|
-
},
|
|
131
|
-
search: async (options) => {
|
|
132
|
-
if (!database)
|
|
133
|
-
return [];
|
|
134
|
-
const accountId = await getAccountId();
|
|
135
|
-
// Build where clauses from search options
|
|
136
|
-
const whereConditions = [...baseWhere(accountId)];
|
|
137
|
-
// Helper to parse filter value into operator and value
|
|
138
|
-
function parseFilterValue(filterValue) {
|
|
139
|
-
if (typeof filterValue === 'object' &&
|
|
140
|
-
filterValue !== null &&
|
|
141
|
-
!Array.isArray(filterValue)) {
|
|
142
|
-
const obj = filterValue;
|
|
143
|
-
if ('contains' in obj && typeof obj.contains === 'string') {
|
|
144
|
-
return { operator: 'like', value: `%${obj.contains}%` };
|
|
145
|
-
}
|
|
146
|
-
if ('equals' in obj) {
|
|
147
|
-
return { operator: '=', value: obj.equals };
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// Exact match
|
|
151
|
-
return { operator: '=', value: filterValue };
|
|
152
|
-
}
|
|
153
|
-
// Reserved keys that aren't entity column filters
|
|
154
|
-
const reservedKeys = new Set(['data', 'limit', 'offset']);
|
|
155
|
-
// Handle entity column filters (derived from CorsairEntity)
|
|
156
|
-
for (const [key, filterValue] of Object.entries(options)) {
|
|
157
|
-
if (reservedKeys.has(key) || filterValue === undefined)
|
|
158
|
-
continue;
|
|
159
|
-
const { operator, value } = parseFilterValue(filterValue);
|
|
160
|
-
whereConditions.push({ field: key, operator, value });
|
|
161
|
-
}
|
|
162
|
-
// Handle data (JSONB) filters
|
|
163
|
-
if (options.data && typeof options.data === 'object') {
|
|
164
|
-
for (const [key, filterValue] of Object.entries(options.data)) {
|
|
165
|
-
if (filterValue === undefined)
|
|
166
|
-
continue;
|
|
167
|
-
const { operator, value } = parseFilterValue(filterValue);
|
|
168
|
-
// Use JSONB path query syntax: data->>'key'
|
|
169
|
-
whereConditions.push({
|
|
170
|
-
field: `data->>'${key}'`,
|
|
171
|
-
operator,
|
|
172
|
-
value,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const rows = await database.findMany({
|
|
177
|
-
table: tableName,
|
|
178
|
-
where: whereConditions,
|
|
179
|
-
limit: options.limit ?? 100,
|
|
180
|
-
offset: options.offset ?? 0,
|
|
181
|
-
});
|
|
182
|
-
return rows.map(parseRow);
|
|
183
|
-
},
|
|
184
|
-
upsertByEntityId: async (entityId, data) => {
|
|
185
|
-
if (!database)
|
|
186
|
-
throw new Error('Database not configured');
|
|
187
|
-
const accountId = await getAccountId();
|
|
188
|
-
const parsed = dataSchema.parse(data);
|
|
189
|
-
const now = new Date();
|
|
190
|
-
const existing = await database.findOne({
|
|
191
|
-
table: tableName,
|
|
192
|
-
select: ['id'],
|
|
193
|
-
where: [
|
|
194
|
-
...baseWhere(accountId),
|
|
195
|
-
{ field: 'entity_id', value: entityId },
|
|
196
|
-
],
|
|
197
|
-
});
|
|
198
|
-
if (existing?.id) {
|
|
199
|
-
await database.update({
|
|
200
|
-
table: tableName,
|
|
201
|
-
where: [{ field: 'id', value: existing.id }],
|
|
202
|
-
data: { version, data: parsed, updated_at: now },
|
|
203
|
-
});
|
|
204
|
-
const updated = await database.findOne({
|
|
205
|
-
table: tableName,
|
|
206
|
-
where: [{ field: 'id', value: existing.id }],
|
|
207
|
-
});
|
|
208
|
-
return parseRow(updated);
|
|
209
|
-
}
|
|
210
|
-
const id = generateUUID();
|
|
211
|
-
await database.insert({
|
|
212
|
-
table: tableName,
|
|
213
|
-
data: {
|
|
214
|
-
id,
|
|
215
|
-
created_at: now,
|
|
216
|
-
updated_at: now,
|
|
217
|
-
account_id: accountId,
|
|
218
|
-
entity_id: entityId,
|
|
219
|
-
entity_type: entityTypeName,
|
|
220
|
-
version,
|
|
221
|
-
data: parsed,
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
const inserted = await database.findOne({
|
|
225
|
-
table: tableName,
|
|
226
|
-
where: [{ field: 'id', value: id }],
|
|
227
|
-
});
|
|
228
|
-
return parseRow(inserted);
|
|
229
|
-
},
|
|
230
|
-
deleteById: async (id) => {
|
|
231
|
-
if (!database)
|
|
232
|
-
return false;
|
|
233
|
-
const accountId = await getAccountId();
|
|
234
|
-
const deleted = await database.deleteMany({
|
|
235
|
-
table: tableName,
|
|
236
|
-
where: [...baseWhere(accountId), { field: 'id', value: id }],
|
|
237
|
-
});
|
|
238
|
-
return deleted > 0;
|
|
239
|
-
},
|
|
240
|
-
deleteByEntityId: async (entityId) => {
|
|
241
|
-
if (!database)
|
|
242
|
-
return false;
|
|
243
|
-
const accountId = await getAccountId();
|
|
244
|
-
const deleted = await database.deleteMany({
|
|
245
|
-
table: tableName,
|
|
246
|
-
where: [
|
|
247
|
-
...baseWhere(accountId),
|
|
248
|
-
{ field: 'entity_id', value: entityId },
|
|
249
|
-
],
|
|
250
|
-
});
|
|
251
|
-
return deleted > 0;
|
|
252
|
-
},
|
|
253
|
-
count: async () => {
|
|
254
|
-
if (!database)
|
|
255
|
-
return 0;
|
|
256
|
-
const accountId = await getAccountId();
|
|
257
|
-
return database.count({ table: tableName, where: baseWhere(accountId) });
|
|
58
|
+
findByEntityId: async () => null,
|
|
59
|
+
findById: async () => null,
|
|
60
|
+
findManyByEntityIds: async () => [],
|
|
61
|
+
list: async () => [],
|
|
62
|
+
search: async () => [],
|
|
63
|
+
upsertByEntityId: async () => {
|
|
64
|
+
throw new Error('Database not configured');
|
|
258
65
|
},
|
|
66
|
+
deleteById: async () => false,
|
|
67
|
+
deleteByEntityId: async () => false,
|
|
68
|
+
count: async () => 0,
|
|
259
69
|
};
|
|
260
70
|
}
|
|
261
71
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -269,7 +79,6 @@ function createEntityClient(database, getAccountId, entityTypeName, version, dat
|
|
|
269
79
|
*/
|
|
270
80
|
export function buildCorsairClient(plugins, options) {
|
|
271
81
|
const { database, tenantId, kek, rootErrorHandlers } = options;
|
|
272
|
-
const scopedDatabase = database && tenantId ? withTenantAdapter(database, tenantId) : database;
|
|
273
82
|
const apiUnsafe = {};
|
|
274
83
|
const pluginEntitiesUnsafe = {};
|
|
275
84
|
for (const plugin of plugins) {
|
|
@@ -280,12 +89,14 @@ export function buildCorsairClient(plugins, options) {
|
|
|
280
89
|
const schema = plugin.schema;
|
|
281
90
|
const effectiveTenantId = tenantId ?? 'default';
|
|
282
91
|
// Create a shared account ID resolver for this plugin
|
|
283
|
-
const getAccountId = createAccountIdResolver(
|
|
92
|
+
const getAccountId = createAccountIdResolver(database, plugin.id, effectiveTenantId);
|
|
284
93
|
// Create typed entity clients from plugin schema, nested under `db`
|
|
285
94
|
if (schema?.entities) {
|
|
286
95
|
const dbClients = {};
|
|
287
96
|
for (const [entityTypeName, dataSchema] of Object.entries(schema.entities)) {
|
|
288
|
-
const entityClient =
|
|
97
|
+
const entityClient = database
|
|
98
|
+
? createKyselyEntityClient(database.db, getAccountId, entityTypeName, schema.version, dataSchema)
|
|
99
|
+
: createEntityClient(undefined, getAccountId, entityTypeName, schema.version, dataSchema);
|
|
289
100
|
dbClients[entityTypeName] = entityClient;
|
|
290
101
|
}
|
|
291
102
|
pluginEntitiesUnsafe[plugin.id].db = dbClients;
|
|
@@ -306,7 +117,7 @@ export function buildCorsairClient(plugins, options) {
|
|
|
306
117
|
}
|
|
307
118
|
// Build plugin context with entity clients under `db`, account ID resolver, and keys manager
|
|
308
119
|
const ctxForPlugin = {
|
|
309
|
-
database
|
|
120
|
+
database,
|
|
310
121
|
db: pluginEntitiesUnsafe[plugin.id]?.db ?? {},
|
|
311
122
|
$getAccountId: getAccountId,
|
|
312
123
|
...(plugin.options ? { options: plugin.options } : {}),
|
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 ["slack", "github", "linear", "hubspot", "gmail", "resend"];
|
|
3
|
-
export type AllProviders = 'slack' | 'github' | 'linear' | 'hubspot' | 'gmail' | 'resend' | (string & {});
|
|
2
|
+
export declare const BaseProviders: readonly ["slack", "github", "linear", "hubspot", "gmail", "resend", "posthog", "googlesheets", "googledrive", "googlecalendar"];
|
|
3
|
+
export type AllProviders = 'slack' | 'github' | 'linear' | 'hubspot' | 'gmail' | 'resend' | 'posthog' | 'googlesheets' | 'googledrive' | 'googlecalendar' | (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,kIAWhB,CAAC;AAEX,MAAM,MAAM,YAAY,GACrB,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,OAAO,GACP,QAAQ,GACR,SAAS,GACT,cAAc,GACd,aAAa,GACb,gBAAgB,GAChB,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"}
|