4.4.0 • Published 5 months ago

@a15-ghm/gh-utils v4.4.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

gh-utils

NPM package with utils methods

Gh-utils package is a package that includes different types of utility methods. Using gh-utils you can interact with different utilities related to sessions, URLs functionality, Data layer functionality, funnels functionality. At the moment the package consists of the following utils with methods:

Installation

npm install --save @a15-ghm/gh-utils

Setup / Configuration

Environments

To use gh-utils, you need to set environment variables. To do this, you need to call the following code in app.component.ts

import {environment} from '../environments/environment';

import Environment from '@a15-ghm/gh-utils/environment';

public ngOnInit(): void {
   Environment.setEnvVariables(environment);
}

Usage

url

.getQueryParamFromUrl()

Accepts a string url and string query param name, returns the value of query param from the url If the url does not contain a query param, returns null.

Example:

// The signature
function getQueryParamFromUrl(urlString: string, param: string): string;

// Usage
const mainFunnelId = getQueryParamFromUrl('https://example.com?mainFunnelId=someValue', 'mainFunnelId');

console.log(mainFunnelId); // someValue

funnels

Environmet variables:

Product utils uses the following environment variables:

  1. FUNNEL_CONFIG_SERVER_URL - funnel config server url
  2. BRAND - brand name

Example:

FUNNEL_CONFIG_SERVER_URL: 'https://funnel-loade-develop-otjipa1qe.herokuapp.com',
BRAND: 'Beverly Hills MD'

Methods:

.getFunnelByGEP()

Get Funnel configs by Generic end-point

// The signature
async function getFunnelByGEP(gep: string): Promise<IFunnelConfiguration>;

// Usage
await getFunnelByGEP('testGenericEndPoint');

Succeed result will correspond to interface .getFunnelByGEP()

.loadFunnelById()

Get a funnel if you pass the mainFunnelId Get funnel and destination if you pass mainFunnelId and destinationId

// The signature
async function loadFunnelById(mainFunnelId: string, destinationId?: string): Promise<IFunnelConfiguration>;

// Usage
await loadFunnelById('mainFunnelId');
await loadFunnelById('mainFunnelId', 'destinationId');

Succeed result will correspond to interface .loadFunnelById()

.getFunnelByPage()

Get funnel and destination by page

// The signature
async function getFunnelByPage(page: string): Promise<IFunnelConfiguration>;

// Usage
await getFunnelByPage('Cart');

Succeed result will correspond to interface .getFunnelByPage()

.getOrderForm()

Get order form configs by products

// The signature
async function getOrderForm(products: string): Promise<IOrderForms>;

// Usage
await getOrderForm('testProduct1, testProduct2');

Succeed result will correspond to interface .getOrderForm()

dataLayer

.pushAppScreenView()

Call a function with parameters to push the appScreenView event in the data layer

// The signature

function pushAppScreenView(page: string, sessionID: string, affiliateInfo: IAffiliateInfo): void;

// Usage

const screenPath = 'checkout';
const sessionID = '123';
const affiliateInfo = {
  utmCampaign: '123',
  utmCampaignId: '123',
  utmContent: '123',
  utmMedium: '123',
  utmSource: '123',
};

pushAppScreenView(screenPath, sessionID, affiliateInfo);

session

.pushSession()

Call a function with parameters to push the session event in the data layer

// The signature
function pushSession(sessionID: string): void;

// Usage
pushSession(sessionID);

.generateSessionId()

Generate a sessionId and return it

// The signature
function generateSessionId(): string;

// Usage
const sessionId: string = generateSessionId();

console.log(sessionId); // 210165331421

product

Environmet variables:

Product utils uses the following environment variables:

  1. API_URL - url of touchcr api
    • for getProductsAndVariantInfo is used the next url: host + apiUrl + 'products/getproductsandvariantinfo/'
    • for getProductsInfoBySfids is used the next url: host + apiUrl + 'products/getproductsinfobysfids/'
  2. BRAND - brand name

Example:

API_URL: '/proxy/',
BRAND: 'Beverly Hills MD'

Methods:

.getProductsAndVariantInfo()

Gets products and variants info by SalesForce Ids (SFIDs)

getProductsAndVariantInfo([productId1, productId2]): IProductsAndVariants;

.getProductsInfoBySfids()

Gets products info by SalesForce Ids (SFIDs)

getProductsInfoBySfids([productId1, productId2]): IProduct[];

Usage

import { getProductsAndVariantInfo, getProductsInfoBySfids } from '@a15-ghm/gh-utils/product';

const productsAndVariants = getProductsAndVariantInfo(['01t0m000004HiNTAA0']);
const products = getProductsInfoBySfids(['01t0m000004HiNTAA0']);

country

Environmet variables:

Country utils uses the following environment variables:

  1. API_URL - url of touchcr api (used the next url: _host + apiUrl + 'utils/countries/')

Example:

API_URL: '/proxy/',

Methods:

.getCountries()

Gets countries from API and decodes the recieved data

getCountries(): Promise<ICountry[]>;

Usage

import { getCountries } from '@a15-ghm/gh-utils/country';

const countries = await getCountries();

touchcrApi

It can be used to make requests to the TouchCR API. You can set the environment variables, import the necessary utility and use the ready exported method for request to the TouchCR API without customizing the request headers and cookies to be processed by this package

Environmet variables:

TouchcrApi utils uses the following environment variables:

  1. API_URL - url of TouchCR API
  2. BRAND - brand name

Example:

API_URL: 'https://test_url/api/v2',
BRAND: 'Beverly Hills MD'

Methods:

.touchcrApiRequestPost()

This method make a POST request to the TouchCR API

touchcrApiRequestPost<T>(endpoint: string, body: BodyInit): Promise<T>;

Usage

import { touchcrApiRequestPost } from '@a15-ghm/gh-utils/touchcrApi';

const couponInfo = await touchcrApiRequestPost<GetCouponResponseDto>(
  'coupon/check',
  JSON.stringify({
    couponCode: 'COUPONTEST10',
  }),
);

Versions

Gh-utils follows semver() rules:

  • MAJOR version when we make incompatible API changes
  • MINOR version when we add functionality in a backward compatible manner
  • PATCH version when we make backward compatible bug fixes
4.4.0

5 months ago

4.3.0

5 months ago

4.2.0

5 months ago

4.1.0

5 months ago

3.1.0

6 months ago

4.0.0

6 months ago

3.0.0

7 months ago

2.1.0

9 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago