AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(asana): see which Asana account each connection belongs to (#16020)
Ibrahim Abuznaidc9a034283ed1
diff --git a/bun.lock b/bun.lockindex 562a31d101a..952ae027bb5 100644--- a/bun.lock+++ b/bun.lock@@ -763,7 +763,7 @@},"packages/pieces/community/asana": {"name": "@activepieces/piece-asana",- "version": "0.6.0",+ "version": "0.6.1","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",@@ -773,6 +773,7 @@},"devDependencies": {"tslib": "2.6.2",+ "vitest": "3.2.6",},},"packages/pieces/community/ashby": {diff --git a/packages/pieces/community/asana/package.json b/packages/pieces/community/asana/package.jsonindex 07d3fc9534a..557af27f7ab 100644--- a/packages/pieces/community/asana/package.json+++ b/packages/pieces/community/asana/package.json@@ -1,12 +1,13 @@{"name": "@activepieces/piece-asana",- "version": "0.6.0",+ "version": "0.6.1","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","scripts": {"build": "tsc -p tsconfig.lib.json && cp package.json dist/","bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",- "lint": "eslint 'src/**/*.ts'"+ "lint": "eslint 'src/**/*.ts'",+ "test": "vitest run"},"dependencies": {"@activepieces/pieces-common": "workspace:*",@@ -16,6 +17,7 @@"@activepieces/core-utils": "workspace:*"},"devDependencies": {- "tslib": "2.6.2"+ "tslib": "2.6.2",+ "vitest": "3.2.6"}}diff --git a/packages/pieces/community/asana/src/lib/auth.test.ts b/packages/pieces/community/asana/src/lib/auth.test.tsnew file mode 100644index 00000000000..1a54c97edcc--- /dev/null+++ b/packages/pieces/community/asana/src/lib/auth.test.ts@@ -0,0 +1,59 @@+import { afterEach, describe, expect, it, vi } from 'vitest';+import { httpClient } from '@activepieces/pieces-common';+import { asanaAuth } from './auth';++const server = { apiUrl: 'http://127.0.0.1:4200/api/', publicUrl: 'http://127.0.0.1:4200/api/' };++function resolveIdentifier(data: Record<string, unknown>) {+ return asanaAuth.getConnectionIdentifier?.({ auth: { access_token: 'token', data }, server });+}++function mockUsersMe(body: unknown) {+ return vi.spyOn(httpClient, 'sendRequest').mockResolvedValue({ status: 200, headers: {}, body });+}++describe('asanaAuth.getConnectionIdentifier', () => {+ afterEach(() => {+ vi.restoreAllMocks();+ });++ it('returns the email from the user Asana puts in the token response, without calling the API', async () => {+ const sendRequest = mockUsersMe({});++ const identifier = await resolveIdentifier({ data: { gid: '1', name: 'Pat Doe', email: '[email protected]' } });++ expect(identifier).toBe('[email protected]');+ expect(sendRequest).not.toHaveBeenCalled();+ });++ it('falls back to the user name when the token user has no email', async () => {+ const sendRequest = mockUsersMe({});++ expect(await resolveIdentifier({ data: { gid: '1', name: 'Pat Doe' } })).toBe('Pat Doe');+ expect(sendRequest).not.toHaveBeenCalled();+ });++ it('asks GET /users/me when the token response carries no user', async () => {+ const sendRequest = mockUsersMe({ data: { email: '[email protected]', name: 'Me' } });++ expect(await resolveIdentifier({})).toBe('[email protected]');+ expect(sendRequest).toHaveBeenCalledWith(+ expect.objectContaining({+ url: 'https://app.asana.com/api/1.0/users/me',+ headers: { Authorization: 'Bearer token' },+ }),+ );+ });++ it('ignores a token user that is not an object', async () => {+ mockUsersMe({ data: { email: '[email protected]' } });++ expect(await resolveIdentifier({ data: 'unexpected' })).toBe('[email protected]');+ });++ it('returns undefined instead of throwing when the API call fails', async () => {+ vi.spyOn(httpClient, 'sendRequest').mockRejectedValue(new Error('401 Unauthorized'));++ expect(await resolveIdentifier({})).toBeUndefined();+ });+});diff --git a/packages/pieces/community/asana/src/lib/auth.ts b/packages/pieces/community/asana/src/lib/auth.tsindex 4a86c44b4a7..9a86c7e3b9e 100644--- a/packages/pieces/community/asana/src/lib/auth.ts+++ b/packages/pieces/community/asana/src/lib/auth.ts@@ -1,4 +1,5 @@import { PieceAuth } from '@activepieces/pieces-framework';+import { httpClient, HttpMethod } from '@activepieces/pieces-common';export const asanaAuth = PieceAuth.OAuth2({description: '',@@ -6,4 +7,31 @@ export const asanaAuth = PieceAuth.OAuth2({tokenUrl: 'https://app.asana.com/-/oauth_token',required: true,scope: ['default'],+ getConnectionIdentifier: async ({ auth }) => {+ const fromToken = labelOf(auth.data['data']);+ if (fromToken) {+ return fromToken;+ }+ try {+ const response = await httpClient.sendRequest<{ data?: unknown }>({+ method: HttpMethod.GET,+ url: 'https://app.asana.com/api/1.0/users/me',+ queryParams: { opt_fields: 'email,name' },+ headers: { Authorization: `Bearer ${auth.access_token}` },+ timeout: 5000,+ });+ return labelOf(response.body.data);+ } catch {+ return undefined;+ }+ },});++function labelOf(user: unknown): string | undefined {+ if (typeof user !== 'object' || user === null) {+ return undefined;+ }+ const email = 'email' in user && typeof user.email === 'string' ? user.email : '';+ const name = 'name' in user && typeof user.name === 'string' ? user.name : '';+ return email || name || undefined;+}diff --git a/packages/pieces/community/asana/vitest.config.ts b/packages/pieces/community/asana/vitest.config.tsnew file mode 100644index 00000000000..ba8ade4a178--- /dev/null+++ b/packages/pieces/community/asana/vitest.config.ts@@ -0,0 +1,17 @@+import path from 'path'+import { defineConfig } from 'vitest/config'++const repoRoot = path.resolve(__dirname, '../../../..')++export default defineConfig({+ test: {+ globals: true,+ environment: 'node',+ },+ resolve: {+ alias: {+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),+ },+ },+})