UNPKG

@joshfarrant/shortcuts-js

Version:
50 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils"); /** * @action Get Contents of URL * @section Content Types > Web > URLs * @icon Downloads * * Gets the contents of URLs passed into the action. Useful for downloading files and web content, or for making API requests. * * ```js * getContentsOfURL({ * headers: { * 'Authorization': 'Pretty please', * 'X-Some-Header': 'Badger', * }, * method: 'POST', * requestBodyType: 'JSON', * requestBody: { * myObj: { * things: [1, 2, 3], * someString: 'Hello', * }, * someOtherString: 'World!', * }, * }); * ``` */ const getContentsOfURL = ({ headers = {}, method = 'GET', requestBodyType = 'JSON', requestBody = {}, }) => { const action = { WFWorkflowActionIdentifier: 'is.workflow.actions.downloadurl', WFWorkflowActionParameters: { WFHTTPHeaders: utils_1.buildSerialization(headers), ShowHeaders: Object.entries(headers).length > 0, Advanced: method !== 'GET', WFHTTPMethod: method, WFHTTPBodyType: requestBodyType, }, }; if (requestBodyType === 'JSON') { action.WFWorkflowActionParameters.WFJSONValues = utils_1.buildSerialization(requestBody); } // I'd love to have an else if here, but it breaks Jest's coverage calculation :( if (requestBodyType === 'Form') { action.WFWorkflowActionParameters.WFFormValues = utils_1.buildSerialization(requestBody); } return action; }; exports.default = utils_1.withActionOutput(getContentsOfURL); //# sourceMappingURL=getContentsOfURL.js.map