Skip to content

Commit

Permalink
export util helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuchi committed Oct 18, 2024
1 parent 6fd376a commit e9198fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/http/src/Adaptor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execute as commonExecute } from '@openfn/language-common';
import { request as sendRequest, xmlParser } from './Utils';
import { request as sendRequest, xmlParser } from './util';

/**
* Options provided to the HTTP request
Expand Down
3 changes: 2 additions & 1 deletion packages/http/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Adaptor from './Adaptor';
export default Adaptor;

export * from './Adaptor';
export * from './Adaptor';
export * as util from './util';
40 changes: 39 additions & 1 deletion packages/http/src/Utils.js → packages/http/src/util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { composeNextState } from '@openfn/language-common';
import {
request as commonRequest,
makeBasicAuthHeader,
expandReferences,
logResponse,
makeBasicAuthHeader,
encode,
decode,
uuid,
} from '@openfn/language-common/util';

import * as cheerio from 'cheerio';
Expand Down Expand Up @@ -136,3 +139,38 @@ export function xmlParser(body, script, callback = s => s) {
}
};
}

export {
/**
* Encodes a given string into Base64 format.
* @function
* @public
* @param {string} data - The string to be encoded.
* @returns {string} - The Base64 encoded string.
* @example <caption>Encode a string</caption>
* const encoded = Util.encode('Hello World');
* console.log(encoded); // Output: SGVsbG8gV29ybGQ=
*/
encode,
/**
* Decodes a Base64 encoded string back to its original format.
* @function
* @public
* @param {string} base64Data - The Base64 encoded string.
* @returns {string} - The decoded string.
* @example <caption>Decode a Base64 string</caption>
* const decoded = Util.decode('SGVsbG8gV29ybGQ=');
* console.log(decoded); // Output: Hello World
*/
decode,
/**
* Generates a UUID (Universally Unique Identifier).
* @function
* @public
* @returns {string} - A newly generated UUID.
* @example <caption>Generate a UUID</caption>
* const id = Util.uuid();
* console.log(id); // Output:'3f4e254e-8f6f-4f8b-9651-1c1c262cc83f'
*/
uuid,
};

0 comments on commit e9198fa

Please sign in to comment.