@zapier/zapier-sdk-cli 0.13.9 → 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.
- package/CHANGELOG.md +6 -0
- package/dist/cli.cjs +65 -86
- package/dist/cli.mjs +67 -88
- package/dist/index.cjs +64 -85
- package/dist/index.d.mts +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.mjs +66 -87
- package/dist/package.json +1 -1
- package/dist/src/plugins/add/index.js +0 -8
- package/dist/src/plugins/buildManifest/index.js +12 -12
- package/dist/src/plugins/buildManifest/schemas.d.ts +0 -4
- package/dist/src/plugins/generateAppTypes/index.js +47 -59
- package/dist/src/plugins/generateAppTypes/schemas.d.ts +0 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/plugins/add/index.ts +0 -9
- package/src/plugins/buildManifest/index.test.ts +96 -53
- package/src/plugins/buildManifest/index.ts +17 -14
- package/src/plugins/buildManifest/schemas.ts +0 -4
- package/src/plugins/generateAppTypes/index.test.ts +679 -0
- package/src/plugins/generateAppTypes/index.ts +53 -61
- package/src/plugins/generateAppTypes/schemas.ts +0 -4
|
@@ -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
|
-
|
|
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 &&
|
|
50
|
-
await mkdir(
|
|
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
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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: "
|
|
117
|
+
type: "file_written",
|
|
111
118
|
manifestKey,
|
|
112
|
-
|
|
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
|
-
|
|
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;
|