|
| 1 | +import codeqr from "../../codeqr.app.mjs"; |
| 2 | + |
| 3 | +export default { |
| 4 | + key: "codeqr-create-link", |
| 5 | + name: "Create a CodeQR Link", |
| 6 | + description: |
| 7 | + "Creates a short link in CodeQR using the CodeQR API. [See the docs here](https://codeqr.mintlify.app/api-reference/endpoint/create-a-link)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + codeqr, |
| 12 | + url: { |
| 13 | + type: "string", |
| 14 | + label: "URL", |
| 15 | + description: "The destination URL of the short link.", |
| 16 | + }, |
| 17 | + key: { |
| 18 | + type: "string", |
| 19 | + label: "Key", |
| 20 | + description: |
| 21 | + "The short link slug. If not provided, a random 7-character slug will be generated.", |
| 22 | + optional: true, |
| 23 | + }, |
| 24 | + domain: { |
| 25 | + type: "string", |
| 26 | + label: "Domain", |
| 27 | + description: |
| 28 | + "The domain of the short link. If not provided, the default workspace domain will be used.", |
| 29 | + optional: true, |
| 30 | + }, |
| 31 | + externalId: { |
| 32 | + type: "string", |
| 33 | + label: "External ID", |
| 34 | + description: |
| 35 | + "This is the ID of the link in your database. Must be prefixed with ext_.", |
| 36 | + optional: true, |
| 37 | + }, |
| 38 | + password: { |
| 39 | + type: "string", |
| 40 | + label: "Password", |
| 41 | + description: "The password required to access the destination URL.", |
| 42 | + optional: true, |
| 43 | + }, |
| 44 | + flexible: { |
| 45 | + type: "boolean", |
| 46 | + label: "Flexible Link", |
| 47 | + description: |
| 48 | + "Whether this is a flexible link with dynamic destination setting.", |
| 49 | + optional: true, |
| 50 | + }, |
| 51 | + title: { |
| 52 | + type: "string", |
| 53 | + label: "Title", |
| 54 | + description: "The title displayed on the short link page.", |
| 55 | + optional: true, |
| 56 | + }, |
| 57 | + description: { |
| 58 | + type: "string", |
| 59 | + label: "Description", |
| 60 | + description: "A description displayed on the short link page.", |
| 61 | + optional: true, |
| 62 | + }, |
| 63 | + image: { |
| 64 | + type: "string", |
| 65 | + label: "Image URL", |
| 66 | + description: "URL of the image displayed on the short link page.", |
| 67 | + optional: true, |
| 68 | + }, |
| 69 | + video: { |
| 70 | + type: "string", |
| 71 | + label: "Video URL", |
| 72 | + description: "URL of the video displayed on the short link page.", |
| 73 | + optional: true, |
| 74 | + }, |
| 75 | + proxy: { |
| 76 | + type: "boolean", |
| 77 | + label: "Proxy", |
| 78 | + description: "Enable proxy settings.", |
| 79 | + optional: true, |
| 80 | + }, |
| 81 | + preRedirection: { |
| 82 | + type: "boolean", |
| 83 | + label: "Pre-Redirection Page", |
| 84 | + description: |
| 85 | + "Enable a pre-redirection page before sending users to the destination URL.", |
| 86 | + optional: true, |
| 87 | + }, |
| 88 | + pageId: { |
| 89 | + type: "string", |
| 90 | + label: "Page ID", |
| 91 | + description: "ID of your page created in CodeQR.", |
| 92 | + optional: true, |
| 93 | + }, |
| 94 | + pageUrl: { |
| 95 | + type: "string", |
| 96 | + label: "Page URL", |
| 97 | + description: "The URL for the pre-redirect page.", |
| 98 | + optional: true, |
| 99 | + }, |
| 100 | + rewrite: { |
| 101 | + type: "boolean", |
| 102 | + label: "Rewrite Link", |
| 103 | + description: "Enable link rewriting.", |
| 104 | + optional: true, |
| 105 | + }, |
| 106 | + ios: { |
| 107 | + type: "string", |
| 108 | + label: "iOS URL", |
| 109 | + description: "The iOS destination URL for device-specific redirection.", |
| 110 | + optional: true, |
| 111 | + }, |
| 112 | + android: { |
| 113 | + type: "string", |
| 114 | + label: "Android URL", |
| 115 | + description: |
| 116 | + "The Android destination URL for device-specific redirection.", |
| 117 | + optional: true, |
| 118 | + }, |
| 119 | + doIndex: { |
| 120 | + type: "boolean", |
| 121 | + label: "Allow Indexing", |
| 122 | + description: "Enable indexing of the short link.", |
| 123 | + optional: true, |
| 124 | + }, |
| 125 | + comments: { |
| 126 | + type: "string", |
| 127 | + label: "Comments", |
| 128 | + description: "Comments or notes about the short link.", |
| 129 | + optional: true, |
| 130 | + }, |
| 131 | + expiresAt: { |
| 132 | + type: "string", |
| 133 | + label: "Expiration Date", |
| 134 | + description: |
| 135 | + "The date and time when the short link will expire (ISO 8601).", |
| 136 | + optional: true, |
| 137 | + }, |
| 138 | + expiredUrl: { |
| 139 | + type: "string", |
| 140 | + label: "Expired Redirect URL", |
| 141 | + description: "The URL to redirect to when the short link has expired.", |
| 142 | + optional: true, |
| 143 | + }, |
| 144 | + geo: { |
| 145 | + type: "object", |
| 146 | + label: "Geo-Targeting", |
| 147 | + description: |
| 148 | + "Mapping of country codes to destination URLs (JSON format).", |
| 149 | + optional: true, |
| 150 | + }, |
| 151 | + publicStats: { |
| 152 | + type: "boolean", |
| 153 | + label: "Public Stats", |
| 154 | + description: "Whether the short link's stats are publicly accessible.", |
| 155 | + optional: true, |
| 156 | + }, |
| 157 | + tagIds: { |
| 158 | + type: "string[]", |
| 159 | + label: "Tag IDs", |
| 160 | + description: "Array of tag IDs to apply to the short link.", |
| 161 | + optional: true, |
| 162 | + }, |
| 163 | + tagNames: { |
| 164 | + type: "string[]", |
| 165 | + label: "Tag Names", |
| 166 | + description: "Array of tag names to apply to the short link.", |
| 167 | + optional: true, |
| 168 | + }, |
| 169 | + }, |
| 170 | + |
| 171 | + async run({ $ }) { |
| 172 | + const { |
| 173 | + url, |
| 174 | + key, |
| 175 | + domain, |
| 176 | + externalId, |
| 177 | + password, |
| 178 | + flexible, |
| 179 | + title, |
| 180 | + description, |
| 181 | + image, |
| 182 | + video, |
| 183 | + proxy, |
| 184 | + preRedirection, |
| 185 | + pageId, |
| 186 | + pageUrl, |
| 187 | + rewrite, |
| 188 | + ios, |
| 189 | + android, |
| 190 | + doIndex, |
| 191 | + comments, |
| 192 | + expiresAt, |
| 193 | + expiredUrl, |
| 194 | + geo, |
| 195 | + publicStats, |
| 196 | + tagIds, |
| 197 | + tagNames, |
| 198 | + } = this; |
| 199 | + |
| 200 | + const payload = { |
| 201 | + url, |
| 202 | + }; |
| 203 | + key && (payload.key = key); |
| 204 | + domain && (payload.domain = domain); |
| 205 | + externalId && (payload.externalId = externalId); |
| 206 | + password && (payload.password = password); |
| 207 | + flexible != null && (payload.flexible = flexible); |
| 208 | + title && (payload.title = title); |
| 209 | + description && (payload.description = description); |
| 210 | + image && (payload.image = image); |
| 211 | + video && (payload.video = video); |
| 212 | + proxy != null && (payload.proxy = proxy); |
| 213 | + preRedirection != null && (payload.preRedirection = preRedirection); |
| 214 | + pageId && (payload.pageId = pageId); |
| 215 | + pageUrl && (payload.pageUrl = pageUrl); |
| 216 | + rewrite != null && (payload.rewrite = rewrite); |
| 217 | + ios && (payload.ios = ios); |
| 218 | + android && (payload.android = android); |
| 219 | + doIndex != null && (payload.doIndex = doIndex); |
| 220 | + comments && (payload.comments = comments); |
| 221 | + expiresAt && (payload.expiresAt = expiresAt); |
| 222 | + expiredUrl && (payload.expiredUrl = expiredUrl); |
| 223 | + geo && (payload.geo = geo); |
| 224 | + publicStats != null && (payload.publicStats = publicStats); |
| 225 | + |
| 226 | + if (tagIds?.length) payload.tagIds = tagIds; |
| 227 | + if (tagNames?.length) payload.tagNames = tagNames; |
| 228 | + |
| 229 | + const response = await this.codeqr.createLink(payload); |
| 230 | + response && $.export("$summary", "Link created successfully"); |
| 231 | + return response; |
| 232 | + }, |
| 233 | +}; |
0 commit comments