Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is a Node.js wrapper for the Iterable API (`node-iterable-api`), providing a clean interface to interact with Iterable's marketing automation platform. The package wraps Iterable's REST API endpoints into JavaScript methods.

## Architecture

- **Entry Point**: `index.js` - Simple module export that re-exports the main Iterable class
- **Core Library**: `lib/` directory contains the main implementation
- `iterable.js` - Main factory function that creates client instances with all resource modules
- `request.js` - HTTP client wrapper using Axios with API key authentication
- `api.js` - Configuration array defining all available API resources and methods
- `resources/` - Individual resource modules (users, lists, events, campaigns, etc.)
- **Resource Pattern**: Each resource in `lib/resources/` exports a factory function that accepts a request instance and returns methods for that resource
- **Testing**: Uses Jest with mock implementations in `lib/__mocks__/`

## Development Commands

```bash
# Run tests with coverage and linting
npm test

# Test-driven development (watch mode)
npm run tdd

# List all implemented resources
node index.js
```

## Testing Setup

- Uses Jest as the test framework
- Standard.js for linting (runs automatically with `npm test`)
- Requires `ITERABLE_API_KEY=fake-key` environment variable for tests
- Mock implementations in `lib/__mocks__/request.js`
- Test helper utilities in `test/resources/helper.js`

## API Resource Structure

Resources are defined in `lib/api.js` and follow this pattern:
- **methods**: Direct HTTP methods on the resource (get, post, delete, etc.)
- **actions**: Named actions that map to specific endpoints
- **subResources**: Nested resources with their own methods (e.g., catalogs.items, catalogs.fieldMappings)

Each resource module exports a factory function that:
1. Takes a request instance as parameter
2. Returns an object with methods corresponding to API endpoints
3. Handles URL construction and parameter formatting

## Key Files to Understand

- `lib/api.js:1` - Complete API resource definitions
- `lib/iterable.js:6` - Main client factory function
- `lib/request.js:4` - HTTP client with Iterable API authentication
- `lib/resources/users.js:20` - Example resource implementation pattern
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ inApp
push
POST - /push/target
campaigns
GET - /campaigns
POST - /campaigns/create
channels
GET - /channels
Expand Down
1 change: 1 addition & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module.exports = [
},
{
resource: 'campaigns',
methods: ['get'],
actions: [
{
name: 'create',
Expand Down
5 changes: 5 additions & 0 deletions lib/resources/campaigns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**

POST - /campaigns/create
GET - /campaigns

*/

Expand Down Expand Up @@ -30,6 +31,10 @@ const factory = request => {
defaultTimeZone,
dataFields
})
},

get () {
return request.get(BASE)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-iterable-api",
"version": "1.2.0",
"version": "1.2.1",
"description": "Wrapper for Iterable API",
"main": "index.js",
"scripts": {
Expand Down