@zapier/zapier-sdk 0.11.0 → 0.11.2

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.
@@ -4,7 +4,7 @@ import type { FunctionRegistryEntry } from "../../types/sdk";
4
4
  export interface RegisterPluginFunctionOptions {}
5
5
 
6
6
  export interface RegistryPluginProvides {
7
- getRegistry: () => {
7
+ getRegistry: (options?: { package?: string }) => {
8
8
  functions: FunctionRegistryEntry[];
9
9
  categories: {
10
10
  key: string;
@@ -62,53 +62,85 @@ export const registryPlugin: Plugin<
62
62
  itemType: meta.itemType,
63
63
  returnType: meta.returnType,
64
64
  inputSchema: meta.inputSchema,
65
+ inputParameters: meta.inputParameters,
65
66
  outputSchema: meta.outputSchema,
66
67
  categories: meta.categories || [],
67
68
  resolvers: meta.resolvers,
69
+ packages: meta.packages,
68
70
  };
69
71
  })
70
72
  .sort((a, b) => a.name.localeCompare(b.name));
71
73
 
72
74
  const knownCategories = Object.keys(categoryDefinitions);
73
75
 
74
- const categories = knownCategories
75
- .sort((a, b) => {
76
- // Keep "other" category last
77
- if (a === "other") return 1;
78
- if (b === "other") return -1;
79
- // Alphabetize by title, not key
80
- const titleA = categoryDefinitions[a].title;
81
- const titleB = categoryDefinitions[b].title;
82
- return titleA.localeCompare(titleB);
83
- })
84
- .map((categoryKey) => {
85
- // Find the functions that are in this category
86
- const categoryFunctions = functions
87
- .filter(
76
+ // Cache the entire registry result for each package
77
+ const registryCache = new Map<
78
+ string,
79
+ { functions: FunctionRegistryEntry[]; categories: any[] }
80
+ >();
81
+
82
+ function getRegistry(options?: { package?: string }) {
83
+ const packageFilter = options?.package;
84
+ const cacheKey = packageFilter || "__all__";
85
+
86
+ // Return cached result if available
87
+ if (registryCache.has(cacheKey)) {
88
+ return registryCache.get(cacheKey)!;
89
+ }
90
+
91
+ // Filter functions by package if specified
92
+ const filteredFunctions = packageFilter
93
+ ? functions.filter(
88
94
  (f) =>
89
- f.categories.includes(categoryKey) ||
90
- // If the category is "other" and the function is not in any other category, include it
91
- (categoryKey === "other" &&
92
- !f.categories.some((c) => knownCategories.includes(c))),
95
+ // Include if packages is undefined (belongs to all packages) or includes the specified package
96
+ !f.packages || f.packages.includes(packageFilter),
93
97
  )
94
- .map((f) => f.name)
95
- .sort(); // Alphabetize functions within each category
98
+ : functions;
96
99
 
97
- const definition = categoryDefinitions[categoryKey];
98
- const title = definition.title;
99
- return {
100
- key: categoryKey,
101
- title,
102
- titlePlural: definition.titlePlural ?? `${title}s`,
103
- functions: categoryFunctions,
104
- };
105
- });
100
+ // Build categories with filtered functions
101
+ const filteredCategories = knownCategories
102
+ .sort((a, b) => {
103
+ // Keep "other" category last
104
+ if (a === "other") return 1;
105
+ if (b === "other") return -1;
106
+ // Alphabetize by title, not key
107
+ const titleA = categoryDefinitions[a].title;
108
+ const titleB = categoryDefinitions[b].title;
109
+ return titleA.localeCompare(titleB);
110
+ })
111
+ .map((categoryKey) => {
112
+ // Find the functions that are in this category and match the package filter
113
+ const categoryFunctions = filteredFunctions
114
+ .filter(
115
+ (f) =>
116
+ f.categories.includes(categoryKey) ||
117
+ // If the category is "other" and the function is not in any other category, include it
118
+ (categoryKey === "other" &&
119
+ !f.categories.some((c) => knownCategories.includes(c))),
120
+ )
121
+ .map((f) => f.name)
122
+ .sort(); // Alphabetize functions within each category
123
+
124
+ const definition = categoryDefinitions[categoryKey];
125
+ const title = definition.title;
126
+ return {
127
+ key: categoryKey,
128
+ title,
129
+ titlePlural: definition.titlePlural ?? `${title}s`,
130
+ functions: categoryFunctions,
131
+ };
132
+ })
133
+ .filter((category) => category.functions.length > 0); // Only include categories with functions
106
134
 
107
- function getRegistry() {
108
- return {
109
- functions,
110
- categories,
135
+ const result = {
136
+ functions: filteredFunctions,
137
+ categories: filteredCategories,
111
138
  };
139
+
140
+ // Cache the result
141
+ registryCache.set(cacheKey, result);
142
+
143
+ return result;
112
144
  }
113
145
 
114
146
  return {
package/src/types/sdk.ts CHANGED
@@ -60,10 +60,12 @@ export interface FunctionRegistryEntry {
60
60
  type?: "list" | "item";
61
61
  itemType?: string;
62
62
  returnType?: string;
63
- inputSchema: z.ZodSchema;
63
+ inputSchema?: z.ZodSchema;
64
+ inputParameters?: Array<{ name: string; schema: z.ZodSchema }>;
64
65
  outputSchema?: z.ZodSchema;
65
66
  categories: string[];
66
67
  resolvers?: Record<string, any>;
68
+ packages?: string[];
67
69
  }
68
70
 
69
71
  // Compose SDK functions from individual function interfaces