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