{"id":15852,"library":"tas-client-umd","title":"TAS Client UMD Module","description":"tas-client-umd is a Unified Module Definition (UMD) repackaging of the core `tas-client` module, designed to provide a client for interacting with an experimentation service, typically a Treatment Assignment Service (TAS). Its primary function is to query, refetch, and cache experimentation data, often referred to as \"flights\" or \"treatment variables,\" from a specified endpoint. This package, currently at version 0.2.0, targets early-stage development with an implied unstable release cadence typical of pre-1.0 software. A key aspect of its design is the requirement for consumers to implement specific interfaces: `IExperimentationFilterProvider` for supplying contextual filters, `IExperimentationTelemetry` for logging events and shared properties, and `IKeyValueStorage` for persistent data storage. This dependency injection approach allows for flexible integration into various environments and telemetry systems. Its UMD format differentiates it by ensuring compatibility across CommonJS, AMD, and browser global environments, making it versatile for diverse JavaScript ecosystems, particularly where `tas-client` is used.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","tas-client","umd","typescript"],"install":[{"cmd":"npm install tas-client-umd","lang":"bash","label":"npm"},{"cmd":"yarn add tas-client-umd","lang":"bash","label":"yarn"},{"cmd":"pnpm add tas-client-umd","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For CommonJS, use destructuring: `const { TASClient } = require('tas-client-umd');`. Direct `require()` without destructuring will yield an object containing the exports.","wrong":"const TASClient = require('tas-client-umd');","symbol":"TASClient","correct":"import { TASClient } from 'tas-client-umd';"},{"note":"All interfaces are named exports. This package ships TypeScript types.","wrong":"import IExperimentationService from 'tas-client-umd';","symbol":"IExperimentationService","correct":"import { IExperimentationService } from 'tas-client-umd';"},{"note":"Type-only import for interfaces when not used as a value, for bundler tree-shaking and type safety.","symbol":"IKeyValueStorage","correct":"import type { IKeyValueStorage } from 'tas-client-umd';"}],"quickstart":{"code":"import { TASClient } from 'tas-client-umd';\n\n// Mock implementations for required interfaces\nconst mockFilterProvider = {\n    getFilters: () => new Map([['region', 'us'], ['platform', 'web']])\n};\n\nconst mockTelemetry = {\n    setSharedProperty: (name, value) => console.log(`Telemetry shared property: ${name}=${value}`),\n    postEvent: (eventName, props) => console.log(`Telemetry event: ${eventName}, props: ${JSON.stringify(Object.fromEntries(props))}`)\n};\n\nconst mockKeyValueStorage = {\n    _storage: new Map(),\n    getValue: async (key, defaultValue) => {\n        const value = mockKeyValueStorage._storage.get(key);\n        return value !== undefined ? value : defaultValue;\n    },\n    setValue: (key, value) => {\n        mockKeyValueStorage._storage.set(key, value);\n    }\n};\n\nconst tasClient = new TASClient({\n    filterProviders: [mockFilterProvider],\n    telemetry: mockTelemetry,\n    storageKey: 'my-tas-experiments',\n    keyValueStorage: mockKeyValueStorage,\n    assignmentContextTelemetryPropertyName: 'myExpContext',\n    telemetryEventName: 'MyExperimentationQuery',\n    endpoint: process.env.TAS_ENDPOINT ?? 'https://example.com/tas-api', // Replace with your actual endpoint\n    refetchInterval: 30000 // Refetch every 30 seconds\n});\n\n// Initialize the client and fetch a treatment variable\ntasClient.initializePromise.then(async () => {\n    console.log('TASClient initialized successfully.');\n    // Example: Getting a treatment variable\n    const treatmentValue = await tasClient.getTreatmentVariable('my-feature-config', 'my-variable-name');\n    console.log(`Treatment variable 'my-variable-name': ${treatmentValue}`);\n}).catch(error => {\n    console.error('Failed to initialize TASClient:', error);\n});","lang":"typescript","description":"This quickstart demonstrates how to instantiate `TASClient` with mock interface implementations and retrieve a treatment variable after initialization."},"warnings":[{"fix":"Replace calls to `tasClient.isFlightEnabled(flightName)` with `tasClient.getTreatmentVariable(configId, variableName)`.","message":"The `isFlightEnabled` method on `IExperimentationService` is deprecated. Consumers should transition to using `getTreatmentVariable` instead for retrieving experiment values.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Ensure all required interfaces are fully implemented with the necessary methods before instantiating `TASClient`. Refer to the interface definitions for details.","message":"The `TASClient` requires multiple interfaces (`IExperimentationFilterProvider`, `IExperimentationTelemetry`, `IKeyValueStorage`) to be implemented by the consumer and provided during construction. Failing to do so or providing incomplete implementations will lead to runtime errors.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Always await `tasClient.initializePromise` before making synchronous calls to `getTreatmentVariable()`. If an asynchronous API is required before full initialization, use the `getTreatmentVariableAsync()` method.","message":"Calling `tasClient.getTreatmentVariable()` before the experimentation service has fully initialized (i.e., before `tasClient.initializePromise` resolves) will result in a runtime error. If you cannot await initialization, use `getTreatmentVariableAsync()`.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"In CommonJS, use `const { TASClient } = require('tas-client-umd');` or access via the default export if bundling: `const TASClient = require('tas-client-umd').TASClient;`","cause":"Attempting to use `const TASClient = require('tas-client-umd'); new TASClient()` in CommonJS, instead of destructuring the import.","error":"TypeError: TASClient is not a constructor"},{"fix":"Ensure the `tas-client-umd` script is loaded in your HTML before any code attempts to use `TASClient`. Verify the global variable name exposed by the UMD bundle.","cause":"In a browser environment using the UMD build, the global variable might not be accessible, or the script tag for `tas-client-umd` was not loaded before its usage.","error":"ReferenceError: TASClient is not defined"},{"fix":"Update your code to use `getTreatmentVariable(configId, name)` instead of `isFlightEnabled(flightName)`.","cause":"Using the `isFlightEnabled` method which has been marked for removal.","error":"Property 'isFlightEnabled' is deprecated."}],"ecosystem":"npm"}