@shipfox/api-integration-jira 5.0.0 → 7.0.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipfox/api-integration-jira",
3
3
  "license": "MIT",
4
- "version": "5.0.0",
4
+ "version": "7.0.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -24,25 +24,23 @@
24
24
  "dependencies": {
25
25
  "drizzle-orm": "^0.45.2",
26
26
  "ky": "^2.0.0",
27
- "@shipfox/api-auth-context": "5.0.0",
28
- "@shipfox/api-integration-core-dto": "5.0.0",
29
- "@shipfox/api-integration-jira-dto": "5.0.0",
30
- "@shipfox/api-workspaces": "5.0.0",
27
+ "@shipfox/api-auth-context": "6.0.0",
28
+ "@shipfox/api-integration-core-dto": "6.0.0",
29
+ "@shipfox/api-integration-jira-dto": "6.0.0",
30
+ "@shipfox/api-workspaces": "7.0.1",
31
31
  "@shipfox/config": "1.2.2",
32
- "@shipfox/node-drizzle": "0.3.1",
33
- "@shipfox/node-fastify": "0.2.3",
32
+ "@shipfox/node-drizzle": "0.3.2",
33
+ "@shipfox/node-fastify": "0.2.4",
34
34
  "@shipfox/node-opentelemetry": "0.5.2",
35
35
  "@shipfox/node-postgres": "0.4.2"
36
36
  },
37
- "peerDependencies": {
38
- "@shipfox/api-secrets": "5.0.0"
39
- },
40
37
  "devDependencies": {
41
38
  "@types/pg": "^8.15.5",
42
39
  "drizzle-kit": "^0.31.10",
43
40
  "fastify": "^5.3.3",
44
41
  "fishery": "^2.4.0",
45
42
  "@shipfox/biome": "1.8.2",
43
+ "@shipfox/depcruise": "1.0.2",
46
44
  "@shipfox/swc": "1.2.6",
47
45
  "@shipfox/ts-config": "1.3.8",
48
46
  "@shipfox/typescript": "1.1.7",
@@ -52,6 +50,7 @@
52
50
  "build": "shipfox-swc",
53
51
  "check": "shipfox-biome-check",
54
52
  "check:fix": "shipfox-biome-check --write",
53
+ "depcruise": "shipfox-depcruise",
55
54
  "test": "shipfox-vitest-run",
56
55
  "test:watch": "shipfox-vitest-watch",
57
56
  "type": "shipfox-tsc-check",
@@ -8,8 +8,8 @@ import {
8
8
 
9
9
  let secrets: JiraSecretsStore;
10
10
 
11
- beforeAll(async () => {
12
- secrets = await import('@shipfox/api-secrets');
11
+ beforeEach(() => {
12
+ secrets = createInMemorySecretsStore();
13
13
  });
14
14
 
15
15
  function createConnectionContext() {
@@ -35,6 +35,20 @@ function storedToken(input: {
35
35
  });
36
36
  }
37
37
 
38
+ function createInMemorySecretsStore(): JiraSecretsStore {
39
+ const values = new Map<string, string>();
40
+ const id = (params: {workspaceId: string; namespace: string; key: string}) =>
41
+ `${params.workspaceId}\0${params.namespace}\0${params.key}`;
42
+ return {
43
+ getSecret: async (params) => values.get(id(params)) ?? null,
44
+ setSecrets: async (params) => {
45
+ await Promise.resolve();
46
+ for (const [key, value] of Object.entries(params.values))
47
+ values.set(id({...params, key}), value);
48
+ },
49
+ };
50
+ }
51
+
38
52
  describe('createJiraTokenStore.storeTokens', () => {
39
53
  it('stores access and refresh tokens in the Jira system namespace', async () => {
40
54
  const {workspaceId, connectionId, store} = createConnectionContext();
@@ -12,7 +12,6 @@ import {
12
12
  jiraCallbackQuerySchema,
13
13
  jiraCallbackResponseSchema,
14
14
  } from '@shipfox/api-integration-jira-dto';
15
- import {requireWorkspaceMembership} from '@shipfox/api-workspaces';
16
15
  import {defineRoute, type RouteGroup} from '@shipfox/node-fastify';
17
16
  import type {JiraApiClient} from '#api/client.js';
18
17
  import {config} from '#config.js';
@@ -41,11 +40,18 @@ export interface CreateJiraIntegrationRoutesOptions {
41
40
  ): Promise<IntegrationConnection<'jira'>>;
42
41
  disconnectJiraInstallation(input: {connectionId: string}): Promise<void>;
43
42
  connectionCapabilities: IntegrationCapability[];
43
+ requireActiveWorkspaceMembership?: (input: {
44
+ workspaceId: string;
45
+ userId: string;
46
+ memberships: ReadonlyArray<import('@shipfox/api-auth-context').UserContextMembership>;
47
+ }) => Promise<unknown>;
44
48
  }
45
49
 
46
50
  export function createJiraIntegrationRoutes(
47
51
  options: CreateJiraIntegrationRoutesOptions,
48
52
  ): RouteGroup {
53
+ const requireMembership =
54
+ options.requireActiveWorkspaceMembership ?? unavailableWorkspaceMembershipCheck;
49
55
  const installRoute = defineRoute({
50
56
  method: 'POST',
51
57
  path: '/install',
@@ -87,7 +93,7 @@ export function createJiraIntegrationRoutes(
87
93
  errorDescription: query.error_description,
88
94
  sessionUserId: actor.userId,
89
95
  sessionMemberships: actor.memberships,
90
- requireWorkspaceMembership,
96
+ requireWorkspaceMembership: requireMembership,
91
97
  });
92
98
  const result = await handleJiraCallback({
93
99
  ...options,
@@ -95,7 +101,7 @@ export function createJiraIntegrationRoutes(
95
101
  state: query.state,
96
102
  sessionUserId: actor.userId,
97
103
  sessionMemberships: actor.memberships,
98
- requireWorkspaceMembership,
104
+ requireWorkspaceMembership: requireMembership,
99
105
  });
100
106
  return 'sites' in result
101
107
  ? {
@@ -127,7 +133,7 @@ export function createJiraIntegrationRoutes(
127
133
  state: request.body.state,
128
134
  sessionUserId: actor.userId,
129
135
  sessionMemberships: actor.memberships,
130
- requireWorkspaceMembership,
136
+ requireWorkspaceMembership: requireMembership,
131
137
  });
132
138
  return toIntegrationConnectionDto(connection, {capabilities: options.connectionCapabilities});
133
139
  },
@@ -138,6 +144,14 @@ export function createJiraIntegrationRoutes(
138
144
  };
139
145
  }
140
146
 
147
+ function unavailableWorkspaceMembershipCheck(_input: {
148
+ workspaceId: string;
149
+ userId: string;
150
+ memberships: ReadonlyArray<import('@shipfox/api-auth-context').UserContextMembership>;
151
+ }): Promise<never> {
152
+ return Promise.reject(new Error('Workspaces inter-module client is not configured'));
153
+ }
154
+
141
155
  function isJiraOAuthErrorCallback(query: JiraCallbackQueryDto): query is JiraCallbackQueryDto & {
142
156
  error: string;
143
157
  error_description?: string | undefined;
@@ -8,15 +8,6 @@ export async function setup() {
8
8
  createPostgresClient();
9
9
 
10
10
  await runMigrations(db(), migrationsPath, '__drizzle_migrations_integrations_jira');
11
- const {secretsModule} = await import('@shipfox/api-secrets');
12
- if (!secretsModule.database || Array.isArray(secretsModule.database)) {
13
- throw new Error('Secrets module database is not configured');
14
- }
15
- await runMigrations(
16
- secretsModule.database.db(),
17
- secretsModule.database.migrationsPath,
18
- '__drizzle_migrations_secrets',
19
- );
20
11
 
21
12
  closeDb();
22
13
  await closePostgresClient();