@kosha-ai/integration-atlassian 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Codemancers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ export { atlassianJira, atlassianJira as default, type AtlassianJiraIntegrationOptions, } from './lib/integration-atlassian-jira.js';
2
+ export { atlassianOAuth, getAccessibleResources, selectResource, type AccessibleResource, type AtlassianOAuthOptions, } from './lib/atlassian-oauth.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,IAAI,OAAO,EACxB,KAAK,+BAA+B,GACrC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { atlassianJira, atlassianJira as default, } from './lib/integration-atlassian-jira.js';
2
+ export { atlassianOAuth, getAccessibleResources, selectResource, } from './lib/atlassian-oauth.js';
@@ -0,0 +1,28 @@
1
+ import type { IntegrationAuthStrategy } from '@kosha-ai/integration-sdk';
2
+ export interface AtlassianOAuthOptions {
3
+ authorizeUrl?: string;
4
+ tokenUrl?: string;
5
+ scopesAvailable: string[];
6
+ }
7
+ /**
8
+ * The OAuth core Jira and Confluence share: same authorization server, same
9
+ * token endpoint, same `accessible-resources` discovery. Only the API base
10
+ * path and the scope catalogue differ per product.
11
+ */
12
+ export declare function atlassianOAuth(options: AtlassianOAuthOptions): IntegrationAuthStrategy;
13
+ export interface AccessibleResource {
14
+ id: string;
15
+ name: string;
16
+ url: string;
17
+ scopes: string[];
18
+ avatarUrl?: string;
19
+ }
20
+ /**
21
+ * The Atlassian site(s) this access token can reach. A Kosha connection maps
22
+ * to exactly one, so when a user has several the first is used — matching
23
+ * Gather's existing behaviour. An org that knows its site ahead of time can
24
+ * pin it via the `siteUrl` config field instead of relying on discovery order.
25
+ */
26
+ export declare function getAccessibleResources(accessToken: string): Promise<AccessibleResource[]>;
27
+ export declare function selectResource(resources: AccessibleResource[], siteUrl?: string): AccessibleResource;
28
+ //# sourceMappingURL=atlassian-oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atlassian-oauth.d.ts","sourceRoot":"","sources":["../../src/lib/atlassian-oauth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAUzE,MAAM,WAAW,qBAAqB;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,uBAAuB,CA4BzB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAe/B;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,kBAAkB,EAAE,EAC/B,OAAO,CAAC,EAAE,MAAM,GACf,kBAAkB,CAgBpB"}
@@ -0,0 +1,71 @@
1
+ import { oauth2 } from '@kosha-ai/integration-sdk';
2
+ /**
3
+ * Atlassian 3LO always issues a refresh token when `offline_access` is
4
+ * requested, and forgets it otherwise — a scope Gather/Alkahest never need to
5
+ * ask for explicitly. Forced on every request the same way google-calendar
6
+ * forces its userinfo scopes.
7
+ */
8
+ const OFFLINE_ACCESS = 'offline_access';
9
+ /**
10
+ * The OAuth core Jira and Confluence share: same authorization server, same
11
+ * token endpoint, same `accessible-resources` discovery. Only the API base
12
+ * path and the scope catalogue differ per product.
13
+ */
14
+ export function atlassianOAuth(options) {
15
+ const auth = oauth2({
16
+ authorizationUrl: options.authorizeUrl ?? 'https://auth.atlassian.com/authorize',
17
+ tokenUrl: options.tokenUrl ?? 'https://auth.atlassian.com/oauth/token',
18
+ // Atlassian wants JSON on the token endpoint, not form-encoded.
19
+ tokenRequest: 'json',
20
+ scopeSeparator: ' ',
21
+ authorizationParams: {
22
+ audience: 'api.atlassian.com',
23
+ // Without this, a user who already granted these scopes to another
24
+ // Kosha configuration is silently reconnected to that grant instead of
25
+ // seeing a consent screen for this one.
26
+ prompt: 'consent',
27
+ },
28
+ scopesAvailable: options.scopesAvailable,
29
+ });
30
+ const originalBuildAuthorizationUrl = auth.buildAuthorizationUrl;
31
+ auth.buildAuthorizationUrl = (args) => {
32
+ const scopes = Array.from(new Set([...args.client.scopes, OFFLINE_ACCESS]));
33
+ return originalBuildAuthorizationUrl({
34
+ ...args,
35
+ client: { ...args.client, scopes },
36
+ });
37
+ };
38
+ return auth;
39
+ }
40
+ const ACCESSIBLE_RESOURCES_URL = 'https://api.atlassian.com/oauth/token/accessible-resources';
41
+ /**
42
+ * The Atlassian site(s) this access token can reach. A Kosha connection maps
43
+ * to exactly one, so when a user has several the first is used — matching
44
+ * Gather's existing behaviour. An org that knows its site ahead of time can
45
+ * pin it via the `siteUrl` config field instead of relying on discovery order.
46
+ */
47
+ export async function getAccessibleResources(accessToken) {
48
+ const response = await fetch(ACCESSIBLE_RESOURCES_URL, {
49
+ headers: {
50
+ Authorization: `Bearer ${accessToken}`,
51
+ Accept: 'application/json',
52
+ },
53
+ });
54
+ if (!response.ok) {
55
+ throw new Error(`Failed to fetch accessible Atlassian resources: HTTP ${response.status}`);
56
+ }
57
+ return (await response.json());
58
+ }
59
+ export function selectResource(resources, siteUrl) {
60
+ if (resources.length === 0) {
61
+ throw new Error('No accessible Atlassian sites granted for this account');
62
+ }
63
+ if (siteUrl) {
64
+ const match = resources.find((resource) => resource.url.toLowerCase() === siteUrl.toLowerCase());
65
+ if (!match) {
66
+ throw new Error(`Configured site "${siteUrl}" is not among the accessible resources for this grant`);
67
+ }
68
+ return match;
69
+ }
70
+ return resources[0];
71
+ }
@@ -0,0 +1,12 @@
1
+ import type { KoshaIntegration } from '@kosha-ai/integration-sdk';
2
+ export interface AtlassianJiraIntegrationOptions {
3
+ /**
4
+ * Pin the connection to one Jira site instead of taking the first one the
5
+ * granting user has access to. Match against the site's URL as returned by
6
+ * `accessible-resources` (e.g. `https://acme.atlassian.net`).
7
+ */
8
+ siteUrl?: string;
9
+ }
10
+ export declare function atlassianJira(options?: AtlassianJiraIntegrationOptions): KoshaIntegration;
11
+ export default atlassianJira;
12
+ //# sourceMappingURL=integration-atlassian-jira.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-atlassian-jira.d.ts","sourceRoot":"","sources":["../../src/lib/integration-atlassian-jira.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAclE,MAAM,WAAW,+BAA+B;IAC9C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAqBD,wBAAgB,aAAa,CAC3B,OAAO,GAAE,+BAAoC,GAC5C,gBAAgB,CAiElB;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { defineIntegration } from '@kosha-ai/integration-sdk';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { atlassianOAuth, getAccessibleResources, selectResource, } from './atlassian-oauth.js';
5
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
6
+ const docsDirectory = path.join(currentDir, '../../docs');
7
+ /**
8
+ * Least-privilege scope set for the operations Gather and Alkahest actually
9
+ * perform against Jira: read/write issues and projects, read the current
10
+ * user, and manage the webhooks that drive incremental sync. Nothing here
11
+ * grants Jira Service Management, admin, or Confluence access.
12
+ */
13
+ const SCOPES = [
14
+ 'read:jira-work',
15
+ 'write:jira-work',
16
+ 'read:jira-user',
17
+ 'manage:jira-webhook',
18
+ ];
19
+ export function atlassianJira(options = {}) {
20
+ const auth = atlassianOAuth({ scopesAvailable: SCOPES });
21
+ return defineIntegration({
22
+ key: 'atlassian-jira',
23
+ name: 'Jira',
24
+ docsUrl: 'https://developer.atlassian.com/cloud/jira/platform/rest/v3/',
25
+ docsPath: docsDirectory,
26
+ auth,
27
+ api: {
28
+ // Every Jira Cloud REST call is routed through this per-site path —
29
+ // there is no host that works without a resolved cloudId, so there is
30
+ // no static baseUrl to fall back to.
31
+ resolveBaseUrl: ({ metadata }) => {
32
+ const cloudId = metadata?.['cloudId'];
33
+ return typeof cloudId === 'string'
34
+ ? `https://api.atlassian.com/ex/jira/${cloudId}`
35
+ : undefined;
36
+ },
37
+ authHeaders: ({ accessToken }) => ({
38
+ Authorization: `Bearer ${accessToken}`,
39
+ Accept: 'application/json',
40
+ }),
41
+ egress: [{ hosts: ['api.atlassian.com'] }],
42
+ },
43
+ identity: {
44
+ async fetchAccount({ accessToken }) {
45
+ const resources = await getAccessibleResources(accessToken);
46
+ const site = selectResource(resources, options.siteUrl);
47
+ const response = await fetch(`https://api.atlassian.com/ex/jira/${site.id}/rest/api/3/myself`, {
48
+ headers: {
49
+ Authorization: `Bearer ${accessToken}`,
50
+ Accept: 'application/json',
51
+ },
52
+ });
53
+ if (!response.ok) {
54
+ throw new Error(`Failed to fetch Jira current user: HTTP ${response.status}`);
55
+ }
56
+ const user = (await response.json());
57
+ return {
58
+ // Composite id: the same Atlassian account can hold a connection
59
+ // per site, and cloudId alone would collide across sites while
60
+ // accountId alone would collide across a user's sites.
61
+ externalAccountId: `${site.id}:${user.accountId}`,
62
+ label: `${user.displayName} — ${site.name}`,
63
+ metadata: {
64
+ cloudId: site.id,
65
+ siteUrl: site.url,
66
+ siteName: site.name,
67
+ accountId: user.accountId,
68
+ },
69
+ };
70
+ },
71
+ },
72
+ });
73
+ }
74
+ export default atlassianJira;
Binary file
package/docs/setup.md ADDED
@@ -0,0 +1,98 @@
1
+ # Jira (Atlassian) Setup
2
+
3
+ To connect to Jira, you need to create an Atlassian OAuth 2.0 (3LO) app. This
4
+ allows Kosha to act on behalf of your users against their Jira Cloud site.
5
+
6
+ ### 1. Create a new OAuth 2.0 (3LO) app
7
+
8
+ 1. Go to the [Atlassian Developer Console](https://developer.atlassian.com/console/myapps).
9
+ 2. Click **Create** > **OAuth 2.0 integration**.
10
+
11
+ ![Start a new OAuth 2.0 integration](./images/atlassian-new-app.png)
12
+
13
+ 3. Name your app, and choose **Resource-level** as the access type — this
14
+ scopes the token to the one site the user selects during authorization,
15
+ matching Kosha's one-connection-per-site model. **Account-level** grants
16
+ access to every site on the user's account, which is broader than this
17
+ integration needs.
18
+ 4. Agree to the developer terms and click **Create**.
19
+
20
+ ![Name the app and pick Resource-level access](./images/atlassian-create-app.png)
21
+
22
+ 5. Once created, open the **Permissions** tab from the sidebar.
23
+
24
+ ![Go to Permissions after creating the app](./images/atlassian-overview-permissions.png)
25
+
26
+ ### 2. Add the Jira API and select scopes
27
+
28
+ 1. Find the **Jira API** row and click **Add**.
29
+
30
+ ![Add the Jira API permission](./images/atlassian-add-jira-api.png)
31
+
32
+ 2. Click **Configure**/**Edit Scopes** on the Jira API row and enable exactly
33
+ these four scopes:
34
+ - `read:jira-work` — View Jira issue data
35
+ - `write:jira-work` — Create and manage issues
36
+ - `read:jira-user` — View user profiles
37
+ - `manage:jira-webhook` — Manage Jira webhooks
38
+
39
+ Then click **Save**.
40
+
41
+ ![Select Jira API scopes](./images/atlassian-scopes.png)
42
+
43
+ `offline_access` (needed for refresh tokens) is requested automatically by
44
+ this package on every authorization — you don't add it here.
45
+
46
+ ### 3. Set the callback URL
47
+
48
+ 1. Go to **Authorization** in the sidebar.
49
+ 2. Under **Callback URLs**, add your Kosha instance's connect callback for
50
+ this provider: `{KOSHA_PUBLIC_URL}/api/connect/callback/atlassian-jira`
51
+ (for local testing this is typically
52
+ `http://localhost:3333/api/connect/callback/atlassian-jira`).
53
+ 3. Click **Save changes**.
54
+
55
+ ![Set the OAuth callback URL](./images/atlassian-callback-url.png)
56
+
57
+ ### 4. Copy your credentials
58
+
59
+ 1. Go to **Settings**.
60
+ 2. Copy the **Client ID** and **Secret** (click the refresh icon to reveal
61
+ the secret if it's masked).
62
+
63
+ ![Copy Client ID and Secret](./images/atlassian-client-secret.png)
64
+
65
+ 3. Paste both into the Kosha configuration form for this provider.
66
+
67
+ ## Scope matrix
68
+
69
+ - **`read:jira-work`** — List/read projects, issues, custom fields, run JQL searches
70
+ - **`write:jira-work`** — Create/update issues, transition status
71
+ - **`read:jira-user`** — Resolve the connected account's identity (`/myself`)
72
+ - **`manage:jira-webhook`** — Register/unregister webhooks for incremental sync
73
+ - **`offline_access`** — Issue a refresh token — requested automatically, not configurable
74
+
75
+ Nothing here grants Jira admin, Jira Service Management, or Confluence
76
+ access. A consumer that also needs Confluence should use
77
+ `atlassianConfluence()` from this same package (once added) rather than
78
+ widening this integration's scopes.
79
+
80
+ ## Site selection
81
+
82
+ An Atlassian OAuth grant can span multiple sites (a user with access to
83
+ `acme.atlassian.net` and `acme-eu.atlassian.net`, say). Kosha resolves one
84
+ site per connection:
85
+
86
+ - By default, the **first** site returned by Atlassian's
87
+ `accessible-resources` endpoint for that grant.
88
+ - To pin a specific site instead, pass `siteUrl` when registering the
89
+ integration:
90
+
91
+ ```ts
92
+ import { atlassianJira } from '@kosha-ai/integration-atlassian';
93
+
94
+ atlassianJira({ siteUrl: 'https://acme.atlassian.net' });
95
+ ```
96
+
97
+ The resolved site's cloudId is stored on the connection and used to route
98
+ every proxied API call to `https://api.atlassian.com/ex/jira/{cloudId}/...`.
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@kosha-ai/integration-atlassian",
3
+ "version": "0.0.1",
4
+ "description": "Atlassian (Jira, Confluence) integration for Kosha",
5
+ "keywords": [
6
+ "kosha",
7
+ "atlassian",
8
+ "jira",
9
+ "confluence",
10
+ "oauth",
11
+ "integrations"
12
+ ],
13
+ "license": "MIT",
14
+ "homepage": "https://github.com/codemancers/kosha#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/codemancers/kosha/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/codemancers/kosha.git",
21
+ "directory": "packages/integrations/atlassian"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "type": "module",
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ "./package.json": "./package.json",
32
+ ".": {
33
+ "@org/source": "./src/index.ts",
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js",
36
+ "default": "./dist/index.js"
37
+ }
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "docs",
42
+ "!**/*.tsbuildinfo"
43
+ ],
44
+ "dependencies": {
45
+ "tslib": "^2.3.0"
46
+ },
47
+ "kosha": {
48
+ "kind": "integration",
49
+ "key": "atlassian-jira"
50
+ },
51
+ "peerDependencies": {
52
+ "@kosha-ai/integration-sdk": "0.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "@kosha-ai/integration-sdk": "0.1.0"
56
+ }
57
+ }