gs-solutions-lib
v1.0.0
Published
JB solutions library
Downloads
2
Readme
Library for JB Console development
The one-stop solution for handling multiple libraries frequently used in JB projects development.
- Support for v4 google-spreadsheets library
- Support for google-auth-library based on latest JWT access
- Support for gDrive library functions - fileUpload to particular folder
- Support for date functions - addDaysToDate, addMinsToDate, formatDate, differenceInDaysBetweenTwoDates etc.
🌈 Installation -
npm i gs-solutions-lib
Examples
The following examples are meant to give you an idea of just some of the things you can do
IMPORTANT NOTE - To keep the examples concise, I'm calling await at the top level which is not allowed in some older versions of node. If you need to call await in a script at the root level and your environment does not support it, you must instead wrap it in an async function like so:
(async function () {
await someAsyncFunction();
})();
The Basics
You can use the pre-defined methods in the library as below.
import { addRow } from 'gs-solutions-lib';
// Initialize the required service account credentials and mandatory details like sheetId, sheetTitle
const cred = "{Google service account credentials}";
const sheetId = "{Google gSheetId}";
const sheetTitle = "Google gSheet title";
// Initialize method specific required params
const rowData = ["row data array to be added in gsheet"];
// Call the required function
(async function () {
try {
await addRow(sheetId, cred, sheetTitle, rowData);
} catch (error) {
console.log(error);
}
})();
GDrive File Upload
import { uploadFileToGdriveFolder } from 'gs-solutions-lib';
// Initialize the required service account credentials
const cred = "{Google service account credentials}";
// Initialize method specific required params
const parentFolderId = "{Google drive folder id in which you want to upload file}";
const fileUrl = "Public file url or file url from Gupshup File Manager";
const fileType = "Specify file type. Ex - image/jpeg, image/png, text/csv etc.";
// Call the required function
(async function () {
try {
const resp = await uploadFileToGdriveFolder(cred, parentFolderId, fileUrl, fileType);
console.log(resp);
} catch (error) {
console.log(error);
}
})();
Date Functions Usage
import { addDaysToDate, formatDate } from 'gs-solutions-lib';
let date = new Date();
console.log(addDaysToDate(date, 2));
console.log(formatDate(date, 'dd-MM-yyyy HH:mm:ss'));
Contributing
Contributions are welcome, but please follow the existing conventions, use the linter, add relevant tests, and add relevant documentation.