@zapier/zapier-sdk 0.34.1 → 0.36.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 (156) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +341 -0
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +10 -2
  5. package/dist/api/types.d.ts +2 -1
  6. package/dist/api/types.d.ts.map +1 -1
  7. package/dist/constants.d.ts +4 -0
  8. package/dist/constants.d.ts.map +1 -1
  9. package/dist/constants.js +4 -0
  10. package/dist/formatters/index.d.ts +2 -0
  11. package/dist/formatters/index.d.ts.map +1 -0
  12. package/dist/formatters/index.js +1 -0
  13. package/dist/formatters/tableRecord.d.ts +6 -0
  14. package/dist/formatters/tableRecord.d.ts.map +1 -0
  15. package/dist/formatters/tableRecord.js +23 -0
  16. package/dist/index.cjs +2054 -191
  17. package/dist/index.d.mts +639 -59
  18. package/dist/index.d.ts +13 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +13 -0
  21. package/dist/index.mjs +2030 -192
  22. package/dist/plugins/deleteClientCredentials/index.d.ts.map +1 -1
  23. package/dist/plugins/deleteClientCredentials/index.js +1 -1
  24. package/dist/plugins/listActions/index.d.ts.map +1 -1
  25. package/dist/plugins/listActions/index.js +2 -1
  26. package/dist/plugins/listApps/index.d.ts.map +1 -1
  27. package/dist/plugins/listApps/index.js +5 -2
  28. package/dist/plugins/listClientCredentials/index.d.ts.map +1 -1
  29. package/dist/plugins/listClientCredentials/index.js +6 -4
  30. package/dist/plugins/listConnections/index.d.ts.map +1 -1
  31. package/dist/plugins/listConnections/index.js +6 -4
  32. package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
  33. package/dist/plugins/listInputFieldChoices/index.js +2 -1
  34. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  35. package/dist/plugins/listInputFields/index.js +2 -1
  36. package/dist/plugins/registry/index.d.ts.map +1 -1
  37. package/dist/plugins/registry/index.js +4 -0
  38. package/dist/plugins/runAction/index.d.ts +2 -0
  39. package/dist/plugins/runAction/index.d.ts.map +1 -1
  40. package/dist/plugins/runAction/index.js +73 -14
  41. package/dist/plugins/tables/createTable/index.d.ts +18 -0
  42. package/dist/plugins/tables/createTable/index.d.ts.map +1 -0
  43. package/dist/plugins/tables/createTable/index.js +48 -0
  44. package/dist/plugins/tables/createTable/schemas.d.ts +37 -0
  45. package/dist/plugins/tables/createTable/schemas.d.ts.map +1 -0
  46. package/dist/plugins/tables/createTable/schemas.js +16 -0
  47. package/dist/plugins/tables/createTableFields/index.d.ts +18 -0
  48. package/dist/plugins/tables/createTableFields/index.d.ts.map +1 -0
  49. package/dist/plugins/tables/createTableFields/index.js +49 -0
  50. package/dist/plugins/tables/createTableFields/schemas.d.ts +192 -0
  51. package/dist/plugins/tables/createTableFields/schemas.d.ts.map +1 -0
  52. package/dist/plugins/tables/createTableFields/schemas.js +42 -0
  53. package/dist/plugins/tables/createTableRecords/index.d.ts +18 -0
  54. package/dist/plugins/tables/createTableRecords/index.d.ts.map +1 -0
  55. package/dist/plugins/tables/createTableRecords/index.js +67 -0
  56. package/dist/plugins/tables/createTableRecords/schemas.d.ts +57 -0
  57. package/dist/plugins/tables/createTableRecords/schemas.d.ts.map +1 -0
  58. package/dist/plugins/tables/createTableRecords/schemas.js +35 -0
  59. package/dist/plugins/tables/deleteTable/index.d.ts +18 -0
  60. package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -0
  61. package/dist/plugins/tables/deleteTable/index.js +43 -0
  62. package/dist/plugins/tables/deleteTable/schemas.d.ts +15 -0
  63. package/dist/plugins/tables/deleteTable/schemas.d.ts.map +1 -0
  64. package/dist/plugins/tables/deleteTable/schemas.js +9 -0
  65. package/dist/plugins/tables/deleteTableFields/index.d.ts +18 -0
  66. package/dist/plugins/tables/deleteTableFields/index.d.ts.map +1 -0
  67. package/dist/plugins/tables/deleteTableFields/index.js +50 -0
  68. package/dist/plugins/tables/deleteTableFields/schemas.d.ts +16 -0
  69. package/dist/plugins/tables/deleteTableFields/schemas.d.ts.map +1 -0
  70. package/dist/plugins/tables/deleteTableFields/schemas.js +13 -0
  71. package/dist/plugins/tables/deleteTableRecords/index.d.ts +18 -0
  72. package/dist/plugins/tables/deleteTableRecords/index.d.ts.map +1 -0
  73. package/dist/plugins/tables/deleteTableRecords/index.js +44 -0
  74. package/dist/plugins/tables/deleteTableRecords/schemas.d.ts +16 -0
  75. package/dist/plugins/tables/deleteTableRecords/schemas.d.ts.map +1 -0
  76. package/dist/plugins/tables/deleteTableRecords/schemas.js +14 -0
  77. package/dist/plugins/tables/getTable/index.d.ts +20 -0
  78. package/dist/plugins/tables/getTable/index.d.ts.map +1 -0
  79. package/dist/plugins/tables/getTable/index.js +48 -0
  80. package/dist/plugins/tables/getTable/schemas.d.ts +34 -0
  81. package/dist/plugins/tables/getTable/schemas.d.ts.map +1 -0
  82. package/dist/plugins/tables/getTable/schemas.js +15 -0
  83. package/dist/plugins/tables/getTableRecord/index.d.ts +18 -0
  84. package/dist/plugins/tables/getTableRecord/index.d.ts.map +1 -0
  85. package/dist/plugins/tables/getTableRecord/index.js +60 -0
  86. package/dist/plugins/tables/getTableRecord/schemas.d.ts +51 -0
  87. package/dist/plugins/tables/getTableRecord/schemas.d.ts.map +1 -0
  88. package/dist/plugins/tables/getTableRecord/schemas.js +44 -0
  89. package/dist/plugins/tables/listTableFields/index.d.ts +18 -0
  90. package/dist/plugins/tables/listTableFields/index.d.ts.map +1 -0
  91. package/dist/plugins/tables/listTableFields/index.js +58 -0
  92. package/dist/plugins/tables/listTableFields/schemas.d.ts +180 -0
  93. package/dist/plugins/tables/listTableFields/schemas.d.ts.map +1 -0
  94. package/dist/plugins/tables/listTableFields/schemas.js +77 -0
  95. package/dist/plugins/tables/listTableRecords/index.d.ts +24 -0
  96. package/dist/plugins/tables/listTableRecords/index.d.ts.map +1 -0
  97. package/dist/plugins/tables/listTableRecords/index.js +97 -0
  98. package/dist/plugins/tables/listTableRecords/schemas.d.ts +120 -0
  99. package/dist/plugins/tables/listTableRecords/schemas.d.ts.map +1 -0
  100. package/dist/plugins/tables/listTableRecords/schemas.js +74 -0
  101. package/dist/plugins/tables/listTables/index.d.ts +24 -0
  102. package/dist/plugins/tables/listTables/index.d.ts.map +1 -0
  103. package/dist/plugins/tables/listTables/index.js +85 -0
  104. package/dist/plugins/tables/listTables/schemas.d.ts +78 -0
  105. package/dist/plugins/tables/listTables/schemas.d.ts.map +1 -0
  106. package/dist/plugins/tables/listTables/schemas.js +63 -0
  107. package/dist/plugins/tables/updateTableRecords/index.d.ts +18 -0
  108. package/dist/plugins/tables/updateTableRecords/index.d.ts.map +1 -0
  109. package/dist/plugins/tables/updateTableRecords/index.js +68 -0
  110. package/dist/plugins/tables/updateTableRecords/schemas.d.ts +59 -0
  111. package/dist/plugins/tables/updateTableRecords/schemas.d.ts.map +1 -0
  112. package/dist/plugins/tables/updateTableRecords/schemas.js +35 -0
  113. package/dist/plugins/tables/utils.d.ts +63 -0
  114. package/dist/plugins/tables/utils.d.ts.map +1 -0
  115. package/dist/plugins/tables/utils.js +262 -0
  116. package/dist/resolvers/index.d.ts +8 -0
  117. package/dist/resolvers/index.d.ts.map +1 -1
  118. package/dist/resolvers/index.js +8 -0
  119. package/dist/resolvers/tableFieldIds.d.ts +6 -0
  120. package/dist/resolvers/tableFieldIds.d.ts.map +1 -0
  121. package/dist/resolvers/tableFieldIds.js +19 -0
  122. package/dist/resolvers/tableFields.d.ts +3 -0
  123. package/dist/resolvers/tableFields.d.ts.map +1 -0
  124. package/dist/resolvers/tableFields.js +31 -0
  125. package/dist/resolvers/tableFilters.d.ts +5 -0
  126. package/dist/resolvers/tableFilters.d.ts.map +1 -0
  127. package/dist/resolvers/tableFilters.js +74 -0
  128. package/dist/resolvers/tableId.d.ts +4 -0
  129. package/dist/resolvers/tableId.d.ts.map +1 -0
  130. package/dist/resolvers/tableId.js +19 -0
  131. package/dist/resolvers/tableName.d.ts +3 -0
  132. package/dist/resolvers/tableName.d.ts.map +1 -0
  133. package/dist/resolvers/tableName.js +5 -0
  134. package/dist/resolvers/tableRecordId.d.ts +9 -0
  135. package/dist/resolvers/tableRecordId.d.ts.map +1 -0
  136. package/dist/resolvers/tableRecordId.js +48 -0
  137. package/dist/resolvers/tableRecords.d.ts +8 -0
  138. package/dist/resolvers/tableRecords.d.ts.map +1 -0
  139. package/dist/resolvers/tableRecords.js +77 -0
  140. package/dist/resolvers/tableSort.d.ts +5 -0
  141. package/dist/resolvers/tableSort.d.ts.map +1 -0
  142. package/dist/resolvers/tableSort.js +43 -0
  143. package/dist/sdk.d.ts +73 -1
  144. package/dist/sdk.d.ts.map +1 -1
  145. package/dist/sdk.js +25 -0
  146. package/dist/types/sdk.d.ts +16 -1
  147. package/dist/types/sdk.d.ts.map +1 -1
  148. package/dist/utils/function-utils.d.ts +2 -2
  149. package/dist/utils/function-utils.d.ts.map +1 -1
  150. package/dist/utils/function-utils.js +2 -3
  151. package/dist/utils/pagination-utils.d.ts +24 -0
  152. package/dist/utils/pagination-utils.d.ts.map +1 -1
  153. package/dist/utils/pagination-utils.js +78 -0
  154. package/dist/utils/schema-utils.d.ts +33 -5
  155. package/dist/utils/schema-utils.d.ts.map +1 -1
  156. package/package.json +7 -2
package/dist/index.mjs CHANGED
@@ -42,6 +42,7 @@ function isPositional(schema) {
42
42
  // src/constants.ts
43
43
  var ZAPIER_BASE_URL = process.env.ZAPIER_BASE_URL || "https://zapier.com";
44
44
  var MAX_PAGE_LIMIT = 1e4;
45
+ var DEFAULT_PAGE_SIZE = 100;
45
46
  var DEFAULT_ACTION_TIMEOUT_MS = 18e4;
46
47
  function parseIntEnvVar(name) {
47
48
  const value = process.env[name];
@@ -810,6 +811,68 @@ async function* paginateBuffered(pageFunction, pageOptions) {
810
811
  }
811
812
  }
812
813
  var paginate = paginateBuffered;
814
+ function concatPaginated({
815
+ sources,
816
+ dedupe,
817
+ pageSize = 100
818
+ }) {
819
+ if (sources.length === 0) {
820
+ const empty = { data: [] };
821
+ return Object.assign(Promise.resolve(empty), {
822
+ [Symbol.asyncIterator]: async function* () {
823
+ yield empty;
824
+ }
825
+ });
826
+ }
827
+ let sourceIndex = 0;
828
+ let currentIterator = null;
829
+ const seen = /* @__PURE__ */ new Set();
830
+ const pageFunction = async (_options) => {
831
+ while (sourceIndex < sources.length) {
832
+ if (!currentIterator) {
833
+ const result = sources[sourceIndex]();
834
+ currentIterator = result[Symbol.asyncIterator]();
835
+ }
836
+ const next = await currentIterator.next();
837
+ if (next.done) {
838
+ sourceIndex++;
839
+ currentIterator = null;
840
+ continue;
841
+ }
842
+ let items = next.value.data;
843
+ if (dedupe) {
844
+ if (sourceIndex > 0) {
845
+ items = items.filter((item) => !seen.has(dedupe(item)));
846
+ }
847
+ for (const item of items) {
848
+ seen.add(dedupe(item));
849
+ }
850
+ }
851
+ const hasMoreInSource = next.value.nextCursor != null;
852
+ const hasMoreSources = sourceIndex < sources.length - 1;
853
+ return {
854
+ data: items,
855
+ nextCursor: hasMoreInSource || hasMoreSources ? "__has_more__" : void 0
856
+ };
857
+ }
858
+ return { data: [] };
859
+ };
860
+ const iterator = paginateBuffered(pageFunction, { pageSize });
861
+ const firstPagePromise = iterator.next().then((result) => {
862
+ if (result.done) {
863
+ return { data: [] };
864
+ }
865
+ return result.value;
866
+ });
867
+ return Object.assign(firstPagePromise, {
868
+ [Symbol.asyncIterator]: async function* () {
869
+ yield await firstPagePromise;
870
+ for await (const page of { [Symbol.asyncIterator]: () => iterator }) {
871
+ yield page;
872
+ }
873
+ }
874
+ });
875
+ }
813
876
 
814
877
  // src/utils/validation.ts
815
878
  var validate = (schema, input) => {
@@ -960,7 +1023,7 @@ function createPageFunction(coreFn) {
960
1023
  };
961
1024
  return namedFunctions[functionName];
962
1025
  }
963
- function createPaginatedFunction(coreFn, schema, telemetry, explicitFunctionName) {
1026
+ function createPaginatedFunction(coreFn, schema, telemetry, explicitFunctionName, defaultPageSize) {
964
1027
  const pageFunction = createPageFunction(coreFn);
965
1028
  const functionName = explicitFunctionName || coreFn.name;
966
1029
  const validator = schema ? createValidator(schema) : null;
@@ -974,7 +1037,7 @@ function createPaginatedFunction(coreFn, schema, telemetry, explicitFunctionName
974
1037
  ...normalizedOptions,
975
1038
  ...validator ? validator(normalizedOptions) : normalizedOptions
976
1039
  };
977
- const pageSize = validatedOptions.pageSize || 100;
1040
+ const pageSize = validatedOptions.pageSize ?? defaultPageSize;
978
1041
  const optimizedOptions = {
979
1042
  ...validatedOptions,
980
1043
  pageSize
@@ -1148,7 +1211,9 @@ var listAppsPlugin = ({ context }) => {
1148
1211
  searchParams: {
1149
1212
  appKeys: implementationIds.join(","),
1150
1213
  ...options.search && { search: options.search },
1151
- pageSize: options.pageSize.toString(),
1214
+ ...options.pageSize !== void 0 && {
1215
+ pageSize: options.pageSize.toString()
1216
+ },
1152
1217
  ...options.cursor && { offset: options.cursor }
1153
1218
  }
1154
1219
  });
@@ -1158,7 +1223,8 @@ var listAppsPlugin = ({ context }) => {
1158
1223
  listAppsPage,
1159
1224
  ListAppsSchema,
1160
1225
  createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
1161
- methodName
1226
+ methodName,
1227
+ DEFAULT_PAGE_SIZE
1162
1228
  );
1163
1229
  return {
1164
1230
  listApps: listAppsDefinition,
@@ -1841,6 +1907,625 @@ var clientIdResolver = {
1841
1907
  })
1842
1908
  };
1843
1909
 
1910
+ // src/resolvers/tableId.ts
1911
+ var tableIdResolver = {
1912
+ type: "dynamic",
1913
+ fetch: (sdk) => {
1914
+ return concatPaginated({
1915
+ sources: [() => sdk.listTables({ owner: "me" }), () => sdk.listTables()],
1916
+ dedupe: (table) => table.id
1917
+ });
1918
+ },
1919
+ prompt: (tables) => ({
1920
+ type: "list",
1921
+ name: "tableId",
1922
+ message: "Select a table:",
1923
+ choices: tables.map((table) => ({
1924
+ name: `${table.name} (${table.id})`,
1925
+ value: table.id
1926
+ }))
1927
+ })
1928
+ };
1929
+ function formatFieldValue(v) {
1930
+ if (v == null) return "";
1931
+ if (typeof v === "object") {
1932
+ try {
1933
+ return JSON.stringify(v);
1934
+ } catch {
1935
+ return String(v);
1936
+ }
1937
+ }
1938
+ return String(v);
1939
+ }
1940
+ function toNumericFieldId(id) {
1941
+ if (typeof id === "number") return id;
1942
+ const num = parseInt(id.replace(/^f/, ""), 10);
1943
+ if (isNaN(num)) {
1944
+ throw new ZapierValidationError(
1945
+ `Invalid field ID: "${id}". Expected a numeric ID like "f6", "6", or 6.`
1946
+ );
1947
+ }
1948
+ return num;
1949
+ }
1950
+ function transformTableItem(apiItem) {
1951
+ return {
1952
+ id: apiItem.id,
1953
+ name: apiItem.name,
1954
+ description: apiItem.description ?? void 0,
1955
+ created_at: apiItem.created_at,
1956
+ edited_at: apiItem.edited_at,
1957
+ kind: apiItem.kind,
1958
+ owner_account_id: String(apiItem.owner_account_id),
1959
+ profile_id: String(apiItem.owner_zapier_customuser_id),
1960
+ parent_table_id: apiItem.parent_table_id ?? void 0
1961
+ };
1962
+ }
1963
+ function transformFieldItem(apiItem) {
1964
+ return {
1965
+ id: `f${apiItem.id}`,
1966
+ type: apiItem.type,
1967
+ name: apiItem.name,
1968
+ created_at: apiItem.created_at,
1969
+ edited_at: apiItem.edited_at,
1970
+ options: apiItem.options,
1971
+ config: apiItem.config
1972
+ };
1973
+ }
1974
+ function transformRecordItem(apiItem) {
1975
+ return {
1976
+ id: apiItem.id,
1977
+ data: apiItem.data,
1978
+ created_at: apiItem.created_at,
1979
+ edited_at: apiItem.edited_at
1980
+ };
1981
+ }
1982
+ function formatRecordError(fieldId, err) {
1983
+ const message = err.h || err.e || "validation error";
1984
+ if (err.v !== void 0) {
1985
+ return `Field ${fieldId}: ${message} (value: ${JSON.stringify(err.v)})`;
1986
+ }
1987
+ return `Field ${fieldId}: ${message}`;
1988
+ }
1989
+ function formatResponseError(err) {
1990
+ const message = err.human_title || err.title || "Unknown error";
1991
+ if (err.meta && Object.keys(err.meta).length > 0) {
1992
+ const metaParts = Object.entries(err.meta).map(([key, val]) => `${key}: ${JSON.stringify(val)}`).join(", ");
1993
+ return `${message} (${metaParts})`;
1994
+ }
1995
+ return message;
1996
+ }
1997
+ function throwOnRecordErrors(record) {
1998
+ if (!record.errors) return;
1999
+ const messages = [];
2000
+ for (const [fieldId, error] of Object.entries(record.errors)) {
2001
+ const err = error;
2002
+ if (err.s === "error") {
2003
+ messages.push(formatRecordError(fieldId, err));
2004
+ }
2005
+ }
2006
+ if (messages.length > 0) {
2007
+ throw new ZapierValidationError(
2008
+ `Record ${record.id} has errors: ${messages.join("; ")}`
2009
+ );
2010
+ }
2011
+ }
2012
+ function throwOnResponseErrors(response) {
2013
+ const errors = response.meta?.errors;
2014
+ if (!errors || errors.length === 0) return;
2015
+ const messages = errors.map(
2016
+ (err) => formatResponseError(err)
2017
+ );
2018
+ throw new ZapierValidationError(messages.join("; "));
2019
+ }
2020
+ var KeyModeSchema = z.enum(["names", "ids"]).optional().default("names").describe(
2021
+ 'How to interpret field keys in record data. "names" (default) uses human-readable field names, "ids" uses raw field IDs (f1, f2).'
2022
+ );
2023
+ var FIELD_ID_PATTERN = /^f\d+$/;
2024
+ function isFieldId(key) {
2025
+ return FIELD_ID_PATTERN.test(key);
2026
+ }
2027
+ var NESTED_COMPONENTS = {
2028
+ labeled_string: /* @__PURE__ */ new Set(["value"]),
2029
+ ai_formula: /* @__PURE__ */ new Set(["value"]),
2030
+ link: /* @__PURE__ */ new Set(["link", "text"]),
2031
+ linked_record: /* @__PURE__ */ new Set(["label", "source"])
2032
+ };
2033
+ async function getFieldMapping(api, tableId, keyMode) {
2034
+ if (keyMode === "ids") {
2035
+ return null;
2036
+ }
2037
+ const rawResponse = await api.get(`/tables/api/v1/tables/${tableId}/fields`, {
2038
+ authRequired: true
2039
+ });
2040
+ const data = rawResponse.data;
2041
+ const nameToId = /* @__PURE__ */ new Map();
2042
+ const idToName = /* @__PURE__ */ new Map();
2043
+ const idToType = /* @__PURE__ */ new Map();
2044
+ for (const field of data) {
2045
+ const id = `f${field.id}`;
2046
+ if (!nameToId.has(field.name)) {
2047
+ nameToId.set(field.name, id);
2048
+ }
2049
+ if (!idToName.has(id)) {
2050
+ idToName.set(id, field.name);
2051
+ }
2052
+ idToType.set(id, field.type);
2053
+ }
2054
+ return { nameToId, idToName, idToType };
2055
+ }
2056
+ async function resolveFieldKeys({
2057
+ api,
2058
+ tableId,
2059
+ fieldKeys
2060
+ }) {
2061
+ const allAreIds = fieldKeys.every(
2062
+ (key) => typeof key === "number" || /^(f?\d+)$/.test(key)
2063
+ );
2064
+ if (allAreIds) {
2065
+ return fieldKeys.map(toNumericFieldId);
2066
+ }
2067
+ const mapping = await getFieldMapping(api, tableId, "names");
2068
+ if (!mapping) {
2069
+ return fieldKeys.map(toNumericFieldId);
2070
+ }
2071
+ return fieldKeys.map((key) => {
2072
+ if (typeof key === "number") return key;
2073
+ if (FIELD_ID_PATTERN.test(key)) return toNumericFieldId(key);
2074
+ const id = mapping.nameToId.get(key);
2075
+ if (!id) {
2076
+ throw new ZapierValidationError(
2077
+ `Unknown field name: "${key}". Use a valid field name or ID.`
2078
+ );
2079
+ }
2080
+ return toNumericFieldId(id);
2081
+ });
2082
+ }
2083
+ async function createFieldKeyTranslator({
2084
+ api,
2085
+ tableId,
2086
+ keyMode
2087
+ }) {
2088
+ const mapping = await getFieldMapping(api, tableId, keyMode);
2089
+ return {
2090
+ translateInput(data) {
2091
+ if (!mapping) return data;
2092
+ const result = {};
2093
+ for (const [key, value] of Object.entries(data)) {
2094
+ if (FIELD_ID_PATTERN.test(key) && mapping.idToName.has(key)) {
2095
+ result[key] = value;
2096
+ } else if (mapping.nameToId.has(key)) {
2097
+ result[mapping.nameToId.get(key)] = value;
2098
+ } else {
2099
+ result[key] = value;
2100
+ }
2101
+ }
2102
+ return result;
2103
+ },
2104
+ translateOutput(data) {
2105
+ if (!mapping) return data;
2106
+ const result = {};
2107
+ for (const [key, value] of Object.entries(data)) {
2108
+ if (mapping.idToName.has(key)) {
2109
+ result[mapping.idToName.get(key)] = value;
2110
+ } else {
2111
+ result[key] = value;
2112
+ }
2113
+ }
2114
+ return result;
2115
+ },
2116
+ translateFieldKey(key) {
2117
+ if (!mapping) return key;
2118
+ if (FIELD_ID_PATTERN.test(key) && mapping.idToName.has(key)) {
2119
+ const fieldType = mapping.idToType.get(key);
2120
+ if (fieldType) {
2121
+ const components = NESTED_COMPONENTS[fieldType];
2122
+ if (components?.size === 1) {
2123
+ return `${key}__${[...components][0]}`;
2124
+ }
2125
+ }
2126
+ return key;
2127
+ }
2128
+ if (mapping.nameToId.has(key)) {
2129
+ const fieldId = mapping.nameToId.get(key);
2130
+ const fieldType = mapping.idToType.get(fieldId);
2131
+ if (fieldType) {
2132
+ const components = NESTED_COMPONENTS[fieldType];
2133
+ if (components?.size === 1) {
2134
+ return `${fieldId}__${[...components][0]}`;
2135
+ }
2136
+ }
2137
+ return fieldId;
2138
+ }
2139
+ const sepIndex = key.lastIndexOf("__");
2140
+ if (sepIndex > 0) {
2141
+ const prefix = key.slice(0, sepIndex);
2142
+ const component = key.slice(sepIndex + 2);
2143
+ let fieldId;
2144
+ if (FIELD_ID_PATTERN.test(prefix) && mapping.idToName.has(prefix)) {
2145
+ fieldId = prefix;
2146
+ } else {
2147
+ fieldId = mapping.nameToId.get(prefix);
2148
+ }
2149
+ if (fieldId) {
2150
+ const fieldType = mapping.idToType.get(fieldId);
2151
+ if (fieldType && NESTED_COMPONENTS[fieldType]?.has(component)) {
2152
+ return `${fieldId}__${component}`;
2153
+ }
2154
+ }
2155
+ }
2156
+ return key;
2157
+ }
2158
+ };
2159
+ }
2160
+
2161
+ // src/resolvers/tableRecordId.ts
2162
+ function summarizeRecord(record) {
2163
+ const values = Object.values(record.data);
2164
+ const preview = values.slice(0, 3).map((v) => formatFieldValue(v).replace(/\s+/g, " ").trim()).filter((s) => s.length > 0).join(", ");
2165
+ const truncated = preview.length > 60 ? preview.slice(0, 57) + "..." : preview;
2166
+ return truncated ? `${record.id} \u2014 ${truncated}` : record.id;
2167
+ }
2168
+ function fetchRecords(sdk, params) {
2169
+ return sdk.listTableRecords({
2170
+ tableId: params.tableId,
2171
+ keyMode: "names"
2172
+ });
2173
+ }
2174
+ function recordChoices(records) {
2175
+ return records.map((record) => ({
2176
+ name: summarizeRecord(record),
2177
+ value: record.id
2178
+ }));
2179
+ }
2180
+ var tableRecordIdResolver = {
2181
+ type: "dynamic",
2182
+ depends: ["tableId"],
2183
+ fetch: fetchRecords,
2184
+ prompt: (records) => ({
2185
+ type: "list",
2186
+ name: "recordId",
2187
+ message: "Select a record:",
2188
+ choices: recordChoices(records)
2189
+ })
2190
+ };
2191
+ var tableRecordIdsResolver = {
2192
+ type: "dynamic",
2193
+ depends: ["tableId"],
2194
+ fetch: fetchRecords,
2195
+ prompt: (records) => ({
2196
+ type: "checkbox",
2197
+ name: "recordIds",
2198
+ message: "Select records to delete:",
2199
+ choices: recordChoices(records),
2200
+ validate: (value) => Array.isArray(value) && value.length > 0 ? true : "Select at least one record"
2201
+ })
2202
+ };
2203
+
2204
+ // src/resolvers/tableFieldIds.ts
2205
+ var tableFieldIdsResolver = {
2206
+ type: "dynamic",
2207
+ depends: ["tableId"],
2208
+ fetch: (sdk, params) => {
2209
+ return sdk.listTableFields({ tableId: params.tableId });
2210
+ },
2211
+ prompt: (fields) => ({
2212
+ type: "checkbox",
2213
+ name: "fieldKeys",
2214
+ message: "Select fields:",
2215
+ choices: fields.map((field) => ({
2216
+ name: `${field.name} (${field.id}, ${field.type})`,
2217
+ value: field.id
2218
+ })),
2219
+ validate: (value) => Array.isArray(value) && value.length > 0 ? true : "Select at least one field"
2220
+ })
2221
+ };
2222
+
2223
+ // src/resolvers/tableName.ts
2224
+ var tableNameResolver = {
2225
+ type: "static",
2226
+ inputType: "text",
2227
+ placeholder: "Enter a name for the table"
2228
+ };
2229
+ var FieldTypeSchema = z.enum([
2230
+ "string",
2231
+ "multiple_string",
2232
+ "labeled_string",
2233
+ "multiple_labeled_string",
2234
+ "text",
2235
+ "multiple_text",
2236
+ "boolean",
2237
+ "multiple_boolean",
2238
+ "number",
2239
+ "multiple_number",
2240
+ "decimal",
2241
+ "multiple_decimal",
2242
+ "datetime",
2243
+ "multiple_datetime",
2244
+ "uuid",
2245
+ "multiple_uuid",
2246
+ "json",
2247
+ "multiple_json",
2248
+ "formula",
2249
+ "button_trigger_zap",
2250
+ "button_continue_zap",
2251
+ "email",
2252
+ "multiple_email",
2253
+ "link",
2254
+ "multiple_link",
2255
+ "currency",
2256
+ "phone_number",
2257
+ "ai_formula",
2258
+ "linked_record",
2259
+ "multiple_linked_record"
2260
+ ]);
2261
+ var FieldApiItemSchema = z.object({
2262
+ id: z.number(),
2263
+ type: FieldTypeSchema,
2264
+ name: z.string(),
2265
+ created_at: z.string().optional(),
2266
+ edited_at: z.string().optional(),
2267
+ options: z.record(z.string(), z.unknown()).optional(),
2268
+ config: z.record(z.string(), z.unknown()).optional(),
2269
+ is_order_field: z.boolean().optional(),
2270
+ is_filter_field: z.boolean().optional(),
2271
+ is_selected_field: z.boolean().optional()
2272
+ });
2273
+ var ListTableFieldsApiResponseSchema = z.object({
2274
+ data: z.array(FieldApiItemSchema)
2275
+ });
2276
+ var FieldItemSchemaBase = z.object({
2277
+ id: z.string(),
2278
+ type: FieldTypeSchema,
2279
+ name: z.string(),
2280
+ created_at: z.string().optional(),
2281
+ edited_at: z.string().optional(),
2282
+ options: z.record(z.string(), z.unknown()).optional(),
2283
+ config: z.record(z.string(), z.unknown()).optional()
2284
+ });
2285
+ var FieldItemSchema = withFormatter(FieldItemSchemaBase, {
2286
+ format: (item) => ({
2287
+ title: item.name,
2288
+ id: item.id,
2289
+ details: [{ text: `Type: ${item.type}`, style: "dim" }]
2290
+ })
2291
+ });
2292
+ var ListTableFieldsOptionsSchema = z.object({
2293
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
2294
+ fieldKeys: z.array(z.union([z.string(), z.number()])).optional().describe(
2295
+ 'Filter by specific fields. Accepts field names (e.g., "Email") or IDs (e.g., "f6", "6", or 6).'
2296
+ )
2297
+ }).describe("List fields for a table");
2298
+
2299
+ // src/resolvers/tableFields.ts
2300
+ var fieldTypeChoices = FieldTypeSchema.options.map((type) => ({
2301
+ label: type,
2302
+ value: type
2303
+ }));
2304
+ var singleFieldResolver = {
2305
+ type: "fields",
2306
+ fetch: async () => {
2307
+ return [
2308
+ {
2309
+ type: "input_field",
2310
+ key: "type",
2311
+ title: "Field type",
2312
+ is_required: true,
2313
+ choices: fieldTypeChoices
2314
+ },
2315
+ {
2316
+ type: "input_field",
2317
+ key: "name",
2318
+ title: "Field name",
2319
+ is_required: true
2320
+ }
2321
+ ];
2322
+ }
2323
+ };
2324
+ var tableFieldsResolver = {
2325
+ type: "array",
2326
+ fetch: async () => singleFieldResolver,
2327
+ minItems: 1
2328
+ };
2329
+
2330
+ // src/resolvers/tableRecords.ts
2331
+ function tableFieldValueType(fieldType) {
2332
+ if (fieldType.startsWith("multiple_")) return "array";
2333
+ switch (fieldType) {
2334
+ case "number":
2335
+ case "decimal":
2336
+ case "currency":
2337
+ return "number";
2338
+ case "boolean":
2339
+ return "boolean";
2340
+ default:
2341
+ return void 0;
2342
+ }
2343
+ }
2344
+ function createSingleRecordResolver({
2345
+ sdk,
2346
+ tableId,
2347
+ includeRecordId
2348
+ }) {
2349
+ return {
2350
+ type: "fields",
2351
+ fetch: async () => {
2352
+ const { data: fields } = await sdk.listTableFields({ tableId });
2353
+ const inputFields = fields.map((field) => ({
2354
+ type: "input_field",
2355
+ key: field.id,
2356
+ title: field.name,
2357
+ is_required: false,
2358
+ ...tableFieldValueType(field.type) && {
2359
+ value_type: tableFieldValueType(field.type)
2360
+ }
2361
+ }));
2362
+ if (includeRecordId) {
2363
+ return [
2364
+ {
2365
+ type: "input_field",
2366
+ key: "_record_id",
2367
+ title: "Record",
2368
+ is_required: true,
2369
+ resolver: tableRecordIdResolver
2370
+ },
2371
+ ...inputFields
2372
+ ];
2373
+ }
2374
+ return inputFields;
2375
+ },
2376
+ transform: (values) => {
2377
+ if (includeRecordId) {
2378
+ const { _record_id: id, ...data } = values;
2379
+ return { id, data };
2380
+ }
2381
+ return { data: values };
2382
+ }
2383
+ };
2384
+ }
2385
+ var tableRecordsResolver = {
2386
+ type: "array",
2387
+ depends: ["tableId"],
2388
+ fetch: async (sdk, params) => {
2389
+ return createSingleRecordResolver({
2390
+ sdk,
2391
+ tableId: params.tableId
2392
+ });
2393
+ },
2394
+ minItems: 1
2395
+ };
2396
+ var tableUpdateRecordsResolver = {
2397
+ type: "array",
2398
+ depends: ["tableId"],
2399
+ fetch: async (sdk, params) => {
2400
+ return createSingleRecordResolver({
2401
+ sdk,
2402
+ tableId: params.tableId,
2403
+ includeRecordId: true
2404
+ });
2405
+ },
2406
+ minItems: 1
2407
+ };
2408
+
2409
+ // src/resolvers/tableFilters.ts
2410
+ var FILTER_OPERATORS = [
2411
+ { label: "equals", value: "exact" },
2412
+ { label: "not equals", value: "different" },
2413
+ { label: "contains", value: "contains" },
2414
+ { label: "contains (case-insensitive)", value: "icontains" },
2415
+ { label: "starts with", value: "startswith" },
2416
+ { label: "search", value: "search" },
2417
+ { label: "greater than", value: "gt" },
2418
+ { label: "greater than or equal", value: "gte" },
2419
+ { label: "less than", value: "lt" },
2420
+ { label: "less than or equal", value: "lte" },
2421
+ { label: "in range", value: "range" },
2422
+ { label: "in list", value: "in" },
2423
+ { label: "is empty", value: "isnull" },
2424
+ { label: "is within (date)", value: "is_within" }
2425
+ ];
2426
+ function createSingleFilterResolver({
2427
+ sdk,
2428
+ tableId
2429
+ }) {
2430
+ return {
2431
+ type: "fields",
2432
+ fetch: async () => {
2433
+ const { data: fields } = await sdk.listTableFields({ tableId });
2434
+ const fieldChoices = fields.flatMap((field) => {
2435
+ const components = NESTED_COMPONENTS[field.type];
2436
+ if (components && components.size > 1) {
2437
+ return [...components].map((component) => ({
2438
+ label: `${field.name}__${component} (${field.id}, ${field.type})`,
2439
+ value: `${field.name}__${component}`
2440
+ }));
2441
+ }
2442
+ return {
2443
+ label: `${field.name} (${field.id}${components ? `, ${field.type}` : ""})`,
2444
+ value: components ? `${field.name}__${[...components][0]}` : field.name
2445
+ };
2446
+ });
2447
+ const fieldItems = [
2448
+ {
2449
+ type: "input_field",
2450
+ key: "fieldKey",
2451
+ title: "Field",
2452
+ is_required: true,
2453
+ choices: fieldChoices
2454
+ },
2455
+ {
2456
+ type: "input_field",
2457
+ key: "operator",
2458
+ title: "Operator",
2459
+ is_required: true,
2460
+ choices: FILTER_OPERATORS
2461
+ },
2462
+ {
2463
+ type: "input_field",
2464
+ key: "value",
2465
+ title: "Value",
2466
+ is_required: false
2467
+ }
2468
+ ];
2469
+ return fieldItems;
2470
+ }
2471
+ };
2472
+ }
2473
+ var tableFiltersResolver = {
2474
+ type: "array",
2475
+ depends: ["tableId"],
2476
+ fetch: async (sdk, params) => {
2477
+ return createSingleFilterResolver({
2478
+ sdk,
2479
+ tableId: params.tableId
2480
+ });
2481
+ },
2482
+ minItems: 0
2483
+ };
2484
+
2485
+ // src/resolvers/tableSort.ts
2486
+ var tableSortResolver = {
2487
+ type: "fields",
2488
+ depends: ["tableId"],
2489
+ fetch: async (sdk, params) => {
2490
+ const { data: fields } = await sdk.listTableFields({
2491
+ tableId: params.tableId
2492
+ });
2493
+ const fieldChoices = fields.flatMap((field) => {
2494
+ const components = NESTED_COMPONENTS[field.type];
2495
+ if (components) {
2496
+ return [...components].map((component) => ({
2497
+ label: `${field.name}__${component} (${field.id}, ${field.type})`,
2498
+ value: `${field.name}__${component}`
2499
+ }));
2500
+ }
2501
+ return {
2502
+ label: `${field.name} (${field.id})`,
2503
+ value: field.name
2504
+ };
2505
+ });
2506
+ const fieldItems = [
2507
+ {
2508
+ type: "input_field",
2509
+ key: "fieldKey",
2510
+ title: "Field",
2511
+ is_required: true,
2512
+ choices: fieldChoices
2513
+ },
2514
+ {
2515
+ type: "input_field",
2516
+ key: "direction",
2517
+ title: "Direction",
2518
+ is_required: true,
2519
+ choices: [
2520
+ { label: "Ascending", value: "asc" },
2521
+ { label: "Descending", value: "desc" }
2522
+ ]
2523
+ }
2524
+ ];
2525
+ return fieldItems;
2526
+ }
2527
+ };
2528
+
1844
2529
  // src/plugins/listActions/index.ts
1845
2530
  var listActionsPlugin = ({ context }) => {
1846
2531
  const methodMeta = {
@@ -1920,7 +2605,8 @@ var listActionsPlugin = ({ context }) => {
1920
2605
  listActionsPage,
1921
2606
  ListActionsSchema,
1922
2607
  createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
1923
- methodName
2608
+ methodName,
2609
+ DEFAULT_PAGE_SIZE
1924
2610
  );
1925
2611
  return {
1926
2612
  listActions: listActionsDefinition,
@@ -2277,7 +2963,8 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
2277
2963
  listInputFieldsPage,
2278
2964
  ListInputFieldsSchema,
2279
2965
  createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
2280
- methodName
2966
+ methodName,
2967
+ DEFAULT_PAGE_SIZE
2281
2968
  );
2282
2969
  return {
2283
2970
  listInputFields: listInputFieldsDefinition,
@@ -2363,9 +3050,10 @@ var ConnectionItemSchema = withFormatter(ConnectionItemSchema$1, {
2363
3050
  var listConnectionsPlugin = ({ context }) => {
2364
3051
  async function listConnectionsPage(options) {
2365
3052
  const { api, getVersionedImplementationId } = context;
2366
- const searchParams = {
2367
- page_size: options.pageSize.toString()
2368
- };
3053
+ const searchParams = {};
3054
+ if (options.pageSize !== void 0) {
3055
+ searchParams.page_size = options.pageSize.toString();
3056
+ }
2369
3057
  if (options.appKey) {
2370
3058
  const implementationId = await getVersionedImplementationId(
2371
3059
  options.appKey
@@ -2429,7 +3117,8 @@ var listConnectionsPlugin = ({ context }) => {
2429
3117
  listConnectionsPage,
2430
3118
  ListConnectionsQuerySchema,
2431
3119
  createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
2432
- methodName
3120
+ methodName,
3121
+ DEFAULT_PAGE_SIZE
2433
3122
  );
2434
3123
  return {
2435
3124
  listConnections: listConnectionsDefinition,
@@ -2507,9 +3196,10 @@ var ClientCredentialsCreatedItemSchema = withFormatter(
2507
3196
  var listClientCredentialsPlugin = ({ context }) => {
2508
3197
  async function listClientCredentialsPage(options) {
2509
3198
  const { api } = context;
2510
- const searchParams = {
2511
- pageSize: options.pageSize.toString()
2512
- };
3199
+ const searchParams = {};
3200
+ if (options.pageSize !== void 0) {
3201
+ searchParams.pageSize = options.pageSize.toString();
3202
+ }
2513
3203
  if (options.cursor) {
2514
3204
  searchParams.offset = options.cursor;
2515
3205
  }
@@ -2543,7 +3233,8 @@ var listClientCredentialsPlugin = ({ context }) => {
2543
3233
  listClientCredentialsPage,
2544
3234
  ListClientCredentialsQuerySchema,
2545
3235
  createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
2546
- methodName
3236
+ methodName,
3237
+ DEFAULT_PAGE_SIZE
2547
3238
  );
2548
3239
  return {
2549
3240
  listClientCredentials: listClientCredentialsDefinition,
@@ -2633,25 +3324,29 @@ var DeleteClientCredentialsSchema = z.object({
2633
3324
  var deleteClientCredentialsPlugin = ({ context }) => {
2634
3325
  async function deleteClientCredentials(options) {
2635
3326
  const { api } = context;
2636
- await api.delete(`/api/v0/client-credentials/${options.clientId}`, {
2637
- customErrorHandler: ({ status }) => {
2638
- if (status === 401) {
2639
- return new ZapierAuthenticationError(
2640
- `Authentication failed. Your token may not have permission to delete client credentials or may be expired. (HTTP ${status})`,
2641
- { statusCode: status }
2642
- );
2643
- }
2644
- if (status === 403) {
2645
- return new ZapierAuthenticationError(
2646
- `Access forbidden. Your token may not have the required scopes to delete client credentials. (HTTP ${status})`,
2647
- { statusCode: status }
2648
- );
2649
- }
2650
- return void 0;
2651
- },
2652
- authRequired: true,
2653
- requiredScopes: ["credentials"]
2654
- });
3327
+ await api.delete(
3328
+ `/api/v0/client-credentials/${options.clientId}`,
3329
+ void 0,
3330
+ {
3331
+ customErrorHandler: ({ status }) => {
3332
+ if (status === 401) {
3333
+ return new ZapierAuthenticationError(
3334
+ `Authentication failed. Your token may not have permission to delete client credentials or may be expired. (HTTP ${status})`,
3335
+ { statusCode: status }
3336
+ );
3337
+ }
3338
+ if (status === 403) {
3339
+ return new ZapierAuthenticationError(
3340
+ `Access forbidden. Your token may not have the required scopes to delete client credentials. (HTTP ${status})`,
3341
+ { statusCode: status }
3342
+ );
3343
+ }
3344
+ return void 0;
3345
+ },
3346
+ authRequired: true,
3347
+ requiredScopes: ["credentials"]
3348
+ }
3349
+ );
2655
3350
  return {
2656
3351
  success: true
2657
3352
  };
@@ -2958,6 +3653,7 @@ async function executeAction(actionOptions) {
2958
3653
  actionKey,
2959
3654
  actionType,
2960
3655
  executionOptions,
3656
+ cursor,
2961
3657
  connectionId,
2962
3658
  timeoutMs
2963
3659
  } = actionOptions;
@@ -2971,6 +3667,9 @@ async function executeAction(actionOptions) {
2971
3667
  if (connectionId !== null && connectionId !== void 0) {
2972
3668
  runRequestData.authentication_id = connectionId;
2973
3669
  }
3670
+ if (cursor) {
3671
+ runRequestData.page = cursor;
3672
+ }
2974
3673
  const runRequest = {
2975
3674
  data: runRequestData
2976
3675
  };
@@ -2990,19 +3689,52 @@ async function executeAction(actionOptions) {
2990
3689
  resultExtractor: (result) => result.data
2991
3690
  });
2992
3691
  }
3692
+ var CONTEXT_CACHE_TTL_MS = 6e4;
3693
+ var CONTEXT_CACHE_MAX_SIZE = 500;
2993
3694
  var runActionPlugin = ({ sdk, context }) => {
2994
- async function runActionPage(options) {
2995
- const { api } = context;
2996
- const {
2997
- appKey,
2998
- actionKey,
2999
- actionType,
3000
- connectionId,
3001
- authenticationId,
3002
- inputs = {},
3003
- timeoutMs
3004
- } = options;
3005
- const resolvedConnectionId = connectionId ?? authenticationId;
3695
+ const runActionContextCache = /* @__PURE__ */ new Map();
3696
+ function evictIfNeeded() {
3697
+ if (runActionContextCache.size < CONTEXT_CACHE_MAX_SIZE) return;
3698
+ const now = Date.now();
3699
+ let oldestKey;
3700
+ let oldestExpiry = Infinity;
3701
+ let evictedAny = false;
3702
+ for (const [key, entry] of runActionContextCache) {
3703
+ if (now >= entry.expiresAt) {
3704
+ runActionContextCache.delete(key);
3705
+ evictedAny = true;
3706
+ } else if (entry.expiresAt < oldestExpiry) {
3707
+ oldestExpiry = entry.expiresAt;
3708
+ oldestKey = key;
3709
+ }
3710
+ }
3711
+ if (!evictedAny && oldestKey) {
3712
+ runActionContextCache.delete(oldestKey);
3713
+ }
3714
+ }
3715
+ function getRunActionContext(options) {
3716
+ const { appKey, actionKey, actionType } = options;
3717
+ const contextKey = `${appKey}:${actionKey}:${actionType}`;
3718
+ const cached = runActionContextCache.get(contextKey);
3719
+ if (cached && Date.now() < cached.expiresAt) {
3720
+ return cached.promise;
3721
+ }
3722
+ const pendingContext = resolveRunActionContext(options).catch((error) => {
3723
+ const current = runActionContextCache.get(contextKey);
3724
+ if (current?.promise === pendingContext) {
3725
+ runActionContextCache.delete(contextKey);
3726
+ }
3727
+ throw error;
3728
+ });
3729
+ evictIfNeeded();
3730
+ runActionContextCache.set(contextKey, {
3731
+ promise: pendingContext,
3732
+ expiresAt: Date.now() + CONTEXT_CACHE_TTL_MS
3733
+ });
3734
+ return pendingContext;
3735
+ }
3736
+ async function resolveRunActionContext(options) {
3737
+ const { appKey, actionKey, actionType } = options;
3006
3738
  const selectedApi = await context.getVersionedImplementationId(appKey);
3007
3739
  if (!selectedApi) {
3008
3740
  throw new ZapierConfigurationError(
@@ -3010,11 +3742,6 @@ var runActionPlugin = ({ sdk, context }) => {
3010
3742
  { configType: "current_implementation_id" }
3011
3743
  );
3012
3744
  }
3013
- setMethodMetadata({
3014
- selectedApi,
3015
- operationType: actionType,
3016
- operationKey: actionKey
3017
- });
3018
3745
  const actionData = await sdk.getAction({
3019
3746
  appKey,
3020
3747
  actionKey,
@@ -3025,7 +3752,27 @@ var runActionPlugin = ({ sdk, context }) => {
3025
3752
  `Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`
3026
3753
  );
3027
3754
  }
3028
- const actionId = actionData.data.id;
3755
+ return { selectedApi, actionId: actionData.data.id };
3756
+ }
3757
+ async function runActionPage(options) {
3758
+ const { api } = context;
3759
+ const {
3760
+ appKey,
3761
+ actionKey,
3762
+ actionType,
3763
+ connectionId,
3764
+ authenticationId,
3765
+ inputs = {},
3766
+ cursor,
3767
+ timeoutMs
3768
+ } = options;
3769
+ const resolvedConnectionId = connectionId ?? authenticationId;
3770
+ const { selectedApi, actionId } = await getRunActionContext(options);
3771
+ setMethodMetadata({
3772
+ selectedApi,
3773
+ operationType: actionType,
3774
+ operationKey: actionKey
3775
+ });
3029
3776
  const result = await executeAction({
3030
3777
  api,
3031
3778
  selectedApi,
@@ -3035,6 +3782,7 @@ var runActionPlugin = ({ sdk, context }) => {
3035
3782
  actionKey,
3036
3783
  actionType,
3037
3784
  executionOptions: { inputs },
3785
+ cursor,
3038
3786
  connectionId: resolvedConnectionId,
3039
3787
  timeoutMs
3040
3788
  });
@@ -3049,8 +3797,7 @@ var runActionPlugin = ({ sdk, context }) => {
3049
3797
  }
3050
3798
  return {
3051
3799
  data: result.results || [],
3052
- nextCursor: void 0
3053
- // No pagination implemented yet
3800
+ nextCursor: result.next_page
3054
3801
  };
3055
3802
  }
3056
3803
  const methodName = stripPageSuffix(runActionPage.name);
@@ -4488,6 +5235,11 @@ var pathConfig = {
4488
5235
  "/zapier": {
4489
5236
  authHeader: "Authorization",
4490
5237
  pathPrefix: "/api/v0/sdk/zapier"
5238
+ },
5239
+ // e.g. /tables -> https://sdkapi.zapier.com/api/v0/sdk/tables/...
5240
+ "/tables": {
5241
+ authHeader: "Authorization",
5242
+ pathPrefix: "/api/v0/sdk/tables"
4491
5243
  }
4492
5244
  };
4493
5245
  var ZapierApiClient = class {
@@ -4555,8 +5307,11 @@ var ZapierApiClient = class {
4555
5307
  this.put = async (path, data, options = {}) => {
4556
5308
  return this.fetchJson("PUT", path, data, options);
4557
5309
  };
4558
- this.delete = async (path, options = {}) => {
4559
- return this.fetchJson("DELETE", path, void 0, options);
5310
+ this.patch = async (path, data, options = {}) => {
5311
+ return this.fetchJson("PATCH", path, data, options);
5312
+ };
5313
+ this.delete = async (path, data, options = {}) => {
5314
+ return this.fetchJson("DELETE", path, data, options);
4560
5315
  };
4561
5316
  this.poll = async (path, options = {}) => {
4562
5317
  return pollUntilComplete({
@@ -4960,155 +5715,1237 @@ async function batch(tasks, options = {}) {
4960
5715
  await Promise.all(workers);
4961
5716
  return results;
4962
5717
  }
5718
+ var TableApiItemSchema = z.object({
5719
+ id: z.string(),
5720
+ name: z.string(),
5721
+ description: z.string().nullable().optional(),
5722
+ created_at: z.string(),
5723
+ edited_at: z.string(),
5724
+ kind: z.enum(["table", "virtual_table"]),
5725
+ owner_account_id: z.number(),
5726
+ owner_user_id: z.number().nullable().optional(),
5727
+ owner_zapier_customuser_id: z.number(),
5728
+ parent_table_id: z.string().nullable().optional()
5729
+ });
5730
+ var ListTablesApiResponseSchema = z.object({
5731
+ data: z.array(TableApiItemSchema),
5732
+ links: z.object({
5733
+ next: z.string().nullable().optional()
5734
+ }).optional()
5735
+ });
5736
+ var TableItemSchema = z.object({
5737
+ id: z.string(),
5738
+ name: z.string(),
5739
+ description: z.string().optional(),
5740
+ created_at: z.string(),
5741
+ edited_at: z.string(),
5742
+ kind: z.enum(["table", "virtual_table"]),
5743
+ owner_account_id: z.string(),
5744
+ profile_id: z.string(),
5745
+ parent_table_id: z.string().optional()
5746
+ });
5747
+ var ListTablesOptionsSchema = z.object({
5748
+ tableIds: z.array(z.string()).optional().describe("Filter by specific table IDs"),
5749
+ kind: z.enum(["table", "virtual_table", "both"]).optional().describe("Filter by table type"),
5750
+ search: z.string().optional().describe("Search term to filter tables by name"),
5751
+ owner: z.string().optional().describe(
5752
+ 'Filter by table owner. Use "me" for the current user, or a numeric user ID.'
5753
+ ),
5754
+ pageSize: z.number().min(1).optional().describe("Number of tables per page"),
5755
+ maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
5756
+ cursor: z.string().optional().describe("Cursor to start from")
5757
+ }).describe("List tables available to the authenticated user");
4963
5758
 
4964
- // src/plugins/registry/index.ts
4965
- var registryPlugin = ({ sdk, context }) => {
4966
- const metaKeys = Object.keys(context.meta || {});
4967
- const categoryDefinitions = {
4968
- account: {
4969
- title: "Account"
4970
- },
4971
- app: {
4972
- title: "App",
4973
- titlePlural: "Apps"
4974
- },
4975
- connection: {
4976
- title: "Connection"
4977
- },
4978
- action: {
4979
- title: "Action"
4980
- },
4981
- "client-credentials": {
4982
- title: "Client Credentials",
4983
- titlePlural: "Client Credentials"
4984
- },
4985
- http: {
4986
- title: "HTTP Request"
4987
- },
4988
- utility: {
4989
- title: "Utility",
4990
- titlePlural: "Utilities"
4991
- },
4992
- other: {
4993
- title: "Other"
5759
+ // src/plugins/tables/listTables/index.ts
5760
+ function extractNextCursor(links) {
5761
+ if (!links?.next) {
5762
+ return void 0;
5763
+ }
5764
+ try {
5765
+ const url = new URL(links.next);
5766
+ const offset = url.searchParams.get("offset");
5767
+ return offset || void 0;
5768
+ } catch {
5769
+ return void 0;
5770
+ }
5771
+ }
5772
+ var listTablesPlugin = ({ context }) => {
5773
+ async function listTablesPage(options) {
5774
+ const { api } = context;
5775
+ const searchParams = {};
5776
+ if (options.pageSize !== void 0) {
5777
+ searchParams.limit = options.pageSize.toString();
4994
5778
  }
4995
- };
4996
- const functions = metaKeys.filter((key) => {
4997
- const property = sdk[key];
4998
- if (typeof property === "function") {
4999
- return true;
5779
+ if (options?.tableIds && options.tableIds.length > 0) {
5780
+ searchParams.ids = options.tableIds.join(",");
5000
5781
  }
5001
- const [rootKey] = key.split(".");
5002
- const rootProperty = sdk[rootKey];
5003
- if (typeof rootProperty === "object" && rootProperty !== null) {
5004
- return true;
5782
+ if (options?.kind) {
5783
+ searchParams.kind = options.kind;
5005
5784
  }
5006
- return false;
5007
- }).map((key) => {
5008
- const meta = context.meta[key];
5009
- return {
5010
- name: key,
5011
- description: meta.description,
5012
- type: meta.type,
5013
- itemType: meta.itemType,
5014
- returnType: meta.returnType,
5015
- inputSchema: meta.inputSchema,
5016
- inputParameters: meta.inputParameters,
5017
- outputSchema: meta.outputSchema,
5018
- categories: meta.categories || [],
5019
- resolvers: meta.resolvers,
5020
- packages: meta.packages,
5021
- // Auto-infer confirm: "delete" from type: "delete" (all deletes should confirm)
5022
- confirm: meta.confirm ?? (meta.type === "delete" ? "delete" : void 0),
5023
- deprecation: meta.deprecation,
5024
- deprecatedParameters: meta.deprecatedParameters,
5025
- aliases: meta.aliases,
5026
- supportsJsonOutput: meta.supportsJsonOutput ?? true
5027
- };
5028
- }).sort((a, b) => a.name.localeCompare(b.name));
5029
- const knownCategories = Object.keys(categoryDefinitions);
5030
- const registryCache = /* @__PURE__ */ new Map();
5031
- function getRegistry(options) {
5032
- const packageFilter = options?.package;
5033
- const cacheKey = packageFilter || "__all__";
5034
- if (registryCache.has(cacheKey)) {
5035
- return registryCache.get(cacheKey);
5785
+ if (options?.search) {
5786
+ searchParams.q = options.search;
5036
5787
  }
5037
- const filteredFunctions = packageFilter ? functions.filter(
5038
- (f) => (
5039
- // Include if packages is undefined (belongs to all packages) or includes the specified package
5040
- !f.packages || f.packages.includes(packageFilter)
5041
- )
5042
- ) : functions;
5043
- const filteredCategories = knownCategories.sort((a, b) => {
5044
- if (a === "other") return 1;
5045
- if (b === "other") return -1;
5046
- const titleA = categoryDefinitions[a].title;
5047
- const titleB = categoryDefinitions[b].title;
5048
- return titleA.localeCompare(titleB);
5049
- }).map((categoryKey) => {
5050
- const categoryFunctions = filteredFunctions.filter(
5051
- (f) => f.categories.includes(categoryKey) || // If the category is "other" and the function is not in any other category, include it
5052
- categoryKey === "other" && !f.categories.some((c) => knownCategories.includes(c))
5053
- ).map((f) => f.name).sort();
5054
- const definition = categoryDefinitions[categoryKey];
5055
- const title = definition.title;
5056
- return {
5057
- key: categoryKey,
5058
- title,
5059
- titlePlural: definition.titlePlural ?? `${title}s`,
5060
- functions: categoryFunctions
5061
- };
5062
- }).filter((category) => category.functions.length > 0);
5063
- const result = {
5064
- functions: filteredFunctions,
5065
- categories: filteredCategories
5788
+ if (options?.owner) {
5789
+ let ownerId = options.owner;
5790
+ if (ownerId === "me") {
5791
+ const profile = await api.get("/zapier/api/v4/profile/", {
5792
+ authRequired: true
5793
+ });
5794
+ ownerId = String(profile.id);
5795
+ }
5796
+ searchParams.owner_customuser_id = ownerId;
5797
+ }
5798
+ if (options.cursor) {
5799
+ searchParams.offset = options.cursor;
5800
+ }
5801
+ const rawResponse = await api.get("/tables/api/v1/tables", {
5802
+ searchParams,
5803
+ customErrorHandler: ({ status }) => {
5804
+ if (status === 401) {
5805
+ return new ZapierAuthenticationError(
5806
+ `Authentication failed. Your token may not have permission to list tables or may be expired. (HTTP ${status})`,
5807
+ { statusCode: status }
5808
+ );
5809
+ }
5810
+ if (status === 403) {
5811
+ return new ZapierAuthenticationError(
5812
+ `Access forbidden. Your token may not have the required scopes to list tables. (HTTP ${status})`,
5813
+ { statusCode: status }
5814
+ );
5815
+ }
5816
+ return void 0;
5817
+ },
5818
+ authRequired: true
5819
+ });
5820
+ const response = ListTablesApiResponseSchema.parse(rawResponse);
5821
+ return {
5822
+ data: response.data.map(transformTableItem),
5823
+ nextCursor: extractNextCursor(response.links)
5066
5824
  };
5067
- registryCache.set(cacheKey, result);
5068
- return result;
5069
5825
  }
5826
+ const methodName = stripPageSuffix(listTablesPage.name);
5827
+ const listTablesDefinition = createPaginatedFunction(
5828
+ listTablesPage,
5829
+ ListTablesOptionsSchema,
5830
+ createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
5831
+ methodName,
5832
+ DEFAULT_PAGE_SIZE
5833
+ );
5070
5834
  return {
5071
- getRegistry
5835
+ listTables: listTablesDefinition,
5836
+ context: {
5837
+ meta: {
5838
+ listTables: {
5839
+ categories: ["table"],
5840
+ type: "list",
5841
+ itemType: "Table",
5842
+ inputSchema: ListTablesOptionsSchema,
5843
+ outputSchema: TableItemSchema
5844
+ }
5845
+ }
5846
+ }
5072
5847
  };
5073
5848
  };
5849
+ var GetTableApiResponseSchema = z.object({
5850
+ data: TableApiItemSchema
5851
+ });
5852
+ var GetTableOptionsSchema = z.object({
5853
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table to retrieve")
5854
+ }).describe("Get detailed information about a specific table");
5074
5855
 
5075
- // src/plugins/deprecated/authentications.ts
5076
- var listAuthenticationsPlugin = ({ sdk }) => ({
5077
- listAuthentications: sdk.listConnections,
5078
- context: {
5079
- meta: {
5080
- listAuthentications: {
5081
- packages: ["cli", "mcp"],
5082
- categories: ["connection", "deprecated"],
5083
- type: "list",
5084
- itemType: "Connection",
5085
- inputSchema: ListConnectionsQuerySchema,
5086
- outputSchema: ConnectionItemSchema
5856
+ // src/plugins/tables/getTable/index.ts
5857
+ var getTablePlugin = ({ context }) => {
5858
+ async function getTable(options) {
5859
+ const { api } = context;
5860
+ const rawResponse = await api.get(
5861
+ `/tables/api/v1/tables/${options.tableId}`,
5862
+ {
5863
+ customErrorHandler: ({ status }) => {
5864
+ if (status === 401) {
5865
+ return new ZapierAuthenticationError(
5866
+ `Authentication failed. Your token may not have permission to access this table or may be expired. (HTTP ${status})`,
5867
+ { statusCode: status }
5868
+ );
5869
+ }
5870
+ if (status === 403) {
5871
+ return new ZapierAuthenticationError(
5872
+ `Access forbidden. Your token may not have the required scopes to access this table. (HTTP ${status})`,
5873
+ { statusCode: status }
5874
+ );
5875
+ }
5876
+ if (status === 404) {
5877
+ return new Error(`Table not found: ${options.tableId}`);
5878
+ }
5879
+ return void 0;
5880
+ },
5881
+ authRequired: true
5087
5882
  }
5088
- }
5883
+ );
5884
+ const response = GetTableApiResponseSchema.parse(rawResponse);
5885
+ return {
5886
+ data: transformTableItem(response.data)
5887
+ };
5089
5888
  }
5090
- });
5091
- var getAuthenticationPlugin = ({ sdk }) => ({
5092
- getAuthentication: sdk.getConnection,
5093
- context: {
5094
- meta: {
5095
- getAuthentication: {
5096
- packages: ["cli", "mcp"],
5097
- categories: ["connection", "deprecated"],
5098
- type: "item",
5099
- itemType: "Connection",
5100
- inputSchema: GetConnectionParamSchema,
5101
- outputSchema: ConnectionItemSchema
5889
+ const getTableDefinition = createFunction(
5890
+ getTable,
5891
+ GetTableOptionsSchema,
5892
+ createTelemetryCallback(
5893
+ context.eventEmission.emitMethodCalled,
5894
+ getTable.name
5895
+ )
5896
+ );
5897
+ return {
5898
+ getTable: getTableDefinition,
5899
+ context: {
5900
+ meta: {
5901
+ getTable: {
5902
+ categories: ["table"],
5903
+ type: "item",
5904
+ itemType: "Table",
5905
+ inputSchema: GetTableOptionsSchema,
5906
+ outputSchema: TableItemSchema,
5907
+ resolvers: {
5908
+ tableId: tableIdResolver
5909
+ }
5910
+ }
5102
5911
  }
5103
5912
  }
5104
- }
5913
+ };
5914
+ };
5915
+ var CreateTableApiResponseSchema = z.object({
5916
+ data: TableApiItemSchema
5105
5917
  });
5106
- var findFirstAuthenticationPlugin = ({ sdk }) => ({
5107
- findFirstAuthentication: sdk.findFirstConnection,
5108
- context: {
5109
- meta: {
5110
- findFirstAuthentication: {
5111
- packages: ["cli", "mcp"],
5918
+ var CreateTableOptionsSchema = z.object({
5919
+ name: z.string().min(1).describe("The name for the new table"),
5920
+ description: z.string().optional().describe("An optional description of the table")
5921
+ }).describe("Create a new table");
5922
+
5923
+ // src/plugins/tables/createTable/index.ts
5924
+ var createTablePlugin = ({ context }) => {
5925
+ async function createTable(options) {
5926
+ const { api } = context;
5927
+ const rawResponse = await api.post(
5928
+ "/tables/api/v1/tables",
5929
+ {
5930
+ name: options.name,
5931
+ description: options.description
5932
+ },
5933
+ {
5934
+ customErrorHandler: ({ status }) => {
5935
+ if (status === 401) {
5936
+ return new ZapierAuthenticationError(
5937
+ `Authentication failed. Your token may not have permission to create tables or may be expired. (HTTP ${status})`,
5938
+ { statusCode: status }
5939
+ );
5940
+ }
5941
+ if (status === 403) {
5942
+ return new ZapierAuthenticationError(
5943
+ `Access forbidden. Your token may not have the required scopes to create tables. (HTTP ${status})`,
5944
+ { statusCode: status }
5945
+ );
5946
+ }
5947
+ return void 0;
5948
+ },
5949
+ authRequired: true
5950
+ }
5951
+ );
5952
+ const response = CreateTableApiResponseSchema.parse(rawResponse);
5953
+ return {
5954
+ data: transformTableItem(response.data)
5955
+ };
5956
+ }
5957
+ const createTableDefinition = createFunction(
5958
+ createTable,
5959
+ CreateTableOptionsSchema,
5960
+ createTelemetryCallback(
5961
+ context.eventEmission.emitMethodCalled,
5962
+ createTable.name
5963
+ )
5964
+ );
5965
+ return {
5966
+ createTable: createTableDefinition,
5967
+ context: {
5968
+ meta: {
5969
+ createTable: {
5970
+ categories: ["table"],
5971
+ type: "create",
5972
+ itemType: "Table",
5973
+ inputSchema: CreateTableOptionsSchema,
5974
+ outputSchema: TableItemSchema,
5975
+ resolvers: {
5976
+ name: tableNameResolver
5977
+ }
5978
+ }
5979
+ }
5980
+ }
5981
+ };
5982
+ };
5983
+ var DeleteTableOptionsSchema = z.object({
5984
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table to delete")
5985
+ }).describe("Delete a table by its ID");
5986
+
5987
+ // src/plugins/tables/deleteTable/index.ts
5988
+ var deleteTablePlugin = ({ context }) => {
5989
+ async function deleteTable(options) {
5990
+ const { api } = context;
5991
+ await api.delete(`/tables/api/v1/tables/${options.tableId}`, void 0, {
5992
+ customErrorHandler: ({ status }) => {
5993
+ if (status === 401) {
5994
+ return new ZapierAuthenticationError(
5995
+ `Authentication failed. Your token may not have permission to delete tables or may be expired. (HTTP ${status})`,
5996
+ { statusCode: status }
5997
+ );
5998
+ }
5999
+ if (status === 403) {
6000
+ return new ZapierAuthenticationError(
6001
+ `Access forbidden. Your token may not have the required scopes to delete tables. (HTTP ${status})`,
6002
+ { statusCode: status }
6003
+ );
6004
+ }
6005
+ return void 0;
6006
+ },
6007
+ authRequired: true
6008
+ });
6009
+ return {
6010
+ success: true
6011
+ };
6012
+ }
6013
+ const deleteTableDefinition = createFunction(
6014
+ deleteTable,
6015
+ DeleteTableOptionsSchema,
6016
+ createTelemetryCallback(
6017
+ context.eventEmission.emitMethodCalled,
6018
+ deleteTable.name
6019
+ )
6020
+ );
6021
+ return {
6022
+ deleteTable: deleteTableDefinition,
6023
+ context: {
6024
+ meta: {
6025
+ deleteTable: {
6026
+ categories: ["table"],
6027
+ type: "delete",
6028
+ itemType: "Table",
6029
+ inputSchema: DeleteTableOptionsSchema,
6030
+ resolvers: {
6031
+ tableId: tableIdResolver
6032
+ },
6033
+ confirm: "delete"
6034
+ }
6035
+ }
6036
+ }
6037
+ };
6038
+ };
6039
+
6040
+ // src/plugins/tables/listTableFields/index.ts
6041
+ var listTableFieldsPlugin = ({ context }) => {
6042
+ async function listTableFields(options) {
6043
+ const { api } = context;
6044
+ const searchParams = {};
6045
+ if (options.fieldKeys && options.fieldKeys.length > 0) {
6046
+ const numericIds = await resolveFieldKeys({
6047
+ api,
6048
+ tableId: options.tableId,
6049
+ fieldKeys: options.fieldKeys
6050
+ });
6051
+ searchParams.field_ids = numericIds.join(",");
6052
+ }
6053
+ const rawResponse = await api.get(
6054
+ `/tables/api/v1/tables/${options.tableId}/fields`,
6055
+ {
6056
+ searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0,
6057
+ customErrorHandler: ({ status }) => {
6058
+ if (status === 401) {
6059
+ return new ZapierAuthenticationError(
6060
+ `Authentication failed. Your token may not have permission to access this table or may be expired. (HTTP ${status})`,
6061
+ { statusCode: status }
6062
+ );
6063
+ }
6064
+ if (status === 403) {
6065
+ return new ZapierAuthenticationError(
6066
+ `Access forbidden. Your token may not have the required scopes to access this table. (HTTP ${status})`,
6067
+ { statusCode: status }
6068
+ );
6069
+ }
6070
+ if (status === 404) {
6071
+ return new Error(`Table not found: ${options.tableId}`);
6072
+ }
6073
+ return void 0;
6074
+ },
6075
+ authRequired: true
6076
+ }
6077
+ );
6078
+ const response = ListTableFieldsApiResponseSchema.parse(rawResponse);
6079
+ return {
6080
+ data: response.data.map(transformFieldItem)
6081
+ };
6082
+ }
6083
+ const listTableFieldsDefinition = createFunction(
6084
+ listTableFields,
6085
+ ListTableFieldsOptionsSchema,
6086
+ createTelemetryCallback(
6087
+ context.eventEmission.emitMethodCalled,
6088
+ listTableFields.name
6089
+ )
6090
+ );
6091
+ return {
6092
+ listTableFields: listTableFieldsDefinition,
6093
+ context: {
6094
+ meta: {
6095
+ listTableFields: {
6096
+ categories: ["table"],
6097
+ type: "list",
6098
+ itemType: "Field",
6099
+ inputSchema: ListTableFieldsOptionsSchema,
6100
+ outputSchema: FieldItemSchema,
6101
+ resolvers: {
6102
+ tableId: tableIdResolver
6103
+ }
6104
+ }
6105
+ }
6106
+ }
6107
+ };
6108
+ };
6109
+ var FieldChangesetItemSchema = z.object({
6110
+ new: FieldApiItemSchema,
6111
+ old: FieldApiItemSchema.nullable(),
6112
+ kind: z.enum(["created", "updated", "deleted"])
6113
+ });
6114
+ var CreateTableFieldsApiResponseSchema = z.object({
6115
+ data: z.array(FieldChangesetItemSchema),
6116
+ meta: z.object({
6117
+ did_change: z.boolean()
6118
+ }).optional()
6119
+ });
6120
+ var NewFieldSchema = z.object({
6121
+ type: FieldTypeSchema.describe("The data type of the field"),
6122
+ name: z.string().min(1).describe("The display name of the field"),
6123
+ options: z.record(z.string(), z.unknown()).optional().describe("Data configuration options for the field"),
6124
+ config: z.record(z.string(), z.unknown()).optional().describe("Display configuration for the field")
6125
+ });
6126
+ var CreateTableFieldsOptionsSchema = z.object({
6127
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6128
+ fields: z.array(NewFieldSchema).min(1).describe("Array of field definitions to create")
6129
+ }).describe("Create one or more fields in a table");
6130
+
6131
+ // src/plugins/tables/createTableFields/index.ts
6132
+ var createTableFieldsPlugin = ({ context }) => {
6133
+ async function createTableFields(options) {
6134
+ const { api } = context;
6135
+ const rawResponse = await api.post(
6136
+ `/tables/api/v1/tables/${options.tableId}/fields`,
6137
+ {
6138
+ new_fields: options.fields
6139
+ },
6140
+ {
6141
+ customErrorHandler: ({ status }) => {
6142
+ if (status === 401) {
6143
+ return new ZapierAuthenticationError(
6144
+ `Authentication failed. Your token may not have permission to create fields or may be expired. (HTTP ${status})`,
6145
+ { statusCode: status }
6146
+ );
6147
+ }
6148
+ if (status === 403) {
6149
+ return new ZapierAuthenticationError(
6150
+ `Access forbidden. Your token may not have the required scopes to create fields. (HTTP ${status})`,
6151
+ { statusCode: status }
6152
+ );
6153
+ }
6154
+ return void 0;
6155
+ },
6156
+ authRequired: true
6157
+ }
6158
+ );
6159
+ const response = CreateTableFieldsApiResponseSchema.parse(rawResponse);
6160
+ return {
6161
+ data: response.data.map((changeset) => transformFieldItem(changeset.new))
6162
+ };
6163
+ }
6164
+ const createTableFieldsDefinition = createFunction(
6165
+ createTableFields,
6166
+ CreateTableFieldsOptionsSchema,
6167
+ createTelemetryCallback(
6168
+ context.eventEmission.emitMethodCalled,
6169
+ createTableFields.name
6170
+ )
6171
+ );
6172
+ return {
6173
+ createTableFields: createTableFieldsDefinition,
6174
+ context: {
6175
+ meta: {
6176
+ createTableFields: {
6177
+ categories: ["table"],
6178
+ type: "create",
6179
+ itemType: "Field",
6180
+ inputSchema: CreateTableFieldsOptionsSchema,
6181
+ outputSchema: FieldItemSchema,
6182
+ resolvers: {
6183
+ tableId: tableIdResolver,
6184
+ fields: tableFieldsResolver
6185
+ }
6186
+ }
6187
+ }
6188
+ }
6189
+ };
6190
+ };
6191
+ var DeleteTableFieldsOptionsSchema = z.object({
6192
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6193
+ fieldKeys: z.array(z.union([z.string(), z.number()])).min(1).describe(
6194
+ 'Fields to delete. Accepts field names (e.g., "Email") or IDs (e.g., "f6", "6", or 6).'
6195
+ )
6196
+ }).describe("Delete one or more fields from a table");
6197
+
6198
+ // src/plugins/tables/deleteTableFields/index.ts
6199
+ var deleteTableFieldsPlugin = ({ context }) => {
6200
+ async function deleteTableFields(options) {
6201
+ const { api } = context;
6202
+ const numericFieldIds = await resolveFieldKeys({
6203
+ api,
6204
+ tableId: options.tableId,
6205
+ fieldKeys: options.fieldKeys
6206
+ });
6207
+ await api.delete(
6208
+ `/tables/api/v1/tables/${options.tableId}/fields`,
6209
+ { field_ids: numericFieldIds },
6210
+ {
6211
+ customErrorHandler: ({ status }) => {
6212
+ if (status === 401) {
6213
+ return new ZapierAuthenticationError(
6214
+ `Authentication failed. Your token may not have permission to delete fields or may be expired. (HTTP ${status})`,
6215
+ { statusCode: status }
6216
+ );
6217
+ }
6218
+ if (status === 403) {
6219
+ return new ZapierAuthenticationError(
6220
+ `Access forbidden. Your token may not have the required scopes to delete fields. (HTTP ${status})`,
6221
+ { statusCode: status }
6222
+ );
6223
+ }
6224
+ return void 0;
6225
+ },
6226
+ authRequired: true
6227
+ }
6228
+ );
6229
+ return {
6230
+ success: true
6231
+ };
6232
+ }
6233
+ const deleteTableFieldsDefinition = createFunction(
6234
+ deleteTableFields,
6235
+ DeleteTableFieldsOptionsSchema,
6236
+ createTelemetryCallback(
6237
+ context.eventEmission.emitMethodCalled,
6238
+ deleteTableFields.name
6239
+ )
6240
+ );
6241
+ return {
6242
+ deleteTableFields: deleteTableFieldsDefinition,
6243
+ context: {
6244
+ meta: {
6245
+ deleteTableFields: {
6246
+ categories: ["table"],
6247
+ type: "delete",
6248
+ itemType: "Field",
6249
+ inputSchema: DeleteTableFieldsOptionsSchema,
6250
+ resolvers: {
6251
+ tableId: tableIdResolver,
6252
+ fieldKeys: tableFieldIdsResolver
6253
+ },
6254
+ confirm: "delete"
6255
+ }
6256
+ }
6257
+ }
6258
+ };
6259
+ };
6260
+ var RecordApiItemSchema = z.object({
6261
+ id: z.string().regex(/^[A-Z0-9]{26}$/, "Record ID must be a valid ULID"),
6262
+ data: z.record(z.string(), z.unknown()),
6263
+ created_at: z.string(),
6264
+ edited_at: z.string(),
6265
+ schema_revision_id: z.number(),
6266
+ errors: z.record(z.string(), z.unknown()).nullable().optional(),
6267
+ orig_data: z.record(z.string(), z.unknown()).nullable().optional(),
6268
+ is_source_record: z.boolean().nullable().optional()
6269
+ });
6270
+ var RecordItemSchemaBase = z.object({
6271
+ id: z.string(),
6272
+ data: z.record(z.string(), z.unknown()),
6273
+ created_at: z.string(),
6274
+ edited_at: z.string()
6275
+ });
6276
+ var RecordItemSchema = withFormatter(RecordItemSchemaBase, {
6277
+ format: (item) => ({
6278
+ title: `Record ${item.id}`,
6279
+ id: item.id,
6280
+ data: item.data,
6281
+ details: []
6282
+ })
6283
+ });
6284
+ var GetTableRecordApiResponseSchema = z.object({
6285
+ data: RecordApiItemSchema
6286
+ });
6287
+ var GetTableRecordOptionsSchema = z.object({
6288
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6289
+ recordId: z.string().regex(/^[A-Z0-9]{26}$/, "Record ID must be a valid ULID").describe("The unique identifier of the record"),
6290
+ keyMode: KeyModeSchema
6291
+ }).describe("Get a single record from a table by ID");
6292
+
6293
+ // src/formatters/tableRecord.ts
6294
+ var tableRecordFormatter = {
6295
+ fetch: async (sdk, params, item, context) => {
6296
+ if (context) return context;
6297
+ const hasFieldIds = Object.keys(item.data).some(isFieldId);
6298
+ if (!hasFieldIds) return {};
6299
+ const { data: fields } = await sdk.listTableFields({
6300
+ tableId: params.tableId
6301
+ });
6302
+ return Object.fromEntries(fields.map((f) => [f.id, f.name]));
6303
+ },
6304
+ format: (item, fieldLabels) => ({
6305
+ title: `Record ${item.id}`,
6306
+ id: item.id,
6307
+ details: Object.entries(item.data).map(([k, v]) => ({
6308
+ label: fieldLabels?.[k] ?? k,
6309
+ text: formatFieldValue(v),
6310
+ style: "normal"
6311
+ }))
6312
+ })
6313
+ };
6314
+
6315
+ // src/plugins/tables/getTableRecord/index.ts
6316
+ var getTableRecordPlugin = ({ context }) => {
6317
+ async function getTableRecord(options) {
6318
+ const { api } = context;
6319
+ const rawResponse = await api.get(
6320
+ `/tables/api/v1/tables/${options.tableId}/records/${options.recordId}`,
6321
+ {
6322
+ customErrorHandler: ({ status }) => {
6323
+ if (status === 401) {
6324
+ return new ZapierAuthenticationError(
6325
+ `Authentication failed. Your token may not have permission to access this record or may be expired. (HTTP ${status})`,
6326
+ { statusCode: status }
6327
+ );
6328
+ }
6329
+ if (status === 403) {
6330
+ return new ZapierAuthenticationError(
6331
+ `Access forbidden. Your token may not have the required scopes to access this record. (HTTP ${status})`,
6332
+ { statusCode: status }
6333
+ );
6334
+ }
6335
+ if (status === 404) {
6336
+ return new Error(`Record not found: ${options.recordId}`);
6337
+ }
6338
+ return void 0;
6339
+ },
6340
+ authRequired: true
6341
+ }
6342
+ );
6343
+ const response = GetTableRecordApiResponseSchema.parse(rawResponse);
6344
+ const translator = await createFieldKeyTranslator({
6345
+ api,
6346
+ tableId: options.tableId,
6347
+ keyMode: options.keyMode
6348
+ });
6349
+ return {
6350
+ data: {
6351
+ ...transformRecordItem(response.data),
6352
+ data: translator.translateOutput(response.data.data)
6353
+ }
6354
+ };
6355
+ }
6356
+ const getTableRecordDefinition = createFunction(
6357
+ getTableRecord,
6358
+ GetTableRecordOptionsSchema,
6359
+ createTelemetryCallback(
6360
+ context.eventEmission.emitMethodCalled,
6361
+ getTableRecord.name
6362
+ )
6363
+ );
6364
+ return {
6365
+ getTableRecord: getTableRecordDefinition,
6366
+ context: {
6367
+ meta: {
6368
+ getTableRecord: {
6369
+ categories: ["table"],
6370
+ type: "item",
6371
+ itemType: "Record",
6372
+ inputSchema: GetTableRecordOptionsSchema,
6373
+ outputSchema: RecordItemSchema,
6374
+ resolvers: {
6375
+ tableId: tableIdResolver,
6376
+ recordId: tableRecordIdResolver
6377
+ },
6378
+ formatter: tableRecordFormatter
6379
+ }
6380
+ }
6381
+ }
6382
+ };
6383
+ };
6384
+ var ListTableRecordsApiResponseSchema = z.object({
6385
+ data: z.array(RecordApiItemSchema),
6386
+ meta: z.object({
6387
+ pagination: z.object({
6388
+ start_cursor: z.string().nullable().optional(),
6389
+ end_cursor: z.string().nullable().optional(),
6390
+ has_more: z.boolean().optional(),
6391
+ has_less: z.boolean().optional()
6392
+ }).optional()
6393
+ }).optional()
6394
+ });
6395
+ var FilterOperatorSchema = z.enum([
6396
+ "exact",
6397
+ "different",
6398
+ "contains",
6399
+ "icontains",
6400
+ "gte",
6401
+ "gt",
6402
+ "lt",
6403
+ "lte",
6404
+ "range",
6405
+ "in",
6406
+ "isnull",
6407
+ "startswith",
6408
+ "search",
6409
+ "is_within"
6410
+ ]);
6411
+ var FilterConditionSchema = z.object({
6412
+ fieldKey: z.string().describe("The field key to filter on (e.g. f1, f2)"),
6413
+ operator: FilterOperatorSchema.describe("The comparison operator"),
6414
+ value: z.unknown().optional().describe("The value to compare against")
6415
+ });
6416
+ var SortDirectionSchema = z.enum(["asc", "desc"]);
6417
+ var SortConditionSchema = z.object({
6418
+ fieldKey: z.string().describe("The field key to sort by"),
6419
+ direction: SortDirectionSchema.optional().default("asc").describe("Sort direction")
6420
+ });
6421
+ var ListTableRecordsOptionsSchema = z.object({
6422
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6423
+ filters: z.array(FilterConditionSchema).optional().describe("Filter conditions for the query"),
6424
+ sort: SortConditionSchema.optional().describe("Sort records by a field"),
6425
+ pageSize: z.number().min(1).max(1e3).optional().describe("Number of records per page (max 1000)"),
6426
+ maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
6427
+ cursor: z.string().optional().describe("Cursor to start from"),
6428
+ keyMode: KeyModeSchema
6429
+ }).describe("List records in a table with optional filtering and sorting");
6430
+
6431
+ // src/plugins/tables/listTableRecords/index.ts
6432
+ function extractNextCursor2(meta) {
6433
+ if (!meta?.pagination?.has_more || !meta.pagination.end_cursor) {
6434
+ return void 0;
6435
+ }
6436
+ return meta.pagination.end_cursor;
6437
+ }
6438
+ var listTableRecordsPlugin = ({ context }) => {
6439
+ async function listTableRecordsPage(options) {
6440
+ const { api } = context;
6441
+ const translator = await createFieldKeyTranslator({
6442
+ api,
6443
+ tableId: options.tableId,
6444
+ keyMode: options.keyMode
6445
+ });
6446
+ const body = {};
6447
+ if (options.pageSize !== void 0) {
6448
+ body.limit = options.pageSize;
6449
+ }
6450
+ if (options.filters) {
6451
+ body.filters = options.filters.map((f) => ({
6452
+ key: translator.translateFieldKey(f.fieldKey),
6453
+ operator: f.operator,
6454
+ value: f.value
6455
+ }));
6456
+ }
6457
+ if (options.sort) {
6458
+ body.orders = [
6459
+ {
6460
+ key: translator.translateFieldKey(options.sort.fieldKey),
6461
+ direction: options.sort.direction
6462
+ }
6463
+ ];
6464
+ }
6465
+ if (options.cursor) {
6466
+ body.cursor_query = {
6467
+ query_type: "window",
6468
+ start_cursor: options.cursor
6469
+ };
6470
+ }
6471
+ const rawResponse = await api.post(
6472
+ `/tables/api/v1/tables/${options.tableId}/records/query`,
6473
+ body,
6474
+ {
6475
+ searchParams: { allow_nested_queries: "true" },
6476
+ customErrorHandler: ({ status }) => {
6477
+ if (status === 401) {
6478
+ return new ZapierAuthenticationError(
6479
+ `Authentication failed. Your token may not have permission to access this table or may be expired. (HTTP ${status})`,
6480
+ { statusCode: status }
6481
+ );
6482
+ }
6483
+ if (status === 403) {
6484
+ return new ZapierAuthenticationError(
6485
+ `Access forbidden. Your token may not have the required scopes to access this table. (HTTP ${status})`,
6486
+ { statusCode: status }
6487
+ );
6488
+ }
6489
+ if (status === 404) {
6490
+ return new Error(`Table not found: ${options.tableId}`);
6491
+ }
6492
+ return void 0;
6493
+ },
6494
+ authRequired: true
6495
+ }
6496
+ );
6497
+ throwOnResponseErrors(rawResponse);
6498
+ const response = ListTableRecordsApiResponseSchema.parse(rawResponse);
6499
+ return {
6500
+ data: response.data.map((item) => ({
6501
+ ...transformRecordItem(item),
6502
+ data: translator.translateOutput(item.data)
6503
+ })),
6504
+ nextCursor: extractNextCursor2(response.meta)
6505
+ };
6506
+ }
6507
+ const methodName = stripPageSuffix(listTableRecordsPage.name);
6508
+ const listTableRecordsDefinition = createPaginatedFunction(
6509
+ listTableRecordsPage,
6510
+ ListTableRecordsOptionsSchema,
6511
+ createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
6512
+ methodName,
6513
+ DEFAULT_PAGE_SIZE
6514
+ );
6515
+ return {
6516
+ listTableRecords: listTableRecordsDefinition,
6517
+ context: {
6518
+ meta: {
6519
+ listTableRecords: {
6520
+ categories: ["table"],
6521
+ type: "list",
6522
+ itemType: "Record",
6523
+ inputSchema: ListTableRecordsOptionsSchema,
6524
+ outputSchema: RecordItemSchema,
6525
+ resolvers: {
6526
+ tableId: tableIdResolver,
6527
+ filters: tableFiltersResolver,
6528
+ sort: tableSortResolver
6529
+ },
6530
+ formatter: tableRecordFormatter
6531
+ }
6532
+ }
6533
+ }
6534
+ };
6535
+ };
6536
+ var RecordChangesetSchema = z.object({
6537
+ change_id: z.string(),
6538
+ old: RecordApiItemSchema.nullable(),
6539
+ new: RecordApiItemSchema,
6540
+ changed_field_ids: z.array(z.number()).nullable(),
6541
+ record_id: z.string()
6542
+ });
6543
+ var CreateTableRecordsApiResponseSchema = z.object({
6544
+ data: z.array(RecordChangesetSchema)
6545
+ });
6546
+ var NewRecordSchema = z.object({
6547
+ data: z.record(z.string(), z.unknown()).describe("The field values for the record, keyed by field ID")
6548
+ });
6549
+ var CreateTableRecordsOptionsSchema = z.object({
6550
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6551
+ records: z.array(NewRecordSchema).min(1).max(100).describe("Array of records to create (max 100)"),
6552
+ keyMode: KeyModeSchema
6553
+ }).describe("Create one or more records in a table");
6554
+
6555
+ // src/plugins/tables/createTableRecords/index.ts
6556
+ var createTableRecordsPlugin = ({ context }) => {
6557
+ async function createTableRecords(options) {
6558
+ const { api } = context;
6559
+ const translator = await createFieldKeyTranslator({
6560
+ api,
6561
+ tableId: options.tableId,
6562
+ keyMode: options.keyMode
6563
+ });
6564
+ const rawResponse = await api.post(
6565
+ `/tables/api/v1/tables/${options.tableId}/records`,
6566
+ {
6567
+ new_records: options.records.map((record) => ({
6568
+ data: translator.translateInput(record.data)
6569
+ }))
6570
+ },
6571
+ {
6572
+ customErrorHandler: ({ status }) => {
6573
+ if (status === 401) {
6574
+ return new ZapierAuthenticationError(
6575
+ `Authentication failed. Your token may not have permission to create records or may be expired. (HTTP ${status})`,
6576
+ { statusCode: status }
6577
+ );
6578
+ }
6579
+ if (status === 403) {
6580
+ return new ZapierAuthenticationError(
6581
+ `Access forbidden. Your token may not have the required scopes to create records. (HTTP ${status})`,
6582
+ { statusCode: status }
6583
+ );
6584
+ }
6585
+ if (status === 404) {
6586
+ return new Error(`Table not found: ${options.tableId}`);
6587
+ }
6588
+ return void 0;
6589
+ },
6590
+ authRequired: true
6591
+ }
6592
+ );
6593
+ throwOnResponseErrors(rawResponse);
6594
+ const response = CreateTableRecordsApiResponseSchema.parse(rawResponse);
6595
+ for (const changeset of response.data) {
6596
+ throwOnRecordErrors(changeset.new);
6597
+ }
6598
+ return {
6599
+ data: response.data.map((changeset) => ({
6600
+ ...transformRecordItem(changeset.new),
6601
+ data: translator.translateOutput(changeset.new.data)
6602
+ }))
6603
+ };
6604
+ }
6605
+ const createTableRecordsDefinition = createFunction(
6606
+ createTableRecords,
6607
+ CreateTableRecordsOptionsSchema,
6608
+ createTelemetryCallback(
6609
+ context.eventEmission.emitMethodCalled,
6610
+ createTableRecords.name
6611
+ )
6612
+ );
6613
+ return {
6614
+ createTableRecords: createTableRecordsDefinition,
6615
+ context: {
6616
+ meta: {
6617
+ createTableRecords: {
6618
+ categories: ["table"],
6619
+ type: "create",
6620
+ itemType: "Record",
6621
+ inputSchema: CreateTableRecordsOptionsSchema,
6622
+ outputSchema: RecordItemSchema,
6623
+ resolvers: {
6624
+ tableId: tableIdResolver,
6625
+ records: tableRecordsResolver
6626
+ },
6627
+ formatter: tableRecordFormatter
6628
+ }
6629
+ }
6630
+ }
6631
+ };
6632
+ };
6633
+ var DeleteTableRecordsOptionsSchema = z.object({
6634
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6635
+ recordIds: z.array(
6636
+ z.string().regex(/^[A-Z0-9]{26}$/, "Record ID must be a valid ULID")
6637
+ ).min(1).max(100).describe("Array of record IDs to delete (max 100)")
6638
+ }).describe("Delete one or more records from a table");
6639
+
6640
+ // src/plugins/tables/deleteTableRecords/index.ts
6641
+ var deleteTableRecordsPlugin = ({ context }) => {
6642
+ async function deleteTableRecords(options) {
6643
+ const { api } = context;
6644
+ await api.delete(
6645
+ `/tables/api/v1/tables/${options.tableId}/records`,
6646
+ { record_ids: options.recordIds },
6647
+ {
6648
+ customErrorHandler: ({ status }) => {
6649
+ if (status === 401) {
6650
+ return new ZapierAuthenticationError(
6651
+ `Authentication failed. Your token may not have permission to delete records or may be expired. (HTTP ${status})`,
6652
+ { statusCode: status }
6653
+ );
6654
+ }
6655
+ if (status === 403) {
6656
+ return new ZapierAuthenticationError(
6657
+ `Access forbidden. Your token may not have the required scopes to delete records. (HTTP ${status})`,
6658
+ { statusCode: status }
6659
+ );
6660
+ }
6661
+ return void 0;
6662
+ },
6663
+ authRequired: true
6664
+ }
6665
+ );
6666
+ return {
6667
+ success: true
6668
+ };
6669
+ }
6670
+ const deleteTableRecordsDefinition = createFunction(
6671
+ deleteTableRecords,
6672
+ DeleteTableRecordsOptionsSchema,
6673
+ createTelemetryCallback(
6674
+ context.eventEmission.emitMethodCalled,
6675
+ deleteTableRecords.name
6676
+ )
6677
+ );
6678
+ return {
6679
+ deleteTableRecords: deleteTableRecordsDefinition,
6680
+ context: {
6681
+ meta: {
6682
+ deleteTableRecords: {
6683
+ categories: ["table"],
6684
+ type: "delete",
6685
+ itemType: "Record",
6686
+ inputSchema: DeleteTableRecordsOptionsSchema,
6687
+ resolvers: {
6688
+ tableId: tableIdResolver,
6689
+ recordIds: tableRecordIdsResolver
6690
+ },
6691
+ confirm: "delete"
6692
+ }
6693
+ }
6694
+ }
6695
+ };
6696
+ };
6697
+ var RecordChangesetSchema2 = z.object({
6698
+ change_id: z.string(),
6699
+ old: RecordApiItemSchema.nullable(),
6700
+ new: RecordApiItemSchema,
6701
+ changed_field_ids: z.array(z.number()).nullable(),
6702
+ record_id: z.string()
6703
+ });
6704
+ var UpdateTableRecordsApiResponseSchema = z.object({
6705
+ data: z.array(RecordChangesetSchema2)
6706
+ });
6707
+ var UpdateRecordSchema = z.object({
6708
+ id: z.string().describe("The record ID to update"),
6709
+ data: z.record(z.string(), z.unknown()).describe("The field values to update, keyed by field key")
6710
+ });
6711
+ var UpdateTableRecordsOptionsSchema = z.object({
6712
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6713
+ records: z.array(UpdateRecordSchema).min(1).max(100).describe("Array of records to update (max 100)"),
6714
+ keyMode: KeyModeSchema
6715
+ }).describe("Update one or more records in a table");
6716
+
6717
+ // src/plugins/tables/updateTableRecords/index.ts
6718
+ var updateTableRecordsPlugin = ({ context }) => {
6719
+ async function updateTableRecords(options) {
6720
+ const { api } = context;
6721
+ const translator = await createFieldKeyTranslator({
6722
+ api,
6723
+ tableId: options.tableId,
6724
+ keyMode: options.keyMode
6725
+ });
6726
+ const rawResponse = await api.patch(
6727
+ `/tables/api/v1/tables/${options.tableId}/records`,
6728
+ {
6729
+ updated_records: options.records.map((record) => ({
6730
+ id: record.id,
6731
+ data: translator.translateInput(record.data)
6732
+ }))
6733
+ },
6734
+ {
6735
+ customErrorHandler: ({ status }) => {
6736
+ if (status === 401) {
6737
+ return new ZapierAuthenticationError(
6738
+ `Authentication failed. Your token may not have permission to update records or may be expired. (HTTP ${status})`,
6739
+ { statusCode: status }
6740
+ );
6741
+ }
6742
+ if (status === 403) {
6743
+ return new ZapierAuthenticationError(
6744
+ `Access forbidden. Your token may not have the required scopes to update records. (HTTP ${status})`,
6745
+ { statusCode: status }
6746
+ );
6747
+ }
6748
+ if (status === 404) {
6749
+ return new Error(`Table not found: ${options.tableId}`);
6750
+ }
6751
+ return void 0;
6752
+ },
6753
+ authRequired: true
6754
+ }
6755
+ );
6756
+ throwOnResponseErrors(rawResponse);
6757
+ const response = UpdateTableRecordsApiResponseSchema.parse(rawResponse);
6758
+ for (const changeset of response.data) {
6759
+ throwOnRecordErrors(changeset.new);
6760
+ }
6761
+ return {
6762
+ data: response.data.map((changeset) => ({
6763
+ ...transformRecordItem(changeset.new),
6764
+ data: translator.translateOutput(changeset.new.data)
6765
+ }))
6766
+ };
6767
+ }
6768
+ const updateTableRecordsDefinition = createFunction(
6769
+ updateTableRecords,
6770
+ UpdateTableRecordsOptionsSchema,
6771
+ createTelemetryCallback(
6772
+ context.eventEmission.emitMethodCalled,
6773
+ updateTableRecords.name
6774
+ )
6775
+ );
6776
+ return {
6777
+ updateTableRecords: updateTableRecordsDefinition,
6778
+ context: {
6779
+ meta: {
6780
+ updateTableRecords: {
6781
+ categories: ["table"],
6782
+ type: "update",
6783
+ itemType: "Record",
6784
+ inputSchema: UpdateTableRecordsOptionsSchema,
6785
+ outputSchema: RecordItemSchema,
6786
+ resolvers: {
6787
+ tableId: tableIdResolver,
6788
+ records: tableUpdateRecordsResolver
6789
+ },
6790
+ formatter: tableRecordFormatter
6791
+ }
6792
+ }
6793
+ }
6794
+ };
6795
+ };
6796
+
6797
+ // src/plugins/registry/index.ts
6798
+ var registryPlugin = ({ sdk, context }) => {
6799
+ const metaKeys = Object.keys(context.meta || {});
6800
+ const categoryDefinitions = {
6801
+ account: {
6802
+ title: "Account"
6803
+ },
6804
+ app: {
6805
+ title: "App",
6806
+ titlePlural: "Apps"
6807
+ },
6808
+ connection: {
6809
+ title: "Connection"
6810
+ },
6811
+ action: {
6812
+ title: "Action"
6813
+ },
6814
+ "client-credentials": {
6815
+ title: "Client Credentials",
6816
+ titlePlural: "Client Credentials"
6817
+ },
6818
+ table: {
6819
+ title: "Table"
6820
+ },
6821
+ http: {
6822
+ title: "HTTP Request"
6823
+ },
6824
+ utility: {
6825
+ title: "Utility",
6826
+ titlePlural: "Utilities"
6827
+ },
6828
+ other: {
6829
+ title: "Other"
6830
+ }
6831
+ };
6832
+ const functions = metaKeys.filter((key) => {
6833
+ const property = sdk[key];
6834
+ if (typeof property === "function") {
6835
+ return true;
6836
+ }
6837
+ const [rootKey] = key.split(".");
6838
+ const rootProperty = sdk[rootKey];
6839
+ if (typeof rootProperty === "object" && rootProperty !== null) {
6840
+ return true;
6841
+ }
6842
+ return false;
6843
+ }).map((key) => {
6844
+ const meta = context.meta[key];
6845
+ return {
6846
+ name: key,
6847
+ description: meta.description,
6848
+ type: meta.type,
6849
+ itemType: meta.itemType,
6850
+ returnType: meta.returnType,
6851
+ inputSchema: meta.inputSchema,
6852
+ inputParameters: meta.inputParameters,
6853
+ outputSchema: meta.outputSchema,
6854
+ categories: meta.categories || [],
6855
+ resolvers: meta.resolvers,
6856
+ formatter: meta.formatter,
6857
+ packages: meta.packages,
6858
+ // Auto-infer confirm: "delete" from type: "delete" (all deletes should confirm)
6859
+ confirm: meta.confirm ?? (meta.type === "delete" ? "delete" : void 0),
6860
+ deprecation: meta.deprecation,
6861
+ deprecatedParameters: meta.deprecatedParameters,
6862
+ aliases: meta.aliases,
6863
+ supportsJsonOutput: meta.supportsJsonOutput ?? true
6864
+ };
6865
+ }).sort((a, b) => a.name.localeCompare(b.name));
6866
+ const knownCategories = Object.keys(categoryDefinitions);
6867
+ const registryCache = /* @__PURE__ */ new Map();
6868
+ function getRegistry(options) {
6869
+ const packageFilter = options?.package;
6870
+ const cacheKey = packageFilter || "__all__";
6871
+ if (registryCache.has(cacheKey)) {
6872
+ return registryCache.get(cacheKey);
6873
+ }
6874
+ const filteredFunctions = packageFilter ? functions.filter(
6875
+ (f) => (
6876
+ // Include if packages is undefined (belongs to all packages) or includes the specified package
6877
+ !f.packages || f.packages.includes(packageFilter)
6878
+ )
6879
+ ) : functions;
6880
+ const filteredCategories = knownCategories.sort((a, b) => {
6881
+ if (a === "other") return 1;
6882
+ if (b === "other") return -1;
6883
+ const titleA = categoryDefinitions[a].title;
6884
+ const titleB = categoryDefinitions[b].title;
6885
+ return titleA.localeCompare(titleB);
6886
+ }).map((categoryKey) => {
6887
+ const categoryFunctions = filteredFunctions.filter(
6888
+ (f) => f.categories.includes(categoryKey) || // If the category is "other" and the function is not in any other category, include it
6889
+ categoryKey === "other" && !f.categories.some((c) => knownCategories.includes(c))
6890
+ ).map((f) => f.name).sort();
6891
+ const definition = categoryDefinitions[categoryKey];
6892
+ const title = definition.title;
6893
+ return {
6894
+ key: categoryKey,
6895
+ title,
6896
+ titlePlural: definition.titlePlural ?? `${title}s`,
6897
+ functions: categoryFunctions
6898
+ };
6899
+ }).filter((category) => category.functions.length > 0);
6900
+ const result = {
6901
+ functions: filteredFunctions,
6902
+ categories: filteredCategories
6903
+ };
6904
+ registryCache.set(cacheKey, result);
6905
+ return result;
6906
+ }
6907
+ return {
6908
+ getRegistry
6909
+ };
6910
+ };
6911
+
6912
+ // src/plugins/deprecated/authentications.ts
6913
+ var listAuthenticationsPlugin = ({ sdk }) => ({
6914
+ listAuthentications: sdk.listConnections,
6915
+ context: {
6916
+ meta: {
6917
+ listAuthentications: {
6918
+ packages: ["cli", "mcp"],
6919
+ categories: ["connection", "deprecated"],
6920
+ type: "list",
6921
+ itemType: "Connection",
6922
+ inputSchema: ListConnectionsQuerySchema,
6923
+ outputSchema: ConnectionItemSchema
6924
+ }
6925
+ }
6926
+ }
6927
+ });
6928
+ var getAuthenticationPlugin = ({ sdk }) => ({
6929
+ getAuthentication: sdk.getConnection,
6930
+ context: {
6931
+ meta: {
6932
+ getAuthentication: {
6933
+ packages: ["cli", "mcp"],
6934
+ categories: ["connection", "deprecated"],
6935
+ type: "item",
6936
+ itemType: "Connection",
6937
+ inputSchema: GetConnectionParamSchema,
6938
+ outputSchema: ConnectionItemSchema
6939
+ }
6940
+ }
6941
+ }
6942
+ });
6943
+ var findFirstAuthenticationPlugin = ({ sdk }) => ({
6944
+ findFirstAuthentication: sdk.findFirstConnection,
6945
+ context: {
6946
+ meta: {
6947
+ findFirstAuthentication: {
6948
+ packages: ["cli", "mcp"],
5112
6949
  categories: ["connection", "deprecated"],
5113
6950
  type: "item",
5114
6951
  itemType: "Connection",
@@ -5373,7 +7210,8 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
5373
7210
  listInputFieldChoicesPage,
5374
7211
  ListInputFieldChoicesSchema,
5375
7212
  createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
5376
- methodName
7213
+ methodName,
7214
+ DEFAULT_PAGE_SIZE
5377
7215
  );
5378
7216
  return {
5379
7217
  listInputFieldChoices: listInputFieldChoicesDefinition,
@@ -5558,7 +7396,7 @@ function getCpuTime() {
5558
7396
  }
5559
7397
 
5560
7398
  // src/plugins/eventEmission/builders.ts
5561
- var SDK_VERSION = "0.34.1";
7399
+ var SDK_VERSION = "0.36.0";
5562
7400
  function createBaseEvent(context = {}) {
5563
7401
  return {
5564
7402
  event_id: generateEventId(),
@@ -6051,7 +7889,7 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
6051
7889
  };
6052
7890
  }
6053
7891
  function createZapierSdkWithoutRegistry(options = {}) {
6054
- return createSdk(options).addPlugin(eventEmissionPlugin).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(getInputFieldsSchemaPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listConnectionsPlugin).addPlugin(getConnectionPlugin).addPlugin(findFirstConnectionPlugin).addPlugin(findUniqueConnectionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(listClientCredentialsPlugin).addPlugin(createClientCredentialsPlugin).addPlugin(deleteClientCredentialsPlugin).addPlugin(fetchPlugin).addPlugin(requestPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
7892
+ return createSdk(options).addPlugin(eventEmissionPlugin).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(getInputFieldsSchemaPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listConnectionsPlugin).addPlugin(getConnectionPlugin).addPlugin(findFirstConnectionPlugin).addPlugin(findUniqueConnectionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(listClientCredentialsPlugin).addPlugin(createClientCredentialsPlugin).addPlugin(deleteClientCredentialsPlugin).addPlugin(fetchPlugin).addPlugin(requestPlugin).addPlugin(listTablesPlugin).addPlugin(getTablePlugin).addPlugin(deleteTablePlugin).addPlugin(createTablePlugin).addPlugin(listTableFieldsPlugin).addPlugin(createTableFieldsPlugin).addPlugin(deleteTableFieldsPlugin).addPlugin(getTableRecordPlugin).addPlugin(listTableRecordsPlugin).addPlugin(createTableRecordsPlugin).addPlugin(deleteTableRecordsPlugin).addPlugin(updateTableRecordsPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
6055
7893
  }
6056
7894
  function createZapierSdk(options = {}) {
6057
7895
  return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
@@ -6085,4 +7923,4 @@ var BaseSdkOptionsSchema = z.object({
6085
7923
  // Use credentials instead
6086
7924
  });
6087
7925
 
6088
- export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, ZAPIER_BASE_URL, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierRelayError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, injectCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, runWithTelemetryContext, toSnakeCase, toTitleCase };
7926
+ export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, CONTEXT_CACHE_MAX_SIZE, CONTEXT_CACHE_TTL_MS, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DEFAULT_PAGE_SIZE, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, ZAPIER_BASE_URL, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierRelayError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createTableFieldsPlugin, createTablePlugin, createTableRecordsPlugin, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, deleteTableFieldsPlugin, deleteTablePlugin, deleteTableRecordsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTablePlugin, getTableRecordPlugin, getTokenFromCliLogin, injectCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, listTableFieldsPlugin, listTableRecordsPlugin, listTablesPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, runWithTelemetryContext, tableFieldIdsResolver, tableFieldsResolver, tableFiltersResolver, tableIdResolver, tableNameResolver, tableRecordIdResolver, tableRecordIdsResolver, tableRecordsResolver, tableSortResolver, tableUpdateRecordsResolver, toSnakeCase, toTitleCase, updateTableRecordsPlugin };