@goldenhippo/gh-utils

4.4.0 • Public • Published

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 @goldenhippo/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 '@goldenhippo/gh-utils/environment';

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

Usage

url

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:

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()

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()

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()

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

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

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

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

// Usage
pushSession(sessionID);

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:

Gets products and variants info by SalesForce Ids (SFIDs)

getProductsAndVariantInfo([productId1, productId2]): IProductsAndVariants;

Gets products info by SalesForce Ids (SFIDs)

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

Usage

import { getProductsAndVariantInfo, getProductsInfoBySfids } from '@goldenhippo/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:

Gets countries from API and decodes the recieved data

getCountries(): Promise<ICountry[]>;

Usage

import { getCountries } from '@goldenhippo/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:

This method make a POST request to the TouchCR API

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

Usage

import { touchcrApiRequestPost } from '@goldenhippo/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

Dependencies (0)

    Dev Dependencies (28)

    Package Sidebar

    Install

    npm i @goldenhippo/gh-utils

    Weekly Downloads

    0

    Version

    4.4.0

    License

    ISC

    Unpacked Size

    35.2 kB

    Total Files

    60

    Last publish

    Collaborators

    • victor-vargas-gh
    • deva_7
    • danni.liu
    • jarednutt-gh
    • sarah.zacharia
    • sher85
    • davidkidwell
    • deva_8
    • steven-t-h