@shipfox/api-integration-core 3.0.0 → 5.0.0
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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +62 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -1
- package/dist/db/webhook-deliveries.d.ts +4 -0
- package/dist/db/webhook-deliveries.d.ts.map +1 -1
- package/dist/db/webhook-deliveries.js +10 -2
- package/dist/db/webhook-deliveries.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/presentation/routes/index.js +1 -1
- package/dist/presentation/routes/index.js.map +1 -1
- package/dist/presentation/routes/manage-connections.d.ts +1 -1
- package/dist/presentation/routes/manage-connections.d.ts.map +1 -1
- package/dist/presentation/routes/manage-connections.js +28 -3
- package/dist/presentation/routes/manage-connections.js.map +1 -1
- package/dist/providers/jira.d.ts +3 -0
- package/dist/providers/jira.d.ts.map +1 -0
- package/dist/providers/jira.js +127 -0
- package/dist/providers/jira.js.map +1 -0
- package/dist/providers/linear.d.ts.map +1 -1
- package/dist/providers/linear.js +15 -1
- package/dist/providers/linear.js.map +1 -1
- package/dist/providers/modules.d.ts.map +1 -1
- package/dist/providers/modules.js +4 -0
- package/dist/providers/modules.js.map +1 -1
- package/dist/providers/slack.d.ts +3 -0
- package/dist/providers/slack.d.ts.map +1 -0
- package/dist/providers/slack.js +149 -0
- package/dist/providers/slack.js.map +1 -0
- package/dist/providers/types.d.ts +2 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +28 -36
- package/src/config.ts +8 -0
- package/src/db/webhook-deliveries.test.ts +11 -0
- package/src/db/webhook-deliveries.ts +12 -3
- package/src/index.ts +2 -1
- package/src/presentation/routes/index.ts +1 -1
- package/src/presentation/routes/manage-connections.test.ts +113 -0
- package/src/presentation/routes/manage-connections.ts +26 -2
- package/src/providers/jira.test.ts +57 -0
- package/src/providers/jira.ts +172 -0
- package/src/providers/linear.test.ts +136 -0
- package/src/providers/linear.ts +14 -0
- package/src/providers/modules.test.ts +26 -0
- package/src/providers/modules.ts +4 -0
- package/src/providers/slack.test.ts +196 -0
- package/src/providers/slack.ts +196 -0
- package/src/providers/types.ts +2 -0
- package/test/env.ts +12 -0
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providers/jira.ts"],"sourcesContent":["import {\n type IntegrationConnection as CoreIntegrationConnection,\n slugifyConnectionSlug,\n} from '@shipfox/api-integration-core-dto';\nimport type {\n ConnectJiraInstallationInput,\n JiraPendingSelectionSecretsStore,\n JiraSecretsStore,\n} from '@shipfox/api-integration-jira';\nimport {config} from '#config.js';\nimport {\n deleteIntegrationConnection,\n getIntegrationConnectionById,\n resolveUniqueConnectionSlug,\n updateIntegrationConnectionLifecycleStatus,\n upsertIntegrationConnection,\n} from '#db/connections.js';\nimport {db} from '#db/db.js';\nimport {retryConnectionSlugCollision} from '#providers/connection-slug.js';\nimport type {IntegrationModuleParts, IntegrationProviderModule} from '#providers/types.js';\n\nconst JIRA_MIGRATIONS_TABLE = '__drizzle_migrations_integrations_jira';\nconst JIRA_SECRETS_NAMESPACE_PREFIX = 'system/integrations/jira/';\ntype IntegrationDb = ReturnType<typeof db>;\ntype IntegrationTx = Parameters<Parameters<IntegrationDb['transaction']>[0]>[0];\n\nasync function loadJiraModuleParts(\n options: Parameters<IntegrationProviderModule['load']>[0] = {},\n): Promise<IntegrationModuleParts> {\n const {\n createJiraIntegrationProvider,\n createJiraPendingSelectionStore,\n createJiraTokenStore,\n db: jiraDb,\n disconnectJiraInstallation: disconnectJiraInstallationRecords,\n getJiraInstallationByCloudId,\n migrationsPath,\n upsertJiraInstallation,\n } = await import('@shipfox/api-integration-jira');\n\n async function getExistingJiraConnection(input: {\n cloudId: string;\n }): Promise<CoreIntegrationConnection<'jira'> | undefined> {\n const installation = await getJiraInstallationByCloudId(input.cloudId);\n if (!installation) return undefined;\n return (await getIntegrationConnectionById(installation.connectionId)) as\n | CoreIntegrationConnection<'jira'>\n | undefined;\n }\n\n function connectJiraInstallation(\n input: ConnectJiraInstallationInput,\n ): Promise<CoreIntegrationConnection<'jira'>> {\n return retryConnectionSlugCollision(() =>\n db().transaction(async (tx) => {\n const slug = await resolveUniqueConnectionSlug(\n {\n workspaceId: input.workspaceId,\n provider: 'jira',\n externalAccountId: input.cloudId,\n baseSlug: slugifyConnectionSlug(`jira_${input.siteName || input.cloudId}`, {\n fallback: 'jira',\n }),\n },\n {tx},\n );\n const connection = await upsertIntegrationConnection(\n {\n workspaceId: input.workspaceId,\n provider: 'jira',\n externalAccountId: input.cloudId,\n slug,\n displayName: input.displayName,\n lifecycleStatus: 'active',\n },\n {tx},\n );\n await upsertJiraInstallation(\n {\n connectionId: connection.id,\n cloudId: input.cloudId,\n siteUrl: input.siteUrl,\n siteName: input.siteName,\n authorizingAccountId: input.authorizingAccountId,\n scopes: input.scopes,\n status: 'installed',\n tokenExpiresAt: input.tokenExpiresAt,\n },\n {tx},\n );\n return connection as CoreIntegrationConnection<'jira'>;\n }),\n );\n }\n\n async function disconnectJiraInstallation(input: {connectionId: string}): Promise<void> {\n await disconnectJiraInstallationRecords<IntegrationTx>({\n connectionId: input.connectionId,\n getConnection: getIntegrationConnectionById,\n deleteSecrets: (params) =>\n options.secrets?.jira?.deleteSecrets({\n ...params,\n namespace: jiraNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(0),\n transaction: (fn) => db().transaction((tx) => fn(tx)),\n deleteConnection: (params, transactionOptions) =>\n deleteIntegrationConnection({id: params.connectionId}, transactionOptions),\n });\n }\n\n const fallbackSecrets: JiraSecretsStore & JiraPendingSelectionSecretsStore = {\n getSecret: () => Promise.resolve(null),\n setSecrets: () => Promise.reject(new Error('Jira token storage is not configured')),\n deleteSecrets: () => Promise.resolve(0),\n };\n const secrets: JiraSecretsStore & JiraPendingSelectionSecretsStore = options.secrets?.jira\n ? {\n getSecret: (params) =>\n options.secrets?.jira?.getSecret({\n ...params,\n namespace: jiraNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(null),\n setSecrets: (params) =>\n options.secrets?.jira?.setSecrets({\n ...params,\n namespace: jiraNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(),\n deleteSecrets: (params) =>\n options.secrets?.jira?.deleteSecrets({\n ...params,\n namespace: jiraNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(0),\n }\n : fallbackSecrets;\n const tokenStore = createJiraTokenStore({\n resolveConnection: getIntegrationConnectionById,\n secrets,\n markConnectionError: async ({connectionId}) => {\n await updateIntegrationConnectionLifecycleStatus({\n id: connectionId,\n lifecycleStatus: 'error',\n });\n },\n });\n const pendingStore = createJiraPendingSelectionStore({secrets});\n\n return {\n provider: createJiraIntegrationProvider({\n routes: {\n tokenStore,\n pendingStore,\n getExistingJiraConnection,\n connectJiraInstallation,\n disconnectJiraInstallation,\n },\n }),\n database: {db: jiraDb, migrationsPath, migrationsTableName: JIRA_MIGRATIONS_TABLE},\n };\n}\n\nexport const jiraProviderModule: IntegrationProviderModule = {\n id: 'jira',\n enabled: config.INTEGRATIONS_ENABLE_JIRA_PROVIDER,\n load: loadJiraModuleParts,\n};\n\nfunction jiraNamespaceSuffix(namespace: string): string {\n if (!namespace.startsWith(JIRA_SECRETS_NAMESPACE_PREFIX)) {\n throw new Error('Jira provider attempted to access an unscoped secret namespace');\n }\n return namespace.slice(JIRA_SECRETS_NAMESPACE_PREFIX.length);\n}\n"],"names":["slugifyConnectionSlug","config","deleteIntegrationConnection","getIntegrationConnectionById","resolveUniqueConnectionSlug","updateIntegrationConnectionLifecycleStatus","upsertIntegrationConnection","db","retryConnectionSlugCollision","JIRA_MIGRATIONS_TABLE","JIRA_SECRETS_NAMESPACE_PREFIX","loadJiraModuleParts","options","createJiraIntegrationProvider","createJiraPendingSelectionStore","createJiraTokenStore","jiraDb","disconnectJiraInstallation","disconnectJiraInstallationRecords","getJiraInstallationByCloudId","migrationsPath","upsertJiraInstallation","getExistingJiraConnection","input","installation","cloudId","undefined","connectionId","connectJiraInstallation","transaction","tx","slug","workspaceId","provider","externalAccountId","baseSlug","siteName","fallback","connection","displayName","lifecycleStatus","id","siteUrl","authorizingAccountId","scopes","status","tokenExpiresAt","getConnection","deleteSecrets","params","secrets","jira","namespace","jiraNamespaceSuffix","Promise","resolve","fn","deleteConnection","transactionOptions","fallbackSecrets","getSecret","setSecrets","reject","Error","tokenStore","resolveConnection","markConnectionError","pendingStore","routes","database","migrationsTableName","jiraProviderModule","enabled","INTEGRATIONS_ENABLE_JIRA_PROVIDER","load","startsWith","slice","length"],"mappings":"AAAA,SAEEA,qBAAqB,QAChB,oCAAoC;AAM3C,SAAQC,MAAM,QAAO,aAAa;AAClC,SACEC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,2BAA2B,EAC3BC,0CAA0C,EAC1CC,2BAA2B,QACtB,qBAAqB;AAC5B,SAAQC,EAAE,QAAO,YAAY;AAC7B,SAAQC,4BAA4B,QAAO,gCAAgC;AAG3E,MAAMC,wBAAwB;AAC9B,MAAMC,gCAAgC;AAItC,eAAeC,oBACbC,UAA4D,CAAC,CAAC;IAE9D,MAAM,EACJC,6BAA6B,EAC7BC,+BAA+B,EAC/BC,oBAAoB,EACpBR,IAAIS,MAAM,EACVC,4BAA4BC,iCAAiC,EAC7DC,4BAA4B,EAC5BC,cAAc,EACdC,sBAAsB,EACvB,GAAG,MAAM,MAAM,CAAC;IAEjB,eAAeC,0BAA0BC,KAExC;QACC,MAAMC,eAAe,MAAML,6BAA6BI,MAAME,OAAO;QACrE,IAAI,CAACD,cAAc,OAAOE;QAC1B,OAAQ,MAAMvB,6BAA6BqB,aAAaG,YAAY;IAGtE;IAEA,SAASC,w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CAACA,UAAUuB,UAAU,CAACjE,gCAAgC;QACxD,MAAM,IAAIqD,MAAM;IAClB;IACA,OAAOX,UAAUwB,KAAK,CAAClE,8BAA8BmE,MAAM;AAC7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linear.d.ts","sourceRoot":"","sources":["../../src/providers/linear.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAyB,yBAAyB,EAAC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"linear.d.ts","sourceRoot":"","sources":["../../src/providers/linear.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAyB,yBAAyB,EAAC,MAAM,qBAAqB,CAAC;AAmK3F,eAAO,MAAM,oBAAoB,EAAE,yBAIlC,CAAC"}
|
package/dist/providers/linear.js
CHANGED
|
@@ -7,7 +7,7 @@ import { retryConnectionSlugCollision } from '#providers/connection-slug.js';
|
|
|
7
7
|
const LINEAR_MIGRATIONS_TABLE = '__drizzle_migrations_integrations_linear';
|
|
8
8
|
const LINEAR_SECRETS_NAMESPACE_PREFIX = 'system/integrations/linear/';
|
|
9
9
|
async function loadLinearModuleParts(options = {}) {
|
|
10
|
-
const { createLinearTokenStore, createLinearE2eRoutes, createLinearIntegrationProvider, config: linearConfig, disconnectLinearInstallation: disconnectLinearInstallationRecords, getLinearInstallationByOrganizationId, db: linearDb, migrationsPath: linearMigrationsPath, upsertLinearInstallation } = await import('@shipfox/api-integration-linear');
|
|
10
|
+
const { createLinearTokenStore, createLinearE2eRoutes, createLinearIntegrationProvider, config: linearConfig, deleteLinearInstallationByConnectionId, disconnectLinearInstallation: disconnectLinearInstallationRecords, getLinearInstallationByOrganizationId, db: linearDb, linearSecretsNamespace, migrationsPath: linearMigrationsPath, upsertLinearInstallation } = await import('@shipfox/api-integration-linear');
|
|
11
11
|
async function getExistingLinearConnection(input) {
|
|
12
12
|
const installation = await getLinearInstallationByOrganizationId(input.organizationId);
|
|
13
13
|
if (!installation) return undefined;
|
|
@@ -90,6 +90,20 @@ async function loadLinearModuleParts(options = {}) {
|
|
|
90
90
|
tokenStore,
|
|
91
91
|
endpoint: linearConfig.LINEAR_MCP_ENDPOINT
|
|
92
92
|
},
|
|
93
|
+
cleanup: {
|
|
94
|
+
deleteConnectionRecords: async (connection, { tx })=>{
|
|
95
|
+
await deleteLinearInstallationByConnectionId(connection.id, {
|
|
96
|
+
tx
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
deleteConnectionSecrets: async (connection)=>{
|
|
100
|
+
// Scoped secrets accept the provider-local suffix, after this helper validates its prefix.
|
|
101
|
+
await (options.secrets?.linear?.deleteSecrets({
|
|
102
|
+
workspaceId: connection.workspaceId,
|
|
103
|
+
namespace: linearNamespaceSuffix(linearSecretsNamespace(connection.id))
|
|
104
|
+
}) ?? Promise.resolve());
|
|
105
|
+
}
|
|
106
|
+
},
|
|
93
107
|
routes: {
|
|
94
108
|
tokenStore,
|
|
95
109
|
getExistingLinearConnection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/linear.ts"],"sourcesContent":["import {\n type IntegrationConnection as CoreIntegrationConnection,\n slugifyConnectionSlug,\n} from '@shipfox/api-integration-core-dto';\nimport type {\n ConnectLinearInstallationInput,\n LinearSecretsStore,\n} from '@shipfox/api-integration-linear';\nimport {config} from '#config.js';\nimport {\n deleteIntegrationConnection,\n getIntegrationConnectionById,\n resolveUniqueConnectionSlug,\n upsertIntegrationConnection,\n} from '#db/connections.js';\nimport {db} from '#db/db.js';\nimport {publishIntegrationEventReceived, recordDeliveryOnly} from '#db/webhook-deliveries.js';\nimport {retryConnectionSlugCollision} from '#providers/connection-slug.js';\nimport type {IntegrationModuleParts, IntegrationProviderModule} from '#providers/types.js';\n\nconst LINEAR_MIGRATIONS_TABLE = '__drizzle_migrations_integrations_linear';\nconst LINEAR_SECRETS_NAMESPACE_PREFIX = 'system/integrations/linear/';\n\ntype IntegrationDb = ReturnType<typeof db>;\ntype IntegrationTx = Parameters<Parameters<IntegrationDb['transaction']>[0]>[0];\n\nasync function loadLinearModuleParts(\n options: Parameters<IntegrationProviderModule['load']>[0] = {},\n): Promise<IntegrationModuleParts> {\n const {\n createLinearTokenStore,\n createLinearE2eRoutes,\n createLinearIntegrationProvider,\n config: linearConfig,\n disconnectLinearInstallation: disconnectLinearInstallationRecords,\n getLinearInstallationByOrganizationId,\n db: linearDb,\n migrationsPath: linearMigrationsPath,\n upsertLinearInstallation,\n } = await import('@shipfox/api-integration-linear');\n\n async function getExistingLinearConnection(input: {\n organizationId: string;\n }): Promise<CoreIntegrationConnection<'linear'> | undefined> {\n const installation = await getLinearInstallationByOrganizationId(input.organizationId);\n if (!installation) return undefined;\n const connection = await getIntegrationConnectionById(installation.connectionId);\n if (!connection) return undefined;\n return connection as CoreIntegrationConnection<'linear'>;\n }\n\n async function connectLinearInstallation(\n input: ConnectLinearInstallationInput,\n ): Promise<CoreIntegrationConnection<'linear'>> {\n return await retryConnectionSlugCollision(() =>\n db().transaction(async (tx) => {\n const baseSlug = slugifyConnectionSlug(`linear_${input.organizationUrlKey}`, {\n fallback: 'linear',\n });\n const slug = await resolveUniqueConnectionSlug(\n {\n workspaceId: input.workspaceId,\n provider: 'linear',\n externalAccountId: input.organizationId,\n baseSlug,\n },\n {tx},\n );\n const connection = await upsertIntegrationConnection(\n {\n workspaceId: input.workspaceId,\n provider: 'linear',\n externalAccountId: input.organizationId,\n slug,\n displayName: input.displayName,\n lifecycleStatus: 'active',\n },\n {tx},\n );\n\n await upsertLinearInstallation(\n {\n connectionId: connection.id,\n organizationId: input.organizationId,\n organizationUrlKey: input.organizationUrlKey,\n appUserId: input.appUserId,\n scopes: input.scopes,\n tokenExpiresAt: input.tokenExpiresAt,\n status: 'installed',\n },\n {tx},\n );\n\n return connection as CoreIntegrationConnection<'linear'>;\n }),\n );\n }\n\n async function disconnectLinearInstallation(input: {connectionId: string}): Promise<void> {\n await disconnectLinearInstallationRecords<IntegrationTx>({\n connectionId: input.connectionId,\n getConnection: getIntegrationConnectionById,\n deleteSecrets: (params) =>\n options.secrets?.linear?.deleteSecrets({\n ...params,\n namespace: linearNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(0),\n transaction: (fn) => db().transaction((tx) => fn(tx)),\n deleteConnection: (params, options) =>\n deleteIntegrationConnection({id: params.connectionId}, options),\n });\n }\n\n const fallbackSecrets: LinearSecretsStore = {\n getSecret: () => Promise.resolve(null),\n setSecrets: () => Promise.reject(new Error('Linear token storage is not configured')),\n };\n const secrets: LinearSecretsStore = options.secrets?.linear\n ? {\n getSecret: (params: Parameters<LinearSecretsStore['getSecret']>[0]) =>\n options.secrets?.linear?.getSecret({\n ...params,\n namespace: linearNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(null),\n setSecrets: (params: Parameters<LinearSecretsStore['setSecrets']>[0]) =>\n options.secrets?.linear?.setSecrets({\n ...params,\n namespace: linearNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(),\n }\n : fallbackSecrets;\n const tokenStore = createLinearTokenStore({\n resolveConnection: async (connectionId) => getIntegrationConnectionById(connectionId),\n secrets,\n });\n\n return {\n provider: createLinearIntegrationProvider({\n agentTools: {tokenStore, endpoint: linearConfig.LINEAR_MCP_ENDPOINT},\n routes: {\n tokenStore,\n getExistingLinearConnection,\n connectLinearInstallation,\n disconnectLinearInstallation,\n publishIntegrationEventReceived,\n recordDeliveryOnly,\n getIntegrationConnectionById,\n coreDb: db,\n },\n }),\n e2eRoutes: [\n createLinearE2eRoutes({\n tokenStore,\n getExistingLinearConnection,\n connectLinearInstallation,\n disconnectLinearInstallation,\n connectionCapabilities: ['agent_tools'],\n }),\n ],\n database: {\n db: linearDb,\n migrationsPath: linearMigrationsPath,\n migrationsTableName: LINEAR_MIGRATIONS_TABLE,\n },\n };\n}\n\nexport const linearProviderModule: IntegrationProviderModule = {\n id: 'linear',\n enabled: config.INTEGRATIONS_ENABLE_LINEAR_PROVIDER,\n load: loadLinearModuleParts,\n};\n\nfunction linearNamespaceSuffix(namespace: string): string {\n if (!namespace.startsWith(LINEAR_SECRETS_NAMESPACE_PREFIX)) {\n throw new Error('Linear provider attempted to access an unscoped secret namespace');\n }\n return namespace.slice(LINEAR_SECRETS_NAMESPACE_PREFIX.length);\n}\n"],"names":["slugifyConnectionSlug","config","deleteIntegrationConnection","getIntegrationConnectionById","resolveUniqueConnectionSlug","upsertIntegrationConnection","db","publishIntegrationEventReceived","recordDeliveryOnly","retryConnectionSlugCollision","LINEAR_MIGRATIONS_TABLE","LINEAR_SECRETS_NAMESPACE_PREFIX","loadLinearModuleParts","options","createLinearTokenStore","createLinearE2eRoutes","createLinearIntegrationProvider","linearConfig","disconnectLinearInstallation","disconnectLinearInstallationRecords","getLinearInstallationByOrganizationId","linearDb","migrationsPath","linearMigrationsPath","upsertLinearInstallation","getExistingLinearConnection","input","installation","organizationId","undefined","connection","connectionId","connectLinearInstallation","transaction","tx","baseSlug","organizationUrlKey","fallback","slug","workspaceId","provider","externalAccountId","displayName","lifecycleStatus","id","appUserId","scopes","tokenExpiresAt","status","getConnection","deleteSecrets","params","secrets","linear","namespace","linearNamespaceSuffix","Promise","resolve","fn","deleteConnection","fallbackSecrets","getSecret","setSecrets","reject","Error","tokenStore","resolveConnection","agentTools","endpoint","LINEAR_MCP_ENDPOINT","routes","coreDb","e2eRoutes","connectionCapabilities","database","migrationsTableName","linearProviderModule","enabled","INTEGRATIONS_ENABLE_LINEAR_PROVIDER","load","startsWith","slice","length"],"mappings":"AAAA,SAEEA,qBAAqB,QAChB,oCAAoC;AAK3C,SAAQC,MAAM,QAAO,aAAa;AAClC,SACEC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,2BAA2B,EAC3BC,2BAA2B,QACtB,qBAAqB;AAC5B,SAAQC,EAAE,QAAO,YAAY;AAC7B,SAAQC,+BAA+B,EAAEC,kBAAkB,QAAO,4BAA4B;AAC9F,SAAQC,4BAA4B,QAAO,gCAAgC;AAG3E,MAAMC,0BAA0B;AAChC,M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oE,QAAQjE;YACV;QACF;QACAkE,WAAW;YACTzD,sBAAsB;gBACpBkD;gBACAxC;gBACAO;gBACAd;gBACAuD,wBAAwB;oBAAC;iBAAc;YACzC;SACD;QACDC,UAAU;YACRpE,IAAIe;YACJC,gBAAgBC;YAChBoD,qBAAqBjE;QACvB;IACF;AACF;AAEA,OAAO,MAAMkE,uBAAkD;IAC7DhC,IAAI;IACJiC,SAAS5E,OAAO6E,mCAAmC;IACnDC,MAAMnE;AACR,EAAE;AAEF,SAAS2C,sBAAsBD,SAAiB;IAC9C,IAAI,CAACA,UAAU0B,UAAU,CAACrE,kCAAkC;QAC1D,MAAM,IAAIqD,MAAM;IAClB;IACA,OAAOV,UAAU2B,KAAK,CAACtE,gCAAgCuE,MAAM;AAC/D"}
|
|
1
|
+
{"version":3,"sources":["../../src/providers/linear.ts"],"sourcesContent":["import {\n type IntegrationConnection as CoreIntegrationConnection,\n slugifyConnectionSlug,\n} from '@shipfox/api-integration-core-dto';\nimport type {\n ConnectLinearInstallationInput,\n LinearSecretsStore,\n} from '@shipfox/api-integration-linear';\nimport {config} from '#config.js';\nimport {\n deleteIntegrationConnection,\n getIntegrationConnectionById,\n resolveUniqueConnectionSlug,\n upsertIntegrationConnection,\n} from '#db/connections.js';\nimport {db} from '#db/db.js';\nimport {publishIntegrationEventReceived, recordDeliveryOnly} from '#db/webhook-deliveries.js';\nimport {retryConnectionSlugCollision} from '#providers/connection-slug.js';\nimport type {IntegrationModuleParts, IntegrationProviderModule} from '#providers/types.js';\n\nconst LINEAR_MIGRATIONS_TABLE = '__drizzle_migrations_integrations_linear';\nconst LINEAR_SECRETS_NAMESPACE_PREFIX = 'system/integrations/linear/';\n\ntype IntegrationDb = ReturnType<typeof db>;\ntype IntegrationTx = Parameters<Parameters<IntegrationDb['transaction']>[0]>[0];\n\nasync function loadLinearModuleParts(\n options: Parameters<IntegrationProviderModule['load']>[0] = {},\n): Promise<IntegrationModuleParts> {\n const {\n createLinearTokenStore,\n createLinearE2eRoutes,\n createLinearIntegrationProvider,\n config: linearConfig,\n deleteLinearInstallationByConnectionId,\n disconnectLinearInstallation: disconnectLinearInstallationRecords,\n getLinearInstallationByOrganizationId,\n db: linearDb,\n linearSecretsNamespace,\n migrationsPath: linearMigrationsPath,\n upsertLinearInstallation,\n } = await import('@shipfox/api-integration-linear');\n\n async function getExistingLinearConnection(input: {\n organizationId: string;\n }): Promise<CoreIntegrationConnection<'linear'> | undefined> {\n const installation = await getLinearInstallationByOrganizationId(input.organizationId);\n if (!installation) return undefined;\n const connection = await getIntegrationConnectionById(installation.connectionId);\n if (!connection) return undefined;\n return connection as CoreIntegrationConnection<'linear'>;\n }\n\n async function connectLinearInstallation(\n input: ConnectLinearInstallationInput,\n ): Promise<CoreIntegrationConnection<'linear'>> {\n return await retryConnectionSlugCollision(() =>\n db().transaction(async (tx) => {\n const baseSlug = slugifyConnectionSlug(`linear_${input.organizationUrlKey}`, {\n fallback: 'linear',\n });\n const slug = await resolveUniqueConnectionSlug(\n {\n workspaceId: input.workspaceId,\n provider: 'linear',\n externalAccountId: input.organizationId,\n baseSlug,\n },\n {tx},\n );\n const connection = await upsertIntegrationConnection(\n {\n workspaceId: input.workspaceId,\n provider: 'linear',\n externalAccountId: input.organizationId,\n slug,\n displayName: input.displayName,\n lifecycleStatus: 'active',\n },\n {tx},\n );\n\n await upsertLinearInstallation(\n {\n connectionId: connection.id,\n organizationId: input.organizationId,\n organizationUrlKey: input.organizationUrlKey,\n appUserId: input.appUserId,\n scopes: input.scopes,\n tokenExpiresAt: input.tokenExpiresAt,\n status: 'installed',\n },\n {tx},\n );\n\n return connection as CoreIntegrationConnection<'linear'>;\n }),\n );\n }\n\n async function disconnectLinearInstallation(input: {connectionId: string}): Promise<void> {\n await disconnectLinearInstallationRecords<IntegrationTx>({\n connectionId: input.connectionId,\n getConnection: getIntegrationConnectionById,\n deleteSecrets: (params) =>\n options.secrets?.linear?.deleteSecrets({\n ...params,\n namespace: linearNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(0),\n transaction: (fn) => db().transaction((tx) => fn(tx)),\n deleteConnection: (params, options) =>\n deleteIntegrationConnection({id: params.connectionId}, options),\n });\n }\n\n const fallbackSecrets: LinearSecretsStore = {\n getSecret: () => Promise.resolve(null),\n setSecrets: () => Promise.reject(new Error('Linear token storage is not configured')),\n };\n const secrets: LinearSecretsStore = options.secrets?.linear\n ? {\n getSecret: (params: Parameters<LinearSecretsStore['getSecret']>[0]) =>\n options.secrets?.linear?.getSecret({\n ...params,\n namespace: linearNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(null),\n setSecrets: (params: Parameters<LinearSecretsStore['setSecrets']>[0]) =>\n options.secrets?.linear?.setSecrets({\n ...params,\n namespace: linearNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(),\n }\n : fallbackSecrets;\n const tokenStore = createLinearTokenStore({\n resolveConnection: async (connectionId) => getIntegrationConnectionById(connectionId),\n secrets,\n });\n\n return {\n provider: createLinearIntegrationProvider({\n agentTools: {tokenStore, endpoint: linearConfig.LINEAR_MCP_ENDPOINT},\n cleanup: {\n deleteConnectionRecords: async (connection, {tx}) => {\n await deleteLinearInstallationByConnectionId(connection.id, {tx});\n },\n deleteConnectionSecrets: async (connection) => {\n // Scoped secrets accept the provider-local suffix, after this helper validates its prefix.\n await (options.secrets?.linear?.deleteSecrets({\n workspaceId: connection.workspaceId,\n namespace: linearNamespaceSuffix(linearSecretsNamespace(connection.id)),\n }) ?? Promise.resolve());\n },\n },\n routes: {\n tokenStore,\n getExistingLinearConnection,\n connectLinearInstallation,\n disconnectLinearInstallation,\n publishIntegrationEventReceived,\n recordDeliveryOnly,\n getIntegrationConnectionById,\n coreDb: db,\n },\n }),\n e2eRoutes: [\n createLinearE2eRoutes({\n tokenStore,\n getExistingLinearConnection,\n connectLinearInstallation,\n disconnectLinearInstallation,\n connectionCapabilities: ['agent_tools'],\n }),\n ],\n database: {\n db: linearDb,\n migrationsPath: linearMigrationsPath,\n migrationsTableName: LINEAR_MIGRATIONS_TABLE,\n },\n };\n}\n\nexport const linearProviderModule: IntegrationProviderModule = {\n id: 'linear',\n enabled: config.INTEGRATIONS_ENABLE_LINEAR_PROVIDER,\n load: loadLinearModuleParts,\n};\n\nfunction linearNamespaceSuffix(namespace: string): string {\n if (!namespace.startsWith(LINEAR_SECRETS_NAMESPACE_PREFIX)) {\n throw new Error('Linear provider attempted to access an unscoped secret namespace');\n }\n return namespace.slice(LINEAR_SECRETS_NAMESPACE_PREFIX.length);\n}\n"],"names":["slugifyConnectionSlug","config","deleteIntegrationConnection","getIntegrationConnectionById","resolveUniqueConnectionSlug","upsertIntegrationConnection","db","publishIntegrationEventReceived","recordDeliveryOnly","retryConnectionSlugCollision","LINEAR_MIGRATIONS_TABLE","LINEAR_SECRETS_NAMESPACE_PREFIX","loadLinearModuleParts","options","createLinearTokenStore","createLinearE2eRoutes","createLinearIntegrationProvider","linearConfig","deleteLinearInstallationByConnectionId","disconnectLinearInstallation","disconnectLinearInstallationRecords","getLinearInstallationByOrganizationId","linearDb","linearSecretsNamespace","migrationsPath","linearMigrationsPath","upsertLinearInstallation","getExistingLinearConnection","input","installation","organizationId","undefined","connection","connectionId","connectLinearInstallation","transaction","tx","baseSlug","organizationUrlKey","fallback","slug","workspaceId","provider","externalAccountId","displayName","lifecycleStatus","id","appUserId","scopes","tokenExpiresAt","status","getConnection","deleteSecrets","params","secrets","linear","namespace","linearNamespaceSuffix","Promise","resolve","fn","deleteConnection","fallbackSecrets","getSecret","setSecrets","reject","Error","tokenStore","resolveConnection","agentTools","endpoint","LINEAR_MCP_ENDPOINT","cleanup","deleteConnectionRecords","deleteConnectionSecrets","routes","coreDb","e2eRoutes","connectionCapabilities","database","migrationsTableName","linearProviderModule","enabled","INTEGRATIONS_ENABLE_LINEAR_PROVIDER","load","startsWith","slice","length"],"mappings":"AAAA,SAEEA,qBAAqB,QAChB,oCAAoC;AAK3C,SAAQC,MAAM,QAAO,aAAa;AAClC,SACEC,2BAA2B,EAC3BC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arD,uBAAuB;QACxCsD,mBAAmB,OAAOnC,eAAiB9B,6BAA6B8B;QACxEqB;IACF;IAEA,OAAO;QACLZ,UAAU1B,gCAAgC;YACxCqD,YAAY;gBAACF;gBAAYG,UAAUrD,aAAasD,mBAAmB;YAAA;YACnEC,SAAS;gBACPC,yBAAyB,OAAOzC,YAAY,EAACI,EAAE,EAAC;oBAC9C,MAAMlB,uCAAuCc,WAAWc,EAAE,EAAE;wBAACV;oBAAE;gBACjE;gBACAsC,yBAAyB,OAAO1C;oBAC9B,2FAA2F;oBAC3F,MAAOnB,CAAAA,QAAQyC,OAAO,EAAEC,QAAQH,cAAc;wBAC5CX,aAAaT,WAAWS,WAAW;wBACnCe,WAAWC,sBAAsBlC,uBAAuBS,WAAWc,EAAE;oBACvE,MAAMY,QAAQC,OAAO,EAAC;gBACxB;YACF;YACAgB,QAAQ;gBACNR;gBACAxC;gBACAO;gBACAf;gBACAZ;gBACAC;gBACAL;gBACAyE,QAAQtE;YACV;QACF;QACAuE,WAAW;YACT9D,sBAAsB;gBACpBoD;gBACAxC;gBACAO;gBACAf;gBACA2D,wBAAwB;oBAAC;iBAAc;YACzC;SACD;QACDC,UAAU;YACRzE,IAAIgB;YACJE,gBAAgBC;YAChBuD,qBAAqBtE;QACvB;IACF;AACF;AAEA,OAAO,MAAMuE,uBAAkD;IAC7DnC,IAAI;IACJoC,SAASjF,OAAOkF,mCAAmC;IACnDC,MAAMxE;AACR,EAAE;AAEF,SAAS6C,sBAAsBD,SAAiB;IAC9C,IAAI,CAACA,UAAU6B,UAAU,CAAC1E,kCAAkC;QAC1D,MAAM,IAAIuD,MAAM;IAClB;IACA,OAAOV,UAAU8B,KAAK,CAAC3E,gCAAgC4E,MAAM;AAC/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../src/providers/modules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../src/providers/modules.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,sBAAsB,EACtB,oCAAoC,EACrC,MAAM,qBAAqB,CAAC;AAgB7B,wBAAsB,0BAA0B,CAC9C,OAAO,GAAE,oCAAyC,GACjD,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAOnC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { cronProviderModule } from '#providers/cron.js';
|
|
2
2
|
import { giteaProviderModule } from '#providers/gitea.js';
|
|
3
3
|
import { githubProviderModule } from '#providers/github.js';
|
|
4
|
+
import { jiraProviderModule } from '#providers/jira.js';
|
|
4
5
|
import { linearProviderModule } from '#providers/linear.js';
|
|
5
6
|
import { sentryProviderModule } from '#providers/sentry.js';
|
|
7
|
+
import { slackProviderModule } from '#providers/slack.js';
|
|
6
8
|
import { webhookProviderModule } from '#providers/webhook.js';
|
|
7
9
|
// Order is significant: databases are migrated in this order, so list a provider
|
|
8
10
|
// before any that depend on its tables.
|
|
9
11
|
const providerModules = [
|
|
10
12
|
githubProviderModule,
|
|
11
13
|
linearProviderModule,
|
|
14
|
+
slackProviderModule,
|
|
15
|
+
jiraProviderModule,
|
|
12
16
|
sentryProviderModule,
|
|
13
17
|
giteaProviderModule,
|
|
14
18
|
cronProviderModule,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/modules.ts"],"sourcesContent":["import {cronProviderModule} from '#providers/cron.js';\nimport {giteaProviderModule} from '#providers/gitea.js';\nimport {githubProviderModule} from '#providers/github.js';\nimport {linearProviderModule} from '#providers/linear.js';\nimport {sentryProviderModule} from '#providers/sentry.js';\nimport type {\n IntegrationModuleParts,\n IntegrationProviderModuleLoadOptions,\n} from '#providers/types.js';\nimport {webhookProviderModule} from '#providers/webhook.js';\n\n// Order is significant: databases are migrated in this order, so list a provider\n// before any that depend on its tables.\nconst providerModules = [\n githubProviderModule,\n linearProviderModule,\n sentryProviderModule,\n giteaProviderModule,\n cronProviderModule,\n webhookProviderModule,\n];\n\nexport async function loadEnabledProviderModules(\n options: IntegrationProviderModuleLoadOptions = {},\n): Promise<IntegrationModuleParts[]> {\n const parts: IntegrationModuleParts[] = [];\n for (const module of providerModules) {\n if (!module.enabled) continue;\n parts.push(await module.load(options));\n }\n return parts;\n}\n"],"names":["cronProviderModule","giteaProviderModule","githubProviderModule","linearProviderModule","sentryProviderModule","webhookProviderModule","providerModules","loadEnabledProviderModules","options","parts","module","enabled","push","load"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,qBAAqB;AACtD,SAAQC,mBAAmB,QAAO,sBAAsB;AACxD,SAAQC,oBAAoB,QAAO,uBAAuB;AAC1D,SAAQC,oBAAoB,QAAO,uBAAuB;AAC1D,SAAQC,oBAAoB,QAAO,uBAAuB;
|
|
1
|
+
{"version":3,"sources":["../../src/providers/modules.ts"],"sourcesContent":["import {cronProviderModule} from '#providers/cron.js';\nimport {giteaProviderModule} from '#providers/gitea.js';\nimport {githubProviderModule} from '#providers/github.js';\nimport {jiraProviderModule} from '#providers/jira.js';\nimport {linearProviderModule} from '#providers/linear.js';\nimport {sentryProviderModule} from '#providers/sentry.js';\nimport {slackProviderModule} from '#providers/slack.js';\nimport type {\n IntegrationModuleParts,\n IntegrationProviderModuleLoadOptions,\n} from '#providers/types.js';\nimport {webhookProviderModule} from '#providers/webhook.js';\n\n// Order is significant: databases are migrated in this order, so list a provider\n// before any that depend on its tables.\nconst providerModules = [\n githubProviderModule,\n linearProviderModule,\n slackProviderModule,\n jiraProviderModule,\n sentryProviderModule,\n giteaProviderModule,\n cronProviderModule,\n webhookProviderModule,\n];\n\nexport async function loadEnabledProviderModules(\n options: IntegrationProviderModuleLoadOptions = {},\n): Promise<IntegrationModuleParts[]> {\n const parts: IntegrationModuleParts[] = [];\n for (const module of providerModules) {\n if (!module.enabled) continue;\n parts.push(await module.load(options));\n }\n return parts;\n}\n"],"names":["cronProviderModule","giteaProviderModule","githubProviderModule","jiraProviderModule","linearProviderModule","sentryProviderModule","slackProviderModule","webhookProviderModule","providerModules","loadEnabledProviderModules","options","parts","module","enabled","push","load"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,qBAAqB;AACtD,SAAQC,mBAAmB,QAAO,sBAAsB;AACxD,SAAQC,oBAAoB,QAAO,uBAAuB;AAC1D,SAAQC,kBAAkB,QAAO,qBAAqB;AACtD,SAAQC,oBAAoB,QAAO,uBAAuB;AAC1D,SAAQC,oBAAoB,QAAO,uBAAuB;AAC1D,SAAQC,mBAAmB,QAAO,sBAAsB;AAKxD,SAAQC,qBAAqB,QAAO,wBAAwB;AAE5D,iFAAiF;AACjF,wCAAwC;AACxC,MAAMC,kBAAkB;IACtBN;IACAE;IACAE;IACAH;IACAE;IACAJ;IACAD;IACAO;CACD;AAED,OAAO,eAAeE,2BACpBC,UAAgD,CAAC,CAAC;IAElD,MAAMC,QAAkC,EAAE;IAC1C,KAAK,MAAMC,UAAUJ,gBAAiB;QACpC,IAAI,CAACI,OAAOC,OAAO,EAAE;QACrBF,MAAMG,IAAI,CAAC,MAAMF,OAAOG,IAAI,CAACL;IAC/B;IACA,OAAOC;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../src/providers/slack.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAyB,yBAAyB,EAAC,MAAM,qBAAqB,CAAC;AAkK3F,eAAO,MAAM,mBAAmB,EAAE,yBAIjC,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { slugifyConnectionSlug } from '@shipfox/api-integration-core-dto';
|
|
2
|
+
import { config } from '#config.js';
|
|
3
|
+
import { deleteIntegrationConnection, getIntegrationConnectionById, resolveUniqueConnectionSlug, upsertIntegrationConnection } from '#db/connections.js';
|
|
4
|
+
import { db } from '#db/db.js';
|
|
5
|
+
import { claimWebhookDelivery, publishIntegrationEventReceived, recordDeliveryOnly } from '#db/webhook-deliveries.js';
|
|
6
|
+
import { retryConnectionSlugCollision } from '#providers/connection-slug.js';
|
|
7
|
+
const SLACK_MIGRATIONS_TABLE = '__drizzle_migrations_integrations_slack';
|
|
8
|
+
const SLACK_SECRETS_NAMESPACE_PREFIX = 'system/integrations/slack/';
|
|
9
|
+
async function loadSlackModuleParts(options = {}) {
|
|
10
|
+
const { createSlackE2eRoutes, createSlackIntegrationProvider, createSlackTokenStore, db: slackDb, deleteSlackInstallationByConnectionId, disconnectSlackInstallation: disconnectSlackInstallationRecords, getSlackInstallationByTeamId, migrationsPath: slackMigrationsPath, slackSecretsNamespace, upsertSlackInstallation } = await import('@shipfox/api-integration-slack');
|
|
11
|
+
async function getExistingSlackConnection(input) {
|
|
12
|
+
const installation = await getSlackInstallationByTeamId(input.teamId);
|
|
13
|
+
if (!installation) return undefined;
|
|
14
|
+
const connection = await getIntegrationConnectionById(installation.connectionId);
|
|
15
|
+
if (!connection) return undefined;
|
|
16
|
+
return connection;
|
|
17
|
+
}
|
|
18
|
+
async function connectSlackInstallation(input) {
|
|
19
|
+
return await retryConnectionSlugCollision(()=>db().transaction(async (tx)=>{
|
|
20
|
+
const baseSlug = slugifyConnectionSlug(`slack_${input.teamName || input.teamId}`, {
|
|
21
|
+
fallback: 'slack'
|
|
22
|
+
});
|
|
23
|
+
const slug = await resolveUniqueConnectionSlug({
|
|
24
|
+
workspaceId: input.workspaceId,
|
|
25
|
+
provider: 'slack',
|
|
26
|
+
externalAccountId: input.teamId,
|
|
27
|
+
baseSlug
|
|
28
|
+
}, {
|
|
29
|
+
tx
|
|
30
|
+
});
|
|
31
|
+
const connection = await upsertIntegrationConnection({
|
|
32
|
+
workspaceId: input.workspaceId,
|
|
33
|
+
provider: 'slack',
|
|
34
|
+
externalAccountId: input.teamId,
|
|
35
|
+
slug,
|
|
36
|
+
displayName: input.displayName,
|
|
37
|
+
lifecycleStatus: 'active'
|
|
38
|
+
}, {
|
|
39
|
+
tx
|
|
40
|
+
});
|
|
41
|
+
await upsertSlackInstallation({
|
|
42
|
+
connectionId: connection.id,
|
|
43
|
+
teamId: input.teamId,
|
|
44
|
+
teamName: input.teamName,
|
|
45
|
+
appId: input.appId,
|
|
46
|
+
botUserId: input.botUserId,
|
|
47
|
+
scopes: input.scopes,
|
|
48
|
+
tokenExpiresAt: input.tokenExpiresAt,
|
|
49
|
+
status: 'installed'
|
|
50
|
+
}, {
|
|
51
|
+
tx
|
|
52
|
+
});
|
|
53
|
+
return connection;
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
async function disconnectSlackInstallation(input) {
|
|
57
|
+
await disconnectSlackInstallationRecords({
|
|
58
|
+
connectionId: input.connectionId,
|
|
59
|
+
getConnection: getIntegrationConnectionById,
|
|
60
|
+
deleteSecrets: (params)=>options.secrets?.slack?.deleteSecrets({
|
|
61
|
+
...params,
|
|
62
|
+
namespace: slackNamespaceSuffix(params.namespace)
|
|
63
|
+
}) ?? Promise.resolve(0),
|
|
64
|
+
transaction: (fn)=>db().transaction((tx)=>fn(tx)),
|
|
65
|
+
deleteConnection: (params, options)=>deleteIntegrationConnection({
|
|
66
|
+
id: params.connectionId
|
|
67
|
+
}, options)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const fallbackSecrets = {
|
|
71
|
+
getSecret: ()=>Promise.resolve(null),
|
|
72
|
+
setSecrets: ()=>Promise.reject(new Error('Slack token storage is not configured'))
|
|
73
|
+
};
|
|
74
|
+
const secrets = options.secrets?.slack ? {
|
|
75
|
+
getSecret: (params)=>options.secrets?.slack?.getSecret({
|
|
76
|
+
...params,
|
|
77
|
+
namespace: slackNamespaceSuffix(params.namespace)
|
|
78
|
+
}) ?? Promise.resolve(null),
|
|
79
|
+
setSecrets: (params)=>options.secrets?.slack?.setSecrets({
|
|
80
|
+
...params,
|
|
81
|
+
namespace: slackNamespaceSuffix(params.namespace)
|
|
82
|
+
}) ?? Promise.resolve()
|
|
83
|
+
} : fallbackSecrets;
|
|
84
|
+
const tokenStore = createSlackTokenStore({
|
|
85
|
+
resolveConnection: async (connectionId)=>getIntegrationConnectionById(connectionId),
|
|
86
|
+
secrets
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
provider: createSlackIntegrationProvider({
|
|
90
|
+
agentTools: {
|
|
91
|
+
tokenStore
|
|
92
|
+
},
|
|
93
|
+
cleanup: {
|
|
94
|
+
deleteConnectionRecords: async (connection, { tx })=>{
|
|
95
|
+
await deleteSlackInstallationByConnectionId(connection.id, {
|
|
96
|
+
tx
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
deleteConnectionSecrets: async (connection)=>{
|
|
100
|
+
// Scoped secrets accept the provider-local suffix, after this helper validates its prefix.
|
|
101
|
+
await (options.secrets?.slack?.deleteSecrets({
|
|
102
|
+
workspaceId: connection.workspaceId,
|
|
103
|
+
namespace: slackNamespaceSuffix(slackSecretsNamespace(connection.id))
|
|
104
|
+
}) ?? Promise.resolve());
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
routes: {
|
|
108
|
+
tokenStore,
|
|
109
|
+
getExistingSlackConnection,
|
|
110
|
+
connectSlackInstallation,
|
|
111
|
+
disconnectSlackInstallation,
|
|
112
|
+
coreDb: db,
|
|
113
|
+
claimWebhookDelivery,
|
|
114
|
+
publishIntegrationEventReceived,
|
|
115
|
+
recordDeliveryOnly,
|
|
116
|
+
getIntegrationConnectionById
|
|
117
|
+
}
|
|
118
|
+
}),
|
|
119
|
+
e2eRoutes: [
|
|
120
|
+
createSlackE2eRoutes({
|
|
121
|
+
tokenStore,
|
|
122
|
+
getExistingSlackConnection,
|
|
123
|
+
connectSlackInstallation,
|
|
124
|
+
disconnectSlackInstallation,
|
|
125
|
+
connectionCapabilities: [
|
|
126
|
+
'agent_tools'
|
|
127
|
+
]
|
|
128
|
+
})
|
|
129
|
+
],
|
|
130
|
+
database: {
|
|
131
|
+
db: slackDb,
|
|
132
|
+
migrationsPath: slackMigrationsPath,
|
|
133
|
+
migrationsTableName: SLACK_MIGRATIONS_TABLE
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export const slackProviderModule = {
|
|
138
|
+
id: 'slack',
|
|
139
|
+
enabled: config.INTEGRATIONS_ENABLE_SLACK_PROVIDER,
|
|
140
|
+
load: loadSlackModuleParts
|
|
141
|
+
};
|
|
142
|
+
function slackNamespaceSuffix(namespace) {
|
|
143
|
+
if (!namespace.startsWith(SLACK_SECRETS_NAMESPACE_PREFIX)) {
|
|
144
|
+
throw new Error('Slack provider attempted to access an unscoped secret namespace');
|
|
145
|
+
}
|
|
146
|
+
return namespace.slice(SLACK_SECRETS_NAMESPACE_PREFIX.length);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=slack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providers/slack.ts"],"sourcesContent":["import {\n type IntegrationConnection as CoreIntegrationConnection,\n slugifyConnectionSlug,\n} from '@shipfox/api-integration-core-dto';\nimport type {\n ConnectSlackInstallationInput,\n SlackSecretsStore,\n} from '@shipfox/api-integration-slack';\nimport {config} from '#config.js';\nimport {\n deleteIntegrationConnection,\n getIntegrationConnectionById,\n resolveUniqueConnectionSlug,\n upsertIntegrationConnection,\n} from '#db/connections.js';\nimport {db} from '#db/db.js';\nimport {\n claimWebhookDelivery,\n publishIntegrationEventReceived,\n recordDeliveryOnly,\n} from '#db/webhook-deliveries.js';\nimport {retryConnectionSlugCollision} from '#providers/connection-slug.js';\nimport type {IntegrationModuleParts, IntegrationProviderModule} from '#providers/types.js';\n\nconst SLACK_MIGRATIONS_TABLE = '__drizzle_migrations_integrations_slack';\nconst SLACK_SECRETS_NAMESPACE_PREFIX = 'system/integrations/slack/';\n\ntype IntegrationDb = ReturnType<typeof db>;\ntype IntegrationTx = Parameters<Parameters<IntegrationDb['transaction']>[0]>[0];\n\nasync function loadSlackModuleParts(\n options: Parameters<IntegrationProviderModule['load']>[0] = {},\n): Promise<IntegrationModuleParts> {\n const {\n createSlackE2eRoutes,\n createSlackIntegrationProvider,\n createSlackTokenStore,\n db: slackDb,\n deleteSlackInstallationByConnectionId,\n disconnectSlackInstallation: disconnectSlackInstallationRecords,\n getSlackInstallationByTeamId,\n migrationsPath: slackMigrationsPath,\n slackSecretsNamespace,\n upsertSlackInstallation,\n } = await import('@shipfox/api-integration-slack');\n\n async function getExistingSlackConnection(input: {\n teamId: string;\n }): Promise<CoreIntegrationConnection<'slack'> | undefined> {\n const installation = await getSlackInstallationByTeamId(input.teamId);\n if (!installation) return undefined;\n const connection = await getIntegrationConnectionById(installation.connectionId);\n if (!connection) return undefined;\n return connection as CoreIntegrationConnection<'slack'>;\n }\n\n async function connectSlackInstallation(\n input: ConnectSlackInstallationInput,\n ): Promise<CoreIntegrationConnection<'slack'>> {\n return await retryConnectionSlugCollision(() =>\n db().transaction(async (tx) => {\n const baseSlug = slugifyConnectionSlug(`slack_${input.teamName || input.teamId}`, {\n fallback: 'slack',\n });\n const slug = await resolveUniqueConnectionSlug(\n {\n workspaceId: input.workspaceId,\n provider: 'slack',\n externalAccountId: input.teamId,\n baseSlug,\n },\n {tx},\n );\n const connection = await upsertIntegrationConnection(\n {\n workspaceId: input.workspaceId,\n provider: 'slack',\n externalAccountId: input.teamId,\n slug,\n displayName: input.displayName,\n lifecycleStatus: 'active',\n },\n {tx},\n );\n await upsertSlackInstallation(\n {\n connectionId: connection.id,\n teamId: input.teamId,\n teamName: input.teamName,\n appId: input.appId,\n botUserId: input.botUserId,\n scopes: input.scopes,\n tokenExpiresAt: input.tokenExpiresAt,\n status: 'installed',\n },\n {tx},\n );\n return connection as CoreIntegrationConnection<'slack'>;\n }),\n );\n }\n\n async function disconnectSlackInstallation(input: {connectionId: string}): Promise<void> {\n await disconnectSlackInstallationRecords<IntegrationTx>({\n connectionId: input.connectionId,\n getConnection: getIntegrationConnectionById,\n deleteSecrets: (params) =>\n options.secrets?.slack?.deleteSecrets({\n ...params,\n namespace: slackNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(0),\n transaction: (fn) => db().transaction((tx) => fn(tx)),\n deleteConnection: (params, options) =>\n deleteIntegrationConnection({id: params.connectionId}, options),\n });\n }\n\n const fallbackSecrets: SlackSecretsStore = {\n getSecret: () => Promise.resolve(null),\n setSecrets: () => Promise.reject(new Error('Slack token storage is not configured')),\n };\n const secrets: SlackSecretsStore = options.secrets?.slack\n ? {\n getSecret: (params: Parameters<SlackSecretsStore['getSecret']>[0]) =>\n options.secrets?.slack?.getSecret({\n ...params,\n namespace: slackNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(null),\n setSecrets: (params: Parameters<SlackSecretsStore['setSecrets']>[0]) =>\n options.secrets?.slack?.setSecrets({\n ...params,\n namespace: slackNamespaceSuffix(params.namespace),\n }) ?? Promise.resolve(),\n }\n : fallbackSecrets;\n const tokenStore = createSlackTokenStore({\n resolveConnection: async (connectionId) => getIntegrationConnectionById(connectionId),\n secrets,\n });\n\n return {\n provider: createSlackIntegrationProvider({\n agentTools: {tokenStore},\n cleanup: {\n deleteConnectionRecords: async (connection, {tx}) => {\n await deleteSlackInstallationByConnectionId(connection.id, {tx});\n },\n deleteConnectionSecrets: async (connection) => {\n // Scoped secrets accept the provider-local suffix, after this helper validates its prefix.\n await (options.secrets?.slack?.deleteSecrets({\n workspaceId: connection.workspaceId,\n namespace: slackNamespaceSuffix(slackSecretsNamespace(connection.id)),\n }) ?? Promise.resolve());\n },\n },\n routes: {\n tokenStore,\n getExistingSlackConnection,\n connectSlackInstallation,\n disconnectSlackInstallation,\n coreDb: db,\n claimWebhookDelivery,\n publishIntegrationEventReceived,\n recordDeliveryOnly,\n getIntegrationConnectionById,\n },\n }),\n e2eRoutes: [\n createSlackE2eRoutes({\n tokenStore,\n getExistingSlackConnection,\n connectSlackInstallation,\n disconnectSlackInstallation,\n connectionCapabilities: ['agent_tools'],\n }),\n ],\n database: {\n db: slackDb,\n migrationsPath: slackMigrationsPath,\n migrationsTableName: SLACK_MIGRATIONS_TABLE,\n },\n };\n}\n\nexport const slackProviderModule: IntegrationProviderModule = {\n id: 'slack',\n enabled: config.INTEGRATIONS_ENABLE_SLACK_PROVIDER,\n load: loadSlackModuleParts,\n};\n\nfunction slackNamespaceSuffix(namespace: string): string {\n if (!namespace.startsWith(SLACK_SECRETS_NAMESPACE_PREFIX)) {\n throw new Error('Slack provider attempted to access an unscoped secret namespace');\n }\n return namespace.slice(SLACK_SECRETS_NAMESPACE_PREFIX.length);\n}\n"],"names":["slugifyConnectionSlug","config","deleteIntegrationConnection","getIntegrationConnectionById","resolveUniqueConnectionSlug","upsertIntegrationConnection","db","claimWebhookDelivery","publishIntegrationEventReceived","recordDeliveryOnly","retryConnectionSlugCollision","SLACK_MIGRATIONS_TABLE","SLACK_SECRETS_NAMESPACE_PREFIX","loadSlackModuleParts","options","createSlackE2eRoutes","createSlackIntegrationProvider","createSlackTokenStore","slackDb","deleteSlackInstallationByConnectionId","disconnectSlackInstallation","disconnectSlackInstallationRecords","getSlackInstallationByTeamId","migrationsPath","slackMigrationsPath","slackSecretsNamespace","upsertSlackInstallation","getExistingSlackConnection","input","installation","teamId","undefined","connection","connectionId","connectSlackInstallation","transaction","tx","baseSlug","teamName","fallback","slug","workspaceId","provider","externalAccountId","displayName","lifecycleStatus","id","appId","botUserId","scopes","tokenExpiresAt","status","getConnection","deleteSecrets","params","secrets","slack","namespace","slackNamespaceSuffix","Promise","resolve","fn","deleteConnection","fallbackSecrets","getSecret","setSecrets","reject","Error","tokenStore","resolveConnection","agentTools","cleanup","deleteConnectionRecords","deleteConnectionSecrets","routes","coreDb","e2eRoutes","connectionCapabilities","database","migrationsTableName","slackProviderModule","enabled","INTEGRATIONS_ENABLE_SLACK_PROVIDER","load","startsWith","slice","length"],"mappings":"AAAA,SAEEA,qBAAqB,QAChB,oCAAoC;AAK3C,SAAQC,MAAM,QAAO,aAAa;AAClC,SACEC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,2BAA2B,EAC3BC,2BAA2B,QACtB,qBAAqB;AAC5B,SAAQC,EA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OpC,eAAiB9B,6BAA6B8B;QACxEsB;IACF;IAEA,OAAO;QACLb,UAAU1B,+BAA+B;YACvCsD,YAAY;gBAACF;YAAU;YACvBG,SAAS;gBACPC,yBAAyB,OAAOxC,YAAY,EAACI,EAAE,EAAC;oBAC9C,MAAMjB,sCAAsCa,WAAWc,EAAE,EAAE;wBAACV;oBAAE;gBAChE;gBACAqC,yBAAyB,OAAOzC;oBAC9B,2FAA2F;oBAC3F,MAAOlB,CAAAA,QAAQyC,OAAO,EAAEC,OAAOH,cAAc;wBAC3CZ,aAAaT,WAAWS,WAAW;wBACnCgB,WAAWC,qBAAqBjC,sBAAsBO,WAAWc,EAAE;oBACrE,MAAMa,QAAQC,OAAO,EAAC;gBACxB;YACF;YACAc,QAAQ;gBACNN;gBACAzC;gBACAO;gBACAd;gBACAuD,QAAQrE;gBACRC;gBACAC;gBACAC;gBACAN;YACF;QACF;QACAyE,WAAW;YACT7D,qBAAqB;gBACnBqD;gBACAzC;gBACAO;gBACAd;gBACAyD,wBAAwB;oBAAC;iBAAc;YACzC;SACD;QACDC,UAAU;YACRxE,IAAIY;YACJK,gBAAgBC;YAChBuD,qBAAqBpE;QACvB;IACF;AACF;AAEA,OAAO,MAAMqE,sBAAiD;IAC5DlC,IAAI;IACJmC,SAAShF,OAAOiF,kCAAkC;IAClDC,MAAMtE;AACR,EAAE;AAEF,SAAS6C,qBAAqBD,SAAiB;IAC7C,IAAI,CAACA,UAAU2B,UAAU,CAACxE,iCAAiC;QACzD,MAAM,IAAIuD,MAAM;IAClB;IACA,OAAOV,UAAU4B,KAAK,CAACzE,+BAA+B0E,MAAM;AAC9D"}
|
|
@@ -32,7 +32,9 @@ export interface IntegrationProviderModuleLoadOptions {
|
|
|
32
32
|
}
|
|
33
33
|
export interface IntegrationProviderSecrets {
|
|
34
34
|
github?: IntegrationProviderScopedSecrets | undefined;
|
|
35
|
+
jira?: IntegrationProviderScopedSecrets | undefined;
|
|
35
36
|
linear?: IntegrationProviderScopedSecrets | undefined;
|
|
37
|
+
slack?: IntegrationProviderScopedSecrets | undefined;
|
|
36
38
|
deleteSecrets(params: {
|
|
37
39
|
workspaceId: string;
|
|
38
40
|
namespace: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAC,cAAc,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AAEpE;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACtC,SAAS,CAAC,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;IACtC,OAAO,CAAC,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IACrC,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;CACvD;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,OAAO,CAAC,EAAE,oCAAoC,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;CACvF;AAED,MAAM,WAAW,oCAAoC;IACnD,OAAO,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;CAClD;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,gCAAgC,GAAG,SAAS,CAAC;IACtD,MAAM,CAAC,EAAE,gCAAgC,GAAG,SAAS,CAAC;IACtD,aAAa,CAAC,MAAM,EAAE;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAC,GAA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|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/types.ts"],"sourcesContent":["import type {RouteExport} from '@shipfox/node-fastify';\nimport type {ModuleDatabase, ModuleWorker} from '@shipfox/node-module';\nimport type {IntegrationProvider} from '#core/entities/provider.js';\n\n/**\n * Everything one integration contributes to the composed integrations module:\n * a registry provider, plus an optional dedicated database, background workers,\n * and one-shot boot-time tasks. Providers that own none of these simply omit them.\n *\n * A startup task is run once after modules are initialized (migrations done). The\n * provider owns its own wiring — core runs each task generically and isolates\n * failures so a task can never gate API boot.\n */\nexport interface IntegrationModuleParts {\n provider: IntegrationProvider;\n database?: ModuleDatabase | undefined;\n e2eRoutes?: RouteExport[] | undefined;\n workers?: ModuleWorker[] | undefined;\n startupTasks?: Array<() => Promise<void>> | undefined;\n}\n\n/**\n * A config-gated integration, registered once in `providerModules`. `load` is\n * called lazily and only when `enabled`, so a disabled provider never imports\n * its (potentially heavy) implementation package.\n */\nexport interface IntegrationProviderModule {\n id: string;\n enabled: boolean;\n load(options?: IntegrationProviderModuleLoadOptions): Promise<IntegrationModuleParts>;\n}\n\nexport interface IntegrationProviderModuleLoadOptions {\n secrets?: IntegrationProviderSecrets | undefined;\n}\n\nexport interface IntegrationProviderSecrets {\n github?: IntegrationProviderScopedSecrets | undefined;\n linear?: IntegrationProviderScopedSecrets | undefined;\n deleteSecrets(params: {workspaceId: string; namespace: string}): Promise<number>;\n}\n\nexport interface IntegrationProviderScopedSecrets {\n getSecret(params: {workspaceId: string; namespace: string; key: string}): Promise<string | null>;\n setSecrets(params: {\n workspaceId: string;\n namespace: string;\n values: Record<string, string>;\n editedBy?: string | null | undefined;\n }): Promise<void>;\n deleteSecrets(params: {workspaceId: string; namespace: string}): Promise<number>;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/providers/types.ts"],"sourcesContent":["import type {RouteExport} from '@shipfox/node-fastify';\nimport type {ModuleDatabase, ModuleWorker} from '@shipfox/node-module';\nimport type {IntegrationProvider} from '#core/entities/provider.js';\n\n/**\n * Everything one integration contributes to the composed integrations module:\n * a registry provider, plus an optional dedicated database, background workers,\n * and one-shot boot-time tasks. Providers that own none of these simply omit them.\n *\n * A startup task is run once after modules are initialized (migrations done). The\n * provider owns its own wiring — core runs each task generically and isolates\n * failures so a task can never gate API boot.\n */\nexport interface IntegrationModuleParts {\n provider: IntegrationProvider;\n database?: ModuleDatabase | undefined;\n e2eRoutes?: RouteExport[] | undefined;\n workers?: ModuleWorker[] | undefined;\n startupTasks?: Array<() => Promise<void>> | undefined;\n}\n\n/**\n * A config-gated integration, registered once in `providerModules`. `load` is\n * called lazily and only when `enabled`, so a disabled provider never imports\n * its (potentially heavy) implementation package.\n */\nexport interface IntegrationProviderModule {\n id: string;\n enabled: boolean;\n load(options?: IntegrationProviderModuleLoadOptions): Promise<IntegrationModuleParts>;\n}\n\nexport interface IntegrationProviderModuleLoadOptions {\n secrets?: IntegrationProviderSecrets | undefined;\n}\n\nexport interface IntegrationProviderSecrets {\n github?: IntegrationProviderScopedSecrets | undefined;\n jira?: IntegrationProviderScopedSecrets | undefined;\n linear?: IntegrationProviderScopedSecrets | undefined;\n slack?: IntegrationProviderScopedSecrets | undefined;\n deleteSecrets(params: {workspaceId: string; namespace: string}): Promise<number>;\n}\n\nexport interface IntegrationProviderScopedSecrets {\n getSecret(params: {workspaceId: string; namespace: string; key: string}): Promise<string | null>;\n setSecrets(params: {\n workspaceId: string;\n namespace: string;\n values: Record<string, string>;\n editedBy?: string | null | undefined;\n }): Promise<void>;\n deleteSecrets(params: {workspaceId: string; namespace: string}): Promise<number>;\n}\n"],"names":[],"mappings":"AA4CA,WASC"}
|