@zapier/zapier-sdk 0.5.1 → 0.6.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +107 -83
  3. package/dist/api/index.d.ts +1 -1
  4. package/dist/api/index.d.ts.map +1 -1
  5. package/dist/api/schemas.d.ts +6 -6
  6. package/dist/api/types.d.ts +7 -7
  7. package/dist/api/types.d.ts.map +1 -1
  8. package/dist/index.cjs +343 -67
  9. package/dist/index.d.mts +416 -347
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +0 -1
  12. package/dist/index.mjs +343 -67
  13. package/dist/plugins/api/index.js +1 -1
  14. package/dist/plugins/apps/types.d.ts +1 -1
  15. package/dist/plugins/apps/types.d.ts.map +1 -1
  16. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
  17. package/dist/plugins/findFirstAuthentication/index.js +1 -0
  18. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
  19. package/dist/plugins/findUniqueAuthentication/index.js +1 -0
  20. package/dist/plugins/getAction/index.d.ts.map +1 -1
  21. package/dist/plugins/getAction/index.js +1 -0
  22. package/dist/plugins/getAction/index.test.js +1 -1
  23. package/dist/plugins/getApp/index.d.ts +6 -3
  24. package/dist/plugins/getApp/index.d.ts.map +1 -1
  25. package/dist/plugins/getApp/index.js +8 -18
  26. package/dist/plugins/getApp/index.test.js +2 -0
  27. package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
  28. package/dist/plugins/getAuthentication/index.js +1 -0
  29. package/dist/plugins/getAuthentication/index.test.js +12 -1
  30. package/dist/plugins/getProfile/index.d.ts.map +1 -1
  31. package/dist/plugins/getProfile/index.js +1 -0
  32. package/dist/plugins/listActions/index.d.ts +5 -3
  33. package/dist/plugins/listActions/index.d.ts.map +1 -1
  34. package/dist/plugins/listActions/index.js +6 -6
  35. package/dist/plugins/listActions/index.test.js +26 -74
  36. package/dist/plugins/listActions/schemas.d.ts +4 -4
  37. package/dist/plugins/listApps/index.d.ts.map +1 -1
  38. package/dist/plugins/listApps/index.js +1 -0
  39. package/dist/plugins/listApps/schemas.d.ts +2 -2
  40. package/dist/plugins/listAuthentications/index.d.ts +4 -2
  41. package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
  42. package/dist/plugins/listAuthentications/index.js +9 -12
  43. package/dist/plugins/listAuthentications/index.test.js +33 -40
  44. package/dist/plugins/listAuthentications/schemas.d.ts +4 -4
  45. package/dist/plugins/listInputFields/index.d.ts +3 -1
  46. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  47. package/dist/plugins/listInputFields/index.js +5 -5
  48. package/dist/plugins/listInputFields/index.test.js +10 -8
  49. package/dist/plugins/listInputFields/schemas.d.ts +4 -4
  50. package/dist/plugins/lockVersion/index.d.ts +24 -0
  51. package/dist/plugins/lockVersion/index.d.ts.map +1 -0
  52. package/dist/plugins/lockVersion/index.js +72 -0
  53. package/dist/plugins/lockVersion/index.test.d.ts +2 -0
  54. package/dist/plugins/lockVersion/index.test.d.ts.map +1 -0
  55. package/dist/plugins/lockVersion/index.test.js +129 -0
  56. package/dist/plugins/lockVersion/schemas.d.ts +10 -0
  57. package/dist/plugins/lockVersion/schemas.d.ts.map +1 -0
  58. package/dist/plugins/lockVersion/schemas.js +6 -0
  59. package/dist/plugins/manifest/index.d.ts +24 -0
  60. package/dist/plugins/manifest/index.d.ts.map +1 -0
  61. package/dist/plugins/manifest/index.js +119 -0
  62. package/dist/plugins/manifest/index.test.d.ts +2 -0
  63. package/dist/plugins/manifest/index.test.d.ts.map +1 -0
  64. package/dist/plugins/manifest/index.test.js +331 -0
  65. package/dist/plugins/manifest/schemas.d.ts +64 -0
  66. package/dist/plugins/manifest/schemas.d.ts.map +1 -0
  67. package/dist/plugins/manifest/schemas.js +25 -0
  68. package/dist/plugins/registry/index.d.ts +9 -1
  69. package/dist/plugins/registry/index.d.ts.map +1 -1
  70. package/dist/plugins/registry/index.js +68 -3
  71. package/dist/plugins/request/index.d.ts.map +1 -1
  72. package/dist/plugins/request/index.js +1 -0
  73. package/dist/plugins/request/index.test.js +6 -1
  74. package/dist/plugins/request/schemas.d.ts +4 -4
  75. package/dist/plugins/runAction/index.d.ts +2 -0
  76. package/dist/plugins/runAction/index.d.ts.map +1 -1
  77. package/dist/plugins/runAction/index.js +5 -5
  78. package/dist/plugins/runAction/index.test.js +9 -8
  79. package/dist/plugins/runAction/schemas.d.ts +4 -4
  80. package/dist/schemas/Auth.d.ts +4 -4
  81. package/dist/schemas/Field.d.ts.map +1 -1
  82. package/dist/sdk.d.ts +3 -3
  83. package/dist/sdk.d.ts.map +1 -1
  84. package/dist/sdk.js +18 -7
  85. package/dist/sdk.test.js +1 -1
  86. package/dist/types/errors.d.ts +6 -6
  87. package/dist/types/errors.d.ts.map +1 -1
  88. package/dist/types/events.d.ts +1 -1
  89. package/dist/types/events.d.ts.map +1 -1
  90. package/dist/types/plugin.d.ts +10 -2
  91. package/dist/types/plugin.d.ts.map +1 -1
  92. package/dist/types/sdk.d.ts +13 -2
  93. package/dist/types/sdk.d.ts.map +1 -1
  94. package/dist/utils/validation.test.js +2 -1
  95. package/package.json +2 -2
  96. package/src/api/client.ts +3 -3
  97. package/src/api/index.ts +2 -0
  98. package/src/api/types.ts +15 -7
  99. package/src/index.ts +0 -2
  100. package/src/plugins/api/index.ts +1 -1
  101. package/src/plugins/apps/types.ts +1 -1
  102. package/src/plugins/findFirstAuthentication/index.ts +1 -0
  103. package/src/plugins/findUniqueAuthentication/index.ts +1 -0
  104. package/src/plugins/getAction/index.test.ts +1 -1
  105. package/src/plugins/getAction/index.ts +1 -0
  106. package/src/plugins/getApp/index.test.ts +2 -0
  107. package/src/plugins/getApp/index.ts +12 -24
  108. package/src/plugins/getAuthentication/index.test.ts +13 -3
  109. package/src/plugins/getAuthentication/index.ts +1 -0
  110. package/src/plugins/getProfile/index.ts +1 -0
  111. package/src/plugins/listActions/index.test.ts +30 -89
  112. package/src/plugins/listActions/index.ts +34 -27
  113. package/src/plugins/listApps/index.ts +1 -0
  114. package/src/plugins/listAuthentications/index.test.ts +38 -47
  115. package/src/plugins/listAuthentications/index.ts +21 -18
  116. package/src/plugins/listInputFields/index.test.ts +12 -9
  117. package/src/plugins/listInputFields/index.ts +10 -6
  118. package/src/plugins/lockVersion/index.test.ts +176 -0
  119. package/src/plugins/lockVersion/index.ts +112 -0
  120. package/src/plugins/lockVersion/schemas.ts +9 -0
  121. package/src/plugins/manifest/index.test.ts +439 -0
  122. package/src/plugins/manifest/index.ts +171 -0
  123. package/src/plugins/manifest/schemas.ts +53 -0
  124. package/src/plugins/registry/index.ts +89 -8
  125. package/src/plugins/request/index.test.ts +8 -4
  126. package/src/plugins/request/index.ts +1 -0
  127. package/src/plugins/runAction/index.test.ts +9 -8
  128. package/src/plugins/runAction/index.ts +18 -9
  129. package/src/schemas/Field.ts +5 -2
  130. package/src/sdk.test.ts +1 -1
  131. package/src/sdk.ts +22 -7
  132. package/src/types/errors.ts +9 -6
  133. package/src/types/events.ts +1 -1
  134. package/src/types/plugin.ts +14 -2
  135. package/src/types/sdk.ts +15 -1
  136. package/src/utils/validation.test.ts +2 -1
  137. package/tsconfig.tsbuildinfo +1 -1
package/dist/index.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var zod = require('zod');
4
+ var fs = require('fs');
5
+ var path = require('path');
4
6
 
5
7
  // src/types/properties.ts
6
8
  function withFormatter(schema, formatMeta) {
@@ -527,15 +529,67 @@ var RelayFetchSchema = RelayRequestSchema;
527
529
  // src/plugins/registry/index.ts
528
530
  var registryPlugin = ({ sdk, context }) => {
529
531
  const metaKeys = Object.keys(context.meta || {});
530
- const registryEntries = metaKeys.map((key) => {
532
+ const categoryDefinitions = {
533
+ app: {
534
+ title: "App",
535
+ titlePlural: "Apps"
536
+ },
537
+ authentication: {
538
+ title: "Authentication"
539
+ },
540
+ action: {
541
+ title: "Action"
542
+ },
543
+ http: {
544
+ title: "HTTP Request"
545
+ },
546
+ user: {
547
+ title: "User"
548
+ },
549
+ utility: {
550
+ title: "Utility",
551
+ titlePlural: "Utilities"
552
+ },
553
+ other: {
554
+ title: "Other"
555
+ }
556
+ };
557
+ const functions = metaKeys.filter((key) => typeof sdk[key] === "function").map((key) => {
531
558
  return {
532
559
  ...context.meta[key],
533
- name: key,
534
- implementation: sdk[key]
560
+ categories: context.meta[key].categories || [],
561
+ name: key
562
+ };
563
+ }).sort((a, b) => a.name.localeCompare(b.name));
564
+ const knownCategories = Object.keys(categoryDefinitions);
565
+ const categories = knownCategories.sort((a, b) => {
566
+ if (a === "other") return 1;
567
+ if (b === "other") return -1;
568
+ const titleA = categoryDefinitions[a].title;
569
+ const titleB = categoryDefinitions[b].title;
570
+ return titleA.localeCompare(titleB);
571
+ }).map((categoryKey) => {
572
+ const categoryFunctions = functions.filter(
573
+ (f) => f.categories.includes(categoryKey) || // If the category is "other" and the function is not in any other category, include it
574
+ categoryKey === "other" && !f.categories.some((c) => knownCategories.includes(c))
575
+ ).map((f) => f.name).sort();
576
+ const definition = categoryDefinitions[categoryKey];
577
+ const title = definition.title;
578
+ return {
579
+ key: categoryKey,
580
+ title,
581
+ titlePlural: definition.titlePlural ?? `${title}s`,
582
+ functions: categoryFunctions
535
583
  };
536
584
  });
585
+ function getRegistry() {
586
+ return {
587
+ functions,
588
+ categories
589
+ };
590
+ }
537
591
  return {
538
- __registry: registryEntries
592
+ getRegistry
539
593
  };
540
594
  };
541
595
 
@@ -624,7 +678,7 @@ async function pollUntilComplete(options) {
624
678
  } else if (response.status === pendingStatus) {
625
679
  errorCount = 0;
626
680
  if (attempt < maxAttempts - 1) {
627
- await new Promise((resolve) => setTimeout(resolve, delay));
681
+ await new Promise((resolve3) => setTimeout(resolve3, delay));
628
682
  delay = Math.min(delay * 2, maxDelay);
629
683
  continue;
630
684
  }
@@ -637,7 +691,7 @@ async function pollUntilComplete(options) {
637
691
  );
638
692
  }
639
693
  if (attempt < maxAttempts - 1) {
640
- await new Promise((resolve) => setTimeout(resolve, delay));
694
+ await new Promise((resolve3) => setTimeout(resolve3, delay));
641
695
  delay = Math.min(delay * 2, maxDelay);
642
696
  continue;
643
697
  }
@@ -961,7 +1015,7 @@ var apiPlugin = (params) => {
961
1015
  getToken,
962
1016
  onEvent,
963
1017
  debug = false
964
- } = params;
1018
+ } = params.context.options;
965
1019
  const api = createZapierApi({
966
1020
  baseUrl,
967
1021
  token,
@@ -1654,6 +1708,7 @@ var getProfilePlugin = ({ context }) => {
1654
1708
  context: {
1655
1709
  meta: {
1656
1710
  getProfile: {
1711
+ categories: ["user"],
1657
1712
  inputSchema: GetProfileSchema
1658
1713
  }
1659
1714
  }
@@ -1708,6 +1763,16 @@ function splitVersionedKey(versionedKey) {
1708
1763
  }
1709
1764
  return [versionedKey, void 0];
1710
1765
  }
1766
+ function normalizeImplementationToAppItem(implementation) {
1767
+ const [selectedApi, appVersion] = implementation.selected_api ? splitVersionedKey(implementation.selected_api) : [implementation.selected_api || "", void 0];
1768
+ return {
1769
+ title: implementation.name || selectedApi,
1770
+ key: selectedApi,
1771
+ current_implementation_id: implementation.selected_api || "",
1772
+ version: appVersion
1773
+ // Extract version separately
1774
+ };
1775
+ }
1711
1776
  function normalizeImplementationMetaToAppItem(implementationMeta) {
1712
1777
  const [selectedApi, appVersion] = splitVersionedKey(implementationMeta.id);
1713
1778
  return {
@@ -1893,6 +1958,7 @@ var listAppsPlugin = ({ context }) => {
1893
1958
  context: {
1894
1959
  meta: {
1895
1960
  listApps: {
1961
+ categories: ["app"],
1896
1962
  inputSchema: ListAppsSchema
1897
1963
  }
1898
1964
  }
@@ -1909,23 +1975,16 @@ var GetAppSchema = withOutputSchema(
1909
1975
  );
1910
1976
 
1911
1977
  // src/plugins/getApp/index.ts
1912
- var getAppPlugin = ({ sdk }) => {
1978
+ var getAppPlugin = ({ context }) => {
1913
1979
  const getApp = createFunction(async function getApp2(options) {
1914
- const { appKey } = options;
1915
- const appsIterator = sdk.listApps({
1916
- ...options,
1917
- appKeys: [appKey]
1918
- }).items();
1919
- const apps = [];
1920
- for await (const app of appsIterator) {
1921
- apps.push(app);
1922
- break;
1923
- }
1924
- if (apps.length === 0) {
1925
- throw new ZapierAppNotFoundError(appKey);
1980
+ const app = await context.getImplementation(options.appKey);
1981
+ if (!app) {
1982
+ throw new ZapierAppNotFoundError("App not found", {
1983
+ appKey: options.appKey
1984
+ });
1926
1985
  }
1927
1986
  return {
1928
- data: apps[0]
1987
+ data: app
1929
1988
  };
1930
1989
  }, GetAppSchema);
1931
1990
  return {
@@ -1933,6 +1992,7 @@ var getAppPlugin = ({ sdk }) => {
1933
1992
  context: {
1934
1993
  meta: {
1935
1994
  getApp: {
1995
+ categories: ["app"],
1936
1996
  inputSchema: GetAppSchema
1937
1997
  }
1938
1998
  }
@@ -1991,12 +2051,11 @@ var ListActionsSchema = withOutputSchema(
1991
2051
  );
1992
2052
 
1993
2053
  // src/plugins/listActions/index.ts
1994
- var listActionsPlugin = ({ sdk, context }) => {
2054
+ var listActionsPlugin = ({ context }) => {
1995
2055
  const listActions = createPaginatedFunction(async function listActionsPage(options) {
1996
- const { api } = context;
1997
- const app = await sdk.getApp({ appKey: options.appKey });
1998
- const implementationId = app.data.current_implementation_id?.split("@")[0];
1999
- if (!implementationId) {
2056
+ const { api, getVersionedImplementationId } = context;
2057
+ const selectedApi = await getVersionedImplementationId(options.appKey);
2058
+ if (!selectedApi) {
2000
2059
  throw new ZapierConfigurationError(
2001
2060
  "No current_implementation_id found for app",
2002
2061
  { configType: "current_implementation_id" }
@@ -2005,26 +2064,29 @@ var listActionsPlugin = ({ sdk, context }) => {
2005
2064
  const searchParams = {
2006
2065
  global: "true",
2007
2066
  public_only: "true",
2008
- selected_apis: implementationId
2067
+ selected_apis: selectedApi
2009
2068
  };
2010
- const data = await api.get("/api/v4/implementations/", {
2011
- searchParams,
2012
- customErrorHandler: ({ status }) => {
2013
- if (status === 401) {
2014
- return new ZapierAuthenticationError(
2015
- `Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
2016
- { statusCode: status }
2017
- );
2018
- }
2019
- if (status === 403) {
2020
- return new ZapierAuthenticationError(
2021
- `Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
2022
- { statusCode: status }
2023
- );
2069
+ const data = await api.get(
2070
+ "/api/v4/implementations/",
2071
+ {
2072
+ searchParams,
2073
+ customErrorHandler: ({ status }) => {
2074
+ if (status === 401) {
2075
+ return new ZapierAuthenticationError(
2076
+ `Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
2077
+ { statusCode: status }
2078
+ );
2079
+ }
2080
+ if (status === 403) {
2081
+ return new ZapierAuthenticationError(
2082
+ `Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
2083
+ { statusCode: status }
2084
+ );
2085
+ }
2086
+ return void 0;
2024
2087
  }
2025
- return void 0;
2026
2088
  }
2027
- });
2089
+ );
2028
2090
  let allActions = [];
2029
2091
  for (const implementation of data.results || []) {
2030
2092
  if (implementation.actions) {
@@ -2052,6 +2114,7 @@ var listActionsPlugin = ({ sdk, context }) => {
2052
2114
  context: {
2053
2115
  meta: {
2054
2116
  listActions: {
2117
+ categories: ["action"],
2055
2118
  inputSchema: ListActionsSchema
2056
2119
  }
2057
2120
  }
@@ -2084,6 +2147,7 @@ var getActionPlugin = ({ sdk }) => {
2084
2147
  context: {
2085
2148
  meta: {
2086
2149
  getAction: {
2150
+ categories: ["action"],
2087
2151
  inputSchema: GetActionSchema
2088
2152
  }
2089
2153
  }
@@ -2106,15 +2170,14 @@ var RunActionSchema = zod.z.object({
2106
2170
  async function executeAction(actionOptions) {
2107
2171
  const {
2108
2172
  api,
2109
- sdk,
2173
+ context,
2110
2174
  appKey,
2111
2175
  actionKey,
2112
2176
  actionType,
2113
2177
  executionOptions,
2114
2178
  authenticationId
2115
2179
  } = actionOptions;
2116
- const appData = await sdk.getApp({ appKey });
2117
- const selectedApi = appData.data.current_implementation_id;
2180
+ const selectedApi = await context.getVersionedImplementationId(appKey);
2118
2181
  if (!selectedApi) {
2119
2182
  throw new ZapierConfigurationError(
2120
2183
  "No current_implementation_id found for app",
@@ -2133,7 +2196,10 @@ async function executeAction(actionOptions) {
2133
2196
  const runRequest = {
2134
2197
  data: runRequestData
2135
2198
  };
2136
- const runData = await api.post("/api/actions/v1/runs", runRequest);
2199
+ const runData = await api.post(
2200
+ "/api/actions/v1/runs",
2201
+ runRequest
2202
+ );
2137
2203
  const runId = runData.data.id;
2138
2204
  return await api.poll(`/api/actions/v1/runs/${runId}`, {
2139
2205
  successStatus: 200,
@@ -2163,7 +2229,7 @@ var runActionPlugin = ({ sdk, context }) => {
2163
2229
  }
2164
2230
  const result = await executeAction({
2165
2231
  api,
2166
- sdk,
2232
+ context,
2167
2233
  appKey,
2168
2234
  actionKey,
2169
2235
  actionType,
@@ -2189,6 +2255,7 @@ var runActionPlugin = ({ sdk, context }) => {
2189
2255
  context: {
2190
2256
  meta: {
2191
2257
  runAction: {
2258
+ categories: ["action"],
2192
2259
  inputSchema: RunActionSchema
2193
2260
  }
2194
2261
  }
@@ -2208,19 +2275,18 @@ var ListAuthenticationsSchema = zod.z.object({
2208
2275
  }).describe("List available authentications with optional filtering");
2209
2276
 
2210
2277
  // src/plugins/listAuthentications/index.ts
2211
- var listAuthenticationsPlugin = ({ sdk, context }) => {
2278
+ var listAuthenticationsPlugin = ({ context }) => {
2212
2279
  const listAuthentications = createPaginatedFunction(
2213
2280
  async function listAuthenticationsPage(options) {
2214
- const { api } = context;
2281
+ const { api, getVersionedImplementationId } = context;
2215
2282
  const searchParams = {};
2216
2283
  if (options.appKey) {
2217
- const app = await sdk.getApp({
2218
- appKey: options.appKey
2219
- });
2220
- const selectedApi = app.data.current_implementation_id;
2221
- if (selectedApi) {
2222
- const versionlessApi = selectedApi.split("@")[0];
2223
- searchParams.versionless_selected_api = versionlessApi;
2284
+ const implementationId = await getVersionedImplementationId(
2285
+ options.appKey
2286
+ );
2287
+ if (implementationId) {
2288
+ const [versionlessSelectedApi] = splitVersionedKey(implementationId);
2289
+ searchParams.versionless_selected_api = versionlessSelectedApi;
2224
2290
  }
2225
2291
  }
2226
2292
  if (options.search) {
@@ -2238,6 +2304,7 @@ var listAuthenticationsPlugin = ({ sdk, context }) => {
2238
2304
  if (options.cursor) {
2239
2305
  searchParams.offset = options.cursor;
2240
2306
  }
2307
+ console.log({ searchParams });
2241
2308
  const data = await api.get(
2242
2309
  "/api/v4/authentications/",
2243
2310
  {
@@ -2278,6 +2345,7 @@ var listAuthenticationsPlugin = ({ sdk, context }) => {
2278
2345
  context: {
2279
2346
  meta: {
2280
2347
  listAuthentications: {
2348
+ categories: ["authentication"],
2281
2349
  inputSchema: ListAuthenticationsSchema
2282
2350
  }
2283
2351
  }
@@ -2332,6 +2400,7 @@ var getAuthenticationPlugin = ({ context }) => {
2332
2400
  context: {
2333
2401
  meta: {
2334
2402
  getAuthentication: {
2403
+ categories: ["authentication"],
2335
2404
  inputSchema: GetAuthenticationSchema
2336
2405
  }
2337
2406
  }
@@ -2367,6 +2436,7 @@ var findFirstAuthenticationPlugin = ({ sdk }) => {
2367
2436
  context: {
2368
2437
  meta: {
2369
2438
  findFirstAuthentication: {
2439
+ categories: ["authentication"],
2370
2440
  inputSchema: FindFirstAuthenticationSchema
2371
2441
  }
2372
2442
  }
@@ -2414,6 +2484,7 @@ var findUniqueAuthenticationPlugin = ({ sdk }) => {
2414
2484
  context: {
2415
2485
  meta: {
2416
2486
  findUniqueAuthentication: {
2487
+ categories: ["authentication"],
2417
2488
  inputSchema: FindUniqueAuthenticationSchema
2418
2489
  }
2419
2490
  }
@@ -2490,13 +2561,12 @@ function transformNeedToInputFieldItem(need) {
2490
2561
  items: itemsType ? { type: itemsType } : void 0
2491
2562
  };
2492
2563
  }
2493
- var listInputFieldsPlugin = ({ sdk, context }) => {
2564
+ var listInputFieldsPlugin = ({ context }) => {
2494
2565
  const listInputFields = createPaginatedFunction(
2495
2566
  async function listInputFieldsPage(options) {
2496
- const { api } = context;
2567
+ const { api, getVersionedImplementationId } = context;
2497
2568
  const { appKey, actionKey, actionType, authenticationId, inputs } = options;
2498
- const appData = await sdk.getApp({ appKey });
2499
- const selectedApi = appData.data.current_implementation_id;
2569
+ const selectedApi = await getVersionedImplementationId(appKey);
2500
2570
  if (!selectedApi) {
2501
2571
  throw new ZapierConfigurationError(
2502
2572
  "No current_implementation_id found for app",
@@ -2537,6 +2607,7 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
2537
2607
  context: {
2538
2608
  meta: {
2539
2609
  listInputFields: {
2610
+ categories: ["action"],
2540
2611
  inputSchema: ListInputFieldsSchema
2541
2612
  }
2542
2613
  }
@@ -2590,32 +2661,237 @@ var requestPlugin = ({ context }) => {
2590
2661
  context: {
2591
2662
  meta: {
2592
2663
  request: {
2664
+ categories: ["http"],
2593
2665
  inputSchema: RelayRequestSchema
2594
2666
  }
2595
2667
  }
2596
2668
  }
2597
2669
  };
2598
2670
  };
2671
+ var ManifestSchema = zod.z.object({
2672
+ apps: zod.z.record(
2673
+ zod.z.string(),
2674
+ zod.z.object({
2675
+ implementationName: zod.z.string().describe(
2676
+ "Base implementation name without version (e.g., 'SlackCLIAPI')"
2677
+ ),
2678
+ version: zod.z.string().describe("Version string (e.g., '1.21.1')")
2679
+ })
2680
+ )
2681
+ }).describe("Manifest mapping app keys to version information");
2682
+ zod.z.object({
2683
+ manifestPath: zod.z.string().optional().describe("Path to manifest file"),
2684
+ manifest: zod.z.record(
2685
+ zod.z.string(),
2686
+ zod.z.object({
2687
+ implementationName: zod.z.string(),
2688
+ version: zod.z.string().optional()
2689
+ })
2690
+ ).optional().describe("Direct manifest object")
2691
+ });
2692
+
2693
+ // src/plugins/manifest/index.ts
2694
+ function parseManifestContent(content, source) {
2695
+ try {
2696
+ const parsed = JSON.parse(content);
2697
+ if (parsed?.apps && typeof parsed?.apps === "object") {
2698
+ const result = ManifestSchema.safeParse(parsed);
2699
+ if (result.success) {
2700
+ return result.data;
2701
+ }
2702
+ console.warn(`\u26A0\uFE0F Invalid manifest format in ${source}: ${result.error}`);
2703
+ }
2704
+ return null;
2705
+ } catch (error) {
2706
+ console.warn(`\u26A0\uFE0F Failed to parse manifest from ${source}:`, error);
2707
+ return null;
2708
+ }
2709
+ }
2710
+ function loadManifestFromFile(filePath) {
2711
+ try {
2712
+ const resolvedPath = path.resolve(filePath);
2713
+ const content = fs.readFileSync(resolvedPath, "utf8");
2714
+ return parseManifestContent(content, resolvedPath);
2715
+ } catch (error) {
2716
+ console.warn(`\u26A0\uFE0F Failed to load manifest from ${filePath}:`, error);
2717
+ return null;
2718
+ }
2719
+ }
2720
+ var emitWarning = (appKey) => {
2721
+ console.warn(
2722
+ `
2723
+ ${"\u26A0\uFE0F".padEnd(3)} ${"WARNING".padEnd(8)} No manifest version found for '${appKey}'`
2724
+ );
2725
+ console.warn(
2726
+ ` ${"\u21B3".padEnd(3)} Using a manifest ensures version locking and prevents unexpected behavior due to version changes.`
2727
+ );
2728
+ console.warn(
2729
+ ` ${"\u21B3".padEnd(3)} Generate/update the manifest with: \`zapier-sdk update-manifest ${appKey}\`
2730
+ `
2731
+ );
2732
+ };
2733
+ var manifestPlugin = (params) => {
2734
+ const { sdk, context } = params;
2735
+ const { api, options } = context;
2736
+ const { manifestPath = ".zapierrc", manifest } = options || {};
2737
+ const resolvedManifest = (() => {
2738
+ if (manifest) {
2739
+ return manifest;
2740
+ }
2741
+ if (manifestPath) {
2742
+ return loadManifestFromFile(manifestPath);
2743
+ }
2744
+ return null;
2745
+ })();
2746
+ const getManifestEntry = (appKey) => {
2747
+ return resolvedManifest?.apps?.[appKey] || null;
2748
+ };
2749
+ const getImplementation = async (appKey) => {
2750
+ let selectedApi = null;
2751
+ const manifestImplementation = resolvedManifest?.apps?.[appKey];
2752
+ const [versionlessAppKey, version] = splitVersionedKey(appKey);
2753
+ if (version) {
2754
+ selectedApi = `${versionlessAppKey}@${version}`;
2755
+ } else if (manifestImplementation) {
2756
+ selectedApi = `${manifestImplementation.implementationName}@${manifestImplementation.version || "latest"}`;
2757
+ }
2758
+ if (selectedApi) {
2759
+ const searchParams = {
2760
+ selected_apis: selectedApi
2761
+ };
2762
+ const implementationData = await api.get(
2763
+ "/api/v4/implementations/",
2764
+ {
2765
+ searchParams
2766
+ }
2767
+ );
2768
+ const implementationResults = implementationData.results[0];
2769
+ if (!implementationResults) return null;
2770
+ return normalizeImplementationToAppItem(implementationResults);
2771
+ }
2772
+ emitWarning(appKey);
2773
+ const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
2774
+ const apps = [];
2775
+ for await (const app2 of appsIterator) {
2776
+ apps.push(app2);
2777
+ break;
2778
+ }
2779
+ if (apps.length === 0) {
2780
+ return null;
2781
+ }
2782
+ const app = apps[0];
2783
+ return app;
2784
+ };
2785
+ const getVersionedImplementationId = async (appKey) => {
2786
+ const manifestEntry = getManifestEntry(appKey);
2787
+ if (manifestEntry) {
2788
+ return `${manifestEntry.implementationName}@${manifestEntry.version || "latest"}`;
2789
+ }
2790
+ const implementation = await getImplementation(appKey);
2791
+ if (!implementation) return null;
2792
+ return implementation.current_implementation_id;
2793
+ };
2794
+ return {
2795
+ context: {
2796
+ manifest: resolvedManifest,
2797
+ getVersionedImplementationId,
2798
+ getManifestEntry,
2799
+ getImplementation
2800
+ }
2801
+ };
2802
+ };
2803
+ var LockVersionSchema = zod.z.object({
2804
+ appKey: zod.z.string().describe("The app key to lock version for (e.g., 'slack', 'gmail')")
2805
+ });
2806
+ var lockVersionPlugin = ({ sdk }) => {
2807
+ const lockVersion = createFunction(
2808
+ async function lockVersion2(options) {
2809
+ const { appKey, configPath = ".zapierrc" } = options;
2810
+ const resolvedPath = path.resolve(configPath);
2811
+ const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
2812
+ const apps = [];
2813
+ for await (const app2 of appsIterator) {
2814
+ apps.push(app2);
2815
+ break;
2816
+ }
2817
+ const app = apps[0];
2818
+ const currentImplementationId = app.current_implementation_id;
2819
+ const [implementationName, version] = currentImplementationId.split("@");
2820
+ if (!implementationName || !version) {
2821
+ throw new Error(
2822
+ `Invalid implementation ID format: ${currentImplementationId}. Expected format: <implementationName>@<version>`
2823
+ );
2824
+ }
2825
+ let config = { apps: {} };
2826
+ if (fs.existsSync(resolvedPath)) {
2827
+ try {
2828
+ const configContent = fs.readFileSync(resolvedPath, "utf8");
2829
+ config = JSON.parse(configContent);
2830
+ if (!config.apps) {
2831
+ config.apps = {};
2832
+ }
2833
+ } catch (error) {
2834
+ console.warn(
2835
+ `\u26A0\uFE0F Failed to parse existing config file, creating new one: ${error}`
2836
+ );
2837
+ config = { apps: {} };
2838
+ }
2839
+ }
2840
+ config.apps[appKey] = {
2841
+ implementationName,
2842
+ version
2843
+ };
2844
+ fs.writeFileSync(resolvedPath, JSON.stringify(config, null, 2));
2845
+ return {
2846
+ data: {
2847
+ ...app,
2848
+ implementationName,
2849
+ version
2850
+ },
2851
+ configPath: resolvedPath
2852
+ };
2853
+ },
2854
+ LockVersionSchema.extend({
2855
+ configPath: zod.z.string().optional().describe("Path to .zapierrc file (defaults to '.zapierrc')")
2856
+ })
2857
+ );
2858
+ return {
2859
+ lockVersion,
2860
+ context: {
2861
+ meta: {
2862
+ lockVersion: {
2863
+ categories: ["utility"],
2864
+ inputSchema: LockVersionSchema
2865
+ }
2866
+ }
2867
+ }
2868
+ };
2869
+ };
2599
2870
 
2600
2871
  // src/sdk.ts
2601
- function createSdk(initialSdk = {}, initialContext = { meta: {} }) {
2872
+ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} }) {
2602
2873
  return {
2603
2874
  ...initialSdk,
2604
2875
  getContext: () => initialContext,
2605
- addPlugin(plugin, options = {}) {
2876
+ addPlugin(plugin, addPluginOptions = {}) {
2606
2877
  const currentSdkWithContext = {
2607
2878
  ...initialSdk,
2608
2879
  getContext: () => initialContext
2609
2880
  };
2610
2881
  const pluginResult = plugin({
2611
2882
  sdk: currentSdkWithContext,
2612
- context: initialContext,
2613
- ...options
2883
+ context: {
2884
+ ...initialContext,
2885
+ // Add the options that createSdk was called with to context
2886
+ options
2887
+ },
2888
+ ...addPluginOptions
2614
2889
  });
2615
2890
  const { context: pluginContext, ...sdkProperties } = pluginResult;
2616
2891
  const newSdk = { ...initialSdk, ...sdkProperties };
2617
2892
  let newContext = {
2618
2893
  ...initialContext,
2894
+ ...addPluginOptions,
2619
2895
  meta: initialContext.meta || {}
2620
2896
  };
2621
2897
  if (pluginContext) {
@@ -2636,12 +2912,12 @@ function createSdk(initialSdk = {}, initialContext = { meta: {} }) {
2636
2912
  };
2637
2913
  }
2638
2914
  }
2639
- return createSdk(newSdk, newContext);
2915
+ return createSdk(options, newSdk, newContext);
2640
2916
  }
2641
2917
  };
2642
2918
  }
2643
2919
  function createZapierSdk(options = {}) {
2644
- return createSdk().addPlugin(apiPlugin, options).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(runActionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin).addPlugin(registryPlugin);
2920
+ return createSdk(options).addPlugin(apiPlugin).addPlugin(listAppsPlugin).addPlugin(manifestPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(runActionPlugin).addPlugin(lockVersionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin).addPlugin(registryPlugin);
2645
2921
  }
2646
2922
 
2647
2923
  exports.ActionKeyPropertySchema = ActionKeyPropertySchema;