@shipfox/api-integration-core 12.2.0 → 12.3.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.
Files changed (68) hide show
  1. package/.turbo/turbo-build.log +11 -8
  2. package/CHANGELOG.md +18 -0
  3. package/dist/core/secret-cleanup.d.ts +20 -0
  4. package/dist/core/secret-cleanup.d.ts.map +1 -0
  5. package/dist/core/secret-cleanup.js +178 -0
  6. package/dist/core/secret-cleanup.js.map +1 -0
  7. package/dist/db/db.d.ts +562 -0
  8. package/dist/db/db.d.ts.map +1 -1
  9. package/dist/db/db.js +2 -0
  10. package/dist/db/db.js.map +1 -1
  11. package/dist/db/schema/secret-cleanups.d.ts +284 -0
  12. package/dist/db/schema/secret-cleanups.d.ts.map +1 -0
  13. package/dist/db/schema/secret-cleanups.js +39 -0
  14. package/dist/db/schema/secret-cleanups.js.map +1 -0
  15. package/dist/db/secret-cleanups.d.ts +52 -0
  16. package/dist/db/secret-cleanups.d.ts.map +1 -0
  17. package/dist/db/secret-cleanups.js +105 -0
  18. package/dist/db/secret-cleanups.js.map +1 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +8 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/presentation/routes/manage-connections.d.ts.map +1 -1
  23. package/dist/presentation/routes/manage-connections.js +57 -18
  24. package/dist/presentation/routes/manage-connections.js.map +1 -1
  25. package/dist/providers/jira.d.ts.map +1 -1
  26. package/dist/providers/jira.js +51 -14
  27. package/dist/providers/jira.js.map +1 -1
  28. package/dist/temporal/activities/index.d.ts +5 -1
  29. package/dist/temporal/activities/index.d.ts.map +1 -1
  30. package/dist/temporal/activities/index.js +8 -2
  31. package/dist/temporal/activities/index.js.map +1 -1
  32. package/dist/temporal/constants.d.ts +1 -0
  33. package/dist/temporal/constants.d.ts.map +1 -1
  34. package/dist/temporal/constants.js +1 -0
  35. package/dist/temporal/constants.js.map +1 -1
  36. package/dist/temporal/workflows/cleanup-integration-secrets-cron.d.ts +2 -0
  37. package/dist/temporal/workflows/cleanup-integration-secrets-cron.d.ts.map +1 -0
  38. package/dist/temporal/workflows/cleanup-integration-secrets-cron.js +21 -0
  39. package/dist/temporal/workflows/cleanup-integration-secrets-cron.js.map +1 -0
  40. package/dist/temporal/workflows/index.bundle.js +64 -3
  41. package/dist/temporal/workflows/index.d.ts +1 -0
  42. package/dist/temporal/workflows/index.d.ts.map +1 -1
  43. package/dist/temporal/workflows/index.js +1 -0
  44. package/dist/temporal/workflows/index.js.map +1 -1
  45. package/dist/tsconfig.test.tsbuildinfo +1 -1
  46. package/drizzle/0001_durable_secret_cleanup.sql +22 -0
  47. package/drizzle/meta/0001_snapshot.json +180 -2
  48. package/drizzle/meta/_journal.json +7 -0
  49. package/package.json +11 -10
  50. package/src/core/secret-cleanup.test.ts +129 -0
  51. package/src/core/secret-cleanup.ts +229 -0
  52. package/src/db/db.ts +2 -0
  53. package/src/db/schema/secret-cleanups.ts +42 -0
  54. package/src/db/secret-cleanups.test.ts +113 -0
  55. package/src/db/secret-cleanups.ts +209 -0
  56. package/src/index.ts +6 -1
  57. package/src/presentation/routes/manage-connections.test.ts +232 -0
  58. package/src/presentation/routes/manage-connections.ts +45 -11
  59. package/src/providers/jira.ts +61 -13
  60. package/src/temporal/activities/index.ts +11 -1
  61. package/src/temporal/constants.ts +2 -0
  62. package/src/temporal/workflows/cleanup-integration-secrets-cron.ts +20 -0
  63. package/src/temporal/workflows/index.ts +1 -0
  64. package/test/env.ts +3 -0
  65. package/test/globalSetup.ts +1 -0
  66. package/test/route-utils.ts +3 -0
  67. package/test/setup.ts +12 -0
  68. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,17 +1,20 @@
1
1
  $ shipfox-swc && shipfox-temporal-bundle dist/temporal/workflows/index.js
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)
2
+ Successfully compiled: 54 files with swc (479.94ms)
3
+ 2026-08-07T08:47:05.106Z [INFO] asset workflow-bundle-e0d869d865fd59433325.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
7
- modules by path ./dist/temporal/workflows/ 1.39 KiB
7
+ modules by path ./dist/temporal/ 2.41 KiB
8
+ modules by path ./dist/temporal/workflows/*.js 1.29 KiB
9
+ ./dist/temporal/workflows/index.js 169 bytes [built] [code generated]
10
+ ./dist/temporal/workflows/cleanup-integration-secrets-cron.js 750 bytes [built] [code generated]
11
+ ./dist/temporal/workflows/prune-webhook-deliveries-cron.js 405 bytes [built] [code generated]
8
12
  ./dist/temporal/workflows/index-autogenerated-entrypoint.cjs 941 bytes [built] [code generated]
9
- ./dist/temporal/workflows/index.js 82 bytes [built] [code generated]
10
- ./dist/temporal/workflows/prune-webhook-deliveries-cron.js 405 bytes [built] [code generated]
13
+ ./dist/temporal/constants.js 198 bytes [built] [code generated]
11
14
  optional modules 30 bytes [optional]
12
15
  __temporal_custom_payload_converter (ignored) 15 bytes [optional] [built] [code generated]
13
16
  __temporal_custom_failure_converter (ignored) 15 bytes [optional] [built] [code generated]
14
17
  ../../../shared/node/temporal/dist/workflow-error-interceptor.js 1.21 KiB [built] [code generated]
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
- /home/runner/work/shipfox/shipfox/libs/api/integration/core/dist/temporal/workflows/index.js: 3323154 bytes
18
+ webpack 5.107.2 compiled successfully in 5802 ms
19
+ 2026-08-07T08:47:05.141Z [INFO] Workflow bundle created { size: '3.17MB' }
20
+ /home/runner/work/shipfox/shipfox/libs/api/integration/core/dist/temporal/workflows/index.js: 3328998 bytes
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @shipfox/api-integration-core
2
2
 
3
+ ## 12.3.0
4
+
5
+ ### Patch Changes
6
+
7
+ - e972eb3: Makes integration secret cleanup retryable after connection deletion.
8
+ - e0110fe: Adds Jira webhook renewal and disconnect deregistration support.
9
+ - Updated dependencies [4b0731e]
10
+ - Updated dependencies [e0110fe]
11
+ - @shipfox/api-workflows-dto@12.3.0
12
+ - @shipfox/api-integration-jira@12.3.0
13
+ - @shipfox/api-integration-spi@1.1.0
14
+ - @shipfox/api-integration-gitea@12.3.0
15
+ - @shipfox/api-integration-github@12.3.0
16
+ - @shipfox/api-integration-linear@12.3.0
17
+ - @shipfox/api-integration-sentry@12.3.0
18
+ - @shipfox/api-integration-slack@12.3.0
19
+ - @shipfox/api-integration-webhook@12.3.0
20
+
3
21
  ## 12.2.0
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,20 @@
1
+ import type { IntegrationConnection } from '#core/entities/connection.js';
2
+ import type { IntegrationProviderRegistry } from '#core/providers/registry.js';
3
+ export interface ProcessIntegrationSecretCleanupsOptions {
4
+ registry: IntegrationProviderRegistry;
5
+ connectionId?: string | undefined;
6
+ connection?: IntegrationConnection | undefined;
7
+ limit?: number | undefined;
8
+ now?: Date | undefined;
9
+ heartbeat?: (() => void) | undefined;
10
+ }
11
+ export interface ProcessIntegrationSecretCleanupsResult {
12
+ claimed: number;
13
+ completed: number;
14
+ failed: number;
15
+ unavailable: number;
16
+ /** Rows whose lease was taken over by another sweep before this one acknowledged them. */
17
+ unacknowledged: number;
18
+ }
19
+ export declare function processIntegrationSecretCleanups(options: ProcessIntegrationSecretCleanupsOptions): Promise<ProcessIntegrationSecretCleanupsResult>;
20
+ //# sourceMappingURL=secret-cleanup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret-cleanup.d.ts","sourceRoot":"","sources":["../../src/core/secret-cleanup.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,6BAA6B,CAAC;AAkB7E,MAAM,WAAW,uCAAuC;IACtD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,UAAU,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC/C,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,GAAG,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CACtC;AAED,MAAM,WAAW,sCAAsC;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,0FAA0F;IAC1F,cAAc,EAAE,MAAM,CAAC;CACxB;AAID,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,uCAAuC,GAC/C,OAAO,CAAC,sCAAsC,CAAC,CAyDjD"}
@@ -0,0 +1,178 @@
1
+ import { reportError } from '@shipfox/node-error-monitoring';
2
+ import { logger } from '@shipfox/node-opentelemetry';
3
+ import { claimIntegrationSecretCleanups, completeIntegrationSecretCleanup, retryIntegrationSecretCleanup } from '#db/secret-cleanups.js';
4
+ const RETRY_BASE_DELAY_MS = 60 * 1_000;
5
+ const RETRY_MAX_DELAY_MS = 60 * 60 * 1_000;
6
+ const DEFAULT_BATCH_SIZE = 100;
7
+ const HEARTBEAT_INTERVAL_MS = 15_000;
8
+ const STUCK_CLEANUP_ALERT_CACHE_LIMIT = 10_000;
9
+ // Attempts, not hours: the backoff caps at RETRY_MAX_DELAY_MS, so a stuck row is retried
10
+ // hourly and this threshold lands about a week out. Revisit it alongside that cap.
11
+ const STUCK_CLEANUP_ATTEMPT_COUNT = 7 * 24;
12
+ const reportedStuckCleanupIds = new Set();
13
+ export async function processIntegrationSecretCleanups(options) {
14
+ const cleanups = await claimIntegrationSecretCleanups({
15
+ connectionId: options.connectionId,
16
+ limit: options.limit ?? DEFAULT_BATCH_SIZE,
17
+ now: options.now ?? new Date()
18
+ });
19
+ const result = {
20
+ claimed: cleanups.length,
21
+ completed: 0,
22
+ failed: 0,
23
+ unavailable: 0,
24
+ unacknowledged: 0
25
+ };
26
+ for (const cleanup of cleanups){
27
+ // Keep heartbeating through the provider call itself. Beating only between rows would
28
+ // let one slow deletion trip the activity's heartbeat timeout and kill the whole sweep.
29
+ options.heartbeat?.();
30
+ const heartbeatInterval = setInterval(()=>options.heartbeat?.(), HEARTBEAT_INTERVAL_MS);
31
+ // A single row must never strand the rest of the claimed batch under its lease.
32
+ try {
33
+ const provider = options.registry.list().find((candidate)=>candidate.provider === cleanup.provider);
34
+ if (!provider) {
35
+ result.unavailable += 1;
36
+ if (!await scheduleRetry(cleanup, 'provider-unavailable')) {
37
+ result.unacknowledged += 1;
38
+ }
39
+ continue;
40
+ }
41
+ // A loaded provider without the hook has no secrets to delete, so the intent is
42
+ // already satisfied and the row can retire.
43
+ await provider.deleteConnectionSecrets?.(getCleanupConnection(cleanup, options.connection));
44
+ const acknowledged = await completeIntegrationSecretCleanup({
45
+ id: cleanup.id,
46
+ leaseToken: requireLeaseToken(cleanup)
47
+ });
48
+ if (acknowledged) {
49
+ result.completed += 1;
50
+ } else {
51
+ result.unacknowledged += 1;
52
+ logLeaseLost(cleanup, 'complete');
53
+ }
54
+ } catch (error) {
55
+ result.failed += 1;
56
+ if (!await scheduleRetry(cleanup, 'cleanup-failed', error)) {
57
+ result.unacknowledged += 1;
58
+ }
59
+ } finally{
60
+ clearInterval(heartbeatInterval);
61
+ options.heartbeat?.();
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ function getCleanupConnection(cleanup, connection) {
67
+ if (connection?.id === cleanup.connectionId) return connection;
68
+ return {
69
+ id: cleanup.connectionId,
70
+ workspaceId: cleanup.workspaceId,
71
+ provider: cleanup.provider,
72
+ externalAccountId: cleanup.externalAccountId,
73
+ slug: cleanup.slug,
74
+ displayName: cleanup.displayName,
75
+ lifecycleStatus: cleanup.lifecycleStatus,
76
+ createdAt: cleanup.connectionCreatedAt,
77
+ updatedAt: cleanup.connectionUpdatedAt
78
+ };
79
+ }
80
+ async function scheduleRetry(cleanup, reason, error) {
81
+ const delayMs = retryDelayMs(cleanup.attemptCount);
82
+ logCleanupRetry(cleanup, reason, delayMs, error);
83
+ if (error !== undefined) {
84
+ reportError(error, {
85
+ boundary: 'integration.secret-cleanup',
86
+ operation: 'delete-connection-secrets',
87
+ tags: {
88
+ provider: cleanup.provider
89
+ }
90
+ });
91
+ }
92
+ // Keep escalating past the threshold. A stuck row means secrets may still exist, and
93
+ // one missed alert would hide that forever. The bounded per-cleanup cache suppresses
94
+ // duplicate reports in this worker while allowing a fresh process to re-alert.
95
+ if (cleanup.attemptCount >= STUCK_CLEANUP_ATTEMPT_COUNT) {
96
+ const stuckErrorMessage = 'Integration connection secret cleanup exceeded its retry threshold';
97
+ logger().error({
98
+ provider: cleanup.provider,
99
+ connectionId: cleanup.connectionId,
100
+ attempt: cleanup.attemptCount
101
+ }, stuckErrorMessage);
102
+ if (!reportedStuckCleanupIds.has(cleanup.id)) {
103
+ const eventId = reportError(new Error(stuckErrorMessage), {
104
+ boundary: 'integration.secret-cleanup',
105
+ operation: 'stuck-cleanup',
106
+ tags: {
107
+ provider: cleanup.provider
108
+ },
109
+ extra: {
110
+ cleanupId: cleanup.id
111
+ }
112
+ });
113
+ if (eventId) {
114
+ reportedStuckCleanupIds.add(cleanup.id);
115
+ if (reportedStuckCleanupIds.size > STUCK_CLEANUP_ALERT_CACHE_LIMIT) {
116
+ const oldestCleanupId = reportedStuckCleanupIds.values().next().value;
117
+ if (oldestCleanupId !== undefined) reportedStuckCleanupIds.delete(oldestCleanupId);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ try {
123
+ const rescheduled = await retryIntegrationSecretCleanup({
124
+ id: cleanup.id,
125
+ leaseToken: requireLeaseToken(cleanup),
126
+ delayMs
127
+ });
128
+ if (!rescheduled) {
129
+ logLeaseLost(cleanup, 'retry');
130
+ return false;
131
+ }
132
+ return true;
133
+ } catch (retryError) {
134
+ // The lease expires on its own, so a later sweep still picks this row up.
135
+ logger().error({
136
+ provider: cleanup.provider,
137
+ connectionId: cleanup.connectionId,
138
+ err: retryError
139
+ }, 'Failed to reschedule integration connection secret cleanup');
140
+ reportError(retryError, {
141
+ boundary: 'integration.secret-cleanup',
142
+ operation: 'reschedule-cleanup',
143
+ tags: {
144
+ provider: cleanup.provider
145
+ }
146
+ });
147
+ return false;
148
+ }
149
+ }
150
+ function retryDelayMs(attemptCount) {
151
+ return Math.min(RETRY_BASE_DELAY_MS * 2 ** Math.max(0, attemptCount - 1), RETRY_MAX_DELAY_MS);
152
+ }
153
+ function requireLeaseToken(cleanup) {
154
+ if (!cleanup.leaseToken) throw new Error('Claimed integration secret cleanup has no lease token');
155
+ return cleanup.leaseToken;
156
+ }
157
+ function logCleanupRetry(cleanup, reason, delayMs, error) {
158
+ logger().warn({
159
+ provider: cleanup.provider,
160
+ connectionId: cleanup.connectionId,
161
+ attempt: cleanup.attemptCount,
162
+ reason,
163
+ delayMs,
164
+ ...error === undefined ? {} : {
165
+ err: error
166
+ }
167
+ }, 'Integration connection secret cleanup will be retried');
168
+ }
169
+ function logLeaseLost(cleanup, operation) {
170
+ logger().warn({
171
+ provider: cleanup.provider,
172
+ connectionId: cleanup.connectionId,
173
+ attempt: cleanup.attemptCount,
174
+ operation
175
+ }, 'Integration connection secret cleanup lease was lost before acknowledgement');
176
+ }
177
+
178
+ //# sourceMappingURL=secret-cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/secret-cleanup.ts"],"sourcesContent":["import {reportError} from '@shipfox/node-error-monitoring';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport type {IntegrationConnection} from '#core/entities/connection.js';\nimport type {IntegrationProviderRegistry} from '#core/providers/registry.js';\nimport {\n claimIntegrationSecretCleanups,\n completeIntegrationSecretCleanup,\n type IntegrationSecretCleanup,\n retryIntegrationSecretCleanup,\n} from '#db/secret-cleanups.js';\n\nconst RETRY_BASE_DELAY_MS = 60 * 1_000;\nconst RETRY_MAX_DELAY_MS = 60 * 60 * 1_000;\nconst DEFAULT_BATCH_SIZE = 100;\nconst HEARTBEAT_INTERVAL_MS = 15_000;\nconst STUCK_CLEANUP_ALERT_CACHE_LIMIT = 10_000;\n// Attempts, not hours: the backoff caps at RETRY_MAX_DELAY_MS, so a stuck row is retried\n// hourly and this threshold lands about a week out. Revisit it alongside that cap.\nconst STUCK_CLEANUP_ATTEMPT_COUNT = 7 * 24;\nconst reportedStuckCleanupIds = new Set<string>();\n\nexport interface ProcessIntegrationSecretCleanupsOptions {\n registry: IntegrationProviderRegistry;\n connectionId?: string | undefined;\n connection?: IntegrationConnection | undefined;\n limit?: number | undefined;\n now?: Date | undefined;\n heartbeat?: (() => void) | undefined;\n}\n\nexport interface ProcessIntegrationSecretCleanupsResult {\n claimed: number;\n completed: number;\n failed: number;\n unavailable: number;\n /** Rows whose lease was taken over by another sweep before this one acknowledged them. */\n unacknowledged: number;\n}\n\ntype CleanupRetryReason = 'provider-unavailable' | 'cleanup-failed';\n\nexport async function processIntegrationSecretCleanups(\n options: ProcessIntegrationSecretCleanupsOptions,\n): Promise<ProcessIntegrationSecretCleanupsResult> {\n const cleanups = await claimIntegrationSecretCleanups({\n connectionId: options.connectionId,\n limit: options.limit ?? DEFAULT_BATCH_SIZE,\n now: options.now ?? new Date(),\n });\n const result: ProcessIntegrationSecretCleanupsResult = {\n claimed: cleanups.length,\n completed: 0,\n failed: 0,\n unavailable: 0,\n unacknowledged: 0,\n };\n\n for (const cleanup of cleanups) {\n // Keep heartbeating through the provider call itself. Beating only between rows would\n // let one slow deletion trip the activity's heartbeat timeout and kill the whole sweep.\n options.heartbeat?.();\n const heartbeatInterval = setInterval(() => options.heartbeat?.(), HEARTBEAT_INTERVAL_MS);\n // A single row must never strand the rest of the claimed batch under its lease.\n try {\n const provider = options.registry\n .list()\n .find((candidate) => candidate.provider === cleanup.provider);\n if (!provider) {\n result.unavailable += 1;\n if (!(await scheduleRetry(cleanup, 'provider-unavailable'))) {\n result.unacknowledged += 1;\n }\n continue;\n }\n\n // A loaded provider without the hook has no secrets to delete, so the intent is\n // already satisfied and the row can retire.\n await provider.deleteConnectionSecrets?.(getCleanupConnection(cleanup, options.connection));\n const acknowledged = await completeIntegrationSecretCleanup({\n id: cleanup.id,\n leaseToken: requireLeaseToken(cleanup),\n });\n if (acknowledged) {\n result.completed += 1;\n } else {\n result.unacknowledged += 1;\n logLeaseLost(cleanup, 'complete');\n }\n } catch (error) {\n result.failed += 1;\n if (!(await scheduleRetry(cleanup, 'cleanup-failed', error))) {\n result.unacknowledged += 1;\n }\n } finally {\n clearInterval(heartbeatInterval);\n options.heartbeat?.();\n }\n }\n\n return result;\n}\n\nfunction getCleanupConnection(\n cleanup: IntegrationSecretCleanup,\n connection: IntegrationConnection | undefined,\n): IntegrationConnection {\n if (connection?.id === cleanup.connectionId) return connection;\n return {\n id: cleanup.connectionId,\n workspaceId: cleanup.workspaceId,\n provider: cleanup.provider,\n externalAccountId: cleanup.externalAccountId,\n slug: cleanup.slug,\n displayName: cleanup.displayName,\n lifecycleStatus: cleanup.lifecycleStatus,\n createdAt: cleanup.connectionCreatedAt,\n updatedAt: cleanup.connectionUpdatedAt,\n };\n}\n\nasync function scheduleRetry(\n cleanup: IntegrationSecretCleanup,\n reason: CleanupRetryReason,\n error?: unknown,\n): Promise<boolean> {\n const delayMs = retryDelayMs(cleanup.attemptCount);\n logCleanupRetry(cleanup, reason, delayMs, error);\n if (error !== undefined) {\n reportError(error, {\n boundary: 'integration.secret-cleanup',\n operation: 'delete-connection-secrets',\n tags: {provider: cleanup.provider},\n });\n }\n // Keep escalating past the threshold. A stuck row means secrets may still exist, and\n // one missed alert would hide that forever. The bounded per-cleanup cache suppresses\n // duplicate reports in this worker while allowing a fresh process to re-alert.\n if (cleanup.attemptCount >= STUCK_CLEANUP_ATTEMPT_COUNT) {\n const stuckErrorMessage = 'Integration connection secret cleanup exceeded its retry threshold';\n logger().error(\n {\n provider: cleanup.provider,\n connectionId: cleanup.connectionId,\n attempt: cleanup.attemptCount,\n },\n stuckErrorMessage,\n );\n if (!reportedStuckCleanupIds.has(cleanup.id)) {\n const eventId = reportError(new Error(stuckErrorMessage), {\n boundary: 'integration.secret-cleanup',\n operation: 'stuck-cleanup',\n tags: {provider: cleanup.provider},\n extra: {cleanupId: cleanup.id},\n });\n if (eventId) {\n reportedStuckCleanupIds.add(cleanup.id);\n if (reportedStuckCleanupIds.size > STUCK_CLEANUP_ALERT_CACHE_LIMIT) {\n const oldestCleanupId = reportedStuckCleanupIds.values().next().value;\n if (oldestCleanupId !== undefined) reportedStuckCleanupIds.delete(oldestCleanupId);\n }\n }\n }\n }\n\n try {\n const rescheduled = await retryIntegrationSecretCleanup({\n id: cleanup.id,\n leaseToken: requireLeaseToken(cleanup),\n delayMs,\n });\n if (!rescheduled) {\n logLeaseLost(cleanup, 'retry');\n return false;\n }\n return true;\n } catch (retryError) {\n // The lease expires on its own, so a later sweep still picks this row up.\n logger().error(\n {provider: cleanup.provider, connectionId: cleanup.connectionId, err: retryError},\n 'Failed to reschedule integration connection secret cleanup',\n );\n reportError(retryError, {\n boundary: 'integration.secret-cleanup',\n operation: 'reschedule-cleanup',\n tags: {provider: cleanup.provider},\n });\n return false;\n }\n}\n\nfunction retryDelayMs(attemptCount: number): number {\n return Math.min(RETRY_BASE_DELAY_MS * 2 ** Math.max(0, attemptCount - 1), RETRY_MAX_DELAY_MS);\n}\n\nfunction requireLeaseToken(cleanup: IntegrationSecretCleanup): string {\n if (!cleanup.leaseToken) throw new Error('Claimed integration secret cleanup has no lease token');\n return cleanup.leaseToken;\n}\n\nfunction logCleanupRetry(\n cleanup: IntegrationSecretCleanup,\n reason: CleanupRetryReason,\n delayMs: number,\n error: unknown,\n): void {\n logger().warn(\n {\n provider: cleanup.provider,\n connectionId: cleanup.connectionId,\n attempt: cleanup.attemptCount,\n reason,\n delayMs,\n ...(error === undefined ? {} : {err: error}),\n },\n 'Integration connection secret cleanup will be retried',\n );\n}\n\nfunction logLeaseLost(cleanup: IntegrationSecretCleanup, operation: 'complete' | 'retry'): void {\n logger().warn(\n {\n provider: cleanup.provider,\n connectionId: cleanup.connectionId,\n attempt: cleanup.attemptCount,\n operation,\n },\n 'Integration connection secret cleanup lease was lost before acknowledgement',\n );\n}\n"],"names":["reportError","logger","claimIntegrationSecretCleanups","completeIntegrationSecretCleanup","retryIntegrationSecretCleanup","RETRY_BASE_DELAY_MS","RETRY_MAX_DELAY_MS","DEFAULT_BATCH_SIZE","HEARTBEAT_INTERVAL_MS","STUCK_CLEANUP_ALERT_CACHE_LIMIT","STUCK_CLEANUP_ATTEMPT_COUNT","reportedStuckCleanupIds","Set","processIntegrationSecretCleanups","options","cleanups","connectionId","limit","now","Date","result","claimed","length","completed","failed","unavailable","unacknowledged","cleanup","heartbeat","heartbeatInterval","setInterval","provider","registry","list","find","candidate","scheduleRetry","deleteConnectionSecrets","getCleanupConnection","connection","acknowledged","id","leaseToken","requireLeaseToken","logLeaseLost","error","clearInterval","workspaceId","externalAccountId","slug","displayName","lifecycleStatus","createdAt","connectionCreatedAt","updatedAt","connectionUpdatedAt","reason","delayMs","retryDelayMs","attemptCount","logCleanupRetry","undefined","boundary","operation","tags","stuckErrorMessage","attempt","has","eventId","Error","extra","cleanupId","add","size","oldestCleanupId","values","next","value","delete","rescheduled","retryError","err","Math","min","max","warn"],"mappings":"AAAA,SAAQA,WAAW,QAAO,iCAAiC;AAC3D,SAAQC,MAAM,QAAO,8BAA8B;AAGnD,SACEC,8BAA8B,EAC9BC,gCAAgC,EAEhCC,6BAA6B,QACxB,yBAAyB;AAEhC,MAAMC,sBAAsB,KAAK;AACjC,MAAMC,qBAAqB,KAAK,KAAK;AACrC,MAAMC,qBAAqB;AAC3B,MAAMC,wBAAwB;AAC9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