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,67 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import {
|
||||
httpClient,
|
||||
HttpMethod,
|
||||
AuthenticationType,
|
||||
} from '@activepieces/pieces-common';
|
||||
import { oneDriveAuth } from '../../';
|
||||
import { oneDriveCommon } from '../common/common';
|
||||
|
||||
export const downloadFile = createAction({
|
||||
auth: oneDriveAuth,
|
||||
name: 'download_file',
|
||||
description: 'Download a file from your Microsoft OneDrive',
|
||||
displayName: 'Download file',
|
||||
props: {
|
||||
fileId: Property.ShortText({
|
||||
displayName: 'File ID',
|
||||
description: 'The ID of the file to download',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
async run(context) {
|
||||
const fileId = context.propsValue.fileId;
|
||||
|
||||
const fileDetails = await httpClient.sendRequest<{name:string}>({
|
||||
method:HttpMethod.GET,
|
||||
url:`${oneDriveCommon.baseUrl}/items/${fileId}?$select=name`,
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: context.auth.access_token,
|
||||
},
|
||||
})
|
||||
|
||||
const result = await httpClient.sendRequest({
|
||||
method: HttpMethod.GET,
|
||||
url: `${oneDriveCommon.baseUrl}/items/${fileId}/content`,
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: context.auth.access_token,
|
||||
},
|
||||
responseType:'arraybuffer'
|
||||
});
|
||||
|
||||
const desiredHeaders = [
|
||||
'content-length',
|
||||
'content-type',
|
||||
'content-location',
|
||||
'expires',
|
||||
];
|
||||
const filteredHeaders: any = {};
|
||||
|
||||
if (result.headers) {
|
||||
for (const key of desiredHeaders) {
|
||||
filteredHeaders[key] = result.headers[key];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...filteredHeaders,
|
||||
data:await context.files.write({
|
||||
fileName: fileDetails.body.name,
|
||||
data: Buffer.from(result.body),
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { createAction } from '@activepieces/pieces-framework';
|
||||
import { oneDriveAuth } from '../../';
|
||||
import { oneDriveCommon } from '../common/common';
|
||||
import { Client, PageCollection } from '@microsoft/microsoft-graph-client';
|
||||
import { DriveItem } from '@microsoft/microsoft-graph-types';
|
||||
|
||||
export const listFiles = createAction({
|
||||
auth: oneDriveAuth,
|
||||
name: 'list_files',
|
||||
description: 'List files in a OneDrive folder',
|
||||
displayName: 'List Files',
|
||||
props: {
|
||||
markdown:oneDriveCommon.parentFolderInfo,
|
||||
parentFolder: oneDriveCommon.parentFolder,
|
||||
},
|
||||
async run(context) {
|
||||
const endpoint = context.propsValue.parentFolder
|
||||
? `/me/drive/items/${context.propsValue.parentFolder}/children`
|
||||
: `/me/drive/items/root/children`;
|
||||
|
||||
const files = [];
|
||||
|
||||
const client = Client.initWithMiddleware({
|
||||
authProvider: {
|
||||
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
||||
},
|
||||
});
|
||||
let response: PageCollection = await client.api(endpoint).get();
|
||||
|
||||
while (response.value.length > 0) {
|
||||
for (const item of response.value as DriveItem[]) {
|
||||
if (item.file) {
|
||||
files.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (response['@odata.nextLink']) {
|
||||
response = await client.api(response['@odata.nextLink']).get();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import {
|
||||
httpClient,
|
||||
HttpMethod,
|
||||
AuthenticationType,
|
||||
} from '@activepieces/pieces-common';
|
||||
import { oneDriveAuth } from '../../';
|
||||
import { oneDriveCommon } from '../common/common';
|
||||
|
||||
export const listFolders = createAction({
|
||||
auth: oneDriveAuth,
|
||||
name: 'list_folders',
|
||||
description: 'List folders in a OneDrive folder',
|
||||
displayName: 'List Folders',
|
||||
props: {
|
||||
markdown:oneDriveCommon.parentFolderInfo,
|
||||
parentFolder: oneDriveCommon.parentFolder,
|
||||
},
|
||||
async run(context) {
|
||||
const parentId = context.propsValue.parentFolder ?? 'root';
|
||||
|
||||
const result = await httpClient.sendRequest({
|
||||
method: HttpMethod.GET,
|
||||
url: `${oneDriveCommon.baseUrl}/items/${parentId}/children?$filter=folder ne null`,
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: context.auth.access_token,
|
||||
},
|
||||
});
|
||||
|
||||
return result.body['value'];
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
import { createAction, Property } from '@activepieces/pieces-framework';
|
||||
import {
|
||||
httpClient,
|
||||
HttpMethod,
|
||||
AuthenticationType,
|
||||
} from '@activepieces/pieces-common';
|
||||
import { oneDriveAuth } from '../../';
|
||||
import mime from 'mime-types';
|
||||
import { oneDriveCommon } from '../common/common';
|
||||
|
||||
const CHUNK_SIZE = 10485760; // Use 10MiB per chunk
|
||||
|
||||
export const uploadFile = createAction({
|
||||
auth: oneDriveAuth,
|
||||
name: 'upload_onedrive_file',
|
||||
description: 'Upload a file to your Microsoft OneDrive with chunked upload if the file is larger than 4MiB',
|
||||
displayName: 'Upload file',
|
||||
props: {
|
||||
fileName: Property.ShortText({
|
||||
displayName: 'File name',
|
||||
description: 'The name the file should be saved as (e.g. file.txt)',
|
||||
required: true,
|
||||
}),
|
||||
file: Property.File({
|
||||
displayName: 'File',
|
||||
description: 'The file URL or base64 to upload',
|
||||
required: true,
|
||||
}),
|
||||
markdown:oneDriveCommon.parentFolderInfo,
|
||||
parentId: oneDriveCommon.parentFolder,
|
||||
},
|
||||
async run(context) {
|
||||
const fileData = context.propsValue.file;
|
||||
const mimeTypeLookup = mime.lookup(
|
||||
fileData.extension ? fileData.extension : ''
|
||||
);
|
||||
const mimeType = mimeTypeLookup
|
||||
? mimeTypeLookup
|
||||
: 'application/octet-stream'; // Fallback to a default MIME type
|
||||
const encodedFilename = encodeURIComponent(context.propsValue.fileName);
|
||||
const parentId = context.propsValue.parentId ?? 'root';
|
||||
|
||||
if (fileData.data.length <= 4 * 1024 * 1024) {
|
||||
// If file is smaller than 4MiB, use simple upload
|
||||
const base64Data = Buffer.from(fileData.base64, 'base64');
|
||||
const result = await httpClient.sendRequest({
|
||||
method: HttpMethod.PUT,
|
||||
url: `${oneDriveCommon.baseUrl}/items/${parentId}:/${encodedFilename}:/content`,
|
||||
body: base64Data,
|
||||
headers: {
|
||||
'Content-Type': mimeType,
|
||||
'Content-length': base64Data.length.toString(),
|
||||
},
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: context.auth.access_token,
|
||||
},
|
||||
});
|
||||
|
||||
return result.body;
|
||||
} else {
|
||||
// For files larger than 4MiB, use chunked upload
|
||||
const session = await httpClient.sendRequest({
|
||||
method: HttpMethod.POST,
|
||||
url: `${oneDriveCommon.baseUrl}/items/${parentId}:/${encodedFilename}:/createUploadSession`,
|
||||
body: {
|
||||
item: {
|
||||
'@microsoft.graph.conflictBehavior': 'replace',
|
||||
name: context.propsValue.fileName,
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: context.auth.access_token,
|
||||
},
|
||||
});
|
||||
|
||||
const uploadUrl = session.body.uploadUrl;
|
||||
let start = 0;
|
||||
let end = CHUNK_SIZE - 1;
|
||||
const fileSize = fileData.data.length;
|
||||
let result;
|
||||
while (start < fileSize) {
|
||||
if (end >= fileSize) {
|
||||
end = fileSize - 1;
|
||||
}
|
||||
|
||||
const chunk = fileData.data.slice(start, end + 1);
|
||||
|
||||
result = await httpClient.sendRequest({
|
||||
method: HttpMethod.PUT,
|
||||
url: uploadUrl,
|
||||
body: chunk,
|
||||
headers: {
|
||||
'Content-Length': chunk.length.toString(),
|
||||
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
|
||||
},
|
||||
});
|
||||
|
||||
start += CHUNK_SIZE;
|
||||
end += CHUNK_SIZE;
|
||||
}
|
||||
|
||||
return result?.body;
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
import {
|
||||
httpClient,
|
||||
HttpMethod,
|
||||
AuthenticationType,
|
||||
} from '@activepieces/pieces-common';
|
||||
import { OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';
|
||||
import { MarkdownVariant } from '@activepieces/shared';
|
||||
import dayjs from 'dayjs';
|
||||
import { oneDriveAuth } from '../..';
|
||||
|
||||
export const oneDriveCommon = {
|
||||
baseUrl: 'https://graph.microsoft.com/v1.0/me/drive',
|
||||
|
||||
parentFolder: Property.Dropdown({
|
||||
auth: oneDriveAuth,
|
||||
displayName: 'Parent Folder',
|
||||
required: false,
|
||||
refreshers: ['auth'],
|
||||
options: async ({ auth }) => {
|
||||
if (!auth) {
|
||||
return {
|
||||
disabled: true,
|
||||
options: [],
|
||||
placeholder: 'Please authenticate first',
|
||||
};
|
||||
}
|
||||
|
||||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue;
|
||||
let folders: { id: string; label: string }[] = [];
|
||||
|
||||
try {
|
||||
folders = await getFoldersRecursively(authProp, 'root', '');
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to get folders\nError:${e}`);
|
||||
}
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
options: folders.map((folder: { id: string; label: string }) => {
|
||||
return {
|
||||
label: folder.label,
|
||||
value: folder.id,
|
||||
};
|
||||
}),
|
||||
};
|
||||
},
|
||||
}),
|
||||
parentFolderInfo : Property.MarkDown({
|
||||
value:
|
||||
`**Note**: If you can't find the folder in the dropdown list (which fetches up to 1000 folders), please click on the **(F)** and type the folder ID directly.\n
|
||||
|
||||
you can find the folder ID in the OneDrive URL after **?id=**, e.g., "onedrive.live.com/?id=**folder-id**&cid=some-other-id"
|
||||
|
||||
`,
|
||||
variant:MarkdownVariant.INFO
|
||||
}),
|
||||
|
||||
async getFiles(
|
||||
auth: OAuth2PropertyValue,
|
||||
search?: {
|
||||
parentFolder?: string;
|
||||
createdTime?: string | number | Date;
|
||||
createdTimeOp?: string;
|
||||
}
|
||||
) {
|
||||
let url = `${this.baseUrl}/items/root/children?$filter=folder eq null`;
|
||||
if (search?.parentFolder) {
|
||||
url = `${this.baseUrl}/items/${search.parentFolder}/children?$filter=folder eq null`;
|
||||
}
|
||||
|
||||
const response = await httpClient.sendRequest<{
|
||||
value: { id: string; name: string; createdDateTime: string }[];
|
||||
}>({
|
||||
method: HttpMethod.GET,
|
||||
url: url,
|
||||
queryParams: {
|
||||
$select: 'id,name,createdDateTime',
|
||||
$orderby: 'createdDateTime asc',
|
||||
},
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: auth.access_token,
|
||||
},
|
||||
});
|
||||
|
||||
const files = response.body.value;
|
||||
|
||||
if (search?.createdTime) {
|
||||
const compareDate = dayjs(search.createdTime);
|
||||
return files.filter((file) => {
|
||||
const fileDate = dayjs(file.createdDateTime);
|
||||
const comparison =
|
||||
search.createdTimeOp === '<'
|
||||
? fileDate.isBefore(compareDate)
|
||||
: fileDate.isAfter(compareDate);
|
||||
return comparison;
|
||||
});
|
||||
}
|
||||
|
||||
return files;
|
||||
},
|
||||
};
|
||||
|
||||
async function getFoldersRecursively(
|
||||
auth: OAuth2PropertyValue,
|
||||
folderId: string,
|
||||
parentPath = '',
|
||||
result: { label: string; id: string }[] = []
|
||||
) {
|
||||
// Stop recursion if limit is reached
|
||||
if (result.length >= 1000) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const url = `${oneDriveCommon.baseUrl}/items/${folderId}/children?$select=id,name,folder`;
|
||||
|
||||
try {
|
||||
const response = await httpClient.sendRequest<getFoldersResponse>({
|
||||
method: HttpMethod.GET,
|
||||
url,
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: auth.access_token,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
const items = response.body.value;
|
||||
|
||||
const folders = items.filter((item) => item.folder);
|
||||
|
||||
for (const folder of folders) {
|
||||
const path = parentPath ? `${parentPath}/${folder.name}` : folder.name;
|
||||
result.push({ label: path, id: folder.id });
|
||||
|
||||
if (folder.folder?.childCount && folder.folder.childCount > 0) {
|
||||
await getFoldersRecursively(auth, folder.id, path, result);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to get folders\nError: ${e}`);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
interface getFoldersResponse {
|
||||
'@odata.nextLink'?: string;
|
||||
'@odata.deltaLink'?: string;
|
||||
value: { id: string; name: string; folder?: { childCount: number } }[];
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { AppConnectionValueForAuthProperty, PiecePropValueSchema, Property, createTrigger } from '@activepieces/pieces-framework';
|
||||
import { TriggerStrategy } from '@activepieces/pieces-framework';
|
||||
import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common';
|
||||
import dayjs from 'dayjs';
|
||||
import { oneDriveAuth } from '../..';
|
||||
import { oneDriveCommon } from '../common/common';
|
||||
import { Client, PageCollection } from '@microsoft/microsoft-graph-client';
|
||||
import { DriveItem } from '@microsoft/microsoft-graph-types';
|
||||
|
||||
type Props = {
|
||||
parentFolder?: string;
|
||||
};
|
||||
|
||||
const polling: Polling<AppConnectionValueForAuthProperty<typeof oneDriveAuth>, Props> = {
|
||||
strategy: DedupeStrategy.TIMEBASED,
|
||||
items: async ({ auth, propsValue, lastFetchEpochMS }) => {
|
||||
const client = Client.initWithMiddleware({
|
||||
authProvider: {
|
||||
getAccessToken: () => Promise.resolve(auth.access_token),
|
||||
},
|
||||
});
|
||||
|
||||
const files = [];
|
||||
|
||||
const endpoint = propsValue.parentFolder
|
||||
? `/me/drive/items/${propsValue.parentFolder}/children`
|
||||
: `/me/drive/items/root/children`;
|
||||
let response: PageCollection = await client.api(endpoint).get();
|
||||
while (response.value.length > 0) {
|
||||
for (const item of response.value as DriveItem[]) {
|
||||
if (item.file) {
|
||||
files.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (response['@odata.nextLink']) {
|
||||
response = await client.api(response['@odata.nextLink']).get();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
files.sort((a, b) => {
|
||||
const aDate = dayjs(a.createdDateTime);
|
||||
const bDate = dayjs(b.createdDateTime);
|
||||
return bDate.diff(aDate);
|
||||
});
|
||||
|
||||
return files.map((file) => ({
|
||||
epochMilliSeconds: dayjs(file.createdDateTime).valueOf(),
|
||||
data: file,
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
export const newFile = createTrigger({
|
||||
auth: oneDriveAuth,
|
||||
name: 'new_file',
|
||||
displayName: 'New File',
|
||||
description: 'Trigger when a new file is uploaded.',
|
||||
props: {
|
||||
markdown:oneDriveCommon.parentFolderInfo,
|
||||
parentFolder: oneDriveCommon.parentFolder,
|
||||
},
|
||||
type: TriggerStrategy.POLLING,
|
||||
async onEnable(context) {
|
||||
await pollingHelper.onEnable(polling, {
|
||||
auth: context.auth,
|
||||
store: context.store,
|
||||
propsValue: context.propsValue,
|
||||
});
|
||||
},
|
||||
async onDisable(context) {
|
||||
await pollingHelper.onDisable(polling, {
|
||||
auth: context.auth,
|
||||
store: context.store,
|
||||
propsValue: context.propsValue,
|
||||
});
|
||||
},
|
||||
async test(context) {
|
||||
return await pollingHelper.test(polling, context);
|
||||
},
|
||||
async run(context) {
|
||||
return await pollingHelper.poll(polling, context);
|
||||
},
|
||||
sampleData: {
|
||||
id: '123456',
|
||||
name: 'example.jpg',
|
||||
createdDateTime: '2023-10-20T10:16:35.5Z',
|
||||
cTag: '07NkI9QUVCNEY1QzU9ITEySi4yNTD',
|
||||
eTag: '331E4899BE5BFA2!sccbdc3441b454cc0a13be0f6be58ca3d',
|
||||
lastModifiedDateTime: '2023-10-20T10:16:35.5Z',
|
||||
size: 53431,
|
||||
createdBy: {
|
||||
application: {
|
||||
id: '00000000-0000-0000-0000-0000481710a4',
|
||||
displayName: '4c5b-b112-36a304b66dad',
|
||||
},
|
||||
user: {
|
||||
email: 'john@outlook.com',
|
||||
id: '0331E4899BE5BFA2',
|
||||
displayName: 'John Doe',
|
||||
},
|
||||
},
|
||||
lastModifiedBy: {
|
||||
application: {
|
||||
id: '00000000-0000-0000-0000-0000481710a4',
|
||||
displayName: '36a304b66dad',
|
||||
},
|
||||
user: {
|
||||
email: 'john@outlook.com',
|
||||
id: '0331E4899BE5BFA2',
|
||||
displayName: 'John Doe',
|
||||
},
|
||||
},
|
||||
parentReference: {
|
||||
driveType: 'personal',
|
||||
driveId: 'E4899BE5BFA2',
|
||||
id: '48dd8265f06fd5e8024d',
|
||||
name: 'child',
|
||||
path: '/drive/root:/parent/child',
|
||||
siteId: '043b2233-0eed-436a',
|
||||
},
|
||||
file: {
|
||||
mimeType: 'image/jpeg',
|
||||
},
|
||||
fileSystemInfo: {
|
||||
createdDateTime: '2025-01-22T09:30:10Z',
|
||||
lastModifiedDateTime: '2025-01-22T09:30:12Z',
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user