attio-ts-sdk 0.0.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Attio CRM TypeScript SDK
2
2
 
3
+ [![npm version](https://badge.fury.io/js/attio-ts-sdk.svg)](https://www.npmjs.com/package/attio-ts-sdk)
4
+ [![ci](https://github.com/hbmartin/attio-ts-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/hbmartin/attio-ts-sdk/actions/workflows/ci.yml)
5
+ [![codecov](https://codecov.io/gh/hbmartin/attio-ts-sdk/graph/badge.svg?token=Po1nDYEr5f)](https://codecov.io/gh/hbmartin/attio-ts-sdk)
6
+ [![NPM License](https://img.shields.io/npm/l/attio-ts-sdk?color=blue)](https://github.com/hbmartin/attio-ts-sdk/blob/main/LICENSE)
7
+ [![Context7](https://img.shields.io/badge/[]-Context7-059669)](https://context7.com/hbmartin/attio-ts-sdk)
8
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/hbmartin/attio-ts-sdk)
9
+
3
10
  A modern, type-safe TypeScript SDK for the [Attio](https://attio.com) CRM API. Built with Zod v4 and a new Attio‑aware client layer that adds retries, error normalization, caching, and higher‑level helpers on top of the generated OpenAPI client.
4
11
 
5
12
  - **Create an Attio client in one line** (`createAttioClient({ apiKey })`)
@@ -15,9 +22,7 @@ You still have full access to the generated, spec‑accurate endpoints.
15
22
 
16
23
  - **Full Attio API Coverage** - People, companies, lists, notes, tasks, meetings, webhooks, and more
17
24
  - **Runtime Validation** - Every request and response validated with Zod v4 schemas
18
- - **Tiny Bundle** - Browser build under 3.5KB gzipped
19
25
  - **Tree-Shakeable** - Import only what you need
20
- - **Isomorphic** - Works in Node.js, Bun, Deno, and browsers
21
26
  - **TypeScript First** - Complete type definitions generated from OpenAPI spec
22
27
  - **Attio-Aware Client** - Retries, normalized errors, caching, helpers
23
28
  - **Zero Config** - Sensible defaults, just add your API key
@@ -152,6 +157,69 @@ const meetings = await paginate(async (cursor) => {
152
157
  });
153
158
  ```
154
159
 
160
+ ### Caching
161
+
162
+ The SDK includes two levels of caching to reduce API calls and improve performance:
163
+
164
+ #### Metadata Caching
165
+
166
+ Attribute metadata (attributes, select options, and statuses) is automatically cached with a 5-minute TTL. This reduces redundant API calls when working with the same objects repeatedly.
167
+
168
+ ```typescript
169
+ import { getAttributeOptions, getAttributeStatuses, listAttributes } from 'attio-ts-sdk';
170
+
171
+ // These calls are cached for 5 minutes
172
+ const options = await getAttributeOptions({
173
+ client,
174
+ target: 'objects',
175
+ identifier: 'companies',
176
+ attribute: 'stage',
177
+ });
178
+
179
+ // Subsequent calls with the same parameters return cached data
180
+ const optionsAgain = await getAttributeOptions({
181
+ client,
182
+ target: 'objects',
183
+ identifier: 'companies',
184
+ attribute: 'stage',
185
+ }); // Returns cached result, no API call
186
+ ```
187
+
188
+ The metadata caches have the following limits:
189
+ - **Attributes cache**: 200 entries max
190
+ - **Options cache**: 500 entries max
191
+ - **Statuses cache**: 500 entries max
192
+
193
+ When a cache reaches its limit, the oldest entry is evicted.
194
+
195
+ #### Client Instance Caching
196
+
197
+ You can cache `AttioClient` instances to reuse them across your application. This is useful when you want to avoid creating new client instances for repeated operations.
198
+
199
+ ```typescript
200
+ import { getAttioClient } from 'attio-ts-sdk';
201
+
202
+ // With cache.key set, the client instance is cached and reused
203
+ const client = getAttioClient({
204
+ apiKey: process.env.ATTIO_API_KEY,
205
+ cache: { key: 'my-app' },
206
+ });
207
+
208
+ // Returns the same cached client instance
209
+ const sameClient = getAttioClient({
210
+ apiKey: process.env.ATTIO_API_KEY,
211
+ cache: { key: 'my-app' },
212
+ });
213
+
214
+ // Disable caching if needed
215
+ const freshClient = getAttioClient({
216
+ apiKey: process.env.ATTIO_API_KEY,
217
+ cache: { enabled: false },
218
+ });
219
+ ```
220
+
221
+ Note: `createAttioClient` always creates a new client instance. Use `getAttioClient` when you want caching behavior.
222
+
155
223
  ### Metadata Helpers
156
224
 
157
225
  ```typescript
@@ -329,23 +397,6 @@ const { data: webhook } = await postV2Webhooks({
329
397
  const { data: webhooks } = await getV2Webhooks({ client });
330
398
  ```
331
399
 
332
- ### Browser Usage
333
-
334
- For browsers, import from the `/browser` entry point:
335
-
336
- ```typescript
337
- import { createClient, getV2Self } from 'attio-ts-sdk/browser';
338
-
339
- const client = createClient({
340
- baseUrl: 'https://api.attio.com',
341
- headers: {
342
- Authorization: `Bearer ${apiKey}`,
343
- },
344
- });
345
-
346
- const { data: self } = await getV2Self({ client });
347
- ```
348
-
349
400
  ### Error Handling
350
401
 
351
402
  ```typescript
@@ -380,10 +431,10 @@ try {
380
431
 
381
432
  ### Tools
382
433
 
434
+ - **[Hey API](https://heyapi.dev/)**: OpenAPI client and Zod schema generation
383
435
  - **Biome**: lint and format with a single tool
384
436
  - **Vitest**: fast tests with coverage and thresholds
385
- - **Size Limit**: keep bundles tiny, with CI checks
386
- - **tsdown**: ESM builds for Node and a separate browser bundle
437
+ - **tsdown**: ESM builds for Node
387
438
  - **CI**: lint, typecheck, test, coverage, and size comments/badges
388
439
  - **Deno-friendly**: `.ts` source imports for direct consumption
389
440
  - **OIDC + Provenance**: publish to npm and JSR via manual CI release