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
import { BOTH_CLIENT_CREDENTIALS_AND_AUTHORIZATION_CODE, OAuth2GrantType } from '@activepieces/core-piece-types';
import * as z from "zod/mini";
import { ShortTextProperty } from '../input/text-property';
import { SecretTextProperty } from './secret-text-property';
import { BasePieceAuthSchema } from './common';
import { TPropertyValue } from '../input/common';
import { PropertyType } from '../input/property-type';
import { StaticDropdownProperty } from '../input/dropdown/static-dropdown';
import { StaticPropsValue } from '..';
export enum OAuth2AuthorizationMethod {
HEADER = 'HEADER',
BODY = 'BODY',
}
const OAuthProp = z.union([
ShortTextProperty,
SecretTextProperty,
StaticDropdownProperty,
])
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type OAuthProp =
| ShortTextProperty<boolean>
| SecretTextProperty<boolean>
| StaticDropdownProperty<any, boolean>;
export const OAuth2Props = z.record(z.string(), OAuthProp);
export type OAuth2Props = {
[key: string]: OAuthProp;
}
type OAuthPropsValue<T extends OAuth2Props> = StaticPropsValue<T>;
export const OAuth2Discovery = z.object({
serverUrlProp: z.string(),
authUrlProp: z.string(),
tokenUrlProp: z.string(),
scopesProp: z.optional(z.string()),
})
export type OAuth2Discovery = {
serverUrlProp: string
authUrlProp: string
tokenUrlProp: string
scopesProp?: string
}
const OAuth2ExtraProps = z.object({
props: z.optional(z.record(z.string(), OAuthProp)),
authUrl: z.string(),
tokenUrl: z.string(),
scope: z.array(z.string()),
prompt: z.optional(z.union([z.literal('none'), z.literal('consent'), z.literal('login'), z.literal('omit')])),
pkce: z.optional(z.boolean()),
pkceMethod: z.optional(z.union([z.literal('plain'), z.literal('S256')])),
authorizationMethod: z.optional(z.enum(OAuth2AuthorizationMethod)),
grantType: z.optional(z.union([z.enum(OAuth2GrantType), z.literal(BOTH_CLIENT_CREDENTIALS_AND_AUTHORIZATION_CODE)])),
extra: z.optional(z.record(z.string(), z.string())),
discovery: z.optional(OAuth2Discovery),
})
type OAuth2ExtraProps = {
props?: OAuth2Props
authUrl: string
tokenUrl: string
scope: string[]
prompt?: 'none' | 'consent' | 'login' | 'omit'
pkce?: boolean
pkceMethod?: 'plain' | 'S256'
authorizationMethod?: OAuth2AuthorizationMethod
grantType?: OAuth2GrantType | typeof BOTH_CLIENT_CREDENTIALS_AND_AUTHORIZATION_CODE
extra?: Record<string, string>,
discovery?: OAuth2Discovery
}
export const OAuth2PropertyValue = z.object({
access_token: z.string(),
props: z.optional(OAuth2Props),
data: z.record(z.string(), z.any())
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type OAuth2PropertyValue<T extends OAuth2Props = any> = {
access_token: string;
props?: OAuthPropsValue<T>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: Record<string, any>;
};
export const OAuth2Property = z.object({
...BasePieceAuthSchema.shape,
...OAuth2ExtraProps.shape,
...TPropertyValue(OAuth2PropertyValue, PropertyType.OAUTH2).shape,
})
export type OAuth2Property<
T extends OAuth2Props
> = BasePieceAuthSchema<OAuth2PropertyValue<T>> &
OAuth2ExtraProps &
TPropertyValue<
OAuth2PropertyValue<T>,
PropertyType.OAUTH2,
true
>;