@zapier/zapier-sdk-cli 0.13.4 → 0.13.6
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 +15 -0
- package/README.md +39 -0
- package/dist/cli.cjs +354 -71
- package/dist/cli.mjs +355 -72
- package/dist/index.cjs +353 -70
- package/dist/index.d.mts +154 -2
- package/dist/index.d.ts +154 -2
- package/dist/index.mjs +354 -71
- package/dist/package.json +2 -2
- 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 +57 -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 +2 -2
- 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/directory-detection.d.ts +5 -0
- package/dist/src/utils/directory-detection.js +21 -0
- package/dist/src/utils/manifest-helpers.d.ts +13 -0
- package/dist/src/utils/manifest-helpers.js +19 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- 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 +61 -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 +23 -20
- package/src/types/sdk.ts +8 -0
- package/src/utils/directory-detection.ts +23 -0
- package/src/utils/manifest-helpers.ts +28 -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/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,156 @@
|
|
|
1
|
-
import { ZapierSdk, BaseEvent } from '@zapier/zapier-sdk';
|
|
1
|
+
import { AppItem, Manifest, GetSdkType, ZapierSdk, BaseEvent } from '@zapier/zapier-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const BuildManifestSchema: z.ZodObject<{
|
|
5
|
+
appKeys: z.ZodArray<z.ZodString, "many">;
|
|
6
|
+
skipWrite: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
configPath: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
appKeys: string[];
|
|
10
|
+
configPath?: string | undefined;
|
|
11
|
+
skipWrite?: boolean | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
appKeys: string[];
|
|
14
|
+
configPath?: string | undefined;
|
|
15
|
+
skipWrite?: boolean | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
type BuildManifestOptions = z.infer<typeof BuildManifestSchema> & {
|
|
18
|
+
onProgress?: (event: ManifestBuildProgressEvent) => void;
|
|
19
|
+
};
|
|
20
|
+
type ManifestBuildProgressEvent = {
|
|
21
|
+
type: "apps_lookup_start";
|
|
22
|
+
count: number;
|
|
23
|
+
} | {
|
|
24
|
+
type: "app_found";
|
|
25
|
+
app: AppItem;
|
|
26
|
+
} | {
|
|
27
|
+
type: "apps_lookup_complete";
|
|
28
|
+
count: number;
|
|
29
|
+
} | {
|
|
30
|
+
type: "app_processing_start";
|
|
31
|
+
appKey: string;
|
|
32
|
+
slug?: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: "manifest_entry_built";
|
|
35
|
+
appKey: string;
|
|
36
|
+
manifestKey: string;
|
|
37
|
+
version: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "manifest_updated";
|
|
40
|
+
appKey: string;
|
|
41
|
+
manifestKey: string;
|
|
42
|
+
version: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: "app_processing_complete";
|
|
45
|
+
appKey: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "app_processing_error";
|
|
48
|
+
appKey: string;
|
|
49
|
+
error: string;
|
|
50
|
+
};
|
|
51
|
+
interface BuildManifestResult {
|
|
52
|
+
manifest?: Manifest;
|
|
53
|
+
errors: Array<{
|
|
54
|
+
appKey: string;
|
|
55
|
+
error: string;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface BuildManifestPluginProvides {
|
|
60
|
+
buildManifest: (options: BuildManifestOptions) => Promise<BuildManifestResult>;
|
|
61
|
+
context: {
|
|
62
|
+
meta: {
|
|
63
|
+
buildManifest: {
|
|
64
|
+
inputSchema: typeof BuildManifestSchema;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare const GenerateAppTypesSchema: z.ZodObject<{
|
|
71
|
+
appKeys: z.ZodArray<z.ZodString, "many">;
|
|
72
|
+
authenticationIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
73
|
+
skipWrite: z.ZodOptional<z.ZodBoolean>;
|
|
74
|
+
typesOutputDirectory: z.ZodOptional<z.ZodString>;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
appKeys: string[];
|
|
77
|
+
authenticationIds?: string[] | undefined;
|
|
78
|
+
skipWrite?: boolean | undefined;
|
|
79
|
+
typesOutputDirectory?: string | undefined;
|
|
80
|
+
}, {
|
|
81
|
+
appKeys: string[];
|
|
82
|
+
authenticationIds?: string[] | undefined;
|
|
83
|
+
skipWrite?: boolean | undefined;
|
|
84
|
+
typesOutputDirectory?: string | undefined;
|
|
85
|
+
}>;
|
|
86
|
+
type GenerateAppTypesOptions = z.infer<typeof GenerateAppTypesSchema> & {
|
|
87
|
+
onProgress?: (event: AppTypesProgressEvent) => void;
|
|
88
|
+
};
|
|
89
|
+
type AppTypesProgressEvent = {
|
|
90
|
+
type: "apps_lookup_start";
|
|
91
|
+
count: number;
|
|
92
|
+
} | {
|
|
93
|
+
type: "app_found";
|
|
94
|
+
app: AppItem;
|
|
95
|
+
} | {
|
|
96
|
+
type: "apps_lookup_complete";
|
|
97
|
+
count: number;
|
|
98
|
+
} | {
|
|
99
|
+
type: "authentications_lookup_start";
|
|
100
|
+
count: number;
|
|
101
|
+
} | {
|
|
102
|
+
type: "authentications_lookup_complete";
|
|
103
|
+
count: number;
|
|
104
|
+
} | {
|
|
105
|
+
type: "app_processing_start";
|
|
106
|
+
appKey: string;
|
|
107
|
+
slug?: string;
|
|
108
|
+
} | {
|
|
109
|
+
type: "authentication_matched";
|
|
110
|
+
appKey: string;
|
|
111
|
+
authenticationId: number;
|
|
112
|
+
authenticationTitle: string;
|
|
113
|
+
} | {
|
|
114
|
+
type: "authentication_not_matched";
|
|
115
|
+
appKey: string;
|
|
116
|
+
} | {
|
|
117
|
+
type: "type_generated";
|
|
118
|
+
manifestKey: string;
|
|
119
|
+
sizeBytes: number;
|
|
120
|
+
} | {
|
|
121
|
+
type: "file_written";
|
|
122
|
+
manifestKey: string;
|
|
123
|
+
filePath: string;
|
|
124
|
+
} | {
|
|
125
|
+
type: "app_processing_complete";
|
|
126
|
+
appKey: string;
|
|
127
|
+
} | {
|
|
128
|
+
type: "app_processing_error";
|
|
129
|
+
appKey: string;
|
|
130
|
+
error: string;
|
|
131
|
+
};
|
|
132
|
+
interface GenerateAppTypesResult {
|
|
133
|
+
typeDefinitions: Record<string, string>;
|
|
134
|
+
writtenFiles?: Record<string, string>;
|
|
135
|
+
errors: Array<{
|
|
136
|
+
appKey: string;
|
|
137
|
+
error: string;
|
|
138
|
+
}>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface GenerateAppTypesPluginProvides {
|
|
142
|
+
generateAppTypes: (options: GenerateAppTypesOptions) => Promise<GenerateAppTypesResult>;
|
|
143
|
+
context: {
|
|
144
|
+
meta: {
|
|
145
|
+
generateAppTypes: {
|
|
146
|
+
inputSchema: typeof GenerateAppTypesSchema;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
interface ZapierSdkCli extends GetSdkType<ZapierSdk & BuildManifestPluginProvides & GenerateAppTypesPluginProvides> {
|
|
153
|
+
}
|
|
2
154
|
|
|
3
155
|
interface ZapierCliSdkOptions {
|
|
4
156
|
debug?: boolean;
|
|
@@ -15,7 +167,7 @@ interface ZapierCliSdkOptions {
|
|
|
15
167
|
* Create a Zapier SDK instance configured specifically for the CLI
|
|
16
168
|
* Includes all CLI-specific plugins in addition to the standard SDK functionality
|
|
17
169
|
*/
|
|
18
|
-
declare function createZapierCliSdk(options?: ZapierCliSdkOptions):
|
|
170
|
+
declare function createZapierCliSdk(options?: ZapierCliSdkOptions): ZapierSdkCli;
|
|
19
171
|
|
|
20
172
|
/**
|
|
21
173
|
* CLI-specific telemetry event definitions
|
package/dist/index.mjs
CHANGED
|
@@ -11,9 +11,9 @@ import { startMcpServerAsProcess } from '@zapier/zapier-sdk-mcp';
|
|
|
11
11
|
import { buildSync } from 'esbuild';
|
|
12
12
|
import * as fs from 'fs';
|
|
13
13
|
import * as path from 'path';
|
|
14
|
-
import {
|
|
15
|
-
import * as ts from 'typescript';
|
|
14
|
+
import { join, resolve } from 'path';
|
|
16
15
|
import { mkdir, writeFile, access } from 'fs/promises';
|
|
16
|
+
import * as ts from 'typescript';
|
|
17
17
|
|
|
18
18
|
// src/sdk.ts
|
|
19
19
|
|
|
@@ -232,7 +232,7 @@ var LoginSchema = z.object({
|
|
|
232
232
|
|
|
233
233
|
// package.json
|
|
234
234
|
var package_default = {
|
|
235
|
-
version: "0.13.
|
|
235
|
+
version: "0.13.6"};
|
|
236
236
|
|
|
237
237
|
// src/telemetry/builders.ts
|
|
238
238
|
function createCliBaseEvent(context = {}) {
|
|
@@ -520,6 +520,146 @@ var AddSchema = z.object({
|
|
|
520
520
|
}).describe(
|
|
521
521
|
"Add apps with manifest locking and TypeScript type generation - updates .zapierrc with app versions and generates TypeScript definition files"
|
|
522
522
|
);
|
|
523
|
+
async function detectTypesOutputDirectory() {
|
|
524
|
+
const candidates = ["src", "lib"];
|
|
525
|
+
for (const candidate of candidates) {
|
|
526
|
+
try {
|
|
527
|
+
await access(candidate);
|
|
528
|
+
return join(candidate, "zapier", "apps");
|
|
529
|
+
} catch {
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return "./zapier/apps/";
|
|
533
|
+
}
|
|
534
|
+
var addPlugin = ({ sdk }) => {
|
|
535
|
+
const add = createFunction(async function add2(options) {
|
|
536
|
+
const {
|
|
537
|
+
appKeys,
|
|
538
|
+
authenticationIds,
|
|
539
|
+
configPath,
|
|
540
|
+
typesOutput = await detectTypesOutputDirectory()
|
|
541
|
+
} = options;
|
|
542
|
+
const resolvedTypesOutput = resolve(typesOutput);
|
|
543
|
+
console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
|
|
544
|
+
const appSlugAndKeyMap = /* @__PURE__ */ new Map();
|
|
545
|
+
const handleManifestProgress = (event) => {
|
|
546
|
+
switch (event.type) {
|
|
547
|
+
case "apps_lookup_start":
|
|
548
|
+
console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
|
|
549
|
+
break;
|
|
550
|
+
case "app_found":
|
|
551
|
+
const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
|
|
552
|
+
appSlugAndKeyMap.set(event.app.key, displayName);
|
|
553
|
+
break;
|
|
554
|
+
case "apps_lookup_complete":
|
|
555
|
+
if (event.count === 0) {
|
|
556
|
+
console.warn("\u26A0\uFE0F No apps found");
|
|
557
|
+
}
|
|
558
|
+
break;
|
|
559
|
+
case "app_processing_start":
|
|
560
|
+
const appName = event.slug ? `${event.slug} (${event.appKey})` : event.appKey;
|
|
561
|
+
console.log(`\u{1F4E6} Adding ${appName}...`);
|
|
562
|
+
break;
|
|
563
|
+
case "manifest_updated":
|
|
564
|
+
const appDisplay = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
565
|
+
console.log(
|
|
566
|
+
`\u{1F4DD} Locked ${appDisplay} to ${event.appKey}@${event.version} using key '${event.manifestKey}'`
|
|
567
|
+
);
|
|
568
|
+
break;
|
|
569
|
+
case "app_processing_error":
|
|
570
|
+
const errorApp = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
571
|
+
console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
const handleTypesProgress = (event) => {
|
|
576
|
+
switch (event.type) {
|
|
577
|
+
case "authentications_lookup_start":
|
|
578
|
+
console.log(`\u{1F510} Looking up ${event.count} authentication(s)...`);
|
|
579
|
+
break;
|
|
580
|
+
case "authentications_lookup_complete":
|
|
581
|
+
console.log(`\u{1F510} Found ${event.count} authentication(s)`);
|
|
582
|
+
break;
|
|
583
|
+
case "authentication_matched":
|
|
584
|
+
const appWithAuth = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
585
|
+
console.log(
|
|
586
|
+
`\u{1F510} Using authentication ${event.authenticationId} (${event.authenticationTitle}) for ${appWithAuth}`
|
|
587
|
+
);
|
|
588
|
+
break;
|
|
589
|
+
case "authentication_not_matched":
|
|
590
|
+
const appWithoutAuth = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
591
|
+
console.warn(
|
|
592
|
+
`\u26A0\uFE0F No matching authentication found for ${appWithoutAuth}`
|
|
593
|
+
);
|
|
594
|
+
break;
|
|
595
|
+
case "file_written":
|
|
596
|
+
console.log(
|
|
597
|
+
`\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
|
|
598
|
+
);
|
|
599
|
+
break;
|
|
600
|
+
case "app_processing_error":
|
|
601
|
+
const errorApp = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
602
|
+
console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
const manifestResult = await sdk.buildManifest({
|
|
607
|
+
appKeys,
|
|
608
|
+
skipWrite: false,
|
|
609
|
+
configPath,
|
|
610
|
+
onProgress: handleManifestProgress
|
|
611
|
+
});
|
|
612
|
+
const typesResult = await sdk.generateAppTypes({
|
|
613
|
+
appKeys,
|
|
614
|
+
authenticationIds,
|
|
615
|
+
skipWrite: false,
|
|
616
|
+
typesOutputDirectory: resolvedTypesOutput,
|
|
617
|
+
onProgress: handleTypesProgress
|
|
618
|
+
});
|
|
619
|
+
const results = manifestResult.manifest?.apps || {};
|
|
620
|
+
const successfulApps = Object.keys(results).filter(
|
|
621
|
+
(manifestKey) => typesResult.writtenFiles?.[manifestKey]
|
|
622
|
+
);
|
|
623
|
+
if (successfulApps.length > 0) {
|
|
624
|
+
console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
|
|
625
|
+
}
|
|
626
|
+
const allErrors = [...manifestResult.errors, ...typesResult.errors];
|
|
627
|
+
if (allErrors.length > 0) {
|
|
628
|
+
console.warn(`
|
|
629
|
+
\u26A0\uFE0F ${allErrors.length} error(s) occurred:`);
|
|
630
|
+
allErrors.forEach(({ appKey, error }) => {
|
|
631
|
+
console.warn(` - ${appKey}: ${error}`);
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}, AddSchema);
|
|
635
|
+
return {
|
|
636
|
+
add,
|
|
637
|
+
context: {
|
|
638
|
+
meta: {
|
|
639
|
+
add: {
|
|
640
|
+
categories: ["utility"],
|
|
641
|
+
inputSchema: AddSchema
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
};
|
|
647
|
+
var GenerateAppTypesSchema = z.object({
|
|
648
|
+
appKeys: z.array(z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
|
|
649
|
+
"One or more app keys to generate types for (e.g., 'slack', 'github', 'trello')"
|
|
650
|
+
),
|
|
651
|
+
authenticationIds: z.array(z.string()).optional().describe(
|
|
652
|
+
"Authentication IDs to use for type generation (e.g., ['123', '456'])"
|
|
653
|
+
),
|
|
654
|
+
skipWrite: z.boolean().optional().describe(
|
|
655
|
+
"If true, returns type definitions without writing to disk. If false or omitted, writes type files."
|
|
656
|
+
),
|
|
657
|
+
typesOutputDirectory: z.string().optional().describe(
|
|
658
|
+
"Directory for TypeScript type files. Required when skipWrite is false or omitted."
|
|
659
|
+
)
|
|
660
|
+
}).describe(
|
|
661
|
+
"Generate TypeScript type definitions for apps - can optionally write to disk or just return type strings"
|
|
662
|
+
);
|
|
523
663
|
var AstTypeGenerator = class {
|
|
524
664
|
constructor() {
|
|
525
665
|
this.factory = ts.factory;
|
|
@@ -1088,69 +1228,92 @@ Usage:
|
|
|
1088
1228
|
return Array.from(allKeys);
|
|
1089
1229
|
}
|
|
1090
1230
|
};
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1231
|
+
|
|
1232
|
+
// src/utils/manifest-helpers.ts
|
|
1233
|
+
function getManifestKey(app) {
|
|
1234
|
+
return app.slug || app.key;
|
|
1235
|
+
}
|
|
1236
|
+
function createManifestEntry(app) {
|
|
1237
|
+
if (!app.version) {
|
|
1238
|
+
throw new Error(
|
|
1239
|
+
`App ${app.key} does not have a version. Implementation ID: ${app.implementation_id}`
|
|
1240
|
+
);
|
|
1099
1241
|
}
|
|
1100
|
-
return
|
|
1242
|
+
return {
|
|
1243
|
+
implementationName: app.key,
|
|
1244
|
+
version: app.version
|
|
1245
|
+
};
|
|
1101
1246
|
}
|
|
1102
|
-
var
|
|
1103
|
-
const
|
|
1247
|
+
var generateAppTypesPlugin = ({ sdk }) => {
|
|
1248
|
+
const generateAppTypes = createFunction(async function generateAppTypes2(options) {
|
|
1104
1249
|
const {
|
|
1105
1250
|
appKeys,
|
|
1106
1251
|
authenticationIds,
|
|
1107
|
-
|
|
1108
|
-
|
|
1252
|
+
skipWrite = false,
|
|
1253
|
+
typesOutputDirectory,
|
|
1254
|
+
onProgress
|
|
1109
1255
|
} = options;
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1256
|
+
if (!skipWrite && !typesOutputDirectory) {
|
|
1257
|
+
throw new Error(
|
|
1258
|
+
"typesOutputDirectory is required when skipWrite is false"
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
const result = {
|
|
1262
|
+
typeDefinitions: {},
|
|
1263
|
+
errors: []
|
|
1264
|
+
};
|
|
1265
|
+
onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
|
|
1113
1266
|
const appsIterator = sdk.listApps({ appKeys }).items();
|
|
1114
1267
|
const apps = [];
|
|
1115
1268
|
for await (const app of appsIterator) {
|
|
1116
1269
|
apps.push(app);
|
|
1270
|
+
onProgress?.({ type: "app_found", app });
|
|
1117
1271
|
}
|
|
1272
|
+
onProgress?.({ type: "apps_lookup_complete", count: apps.length });
|
|
1118
1273
|
if (apps.length === 0) {
|
|
1119
|
-
|
|
1120
|
-
return;
|
|
1274
|
+
return result;
|
|
1121
1275
|
}
|
|
1122
|
-
|
|
1276
|
+
const authentications = [];
|
|
1123
1277
|
if (authenticationIds && authenticationIds.length > 0) {
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1278
|
+
onProgress?.({
|
|
1279
|
+
type: "authentications_lookup_start",
|
|
1280
|
+
count: authenticationIds.length
|
|
1281
|
+
});
|
|
1127
1282
|
const authsIterator = sdk.listAuthentications({ authenticationIds }).items();
|
|
1128
1283
|
for await (const auth of authsIterator) {
|
|
1129
1284
|
authentications.push(auth);
|
|
1130
1285
|
}
|
|
1131
|
-
|
|
1286
|
+
onProgress?.({
|
|
1287
|
+
type: "authentications_lookup_complete",
|
|
1288
|
+
count: authentications.length
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
if (!skipWrite && typesOutputDirectory) {
|
|
1292
|
+
await mkdir(typesOutputDirectory, { recursive: true });
|
|
1293
|
+
}
|
|
1294
|
+
if (!skipWrite) {
|
|
1295
|
+
result.writtenFiles = {};
|
|
1132
1296
|
}
|
|
1133
1297
|
for (const app of apps) {
|
|
1134
|
-
|
|
1135
|
-
|
|
1298
|
+
onProgress?.({
|
|
1299
|
+
type: "app_processing_start",
|
|
1300
|
+
appKey: app.key,
|
|
1301
|
+
slug: app.slug
|
|
1302
|
+
});
|
|
1136
1303
|
try {
|
|
1137
1304
|
if (!app.version) {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1305
|
+
const error = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
|
|
1306
|
+
result.errors.push({
|
|
1307
|
+
appKey: app.key,
|
|
1308
|
+
error
|
|
1309
|
+
});
|
|
1310
|
+
onProgress?.({
|
|
1311
|
+
type: "app_processing_error",
|
|
1312
|
+
appKey: app.key,
|
|
1313
|
+
error
|
|
1314
|
+
});
|
|
1141
1315
|
continue;
|
|
1142
1316
|
}
|
|
1143
|
-
const [manifestKey] = await context.updateManifestEntry(
|
|
1144
|
-
app.key,
|
|
1145
|
-
{
|
|
1146
|
-
implementationName: app.key,
|
|
1147
|
-
version: app.version
|
|
1148
|
-
},
|
|
1149
|
-
configPath
|
|
1150
|
-
);
|
|
1151
|
-
console.log(
|
|
1152
|
-
`\u{1F4DD} Locked ${appSlugAndKey} to ${app.key}@${app.version} using key '${manifestKey}'`
|
|
1153
|
-
);
|
|
1154
1317
|
let authenticationId;
|
|
1155
1318
|
if (authentications.length > 0) {
|
|
1156
1319
|
const matchingAuth = authentications.find((auth) => {
|
|
@@ -1158,43 +1321,171 @@ var addPlugin = ({ sdk, context }) => {
|
|
|
1158
1321
|
});
|
|
1159
1322
|
if (matchingAuth) {
|
|
1160
1323
|
authenticationId = matchingAuth.id;
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1324
|
+
onProgress?.({
|
|
1325
|
+
type: "authentication_matched",
|
|
1326
|
+
appKey: app.key,
|
|
1327
|
+
authenticationId: matchingAuth.id,
|
|
1328
|
+
authenticationTitle: matchingAuth.title || ""
|
|
1329
|
+
});
|
|
1164
1330
|
} else {
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1331
|
+
onProgress?.({
|
|
1332
|
+
type: "authentication_not_matched",
|
|
1333
|
+
appKey: app.key
|
|
1334
|
+
});
|
|
1168
1335
|
}
|
|
1169
1336
|
}
|
|
1170
|
-
const
|
|
1337
|
+
const manifestKey = getManifestKey(app);
|
|
1171
1338
|
try {
|
|
1172
1339
|
const generator = new AstTypeGenerator();
|
|
1173
|
-
const
|
|
1340
|
+
const typeDefinitionString = await generator.generateTypes({
|
|
1174
1341
|
app,
|
|
1175
1342
|
authenticationId,
|
|
1176
1343
|
sdk
|
|
1177
1344
|
});
|
|
1178
|
-
|
|
1179
|
-
|
|
1345
|
+
result.typeDefinitions[manifestKey] = typeDefinitionString;
|
|
1346
|
+
onProgress?.({
|
|
1347
|
+
type: "type_generated",
|
|
1348
|
+
manifestKey,
|
|
1349
|
+
sizeBytes: typeDefinitionString.length
|
|
1350
|
+
});
|
|
1351
|
+
if (!skipWrite && typesOutputDirectory && result.writtenFiles) {
|
|
1352
|
+
const filePath = join(typesOutputDirectory, `${manifestKey}.d.ts`);
|
|
1353
|
+
await writeFile(filePath, typeDefinitionString, "utf8");
|
|
1354
|
+
result.writtenFiles[manifestKey] = filePath;
|
|
1355
|
+
onProgress?.({
|
|
1356
|
+
type: "file_written",
|
|
1357
|
+
manifestKey,
|
|
1358
|
+
filePath
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
onProgress?.({
|
|
1362
|
+
type: "app_processing_complete",
|
|
1363
|
+
appKey: app.key
|
|
1364
|
+
});
|
|
1180
1365
|
} catch (error) {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1366
|
+
const errorMessage = `Failed to generate types: ${error}`;
|
|
1367
|
+
result.errors.push({
|
|
1368
|
+
appKey: app.key,
|
|
1369
|
+
error: errorMessage
|
|
1370
|
+
});
|
|
1371
|
+
onProgress?.({
|
|
1372
|
+
type: "app_processing_error",
|
|
1373
|
+
appKey: app.key,
|
|
1374
|
+
error: errorMessage
|
|
1375
|
+
});
|
|
1184
1376
|
}
|
|
1185
1377
|
} catch (error) {
|
|
1186
|
-
|
|
1378
|
+
const errorMessage = `Failed to process app: ${error}`;
|
|
1379
|
+
result.errors.push({
|
|
1380
|
+
appKey: app.key,
|
|
1381
|
+
error: errorMessage
|
|
1382
|
+
});
|
|
1383
|
+
onProgress?.({
|
|
1384
|
+
type: "app_processing_error",
|
|
1385
|
+
appKey: app.key,
|
|
1386
|
+
error: errorMessage
|
|
1387
|
+
});
|
|
1187
1388
|
}
|
|
1188
1389
|
}
|
|
1189
|
-
|
|
1190
|
-
},
|
|
1390
|
+
return result;
|
|
1391
|
+
}, GenerateAppTypesSchema);
|
|
1191
1392
|
return {
|
|
1192
|
-
|
|
1393
|
+
generateAppTypes,
|
|
1193
1394
|
context: {
|
|
1194
1395
|
meta: {
|
|
1195
|
-
|
|
1396
|
+
generateAppTypes: {
|
|
1196
1397
|
categories: ["utility"],
|
|
1197
|
-
inputSchema:
|
|
1398
|
+
inputSchema: GenerateAppTypesSchema
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
};
|
|
1404
|
+
var BuildManifestSchema = z.object({
|
|
1405
|
+
appKeys: z.array(z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
|
|
1406
|
+
"One or more app keys to build manifest entries for (e.g., 'slack', 'github', 'trello')"
|
|
1407
|
+
),
|
|
1408
|
+
skipWrite: z.boolean().optional().describe(
|
|
1409
|
+
"If true, returns manifest entries without writing to disk. If false or omitted, writes to the manifest file."
|
|
1410
|
+
),
|
|
1411
|
+
configPath: z.string().optional().describe(
|
|
1412
|
+
"Path to the manifest file. Only used when skipWrite is false or omitted."
|
|
1413
|
+
)
|
|
1414
|
+
}).describe(
|
|
1415
|
+
"Build manifest entries for apps - can optionally write to disk or just return JSON"
|
|
1416
|
+
);
|
|
1417
|
+
|
|
1418
|
+
// src/plugins/buildManifest/index.ts
|
|
1419
|
+
var buildManifestPlugin = ({ sdk, context }) => {
|
|
1420
|
+
const buildManifest = createFunction(async function buildManifest2(options) {
|
|
1421
|
+
const { appKeys, skipWrite = false, configPath, onProgress } = options;
|
|
1422
|
+
const result = {
|
|
1423
|
+
errors: []
|
|
1424
|
+
};
|
|
1425
|
+
onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
|
|
1426
|
+
const appsIterator = sdk.listApps({ appKeys }).items();
|
|
1427
|
+
const apps = [];
|
|
1428
|
+
for await (const app of appsIterator) {
|
|
1429
|
+
apps.push(app);
|
|
1430
|
+
onProgress?.({ type: "app_found", app });
|
|
1431
|
+
}
|
|
1432
|
+
onProgress?.({ type: "apps_lookup_complete", count: apps.length });
|
|
1433
|
+
if (apps.length === 0) {
|
|
1434
|
+
return result;
|
|
1435
|
+
}
|
|
1436
|
+
let updatedManifest;
|
|
1437
|
+
for (const app of apps) {
|
|
1438
|
+
onProgress?.({
|
|
1439
|
+
type: "app_processing_start",
|
|
1440
|
+
appKey: app.key,
|
|
1441
|
+
slug: app.slug
|
|
1442
|
+
});
|
|
1443
|
+
try {
|
|
1444
|
+
const manifestEntry = createManifestEntry(app);
|
|
1445
|
+
onProgress?.({
|
|
1446
|
+
type: "manifest_entry_built",
|
|
1447
|
+
appKey: app.key,
|
|
1448
|
+
manifestKey: manifestEntry.implementationName,
|
|
1449
|
+
version: manifestEntry.version
|
|
1450
|
+
});
|
|
1451
|
+
const [updatedManifestKey, , manifest] = await context.updateManifestEntry({
|
|
1452
|
+
appKey: app.key,
|
|
1453
|
+
entry: manifestEntry,
|
|
1454
|
+
configPath,
|
|
1455
|
+
skipWrite,
|
|
1456
|
+
manifest: updatedManifest
|
|
1457
|
+
});
|
|
1458
|
+
updatedManifest = manifest;
|
|
1459
|
+
onProgress?.({
|
|
1460
|
+
type: "manifest_updated",
|
|
1461
|
+
appKey: app.key,
|
|
1462
|
+
manifestKey: updatedManifestKey,
|
|
1463
|
+
version: manifestEntry.version
|
|
1464
|
+
});
|
|
1465
|
+
onProgress?.({ type: "app_processing_complete", appKey: app.key });
|
|
1466
|
+
} catch (error) {
|
|
1467
|
+
const errorMessage = `Failed to process app: ${error}`;
|
|
1468
|
+
result.errors.push({
|
|
1469
|
+
appKey: app.key,
|
|
1470
|
+
error: errorMessage
|
|
1471
|
+
});
|
|
1472
|
+
onProgress?.({
|
|
1473
|
+
type: "app_processing_error",
|
|
1474
|
+
appKey: app.key,
|
|
1475
|
+
error: errorMessage
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
result.manifest = updatedManifest;
|
|
1480
|
+
return result;
|
|
1481
|
+
}, BuildManifestSchema);
|
|
1482
|
+
return {
|
|
1483
|
+
buildManifest,
|
|
1484
|
+
context: {
|
|
1485
|
+
meta: {
|
|
1486
|
+
buildManifest: {
|
|
1487
|
+
categories: ["utility"],
|
|
1488
|
+
inputSchema: BuildManifestSchema
|
|
1198
1489
|
}
|
|
1199
1490
|
}
|
|
1200
1491
|
}
|
|
@@ -1203,18 +1494,10 @@ var addPlugin = ({ sdk, context }) => {
|
|
|
1203
1494
|
|
|
1204
1495
|
// src/sdk.ts
|
|
1205
1496
|
function createZapierCliSdk(options = {}) {
|
|
1206
|
-
|
|
1497
|
+
return createZapierSdkWithoutRegistry({
|
|
1207
1498
|
debug: options.debug,
|
|
1208
1499
|
eventEmission: options.eventEmission
|
|
1209
|
-
});
|
|
1210
|
-
sdk = sdk.addPlugin(bundleCodePlugin);
|
|
1211
|
-
sdk = sdk.addPlugin(getLoginConfigPathPlugin);
|
|
1212
|
-
sdk = sdk.addPlugin(addPlugin);
|
|
1213
|
-
sdk = sdk.addPlugin(mcpPlugin);
|
|
1214
|
-
sdk = sdk.addPlugin(loginPlugin);
|
|
1215
|
-
sdk = sdk.addPlugin(logoutPlugin);
|
|
1216
|
-
const finalSdk = sdk.addPlugin(registryPlugin);
|
|
1217
|
-
return finalSdk;
|
|
1500
|
+
}).addPlugin(generateAppTypesPlugin).addPlugin(buildManifestPlugin).addPlugin(bundleCodePlugin).addPlugin(getLoginConfigPathPlugin).addPlugin(addPlugin).addPlugin(mcpPlugin).addPlugin(loginPlugin).addPlugin(logoutPlugin).addPlugin(registryPlugin);
|
|
1218
1501
|
}
|
|
1219
1502
|
|
|
1220
1503
|
export { buildCliCommandExecutedEvent, createZapierCliSdk };
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk-cli",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.6",
|
|
4
4
|
"description": "Command line interface for Zapier SDK",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"open": "^10.2.0",
|
|
54
54
|
"ora": "^8.2.0",
|
|
55
55
|
"pkce-challenge": "^5.0.0",
|
|
56
|
+
"typescript": "^5.8.3",
|
|
56
57
|
"zod": "^3.25.67"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
@@ -61,7 +62,6 @@
|
|
|
61
62
|
"@types/jsonwebtoken": "^9.0.10",
|
|
62
63
|
"@types/node": "^24.0.1",
|
|
63
64
|
"tsup": "^8.5.0",
|
|
64
|
-
"typescript": "^5.8.3",
|
|
65
65
|
"vitest": "^3.2.3"
|
|
66
66
|
}
|
|
67
67
|
}
|