@zapier/zapier-sdk 0.6.2 → 0.6.4
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 +12 -0
- package/README.md +18 -18
- package/dist/index.cjs +1666 -1638
- package/dist/index.d.mts +241 -2
- package/dist/index.d.ts +18 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/index.mjs +1649 -1640
- package/dist/plugins/getProfile/index.js +1 -1
- package/dist/plugins/manifest/index.d.ts +0 -1
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +11 -5
- package/dist/plugins/manifest/index.test.js +46 -16
- package/dist/plugins/registry/index.js +3 -3
- package/dist/sdk.d.ts +87 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +5 -2
- package/package.json +1 -1
- package/src/index.ts +25 -1
- package/src/plugins/getProfile/index.ts +1 -1
- package/src/plugins/manifest/index.test.ts +49 -17
- package/src/plugins/manifest/index.ts +14 -6
- package/src/plugins/registry/index.ts +3 -3
- package/src/sdk.ts +6 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -7,7 +7,6 @@ import { ListAppsPluginProvides } from "../listApps";
|
|
|
7
7
|
export type ManifestPluginOptions = z.infer<typeof ManifestPluginOptionsSchema>;
|
|
8
8
|
export interface ManifestPluginProvides {
|
|
9
9
|
context: {
|
|
10
|
-
manifest: Manifest | null;
|
|
11
10
|
getVersionedImplementationId: GetVersionedImplementationId;
|
|
12
11
|
getManifestEntry: GetManifestEntry;
|
|
13
12
|
getImplementation: GetImplementation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/manifest/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,4BAA4B,EAC5B,QAAQ,EACT,MAAM,WAAW,CAAC;AACnB,OAAO,EAAkB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AAC,sBAAsB,CAAC,EAClC;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,EAClB,sBAAsB,CA6FvB,CAAC"}
|
|
@@ -47,7 +47,8 @@ export const manifestPlugin = (params) => {
|
|
|
47
47
|
const { sdk, context } = params;
|
|
48
48
|
const { api, options } = context;
|
|
49
49
|
const { manifestPath = ".zapierrc", manifest } = options || {};
|
|
50
|
-
|
|
50
|
+
let resolvedManifest;
|
|
51
|
+
function resolveManifest() {
|
|
51
52
|
// If manifest is provided directly, use it
|
|
52
53
|
if (manifest) {
|
|
53
54
|
return manifest;
|
|
@@ -57,13 +58,19 @@ export const manifestPlugin = (params) => {
|
|
|
57
58
|
return loadManifestFromFile(manifestPath);
|
|
58
59
|
}
|
|
59
60
|
return null;
|
|
60
|
-
}
|
|
61
|
+
}
|
|
62
|
+
const getResolvedManifest = () => {
|
|
63
|
+
if (typeof resolvedManifest === "undefined") {
|
|
64
|
+
resolvedManifest = resolveManifest() ?? null;
|
|
65
|
+
}
|
|
66
|
+
return resolvedManifest;
|
|
67
|
+
};
|
|
61
68
|
const getManifestEntry = (appKey) => {
|
|
62
|
-
return
|
|
69
|
+
return getResolvedManifest()?.apps?.[appKey] || null;
|
|
63
70
|
};
|
|
64
71
|
const getImplementation = async (appKey) => {
|
|
65
72
|
let selectedApi = null;
|
|
66
|
-
const manifestImplementation =
|
|
73
|
+
const manifestImplementation = getResolvedManifest()?.apps?.[appKey];
|
|
67
74
|
const [versionlessAppKey, version] = splitVersionedKey(appKey);
|
|
68
75
|
// Use versioned app key if provided
|
|
69
76
|
if (version) {
|
|
@@ -110,7 +117,6 @@ export const manifestPlugin = (params) => {
|
|
|
110
117
|
};
|
|
111
118
|
return {
|
|
112
119
|
context: {
|
|
113
|
-
manifest: resolvedManifest,
|
|
114
120
|
getVersionedImplementationId,
|
|
115
121
|
getManifestEntry,
|
|
116
122
|
getImplementation,
|
|
@@ -123,25 +123,35 @@ describe("manifestPlugin", () => {
|
|
|
123
123
|
.addPlugin(manifestPlugin);
|
|
124
124
|
}
|
|
125
125
|
describe("plugin initialization", () => {
|
|
126
|
-
it("should provide
|
|
126
|
+
it("should provide helper functions with direct manifest", () => {
|
|
127
127
|
const sdk = createTestSdk({ manifest: mockManifest });
|
|
128
128
|
const context = sdk.getContext();
|
|
129
|
-
expect(context.manifest).toEqual(mockManifest);
|
|
130
129
|
expect(context.getVersionedImplementationId).toBeInstanceOf(Function);
|
|
131
130
|
expect(context.getImplementation).toBeInstanceOf(Function);
|
|
131
|
+
expect(context.getManifestEntry).toBeInstanceOf(Function);
|
|
132
132
|
});
|
|
133
|
-
it("should provide
|
|
133
|
+
it("should provide helper functions with manifestPath", () => {
|
|
134
134
|
mockReadFileSync.mockReturnValue(mockManifestContent);
|
|
135
135
|
const sdk = createTestSdk({ manifestPath: "manifest.json" });
|
|
136
136
|
const context = sdk.getContext();
|
|
137
|
+
expect(context.getVersionedImplementationId).toBeInstanceOf(Function);
|
|
138
|
+
expect(context.getImplementation).toBeInstanceOf(Function);
|
|
139
|
+
expect(context.getManifestEntry).toBeInstanceOf(Function);
|
|
140
|
+
// Verify file operations happen when functions are called
|
|
141
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
137
142
|
expect(mockResolve).toHaveBeenCalledWith("manifest.json");
|
|
138
143
|
expect(mockReadFileSync).toHaveBeenCalledWith("/resolved/manifest.json", "utf8");
|
|
139
|
-
expect(
|
|
144
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
140
145
|
});
|
|
141
|
-
it("should provide
|
|
146
|
+
it("should provide helper functions when no manifest or path provided", () => {
|
|
142
147
|
const sdk = createTestSdk();
|
|
143
148
|
const context = sdk.getContext();
|
|
144
|
-
expect(context.
|
|
149
|
+
expect(context.getVersionedImplementationId).toBeInstanceOf(Function);
|
|
150
|
+
expect(context.getImplementation).toBeInstanceOf(Function);
|
|
151
|
+
expect(context.getManifestEntry).toBeInstanceOf(Function);
|
|
152
|
+
// Verify that no manifest entry is found
|
|
153
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
154
|
+
expect(manifestEntry).toBeNull();
|
|
145
155
|
});
|
|
146
156
|
it("should prioritize direct manifest over manifestPath", () => {
|
|
147
157
|
mockReadFileSync.mockReturnValue('{"apps": {"other": {"implementationName": "Other", "version": "1.0.0"}}}');
|
|
@@ -150,7 +160,9 @@ describe("manifestPlugin", () => {
|
|
|
150
160
|
manifestPath: "manifest.json",
|
|
151
161
|
});
|
|
152
162
|
const context = sdk.getContext();
|
|
153
|
-
|
|
163
|
+
// Verify that direct manifest is used (should find slack app)
|
|
164
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
165
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
154
166
|
expect(mockReadFileSync).not.toHaveBeenCalled();
|
|
155
167
|
});
|
|
156
168
|
});
|
|
@@ -211,7 +223,9 @@ describe("manifestPlugin", () => {
|
|
|
211
223
|
it("should parse valid manifest content", () => {
|
|
212
224
|
const sdk = createTestSdk({ manifest: mockManifest });
|
|
213
225
|
const context = sdk.getContext();
|
|
214
|
-
|
|
226
|
+
// Verify manifest content is accessible through helper functions
|
|
227
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
228
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
215
229
|
});
|
|
216
230
|
it("should handle manifest with missing version", () => {
|
|
217
231
|
const manifestWithoutVersion = {
|
|
@@ -223,12 +237,16 @@ describe("manifestPlugin", () => {
|
|
|
223
237
|
};
|
|
224
238
|
const sdk = createTestSdk({ manifest: manifestWithoutVersion });
|
|
225
239
|
const context = sdk.getContext();
|
|
226
|
-
|
|
240
|
+
// Verify manifest entry is accessible and matches expected structure
|
|
241
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
242
|
+
expect(manifestEntry).toEqual(manifestWithoutVersion.apps.slack);
|
|
227
243
|
});
|
|
228
244
|
it("should handle empty manifest", () => {
|
|
229
245
|
const sdk = createTestSdk({ manifest: {} });
|
|
230
246
|
const context = sdk.getContext();
|
|
231
|
-
|
|
247
|
+
// Verify that no manifest entry is found for any app
|
|
248
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
249
|
+
expect(manifestEntry).toBeNull();
|
|
232
250
|
});
|
|
233
251
|
});
|
|
234
252
|
describe("file loading", () => {
|
|
@@ -236,9 +254,11 @@ describe("manifestPlugin", () => {
|
|
|
236
254
|
mockReadFileSync.mockReturnValue(mockManifestContent);
|
|
237
255
|
const sdk = createTestSdk({ manifestPath: "manifest.json" });
|
|
238
256
|
const context = sdk.getContext();
|
|
257
|
+
// Verify that file operations happen when functions are called
|
|
258
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
239
259
|
expect(mockResolve).toHaveBeenCalledWith("manifest.json");
|
|
240
260
|
expect(mockReadFileSync).toHaveBeenCalledWith("/resolved/manifest.json", "utf8");
|
|
241
|
-
expect(
|
|
261
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
242
262
|
});
|
|
243
263
|
it("should handle file read errors gracefully", () => {
|
|
244
264
|
mockReadFileSync.mockImplementation(() => {
|
|
@@ -246,27 +266,35 @@ describe("manifestPlugin", () => {
|
|
|
246
266
|
});
|
|
247
267
|
const sdk = createTestSdk({ manifestPath: "nonexistent.json" });
|
|
248
268
|
const context = sdk.getContext();
|
|
249
|
-
|
|
269
|
+
// Verify that no manifest entry is found when file loading fails
|
|
270
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
271
|
+
expect(manifestEntry).toBeNull();
|
|
250
272
|
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("Failed to load manifest from nonexistent.json"));
|
|
251
273
|
});
|
|
252
274
|
it("should handle invalid JSON gracefully", () => {
|
|
253
275
|
mockReadFileSync.mockReturnValue("invalid json content");
|
|
254
276
|
const sdk = createTestSdk({ manifestPath: "invalid.json" });
|
|
255
277
|
const context = sdk.getContext();
|
|
256
|
-
|
|
278
|
+
// Verify that no manifest entry is found when JSON parsing fails
|
|
279
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
280
|
+
expect(manifestEntry).toBeNull();
|
|
257
281
|
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("Failed to parse manifest from /resolved/invalid.json"), expect.any(SyntaxError));
|
|
258
282
|
});
|
|
259
283
|
it("should handle JSON without apps property", () => {
|
|
260
284
|
mockReadFileSync.mockReturnValue('{"other": "data"}');
|
|
261
285
|
const sdk = createTestSdk({ manifestPath: "no-apps.json" });
|
|
262
286
|
const context = sdk.getContext();
|
|
263
|
-
|
|
287
|
+
// Verify that no manifest entry is found when apps property is missing
|
|
288
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
289
|
+
expect(manifestEntry).toBeNull();
|
|
264
290
|
});
|
|
265
291
|
it("should handle JSON with invalid apps format", () => {
|
|
266
292
|
mockReadFileSync.mockReturnValue('{"apps": "not an object"}');
|
|
267
293
|
const sdk = createTestSdk({ manifestPath: "invalid-apps.json" });
|
|
268
294
|
const context = sdk.getContext();
|
|
269
|
-
|
|
295
|
+
// Verify that no manifest entry is found when apps format is invalid
|
|
296
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
297
|
+
expect(manifestEntry).toBeNull();
|
|
270
298
|
});
|
|
271
299
|
});
|
|
272
300
|
describe("integration with SDK", () => {
|
|
@@ -276,7 +304,9 @@ describe("manifestPlugin", () => {
|
|
|
276
304
|
.addPlugin(listAppsMockPlugin)
|
|
277
305
|
.addPlugin(manifestPlugin);
|
|
278
306
|
const context = sdk.getContext();
|
|
279
|
-
|
|
307
|
+
// Verify that the manifest data is used correctly
|
|
308
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
309
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
280
310
|
const versionedId = await context.getVersionedImplementationId("slack");
|
|
281
311
|
expect(versionedId).toBe("SlackCLIAPI@1.21.1");
|
|
282
312
|
});
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
export const registryPlugin = ({ sdk, context }) => {
|
|
3
3
|
const metaKeys = Object.keys(context.meta || {});
|
|
4
4
|
const categoryDefinitions = {
|
|
5
|
+
account: {
|
|
6
|
+
title: "Account",
|
|
7
|
+
},
|
|
5
8
|
app: {
|
|
6
9
|
title: "App",
|
|
7
10
|
titlePlural: "Apps",
|
|
@@ -15,9 +18,6 @@ export const registryPlugin = ({ sdk, context }) => {
|
|
|
15
18
|
http: {
|
|
16
19
|
title: "HTTP Request",
|
|
17
20
|
},
|
|
18
|
-
user: {
|
|
19
|
-
title: "User",
|
|
20
|
-
},
|
|
21
21
|
utility: {
|
|
22
22
|
title: "Utility",
|
|
23
23
|
titlePlural: "Utilities",
|
package/dist/sdk.d.ts
CHANGED
|
@@ -6,5 +6,92 @@ export interface ZapierSdkOptions extends BaseSdkOptions {
|
|
|
6
6
|
export declare function createSdk<TCurrentSdk = {}, TCurrentContext = {
|
|
7
7
|
meta: Record<string, PluginMeta>;
|
|
8
8
|
}>(options?: ZapierSdkOptions, initialSdk?: TCurrentSdk, initialContext?: TCurrentContext): Sdk<TCurrentSdk, TCurrentContext>;
|
|
9
|
+
export declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk<import("./types/plugin").ExtractSdkProperties<import(".").ApiPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").ListAppsPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").ManifestPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").GetAppPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").ListActionsPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").GetActionPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").ListInputFieldsPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").RunActionPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").LockVersionPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").ListAuthenticationsPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").GetAuthenticationPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").FindFirstAuthenticationPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").FindUniqueAuthenticationPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").RequestPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").FetchPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").AppsPluginProvides> & import("./types/plugin").ExtractSdkProperties<import(".").GetProfilePluginProvides>, {
|
|
10
|
+
meta: Record<string, PluginMeta>;
|
|
11
|
+
} & {
|
|
12
|
+
api: import("./api").ApiClient;
|
|
13
|
+
} & {
|
|
14
|
+
meta: {
|
|
15
|
+
listApps: {
|
|
16
|
+
inputSchema: typeof import("./plugins/listApps/schemas").ListAppsSchema;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
} & {
|
|
20
|
+
getVersionedImplementationId: import("./plugins/manifest/schemas").GetVersionedImplementationId;
|
|
21
|
+
getManifestEntry: import("./plugins/manifest/schemas").GetManifestEntry;
|
|
22
|
+
getImplementation: import("./plugins/manifest/schemas").GetImplementation;
|
|
23
|
+
} & {
|
|
24
|
+
meta: {
|
|
25
|
+
getApp: {
|
|
26
|
+
inputSchema: typeof import("./plugins/getApp/schemas").GetAppSchema;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
} & {
|
|
30
|
+
meta: {
|
|
31
|
+
listActions: {
|
|
32
|
+
inputSchema: typeof import("./plugins/listActions/schemas").ListActionsSchema;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
} & {
|
|
36
|
+
meta: {
|
|
37
|
+
getAction: {
|
|
38
|
+
inputSchema: typeof import("./plugins/getAction/schemas").GetActionSchema;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
} & {
|
|
42
|
+
meta: {
|
|
43
|
+
listInputFields: {
|
|
44
|
+
inputSchema: typeof import("./plugins/listInputFields/schemas").ListInputFieldsSchema;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
} & {
|
|
48
|
+
meta: {
|
|
49
|
+
runAction: {
|
|
50
|
+
inputSchema: typeof import("./plugins/runAction/schemas").RunActionSchema;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
} & {
|
|
54
|
+
meta: {
|
|
55
|
+
lockVersion: {
|
|
56
|
+
inputSchema: typeof import("./plugins/lockVersion/schemas").LockVersionSchema;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
} & {
|
|
60
|
+
meta: {
|
|
61
|
+
listAuthentications: {
|
|
62
|
+
inputSchema: typeof import("./plugins/listAuthentications/schemas").ListAuthenticationsSchema;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
} & {
|
|
66
|
+
meta: {
|
|
67
|
+
getAuthentication: {
|
|
68
|
+
inputSchema: typeof import("./plugins/getAuthentication/schemas").GetAuthenticationSchema;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
} & {
|
|
72
|
+
meta: {
|
|
73
|
+
findFirstAuthentication: {
|
|
74
|
+
inputSchema: typeof import("./plugins/findFirstAuthentication/schemas").FindFirstAuthenticationSchema;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
} & {
|
|
78
|
+
meta: {
|
|
79
|
+
findUniqueAuthentication: {
|
|
80
|
+
inputSchema: typeof import("./plugins/findUniqueAuthentication/schemas").FindUniqueAuthenticationSchema;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
} & {
|
|
84
|
+
meta: {
|
|
85
|
+
request: {
|
|
86
|
+
inputSchema: typeof import(".").RelayRequestSchema;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
} & {
|
|
90
|
+
meta: {
|
|
91
|
+
getProfile: {
|
|
92
|
+
inputSchema: typeof import("./plugins/getProfile/schemas").GetProfileSchema;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
}>;
|
|
9
96
|
export declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
|
10
97
|
//# sourceMappingURL=sdk.d.ts.map
|
package/dist/sdk.d.ts.map
CHANGED
|
@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AqB;UA5EjD,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkHrD;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAMzE"}
|
package/dist/sdk.js
CHANGED
|
@@ -72,7 +72,7 @@ export function createSdk(options = {}, initialSdk = {}, initialContext = { meta
|
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
export function
|
|
75
|
+
export function createZapierSdkWithoutRegistry(options = {}) {
|
|
76
76
|
return (createSdk(options)
|
|
77
77
|
// Provides the API client in context
|
|
78
78
|
.addPlugin(apiPlugin)
|
|
@@ -99,7 +99,10 @@ export function createZapierSdk(options = {}) {
|
|
|
99
99
|
// Magic apps plugin
|
|
100
100
|
.addPlugin(appsPlugin)
|
|
101
101
|
// Profile
|
|
102
|
-
.addPlugin(getProfilePlugin)
|
|
102
|
+
.addPlugin(getProfilePlugin));
|
|
103
|
+
}
|
|
104
|
+
export function createZapierSdk(options = {}) {
|
|
105
|
+
return (createZapierSdkWithoutRegistry(options)
|
|
103
106
|
// Register plugins for CLI/MCP metadata
|
|
104
107
|
.addPlugin(registryPlugin));
|
|
105
108
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,6 +5,21 @@ export * from "./types/properties";
|
|
|
5
5
|
export * from "./types/errors";
|
|
6
6
|
export * from "./plugins/apps";
|
|
7
7
|
export * from "./plugins/fetch";
|
|
8
|
+
export * from "./plugins/listApps";
|
|
9
|
+
export * from "./plugins/listActions";
|
|
10
|
+
export * from "./plugins/listInputFields";
|
|
11
|
+
export * from "./plugins/listAuthentications";
|
|
12
|
+
export * from "./plugins/getApp";
|
|
13
|
+
export * from "./plugins/getAction";
|
|
14
|
+
export * from "./plugins/getAuthentication";
|
|
15
|
+
export * from "./plugins/findFirstAuthentication";
|
|
16
|
+
export * from "./plugins/findUniqueAuthentication";
|
|
17
|
+
export * from "./plugins/runAction";
|
|
18
|
+
export * from "./plugins/request";
|
|
19
|
+
export * from "./plugins/manifest";
|
|
20
|
+
export * from "./plugins/lockVersion";
|
|
21
|
+
export * from "./plugins/getProfile";
|
|
22
|
+
export * from "./plugins/api";
|
|
8
23
|
|
|
9
24
|
// Export API types directly (no longer re-exported from domain)
|
|
10
25
|
export type {
|
|
@@ -26,6 +41,7 @@ export type {
|
|
|
26
41
|
// Export schema utilities for CLI
|
|
27
42
|
export { isPositional } from "./utils/schema-utils";
|
|
28
43
|
export { hasResolver } from "./resolvers";
|
|
44
|
+
export { createFunction } from "./utils/function-utils";
|
|
29
45
|
|
|
30
46
|
// Export auth utilities for CLI use
|
|
31
47
|
export * from "./auth";
|
|
@@ -41,7 +57,12 @@ export {
|
|
|
41
57
|
} from "./plugins/request/schemas";
|
|
42
58
|
|
|
43
59
|
// Export the main combined SDK and new flexible SDK creator
|
|
44
|
-
export {
|
|
60
|
+
export {
|
|
61
|
+
createZapierSdk,
|
|
62
|
+
createZapierSdkWithoutRegistry,
|
|
63
|
+
createSdk,
|
|
64
|
+
ZapierSdkOptions,
|
|
65
|
+
} from "./sdk";
|
|
45
66
|
|
|
46
67
|
// Export SDK types from types (not sdk.ts to avoid circular imports)
|
|
47
68
|
export type { FunctionRegistryEntry } from "./types/sdk";
|
|
@@ -56,5 +77,8 @@ export type {
|
|
|
56
77
|
Sdk,
|
|
57
78
|
} from "./types/plugin";
|
|
58
79
|
|
|
80
|
+
// Export registry plugin for manual use
|
|
81
|
+
export { registryPlugin } from "./plugins/registry";
|
|
82
|
+
|
|
59
83
|
// Export ZapierSdk from sdk.ts (it's now ReturnType<typeof createZapierSdk>)
|
|
60
84
|
export type { ZapierSdk } from "./types/sdk";
|
|
@@ -148,35 +148,46 @@ describe("manifestPlugin", () => {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
describe("plugin initialization", () => {
|
|
151
|
-
it("should provide
|
|
151
|
+
it("should provide helper functions with direct manifest", () => {
|
|
152
152
|
const sdk = createTestSdk({ manifest: mockManifest });
|
|
153
153
|
const context = sdk.getContext();
|
|
154
154
|
|
|
155
|
-
expect(context.manifest).toEqual(mockManifest);
|
|
156
|
-
|
|
157
155
|
expect(context.getVersionedImplementationId).toBeInstanceOf(Function);
|
|
158
156
|
expect(context.getImplementation).toBeInstanceOf(Function);
|
|
157
|
+
expect(context.getManifestEntry).toBeInstanceOf(Function);
|
|
159
158
|
});
|
|
160
159
|
|
|
161
|
-
it("should provide
|
|
160
|
+
it("should provide helper functions with manifestPath", () => {
|
|
162
161
|
mockReadFileSync.mockReturnValue(mockManifestContent);
|
|
163
162
|
|
|
164
163
|
const sdk = createTestSdk({ manifestPath: "manifest.json" });
|
|
165
164
|
const context = sdk.getContext();
|
|
166
165
|
|
|
166
|
+
expect(context.getVersionedImplementationId).toBeInstanceOf(Function);
|
|
167
|
+
expect(context.getImplementation).toBeInstanceOf(Function);
|
|
168
|
+
expect(context.getManifestEntry).toBeInstanceOf(Function);
|
|
169
|
+
|
|
170
|
+
// Verify file operations happen when functions are called
|
|
171
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
167
172
|
expect(mockResolve).toHaveBeenCalledWith("manifest.json");
|
|
168
173
|
expect(mockReadFileSync).toHaveBeenCalledWith(
|
|
169
174
|
"/resolved/manifest.json",
|
|
170
175
|
"utf8",
|
|
171
176
|
);
|
|
172
|
-
expect(
|
|
177
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
173
178
|
});
|
|
174
179
|
|
|
175
|
-
it("should provide
|
|
180
|
+
it("should provide helper functions when no manifest or path provided", () => {
|
|
176
181
|
const sdk = createTestSdk();
|
|
177
182
|
const context = sdk.getContext();
|
|
178
183
|
|
|
179
|
-
expect(context.
|
|
184
|
+
expect(context.getVersionedImplementationId).toBeInstanceOf(Function);
|
|
185
|
+
expect(context.getImplementation).toBeInstanceOf(Function);
|
|
186
|
+
expect(context.getManifestEntry).toBeInstanceOf(Function);
|
|
187
|
+
|
|
188
|
+
// Verify that no manifest entry is found
|
|
189
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
190
|
+
expect(manifestEntry).toBeNull();
|
|
180
191
|
});
|
|
181
192
|
|
|
182
193
|
it("should prioritize direct manifest over manifestPath", () => {
|
|
@@ -190,7 +201,9 @@ describe("manifestPlugin", () => {
|
|
|
190
201
|
});
|
|
191
202
|
const context = sdk.getContext();
|
|
192
203
|
|
|
193
|
-
|
|
204
|
+
// Verify that direct manifest is used (should find slack app)
|
|
205
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
206
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
194
207
|
expect(mockReadFileSync).not.toHaveBeenCalled();
|
|
195
208
|
});
|
|
196
209
|
});
|
|
@@ -270,7 +283,9 @@ describe("manifestPlugin", () => {
|
|
|
270
283
|
const sdk = createTestSdk({ manifest: mockManifest });
|
|
271
284
|
const context = sdk.getContext();
|
|
272
285
|
|
|
273
|
-
|
|
286
|
+
// Verify manifest content is accessible through helper functions
|
|
287
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
288
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
274
289
|
});
|
|
275
290
|
|
|
276
291
|
it("should handle manifest with missing version", () => {
|
|
@@ -285,14 +300,18 @@ describe("manifestPlugin", () => {
|
|
|
285
300
|
const sdk = createTestSdk({ manifest: manifestWithoutVersion });
|
|
286
301
|
const context = sdk.getContext();
|
|
287
302
|
|
|
288
|
-
|
|
303
|
+
// Verify manifest entry is accessible and matches expected structure
|
|
304
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
305
|
+
expect(manifestEntry).toEqual(manifestWithoutVersion.apps.slack);
|
|
289
306
|
});
|
|
290
307
|
|
|
291
308
|
it("should handle empty manifest", () => {
|
|
292
309
|
const sdk = createTestSdk({ manifest: {} });
|
|
293
310
|
const context = sdk.getContext();
|
|
294
311
|
|
|
295
|
-
|
|
312
|
+
// Verify that no manifest entry is found for any app
|
|
313
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
314
|
+
expect(manifestEntry).toBeNull();
|
|
296
315
|
});
|
|
297
316
|
});
|
|
298
317
|
|
|
@@ -303,12 +322,14 @@ describe("manifestPlugin", () => {
|
|
|
303
322
|
const sdk = createTestSdk({ manifestPath: "manifest.json" });
|
|
304
323
|
const context = sdk.getContext();
|
|
305
324
|
|
|
325
|
+
// Verify that file operations happen when functions are called
|
|
326
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
306
327
|
expect(mockResolve).toHaveBeenCalledWith("manifest.json");
|
|
307
328
|
expect(mockReadFileSync).toHaveBeenCalledWith(
|
|
308
329
|
"/resolved/manifest.json",
|
|
309
330
|
"utf8",
|
|
310
331
|
);
|
|
311
|
-
expect(
|
|
332
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
312
333
|
});
|
|
313
334
|
|
|
314
335
|
it("should handle file read errors gracefully", () => {
|
|
@@ -319,7 +340,9 @@ describe("manifestPlugin", () => {
|
|
|
319
340
|
const sdk = createTestSdk({ manifestPath: "nonexistent.json" });
|
|
320
341
|
const context = sdk.getContext();
|
|
321
342
|
|
|
322
|
-
|
|
343
|
+
// Verify that no manifest entry is found when file loading fails
|
|
344
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
345
|
+
expect(manifestEntry).toBeNull();
|
|
323
346
|
expect(console.warn).toHaveBeenCalledWith(
|
|
324
347
|
expect.stringContaining(
|
|
325
348
|
"Failed to load manifest from nonexistent.json",
|
|
@@ -333,7 +356,9 @@ describe("manifestPlugin", () => {
|
|
|
333
356
|
const sdk = createTestSdk({ manifestPath: "invalid.json" });
|
|
334
357
|
const context = sdk.getContext();
|
|
335
358
|
|
|
336
|
-
|
|
359
|
+
// Verify that no manifest entry is found when JSON parsing fails
|
|
360
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
361
|
+
expect(manifestEntry).toBeNull();
|
|
337
362
|
expect(console.warn).toHaveBeenCalledWith(
|
|
338
363
|
expect.stringContaining(
|
|
339
364
|
"Failed to parse manifest from /resolved/invalid.json",
|
|
@@ -348,7 +373,9 @@ describe("manifestPlugin", () => {
|
|
|
348
373
|
const sdk = createTestSdk({ manifestPath: "no-apps.json" });
|
|
349
374
|
const context = sdk.getContext();
|
|
350
375
|
|
|
351
|
-
|
|
376
|
+
// Verify that no manifest entry is found when apps property is missing
|
|
377
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
378
|
+
expect(manifestEntry).toBeNull();
|
|
352
379
|
});
|
|
353
380
|
|
|
354
381
|
it("should handle JSON with invalid apps format", () => {
|
|
@@ -357,7 +384,9 @@ describe("manifestPlugin", () => {
|
|
|
357
384
|
const sdk = createTestSdk({ manifestPath: "invalid-apps.json" });
|
|
358
385
|
const context = sdk.getContext();
|
|
359
386
|
|
|
360
|
-
|
|
387
|
+
// Verify that no manifest entry is found when apps format is invalid
|
|
388
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
389
|
+
expect(manifestEntry).toBeNull();
|
|
361
390
|
});
|
|
362
391
|
});
|
|
363
392
|
|
|
@@ -369,7 +398,10 @@ describe("manifestPlugin", () => {
|
|
|
369
398
|
.addPlugin(manifestPlugin);
|
|
370
399
|
const context = sdk.getContext();
|
|
371
400
|
|
|
372
|
-
|
|
401
|
+
// Verify that the manifest data is used correctly
|
|
402
|
+
const manifestEntry = context.getManifestEntry("slack");
|
|
403
|
+
expect(manifestEntry).toEqual(mockManifest.apps.slack);
|
|
404
|
+
|
|
373
405
|
const versionedId = await context.getVersionedImplementationId("slack");
|
|
374
406
|
expect(versionedId).toBe("SlackCLIAPI@1.21.1");
|
|
375
407
|
});
|
|
@@ -21,7 +21,6 @@ export type ManifestPluginOptions = z.infer<typeof ManifestPluginOptionsSchema>;
|
|
|
21
21
|
|
|
22
22
|
export interface ManifestPluginProvides {
|
|
23
23
|
context: {
|
|
24
|
-
manifest: Manifest | null;
|
|
25
24
|
getVersionedImplementationId: GetVersionedImplementationId;
|
|
26
25
|
getManifestEntry: GetManifestEntry;
|
|
27
26
|
getImplementation: GetImplementation;
|
|
@@ -90,7 +89,9 @@ export const manifestPlugin: Plugin<
|
|
|
90
89
|
const { api, options } = context;
|
|
91
90
|
const { manifestPath = ".zapierrc", manifest } = options || {};
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
let resolvedManifest: Manifest | undefined | null;
|
|
93
|
+
|
|
94
|
+
function resolveManifest() {
|
|
94
95
|
// If manifest is provided directly, use it
|
|
95
96
|
if (manifest) {
|
|
96
97
|
return manifest;
|
|
@@ -100,15 +101,23 @@ export const manifestPlugin: Plugin<
|
|
|
100
101
|
return loadManifestFromFile(manifestPath);
|
|
101
102
|
}
|
|
102
103
|
return null;
|
|
103
|
-
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const getResolvedManifest = () => {
|
|
107
|
+
if (typeof resolvedManifest === "undefined") {
|
|
108
|
+
resolvedManifest = resolveManifest() ?? null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return resolvedManifest;
|
|
112
|
+
};
|
|
104
113
|
|
|
105
114
|
const getManifestEntry = (appKey: string) => {
|
|
106
|
-
return
|
|
115
|
+
return getResolvedManifest()?.apps?.[appKey] || null;
|
|
107
116
|
};
|
|
108
117
|
|
|
109
118
|
const getImplementation = async (appKey: string) => {
|
|
110
119
|
let selectedApi = null;
|
|
111
|
-
const manifestImplementation =
|
|
120
|
+
const manifestImplementation = getResolvedManifest()?.apps?.[appKey];
|
|
112
121
|
const [versionlessAppKey, version] = splitVersionedKey(appKey);
|
|
113
122
|
|
|
114
123
|
// Use versioned app key if provided
|
|
@@ -162,7 +171,6 @@ export const manifestPlugin: Plugin<
|
|
|
162
171
|
|
|
163
172
|
return {
|
|
164
173
|
context: {
|
|
165
|
-
manifest: resolvedManifest,
|
|
166
174
|
getVersionedImplementationId,
|
|
167
175
|
getManifestEntry,
|
|
168
176
|
getImplementation,
|