npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@goldenhippo/gh-utils

v4.4.0

Published

NPM package with gh-utils methods

Downloads

4

Readme

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

.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 '@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:

.getCountries()

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:

.touchcrApiRequestPost()

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