|
| 1 | +import type { ISchemaProperties } from '../types.js'; |
| 2 | + |
| 3 | +export function addResourcePickerProperties(property: ISchemaProperties): ISchemaProperties { |
| 4 | + return { |
| 5 | + ...property, |
| 6 | + items: { |
| 7 | + ...property.items, |
| 8 | + type: 'string', |
| 9 | + title: 'Resource ID', |
| 10 | + description: 'Resource ID, either Apify Dataset, Key-Value Store, or Request List identifier', |
| 11 | + }, |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +/** |
| 16 | + * Adds key-value schema structure to array properties with editor === 'keyValue'. |
| 17 | + */ |
| 18 | +export function addKeyValueProperties(property: ISchemaProperties): ISchemaProperties { |
| 19 | + return { |
| 20 | + ...property, |
| 21 | + items: { |
| 22 | + ...property.items, |
| 23 | + type: 'object', |
| 24 | + title: 'Key-Value Pair', |
| 25 | + description: 'Key-value pair definition', |
| 26 | + properties: { |
| 27 | + key: { |
| 28 | + type: 'string', |
| 29 | + title: 'Key', |
| 30 | + description: 'Key string', |
| 31 | + }, |
| 32 | + value: { |
| 33 | + type: 'string', |
| 34 | + title: 'Value', |
| 35 | + description: 'Value string', |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + }; |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * Adds globs schema structure to array properties with editor === 'globs'. |
| 44 | + */ |
| 45 | +/** |
| 46 | + * Adds pseudoUrls schema structure to array properties with items.editor === 'pseudoUrls'. |
| 47 | + */ |
| 48 | + |
| 49 | +const USER_DATA_DESCRIPTION = `User data object. A JSON object with custom user data that will be passed in the userData property of the Request object for each URL`; |
| 50 | +const HEADERS_DESCRIPTION = `Headers object. A JSON object whose properties and values contain HTTP headers that will sent with the request.`; |
| 51 | + |
| 52 | +export function addGlobsProperties(property: ISchemaProperties): ISchemaProperties { |
| 53 | + return { |
| 54 | + ...property, |
| 55 | + items: { |
| 56 | + ...property.items, |
| 57 | + type: 'object', |
| 58 | + title: 'Glob', |
| 59 | + description: 'Glob pattern definition', |
| 60 | + properties: { |
| 61 | + glob: { |
| 62 | + type: 'string', |
| 63 | + title: 'Glob', |
| 64 | + description: 'Glob pattern string', |
| 65 | + }, |
| 66 | + method: { |
| 67 | + type: 'string', |
| 68 | + title: 'HTTP Method', |
| 69 | + description: 'HTTP method for the request', |
| 70 | + }, |
| 71 | + payload: { |
| 72 | + type: 'string', |
| 73 | + title: 'Payload', |
| 74 | + description: 'Payload for the request', |
| 75 | + }, |
| 76 | + userData: { |
| 77 | + type: 'object', |
| 78 | + title: 'User Data', |
| 79 | + description: USER_DATA_DESCRIPTION, |
| 80 | + properties: {}, |
| 81 | + }, |
| 82 | + headers: { |
| 83 | + type: 'object', |
| 84 | + title: 'Headers', |
| 85 | + description: HEADERS_DESCRIPTION, |
| 86 | + properties: {}, |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }; |
| 91 | +} |
| 92 | + |
| 93 | +export function addPseudoUrlsProperties(property: ISchemaProperties): ISchemaProperties { |
| 94 | + return { |
| 95 | + ...property, |
| 96 | + items: { |
| 97 | + ...property.items, |
| 98 | + type: 'object', |
| 99 | + title: 'PseudoUrl', |
| 100 | + description: `PseudoUrl definition. Represents a pseudo-URL (PURL) - an URL pattern used by web crawlers to specify which URLs should the crawler visit. |
| 101 | + A PURL is simply a URL with special directives enclosed in [] brackets. Currently, the only supported directive is [RegExp], which defines a JavaScript-style regular expression to match against the URL.`, |
| 102 | + properties: { |
| 103 | + purl: { |
| 104 | + type: 'string', |
| 105 | + title: 'PseudoUrl', |
| 106 | + description: `PseudoUrl pattern string. Be careful to correctly escape special characters in the pseudo-URL string. If either [ or ] is part of the normal query string, it must be encoded as [\\x5B] or [\\x5D], respectively`, |
| 107 | + examples: [ |
| 108 | + 'http://www.example.com/pages/[(\\w|-)*]', |
| 109 | + ], |
| 110 | + }, |
| 111 | + method: { |
| 112 | + type: 'string', |
| 113 | + title: 'HTTP Method', |
| 114 | + description: 'HTTP method for the request', |
| 115 | + enum: [ |
| 116 | + 'GET', |
| 117 | + 'POST', |
| 118 | + 'PUT', |
| 119 | + 'DELETE', |
| 120 | + 'PATCH', |
| 121 | + 'HEAD', |
| 122 | + 'OPTIONS', |
| 123 | + 'CONNECT', |
| 124 | + 'TRACE', |
| 125 | + ], |
| 126 | + }, |
| 127 | + payload: { |
| 128 | + type: 'string', |
| 129 | + title: 'Payload', |
| 130 | + description: 'Payload for the request', |
| 131 | + }, |
| 132 | + userData: { |
| 133 | + type: 'object', |
| 134 | + title: 'User Data', |
| 135 | + description: USER_DATA_DESCRIPTION, |
| 136 | + properties: {}, |
| 137 | + }, |
| 138 | + headers: { |
| 139 | + type: 'object', |
| 140 | + title: 'Headers', |
| 141 | + description: HEADERS_DESCRIPTION, |
| 142 | + properties: {}, |
| 143 | + }, |
| 144 | + }, |
| 145 | + }, |
| 146 | + }; |
| 147 | +} |
| 148 | + |
| 149 | +/** |
| 150 | + * Adds Apify proxy-specific properties to a proxy object property. |
| 151 | + */ |
| 152 | +export function addProxyProperties(property: ISchemaProperties): ISchemaProperties { |
| 153 | + return { |
| 154 | + ...property, |
| 155 | + properties: { |
| 156 | + ...property.properties, |
| 157 | + useApifyProxy: { |
| 158 | + title: 'Use Apify Proxy', |
| 159 | + type: 'boolean', |
| 160 | + description: 'Whether to use Apify Proxy. Set this to false when you want to use custom proxy URLs.', |
| 161 | + default: true, |
| 162 | + }, |
| 163 | + apifyProxyGroups: { |
| 164 | + title: 'Apify Proxy Groups', |
| 165 | + type: 'array', |
| 166 | + description: `Select specific Apify Proxy groups to use (e.g., RESIDENTIAL, DATACENTER). |
| 167 | +**DATACENTER:** |
| 168 | +The fastest and cheapest option. It uses datacenters to change your IP address. Note that there is a chance of being blocked because of the activity of other users. |
| 169 | +
|
| 170 | +**RESIDENTIAL:** |
| 171 | +IP addresses located in homes and offices around the world. These IPs are the least likely to be blocked.`, |
| 172 | + items: { |
| 173 | + type: 'string', |
| 174 | + title: 'Proxy group name', |
| 175 | + description: 'Proxy group name', |
| 176 | + enum: [ |
| 177 | + 'RESIDENTIAL', |
| 178 | + 'DATACENTER', |
| 179 | + ], |
| 180 | + }, |
| 181 | + }, |
| 182 | + proxyUrls: { |
| 183 | + title: 'Proxy URLs', |
| 184 | + type: 'array', |
| 185 | + description: 'List of custom proxy URLs to be used instead of the Apify Proxy.', |
| 186 | + items: { |
| 187 | + type: 'string', |
| 188 | + title: 'Custom proxy URL', |
| 189 | + description: 'Custom proxy URL', |
| 190 | + }, |
| 191 | + }, |
| 192 | + }, |
| 193 | + required: ['useApifyProxy'], |
| 194 | + }; |
| 195 | +} |
| 196 | + |
| 197 | +/** |
| 198 | + * Adds request list source structure to array properties with editor 'requestListSources'. |
| 199 | + */ |
| 200 | +export function addRequestListSourcesProperties(property: ISchemaProperties): ISchemaProperties { |
| 201 | + return { |
| 202 | + ...property, |
| 203 | + items: { |
| 204 | + ...property.items, |
| 205 | + type: 'object', |
| 206 | + title: 'Request list source', |
| 207 | + description: 'Request list source', |
| 208 | + properties: { |
| 209 | + url: { |
| 210 | + title: 'URL', |
| 211 | + type: 'string', |
| 212 | + description: 'URL of the request list source', |
| 213 | + }, |
| 214 | + }, |
| 215 | + }, |
| 216 | + }; |
| 217 | +} |
0 commit comments