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

sfcc-cip-analytics-client

v0.0.9

Published

SFCC Commerce Intelligence Platform Analytics Client

Readme

SFCC Commerce Intelligence Platform Analytics Client

A TypeScript/Node.js client library and CLI tool for querying Salesforce Commerce Cloud (SFCC) Commerce Intelligence Platform (CIP) analytics data through the use of the JDBC protocol. This client abstracts the underlying Avatica protobuf protocol and provides both programmatic and command-line interfaces for accessing your commerce analytics data.

See https://developer.salesforce.com/docs/commerce/b2c-commerce/guide/jdbc_intro.html for the details of the JDBC driver used with Java applications as well as the business object and schema reference.

Screenshot of CLI output

Installation

npm install sfcc-cip-analytics-client

Global CLI Installation

npm install -g sfcc-cip-analytics-client
# Now you can use: cip-query "SELECT * FROM table"

CLI Usage

Screenshot of CLI

Configuration

The CLI can be configured using environment variables or command-line options. Your Account Manager API client must have the SALESFORCE_COMMERCE_API:[instance] role and tenant filter.

Environment Variables

export SFCC_CLIENT_ID="your-client-id"
export SFCC_CLIENT_SECRET="your-client-secret"
export SFCC_CIP_INSTANCE="your-instance-name" # example abcd_prd

# Optional: Enable debug logging
export SFCC_DEBUG=true

Command-line Options

You can also provide credentials directly via CLI options (these override environment variables):

cip-query sql --client-id "your-client-id" \
              --client-secret "your-client-secret" \
              --instance "your-instance-name" \
              "SELECT * FROM ccdw_aggr_ocapi_request LIMIT 10"

Commands

The CLI supports two main commands:

sql - Execute custom SQL queries

cip-query sql "SELECT * FROM ccdw_aggr_ocapi_request LIMIT 10"

query - Execute predefined business object queries

cip-query query --list
cip-query query --name ocapi-requests --from "2024-01-01" --to "2024-01-31"

Basic Query

cip-query sql "SELECT * FROM ccdw_aggr_ocapi_request LIMIT 10"

With Date Placeholders

cip-query sql --from "2024-07-01" --to "2024-07-31" \
  "SELECT * FROM ccdw_aggr_ocapi_request WHERE request_date >= <FROM> AND request_date <= <TO>"

Different Output Formats

# JSON output
cip-query sql --format json "SELECT api_name, COUNT(*) as count FROM ccdw_aggr_ocapi_request GROUP BY api_name"

# CSV output for spreadsheet analysis
cip-query sql --format csv --from "last week" \
  "SELECT * FROM ccdw_aggr_ocapi_request WHERE request_date >= <FROM>"

Using Heredocs (Multi-line SQL)

cip-query sql --format json --from "2024-01-01" --to "2024-01-31" <<SQL
  SELECT 
    api_name,
    "method",
    AVG(response_time) as avg_response_time,
    COUNT(*) as request_count
  FROM ccdw_aggr_ocapi_request 
  WHERE request_date >= <FROM> 
    AND request_date <= <TO>
  GROUP BY api_name, "method"
  ORDER BY request_count DESC
SQL

From Files

# Save complex queries in .sql files
cip-query sql --format csv < my-analytics-query.sql

API Usage

Low Level Client

import { CIPClient } from 'sfcc-cip-analytics-client';

const client = new CIPClient(
  process.env.SFCC_CLIENT_ID!,
  process.env.SFCC_CLIENT_SECRET!,
  process.env.SFCC_CIP_INSTANCE!
);

async function queryData() {
  // direct statement execution
  try {
    await client.openConnection();
    const statementId = await client.createStatement();
    
    const result = await client.execute(
      statementId, 
      "SELECT * FROM ccdw_aggr_ocapi_request LIMIT 10"
    );
    
    // see example/basic.ts for more details on result structure
    console.table(result);
    
    await client.closeStatement(statementId);
  } finally {
    await client.closeConnection();
  }
}

queryData();

Type-Centric Parameterized Queries

import { CIPClient, executeParameterizedQuery } from 'sfcc-cip-analytics-client';

interface OCAPISummary {
  request_date: string;
  site_id: string;
  api_resource: string;
  num_requests: number;
}

try {
  await client.openConnection();
  
  const query = executeParameterizedQuery<OCAPISummary>(
    client,
    `SELECT request_date,site_id,api_resource,SUM(num_requests) as requests FROM
      ccdw_aggr_ocapi_request
    WHERE
      request_date >= '2024-01-01'
    AND request_date <= '2024-01-31'
    GROUP BY request_date,site_id,api_resource`,
    [],
    100 // batch size
  );
  
  for await (const batch of query) {
    console.log(`Processed ${batch.length} ocapi requests`);
    for (const record of batch) {
      // Each record is typed as OCAPISummary
      console.log(record.api_resource);
    }
  }
} finally {
  await client.closeConnection();
}


queryData();

High Level Business Use Case Queries

The client provides specialized query functions for common business analytics use cases. These return simple arrays of plain old JavaScript objects, making it easy to work with the data.

For complete documentation of all available business queries, see Business Queries Reference.

import { CIPClient, querySalesAnalytics } from 'sfcc-cip-analytics-client';

const client = new CIPClient(clientId, clientSecret, instance);

async function analyzeSalesData() {
  await client.openConnection();
  
  const query = querySalesAnalytics(
    client,
    { siteId: 'Sites-RefArch-Site', startDate: new Date('2024-01-01'), endDate: new Date('2024-01-31') },
    100 // batch size
  );
  
  for await (const batch of query) {
    console.log(`Processed ${batch.length} daily sales metrics`);
    // Each record has: date, std_revenue, orders, std_aov, units, aos
  }
  
  await client.closeConnection();
}

Examples

See the examples/ directory for complete working examples:

Development Setup

Prerequisites

  • Node.js 18+ or Bun
  • SFCC Commerce Cloud production access with CIP Analytics enabled

Getting Started

  1. Clone and install

    git clone <repository-url>
    # ...
    npm install
  2. Build the project

    npm run build
  3. Run linting

    npm run lint

API Documentation

CIPClient

Main client class for interacting with CIP.

Constructor

new CIPClient(clientId: string, clientSecret: string, instance: string, options?: CIPClientOptions)

Methods

  • openConnection(info?: IConnectionProperties): Promise<void> - Open database connection
  • closeConnection(): Promise<void> - Close database connection
  • createStatement(): Promise<number> - Create a new SQL statement
  • closeStatement(statementId: number): Promise<void> - Close a statement
  • execute(statementId: number, sql: string, maxRowCount?: number): Promise<NormalizedExecuteResponse> - Execute SQL query
  • fetch(statementId: number, offset: number, fetchMaxRowCount: number): Promise<NormalizedFetchResponse> - Fetch more results
  • prepare(sql: string, maxRowsTotal?: number): Promise<IPrepareResponse> - Prepare a SQL statement with parameter placeholders
  • executeWithParameters(statementHandle: IStatementHandle, parameters?: any[], firstFrameMaxSize?: number): Promise<IExecuteResponse> - Execute a prepared statement with parameters
  • prepareAndExecuteWithParameters(sql: string, parameters?: any[], firstFrameMaxSize?: number): Promise<IExecuteResponse> - Prepare and execute a statement with parameters in one call

Todo

  • [ ] support proxy / fetch replacement (for browser use and advanced proxy scenarios)
  • [ ] static build of protobuf for web use

License

Licensed under the current NDA and licensing agreement in place with your organization. (This is explicitly not open source licensing.)

Support

This project should not be treated as Salesforce Product. It is a tool B2C instances. Customers and partners implement this at-will with no expectation of roadmap, technical support, defect resolution, production-style SLAs.

This project is maintained by the Salesforce Community. Salesforce Commerce Cloud or Salesforce Platform Technical Support do not support this project or its setup.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.

For feature requests or bugs, please open a GitHub issue.