0.0.4 • Published 2 years ago

xlcoreservice v0.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

CoreServices

NOTE

Accessible AWS, Stripe, Cloudinary, Error, Logger, Twilio etc.. components for Node.JS

Installation

To install, you can use npm:

npm install --save @xongolab/coreservices

Documentation

The documentation for @xongolab/coreservices, which describes the API and gives examples of its usage.

Examples

Here is the simple usage of AWS components

const coreServices = require('@xongolab/coreservices');
const awsHandler = coreServices.awsHandler;
const AWSHandler = new awsHandler();
AWSHandler.config({keyId:'key_id', key:'key', region:'region'});

>> For Upload File

await AWSHandler.imageUpload(file);

>> For Upload multiple size images using imagemagick

const sizeArr = [{
        width: 200,
        height: 200,
    },
    {
        width: 400,
        height: 400,
    },
    {
        width: 700,
        height: 300,
    },
];
const file = req.files.image;
const fileType = file.name.split('.').pop().toLowerCase();
file.bucket = config.aws.s3.userBucket;
file.contentType = fileType;
file.sizeArr = sizeArr;
await AWSHandler.imageWithImageMagicUpload(file);

>> For Delete File

let objects = [{
    Key: 'FOLDER/FILENAME'
}];
await AWSHandler.imageDelete({objects:objects, bucket:BUCKET});

>> For Get Uploaded File as URL

await AWSHandler.imageGet({bucket: BUCKET, key:'FOLDER/FILENAME'});

>> For Sending Email

await AWSHandler.sendEmail({
    to_email: ["gaurav.patel@xongolab.com"],
    from_email: "Coreservices <demo1.testing1@gmail.com>",
    subject: "Welcome to Coreservices",
    description: "Hello Coreservices",
    ses_region: "us-east-2" // Only pass if aws region and ses region both different
});

Here is the simple usage of Cloudinary components

const coreServices = require('@xongolab/coreservices');
const cloudinaryHandler = coreServices.cloudinaryHandler;
cloudinaryHandler.config({cloud_name:'cloud_name', api_key:'api_key', api_secret:'secret_key'})

>> For Upload File

await cloudinaryHandler.imageUpload(file);

>> For Delete File

let objects = [FILENAME];
await cloudinaryHandler.imageDelete({objects:objects, bucket:FOLDER});

>> For Delete Folder

let objects = [FILENAME];
await cloudinaryHandler.folderDelete({objects:objects, bucket:FOLDER});

Here is the simple usage of Stripe components

const coreServices = require('@xongolab/coreservices');
const stripeHandler = coreServices.stripeHandler;

>> For Create Customer Profile

let stripeProfile = await stripeHandler.createCustomerProfile({ email: 'email', description: 'description', stripe_key:'stripe_key' })
console.log(stripeProfile.id)

>> For Get List of Added Cards

let cardsArr = await stripeHandler.listCards({stripe_profile_id:'customer_stripe_profile_id', stripe_key:'stripe_key'})
console.log(cardsArr.data)

>> For Create Token For Card

let stripeToken = await stripeHandler.createToken({ card: { "name": 'name', "number": 'card_number', "exp_month": 'exp_month', "exp_year": 'exp_year', "cvc": 'cvc' }}, 'stripe_key')
console.log(stripeToken.id)

>> For Create Token Bank

NOTE: For Different Country have different bank details so pass accordingly.

let stripeToken = await stripeHandler.createToken({ bank_account: { "country": 'country > US', "currency": 'currency', "account_holder_name": 'name', "account_holder_type": 'type', "routing_number": 'routing_number', account_number:account_number }}, 'stripe_key')
console.log(stripeToken.id)

>> For Create Source

let response = await stripeHandler.createSource({ stripe_profile_id:'customer_stripe_profile_id', token: stripeToken.id, stripe_key:'stripe_key' })
console.log(response.id)

>> For Delete Source

await stripeHandler.deleteSource({stripe_profile_id: 'customer_stripe_profile_id', id: 'card_id/bank_id', stripe_key:'stripe_key'})

Here is the simple usage of Error components

const coreServices = require('@xongolab/coreservices');
const errors = coreServices.errorHandler;
errors('TITLE', response_code) // TITLE -> You can pass your custom message, response_code -> 500,200,400 etc.. based on your response

Here is the simple usage of Logger components

const coreServices = require('@xongolab/coreservices');
const logger = coreServices.loggerHandler;
logger('TITLE'); // TITLE -> You can pass your custom message whatever you want to print into your terminal

Here is the simple usage of JSON Response components

const coreServices = require('@xongolab/coreservices');
const jsonResponse = coreServices.jsonResponseHandler;
jsonResponse(res, response_code, error/null, response/null);

For Example

>> Want to pass success resposne then
jsonResponse(res, 200, null, {msg:'Success'});

>> If getting some error then you Want to pass error resposne
jsonResponse(res, 500, errors('ERROR_MSG', null);

Here is the simple usage of Twilio components

const coreServices = require('@xongolab/coreservices');
const twilioHandler = coreServices.twilioHandler;
twilioHandler.config({account_sid:'account_sid', auth_token:'auth_token'})
await twilioHandler.sendSms({message:'Dear customer your OTP is: 1111, Thanks.', from: TwilioFromNo, to: toNo});

Here is the simple usage of Password components

const coreServices = require('@xongolab/coreservices');
const passwordHandler = coreServices.passwordHandler;

>> For Encryption

await passwordHandler.encrypt((YOUR_PASSWORD).toString());

>> For Decryption

await passwordHandler.decrypt((ENCRYPTED_PASSWORD).toString());

Here is the simple usage of ID Generator components

const coreServices = require('@xongolab/coreservices');
const idGenerator = coreServices.idGeneratorHandler;

NOTE: `LBL` is not required to pass if you want to generate id with some prefix then pass

>> Generate Regular ID

await idGenerator.generateId('LBL')

>> Generate Short ID

await idGenerator.generateShortId('LBL')

>> Generate Medium ID

await idGenerator.generateMediumId('LBL')

>> Generate Larger ID

await idGenerator.generateLongId('LBL')

>> Generate Invitation Code

await idGenerator.generateInviteCode('LENGTH') // LENGTH > Pass how many character you want in code