Skip to content

Commit b637ee8

Browse files
authored
Merge branch 'master' into issue-14568
2 parents 001cd93 + 65d964b commit b637ee8

File tree

245 files changed

+3791
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+3791
-329
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nodejs 18.18.0
1+
nodejs 20.13.1
22
pnpm 9.14.2
33
python 3.11.5
44
poetry 1.6.1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import asters from "../../asters.app.mjs";
2+
3+
export default {
4+
key: "asters-list-labels",
5+
name: "List Labels",
6+
description: "Retrieve the list of all labels of a specific workspace. [See the documentation](https://docs.asters.ai/api/endpoints/labels)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
asters,
11+
workspaceId: {
12+
propDefinition: [
13+
asters,
14+
"workspaceId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const { data } = await this.asters.listLabels({
20+
workspaceId: this.workspaceId,
21+
});
22+
$.export("$summary", `Successfully retrieved ${data.length} label${data.length === 1
23+
? ""
24+
: "s"}`);
25+
return data;
26+
},
27+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import asters from "../../asters.app.mjs";
2+
3+
export default {
4+
key: "asters-list-posts-analytics",
5+
name: "List Posts Analytics",
6+
description: "Retrieve the list of posts' analytics of a social account. [See the documentation](https://docs.asters.ai/api/endpoints/analytics)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
asters,
11+
workspaceId: {
12+
propDefinition: [
13+
asters,
14+
"workspaceId",
15+
],
16+
},
17+
socialAccountId: {
18+
propDefinition: [
19+
asters,
20+
"socialAccountId",
21+
(c) => ({
22+
workspaceId: c.workspaceId,
23+
}),
24+
],
25+
},
26+
fromDate: {
27+
propDefinition: [
28+
asters,
29+
"fromDate",
30+
],
31+
},
32+
toDate: {
33+
propDefinition: [
34+
asters,
35+
"toDate",
36+
],
37+
},
38+
},
39+
async run({ $ }) {
40+
const posts = await this.asters.getPaginatedResources({
41+
fn: this.asters.listPostAnalytics,
42+
args: {
43+
data: {
44+
socialAccountId: this.socialAccountId,
45+
filters: {
46+
date: {
47+
from: this.fromDate,
48+
to: this.toDate,
49+
},
50+
},
51+
},
52+
},
53+
});
54+
$.export("$summary", `Successfully retrieved ${posts.length} post${posts.length === 1
55+
? ""
56+
: "s"}`);
57+
return posts;
58+
},
59+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import asters from "../../asters.app.mjs";
2+
3+
export default {
4+
key: "asters-list-posts",
5+
name: "List Posts",
6+
description: "Retrieve a list of posts of a social profile. [See the documentation](https://docs.asters.ai/api/endpoints/posts)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
asters,
11+
workspaceId: {
12+
propDefinition: [
13+
asters,
14+
"workspaceId",
15+
],
16+
},
17+
socialAccountId: {
18+
propDefinition: [
19+
asters,
20+
"socialAccountId",
21+
(c) => ({
22+
workspaceId: c.workspaceId,
23+
}),
24+
],
25+
},
26+
fromDate: {
27+
propDefinition: [
28+
asters,
29+
"fromDate",
30+
],
31+
},
32+
toDate: {
33+
propDefinition: [
34+
asters,
35+
"toDate",
36+
],
37+
},
38+
},
39+
async run({ $ }) {
40+
const posts = await this.asters.getPaginatedResources({
41+
fn: this.asters.listPosts,
42+
args: {
43+
data: {
44+
socialAccountId: this.socialAccountId,
45+
filters: {
46+
date: {
47+
from: this.fromDate,
48+
to: this.toDate,
49+
},
50+
},
51+
},
52+
},
53+
});
54+
$.export("$summary", `Successfully retrieved ${posts.length} post${posts.length === 1
55+
? ""
56+
: "s"}`);
57+
return posts;
58+
},
59+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import asters from "../../asters.app.mjs";
2+
3+
export default {
4+
key: "asters-list-social-accounts",
5+
name: "List Social Accounts",
6+
description: "Retrieve the list of all social accounts of a specific workspace. [See the documentation](https://docs.asters.ai/api/endpoints/social-accounts)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
asters,
11+
workspaceId: {
12+
propDefinition: [
13+
asters,
14+
"workspaceId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const { data } = await this.asters.listSocialAccounts({
20+
workspaceId: this.workspaceId,
21+
});
22+
$.export("$summary", `Successfully retrieved ${data.length} social account${data.length === 1
23+
? ""
24+
: "s"}`);
25+
return data;
26+
},
27+
};

components/asters/asters.app.mjs

Lines changed: 124 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,131 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "asters",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
workspaceId: {
8+
type: "string",
9+
label: "Workspace ID",
10+
description: "The ID of a workspace",
11+
async options() {
12+
const { data: { workspaces = [] } } = await this.listWorkspaces();
13+
return workspaces.map((workspace) => ({
14+
label: workspace.name,
15+
value: workspace._id,
16+
}));
17+
},
18+
},
19+
socialAccountId: {
20+
type: "string",
21+
label: "Social Account ID",
22+
description: "The ID of a social account",
23+
async options({ workspaceId }) {
24+
const { data = [] } = await this.listSocialAccounts({
25+
workspaceId,
26+
});
27+
return data.map((account) => ({
28+
label: account.name,
29+
value: account.account_id,
30+
}));
31+
},
32+
},
33+
fromDate: {
34+
type: "string",
35+
label: "From Date",
36+
description: "The date to start the search from (YYYY-MM-DD)",
37+
},
38+
toDate: {
39+
type: "string",
40+
label: "To Date",
41+
description: "The date to end the search (YYYY-MM-DD)",
42+
},
43+
},
544
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
45+
_baseUrl() {
46+
return "https://api.asters.ai/api/external/v1.0";
47+
},
48+
_makeRequest({
49+
$ = this, path, ...opts
50+
}) {
51+
return axios($, {
52+
url: `${this._baseUrl()}${path}`,
53+
headers: {
54+
"x-api-key": `${this.$auth.api_key}`,
55+
},
56+
...opts,
57+
});
58+
},
59+
listWorkspaces(opts = {}) {
60+
return this._makeRequest({
61+
path: "/workspaces",
62+
...opts,
63+
});
64+
},
65+
listSocialAccounts({
66+
workspaceId, ...opts
67+
}) {
68+
return this._makeRequest({
69+
path: `/workspaces/${workspaceId}/socialAccounts`,
70+
...opts,
71+
});
72+
},
73+
listLabels({
74+
workspaceId, ...opts
75+
}) {
76+
return this._makeRequest({
77+
path: `/workspaces/${workspaceId}/labels`,
78+
...opts,
79+
});
80+
},
81+
listPosts(opts = {}) {
82+
return this._makeRequest({
83+
method: "POST",
84+
path: "/data/posts",
85+
...opts,
86+
});
87+
},
88+
listPostAnalytics(opts = {}) {
89+
return this._makeRequest({
90+
method: "POST",
91+
path: "/analytics/posts",
92+
...opts,
93+
});
94+
},
95+
async *paginate({
96+
fn, args, max,
97+
}) {
98+
args = {
99+
...args,
100+
data: {
101+
...args?.data,
102+
page: 1,
103+
},
104+
};
105+
let hasMore, count = 0;
106+
do {
107+
const {
108+
data, pagination,
109+
} = await fn(args);
110+
if (!data?.length) {
111+
return;
112+
}
113+
for (const item of data) {
114+
yield item;
115+
if (max && ++count >= max) {
116+
return;
117+
}
118+
}
119+
hasMore = pagination?.totalPages > args.data.page;
120+
args.data.page++;
121+
} while (hasMore);
122+
},
123+
async getPaginatedResources(opts) {
124+
const results = [];
125+
for await (const item of this.paginate(opts)) {
126+
results.push(item);
127+
}
128+
return results;
9129
},
10130
},
11131
};

components/asters/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/asters",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Asters Components",
55
"main": "asters.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import asters from "../../asters.app.mjs";
2+
import {
3+
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
4+
} from "@pipedream/platform";
5+
6+
export default {
7+
props: {
8+
asters,
9+
db: "$.service.db",
10+
timer: {
11+
type: "$.interface.timer",
12+
default: {
13+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14+
},
15+
},
16+
},
17+
methods: {
18+
getResourceFn() {
19+
throw new ConfigurationError("getResourceFn must be implemented");
20+
},
21+
getArgs() {
22+
throw new ConfigurationError("getArgs must be implemented");
23+
},
24+
generateMeta() {
25+
throw new ConfigurationError("generateMeta must be implemented");
26+
},
27+
processResources() {
28+
throw new ConfigurationError("processResources must be implemented");
29+
},
30+
},
31+
async run() {
32+
const resources = await this.asters.getPaginatedResources({
33+
fn: this.getResourceFn(),
34+
args: this.getArgs(),
35+
});
36+
37+
await this.processResources(resources);
38+
},
39+
};

0 commit comments

Comments
 (0)