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,31 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { pdfmonkeyAuth } from '../common/auth';
|
||||
import { makeRequest } from '../common/client';
|
||||
import { HttpMethod } from '@activepieces/pieces-common';
|
||||
import { documentIdDropdown } from '../common/props';
|
||||
|
||||
export const deleteDocumentAction = createAction({
|
||||
auth: pdfmonkeyAuth,
|
||||
name: 'deleteDocument',
|
||||
displayName: 'Delete Document',
|
||||
description: 'Deletes a document.',
|
||||
props: {
|
||||
document_id: documentIdDropdown,
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const { document_id } = propsValue;
|
||||
if (!document_id) {
|
||||
throw new Error('Document ID is required');
|
||||
}
|
||||
const response = await makeRequest(
|
||||
auth,
|
||||
HttpMethod.DELETE,
|
||||
`/documents/${document_id}`,
|
||||
);
|
||||
return {
|
||||
status: 'success',
|
||||
message: 'Document deleted successfully.',
|
||||
data: response,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { pdfmonkeyAuth } from '../common/auth';
|
||||
import { makeRequest } from '../common/client';
|
||||
import { HttpMethod } from '@activepieces/pieces-common';
|
||||
import { documentIdDropdown } from '../common/props';
|
||||
|
||||
export const findDocumentAction = createAction({
|
||||
auth: pdfmonkeyAuth,
|
||||
name: 'findDocument',
|
||||
displayName: 'Find Document',
|
||||
description: 'Finds a document by ID.',
|
||||
props: {
|
||||
document_id: documentIdDropdown,
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const { document_id } = propsValue;
|
||||
return await makeRequest(auth, HttpMethod.GET, `/documents/${document_id}`);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import { pdfmonkeyAuth } from '../common/auth';
|
||||
import { makeRequest } from '../common/client';
|
||||
import { HttpMethod } from '@activepieces/pieces-common';
|
||||
import { templateIdDropdown } from '../common/props';
|
||||
|
||||
export const generateDocumentAction = createAction({
|
||||
auth: pdfmonkeyAuth,
|
||||
name: 'generateDocument',
|
||||
displayName: 'Generate Document',
|
||||
description: 'Generates a new document using a specified template.',
|
||||
props: {
|
||||
document_template_id: templateIdDropdown,
|
||||
payload: Property.Json({
|
||||
displayName: 'Payload',
|
||||
description: 'Data to use for the Document generation.',
|
||||
required: true,
|
||||
}),
|
||||
meta: Property.Json({
|
||||
displayName: 'Meta',
|
||||
description: 'Meta-Data to attach to the Document.',
|
||||
required: false,
|
||||
}),
|
||||
fileName: Property.ShortText({
|
||||
displayName: 'Custom File Name',
|
||||
required: false,
|
||||
}),
|
||||
status: Property.StaticDropdown({
|
||||
displayName: 'Document Status',
|
||||
required: false,
|
||||
defaultValue: 'draft',
|
||||
options: {
|
||||
options: [
|
||||
{
|
||||
label: 'Draft',
|
||||
value: 'draft',
|
||||
},
|
||||
{
|
||||
label: 'Pending',
|
||||
value: 'pending',
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
},
|
||||
async run({ auth, propsValue }) {
|
||||
const { document_template_id, payload, meta, status, fileName } = propsValue;
|
||||
|
||||
const metapayload = { ...meta };
|
||||
|
||||
if (fileName) metapayload['_filename'] = fileName;
|
||||
|
||||
const body = {
|
||||
document: {
|
||||
document_template_id,
|
||||
status,
|
||||
payload,
|
||||
meta: metapayload,
|
||||
},
|
||||
};
|
||||
const response = await makeRequest(
|
||||
auth,
|
||||
HttpMethod.POST,
|
||||
'/documents',
|
||||
undefined,
|
||||
body,
|
||||
);
|
||||
return response;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { PieceAuth } from '@activepieces/pieces-framework';
|
||||
import { makeRequest } from './client';
|
||||
import { HttpMethod } from '@activepieces/pieces-common';
|
||||
import { AppConnectionType } from '@activepieces/shared';
|
||||
|
||||
export const pdfmonkeyAuth = PieceAuth.SecretText({
|
||||
displayName: 'API Key',
|
||||
description: `You can obtain your API key by navigating to [Account Settings](https://dashboard.pdfmonkey.io/account).`,
|
||||
required: true,
|
||||
validate: async ({ auth }) => {
|
||||
try {
|
||||
await makeRequest({
|
||||
type: AppConnectionType.SECRET_TEXT,
|
||||
secret_text: auth,
|
||||
}, HttpMethod.GET, '/documents', {});
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'Invalid API Key.',
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import { HttpMethod, QueryParams, httpClient } from '@activepieces/pieces-common';
|
||||
import { pdfmonkeyAuth } from './auth';
|
||||
import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
|
||||
|
||||
|
||||
export const BASE_URL = `https://api.pdfmonkey.io/api/v1`;
|
||||
|
||||
export async function makeRequest<T>(
|
||||
api_key: AppConnectionValueForAuthProperty<typeof pdfmonkeyAuth>,
|
||||
method: HttpMethod,
|
||||
path: string,
|
||||
query?:QueryParams,
|
||||
body?: unknown,
|
||||
) {
|
||||
try {
|
||||
|
||||
const response = await httpClient.sendRequest<T>({
|
||||
method,
|
||||
url: `${BASE_URL}${path}`,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${api_key.secret_text}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body,
|
||||
queryParams:query
|
||||
});
|
||||
return response.body;
|
||||
|
||||
} catch (error: any) {
|
||||
throw new Error(`Unexpected error: ${error.message || String(error)}`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import { DropdownOption, Property } from '@activepieces/pieces-framework';
|
||||
import { makeRequest } from './client';
|
||||
import { HttpMethod } from '@activepieces/pieces-common';
|
||||
import { pdfmonkeyAuth } from './auth';
|
||||
|
||||
export const templateIdDropdown = Property.Dropdown({
|
||||
displayName: 'Template ID',
|
||||
auth: pdfmonkeyAuth,
|
||||
required: true,
|
||||
refreshers: [],
|
||||
options: async ({ auth }) => {
|
||||
if (!auth) {
|
||||
return {
|
||||
disabled: true,
|
||||
options: [],
|
||||
placeholder: 'Please connect your account first.',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
let page = 1;
|
||||
let hasMore = true;
|
||||
|
||||
const options: DropdownOption<string>[] = [];
|
||||
|
||||
do {
|
||||
const response = await makeRequest<{
|
||||
document_template_cards: Array<{ id: string; identifier: string }>;
|
||||
meta: { total_pages: number; current_page: number };
|
||||
}>(auth, HttpMethod.GET, '/document_template_cards',{ page: page.toString() });
|
||||
|
||||
const items = response.document_template_cards ?? [];
|
||||
|
||||
for (const template of items) {
|
||||
options.push({ label: template.identifier, value: template.id });
|
||||
}
|
||||
|
||||
page++;
|
||||
hasMore = response.meta.current_page < response.meta.total_pages;
|
||||
} while (hasMore);
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
options,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
disabled: true,
|
||||
options: [],
|
||||
placeholder: 'Error loading document templates.',
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const documentIdDropdown = Property.Dropdown({
|
||||
displayName: 'Document ID',
|
||||
required: true,
|
||||
refreshers: [],
|
||||
auth: pdfmonkeyAuth,
|
||||
options: async ({ auth }) => {
|
||||
if (!auth) {
|
||||
return {
|
||||
disabled: true,
|
||||
options: [],
|
||||
placeholder: 'Please connect your account first.',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
let page = 1;
|
||||
let hasMore = true;
|
||||
|
||||
const options: DropdownOption<string>[] = [];
|
||||
|
||||
do {
|
||||
const response = await makeRequest<{
|
||||
document_cards: Array<{ id: string; filename: string }>;
|
||||
meta: { total_pages: number; current_page: number };
|
||||
}>(auth, HttpMethod.GET, '/document_cards', { page: page.toString() });
|
||||
|
||||
const items = response.document_cards ?? [];
|
||||
|
||||
for (const doc of items) {
|
||||
options.push({ label: doc.filename, value: doc.id });
|
||||
}
|
||||
page++;
|
||||
hasMore = response.meta.current_page < response.meta.total_pages;
|
||||
} while (hasMore);
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
options,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
disabled: true,
|
||||
options: [],
|
||||
placeholder: 'Error loading documents.',
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import {
|
||||
createTrigger,
|
||||
TriggerStrategy,
|
||||
PiecePropValueSchema,
|
||||
AppConnectionValueForAuthProperty,
|
||||
} from '@activepieces/pieces-framework';
|
||||
import {
|
||||
DedupeStrategy,
|
||||
HttpMethod,
|
||||
Polling,
|
||||
pollingHelper,
|
||||
QueryParams,
|
||||
} from '@activepieces/pieces-common';
|
||||
import dayjs from 'dayjs';
|
||||
import { pdfmonkeyAuth } from '../common/auth';
|
||||
import { makeRequest } from '../common/client';
|
||||
|
||||
const polling: Polling<AppConnectionValueForAuthProperty<typeof pdfmonkeyAuth>, Record<string, never>> = {
|
||||
strategy: DedupeStrategy.TIMEBASED,
|
||||
items: async ({ auth, lastFetchEpochMS }) => {
|
||||
let page = 1;
|
||||
let hasMore = true;
|
||||
const isTest = lastFetchEpochMS === 0;
|
||||
|
||||
const documents = [];
|
||||
|
||||
do {
|
||||
const qs: QueryParams = {
|
||||
'page[number]': page.toString(),
|
||||
'q[status]': 'success',
|
||||
};
|
||||
|
||||
if (!isTest) qs['q[updated_since]'] = lastFetchEpochMS.toString();
|
||||
|
||||
const response = await makeRequest<{
|
||||
document_cards: Array<{ id: string; created_at: string }>;
|
||||
meta: { total_pages: number; current_page: number };
|
||||
}>(auth, HttpMethod.GET, '/document_cards', qs);
|
||||
|
||||
const items = response.document_cards ?? [];
|
||||
|
||||
documents.push(...items);
|
||||
|
||||
if (isTest) break;
|
||||
|
||||
page++;
|
||||
hasMore = response.meta.current_page < response.meta.total_pages;
|
||||
} while (hasMore);
|
||||
|
||||
return documents.map((doc) => {
|
||||
return {
|
||||
epochMilliSeconds: dayjs(doc.created_at).valueOf(),
|
||||
data: doc,
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export const documentGeneratedTrigger = createTrigger({
|
||||
auth: pdfmonkeyAuth,
|
||||
name: 'documentGenerated',
|
||||
displayName: 'Document Generated',
|
||||
description: 'Triggers when a document generation completes successfully.',
|
||||
props: {},
|
||||
sampleData: {
|
||||
id: '11475e57-0334-4ad5-8896-9462a2243957',
|
||||
app_id: 'c2b67b84-4aac-49ea-bed8-69a15d7a65d3',
|
||||
created_at: '2022-04-07T11:01:38.201+02:00',
|
||||
document_template_id: '96611e9e-ab03-4ac3-8551-1b485210c892',
|
||||
document_template_identifier: 'My Awesome Template',
|
||||
download_url:
|
||||
'https://pdfmonkey.s3.eu-west-1.amazonaws.com/production/backend/document/11475e57-0334-4ad5-8896-9462a2243957/my-test-document.pdf?...',
|
||||
failure_cause: null,
|
||||
filename: 'my-test-document.pdf',
|
||||
meta: '{ "_filename":"my-test-document.pdf" }',
|
||||
public_share_link:
|
||||
'https://files.pdfmonkey.io/share/5CEA8C37-D130-4C19-9E11-72BE2293C82B/my-test-document.pdf',
|
||||
status: 'success',
|
||||
updated_at: '2022-04-03T11:12:56.023+02:00',
|
||||
},
|
||||
type: TriggerStrategy.POLLING,
|
||||
async test(context) {
|
||||
return await pollingHelper.test(polling, context);
|
||||
},
|
||||
async onEnable(context) {
|
||||
const { store, auth, propsValue } = context;
|
||||
await pollingHelper.onEnable(polling, { store, auth, propsValue });
|
||||
},
|
||||
|
||||
async onDisable(context) {
|
||||
const { store, auth, propsValue } = context;
|
||||
await pollingHelper.onDisable(polling, { store, auth, propsValue });
|
||||
},
|
||||
|
||||
async run(context) {
|
||||
return await pollingHelper.poll(polling, context);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user