Skip to content

Commit 4c36ad7

Browse files
committed
new actions
1 parent d637019 commit 4c36ad7

File tree

9 files changed

+253
-8
lines changed

9 files changed

+253
-8
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import apify from "../../apify.app.mjs";
2+
import { LIMIT } from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "apify-get-dataset-items",
6+
name: "Get Dataset Items",
7+
description: "Returns data stored in a dataset. [See the documentation](https://docs.apify.com/api/v2/dataset-items-get)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
apify,
12+
datasetId: {
13+
propDefinition: [
14+
apify,
15+
"datasetId",
16+
],
17+
},
18+
clean: {
19+
propDefinition: [
20+
apify,
21+
"clean",
22+
],
23+
},
24+
fields: {
25+
propDefinition: [
26+
apify,
27+
"fields",
28+
],
29+
},
30+
omit: {
31+
propDefinition: [
32+
apify,
33+
"omit",
34+
],
35+
},
36+
flatten: {
37+
propDefinition: [
38+
apify,
39+
"flatten",
40+
],
41+
},
42+
maxResults: {
43+
propDefinition: [
44+
apify,
45+
"maxResults",
46+
],
47+
},
48+
},
49+
async run({ $ }) {
50+
const params = {
51+
limit: LIMIT,
52+
offset: 0,
53+
clean: this.clean,
54+
fields: this.fields && this.fields.join(),
55+
omit: this.omit && this.omit.join(),
56+
flatten: this.flatten && this.flatten.join(),
57+
};
58+
59+
const results = [];
60+
let total;
61+
62+
do {
63+
const items = await this.apify.listDatasetItems({
64+
$,
65+
datasetId: this.datasetId,
66+
params,
67+
});
68+
results.push(...items);
69+
if (results.length >= this.maxResults) {
70+
break;
71+
}
72+
total = items?.length;
73+
params.offset += LIMIT;
74+
} while (total);
75+
76+
if (results.length > this.maxResults) {
77+
results.length = this.maxResults;
78+
}
79+
80+
if (results.length > 0) {
81+
$.export("$summary", `Successfully retrieved ${results.length} item${results.length === 1
82+
? ""
83+
: "s"}`);
84+
}
85+
return results;
86+
},
87+
};

components/apify/actions/run-actor/run-actor.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "apify-run-actor",
66
name: "Run Actor",
77
description: "Performs an execution of a selected actor in Apify. [See the documentation](https://docs.apify.com/api/v2#/reference/actors/run-collection/run-actor)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
apify,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import apify from "../../apify.app.mjs";
2+
3+
export default {
4+
key: "apify-run-task-synchronously",
5+
name: "Run Task Synchronously",
6+
description: "Run a specific task and return its dataset items. [See the documentation](https://docs.apify.com/api/v2/actor-task-run-sync-get-dataset-items-get)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
apify,
11+
taskId: {
12+
propDefinition: [
13+
apify,
14+
"taskId",
15+
],
16+
description: "The ID of the task to run",
17+
},
18+
timeout: {
19+
type: "integer",
20+
label: "Timeout",
21+
description: "Optional timeout for the run, in seconds. By default, the run uses a timeout specified in the task settings.",
22+
optional: true,
23+
},
24+
memory: {
25+
type: "integer",
26+
label: "Memory",
27+
description: "Memory limit for the run, in megabytes. The amount of memory can be set to a power of 2 with a minimum of 128. By default, the run uses a memory limit specified in the task settings.",
28+
optional: true,
29+
},
30+
build: {
31+
type: "string",
32+
label: "Build",
33+
description: "Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build specified in the task settings (typically latest).",
34+
optional: true,
35+
},
36+
clean: {
37+
propDefinition: [
38+
apify,
39+
"clean",
40+
],
41+
},
42+
fields: {
43+
propDefinition: [
44+
apify,
45+
"fields",
46+
],
47+
},
48+
omit: {
49+
propDefinition: [
50+
apify,
51+
"omit",
52+
],
53+
},
54+
flatten: {
55+
propDefinition: [
56+
apify,
57+
"flatten",
58+
],
59+
},
60+
maxResults: {
61+
propDefinition: [
62+
apify,
63+
"maxResults",
64+
],
65+
},
66+
},
67+
async run({ $ }) {
68+
const response = await this.apify.runTaskSynchronously({
69+
$,
70+
taskId: this.taskId,
71+
params: {
72+
timeout: this.timeout,
73+
memory: this.memory,
74+
build: this.build,
75+
clean: this.clean,
76+
fields: this.fields && this.fields.join(),
77+
omit: this.omit && this.omit.join(),
78+
flatten: this.flatten && this.flatten.join(),
79+
maxItems: this.maxResults,
80+
},
81+
});
82+
83+
$.export("$summary", `Successfully ran task with ID: ${this.taskId}`);
84+
85+
return response;
86+
},
87+
};

components/apify/actions/scrape-single-url/scrape-single-url.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "apify-scrape-single-url",
66
name: "Scrape Single URL",
77
description: "Executes a scraper on a specific website and returns its content as text. This action is perfect for extracting content from a single page.",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
apify,

components/apify/actions/set-key-value-store-record/set-key-value-store-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "apify-set-key-value-store-record",
66
name: "Set Key-Value Store Record",
77
description: "Create or update a record in the key-value store of Apify. [See the documentation](https://docs.apify.com/api/v2#/reference/key-value-stores/record-collection/put-record)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
apify,

components/apify/apify.app.mjs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,56 @@ export default {
8686
}));
8787
},
8888
},
89+
datasetId: {
90+
type: "string",
91+
label: "Dataset ID",
92+
description: "The ID of the dataset to retrieve items within",
93+
async options({ page }) {
94+
const { data: { items } } = await this.listDatasets({
95+
params: {
96+
offset: LIMIT * page,
97+
limit: LIMIT,
98+
},
99+
});
100+
return items?.map(({
101+
id: value, name: label,
102+
}) => ({
103+
label,
104+
value,
105+
})) || [];
106+
},
107+
},
108+
clean: {
109+
type: "boolean",
110+
label: "Clean",
111+
description: "Return only non-empty items and skips hidden fields (i.e. fields starting with the # character)",
112+
optional: true,
113+
},
114+
fields: {
115+
type: "string[]",
116+
label: "Fields",
117+
description: "An array of fields which should be picked from the items, only these fields will remain in the resulting record objects.",
118+
optional: true,
119+
},
120+
omit: {
121+
type: "string[]",
122+
label: "Omit",
123+
description: "An array of fields which should be omitted from the items",
124+
optional: true,
125+
},
126+
flatten: {
127+
type: "string[]",
128+
label: "Flatten",
129+
description: "An array of fields which should transform nested objects into flat structures. For example, with `flatten=\"foo\"` the object `{\"foo\":{\"bar\": \"hello\"}}` is turned into `{\"foo.bar\": \"hello\"}`",
130+
optional: true,
131+
},
132+
maxResults: {
133+
type: "integer",
134+
label: "Max Results",
135+
description: "The maximum number of items to return",
136+
default: LIMIT,
137+
optional: true,
138+
},
89139
},
90140
methods: {
91141
_baseUrl() {
@@ -168,6 +218,28 @@ export default {
168218
...opts,
169219
});
170220
},
221+
listDatasets(opts = {}) {
222+
return this._makeRequest({
223+
path: "/datasets",
224+
...opts,
225+
});
226+
},
227+
listDatasetItems({
228+
datasetId, ...opts
229+
}) {
230+
return this._makeRequest({
231+
path: `/datasets/${datasetId}/items`,
232+
...opts,
233+
});
234+
},
235+
runTaskSynchronously({
236+
taskId, ...opts
237+
}) {
238+
return this._makeRequest({
239+
path: `/actor-tasks/${taskId}/run-sync-get-dataset-items`,
240+
...opts,
241+
});
242+
},
171243
setKeyValueStoreRecord({
172244
storeId, recordKey, ...opts
173245
}) {

components/apify/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/apify",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream Apify Components",
55
"main": "apify.app.mjs",
66
"keywords": [
@@ -13,7 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.6.5"
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}
19-

components/apify/sources/new-finished-actor-run-instant/new-finished-actor-run-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "apify-new-finished-actor-run-instant",
77
name: "New Finished Actor Run (Instant)",
88
description: "Emit new event when a selected actor is run and finishes.",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {

components/apify/sources/new-finished-task-run-instant/new-finished-task-run-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "apify-new-finished-task-run-instant",
77
name: "New Finished Task Run (Instant)",
88
description: "Emit new event when a selected task is run and finishes.",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {

0 commit comments

Comments
 (0)