|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | +import constants from "./common/constants.mjs"; |
| 3 | + |
1 | 4 | export default { |
2 | 5 | type: "app", |
3 | 6 | app: "ayrshare", |
4 | | - propDefinitions: {}, |
| 7 | + propDefinitions: { |
| 8 | + title: { |
| 9 | + type: "string", |
| 10 | + label: "Title", |
| 11 | + description: "Unique title for the new profile", |
| 12 | + }, |
| 13 | + messagingActive: { |
| 14 | + type: "boolean", |
| 15 | + label: "Messaging Active", |
| 16 | + description: "Enable messaging functionality for this profile", |
| 17 | + optional: true, |
| 18 | + }, |
| 19 | + hideTopHeader: { |
| 20 | + type: "boolean", |
| 21 | + label: "Hide Top Header", |
| 22 | + description: "Hide the top header text on the account linking page", |
| 23 | + optional: true, |
| 24 | + }, |
| 25 | + topHeader: { |
| 26 | + type: "string", |
| 27 | + label: "Top Header", |
| 28 | + description: "Custom header text shown on the social linking page", |
| 29 | + optional: true, |
| 30 | + }, |
| 31 | + subHeader: { |
| 32 | + type: "string", |
| 33 | + label: "Sub Header", |
| 34 | + description: "Custom sub-header text shown below the header on the linking page", |
| 35 | + optional: true, |
| 36 | + }, |
| 37 | + disableSocial: { |
| 38 | + type: "string[]", |
| 39 | + label: "Disable Social", |
| 40 | + description: "List of social platforms to disable for this profile", |
| 41 | + options: constants.SOCIAL_NETWORKS, |
| 42 | + optional: true, |
| 43 | + }, |
| 44 | + team: { |
| 45 | + type: "boolean", |
| 46 | + label: "Team", |
| 47 | + description: "Set to true to invite the user as a team member", |
| 48 | + optional: true, |
| 49 | + }, |
| 50 | + email: { |
| 51 | + type: "string", |
| 52 | + label: "Email", |
| 53 | + description: "Email address to send the team invitation to", |
| 54 | + optional: true, |
| 55 | + }, |
| 56 | + tags: { |
| 57 | + type: "string[]", |
| 58 | + label: "Tags", |
| 59 | + description: "Custom internal tags to help categorize the profile", |
| 60 | + optional: true, |
| 61 | + }, |
| 62 | + profileKey: { |
| 63 | + type: "string", |
| 64 | + label: "Profile Key", |
| 65 | + description: "Unique key returned after profile creation", |
| 66 | + }, |
| 67 | + profileToDelete: { |
| 68 | + type: "string", |
| 69 | + label: "Title", |
| 70 | + description: "Unique title of the profile that will be deleted. Must be informed only if `profileKey` is not provided", |
| 71 | + optional: true, |
| 72 | + async options() { |
| 73 | + const response = await this.getProfiles(); |
| 74 | + const profiles = response.profiles; |
| 75 | + return profiles.map((profiles) => ({ |
| 76 | + label: profiles.title, |
| 77 | + value: profiles.title, |
| 78 | + })); |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
5 | 82 | methods: { |
6 | | - // this.$auth contains connected account data |
7 | | - authKeys() { |
8 | | - console.log(Object.keys(this.$auth)); |
| 83 | + _baseUrl() { |
| 84 | + return "https://api.ayrshare.com/api"; |
| 85 | + }, |
| 86 | + async _makeRequest(opts = {}) { |
| 87 | + const { |
| 88 | + $ = this, |
| 89 | + path, |
| 90 | + headers, |
| 91 | + ...otherOpts |
| 92 | + } = opts; |
| 93 | + return axios($, { |
| 94 | + ...otherOpts, |
| 95 | + url: this._baseUrl() + path, |
| 96 | + headers: { |
| 97 | + Authorization: `Bearer ${this.$auth.api_key}`, |
| 98 | + ...headers, |
| 99 | + }, |
| 100 | + }); |
| 101 | + }, |
| 102 | + async createUser(args = {}) { |
| 103 | + return this._makeRequest({ |
| 104 | + path: "/profiles", |
| 105 | + method: "post", |
| 106 | + ...args, |
| 107 | + }); |
| 108 | + }, |
| 109 | + async updateUser(args = {}) { |
| 110 | + return this._makeRequest({ |
| 111 | + path: "/profiles", |
| 112 | + method: "patch", |
| 113 | + ...args, |
| 114 | + }); |
| 115 | + }, |
| 116 | + async deleteUser(args = {}) { |
| 117 | + return this._makeRequest({ |
| 118 | + path: "/profiles", |
| 119 | + method: "delete", |
| 120 | + ...args, |
| 121 | + }); |
| 122 | + }, |
| 123 | + async getProfiles(args = {}) { |
| 124 | + return this._makeRequest({ |
| 125 | + path: "/profiles", |
| 126 | + ...args, |
| 127 | + }); |
9 | 128 | }, |
10 | 129 | }, |
11 | 130 | }; |
0 commit comments