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,58 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import { base44Auth } from '../..';
|
||||
import { createClient, Base44Error, type Base44Client } from '@base44/sdk';
|
||||
|
||||
export const createEntity = createAction({
|
||||
auth: base44Auth,
|
||||
name: 'create_entity',
|
||||
displayName: 'Create Entity',
|
||||
description: 'Creates an entity (record) in your Base44 app',
|
||||
props: {
|
||||
entityType: Property.ShortText({
|
||||
displayName: 'Entity Type',
|
||||
description: 'The name of the entity type (e.g. "Product", "User", "Order")',
|
||||
required: true,
|
||||
}),
|
||||
entityData: Property.Json({
|
||||
displayName: 'Entity Data',
|
||||
description: 'The data to create the entity with',
|
||||
required: true,
|
||||
defaultValue: {},
|
||||
}),
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const appId = auth.props.appId;
|
||||
const token = auth.props.token;
|
||||
const { entityType, entityData } = propsValue;
|
||||
|
||||
if (!appId) {
|
||||
throw new Error('App ID is required.');
|
||||
}
|
||||
|
||||
const base44: Base44Client = createClient({
|
||||
appId,
|
||||
token,
|
||||
serviceToken: token,
|
||||
});
|
||||
|
||||
try {
|
||||
const entitiesModule = token
|
||||
? base44.asServiceRole.entities as Record<string, { create: (data: Record<string, unknown>) => Promise<unknown> }>
|
||||
: base44.entities as Record<string, { create: (data: Record<string, unknown>) => Promise<unknown> }>;
|
||||
|
||||
const result = await entitiesModule[entityType].create(entityData as Record<string, unknown>);
|
||||
return result;
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Base44Error) {
|
||||
if (error.status === 404) {
|
||||
throw new Error(`Entity type "${entityType}" not found. Please check the name.`);
|
||||
}
|
||||
if (error.status === 401 || error.status === 403) {
|
||||
throw new Error('Authentication failed. Please check your credentials.');
|
||||
}
|
||||
throw new Error(`Failed to create entity: ${error.message}`);
|
||||
}
|
||||
throw new Error(`Failed to create entity: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import { base44Auth } from '../..';
|
||||
import { createClient, Base44Error, type Base44Client } from '@base44/sdk';
|
||||
|
||||
export const findEntity = createAction({
|
||||
auth: base44Auth,
|
||||
name: 'find_entity',
|
||||
displayName: 'Find Entity Record',
|
||||
description: 'Find a matching entity record in your Base44 app',
|
||||
props: {
|
||||
entityType: Property.ShortText({
|
||||
displayName: 'Entity Type',
|
||||
description: 'The name of the entity type (e.g. "Product", "User", "Order")',
|
||||
required: true,
|
||||
}),
|
||||
searchQuery: Property.Json({
|
||||
displayName: 'Search Query',
|
||||
description: 'Query to find the entity (e.g. {"email": "john@example.com"})',
|
||||
required: true,
|
||||
defaultValue: {},
|
||||
}),
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const appId = auth.props.appId;
|
||||
const token = auth.props.token;
|
||||
const { entityType, searchQuery } = propsValue;
|
||||
|
||||
if (!appId) {
|
||||
throw new Error('App ID is required.');
|
||||
}
|
||||
|
||||
const base44: Base44Client = createClient({
|
||||
appId,
|
||||
token,
|
||||
serviceToken: token,
|
||||
});
|
||||
|
||||
try {
|
||||
const entitiesModule = token
|
||||
? base44.asServiceRole.entities as Record<string, {
|
||||
filter: (query: Record<string, unknown>) => Promise<unknown[]>;
|
||||
}>
|
||||
: base44.entities as Record<string, {
|
||||
filter: (query: Record<string, unknown>) => Promise<unknown[]>;
|
||||
}>;
|
||||
|
||||
const results = await entitiesModule[entityType].filter(searchQuery as Record<string, unknown>);
|
||||
|
||||
return {
|
||||
found: Array.isArray(results) && results.length > 0,
|
||||
count: Array.isArray(results) ? results.length : 0,
|
||||
results: results,
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Base44Error) {
|
||||
if (error.status === 404) {
|
||||
throw new Error(`Entity type "${entityType}" not found. Please check the name.`);
|
||||
}
|
||||
if (error.status === 401 || error.status === 403) {
|
||||
throw new Error('Authentication failed. Please check your credentials.');
|
||||
}
|
||||
throw new Error(`Failed to find entity: ${error.message}`);
|
||||
}
|
||||
throw new Error(`Failed to find entity: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import { base44Auth } from '../..';
|
||||
import { createClient, Base44Error, type Base44Client } from '@base44/sdk';
|
||||
|
||||
export const findOrCreateEntity = createAction({
|
||||
auth: base44Auth,
|
||||
name: 'find_or_create_entity',
|
||||
displayName: 'Find or Create Entity',
|
||||
description: 'Find a matching entity record, or create one if not found',
|
||||
props: {
|
||||
entityType: Property.ShortText({
|
||||
displayName: 'Entity Type',
|
||||
description: 'The name of the entity type (e.g. "Product", "User", "Order")',
|
||||
required: true,
|
||||
}),
|
||||
searchQuery: Property.Json({
|
||||
displayName: 'Search Query',
|
||||
description: 'Query to find the entity (e.g. {"email": "john@example.com"})',
|
||||
required: true,
|
||||
defaultValue: {},
|
||||
}),
|
||||
createData: Property.Json({
|
||||
displayName: 'Create Data',
|
||||
description: 'Data to create the entity with if not found',
|
||||
required: true,
|
||||
defaultValue: {},
|
||||
}),
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const appId = auth.props.appId;
|
||||
const token = auth.props.token;
|
||||
const { entityType, searchQuery, createData } = propsValue;
|
||||
|
||||
if (!appId) {
|
||||
throw new Error('App ID is required.');
|
||||
}
|
||||
|
||||
const base44: Base44Client = createClient({
|
||||
appId,
|
||||
token,
|
||||
serviceToken: token,
|
||||
});
|
||||
|
||||
try {
|
||||
const entitiesModule = token
|
||||
? base44.asServiceRole.entities as Record<string, {
|
||||
filter: (query: Record<string, unknown>) => Promise<unknown[]>;
|
||||
create: (data: Record<string, unknown>) => Promise<unknown>;
|
||||
}>
|
||||
: base44.entities as Record<string, {
|
||||
filter: (query: Record<string, unknown>) => Promise<unknown[]>;
|
||||
create: (data: Record<string, unknown>) => Promise<unknown>;
|
||||
}>;
|
||||
|
||||
const results = await entitiesModule[entityType].filter(searchQuery as Record<string, unknown>);
|
||||
|
||||
if (Array.isArray(results) && results.length > 0) {
|
||||
return {
|
||||
found: true,
|
||||
created: false,
|
||||
entity: results[0],
|
||||
};
|
||||
}
|
||||
|
||||
const newEntity = await entitiesModule[entityType].create(createData as Record<string, unknown>);
|
||||
|
||||
return {
|
||||
found: false,
|
||||
created: true,
|
||||
entity: newEntity,
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Base44Error) {
|
||||
if (error.status === 404) {
|
||||
throw new Error(`Entity type "${entityType}" not found. Please check the name.`);
|
||||
}
|
||||
if (error.status === 401 || error.status === 403) {
|
||||
throw new Error('Authentication failed. Please check your credentials.');
|
||||
}
|
||||
throw new Error(`Failed: ${error.message}`);
|
||||
}
|
||||
throw new Error(`Failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
import {
|
||||
createTrigger,
|
||||
TriggerStrategy,
|
||||
Property,
|
||||
AppConnectionValueForAuthProperty,
|
||||
} from '@activepieces/pieces-framework';
|
||||
import {
|
||||
DedupeStrategy,
|
||||
pollingHelper,
|
||||
Polling,
|
||||
} from '@activepieces/pieces-common';
|
||||
import { base44Auth } from '../..';
|
||||
import { createClient, Base44Error, type Base44Client } from '@base44/sdk';
|
||||
|
||||
type Base44AuthType = AppConnectionValueForAuthProperty<typeof base44Auth>;
|
||||
|
||||
const polling: Polling<Base44AuthType, { entityType: string; eventType: string }> = {
|
||||
strategy: DedupeStrategy.TIMEBASED,
|
||||
items: async ({ auth, propsValue, lastFetchEpochMS }) => {
|
||||
const appId = auth.props.appId;
|
||||
const token = auth.props.token;
|
||||
const { entityType, eventType } = propsValue;
|
||||
|
||||
const base44: Base44Client = createClient({
|
||||
appId,
|
||||
token,
|
||||
serviceToken: token,
|
||||
});
|
||||
|
||||
try {
|
||||
const entitiesModule = token
|
||||
? base44.asServiceRole.entities as Record<string, {
|
||||
list: (sort?: string, limit?: number, skip?: number) => Promise<unknown[]>;
|
||||
}>
|
||||
: base44.entities as Record<string, {
|
||||
list: (sort?: string, limit?: number, skip?: number) => Promise<unknown[]>;
|
||||
}>;
|
||||
|
||||
const sortField = eventType === 'created' ? '-created_date' : '-updated_date';
|
||||
const results = await entitiesModule[entityType].list(sortField, 100);
|
||||
|
||||
if (!Array.isArray(results)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return results
|
||||
.filter((item: any) => {
|
||||
const timestamp = eventType === 'created'
|
||||
? new Date(item.created_date).getTime()
|
||||
: new Date(item.updated_date).getTime();
|
||||
return timestamp > lastFetchEpochMS;
|
||||
})
|
||||
.map((item: any) => {
|
||||
const timestamp = eventType === 'created'
|
||||
? new Date(item.created_date).getTime()
|
||||
: new Date(item.updated_date).getTime();
|
||||
return {
|
||||
epochMilliSeconds: timestamp,
|
||||
data: {
|
||||
...item,
|
||||
_eventType: eventType,
|
||||
_entityType: entityType,
|
||||
},
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Base44Error) {
|
||||
console.error(`Base44 Error: ${error.message}`);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const entityEvent = createTrigger({
|
||||
auth: base44Auth,
|
||||
name: 'entity_event',
|
||||
displayName: 'Entity Event',
|
||||
description: 'Triggers when an entity is created or updated',
|
||||
props: {
|
||||
entityType: Property.ShortText({
|
||||
displayName: 'Entity Type',
|
||||
description: 'The name of the entity type (e.g. "Product", "User", "Order")',
|
||||
required: true,
|
||||
}),
|
||||
eventType: Property.StaticDropdown({
|
||||
displayName: 'Event Type',
|
||||
description: 'When to trigger',
|
||||
required: true,
|
||||
defaultValue: 'created',
|
||||
options: {
|
||||
disabled: false,
|
||||
options: [
|
||||
{ label: 'Created', value: 'created' },
|
||||
{ label: 'Updated', value: 'updated' },
|
||||
],
|
||||
},
|
||||
}),
|
||||
},
|
||||
sampleData: {
|
||||
id: 'sample-entity-id',
|
||||
created_date: '2024-01-01T00:00:00.000Z',
|
||||
updated_date: '2024-01-01T00:00:00.000Z',
|
||||
_eventType: 'created',
|
||||
_entityType: 'Product',
|
||||
},
|
||||
type: TriggerStrategy.POLLING,
|
||||
async test(ctx) {
|
||||
return await pollingHelper.test(polling, {
|
||||
auth: ctx.auth,
|
||||
store: ctx.store,
|
||||
propsValue: ctx.propsValue,
|
||||
files: ctx.files,
|
||||
});
|
||||
},
|
||||
async onEnable(ctx) {
|
||||
await pollingHelper.onEnable(polling, {
|
||||
auth: ctx.auth,
|
||||
store: ctx.store,
|
||||
propsValue: ctx.propsValue,
|
||||
});
|
||||
},
|
||||
async onDisable(ctx) {
|
||||
await pollingHelper.onDisable(polling, {
|
||||
auth: ctx.auth,
|
||||
store: ctx.store,
|
||||
propsValue: ctx.propsValue,
|
||||
});
|
||||
},
|
||||
async run(ctx) {
|
||||
return await pollingHelper.poll(polling, {
|
||||
auth: ctx.auth,
|
||||
store: ctx.store,
|
||||
propsValue: ctx.propsValue,
|
||||
files: ctx.files,
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user