@pipedream/twitter 0.3.11 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +18 -71
  2. package/dist/actions/add-user-to-list/add-user-to-list.d.ts +194 -0
  3. package/dist/actions/add-user-to-list/add-user-to-list.mjs +44 -0
  4. package/dist/actions/create-tweet/create-tweet.d.ts +101 -0
  5. package/dist/actions/create-tweet/create-tweet.mjs +78 -0
  6. package/dist/actions/delete-tweet/delete-tweet.d.ts +128 -0
  7. package/dist/actions/delete-tweet/delete-tweet.mjs +29 -0
  8. package/dist/actions/follow-user/follow-user.d.ts +131 -0
  9. package/dist/actions/follow-user/follow-user.mjs +37 -0
  10. package/dist/actions/get-tweet/get-tweet.d.ts +132 -0
  11. package/dist/actions/get-tweet/get-tweet.mjs +34 -0
  12. package/dist/actions/get-user/get-user.d.ts +133 -0
  13. package/dist/actions/get-user/get-user.mjs +40 -0
  14. package/dist/actions/like-tweet/like-tweet.d.ts +128 -0
  15. package/dist/actions/like-tweet/like-tweet.mjs +31 -0
  16. package/dist/actions/list-favorites/list-favorites.d.ts +202 -0
  17. package/dist/actions/list-favorites/list-favorites.mjs +50 -0
  18. package/dist/actions/list-followers/list-followers.d.ts +202 -0
  19. package/dist/actions/list-followers/list-followers.mjs +50 -0
  20. package/dist/actions/list-lists/list-lists.d.ts +200 -0
  21. package/dist/actions/list-lists/list-lists.mjs +50 -0
  22. package/dist/actions/list-mentions/list-mentions.d.ts +200 -0
  23. package/dist/actions/list-mentions/list-mentions.mjs +50 -0
  24. package/dist/actions/list-user-tweets/list-user-tweets.d.ts +202 -0
  25. package/dist/actions/list-user-tweets/list-user-tweets.mjs +50 -0
  26. package/dist/actions/retweet/retweet.d.ts +128 -0
  27. package/dist/actions/retweet/retweet.mjs +34 -0
  28. package/dist/actions/simple-search/simple-search.d.ts +201 -0
  29. package/dist/actions/simple-search/simple-search.mjs +50 -0
  30. package/dist/actions/simple-search-in-list/simple-search-in-list.d.ts +206 -0
  31. package/dist/actions/simple-search-in-list/simple-search-in-list.mjs +58 -0
  32. package/dist/actions/unfollow-user/unfollow-user.d.ts +131 -0
  33. package/dist/actions/unfollow-user/unfollow-user.mjs +33 -0
  34. package/dist/actions/unlike-tweet/unlike-tweet.d.ts +128 -0
  35. package/dist/actions/unlike-tweet/unlike-tweet.mjs +29 -0
  36. package/dist/app/twitter.app.d.ts +65 -0
  37. package/dist/app/twitter.app.mjs +291 -0
  38. package/dist/common/additionalProps.d.ts +0 -0
  39. package/dist/common/additionalProps.mjs +138 -0
  40. package/dist/common/dataFields.d.ts +6 -0
  41. package/dist/common/dataFields.mjs +80 -0
  42. package/dist/common/expansions.d.ts +3 -0
  43. package/dist/common/expansions.mjs +17 -0
  44. package/dist/common/methods.d.ts +20 -0
  45. package/dist/common/methods.mjs +69 -0
  46. package/dist/common/types/fields.d.ts +18 -0
  47. package/dist/common/types/fields.mjs +1 -0
  48. package/dist/common/types/requestParams.d.ts +105 -0
  49. package/dist/common/types/requestParams.mjs +1 -0
  50. package/dist/common/types/responseSchemas.d.ts +42 -0
  51. package/dist/common/types/responseSchemas.mjs +1 -0
  52. package/dist/sources/common/base.d.ts +87 -0
  53. package/dist/sources/common/base.mjs +60 -0
  54. package/dist/sources/common/cacheUserId.d.ts +7 -0
  55. package/dist/sources/common/cacheUserId.mjs +18 -0
  56. package/dist/sources/common/getItemSummary.d.ts +4 -0
  57. package/dist/sources/common/getItemSummary.mjs +12 -0
  58. package/dist/sources/new-follower-of-user/new-follower-of-user.d.ts +149 -0
  59. package/dist/sources/new-follower-of-user/new-follower-of-user.mjs +45 -0
  60. package/dist/sources/new-list-followed/new-list-followed.d.ts +149 -0
  61. package/dist/sources/new-list-followed/new-list-followed.mjs +46 -0
  62. package/dist/sources/new-tweet-in-list/new-tweet-in-list.d.ts +147 -0
  63. package/dist/sources/new-tweet-in-list/new-tweet-in-list.mjs +42 -0
  64. package/dist/sources/new-tweet-liked-by-user/new-tweet-liked-by-user.d.ts +149 -0
  65. package/dist/sources/new-tweet-liked-by-user/new-tweet-liked-by-user.mjs +45 -0
  66. package/dist/sources/new-tweet-posted-by-user/new-tweet-posted-by-user.d.ts +149 -0
  67. package/dist/sources/new-tweet-posted-by-user/new-tweet-posted-by-user.mjs +45 -0
  68. package/dist/sources/new-tweet-posted-matching-query/new-tweet-posted-matching-query.d.ts +147 -0
  69. package/dist/sources/new-tweet-posted-matching-query/new-tweet-posted-matching-query.mjs +44 -0
  70. package/dist/sources/new-unfollower-of-user/new-unfollower-of-user.d.ts +149 -0
  71. package/dist/sources/new-unfollower-of-user/new-unfollower-of-user.mjs +75 -0
  72. package/dist/sources/new-user-followed/new-user-followed.d.ts +148 -0
  73. package/dist/sources/new-user-followed/new-user-followed.mjs +46 -0
  74. package/dist/tsconfig.tsbuildinfo +1 -0
  75. package/package.json +10 -14
  76. package/actions/add-user-to-list/add-user-to-list.mjs +0 -62
  77. package/actions/advanced-search/advanced-search.mjs +0 -113
  78. package/actions/common.mjs +0 -29
  79. package/actions/create-tweet/create-tweet.mjs +0 -146
  80. package/actions/delete-tweet/delete-tweet.mjs +0 -42
  81. package/actions/follow-user/follow-user.mjs +0 -48
  82. package/actions/get-tweet/get-tweet.mjs +0 -42
  83. package/actions/get-user/get-user.mjs +0 -50
  84. package/actions/like-tweet/like-tweet.mjs +0 -42
  85. package/actions/list-favorites/list-favorites.mjs +0 -63
  86. package/actions/list-followers/list-followers.mjs +0 -67
  87. package/actions/list-lists/list-lists.mjs +0 -69
  88. package/actions/list-mentions/list-mentions.mjs +0 -55
  89. package/actions/list-pending-followers/list-pending-followers.mjs +0 -32
  90. package/actions/list-retweets/list-retweets.mjs +0 -54
  91. package/actions/list-user-tweets/list-user-tweets.mjs +0 -80
  92. package/actions/retweet/retweet.mjs +0 -27
  93. package/actions/simple-search/simple-search.mjs +0 -62
  94. package/actions/simple-search-in-list/simple-search-in-list.mjs +0 -48
  95. package/actions/unfollow-user/unfollow-user.mjs +0 -48
  96. package/actions/unlike-tweet/unlike-tweet.mjs +0 -40
  97. package/actions/upload-media/upload-media.mjs +0 -122
  98. package/old.md +0 -169
  99. package/sources/common/followed.mjs +0 -38
  100. package/sources/common/followers.mjs +0 -159
  101. package/sources/common/tweets.mjs +0 -155
  102. package/sources/language-codes.mjs +0 -742
  103. package/sources/my-liked-tweets/my-liked-tweets.mjs +0 -30
  104. package/sources/my-tweets/my-tweets.mjs +0 -48
  105. package/sources/new-follower-of-me/new-follower-of-me.mjs +0 -69
  106. package/sources/new-follower-of-user/new-follower-of-user.mjs +0 -25
  107. package/sources/new-list-followed/new-list-followed.mjs +0 -24
  108. package/sources/new-trends-by-geo/new-trends-by-geo.mjs +0 -40
  109. package/sources/new-tweet-in-list/new-tweet-in-list.mjs +0 -49
  110. package/sources/new-unfollower-of-me/new-unfollower-of-me.mjs +0 -16
  111. package/sources/new-unfollower-of-user/new-unfollower-of-user.mjs +0 -25
  112. package/sources/new-user-followed/new-user-followed.mjs +0 -25
  113. package/sources/search-mentions/search-mentions.mjs +0 -144
  114. package/sources/tweets-liked-by-user/tweets-liked-by-user.mjs +0 -38
  115. package/sources/user-tweets/user-tweets.mjs +0 -49
  116. package/sources/watch-retweets-of-me/watch-retweets-of-me.mjs +0 -36
  117. package/sources/watch-retweets-of-my-tweet/watch-retweets-of-my-tweet.mjs +0 -44
  118. package/sources/watch-retweets-of-user-tweet/watch-retweets-of-user-tweet.mjs +0 -34
  119. package/twitter.app.mjs +0 -1161
@@ -1,38 +0,0 @@
1
- import twitter from "../../twitter.app.mjs";
2
- import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3
-
4
- export default {
5
- props: {
6
- twitter,
7
- db: "$.service.db",
8
- timer: {
9
- label: "Polling interval",
10
- description: "Pipedream will poll the Twitter API on this schedule",
11
- type: "$.interface.timer",
12
- default: {
13
- intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14
- },
15
- },
16
- },
17
- methods: {
18
- _getPreviousIds() {
19
- return this.db.get("previousIds") || [];
20
- },
21
- _setPreviousIds(previousIds) {
22
- this.db.set("previousIds", previousIds);
23
- },
24
- },
25
- async run() {
26
- const previousIds = this._getPreviousIds();
27
- const followedItems = await this.getFollowed();
28
- for (const item of followedItems.reverse()) {
29
- if (previousIds.includes(item.id)) {
30
- continue;
31
- }
32
- previousIds.push(item.id);
33
- const meta = this.generateMeta(item);
34
- this.$emit(item, meta);
35
- }
36
- this._setPreviousIds(previousIds);
37
- },
38
- };
@@ -1,159 +0,0 @@
1
- import twitter from "../../twitter.app.mjs";
2
- import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3
-
4
- export default {
5
- props: {
6
- db: "$.service.db",
7
- twitter,
8
- timer: {
9
- label: "Polling interval",
10
- description: "Pipedream will poll the Twitter API on this schedule",
11
- type: "$.interface.timer",
12
- default: {
13
- intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14
- },
15
- },
16
- },
17
- hooks: {
18
- async activate() {
19
- await this._provisionFollowersCache();
20
- },
21
- },
22
- deactivate() {
23
- this._clearFollowersCache();
24
- },
25
- methods: {
26
- /**
27
- * This method returns the size of the internal cache used by the event
28
- * source to keep track of the latest Twitter followers of the corresponding
29
- * account.
30
- *
31
- * The size represents the maximum amount of entries/ID's that will be
32
- * cached at any given time (or 0 for unlimited). Keep in mind that the
33
- * Pipedream platform itself imposes size limits as well in terms of DB
34
- * usage.
35
- *
36
- * @returns The maximum amount of Twitter followers entries to be cached at
37
- * any given moment (or 0 for unlimited).
38
- */
39
- getFollowersCacheSize() {
40
- return 0;
41
- },
42
- getScreenName() {
43
- // When screen name is not explicitly provided, the Twitter API defaults
44
- // it to the user making the API request
45
- return undefined;
46
- },
47
- /**
48
- * This function provides the list of relevant, follower-related, user ID's
49
- * that are used by the event source to emit events. How each event source
50
- * that implements it depends on the purpose of the event source itself. For
51
- * example, an event source that emits an event for every new follower will
52
- * implement this function in such a way that its result is a list of user
53
- * ID's for each new follower detected.
54
- *
55
- * @returns the list of relevant user ID's for this event source to process
56
- */
57
- getRelevantIds() {
58
- return [];
59
- },
60
- generateMeta(data) {
61
- const {
62
- timestamp,
63
- user,
64
- } = data;
65
- const {
66
- id_str: id,
67
- screen_name: summary,
68
- } = user;
69
- // Event timestamp is expressed in seconds, whereas Javascript timestamps
70
- // are expressed in milliseconds
71
- const ts = timestamp * 1000;
72
- return {
73
- id,
74
- summary,
75
- ts,
76
- };
77
- },
78
- _clearFollowersCache() {
79
- this.setFollowersCache([]);
80
- },
81
- async _provisionFollowersCache() {
82
- const screenName = this.getScreenName();
83
- const followerIdsGen = this.twitter.scanFollowerIds(screenName);
84
- const maxFollowerListSize = Math.max(this.getFollowersCacheSize(), 0);
85
- const result = [];
86
- for await (const id of followerIdsGen) {
87
- if (maxFollowerListSize !== 0 && maxFollowerListSize === result.length) {
88
- break;
89
- }
90
-
91
- result.push(id);
92
- }
93
-
94
- this.setFollowersCache(result);
95
- return result;
96
- },
97
- getFollowersCache() {
98
- return this.db.get("followers");
99
- },
100
- setFollowersCache(followers) {
101
- const followersCacheSize = Math.max(this.getFollowersCacheSize(), 0);
102
- const trimmedFollowers = followersCacheSize !== 0
103
- ? followers.slice(0, followersCacheSize)
104
- : followers;
105
- this.db.set("followers", trimmedFollowers);
106
- console.log(`
107
- Updated followers cache: ${trimmedFollowers.length} records
108
- `);
109
- },
110
- /**
111
- * This generator method scans the list of Twitter followers until it finds
112
- * the ID of a follower that was already processed.
113
- *
114
- * @param {string[]} processedFollowerIds a list of the ID's of the most
115
- * recent Twitter followers processed by the event source
116
- * @yields the ID of a new Twitter follower
117
- */
118
- async *scanNewFollowers(processedFollowerIds = []) {
119
- const processeedFollowerIdsSet = new Set(processedFollowerIds);
120
- const screenName = this.getScreenName();
121
- const followerIdsGen = this.twitter.scanFollowerIds(screenName);
122
- for await (const id of followerIdsGen) {
123
- if (processeedFollowerIdsSet.has(id)) {
124
- break;
125
- }
126
- yield id;
127
- }
128
- },
129
- async getUnfollowers() {
130
- const prevFollowers = this.getFollowersCache();
131
- const currFollowers = await this._provisionFollowersCache();
132
- const currFollowersSet = new Set(currFollowers);
133
- return prevFollowers.filter((pf) => !currFollowersSet.has(pf));
134
- },
135
- },
136
- async run(event) {
137
- const { timestamp } = event;
138
- const relevantIds = await this.getRelevantIds();
139
- if (relevantIds.length <= 0) {
140
- console.log(`
141
- No changes in followers data for this event source to emit a new event
142
- `);
143
- return;
144
- }
145
-
146
- const users = await this.twitter.lookupUsers({
147
- userIdArray: relevantIds,
148
- });
149
- users.forEach((user) => {
150
- const data = {
151
- timestamp,
152
- user,
153
- };
154
- user.profile_url = `https://twitter.com/${user.screen_name}/`;
155
- const meta = this.generateMeta(data);
156
- this.$emit(user, meta);
157
- });
158
- },
159
- };
@@ -1,155 +0,0 @@
1
- import twitter from "../../twitter.app.mjs";
2
- import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3
-
4
- export default {
5
- props: {
6
- db: "$.service.db",
7
- twitter,
8
- count: {
9
- propDefinition: [
10
- twitter,
11
- "count",
12
- ],
13
- },
14
- maxRequests: {
15
- propDefinition: [
16
- twitter,
17
- "maxRequests",
18
- ],
19
- },
20
- timer: {
21
- label: "Polling interval",
22
- description: "Pipedream will poll the Twitter API on this schedule",
23
- type: "$.interface.timer",
24
- default: {
25
- intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
26
- },
27
- },
28
- },
29
- methods: {
30
- _compareByIdAsc({ id_str: a }, { id_str: b }) {
31
- const A = BigInt(a);
32
- const B = BigInt(b);
33
- if (A < B) return -1;
34
- if (A > B) return 1;
35
- return 0;
36
- },
37
- sortTweets(tweets) {
38
- return tweets
39
- .sort(this._compareByIdAsc);
40
- },
41
- /**
42
- * This function returns the Twitter screen name of the subject account
43
- *
44
- * @returns a string containing the relevant Twitter screen name
45
- */
46
- getScreenName() {
47
- throw new Error("getScreenName is not implemented");
48
- },
49
- /**
50
- * This function provides the list of options for the `tweetId` user prop.
51
- * It is meant to be called by Pipedream during the setup of the user prop
52
- * and not during normal operations of the event source.
53
- *
54
- * @param {object} context the context object for the pagination of the
55
- * prop options
56
- * @param {object} context.prevContext the context object of a previous
57
- * call to this method
58
- * @returns an object containing the list of Tweet ID options for the
59
- * `tweetId` user prop and the context for pagination
60
- */
61
- async tweetIdOptions(context) {
62
- const { prevContext = {} } = context;
63
- const {
64
- screenName = await this.getScreenName(),
65
- sinceId = "1",
66
- } = prevContext;
67
-
68
- const userTimelineOpts = {
69
- screenName,
70
- sinceId,
71
- count: 10,
72
- trim_user: true,
73
- exclude_replies: false,
74
- include_rts: false,
75
- };
76
- const tweets = await this.twitter.getUserTimeline(userTimelineOpts);
77
- if (tweets.length === 0) {
78
- // There are no more tweets to go through
79
- return {
80
- options: null,
81
- context: prevContext,
82
- };
83
- }
84
-
85
- const sortedTweets = this.sortTweets(tweets);
86
- const { id_str: lastId } = sortedTweets[sortedTweets.length - 1];
87
- const options = sortedTweets.map(({
88
- full_text: fullText,
89
- id_str: idStr,
90
- }) => ({
91
- label: fullText,
92
- value: idStr,
93
- }));
94
-
95
- return {
96
- options,
97
- context: {
98
- screenName,
99
- sinceId: lastId,
100
- },
101
- };
102
- },
103
- getSinceId() {
104
- return this.db.get("sinceId") || "1";
105
- },
106
- setSinceId(sinceId = "1") {
107
- this.db.set("sinceId", sinceId);
108
- },
109
- generateMeta(tweet) {
110
- const {
111
- created_at: createdAt,
112
- full_text: fullText,
113
- id_str: id,
114
- text,
115
- } = tweet;
116
- const summary = fullText || text;
117
- const ts = this.twitter.parseDate(createdAt);
118
- return {
119
- id,
120
- summary,
121
- ts,
122
- };
123
- },
124
- /**
125
- * The purpose of this function is to retrieve the relevant Tweets for the
126
- * event source that implements it. For example, if the event source emits
127
- * an event for each new Tweet of a specific user, the implementation of
128
- * this function will perform the retrieval of such Tweets and return it as
129
- * a list of [Tweet
130
- * objects](https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/tweet)
131
- *
132
- * @returns a list of Tweet objects for which to emit new events
133
- */
134
- retrieveTweets() {
135
- throw new Error("retrieveTweets is not implemented");
136
- },
137
- },
138
- async run() {
139
- const tweets = await this.retrieveTweets();
140
- if (tweets.length === 0) {
141
- console.log("No new tweets available. Skipping...");
142
- return;
143
- }
144
-
145
- const sortedTweets = this.sortTweets(tweets);
146
- const { id_str: lastId } = sortedTweets[sortedTweets.length - 1];
147
- this.setSinceId(lastId);
148
-
149
- // Emit array of tweet objects
150
- sortedTweets.forEach((tweet) => {
151
- const meta = this.generateMeta(tweet);
152
- this.$emit(tweet, meta);
153
- });
154
- },
155
- };