@shipfox/api-integration-jira 12.0.0 → 12.1.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 (86) hide show
  1. package/.turbo/turbo-build.log +17 -2
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +58 -2
  4. package/dist/api/client.d.ts +19 -0
  5. package/dist/api/client.d.ts.map +1 -1
  6. package/dist/api/client.js +78 -0
  7. package/dist/api/client.js.map +1 -1
  8. package/dist/core/agent-tools-provider.d.ts +26 -0
  9. package/dist/core/agent-tools-provider.d.ts.map +1 -0
  10. package/dist/core/agent-tools-provider.js +130 -0
  11. package/dist/core/agent-tools-provider.js.map +1 -0
  12. package/dist/core/agent-tools.d.ts +16 -0
  13. package/dist/core/agent-tools.d.ts.map +1 -0
  14. package/dist/core/agent-tools.js +441 -0
  15. package/dist/core/agent-tools.js.map +1 -0
  16. package/dist/core/tokens.d.ts +2 -0
  17. package/dist/core/tokens.d.ts.map +1 -1
  18. package/dist/core/tokens.js +129 -37
  19. package/dist/core/tokens.js.map +1 -1
  20. package/dist/db/db.d.ts +68 -0
  21. package/dist/db/db.d.ts.map +1 -1
  22. package/dist/db/installations.d.ts +23 -7
  23. package/dist/db/installations.d.ts.map +1 -1
  24. package/dist/db/installations.js +42 -19
  25. package/dist/db/installations.js.map +1 -1
  26. package/dist/db/schema/installations.d.ts +34 -0
  27. package/dist/db/schema/installations.d.ts.map +1 -1
  28. package/dist/db/schema/installations.js +12 -2
  29. package/dist/db/schema/installations.js.map +1 -1
  30. package/dist/index.d.ts +20 -5
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +17 -5
  33. package/dist/index.js.map +1 -1
  34. package/dist/temporal/activities/index.d.ts +2 -0
  35. package/dist/temporal/activities/index.d.ts.map +1 -0
  36. package/dist/temporal/activities/index.js +3 -0
  37. package/dist/temporal/activities/index.js.map +1 -0
  38. package/dist/temporal/activities/refresh-jira-tokens.d.ts +20 -0
  39. package/dist/temporal/activities/refresh-jira-tokens.d.ts.map +1 -0
  40. package/dist/temporal/activities/refresh-jira-tokens.js +58 -0
  41. package/dist/temporal/activities/refresh-jira-tokens.js.map +1 -0
  42. package/dist/temporal/constants.d.ts +6 -0
  43. package/dist/temporal/constants.d.ts.map +1 -0
  44. package/dist/temporal/constants.js +8 -0
  45. package/dist/temporal/constants.js.map +1 -0
  46. package/dist/temporal/worker.d.ts +9 -0
  47. package/dist/temporal/worker.d.ts.map +1 -0
  48. package/dist/temporal/worker.js +26 -0
  49. package/dist/temporal/worker.js.map +1 -0
  50. package/dist/temporal/workflows/index.bundle.js +25225 -0
  51. package/dist/temporal/workflows/index.bundle.meta.json +1 -0
  52. package/dist/temporal/workflows/index.d.ts +2 -0
  53. package/dist/temporal/workflows/index.d.ts.map +1 -0
  54. package/dist/temporal/workflows/index.js +3 -0
  55. package/dist/temporal/workflows/index.js.map +1 -0
  56. package/dist/temporal/workflows/refresh-jira-tokens-cron.d.ts +2 -0
  57. package/dist/temporal/workflows/refresh-jira-tokens-cron.d.ts.map +1 -0
  58. package/dist/temporal/workflows/refresh-jira-tokens-cron.js +20 -0
  59. package/dist/temporal/workflows/refresh-jira-tokens-cron.js.map +1 -0
  60. package/dist/tsconfig.test.tsbuildinfo +1 -1
  61. package/drizzle/0001_jira-token-refresh-state.sql +12 -0
  62. package/drizzle/meta/0001_snapshot.json +245 -0
  63. package/drizzle/meta/_journal.json +7 -0
  64. package/package.json +12 -5
  65. package/src/api/client.test.ts +133 -12
  66. package/src/api/client.ts +107 -0
  67. package/src/core/agent-tools-provider.test.ts +299 -0
  68. package/src/core/agent-tools-provider.ts +175 -0
  69. package/src/core/agent-tools.ts +450 -0
  70. package/src/core/tokens-refresh.test.ts +221 -4
  71. package/src/core/tokens.test.ts +1 -1
  72. package/src/core/tokens.ts +153 -33
  73. package/src/db/installations.test.ts +84 -2
  74. package/src/db/installations.ts +81 -21
  75. package/src/db/schema/installations.ts +21 -1
  76. package/src/index.test.ts +34 -0
  77. package/src/index.ts +47 -3
  78. package/src/temporal/activities/index.ts +5 -0
  79. package/src/temporal/activities/refresh-jira-tokens.test.ts +156 -0
  80. package/src/temporal/activities/refresh-jira-tokens.ts +88 -0
  81. package/src/temporal/constants.ts +8 -0
  82. package/src/temporal/worker.ts +39 -0
  83. package/src/temporal/workflows/index.ts +1 -0
  84. package/src/temporal/workflows/refresh-jira-tokens-cron.ts +19 -0
  85. package/test/factories/jira-installation.ts +4 -0
  86. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1,39 @@
1
+ import {dirname, resolve} from 'node:path';
2
+ import {fileURLToPath} from 'node:url';
3
+ import type {IntegrationConnection} from '@shipfox/api-integration-spi';
4
+ import type {ModuleWorker} from '@shipfox/node-module';
5
+ import {Context} from '@temporalio/activity';
6
+ import type {JiraTokenStore} from '#core/tokens.js';
7
+ import {createJiraMaintenanceActivities} from '#temporal/activities/index.js';
8
+ import {JIRA_MAINTENANCE_TASK_QUEUE} from '#temporal/constants.js';
9
+
10
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
11
+ const workflowsPath = resolve(packageRoot, 'dist/temporal/workflows/index.js');
12
+
13
+ export interface CreateJiraMaintenanceWorkerOptions {
14
+ tokenStore: Pick<JiraTokenStore, 'getAccessToken'>;
15
+ resolveConnection(
16
+ connectionId: string,
17
+ ): Promise<Pick<IntegrationConnection, 'lifecycleStatus'> | undefined>;
18
+ }
19
+
20
+ export function createJiraMaintenanceWorker(
21
+ options: CreateJiraMaintenanceWorkerOptions,
22
+ ): ModuleWorker {
23
+ return {
24
+ taskQueue: JIRA_MAINTENANCE_TASK_QUEUE,
25
+ workflowsPath,
26
+ activities: () =>
27
+ createJiraMaintenanceActivities({
28
+ ...options,
29
+ heartbeat: () => Context.current().heartbeat(),
30
+ }),
31
+ workflows: [
32
+ {
33
+ name: 'refreshJiraTokensCron',
34
+ id: 'jira-refresh-tokens',
35
+ cronSchedule: '0 */6 * * *',
36
+ },
37
+ ],
38
+ };
39
+ }
@@ -0,0 +1 @@
1
+ export {refreshJiraTokensCron} from './refresh-jira-tokens-cron.js';
@@ -0,0 +1,19 @@
1
+ import {log, proxyActivities} from '@temporalio/workflow';
2
+ import type {createJiraMaintenanceActivities} from '../activities/index.js';
3
+
4
+ const {refreshJiraTokensActivity} = proxyActivities<
5
+ ReturnType<typeof createJiraMaintenanceActivities>
6
+ >({
7
+ startToCloseTimeout: '5 minutes',
8
+ heartbeatTimeout: '1 minute',
9
+ // A later cron run is the retry mechanism. Retrying this serial sweep in-place
10
+ // could overlap a still-running attempt after a timeout.
11
+ retry: {maximumAttempts: 1},
12
+ });
13
+
14
+ export async function refreshJiraTokensCron(): Promise<void> {
15
+ const result = await refreshJiraTokensActivity();
16
+ if (result.refreshed > 0 || result.failed > 0 || result.skipped > 0) {
17
+ log.info('Completed Jira proactive token refresh', {...result});
18
+ }
19
+ }
@@ -14,6 +14,8 @@ export const jiraInstallationFactory = Factory.define<JiraInstallation>(({sequen
14
14
  webhookExpiresAt: installation.webhookExpiresAt,
15
15
  status: installation.status,
16
16
  tokenExpiresAt: installation.tokenExpiresAt,
17
+ refreshTokenLastUsedAt: installation.refreshTokenLastUsedAt,
18
+ refreshTokenLastAttemptedAt: installation.refreshTokenLastAttemptedAt,
17
19
  }),
18
20
  );
19
21
 
@@ -29,6 +31,8 @@ export const jiraInstallationFactory = Factory.define<JiraInstallation>(({sequen
29
31
  webhookExpiresAt: null,
30
32
  status: 'installed',
31
33
  tokenExpiresAt: null,
34
+ refreshTokenLastUsedAt: new Date(),
35
+ refreshTokenLastAttemptedAt: new Date(),
32
36
  createdAt: new Date(),
33
37
  updatedAt: new Date(),
34
38
  };