Add Activepieces integration for workflow automation
- Add Activepieces fork with SmoothSchedule custom piece - Create integrations app with Activepieces service layer - Add embed token endpoint for iframe integration - Create Automations page with embedded workflow builder - Add sidebar visibility fix for embed mode - Add list inactive customers endpoint to Public API - Include SmoothSchedule triggers: event created/updated/cancelled - Include SmoothSchedule actions: create/update/cancel events, list resources/services/customers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import { Property, createAction } from '@activepieces/pieces-framework';
|
||||
import { createDiscount } from '../api';
|
||||
import { CartloomAuthType, cartloomAuth } from '../auth';
|
||||
import { buildProductsDropdown } from '../props';
|
||||
|
||||
export const createDiscountAction = createAction({
|
||||
name: 'create_discount',
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Create Discount',
|
||||
description: 'Create a discount in Cartloom',
|
||||
props: {
|
||||
title: Property.ShortText({
|
||||
displayName: 'Title',
|
||||
description: 'Enter the title of the discount',
|
||||
required: true,
|
||||
}),
|
||||
enabled: Property.Checkbox({
|
||||
displayName: 'Enabled',
|
||||
description: 'Is this discount enabled?',
|
||||
required: true,
|
||||
defaultValue: false,
|
||||
}),
|
||||
auto: Property.Checkbox({
|
||||
displayName: 'Auto',
|
||||
description: 'Is this discount automatically applied?',
|
||||
required: true,
|
||||
defaultValue: false,
|
||||
}),
|
||||
unlimited: Property.Checkbox({
|
||||
displayName: 'Unlimited',
|
||||
description: 'Is this discount unlimited?',
|
||||
required: true,
|
||||
defaultValue: false,
|
||||
}),
|
||||
selfDestruct: Property.Checkbox({
|
||||
displayName: 'Self Destruct',
|
||||
description: 'Remove the discount after use',
|
||||
required: true,
|
||||
defaultValue: false,
|
||||
}),
|
||||
applyOnce: Property.Checkbox({
|
||||
displayName: 'Apply Once',
|
||||
description: 'Apply the discount once per order',
|
||||
required: true,
|
||||
defaultValue: false,
|
||||
}),
|
||||
type: Property.StaticDropdown({
|
||||
displayName: 'Type of Discount',
|
||||
description: 'Select the type of discount',
|
||||
defaultValue: 'fixed',
|
||||
required: true,
|
||||
options: {
|
||||
options: [
|
||||
{ label: 'Fixed Amount', value: 'fixed' },
|
||||
{ label: 'Percentage', value: 'percent' },
|
||||
],
|
||||
},
|
||||
}),
|
||||
amount: Property.Number({
|
||||
displayName: 'Amount',
|
||||
description: 'Enter the amount of the discount',
|
||||
required: true,
|
||||
defaultValue: 0,
|
||||
}),
|
||||
target: Property.StaticDropdown({
|
||||
displayName: 'Discount Target',
|
||||
description: 'Select the target of the discount',
|
||||
defaultValue: 'all',
|
||||
required: true,
|
||||
options: {
|
||||
options: [
|
||||
{ label: 'Selected Products', value: 'product' },
|
||||
{ label: 'Total', value: 'total' },
|
||||
{ label: 'All Products', value: 'all' },
|
||||
],
|
||||
},
|
||||
}),
|
||||
startDate: Property.DateTime({
|
||||
displayName: 'Start Date',
|
||||
description: 'The start date of the discount. YYYY-MM-DD HH:MM:SS',
|
||||
required: true,
|
||||
}),
|
||||
stopDate: Property.DateTime({
|
||||
displayName: 'Stop Date',
|
||||
description: 'The stop date of the discount. YYYY-MM-DD HH:MM:SS',
|
||||
required: true,
|
||||
}),
|
||||
optional: Property.MarkDown({
|
||||
value: '## Optional Settings based on above settings',
|
||||
}),
|
||||
code: Property.ShortText({
|
||||
displayName: 'Discount Code',
|
||||
description: 'Enter the discount code. Leave blank for no code.',
|
||||
required: false,
|
||||
}),
|
||||
targetPids: Property.MultiSelectDropdown({
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Target Products',
|
||||
description: 'Select the products to apply the discount to',
|
||||
required: false,
|
||||
refreshers: [],
|
||||
options: async ({ auth }) =>
|
||||
{ if(!auth)
|
||||
{
|
||||
return {
|
||||
options: [],
|
||||
disabled:true,
|
||||
placeholder:"please authenticate"
|
||||
}
|
||||
}
|
||||
return await buildProductsDropdown(auth.props)},
|
||||
}),
|
||||
targetAmount: Property.Number({
|
||||
displayName: 'Target Amount',
|
||||
description:
|
||||
'The target amount for the discount when the target is set to Total',
|
||||
required: false,
|
||||
}),
|
||||
targetQuantity: Property.Number({
|
||||
displayName: 'Target Quantity',
|
||||
description:
|
||||
'The target quantity for the discount when the target is set to All or Products',
|
||||
required: false,
|
||||
defaultValue: 0,
|
||||
}),
|
||||
allowance: Property.Number({
|
||||
displayName: 'Allowance',
|
||||
description: 'The number of times the discount can be used',
|
||||
required: false,
|
||||
}),
|
||||
},
|
||||
async run(context) {
|
||||
return await createDiscount(context.auth.props, {
|
||||
enabled: context.propsValue.enabled ? 1 : 0,
|
||||
auto: context.propsValue.auto ? 1 : 0,
|
||||
unlimited: context.propsValue.unlimited ? 1 : 0,
|
||||
self_destruct: context.propsValue.selfDestruct ? 1 : 0,
|
||||
apply_once: context.propsValue.applyOnce ? 1 : 0,
|
||||
title: context.propsValue.title,
|
||||
type: context.propsValue.type,
|
||||
amount: context.propsValue.amount,
|
||||
target: context.propsValue.target,
|
||||
start_date: context.propsValue.startDate.split('T')[0],
|
||||
stop_date: context.propsValue.stopDate.split('T')[0],
|
||||
code: context.propsValue.code,
|
||||
target_pid: context.propsValue.targetPids?.join(','),
|
||||
target_amount: context.propsValue.targetAmount,
|
||||
target_quantity: context.propsValue.targetQuantity,
|
||||
allowance: context.propsValue.allowance,
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Property, createAction } from '@activepieces/pieces-framework';
|
||||
import { getDiscount } from '../api';
|
||||
import { cartloomAuth } from '../auth';
|
||||
|
||||
export const getDiscountAction = createAction({
|
||||
name: 'get_discount',
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Get Discount',
|
||||
description: 'Get discount info from Cartloom',
|
||||
props: {
|
||||
discountId: Property.ShortText({
|
||||
displayName: 'Discount ID',
|
||||
description: 'Enter the ID of the discount you want to retrieve',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
async run(context) {
|
||||
return await getDiscount(context.auth.props, context.propsValue.discountId);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { getAllDiscounts } from '../api';
|
||||
import { cartloomAuth } from '../auth';
|
||||
|
||||
export const getAllDiscountsAction = createAction({
|
||||
name: 'get_all_discounts',
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Get All Discounts',
|
||||
description: 'Get a list of discounts from Cartloom',
|
||||
props: {},
|
||||
async run(context) {
|
||||
return await getAllDiscounts(context.auth.props);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Property, createAction } from '@activepieces/pieces-framework';
|
||||
import { getOrder } from '../api';
|
||||
import { cartloomAuth } from '../auth';
|
||||
|
||||
export const getOrderAction = createAction({
|
||||
name: 'get_order',
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Get Order',
|
||||
description: 'Get an order from Cartloom',
|
||||
props: {
|
||||
invoice: Property.ShortText({
|
||||
displayName: 'Invoice ID',
|
||||
description: 'The invoice ID for the order you want to retrieve',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
async run(context) {
|
||||
return await getOrder(context.auth.props, context.propsValue.invoice);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Property, createAction } from '@activepieces/pieces-framework';
|
||||
import { getOrdersByDate } from '../api';
|
||||
import { cartloomAuth } from '../auth';
|
||||
|
||||
export const getOrderEmailAction = createAction({
|
||||
name: 'get_orders_by_email',
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Get Order by Email',
|
||||
description: 'Get a list of orders for an email within a date range',
|
||||
props: {
|
||||
start: Property.DateTime({
|
||||
displayName: 'Start Date',
|
||||
description: 'Select a date to start the search',
|
||||
required: true,
|
||||
}),
|
||||
end: Property.DateTime({
|
||||
displayName: 'End Date',
|
||||
description: 'Select a date to end the search. Defaults to today.',
|
||||
required: false,
|
||||
}),
|
||||
email: Property.ShortText({
|
||||
displayName: 'Email',
|
||||
description: 'Email address to search for.',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
async run(context) {
|
||||
return await getOrdersByDate(context.auth.props, {
|
||||
search_type: 'email',
|
||||
keyword: context.propsValue.email,
|
||||
start_date: context.propsValue.start.split('T')[0],
|
||||
end_date:
|
||||
context.propsValue.end || new Date().toISOString().split('T')[0],
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Property, createAction } from '@activepieces/pieces-framework';
|
||||
import { getOrdersByDate } from '../api';
|
||||
import { cartloomAuth } from '../auth';
|
||||
|
||||
export const getOrderDateAction = createAction({
|
||||
name: 'get_orders_by_date',
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Get Order by Date',
|
||||
description: 'Get a list of orders from Cartloom within a date range',
|
||||
props: {
|
||||
start: Property.DateTime({
|
||||
displayName: 'Start Date',
|
||||
description: 'Select a date to start the search',
|
||||
required: true,
|
||||
}),
|
||||
end: Property.DateTime({
|
||||
displayName: 'End Date',
|
||||
description: 'Select a date to end the search. Defaults to today.',
|
||||
required: false,
|
||||
}),
|
||||
},
|
||||
async run(context) {
|
||||
return await getOrdersByDate(context.auth.props, {
|
||||
start_date: context.propsValue.start.split('T')[0],
|
||||
end_date:
|
||||
context.propsValue.end || new Date().toISOString().split('T')[0],
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { getProducts } from '../api';
|
||||
import { cartloomAuth } from '../auth';
|
||||
|
||||
export const getProductsAction = createAction({
|
||||
name: 'get_products',
|
||||
auth: cartloomAuth,
|
||||
displayName: 'Get Products',
|
||||
description: 'Get a list of products from Cartloom',
|
||||
props: {},
|
||||
async run(context) {
|
||||
return await getProducts(context.auth.props);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
httpClient,
|
||||
HttpMethod,
|
||||
HttpRequest,
|
||||
} from '@activepieces/pieces-common';
|
||||
import { CartloomAuthType } from './auth';
|
||||
|
||||
type KeyValuePair = { [key: string]: string | boolean | number | undefined };
|
||||
|
||||
const cartloomAPI = async (
|
||||
api: string,
|
||||
auth: CartloomAuthType,
|
||||
body: KeyValuePair = {}
|
||||
) => {
|
||||
const request: HttpRequest = {
|
||||
method: HttpMethod.POST,
|
||||
url: `https://${auth.domain}.cartloom.com/api${api}`,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-API-KEY': auth.apiKey,
|
||||
},
|
||||
body: body,
|
||||
};
|
||||
const response = await httpClient.sendRequest(request);
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Cartloom API Error: ${response.status} ${response.body}`);
|
||||
}
|
||||
|
||||
let data = Object.keys(response.body).map((key) => response.body[key]);
|
||||
|
||||
const arrayTest = response.body['0'];
|
||||
if (typeof arrayTest === 'undefined') {
|
||||
// when response is an object, it is wrapped in an array
|
||||
data = [response.body];
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: data,
|
||||
};
|
||||
};
|
||||
|
||||
export async function getProducts(auth: CartloomAuthType) {
|
||||
return cartloomAPI('/products/list', auth);
|
||||
}
|
||||
|
||||
export async function getAllDiscounts(auth: CartloomAuthType) {
|
||||
return cartloomAPI('/discounts/list', auth);
|
||||
}
|
||||
|
||||
export async function getDiscount(auth: CartloomAuthType, discountId: string) {
|
||||
return cartloomAPI('/discounts/get', auth, { id: discountId });
|
||||
}
|
||||
|
||||
export async function getOrder(auth: CartloomAuthType, invoice: string) {
|
||||
return cartloomAPI('/orders/get', auth, { invoice: invoice });
|
||||
}
|
||||
|
||||
export async function getOrdersByDate(
|
||||
auth: CartloomAuthType,
|
||||
data: KeyValuePair
|
||||
) {
|
||||
return cartloomAPI('/orders/list', auth, data);
|
||||
}
|
||||
|
||||
export async function createDiscount(
|
||||
auth: CartloomAuthType,
|
||||
data: KeyValuePair
|
||||
) {
|
||||
return cartloomAPI('/discounts/add', auth, data);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
PieceAuth,
|
||||
Property,
|
||||
} from '@activepieces/pieces-framework';
|
||||
import { getProducts } from './api';
|
||||
|
||||
export type CartloomAuthType = { apiKey: string; domain: string };
|
||||
|
||||
export const cartloomAuth = PieceAuth.CustomAuth({
|
||||
description: 'Cartloom Authentication',
|
||||
props: {
|
||||
domain: Property.ShortText({
|
||||
displayName: 'Cartloom Domain',
|
||||
description:
|
||||
'Your cartloom domain will be the subdomain part of your Cartloom URL. Example: https://<strong>mycompany</strong>.cartloom.com',
|
||||
required: true,
|
||||
}),
|
||||
apiKey: PieceAuth.SecretText({
|
||||
displayName: 'API Key',
|
||||
description: 'The API key for your Cartloom account',
|
||||
required: true
|
||||
}),
|
||||
},
|
||||
validate: async ({ auth }) => {
|
||||
try {
|
||||
await validateAuth(auth);
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
valid: false,
|
||||
error: (e as Error)?.message,
|
||||
};
|
||||
}
|
||||
},
|
||||
required: true,
|
||||
});
|
||||
|
||||
const validateAuth = async (auth: CartloomAuthType) => {
|
||||
const response = await getProducts(auth);
|
||||
if (response.success !== true) {
|
||||
throw new Error(
|
||||
'Authentication failed. Please check your domain and API key and try again.'
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { CartloomAuthType } from './auth';
|
||||
import { getProducts } from './api';
|
||||
|
||||
export async function buildProductsDropdown(auth: CartloomAuthType) {
|
||||
if (!auth) {
|
||||
return {
|
||||
options: [],
|
||||
disabled: true,
|
||||
placeholder: 'Please authenticate first',
|
||||
};
|
||||
}
|
||||
const response = await getProducts(auth);
|
||||
const options = response.data.map((product) => {
|
||||
return { label: product.name, value: product.pid };
|
||||
});
|
||||
return {
|
||||
options: options,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user