Advanced functionality for modifying HTTP requests and responses during recording and playback, enabling custom data transformations and request standardization for Azure SDK testing scenarios.
Union type defining all available transform types for modifying HTTP traffic during recording and playback.
/**
* Transform type definitions for HTTP request/response modification
*/
type Transform =
| TransformType<"ApiVersionTransform">
| TransformType<"ClientIdTransform">
| TransformType<"StorageRequestIdTransform">
| TransformType<"HeaderTransform", HeaderTransformParams>;
/**
* Generic transform type with optional parameters and apply conditions
*/
type TransformType<TType extends string, TParams = undefined> = {
type: TType;
applyCondition?: ApplyCondition;
} & (TParams extends undefined ? unknown : { params: TParams });
/**
* Condition for when to apply a transform based on URI patterns
*/
interface ApplyCondition {
uriRegex: string;
}Usage Examples:
// API version transform applied to all requests
const apiVersionTransform: Transform = {
type: "ApiVersionTransform"
};
// Header transform with parameters
const headerTransform: Transform = {
type: "HeaderTransform",
params: {
key: "x-ms-version",
value: "2021-01-01"
}
};
// Transform with URI condition
const conditionalTransform: Transform = {
type: "ClientIdTransform",
applyCondition: {
uriRegex: "https://.*\\.blob\\.core\\.windows\\.net/.*"
}
};Configuration interface for header transformation operations, allowing modification of specific HTTP headers.
/**
* Parameters for header transformation operations
*/
interface HeaderTransformParams {
/** The header name to modify */
key: string;
/** The value to set for the header */
value: string;
}Usage Examples:
// Transform to standardize API version headers
const versionHeaderTransform: Transform = {
type: "HeaderTransform",
params: {
key: "x-ms-version",
value: "2023-01-03"
}
};
// Transform to set consistent user agent
const userAgentTransform: Transform = {
type: "HeaderTransform",
params: {
key: "User-Agent",
value: "Azure-SDK-Test/1.0.0"
}
};
await recorder.addTransform(versionHeaderTransform);Method for applying transforms to the current recording session, enabling dynamic modification of HTTP traffic.
/**
* Adds a transform to modify requests/responses during recording or playback
* @param transform - Transform configuration to apply
*/
async addTransform(transform: Transform): Promise<void>;Usage Examples:
// Add API version standardization
await recorder.addTransform({
type: "ApiVersionTransform"
});
// Add client ID transformation for consistent recording
await recorder.addTransform({
type: "ClientIdTransform"
});
// Add storage request ID transformation
await recorder.addTransform({
type: "StorageRequestIdTransform"
});
// Add header transform with specific conditions
await recorder.addTransform({
type: "HeaderTransform",
params: {
key: "x-ms-client-request-id",
value: "standardized-request-id"
},
applyCondition: {
uriRegex: "https://.*\\.table\\.core\\.windows\\.net/.*"
}
});Method for retrieving information about currently configured transforms in the recording session.
/**
* Gets information about currently configured transforms
* @returns Transform information as string or null if no transforms configured
*/
async transformsInfo(): Promise<string | null | undefined>;Usage Examples:
// Get current transform configuration
const transformInfo = await recorder.transformsInfo();
if (transformInfo) {
console.log("Active transforms:", transformInfo);
} else {
console.log("No transforms configured");
}
// Use in debugging scenarios
if (process.env.DEBUG) {
const info = await recorder.transformsInfo();
console.log("Transform configuration:", info);
}Automatically standardizes API version headers across all requests to ensure consistent recording behavior regardless of SDK version differences.
Usage Examples:
// Standardize API versions across all Azure Storage requests
await recorder.addTransform({
type: "ApiVersionTransform"
});
// The transform will automatically handle version differences between:
// - Different SDK versions
// - Different service API versions
// - Preview vs. stable API versionsStandardizes client identification headers to ensure recordings don't contain environment-specific client identifiers.
Usage Examples:
// Standardize client identifiers
await recorder.addTransform({
type: "ClientIdTransform"
});
// Apply only to specific services
await recorder.addTransform({
type: "ClientIdTransform",
applyCondition: {
uriRegex: "https://.*\\.servicebus\\.windows\\.net/.*"
}
});Specifically designed for Azure Storage operations to standardize request IDs and ensure consistent recording behavior.
Usage Examples:
// Standardize storage request IDs
await recorder.addTransform({
type: "StorageRequestIdTransform"
});
// Apply to blob storage operations only
await recorder.addTransform({
type: "StorageRequestIdTransform",
applyCondition: {
uriRegex: "https://.*\\.blob\\.core\\.windows\\.net/.*"
}
});Flexible transform for modifying any HTTP header with custom values, providing fine-grained control over request standardization.
Usage Examples:
// Set consistent date headers
await recorder.addTransform({
type: "HeaderTransform",
params: {
key: "x-ms-date",
value: "2023-01-01T00:00:00Z"
}
});
// Remove volatile headers by setting empty values
await recorder.addTransform({
type: "HeaderTransform",
params: {
key: "x-ms-client-request-id",
value: ""
}
});
// Set consistent authorization patterns (be careful with real auth!)
await recorder.addTransform({
type: "HeaderTransform",
params: {
key: "Authorization",
value: "Bearer sanitized-token"
},
applyCondition: {
uriRegex: "https://management\\.azure\\.com/.*"
}
});Apply transforms only to specific services or URL patterns using URI regex conditions.
// Transform for Azure Key Vault operations only
await recorder.addTransform({
type: "HeaderTransform",
params: {
key: "x-ms-keyvault-region",
value: "standardized-region"
},
applyCondition: {
uriRegex: "https://.*\\.vault\\.azure\\.net/.*"
}
});
// Transform for management API calls
await recorder.addTransform({
type: "ApiVersionTransform",
applyCondition: {
uriRegex: "https://management\\.azure\\.com/.*"
}
});Chain multiple transforms for comprehensive request standardization.
// Comprehensive transform setup for storage testing
await recorder.addTransform({
type: "ApiVersionTransform"
});
await recorder.addTransform({
type: "StorageRequestIdTransform"
});
await recorder.addTransform({
type: "HeaderTransform",
params: {
key: "x-ms-date",
value: "2023-01-01T00:00:00Z"
}
});
// Verify all transforms are active
const transformInfo = await recorder.transformsInfo();
console.log("Active transforms:", transformInfo);Different Azure services may require different transform approaches.
// Azure Storage: Focus on request IDs and timestamps
await recorder.addTransform({ type: "StorageRequestIdTransform" });
await recorder.addTransform({ type: "ApiVersionTransform" });
// Azure Service Bus: Focus on client identification
await recorder.addTransform({
type: "ClientIdTransform",
applyCondition: { uriRegex: "https://.*\\.servicebus\\.windows\\.net/.*" }
});
// Azure Key Vault: Custom headers for regional consistency
await recorder.addTransform({
type: "HeaderTransform",
params: { key: "x-ms-keyvault-region", value: "test-region" },
applyCondition: { uriRegex: "https://.*\\.vault\\.azure\\.net/.*" }
});