Skip to content

Commit

Permalink
fix(apify): update auth
Browse files Browse the repository at this point in the history
  • Loading branch information
kishanprmr committed Nov 19, 2024
1 parent e6f9818 commit 2e5844e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 70 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/apify/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-apify",
"version": "0.0.1"
"version": "0.0.2"
}
86 changes: 41 additions & 45 deletions packages/pieces/community/apify/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
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 { startActor } from './lib/actions/start-actor';

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 { startActor } from './lib/actions/start-actor';
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 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, startActor
],
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.png',
categories: [PieceCategory.BUSINESS_INTELLIGENCE],
authors: ['buttonsbond'],
actions: [getDatasetItems, getActors, getLastRun, startActor],
triggers: [],
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getActors = createAction({
description: 'Gets the list of Actors available to the user.',
props: {},
async run(context) {
const apifyToken = context.auth;
const apifyToken = context.auth.apikey;
const headers = {
Authorization: 'Bearer ' + apifyToken,
'Content-Type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ export const getDatasetItems = createAction({
props: {
runid: Property.ShortText({
displayName: 'The runid of the Actor (alphanumeric)',
description: 'The runid of the completed Actors run [defaultDatasetId] (compulsory)',
description:
'The runid of the completed Actors run [defaultDatasetId] (compulsory)',
required: true,
}),
},
async run(context) {
const apifyToken = context.auth;
const apifyToken = context.auth.apikey;
const headers = {
Authorization: 'Bearer ' + apifyToken,
'Content-Type': 'application/json',
Expand Down
22 changes: 13 additions & 9 deletions packages/pieces/community/apify/src/lib/actions/get-last-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@ export const getLastRun = createAction({
description: 'Gets last run details for a given Actor.',
props: {
actorid: Property.ShortText({
displayName: 'The id of the Actor (alphanumeric)',
// updated the description as can also use the actors user or ownername a tilde and the actor name in place of the id
description: 'The id [defaultDatasetId] of the Actor to get run information [you can also use the username then ~ then the name] (compulsory)',
required: true,
}),
displayName: 'The id of the Actor (alphanumeric)',
// updated the description as can also use the actors user or ownername a tilde and the actor name in place of the id
description:
'The id [defaultDatasetId] of the Actor to get run information [you can also use the username then ~ then the name] (compulsory)',
required: true,
}),
},
async run(context) {
const apifyToken = context.auth;
const apifyToken = context.auth.apikey;
const headers = {
Authorization: 'Bearer ' + apifyToken,
'Content-Type': 'application/json',
};

// removed ?status=SUCCEEDED as we might need to know if a particular actor failed
const url = 'https://api.apify.com/v2/acts/' + context.propsValue.actorid + '/runs/last';
const url =
'https://api.apify.com/v2/acts/' +
context.propsValue.actorid +
'/runs/last';
//?status=SUCCEEDED'

const httprequestdata = {
method: HttpMethod.GET,
url,
Expand Down
27 changes: 15 additions & 12 deletions packages/pieces/community/apify/src/lib/actions/start-actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,36 @@ import { apifyAuth } from '../..';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';

export const startActor = createAction({
// https://api.apify.com/v2/acts/{actorId}/run-sync
// https://api.apify.com/v2/acts/{actorId}/runs
// https://api.apify.com/v2/acts/{actorId}/run-sync
// https://api.apify.com/v2/acts/{actorId}/runs
name: 'startActor',
auth: apifyAuth,
displayName: 'Start an Apify Actor',
description: 'Starts an Apify Actor web scraper',
props: {
actorid: Property.ShortText({
displayName: 'The id or name of the Actor (alphanumeric)',
description: 'The id of the Actor to run [Use either id, or the username then ~ then the name] (compulsory)',
required: true,
}),
displayName: 'The id or name of the Actor (alphanumeric)',
description:
'The id of the Actor to run [Use either id, or the username then ~ then the name] (compulsory)',
required: true,
}),
jsonbody: Property.Json({
displayName: 'JSON input',
description: 'The JSON input to pass to the Actor [you can get the JSON from a run in your Apify account]. If left blank will use defaults. (optional)',
required: true,
displayName: 'JSON input',
description:
'The JSON input to pass to the Actor [you can get the JSON from a run in your Apify account]. If left blank will use defaults. (optional)',
required: true,
}),
},
async run(context) {
const apifyToken = context.auth.apikey;
const headers = {
'Authorization': 'Bearer ' + apifyToken,
Authorization: 'Bearer ' + apifyToken,
'Content-Type': 'application/json',
};

const url = 'https://api.apify.com/v2/acts/' + context.propsValue.actorid + '/runs/';

const url =
'https://api.apify.com/v2/acts/' + context.propsValue.actorid + '/runs/';

const httprequestdata = {
method: HttpMethod.POST,
url,
Expand Down

0 comments on commit 2e5844e

Please sign in to comment.