Skip to content

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

1.8 KB
Raw Blame
import {
  AppConnectionValueForAuthProperty,
  PieceAuth,
  Property,
} from '@activepieces/pieces-framework';
import { sendJiraRequest } from './lib/common';
import { HttpError, HttpMethod } from '@activepieces/pieces-common';
import * as z from 'zod/mini'
import { propsValidation } from '@activepieces/pieces-common';
import { AppConnectionType } from '@activepieces/pieces-framework';

export const jiraCloudAuth = PieceAuth.CustomAuth({
  description: `
You can generate your API token from:
***https://id.atlassian.com/manage-profile/security/api-tokens***
    `,
  required: true,
  props: {
    instanceUrl: Property.ShortText({
      displayName: 'Instance URL',
      description:
        'The link of your Jira instance (e.g https://example.atlassian.net)',
      required: true,
    }),
    email: Property.ShortText({
      displayName: 'Email',
      description: 'The email you use to login to Jira',
      required: true,
    }),
    apiToken: PieceAuth.SecretText({
      displayName: 'API Token',
      description: 'Your Jira API Token',
      required: true,
    }),
  },
  validate: async ({ auth }) => {
    try {
      await propsValidation.validateZod(auth, {
        instanceUrl: z.string().check(z.url()),
        email: z.string().check(z.email()),
      });

      await sendJiraRequest({
        auth: {
          type: AppConnectionType.CUSTOM_AUTH,
          props: auth,
        },
        method: HttpMethod.GET,
        url: 'myself',
      });
      return {
        valid: true,
      };
    } catch (e) {
      const message = ((e as HttpError).response?.body as any)?.message;
      return {
        valid: false,
        error: message ?? 'Invalid credentials',
      };
    }
  },
});

export type JiraAuth = AppConnectionValueForAuthProperty<typeof jiraCloudAuth>;