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

2.5 KB
Raw Blame
import {
  PieceAuth,
  createPiece,
  Property,
  PiecePropValueSchema,
} from '@activepieces/pieces-framework';
import { getVendor } from './lib/actions/get-vendor';
import { getCustomer } from './lib/actions/get-customer';
import { runSuiteQL } from './lib/actions/run-suiteql';
import { executeDataset } from './lib/actions/execute-dataset';
import { PieceCategory } from '@activepieces/pieces-framework';
import { createCustomApiCallAction } from '@activepieces/pieces-common';
import { createOAuthHeader } from './lib/common/oauth';

export const netsuiteAuth = PieceAuth.CustomAuth({
  required: true,
  props: {
    accountId: Property.ShortText({
      displayName: 'Account ID',
      required: true,
      description: 'Your NetSuite account ID',
    }),
    consumerKey: Property.ShortText({
      displayName: 'Consumer Key',
      required: true,
      description: 'Your NetSuite consumer key',
    }),
    consumerSecret: PieceAuth.SecretText({
      displayName: 'Consumer Secret',
      required: true,
      description: 'Your NetSuite consumer secret',
    }),
    tokenId: Property.ShortText({
      displayName: 'Token ID',
      required: true,
      description: 'Your NetSuite token ID',
    }),
    tokenSecret: PieceAuth.SecretText({
      displayName: 'Token Secret',
      required: true,
      description: 'Your NetSuite token secret',
    }),
  },
});

export const netsuite = createPiece({
  displayName: 'NetSuite',
  logoUrl: 'https://cdn.activepieces.com/pieces/netsuite.png',
  categories: [PieceCategory.ACCOUNTING],
  auth: netsuiteAuth,
  authors: ['geekyme', 'danielpoonwj'],
  actions: [
    getVendor,
    getCustomer,
    runSuiteQL,
    executeDataset,
    createCustomApiCallAction({
      baseUrl: (auth) => {
        if (!auth) {
          return '';
        }
        const authValue = auth.props;
        return `https://${authValue.accountId}.suitetalk.api.netsuite.com`;
      },
      auth: netsuiteAuth,
      authMapping: async (auth, propsValue) => {
        const authValue = auth.props;

        const authHeader = createOAuthHeader(
          authValue.accountId,
          authValue.consumerKey,
          authValue.consumerSecret,
          authValue.tokenId,
          authValue.tokenSecret,
          propsValue['url']['url'],
          propsValue['method'],
          propsValue['queryParams']
        );

        return {
          Authorization: authHeader,
          prefer: 'transient',
          Cookie: 'NS_ROUTING_VERSION=LAGGING',
        };
      },
    }),
  ],
  triggers: [],
});