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.6 KB
Raw Blame
import { PieceAuth, Property } from '@activepieces/pieces-framework';

const authDescription = `
To generate your API credentials, follow the steps below:
1. Go to WooCommerce -> Settings -> Advanced tab -> REST API.
2. Click on Add Key to create a new key.
3. Enter the key description and change the permissions to Read/Write.
4. Click Generate Key.
5. Copy the Consumer Key and Consumer Secret into the fields below. You will not be able to view the Consumer Secret after exiting the page.

Note that the base URL of your WooCommerce instance needs to be on a secure (HTTPS) connection, or the piece will not work even on local instances on the same device.
`;

export const wooAuth = PieceAuth.CustomAuth({
  description: authDescription,
  required: true,
  props: {
    baseUrl: Property.ShortText({
      displayName: 'Base URL',
      description: "Your store's address. It must start with https://.",
      placeholder: 'https://mystore.com',
      required: true,
    }),
    consumerKey: Property.ShortText({
      displayName: 'Consumer Key',
      description:
        'Starts with ck_. Created under Settings > Advanced > REST API.',
      placeholder: 'ck_...',
      required: true,
    }),
    consumerSecret: PieceAuth.SecretText({
      displayName: 'Consumer Secret',
      description: 'Starts with cs_. WooCommerce shows it only once.',
      required: true,
    }),
  },
  async validate({ auth }) {
    const baseUrl = auth.baseUrl;
    if (!baseUrl.match(/^(https):\/\//)) {
      return {
        valid: false,
        error: 'Base URL must start with https (e.g https://mystore.com)',
      };
    }
    return { valid: true };
  },
});