🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@chalk-ai/client

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chalk-ai/client

TypeScript client for Chalk

1.30.0
latest
Source
npm
Version published
Weekly downloads
1.3K
33.27%
Maintainers
2
Weekly downloads
 
Created
Source

@chalk-ai/client

npm version CI

TypeScript client for Chalk.

Installation

$ yarn add @chalk-ai/client

Generate Types

Starting in your Chalk project directory, run:

$ chalk codegen typescript --out=generated_types.ts

Usage

Modern JavaScript ES6

import { ChalkClient } from "@chalk-ai/client";

// Import your generated types (recommended)
import { FeaturesType } from "local/generated_types";

// Alternatively, define features you want to pull using the client
// as an interface with the feature type and feature name.
interface FeaturesType {
  "user.id": string;
  "user.socure_score": number;
}

const client = new ChalkClient<FeaturesType>();

const result = await client.query({
  inputs: {
    "user.id": "1",
  },
  outputs: ["user.socure_score"],
});

// The property `.data` has auto-complete based on the
// list provided in `output` above. So if you try to pull
// a feature that wasn't requested, you will see an error
// in type checking.
console.log(result.data["user.socure_score"].value);

CommonJS

var ChalkClient = require("@chalk-ai/client").ChalkClient;

interface FeaturesType {
  "user.id": string;
  "user.socure_score": number;
}

var client = new ChalkClient<FeaturesType>();

client
  .query({
    inputs: {
      "user.id": "1",
    },
    outputs: ["user.socure_score"],
  })
  .then((result) => {
    console.log(result.data["user.socure_score"].value);
  });

Constructor options

new ChalkClient({
  /**
   * Your Chalk Client ID. This value will be read from the _CHALK_CLIENT_ID environment variable if not set explicitly.
   *
   * If not specified and unset by your environment, an error will be thrown on client creation
   */
  clientId?: string;

  /**
   * Your Chalk Client Secret. This value will be read from the _CHALK_CLIENT_SECRET environment variable if not set explicitly.
   *
   * If not specified and unset by your environment, an error will be thrown on client creation
   */
  clientSecret?: string;

  /**
   * The URL of your chalk API server. Defaults to https://api.chalk.ai
   */
  apiServer?: string;

  /**
   * The environment that your client will run against. This value will be read from the _CHALK_ACTIVE_ENVIRONMENT environment variable if not set explicitly.
   *
   * If not specified and unset by your environment, an error will be thrown on client creation
   */
  activeEnvironment?: string;

  /**
   * A custom fetch client that will replace the fetch polyfill used by default.
   *
   * If not provided, the client will use the default fetch polyfill (native fetch with node-fetch as a fallback).
   */
  fetch?: CustomFetchClient;

  /**
   * A custom fetch headers object that will replace the fetch Headers polyfill used by default.
   *
   * If not provided, the client will use the default fetch Headers polyfill (native fetch with node-fetch as a fallback).
   */
  fetchHeaders?: typeof Headers;

  /**
   * The format to use for date-type data.
   *
   * Defaults to "ISO_8601" (in UTC), also supports "EPOCH_MILLIS" as number of milliseconds since epoch
   */
  timestampFormat?: TimestampFormat.ISO_8601 | TimestampFormat.EPOCH_MILLIS;
})

Supported environment variables

VariableKindDescription
process.env._CHALK_CLIENT_IDRequiredYour Chalk client ID. You must specify this environment variable or pass an explicit clientId value when constructing your ChalkClient
process.env._CHALK_CLIENT_SECRETRequiredYour Chalk client secret. You must specify this environment variable or pass an explicit clientSecret value when constructing your ChalkClient
process.env._CHALK_ACTIVE_ENVIRONMENTOptionalThe environment that your client should connect to. If not specified, the client will query your project's default environment
process.env._CHALK_API_SERVEROptionalThe API server that the client will communicate with. This defaults to https://api.chalk.ai which should be sufficient for most consumers

You can find relevant variables to use with your Chalk Client by running chalk config with the Chalk command line tool.

$ chalk config

Path:          ~~~
Name:          Organization Token
Client Id:     <client-id>
Client Secret: <client-secret>
Environment:   <active-environment>
API Server:    https://api.chalk.ai
Valid Until:   2023-11-10T06:11:17.516000

FAQs

Package last updated on 28 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts