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:
npm install --save @goldenhippo/gh-utils
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);
}
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
Product utils uses the following environment variables:
- FUNNEL_CONFIG_SERVER_URL - funnel config server url
- BRAND - brand name
Example:
FUNNEL_CONFIG_SERVER_URL: 'https://funnel-loade-develop-otjipa1qe.herokuapp.com',
BRAND: 'Beverly Hills MD'
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()
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);
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 utils uses the following environment variables:
- 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/'
- BRAND - brand name
Example:
API_URL: '/proxy/',
BRAND: 'Beverly Hills MD'
Gets products and variants info by SalesForce Ids (SFIDs)
getProductsAndVariantInfo([productId1, productId2]): IProductsAndVariants;
Gets products info by SalesForce Ids (SFIDs)
getProductsInfoBySfids([productId1, productId2]): IProduct[];
import { getProductsAndVariantInfo, getProductsInfoBySfids } from '@goldenhippo/gh-utils/product';
const productsAndVariants = getProductsAndVariantInfo(['01t0m000004HiNTAA0']);
const products = getProductsInfoBySfids(['01t0m000004HiNTAA0']);
Country utils uses the following environment variables:
- API_URL - url of touchcr api (used the next url: _host + apiUrl + 'utils/countries/')
Example:
API_URL: '/proxy/',
Gets countries from API and decodes the recieved data
getCountries(): Promise<ICountry[]>;
import { getCountries } from '@goldenhippo/gh-utils/country';
const countries = await getCountries();
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
TouchcrApi utils uses the following environment variables:
- API_URL - url of TouchCR API
- BRAND - brand name
Example:
API_URL: 'https://test_url/api/v2',
BRAND: 'Beverly Hills MD'
This method make a POST request to the TouchCR API
touchcrApiRequestPost<T>(endpoint: string, body: BodyInit): Promise<T>;
import { touchcrApiRequestPost } from '@goldenhippo/gh-utils/touchcrApi';
const couponInfo = await touchcrApiRequestPost<GetCouponResponseDto>(
'coupon/check',
JSON.stringify({
couponCode: 'COUPONTEST10',
}),
);
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