@zapier/zapier-sdk-cli 0.13.8 → 0.13.10

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.
@@ -8,7 +8,11 @@ import type {
8
8
  ManifestPluginProvides,
9
9
  AppItem,
10
10
  } from "@zapier/zapier-sdk";
11
- import { createFunction } from "@zapier/zapier-sdk";
11
+ import {
12
+ createFunction,
13
+ ZapierValidationError,
14
+ ZapierUnknownError,
15
+ } from "@zapier/zapier-sdk";
12
16
  import {
13
17
  GenerateAppTypesSchema,
14
18
  type GenerateAppTypesOptions,
@@ -17,7 +21,8 @@ import {
17
21
  import { AstTypeGenerator } from "../../generators/ast-generator";
18
22
  import { getManifestKey } from "../../utils/manifest-helpers";
19
23
  import { mkdir, writeFile } from "fs/promises";
20
- import { join } from "path";
24
+ import { join, resolve } from "path";
25
+ import { detectTypesOutputDirectory } from "../../utils/directory-detection";
21
26
 
22
27
  export interface GenerateAppTypesPluginProvides {
23
28
  generateAppTypes: (
@@ -50,20 +55,14 @@ export const generateAppTypesPlugin: Plugin<
50
55
  appKeys,
51
56
  authenticationIds,
52
57
  skipWrite = false,
53
- typesOutputDirectory,
58
+ typesOutputDirectory = await detectTypesOutputDirectory(),
54
59
  onProgress,
55
60
  } = options;
56
61
 
57
- // Validate that typesOutputDirectory is provided when skipWrite is false
58
- if (!skipWrite && !typesOutputDirectory) {
59
- throw new Error(
60
- "typesOutputDirectory is required when skipWrite is false",
61
- );
62
- }
62
+ const resolvedTypesOutput = resolve(typesOutputDirectory);
63
63
 
64
64
  const result: GenerateAppTypesResult = {
65
65
  typeDefinitions: {},
66
- errors: [],
67
66
  };
68
67
 
69
68
  // Get apps using listApps (which respects existing manifest for version locking)
@@ -100,8 +99,8 @@ export const generateAppTypesPlugin: Plugin<
100
99
  }
101
100
 
102
101
  // Ensure output directory exists if we're writing files
103
- if (!skipWrite && typesOutputDirectory) {
104
- await mkdir(typesOutputDirectory, { recursive: true });
102
+ if (!skipWrite && resolvedTypesOutput) {
103
+ await mkdir(resolvedTypesOutput, { recursive: true });
105
104
  }
106
105
 
107
106
  // Initialize writtenFiles if we're writing to disk
@@ -119,17 +118,18 @@ export const generateAppTypesPlugin: Plugin<
119
118
 
120
119
  try {
121
120
  if (!app.version) {
122
- const error = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
123
- result.errors.push({
124
- appKey: app.key,
125
- error,
126
- });
121
+ const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
127
122
  onProgress?.({
128
123
  type: "app_processing_error",
129
124
  appKey: app.key,
130
- error,
125
+ error: errorMessage,
126
+ });
127
+ throw new ZapierValidationError(errorMessage, {
128
+ details: {
129
+ appKey: app.key,
130
+ implementationId: app.implementation_id,
131
+ },
131
132
  });
132
- continue;
133
133
  }
134
134
 
135
135
  // Find matching authentication for this app if authentications were provided
@@ -158,63 +158,55 @@ export const generateAppTypesPlugin: Plugin<
158
158
  const manifestKey = getManifestKey(app);
159
159
 
160
160
  // Generate type definitions
161
- try {
162
- const generator = new AstTypeGenerator();
163
- const typeDefinitionString = await generator.generateTypes({
164
- app,
165
- authenticationId,
166
- sdk,
167
- });
168
-
169
- result.typeDefinitions[manifestKey] = typeDefinitionString;
161
+ const generator = new AstTypeGenerator();
162
+ const typeDefinitionString = await generator.generateTypes({
163
+ app,
164
+ authenticationId,
165
+ sdk,
166
+ });
170
167
 
171
- onProgress?.({
172
- type: "type_generated",
173
- manifestKey,
174
- sizeBytes: typeDefinitionString.length,
175
- });
168
+ result.typeDefinitions[manifestKey] = typeDefinitionString;
176
169
 
177
- // Write to file if skipWrite is false
178
- if (!skipWrite && typesOutputDirectory && result.writtenFiles) {
179
- const filePath = join(typesOutputDirectory, `${manifestKey}.d.ts`);
180
- await writeFile(filePath, typeDefinitionString, "utf8");
170
+ onProgress?.({
171
+ type: "type_generated",
172
+ manifestKey,
173
+ sizeBytes: typeDefinitionString.length,
174
+ });
181
175
 
182
- result.writtenFiles[manifestKey] = filePath;
176
+ // Write to file if skipWrite is false
177
+ if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
178
+ const filePath = join(resolvedTypesOutput, `${manifestKey}.d.ts`);
179
+ await writeFile(filePath, typeDefinitionString, "utf8");
183
180
 
184
- onProgress?.({
185
- type: "file_written",
186
- manifestKey,
187
- filePath,
188
- });
189
- }
181
+ result.writtenFiles[manifestKey] = filePath;
190
182
 
191
183
  onProgress?.({
192
- type: "app_processing_complete",
193
- appKey: app.key,
194
- });
195
- } catch (error) {
196
- const errorMessage = `Failed to generate types: ${error}`;
197
- result.errors.push({
198
- appKey: app.key,
199
- error: errorMessage,
200
- });
201
- onProgress?.({
202
- type: "app_processing_error",
203
- appKey: app.key,
204
- error: errorMessage,
184
+ type: "file_written",
185
+ manifestKey,
186
+ filePath,
205
187
  });
206
188
  }
207
- } catch (error) {
208
- const errorMessage = `Failed to process app: ${error}`;
209
- result.errors.push({
189
+
190
+ onProgress?.({
191
+ type: "app_processing_complete",
210
192
  appKey: app.key,
211
- error: errorMessage,
212
193
  });
194
+ } catch (error) {
195
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
196
+
213
197
  onProgress?.({
214
198
  type: "app_processing_error",
215
199
  appKey: app.key,
216
200
  error: errorMessage,
217
201
  });
202
+
203
+ if (error instanceof ZapierValidationError) {
204
+ throw error; // Preserve the specific error type
205
+ } else {
206
+ throw new ZapierUnknownError(errorMessage, {
207
+ cause: error, // Works for both Error and non-Error
208
+ });
209
+ }
218
210
  }
219
211
  }
220
212
 
@@ -58,8 +58,4 @@ export type AppTypesProgressEvent =
58
58
  export interface GenerateAppTypesResult {
59
59
  typeDefinitions: Record<string, string>; // manifestKey -> type definition string
60
60
  writtenFiles?: Record<string, string>; // manifestKey -> file path (only when skipWrite is false)
61
- errors: Array<{
62
- appKey: string;
63
- error: string;
64
- }>;
65
61
  }
package/src/sdk.ts CHANGED
@@ -15,17 +15,7 @@ import {
15
15
  } from "./plugins/index";
16
16
  import type { ZapierSdkCli } from "./types/sdk";
17
17
 
18
- export interface ZapierCliSdkOptions extends ZapierSdkOptions {
19
- debug?: boolean;
20
- eventEmission?: {
21
- enabled?: boolean;
22
- transport?: {
23
- type: "http" | "console" | "noop";
24
- endpoint?: string;
25
- headers?: Record<string, string>;
26
- };
27
- };
28
- }
18
+ export interface ZapierCliSdkOptions extends ZapierSdkOptions {}
29
19
 
30
20
  /**
31
21
  * Create a Zapier SDK instance configured specifically for the CLI
@@ -38,8 +28,7 @@ export function createZapierCliSdk(
38
28
  // Chaining prevents type widening that occurs with let reassignment
39
29
  return (
40
30
  createZapierSdkWithoutRegistry({
41
- debug: options.debug,
42
- eventEmission: options.eventEmission,
31
+ ...options,
43
32
  })
44
33
  // Add CLI-specific plugins before registry
45
34
  .addPlugin(generateAppTypesPlugin)