open-index/open-npm huggingface dataset:
npm package: @global-savings-group/caa-engine
Description: Coupon Auto Applier - Engine
Author: Global Savings Group: Browser Extension Domain
Latest version: 4.5.1

# Coupon Auto Applier Engine

In an age where bits and trade convene,
Digital tapestries weave, a modern scene.
Coupons, a currency of savvy minds,
Frugal artistry, where innovation finds.

Discount's embrace, a societal thread,
Marketplace dreams by it are spread.
Wise wallets wield its saving grace,
Balance struck in life's bustling chase.

Yet time's a jewel, its moments dear,
In ceaseless quests, it disappears.
Here strides JavaScript, a code maestro,
Library's API, a star's bright echo.

With patterns enforced, development soars,
Stability across, a promise it pours.
Products diverse, yet work stable and sound,
Innovation thrives, on solid ground.

Auto applying coupons, the library's feat,
A tap of keys, and savings greet.
Rapid trials of codes, it deftly assays,
A dance of scripts in complex arrays.

Oh, marvel at this technological art,
Where codes and commerce entwine, impart.
Efficiency crafted through lines of script,
Society transformed, a paradigm shift.

Raise a cheer for the library, bold and grand,
In the digital realm, where futures expand.
Discounts unfurl, time finds a new hue,
In the coded domains, dreams ring true.
npm package: @global-savings-group/extension-cli
Description: GSG Extension Framework Command Line Interface
Author: Global Savings Group
Latest version: 0.2.0

# GSG Browser Extension Framework CLI

## Usage
`npx @global-savings-group/extension-cli init <directory>` - interactive guide to create new browser extension project or update existing one

`npx @global-savings-group/extension-cli init <directory> --i18n "en, de, fr"` - add or create `en`, `de` and `fr` localizations; "en" will be set as default
npm package: @global-savings-group/extension-google-analytics
Description: Extension library for Google Analytics 4
Author: Global Savings Group
Latest version: 1.0.1

# Extension library for Google Analytics


### Usage
```typescript
import { GoogleAnalytics } from "@global-savings-group/extension-google-analytics"
import { localStorageService } from "../services/storage";

const googleAnalytics = new GoogleAnalytics({
  apiSecret: '{API_SECRET}',
  measurementId: '{MEASUREMENT_ID}',
  storage: localStorageService,
});

googleAnalytics.sendEvent('view_notification', { retailer_name: 'Samsung' });

```
npm package: @global-savings-group/extension-logs
Description: Browser Extension DataDog monitoring & logging service
Author: Global Savings Group
Latest version: 2.2.6

# Extension logs and monitoring service

Based on DataDog and required Megatron clientHash as session ID.

Documentation: https://docs.datadoghq.com/logs/error_tracking/browser_and_mobile?tab=browser

## Usage

Install package:

- `npm install @global-savings-group/extension-logs`

Import log service and init in project:

```typescript
// Logger.ts
import { ExtensionLogsService } from '@global-savings-group/extension-logs';

// IMPORTANT: 
// If using more than one instance of ExtensionLogsService, 
// each instance must have a unique store key.
// In the example below, the default store key is "DataDogLogger".
export const logsService = new ExtensionLogsService();

/**
 * init() can be called asynchronously and any log calls (debug, error, info, warn) will be queued until then
 * init() can be called multiple times to change options or enable/disable logging
 * if init() is not called within 60s, it logs error to console as reminder to avoid memory leaks
 */
logsService.init({
  // required for enabling logging to DataDog API
  // if omitted or set to undefined - logging is disabled
  clientToken: '{DataDog client token}',
  
  // optional; values: 'local' | 'production' | 'staging'
  env: 'production',
  
  // required
  service: '{brand}:extension',
  
  // optional session ID
  sessionId: '{Megatron clientHash}',

  // optional - send logs for X% of sessions
  // value [0..1] - 0%..100%; default value - 1 (send logs for all sessions)
  sessionSampleRate: 0.2, // log 20% of all sessions
  
  // optional - limit logs per 24h that are sent to DataDog
  // default value - undefined (send all logs)
  threshold: 2000,
  
  // optional version
  version: chrome.runtime.getManifest().version,
});

logsService.logConsoleErrors();
logsService.logUnhandledErrors();

/**
 * ExtensionLogsService logs
 *
 * Every log method accepts these params:
 * - message: string
 * - data?: object - additional data
 * - forceLog?: boolean - set to true to always log, overriding the sessionSampleRate set in init() or threshold value
 */

logsService.debug({
  message: 'Debug message',
  data: { 'x': 'y' }, // addtional log data
  forceLog: true, // force logging; ignores sessionSampleRate or threshold
});

logsService.error({
  message: 'Error message',
  origin: 'custom',
  stack: '{call stack as string}'
});

logsService.info({
  message: 'Info message',
});

logsService.warn({
  message: 'Warn message',
});
``` 

Enable session logging:

```typescript
// background.ts
const sessionTrackAlarmName = 'session:track';
chrome.alarms.onAlarm.addListener(async (alarm) => {
  if (alarm.name === sessionTrackAlarmName) {
    logsService.ping();
  }
});

chrome.alarms.create(sessionTrackAlarmName, { periodInMinutes: 10 });
```

Optionally, `ping()` supports callback to add custom session data:

```typescript
const getSessionData = () => ({
  my_custom_session_data: 'some data',
  another_key: 'more data',
});

logsService.ping(getSessionData);
```
npm package: @global-savings-group/extension-megatron
Description: Megatron analytics library
Author: Global Savings Group
Latest version: 1.3.7

# Megatron analytics library

Requires next [permissions](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) in manifest.json:
- `alarms` - send keep-alive notifications
- `storage` - store customerHash and last keep-alive notification date

## Usage

Init Megatron singleton object anytime when all required params loaded/available:
```typescript
import { BusinessModel, megatron } from '@global-savings-group/extension-megatron';

await megatron.init({
  apiUrl: '{API URL}',
  businessModel: BusinessModel.Conversion, // optional field, ask BI team for value
  customerHash: '{customerHash}', // customerHash as string or undefined for auto-generation
  trackId: '{track ID}', // ask BI team for unique trackId
  trackUrlPrefix: 'https://website', // automatic URL prefix for "/page/urls"
  version: chrome.runtime.getManifest().version,
});
```

Track page view (can be called even before `.init()`):
```typescript
import { megatron } from '@global-savings-group/extension-megatron'

// `trackUrlPrefix` will be added automatically before for all URLs started with "/"
await megatron.trackPageView({
  title: 'optional page title',
  url: '/page/url' 
});
```

Keep alive notifications:
```typescript
import { megatron } from '@global-savings-group/extension-megatron'

// Recommended check interval is 5-10 minutes, Megatron will send it only once per 24h
chrome.alarms.create('megatron:ping', { periodInMinutes: 10 });

// add global onAlarm listener or add logic to the beginning of existing listener
chrome.alarms.onAlarm.addListener((alarm) => {
  if(alarm.name === 'megatron:ping'){
    megatron.init({...});
    megatron.ping();
    return;
  }
  
  // ... other event handlers
});
```
npm package: @global-savings-group/extension-serp
Description: Browser Extension Search Engine Result Page
Author: Global Savings Group
Latest version: 2.0.3

# Usage
Init Serp singleton object in Injection file with callback functions that renders the UI part.

```typescript
import { Serp, Theme, SearchEngine, BadgeDataSet } from '@global-savings-group/extension-serp'

const renderUI = (
  partnerLink: Element,
  theme: Theme,
  searchEngine: SearchEngine,
  container: HTMLElement,
) => {
  const customDomain = partnerLink.getAttribute("href");

  chrome.runtime.sendMessage(
    {
      type: "check-partner",
      param: { customDomain },
    },
    (partner: Partner) => {
      if (!partner) {
        return;
      }
      if (partner.vouchers.length > 0 || partner.deals.length > 0) {
        const emptyElement = document.createElement("div");
        emptyElement.dataset[BadgeDataSet.key] = BadgeDataSet.value;
        render(
          SERPBadge({
            vouchersCount: partner.vouchers.length,
            theme,
            searchEngine,
          }),
          emptyElement
        );
        Serp.insertElementTo(container, emptyElement);
      }
    }
  );
};

const sendAnalytics = (partnerName: string): void => {
  sendMessage(MESSAGE_TYPE.SEND_GA, {
    name: 'view_serp',
    params: {
      retailer_name: partnerName,
    },
  });
};

const EXTENSION_NAME = 'Extension Name';

const getSERPSettings = () =>
  chrome.runtime.sendMessage({ type: "get-serp-settings" });

getSERPSettings().then((SERPSettings: iSERPSettings) => {
  if (SERPSettings.enabled) {
    Serp.init(renderBadgePartner, sendAnalytics, EXTENSION_NAME);
  }
});

```
npm package: @global-savings-group/extension-storage
Description: Cross-browser storage service for browser extensions
Author: Global Savings Group
Latest version: 0.3.1

# Cross-browser storage service for browser extensions

## Usage

```typescript
import { localStorageService, sessionStorageService } from '@global-savings-group/extension-storage';

setTimeout(async () => {
  const localData = await localStorageService.get('key') ?? 1000;
  await localStorageService.set('key', localData + 1);
  console.log(`Local data: ${localData}`);

  const sessionData = await sessionStorageService.get('key') ?? 2000;
  await sessionStorageService.set('key', sessionData + 1);
  console.log(`Session data: ${sessionData}`);
}, 5000);

```
npm package: @global-savings-group/extension-utils
Description: Utilities for browser extensions
Author: Global Savings Group
Latest version: 0.3.0

# Browser extension utilities

### AffiliateNetworkService

```typescript
import { AffiliateNetworkService } from '@global-savings-group/extension-utils';

const affiliateNetworkService = new AffiliateNetworkService();

async function activateAffiliateNetwork() {
  ...
  try {
    await affiliateNetworkService.activate(affiliateLink);
  } catch (e){
    console.error('Cannot activate affiliate network', e);
  }
};

// subscribe to tab update events to close tab after activating affiliate network
chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo) => {
  if (affiliateNetworkService.isActivationTab(tabId)) {
    affiliateNetworkService.onUpdated(tabId, changeInfo);
    return;
  }
  
  // other code/logic
});

```

### RemoteConfigService

```typescript
import { RemoteConfigService } from '@global-savings-group/extension-utils';

/**
 * {TIMESTAMP} is optional placeholder to be replaced with current timestamp, rounded down to cache duration
 */
const remoteConfigService = new RemoteConfigService('https://api.service.com/config.json?z={TIMESTAMP}');

const config = await remoteConfigService.get(); // returns remote config or undefined
console.log(config);
```