@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.
@@ -1,12 +1,9 @@
1
- import { createFunction } from "@zapier/zapier-sdk";
1
+ import { createFunction, ZapierValidationError, ZapierUnknownError, } from "@zapier/zapier-sdk";
2
2
  import { BuildManifestSchema, } from "./schemas";
3
3
  import { createManifestEntry } from "../../utils/manifest-helpers";
4
4
  export const buildManifestPlugin = ({ sdk, context }) => {
5
5
  const buildManifest = createFunction(async function buildManifest(options) {
6
6
  const { appKeys, skipWrite = false, configPath, onProgress } = options;
7
- const result = {
8
- errors: [],
9
- };
10
7
  // Get apps using listApps (which respects existing manifest for version locking)
11
8
  onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
12
9
  const appsIterator = sdk.listApps({ appKeys }).items();
@@ -17,7 +14,7 @@ export const buildManifestPlugin = ({ sdk, context }) => {
17
14
  }
18
15
  onProgress?.({ type: "apps_lookup_complete", count: apps.length });
19
16
  if (apps.length === 0) {
20
- return result;
17
+ return {};
21
18
  }
22
19
  let updatedManifest;
23
20
  // Process each app
@@ -52,20 +49,23 @@ export const buildManifestPlugin = ({ sdk, context }) => {
52
49
  onProgress?.({ type: "app_processing_complete", appKey: app.key });
53
50
  }
54
51
  catch (error) {
55
- const errorMessage = `Failed to process app: ${error}`;
56
- result.errors.push({
57
- appKey: app.key,
58
- error: errorMessage,
59
- });
52
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
60
53
  onProgress?.({
61
54
  type: "app_processing_error",
62
55
  appKey: app.key,
63
56
  error: errorMessage,
64
57
  });
58
+ if (error instanceof ZapierValidationError) {
59
+ throw error; // Preserve the specific error type
60
+ }
61
+ else {
62
+ throw new ZapierUnknownError(errorMessage, {
63
+ cause: error, // Works for both Error and non-Error
64
+ });
65
+ }
65
66
  }
66
67
  }
67
- result.manifest = updatedManifest;
68
- return result;
68
+ return { manifest: updatedManifest };
69
69
  }, BuildManifestSchema);
70
70
  return {
71
71
  buildManifest,
@@ -49,8 +49,4 @@ export type ManifestBuildProgressEvent = {
49
49
  };
50
50
  export interface BuildManifestResult {
51
51
  manifest?: Manifest;
52
- errors: Array<{
53
- appKey: string;
54
- error: string;
55
- }>;
56
52
  }
@@ -1,19 +1,16 @@
1
- import { createFunction } from "@zapier/zapier-sdk";
1
+ import { createFunction, ZapierValidationError, ZapierUnknownError, } from "@zapier/zapier-sdk";
2
2
  import { GenerateAppTypesSchema, } from "./schemas";
3
3
  import { AstTypeGenerator } from "../../generators/ast-generator";
4
4
  import { getManifestKey } from "../../utils/manifest-helpers";
5
5
  import { mkdir, writeFile } from "fs/promises";
6
- import { join } from "path";
6
+ import { join, resolve } from "path";
7
+ import { detectTypesOutputDirectory } from "../../utils/directory-detection";
7
8
  export const generateAppTypesPlugin = ({ sdk }) => {
8
9
  const generateAppTypes = createFunction(async function generateAppTypes(options) {
9
- const { appKeys, authenticationIds, skipWrite = false, typesOutputDirectory, onProgress, } = options;
10
- // Validate that typesOutputDirectory is provided when skipWrite is false
11
- if (!skipWrite && !typesOutputDirectory) {
12
- throw new Error("typesOutputDirectory is required when skipWrite is false");
13
- }
10
+ const { appKeys, authenticationIds, skipWrite = false, typesOutputDirectory = await detectTypesOutputDirectory(), onProgress, } = options;
11
+ const resolvedTypesOutput = resolve(typesOutputDirectory);
14
12
  const result = {
15
13
  typeDefinitions: {},
16
- errors: [],
17
14
  };
18
15
  // Get apps using listApps (which respects existing manifest for version locking)
19
16
  onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
@@ -46,8 +43,8 @@ export const generateAppTypesPlugin = ({ sdk }) => {
46
43
  });
47
44
  }
48
45
  // Ensure output directory exists if we're writing files
49
- if (!skipWrite && typesOutputDirectory) {
50
- await mkdir(typesOutputDirectory, { recursive: true });
46
+ if (!skipWrite && resolvedTypesOutput) {
47
+ await mkdir(resolvedTypesOutput, { recursive: true });
51
48
  }
52
49
  // Initialize writtenFiles if we're writing to disk
53
50
  if (!skipWrite) {
@@ -62,17 +59,18 @@ export const generateAppTypesPlugin = ({ sdk }) => {
62
59
  });
63
60
  try {
64
61
  if (!app.version) {
65
- const error = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
66
- result.errors.push({
67
- appKey: app.key,
68
- error,
69
- });
62
+ const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
70
63
  onProgress?.({
71
64
  type: "app_processing_error",
72
65
  appKey: app.key,
73
- error,
66
+ error: errorMessage,
67
+ });
68
+ throw new ZapierValidationError(errorMessage, {
69
+ details: {
70
+ appKey: app.key,
71
+ implementationId: app.implementation_id,
72
+ },
74
73
  });
75
- continue;
76
74
  }
77
75
  // Find matching authentication for this app if authentications were provided
78
76
  let authenticationId;
@@ -98,59 +96,49 @@ export const generateAppTypesPlugin = ({ sdk }) => {
98
96
  }
99
97
  const manifestKey = getManifestKey(app);
100
98
  // Generate type definitions
101
- try {
102
- const generator = new AstTypeGenerator();
103
- const typeDefinitionString = await generator.generateTypes({
104
- app,
105
- authenticationId,
106
- sdk,
107
- });
108
- result.typeDefinitions[manifestKey] = typeDefinitionString;
99
+ const generator = new AstTypeGenerator();
100
+ const typeDefinitionString = await generator.generateTypes({
101
+ app,
102
+ authenticationId,
103
+ sdk,
104
+ });
105
+ result.typeDefinitions[manifestKey] = typeDefinitionString;
106
+ onProgress?.({
107
+ type: "type_generated",
108
+ manifestKey,
109
+ sizeBytes: typeDefinitionString.length,
110
+ });
111
+ // Write to file if skipWrite is false
112
+ if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
113
+ const filePath = join(resolvedTypesOutput, `${manifestKey}.d.ts`);
114
+ await writeFile(filePath, typeDefinitionString, "utf8");
115
+ result.writtenFiles[manifestKey] = filePath;
109
116
  onProgress?.({
110
- type: "type_generated",
117
+ type: "file_written",
111
118
  manifestKey,
112
- sizeBytes: typeDefinitionString.length,
113
- });
114
- // Write to file if skipWrite is false
115
- if (!skipWrite && typesOutputDirectory && result.writtenFiles) {
116
- const filePath = join(typesOutputDirectory, `${manifestKey}.d.ts`);
117
- await writeFile(filePath, typeDefinitionString, "utf8");
118
- result.writtenFiles[manifestKey] = filePath;
119
- onProgress?.({
120
- type: "file_written",
121
- manifestKey,
122
- filePath,
123
- });
124
- }
125
- onProgress?.({
126
- type: "app_processing_complete",
127
- appKey: app.key,
128
- });
129
- }
130
- catch (error) {
131
- const errorMessage = `Failed to generate types: ${error}`;
132
- result.errors.push({
133
- appKey: app.key,
134
- error: errorMessage,
135
- });
136
- onProgress?.({
137
- type: "app_processing_error",
138
- appKey: app.key,
139
- error: errorMessage,
119
+ filePath,
140
120
  });
141
121
  }
142
- }
143
- catch (error) {
144
- const errorMessage = `Failed to process app: ${error}`;
145
- result.errors.push({
122
+ onProgress?.({
123
+ type: "app_processing_complete",
146
124
  appKey: app.key,
147
- error: errorMessage,
148
125
  });
126
+ }
127
+ catch (error) {
128
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
149
129
  onProgress?.({
150
130
  type: "app_processing_error",
151
131
  appKey: app.key,
152
132
  error: errorMessage,
153
133
  });
134
+ if (error instanceof ZapierValidationError) {
135
+ throw error; // Preserve the specific error type
136
+ }
137
+ else {
138
+ throw new ZapierUnknownError(errorMessage, {
139
+ cause: error, // Works for both Error and non-Error
140
+ });
141
+ }
154
142
  }
155
143
  }
156
144
  return result;
@@ -65,8 +65,4 @@ export type AppTypesProgressEvent = {
65
65
  export interface GenerateAppTypesResult {
66
66
  typeDefinitions: Record<string, string>;
67
67
  writtenFiles?: Record<string, string>;
68
- errors: Array<{
69
- appKey: string;
70
- error: string;
71
- }>;
72
68
  }
package/dist/src/sdk.d.ts CHANGED
@@ -1,15 +1,6 @@
1
1
  import { type ZapierSdkOptions } from "@zapier/zapier-sdk";
2
2
  import type { ZapierSdkCli } from "./types/sdk";
3
3
  export interface ZapierCliSdkOptions extends ZapierSdkOptions {
4
- debug?: boolean;
5
- eventEmission?: {
6
- enabled?: boolean;
7
- transport?: {
8
- type: "http" | "console" | "noop";
9
- endpoint?: string;
10
- headers?: Record<string, string>;
11
- };
12
- };
13
4
  }
14
5
  /**
15
6
  * Create a Zapier SDK instance configured specifically for the CLI
package/dist/src/sdk.js CHANGED
@@ -8,8 +8,7 @@ export function createZapierCliSdk(options = {}) {
8
8
  // Create SDK instance and chain all plugins
9
9
  // Chaining prevents type widening that occurs with let reassignment
10
10
  return (createZapierSdkWithoutRegistry({
11
- debug: options.debug,
12
- eventEmission: options.eventEmission,
11
+ ...options,
13
12
  })
14
13
  // Add CLI-specific plugins before registry
15
14
  .addPlugin(generateAppTypesPlugin)