@pipedream/twitter 2.3.2 → 2.3.4

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 (94) hide show
  1. package/dist/actions/add-user-to-list/add-user-to-list.mjs +545 -45
  2. package/dist/actions/create-tweet/create-tweet.mjs +542 -76
  3. package/dist/actions/delete-tweet/delete-tweet.mjs +513 -29
  4. package/dist/actions/follow-user/follow-user.mjs +538 -38
  5. package/dist/actions/get-tweet/get-tweet.mjs +622 -35
  6. package/dist/actions/get-user/get-user.mjs +596 -39
  7. package/dist/actions/like-tweet/like-tweet.mjs +515 -31
  8. package/dist/actions/list-favorites/list-favorites.mjs +657 -51
  9. package/dist/actions/list-followers/list-followers.mjs +614 -51
  10. package/dist/actions/list-lists/list-lists.mjs +597 -51
  11. package/dist/actions/list-mentions/list-mentions.mjs +657 -51
  12. package/dist/actions/list-user-tweets/list-user-tweets.mjs +657 -51
  13. package/dist/actions/retweet/retweet.mjs +519 -34
  14. package/dist/actions/send-dm/send-dm.mjs +546 -44
  15. package/dist/actions/simple-search/simple-search.mjs +646 -51
  16. package/dist/actions/simple-search-in-list/simple-search-in-list.mjs +656 -58
  17. package/dist/actions/unfollow-user/unfollow-user.mjs +533 -34
  18. package/dist/actions/unlike-tweet/unlike-tweet.mjs +513 -29
  19. package/dist/actions/upload-media/upload-media.mjs +549 -52
  20. package/dist/app/twitter.app.mjs +443 -342
  21. package/dist/common/addObjIncludes.mjs +89 -63
  22. package/dist/common/additionalProps.mjs +0 -138
  23. package/dist/common/appValidation.mjs +475 -24
  24. package/dist/common/constants.mjs +11 -7
  25. package/dist/common/dataFields.mjs +100 -89
  26. package/dist/common/errorMessage.mjs +32 -26
  27. package/dist/common/expansions.mjs +26 -19
  28. package/dist/common/methods.mjs +170 -81
  29. package/dist/common/types/fields.mjs +0 -1
  30. package/dist/common/types/includeMapping.mjs +0 -1
  31. package/dist/common/types/requestParams.mjs +0 -1
  32. package/dist/common/types/responseSchemas.mjs +0 -1
  33. package/dist/sources/common/base.mjs +546 -69
  34. package/dist/sources/common/cacheUserId.mjs +32 -15
  35. package/dist/sources/common/getItemSummary.mjs +13 -9
  36. package/dist/sources/new-follower-of-user/new-follower-of-user.mjs +799 -40
  37. package/dist/sources/new-list-followed/new-list-followed.mjs +722 -41
  38. package/dist/sources/new-mention-received-by-user/new-mention-received-by-user.mjs +860 -40
  39. package/dist/sources/new-message/new-message.mjs +738 -32
  40. package/dist/sources/new-tweet-in-list/new-tweet-in-list.mjs +839 -37
  41. package/dist/sources/new-tweet-liked-by-user/new-tweet-liked-by-user.mjs +860 -40
  42. package/dist/sources/new-tweet-metrics/new-tweet-metrics.mjs +629 -59
  43. package/dist/sources/new-tweet-posted-by-user/new-tweet-posted-by-user.mjs +860 -40
  44. package/dist/sources/new-tweet-posted-matching-query/new-tweet-posted-matching-query.mjs +830 -39
  45. package/dist/sources/new-unfollower-of-user/new-unfollower-of-user.mjs +829 -70
  46. package/dist/sources/new-user-followed/new-user-followed.mjs +737 -41
  47. package/package.json +3 -3
  48. package/dist/actions/add-user-to-list/add-user-to-list.d.ts +0 -6
  49. package/dist/actions/create-tweet/create-tweet.d.ts +0 -105
  50. package/dist/actions/delete-tweet/delete-tweet.d.ts +0 -4
  51. package/dist/actions/follow-user/follow-user.d.ts +0 -6
  52. package/dist/actions/get-tweet/get-tweet.d.ts +0 -6
  53. package/dist/actions/get-user/get-user.d.ts +0 -7
  54. package/dist/actions/like-tweet/like-tweet.d.ts +0 -4
  55. package/dist/actions/list-favorites/list-favorites.d.ts +0 -10
  56. package/dist/actions/list-followers/list-followers.d.ts +0 -10
  57. package/dist/actions/list-lists/list-lists.d.ts +0 -8
  58. package/dist/actions/list-mentions/list-mentions.d.ts +0 -10
  59. package/dist/actions/list-user-tweets/list-user-tweets.d.ts +0 -10
  60. package/dist/actions/retweet/retweet.d.ts +0 -4
  61. package/dist/actions/send-dm/send-dm.d.ts +0 -6
  62. package/dist/actions/simple-search/simple-search.d.ts +0 -9
  63. package/dist/actions/simple-search-in-list/simple-search-in-list.d.ts +0 -9
  64. package/dist/actions/unfollow-user/unfollow-user.d.ts +0 -6
  65. package/dist/actions/unlike-tweet/unlike-tweet.d.ts +0 -4
  66. package/dist/actions/upload-media/upload-media.d.ts +0 -4
  67. package/dist/app/twitter.app.d.ts +0 -69
  68. package/dist/common/addObjIncludes.d.ts +0 -9
  69. package/dist/common/additionalProps.d.ts +0 -0
  70. package/dist/common/appValidation.d.ts +0 -144
  71. package/dist/common/constants.d.ts +0 -7
  72. package/dist/common/dataFields.d.ts +0 -8
  73. package/dist/common/errorMessage.d.ts +0 -25
  74. package/dist/common/expansions.d.ts +0 -4
  75. package/dist/common/methods.d.ts +0 -27
  76. package/dist/common/types/fields.d.ts +0 -25
  77. package/dist/common/types/includeMapping.d.ts +0 -11
  78. package/dist/common/types/requestParams.d.ts +0 -126
  79. package/dist/common/types/responseSchemas.d.ts +0 -82
  80. package/dist/sources/common/base.d.ts +0 -163
  81. package/dist/sources/common/cacheUserId.d.ts +0 -7
  82. package/dist/sources/common/getItemSummary.d.ts +0 -4
  83. package/dist/sources/new-follower-of-user/new-follower-of-user.d.ts +0 -17
  84. package/dist/sources/new-list-followed/new-list-followed.d.ts +0 -17
  85. package/dist/sources/new-mention-received-by-user/new-mention-received-by-user.d.ts +0 -17
  86. package/dist/sources/new-message/new-message.d.ts +0 -15
  87. package/dist/sources/new-tweet-in-list/new-tweet-in-list.d.ts +0 -15
  88. package/dist/sources/new-tweet-liked-by-user/new-tweet-liked-by-user.d.ts +0 -17
  89. package/dist/sources/new-tweet-metrics/new-tweet-metrics.d.ts +0 -13
  90. package/dist/sources/new-tweet-posted-by-user/new-tweet-posted-by-user.d.ts +0 -17
  91. package/dist/sources/new-tweet-posted-matching-query/new-tweet-posted-matching-query.d.ts +0 -15
  92. package/dist/sources/new-unfollower-of-user/new-unfollower-of-user.d.ts +0 -17
  93. package/dist/sources/new-user-followed/new-user-followed.d.ts +0 -17
  94. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,78 +1,555 @@
1
+ // components/twitter/sources/common/base.ts
1
2
  import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
- import common from "../../common/appValidation.mjs";
3
- import { ERROR_MESSAGE } from "../../common/errorMessage.mjs";
4
- export default {
5
- ...common,
6
- props: {
7
- ...common.props,
8
- db: "$.service.db",
9
- timer: {
10
- type: "$.interface.timer",
11
- default: {
12
- intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
13
- },
14
- },
3
+
4
+ // components/twitter/app/twitter.app.ts
5
+ import OAuth from "oauth-1.0a";
6
+ import crypto from "crypto";
7
+ import { defineApp } from "@pipedream/types";
8
+ import {
9
+ axios,
10
+ transformConfigForOauth,
11
+ ConfigurationError
12
+ } from "@pipedream/platform";
13
+
14
+ // components/twitter/common/errorMessage.ts
15
+ var ERROR_URL = "https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#item0";
16
+ var ERROR_MESSAGE = `Check if your app is properly configured on the [Twitter Developer Portal](${ERROR_URL}), and if your plan has access to the endpoint used by this component.`;
17
+ var ACTION_ERROR_MESSAGE = `${ERROR_MESSAGE} Additional debugging information has been exported from the step.`;
18
+ var PROBLEM_BASE_URL = "https://api.twitter.com/2/problems";
19
+ var ERROR_BY_TYPE = {
20
+ [`${PROBLEM_BASE_URL}/client-forbidden`]: "This X (Twitter) account appears to be on the Free plan, which only has access to **Create Tweets**. [Refer to Twitter's developer docs](https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve) for the latest info on API access.",
21
+ ["about:blank"]: "A generic problem with no additional information beyond that provided by the HTTP status code.",
22
+ [`${PROBLEM_BASE_URL}/invalid-request`]: "A problem that indicates this request is invalid. If your request takes a POST body, ensure the contents is valid JSON and matches the [OpenAPI spec](https://api.twitter.com/2/openapi.json).",
23
+ [`${PROBLEM_BASE_URL}/resource-not-found`]: "A problem that indicates that a given Post, User, etc. does not exist.",
24
+ [`${PROBLEM_BASE_URL}/not-authorized-for-resource`]: "A problem that indicates you are not allowed to see a particular Post, User, etc.",
25
+ [`${PROBLEM_BASE_URL}/disallowed-resource`]: "A problem that indicates that the resource requested violates the precepts of this API.",
26
+ [`${PROBLEM_BASE_URL}/unsupported-authentication`]: "A problem that indicates that the authentication used is not supported.",
27
+ [`${PROBLEM_BASE_URL}/usage-capped`]: "A problem that indicates that a usage cap has been exceeded.",
28
+ [`${PROBLEM_BASE_URL}/streaming-connection`]: "A problem that indicates something is wrong with the connection.",
29
+ [`${PROBLEM_BASE_URL}/client-disconnected`]: "Your client has gone away.",
30
+ [`${PROBLEM_BASE_URL}/operational-disconnect`]: "You have been disconnected for operational reasons.",
31
+ [`${PROBLEM_BASE_URL}/rule-cap`]: "You have exceeded the maximum number of rules.",
32
+ [`${PROBLEM_BASE_URL}/rule-length`]: "You have exceeded the maximum number of characters allowed on your query or rule based on your access level. See [access levels](https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api.html#Access).",
33
+ [`${PROBLEM_BASE_URL}/invalid-rules`]: "The rule you have submitted is invalid.",
34
+ [`${PROBLEM_BASE_URL}/duplicate-rules`]: "The rule you have submitted is a duplicate.",
35
+ [`${PROBLEM_BASE_URL}/conflict`]: "The rule you have submitted is in conflict with another rule.",
36
+ [`${PROBLEM_BASE_URL}/noncompliant-rules`]: "The rule you have submitted is not compliant with Twitter's Automation Rules",
37
+ [`${PROBLEM_BASE_URL}/not-authorized-for-field`]: "A problem that indicates you are not allowed to see a particular field.",
38
+ [`${PROBLEM_BASE_URL}/oauth1-permissions`]: "A problem that indicates you are not allowed to see a particular field.",
39
+ [`${PROBLEM_BASE_URL}/resource-unavailable`]: "A problem that indicates that a given Post, User, etc. is temporarily unavailable."
40
+ };
41
+
42
+ // components/twitter/app/twitter.app.ts
43
+ var twitter_app_default = defineApp({
44
+ type: "app",
45
+ app: "twitter",
46
+ propDefinitions: {
47
+ maxResults: {
48
+ type: "integer",
49
+ label: "Max Results",
50
+ description: "Maximum amount of items to return. The maximum amount per request for each endpoint is included in the API documentation.",
51
+ optional: true
15
52
  },
16
- hooks: {
17
- async deploy() {
18
- const q = "Pipedream";
19
- const data = await this.getRecentTweets({
20
- params: {
21
- query: q,
22
- },
23
- validateStatus: () => true,
24
- });
25
- this.app.throwError(data);
26
- await this.getAndProcessData();
27
- },
53
+ listId: {
54
+ type: "string",
55
+ label: "List ID",
56
+ description: "Select a **List** owned by the authenticated user, or use a custom *List ID*.",
57
+ async options() {
58
+ const userId = await this.getAuthenticatedUserId();
59
+ const lists = await this.getUserOwnedLists({
60
+ userId
61
+ });
62
+ return lists.data?.map(({
63
+ id,
64
+ name
65
+ }) => ({
66
+ label: name,
67
+ value: id
68
+ })) ?? [];
69
+ }
28
70
  },
29
- methods: {
30
- ...common.methods,
31
- getEntityName() {
32
- return "Entity";
33
- },
34
- getItemSummary() {
35
- throw new Error("getItemSummary() not implemented in component");
36
- },
37
- async getResources() {
38
- throw new Error("getResources() not implemented in component");
39
- },
40
- getSavedIds() {
41
- return this.db.get("savedEntityIds");
42
- },
43
- setSavedIds(data) {
44
- this.db.set("savedEntityIds", data);
45
- },
46
- async getAndProcessData(maxResults) {
47
- const data = await this.getResources(maxResults);
48
- if (data) {
49
- const savedIds = this.getSavedIds() ?? [];
50
- data
51
- .filter(({ id }) => !savedIds.includes(id))
52
- .reverse()
53
- .forEach((obj) => {
54
- this.emitEvent(obj);
55
- savedIds.push(obj.id);
56
- });
57
- this.setSavedIds(savedIds);
58
- }
59
- },
60
- emitEvent(data) {
61
- const ts = Date.now();
62
- const { id } = data;
63
- this.$emit(data, {
64
- id,
65
- summary: `New ${this.getEntityName()}: "${this.getItemSummary(data)}"`,
66
- ts,
67
- });
68
- },
71
+ userNameOrId: {
72
+ type: "string",
73
+ label: "User Name or ID",
74
+ description: "A Twitter username (handle) prefixed with `@` (e.g. `@pipedream`). You can also use the string `me` to use the authenticated user (default), or a numeric User ID.",
75
+ optional: true,
76
+ default: "me"
77
+ },
78
+ // See comment on "../common/additionalProps.ts"
79
+ /*
80
+ includeAllFields: {
81
+ type: "boolean",
82
+ label: "Include All Metadata",
83
+ description: "If set to `false`, you can choose which fields will be returned for each data type.",
84
+ optional: true,
85
+ default: true,
86
+ reloadProps: true,
69
87
  },
70
- async run() {
88
+ */
89
+ tweetId: {
90
+ type: "string",
91
+ label: "Tweet ID",
92
+ description: "The numerical ID of the tweet."
93
+ },
94
+ query: {
95
+ type: "string",
96
+ label: "Query",
97
+ description: "One query for matching Tweets. See the [Twitter API guide on building queries](https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query)."
98
+ }
99
+ },
100
+ methods: {
101
+ throwError(data) {
102
+ const errorMessage = ERROR_BY_TYPE[data?.type];
103
+ if (!errorMessage) {
104
+ return;
105
+ }
106
+ throw new ConfigurationError(errorMessage);
107
+ },
108
+ _getAuthHeader(config) {
109
+ const {
110
+ developer_consumer_key: devKey,
111
+ developer_consumer_secret: devSecret,
112
+ oauth_access_token: key,
113
+ oauth_refresh_token: secret
114
+ } = this.$auth;
115
+ const consumer = {
116
+ key: devKey,
117
+ secret: devSecret
118
+ };
119
+ const oauth = new OAuth({
120
+ consumer,
121
+ signature_method: "HMAC-SHA1",
122
+ hash_function(base_string, key2) {
123
+ return crypto.createHmac("sha1", key2).update(base_string).digest("base64");
124
+ }
125
+ });
126
+ const token = {
127
+ key,
128
+ secret
129
+ };
130
+ const requestData = transformConfigForOauth(config);
131
+ return oauth.toHeader(oauth.authorize(requestData, token));
132
+ },
133
+ _getBaseUrl() {
134
+ return "https://api.twitter.com/2";
135
+ },
136
+ async _httpRequest({
137
+ $ = this,
138
+ headers,
139
+ specialAuth = false,
140
+ throwError = true,
141
+ fallbackError,
142
+ ...args
143
+ }) {
144
+ const maxRetries = 3;
145
+ let response;
146
+ let counter = 1;
147
+ const config = {
148
+ baseURL: this._getBaseUrl(),
149
+ ...args
150
+ };
151
+ const authConfig = specialAuth ? {
152
+ ...config,
153
+ params: {},
154
+ data: {}
155
+ } : config;
156
+ const axiosConfig = {
157
+ debug: true,
158
+ ...config,
159
+ headers: {
160
+ ...headers,
161
+ ...this._getAuthHeader(authConfig)
162
+ }
163
+ };
164
+ do {
71
165
  try {
72
- await this.getAndProcessData(50);
166
+ response = await axios($, axiosConfig);
167
+ } catch (err) {
168
+ console.log(`Request error on attempt #${counter}: `, err);
169
+ if (counter === maxRetries) {
170
+ if (throwError && err.response?.data) {
171
+ this.throwError(err.response.data);
172
+ }
173
+ if (fallbackError) {
174
+ throw new ConfigurationError(fallbackError);
175
+ }
176
+ throw err;
177
+ }
178
+ }
179
+ } while (!response && ++counter <= maxRetries);
180
+ return response;
181
+ },
182
+ async _paginatedRequest({
183
+ maxResults = 100,
184
+ maxPerPage = 100,
185
+ params,
186
+ ...args
187
+ }) {
188
+ const totalData = [], totalErrors = [], totalIncludes = {};
189
+ let paginationToken;
190
+ let resultCount = 0;
191
+ do {
192
+ const perPage = Math.min(maxResults - resultCount, maxPerPage);
193
+ const {
194
+ data,
195
+ errors,
196
+ meta: { next_token },
197
+ includes
198
+ } = await this._httpRequest({
199
+ params: {
200
+ ...params,
201
+ max_results: perPage,
202
+ pagination_token: paginationToken
203
+ },
204
+ ...args
205
+ });
206
+ if (data) {
207
+ totalData.push(...Array.isArray(data) ? data : [
208
+ data
209
+ ]);
73
210
  }
74
- catch (err) {
75
- throw new Error(`${ERROR_MESSAGE} Error response: ${JSON.stringify(err)}`);
211
+ if (errors) {
212
+ totalErrors.push(...Array.isArray(errors) ? errors : [
213
+ errors
214
+ ]);
76
215
  }
216
+ if (includes) {
217
+ Object.entries(includes).forEach(
218
+ ([
219
+ key,
220
+ value
221
+ ]) => {
222
+ if (!totalIncludes[key]) totalIncludes[key] = [];
223
+ totalIncludes[key].push(...value);
224
+ }
225
+ );
226
+ }
227
+ paginationToken = next_token;
228
+ resultCount += perPage;
229
+ } while (paginationToken && resultCount < maxResults);
230
+ return {
231
+ data: totalData,
232
+ errors: totalErrors,
233
+ includes: totalIncludes
234
+ };
235
+ },
236
+ async addUserToList({
237
+ listId,
238
+ ...args
239
+ }) {
240
+ return this._httpRequest({
241
+ method: "POST",
242
+ url: `/lists/${listId}/members`,
243
+ ...args
244
+ });
245
+ },
246
+ async createTweet(args) {
247
+ return this._httpRequest({
248
+ throwError: false,
249
+ method: "POST",
250
+ url: "/tweets",
251
+ ...args
252
+ });
253
+ },
254
+ async deleteTweet({
255
+ tweetId,
256
+ ...args
257
+ }) {
258
+ return this._httpRequest({
259
+ method: "DELETE",
260
+ url: `/tweets/${tweetId}`,
261
+ ...args
262
+ });
263
+ },
264
+ async followUser(args) {
265
+ const id = await this.getAuthenticatedUserId();
266
+ return this._httpRequest({
267
+ method: "POST",
268
+ url: `/users/${id}/following`,
269
+ ...args
270
+ });
271
+ },
272
+ async getListTweets({
273
+ listId,
274
+ ...args
275
+ }) {
276
+ return this._paginatedRequest({
277
+ url: `/lists/${listId}/tweets`,
278
+ ...args
279
+ });
77
280
  },
281
+ async getTweet({
282
+ tweetId,
283
+ ...args
284
+ }) {
285
+ return this._httpRequest({
286
+ url: `/tweets/${tweetId}`,
287
+ ...args
288
+ });
289
+ },
290
+ async getAuthenticatedUser(args) {
291
+ return this._httpRequest({
292
+ url: "/users/me",
293
+ ...args
294
+ });
295
+ },
296
+ async getAuthenticatedUserId() {
297
+ const response = await this.getAuthenticatedUser();
298
+ return response.data.id;
299
+ },
300
+ async getDirectMessages(args) {
301
+ return this._paginatedRequest({
302
+ url: "/dm_events",
303
+ ...args
304
+ });
305
+ },
306
+ async getUserLikedTweets({
307
+ userId,
308
+ ...args
309
+ }) {
310
+ return this._paginatedRequest({
311
+ url: `/users/${userId}/liked_tweets`,
312
+ ...args
313
+ });
314
+ },
315
+ async getUserOwnedLists({
316
+ userId,
317
+ ...args
318
+ }) {
319
+ return this._httpRequest({
320
+ url: `/users/${userId}/owned_lists`,
321
+ ...args
322
+ });
323
+ },
324
+ async getUserFollowedLists({
325
+ userId,
326
+ ...args
327
+ }) {
328
+ return this._paginatedRequest({
329
+ url: `/users/${userId}/followed_lists`,
330
+ ...args
331
+ });
332
+ },
333
+ async getUserMentions({
334
+ userId,
335
+ ...args
336
+ }) {
337
+ return this._paginatedRequest({
338
+ url: `/users/${userId}/mentions`,
339
+ ...args
340
+ });
341
+ },
342
+ async getUserTweets({
343
+ userId,
344
+ ...args
345
+ }) {
346
+ return this._paginatedRequest({
347
+ url: `/users/${userId}/tweets`,
348
+ ...args
349
+ });
350
+ },
351
+ async getUserByUsername(username) {
352
+ return this._httpRequest({
353
+ url: `/users/by/username/${username}`
354
+ });
355
+ },
356
+ async getUser({
357
+ userId,
358
+ ...args
359
+ }) {
360
+ return this._httpRequest({
361
+ url: `/users/${userId}`,
362
+ ...args
363
+ });
364
+ },
365
+ async likeTweet(args) {
366
+ const id = await this.getAuthenticatedUserId();
367
+ return this._httpRequest({
368
+ method: "POST",
369
+ url: `/users/${id}/likes`,
370
+ ...args
371
+ });
372
+ },
373
+ async getUserFollowers({
374
+ userId,
375
+ ...args
376
+ }) {
377
+ return this._paginatedRequest({
378
+ url: `/users/${userId}/followers`,
379
+ ...args
380
+ });
381
+ },
382
+ async getUserFollowing({
383
+ userId,
384
+ ...args
385
+ }) {
386
+ return this._paginatedRequest({
387
+ url: `/users/${userId}/following`,
388
+ ...args
389
+ });
390
+ },
391
+ async retweet(args) {
392
+ const id = await this.getAuthenticatedUserId();
393
+ return this._httpRequest({
394
+ method: "POST",
395
+ url: `/users/${id}/retweets`,
396
+ ...args
397
+ });
398
+ },
399
+ async searchTweets(args) {
400
+ return this._paginatedRequest({
401
+ url: "/tweets/search/recent",
402
+ ...args
403
+ });
404
+ },
405
+ async sendMessage({
406
+ userId,
407
+ ...args
408
+ }) {
409
+ return this._httpRequest({
410
+ method: "POST",
411
+ url: `/dm_conversations/with/${userId}/messages`,
412
+ ...args
413
+ });
414
+ },
415
+ async unfollowUser({
416
+ userId,
417
+ ...args
418
+ }) {
419
+ const id = await this.getAuthenticatedUserId();
420
+ return this._httpRequest({
421
+ method: "DELETE",
422
+ url: `/users/${id}/following/${userId}`,
423
+ ...args
424
+ });
425
+ },
426
+ async unlikeTweet({
427
+ tweetId,
428
+ ...args
429
+ }) {
430
+ const id = await this.getAuthenticatedUserId();
431
+ return this._httpRequest({
432
+ method: "DELETE",
433
+ url: `/users/${id}/likes/${tweetId}`,
434
+ ...args
435
+ });
436
+ },
437
+ async uploadMedia(args) {
438
+ return this._httpRequest({
439
+ baseURL: "https://upload.twitter.com/1.1",
440
+ url: "/media/upload.json",
441
+ method: "POST",
442
+ headers: {
443
+ "Content-Type": `multipart/form-data; boundary=${args.data.getBoundary()}`
444
+ },
445
+ specialAuth: true,
446
+ ...args
447
+ });
448
+ }
449
+ }
450
+ });
451
+
452
+ // components/twitter/common/appValidation.ts
453
+ var appValidation_default = {
454
+ props: {
455
+ app: {
456
+ ...twitter_app_default,
457
+ reloadProps: true
458
+ }
459
+ },
460
+ async additionalProps() {
461
+ const q = "Pipedream";
462
+ const data = await this.getRecentTweets({
463
+ params: {
464
+ query: q
465
+ },
466
+ validateStatus: () => true
467
+ });
468
+ this.app.throwError(data);
469
+ return {};
470
+ },
471
+ methods: {
472
+ getRecentTweets(args = {}) {
473
+ return this.app._httpRequest({
474
+ url: "/tweets/search/recent",
475
+ ...args
476
+ });
477
+ }
478
+ }
479
+ };
480
+
481
+ // components/twitter/sources/common/base.ts
482
+ var base_default = {
483
+ ...appValidation_default,
484
+ props: {
485
+ ...appValidation_default.props,
486
+ db: "$.service.db",
487
+ timer: {
488
+ type: "$.interface.timer",
489
+ default: {
490
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL
491
+ }
492
+ }
493
+ },
494
+ hooks: {
495
+ async deploy() {
496
+ const q = "Pipedream";
497
+ const data = await this.getRecentTweets({
498
+ params: {
499
+ query: q
500
+ },
501
+ validateStatus: () => true
502
+ });
503
+ this.app.throwError(data);
504
+ await this.getAndProcessData();
505
+ }
506
+ },
507
+ methods: {
508
+ ...appValidation_default.methods,
509
+ getEntityName() {
510
+ return "Entity";
511
+ },
512
+ getItemSummary() {
513
+ throw new Error("getItemSummary() not implemented in component");
514
+ },
515
+ async getResources() {
516
+ throw new Error("getResources() not implemented in component");
517
+ },
518
+ getSavedIds() {
519
+ return this.db.get("savedEntityIds");
520
+ },
521
+ setSavedIds(data) {
522
+ this.db.set("savedEntityIds", data);
523
+ },
524
+ async getAndProcessData(maxResults) {
525
+ const data = await this.getResources(maxResults);
526
+ if (data) {
527
+ const savedIds = this.getSavedIds() ?? [];
528
+ data.filter(({ id }) => !savedIds.includes(id)).reverse().forEach((obj) => {
529
+ this.emitEvent(obj);
530
+ savedIds.push(obj.id);
531
+ });
532
+ this.setSavedIds(savedIds);
533
+ }
534
+ },
535
+ emitEvent(data) {
536
+ const ts = Date.now();
537
+ const { id } = data;
538
+ this.$emit(data, {
539
+ id,
540
+ summary: `New ${this.getEntityName()}: "${this.getItemSummary(data)}"`,
541
+ ts
542
+ });
543
+ }
544
+ },
545
+ async run() {
546
+ try {
547
+ await this.getAndProcessData(50);
548
+ } catch (err) {
549
+ throw new Error(`${ERROR_MESSAGE} Error response: ${JSON.stringify(err)}`);
550
+ }
551
+ }
552
+ };
553
+ export {
554
+ base_default as default
78
555
  };
@@ -1,18 +1,35 @@
1
- import { getUserId } from "../../common/methods.mjs";
1
+ // components/twitter/common/methods.ts
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+ async function getUserId() {
4
+ let { userNameOrId: id } = this;
5
+ if (id === "me" || id === void 0) {
6
+ id = await this.app.getAuthenticatedUserId();
7
+ } else if (id.startsWith("@")) {
8
+ const userData = await this.app.getUserByUsername(id.slice(1));
9
+ id = userData?.data?.id;
10
+ if (!id) throw new ConfigurationError("**User not found!** Check the `User Name or ID` prop.");
11
+ }
12
+ return id;
13
+ }
14
+
15
+ // components/twitter/sources/common/cacheUserId.ts
2
16
  async function getCachedUserId() {
3
- const { userNameOrId: name } = this;
4
- const cache = this.db.get("cachedUser");
5
- if (cache?.name === name) {
6
- return cache.id;
7
- }
8
- const id = await this.getUserId();
9
- this.db.set("cachedUser", {
10
- id,
11
- name,
12
- });
13
- return id;
17
+ const { userNameOrId: name } = this;
18
+ const cache = this.db.get("cachedUser");
19
+ if (cache?.name === name) {
20
+ return cache.id;
21
+ }
22
+ const id = await this.getUserId();
23
+ this.db.set("cachedUser", {
24
+ id,
25
+ name
26
+ });
27
+ return id;
14
28
  }
15
- export default {
16
- getCachedUserId,
17
- getUserId,
29
+ var cacheUserId_default = {
30
+ getCachedUserId,
31
+ getUserId
32
+ };
33
+ export {
34
+ cacheUserId_default as default
18
35
  };
@@ -1,12 +1,16 @@
1
- const SUMMARY_TEXT_MAX_LENGTH = 30;
2
- export function getListSummary({ name }) {
3
- return name;
1
+ // components/twitter/sources/common/getItemSummary.ts
2
+ var SUMMARY_TEXT_MAX_LENGTH = 30;
3
+ function getListSummary({ name }) {
4
+ return name;
4
5
  }
5
- export function getTweetSummary({ text }) {
6
- return text.length > SUMMARY_TEXT_MAX_LENGTH
7
- ? text.slice(0, SUMMARY_TEXT_MAX_LENGTH) + "..."
8
- : text;
6
+ function getTweetSummary({ text }) {
7
+ return text.length > SUMMARY_TEXT_MAX_LENGTH ? text.slice(0, SUMMARY_TEXT_MAX_LENGTH) + "..." : text;
9
8
  }
10
- export function getUserSummary({ username }) {
11
- return username;
9
+ function getUserSummary({ username }) {
10
+ return username;
12
11
  }
12
+ export {
13
+ getListSummary,
14
+ getTweetSummary,
15
+ getUserSummary
16
+ };