From de8bcb8c775f9307868b0d065d5135b6438c3528 Mon Sep 17 00:00:00 2001 From: Mark van Bellen Date: Sat, 16 Nov 2024 14:48:48 +0000 Subject: [PATCH 1/2] feat: new piece 3 actions --- packages/pieces/community/apify/package.json | 4 ++ packages/pieces/community/apify/project.json | 45 ++++++++++++++++++ packages/pieces/community/apify/src/index.ts | 46 +++++++++++++++++++ .../apify/src/lib/actions/get-actors.ts | 31 +++++++++++++ .../src/lib/actions/get-dataset-items.ts | 37 +++++++++++++++ .../apify/src/lib/actions/get-last-run.ts | 37 +++++++++++++++ tsconfig.base.json | 3 ++ 7 files changed, 203 insertions(+) create mode 100644 packages/pieces/community/apify/package.json create mode 100644 packages/pieces/community/apify/project.json create mode 100644 packages/pieces/community/apify/src/index.ts create mode 100644 packages/pieces/community/apify/src/lib/actions/get-actors.ts create mode 100644 packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts create mode 100644 packages/pieces/community/apify/src/lib/actions/get-last-run.ts diff --git a/packages/pieces/community/apify/package.json b/packages/pieces/community/apify/package.json new file mode 100644 index 0000000000..c61b5a5409 --- /dev/null +++ b/packages/pieces/community/apify/package.json @@ -0,0 +1,4 @@ +{ + "name": "@activepieces/piece-apify", + "version": "0.0.1" +} diff --git a/packages/pieces/community/apify/project.json b/packages/pieces/community/apify/project.json new file mode 100644 index 0000000000..0c44266be8 --- /dev/null +++ b/packages/pieces/community/apify/project.json @@ -0,0 +1,45 @@ +{ + "name": "pieces-apify", + "$schema": "../../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "packages/pieces/community/apify/src", + "projectType": "library", + "release": { + "version": { + "generatorOptions": { + "packageRoot": "dist/{projectRoot}", + "currentVersionResolver": "git-tag" + } + } + }, + "tags": [], + "targets": { + "build": { + "executor": "@nx/js:tsc", + "outputs": [ + "{options.outputPath}" + ], + "options": { + "outputPath": "dist/packages/pieces/community/apify", + "tsConfig": "packages/pieces/community/apify/tsconfig.lib.json", + "packageJson": "packages/pieces/community/apify/package.json", + "main": "packages/pieces/community/apify/src/index.ts", + "assets": [ + "packages/pieces/community/apify/*.md" + ], + "buildableProjectDepsInPackageJsonType": "dependencies", + "updateBuildableProjectDepsInPackageJson": true + } + }, + "nx-release-publish": { + "options": { + "packageRoot": "dist/{projectRoot}" + } + }, + "lint": { + "executor": "@nx/eslint:lint", + "outputs": [ + "{options.outputFile}" + ] + } + } +} \ No newline at end of file diff --git a/packages/pieces/community/apify/src/index.ts b/packages/pieces/community/apify/src/index.ts new file mode 100644 index 0000000000..243e02542d --- /dev/null +++ b/packages/pieces/community/apify/src/index.ts @@ -0,0 +1,46 @@ + + import { createPiece, PieceAuth } from "@activepieces/pieces-framework"; + import { PieceCategory } from '@activepieces/shared'; + import { getDatasetItems } from './lib/actions/get-dataset-items'; + import { getActors } from './lib/actions/get-actors'; + import { getLastRun } from './lib/actions/get-last-run'; + + export const apifyAuth = PieceAuth.CustomAuth({ + description: 'Enter API key authentication details', + props: { + apikey: PieceAuth.SecretText({ + displayName: 'API Key', + required: true, + description: 'Find your API key on Apify in the settings, API & Integrations section.' + }) + }, + // Optional Validation + validate: async ({auth}) => { + if(auth){ + return { + valid: true, + } + } + return { + valid: false, + error: 'Invalid Api Key' + } + }, + required: true + }); + + + export const apify = createPiece({ + displayName: "Apify", + description: "Your full‑stack platform for web scraping", + auth: apifyAuth, + minimumSupportedRelease: '0.20.0', + logoUrl: "https://cdn.activepieces.com/pieces/apify.png", + categories: [PieceCategory.BUSINESS_INTELLIGENCE], + authors: ["buttonsbond"], + actions: [ + getDatasetItems, getActors, getLastRun + ], + triggers: [], + }); + diff --git a/packages/pieces/community/apify/src/lib/actions/get-actors.ts b/packages/pieces/community/apify/src/lib/actions/get-actors.ts new file mode 100644 index 0000000000..1ac8a8d94c --- /dev/null +++ b/packages/pieces/community/apify/src/lib/actions/get-actors.ts @@ -0,0 +1,31 @@ +import { createAction } from '@activepieces/pieces-framework'; +import { apifyAuth } from '../..'; +import { httpClient, HttpMethod } from '@activepieces/pieces-common'; + +export const getActors = createAction({ + + name: 'getActors', + auth: apifyAuth, + displayName: 'Get users Actors', + description: 'Gets the list of Actors the user has available', + props: {}, + async run(context) { + const apifyToken = context.auth.apikey; + const headers = { + 'Authorization': 'Bearer ' + apifyToken, + 'Content-Type': 'application/json', + }; + + const url = 'https://api.apify.com/v2/acts/' + + const httprequestdata = { + method: HttpMethod.GET, + url, + headers, + + }; + + const response = await httpClient.sendRequest(httprequestdata); + return response.body; + }, +}); diff --git a/packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts b/packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts new file mode 100644 index 0000000000..0eb3546a83 --- /dev/null +++ b/packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts @@ -0,0 +1,37 @@ +import { createAction, Property } from '@activepieces/pieces-framework'; +import { apifyAuth } from '../..'; +import { httpClient, HttpMethod } from '@activepieces/pieces-common'; + +export const getDatasetItems = createAction({ + + name: 'getDatasetItems', + auth: apifyAuth, + displayName: 'Get Dataset Items', + description: 'Gets the data from an Actors run', + props: { + runid: Property.ShortText({ + displayName: 'The runid of the Actor (alphanumeric)', + description: 'The runid of the completed Actors run (compulsory)', + required: true, + }), + }, + async run(context) { + const apifyToken = context.auth.apikey; + const headers = { + 'Authorization': 'Bearer ' + apifyToken, + 'Content-Type': 'application/json', + }; + + const url = 'https://api.apify.com/v2/datasets/' + context.propsValue.runid + '/items/'; + + const httprequestdata = { + method: HttpMethod.GET, + url, + headers, + + }; + + const response = await httpClient.sendRequest(httprequestdata); + return response.body; + }, +}); diff --git a/packages/pieces/community/apify/src/lib/actions/get-last-run.ts b/packages/pieces/community/apify/src/lib/actions/get-last-run.ts new file mode 100644 index 0000000000..2af7840c87 --- /dev/null +++ b/packages/pieces/community/apify/src/lib/actions/get-last-run.ts @@ -0,0 +1,37 @@ +import { createAction, Property } from '@activepieces/pieces-framework'; +import { apifyAuth } from '../..'; +import { httpClient, HttpMethod } from '@activepieces/pieces-common'; + +export const getLastRun = createAction({ + + name: 'getLastRun', + auth: apifyAuth, + displayName: 'Get last run details', + description: 'Gets last run details for a given Actor', + props: { + actorid: Property.ShortText({ + displayName: 'The id of the Actor (alphanumeric)', + description: 'The id of the Actor to get run information [item of interest:defaultDatasetId] (compulsory)', + required: true, + }), + }, + async run(context) { + const apifyToken = context.auth.apikey; + const headers = { + 'Authorization': 'Bearer ' + apifyToken, + 'Content-Type': 'application/json', + }; + + const url = 'https://api.apify.com/v2/acts/' + context.propsValue.actorid + '/runs/last?status=SUCCEEDED' + + const httprequestdata = { + method: HttpMethod.GET, + url, + headers, + + }; + + const response = await httpClient.sendRequest(httprequestdata); + return response.body; + }, +}); diff --git a/tsconfig.base.json b/tsconfig.base.json index eb46cc6c26..ec6e0a8146 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -51,6 +51,9 @@ "@activepieces/piece-aminos": [ "packages/pieces/community/aminos/src/index.ts" ], + "@activepieces/piece-apify": [ + "packages/pieces/community/apify/src/index.ts" + ], "@activepieces/piece-apitable": [ "packages/pieces/community/apitable/src/index.ts" ], From 3fe820cf539d997a40d79cf4dc9ab7dbaeb91d6d Mon Sep 17 00:00:00 2001 From: Kishan Parmar Date: Mon, 18 Nov 2024 13:16:08 +0530 Subject: [PATCH 2/2] fix(apify): fix imports and logo url --- .../pieces/community/apify/.eslintrc.json | 33 ++++++++ packages/pieces/community/apify/README.md | 7 ++ packages/pieces/community/apify/src/index.ts | 77 ++++++++----------- .../apify/src/lib/actions/get-actors.ts | 16 ++-- .../src/lib/actions/get-dataset-items.ts | 19 ++--- .../apify/src/lib/actions/get-last-run.ts | 26 ++++--- packages/pieces/community/apify/tsconfig.json | 19 +++++ .../pieces/community/apify/tsconfig.lib.json | 11 +++ 8 files changed, 134 insertions(+), 74 deletions(-) create mode 100644 packages/pieces/community/apify/.eslintrc.json create mode 100644 packages/pieces/community/apify/README.md create mode 100644 packages/pieces/community/apify/tsconfig.json create mode 100644 packages/pieces/community/apify/tsconfig.lib.json diff --git a/packages/pieces/community/apify/.eslintrc.json b/packages/pieces/community/apify/.eslintrc.json new file mode 100644 index 0000000000..4a4e695c54 --- /dev/null +++ b/packages/pieces/community/apify/.eslintrc.json @@ -0,0 +1,33 @@ +{ + "extends": [ + "../../../../.eslintrc.base.json" + ], + "ignorePatterns": [ + "!**/*" + ], + "overrides": [ + { + "files": [ + "*.ts", + "*.tsx", + "*.js", + "*.jsx" + ], + "rules": {} + }, + { + "files": [ + "*.ts", + "*.tsx" + ], + "rules": {} + }, + { + "files": [ + "*.js", + "*.jsx" + ], + "rules": {} + } + ] +} \ No newline at end of file diff --git a/packages/pieces/community/apify/README.md b/packages/pieces/community/apify/README.md new file mode 100644 index 0000000000..5c2fc8531c --- /dev/null +++ b/packages/pieces/community/apify/README.md @@ -0,0 +1,7 @@ +# pieces-apify + +This library was generated with [Nx](https://nx.dev). + +## Building + +Run `nx build pieces-apify` to build the library. diff --git a/packages/pieces/community/apify/src/index.ts b/packages/pieces/community/apify/src/index.ts index 243e02542d..db044e4caf 100644 --- a/packages/pieces/community/apify/src/index.ts +++ b/packages/pieces/community/apify/src/index.ts @@ -1,46 +1,35 @@ +import { createPiece, PieceAuth } from '@activepieces/pieces-framework'; +import { PieceCategory } from '@activepieces/shared'; +import { getDatasetItems } from './lib/actions/get-dataset-items'; +import { getActors } from './lib/actions/get-actors'; +import { getLastRun } from './lib/actions/get-last-run'; - import { createPiece, PieceAuth } from "@activepieces/pieces-framework"; - import { PieceCategory } from '@activepieces/shared'; - import { getDatasetItems } from './lib/actions/get-dataset-items'; - import { getActors } from './lib/actions/get-actors'; - import { getLastRun } from './lib/actions/get-last-run'; +export const apifyAuth = PieceAuth.SecretText({ + displayName: 'API Key', + required: true, + description: + 'Find your API key on Apify in the settings, API & Integrations section.', + validate: async ({ auth }) => { + if (auth) { + return { + valid: true, + }; + } + return { + valid: false, + error: 'Invalid API Key', + }; + }, +}); - export const apifyAuth = PieceAuth.CustomAuth({ - description: 'Enter API key authentication details', - props: { - apikey: PieceAuth.SecretText({ - displayName: 'API Key', - required: true, - description: 'Find your API key on Apify in the settings, API & Integrations section.' - }) - }, - // Optional Validation - validate: async ({auth}) => { - if(auth){ - return { - valid: true, - } - } - return { - valid: false, - error: 'Invalid Api Key' - } - }, - required: true - }); - - - export const apify = createPiece({ - displayName: "Apify", - description: "Your full‑stack platform for web scraping", - auth: apifyAuth, - minimumSupportedRelease: '0.20.0', - logoUrl: "https://cdn.activepieces.com/pieces/apify.png", - categories: [PieceCategory.BUSINESS_INTELLIGENCE], - authors: ["buttonsbond"], - actions: [ - getDatasetItems, getActors, getLastRun - ], - triggers: [], - }); - +export const apify = createPiece({ + displayName: 'Apify', + description: 'Your full‑stack platform for web scraping', + auth: apifyAuth, + minimumSupportedRelease: '0.20.0', + logoUrl: 'https://cdn.activepieces.com/pieces/apify.svg', + categories: [PieceCategory.BUSINESS_INTELLIGENCE], + authors: ['buttonsbond'], + actions: [getDatasetItems, getActors, getLastRun], + triggers: [], +}); diff --git a/packages/pieces/community/apify/src/lib/actions/get-actors.ts b/packages/pieces/community/apify/src/lib/actions/get-actors.ts index 1ac8a8d94c..a4a9da696b 100644 --- a/packages/pieces/community/apify/src/lib/actions/get-actors.ts +++ b/packages/pieces/community/apify/src/lib/actions/get-actors.ts @@ -3,26 +3,24 @@ import { apifyAuth } from '../..'; import { httpClient, HttpMethod } from '@activepieces/pieces-common'; export const getActors = createAction({ - name: 'getActors', auth: apifyAuth, - displayName: 'Get users Actors', - description: 'Gets the list of Actors the user has available', + displayName: "Get user's Actors", + description: 'Gets the list of Actors available to the user.', props: {}, async run(context) { - const apifyToken = context.auth.apikey; + const apifyToken = context.auth; const headers = { - 'Authorization': 'Bearer ' + apifyToken, + Authorization: 'Bearer ' + apifyToken, 'Content-Type': 'application/json', }; - - const url = 'https://api.apify.com/v2/acts/' - + + const url = 'https://api.apify.com/v2/acts/'; + const httprequestdata = { method: HttpMethod.GET, url, headers, - }; const response = await httpClient.sendRequest(httprequestdata); diff --git a/packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts b/packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts index 0eb3546a83..eeb37a4d7b 100644 --- a/packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts +++ b/packages/pieces/community/apify/src/lib/actions/get-dataset-items.ts @@ -3,32 +3,33 @@ import { apifyAuth } from '../..'; import { httpClient, HttpMethod } from '@activepieces/pieces-common'; export const getDatasetItems = createAction({ - name: 'getDatasetItems', auth: apifyAuth, displayName: 'Get Dataset Items', - description: 'Gets the data from an Actors run', + description: 'Gets the data from an Actors run.', props: { runid: Property.ShortText({ displayName: 'The runid of the Actor (alphanumeric)', - description: 'The runid of the completed Actors run (compulsory)', + description: 'The runid of the completed Actors run (compulsory).', required: true, }), }, async run(context) { - const apifyToken = context.auth.apikey; + const apifyToken = context.auth; const headers = { - 'Authorization': 'Bearer ' + apifyToken, + Authorization: 'Bearer ' + apifyToken, 'Content-Type': 'application/json', }; - - const url = 'https://api.apify.com/v2/datasets/' + context.propsValue.runid + '/items/'; - + + const url = + 'https://api.apify.com/v2/datasets/' + + context.propsValue.runid + + '/items/'; + const httprequestdata = { method: HttpMethod.GET, url, headers, - }; const response = await httpClient.sendRequest(httprequestdata); diff --git a/packages/pieces/community/apify/src/lib/actions/get-last-run.ts b/packages/pieces/community/apify/src/lib/actions/get-last-run.ts index 2af7840c87..0b75646633 100644 --- a/packages/pieces/community/apify/src/lib/actions/get-last-run.ts +++ b/packages/pieces/community/apify/src/lib/actions/get-last-run.ts @@ -3,32 +3,34 @@ import { apifyAuth } from '../..'; import { httpClient, HttpMethod } from '@activepieces/pieces-common'; export const getLastRun = createAction({ - name: 'getLastRun', auth: apifyAuth, displayName: 'Get last run details', - description: 'Gets last run details for a given Actor', + description: 'Gets last run details for a given Actor.', props: { actorid: Property.ShortText({ - displayName: 'The id of the Actor (alphanumeric)', - description: 'The id of the Actor to get run information [item of interest:defaultDatasetId] (compulsory)', - required: true, - }), + displayName: 'The id of the Actor (alphanumeric)', + description: + 'The id of the Actor to get run information [item of interest:defaultDatasetId] (compulsory)', + required: true, + }), }, async run(context) { - const apifyToken = context.auth.apikey; + const apifyToken = context.auth; const headers = { - 'Authorization': 'Bearer ' + apifyToken, + Authorization: 'Bearer ' + apifyToken, 'Content-Type': 'application/json', }; - - const url = 'https://api.apify.com/v2/acts/' + context.propsValue.actorid + '/runs/last?status=SUCCEEDED' - + + const url = + 'https://api.apify.com/v2/acts/' + + context.propsValue.actorid + + '/runs/last?status=SUCCEEDED'; + const httprequestdata = { method: HttpMethod.GET, url, headers, - }; const response = await httpClient.sendRequest(httprequestdata); diff --git a/packages/pieces/community/apify/tsconfig.json b/packages/pieces/community/apify/tsconfig.json new file mode 100644 index 0000000000..059cd81661 --- /dev/null +++ b/packages/pieces/community/apify/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + } + ] +} diff --git a/packages/pieces/community/apify/tsconfig.lib.json b/packages/pieces/community/apify/tsconfig.lib.json new file mode 100644 index 0000000000..28369ef762 --- /dev/null +++ b/packages/pieces/community/apify/tsconfig.lib.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], + "include": ["src/**/*.ts"] +}