TypeScript client for the RWAI Pulse API.
- Node.js 18 or higher
- TypeScript 5.0 or higher
- Bun 1.0 or higher
- Qlty CLI
- Zod 4 or higher (tree-shakeable via
zod/mini)
Install with Bun:
bun add @rwai/pulseOr with npm/yarn:
npm install @rwai/pulse
# or
yarn add @rwai/pulsePulse provides helpers and a workflow DSL to make analysis easy. For an overview of the helper functions see the Starter Helpers guide.
import {
sentimentAnalysis,
themeAllocation,
clusterAnalysis,
summarize,
generateDataDictionary,
} from '@rwai/pulse'
const sentiments = await sentimentAnalysis(['text1', 'text2'])
const allocation = await themeAllocation(['text1', 'text2'], ['theme1', 'theme2'])
// Themes are optional in the themeAllocation function
const allocationWithoutThemes = await themeAllocation(['text1', 'text2'])
const clusters = await clusterAnalysis(['text1', 'text2'])
const summary = await summarize(['text1', 'text2'], 'What is the gist?')
// Generate a data dictionary from tabular data
const surveyData = [
['Name', 'Age', 'City', 'Satisfaction'],
['John Doe', '25', 'New York', 'Very Satisfied'],
['Jane Smith', '30', 'Los Angeles', 'Satisfied'],
]
const dataDictionary = await generateDataDictionary(surveyData, {
title: 'Customer Survey',
description: 'Survey responses from Q1 2024',
})Configure OAuth2 credentials and create a client:
import { ClientCredentialsAuth, CoreClient } from '@rwai/pulse'
const auth = new ClientCredentialsAuth(
process.env.PULSE_CLIENT_ID!,
process.env.PULSE_CLIENT_SECRET!,
)
const client = new CoreClient({
baseUrl: 'https://api.rwai.com/pulse',
auth,
// Enable request debugging if needed
debug: true,
})Generate comprehensive DDI Codebook documentation from tabular data:
import { generateDataDictionary } from '@rwai/pulse'
const data = [
['Name', 'Age', 'City'],
['John', '25', 'New York'],
['Jane', '30', 'Los Angeles'],
]
const result = await generateDataDictionary(data)
console.log(result.getVariables())
console.log(result.getSummary())const result = await generateDataDictionary(data, {
title: 'Customer Survey 2024',
description: 'Annual customer satisfaction survey responses',
context: 'Survey conducted among retail customers',
language: 'en',
})
// Access variables
const variables = result.getVariables()
const ageVariable = result.getVariableByName('Age')
// Access value domains and categories
const valueDomains = result.getValueDomains()
const categories = result.getCategoriesForDomain('satisfaction_domain')
// Get metadata
const metadata = result.getMetadata()
console.log(metadata.title, metadata.description)import { Analyzer, GenerateDataDictionary, CoreClient } from '@rwai/pulse'
const analyzer = new Analyzer({
datasets: { surveyData: data },
processes: [
new GenerateDataDictionary({
data,
title: 'Customer Survey',
description: 'Survey responses',
}),
],
client: new CoreClient(),
fast: false, // Data dictionary always uses async mode
})
const results = await analyzer.run()
const codebook = results.generateDataDictionaryCompose analysis steps using Workflow:
import { Workflow } from '@rwai/pulse'
const wf = new Workflow()
.source('dataset', ['hello', 'world'])
.sentiment()
.theme_generation()
.cluster()
const results = await wf.run({ client })
console.log(results.sentiment.summary())const workflow = new Workflow()
.source('surveyData', [
['Name', 'Age', 'City', 'Satisfaction'],
['John Doe', '25', 'New York', 'Very Satisfied'],
['Jane Smith', '30', 'Los Angeles', 'Satisfied'],
])
.source('comments', ['Great service!', 'Could be better'])
.generateDataDictionary('surveyData', {
name: 'codebook',
title: 'Customer Survey',
})
.sentiment({ source: 'comments', name: 'commentSentiment' })
const results = await workflow.run({ client })
const codebook = results.codebook // DataDictionaryResult
const sentiment = results.commentSentiment // SentimentResultThe API is transitioning to snake_case JSON fields (e.g., job_id). The client normalizes both
formats so you can continue using camelCase names in your code.
For information on how to report security vulnerabilities see SECURITY.md.
The remainder of this document is aimed at contributors.
Generate the Typedoc reference:
bun run docsThe documentation will be written to docs/api.
Produce the distributable files:
bun run buildThis creates dist/index.js, dist/index.mjs and type declarations in dist/index.d.ts.
Run the unit tests with Bun. If you have a .env.test file in your project root, it will be loaded
automatically prior to running tests:
bun run testIntegration tests require several environment variables. Create a .env.test or .env file (or
export them in your shell) providing:
PULSE_CLIENT_IDPULSE_CLIENT_SECRETPULSE_TOKEN_URLPULSE_AUDIENCEPULSE_BASE_URL
See .env.example for a template.
Update src/models.ts from the OpenAPI schema:
bun run generateTag the repository to trigger the release workflow:
VERSION=0.1.0
git tag -s "v$VERSION" -m "v$VERSION"
git push origin "v$VERSION"Ensure NPM_TOKEN and COSIGN_PRIVATE_KEY secrets are configured so the workflow can publish the
package and sign the tarball.
Pre-built bundles, signatures and SBOM files are attached to each GitHub release.
VERSION=<tag>
curl -LO https://github.com/rwai/pulse-ts/releases/download/$VERSION/pulse-ts-$VERSION.tgz
curl -LO https://github.com/rwai/pulse-ts/releases/download/$VERSION/pulse-ts-$VERSION.tgz.sig
cosign verify-blob --key cosign.pub \
--signature pulse-ts-$VERSION.tgz.sig \
pulse-ts-$VERSION.tgzIf verification succeeds, unpack the archive and inspect sbom.xml for dependency metadata.
If you discover a security vulnerability, please report it to us. We will acknowledge receipt of your report within 2 business days and work to address the issue promptly.