@zapier/zapier-sdk 0.68.0 → 0.69.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.
Files changed (35) hide show
  1. package/AGENTS.md +321 -0
  2. package/CHANGELOG.md +15 -0
  3. package/CLAUDE.md +3 -319
  4. package/README.md +17 -17
  5. package/dist/api/client.d.ts.map +1 -1
  6. package/dist/api/client.js +108 -3
  7. package/dist/api/error-classification.d.ts +12 -0
  8. package/dist/api/error-classification.d.ts.map +1 -0
  9. package/dist/api/error-classification.js +18 -0
  10. package/dist/api/index.d.ts +2 -0
  11. package/dist/api/index.d.ts.map +1 -1
  12. package/dist/api/index.js +3 -0
  13. package/dist/api/sse-parser.d.ts +17 -0
  14. package/dist/api/sse-parser.d.ts.map +1 -0
  15. package/dist/api/sse-parser.js +67 -0
  16. package/dist/api/types.d.ts +16 -0
  17. package/dist/api/types.d.ts.map +1 -1
  18. package/dist/experimental.cjs +356 -67
  19. package/dist/experimental.d.mts +2 -2
  20. package/dist/experimental.mjs +356 -67
  21. package/dist/{index-oRnHsPn5.d.mts → index-DC31DAP2.d.mts} +20 -1
  22. package/dist/{index-oRnHsPn5.d.ts → index-DC31DAP2.d.ts} +20 -1
  23. package/dist/index.cjs +131 -7
  24. package/dist/index.d.mts +1 -1
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.mjs +131 -7
  28. package/dist/plugins/triggers/drainTriggerInbox/schemas.js +2 -2
  29. package/dist/plugins/triggers/watchTriggerInbox/index.d.ts +31 -6
  30. package/dist/plugins/triggers/watchTriggerInbox/index.d.ts.map +1 -1
  31. package/dist/plugins/triggers/watchTriggerInbox/index.js +272 -65
  32. package/dist/plugins/triggers/watchTriggerInbox/sse.d.ts +30 -0
  33. package/dist/plugins/triggers/watchTriggerInbox/sse.d.ts.map +1 -0
  34. package/dist/plugins/triggers/watchTriggerInbox/sse.js +38 -0
  35. package/package.json +2 -1
package/AGENTS.md ADDED
@@ -0,0 +1,321 @@
1
+ # @zapier/zapier-sdk
2
+
3
+ TypeScript SDK for interacting with Zapier's API. See the [README](./README.md) for installation and quickstart instructions.
4
+
5
+ ## Architecture & Mental Model
6
+
7
+ The SDK uses a **plugin-based architecture** where functionality is composed from modular plugins. Each plugin (like `listApps`, `runAction`, `apps`) adds methods to the SDK instance. This design allows for tree-shaking and modular extension.
8
+
9
+ **Key principles:**
10
+
11
+ - **Factory functions over classes**: Always use `createZapierSdk()` to create an SDK instance. The SDK never requires `new`.
12
+ - **Wrapped responses**: All SDK methods return `{ data }` wrappers (e.g., `{ data: app }` or `{ data: apps, nextCursor }`). This allows adding metadata in the future without breaking changes.
13
+ - **Single object parameters**: Methods take a single options object, making it easy to add parameters later without breaking existing code.
14
+
15
+ ```typescript
16
+ // The SDK instance provides all methods via plugins
17
+ const zapier = createZapierSdk();
18
+
19
+ // Methods return wrapped responses
20
+ const { data: app } = await zapier.getApp({ app: "slack" });
21
+ const { data: apps, nextCursor } = await zapier.listApps();
22
+ ```
23
+
24
+ ## Authentication Flow
25
+
26
+ The SDK uses a unified `credentials` option that supports multiple authentication methods.
27
+
28
+ ### Development: CLI Login (Recommended)
29
+
30
+ The easiest approach for local development. Run `npx zapier-sdk login` once, and the SDK automatically uses those credentials.
31
+
32
+ ```typescript
33
+ // No credentials needed - SDK reads from CLI login automatically
34
+ const zapier = createZapierSdk();
35
+ ```
36
+
37
+ The CLI stores tokens in `~/.zapier-sdk/config.json`. The SDK checks for this file when no credentials are provided.
38
+
39
+ ### Production: Token String
40
+
41
+ For deployed applications with a pre-obtained token:
42
+
43
+ ```typescript
44
+ // Option 1: Pass token directly via credentials
45
+ const zapier = createZapierSdk({ credentials: process.env.ZAPIER_CREDENTIALS });
46
+
47
+ // Option 2: Use ZAPIER_CREDENTIALS environment variable (SDK reads it automatically)
48
+ const zapier = createZapierSdk();
49
+ ```
50
+
51
+ ### Production: Client Credentials (OAuth)
52
+
53
+ For server-to-server authentication using OAuth client credentials flow:
54
+
55
+ ```typescript
56
+ const zapier = createZapierSdk({
57
+ credentials: {
58
+ type: "client_credentials",
59
+ clientId: process.env.ZAPIER_CREDENTIALS_CLIENT_ID,
60
+ clientSecret: process.env.ZAPIER_CREDENTIALS_CLIENT_SECRET,
61
+ // Optional: baseUrl and scope
62
+ },
63
+ });
64
+ ```
65
+
66
+ The SDK automatically exchanges these credentials for an access token and handles token refresh.
67
+
68
+ ### Dynamic Credentials (Advanced)
69
+
70
+ For scenarios where credentials change at runtime (e.g., multi-tenant apps):
71
+
72
+ ```typescript
73
+ const zapier = createZapierSdk({
74
+ credentials: async () => {
75
+ // Return a token string or credentials object
76
+ return await getCredentialsForCurrentUser();
77
+ },
78
+ });
79
+ ```
80
+
81
+ ### Credential Types Summary
82
+
83
+ | Type | Use Case | Example |
84
+ | ------------------ | ----------------------- | ----------------------------------------- |
85
+ | String | Pre-obtained token | `credentials: "your_token"` |
86
+ | Client Credentials | Server-to-server OAuth | `credentials: { clientId, clientSecret }` |
87
+ | PKCE | Interactive login (CLI) | `credentials: { clientId }` (no secret) |
88
+ | Function | Dynamic/lazy resolution | `credentials: async () => getToken()` |
89
+
90
+ ## Working with Paginated Results
91
+
92
+ Most list methods return paginated results. Understanding pagination is essential because some lists (like apps) have thousands of items.
93
+
94
+ ### Single Page
95
+
96
+ ```typescript
97
+ // Get first page only
98
+ const { data: apps, nextCursor } = await zapier.listApps();
99
+
100
+ // Get next page using cursor
101
+ const { data: moreApps } = await zapier.listApps({ cursor: nextCursor });
102
+ ```
103
+
104
+ ### Iterate All Pages
105
+
106
+ ```typescript
107
+ // Iterate over pages (each page has { data, nextCursor })
108
+ for await (const page of zapier.listApps()) {
109
+ console.log(`Got ${page.data.length} apps`);
110
+ }
111
+ ```
112
+
113
+ ### Iterate Individual Items
114
+
115
+ ```typescript
116
+ // Iterate over individual items across all pages
117
+ for await (const app of zapier.listApps().items()) {
118
+ console.log(app.title);
119
+ }
120
+
121
+ // Collect all items (be careful with large lists!)
122
+ const allApps = await Array.fromAsync(zapier.listApps().items());
123
+ ```
124
+
125
+ ### Limit Results
126
+
127
+ ```typescript
128
+ // Limit to 50 total items across all pages
129
+ for await (const app of zapier.listApps({ maxItems: 50 }).items()) {
130
+ console.log(app.title);
131
+ }
132
+ ```
133
+
134
+ ## The Apps Proxy Pattern
135
+
136
+ The `zapier.apps` proxy provides a type-safe, fluent way to execute actions. This is the recommended approach when you've generated TypeScript types for your apps.
137
+
138
+ ### Basic Usage
139
+
140
+ ```typescript
141
+ // Pattern: zapier.apps.{appKey}.{actionType}.{actionKey}(options)
142
+ const { data: channels } = await zapier.apps.slack.read.channels({
143
+ connection: "123",
144
+ });
145
+ ```
146
+
147
+ ### Binding Connection
148
+
149
+ Instead of passing `connection` to every call, bind it once:
150
+
151
+ ```typescript
152
+ // Create a bound app instance
153
+ const mySlack = zapier.apps.slack({ connection: "123" });
154
+
155
+ // Now all calls use that auth
156
+ const { data: channels } = await mySlack.read.channels({});
157
+ const { data: users } = await mySlack.search.user_by_email({
158
+ inputs: { email: "user@example.com" },
159
+ });
160
+ ```
161
+
162
+ ### App Key Formats
163
+
164
+ Apps support multiple key formats. Use whichever is most convenient:
165
+
166
+ ```typescript
167
+ // These are equivalent for Google Sheets:
168
+ zapier.apps.google_sheets; // snake_case (works as property)
169
+ zapier.apps["google-sheets"]; // slug with dashes
170
+ zapier.apps.GoogleSheetsV2CLIAPI; // implementation name
171
+ ```
172
+
173
+ ## App Keys and Discovery
174
+
175
+ Apps have multiple identifiers that can be used interchangeably:
176
+
177
+ - **Slug**: Human-friendly, like `slack` or `google-sheets`
178
+ - **Implementation name**: Internal identifier like `SlackCLIAPI` or `GoogleSheetsV2CLIAPI`
179
+ - **Snake_case**: Derived from slug, like `google_sheets`
180
+
181
+ ### Finding Apps
182
+
183
+ ```typescript
184
+ // Search by name
185
+ const { data: results } = await zapier.listApps({ search: "google sheets" });
186
+ // Results show all valid keys: "Google Sheets (GoogleSheetsV2CLIAPI, google-sheets, google_sheets)"
187
+
188
+ // Get specific app details
189
+ const { data: app } = await zapier.getApp({ app: "slack" });
190
+ ```
191
+
192
+ ### The Manifest (`.zapierrc`)
193
+
194
+ The manifest file locks app versions for reproducibility. When you run `npx zapier-sdk add slack`, it:
195
+
196
+ 1. Records the current Slack app version in `.zapierrc`
197
+ 2. Generates TypeScript types for that version
198
+
199
+ This ensures your code works with a known app version, not whatever happens to be latest.
200
+
201
+ ## Type Generation Workflow
202
+
203
+ TypeScript types give you autocomplete for action inputs and outputs.
204
+
205
+ ### Generate Types
206
+
207
+ ```bash
208
+ # Add apps and generate types
209
+ npx zapier-sdk add slack google-sheets
210
+
211
+ # Types are created in src/zapier/apps/ or lib/zapier/apps/ by default
212
+ ```
213
+
214
+ ### Using Generated Types
215
+
216
+ After generation, the apps proxy becomes fully typed:
217
+
218
+ ```typescript
219
+ // With generated types, you get autocomplete for:
220
+ // - Action names (read.channels, write.send_message, etc.)
221
+ // - Input field names and types
222
+ // - Output field types
223
+ const { data } = await zapier.apps.slack.write.send_message({
224
+ connection: "123",
225
+ inputs: {
226
+ channel: "#general", // TypeScript knows this field exists
227
+ text: "Hello!",
228
+ },
229
+ });
230
+ ```
231
+
232
+ ### Regenerating Types
233
+
234
+ Run `add` again when:
235
+
236
+ - You need types for a new app
237
+ - An app has been updated and you want the latest fields
238
+ - You've deleted your generated types
239
+
240
+ ## Named Connections
241
+
242
+ Named connections let you decouple workflow code from specific connection IDs. An external system (like an execution engine) provides the mapping via `.zapierrc`, and the workflow code references connections by name.
243
+
244
+ ### Providing the Mapping
245
+
246
+ Connections are configured in `.zapierrc` alongside app version pins, or inline via the `manifest` option:
247
+
248
+ ```typescript
249
+ const zapier = createZapierSdk({
250
+ manifest: {
251
+ apps: { slack: { implementationName: "SlackCLIAPI", version: "1.21.1" } },
252
+ connections: {
253
+ slack_work: { connectionId: 12345 },
254
+ google_sheets: { connectionId: 67890 },
255
+ },
256
+ },
257
+ });
258
+ ```
259
+
260
+ ### Using Named Connections
261
+
262
+ ```typescript
263
+ // Per-call with alias
264
+ await zapier.apps.slack.read.channels({ connection: "slack_work" });
265
+
266
+ // Factory binding
267
+ const slack = zapier.apps.slack({ connection: "slack_work" });
268
+ await slack.read.channels({});
269
+
270
+ // Lower-level API
271
+ await zapier.runAction({
272
+ app: "slack",
273
+ actionType: "read",
274
+ action: "channels",
275
+ connection: "slack_work",
276
+ });
277
+
278
+ // Direct numeric connection ID also works
279
+ await zapier.apps.slack.read.channels({ connection: 12345 });
280
+ ```
281
+
282
+ ### Resolution Precedence
283
+
284
+ For `connection`: explicit value > factory binding. String values are resolved from the connections map; numeric values are used directly as connection IDs. `connectionId` and `authenticationId` are deprecated aliases for `connection`.
285
+
286
+ App version is always resolved from the `.zapierrc` manifest, not from connections.
287
+
288
+ ## Error Handling
289
+
290
+ ### Debugging
291
+
292
+ Enable debug mode to see API requests and responses:
293
+
294
+ ```typescript
295
+ const zapier = createZapierSdk({ debug: true });
296
+ ```
297
+
298
+ Or set the environment variable:
299
+
300
+ ```bash
301
+ DEBUG=zapier:* node your-script.js
302
+ ```
303
+
304
+ ### Common Errors
305
+
306
+ - **"No credentials provided"**: Run `npx zapier-sdk login` or provide credentials explicitly
307
+ - **"Connection not found"**: The `connection` doesn't exist or you don't have access
308
+ - **"App not found"**: Check the app key using `listApps({ search: "..." })`
309
+ - **"Action not found"**: Verify the action type and key with `listActions({ app: "..." })`
310
+
311
+ ## Environment Variables
312
+
313
+ | Variable | Purpose |
314
+ | ---------------------------------- | ---------------------------------------------------------- |
315
+ | `ZAPIER_CREDENTIALS` | Token string (alternative to passing `credentials` option) |
316
+ | `ZAPIER_CREDENTIALS_CLIENT_ID` | OAuth client ID for client_credentials or PKCE flow |
317
+ | `ZAPIER_CREDENTIALS_CLIENT_SECRET` | OAuth client secret (for client_credentials flow) |
318
+ | `ZAPIER_CREDENTIALS_BASE_URL` | Override auth base URL |
319
+ | `ZAPIER_CREDENTIALS_SCOPE` | OAuth scope |
320
+ | `ZAPIER_BASE_URL` | Override API base URL (for testing) |
321
+ | `DEBUG` | Enable debug logging (`zapier:*` for all SDK logs) |
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.69.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9f1e934: Switched `watchTriggerInbox` from backoff polling to a Server-Sent Events subscription, so it now wakes on near-real-time inbox notifications instead of repeatedly polling for new messages.
8
+ - The `maxDrainIntervalSeconds` option now controls a periodic safety drain that backstops the SSE stream — guaranteeing forward progress if events are missed or the connection drops — and its default changed from 60 to 300 seconds.
9
+ - Real-time wake-up health is now reported on stderr: a warning when wake-ups pause and the watch falls back to the safety drain, plus transient reconnect notices in debug mode. stdout (including `--json` NDJSON output) is unaffected.
10
+ - Added a `fetchStream` method to the API client, along with an exported `SseMessage` type, for opening Server-Sent Events connections through the standard request pipeline (auth, base URL, 429 retry, approval, and concurrency).
11
+
12
+ ## 0.68.1
13
+
14
+ ### Patch Changes
15
+
16
+ - 9d6bd4d: Ship `AGENTS.md` as the canonical agent-instructions file. Each `CLAUDE.md` is now a thin stub that imports it, so Claude Code, Codex, and Cursor read the same guidance.
17
+
3
18
  ## 0.68.0
4
19
 
5
20
  ### Minor Changes
package/CLAUDE.md CHANGED
@@ -1,321 +1,5 @@
1
- # @zapier/zapier-sdk
1
+ # CLAUDE.md
2
2
 
3
- TypeScript SDK for interacting with Zapier's API. See the [README](./README.md) for installation and quickstart instructions.
3
+ Claude Code loads this file automatically. The canonical AI-agent guidance lives in [AGENTS.md](./AGENTS.md) so that Claude Code, Codex, Cursor, and any other tool following the AGENTS.md convention read the same content.
4
4
 
5
- ## Architecture & Mental Model
6
-
7
- The SDK uses a **plugin-based architecture** where functionality is composed from modular plugins. Each plugin (like `listApps`, `runAction`, `apps`) adds methods to the SDK instance. This design allows for tree-shaking and modular extension.
8
-
9
- **Key principles:**
10
-
11
- - **Factory functions over classes**: Always use `createZapierSdk()` to create an SDK instance. The SDK never requires `new`.
12
- - **Wrapped responses**: All SDK methods return `{ data }` wrappers (e.g., `{ data: app }` or `{ data: apps, nextCursor }`). This allows adding metadata in the future without breaking changes.
13
- - **Single object parameters**: Methods take a single options object, making it easy to add parameters later without breaking existing code.
14
-
15
- ```typescript
16
- // The SDK instance provides all methods via plugins
17
- const zapier = createZapierSdk();
18
-
19
- // Methods return wrapped responses
20
- const { data: app } = await zapier.getApp({ app: "slack" });
21
- const { data: apps, nextCursor } = await zapier.listApps();
22
- ```
23
-
24
- ## Authentication Flow
25
-
26
- The SDK uses a unified `credentials` option that supports multiple authentication methods.
27
-
28
- ### Development: CLI Login (Recommended)
29
-
30
- The easiest approach for local development. Run `npx zapier-sdk login` once, and the SDK automatically uses those credentials.
31
-
32
- ```typescript
33
- // No credentials needed - SDK reads from CLI login automatically
34
- const zapier = createZapierSdk();
35
- ```
36
-
37
- The CLI stores tokens in `~/.zapier-sdk/config.json`. The SDK checks for this file when no credentials are provided.
38
-
39
- ### Production: Token String
40
-
41
- For deployed applications with a pre-obtained token:
42
-
43
- ```typescript
44
- // Option 1: Pass token directly via credentials
45
- const zapier = createZapierSdk({ credentials: process.env.ZAPIER_CREDENTIALS });
46
-
47
- // Option 2: Use ZAPIER_CREDENTIALS environment variable (SDK reads it automatically)
48
- const zapier = createZapierSdk();
49
- ```
50
-
51
- ### Production: Client Credentials (OAuth)
52
-
53
- For server-to-server authentication using OAuth client credentials flow:
54
-
55
- ```typescript
56
- const zapier = createZapierSdk({
57
- credentials: {
58
- type: "client_credentials",
59
- clientId: process.env.ZAPIER_CREDENTIALS_CLIENT_ID,
60
- clientSecret: process.env.ZAPIER_CREDENTIALS_CLIENT_SECRET,
61
- // Optional: baseUrl and scope
62
- },
63
- });
64
- ```
65
-
66
- The SDK automatically exchanges these credentials for an access token and handles token refresh.
67
-
68
- ### Dynamic Credentials (Advanced)
69
-
70
- For scenarios where credentials change at runtime (e.g., multi-tenant apps):
71
-
72
- ```typescript
73
- const zapier = createZapierSdk({
74
- credentials: async () => {
75
- // Return a token string or credentials object
76
- return await getCredentialsForCurrentUser();
77
- },
78
- });
79
- ```
80
-
81
- ### Credential Types Summary
82
-
83
- | Type | Use Case | Example |
84
- | ------------------ | ----------------------- | ----------------------------------------- |
85
- | String | Pre-obtained token | `credentials: "your_token"` |
86
- | Client Credentials | Server-to-server OAuth | `credentials: { clientId, clientSecret }` |
87
- | PKCE | Interactive login (CLI) | `credentials: { clientId }` (no secret) |
88
- | Function | Dynamic/lazy resolution | `credentials: async () => getToken()` |
89
-
90
- ## Working with Paginated Results
91
-
92
- Most list methods return paginated results. Understanding pagination is essential because some lists (like apps) have thousands of items.
93
-
94
- ### Single Page
95
-
96
- ```typescript
97
- // Get first page only
98
- const { data: apps, nextCursor } = await zapier.listApps();
99
-
100
- // Get next page using cursor
101
- const { data: moreApps } = await zapier.listApps({ cursor: nextCursor });
102
- ```
103
-
104
- ### Iterate All Pages
105
-
106
- ```typescript
107
- // Iterate over pages (each page has { data, nextCursor })
108
- for await (const page of zapier.listApps()) {
109
- console.log(`Got ${page.data.length} apps`);
110
- }
111
- ```
112
-
113
- ### Iterate Individual Items
114
-
115
- ```typescript
116
- // Iterate over individual items across all pages
117
- for await (const app of zapier.listApps().items()) {
118
- console.log(app.title);
119
- }
120
-
121
- // Collect all items (be careful with large lists!)
122
- const allApps = await Array.fromAsync(zapier.listApps().items());
123
- ```
124
-
125
- ### Limit Results
126
-
127
- ```typescript
128
- // Limit to 50 total items across all pages
129
- for await (const app of zapier.listApps({ maxItems: 50 }).items()) {
130
- console.log(app.title);
131
- }
132
- ```
133
-
134
- ## The Apps Proxy Pattern
135
-
136
- The `zapier.apps` proxy provides a type-safe, fluent way to execute actions. This is the recommended approach when you've generated TypeScript types for your apps.
137
-
138
- ### Basic Usage
139
-
140
- ```typescript
141
- // Pattern: zapier.apps.{appKey}.{actionType}.{actionKey}(options)
142
- const { data: channels } = await zapier.apps.slack.read.channels({
143
- connection: "123",
144
- });
145
- ```
146
-
147
- ### Binding Connection
148
-
149
- Instead of passing `connection` to every call, bind it once:
150
-
151
- ```typescript
152
- // Create a bound app instance
153
- const mySlack = zapier.apps.slack({ connection: "123" });
154
-
155
- // Now all calls use that auth
156
- const { data: channels } = await mySlack.read.channels({});
157
- const { data: users } = await mySlack.search.user_by_email({
158
- inputs: { email: "user@example.com" },
159
- });
160
- ```
161
-
162
- ### App Key Formats
163
-
164
- Apps support multiple key formats. Use whichever is most convenient:
165
-
166
- ```typescript
167
- // These are equivalent for Google Sheets:
168
- zapier.apps.google_sheets; // snake_case (works as property)
169
- zapier.apps["google-sheets"]; // slug with dashes
170
- zapier.apps.GoogleSheetsV2CLIAPI; // implementation name
171
- ```
172
-
173
- ## App Keys and Discovery
174
-
175
- Apps have multiple identifiers that can be used interchangeably:
176
-
177
- - **Slug**: Human-friendly, like `slack` or `google-sheets`
178
- - **Implementation name**: Internal identifier like `SlackCLIAPI` or `GoogleSheetsV2CLIAPI`
179
- - **Snake_case**: Derived from slug, like `google_sheets`
180
-
181
- ### Finding Apps
182
-
183
- ```typescript
184
- // Search by name
185
- const { data: results } = await zapier.listApps({ search: "google sheets" });
186
- // Results show all valid keys: "Google Sheets (GoogleSheetsV2CLIAPI, google-sheets, google_sheets)"
187
-
188
- // Get specific app details
189
- const { data: app } = await zapier.getApp({ app: "slack" });
190
- ```
191
-
192
- ### The Manifest (`.zapierrc`)
193
-
194
- The manifest file locks app versions for reproducibility. When you run `npx zapier-sdk add slack`, it:
195
-
196
- 1. Records the current Slack app version in `.zapierrc`
197
- 2. Generates TypeScript types for that version
198
-
199
- This ensures your code works with a known app version, not whatever happens to be latest.
200
-
201
- ## Type Generation Workflow
202
-
203
- TypeScript types give you autocomplete for action inputs and outputs.
204
-
205
- ### Generate Types
206
-
207
- ```bash
208
- # Add apps and generate types
209
- npx zapier-sdk add slack google-sheets
210
-
211
- # Types are created in src/zapier/apps/ or lib/zapier/apps/ by default
212
- ```
213
-
214
- ### Using Generated Types
215
-
216
- After generation, the apps proxy becomes fully typed:
217
-
218
- ```typescript
219
- // With generated types, you get autocomplete for:
220
- // - Action names (read.channels, write.send_message, etc.)
221
- // - Input field names and types
222
- // - Output field types
223
- const { data } = await zapier.apps.slack.write.send_message({
224
- connection: "123",
225
- inputs: {
226
- channel: "#general", // TypeScript knows this field exists
227
- text: "Hello!",
228
- },
229
- });
230
- ```
231
-
232
- ### Regenerating Types
233
-
234
- Run `add` again when:
235
-
236
- - You need types for a new app
237
- - An app has been updated and you want the latest fields
238
- - You've deleted your generated types
239
-
240
- ## Named Connections
241
-
242
- Named connections let you decouple workflow code from specific connection IDs. An external system (like an execution engine) provides the mapping via `.zapierrc`, and the workflow code references connections by name.
243
-
244
- ### Providing the Mapping
245
-
246
- Connections are configured in `.zapierrc` alongside app version pins, or inline via the `manifest` option:
247
-
248
- ```typescript
249
- const zapier = createZapierSdk({
250
- manifest: {
251
- apps: { slack: { implementationName: "SlackCLIAPI", version: "1.21.1" } },
252
- connections: {
253
- slack_work: { connectionId: 12345 },
254
- google_sheets: { connectionId: 67890 },
255
- },
256
- },
257
- });
258
- ```
259
-
260
- ### Using Named Connections
261
-
262
- ```typescript
263
- // Per-call with alias
264
- await zapier.apps.slack.read.channels({ connection: "slack_work" });
265
-
266
- // Factory binding
267
- const slack = zapier.apps.slack({ connection: "slack_work" });
268
- await slack.read.channels({});
269
-
270
- // Lower-level API
271
- await zapier.runAction({
272
- app: "slack",
273
- actionType: "read",
274
- action: "channels",
275
- connection: "slack_work",
276
- });
277
-
278
- // Direct numeric connection ID also works
279
- await zapier.apps.slack.read.channels({ connection: 12345 });
280
- ```
281
-
282
- ### Resolution Precedence
283
-
284
- For `connection`: explicit value > factory binding. String values are resolved from the connections map; numeric values are used directly as connection IDs. `connectionId` and `authenticationId` are deprecated aliases for `connection`.
285
-
286
- App version is always resolved from the `.zapierrc` manifest, not from connections.
287
-
288
- ## Error Handling
289
-
290
- ### Debugging
291
-
292
- Enable debug mode to see API requests and responses:
293
-
294
- ```typescript
295
- const zapier = createZapierSdk({ debug: true });
296
- ```
297
-
298
- Or set the environment variable:
299
-
300
- ```bash
301
- DEBUG=zapier:* node your-script.js
302
- ```
303
-
304
- ### Common Errors
305
-
306
- - **"No credentials provided"**: Run `npx zapier-sdk login` or provide credentials explicitly
307
- - **"Connection not found"**: The `connection` doesn't exist or you don't have access
308
- - **"App not found"**: Check the app key using `listApps({ search: "..." })`
309
- - **"Action not found"**: Verify the action type and key with `listActions({ app: "..." })`
310
-
311
- ## Environment Variables
312
-
313
- | Variable | Purpose |
314
- | ---------------------------------- | ---------------------------------------------------------- |
315
- | `ZAPIER_CREDENTIALS` | Token string (alternative to passing `credentials` option) |
316
- | `ZAPIER_CREDENTIALS_CLIENT_ID` | OAuth client ID for client_credentials or PKCE flow |
317
- | `ZAPIER_CREDENTIALS_CLIENT_SECRET` | OAuth client secret (for client_credentials flow) |
318
- | `ZAPIER_CREDENTIALS_BASE_URL` | Override auth base URL |
319
- | `ZAPIER_CREDENTIALS_SCOPE` | OAuth scope |
320
- | `ZAPIER_BASE_URL` | Override API base URL (for testing) |
321
- | `DEBUG` | Enable debug logging (`zapier:*` for all SDK logs) |
5
+ @AGENTS.md