{"id":15853,"library":"tas-client","title":"TAS Client for Experimentation Services","description":"The `tas-client` package, currently at version 0.3.2, provides a client-side library for querying, refetching, and caching data from an experimentation service endpoint. It is specifically designed to interact with endpoints whose results conform to a required experimentation data structure. This client library emphasizes integration via consumer-provided implementations of key interfaces, including `IExperimentationFilterProvider`, `IExperimentationTelemetry`, and `IKeyValueStorage`, allowing for flexible integration with various application environments. Its focus on managing experiment data, including features like configurable refetch intervals and treatment variable retrieval, differentiates it from generic HTTP clients by providing specialized logic for experimentation workflows. Given its `0.x` version, releases are likely feature-driven and ad-hoc rather than on a fixed schedule, indicating an active but evolving development phase.","status":"active","version":"0.3.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","tas-client","typescript"],"install":[{"cmd":"npm install tas-client","lang":"bash","label":"npm"},{"cmd":"yarn add tas-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add tas-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime environment requirement for the package.","package":"node","optional":false}],"imports":[{"note":"The package is designed for modern Node.js environments and is typically consumed via ESM imports.","wrong":"const TASClient = require('tas-client');","symbol":"TASClient","correct":"import { TASClient } from 'tas-client';"},{"note":"This is an interface that consumers must implement to provide experiment filtering capabilities to the TASClient. Use `import type` for type-only imports in TypeScript.","symbol":"IExperimentationFilterProvider","correct":"import type { IExperimentationFilterProvider } from 'tas-client';"},{"note":"This interface must be implemented by the consumer to integrate custom telemetry reporting with the TASClient. Use `import type` for type-only imports in TypeScript.","symbol":"IExperimentationTelemetry","correct":"import type { IExperimentationTelemetry } from 'tas-client';"},{"note":"This interface must be implemented by the consumer to provide key-value storage for the TASClient's caching mechanisms. Use `import type` for type-only imports in TypeScript.","symbol":"IKeyValueStorage","correct":"import type { IKeyValueStorage } from 'tas-client';"}],"quickstart":{"code":"import { TASClient, type IExperimentationFilterProvider, type IExperimentationTelemetry, type IKeyValueStorage } from 'tas-client';\n\n// Minimal implementation of IExperimentationFilterProvider\nclass MyFilterProvider implements IExperimentationFilterProvider {\n  getFilters(): Record<string, string> {\n    return { 'userSegment': 'premium' };\n  }\n}\n\n// Minimal implementation of IExperimentationTelemetry\nclass MyTelemetry implements IExperimentationTelemetry {\n  async postEvent(eventName: string, properties: Record<string, any>): Promise<void> {\n    console.log(`Telemetry event: ${eventName}`, properties);\n  }\n}\n\n// Minimal implementation of IKeyValueStorage\nclass MyKeyValueStorage implements IKeyValueStorage {\n  private store: Record<string, string> = {};\n  async get(key: string): Promise<string | undefined> {\n    console.log(`Getting key: ${key}`);\n    return this.store[key];\n  }\n  async set(key: string, value: string): Promise<void> {\n    console.log(`Setting key: ${key} to value: ${value}`);\n    this.store[key] = value;\n  }\n}\n\nasync function runTasClient() {\n  const filterProvider = new MyFilterProvider();\n  const telemetry = new MyTelemetry();\n  const keyValueStorage = new MyKeyValueStorage();\n  const storageKey = 'myTasClientCache'; // Unique key for storage\n  const tasEndpoint = process.env.TAS_ENDPOINT ?? 'https://api.example.com/experimentation'; // Replace with actual endpoint\n  const refetchInterval = 60 * 60 * 1000; // Refetch every hour\n\n  const tasClient = new TASClient({\n    filterProviders: [filterProvider],\n    telemetry: telemetry,\n    storageKey: storageKey,\n    keyValueStorage: keyValueStorage,\n    assignmentContextTelemetryPropertyName: 'assignmentContext',\n    telemetryEventName: 'tasClientEvent',\n    endpoint: tasEndpoint,\n    refetchInterval: refetchInterval,\n  });\n\n  // Wait for initialization to complete before getting synchronous treatment variables\n  await tasClient.initializePromise;\n\n  const treatmentVariable = tasClient.getTreatmentVariable('myConfigId', 'featureFlag');\n  console.log(`Treatment variable for 'featureFlag': ${treatmentVariable}`);\n\n  // Alternatively, if not awaiting initializePromise:\n  const treatmentVariableAsync = await tasClient.getTreatmentVariableAsync('anotherConfigId', 'anotherFeature');\n  console.log(`Async treatment variable for 'anotherFeature': ${treatmentVariableAsync}`);\n}\n\nrunTasClient().catch(console.error);","lang":"typescript","description":"This quickstart demonstrates how to instantiate and use `TASClient` by providing minimal implementations for its required interfaces (`IExperimentationFilterProvider`, `IExperimentationTelemetry`, `IKeyValueStorage`), initializing the client, and retrieving experiment treatment variables both synchronously and asynchronously after awaiting initialization."},"warnings":[{"fix":"Ensure `await tasClient.initializePromise;` is called before any synchronous `getTreatmentVariable()` calls. Alternatively, use the asynchronous `await tasClient.getTreatmentVariableAsync()` method, which handles initialization internally.","message":"The synchronous `getTreatmentVariable()` method requires `tasClient.initializePromise` to be awaited beforehand to ensure the client is fully initialized and data is fetched. Failure to do so may result in unexpected behavior or `undefined` values.","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Upgrade your Node.js environment to version 22 or newer to meet the package's engine requirements. Consider using a Node.js version manager like `nvm` to manage multiple Node.js versions.","message":"This package explicitly requires Node.js version 22 or higher as specified in its `engines` field in `package.json`. Running it on older Node.js versions will likely lead to runtime errors or installation issues.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Thoroughly review the `IExperimentationFilterProvider`, `IExperimentationTelemetry`, and `IKeyValueStorage` interfaces and provide complete, robust implementations for each method. Ensure these implementations handle potential errors and asynchronous operations correctly.","message":"The `TASClient` constructor requires implementations of `IExperimentationFilterProvider`, `IExperimentationTelemetry`, and `IKeyValueStorage`. Providing incomplete or incorrect implementations of these interfaces will cause the client to malfunction or throw errors during operation.","severity":"gotcha","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are using `import { TASClient } from 'tas-client';` for ESM environments. Verify your `tsconfig.json` (for TypeScript) or `package.json` (`\"type\": \"module\"`) is configured for ESM.","cause":"Attempting to use CommonJS `require` syntax (`const TASClient = require('tas-client');`) in an environment where the package is published as an ESM module, or incorrect named import.","error":"TypeError: tasClient is not a constructor"},{"fix":"Double-check that all required properties (`filterProviders`, `telemetry`, `keyValueStorage`, `endpoint`, etc.) are correctly provided and configured in the `TASClient` constructor. Ensure your experimentation service endpoint returns data in the format the `tas-client` expects.","cause":"This typically occurs if the `TASClient` instance was not properly initialized due to missing or invalid constructor parameters, or if the underlying endpoint did not return data conforming to the expected experimentation structure, leading to an uninitialized internal state.","error":"TypeError: Cannot read properties of undefined (reading 'getTreatmentVariable')"}],"ecosystem":"npm"}