This directory contains a consolidated formatter system for different types of Attio attribute values. The formatters convert Attio API data into human-readable strings for display in Slack notifications.
Import and use the single formatter function:
import { formatAttributeValue } from "./formatters/index.ts";
const formattedValue = await formatAttributeValue(attributeValue);
The formatter system uses a registry pattern where all formatters are defined in a single object and automatically selected based on the attribute type. This provides:
- Type Safety: Each formatter is properly typed for its specific attribute type
- Automatic Selection: No need to manually choose which formatter to use
- Centralized Management: All formatters are defined in one place
- Easy Extension: Adding new formatters requires only one line
The system automatically handles these Attio attribute types:
text- Simple text valuesstatus- Status values with titlesselect- Dropdown/select values with option titlesdate- Date valuestimestamp- Timestamp valuesrating- Numeric rating valuescheckbox- Boolean checkbox valuescurrency- Currency values with proper formattingrecord-reference- References to other records (fetches record name)actor-reference- References to users/actors (fetches actor name)
The system includes 10 core formatters for commonly used Attio attribute types. These are always available and don't require any setup.
For the 7 additional Attio attribute types, you can easily add formatters when needed:
import { addUncommonFormatters } from "./formatters/uncommon.ts";
// Add all 7 uncommon formatters at once
addUncommonFormatters();
import { addSpecificUncommonFormatters } from "./formatters/uncommon.ts";
// Add only the formatters you need
addSpecificUncommonFormatters(["domain", "email-address", "location"]);
import { addFormatters } from "./formatters/index.ts";
// Add your own custom formatters
addFormatters({
"custom-type": (value) => value.customProperty,
"another-type": async (value) => {
const result = await someAsyncOperation(value);
return result.toString();
},
});
domain- Domain namesemail-address- Email addresses with parsed componentsinteraction- Interaction tracking (calls, meetings, etc.)location- Address information with coordinatesnumber- Numeric valuespersonal-name- First/last name combinationsphone-number- Phone numbers with country codes
import { formatAttributeValue } from "./formatters/index.ts";
// Text attribute
const textValue = await formatAttributeValue({
attribute_type: "text",
value: "Hello World",
});
// Status attribute
const statusValue = await formatAttributeValue({
attribute_type: "status",
status: { title: "Active" },
});
// Currency attribute
const currencyValue = await formatAttributeValue({
attribute_type: "currency",
currency_value: 123.45,
currency_code: "USD",
});
// Result: "$123.45"
import { formatAttributeValue } from "./formatters/index.ts";
import { addUncommonFormatters } from "./formatters/uncommon.ts";
// First, add the uncommon formatters you need
addUncommonFormatters();
// Now you can format uncommon attribute types
const domainValue = await formatAttributeValue({
attribute_type: "domain",
domain: "example.com",
root_domain: "example.com",
// ... other properties
});
// Result: "example.com"
const emailValue = await formatAttributeValue({
attribute_type: "email-address",
email_address: "user@example.com",
// ... other properties
});
// Result: "user@example.com"
// If an unsupported attribute type is provided
const result = await formatAttributeValue({
attribute_type: "unsupported-type",
// ... other properties
});
// Result: "Error: no formatter found for attribute type 'unsupported-type'. Use addFormatters() to add support for this type."
The formatter system consists of:
- Type Definition:
FormatterFunction<T>- Generic type for formatter functions - Registry Object: Maps attribute types to their specific formatters
- Main Function:
formatAttributeValue()- Public API that handles type selection and execution - Type Safety: Uses TypeScript's
Extractutility to ensure proper typing
This design eliminates the need for individual formatter functions and provides a clean, maintainable API.