Skip to content

Commit

Permalink
Merge pull request activepieces#6059 from buttonsbond/main
Browse files Browse the repository at this point in the history
feat(apify): get actors ,get database items and get last run actions
  • Loading branch information
kishanprmr authored Nov 18, 2024
2 parents aa510ee + 3fe820c commit a0ceb29
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/pieces/community/apify/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": [
"../../../../.eslintrc.base.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/pieces/community/apify/README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions packages/pieces/community/apify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@activepieces/piece-apify",
"version": "0.0.1"
}
45 changes: 45 additions & 0 deletions packages/pieces/community/apify/project.json
Original file line number Diff line number Diff line change
@@ -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}"
]
}
}
}
35 changes: 35 additions & 0 deletions packages/pieces/community/apify/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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';

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 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: [],
});
29 changes: 29 additions & 0 deletions packages/pieces/community/apify/src/lib/actions/get-actors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 user's Actors",
description: 'Gets the list of Actors available to the user.',
props: {},
async run(context) {
const apifyToken = context.auth;
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;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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;
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;
},
});
39 changes: 39 additions & 0 deletions packages/pieces/community/apify/src/lib/actions/get-last-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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;
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;
},
});
19 changes: 19 additions & 0 deletions packages/pieces/community/apify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
11 changes: 11 additions & 0 deletions packages/pieces/community/apify/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -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"]
}
3 changes: 3 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down

0 comments on commit a0ceb29

Please sign in to comment.