Skip to content

Commit

Permalink
Merge pull request #4597 from kishanprmr/webflow
Browse files Browse the repository at this point in the history
feat(webflow): fix show collection fields in all items actions
  • Loading branch information
abuaboud committed May 2, 2024
2 parents 6fb6c51 + a7250a8 commit 10286c1
Show file tree
Hide file tree
Showing 16 changed files with 861 additions and 838 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/webflow/package.json
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-webflow",
"version": "0.1.4"
"version": "0.1.5"
}
77 changes: 40 additions & 37 deletions packages/pieces/community/webflow/src/index.ts
@@ -1,11 +1,7 @@
import { createCustomApiCallAction } from '@activepieces/pieces-common';
import {
OAuth2PropertyValue,
PieceAuth,
createPiece,
} from '@activepieces/pieces-framework';
import { OAuth2PropertyValue, PieceAuth, createPiece } from '@activepieces/pieces-framework';
import { PieceCategory } from '@activepieces/shared';
import { webflowCreateCollectionItem } from './lib/actions/create-collection-item';
import { webflowCreateCollectionItemAction } from './lib/actions/create-collection-item';
import { webflowDeleteCollectionItem } from './lib/actions/delete-collection-item';
import { webflowFindCollectionItem } from './lib/actions/find-collection-item';
import { webflowFindOrder } from './lib/actions/find-order';
Expand All @@ -17,38 +13,45 @@ import { webflowUpdateCollectionItem } from './lib/actions/update-collection-ite
import { webflowNewSubmission } from './lib/triggers/new-form-submitted';

export const webflowAuth = PieceAuth.OAuth2({
description: '',
authUrl: 'https://webflow.com/oauth/authorize',
tokenUrl: 'https://api.webflow.com/oauth/access_token',
required: true,
scope: ['webhooks:write', 'forms:read'],
description: '',
authUrl: 'https://webflow.com/oauth/authorize',
tokenUrl: 'https://api.webflow.com/oauth/access_token',
required: true,
scope: ['webhooks:write', 'forms:read'],
});

export const webflow = createPiece({
displayName: 'Webflow',
description: 'Design, build, and launch responsive websites visually',
minimumSupportedRelease: '0.5.0',
logoUrl: 'https://cdn.activepieces.com/pieces/webflow.png',
categories: [PieceCategory.MARKETING],
authors: ["Ahmad-AbuOsbeh","TaskMagicKyle","kishanprmr","MoShizzle","khaledmashaly","abuaboud"],
auth: webflowAuth,
actions: [
webflowCreateCollectionItem,
webflowDeleteCollectionItem,
webflowUpdateCollectionItem,
webflowFindCollectionItem,
webflowGetCollectionItem,
webflowFulfillOrder,
webflowUnfulfillOrder,
webflowRefundOrder,
webflowFindOrder,
createCustomApiCallAction({
baseUrl: () => 'https://api.webflow.com',
auth: webflowAuth,
authMapping: (auth) => ({
Authorization: `Bearer ${(auth as OAuth2PropertyValue).access_token}`,
}),
}),
],
triggers: [webflowNewSubmission],
displayName: 'Webflow',
description: 'Design, build, and launch responsive websites visually',
minimumSupportedRelease: '0.5.0',
logoUrl: 'https://cdn.activepieces.com/pieces/webflow.png',
categories: [PieceCategory.MARKETING],
authors: [
'Ahmad-AbuOsbeh',
'TaskMagicKyle',
'kishanprmr',
'MoShizzle',
'khaledmashaly',
'abuaboud',
],
auth: webflowAuth,
actions: [
webflowCreateCollectionItemAction,
webflowDeleteCollectionItem,
webflowUpdateCollectionItem,
webflowFindCollectionItem,
webflowGetCollectionItem,
webflowFulfillOrder,
webflowUnfulfillOrder,
webflowRefundOrder,
webflowFindOrder,
createCustomApiCallAction({
baseUrl: () => 'https://api.webflow.com',
auth: webflowAuth,
authMapping: (auth) => ({
Authorization: `Bearer ${(auth as OAuth2PropertyValue).access_token}`,
}),
}),
],
triggers: [webflowNewSubmission],
});
@@ -1,56 +1,62 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
HttpRequest,
HttpMethod,
httpClient,
AuthenticationType,
} from '@activepieces/pieces-common';
import { createAction, DynamicPropsValue, Property } from '@activepieces/pieces-framework';

import { webflowAuth } from '../..';
import { webflowCommon } from '../common/common';
import { webflowProps } from '../common/props';
import { WebflowApiClient } from '../common/client';

export const webflowCreateCollectionItem = createAction({
auth: webflowAuth,
name: 'create_collection_item',
description: 'Create collection item',
displayName: 'Create an item in a collection',
props: {
site_id: webflowCommon.sitesDropdown,
collection_id: webflowCommon.collectionsDropdown,
values: webflowCommon.collectionFieldProperties,
is_archived: Property.Checkbox({
displayName: 'Is Archived',
description: 'Whether the item is archived or not',
required: false,
}),
is_draft: Property.Checkbox({
displayName: 'Is Draft',
description: 'Whether the item is a draft or not',
required: false,
}),
},
export const webflowCreateCollectionItemAction = createAction({
auth: webflowAuth,
name: 'create_collection_item',
displayName: 'Create Collection Item',
description: 'Creates new collection item.',
props: {
site_id: webflowProps.site_id,
collection_id: webflowProps.collection_id,
collection_fields: webflowProps.collection_fields,
is_archived: Property.Checkbox({
displayName: 'Is Archived',
description: 'Whether the item is archived or not',
required: false,
}),
is_draft: Property.Checkbox({
displayName: 'Is Draft',
description: 'Whether the item is a draft or not',
required: false,
}),
},
async run(context) {
const collectionId = context.propsValue.collection_id;
const isArchived = context.propsValue.is_archived;
const isDraft = context.propsValue.is_draft;
const collectionInputFields = context.propsValue.collection_fields;

async run(configValue) {
const accessToken = configValue.auth['access_token'];
const collectionId = configValue.propsValue['collection_id'];
const isArchived = configValue.propsValue['is_archived'];
const isDraft = configValue.propsValue['is_draft'];
const client = new WebflowApiClient(context.auth.access_token);
const { fields: CollectionFields } = await client.getCollection(collectionId);

const request: HttpRequest = {
method: HttpMethod.POST,
url: `https://api.webflow.com/collections/${collectionId}/items`,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: accessToken,
},
body: {
fields: configValue.propsValue['values'],
isArchived,
isDraft,
},
};
const formattedCollectionFields: DynamicPropsValue = {};
for (const field of CollectionFields) {
const fieldValue = collectionInputFields[field.slug];

const res = await httpClient.sendRequest<never>(request);
if (fieldValue !== undefined && fieldValue !== '') {
switch (field.type) {
case 'ImageRef':
case 'FileRef':
formattedCollectionFields[field.slug] = { url: fieldValue };
break;
case 'Set':
formattedCollectionFields[field.slug] = fieldValue.map((url: string) => ({ url: url }));
break;
case 'Number':
formattedCollectionFields[field.slug] = Number(fieldValue);
break;
default:
formattedCollectionFields[field.slug] = fieldValue;
}
}
}

return res.body;
},
return await client.createCollectionItem(collectionId, {
fields: { ...formattedCollectionFields, _archived: isArchived, _draft: isDraft },
});
},
});
@@ -1,40 +1,26 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
HttpRequest,
HttpMethod,
httpClient,
AuthenticationType,
} from '@activepieces/pieces-common';
import { createAction } from '@activepieces/pieces-framework';

import { webflowAuth } from '../..';
import { webflowCommon } from '../common/common';
import { webflowProps } from '../common/props';
import { WebflowApiClient } from '../common/client';

export const webflowDeleteCollectionItem = createAction({
auth: webflowAuth,
name: 'delete_collection_item',
description: 'Delete collection item',
displayName: 'Delete an item in a collection',
props: {
site_id: webflowCommon.sitesDropdown,
collection_id: webflowCommon.collectionsDropdown,
collection_item_id: webflowCommon.collectionItemsDropdown,
},

async run(configValue) {
const accessToken = configValue.auth['access_token'];
const collectionId = configValue.propsValue['collection_id'];
const collectionItemId = configValue.propsValue['collection_item_id'];
auth: webflowAuth,
name: 'delete_collection_item',
description: 'Delete collection item',
displayName: 'Delete an item in a collection',
props: {
site_id: webflowProps.site_id,
collection_id: webflowProps.collection_id,
collection_item_id: webflowProps.collection_item_id,
},

const request: HttpRequest = {
method: HttpMethod.DELETE,
url: `https://api.webflow.com/collections/${collectionId}/items/${collectionItemId}`,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: accessToken,
},
};
async run(context) {
const collectionId = context.propsValue.collection_id;
const collectionItemId = context.propsValue.collection_item_id;

const res = await httpClient.sendRequest<never>(request);
const client = new WebflowApiClient(context.auth.access_token);

return res.body;
},
return await client.deleteCollectionItem(collectionId, collectionItemId);
},
});

0 comments on commit 10286c1

Please sign in to comment.