@zapier/zapier-sdk-cli 0.13.5 → 0.13.7
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 +21 -0
- package/README.md +39 -0
- package/dist/cli.cjs +360 -82
- package/dist/cli.mjs +356 -78
- package/dist/index.cjs +359 -81
- package/dist/index.d.mts +155 -3
- package/dist/index.d.ts +155 -3
- package/dist/index.mjs +355 -77
- package/dist/package.json +1 -1
- package/dist/src/plugins/add/index.d.ts +4 -2
- package/dist/src/plugins/add/index.js +89 -98
- package/dist/src/plugins/buildManifest/index.d.ts +13 -0
- package/dist/src/plugins/buildManifest/index.js +81 -0
- package/dist/src/plugins/buildManifest/schemas.d.ts +56 -0
- package/dist/src/plugins/buildManifest/schemas.js +17 -0
- package/dist/src/plugins/generateAppTypes/index.d.ts +13 -0
- package/dist/src/plugins/generateAppTypes/index.js +169 -0
- package/dist/src/plugins/generateAppTypes/schemas.d.ts +72 -0
- package/dist/src/plugins/generateAppTypes/schemas.js +21 -0
- package/dist/src/plugins/index.d.ts +2 -0
- package/dist/src/plugins/index.js +2 -0
- package/dist/src/sdk.d.ts +4 -3
- package/dist/src/sdk.js +16 -14
- package/dist/src/types/sdk.d.ts +5 -0
- package/dist/src/types/sdk.js +1 -0
- package/dist/src/utils/constants.d.ts +1 -3
- package/dist/src/utils/constants.js +3 -4
- package/dist/src/utils/directory-detection.d.ts +5 -0
- package/dist/src/utils/directory-detection.js +21 -0
- package/dist/src/utils/manifest-helpers.d.ts +10 -0
- package/dist/src/utils/manifest-helpers.js +19 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/plugins/add/index.ts +123 -125
- package/src/plugins/buildManifest/index.test.ts +612 -0
- package/src/plugins/buildManifest/index.ts +128 -0
- package/src/plugins/buildManifest/schemas.ts +59 -0
- package/src/plugins/generateAppTypes/index.ts +235 -0
- package/src/plugins/generateAppTypes/schemas.ts +65 -0
- package/src/plugins/index.ts +2 -0
- package/src/sdk.ts +25 -21
- package/src/types/sdk.ts +8 -0
- package/src/utils/constants.ts +7 -6
- package/src/utils/directory-detection.ts +23 -0
- package/src/utils/manifest-helpers.ts +25 -0
- /package/dist/src/{plugins/add → generators}/ast-generator.d.ts +0 -0
- /package/dist/src/{plugins/add → generators}/ast-generator.js +0 -0
- /package/src/{plugins/add → generators}/ast-generator.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk-cli",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.7",
|
|
4
4
|
"description": "Command line interface for Zapier SDK",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"pkce-challenge": "^5.0.0",
|
|
44
44
|
"typescript": "^5.8.3",
|
|
45
45
|
"zod": "^3.25.67",
|
|
46
|
-
"@zapier/zapier-sdk": "0.13.
|
|
47
|
-
"@zapier/zapier-sdk-cli-login": "0.3.
|
|
48
|
-
"@zapier/zapier-sdk-mcp": "0.3.
|
|
46
|
+
"@zapier/zapier-sdk": "0.13.6",
|
|
47
|
+
"@zapier/zapier-sdk-cli-login": "0.3.3",
|
|
48
|
+
"@zapier/zapier-sdk-mcp": "0.3.19"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/express": "^5.0.3",
|
package/src/plugins/add/index.ts
CHANGED
|
@@ -1,40 +1,22 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Plugin,
|
|
3
3
|
GetSdkType,
|
|
4
|
-
GetContextType,
|
|
5
4
|
ListActionsPluginProvides,
|
|
6
5
|
ListAppsPluginProvides,
|
|
7
6
|
ListInputFieldsPluginProvides,
|
|
8
7
|
ListAuthenticationsPluginProvides,
|
|
9
|
-
ManifestPluginProvides,
|
|
10
|
-
AppItem,
|
|
11
8
|
} from "@zapier/zapier-sdk";
|
|
12
9
|
import { createFunction } from "@zapier/zapier-sdk";
|
|
13
10
|
import { AddSchema, type AddOptions } from "./schemas";
|
|
14
|
-
import { AstTypeGenerator } from "./ast-generator";
|
|
15
|
-
import { mkdir, access, writeFile } from "fs/promises";
|
|
16
|
-
import { resolve, join } from "path";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Detect the best default directory for TypeScript types
|
|
20
|
-
* Looks for src or lib directories, falls back to current directory
|
|
21
|
-
*/
|
|
22
|
-
async function detectTypesOutputDirectory(): Promise<string> {
|
|
23
|
-
// Check for common source directories in priority order
|
|
24
|
-
const candidates = ["src", "lib"];
|
|
25
|
-
|
|
26
|
-
for (const candidate of candidates) {
|
|
27
|
-
try {
|
|
28
|
-
await access(candidate);
|
|
29
|
-
return join(candidate, "zapier", "apps");
|
|
30
|
-
} catch {
|
|
31
|
-
// Directory doesn't exist, continue to next candidate
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
11
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
12
|
+
import { type GenerateAppTypesPluginProvides } from "../generateAppTypes";
|
|
13
|
+
import { type AppTypesProgressEvent } from "../generateAppTypes/schemas";
|
|
14
|
+
import { type BuildManifestPluginProvides } from "../buildManifest";
|
|
15
|
+
import { type ManifestBuildProgressEvent } from "../buildManifest/schemas";
|
|
16
|
+
|
|
17
|
+
import { detectTypesOutputDirectory } from "../../utils/directory-detection";
|
|
18
|
+
|
|
19
|
+
import { resolve } from "path";
|
|
38
20
|
export interface AddPluginProvides {
|
|
39
21
|
add: (options: AddOptions) => Promise<void>;
|
|
40
22
|
context: {
|
|
@@ -52,11 +34,12 @@ export const addPlugin: Plugin<
|
|
|
52
34
|
ListActionsPluginProvides &
|
|
53
35
|
ListInputFieldsPluginProvides &
|
|
54
36
|
ListAuthenticationsPluginProvides &
|
|
55
|
-
|
|
37
|
+
BuildManifestPluginProvides &
|
|
38
|
+
GenerateAppTypesPluginProvides
|
|
56
39
|
>,
|
|
57
|
-
|
|
40
|
+
{},
|
|
58
41
|
AddPluginProvides
|
|
59
|
-
> = ({ sdk
|
|
42
|
+
> = ({ sdk }) => {
|
|
60
43
|
const add = createFunction(async function add(options: AddOptions) {
|
|
61
44
|
const {
|
|
62
45
|
appKeys,
|
|
@@ -64,114 +47,129 @@ export const addPlugin: Plugin<
|
|
|
64
47
|
configPath,
|
|
65
48
|
typesOutput = await detectTypesOutputDirectory(),
|
|
66
49
|
} = options;
|
|
67
|
-
|
|
68
50
|
const resolvedTypesOutput = resolve(typesOutput);
|
|
69
51
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
52
|
+
console.log(`📦 Adding ${appKeys.length} app(s)...`);
|
|
53
|
+
|
|
54
|
+
// Track app names for better console output
|
|
55
|
+
const appSlugAndKeyMap = new Map<string, string>();
|
|
56
|
+
|
|
57
|
+
// Define progress handler for manifest building
|
|
58
|
+
const handleManifestProgress = (event: ManifestBuildProgressEvent) => {
|
|
59
|
+
switch (event.type) {
|
|
60
|
+
case "apps_lookup_start":
|
|
61
|
+
console.log(`📦 Looking up ${event.count} app(s)...`);
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case "app_found":
|
|
65
|
+
// Store the app display name for later use
|
|
66
|
+
const displayName = event.app.slug
|
|
67
|
+
? `${event.app.slug} (${event.app.key})`
|
|
68
|
+
: event.app.key;
|
|
69
|
+
appSlugAndKeyMap.set(event.app.key, displayName);
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case "apps_lookup_complete":
|
|
73
|
+
if (event.count === 0) {
|
|
74
|
+
console.warn("⚠️ No apps found");
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case "app_processing_start":
|
|
79
|
+
const appName = event.slug
|
|
80
|
+
? `${event.slug} (${event.appKey})`
|
|
81
|
+
: event.appKey;
|
|
82
|
+
console.log(`📦 Adding ${appName}...`);
|
|
83
|
+
break;
|
|
84
|
+
|
|
85
|
+
case "manifest_updated":
|
|
86
|
+
const appDisplay = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
87
|
+
console.log(
|
|
88
|
+
`📝 Locked ${appDisplay} to ${event.appKey}@${event.version} using key '${event.manifestKey}'`,
|
|
89
|
+
);
|
|
90
|
+
break;
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
`🔐 Looking up ${authenticationIds.length} authentication(s)...`,
|
|
91
|
-
);
|
|
92
|
-
const authsIterator = sdk
|
|
93
|
-
.listAuthentications({ authenticationIds })
|
|
94
|
-
.items();
|
|
95
|
-
for await (const auth of authsIterator) {
|
|
96
|
-
authentications.push(auth);
|
|
92
|
+
case "app_processing_error":
|
|
93
|
+
const errorApp = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
94
|
+
console.warn(`⚠️ ${event.error} for ${errorApp}`);
|
|
95
|
+
break;
|
|
97
96
|
}
|
|
98
|
-
|
|
99
|
-
}
|
|
97
|
+
};
|
|
100
98
|
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
// Define progress handler for type generation
|
|
100
|
+
const handleTypesProgress = (event: AppTypesProgressEvent) => {
|
|
101
|
+
switch (event.type) {
|
|
102
|
+
case "authentications_lookup_start":
|
|
103
|
+
console.log(`🔐 Looking up ${event.count} authentication(s)...`);
|
|
104
|
+
break;
|
|
105
|
+
|
|
106
|
+
case "authentications_lookup_complete":
|
|
107
|
+
console.log(`🔐 Found ${event.count} authentication(s)`);
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
case "authentication_matched":
|
|
111
|
+
const appWithAuth =
|
|
112
|
+
appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
113
|
+
console.log(
|
|
114
|
+
`🔐 Using authentication ${event.authenticationId} (${event.authenticationTitle}) for ${appWithAuth}`,
|
|
115
|
+
);
|
|
116
|
+
break;
|
|
105
117
|
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
case "authentication_not_matched":
|
|
119
|
+
const appWithoutAuth =
|
|
120
|
+
appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
108
121
|
console.warn(
|
|
109
|
-
`⚠️
|
|
122
|
+
`⚠️ No matching authentication found for ${appWithoutAuth}`,
|
|
110
123
|
);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
app.key,
|
|
117
|
-
{
|
|
118
|
-
implementationName: app.key,
|
|
119
|
-
version: app.version,
|
|
120
|
-
},
|
|
121
|
-
configPath,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
console.log(
|
|
125
|
-
`📝 Locked ${appSlugAndKey} to ${app.key}@${app.version} using key '${manifestKey}'`,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// Find matching authentication for this app if authentications were provided
|
|
129
|
-
let authenticationId: number | undefined;
|
|
130
|
-
if (authentications.length > 0) {
|
|
131
|
-
// Match authentication by app_key
|
|
132
|
-
const matchingAuth = authentications.find((auth) => {
|
|
133
|
-
return auth.app_key === app.key;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
if (matchingAuth) {
|
|
137
|
-
authenticationId = matchingAuth.id;
|
|
138
|
-
console.log(
|
|
139
|
-
`🔐 Using authentication ${authenticationId} (${matchingAuth.title}) for ${appSlugAndKey}`,
|
|
140
|
-
);
|
|
141
|
-
} else {
|
|
142
|
-
console.warn(
|
|
143
|
-
`⚠️ No matching authentication found for ${appSlugAndKey}`,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Generate types using the manifest key for consistency
|
|
149
|
-
const typesPath = join(resolvedTypesOutput, `${manifestKey}.d.ts`);
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
// Use AST-based generator directly
|
|
153
|
-
const generator = new AstTypeGenerator();
|
|
154
|
-
const typeDefinitions = await generator.generateTypes({
|
|
155
|
-
app,
|
|
156
|
-
authenticationId,
|
|
157
|
-
sdk,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Write to file
|
|
161
|
-
await writeFile(typesPath, typeDefinitions, "utf8");
|
|
162
|
-
console.log(`🔧 Generated types for ${manifestKey} at ${typesPath}`);
|
|
163
|
-
} catch (error) {
|
|
164
|
-
console.warn(
|
|
165
|
-
`⚠️ Failed to generate types for ${appSlugAndKey}: ${error}`,
|
|
124
|
+
break;
|
|
125
|
+
|
|
126
|
+
case "file_written":
|
|
127
|
+
console.log(
|
|
128
|
+
`🔧 Generated types for ${event.manifestKey} at ${event.filePath}`,
|
|
166
129
|
);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
130
|
+
break;
|
|
131
|
+
|
|
132
|
+
case "app_processing_error":
|
|
133
|
+
const errorApp = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
134
|
+
console.warn(`⚠️ ${event.error} for ${errorApp}`);
|
|
135
|
+
break;
|
|
171
136
|
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const manifestResult = await sdk.buildManifest({
|
|
140
|
+
appKeys,
|
|
141
|
+
skipWrite: false,
|
|
142
|
+
configPath,
|
|
143
|
+
onProgress: handleManifestProgress,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const typesResult = await sdk.generateAppTypes({
|
|
147
|
+
appKeys,
|
|
148
|
+
authenticationIds,
|
|
149
|
+
skipWrite: false,
|
|
150
|
+
typesOutputDirectory: resolvedTypesOutput,
|
|
151
|
+
onProgress: handleTypesProgress,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const results = manifestResult.manifest?.apps || {};
|
|
155
|
+
|
|
156
|
+
// Final summary
|
|
157
|
+
const successfulApps = Object.keys(results).filter(
|
|
158
|
+
(manifestKey) => typesResult.writtenFiles?.[manifestKey],
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (successfulApps.length > 0) {
|
|
162
|
+
console.log(`✅ Added ${successfulApps.length} app(s) to manifest`);
|
|
172
163
|
}
|
|
173
164
|
|
|
174
|
-
|
|
165
|
+
// Report any errors
|
|
166
|
+
const allErrors = [...manifestResult.errors, ...typesResult.errors];
|
|
167
|
+
if (allErrors.length > 0) {
|
|
168
|
+
console.warn(`\n⚠️ ${allErrors.length} error(s) occurred:`);
|
|
169
|
+
allErrors.forEach(({ appKey, error }) => {
|
|
170
|
+
console.warn(` - ${appKey}: ${error}`);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
175
173
|
}, AddSchema);
|
|
176
174
|
|
|
177
175
|
return {
|