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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@adobe/spacecat-shared-tier-client

v1.3.10

Published

Shared modules of the Spacecat Services - Tier Client

Readme

Spacecat Shared - Tier Client

Overview

The TierClient library provides methods to manage entitlements and site enrollments for the Spacecat Services. This client facilitates the creation and validation of product entitlements and site enrollments for organizations and sites.

Installation

Include the TierClient in your project by importing it from the package. Ensure that dependencies such as @adobe/spacecat-shared-utils and @adobe/spacecat-shared-data-access are also installed in your project.

import TierClient from '@adobe/spacecat-shared-tier-client';

Usage

Creating a TierClient Instance

There are three ways to create a TierClient instance:

1. Using Static Factory Methods (Recommended)

For Organization-only operations:

const context = {
  dataAccess: {
    Entitlement: /* Entitlement data access object */,
    SiteEnrollment: /* SiteEnrollment data access object */,
    Organization: /* Organization data access object */,
    Site: /* Site data access object */,
    OrganizationIdentityProvider: /* OrganizationIdentityProvider data access object */,
  },
  log: {
    info: (message) => console.log(message),
    error: (message) => console.error(message),
  },
};

const organization = {
  getId: () => 'your-org-id',
};

const productCode = 'LLMO';

// Create client for organization-only operations
const orgClient = TierClient.createForOrg(context, organization, productCode);

For Site-specific operations:

const site = {
  getId: () => 'your-site-id',
  getOrganizationId: () => 'your-org-id', // or getOrganization() method
};

// Create client for site operations
const siteClient = TierClient.createForSite(context, site, productCode);

2. Direct Constructor Usage

const context = {
  dataAccess: {
    Entitlement: /* Entitlement data access object */,
    SiteEnrollment: /* SiteEnrollment data access object */,
    Organization: /* Organization data access object */,
    Site: /* Site data access object */,
    OrganizationIdentityProvider: /* OrganizationIdentityProvider data access object */,
  },
  log: {
    info: (message) => console.log(message),
    error: (message) => console.error(message),
  },
};

const orgId = 'your-org-id';
const siteId = 'your-site-id'; // Optional for organization-only operations
const productCode = 'LLMO';

const tierClient = new TierClient(context, orgId, siteId, productCode);

Checking Valid Entitlement

To check for valid entitlement and site enrollment, use the checkValidEntitlement method.

async function checkEntitlement() {
  try {
    const result = await tierClient.checkValidEntitlement();
    
    if (result.entitlement) {
      console.log('Valid entitlement found:', result.entitlement.getId());
    }
    
    if (result.siteEnrollment) {
      console.log('Valid site enrollment found:', result.siteEnrollment.getId());
    }
    
    if (!result.entitlement) {
      console.log('No valid entitlement found');
    }
  } catch (error) {
    console.error('Error checking entitlement:', error);
  }
}

checkEntitlement();

Creating Entitlement

To create a new entitlement and site enrollment, use the createEntitlement method.

async function createEntitlement() {
  try {
    const tier = 'FREE_TRIAL'; // Valid tiers: FREE_TRIAL, PAID, etc.
    const result = await tierClient.createEntitlement(tier);
    
    console.log('Created entitlement:', result.entitlement.getId());
    console.log('Created site enrollment:', result.siteEnrollment.getId());
  } catch (error) {
    console.error('Error creating entitlement:', error);
  }
}

createEntitlement();

API Reference

Static Factory Methods

TierClient.createForOrg(context, organization, productCode)

Creates a TierClient for organization-only operations.

Parameters:

  • context (object): Context object containing dataAccess and log
  • organization (object): Organization object with getId() method
  • productCode (string): Product code (required)

Returns: TierClient instance for organization operations

TierClient.createForSite(context, site, productCode)

Creates a TierClient for site-specific operations.

Parameters:

  • context (object): Context object containing dataAccess and log
  • site (object): Site object with getId() method and either getOrganizationId() or getOrganization() method
  • productCode (string): Product code (required)

Returns: TierClient instance for site operations

Constructor

TierClient(context, orgId, siteId, productCode)

Creates a new TierClient instance directly.

Parameters:

  • context (object): Context object containing dataAccess and log
  • orgId (string): Organization ID (required)
  • siteId (string|null|undefined): Site ID (optional for organization-only operations)
  • productCode (string): Product code (required)

Returns: TierClient instance

checkValidEntitlement()

Checks for valid entitlement on organization and valid site enrollment on site.

Returns: Promise - Object with entitlement and/or siteEnrollment based on what exists

createEntitlement(tier)

Creates entitlement for organization and site enrollment for site.

Parameters:

  • tier (string): Entitlement tier (must be a valid tier from EntitlementModel.TIERS)

Returns: Promise - Object with created entitlement and siteEnrollment

Error Handling

All methods return promises. It's important to handle errors using try/catch blocks in async functions to manage database errors or validation failures gracefully.

Development

Testing

To run tests:

npm test

Linting

Lint your code:

npm run lint

Cleaning

To remove node_modules and package-lock.json:

npm run clean

Additional Information