Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salesforce add request() function #465

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grumpy-cows-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/language-salesforce': minor
---

Add `request(path, opts, cb)` function
44 changes: 44 additions & 0 deletions packages/salesforce/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,50 @@ export function toUTF8(input) {
return anyAscii(input);
}

/**
mtuchi marked this conversation as resolved.
Show resolved Hide resolved
* Send a HTTP request using connected session information.
*
* @example
* request('/actions/custom/flow/POC_OpenFN_Test_Flow', {
* method: 'POST',
* json: { inputs: [{}] },
* });
* @param {String} url - Relative or absolute URL to request from
* @param {Object} options - Request options
* @param {String} [options.method] - HTTP method to use. Defaults to GET
* @param {Object} [options.headers] - Object of request headers
* @param {Object} [options.json] - A JSON Object request body
* @param {String} [options.body] - HTTP body (in POST/PUT/PATCH methods)
* @param {Function} callback - A callback to execute once the request is complete
* @returns {Operation}
*/

export function request(path, options, callback = s => s) {
return async state => {
const { connection } = state;
const [resolvedPath, resolvedOptions] = newExpandReferences(
state,
path,
options
);
const { method = 'GET', json, body, headers } = resolvedOptions;

const requestOptions = {
url: resolvedPath,
method,
headers: json
? { 'content-type': 'application/json', ...headers }
: headers,
body: json ? JSON.stringify(json) : body,
};

const result = await connection.request(requestOptions);

const nextState = composeNextState(state, result);

return callback(nextState);
};
}
// Note that we expose the entire axios package to the user here.
import axios from 'axios';

Expand Down
Loading