@zapier/zapier-sdk 0.77.2 → 0.78.0

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.
@@ -52,6 +52,7 @@ function canonicalInputSchema(schema) {
52
52
  function buildRegistry({
53
53
  sdk,
54
54
  meta,
55
+ formatters,
55
56
  packageFilter
56
57
  }) {
57
58
  const definitionsByKey = /* @__PURE__ */ new Map();
@@ -92,7 +93,7 @@ function buildRegistry({
92
93
  (c) => typeof c === "string" ? c : c.key
93
94
  ),
94
95
  resolvers: m.resolvers,
95
- formatter: m.formatter,
96
+ formatter: formatters?.[key],
96
97
  experimental: m.experimental,
97
98
  packages: m.packages,
98
99
  confirm: m.confirm ?? (m.type === "delete" ? "delete" : void 0),
@@ -518,8 +519,8 @@ function normalizeError(error, adaptError) {
518
519
  );
519
520
  }
520
521
  function createFunction(coreFn, options) {
521
- const { sdk, schema } = options;
522
- const functionName = coreFn.name;
522
+ const { sdk, schema, name } = options;
523
+ const functionName = name || coreFn.name;
523
524
  const namedFunctions = {
524
525
  [functionName]: async function(callOptions) {
525
526
  return runInMethodScope(async () => {
@@ -694,9 +695,6 @@ function createPaginatedFunction(coreFn, options) {
694
695
  };
695
696
  return namedFunctions[functionName];
696
697
  }
697
- function definePlugin(fn) {
698
- return fn;
699
- }
700
698
  function createPluginMethod(sdk, config) {
701
699
  const { name, inputSchema, handler, ...metaFields } = config;
702
700
  const namedHandlers = {
@@ -765,8 +763,7 @@ function splitPluginContribution(result) {
765
763
  }
766
764
  var RESERVED_ROOT_KEYS = /* @__PURE__ */ new Set([
767
765
  "context",
768
- "getRegistry",
769
- "addPlugin"
766
+ "getRegistry"
770
767
  ]);
771
768
  function hasOwn(obj, key) {
772
769
  return Object.prototype.hasOwnProperty.call(obj, key);
@@ -780,15 +777,28 @@ function setOwn(target, key, value) {
780
777
  });
781
778
  }
782
779
  function checkCollisions(target, source, kind, callerLabel, override) {
780
+ if (kind === "root key") {
781
+ checkRootKeyCollisions(target, Object.keys(source), override, callerLabel);
782
+ return;
783
+ }
783
784
  for (const key of Object.keys(source)) {
784
- if (kind === "root key" && RESERVED_ROOT_KEYS.has(key)) {
785
+ if (!override && hasOwn(target, key)) {
786
+ throw new Error(
787
+ `${callerLabel}: duplicate ${kind} "${key}". If the override is intentional, pass { override: true } in the options.`
788
+ );
789
+ }
790
+ }
791
+ }
792
+ function checkRootKeyCollisions(target, keys, override, callerLabel) {
793
+ for (const key of keys) {
794
+ if (RESERVED_ROOT_KEYS.has(key)) {
785
795
  throw new Error(
786
796
  `${callerLabel}: plugin attempted to register reserved root key "${key}". The SDK uses this key for its own accessor; rename the plugin's method.`
787
797
  );
788
798
  }
789
799
  if (!override && hasOwn(target, key)) {
790
800
  throw new Error(
791
- `${callerLabel}: duplicate ${kind} "${key}". If the override is intentional, pass { override: true } in the options.`
801
+ `${callerLabel}: duplicate root key "${key}". If the override is intentional, pass { override: true } in the options.`
792
802
  );
793
803
  }
794
804
  }
@@ -839,7 +849,7 @@ function mergeContribution(propertiesTarget, contextTarget, contribution, option
839
849
  function applyPluginContribution(acc, contribution, options) {
840
850
  mergeContribution(acc.view, acc.context, contribution, options);
841
851
  }
842
- function wrapAsSdk(properties, context, opts) {
852
+ function wrapAsSdk(properties, context) {
843
853
  const sdk = {
844
854
  ...properties,
845
855
  context,
@@ -851,9 +861,6 @@ function wrapAsSdk(properties, context, opts) {
851
861
  });
852
862
  }
853
863
  };
854
- if (opts?.addPlugin !== void 0) {
855
- sdk.addPlugin = opts.addPlugin;
856
- }
857
864
  return sdk;
858
865
  }
859
866
  function wrapAccumulatorAsSdk(acc) {
@@ -872,126 +879,92 @@ function applyPluginToSdk(sdk, plugin, options) {
872
879
  callerLabel: "addPlugin",
873
880
  override: options.override === true
874
881
  });
882
+ return contribution;
875
883
  }
876
- function buildStackAccumulator(head, callerLabel) {
877
- const ordered = [];
884
+ function resolveStack(head) {
885
+ const entries = [];
878
886
  let node = head;
879
887
  while (node) {
880
- ordered.unshift(node);
888
+ entries.unshift({ apply: node.entry, override: node.override });
881
889
  node = node.prev;
882
890
  }
883
- const acc = createPluginAccumulator();
884
- for (const { plugin, override } of ordered) {
885
- const contribution = splitPluginContribution(
886
- plugin(acc.view)
887
- );
888
- applyPluginContribution(acc, contribution, { callerLabel, override });
889
- }
890
- return acc;
891
- }
892
- function addPlugin(sdk, plugin, options) {
893
- applyPluginToSdk(
894
- sdk,
895
- plugin,
896
- options ?? {}
897
- );
891
+ return entries;
892
+ }
893
+ function composeStackHooks(hooks) {
894
+ let composed = {};
895
+ for (const h of hooks) composed = buildHooks(composed, h);
896
+ return composed;
897
+ }
898
+ function collapseStackEntries(entries, callerLabel) {
899
+ return (outerSdk) => {
900
+ const { context: outerContext, ...outerProperties } = outerSdk ?? {};
901
+ const viewAcc = createPluginAccumulator(outerProperties, outerContext);
902
+ const contribsAcc = createPluginAccumulator();
903
+ const hooks = [];
904
+ for (const { apply, override } of entries) {
905
+ const contribution = splitPluginContribution(
906
+ apply(viewAcc.view)
907
+ );
908
+ const hookless = { ...contribution, hooks: {} };
909
+ applyPluginContribution(viewAcc, hookless, { callerLabel, override });
910
+ applyPluginContribution(contribsAcc, hookless, { callerLabel, override });
911
+ hooks.push(contribution.hooks);
912
+ }
913
+ const stackHooks = composeStackHooks(hooks);
914
+ viewAcc.context.hooks = buildHooks(viewAcc.context.hooks, stackHooks);
915
+ contribsAcc.context.hooks = stackHooks;
916
+ const { context: _ignored, ...contributedRoot } = contribsAcc.view;
917
+ return {
918
+ ...contributedRoot,
919
+ context: contribsAcc.context
920
+ };
921
+ };
898
922
  }
899
- function buildSdk(properties, context) {
900
- const addPlugin2 = (plugin, options) => {
901
- logDeprecation(
902
- "sdk.addPlugin(plugin) (the chain-style extension) is deprecated. Build the SDK in one pass with createPluginStack().use(...).toSdk() instead \u2014 each .toSdk() produces fresh plugin closures and avoids the closure-sharing semantics that caused this to be deprecated."
903
- );
923
+ function buildStackAccumulator(head, callerLabel) {
924
+ const entries = resolveStack(head);
925
+ const acc = createPluginAccumulator();
926
+ const hooks = [];
927
+ for (const { apply, override } of entries) {
904
928
  const contribution = splitPluginContribution(
905
- plugin({ ...properties, context })
929
+ apply(acc.view)
906
930
  );
907
- const mergedProperties = { ...properties };
908
- const mergedContext = {
909
- ...context,
910
- meta: { ...context.meta },
911
- hooks: { ...context.hooks }
912
- };
913
- mergeContribution(mergedProperties, mergedContext, contribution, {
914
- callerLabel: "addPlugin",
915
- override: options?.override === true
916
- });
917
- return buildSdk(
918
- mergedProperties,
919
- mergedContext
931
+ applyPluginContribution(
932
+ acc,
933
+ { ...contribution, hooks: {} },
934
+ { callerLabel, override }
920
935
  );
921
- };
922
- return wrapAsSdk(properties, context, { addPlugin: addPlugin2 });
923
- }
924
- function withDeprecatedAddPlugin(sdk) {
925
- const initialProperties = {};
926
- for (const key of Object.keys(sdk)) {
927
- if (key === "context" || key === "getRegistry" || key === "addPlugin") {
928
- continue;
929
- }
930
- initialProperties[key] = sdk[key];
936
+ hooks.push(contribution.hooks);
931
937
  }
932
- const initialContext = sdk.context;
933
- return buildSdk(
934
- initialProperties,
935
- initialContext
936
- );
938
+ acc.context.hooks = composeStackHooks(hooks);
939
+ return acc;
937
940
  }
938
941
  function composePlugins(...plugins) {
939
942
  logDeprecation(
940
- "composePlugins(...) is deprecated. Use createPluginStack().use(a).use(b).use(c).toPlugin() instead. The stack carries the same collision-detection and hook-composition behavior, supports per-step { override: true } for intentional duplicates, and progressively narrows types so dependency mistakes surface at the specific .use call."
941
- );
942
- let stack = buildPluginStack(
943
- null,
944
- "composePlugins"
943
+ "composePlugins(...) is deprecated. Use createPluginStack().use(a).use(b).use(c).toPlugin({ name }) instead. The stack carries the same collision-detection and hook-composition behavior and supports per-step { override: true } for intentional duplicates."
945
944
  );
945
+ let head = null;
946
946
  for (const plugin of plugins) {
947
- stack = stack.use(plugin);
947
+ head = { entry: plugin, override: false, prev: head };
948
948
  }
949
- return stack.toPlugin();
949
+ const entries = resolveStack(head);
950
+ return collapseStackEntries(entries, "composePlugins");
950
951
  }
951
952
  function createPluginStack() {
952
953
  return buildPluginStack(null, "createPluginStack");
953
954
  }
954
955
  function buildPluginStack(head, callerLabel) {
955
- return {
956
+ const stack = {
956
957
  use(plugin, options) {
957
958
  const next = {
958
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
959
- plugin,
959
+ entry: plugin,
960
960
  override: options?.override === true,
961
961
  prev: head
962
962
  };
963
963
  return buildPluginStack(next, callerLabel);
964
964
  },
965
965
  toPlugin() {
966
- const ordered = [];
967
- let node = head;
968
- while (node) {
969
- ordered.unshift(node);
970
- node = node.prev;
971
- }
972
- return (outerSdk) => {
973
- const { context: outerContext, ...outerProperties } = outerSdk ?? {};
974
- const viewAcc = createPluginAccumulator(outerProperties, outerContext);
975
- const contribsAcc = createPluginAccumulator();
976
- for (const { plugin: subPlugin, override } of ordered) {
977
- const contribution = splitPluginContribution(
978
- subPlugin(viewAcc.view)
979
- );
980
- applyPluginContribution(viewAcc, contribution, {
981
- callerLabel,
982
- override
983
- });
984
- applyPluginContribution(contribsAcc, contribution, {
985
- callerLabel,
986
- override
987
- });
988
- }
989
- const { context: _ignored, ...contributedRoot } = contribsAcc.view;
990
- return {
991
- ...contributedRoot,
992
- context: contribsAcc.context
993
- };
994
- };
966
+ const entries = resolveStack(head);
967
+ return collapseStackEntries(entries, callerLabel);
995
968
  },
996
969
  toSdk() {
997
970
  return wrapAccumulatorAsSdk(
@@ -999,6 +972,891 @@ function buildPluginStack(head, callerLabel) {
999
972
  );
1000
973
  }
1001
974
  };
975
+ return stack;
976
+ }
977
+ function parseId(id) {
978
+ const at = id.lastIndexOf("/");
979
+ return at === -1 ? { name: id, namespace: void 0 } : { name: id.slice(at + 1), namespace: id.slice(0, at) };
980
+ }
981
+ function makeId(name, namespace, kind = "leaf") {
982
+ validateName(name, kind);
983
+ if (namespace !== void 0) validateNamespace(namespace);
984
+ return namespace ? `${namespace}/${name}` : name;
985
+ }
986
+ var NAME_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
987
+ var SEGMENT_RE = /^@?[A-Za-z0-9._-]+$/;
988
+ function validateName(name, kind) {
989
+ if (name === "") throw new Error("Plugin name must not be empty.");
990
+ if (kind === "leaf") {
991
+ if (!NAME_RE.test(name)) {
992
+ throw new Error(
993
+ `Plugin name "${name}" must be a valid JS identifier (it is the binding name).`
994
+ );
995
+ }
996
+ } else if (!SEGMENT_RE.test(name)) {
997
+ throw new Error(
998
+ `Plugin name "${name}" must be package-like (letters, digits, ".", "_", "-", optional leading "@") with no "/".`
999
+ );
1000
+ }
1001
+ }
1002
+ function validateNamespace(namespace) {
1003
+ if (namespace === "") throw new Error("Plugin namespace must not be empty.");
1004
+ for (const segment of namespace.split("/")) {
1005
+ if (!SEGMENT_RE.test(segment)) {
1006
+ throw new Error(
1007
+ `Plugin namespace "${namespace}" is invalid: each "/"-separated segment must be package-like (letters, digits, ".", "_", "-", optional leading "@").`
1008
+ );
1009
+ }
1010
+ }
1011
+ }
1012
+ var LEAF_META_KEYS = [
1013
+ "description",
1014
+ "categories",
1015
+ "type",
1016
+ "itemType",
1017
+ "returnType",
1018
+ "outputSchema",
1019
+ "inputParameters",
1020
+ "packages",
1021
+ "experimental",
1022
+ "confirm",
1023
+ "deprecation",
1024
+ "aliases",
1025
+ "supportsJsonOutput"
1026
+ ];
1027
+ function normalizeImports(deps) {
1028
+ if (!deps) return { plugins: [], bindings: [] };
1029
+ const seen = /* @__PURE__ */ new Map();
1030
+ const bindings = [];
1031
+ const add = (binding, id) => {
1032
+ const priorId = seen.get(binding);
1033
+ if (priorId !== void 0 && priorId !== id) {
1034
+ throw new Error(
1035
+ `Import binding "${binding}" is declared twice. Two different plugins ("${priorId}" and "${id}") bind the same name; wrap one in selectExports to rename it.`
1036
+ );
1037
+ }
1038
+ if (priorId === void 0) {
1039
+ seen.set(binding, id);
1040
+ bindings.push({ binding, id });
1041
+ }
1042
+ };
1043
+ for (const plugin of deps) {
1044
+ if (plugin.pluginType === "aggregate") {
1045
+ for (const [binding, child] of Object.entries(plugin.exports)) {
1046
+ add(binding, child.id);
1047
+ }
1048
+ } else {
1049
+ add(plugin.name, plugin.id);
1050
+ }
1051
+ }
1052
+ return { plugins: deps, bindings };
1053
+ }
1054
+ function collectLeafMeta(config) {
1055
+ let meta;
1056
+ for (const key of LEAF_META_KEYS) {
1057
+ if (config[key] !== void 0) (meta ?? (meta = {}))[key] = config[key];
1058
+ }
1059
+ return meta;
1060
+ }
1061
+ function defineMethod(config) {
1062
+ const deps = normalizeImports(config.imports);
1063
+ return {
1064
+ pluginType: "method",
1065
+ name: config.name,
1066
+ namespace: config.namespace,
1067
+ id: makeId(config.name, config.namespace),
1068
+ imports: deps.plugins,
1069
+ importBindings: deps.bindings,
1070
+ inputSchema: config.inputSchema,
1071
+ meta: collectLeafMeta(config),
1072
+ resolvers: config.resolvers,
1073
+ formatter: config.formatter,
1074
+ output: config.output,
1075
+ positional: config.positional,
1076
+ setup: config.setup,
1077
+ run: config.run
1078
+ };
1079
+ }
1080
+ function defineFormatter(config) {
1081
+ const deps = normalizeImports(config.imports);
1082
+ return {
1083
+ imports: deps.plugins,
1084
+ importBindings: deps.bindings,
1085
+ fetchContext: config.fetchContext,
1086
+ format: config.format
1087
+ };
1088
+ }
1089
+ function declareMethod(config) {
1090
+ const { name, namespace } = parseId(config.id);
1091
+ const id = makeId(name, namespace);
1092
+ return {
1093
+ pluginType: "method",
1094
+ name,
1095
+ namespace,
1096
+ id,
1097
+ standIn: true,
1098
+ imports: [],
1099
+ importBindings: [],
1100
+ run: () => {
1101
+ throw new Error(
1102
+ `Plugin "${id}" is a stand-in (declareMethod) with no implementation. Register the real plugin under this id.`
1103
+ );
1104
+ }
1105
+ };
1106
+ }
1107
+ function defineProperty(config) {
1108
+ const deps = normalizeImports(config.imports);
1109
+ return {
1110
+ pluginType: "property",
1111
+ name: config.name,
1112
+ namespace: config.namespace,
1113
+ id: makeId(config.name, config.namespace),
1114
+ imports: deps.plugins,
1115
+ importBindings: deps.bindings,
1116
+ setup: config.setup,
1117
+ value: config.value,
1118
+ get: config.get,
1119
+ meta: collectLeafMeta(config)
1120
+ };
1121
+ }
1122
+ function declareProperty(config) {
1123
+ const { name, namespace } = parseId(config.id);
1124
+ return {
1125
+ pluginType: "property",
1126
+ name,
1127
+ namespace,
1128
+ id: makeId(name, namespace),
1129
+ standIn: true,
1130
+ imports: [],
1131
+ importBindings: []
1132
+ };
1133
+ }
1134
+ function definePlugin(fnOrConfig) {
1135
+ if (typeof fnOrConfig === "function") return fnOrConfig;
1136
+ const config = fnOrConfig;
1137
+ const deps = normalizeImports(config.imports);
1138
+ return {
1139
+ pluginType: "aggregate",
1140
+ name: config.name,
1141
+ namespace: config.namespace,
1142
+ id: makeId(config.name, config.namespace, "aggregate"),
1143
+ imports: deps.plugins,
1144
+ importBindings: deps.bindings,
1145
+ exports: normalizeExports(config.exports),
1146
+ middleware: config.middleware
1147
+ };
1148
+ }
1149
+ function normalizeExports(exports) {
1150
+ if (!exports) return {};
1151
+ const out = {};
1152
+ const add = (binding, leaf) => {
1153
+ const existing = out[binding];
1154
+ if (existing && existing.id !== leaf.id) {
1155
+ throw new Error(
1156
+ `definePlugin: duplicate export binding "${binding}". Two different plugins ("${existing.id}" and "${leaf.id}") bind the same name; wrap one in selectExports to rename it.`
1157
+ );
1158
+ }
1159
+ out[binding] = leaf;
1160
+ };
1161
+ for (const element of exports) {
1162
+ if (element.pluginType === "aggregate") {
1163
+ for (const [binding, child] of Object.entries(element.exports)) {
1164
+ add(binding, child);
1165
+ }
1166
+ } else {
1167
+ add(element.name, element);
1168
+ }
1169
+ }
1170
+ return out;
1171
+ }
1172
+ function fromFunctionPlugin(fn, config) {
1173
+ return {
1174
+ pluginType: "legacy",
1175
+ name: config.name,
1176
+ namespace: config.namespace,
1177
+ id: makeId(config.name, config.namespace, "aggregate"),
1178
+ imports: [],
1179
+ importBindings: [],
1180
+ run: fn
1181
+ };
1182
+ }
1183
+ function defineLegacyMerge(args) {
1184
+ return {
1185
+ pluginType: "legacy-merge",
1186
+ name: args.name,
1187
+ namespace: args.namespace,
1188
+ id: makeId(args.name, args.namespace, "aggregate"),
1189
+ legacy: fromFunctionPlugin(args.legacy, {
1190
+ name: args.name,
1191
+ namespace: args.namespace
1192
+ }),
1193
+ plugin: args.plugin
1194
+ };
1195
+ }
1196
+ function legacyGraphEntry(name, value, pluginMeta) {
1197
+ const { inputSchema, ...rest } = pluginMeta ?? {};
1198
+ const meta = Object.keys(rest).length ? rest : void 0;
1199
+ if (typeof value === "function") {
1200
+ return {
1201
+ pluginType: "method",
1202
+ name,
1203
+ value,
1204
+ chain: [],
1205
+ ...inputSchema ? { inputSchema } : {},
1206
+ ...meta ? { meta } : {}
1207
+ };
1208
+ }
1209
+ return { pluginType: "property", name, value, ...meta ? { meta } : {} };
1210
+ }
1211
+ function adaptLegacyFormatter(legacy, sdk) {
1212
+ const legacyFetch = legacy.fetch;
1213
+ return {
1214
+ fetchContext: legacyFetch ? async ({ items, input, context }) => {
1215
+ let ctx = context;
1216
+ for (const item of items) {
1217
+ ctx = await legacyFetch(sdk, input, item, ctx);
1218
+ }
1219
+ return ctx;
1220
+ } : void 0,
1221
+ format: ({ item, context }) => legacy.format(item, context)
1222
+ };
1223
+ }
1224
+ function normalizeFormatter(entry, sdk) {
1225
+ if (entry.pluginType !== "method") return void 0;
1226
+ if (entry.formatter) return entry.formatter;
1227
+ const legacy = entry.meta?.formatter;
1228
+ return legacy ? adaptLegacyFormatter(legacy, sdk) : void 0;
1229
+ }
1230
+ function pluginEntryMeta(entry) {
1231
+ if (entry.pluginType === "method" && entry.meta) {
1232
+ return entry.inputSchema ? { ...entry.meta, inputSchema: entry.inputSchema } : entry.meta;
1233
+ }
1234
+ if (entry.pluginType === "property" && entry.meta) return entry.meta;
1235
+ return void 0;
1236
+ }
1237
+ function buildSurfaceRegistry(context, packageFilter) {
1238
+ const meta = {};
1239
+ const surface = {};
1240
+ const entries = {};
1241
+ for (const [binding, id] of Object.entries(context.surface)) {
1242
+ const entry = context.plugins[id];
1243
+ if (!entry || entry.pluginType === "aggregate") continue;
1244
+ surface[binding] = entry.value;
1245
+ entries[binding] = entry;
1246
+ const m = pluginEntryMeta(entry);
1247
+ if (m) meta[binding] = m;
1248
+ }
1249
+ const formatters = {};
1250
+ for (const [binding, entry] of Object.entries(entries)) {
1251
+ const f = normalizeFormatter(entry, surface);
1252
+ if (f) formatters[binding] = f;
1253
+ }
1254
+ return buildRegistry({ sdk: surface, meta, formatters, packageFilter });
1255
+ }
1256
+ var dangerousContextPlugin = {
1257
+ pluginType: "property",
1258
+ name: "context",
1259
+ namespace: "kitcore",
1260
+ id: "kitcore/context",
1261
+ imports: [],
1262
+ importBindings: [],
1263
+ privileged: true
1264
+ };
1265
+ defineMethod({
1266
+ name: "getRegistry",
1267
+ namespace: "kitcore",
1268
+ imports: [dangerousContextPlugin],
1269
+ inputSchema: zod.z.object({ package: zod.z.string().optional() }).optional(),
1270
+ run: ({ imports, input }) => buildSurfaceRegistry(imports.context, input?.package)
1271
+ });
1272
+ function normalizeOutput(output) {
1273
+ if (output === void 0) return { type: "raw" };
1274
+ if (typeof output === "string") return { type: output };
1275
+ return output;
1276
+ }
1277
+ var CONTEXT = Symbol("kitcore.context");
1278
+ function getContext(sdk) {
1279
+ return sdk[CONTEXT];
1280
+ }
1281
+ function isResolverRef(value) {
1282
+ return "ref" in value;
1283
+ }
1284
+ function nestedResolvers(resolver) {
1285
+ const out = [];
1286
+ if (resolver.type === "object") {
1287
+ for (const field of Object.values(resolver.properties ?? {})) {
1288
+ if (!isResolverRef(field.resolver)) out.push(field.resolver);
1289
+ }
1290
+ out.push(...Object.values(resolver.definitions ?? {}));
1291
+ } else if (resolver.type === "array") {
1292
+ if (!isResolverRef(resolver.items)) out.push(resolver.items);
1293
+ out.push(...Object.values(resolver.definitions ?? {}));
1294
+ }
1295
+ return out;
1296
+ }
1297
+ function resolverImportEdges(resolver) {
1298
+ const out = [...resolver.imports];
1299
+ for (const child of nestedResolvers(resolver)) {
1300
+ out.push(...resolverImportEdges(child));
1301
+ }
1302
+ return out;
1303
+ }
1304
+ function methodAttachmentEdges(plugin) {
1305
+ const out = [];
1306
+ if (plugin.resolvers) {
1307
+ for (const resolver of Object.values(plugin.resolvers)) {
1308
+ out.push(...resolverImportEdges(resolver));
1309
+ }
1310
+ }
1311
+ if (plugin.formatter) out.push(...plugin.formatter.imports);
1312
+ return out;
1313
+ }
1314
+ function edgesOf(plugin) {
1315
+ if (plugin.pluginType === "aggregate") {
1316
+ return [...Object.values(plugin.exports), ...plugin.imports];
1317
+ }
1318
+ if (plugin.pluginType === "method") {
1319
+ return [...plugin.imports, ...methodAttachmentEdges(plugin)];
1320
+ }
1321
+ return plugin.imports;
1322
+ }
1323
+ function isStandIn(plugin) {
1324
+ return (plugin.pluginType === "method" || plugin.pluginType === "property" || plugin.pluginType === "aggregate") && plugin.standIn === true;
1325
+ }
1326
+ function topoOrder(descriptors) {
1327
+ const order = [];
1328
+ const visited = /* @__PURE__ */ new Set();
1329
+ const visit = (id) => {
1330
+ if (visited.has(id)) return;
1331
+ visited.add(id);
1332
+ const descriptor = descriptors.get(id);
1333
+ if (descriptor) for (const edge of edgesOf(descriptor)) visit(edge.id);
1334
+ order.push(id);
1335
+ };
1336
+ for (const id of descriptors.keys()) visit(id);
1337
+ return order;
1338
+ }
1339
+ function collectPlugins(root, materialized = /* @__PURE__ */ new Set()) {
1340
+ const byId = /* @__PURE__ */ new Map();
1341
+ const visit = (plugin) => {
1342
+ if (materialized.has(plugin.id)) return;
1343
+ const existing = byId.get(plugin.id);
1344
+ if (existing === plugin) return;
1345
+ if (existing) {
1346
+ const bothReal = !isStandIn(existing) && !isStandIn(plugin);
1347
+ if (bothReal) {
1348
+ throw new Error(
1349
+ `createSdk: duplicate plugin id "${plugin.id}". Two different plugins registered under the same id.`
1350
+ );
1351
+ }
1352
+ if (isStandIn(existing) && !isStandIn(plugin)) {
1353
+ byId.set(plugin.id, plugin);
1354
+ for (const edge of edgesOf(plugin)) visit(edge);
1355
+ }
1356
+ return;
1357
+ }
1358
+ byId.set(plugin.id, plugin);
1359
+ for (const edge of edgesOf(plugin)) visit(edge);
1360
+ };
1361
+ visit(root);
1362
+ for (const [id, plugin] of byId) {
1363
+ if (isStandIn(plugin)) {
1364
+ throw new Error(
1365
+ `createSdk: missing dependency "${id}". A plugin depends on it (via a stand-in) but no implementation was registered.`
1366
+ );
1367
+ }
1368
+ }
1369
+ return byId;
1370
+ }
1371
+ function bindValue(target, key, entry) {
1372
+ if (entry.pluginType === "property" && entry.getValue) {
1373
+ Object.defineProperty(target, key, {
1374
+ get: entry.getValue,
1375
+ enumerable: true,
1376
+ configurable: true
1377
+ });
1378
+ } else {
1379
+ Object.defineProperty(target, key, {
1380
+ value: entry.value,
1381
+ writable: true,
1382
+ enumerable: true,
1383
+ configurable: true
1384
+ });
1385
+ }
1386
+ }
1387
+ function buildSurface(context, ...maps) {
1388
+ const sdk = {};
1389
+ for (const map of maps) {
1390
+ Object.defineProperties(sdk, Object.getOwnPropertyDescriptors(map));
1391
+ }
1392
+ sdk.context = context;
1393
+ sdk[CONTEXT] = context;
1394
+ return sdk;
1395
+ }
1396
+ function buildImports(plugins, importBindings) {
1397
+ const imports = {};
1398
+ for (const { binding, id } of importBindings) {
1399
+ bindValue(imports, binding, plugins[id]);
1400
+ }
1401
+ return imports;
1402
+ }
1403
+ function mirrorLegacyRootKeys(context, rootKeys, meta) {
1404
+ const exports = {};
1405
+ for (const [name, value] of Object.entries(rootKeys)) {
1406
+ context.plugins[name] = legacyGraphEntry(name, value, meta[name]);
1407
+ exports[name] = value;
1408
+ }
1409
+ return exports;
1410
+ }
1411
+ function recordExportSurface(context, exports) {
1412
+ for (const [binding, child] of Object.entries(exports)) {
1413
+ context.surface[binding] = child.id;
1414
+ }
1415
+ }
1416
+ function materialize(descriptors, context) {
1417
+ const states = /* @__PURE__ */ new Map();
1418
+ runLegacyPass(descriptors, context);
1419
+ buildMethodEntries(descriptors, context, states);
1420
+ buildEagerArtifacts(descriptors, context, states);
1421
+ bindAttachments(descriptors, context);
1422
+ resolveAggregates(descriptors, context);
1423
+ assembleMiddleware(descriptors, context);
1424
+ return context.plugins;
1425
+ }
1426
+ function bindResolver(resolver, plugins) {
1427
+ switch (resolver.type) {
1428
+ case "static":
1429
+ return {
1430
+ type: "static",
1431
+ requireParams: resolver.requireParams,
1432
+ requireCapabilities: resolver.requireCapabilities,
1433
+ inputType: resolver.inputType,
1434
+ placeholder: resolver.placeholder
1435
+ };
1436
+ case "constant":
1437
+ return {
1438
+ type: "constant",
1439
+ value: resolver.value,
1440
+ requireParams: resolver.requireParams,
1441
+ requireCapabilities: resolver.requireCapabilities
1442
+ };
1443
+ case "info":
1444
+ return { type: "info", text: resolver.text };
1445
+ case "object": {
1446
+ const imports = buildImports(plugins, resolver.importBindings);
1447
+ const bound = {
1448
+ type: "object",
1449
+ requireParams: resolver.requireParams,
1450
+ requireCapabilities: resolver.requireCapabilities
1451
+ };
1452
+ if (resolver.properties)
1453
+ bound.properties = bindFields(resolver.properties, plugins);
1454
+ if (resolver.definitions)
1455
+ bound.definitions = bindDefinitions(resolver.definitions, plugins);
1456
+ const { fetch: fetch2 } = resolver;
1457
+ if (fetch2) bound.fetch = ({ params }) => fetch2({ imports, params });
1458
+ return bound;
1459
+ }
1460
+ case "array": {
1461
+ const bound = {
1462
+ type: "array",
1463
+ requireParams: resolver.requireParams,
1464
+ requireCapabilities: resolver.requireCapabilities,
1465
+ minItems: resolver.minItems,
1466
+ maxItems: resolver.maxItems,
1467
+ items: isResolverRef(resolver.items) ? resolver.items : bindResolver(resolver.items, plugins)
1468
+ };
1469
+ if (resolver.definitions)
1470
+ bound.definitions = bindDefinitions(resolver.definitions, plugins);
1471
+ return bound;
1472
+ }
1473
+ default: {
1474
+ const imports = buildImports(plugins, resolver.importBindings);
1475
+ const bound = {
1476
+ type: "dynamic",
1477
+ requireParams: resolver.requireParams,
1478
+ requireCapabilities: resolver.requireCapabilities,
1479
+ inputType: resolver.inputType,
1480
+ placeholder: resolver.placeholder,
1481
+ prompt: resolver.prompt
1482
+ };
1483
+ const { fetch: fetch2, tryResolveWithoutPrompt } = resolver;
1484
+ if (fetch2)
1485
+ bound.fetch = ({ params, search }) => fetch2({ imports, params, search });
1486
+ if (tryResolveWithoutPrompt) {
1487
+ bound.tryResolveWithoutPrompt = ({ params }) => tryResolveWithoutPrompt({ imports, params });
1488
+ }
1489
+ return bound;
1490
+ }
1491
+ }
1492
+ }
1493
+ function bindFields(fields, plugins) {
1494
+ const out = {};
1495
+ for (const [key, field] of Object.entries(fields)) {
1496
+ out[key] = {
1497
+ ...field,
1498
+ resolver: isResolverRef(field.resolver) ? field.resolver : bindResolver(field.resolver, plugins)
1499
+ };
1500
+ }
1501
+ return out;
1502
+ }
1503
+ function bindDefinitions(definitions, plugins) {
1504
+ const out = {};
1505
+ for (const [key, def] of Object.entries(definitions)) {
1506
+ out[key] = bindResolver(def, plugins);
1507
+ }
1508
+ return out;
1509
+ }
1510
+ function bindFormatter(formatter, plugins) {
1511
+ const imports = buildImports(plugins, formatter.importBindings);
1512
+ const bound = { format: formatter.format };
1513
+ const { fetchContext } = formatter;
1514
+ if (fetchContext)
1515
+ bound.fetchContext = ({ items, input, context }) => fetchContext({ imports, items, input, context });
1516
+ return bound;
1517
+ }
1518
+ function bindAttachments(descriptors, context) {
1519
+ const plugins = context.plugins;
1520
+ for (const [id, descriptor] of descriptors) {
1521
+ if (descriptor.pluginType !== "method") continue;
1522
+ const entry = plugins[id];
1523
+ if (!entry || entry.pluginType !== "method") continue;
1524
+ if (descriptor.resolvers) {
1525
+ const bound = {};
1526
+ for (const [param, resolver] of Object.entries(descriptor.resolvers)) {
1527
+ bound[param] = bindResolver(resolver, plugins);
1528
+ }
1529
+ entry.resolvers = bound;
1530
+ }
1531
+ if (descriptor.formatter) {
1532
+ entry.formatter = bindFormatter(descriptor.formatter, plugins);
1533
+ }
1534
+ }
1535
+ }
1536
+ function runLegacyPass(descriptors, context) {
1537
+ const plugins = context.plugins;
1538
+ const compatView = new Proxy(
1539
+ {},
1540
+ {
1541
+ get: (_target, prop) => {
1542
+ if (prop === "context") return context;
1543
+ const entry = plugins[prop];
1544
+ return entry?.value;
1545
+ }
1546
+ }
1547
+ );
1548
+ for (const id of topoOrder(descriptors)) {
1549
+ const descriptor = descriptors.get(id);
1550
+ if (!descriptor || descriptor.pluginType !== "legacy") continue;
1551
+ const { rootKeys, meta, hooks, contextRest } = splitPluginContribution(
1552
+ descriptor.run(compatView)
1553
+ );
1554
+ Object.assign(context.meta, meta);
1555
+ Object.assign(context, contextRest);
1556
+ context.hooks = buildHooks(context.hooks, hooks);
1557
+ const exports = mirrorLegacyRootKeys(context, rootKeys, meta);
1558
+ if (!("getRegistry" in exports)) {
1559
+ let getRegistry2 = function(options) {
1560
+ const sdk = this ?? exports;
1561
+ const meta2 = {};
1562
+ const formatters = {};
1563
+ for (const [binding, id2] of Object.entries(context.surface)) {
1564
+ const entry = context.plugins[id2];
1565
+ if (!entry || entry.pluginType === "aggregate") continue;
1566
+ const m = pluginEntryMeta(entry);
1567
+ if (m) meta2[binding] = m;
1568
+ const f = normalizeFormatter(entry, sdk);
1569
+ if (f) formatters[binding] = f;
1570
+ }
1571
+ Object.assign(meta2, context.meta);
1572
+ return buildRegistry({
1573
+ sdk,
1574
+ meta: meta2,
1575
+ formatters,
1576
+ packageFilter: options?.package
1577
+ });
1578
+ };
1579
+ exports.getRegistry = getRegistry2;
1580
+ plugins.getRegistry = {
1581
+ pluginType: "method",
1582
+ name: "getRegistry",
1583
+ value: getRegistry2,
1584
+ chain: []
1585
+ };
1586
+ }
1587
+ plugins[id] = { pluginType: "aggregate", name: descriptor.name, exports };
1588
+ }
1589
+ }
1590
+ function buildMethodEntries(descriptors, context, states) {
1591
+ const plugins = context.plugins;
1592
+ for (const [id, descriptor] of descriptors) {
1593
+ if (descriptor.pluginType !== "method") continue;
1594
+ const out = normalizeOutput(descriptor.output);
1595
+ const entry = {
1596
+ pluginType: "method",
1597
+ name: descriptor.name,
1598
+ chain: [],
1599
+ inputSchema: descriptor.inputSchema,
1600
+ // Derive the presentation type from the output mode when the author did
1601
+ // not set one; an explicit meta.type (e.g. "create") still wins.
1602
+ meta: out.type === "raw" || descriptor.meta?.type ? descriptor.meta : { ...descriptor.meta, type: out.type },
1603
+ output: out,
1604
+ // Replaced below; never called.
1605
+ value: () => void 0
1606
+ };
1607
+ const callRun = (input) => descriptor.run({
1608
+ imports: buildImports(plugins, descriptor.importBindings),
1609
+ state: states.get(id),
1610
+ input
1611
+ });
1612
+ const fold = (coreFn) => (input) => {
1613
+ let next = coreFn;
1614
+ for (const wrap of entry.chain) {
1615
+ const inner = next;
1616
+ next = (i) => wrap.run({
1617
+ imports: buildImports(plugins, wrap.owner.importBindings),
1618
+ next: inner,
1619
+ input: i
1620
+ });
1621
+ }
1622
+ return next(input);
1623
+ };
1624
+ const sdk = { context };
1625
+ if (out.type === "list") {
1626
+ entry.value = createPaginatedFunction(
1627
+ fold(callRun),
1628
+ {
1629
+ sdk,
1630
+ schema: descriptor.inputSchema,
1631
+ name: descriptor.name,
1632
+ defaultPageSize: out.defaultPageSize,
1633
+ adaptPage: out.adaptPage
1634
+ }
1635
+ );
1636
+ } else if (out.type === "item") {
1637
+ const itemCore = async (input) => ({
1638
+ data: await callRun(input)
1639
+ });
1640
+ entry.value = createFunction(
1641
+ fold(itemCore),
1642
+ { sdk, schema: descriptor.inputSchema, name: descriptor.name }
1643
+ );
1644
+ } else {
1645
+ entry.value = (rawInput) => {
1646
+ const input = descriptor.inputSchema ? descriptor.inputSchema.parse(rawInput) : rawInput;
1647
+ return fold(callRun)(input);
1648
+ };
1649
+ }
1650
+ if (descriptor.positional) {
1651
+ const names = descriptor.positional;
1652
+ const canonicalValue = entry.value;
1653
+ entry.value = (...args) => {
1654
+ const packed = {};
1655
+ names.forEach((name, i) => {
1656
+ if (i < args.length) packed[name] = args[i];
1657
+ });
1658
+ return canonicalValue(packed);
1659
+ };
1660
+ entry.positional = names;
1661
+ }
1662
+ plugins[id] = entry;
1663
+ }
1664
+ }
1665
+ function buildEagerArtifacts(descriptors, context, states) {
1666
+ const plugins = context.plugins;
1667
+ const built = /* @__PURE__ */ new Set();
1668
+ const building = /* @__PURE__ */ new Set();
1669
+ const ensureBuilt = (id) => {
1670
+ if (built.has(id)) return;
1671
+ const descriptor = descriptors.get(id);
1672
+ if (!descriptor || descriptor.pluginType === "aggregate" || descriptor.pluginType === "legacy") {
1673
+ built.add(id);
1674
+ return;
1675
+ }
1676
+ if (building.has(id)) {
1677
+ throw new Error(`createSdk: dependency cycle at "${id}".`);
1678
+ }
1679
+ building.add(id);
1680
+ for (const { id: depId } of descriptor.importBindings) ensureBuilt(depId);
1681
+ if (descriptor.pluginType === "method") {
1682
+ states.set(
1683
+ id,
1684
+ descriptor.setup ? descriptor.setup({
1685
+ imports: buildImports(plugins, descriptor.importBindings)
1686
+ }) : void 0
1687
+ );
1688
+ } else {
1689
+ states.set(
1690
+ id,
1691
+ descriptor.setup ? descriptor.setup({
1692
+ imports: buildImports(plugins, descriptor.importBindings)
1693
+ }) : void 0
1694
+ );
1695
+ if (descriptor.privileged) {
1696
+ plugins[id] = {
1697
+ pluginType: "property",
1698
+ name: descriptor.name,
1699
+ value: context,
1700
+ meta: descriptor.meta
1701
+ };
1702
+ } else if (descriptor.get) {
1703
+ const get = descriptor.get;
1704
+ const importBindings = descriptor.importBindings;
1705
+ plugins[id] = {
1706
+ pluginType: "property",
1707
+ name: descriptor.name,
1708
+ getValue: () => get({
1709
+ imports: buildImports(plugins, importBindings),
1710
+ state: states.get(id)
1711
+ }),
1712
+ meta: descriptor.meta
1713
+ };
1714
+ } else {
1715
+ plugins[id] = {
1716
+ pluginType: "property",
1717
+ name: descriptor.name,
1718
+ value: descriptor.value,
1719
+ meta: descriptor.meta
1720
+ };
1721
+ }
1722
+ }
1723
+ building.delete(id);
1724
+ built.add(id);
1725
+ };
1726
+ for (const id of descriptors.keys()) ensureBuilt(id);
1727
+ }
1728
+ function resolveAggregates(descriptors, context) {
1729
+ const plugins = context.plugins;
1730
+ for (const [id, descriptor] of descriptors) {
1731
+ if (descriptor.pluginType !== "aggregate") continue;
1732
+ const exports = {};
1733
+ for (const [binding, child] of Object.entries(descriptor.exports)) {
1734
+ bindValue(exports, binding, plugins[child.id]);
1735
+ }
1736
+ plugins[id] = { pluginType: "aggregate", name: descriptor.name, exports };
1737
+ }
1738
+ }
1739
+ function assembleMiddleware(descriptors, context) {
1740
+ const plugins = context.plugins;
1741
+ for (const id of topoOrder(descriptors)) {
1742
+ const descriptor = descriptors.get(id);
1743
+ if (!descriptor || descriptor.pluginType !== "aggregate" || !descriptor.middleware) {
1744
+ continue;
1745
+ }
1746
+ for (const [targetBinding, fn] of Object.entries(descriptor.middleware)) {
1747
+ const edge = descriptor.importBindings.find(
1748
+ (b) => b.binding === targetBinding
1749
+ );
1750
+ if (!edge) {
1751
+ throw new Error(
1752
+ `createSdk: middleware target "${targetBinding}" in plugin "${id}" is not a direct dependency. A middleware target must be a declared dependency of the wrapping plugin.`
1753
+ );
1754
+ }
1755
+ const target = plugins[edge.id];
1756
+ if (!target || target.pluginType !== "method") {
1757
+ throw new Error(
1758
+ `createSdk: middleware target "${targetBinding}" in plugin "${id}" does not resolve to a method.`
1759
+ );
1760
+ }
1761
+ if (target.output?.type === "list") {
1762
+ throw new Error(
1763
+ `createSdk: middleware target "${targetBinding}" in plugin "${id}" resolves to a list-output method, which does not support middleware yet.`
1764
+ );
1765
+ }
1766
+ target.chain.push({ run: fn, owner: descriptor });
1767
+ }
1768
+ }
1769
+ }
1770
+ function createSdk(root) {
1771
+ const context = { plugins: {}, meta: {}, hooks: {}, surface: {} };
1772
+ if (root.pluginType === "legacy-merge") {
1773
+ const { legacy, plugin } = root;
1774
+ const collectRoot = {
1775
+ pluginType: "aggregate",
1776
+ name: root.name,
1777
+ id: `${root.id}:merge`,
1778
+ imports: [legacy, plugin],
1779
+ importBindings: [],
1780
+ exports: {}
1781
+ };
1782
+ const plugins2 = materialize(collectPlugins(collectRoot), context);
1783
+ const legacyExports = plugins2[legacy.id].exports;
1784
+ let pluginSurface;
1785
+ if (plugin.pluginType === "aggregate") {
1786
+ pluginSurface = plugins2[plugin.id].exports;
1787
+ } else {
1788
+ pluginSurface = {};
1789
+ bindValue(pluginSurface, plugin.name, plugins2[plugin.id]);
1790
+ }
1791
+ for (const key of Object.keys(legacyExports)) context.surface[key] = key;
1792
+ if (plugin.pluginType === "aggregate") {
1793
+ recordExportSurface(context, plugin.exports);
1794
+ } else {
1795
+ context.surface[plugin.name] = plugin.id;
1796
+ }
1797
+ return buildSurface(context, legacyExports, pluginSurface);
1798
+ }
1799
+ const plugins = materialize(collectPlugins(root), context);
1800
+ if (root.pluginType === "method" || root.pluginType === "property") {
1801
+ context.surface[root.name] = root.id;
1802
+ const sdk = buildSurface(context);
1803
+ bindValue(sdk, root.name, plugins[root.id]);
1804
+ return sdk;
1805
+ }
1806
+ if (root.pluginType === "aggregate")
1807
+ recordExportSurface(context, root.exports);
1808
+ return buildSurface(context, plugins[root.id].exports);
1809
+ }
1810
+ function addModelPlugin(sdk, plugin, options = {}) {
1811
+ const override = options.override === true;
1812
+ const context = getContext(sdk);
1813
+ const surfaceKeys = plugin.pluginType === "aggregate" ? Object.keys(plugin.exports) : [plugin.name];
1814
+ checkRootKeyCollisions(sdk, surfaceKeys, override, "addPlugin");
1815
+ const materialized = new Set(Object.keys(context.plugins));
1816
+ if (override && materialized.has(plugin.id)) {
1817
+ throw new Error(
1818
+ `addPlugin: cannot override already-materialized plugin "${plugin.id}" on the incremental path. Rebuild the SDK with the replacement via createSdk.`
1819
+ );
1820
+ }
1821
+ materialize(collectPlugins(plugin, materialized), context);
1822
+ const entry = context.plugins[plugin.id];
1823
+ if (entry.pluginType === "aggregate") {
1824
+ Object.defineProperties(
1825
+ sdk,
1826
+ Object.getOwnPropertyDescriptors(entry.exports)
1827
+ );
1828
+ for (const [binding, child] of Object.entries(
1829
+ plugin.exports
1830
+ )) {
1831
+ context.surface[binding] = child.id;
1832
+ }
1833
+ } else {
1834
+ bindValue(sdk, plugin.name, entry);
1835
+ context.surface[plugin.name] = plugin.id;
1836
+ }
1837
+ }
1838
+ function addPlugin(sdk, plugin, options) {
1839
+ if (typeof plugin === "function") {
1840
+ const record = sdk;
1841
+ const contribution = applyPluginToSdk(
1842
+ record,
1843
+ plugin,
1844
+ options ?? {}
1845
+ );
1846
+ const context = record[CONTEXT];
1847
+ if (context) {
1848
+ mirrorLegacyRootKeys(context, contribution.rootKeys, contribution.meta);
1849
+ for (const name of Object.keys(contribution.rootKeys)) {
1850
+ context.surface[name] = name;
1851
+ }
1852
+ }
1853
+ return;
1854
+ }
1855
+ addModelPlugin(
1856
+ sdk,
1857
+ plugin,
1858
+ options ?? {}
1859
+ );
1002
1860
  }
1003
1861
  function createCorePlugin(options) {
1004
1862
  return () => ({
@@ -1282,6 +2140,66 @@ var zapierCorePlugin = createCorePlugin({
1282
2140
  function createZapierCoreStack() {
1283
2141
  return createPluginStack().use(zapierCorePlugin);
1284
2142
  }
2143
+ var GetProfileSchema = zod.z.object({}).optional().describe("Get current user's profile information");
2144
+ var UserProfileItemSchema = zod.z.object({
2145
+ id: zod.z.string(),
2146
+ first_name: zod.z.string(),
2147
+ last_name: zod.z.string(),
2148
+ full_name: zod.z.string(),
2149
+ email: zod.z.string(),
2150
+ email_confirmed: zod.z.boolean(),
2151
+ timezone: zod.z.string()
2152
+ });
2153
+
2154
+ // src/formatters/userProfile.ts
2155
+ var userProfileItemFormatter = defineFormatter({
2156
+ format: ({
2157
+ item
2158
+ }) => {
2159
+ const details = [];
2160
+ if (item.email) {
2161
+ details.push({ text: item.email, style: "dim" });
2162
+ }
2163
+ if (item.timezone) {
2164
+ details.push({
2165
+ text: `Timezone: ${item.timezone}`,
2166
+ style: "accent"
2167
+ });
2168
+ }
2169
+ return {
2170
+ title: item.full_name,
2171
+ hint: item.id,
2172
+ details
2173
+ };
2174
+ }
2175
+ });
2176
+
2177
+ // src/plugins/getProfile/index.ts
2178
+ var getProfilePlugin = defineMethod({
2179
+ name: "getProfile",
2180
+ imports: [dangerousContextPlugin],
2181
+ inputSchema: GetProfileSchema,
2182
+ output: "item",
2183
+ formatter: userProfileItemFormatter,
2184
+ categories: ["account"],
2185
+ itemType: "Profile",
2186
+ outputSchema: UserProfileItemSchema,
2187
+ run: async ({ imports }) => {
2188
+ const api = imports.context.api;
2189
+ const profile = await api.get("/zapier/api/v4/profile/", {
2190
+ authRequired: true
2191
+ });
2192
+ return {
2193
+ id: String(profile.public_id ?? profile.id),
2194
+ first_name: profile.first_name,
2195
+ last_name: profile.last_name,
2196
+ full_name: `${profile.first_name} ${profile.last_name}`,
2197
+ email: profile.email,
2198
+ email_confirmed: profile.email_confirmed,
2199
+ timezone: profile.timezone
2200
+ };
2201
+ }
2202
+ });
1285
2203
 
1286
2204
  // src/constants.ts
1287
2205
  var ZAPIER_BASE_URL = globalThis.process?.env?.ZAPIER_BASE_URL || "https://zapier.com";
@@ -3403,7 +4321,7 @@ function parseApprovalReviewStreamPayload(parsed, toolNames) {
3403
4321
  }
3404
4322
 
3405
4323
  // src/sdk-version.ts
3406
- var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.77.2" : void 0) || "unknown";
4324
+ var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.78.0" : void 0) || "unknown";
3407
4325
 
3408
4326
  // src/utils/open-url.ts
3409
4327
  var nodePrefix = "node:";
@@ -4647,67 +5565,6 @@ var apiPlugin = definePlugin(
4647
5565
  };
4648
5566
  }
4649
5567
  );
4650
- var GetProfileSchema = zod.z.object({}).optional().describe("Get current user's profile information");
4651
- var UserProfileItemSchema = zod.z.object({
4652
- id: zod.z.string(),
4653
- first_name: zod.z.string(),
4654
- last_name: zod.z.string(),
4655
- full_name: zod.z.string(),
4656
- email: zod.z.string(),
4657
- email_confirmed: zod.z.boolean(),
4658
- timezone: zod.z.string()
4659
- });
4660
-
4661
- // src/formatters/userProfile.ts
4662
- var userProfileItemFormatter = {
4663
- format: (item) => {
4664
- const details = [];
4665
- if (item.email) {
4666
- details.push({ text: item.email, style: "dim" });
4667
- }
4668
- if (item.timezone) {
4669
- details.push({
4670
- text: `Timezone: ${item.timezone}`,
4671
- style: "accent"
4672
- });
4673
- }
4674
- return {
4675
- title: item.full_name,
4676
- id: item.id,
4677
- details
4678
- };
4679
- }
4680
- };
4681
-
4682
- // src/plugins/getProfile/index.ts
4683
- var getProfilePlugin = definePlugin(
4684
- (sdk) => createPluginMethod(sdk, {
4685
- name: "getProfile",
4686
- categories: ["account"],
4687
- type: "item",
4688
- itemType: "Profile",
4689
- inputSchema: GetProfileSchema,
4690
- outputSchema: UserProfileItemSchema,
4691
- formatter: userProfileItemFormatter,
4692
- handler: async ({ sdk: sdk2 }) => {
4693
- const profile = await sdk2.context.api.get(
4694
- "/zapier/api/v4/profile/",
4695
- { authRequired: true }
4696
- );
4697
- return {
4698
- data: {
4699
- id: String(profile.public_id ?? profile.id),
4700
- first_name: profile.first_name,
4701
- last_name: profile.last_name,
4702
- full_name: `${profile.first_name} ${profile.last_name}`,
4703
- email: profile.email,
4704
- email_confirmed: profile.email_confirmed,
4705
- timezone: profile.timezone
4706
- }
4707
- };
4708
- }
4709
- })
4710
- );
4711
5568
 
4712
5569
  // src/utils/pagination.ts
4713
5570
  function extractCursorFromUrl(url) {
@@ -6382,7 +7239,7 @@ var actionResultItemFormatter = {
6382
7239
  id: getStringProperty(obj, "id"),
6383
7240
  key: getStringProperty(obj, "key"),
6384
7241
  description: getStringProperty(obj, "description"),
6385
- data: item,
7242
+ raw: item,
6386
7243
  details: []
6387
7244
  };
6388
7245
  }
@@ -10154,12 +11011,6 @@ var eventEmissionPlugin = definePlugin(
10154
11011
  function createOptionsPlugin(options) {
10155
11012
  return () => ({ context: { options } });
10156
11013
  }
10157
- function createSdk() {
10158
- logDeprecation2(
10159
- "createSdk() is deprecated. Build SDKs with createPluginStack().use(...).toSdk() instead. The chain pattern shares plugin closures (and their state) across derived SDKs in ways that are rarely what callers expect; stacks produce fresh closures per .toSdk() call."
10160
- );
10161
- return withDeprecatedAddPlugin(createZapierCoreStack().toSdk());
10162
- }
10163
11014
  function createZapierSdkWithoutRegistry(options = {}) {
10164
11015
  logDeprecation2(
10165
11016
  "createZapierSdkWithoutRegistry is deprecated; use createZapierSdk instead. getRegistry is now available on every sdk."
@@ -10167,10 +11018,22 @@ function createZapierSdkWithoutRegistry(options = {}) {
10167
11018
  return createZapierSdk(options);
10168
11019
  }
10169
11020
  function createZapierSdkStack(options = {}) {
10170
- return createZapierCoreStack().use(createOptionsPlugin(options)).use(eventEmissionPlugin).use(apiPlugin).use(manifestPlugin).use(capabilitiesPlugin).use(connectionsPlugin).use(listAppsPlugin).use(getAppPlugin).use(listConnectionsPlugin).use(getConnectionPlugin).use(findFirstConnectionPlugin).use(findUniqueConnectionPlugin).use(getConnectionStartUrlPlugin).use(waitForNewConnectionPlugin).use(createConnectionPlugin).use(listActionsPlugin).use(getActionPlugin).use(listActionInputFieldsPlugin).use(getActionInputFieldsSchemaPlugin).use(listActionInputFieldChoicesPlugin).use(listInputFieldsDeprecatedPlugin).use(getInputFieldsSchemaDeprecatedPlugin).use(listInputFieldChoicesDeprecatedPlugin).use(runActionPlugin).use(listAuthenticationsPlugin).use(getAuthenticationPlugin).use(findFirstAuthenticationPlugin).use(findUniqueAuthenticationPlugin).use(listClientCredentialsPlugin).use(createClientCredentialsPlugin).use(deleteClientCredentialsPlugin).use(fetchPlugin).use(requestPlugin).use(listTablesPlugin).use(getTablePlugin).use(deleteTablePlugin).use(createTablePlugin).use(listTableFieldsPlugin).use(createTableFieldsPlugin).use(deleteTableFieldsPlugin).use(listTableRecordsPlugin).use(getTableRecordPlugin).use(createTableRecordsPlugin).use(deleteTableRecordsPlugin).use(updateTableRecordsPlugin).use(appsPlugin).use(getProfilePlugin);
11021
+ return createZapierCoreStack().use(createOptionsPlugin(options)).use(eventEmissionPlugin).use(apiPlugin).use(manifestPlugin).use(capabilitiesPlugin).use(connectionsPlugin).use(listAppsPlugin).use(getAppPlugin).use(listConnectionsPlugin).use(getConnectionPlugin).use(findFirstConnectionPlugin).use(findUniqueConnectionPlugin).use(getConnectionStartUrlPlugin).use(waitForNewConnectionPlugin).use(createConnectionPlugin).use(listActionsPlugin).use(getActionPlugin).use(listActionInputFieldsPlugin).use(getActionInputFieldsSchemaPlugin).use(listActionInputFieldChoicesPlugin).use(listInputFieldsDeprecatedPlugin).use(getInputFieldsSchemaDeprecatedPlugin).use(listInputFieldChoicesDeprecatedPlugin).use(runActionPlugin).use(listAuthenticationsPlugin).use(getAuthenticationPlugin).use(findFirstAuthenticationPlugin).use(findUniqueAuthenticationPlugin).use(listClientCredentialsPlugin).use(createClientCredentialsPlugin).use(deleteClientCredentialsPlugin).use(fetchPlugin).use(requestPlugin).use(listTablesPlugin).use(getTablePlugin).use(deleteTablePlugin).use(createTablePlugin).use(listTableFieldsPlugin).use(createTableFieldsPlugin).use(deleteTableFieldsPlugin).use(listTableRecordsPlugin).use(getTableRecordPlugin).use(createTableRecordsPlugin).use(deleteTableRecordsPlugin).use(updateTableRecordsPlugin).use(appsPlugin);
10171
11022
  }
11023
+ var zapierSdkPlugin = definePlugin({
11024
+ namespace: "zapier",
11025
+ name: "sdk",
11026
+ exports: [getProfilePlugin]
11027
+ });
10172
11028
  function createZapierSdk(options = {}) {
10173
- return withDeprecatedAddPlugin(createZapierSdkStack(options).toSdk());
11029
+ return createSdk(
11030
+ defineLegacyMerge({
11031
+ namespace: "zapier",
11032
+ name: "sdk-stack-merge",
11033
+ legacy: createZapierSdkStack(options).toPlugin(),
11034
+ plugin: zapierSdkPlugin
11035
+ })
11036
+ );
10174
11037
  }
10175
11038
  var TriggerInboxStatusSchema = zod.z.union([
10176
11039
  zod.z.enum([
@@ -13310,10 +14173,17 @@ var registryPlugin = definePlugin((_sdk) => {
13310
14173
 
13311
14174
  // src/experimental.ts
13312
14175
  function createZapierSdkStack2(options = {}) {
13313
- return createZapierCoreStack().use(createOptionsPlugin(options)).use(eventEmissionPlugin).use(apiPlugin).use(manifestPlugin).use(capabilitiesPlugin).use(connectionsPlugin).use(listAppsPlugin).use(getAppPlugin).use(listConnectionsPlugin).use(getConnectionPlugin).use(findFirstConnectionPlugin).use(findUniqueConnectionPlugin).use(getConnectionStartUrlPlugin).use(waitForNewConnectionPlugin).use(createConnectionPlugin).use(listActionsPlugin).use(getActionPlugin).use(listActionInputFieldsPlugin).use(getActionInputFieldsSchemaPlugin).use(listActionInputFieldChoicesPlugin).use(listInputFieldsDeprecatedPlugin).use(getInputFieldsSchemaDeprecatedPlugin).use(listInputFieldChoicesDeprecatedPlugin).use(runActionPlugin).use(listAuthenticationsPlugin).use(getAuthenticationPlugin).use(findFirstAuthenticationPlugin).use(findUniqueAuthenticationPlugin).use(listClientCredentialsPlugin).use(createClientCredentialsPlugin).use(deleteClientCredentialsPlugin).use(fetchPlugin).use(requestPlugin).use(listTriggerInboxesPlugin).use(createTriggerInboxPlugin).use(ensureTriggerInboxPlugin).use(getTriggerInboxPlugin).use(updateTriggerInboxPlugin).use(deleteTriggerInboxPlugin).use(pauseTriggerInboxPlugin).use(resumeTriggerInboxPlugin).use(listTriggerInboxMessagesPlugin).use(leaseTriggerInboxMessagesPlugin).use(ackTriggerInboxMessagesPlugin).use(releaseTriggerInboxMessagesPlugin).use(drainTriggerInboxPlugin).use(watchTriggerInboxPlugin).use(listTriggersPlugin).use(listTriggerInputFieldsPlugin).use(listTriggerInputFieldChoicesPlugin).use(getTriggerInputFieldsSchemaPlugin).use(listTablesPlugin).use(getTablePlugin).use(deleteTablePlugin).use(createTablePlugin).use(listTableFieldsPlugin).use(createTableFieldsPlugin).use(deleteTableFieldsPlugin).use(listTableRecordsPlugin).use(getTableRecordPlugin).use(createTableRecordsPlugin).use(deleteTableRecordsPlugin).use(updateTableRecordsPlugin).use(listWorkflowsPlugin).use(getWorkflowPlugin).use(createWorkflowPlugin).use(updateWorkflowPlugin).use(enableWorkflowPlugin).use(disableWorkflowPlugin).use(deleteWorkflowPlugin).use(listDurableRunsPlugin).use(getDurableRunPlugin).use(runDurablePlugin).use(cancelDurableRunPlugin).use(publishWorkflowVersionPlugin).use(listWorkflowVersionsPlugin).use(getWorkflowVersionPlugin).use(listWorkflowRunsPlugin).use(getWorkflowRunPlugin).use(getTriggerRunPlugin).use(triggerWorkflowPlugin).use(appsPlugin).use(getProfilePlugin);
14176
+ return createZapierCoreStack().use(createOptionsPlugin(options)).use(eventEmissionPlugin).use(apiPlugin).use(manifestPlugin).use(capabilitiesPlugin).use(connectionsPlugin).use(listAppsPlugin).use(getAppPlugin).use(listConnectionsPlugin).use(getConnectionPlugin).use(findFirstConnectionPlugin).use(findUniqueConnectionPlugin).use(getConnectionStartUrlPlugin).use(waitForNewConnectionPlugin).use(createConnectionPlugin).use(listActionsPlugin).use(getActionPlugin).use(listActionInputFieldsPlugin).use(getActionInputFieldsSchemaPlugin).use(listActionInputFieldChoicesPlugin).use(listInputFieldsDeprecatedPlugin).use(getInputFieldsSchemaDeprecatedPlugin).use(listInputFieldChoicesDeprecatedPlugin).use(runActionPlugin).use(listAuthenticationsPlugin).use(getAuthenticationPlugin).use(findFirstAuthenticationPlugin).use(findUniqueAuthenticationPlugin).use(listClientCredentialsPlugin).use(createClientCredentialsPlugin).use(deleteClientCredentialsPlugin).use(fetchPlugin).use(requestPlugin).use(listTriggerInboxesPlugin).use(createTriggerInboxPlugin).use(ensureTriggerInboxPlugin).use(getTriggerInboxPlugin).use(updateTriggerInboxPlugin).use(deleteTriggerInboxPlugin).use(pauseTriggerInboxPlugin).use(resumeTriggerInboxPlugin).use(listTriggerInboxMessagesPlugin).use(leaseTriggerInboxMessagesPlugin).use(ackTriggerInboxMessagesPlugin).use(releaseTriggerInboxMessagesPlugin).use(drainTriggerInboxPlugin).use(watchTriggerInboxPlugin).use(listTriggersPlugin).use(listTriggerInputFieldsPlugin).use(listTriggerInputFieldChoicesPlugin).use(getTriggerInputFieldsSchemaPlugin).use(listTablesPlugin).use(getTablePlugin).use(deleteTablePlugin).use(createTablePlugin).use(listTableFieldsPlugin).use(createTableFieldsPlugin).use(deleteTableFieldsPlugin).use(listTableRecordsPlugin).use(getTableRecordPlugin).use(createTableRecordsPlugin).use(deleteTableRecordsPlugin).use(updateTableRecordsPlugin).use(listWorkflowsPlugin).use(getWorkflowPlugin).use(createWorkflowPlugin).use(updateWorkflowPlugin).use(enableWorkflowPlugin).use(disableWorkflowPlugin).use(deleteWorkflowPlugin).use(listDurableRunsPlugin).use(getDurableRunPlugin).use(runDurablePlugin).use(cancelDurableRunPlugin).use(publishWorkflowVersionPlugin).use(listWorkflowVersionsPlugin).use(getWorkflowVersionPlugin).use(listWorkflowRunsPlugin).use(getWorkflowRunPlugin).use(getTriggerRunPlugin).use(triggerWorkflowPlugin).use(appsPlugin);
13314
14177
  }
13315
14178
  function createZapierSdk2(options = {}) {
13316
- return withDeprecatedAddPlugin(createZapierSdkStack2(options).toSdk());
14179
+ return createSdk(
14180
+ defineLegacyMerge({
14181
+ namespace: "zapier",
14182
+ name: "experimental-stack-merge",
14183
+ legacy: createZapierSdkStack2(options).toPlugin(),
14184
+ plugin: zapierSdkPlugin
14185
+ })
14186
+ );
13317
14187
  }
13318
14188
 
13319
14189
  exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
@@ -13430,7 +14300,13 @@ exports.createZapierCoreStack = createZapierCoreStack;
13430
14300
  exports.createZapierSdk = createZapierSdk2;
13431
14301
  exports.createZapierSdkStack = createZapierSdkStack2;
13432
14302
  exports.createZapierSdkWithoutRegistry = createZapierSdkWithoutRegistry;
14303
+ exports.dangerousContextPlugin = dangerousContextPlugin;
14304
+ exports.declareMethod = declareMethod;
14305
+ exports.declareProperty = declareProperty;
14306
+ exports.defineLegacyMerge = defineLegacyMerge;
14307
+ exports.defineMethod = defineMethod;
13433
14308
  exports.definePlugin = definePlugin;
14309
+ exports.defineProperty = defineProperty;
13434
14310
  exports.deleteClientCredentialsPlugin = deleteClientCredentialsPlugin;
13435
14311
  exports.deleteTableFieldsPlugin = deleteTableFieldsPlugin;
13436
14312
  exports.deleteTablePlugin = deleteTablePlugin;
@@ -13442,6 +14318,7 @@ exports.findFirstConnectionPlugin = findFirstConnectionPlugin;
13442
14318
  exports.findManifestEntry = findManifestEntry;
13443
14319
  exports.findUniqueConnectionPlugin = findUniqueConnectionPlugin;
13444
14320
  exports.formatErrorMessage = formatErrorMessage;
14321
+ exports.fromFunctionPlugin = fromFunctionPlugin;
13445
14322
  exports.generateEventId = generateEventId;
13446
14323
  exports.getActionInputFieldsSchemaPlugin = getActionInputFieldsSchemaPlugin;
13447
14324
  exports.getActionPlugin = getActionPlugin;
@@ -13452,6 +14329,7 @@ exports.getCallerContext = getCallerContext;
13452
14329
  exports.getCiPlatform = getCiPlatform;
13453
14330
  exports.getClientIdFromCredentials = getClientIdFromCredentials;
13454
14331
  exports.getConnectionPlugin = getConnectionPlugin;
14332
+ exports.getContext = getContext;
13455
14333
  exports.getCoreErrorCause = getCoreErrorCause;
13456
14334
  exports.getCoreErrorCode = getCoreErrorCode;
13457
14335
  exports.getCpuTime = getCpuTime;
@@ -13529,3 +14407,4 @@ exports.workflowIdResolver = workflowIdResolver;
13529
14407
  exports.workflowRunIdResolver = workflowRunIdResolver;
13530
14408
  exports.workflowVersionIdResolver = workflowVersionIdResolver;
13531
14409
  exports.zapierAdaptError = zapierAdaptError;
14410
+ exports.zapierSdkPlugin = zapierSdkPlugin;