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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bluecopa/core

v0.1.34

Published

The core package provides essential API utilities and functions for data management, workbook handling, dataset operations, and definition execution in the Bluecopa platform.

Readme

@bluecopa/core

The core package provides essential API utilities and functions for data management, workbook handling, dataset operations, and definition execution in the Bluecopa platform.

Table of Contents

Version

Current version: 0.1.4

Installation

npm install @bluecopa/core

Requirements

  • Node.js >= 18.0.0
  • Dependencies:
    • axios (1.12.0) - For HTTP requests
    • lodash (4.17.21) - For utility functions
    • centrifuge (5.0.0) - For WebSocket connections

Configuration

The package uses a singleton-based configuration system to manage API settings. Configure it before making API calls.

Import and set the config:

import { copaSetConfig, copaApi } from '@bluecopa/core';

copaSetConfig({
  apiBaseUrl: 'https://develop.bluecopa.com', // Base URL for API endpoints
  accessToken: 'your-access-token',       // Authentication token
  workspaceId: 'your-workspace-id',       // Current workspace identifier
  userId: 'your-user-id'                  // User identifier for WebSocket connections
});

Getting User Details and Setting User ID

To automatically set the userId from the logged-in user:

import { copaSetConfig, copaApi } from '@bluecopa/core';

// First configure basic settings
copaSetConfig({
  apiBaseUrl: 'https://develop.bluecopa.com',
  accessToken: 'your-access-token',
  workspaceId: 'your-workspace-id'
});

// Get user details and set userId
try {
  const userDetails = await copaApi.user.getLoggedInUserDetails();
  copaSetConfig({ userId: userDetails.id });
  console.log('User ID set:', userDetails.id);
} catch (error) {
  console.error('Failed to get user details:', error);
}
  • copaSetConfig(partialConfig: Partial<Config>): Updates the configuration.
  • copaGetConfig(): Retrieves the current configuration.
  • resetConfig(): Resets to default empty values.

The Config interface:

export interface Config {
  apiBaseUrl: string;
  accessToken: string;
  workspaceId: string;
  userId: string;
}

API Reference

All API functions are asynchronous and use the shared apiClient for HTTP requests. They handle errors by throwing objects with message and status. Access via copaApi.moduleName.functionName().

Dataset Module

  • copaApi.dataset.getData(): Retrieves specific dataset data by ID or parameters
  • copaApi.dataset.getDatasets(): Fetches a list of datasets
  • copaApi.dataset.getSampleData(): Gets sample data for datasets

See: dataset/getData.ts, dataset/getSampleData.ts, dataset/getDatasets.ts

Definition Module

  • copaApi.definition.runDefinition(): Executes a custom definition
  • copaApi.definition.runPublishedDefinition(): Runs a published definition
  • copaApi.definition.runSampleDefinition(): Executes a sample definition for testing

See: definition/runPublishedDefinition.ts, definition/runSampleDefinition.ts, definition/runDefinition.ts

File Module

  • copaApi.files.getFileUrlByFileId(fileId: string): Generates a URL for a file by its ID

See: file/getFileUrlByFileId.ts

InputTable Module

  • copaApi.inputTable.getData(): Retrieves data from an input table
  • copaApi.inputTable.getInputTables(): Fetches all input tables
  • copaApi.inputTable.getTableById(id: string): Gets a specific input table by ID

See: inputTable/getData.ts, inputTable/getInputTables.ts, inputTable/getTableById.ts

Metric Module

  • copaApi.metric.getData(): Fetches metric data

See: metric/getData.ts

User Module

  • copaApi.user.getLoggedInUserDetails(): Retrieves details of the currently logged-in user

See: user/getLoggedInUserDetails.ts

Workbook Module

  • copaApi.workbook.getPublishedWorkbookById(id: string): Fetches a published workbook by ID
  • copaApi.workbook.getWorkbooksByType(type: string): Retrieves workbooks filtered by type

See: workbook/getPublishedWorkbookById.ts, workbook/getWorkbooksByType.ts

Workflow Module

  • copaApi.workflow.getWorkflowInstanceStatusById(id: string): Checks the status of a workflow instance
  • copaApi.workflow.triggerHttpWorkflowById(id: string): Triggers an HTTP-based workflow
  • copaApi.workflow.triggerWorkflowById(id: string): Triggers a workflow by ID

See: workflow/triggerHttpWorkflowById.ts, workflow/triggerWorkflowById.ts, workflow/getWorkflowInstanceStatusById.ts

Worksheet Module

  • copaApi.worksheet.getWorksheets(): Fetches all worksheets
  • copaApi.worksheet.getWorksheetsByType(type: string): Retrieves worksheets by type

See: worksheet/getWorksheets.ts, worksheet/getWorksheetsByType.ts

WebSocket Connection

The core package provides WebSocket utilities for real-time communication using Centrifugo.

WebSocket Factory

Access WebSocket functionality through the utilities:

import { copaUtils } from '@bluecopa/core';

// Create a WebSocket connection
const websocket = copaUtils.websocketUtils.WebsocketContextFactory.create('centrifugo', {
  connectionUrl: 'wss://your-centrifugo-url'
});

WebSocket Provider Interface

The IWebsocketProvider interface provides the following methods:

  • connect(): Establishes the WebSocket connection
  • bind(channel: string, event: string, callback: (data: any) => void): Subscribe to private user-specific channels
  • bindGlobal(event: string, callback: (data: any) => void): Subscribe to global channels
  • unbindAll(channel: string): Unsubscribe from all events on a channel
  • disconnect(): Close the WebSocket connection

WebSocket Usage Example

import { copaSetConfig, copaApi, copaUtils } from '@bluecopa/core';

// Configure with userId for WebSocket connections
copaSetConfig({
  apiBaseUrl: 'https://develop.bluecopa.com',
  accessToken: 'your-access-token',
  workspaceId: 'your-workspace-id',
  userId: 'your-user-id'
});

// Create WebSocket connection
const websocket = copaUtils.websocketUtils.WebsocketContextFactory.create('centrifugo', {
  connectionUrl: 'wss://centrifugo.your-domain.com/connection/websocket'
});

// Subscribe to user-specific events
websocket.bind('notifications', 'new_message', (data) => {
  console.log('New notification:', data);
});

// Subscribe to global events
websocket.bindGlobal('system_updates', (data) => {
  console.log('System update:', data);
});

// Clean up when done
websocket.disconnect();

WebSocket Requirements

  • userId: Required for private channel subscriptions (bind method)
  • accessToken: Required for authentication with Centrifugo
  • connectionUrl: WebSocket endpoint URL

The WebSocket connection automatically uses the configured accessToken and userId from the config for authentication and channel binding.

Examples

1. Complete Setup with User Details and WebSocket

Complete example showing configuration, user details retrieval, and WebSocket setup.

import { copaSetConfig, copaApi, copaUtils } from '@bluecopa/core';

// Initial configuration
copaSetConfig({
  apiBaseUrl: 'https://develop.bluecopa.com',
  accessToken: 'your-access-token',
  workspaceId: 'your-workspace-id'
});

// Get user details and set userId
try {
  const userDetails = await copaApi.user.getLoggedInUserDetails();
  copaSetConfig({ userId: userDetails.id });
  console.log('User configured:', userDetails.name, userDetails.id);
} catch (error: any) {
  console.error('Failed to get user details:', error.message, error.status);
}

// Set up WebSocket connection
const websocket = copaUtils.websocketUtils.WebsocketContextFactory.create('centrifugo', {
  connectionUrl: 'wss://centrifugo.develop.bluecopa.com/connection/websocket'
});

// Subscribe to notifications
websocket.bind('notifications', 'new_message', (data) => {
  console.log('New notification received:', data);
});

2. Get Input Tables

Fetches all input tables from the API.

import { copaApi } from '@bluecopa/core';

// Configure first
copaSetConfig({ 
  apiBaseUrl: 'https://api.example.com', 
  accessToken: 'token', 
  workspaceId: 'ws1',
  userId: 'user123'
});

// Use API
const { getInputTables } = copaApi.inputTable;
const { getWorkbooksByType } = copaApi.workbook;

3. Get Workbooks by Type

Retrieves workbooks filtered by a specific type.

import { copaApi } from '@bluecopa/core';
import type { Worksheet } from "$models/gen/Api";

try {
  const workbooks = await copaApi.workbook.getWorkbooksByType('dashboard' as Worksheet["type"]);
  console.log(workbooks); // Array of Worksheet
} catch (error: any) {
  console.error(error.message, error.status);
}

Development

  • Run the build: npm run build (in the root or package-specific script)
  • TypeScript configuration: See tsconfig.json
  • Vite configuration: See vite.config.ts

Related Packages