@zapier/zapier-sdk 0.25.2 → 0.25.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.25.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 7ab8539: Adding feedback command for submitting SDK feedback
8
+
3
9
  ## 0.25.2
4
10
 
5
11
  ### Patch Changes
package/CLAUDE.md ADDED
@@ -0,0 +1,273 @@
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({ appKey: "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
+ authenticationId: "123",
144
+ });
145
+ ```
146
+
147
+ ### Binding Authentication
148
+
149
+ Instead of passing `authenticationId` to every call, bind it once:
150
+
151
+ ```typescript
152
+ // Create a bound app instance
153
+ const mySlack = zapier.apps.slack({ authenticationId: "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({ appKey: "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
+ authenticationId: "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
+ ## Error Handling
241
+
242
+ ### Debugging
243
+
244
+ Enable debug mode to see API requests and responses:
245
+
246
+ ```typescript
247
+ const zapier = createZapierSdk({ debug: true });
248
+ ```
249
+
250
+ Or set the environment variable:
251
+
252
+ ```bash
253
+ DEBUG=zapier:* node your-script.js
254
+ ```
255
+
256
+ ### Common Errors
257
+
258
+ - **"No credentials provided"**: Run `npx zapier-sdk login` or provide credentials explicitly
259
+ - **"Authentication not found"**: The `authenticationId` doesn't exist or you don't have access
260
+ - **"App not found"**: Check the app key using `listApps({ search: "..." })`
261
+ - **"Action not found"**: Verify the action type and key with `listActions({ appKey: "..." })`
262
+
263
+ ## Environment Variables
264
+
265
+ | Variable | Purpose |
266
+ | ---------------------------------- | ---------------------------------------------------------- |
267
+ | `ZAPIER_CREDENTIALS` | Token string (alternative to passing `credentials` option) |
268
+ | `ZAPIER_CREDENTIALS_CLIENT_ID` | OAuth client ID for client_credentials or PKCE flow |
269
+ | `ZAPIER_CREDENTIALS_CLIENT_SECRET` | OAuth client secret (for client_credentials flow) |
270
+ | `ZAPIER_CREDENTIALS_BASE_URL` | Override auth base URL |
271
+ | `ZAPIER_CREDENTIALS_SCOPE` | OAuth scope |
272
+ | `ZAPIER_BASE_URL` | Override API base URL (for testing) |
273
+ | `DEBUG` | Enable debug logging (`zapier:*` for all SDK logs) |
package/dist/index.cjs CHANGED
@@ -5155,7 +5155,7 @@ function getCpuTime() {
5155
5155
 
5156
5156
  // package.json
5157
5157
  var package_default = {
5158
- version: "0.25.2"};
5158
+ version: "0.25.3"};
5159
5159
 
5160
5160
  // src/plugins/eventEmission/builders.ts
5161
5161
  function createBaseEvent(context = {}) {
package/dist/index.mjs CHANGED
@@ -5133,7 +5133,7 @@ function getCpuTime() {
5133
5133
 
5134
5134
  // package.json
5135
5135
  var package_default = {
5136
- version: "0.25.2"};
5136
+ version: "0.25.3"};
5137
5137
 
5138
5138
  // src/plugins/eventEmission/builders.ts
5139
5139
  function createBaseEvent(context = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.25.2",
3
+ "version": "0.25.3",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -20,6 +20,7 @@
20
20
  "files": [
21
21
  "dist",
22
22
  "README.md",
23
+ "CLAUDE.md",
23
24
  "CHANGELOG.md"
24
25
  ],
25
26
  "keywords": [