@zapier/zapier-sdk 0.34.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +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/formatters/index.d.ts +2 -0
  8. package/dist/formatters/index.d.ts.map +1 -0
  9. package/dist/formatters/index.js +1 -0
  10. package/dist/formatters/tableRecord.d.ts +6 -0
  11. package/dist/formatters/tableRecord.d.ts.map +1 -0
  12. package/dist/formatters/tableRecord.js +23 -0
  13. package/dist/index.cjs +1828 -35
  14. package/dist/index.d.mts +644 -70
  15. package/dist/index.d.ts +13 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +13 -0
  18. package/dist/index.mjs +1807 -36
  19. package/dist/plugins/apps/schemas.d.ts +11 -11
  20. package/dist/plugins/apps/schemas.d.ts.map +1 -1
  21. package/dist/plugins/deleteClientCredentials/index.d.ts.map +1 -1
  22. package/dist/plugins/deleteClientCredentials/index.js +1 -1
  23. package/dist/plugins/registry/index.d.ts.map +1 -1
  24. package/dist/plugins/registry/index.js +4 -0
  25. package/dist/plugins/tables/createTable/index.d.ts +18 -0
  26. package/dist/plugins/tables/createTable/index.d.ts.map +1 -0
  27. package/dist/plugins/tables/createTable/index.js +48 -0
  28. package/dist/plugins/tables/createTable/schemas.d.ts +37 -0
  29. package/dist/plugins/tables/createTable/schemas.d.ts.map +1 -0
  30. package/dist/plugins/tables/createTable/schemas.js +16 -0
  31. package/dist/plugins/tables/createTableFields/index.d.ts +18 -0
  32. package/dist/plugins/tables/createTableFields/index.d.ts.map +1 -0
  33. package/dist/plugins/tables/createTableFields/index.js +49 -0
  34. package/dist/plugins/tables/createTableFields/schemas.d.ts +192 -0
  35. package/dist/plugins/tables/createTableFields/schemas.d.ts.map +1 -0
  36. package/dist/plugins/tables/createTableFields/schemas.js +42 -0
  37. package/dist/plugins/tables/createTableRecords/index.d.ts +18 -0
  38. package/dist/plugins/tables/createTableRecords/index.d.ts.map +1 -0
  39. package/dist/plugins/tables/createTableRecords/index.js +67 -0
  40. package/dist/plugins/tables/createTableRecords/schemas.d.ts +57 -0
  41. package/dist/plugins/tables/createTableRecords/schemas.d.ts.map +1 -0
  42. package/dist/plugins/tables/createTableRecords/schemas.js +35 -0
  43. package/dist/plugins/tables/deleteTable/index.d.ts +18 -0
  44. package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -0
  45. package/dist/plugins/tables/deleteTable/index.js +43 -0
  46. package/dist/plugins/tables/deleteTable/schemas.d.ts +15 -0
  47. package/dist/plugins/tables/deleteTable/schemas.d.ts.map +1 -0
  48. package/dist/plugins/tables/deleteTable/schemas.js +9 -0
  49. package/dist/plugins/tables/deleteTableFields/index.d.ts +18 -0
  50. package/dist/plugins/tables/deleteTableFields/index.d.ts.map +1 -0
  51. package/dist/plugins/tables/deleteTableFields/index.js +50 -0
  52. package/dist/plugins/tables/deleteTableFields/schemas.d.ts +16 -0
  53. package/dist/plugins/tables/deleteTableFields/schemas.d.ts.map +1 -0
  54. package/dist/plugins/tables/deleteTableFields/schemas.js +13 -0
  55. package/dist/plugins/tables/deleteTableRecords/index.d.ts +18 -0
  56. package/dist/plugins/tables/deleteTableRecords/index.d.ts.map +1 -0
  57. package/dist/plugins/tables/deleteTableRecords/index.js +44 -0
  58. package/dist/plugins/tables/deleteTableRecords/schemas.d.ts +16 -0
  59. package/dist/plugins/tables/deleteTableRecords/schemas.d.ts.map +1 -0
  60. package/dist/plugins/tables/deleteTableRecords/schemas.js +14 -0
  61. package/dist/plugins/tables/getTable/index.d.ts +20 -0
  62. package/dist/plugins/tables/getTable/index.d.ts.map +1 -0
  63. package/dist/plugins/tables/getTable/index.js +48 -0
  64. package/dist/plugins/tables/getTable/schemas.d.ts +34 -0
  65. package/dist/plugins/tables/getTable/schemas.d.ts.map +1 -0
  66. package/dist/plugins/tables/getTable/schemas.js +15 -0
  67. package/dist/plugins/tables/getTableRecord/index.d.ts +18 -0
  68. package/dist/plugins/tables/getTableRecord/index.d.ts.map +1 -0
  69. package/dist/plugins/tables/getTableRecord/index.js +60 -0
  70. package/dist/plugins/tables/getTableRecord/schemas.d.ts +51 -0
  71. package/dist/plugins/tables/getTableRecord/schemas.d.ts.map +1 -0
  72. package/dist/plugins/tables/getTableRecord/schemas.js +44 -0
  73. package/dist/plugins/tables/listTableFields/index.d.ts +18 -0
  74. package/dist/plugins/tables/listTableFields/index.d.ts.map +1 -0
  75. package/dist/plugins/tables/listTableFields/index.js +58 -0
  76. package/dist/plugins/tables/listTableFields/schemas.d.ts +180 -0
  77. package/dist/plugins/tables/listTableFields/schemas.d.ts.map +1 -0
  78. package/dist/plugins/tables/listTableFields/schemas.js +77 -0
  79. package/dist/plugins/tables/listTableRecords/index.d.ts +24 -0
  80. package/dist/plugins/tables/listTableRecords/index.d.ts.map +1 -0
  81. package/dist/plugins/tables/listTableRecords/index.js +95 -0
  82. package/dist/plugins/tables/listTableRecords/schemas.d.ts +120 -0
  83. package/dist/plugins/tables/listTableRecords/schemas.d.ts.map +1 -0
  84. package/dist/plugins/tables/listTableRecords/schemas.js +74 -0
  85. package/dist/plugins/tables/listTables/index.d.ts +24 -0
  86. package/dist/plugins/tables/listTables/index.d.ts.map +1 -0
  87. package/dist/plugins/tables/listTables/index.js +83 -0
  88. package/dist/plugins/tables/listTables/schemas.d.ts +78 -0
  89. package/dist/plugins/tables/listTables/schemas.d.ts.map +1 -0
  90. package/dist/plugins/tables/listTables/schemas.js +63 -0
  91. package/dist/plugins/tables/updateTableRecords/index.d.ts +18 -0
  92. package/dist/plugins/tables/updateTableRecords/index.d.ts.map +1 -0
  93. package/dist/plugins/tables/updateTableRecords/index.js +68 -0
  94. package/dist/plugins/tables/updateTableRecords/schemas.d.ts +59 -0
  95. package/dist/plugins/tables/updateTableRecords/schemas.d.ts.map +1 -0
  96. package/dist/plugins/tables/updateTableRecords/schemas.js +35 -0
  97. package/dist/plugins/tables/utils.d.ts +63 -0
  98. package/dist/plugins/tables/utils.d.ts.map +1 -0
  99. package/dist/plugins/tables/utils.js +262 -0
  100. package/dist/resolvers/index.d.ts +8 -0
  101. package/dist/resolvers/index.d.ts.map +1 -1
  102. package/dist/resolvers/index.js +8 -0
  103. package/dist/resolvers/tableFieldIds.d.ts +6 -0
  104. package/dist/resolvers/tableFieldIds.d.ts.map +1 -0
  105. package/dist/resolvers/tableFieldIds.js +19 -0
  106. package/dist/resolvers/tableFields.d.ts +3 -0
  107. package/dist/resolvers/tableFields.d.ts.map +1 -0
  108. package/dist/resolvers/tableFields.js +31 -0
  109. package/dist/resolvers/tableFilters.d.ts +5 -0
  110. package/dist/resolvers/tableFilters.d.ts.map +1 -0
  111. package/dist/resolvers/tableFilters.js +74 -0
  112. package/dist/resolvers/tableId.d.ts +4 -0
  113. package/dist/resolvers/tableId.d.ts.map +1 -0
  114. package/dist/resolvers/tableId.js +19 -0
  115. package/dist/resolvers/tableName.d.ts +3 -0
  116. package/dist/resolvers/tableName.d.ts.map +1 -0
  117. package/dist/resolvers/tableName.js +5 -0
  118. package/dist/resolvers/tableRecordId.d.ts +9 -0
  119. package/dist/resolvers/tableRecordId.d.ts.map +1 -0
  120. package/dist/resolvers/tableRecordId.js +48 -0
  121. package/dist/resolvers/tableRecords.d.ts +8 -0
  122. package/dist/resolvers/tableRecords.d.ts.map +1 -0
  123. package/dist/resolvers/tableRecords.js +77 -0
  124. package/dist/resolvers/tableSort.d.ts +5 -0
  125. package/dist/resolvers/tableSort.d.ts.map +1 -0
  126. package/dist/resolvers/tableSort.js +43 -0
  127. package/dist/sdk.d.ts +73 -1
  128. package/dist/sdk.d.ts.map +1 -1
  129. package/dist/sdk.js +25 -0
  130. package/dist/types/sdk.d.ts +16 -1
  131. package/dist/types/sdk.d.ts.map +1 -1
  132. package/dist/utils/pagination-utils.d.ts +24 -0
  133. package/dist/utils/pagination-utils.d.ts.map +1 -1
  134. package/dist/utils/pagination-utils.js +78 -0
  135. package/dist/utils/schema-utils.d.ts +33 -5
  136. package/dist/utils/schema-utils.d.ts.map +1 -1
  137. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -810,6 +810,68 @@ async function* paginateBuffered(pageFunction, pageOptions) {
810
810
  }
811
811
  }
812
812
  var paginate = paginateBuffered;
813
+ function concatPaginated({
814
+ sources,
815
+ dedupe,
816
+ pageSize = 100
817
+ }) {
818
+ if (sources.length === 0) {
819
+ const empty = { data: [] };
820
+ return Object.assign(Promise.resolve(empty), {
821
+ [Symbol.asyncIterator]: async function* () {
822
+ yield empty;
823
+ }
824
+ });
825
+ }
826
+ let sourceIndex = 0;
827
+ let currentIterator = null;
828
+ const seen = /* @__PURE__ */ new Set();
829
+ const pageFunction = async (_options) => {
830
+ while (sourceIndex < sources.length) {
831
+ if (!currentIterator) {
832
+ const result = sources[sourceIndex]();
833
+ currentIterator = result[Symbol.asyncIterator]();
834
+ }
835
+ const next = await currentIterator.next();
836
+ if (next.done) {
837
+ sourceIndex++;
838
+ currentIterator = null;
839
+ continue;
840
+ }
841
+ let items = next.value.data;
842
+ if (dedupe) {
843
+ if (sourceIndex > 0) {
844
+ items = items.filter((item) => !seen.has(dedupe(item)));
845
+ }
846
+ for (const item of items) {
847
+ seen.add(dedupe(item));
848
+ }
849
+ }
850
+ const hasMoreInSource = next.value.nextCursor != null;
851
+ const hasMoreSources = sourceIndex < sources.length - 1;
852
+ return {
853
+ data: items,
854
+ nextCursor: hasMoreInSource || hasMoreSources ? "__has_more__" : void 0
855
+ };
856
+ }
857
+ return { data: [] };
858
+ };
859
+ const iterator = paginateBuffered(pageFunction, { pageSize });
860
+ const firstPagePromise = iterator.next().then((result) => {
861
+ if (result.done) {
862
+ return { data: [] };
863
+ }
864
+ return result.value;
865
+ });
866
+ return Object.assign(firstPagePromise, {
867
+ [Symbol.asyncIterator]: async function* () {
868
+ yield await firstPagePromise;
869
+ for await (const page of { [Symbol.asyncIterator]: () => iterator }) {
870
+ yield page;
871
+ }
872
+ }
873
+ });
874
+ }
813
875
 
814
876
  // src/utils/validation.ts
815
877
  var validate = (schema, input) => {
@@ -1841,6 +1903,625 @@ var clientIdResolver = {
1841
1903
  })
1842
1904
  };
1843
1905
 
1906
+ // src/resolvers/tableId.ts
1907
+ var tableIdResolver = {
1908
+ type: "dynamic",
1909
+ fetch: (sdk) => {
1910
+ return concatPaginated({
1911
+ sources: [() => sdk.listTables({ owner: "me" }), () => sdk.listTables()],
1912
+ dedupe: (table) => table.id
1913
+ });
1914
+ },
1915
+ prompt: (tables) => ({
1916
+ type: "list",
1917
+ name: "tableId",
1918
+ message: "Select a table:",
1919
+ choices: tables.map((table) => ({
1920
+ name: `${table.name} (${table.id})`,
1921
+ value: table.id
1922
+ }))
1923
+ })
1924
+ };
1925
+ function formatFieldValue(v) {
1926
+ if (v == null) return "";
1927
+ if (typeof v === "object") {
1928
+ try {
1929
+ return JSON.stringify(v);
1930
+ } catch {
1931
+ return String(v);
1932
+ }
1933
+ }
1934
+ return String(v);
1935
+ }
1936
+ function toNumericFieldId(id) {
1937
+ if (typeof id === "number") return id;
1938
+ const num = parseInt(id.replace(/^f/, ""), 10);
1939
+ if (isNaN(num)) {
1940
+ throw new ZapierValidationError(
1941
+ `Invalid field ID: "${id}". Expected a numeric ID like "f6", "6", or 6.`
1942
+ );
1943
+ }
1944
+ return num;
1945
+ }
1946
+ function transformTableItem(apiItem) {
1947
+ return {
1948
+ id: apiItem.id,
1949
+ name: apiItem.name,
1950
+ description: apiItem.description ?? void 0,
1951
+ created_at: apiItem.created_at,
1952
+ edited_at: apiItem.edited_at,
1953
+ kind: apiItem.kind,
1954
+ owner_account_id: String(apiItem.owner_account_id),
1955
+ profile_id: String(apiItem.owner_zapier_customuser_id),
1956
+ parent_table_id: apiItem.parent_table_id ?? void 0
1957
+ };
1958
+ }
1959
+ function transformFieldItem(apiItem) {
1960
+ return {
1961
+ id: `f${apiItem.id}`,
1962
+ type: apiItem.type,
1963
+ name: apiItem.name,
1964
+ created_at: apiItem.created_at,
1965
+ edited_at: apiItem.edited_at,
1966
+ options: apiItem.options,
1967
+ config: apiItem.config
1968
+ };
1969
+ }
1970
+ function transformRecordItem(apiItem) {
1971
+ return {
1972
+ id: apiItem.id,
1973
+ data: apiItem.data,
1974
+ created_at: apiItem.created_at,
1975
+ edited_at: apiItem.edited_at
1976
+ };
1977
+ }
1978
+ function formatRecordError(fieldId, err) {
1979
+ const message = err.h || err.e || "validation error";
1980
+ if (err.v !== void 0) {
1981
+ return `Field ${fieldId}: ${message} (value: ${JSON.stringify(err.v)})`;
1982
+ }
1983
+ return `Field ${fieldId}: ${message}`;
1984
+ }
1985
+ function formatResponseError(err) {
1986
+ const message = err.human_title || err.title || "Unknown error";
1987
+ if (err.meta && Object.keys(err.meta).length > 0) {
1988
+ const metaParts = Object.entries(err.meta).map(([key, val]) => `${key}: ${JSON.stringify(val)}`).join(", ");
1989
+ return `${message} (${metaParts})`;
1990
+ }
1991
+ return message;
1992
+ }
1993
+ function throwOnRecordErrors(record) {
1994
+ if (!record.errors) return;
1995
+ const messages = [];
1996
+ for (const [fieldId, error] of Object.entries(record.errors)) {
1997
+ const err = error;
1998
+ if (err.s === "error") {
1999
+ messages.push(formatRecordError(fieldId, err));
2000
+ }
2001
+ }
2002
+ if (messages.length > 0) {
2003
+ throw new ZapierValidationError(
2004
+ `Record ${record.id} has errors: ${messages.join("; ")}`
2005
+ );
2006
+ }
2007
+ }
2008
+ function throwOnResponseErrors(response) {
2009
+ const errors = response.meta?.errors;
2010
+ if (!errors || errors.length === 0) return;
2011
+ const messages = errors.map(
2012
+ (err) => formatResponseError(err)
2013
+ );
2014
+ throw new ZapierValidationError(messages.join("; "));
2015
+ }
2016
+ var KeyModeSchema = z.enum(["names", "ids"]).optional().default("names").describe(
2017
+ 'How to interpret field keys in record data. "names" (default) uses human-readable field names, "ids" uses raw field IDs (f1, f2).'
2018
+ );
2019
+ var FIELD_ID_PATTERN = /^f\d+$/;
2020
+ function isFieldId(key) {
2021
+ return FIELD_ID_PATTERN.test(key);
2022
+ }
2023
+ var NESTED_COMPONENTS = {
2024
+ labeled_string: /* @__PURE__ */ new Set(["value"]),
2025
+ ai_formula: /* @__PURE__ */ new Set(["value"]),
2026
+ link: /* @__PURE__ */ new Set(["link", "text"]),
2027
+ linked_record: /* @__PURE__ */ new Set(["label", "source"])
2028
+ };
2029
+ async function getFieldMapping(api, tableId, keyMode) {
2030
+ if (keyMode === "ids") {
2031
+ return null;
2032
+ }
2033
+ const rawResponse = await api.get(`/tables/api/v1/tables/${tableId}/fields`, {
2034
+ authRequired: true
2035
+ });
2036
+ const data = rawResponse.data;
2037
+ const nameToId = /* @__PURE__ */ new Map();
2038
+ const idToName = /* @__PURE__ */ new Map();
2039
+ const idToType = /* @__PURE__ */ new Map();
2040
+ for (const field of data) {
2041
+ const id = `f${field.id}`;
2042
+ if (!nameToId.has(field.name)) {
2043
+ nameToId.set(field.name, id);
2044
+ }
2045
+ if (!idToName.has(id)) {
2046
+ idToName.set(id, field.name);
2047
+ }
2048
+ idToType.set(id, field.type);
2049
+ }
2050
+ return { nameToId, idToName, idToType };
2051
+ }
2052
+ async function resolveFieldKeys({
2053
+ api,
2054
+ tableId,
2055
+ fieldKeys
2056
+ }) {
2057
+ const allAreIds = fieldKeys.every(
2058
+ (key) => typeof key === "number" || /^(f?\d+)$/.test(key)
2059
+ );
2060
+ if (allAreIds) {
2061
+ return fieldKeys.map(toNumericFieldId);
2062
+ }
2063
+ const mapping = await getFieldMapping(api, tableId, "names");
2064
+ if (!mapping) {
2065
+ return fieldKeys.map(toNumericFieldId);
2066
+ }
2067
+ return fieldKeys.map((key) => {
2068
+ if (typeof key === "number") return key;
2069
+ if (FIELD_ID_PATTERN.test(key)) return toNumericFieldId(key);
2070
+ const id = mapping.nameToId.get(key);
2071
+ if (!id) {
2072
+ throw new ZapierValidationError(
2073
+ `Unknown field name: "${key}". Use a valid field name or ID.`
2074
+ );
2075
+ }
2076
+ return toNumericFieldId(id);
2077
+ });
2078
+ }
2079
+ async function createFieldKeyTranslator({
2080
+ api,
2081
+ tableId,
2082
+ keyMode
2083
+ }) {
2084
+ const mapping = await getFieldMapping(api, tableId, keyMode);
2085
+ return {
2086
+ translateInput(data) {
2087
+ if (!mapping) return data;
2088
+ const result = {};
2089
+ for (const [key, value] of Object.entries(data)) {
2090
+ if (FIELD_ID_PATTERN.test(key) && mapping.idToName.has(key)) {
2091
+ result[key] = value;
2092
+ } else if (mapping.nameToId.has(key)) {
2093
+ result[mapping.nameToId.get(key)] = value;
2094
+ } else {
2095
+ result[key] = value;
2096
+ }
2097
+ }
2098
+ return result;
2099
+ },
2100
+ translateOutput(data) {
2101
+ if (!mapping) return data;
2102
+ const result = {};
2103
+ for (const [key, value] of Object.entries(data)) {
2104
+ if (mapping.idToName.has(key)) {
2105
+ result[mapping.idToName.get(key)] = value;
2106
+ } else {
2107
+ result[key] = value;
2108
+ }
2109
+ }
2110
+ return result;
2111
+ },
2112
+ translateFieldKey(key) {
2113
+ if (!mapping) return key;
2114
+ if (FIELD_ID_PATTERN.test(key) && mapping.idToName.has(key)) {
2115
+ const fieldType = mapping.idToType.get(key);
2116
+ if (fieldType) {
2117
+ const components = NESTED_COMPONENTS[fieldType];
2118
+ if (components?.size === 1) {
2119
+ return `${key}__${[...components][0]}`;
2120
+ }
2121
+ }
2122
+ return key;
2123
+ }
2124
+ if (mapping.nameToId.has(key)) {
2125
+ const fieldId = mapping.nameToId.get(key);
2126
+ const fieldType = mapping.idToType.get(fieldId);
2127
+ if (fieldType) {
2128
+ const components = NESTED_COMPONENTS[fieldType];
2129
+ if (components?.size === 1) {
2130
+ return `${fieldId}__${[...components][0]}`;
2131
+ }
2132
+ }
2133
+ return fieldId;
2134
+ }
2135
+ const sepIndex = key.lastIndexOf("__");
2136
+ if (sepIndex > 0) {
2137
+ const prefix = key.slice(0, sepIndex);
2138
+ const component = key.slice(sepIndex + 2);
2139
+ let fieldId;
2140
+ if (FIELD_ID_PATTERN.test(prefix) && mapping.idToName.has(prefix)) {
2141
+ fieldId = prefix;
2142
+ } else {
2143
+ fieldId = mapping.nameToId.get(prefix);
2144
+ }
2145
+ if (fieldId) {
2146
+ const fieldType = mapping.idToType.get(fieldId);
2147
+ if (fieldType && NESTED_COMPONENTS[fieldType]?.has(component)) {
2148
+ return `${fieldId}__${component}`;
2149
+ }
2150
+ }
2151
+ }
2152
+ return key;
2153
+ }
2154
+ };
2155
+ }
2156
+
2157
+ // src/resolvers/tableRecordId.ts
2158
+ function summarizeRecord(record) {
2159
+ const values = Object.values(record.data);
2160
+ const preview = values.slice(0, 3).map((v) => formatFieldValue(v).replace(/\s+/g, " ").trim()).filter((s) => s.length > 0).join(", ");
2161
+ const truncated = preview.length > 60 ? preview.slice(0, 57) + "..." : preview;
2162
+ return truncated ? `${record.id} \u2014 ${truncated}` : record.id;
2163
+ }
2164
+ function fetchRecords(sdk, params) {
2165
+ return sdk.listTableRecords({
2166
+ tableId: params.tableId,
2167
+ keyMode: "names"
2168
+ });
2169
+ }
2170
+ function recordChoices(records) {
2171
+ return records.map((record) => ({
2172
+ name: summarizeRecord(record),
2173
+ value: record.id
2174
+ }));
2175
+ }
2176
+ var tableRecordIdResolver = {
2177
+ type: "dynamic",
2178
+ depends: ["tableId"],
2179
+ fetch: fetchRecords,
2180
+ prompt: (records) => ({
2181
+ type: "list",
2182
+ name: "recordId",
2183
+ message: "Select a record:",
2184
+ choices: recordChoices(records)
2185
+ })
2186
+ };
2187
+ var tableRecordIdsResolver = {
2188
+ type: "dynamic",
2189
+ depends: ["tableId"],
2190
+ fetch: fetchRecords,
2191
+ prompt: (records) => ({
2192
+ type: "checkbox",
2193
+ name: "recordIds",
2194
+ message: "Select records to delete:",
2195
+ choices: recordChoices(records),
2196
+ validate: (value) => Array.isArray(value) && value.length > 0 ? true : "Select at least one record"
2197
+ })
2198
+ };
2199
+
2200
+ // src/resolvers/tableFieldIds.ts
2201
+ var tableFieldIdsResolver = {
2202
+ type: "dynamic",
2203
+ depends: ["tableId"],
2204
+ fetch: (sdk, params) => {
2205
+ return sdk.listTableFields({ tableId: params.tableId });
2206
+ },
2207
+ prompt: (fields) => ({
2208
+ type: "checkbox",
2209
+ name: "fieldKeys",
2210
+ message: "Select fields:",
2211
+ choices: fields.map((field) => ({
2212
+ name: `${field.name} (${field.id}, ${field.type})`,
2213
+ value: field.id
2214
+ })),
2215
+ validate: (value) => Array.isArray(value) && value.length > 0 ? true : "Select at least one field"
2216
+ })
2217
+ };
2218
+
2219
+ // src/resolvers/tableName.ts
2220
+ var tableNameResolver = {
2221
+ type: "static",
2222
+ inputType: "text",
2223
+ placeholder: "Enter a name for the table"
2224
+ };
2225
+ var FieldTypeSchema = z.enum([
2226
+ "string",
2227
+ "multiple_string",
2228
+ "labeled_string",
2229
+ "multiple_labeled_string",
2230
+ "text",
2231
+ "multiple_text",
2232
+ "boolean",
2233
+ "multiple_boolean",
2234
+ "number",
2235
+ "multiple_number",
2236
+ "decimal",
2237
+ "multiple_decimal",
2238
+ "datetime",
2239
+ "multiple_datetime",
2240
+ "uuid",
2241
+ "multiple_uuid",
2242
+ "json",
2243
+ "multiple_json",
2244
+ "formula",
2245
+ "button_trigger_zap",
2246
+ "button_continue_zap",
2247
+ "email",
2248
+ "multiple_email",
2249
+ "link",
2250
+ "multiple_link",
2251
+ "currency",
2252
+ "phone_number",
2253
+ "ai_formula",
2254
+ "linked_record",
2255
+ "multiple_linked_record"
2256
+ ]);
2257
+ var FieldApiItemSchema = z.object({
2258
+ id: z.number(),
2259
+ type: FieldTypeSchema,
2260
+ name: z.string(),
2261
+ created_at: z.string().optional(),
2262
+ edited_at: z.string().optional(),
2263
+ options: z.record(z.string(), z.unknown()).optional(),
2264
+ config: z.record(z.string(), z.unknown()).optional(),
2265
+ is_order_field: z.boolean().optional(),
2266
+ is_filter_field: z.boolean().optional(),
2267
+ is_selected_field: z.boolean().optional()
2268
+ });
2269
+ var ListTableFieldsApiResponseSchema = z.object({
2270
+ data: z.array(FieldApiItemSchema)
2271
+ });
2272
+ var FieldItemSchemaBase = z.object({
2273
+ id: z.string(),
2274
+ type: FieldTypeSchema,
2275
+ name: z.string(),
2276
+ created_at: z.string().optional(),
2277
+ edited_at: z.string().optional(),
2278
+ options: z.record(z.string(), z.unknown()).optional(),
2279
+ config: z.record(z.string(), z.unknown()).optional()
2280
+ });
2281
+ var FieldItemSchema = withFormatter(FieldItemSchemaBase, {
2282
+ format: (item) => ({
2283
+ title: item.name,
2284
+ id: item.id,
2285
+ details: [{ text: `Type: ${item.type}`, style: "dim" }]
2286
+ })
2287
+ });
2288
+ var ListTableFieldsOptionsSchema = z.object({
2289
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
2290
+ fieldKeys: z.array(z.union([z.string(), z.number()])).optional().describe(
2291
+ 'Filter by specific fields. Accepts field names (e.g., "Email") or IDs (e.g., "f6", "6", or 6).'
2292
+ )
2293
+ }).describe("List fields for a table");
2294
+
2295
+ // src/resolvers/tableFields.ts
2296
+ var fieldTypeChoices = FieldTypeSchema.options.map((type) => ({
2297
+ label: type,
2298
+ value: type
2299
+ }));
2300
+ var singleFieldResolver = {
2301
+ type: "fields",
2302
+ fetch: async () => {
2303
+ return [
2304
+ {
2305
+ type: "input_field",
2306
+ key: "type",
2307
+ title: "Field type",
2308
+ is_required: true,
2309
+ choices: fieldTypeChoices
2310
+ },
2311
+ {
2312
+ type: "input_field",
2313
+ key: "name",
2314
+ title: "Field name",
2315
+ is_required: true
2316
+ }
2317
+ ];
2318
+ }
2319
+ };
2320
+ var tableFieldsResolver = {
2321
+ type: "array",
2322
+ fetch: async () => singleFieldResolver,
2323
+ minItems: 1
2324
+ };
2325
+
2326
+ // src/resolvers/tableRecords.ts
2327
+ function tableFieldValueType(fieldType) {
2328
+ if (fieldType.startsWith("multiple_")) return "array";
2329
+ switch (fieldType) {
2330
+ case "number":
2331
+ case "decimal":
2332
+ case "currency":
2333
+ return "number";
2334
+ case "boolean":
2335
+ return "boolean";
2336
+ default:
2337
+ return void 0;
2338
+ }
2339
+ }
2340
+ function createSingleRecordResolver({
2341
+ sdk,
2342
+ tableId,
2343
+ includeRecordId
2344
+ }) {
2345
+ return {
2346
+ type: "fields",
2347
+ fetch: async () => {
2348
+ const { data: fields } = await sdk.listTableFields({ tableId });
2349
+ const inputFields = fields.map((field) => ({
2350
+ type: "input_field",
2351
+ key: field.id,
2352
+ title: field.name,
2353
+ is_required: false,
2354
+ ...tableFieldValueType(field.type) && {
2355
+ value_type: tableFieldValueType(field.type)
2356
+ }
2357
+ }));
2358
+ if (includeRecordId) {
2359
+ return [
2360
+ {
2361
+ type: "input_field",
2362
+ key: "_record_id",
2363
+ title: "Record",
2364
+ is_required: true,
2365
+ resolver: tableRecordIdResolver
2366
+ },
2367
+ ...inputFields
2368
+ ];
2369
+ }
2370
+ return inputFields;
2371
+ },
2372
+ transform: (values) => {
2373
+ if (includeRecordId) {
2374
+ const { _record_id: id, ...data } = values;
2375
+ return { id, data };
2376
+ }
2377
+ return { data: values };
2378
+ }
2379
+ };
2380
+ }
2381
+ var tableRecordsResolver = {
2382
+ type: "array",
2383
+ depends: ["tableId"],
2384
+ fetch: async (sdk, params) => {
2385
+ return createSingleRecordResolver({
2386
+ sdk,
2387
+ tableId: params.tableId
2388
+ });
2389
+ },
2390
+ minItems: 1
2391
+ };
2392
+ var tableUpdateRecordsResolver = {
2393
+ type: "array",
2394
+ depends: ["tableId"],
2395
+ fetch: async (sdk, params) => {
2396
+ return createSingleRecordResolver({
2397
+ sdk,
2398
+ tableId: params.tableId,
2399
+ includeRecordId: true
2400
+ });
2401
+ },
2402
+ minItems: 1
2403
+ };
2404
+
2405
+ // src/resolvers/tableFilters.ts
2406
+ var FILTER_OPERATORS = [
2407
+ { label: "equals", value: "exact" },
2408
+ { label: "not equals", value: "different" },
2409
+ { label: "contains", value: "contains" },
2410
+ { label: "contains (case-insensitive)", value: "icontains" },
2411
+ { label: "starts with", value: "startswith" },
2412
+ { label: "search", value: "search" },
2413
+ { label: "greater than", value: "gt" },
2414
+ { label: "greater than or equal", value: "gte" },
2415
+ { label: "less than", value: "lt" },
2416
+ { label: "less than or equal", value: "lte" },
2417
+ { label: "in range", value: "range" },
2418
+ { label: "in list", value: "in" },
2419
+ { label: "is empty", value: "isnull" },
2420
+ { label: "is within (date)", value: "is_within" }
2421
+ ];
2422
+ function createSingleFilterResolver({
2423
+ sdk,
2424
+ tableId
2425
+ }) {
2426
+ return {
2427
+ type: "fields",
2428
+ fetch: async () => {
2429
+ const { data: fields } = await sdk.listTableFields({ tableId });
2430
+ const fieldChoices = fields.flatMap((field) => {
2431
+ const components = NESTED_COMPONENTS[field.type];
2432
+ if (components && components.size > 1) {
2433
+ return [...components].map((component) => ({
2434
+ label: `${field.name}__${component} (${field.id}, ${field.type})`,
2435
+ value: `${field.name}__${component}`
2436
+ }));
2437
+ }
2438
+ return {
2439
+ label: `${field.name} (${field.id}${components ? `, ${field.type}` : ""})`,
2440
+ value: components ? `${field.name}__${[...components][0]}` : field.name
2441
+ };
2442
+ });
2443
+ const fieldItems = [
2444
+ {
2445
+ type: "input_field",
2446
+ key: "fieldKey",
2447
+ title: "Field",
2448
+ is_required: true,
2449
+ choices: fieldChoices
2450
+ },
2451
+ {
2452
+ type: "input_field",
2453
+ key: "operator",
2454
+ title: "Operator",
2455
+ is_required: true,
2456
+ choices: FILTER_OPERATORS
2457
+ },
2458
+ {
2459
+ type: "input_field",
2460
+ key: "value",
2461
+ title: "Value",
2462
+ is_required: false
2463
+ }
2464
+ ];
2465
+ return fieldItems;
2466
+ }
2467
+ };
2468
+ }
2469
+ var tableFiltersResolver = {
2470
+ type: "array",
2471
+ depends: ["tableId"],
2472
+ fetch: async (sdk, params) => {
2473
+ return createSingleFilterResolver({
2474
+ sdk,
2475
+ tableId: params.tableId
2476
+ });
2477
+ },
2478
+ minItems: 0
2479
+ };
2480
+
2481
+ // src/resolvers/tableSort.ts
2482
+ var tableSortResolver = {
2483
+ type: "fields",
2484
+ depends: ["tableId"],
2485
+ fetch: async (sdk, params) => {
2486
+ const { data: fields } = await sdk.listTableFields({
2487
+ tableId: params.tableId
2488
+ });
2489
+ const fieldChoices = fields.flatMap((field) => {
2490
+ const components = NESTED_COMPONENTS[field.type];
2491
+ if (components) {
2492
+ return [...components].map((component) => ({
2493
+ label: `${field.name}__${component} (${field.id}, ${field.type})`,
2494
+ value: `${field.name}__${component}`
2495
+ }));
2496
+ }
2497
+ return {
2498
+ label: `${field.name} (${field.id})`,
2499
+ value: field.name
2500
+ };
2501
+ });
2502
+ const fieldItems = [
2503
+ {
2504
+ type: "input_field",
2505
+ key: "fieldKey",
2506
+ title: "Field",
2507
+ is_required: true,
2508
+ choices: fieldChoices
2509
+ },
2510
+ {
2511
+ type: "input_field",
2512
+ key: "direction",
2513
+ title: "Direction",
2514
+ is_required: true,
2515
+ choices: [
2516
+ { label: "Ascending", value: "asc" },
2517
+ { label: "Descending", value: "desc" }
2518
+ ]
2519
+ }
2520
+ ];
2521
+ return fieldItems;
2522
+ }
2523
+ };
2524
+
1844
2525
  // src/plugins/listActions/index.ts
1845
2526
  var listActionsPlugin = ({ context }) => {
1846
2527
  const methodMeta = {
@@ -2633,25 +3314,29 @@ var DeleteClientCredentialsSchema = z.object({
2633
3314
  var deleteClientCredentialsPlugin = ({ context }) => {
2634
3315
  async function deleteClientCredentials(options) {
2635
3316
  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
- });
3317
+ await api.delete(
3318
+ `/api/v0/client-credentials/${options.clientId}`,
3319
+ void 0,
3320
+ {
3321
+ customErrorHandler: ({ status }) => {
3322
+ if (status === 401) {
3323
+ return new ZapierAuthenticationError(
3324
+ `Authentication failed. Your token may not have permission to delete client credentials or may be expired. (HTTP ${status})`,
3325
+ { statusCode: status }
3326
+ );
3327
+ }
3328
+ if (status === 403) {
3329
+ return new ZapierAuthenticationError(
3330
+ `Access forbidden. Your token may not have the required scopes to delete client credentials. (HTTP ${status})`,
3331
+ { statusCode: status }
3332
+ );
3333
+ }
3334
+ return void 0;
3335
+ },
3336
+ authRequired: true,
3337
+ requiredScopes: ["credentials"]
3338
+ }
3339
+ );
2655
3340
  return {
2656
3341
  success: true
2657
3342
  };
@@ -4488,6 +5173,11 @@ var pathConfig = {
4488
5173
  "/zapier": {
4489
5174
  authHeader: "Authorization",
4490
5175
  pathPrefix: "/api/v0/sdk/zapier"
5176
+ },
5177
+ // e.g. /tables -> https://sdkapi.zapier.com/api/v0/sdk/tables/...
5178
+ "/tables": {
5179
+ authHeader: "Authorization",
5180
+ pathPrefix: "/api/v0/sdk/tables"
4491
5181
  }
4492
5182
  };
4493
5183
  var ZapierApiClient = class {
@@ -4555,8 +5245,11 @@ var ZapierApiClient = class {
4555
5245
  this.put = async (path, data, options = {}) => {
4556
5246
  return this.fetchJson("PUT", path, data, options);
4557
5247
  };
4558
- this.delete = async (path, options = {}) => {
4559
- return this.fetchJson("DELETE", path, void 0, options);
5248
+ this.patch = async (path, data, options = {}) => {
5249
+ return this.fetchJson("PATCH", path, data, options);
5250
+ };
5251
+ this.delete = async (path, data, options = {}) => {
5252
+ return this.fetchJson("DELETE", path, data, options);
4560
5253
  };
4561
5254
  this.poll = async (path, options = {}) => {
4562
5255
  return pollUntilComplete({
@@ -4960,19 +5653,1093 @@ async function batch(tasks, options = {}) {
4960
5653
  await Promise.all(workers);
4961
5654
  return results;
4962
5655
  }
5656
+ var TableApiItemSchema = z.object({
5657
+ id: z.string(),
5658
+ name: z.string(),
5659
+ description: z.string().nullable().optional(),
5660
+ created_at: z.string(),
5661
+ edited_at: z.string(),
5662
+ kind: z.enum(["table", "virtual_table"]),
5663
+ owner_account_id: z.number(),
5664
+ owner_user_id: z.number().nullable().optional(),
5665
+ owner_zapier_customuser_id: z.number(),
5666
+ parent_table_id: z.string().nullable().optional()
5667
+ });
5668
+ var ListTablesApiResponseSchema = z.object({
5669
+ data: z.array(TableApiItemSchema),
5670
+ links: z.object({
5671
+ next: z.string().nullable().optional()
5672
+ }).optional()
5673
+ });
5674
+ var TableItemSchema = z.object({
5675
+ id: z.string(),
5676
+ name: z.string(),
5677
+ description: z.string().optional(),
5678
+ created_at: z.string(),
5679
+ edited_at: z.string(),
5680
+ kind: z.enum(["table", "virtual_table"]),
5681
+ owner_account_id: z.string(),
5682
+ profile_id: z.string(),
5683
+ parent_table_id: z.string().optional()
5684
+ });
5685
+ var ListTablesOptionsSchema = z.object({
5686
+ tableIds: z.array(z.string()).optional().describe("Filter by specific table IDs"),
5687
+ kind: z.enum(["table", "virtual_table", "both"]).optional().describe("Filter by table type"),
5688
+ search: z.string().optional().describe("Search term to filter tables by name"),
5689
+ owner: z.string().optional().describe(
5690
+ 'Filter by table owner. Use "me" for the current user, or a numeric user ID.'
5691
+ ),
5692
+ pageSize: z.number().min(1).optional().describe("Number of tables per page"),
5693
+ maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
5694
+ cursor: z.string().optional().describe("Cursor to start from")
5695
+ }).describe("List tables available to the authenticated user");
4963
5696
 
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: {
5697
+ // src/plugins/tables/listTables/index.ts
5698
+ function extractNextCursor(links) {
5699
+ if (!links?.next) {
5700
+ return void 0;
5701
+ }
5702
+ try {
5703
+ const url = new URL(links.next);
5704
+ const offset = url.searchParams.get("offset");
5705
+ return offset || void 0;
5706
+ } catch {
5707
+ return void 0;
5708
+ }
5709
+ }
5710
+ var listTablesPlugin = ({ context }) => {
5711
+ async function listTablesPage(options) {
5712
+ const { api } = context;
5713
+ const searchParams = {
5714
+ limit: options.pageSize.toString()
5715
+ };
5716
+ if (options?.tableIds && options.tableIds.length > 0) {
5717
+ searchParams.ids = options.tableIds.join(",");
5718
+ }
5719
+ if (options?.kind) {
5720
+ searchParams.kind = options.kind;
5721
+ }
5722
+ if (options?.search) {
5723
+ searchParams.q = options.search;
5724
+ }
5725
+ if (options?.owner) {
5726
+ let ownerId = options.owner;
5727
+ if (ownerId === "me") {
5728
+ const profile = await api.get("/zapier/api/v4/profile/", {
5729
+ authRequired: true
5730
+ });
5731
+ ownerId = String(profile.id);
5732
+ }
5733
+ searchParams.owner_customuser_id = ownerId;
5734
+ }
5735
+ if (options.cursor) {
5736
+ searchParams.offset = options.cursor;
5737
+ }
5738
+ const rawResponse = await api.get("/tables/api/v1/tables", {
5739
+ searchParams,
5740
+ customErrorHandler: ({ status }) => {
5741
+ if (status === 401) {
5742
+ return new ZapierAuthenticationError(
5743
+ `Authentication failed. Your token may not have permission to list tables or may be expired. (HTTP ${status})`,
5744
+ { statusCode: status }
5745
+ );
5746
+ }
5747
+ if (status === 403) {
5748
+ return new ZapierAuthenticationError(
5749
+ `Access forbidden. Your token may not have the required scopes to list tables. (HTTP ${status})`,
5750
+ { statusCode: status }
5751
+ );
5752
+ }
5753
+ return void 0;
5754
+ },
5755
+ authRequired: true
5756
+ });
5757
+ const response = ListTablesApiResponseSchema.parse(rawResponse);
5758
+ return {
5759
+ data: response.data.map(transformTableItem),
5760
+ nextCursor: extractNextCursor(response.links)
5761
+ };
5762
+ }
5763
+ const methodName = stripPageSuffix(listTablesPage.name);
5764
+ const listTablesDefinition = createPaginatedFunction(
5765
+ listTablesPage,
5766
+ ListTablesOptionsSchema,
5767
+ createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
5768
+ methodName
5769
+ );
5770
+ return {
5771
+ listTables: listTablesDefinition,
5772
+ context: {
5773
+ meta: {
5774
+ listTables: {
5775
+ categories: ["table"],
5776
+ type: "list",
5777
+ itemType: "Table",
5778
+ inputSchema: ListTablesOptionsSchema,
5779
+ outputSchema: TableItemSchema
5780
+ }
5781
+ }
5782
+ }
5783
+ };
5784
+ };
5785
+ var GetTableApiResponseSchema = z.object({
5786
+ data: TableApiItemSchema
5787
+ });
5788
+ var GetTableOptionsSchema = z.object({
5789
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table to retrieve")
5790
+ }).describe("Get detailed information about a specific table");
5791
+
5792
+ // src/plugins/tables/getTable/index.ts
5793
+ var getTablePlugin = ({ context }) => {
5794
+ async function getTable(options) {
5795
+ const { api } = context;
5796
+ const rawResponse = await api.get(
5797
+ `/tables/api/v1/tables/${options.tableId}`,
5798
+ {
5799
+ customErrorHandler: ({ status }) => {
5800
+ if (status === 401) {
5801
+ return new ZapierAuthenticationError(
5802
+ `Authentication failed. Your token may not have permission to access this table or may be expired. (HTTP ${status})`,
5803
+ { statusCode: status }
5804
+ );
5805
+ }
5806
+ if (status === 403) {
5807
+ return new ZapierAuthenticationError(
5808
+ `Access forbidden. Your token may not have the required scopes to access this table. (HTTP ${status})`,
5809
+ { statusCode: status }
5810
+ );
5811
+ }
5812
+ if (status === 404) {
5813
+ return new Error(`Table not found: ${options.tableId}`);
5814
+ }
5815
+ return void 0;
5816
+ },
5817
+ authRequired: true
5818
+ }
5819
+ );
5820
+ const response = GetTableApiResponseSchema.parse(rawResponse);
5821
+ return {
5822
+ data: transformTableItem(response.data)
5823
+ };
5824
+ }
5825
+ const getTableDefinition = createFunction(
5826
+ getTable,
5827
+ GetTableOptionsSchema,
5828
+ createTelemetryCallback(
5829
+ context.eventEmission.emitMethodCalled,
5830
+ getTable.name
5831
+ )
5832
+ );
5833
+ return {
5834
+ getTable: getTableDefinition,
5835
+ context: {
5836
+ meta: {
5837
+ getTable: {
5838
+ categories: ["table"],
5839
+ type: "item",
5840
+ itemType: "Table",
5841
+ inputSchema: GetTableOptionsSchema,
5842
+ outputSchema: TableItemSchema,
5843
+ resolvers: {
5844
+ tableId: tableIdResolver
5845
+ }
5846
+ }
5847
+ }
5848
+ }
5849
+ };
5850
+ };
5851
+ var CreateTableApiResponseSchema = z.object({
5852
+ data: TableApiItemSchema
5853
+ });
5854
+ var CreateTableOptionsSchema = z.object({
5855
+ name: z.string().min(1).describe("The name for the new table"),
5856
+ description: z.string().optional().describe("An optional description of the table")
5857
+ }).describe("Create a new table");
5858
+
5859
+ // src/plugins/tables/createTable/index.ts
5860
+ var createTablePlugin = ({ context }) => {
5861
+ async function createTable(options) {
5862
+ const { api } = context;
5863
+ const rawResponse = await api.post(
5864
+ "/tables/api/v1/tables",
5865
+ {
5866
+ name: options.name,
5867
+ description: options.description
5868
+ },
5869
+ {
5870
+ customErrorHandler: ({ status }) => {
5871
+ if (status === 401) {
5872
+ return new ZapierAuthenticationError(
5873
+ `Authentication failed. Your token may not have permission to create tables or may be expired. (HTTP ${status})`,
5874
+ { statusCode: status }
5875
+ );
5876
+ }
5877
+ if (status === 403) {
5878
+ return new ZapierAuthenticationError(
5879
+ `Access forbidden. Your token may not have the required scopes to create tables. (HTTP ${status})`,
5880
+ { statusCode: status }
5881
+ );
5882
+ }
5883
+ return void 0;
5884
+ },
5885
+ authRequired: true
5886
+ }
5887
+ );
5888
+ const response = CreateTableApiResponseSchema.parse(rawResponse);
5889
+ return {
5890
+ data: transformTableItem(response.data)
5891
+ };
5892
+ }
5893
+ const createTableDefinition = createFunction(
5894
+ createTable,
5895
+ CreateTableOptionsSchema,
5896
+ createTelemetryCallback(
5897
+ context.eventEmission.emitMethodCalled,
5898
+ createTable.name
5899
+ )
5900
+ );
5901
+ return {
5902
+ createTable: createTableDefinition,
5903
+ context: {
5904
+ meta: {
5905
+ createTable: {
5906
+ categories: ["table"],
5907
+ type: "create",
5908
+ itemType: "Table",
5909
+ inputSchema: CreateTableOptionsSchema,
5910
+ outputSchema: TableItemSchema,
5911
+ resolvers: {
5912
+ name: tableNameResolver
5913
+ }
5914
+ }
5915
+ }
5916
+ }
5917
+ };
5918
+ };
5919
+ var DeleteTableOptionsSchema = z.object({
5920
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table to delete")
5921
+ }).describe("Delete a table by its ID");
5922
+
5923
+ // src/plugins/tables/deleteTable/index.ts
5924
+ var deleteTablePlugin = ({ context }) => {
5925
+ async function deleteTable(options) {
5926
+ const { api } = context;
5927
+ await api.delete(`/tables/api/v1/tables/${options.tableId}`, void 0, {
5928
+ customErrorHandler: ({ status }) => {
5929
+ if (status === 401) {
5930
+ return new ZapierAuthenticationError(
5931
+ `Authentication failed. Your token may not have permission to delete tables or may be expired. (HTTP ${status})`,
5932
+ { statusCode: status }
5933
+ );
5934
+ }
5935
+ if (status === 403) {
5936
+ return new ZapierAuthenticationError(
5937
+ `Access forbidden. Your token may not have the required scopes to delete tables. (HTTP ${status})`,
5938
+ { statusCode: status }
5939
+ );
5940
+ }
5941
+ return void 0;
5942
+ },
5943
+ authRequired: true
5944
+ });
5945
+ return {
5946
+ success: true
5947
+ };
5948
+ }
5949
+ const deleteTableDefinition = createFunction(
5950
+ deleteTable,
5951
+ DeleteTableOptionsSchema,
5952
+ createTelemetryCallback(
5953
+ context.eventEmission.emitMethodCalled,
5954
+ deleteTable.name
5955
+ )
5956
+ );
5957
+ return {
5958
+ deleteTable: deleteTableDefinition,
5959
+ context: {
5960
+ meta: {
5961
+ deleteTable: {
5962
+ categories: ["table"],
5963
+ type: "delete",
5964
+ itemType: "Table",
5965
+ inputSchema: DeleteTableOptionsSchema,
5966
+ resolvers: {
5967
+ tableId: tableIdResolver
5968
+ },
5969
+ confirm: "delete"
5970
+ }
5971
+ }
5972
+ }
5973
+ };
5974
+ };
5975
+
5976
+ // src/plugins/tables/listTableFields/index.ts
5977
+ var listTableFieldsPlugin = ({ context }) => {
5978
+ async function listTableFields(options) {
5979
+ const { api } = context;
5980
+ const searchParams = {};
5981
+ if (options.fieldKeys && options.fieldKeys.length > 0) {
5982
+ const numericIds = await resolveFieldKeys({
5983
+ api,
5984
+ tableId: options.tableId,
5985
+ fieldKeys: options.fieldKeys
5986
+ });
5987
+ searchParams.field_ids = numericIds.join(",");
5988
+ }
5989
+ const rawResponse = await api.get(
5990
+ `/tables/api/v1/tables/${options.tableId}/fields`,
5991
+ {
5992
+ searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0,
5993
+ customErrorHandler: ({ status }) => {
5994
+ if (status === 401) {
5995
+ return new ZapierAuthenticationError(
5996
+ `Authentication failed. Your token may not have permission to access this table or may be expired. (HTTP ${status})`,
5997
+ { statusCode: status }
5998
+ );
5999
+ }
6000
+ if (status === 403) {
6001
+ return new ZapierAuthenticationError(
6002
+ `Access forbidden. Your token may not have the required scopes to access this table. (HTTP ${status})`,
6003
+ { statusCode: status }
6004
+ );
6005
+ }
6006
+ if (status === 404) {
6007
+ return new Error(`Table not found: ${options.tableId}`);
6008
+ }
6009
+ return void 0;
6010
+ },
6011
+ authRequired: true
6012
+ }
6013
+ );
6014
+ const response = ListTableFieldsApiResponseSchema.parse(rawResponse);
6015
+ return {
6016
+ data: response.data.map(transformFieldItem)
6017
+ };
6018
+ }
6019
+ const listTableFieldsDefinition = createFunction(
6020
+ listTableFields,
6021
+ ListTableFieldsOptionsSchema,
6022
+ createTelemetryCallback(
6023
+ context.eventEmission.emitMethodCalled,
6024
+ listTableFields.name
6025
+ )
6026
+ );
6027
+ return {
6028
+ listTableFields: listTableFieldsDefinition,
6029
+ context: {
6030
+ meta: {
6031
+ listTableFields: {
6032
+ categories: ["table"],
6033
+ type: "list",
6034
+ itemType: "Field",
6035
+ inputSchema: ListTableFieldsOptionsSchema,
6036
+ outputSchema: FieldItemSchema,
6037
+ resolvers: {
6038
+ tableId: tableIdResolver
6039
+ }
6040
+ }
6041
+ }
6042
+ }
6043
+ };
6044
+ };
6045
+ var FieldChangesetItemSchema = z.object({
6046
+ new: FieldApiItemSchema,
6047
+ old: FieldApiItemSchema.nullable(),
6048
+ kind: z.enum(["created", "updated", "deleted"])
6049
+ });
6050
+ var CreateTableFieldsApiResponseSchema = z.object({
6051
+ data: z.array(FieldChangesetItemSchema),
6052
+ meta: z.object({
6053
+ did_change: z.boolean()
6054
+ }).optional()
6055
+ });
6056
+ var NewFieldSchema = z.object({
6057
+ type: FieldTypeSchema.describe("The data type of the field"),
6058
+ name: z.string().min(1).describe("The display name of the field"),
6059
+ options: z.record(z.string(), z.unknown()).optional().describe("Data configuration options for the field"),
6060
+ config: z.record(z.string(), z.unknown()).optional().describe("Display configuration for the field")
6061
+ });
6062
+ var CreateTableFieldsOptionsSchema = z.object({
6063
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6064
+ fields: z.array(NewFieldSchema).min(1).describe("Array of field definitions to create")
6065
+ }).describe("Create one or more fields in a table");
6066
+
6067
+ // src/plugins/tables/createTableFields/index.ts
6068
+ var createTableFieldsPlugin = ({ context }) => {
6069
+ async function createTableFields(options) {
6070
+ const { api } = context;
6071
+ const rawResponse = await api.post(
6072
+ `/tables/api/v1/tables/${options.tableId}/fields`,
6073
+ {
6074
+ new_fields: options.fields
6075
+ },
6076
+ {
6077
+ customErrorHandler: ({ status }) => {
6078
+ if (status === 401) {
6079
+ return new ZapierAuthenticationError(
6080
+ `Authentication failed. Your token may not have permission to create fields or may be expired. (HTTP ${status})`,
6081
+ { statusCode: status }
6082
+ );
6083
+ }
6084
+ if (status === 403) {
6085
+ return new ZapierAuthenticationError(
6086
+ `Access forbidden. Your token may not have the required scopes to create fields. (HTTP ${status})`,
6087
+ { statusCode: status }
6088
+ );
6089
+ }
6090
+ return void 0;
6091
+ },
6092
+ authRequired: true
6093
+ }
6094
+ );
6095
+ const response = CreateTableFieldsApiResponseSchema.parse(rawResponse);
6096
+ return {
6097
+ data: response.data.map((changeset) => transformFieldItem(changeset.new))
6098
+ };
6099
+ }
6100
+ const createTableFieldsDefinition = createFunction(
6101
+ createTableFields,
6102
+ CreateTableFieldsOptionsSchema,
6103
+ createTelemetryCallback(
6104
+ context.eventEmission.emitMethodCalled,
6105
+ createTableFields.name
6106
+ )
6107
+ );
6108
+ return {
6109
+ createTableFields: createTableFieldsDefinition,
6110
+ context: {
6111
+ meta: {
6112
+ createTableFields: {
6113
+ categories: ["table"],
6114
+ type: "create",
6115
+ itemType: "Field",
6116
+ inputSchema: CreateTableFieldsOptionsSchema,
6117
+ outputSchema: FieldItemSchema,
6118
+ resolvers: {
6119
+ tableId: tableIdResolver,
6120
+ fields: tableFieldsResolver
6121
+ }
6122
+ }
6123
+ }
6124
+ }
6125
+ };
6126
+ };
6127
+ var DeleteTableFieldsOptionsSchema = z.object({
6128
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6129
+ fieldKeys: z.array(z.union([z.string(), z.number()])).min(1).describe(
6130
+ 'Fields to delete. Accepts field names (e.g., "Email") or IDs (e.g., "f6", "6", or 6).'
6131
+ )
6132
+ }).describe("Delete one or more fields from a table");
6133
+
6134
+ // src/plugins/tables/deleteTableFields/index.ts
6135
+ var deleteTableFieldsPlugin = ({ context }) => {
6136
+ async function deleteTableFields(options) {
6137
+ const { api } = context;
6138
+ const numericFieldIds = await resolveFieldKeys({
6139
+ api,
6140
+ tableId: options.tableId,
6141
+ fieldKeys: options.fieldKeys
6142
+ });
6143
+ await api.delete(
6144
+ `/tables/api/v1/tables/${options.tableId}/fields`,
6145
+ { field_ids: numericFieldIds },
6146
+ {
6147
+ customErrorHandler: ({ status }) => {
6148
+ if (status === 401) {
6149
+ return new ZapierAuthenticationError(
6150
+ `Authentication failed. Your token may not have permission to delete fields or may be expired. (HTTP ${status})`,
6151
+ { statusCode: status }
6152
+ );
6153
+ }
6154
+ if (status === 403) {
6155
+ return new ZapierAuthenticationError(
6156
+ `Access forbidden. Your token may not have the required scopes to delete fields. (HTTP ${status})`,
6157
+ { statusCode: status }
6158
+ );
6159
+ }
6160
+ return void 0;
6161
+ },
6162
+ authRequired: true
6163
+ }
6164
+ );
6165
+ return {
6166
+ success: true
6167
+ };
6168
+ }
6169
+ const deleteTableFieldsDefinition = createFunction(
6170
+ deleteTableFields,
6171
+ DeleteTableFieldsOptionsSchema,
6172
+ createTelemetryCallback(
6173
+ context.eventEmission.emitMethodCalled,
6174
+ deleteTableFields.name
6175
+ )
6176
+ );
6177
+ return {
6178
+ deleteTableFields: deleteTableFieldsDefinition,
6179
+ context: {
6180
+ meta: {
6181
+ deleteTableFields: {
6182
+ categories: ["table"],
6183
+ type: "delete",
6184
+ itemType: "Field",
6185
+ inputSchema: DeleteTableFieldsOptionsSchema,
6186
+ resolvers: {
6187
+ tableId: tableIdResolver,
6188
+ fieldKeys: tableFieldIdsResolver
6189
+ },
6190
+ confirm: "delete"
6191
+ }
6192
+ }
6193
+ }
6194
+ };
6195
+ };
6196
+ var RecordApiItemSchema = z.object({
6197
+ id: z.string().regex(/^[A-Z0-9]{26}$/, "Record ID must be a valid ULID"),
6198
+ data: z.record(z.string(), z.unknown()),
6199
+ created_at: z.string(),
6200
+ edited_at: z.string(),
6201
+ schema_revision_id: z.number(),
6202
+ errors: z.record(z.string(), z.unknown()).nullable().optional(),
6203
+ orig_data: z.record(z.string(), z.unknown()).nullable().optional(),
6204
+ is_source_record: z.boolean().nullable().optional()
6205
+ });
6206
+ var RecordItemSchemaBase = z.object({
6207
+ id: z.string(),
6208
+ data: z.record(z.string(), z.unknown()),
6209
+ created_at: z.string(),
6210
+ edited_at: z.string()
6211
+ });
6212
+ var RecordItemSchema = withFormatter(RecordItemSchemaBase, {
6213
+ format: (item) => ({
6214
+ title: `Record ${item.id}`,
6215
+ id: item.id,
6216
+ data: item.data,
6217
+ details: []
6218
+ })
6219
+ });
6220
+ var GetTableRecordApiResponseSchema = z.object({
6221
+ data: RecordApiItemSchema
6222
+ });
6223
+ var GetTableRecordOptionsSchema = z.object({
6224
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6225
+ recordId: z.string().regex(/^[A-Z0-9]{26}$/, "Record ID must be a valid ULID").describe("The unique identifier of the record"),
6226
+ keyMode: KeyModeSchema
6227
+ }).describe("Get a single record from a table by ID");
6228
+
6229
+ // src/formatters/tableRecord.ts
6230
+ var tableRecordFormatter = {
6231
+ fetch: async (sdk, params, item, context) => {
6232
+ if (context) return context;
6233
+ const hasFieldIds = Object.keys(item.data).some(isFieldId);
6234
+ if (!hasFieldIds) return {};
6235
+ const { data: fields } = await sdk.listTableFields({
6236
+ tableId: params.tableId
6237
+ });
6238
+ return Object.fromEntries(fields.map((f) => [f.id, f.name]));
6239
+ },
6240
+ format: (item, fieldLabels) => ({
6241
+ title: `Record ${item.id}`,
6242
+ id: item.id,
6243
+ details: Object.entries(item.data).map(([k, v]) => ({
6244
+ label: fieldLabels?.[k] ?? k,
6245
+ text: formatFieldValue(v),
6246
+ style: "normal"
6247
+ }))
6248
+ })
6249
+ };
6250
+
6251
+ // src/plugins/tables/getTableRecord/index.ts
6252
+ var getTableRecordPlugin = ({ context }) => {
6253
+ async function getTableRecord(options) {
6254
+ const { api } = context;
6255
+ const rawResponse = await api.get(
6256
+ `/tables/api/v1/tables/${options.tableId}/records/${options.recordId}`,
6257
+ {
6258
+ customErrorHandler: ({ status }) => {
6259
+ if (status === 401) {
6260
+ return new ZapierAuthenticationError(
6261
+ `Authentication failed. Your token may not have permission to access this record or may be expired. (HTTP ${status})`,
6262
+ { statusCode: status }
6263
+ );
6264
+ }
6265
+ if (status === 403) {
6266
+ return new ZapierAuthenticationError(
6267
+ `Access forbidden. Your token may not have the required scopes to access this record. (HTTP ${status})`,
6268
+ { statusCode: status }
6269
+ );
6270
+ }
6271
+ if (status === 404) {
6272
+ return new Error(`Record not found: ${options.recordId}`);
6273
+ }
6274
+ return void 0;
6275
+ },
6276
+ authRequired: true
6277
+ }
6278
+ );
6279
+ const response = GetTableRecordApiResponseSchema.parse(rawResponse);
6280
+ const translator = await createFieldKeyTranslator({
6281
+ api,
6282
+ tableId: options.tableId,
6283
+ keyMode: options.keyMode
6284
+ });
6285
+ return {
6286
+ data: {
6287
+ ...transformRecordItem(response.data),
6288
+ data: translator.translateOutput(response.data.data)
6289
+ }
6290
+ };
6291
+ }
6292
+ const getTableRecordDefinition = createFunction(
6293
+ getTableRecord,
6294
+ GetTableRecordOptionsSchema,
6295
+ createTelemetryCallback(
6296
+ context.eventEmission.emitMethodCalled,
6297
+ getTableRecord.name
6298
+ )
6299
+ );
6300
+ return {
6301
+ getTableRecord: getTableRecordDefinition,
6302
+ context: {
6303
+ meta: {
6304
+ getTableRecord: {
6305
+ categories: ["table"],
6306
+ type: "item",
6307
+ itemType: "Record",
6308
+ inputSchema: GetTableRecordOptionsSchema,
6309
+ outputSchema: RecordItemSchema,
6310
+ resolvers: {
6311
+ tableId: tableIdResolver,
6312
+ recordId: tableRecordIdResolver
6313
+ },
6314
+ formatter: tableRecordFormatter
6315
+ }
6316
+ }
6317
+ }
6318
+ };
6319
+ };
6320
+ var ListTableRecordsApiResponseSchema = z.object({
6321
+ data: z.array(RecordApiItemSchema),
6322
+ meta: z.object({
6323
+ pagination: z.object({
6324
+ start_cursor: z.string().nullable().optional(),
6325
+ end_cursor: z.string().nullable().optional(),
6326
+ has_more: z.boolean().optional(),
6327
+ has_less: z.boolean().optional()
6328
+ }).optional()
6329
+ }).optional()
6330
+ });
6331
+ var FilterOperatorSchema = z.enum([
6332
+ "exact",
6333
+ "different",
6334
+ "contains",
6335
+ "icontains",
6336
+ "gte",
6337
+ "gt",
6338
+ "lt",
6339
+ "lte",
6340
+ "range",
6341
+ "in",
6342
+ "isnull",
6343
+ "startswith",
6344
+ "search",
6345
+ "is_within"
6346
+ ]);
6347
+ var FilterConditionSchema = z.object({
6348
+ fieldKey: z.string().describe("The field key to filter on (e.g. f1, f2)"),
6349
+ operator: FilterOperatorSchema.describe("The comparison operator"),
6350
+ value: z.unknown().optional().describe("The value to compare against")
6351
+ });
6352
+ var SortDirectionSchema = z.enum(["asc", "desc"]);
6353
+ var SortConditionSchema = z.object({
6354
+ fieldKey: z.string().describe("The field key to sort by"),
6355
+ direction: SortDirectionSchema.optional().default("asc").describe("Sort direction")
6356
+ });
6357
+ var ListTableRecordsOptionsSchema = z.object({
6358
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6359
+ filters: z.array(FilterConditionSchema).optional().describe("Filter conditions for the query"),
6360
+ sort: SortConditionSchema.optional().describe("Sort records by a field"),
6361
+ pageSize: z.number().min(1).max(1e3).optional().describe("Number of records per page (max 1000)"),
6362
+ maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
6363
+ cursor: z.string().optional().describe("Cursor to start from"),
6364
+ keyMode: KeyModeSchema
6365
+ }).describe("List records in a table with optional filtering and sorting");
6366
+
6367
+ // src/plugins/tables/listTableRecords/index.ts
6368
+ function extractNextCursor2(meta) {
6369
+ if (!meta?.pagination?.has_more || !meta.pagination.end_cursor) {
6370
+ return void 0;
6371
+ }
6372
+ return meta.pagination.end_cursor;
6373
+ }
6374
+ var listTableRecordsPlugin = ({ context }) => {
6375
+ async function listTableRecordsPage(options) {
6376
+ const { api } = context;
6377
+ const translator = await createFieldKeyTranslator({
6378
+ api,
6379
+ tableId: options.tableId,
6380
+ keyMode: options.keyMode
6381
+ });
6382
+ const body = {
6383
+ limit: options.pageSize
6384
+ };
6385
+ if (options.filters) {
6386
+ body.filters = options.filters.map((f) => ({
6387
+ key: translator.translateFieldKey(f.fieldKey),
6388
+ operator: f.operator,
6389
+ value: f.value
6390
+ }));
6391
+ }
6392
+ if (options.sort) {
6393
+ body.orders = [
6394
+ {
6395
+ key: translator.translateFieldKey(options.sort.fieldKey),
6396
+ direction: options.sort.direction
6397
+ }
6398
+ ];
6399
+ }
6400
+ if (options.cursor) {
6401
+ body.cursor_query = {
6402
+ query_type: "window",
6403
+ start_cursor: options.cursor
6404
+ };
6405
+ }
6406
+ const rawResponse = await api.post(
6407
+ `/tables/api/v1/tables/${options.tableId}/records/query`,
6408
+ body,
6409
+ {
6410
+ searchParams: { allow_nested_queries: "true" },
6411
+ customErrorHandler: ({ status }) => {
6412
+ if (status === 401) {
6413
+ return new ZapierAuthenticationError(
6414
+ `Authentication failed. Your token may not have permission to access this table or may be expired. (HTTP ${status})`,
6415
+ { statusCode: status }
6416
+ );
6417
+ }
6418
+ if (status === 403) {
6419
+ return new ZapierAuthenticationError(
6420
+ `Access forbidden. Your token may not have the required scopes to access this table. (HTTP ${status})`,
6421
+ { statusCode: status }
6422
+ );
6423
+ }
6424
+ if (status === 404) {
6425
+ return new Error(`Table not found: ${options.tableId}`);
6426
+ }
6427
+ return void 0;
6428
+ },
6429
+ authRequired: true
6430
+ }
6431
+ );
6432
+ throwOnResponseErrors(rawResponse);
6433
+ const response = ListTableRecordsApiResponseSchema.parse(rawResponse);
6434
+ return {
6435
+ data: response.data.map((item) => ({
6436
+ ...transformRecordItem(item),
6437
+ data: translator.translateOutput(item.data)
6438
+ })),
6439
+ nextCursor: extractNextCursor2(response.meta)
6440
+ };
6441
+ }
6442
+ const methodName = stripPageSuffix(listTableRecordsPage.name);
6443
+ const listTableRecordsDefinition = createPaginatedFunction(
6444
+ listTableRecordsPage,
6445
+ ListTableRecordsOptionsSchema,
6446
+ createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
6447
+ methodName
6448
+ );
6449
+ return {
6450
+ listTableRecords: listTableRecordsDefinition,
6451
+ context: {
6452
+ meta: {
6453
+ listTableRecords: {
6454
+ categories: ["table"],
6455
+ type: "list",
6456
+ itemType: "Record",
6457
+ inputSchema: ListTableRecordsOptionsSchema,
6458
+ outputSchema: RecordItemSchema,
6459
+ resolvers: {
6460
+ tableId: tableIdResolver,
6461
+ filters: tableFiltersResolver,
6462
+ sort: tableSortResolver
6463
+ },
6464
+ formatter: tableRecordFormatter
6465
+ }
6466
+ }
6467
+ }
6468
+ };
6469
+ };
6470
+ var RecordChangesetSchema = z.object({
6471
+ change_id: z.string(),
6472
+ old: RecordApiItemSchema.nullable(),
6473
+ new: RecordApiItemSchema,
6474
+ changed_field_ids: z.array(z.number()).nullable(),
6475
+ record_id: z.string()
6476
+ });
6477
+ var CreateTableRecordsApiResponseSchema = z.object({
6478
+ data: z.array(RecordChangesetSchema)
6479
+ });
6480
+ var NewRecordSchema = z.object({
6481
+ data: z.record(z.string(), z.unknown()).describe("The field values for the record, keyed by field ID")
6482
+ });
6483
+ var CreateTableRecordsOptionsSchema = z.object({
6484
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6485
+ records: z.array(NewRecordSchema).min(1).max(100).describe("Array of records to create (max 100)"),
6486
+ keyMode: KeyModeSchema
6487
+ }).describe("Create one or more records in a table");
6488
+
6489
+ // src/plugins/tables/createTableRecords/index.ts
6490
+ var createTableRecordsPlugin = ({ context }) => {
6491
+ async function createTableRecords(options) {
6492
+ const { api } = context;
6493
+ const translator = await createFieldKeyTranslator({
6494
+ api,
6495
+ tableId: options.tableId,
6496
+ keyMode: options.keyMode
6497
+ });
6498
+ const rawResponse = await api.post(
6499
+ `/tables/api/v1/tables/${options.tableId}/records`,
6500
+ {
6501
+ new_records: options.records.map((record) => ({
6502
+ data: translator.translateInput(record.data)
6503
+ }))
6504
+ },
6505
+ {
6506
+ customErrorHandler: ({ status }) => {
6507
+ if (status === 401) {
6508
+ return new ZapierAuthenticationError(
6509
+ `Authentication failed. Your token may not have permission to create records or may be expired. (HTTP ${status})`,
6510
+ { statusCode: status }
6511
+ );
6512
+ }
6513
+ if (status === 403) {
6514
+ return new ZapierAuthenticationError(
6515
+ `Access forbidden. Your token may not have the required scopes to create records. (HTTP ${status})`,
6516
+ { statusCode: status }
6517
+ );
6518
+ }
6519
+ if (status === 404) {
6520
+ return new Error(`Table not found: ${options.tableId}`);
6521
+ }
6522
+ return void 0;
6523
+ },
6524
+ authRequired: true
6525
+ }
6526
+ );
6527
+ throwOnResponseErrors(rawResponse);
6528
+ const response = CreateTableRecordsApiResponseSchema.parse(rawResponse);
6529
+ for (const changeset of response.data) {
6530
+ throwOnRecordErrors(changeset.new);
6531
+ }
6532
+ return {
6533
+ data: response.data.map((changeset) => ({
6534
+ ...transformRecordItem(changeset.new),
6535
+ data: translator.translateOutput(changeset.new.data)
6536
+ }))
6537
+ };
6538
+ }
6539
+ const createTableRecordsDefinition = createFunction(
6540
+ createTableRecords,
6541
+ CreateTableRecordsOptionsSchema,
6542
+ createTelemetryCallback(
6543
+ context.eventEmission.emitMethodCalled,
6544
+ createTableRecords.name
6545
+ )
6546
+ );
6547
+ return {
6548
+ createTableRecords: createTableRecordsDefinition,
6549
+ context: {
6550
+ meta: {
6551
+ createTableRecords: {
6552
+ categories: ["table"],
6553
+ type: "create",
6554
+ itemType: "Record",
6555
+ inputSchema: CreateTableRecordsOptionsSchema,
6556
+ outputSchema: RecordItemSchema,
6557
+ resolvers: {
6558
+ tableId: tableIdResolver,
6559
+ records: tableRecordsResolver
6560
+ },
6561
+ formatter: tableRecordFormatter
6562
+ }
6563
+ }
6564
+ }
6565
+ };
6566
+ };
6567
+ var DeleteTableRecordsOptionsSchema = z.object({
6568
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6569
+ recordIds: z.array(
6570
+ z.string().regex(/^[A-Z0-9]{26}$/, "Record ID must be a valid ULID")
6571
+ ).min(1).max(100).describe("Array of record IDs to delete (max 100)")
6572
+ }).describe("Delete one or more records from a table");
6573
+
6574
+ // src/plugins/tables/deleteTableRecords/index.ts
6575
+ var deleteTableRecordsPlugin = ({ context }) => {
6576
+ async function deleteTableRecords(options) {
6577
+ const { api } = context;
6578
+ await api.delete(
6579
+ `/tables/api/v1/tables/${options.tableId}/records`,
6580
+ { record_ids: options.recordIds },
6581
+ {
6582
+ customErrorHandler: ({ status }) => {
6583
+ if (status === 401) {
6584
+ return new ZapierAuthenticationError(
6585
+ `Authentication failed. Your token may not have permission to delete records or may be expired. (HTTP ${status})`,
6586
+ { statusCode: status }
6587
+ );
6588
+ }
6589
+ if (status === 403) {
6590
+ return new ZapierAuthenticationError(
6591
+ `Access forbidden. Your token may not have the required scopes to delete records. (HTTP ${status})`,
6592
+ { statusCode: status }
6593
+ );
6594
+ }
6595
+ return void 0;
6596
+ },
6597
+ authRequired: true
6598
+ }
6599
+ );
6600
+ return {
6601
+ success: true
6602
+ };
6603
+ }
6604
+ const deleteTableRecordsDefinition = createFunction(
6605
+ deleteTableRecords,
6606
+ DeleteTableRecordsOptionsSchema,
6607
+ createTelemetryCallback(
6608
+ context.eventEmission.emitMethodCalled,
6609
+ deleteTableRecords.name
6610
+ )
6611
+ );
6612
+ return {
6613
+ deleteTableRecords: deleteTableRecordsDefinition,
6614
+ context: {
6615
+ meta: {
6616
+ deleteTableRecords: {
6617
+ categories: ["table"],
6618
+ type: "delete",
6619
+ itemType: "Record",
6620
+ inputSchema: DeleteTableRecordsOptionsSchema,
6621
+ resolvers: {
6622
+ tableId: tableIdResolver,
6623
+ recordIds: tableRecordIdsResolver
6624
+ },
6625
+ confirm: "delete"
6626
+ }
6627
+ }
6628
+ }
6629
+ };
6630
+ };
6631
+ var RecordChangesetSchema2 = z.object({
6632
+ change_id: z.string(),
6633
+ old: RecordApiItemSchema.nullable(),
6634
+ new: RecordApiItemSchema,
6635
+ changed_field_ids: z.array(z.number()).nullable(),
6636
+ record_id: z.string()
6637
+ });
6638
+ var UpdateTableRecordsApiResponseSchema = z.object({
6639
+ data: z.array(RecordChangesetSchema2)
6640
+ });
6641
+ var UpdateRecordSchema = z.object({
6642
+ id: z.string().describe("The record ID to update"),
6643
+ data: z.record(z.string(), z.unknown()).describe("The field values to update, keyed by field key")
6644
+ });
6645
+ var UpdateTableRecordsOptionsSchema = z.object({
6646
+ tableId: z.string().regex(/^[A-Z0-9]{26}$/, "Table ID must be a valid ULID").describe("The unique identifier of the table"),
6647
+ records: z.array(UpdateRecordSchema).min(1).max(100).describe("Array of records to update (max 100)"),
6648
+ keyMode: KeyModeSchema
6649
+ }).describe("Update one or more records in a table");
6650
+
6651
+ // src/plugins/tables/updateTableRecords/index.ts
6652
+ var updateTableRecordsPlugin = ({ context }) => {
6653
+ async function updateTableRecords(options) {
6654
+ const { api } = context;
6655
+ const translator = await createFieldKeyTranslator({
6656
+ api,
6657
+ tableId: options.tableId,
6658
+ keyMode: options.keyMode
6659
+ });
6660
+ const rawResponse = await api.patch(
6661
+ `/tables/api/v1/tables/${options.tableId}/records`,
6662
+ {
6663
+ updated_records: options.records.map((record) => ({
6664
+ id: record.id,
6665
+ data: translator.translateInput(record.data)
6666
+ }))
6667
+ },
6668
+ {
6669
+ customErrorHandler: ({ status }) => {
6670
+ if (status === 401) {
6671
+ return new ZapierAuthenticationError(
6672
+ `Authentication failed. Your token may not have permission to update records or may be expired. (HTTP ${status})`,
6673
+ { statusCode: status }
6674
+ );
6675
+ }
6676
+ if (status === 403) {
6677
+ return new ZapierAuthenticationError(
6678
+ `Access forbidden. Your token may not have the required scopes to update records. (HTTP ${status})`,
6679
+ { statusCode: status }
6680
+ );
6681
+ }
6682
+ if (status === 404) {
6683
+ return new Error(`Table not found: ${options.tableId}`);
6684
+ }
6685
+ return void 0;
6686
+ },
6687
+ authRequired: true
6688
+ }
6689
+ );
6690
+ throwOnResponseErrors(rawResponse);
6691
+ const response = UpdateTableRecordsApiResponseSchema.parse(rawResponse);
6692
+ for (const changeset of response.data) {
6693
+ throwOnRecordErrors(changeset.new);
6694
+ }
6695
+ return {
6696
+ data: response.data.map((changeset) => ({
6697
+ ...transformRecordItem(changeset.new),
6698
+ data: translator.translateOutput(changeset.new.data)
6699
+ }))
6700
+ };
6701
+ }
6702
+ const updateTableRecordsDefinition = createFunction(
6703
+ updateTableRecords,
6704
+ UpdateTableRecordsOptionsSchema,
6705
+ createTelemetryCallback(
6706
+ context.eventEmission.emitMethodCalled,
6707
+ updateTableRecords.name
6708
+ )
6709
+ );
6710
+ return {
6711
+ updateTableRecords: updateTableRecordsDefinition,
6712
+ context: {
6713
+ meta: {
6714
+ updateTableRecords: {
6715
+ categories: ["table"],
6716
+ type: "update",
6717
+ itemType: "Record",
6718
+ inputSchema: UpdateTableRecordsOptionsSchema,
6719
+ outputSchema: RecordItemSchema,
6720
+ resolvers: {
6721
+ tableId: tableIdResolver,
6722
+ records: tableUpdateRecordsResolver
6723
+ },
6724
+ formatter: tableRecordFormatter
6725
+ }
6726
+ }
6727
+ }
6728
+ };
6729
+ };
6730
+
6731
+ // src/plugins/registry/index.ts
6732
+ var registryPlugin = ({ sdk, context }) => {
6733
+ const metaKeys = Object.keys(context.meta || {});
6734
+ const categoryDefinitions = {
6735
+ account: {
6736
+ title: "Account"
6737
+ },
6738
+ app: {
6739
+ title: "App",
6740
+ titlePlural: "Apps"
6741
+ },
6742
+ connection: {
4976
6743
  title: "Connection"
4977
6744
  },
4978
6745
  action: {
@@ -4982,6 +6749,9 @@ var registryPlugin = ({ sdk, context }) => {
4982
6749
  title: "Client Credentials",
4983
6750
  titlePlural: "Client Credentials"
4984
6751
  },
6752
+ table: {
6753
+ title: "Table"
6754
+ },
4985
6755
  http: {
4986
6756
  title: "HTTP Request"
4987
6757
  },
@@ -5017,6 +6787,7 @@ var registryPlugin = ({ sdk, context }) => {
5017
6787
  outputSchema: meta.outputSchema,
5018
6788
  categories: meta.categories || [],
5019
6789
  resolvers: meta.resolvers,
6790
+ formatter: meta.formatter,
5020
6791
  packages: meta.packages,
5021
6792
  // Auto-infer confirm: "delete" from type: "delete" (all deletes should confirm)
5022
6793
  confirm: meta.confirm ?? (meta.type === "delete" ? "delete" : void 0),
@@ -5558,7 +7329,7 @@ function getCpuTime() {
5558
7329
  }
5559
7330
 
5560
7331
  // src/plugins/eventEmission/builders.ts
5561
- var SDK_VERSION = "0.34.0";
7332
+ var SDK_VERSION = "0.35.0";
5562
7333
  function createBaseEvent(context = {}) {
5563
7334
  return {
5564
7335
  event_id: generateEventId(),
@@ -6051,7 +7822,7 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
6051
7822
  };
6052
7823
  }
6053
7824
  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);
7825
+ 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
7826
  }
6056
7827
  function createZapierSdk(options = {}) {
6057
7828
  return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
@@ -6085,4 +7856,4 @@ var BaseSdkOptionsSchema = z.object({
6085
7856
  // Use credentials instead
6086
7857
  });
6087
7858
 
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 };
7859
+ 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, 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 };