From e9198fadf69505108160c0870cdf88ec8ac601ce Mon Sep 17 00:00:00 2001 From: Emmanuel Evance Date: Fri, 18 Oct 2024 16:58:21 +0300 Subject: [PATCH] export util helpers --- packages/http/src/Adaptor.js | 2 +- packages/http/src/index.js | 3 +- packages/http/src/{Utils.js => util.js} | 40 ++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) rename packages/http/src/{Utils.js => util.js} (76%) diff --git a/packages/http/src/Adaptor.js b/packages/http/src/Adaptor.js index 7c465d37a..8d1afb9e4 100644 --- a/packages/http/src/Adaptor.js +++ b/packages/http/src/Adaptor.js @@ -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 diff --git a/packages/http/src/index.js b/packages/http/src/index.js index a013b3648..1a56090c3 100644 --- a/packages/http/src/index.js +++ b/packages/http/src/index.js @@ -1,4 +1,5 @@ import * as Adaptor from './Adaptor'; export default Adaptor; -export * from './Adaptor'; \ No newline at end of file +export * from './Adaptor'; +export * as util from './util'; diff --git a/packages/http/src/Utils.js b/packages/http/src/util.js similarity index 76% rename from packages/http/src/Utils.js rename to packages/http/src/util.js index b49f4c330..5670bb0b2 100644 --- a/packages/http/src/Utils.js +++ b/packages/http/src/util.js @@ -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'; @@ -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 Encode a string + * 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 Decode a Base64 string + * 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 Generate a UUID + * const id = Util.uuid(); + * console.log(id); // Output:'3f4e254e-8f6f-4f8b-9651-1c1c262cc83f' + */ + uuid, +};