@shipfox/api-integration-core 12.1.1 → 12.2.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/.turbo/turbo-type.log +0 -1
- package/CHANGELOG.md +26 -0
- package/dist/db/connections.d.ts.map +1 -1
- package/dist/db/connections.js +66 -13
- package/dist/db/connections.js.map +1 -1
- package/dist/providers/jira.d.ts.map +1 -1
- package/dist/providers/jira.js +17 -1
- package/dist/providers/jira.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/db/connections.test.ts +90 -0
- package/src/db/connections.ts +92 -13
- package/src/providers/jira.test.ts +133 -0
- package/src/providers/jira.ts +17 -0
- package/tsconfig.build.tsbuildinfo +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
$ shipfox-swc && shipfox-temporal-bundle dist/temporal/workflows/index.js
|
|
2
|
-
Successfully compiled: 50 files with swc (
|
|
3
|
-
2026-08-
|
|
2
|
+
Successfully compiled: 50 files with swc (632.34ms)
|
|
3
|
+
2026-08-06T13:13:12.437Z [INFO] asset workflow-bundle-646aca428e9943f8cf17.js 3.17 MiB [emitted] [immutable] (name: main)
|
|
4
4
|
orphan modules 33.5 KiB [orphan] 21 modules
|
|
5
5
|
runtime modules 1.13 KiB 5 modules
|
|
6
6
|
modules by path ../../../../node_modules/.pnpm/ 970 KiB 196 modules
|
|
@@ -12,6 +12,6 @@ optional modules 30 bytes [optional]
|
|
|
12
12
|
__temporal_custom_payload_converter (ignored) 15 bytes [optional] [built] [code generated]
|
|
13
13
|
__temporal_custom_failure_converter (ignored) 15 bytes [optional] [built] [code generated]
|
|
14
14
|
../../../shared/node/temporal/dist/workflow-error-interceptor.js 1.21 KiB [built] [code generated]
|
|
15
|
-
webpack 5.107.2 compiled successfully in
|
|
16
|
-
2026-08-
|
|
15
|
+
webpack 5.107.2 compiled successfully in 10166 ms
|
|
16
|
+
2026-08-06T13:13:12.466Z [INFO] Workflow bundle created { size: '3.17MB' }
|
|
17
17
|
/home/runner/work/shipfox/shipfox/libs/api/integration/core/dist/temporal/workflows/index.js: 3323154 bytes
|
package/.turbo/turbo-type.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @shipfox/api-integration-core
|
|
2
2
|
|
|
3
|
+
## 12.2.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9695359: Cleans up Jira installation records and tokens when a workspace deletes an integration so the site can be reinstalled.
|
|
8
|
+
- 7901a60: Retry workspace workflow definition syncs when an integration connection becomes available.
|
|
9
|
+
- Updated dependencies [9695359]
|
|
10
|
+
- Updated dependencies [7901a60]
|
|
11
|
+
- Updated dependencies [ce0984d]
|
|
12
|
+
- @shipfox/api-integration-jira@12.2.0
|
|
13
|
+
- @shipfox/api-integration-core-dto@12.2.0
|
|
14
|
+
- @shipfox/api-workflows-dto@12.2.0
|
|
15
|
+
- @shipfox/api-integration-spi@1.0.1
|
|
16
|
+
- @shipfox/node-opentelemetry@0.6.4
|
|
17
|
+
- @shipfox/api-agent-dto@12.2.0
|
|
18
|
+
- @shipfox/api-integration-gitea@12.2.0
|
|
19
|
+
- @shipfox/api-integration-github@12.2.0
|
|
20
|
+
- @shipfox/api-integration-linear@12.2.0
|
|
21
|
+
- @shipfox/api-integration-sentry@12.2.0
|
|
22
|
+
- @shipfox/api-integration-slack@12.2.0
|
|
23
|
+
- @shipfox/api-integration-webhook@12.2.0
|
|
24
|
+
- @shipfox/node-fastify@0.4.2
|
|
25
|
+
- @shipfox/node-module@1.0.6
|
|
26
|
+
- @shipfox/node-temporal@0.4.5
|
|
27
|
+
- @shipfox/api-auth-context@12.2.0
|
|
28
|
+
|
|
3
29
|
## 12.1.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../src/db/connections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../src/db/connections.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,qBAAqB,EACrB,oCAAoC,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AAExE,OAAO,EAAC,EAAE,EAAC,MAAM,SAAS,CAAC;AAI3B,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AAC3C,KAAK,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhF,MAAM,WAAW,iCAAiC;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,oCAAoC,GAAG,SAAS,CAAC;CACpE;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,EACzC,OAAO,GAAE;IAAC,EAAE,CAAC,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS,CAAA;CAAM,GAC7D,OAAO,CAAC,qBAAqB,CAAC,CA+DhC;AAED,MAAM,WAAW,iCAAiC;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,oCAAoC,GAAG,SAAS,CAAC;CACpE;AAOD,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAW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,MAAM,EAAE,gDAAgD,EACxD,OAAO,GAAE;IAAC,EAAE,CAAC,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS,CAAA;CAAM,GAC7D,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAyB5C;AAED,MAAM,MAAM,4CAA4C,GACtD,OAAO,0CAA0C,CAAC;AAiBpD,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,EACpB,OAAO,GAAE;IAAC,EAAE,CAAC,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS,CAAA;CAAM,GAC7D,OAAO,CAAC,OAAO,CAAC,CAMlB;AAED,MAAM,MAAM,6BAA6B,GAAG,OAAO,2BAA2B,CAAC;AAE/E,MAAM,WAAW,gCAAgC;IAC/C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,gCAAgC,GACvC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CASlC;AAED,MAAM,WAAW,0CAA0C;IACzD,QAAQ,EAAE,uBAAuB,CAAC;CACnC;AAED,wBAAsB,oCAAoC,CACxD,MAAM,EAAE,0CAA0C,GACjD,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAQlC"}
|
package/dist/db/connections.js
CHANGED
|
@@ -1,33 +1,53 @@
|
|
|
1
|
-
import { CONNECTION_SLUG_MAX_LENGTH } from '@shipfox/api-integration-core-dto';
|
|
1
|
+
import { CONNECTION_SLUG_MAX_LENGTH, INTEGRATION_CONNECTION_AVAILABLE } from '@shipfox/api-integration-core-dto';
|
|
2
2
|
import { ConnectionSlugConflictError } from '@shipfox/api-integration-spi';
|
|
3
|
+
import { writeOutboxEvent } from '@shipfox/node-outbox';
|
|
3
4
|
import { and, eq } from 'drizzle-orm';
|
|
4
5
|
import { IntegrationConnectionAlreadyExistsError } from '#core/errors.js';
|
|
5
6
|
import { db } from './db.js';
|
|
6
7
|
import { integrationConnections, toIntegrationConnection } from './schema/connections.js';
|
|
8
|
+
import { integrationsOutbox } from './schema/outbox.js';
|
|
7
9
|
export async function upsertIntegrationConnection(params, options = {}) {
|
|
8
|
-
|
|
10
|
+
if (options.tx === undefined) {
|
|
11
|
+
return await db().transaction((tx)=>upsertIntegrationConnection(params, {
|
|
12
|
+
tx
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
const executor = options.tx;
|
|
9
16
|
const now = new Date();
|
|
10
|
-
|
|
17
|
+
let [row] = await executor.insert(integrationConnections).values({
|
|
11
18
|
workspaceId: params.workspaceId,
|
|
12
19
|
provider: params.provider,
|
|
13
20
|
externalAccountId: params.externalAccountId,
|
|
14
21
|
slug: params.slug,
|
|
15
22
|
displayName: params.displayName,
|
|
16
23
|
lifecycleStatus: params.lifecycleStatus ?? 'active'
|
|
17
|
-
}).
|
|
24
|
+
}).onConflictDoNothing({
|
|
18
25
|
target: [
|
|
19
26
|
integrationConnections.workspaceId,
|
|
20
27
|
integrationConnections.provider,
|
|
21
28
|
integrationConnections.externalAccountId
|
|
22
|
-
]
|
|
23
|
-
|
|
29
|
+
]
|
|
30
|
+
}).returning();
|
|
31
|
+
let becameAvailable = row?.lifecycleStatus === 'active';
|
|
32
|
+
if (!row) {
|
|
33
|
+
const [existing] = await executor.select({
|
|
34
|
+
id: integrationConnections.id,
|
|
35
|
+
lifecycleStatus: integrationConnections.lifecycleStatus
|
|
36
|
+
}).from(integrationConnections).where(and(eq(integrationConnections.workspaceId, params.workspaceId), eq(integrationConnections.provider, params.provider), eq(integrationConnections.externalAccountId, params.externalAccountId))).limit(1).for('update');
|
|
37
|
+
if (!existing) throw new Error('Integration connection upsert conflict row was not found');
|
|
38
|
+
[row] = await executor.update(integrationConnections).set({
|
|
24
39
|
displayName: params.displayName,
|
|
25
40
|
lifecycleStatus: params.lifecycleStatus ?? 'active',
|
|
26
41
|
updatedAt: now
|
|
27
|
-
}
|
|
28
|
-
|
|
42
|
+
}).where(eq(integrationConnections.id, existing.id)).returning();
|
|
43
|
+
becameAvailable = existing.lifecycleStatus !== 'active' && row?.lifecycleStatus === 'active';
|
|
44
|
+
}
|
|
29
45
|
if (!row) throw new Error('Integration connection upsert returned no rows');
|
|
30
|
-
|
|
46
|
+
const connection = toIntegrationConnection(row);
|
|
47
|
+
if (becameAvailable) {
|
|
48
|
+
await writeConnectionAvailableEvent(executor, connection);
|
|
49
|
+
}
|
|
50
|
+
return connection;
|
|
31
51
|
}
|
|
32
52
|
const INTEGRATION_CONNECTION_EXTERNAL_UNIQUE_CONSTRAINT = 'integrations_connections_workspace_external_unique';
|
|
33
53
|
const INTEGRATION_CONNECTION_SLUG_UNIQUE_CONSTRAINT = 'integrations_connections_workspace_slug_unique';
|
|
@@ -56,7 +76,12 @@ export function isIntegrationConnectionSlugUniqueViolation(error) {
|
|
|
56
76
|
return false;
|
|
57
77
|
}
|
|
58
78
|
export async function createIntegrationConnection(params, options = {}) {
|
|
59
|
-
|
|
79
|
+
if (options.tx === undefined) {
|
|
80
|
+
return await db().transaction((tx)=>createIntegrationConnection(params, {
|
|
81
|
+
tx
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
const executor = options.tx;
|
|
60
85
|
let rows;
|
|
61
86
|
try {
|
|
62
87
|
rows = await executor.insert(integrationConnections).values({
|
|
@@ -78,7 +103,11 @@ export async function createIntegrationConnection(params, options = {}) {
|
|
|
78
103
|
}
|
|
79
104
|
const row = rows[0];
|
|
80
105
|
if (!row) throw new Error('Integration connection insert returned no rows');
|
|
81
|
-
|
|
106
|
+
const connection = toIntegrationConnection(row);
|
|
107
|
+
if (connection.lifecycleStatus === 'active') {
|
|
108
|
+
await writeConnectionAvailableEvent(executor, connection);
|
|
109
|
+
}
|
|
110
|
+
return connection;
|
|
82
111
|
}
|
|
83
112
|
export async function resolveUniqueConnectionSlug(params, options = {}) {
|
|
84
113
|
const executor = options.tx ?? db();
|
|
@@ -111,13 +140,37 @@ export async function getIntegrationConnectionBySlug(params) {
|
|
|
111
140
|
return toIntegrationConnection(row);
|
|
112
141
|
}
|
|
113
142
|
export async function updateIntegrationConnectionLifecycleStatus(params, options = {}) {
|
|
114
|
-
|
|
143
|
+
if (options.tx === undefined) {
|
|
144
|
+
return await db().transaction((tx)=>updateIntegrationConnectionLifecycleStatus(params, {
|
|
145
|
+
tx
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
const executor = options.tx;
|
|
149
|
+
const [existing] = await executor.select({
|
|
150
|
+
lifecycleStatus: integrationConnections.lifecycleStatus
|
|
151
|
+
}).from(integrationConnections).where(eq(integrationConnections.id, params.id)).limit(1).for('update');
|
|
152
|
+
if (!existing) return undefined;
|
|
115
153
|
const [row] = await executor.update(integrationConnections).set({
|
|
116
154
|
lifecycleStatus: params.lifecycleStatus,
|
|
117
155
|
updatedAt: new Date()
|
|
118
156
|
}).where(eq(integrationConnections.id, params.id)).returning();
|
|
119
157
|
if (!row) return undefined;
|
|
120
|
-
|
|
158
|
+
const connection = toIntegrationConnection(row);
|
|
159
|
+
if (existing.lifecycleStatus !== 'active' && connection.lifecycleStatus === 'active') {
|
|
160
|
+
await writeConnectionAvailableEvent(executor, connection);
|
|
161
|
+
}
|
|
162
|
+
return connection;
|
|
163
|
+
}
|
|
164
|
+
async function writeConnectionAvailableEvent(executor, connection) {
|
|
165
|
+
await writeOutboxEvent(executor, integrationsOutbox, {
|
|
166
|
+
type: INTEGRATION_CONNECTION_AVAILABLE,
|
|
167
|
+
payload: {
|
|
168
|
+
provider: connection.provider,
|
|
169
|
+
workspaceId: connection.workspaceId,
|
|
170
|
+
connectionId: connection.id,
|
|
171
|
+
slug: connection.slug
|
|
172
|
+
}
|
|
173
|
+
});
|
|
121
174
|
}
|
|
122
175
|
export async function deleteIntegrationConnection(params, options = {}) {
|
|
123
176
|
const executor = options.tx ?? db();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/db/connections.ts"],"sourcesContent":["import {CONNECTION_SLUG_MAX_LENGTH} from '@shipfox/api-integration-core-dto';\nimport {ConnectionSlugConflictError} from '@shipfox/api-integration-spi';\nimport {and, eq} from 'drizzle-orm';\nimport type {\n IntegrationConnection,\n IntegrationConnectionLifecycleStatus,\n} from '#core/entities/connection.js';\nimport type {IntegrationProviderKind} from '#core/entities/provider.js';\nimport {IntegrationConnectionAlreadyExistsError} from '#core/errors.js';\nimport {db} from './db.js';\nimport {integrationConnections, toIntegrationConnection} from './schema/connections.js';\n\ntype IntegrationDb = ReturnType<typeof db>;\ntype IntegrationTx = Parameters<Parameters<IntegrationDb['transaction']>[0]>[0];\n\nexport interface UpsertIntegrationConnectionParams {\n workspaceId: string;\n provider: IntegrationProviderKind;\n externalAccountId: string;\n slug: string;\n displayName: string;\n lifecycleStatus?: IntegrationConnectionLifecycleStatus | undefined;\n}\n\nexport async function upsertIntegrationConnection(\n params: UpsertIntegrationConnectionParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection> {\n const executor = options.tx ?? db();\n const now = new Date();\n const [row] = await executor\n .insert(integrationConnections)\n .values({\n workspaceId: params.workspaceId,\n provider: params.provider,\n externalAccountId: params.externalAccountId,\n slug: params.slug,\n displayName: params.displayName,\n lifecycleStatus: params.lifecycleStatus ?? 'active',\n })\n .onConflictDoUpdate({\n target: [\n integrationConnections.workspaceId,\n integrationConnections.provider,\n integrationConnections.externalAccountId,\n ],\n set: {\n displayName: params.displayName,\n lifecycleStatus: params.lifecycleStatus ?? 'active',\n updatedAt: now,\n },\n })\n .returning();\n\n if (!row) throw new Error('Integration connection upsert returned no rows');\n return toIntegrationConnection(row);\n}\n\nexport interface CreateIntegrationConnectionParams {\n workspaceId: string;\n provider: IntegrationProviderKind;\n externalAccountId: string;\n slug: string;\n displayName: string;\n lifecycleStatus?: IntegrationConnectionLifecycleStatus | undefined;\n}\n\nconst INTEGRATION_CONNECTION_EXTERNAL_UNIQUE_CONSTRAINT =\n 'integrations_connections_workspace_external_unique';\nconst INTEGRATION_CONNECTION_SLUG_UNIQUE_CONSTRAINT =\n 'integrations_connections_workspace_slug_unique';\n\nexport function isIntegrationConnectionUniqueViolation(error: unknown): boolean {\n let current: unknown = error;\n for (let depth = 0; depth < 5 && current != null; depth += 1) {\n if (typeof current !== 'object') return false;\n const {code, constraint} = current as {code?: unknown; constraint?: unknown};\n if (code === '23505' && constraint === INTEGRATION_CONNECTION_EXTERNAL_UNIQUE_CONSTRAINT) {\n return true;\n }\n current = (current as {cause?: unknown}).cause;\n }\n return false;\n}\n\nexport function isIntegrationConnectionSlugUniqueViolation(error: unknown): boolean {\n let current: unknown = error;\n for (let depth = 0; depth < 5 && current != null; depth += 1) {\n if (typeof current !== 'object') return false;\n const {code, constraint} = current as {code?: unknown; constraint?: unknown};\n if (code === '23505' && constraint === INTEGRATION_CONNECTION_SLUG_UNIQUE_CONSTRAINT) {\n return true;\n }\n current = (current as {cause?: unknown}).cause;\n }\n return false;\n}\n\nexport async function createIntegrationConnection(\n params: CreateIntegrationConnectionParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection> {\n const executor = options.tx ?? db();\n let rows: (typeof integrationConnections.$inferSelect)[];\n try {\n rows = await executor\n .insert(integrationConnections)\n .values({\n workspaceId: params.workspaceId,\n provider: params.provider,\n externalAccountId: params.externalAccountId,\n slug: params.slug,\n displayName: params.displayName,\n lifecycleStatus: params.lifecycleStatus ?? 'active',\n })\n .returning();\n } catch (error) {\n if (isIntegrationConnectionUniqueViolation(error)) {\n throw new IntegrationConnectionAlreadyExistsError(\n params.workspaceId,\n params.provider,\n params.externalAccountId,\n );\n }\n if (isIntegrationConnectionSlugUniqueViolation(error)) {\n throw new ConnectionSlugConflictError(error);\n }\n throw error;\n }\n\n const row = rows[0];\n if (!row) throw new Error('Integration connection insert returned no rows');\n return toIntegrationConnection(row);\n}\n\nexport interface ResolveUniqueConnectionSlugParams {\n workspaceId: string;\n provider: IntegrationProviderKind;\n externalAccountId: string;\n baseSlug: string;\n}\n\nexport async function resolveUniqueConnectionSlug(\n params: ResolveUniqueConnectionSlugParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<string> {\n const executor = options.tx ?? db();\n const [existing] = await executor\n .select({slug: integrationConnections.slug})\n .from(integrationConnections)\n .where(\n and(\n eq(integrationConnections.workspaceId, params.workspaceId),\n eq(integrationConnections.provider, params.provider),\n eq(integrationConnections.externalAccountId, params.externalAccountId),\n ),\n )\n .limit(1);\n if (existing) return existing.slug;\n\n const workspaceSlugs = await executor\n .select({slug: integrationConnections.slug})\n .from(integrationConnections)\n .where(eq(integrationConnections.workspaceId, params.workspaceId));\n const used = new Set(workspaceSlugs.map((row) => row.slug));\n\n for (let suffixNumber = 1; ; suffixNumber += 1) {\n const suffix = suffixNumber === 1 ? '' : `_${suffixNumber}`;\n const baseBudget = CONNECTION_SLUG_MAX_LENGTH - suffix.length;\n const candidate = `${params.baseSlug.slice(0, baseBudget).replaceAll(/[_-]+$/g, '')}${suffix}`;\n if (!used.has(candidate)) return candidate;\n }\n}\n\nexport type CreateIntegrationConnectionFn = typeof createIntegrationConnection;\n\nexport async function getIntegrationConnectionById(\n id: string,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection | undefined> {\n const executor = options.tx ?? db();\n const rows = await executor\n .select()\n .from(integrationConnections)\n .where(eq(integrationConnections.id, id))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toIntegrationConnection(row);\n}\n\nexport type GetIntegrationConnectionByIdFn = typeof getIntegrationConnectionById;\n\nexport interface GetIntegrationConnectionBySlugParams {\n workspaceId: string;\n slug: string;\n}\n\nexport async function getIntegrationConnectionBySlug(\n params: GetIntegrationConnectionBySlugParams,\n): Promise<IntegrationConnection | undefined> {\n const rows = await db()\n .select()\n .from(integrationConnections)\n .where(\n and(\n eq(integrationConnections.workspaceId, params.workspaceId),\n eq(integrationConnections.slug, params.slug),\n ),\n )\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toIntegrationConnection(row);\n}\n\nexport type GetIntegrationConnectionBySlugFn = typeof getIntegrationConnectionBySlug;\n\nexport interface UpdateIntegrationConnectionLifecycleStatusParams {\n id: string;\n lifecycleStatus: IntegrationConnectionLifecycleStatus;\n}\n\nexport async function updateIntegrationConnectionLifecycleStatus(\n params: UpdateIntegrationConnectionLifecycleStatusParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection | undefined> {\n const executor = options.tx ?? db();\n const [row] = await executor\n .update(integrationConnections)\n .set({lifecycleStatus: params.lifecycleStatus, updatedAt: new Date()})\n .where(eq(integrationConnections.id, params.id))\n .returning();\n if (!row) return undefined;\n return toIntegrationConnection(row);\n}\n\nexport type UpdateIntegrationConnectionLifecycleStatusFn =\n typeof updateIntegrationConnectionLifecycleStatus;\n\nexport async function deleteIntegrationConnection(\n params: {id: string},\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<boolean> {\n const executor = options.tx ?? db();\n const result = await executor\n .delete(integrationConnections)\n .where(eq(integrationConnections.id, params.id));\n return (result.rowCount ?? 0) > 0;\n}\n\nexport type DeleteIntegrationConnectionFn = typeof deleteIntegrationConnection;\n\nexport interface ListIntegrationConnectionsParams {\n workspaceId: string;\n}\n\nexport async function listIntegrationConnections(\n params: ListIntegrationConnectionsParams,\n): Promise<IntegrationConnection[]> {\n const rows = await db()\n .select()\n .from(integrationConnections)\n .where(eq(integrationConnections.workspaceId, params.workspaceId))\n .orderBy(integrationConnections.createdAt, integrationConnections.id);\n\n const connections = rows.map(toIntegrationConnection);\n return connections;\n}\n\nexport interface ListIntegrationConnectionsByProviderParams {\n provider: IntegrationProviderKind;\n}\n\nexport async function listIntegrationConnectionsByProvider(\n params: ListIntegrationConnectionsByProviderParams,\n): Promise<IntegrationConnection[]> {\n const rows = await db()\n .select()\n .from(integrationConnections)\n .where(eq(integrationConnections.provider, params.provider))\n .orderBy(integrationConnections.createdAt, integrationConnections.id);\n\n return rows.map(toIntegrationConnection);\n}\n"],"names":["CONNECTION_SLUG_MAX_LENGTH","ConnectionSlugConflictError","and","eq","IntegrationConnectionAlreadyExistsError","db","integrationConnections","toIntegrationConnection","upsertIntegrationConnection","params","options","executor","tx","now","Date","row","insert","values","workspaceId","provider","externalAccountId","slug","displayName","lifecycleStatus","onConflictDoUpdate","target","set","updatedAt","returning","Error","INTEGRATION_CONNECTION_EXTERNAL_UNIQUE_CONSTRAINT","INTEGRATION_CONNECTION_SLUG_UNIQUE_CONSTRAINT","isIntegrationConnectionUniqueViolation","error","current","depth","code","constraint","cause","isIntegrationConnectionSlugUniqueViolation","createIntegrationConnection","rows","resolveUniqueConnectionSlug","existing","select","from","where","limit","workspaceSlugs","used","Set","map","suffixNumber","suffix","baseBudget","length","candidate","baseSlug","slice","replaceAll","has","getIntegrationConnectionById","id","undefined","getIntegrationConnectionBySlug","updateIntegrationConnectionLifecycleStatus","update","deleteIntegrationConnection","result","delete","rowCount","listIntegrationConnections","orderBy","createdAt","connections","listIntegrationConnectionsByProvider"],"mappings":"AAAA,SAAQA,0BAA0B,QAAO,oCAAoC;AAC7E,SAAQC,2BAA2B,QAAO,+BAA+B;AACzE,SAAQC,GAAG,EAAEC,EAAE,QAAO,cAAc;AAMpC,SAAQC,uCAAuC,QAAO,kBAAkB;AACxE,SAAQC,EAAE,QAAO,UAAU;AAC3B,SAAQC,sBAAsB,EAAEC,uBAAuB,QAAO,0BAA0B;AAcxF,OAAO,eAAeC,4BACpBC,MAAyC,EACzCC,UAA4D,CAAC,CAAC;IAE9D,MAAMC,WAAWD,QAAQE,EAAE,IAAIP;IAC/B,MAAMQ,MAAM,IAAIC;IAChB,MAAM,CAACC,IAAI,GAAG,MAAMJ,SACjBK,MAAM,CAACV,wBACPW,MAAM,CAAC;QACNC,aAAaT,OAAOS,WAAW;QAC/BC,UAAUV,OAAOU,QAAQ;QACzBC,mBAAmBX,OAAOW,iBAAiB;QAC3CC,MAAMZ,OAAOY,IAAI;QACjBC,aAAab,OA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egrationsEventMap,\n} from '@shipfox/api-integration-core-dto';\nimport {ConnectionSlugConflictError} from '@shipfox/api-integration-spi';\nimport {writeOutboxEvent} from '@shipfox/node-outbox';\nimport {and, eq} from 'drizzle-orm';\nimport type {\n IntegrationConnection,\n IntegrationConnectionLifecycleStatus,\n} from '#core/entities/connection.js';\nimport type {IntegrationProviderKind} from '#core/entities/provider.js';\nimport {IntegrationConnectionAlreadyExistsError} from '#core/errors.js';\nimport {db} from './db.js';\nimport {integrationConnections, toIntegrationConnection} from './schema/connections.js';\nimport {integrationsOutbox} from './schema/outbox.js';\n\ntype IntegrationDb = ReturnType<typeof db>;\ntype IntegrationTx = Parameters<Parameters<IntegrationDb['transaction']>[0]>[0];\n\nexport interface UpsertIntegrationConnectionParams {\n workspaceId: string;\n provider: IntegrationProviderKind;\n externalAccountId: string;\n slug: string;\n displayName: string;\n lifecycleStatus?: IntegrationConnectionLifecycleStatus | undefined;\n}\n\nexport async function upsertIntegrationConnection(\n params: UpsertIntegrationConnectionParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection> {\n if (options.tx === undefined) {\n return await db().transaction((tx) => upsertIntegrationConnection(params, {tx}));\n }\n\n const executor = options.tx;\n const now = new Date();\n let [row] = await executor\n .insert(integrationConnections)\n .values({\n workspaceId: params.workspaceId,\n provider: params.provider,\n externalAccountId: params.externalAccountId,\n slug: params.slug,\n displayName: params.displayName,\n lifecycleStatus: params.lifecycleStatus ?? 'active',\n })\n .onConflictDoNothing({\n target: [\n integrationConnections.workspaceId,\n integrationConnections.provider,\n integrationConnections.externalAccountId,\n ],\n })\n .returning();\n\n let becameAvailable = row?.lifecycleStatus === 'active';\n if (!row) {\n const [existing] = await executor\n .select({\n id: integrationConnections.id,\n lifecycleStatus: integrationConnections.lifecycleStatus,\n })\n .from(integrationConnections)\n .where(\n and(\n eq(integrationConnections.workspaceId, params.workspaceId),\n eq(integrationConnections.provider, params.provider),\n eq(integrationConnections.externalAccountId, params.externalAccountId),\n ),\n )\n .limit(1)\n .for('update');\n if (!existing) throw new Error('Integration connection upsert conflict row was not found');\n\n [row] = await executor\n .update(integrationConnections)\n .set({\n displayName: params.displayName,\n lifecycleStatus: params.lifecycleStatus ?? 'active',\n updatedAt: now,\n })\n .where(eq(integrationConnections.id, existing.id))\n .returning();\n becameAvailable = existing.lifecycleStatus !== 'active' && row?.lifecycleStatus === 'active';\n }\n\n if (!row) throw new Error('Integration connection upsert returned no rows');\n const connection = toIntegrationConnection(row);\n if (becameAvailable) {\n await writeConnectionAvailableEvent(executor, connection);\n }\n return connection;\n}\n\nexport interface CreateIntegrationConnectionParams {\n workspaceId: string;\n provider: IntegrationProviderKind;\n externalAccountId: string;\n slug: string;\n displayName: string;\n lifecycleStatus?: IntegrationConnectionLifecycleStatus | undefined;\n}\n\nconst INTEGRATION_CONNECTION_EXTERNAL_UNIQUE_CONSTRAINT =\n 'integrations_connections_workspace_external_unique';\nconst INTEGRATION_CONNECTION_SLUG_UNIQUE_CONSTRAINT =\n 'integrations_connections_workspace_slug_unique';\n\nexport function isIntegrationConnectionUniqueViolation(error: unknown): boolean {\n let current: unknown = error;\n for (let depth = 0; depth < 5 && current != null; depth += 1) {\n if (typeof current !== 'object') return false;\n const {code, constraint} = current as {code?: unknown; constraint?: unknown};\n if (code === '23505' && constraint === INTEGRATION_CONNECTION_EXTERNAL_UNIQUE_CONSTRAINT) {\n return true;\n }\n current = (current as {cause?: unknown}).cause;\n }\n return false;\n}\n\nexport function isIntegrationConnectionSlugUniqueViolation(error: unknown): boolean {\n let current: unknown = error;\n for (let depth = 0; depth < 5 && current != null; depth += 1) {\n if (typeof current !== 'object') return false;\n const {code, constraint} = current as {code?: unknown; constraint?: unknown};\n if (code === '23505' && constraint === INTEGRATION_CONNECTION_SLUG_UNIQUE_CONSTRAINT) {\n return true;\n }\n current = (current as {cause?: unknown}).cause;\n }\n return false;\n}\n\nexport async function createIntegrationConnection(\n params: CreateIntegrationConnectionParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection> {\n if (options.tx === undefined) {\n return await db().transaction((tx) => createIntegrationConnection(params, {tx}));\n }\n\n const executor = options.tx;\n let rows: (typeof integrationConnections.$inferSelect)[];\n try {\n rows = await executor\n .insert(integrationConnections)\n .values({\n workspaceId: params.workspaceId,\n provider: params.provider,\n externalAccountId: params.externalAccountId,\n slug: params.slug,\n displayName: params.displayName,\n lifecycleStatus: params.lifecycleStatus ?? 'active',\n })\n .returning();\n } catch (error) {\n if (isIntegrationConnectionUniqueViolation(error)) {\n throw new IntegrationConnectionAlreadyExistsError(\n params.workspaceId,\n params.provider,\n params.externalAccountId,\n );\n }\n if (isIntegrationConnectionSlugUniqueViolation(error)) {\n throw new ConnectionSlugConflictError(error);\n }\n throw error;\n }\n\n const row = rows[0];\n if (!row) throw new Error('Integration connection insert returned no rows');\n const connection = toIntegrationConnection(row);\n if (connection.lifecycleStatus === 'active') {\n await writeConnectionAvailableEvent(executor, connection);\n }\n return connection;\n}\n\nexport interface ResolveUniqueConnectionSlugParams {\n workspaceId: string;\n provider: IntegrationProviderKind;\n externalAccountId: string;\n baseSlug: string;\n}\n\nexport async function resolveUniqueConnectionSlug(\n params: ResolveUniqueConnectionSlugParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<string> {\n const executor = options.tx ?? db();\n const [existing] = await executor\n .select({slug: integrationConnections.slug})\n .from(integrationConnections)\n .where(\n and(\n eq(integrationConnections.workspaceId, params.workspaceId),\n eq(integrationConnections.provider, params.provider),\n eq(integrationConnections.externalAccountId, params.externalAccountId),\n ),\n )\n .limit(1);\n if (existing) return existing.slug;\n\n const workspaceSlugs = await executor\n .select({slug: integrationConnections.slug})\n .from(integrationConnections)\n .where(eq(integrationConnections.workspaceId, params.workspaceId));\n const used = new Set(workspaceSlugs.map((row) => row.slug));\n\n for (let suffixNumber = 1; ; suffixNumber += 1) {\n const suffix = suffixNumber === 1 ? '' : `_${suffixNumber}`;\n const baseBudget = CONNECTION_SLUG_MAX_LENGTH - suffix.length;\n const candidate = `${params.baseSlug.slice(0, baseBudget).replaceAll(/[_-]+$/g, '')}${suffix}`;\n if (!used.has(candidate)) return candidate;\n }\n}\n\nexport type CreateIntegrationConnectionFn = typeof createIntegrationConnection;\n\nexport async function getIntegrationConnectionById(\n id: string,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection | undefined> {\n const executor = options.tx ?? db();\n const rows = await executor\n .select()\n .from(integrationConnections)\n .where(eq(integrationConnections.id, id))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toIntegrationConnection(row);\n}\n\nexport type GetIntegrationConnectionByIdFn = typeof getIntegrationConnectionById;\n\nexport interface GetIntegrationConnectionBySlugParams {\n workspaceId: string;\n slug: string;\n}\n\nexport async function getIntegrationConnectionBySlug(\n params: GetIntegrationConnectionBySlugParams,\n): Promise<IntegrationConnection | undefined> {\n const rows = await db()\n .select()\n .from(integrationConnections)\n .where(\n and(\n eq(integrationConnections.workspaceId, params.workspaceId),\n eq(integrationConnections.slug, params.slug),\n ),\n )\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toIntegrationConnection(row);\n}\n\nexport type GetIntegrationConnectionBySlugFn = typeof getIntegrationConnectionBySlug;\n\nexport interface UpdateIntegrationConnectionLifecycleStatusParams {\n id: string;\n lifecycleStatus: IntegrationConnectionLifecycleStatus;\n}\n\nexport async function updateIntegrationConnectionLifecycleStatus(\n params: UpdateIntegrationConnectionLifecycleStatusParams,\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<IntegrationConnection | undefined> {\n if (options.tx === undefined) {\n return await db().transaction((tx) => updateIntegrationConnectionLifecycleStatus(params, {tx}));\n }\n\n const executor = options.tx;\n const [existing] = await executor\n .select({lifecycleStatus: integrationConnections.lifecycleStatus})\n .from(integrationConnections)\n .where(eq(integrationConnections.id, params.id))\n .limit(1)\n .for('update');\n if (!existing) return undefined;\n\n const [row] = await executor\n .update(integrationConnections)\n .set({lifecycleStatus: params.lifecycleStatus, updatedAt: new Date()})\n .where(eq(integrationConnections.id, params.id))\n .returning();\n if (!row) return undefined;\n const connection = toIntegrationConnection(row);\n if (existing.lifecycleStatus !== 'active' && connection.lifecycleStatus === 'active') {\n await writeConnectionAvailableEvent(executor, connection);\n }\n return connection;\n}\n\nexport type UpdateIntegrationConnectionLifecycleStatusFn =\n typeof updateIntegrationConnectionLifecycleStatus;\n\nasync function writeConnectionAvailableEvent(\n executor: IntegrationDb | IntegrationTx,\n connection: IntegrationConnection,\n): Promise<void> {\n await writeOutboxEvent<IntegrationsEventMap>(executor, integrationsOutbox, {\n type: INTEGRATION_CONNECTION_AVAILABLE,\n payload: {\n provider: connection.provider,\n workspaceId: connection.workspaceId,\n connectionId: connection.id,\n slug: connection.slug,\n },\n });\n}\n\nexport async function deleteIntegrationConnection(\n params: {id: string},\n options: {tx?: IntegrationDb | IntegrationTx | undefined} = {},\n): Promise<boolean> {\n const executor = options.tx ?? db();\n const result = await executor\n .delete(integrationConnections)\n .where(eq(integrationConnections.id, params.id));\n return (result.rowCount ?? 0) > 0;\n}\n\nexport type DeleteIntegrationConnectionFn = typeof deleteIntegrationConnection;\n\nexport interface ListIntegrationConnectionsParams {\n workspaceId: string;\n}\n\nexport async function listIntegrationConnections(\n params: ListIntegrationConnectionsParams,\n): Promise<IntegrationConnection[]> {\n const rows = await db()\n .select()\n .from(integrationConnections)\n .where(eq(integrationConnections.workspaceId, params.workspaceId))\n .orderBy(integrationConnections.createdAt, integrationConnections.id);\n\n const connections = rows.map(toIntegrationConnection);\n return connections;\n}\n\nexport interface ListIntegrationConnectionsByProviderParams {\n provider: IntegrationProviderKind;\n}\n\nexport async function listIntegrationConnectionsByProvider(\n params: ListIntegrationConnectionsByProviderParams,\n): Promise<IntegrationConnection[]> {\n const rows = await db()\n .select()\n .from(integrationConnections)\n .where(eq(integrationConnections.provider, params.provider))\n .orderBy(integrationConnections.createdAt, integrationConnections.id);\n\n return rows.map(toIntegrationConnection);\n}\n"],"names":["CONNECTION_SLUG_MAX_LENGTH","INTEGRATION_CONNECTION_AVAILABLE","ConnectionSlugConflictError","writeOutboxEvent","and","eq","IntegrationConnectionAlreadyExistsError","db","integrationConnections","toIntegrationConnection","integrationsOutbox","upsertIntegrationConnection","params","options","tx","undefined","transaction","executor","now","Date","row","insert","values","workspaceId","provider","externalAccountId","slug","displayName","lifecycleStatus","onConflictDoNothing","target","returning","becameAvailable","existing","select","id","from","where","limit","for","Error","update","set","updatedAt","connection","writeConnectionAvailableEvent","INTEGRATION_CONNECTION_EXTERNAL_UNIQUE_CONSTRAINT","INTEGRATION_CONNECTION_SLUG_UNIQUE_CONSTRAINT","isIntegrationConnectionUniqueViolation","error","current","depth","code","constraint","cause","isIntegrationConnectionSlugUniqueViolation","createIntegrationConnection","rows","resolveUniqueConnectionSlug","workspaceSlugs","used","Set","map","suffixNumber","suffix","baseBudget","length","candidate","baseSlug","slice","replaceAll","has","getIntegrationConnectionById","getIntegrationConnectionBySlug","updateIntegrationConnectionLifecycleStatus","type","payload","connectionId","deleteIntegrationConnection","result","delete","rowCount","listIntegrationConnections","orderBy","createdAt","connections","listIntegrationConnectionsByProvider"],"mappings":"AAAA,SACEA,0BAA0B,EAC1BC,gCAAgC,QAE3B,oCAAoC;AAC3C,SAAQC,2BAA2B,QAAO,+BAA+B;AACzE,SAAQC,gBAAgB,QAAO,uBAAuB;AACtD,SAAQC,GAAG,EAAEC,EAAE,QAAO,cAAc;AAMpC,SAAQC,uCAAuC,QAAO,kBAAkB;AACxE,SAAQC,EAAE,QAAO,UAAU;AAC3B,SAAQC,sBAAsB,EAAEC,uBAAuB,QAAO,0BAA0B;AACxF,SAAQC,kBAAkB,QAAO,qBAAqB;AActD,OAAO,eAAeC,4BACpBC,MAAyC,EACzCC,UAA4D,CAAC,CAAC;IAE9D,IAAIA,QAAQC,EAAE,KAAKC,WAAW;QAC5B,OAAO,MAAMR,KAAKS,WAAW,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C/B,MAAMwE,SAAS,MAAM9D,SAClB+D,MAAM,CAACxE,wBACP6B,KAAK,CAAChC,GAAGG,uBAAuB2B,EAAE,EAAEvB,OAAOuB,EAAE;IAChD,OAAO,AAAC4C,CAAAA,OAAOE,QAAQ,IAAI,CAAA,IAAK;AAClC;AAQA,OAAO,eAAeC,2BACpBtE,MAAwC;IAExC,MAAM6C,OAAO,MAAMlD,KAChB2B,MAAM,GACNE,IAAI,CAAC5B,wBACL6B,KAAK,CAAChC,GAAGG,uBAAuBe,WAAW,EAAEX,OAAOW,WAAW,GAC/D4D,OAAO,CAAC3E,uBAAuB4E,SAAS,EAAE5E,uBAAuB2B,EAAE;IAEtE,MAAMkD,cAAc5B,KAAKK,GAAG,CAACrD;IAC7B,OAAO4E;AACT;AAMA,OAAO,eAAeC,qCACpB1E,MAAkD;IAElD,MAAM6C,OAAO,MAAMlD,KAChB2B,MAAM,GACNE,IAAI,CAAC5B,wBACL6B,KAAK,CAAChC,GAAGG,uBAAuBgB,QAAQ,EAAEZ,OAAOY,QAAQ,GACzD2D,OAAO,CAAC3E,uBAAuB4E,SAAS,EAAE5E,uBAAuB2B,EAAE;IAEtE,OAAOsB,KAAKK,GAAG,CAACrD;AAClB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jira.d.ts","sourceRoot":"","sources":["../../src/providers/jira.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAyB,yBAAyB,EAAC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"jira.d.ts","sourceRoot":"","sources":["../../src/providers/jira.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAyB,yBAAyB,EAAC,MAAM,qBAAqB,CAAC;AAiM3F,eAAO,MAAM,kBAAkB,EAAE,yBAIhC,CAAC"}
|
package/dist/providers/jira.js
CHANGED
|
@@ -5,7 +5,7 @@ import { publishIntegrationEventReceived, recordDeliveryOnly } from '#db/webhook
|
|
|
5
5
|
import { retryConnectionSlugCollision, slugifyConnectionSlug } from '#providers/connection-slug.js';
|
|
6
6
|
const JIRA_SECRETS_NAMESPACE_PREFIX = 'system/integrations/jira/';
|
|
7
7
|
async function loadJiraModuleParts(options = {}) {
|
|
8
|
-
const { createJiraIntegrationProvider, createJiraMaintenanceWorker, createJiraPendingSelectionStore, createJiraTokenStore, db: jiraDb, disconnectJiraInstallation: disconnectJiraInstallationRecords, getJiraInstallationByCloudId, migrationsPath, upsertJiraInstallation } = await import('@shipfox/api-integration-jira');
|
|
8
|
+
const { createJiraIntegrationProvider, createJiraMaintenanceWorker, createJiraPendingSelectionStore, createJiraTokenStore, db: jiraDb, deleteJiraInstallationByConnectionId, disconnectJiraInstallation: disconnectJiraInstallationRecords, getJiraInstallationByCloudId, jiraSecretsNamespace, migrationsPath, upsertJiraInstallation, withJiraRefreshLockAndWait } = await import('@shipfox/api-integration-jira');
|
|
9
9
|
async function getExistingJiraConnection(input) {
|
|
10
10
|
const installation = await getJiraInstallationByCloudId(input.cloudId);
|
|
11
11
|
if (!installation) return undefined;
|
|
@@ -98,6 +98,22 @@ async function loadJiraModuleParts(options = {}) {
|
|
|
98
98
|
agentTools: {
|
|
99
99
|
tokenStore
|
|
100
100
|
},
|
|
101
|
+
cleanup: {
|
|
102
|
+
deleteConnectionRecords: async (connection, { tx })=>{
|
|
103
|
+
await deleteJiraInstallationByConnectionId(connection.id, {
|
|
104
|
+
tx
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
deleteConnectionSecrets: async (connection)=>{
|
|
108
|
+
await withJiraRefreshLockAndWait(connection.id, async ()=>{
|
|
109
|
+
// Scoped secrets accept the provider-local suffix, after this helper validates its prefix.
|
|
110
|
+
await (options.secrets?.jira?.deleteSecrets({
|
|
111
|
+
workspaceId: connection.workspaceId,
|
|
112
|
+
namespace: jiraNamespaceSuffix(jiraSecretsNamespace(connection.id))
|
|
113
|
+
}) ?? Promise.resolve());
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
},
|
|
101
117
|
routes: {
|
|
102
118
|
tokenStore,
|
|
103
119
|
pendingStore,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/jira.ts"],"sourcesContent":["import type {\n ConnectJiraInstallationInput,\n JiraPendingSelectionSecretsStore,\n JiraSecretsStore,\n} from '@shipfox/api-integration-jira';\nimport type {IntegrationConnection as CoreIntegrationConnection} from '@shipfox/api-integration-spi';\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 {publishIntegrationEventReceived, recordDeliveryOnly} from '#db/webhook-deliveries.js';\nimport {retryConnectionSlugCollision, slugifyConnectionSlug} from '#providers/connection-slug.js';\nimport type {IntegrationModuleParts, IntegrationProviderModule} from '#providers/types.js';\n\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 createJiraMaintenanceWorker,\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 const integrationProvider = createJiraIntegrationProvider({\n agentTools: {tokenStore},\n routes: {\n tokenStore,\n pendingStore,\n getExistingJiraConnection,\n connectJiraInstallation,\n disconnectJiraInstallation,\n coreDb: db,\n publishIntegrationEventReceived,\n recordDeliveryOnly,\n getIntegrationConnectionById,\n markConnectionActive: async ({connectionId, tx}) => {\n await updateIntegrationConnectionLifecycleStatus(\n {\n id: connectionId,\n lifecycleStatus: 'active',\n },\n tx === undefined ? {} : {tx: tx as IntegrationTx},\n );\n },\n markConnectionError: async ({connectionId, tx}) => {\n await updateIntegrationConnectionLifecycleStatus(\n {\n id: connectionId,\n lifecycleStatus: 'error',\n },\n tx === undefined ? {} : {tx: tx as IntegrationTx},\n );\n },\n ...(options.requireActiveWorkspaceMembership\n ? {requireActiveWorkspaceMembership: options.requireActiveWorkspaceMembership}\n : {}),\n },\n });\n\n return {\n provider: integrationProvider,\n workers: [\n createJiraMaintenanceWorker({\n tokenStore,\n resolveConnection: getIntegrationConnectionById,\n }),\n ],\n webhookProcessors: integrationProvider.webhookProcessors,\n database: {db: jiraDb, migrationsPath, databaseNamespace: 'integrations_jira'},\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":["config","deleteIntegrationConnection","getIntegrationConnectionById","resolveUniqueConnectionSlug","updateIntegrationConnectionLifecycleStatus","upsertIntegrationConnection","db","publishIntegrationEventReceived","recordDeliveryOnly","retryConnectionSlugCollision","slugifyConnectionSlug","JIRA_SECRETS_NAMESPACE_PREFIX","loadJiraModuleParts","options","createJiraIntegrationProvider","createJiraMaintenanceWorker","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","integrationProvider","agentTools","routes","coreDb","markConnectionActive","requireActiveWorkspaceMembership","workers","webhookProcessors","database","databaseNamespace","jiraProviderModule","enabled","INTEGRATIONS_ENABLE_JIRA_PROVIDER","load","startsWith","slice","length"],"mappings":"AAMA,SAAQA,MAAM,QAAO,aAAa;AAClC,SACEC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,2BAA2B,EAC3BC,0CAA0C,EAC1CC,2BAA2B,QACtB,qBAAqB;AAC5B,SAAQC,EAAE,QAAO,YAAY;AAC7B,SAAQC,+BAA+B,EAAEC,kBAAkB,QAAO,4BAA4B;AAC9F,SAAQC,4BAA4B,EAAEC,qBAAqB,QAAO,gCAAgC;AAGlG,MAAMC,gCAAgC;AAItC,eAAeC,oBACbC,UAA4D,CAAC,CAAC;IAE9D,MAAM,EACJ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M2B,eAAerD,gCAAgC;QAACoC;IAAO;IAE7D,MAAMkB,sBAAsBxD,8BAA8B;QACxDyD,YAAY;YAACL;QAAU;QACvBM,QAAQ;YACNN;YACAG;YACA7C;YACAM;YACAX;YACAsD,QAAQnE;YACRC;YACAC;YACAN;YACAwE,sBAAsB,OAAO,EAAC7C,YAAY,EAAEG,EAAE,EAAC;gBAC7C,MAAM5B,2CACJ;oBACEuC,IAAId;oBACJa,iBAAiB;gBACnB,GACAV,OAAOJ,YAAY,CAAC,IAAI;oBAACI,IAAIA;gBAAmB;YAEpD;YACAoC,qBAAqB,OAAO,EAACvC,YAAY,EAAEG,EAAE,EAAC;gBAC5C,MAAM5B,2CACJ;oBACEuC,IAAId;oBACJa,iBAAiB;gBACnB,GACAV,OAAOJ,YAAY,CAAC,IAAI;oBAACI,IAAIA;gBAAmB;YAEpD;YACA,GAAInB,QAAQ8D,gCAAgC,GACxC;gBAACA,kCAAkC9D,QAAQ8D,gCAAgC;YAAA,IAC3E,CAAC,CAAC;QACR;IACF;IAEA,OAAO;QACLxC,UAAUmC;QACVM,SAAS;YACP7D,4BAA4B;gBAC1BmD;gBACAC,mBAAmBjE;YACrB;SACD;QACD2E,mBAAmBP,oBAAoBO,iBAAiB;QACxDC,UAAU;YAACxE,IAAIY;YAAQI;YAAgByD,mBAAmB;QAAmB;IAC/E;AACF;AAEA,OAAO,MAAMC,qBAAgD;IAC3DrC,IAAI;IACJsC,SAASjF,OAAOkF,iCAAiC;IACjDC,MAAMvE;AACR,EAAE;AAEF,SAAS2C,oBAAoBD,SAAiB;IAC5C,IAAI,CAACA,UAAU8B,UAAU,CAACzE,gCAAgC;QACxD,MAAM,IAAIsD,MAAM;IAClB;IACA,OAAOX,UAAU+B,KAAK,CAAC1E,8BAA8B2E,MAAM;AAC7D"}
|
|
1
|
+
{"version":3,"sources":["../../src/providers/jira.ts"],"sourcesContent":["import type {\n ConnectJiraInstallationInput,\n JiraPendingSelectionSecretsStore,\n JiraSecretsStore,\n} from '@shipfox/api-integration-jira';\nimport type {IntegrationConnection as CoreIntegrationConnection} from '@shipfox/api-integration-spi';\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 {publishIntegrationEventReceived, recordDeliveryOnly} from '#db/webhook-deliveries.js';\nimport {retryConnectionSlugCollision, slugifyConnectionSlug} from '#providers/connection-slug.js';\nimport type {IntegrationModuleParts, IntegrationProviderModule} from '#providers/types.js';\n\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 createJiraMaintenanceWorker,\n createJiraPendingSelectionStore,\n createJiraTokenStore,\n db: jiraDb,\n deleteJiraInstallationByConnectionId,\n disconnectJiraInstallation: disconnectJiraInstallationRecords,\n getJiraInstallationByCloudId,\n jiraSecretsNamespace,\n migrationsPath,\n upsertJiraInstallation,\n withJiraRefreshLockAndWait,\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 const integrationProvider = createJiraIntegrationProvider({\n agentTools: {tokenStore},\n cleanup: {\n deleteConnectionRecords: async (connection, {tx}) => {\n await deleteJiraInstallationByConnectionId(connection.id, {tx});\n },\n deleteConnectionSecrets: async (connection) => {\n await withJiraRefreshLockAndWait(connection.id, async () => {\n // Scoped secrets accept the provider-local suffix, after this helper validates its prefix.\n await (options.secrets?.jira?.deleteSecrets({\n workspaceId: connection.workspaceId,\n namespace: jiraNamespaceSuffix(jiraSecretsNamespace(connection.id)),\n }) ?? Promise.resolve());\n });\n },\n },\n routes: {\n tokenStore,\n pendingStore,\n getExistingJiraConnection,\n connectJiraInstallation,\n disconnectJiraInstallation,\n coreDb: db,\n publishIntegrationEventReceived,\n recordDeliveryOnly,\n getIntegrationConnectionById,\n markConnectionActive: async ({connectionId, tx}) => {\n await updateIntegrationConnectionLifecycleStatus(\n {\n id: connectionId,\n lifecycleStatus: 'active',\n },\n tx === undefined ? {} : {tx: tx as IntegrationTx},\n );\n },\n markConnectionError: async ({connectionId, tx}) => {\n await updateIntegrationConnectionLifecycleStatus(\n {\n id: connectionId,\n lifecycleStatus: 'error',\n },\n tx === undefined ? {} : {tx: tx as IntegrationTx},\n );\n },\n ...(options.requireActiveWorkspaceMembership\n ? {requireActiveWorkspaceMembership: options.requireActiveWorkspaceMembership}\n : {}),\n },\n });\n\n return {\n provider: integrationProvider,\n workers: [\n createJiraMaintenanceWorker({\n tokenStore,\n resolveConnection: getIntegrationConnectionById,\n }),\n ],\n webhookProcessors: integrationProvider.webhookProcessors,\n database: {db: jiraDb, migrationsPath, databaseNamespace: 'integrations_jira'},\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":["config","deleteIntegrationConnection","getIntegrationConnectionById","resolveUniqueConnectionSlug","updateIntegrationConnectionLifecycleStatus","upsertIntegrationConnection","db","publishIntegrationEventReceived","recordDeliveryOnly","retryConnectionSlugCollision","slugifyConnectionSlug","JIRA_SECRETS_NAMESPACE_PREFIX","loadJiraModuleParts","options","createJiraIntegrationProvider","createJiraMaintenanceWorker","createJiraPendingSelectionStore","createJiraTokenStore","jiraDb","deleteJiraInstallationByConnectionId","disconnectJiraInstallation","disconnectJiraInstallationRecords","getJiraInstallationByCloudId","jiraSecretsNamespace","migrationsPath","upsertJiraInstallation","withJiraRefreshLockAndWait","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","integrationProvider","agentTools","cleanup","deleteConnectionRecords","deleteConnectionSecrets","routes","coreDb","markConnectionActive","requireActiveWorkspaceMembership","workers","webhookProcessors","database","databaseNamespace","jiraProviderModule","enabled","INTEGRATIONS_ENABLE_JIRA_PROVIDER","load","startsWith","slice","length"],"mappings":"AAMA,SAAQA,MAAM,QAAO,aAAa;AAClC,SACEC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,2BAA2B,EAC3BC,0CAA0C,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