@kosha-ai/integration-asana 0.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.
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.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @kosha-ai/integration-asana
2
+
3
+ Asana provider for [Kosha](https://github.com/codemancers/kosha). Adds OAuth2
4
+ connect, automatic token refresh, an authenticated request proxy, and
5
+ account/workspace identity for the Asana REST API.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @kosha-ai/integration-asana
11
+ ```
12
+
13
+ ## Use
14
+
15
+ Add it to your `kosha.config.ts`:
16
+
17
+ ```ts
18
+ import { defineConfig } from '@kosha-ai/server';
19
+ import asana from '@kosha-ai/integration-asana';
20
+
21
+ export default defineConfig({
22
+ // ...database, auth, encryption
23
+ integrations: [asana()],
24
+ });
25
+ ```
26
+
27
+ On boot Kosha reconciles the provider catalogue from the installed packages, so
28
+ Asana appears in the admin's provider list with nothing else to register.
29
+
30
+ `asana()` accepts optional overrides, mainly for testing or an Asana-compatible
31
+ host:
32
+
33
+ ```ts
34
+ asana({
35
+ baseUrl: 'https://app.asana.com/api/1.0', // REST base
36
+ authBaseUrl: 'https://app.asana.com', // authorize/token/revoke host
37
+ });
38
+ ```
39
+
40
+ ## Scopes
41
+
42
+ Asana uses granular `resource:action` scopes. The package advertises Asana's
43
+ full scope catalogue (`projects:*`, `tasks:*`, `stories:*`, `attachments:*`,
44
+ `goals:read`, `webhooks:*`, `workspaces:read`, `users:read`, and more); an
45
+ organization selects the least-privilege subset it needs per configuration.
46
+ `users:read` (and `workspaces:read`) are required for the connect-time identity
47
+ call.
48
+ See [docs/setup.md](./docs/setup.md) for the operation → scope matrix and the
49
+ "Full permissions" caveat.
50
+
51
+ ## Workspace selection
52
+
53
+ An Asana account can belong to several workspaces, and most operations are
54
+ scoped to one. Kosha identifies the **account** (by the user's `gid`); the
55
+ target **workspace** is supplied by the caller per request through the proxy
56
+ (as Asana's `workspace` parameter). See [docs/setup.md](./docs/setup.md).
57
+
58
+ ## Setup
59
+
60
+ See [docs/setup.md](./docs/setup.md) for registering the OAuth app and the
61
+ redirect URL.
@@ -0,0 +1,2 @@
1
+ export { asana, asana as default, type AsanaIntegrationOptions, } from './lib/integration-asana.js';
2
+ //# 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,KAAK,EACL,KAAK,IAAI,OAAO,EAChB,KAAK,uBAAuB,GAC7B,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { asana, asana as default, } from './lib/integration-asana.js';
@@ -0,0 +1,13 @@
1
+ import type { KoshaIntegration } from '@kosha-ai/integration-sdk';
2
+ export interface AsanaIntegrationOptions {
3
+ /** Override the REST API base — e.g. to point tests at a mock server. */
4
+ baseUrl?: string;
5
+ /**
6
+ * Override the OAuth host that serves authorize/token/revoke. Same host as
7
+ * the app in practice; separated only so tests can retarget it.
8
+ */
9
+ authBaseUrl?: string;
10
+ }
11
+ export declare function asana(options?: AsanaIntegrationOptions): KoshaIntegration;
12
+ export default asana;
13
+ //# sourceMappingURL=integration-asana.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-asana.d.ts","sourceRoot":"","sources":["../../src/lib/integration-asana.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAQlE,MAAM,WAAW,uBAAuB;IACtC,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAeD,wBAAgB,KAAK,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAyG7E;AAED,eAAe,KAAK,CAAC"}
@@ -0,0 +1,108 @@
1
+ import { defineIntegration, oauth2 } from '@kosha-ai/integration-sdk';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
5
+ const docsDirectory = path.join(currentDir, '../../docs');
6
+ export function asana(options = {}) {
7
+ const apiBaseUrl = options.baseUrl ?? 'https://app.asana.com/api/1.0';
8
+ const authBaseUrl = options.authBaseUrl ?? 'https://app.asana.com';
9
+ return defineIntegration({
10
+ key: 'asana',
11
+ name: 'Asana',
12
+ docsUrl: 'https://developers.asana.com/reference/rest-api-reference',
13
+ docsPath: docsDirectory,
14
+ auth: oauth2({
15
+ authorizationUrl: `${authBaseUrl}/-/oauth_authorize`,
16
+ tokenUrl: `${authBaseUrl}/-/oauth_token`,
17
+ revokeUrl: `${authBaseUrl}/-/oauth_revoke`,
18
+ // Asana is textbook OAuth2: form-encoded token requests, space-separated
19
+ // scopes, and a standard `{ access_token, refresh_token, expires_in }`
20
+ // body. Both settings below are the SDK defaults — stated for clarity.
21
+ tokenRequest: 'form',
22
+ scopeSeparator: ' ',
23
+ // Asana's full OAuth permission-scope catalogue, mirroring the app
24
+ // console's scope list. Listing a scope only makes it selectable in a
25
+ // configuration — the Asana app must also enable it and the operator must
26
+ // request it. This is hand-maintained: keep it in sync with
27
+ // https://developers.asana.com/docs/oauth-scopes when Asana changes it.
28
+ // Identity's `GET /users/me` needs `users:read` (and `workspaces:read`
29
+ // for the workspace list), so those must stay.
30
+ scopesAvailable: [
31
+ 'attachments:read',
32
+ 'attachments:write',
33
+ 'attachments:delete',
34
+ 'custom_fields:read',
35
+ 'custom_fields:write',
36
+ 'custom_types:read',
37
+ 'goals:read',
38
+ 'openid',
39
+ 'email',
40
+ 'profile',
41
+ 'jobs:read',
42
+ 'notifications:read',
43
+ 'notifications:write',
44
+ 'ooo_entries:read',
45
+ 'ooo_entries:write',
46
+ 'ooo_entries:delete',
47
+ 'portfolios:read',
48
+ 'portfolios:write',
49
+ 'project_portfolio_settings:read',
50
+ 'project_portfolio_settings:write',
51
+ 'project_templates:read',
52
+ 'projects:read',
53
+ 'projects:write',
54
+ 'projects:delete',
55
+ 'roles:read',
56
+ 'roles:write',
57
+ 'roles:delete',
58
+ 'stories:read',
59
+ 'stories:write',
60
+ 'tags:read',
61
+ 'tags:write',
62
+ 'task_templates:read',
63
+ 'tasks:read',
64
+ 'tasks:write',
65
+ 'tasks:delete',
66
+ 'team_memberships:read',
67
+ 'teams:read',
68
+ 'time_tracking_categories:read',
69
+ 'time_tracking_categories:write',
70
+ 'time_tracking_categories:delete',
71
+ 'time_tracking_entries:read',
72
+ 'timesheet_approval_statuses:read',
73
+ 'timesheet_approval_statuses:write',
74
+ 'users:read',
75
+ 'webhooks:read',
76
+ 'webhooks:write',
77
+ 'webhooks:delete',
78
+ 'workspaces:read',
79
+ 'workspaces.typeahead:read',
80
+ ],
81
+ }),
82
+ api: {
83
+ baseUrl: apiBaseUrl,
84
+ authHeaders: ({ accessToken }) => ({
85
+ Authorization: `Bearer ${accessToken}`,
86
+ Accept: 'application/json',
87
+ }),
88
+ // Lend the connection's identity to a sandbox only for Asana's own API
89
+ // host, using the same bearer header the REST proxy sends.
90
+ egress: [{ hosts: [new URL(apiBaseUrl).hostname] }],
91
+ },
92
+ identity: {
93
+ async fetchAccount({ accessToken, http }) {
94
+ const me = await http.get('/users/me', {
95
+ accessToken,
96
+ });
97
+ const user = me.data;
98
+ // gid is the stable per-account key Kosha dedupes connections on, so a
99
+ // reconnect updates the same row instead of forking a duplicate.
100
+ return {
101
+ externalAccountId: user.gid,
102
+ label: user.name ?? user.email ?? user.gid,
103
+ };
104
+ },
105
+ },
106
+ });
107
+ }
108
+ export default asana;
Binary file
package/docs/setup.md ADDED
@@ -0,0 +1,94 @@
1
+ # Asana Setup
2
+
3
+ To connect to Asana you need an Asana OAuth application. It lets Kosha complete
4
+ the OAuth handshake and act on behalf of your users.
5
+
6
+ ## 1. Create the app
7
+
8
+ Open the [Asana developer console](https://app.asana.com/0/my-apps) and click
9
+ **+ New app**.
10
+
11
+ ![Asana developer console — New app](./images/asana-my-apps-new-app.png)
12
+
13
+ Give it a name, choose **API app** ("host your own server and connect it to
14
+ Asana using the API and OAuth"), agree to the Asana API Terms, and click
15
+ **Create**.
16
+
17
+ ![Name the app and choose API app](./images/asana-create-app.png)
18
+
19
+ ## 2. Add the redirect URL
20
+
21
+ Open the app's **OAuth** tab and click **Add redirect URL**.
22
+
23
+ ![OAuth tab — Add redirect URL](./images/asana-oauth-add-redirect.png)
24
+
25
+ Enter your Kosha deployment's Asana callback and click **Add**:
26
+
27
+ ```
28
+ https://your-kosha-host/api/connect/callback/asana
29
+ ```
30
+
31
+ For local development this is `http://localhost:3333/api/connect/callback/asana`.
32
+ It must match exactly.
33
+
34
+ ![Enter the Kosha redirect URL](./images/asana-add-redirect-url.png)
35
+
36
+ ## 3. Copy the credentials
37
+
38
+ On the **OAuth** tab, under **App credentials**, copy the **Client ID** and
39
+ **Client secret** into the Kosha configuration form for Asana. Kosha stores the
40
+ secret encrypted (AES-256-GCM); it is never returned to a client.
41
+
42
+ ![Copy the Client ID and Client secret](./images/asana-oauth-credentials.png)
43
+
44
+ ## 4. Choose permission scopes
45
+
46
+ Scopes are chosen in **two places, and they must agree**:
47
+
48
+ 1. **On the Asana app** — what the app is _allowed_ to request. Either leave it
49
+ on **Full permissions**, or turn that off and tick the read/write/delete
50
+ boxes you want, then **Save changes**.
51
+ 2. **In the Kosha configuration** — what Kosha _actually requests_ for this
52
+ configuration (sent on the authorize redirect). Kosha exposes Asana's full
53
+ scope catalogue; pick the least-privilege subset your integration uses.
54
+
55
+ ![Select Asana permission scopes and save](./images/asana-permission-scopes.png)
56
+
57
+ The set you request in Kosha must be enabled on the Asana app, or Asana rejects
58
+ the authorization with `invalid_scope`. The simplest setup is to enable the same
59
+ set in both. **If the Asana app is left on Full permissions, leave the Kosha
60
+ scopes empty** — a Full-permissions app rejects a granular scope list.
61
+
62
+ ## Operation → scope reference
63
+
64
+ The scope each representative project/task operation needs:
65
+
66
+ - **`projects:read`** — list / read projects (`GET /projects`, `/projects/{gid}`)
67
+ - **`projects:write`** — create / update projects (`POST` / `PUT /projects`)
68
+ - **`tasks:read`** — list / read tasks (`GET /tasks`, `/tasks/{gid}`)
69
+ - **`tasks:write`** — create / update / complete tasks (`POST` / `PUT /tasks`)
70
+ - **`stories:read`** — read task comments / stories (`GET /tasks/{gid}/stories`)
71
+ - **`workspaces:read`** — list workspaces (`GET /workspaces`, `/users/me`)
72
+ - **`users:read`** — read users (`GET /users`, `/users/{gid}`)
73
+
74
+ **Connecting requires `users:read`.** The connect flow calls `GET /users/me`
75
+ to identify the account, so a granular-scope configuration must grant
76
+ `users:read` (and `workspaces:read` to include the account's workspaces), or the
77
+ connection fails. Asana has no `sections:*` scope — section endpoints fall under
78
+ `projects`. Some endpoints aren't scoped yet; those require Full permissions.
79
+
80
+ ## Workspace selection
81
+
82
+ Asana objects live inside a **workspace**, and a connected account may belong to
83
+ several. Kosha does not pin a workspace onto the connection:
84
+
85
+ - The **account** is identified by the user's Asana `gid` (from `GET /users/me`),
86
+ which is also the key Kosha dedupes connections on — reconnecting the same
87
+ account updates the existing connection rather than creating a duplicate.
88
+ - The **workspace** for an operation is supplied by the calling application on
89
+ each proxied request, using Asana's own `workspace` parameter (for endpoints
90
+ that require it). `GET /users/me` returns the account's `workspaces`, which a
91
+ caller can use to let a user choose.
92
+
93
+ If a deployment later needs a stored default workspace, it belongs in the
94
+ configuration's non-secret `metadata` as a config field — not in the credential.
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@kosha-ai/integration-asana",
3
+ "version": "0.1.0",
4
+ "description": "Asana integration for Kosha",
5
+ "keywords": [
6
+ "kosha",
7
+ "asana",
8
+ "oauth",
9
+ "integrations"
10
+ ],
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/codemancers/kosha#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/codemancers/kosha/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/codemancers/kosha.git",
19
+ "directory": "packages/integrations/asana"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ "./package.json": "./package.json",
30
+ ".": {
31
+ "@org/source": "./src/index.ts",
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "docs",
40
+ "!**/*.tsbuildinfo"
41
+ ],
42
+ "dependencies": {
43
+ "tslib": "^2.3.0"
44
+ },
45
+ "kosha": {
46
+ "kind": "integration",
47
+ "key": "asana"
48
+ },
49
+ "peerDependencies": {
50
+ "@kosha-ai/integration-sdk": "0.1.0"
51
+ },
52
+ "devDependencies": {
53
+ "@kosha-ai/integration-sdk": "0.1.0"
54
+ }
55
+ }