@zapier/zapier-sdk 0.15.11 → 0.15.12
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 +6 -0
- package/dist/index.cjs +538 -521
- package/dist/index.mjs +538 -521
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.js +4 -3
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.js +4 -3
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +4 -3
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +4 -3
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +4 -3
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.js +4 -3
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +4 -3
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +6 -3
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +6 -3
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +6 -3
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +6 -3
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +6 -4
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +4 -3
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +6 -3
- package/dist/utils/function-utils.d.ts +1 -1
- package/dist/utils/function-utils.d.ts.map +1 -1
- package/dist/utils/function-utils.js +2 -2
- package/dist/utils/string-utils.d.ts +19 -0
- package/dist/utils/string-utils.d.ts.map +1 -1
- package/dist/utils/string-utils.js +21 -0
- package/dist/utils/string-utils.test.js +24 -1
- package/dist/utils/telemetry-utils.d.ts +25 -13
- package/dist/utils/telemetry-utils.d.ts.map +1 -1
- package/dist/utils/telemetry-utils.js +25 -13
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -710,9 +710,9 @@ function createPageFunction(coreFn) {
|
|
|
710
710
|
};
|
|
711
711
|
return namedFunctions[functionName];
|
|
712
712
|
}
|
|
713
|
-
function createPaginatedFunction(coreFn, schema, telemetry) {
|
|
713
|
+
function createPaginatedFunction(coreFn, schema, telemetry, explicitFunctionName) {
|
|
714
714
|
const pageFunction = createPageFunction(coreFn);
|
|
715
|
-
const functionName = coreFn.name;
|
|
715
|
+
const functionName = explicitFunctionName || coreFn.name;
|
|
716
716
|
const validator = schema ? createValidator(schema) : null;
|
|
717
717
|
const namedFunctions = {
|
|
718
718
|
[functionName]: function(options) {
|
|
@@ -1284,6 +1284,9 @@ function toSnakeCase(input) {
|
|
|
1284
1284
|
}
|
|
1285
1285
|
return result;
|
|
1286
1286
|
}
|
|
1287
|
+
function stripPageSuffix(functionName) {
|
|
1288
|
+
return functionName.replace(/Page$/, "");
|
|
1289
|
+
}
|
|
1287
1290
|
|
|
1288
1291
|
// src/schemas/App.ts
|
|
1289
1292
|
var AppItemSchema2 = withFormatter(
|
|
@@ -1335,50 +1338,53 @@ function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
|
1335
1338
|
|
|
1336
1339
|
// src/plugins/listApps/index.ts
|
|
1337
1340
|
var listAppsPlugin = ({ context }) => {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
implementationNameToLocator[locator.implementationName]
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1341
|
+
async function listAppsPage(options) {
|
|
1342
|
+
const { api, resolveAppKeys: resolveAppKeys2 } = context;
|
|
1343
|
+
const appKeys = options.appKeys ?? [];
|
|
1344
|
+
const appLocators = await resolveAppKeys2({
|
|
1345
|
+
appKeys: [...appKeys]
|
|
1346
|
+
});
|
|
1347
|
+
const implementationNameToLocator = {};
|
|
1348
|
+
for (const locator of appLocators) {
|
|
1349
|
+
implementationNameToLocator[locator.implementationName] = [
|
|
1350
|
+
...implementationNameToLocator[locator.implementationName] ?? [],
|
|
1351
|
+
locator
|
|
1352
|
+
];
|
|
1353
|
+
}
|
|
1354
|
+
const duplicatedLookupAppKeys = Object.keys(implementationNameToLocator).filter((key) => implementationNameToLocator[key].length > 1).map((key) => implementationNameToLocator[key]).flat().map((locator) => locator.lookupAppKey);
|
|
1355
|
+
if (duplicatedLookupAppKeys.length > 0) {
|
|
1356
|
+
throw new Error(
|
|
1357
|
+
`Duplicate lookup app keys found: ${duplicatedLookupAppKeys.join(", ")}`
|
|
1358
|
+
);
|
|
1359
|
+
}
|
|
1360
|
+
if (appKeys.length > 0 && appLocators.length === 0 && !options.search) {
|
|
1361
|
+
return {
|
|
1362
|
+
data: [],
|
|
1363
|
+
nextCursor: void 0
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
const implementationIds = appLocators.map((locator) => {
|
|
1367
|
+
const version = locator.version || "latest";
|
|
1368
|
+
return `${locator.implementationName}@${version}`;
|
|
1369
|
+
});
|
|
1370
|
+
return await api.get("/api/v0/apps", {
|
|
1371
|
+
searchParams: {
|
|
1372
|
+
implementationIds: implementationIds.join(","),
|
|
1373
|
+
...options.search && { search: options.search },
|
|
1374
|
+
pageSize: options.pageSize.toString(),
|
|
1375
|
+
...options.cursor && { cursor: options.cursor }
|
|
1363
1376
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
searchParams: {
|
|
1370
|
-
implementationIds: implementationIds.join(","),
|
|
1371
|
-
...options.search && { search: options.search },
|
|
1372
|
-
pageSize: options.pageSize.toString(),
|
|
1373
|
-
...options.cursor && { cursor: options.cursor }
|
|
1374
|
-
}
|
|
1375
|
-
});
|
|
1376
|
-
},
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
const methodName = stripPageSuffix(listAppsPage.name);
|
|
1380
|
+
const listAppsDefinition = createPaginatedFunction(
|
|
1381
|
+
listAppsPage,
|
|
1377
1382
|
ListAppsOptionsSchema,
|
|
1378
|
-
createTelemetryCallback(context.eventEmission.emitMethodCalled,
|
|
1383
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
1384
|
+
methodName
|
|
1379
1385
|
);
|
|
1380
1386
|
return {
|
|
1381
|
-
listApps,
|
|
1387
|
+
listApps: listAppsDefinition,
|
|
1382
1388
|
context: {
|
|
1383
1389
|
meta: {
|
|
1384
1390
|
listApps: {
|
|
@@ -1767,72 +1773,72 @@ var listActionsPlugin = ({ context }) => {
|
|
|
1767
1773
|
actionType: actionTypeResolver
|
|
1768
1774
|
}
|
|
1769
1775
|
};
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
{ configType: "current_implementation_id" }
|
|
1778
|
-
);
|
|
1779
|
-
}
|
|
1780
|
-
const searchParams = {
|
|
1781
|
-
global: "true",
|
|
1782
|
-
public_only: "true",
|
|
1783
|
-
selected_apis: selectedApi
|
|
1784
|
-
};
|
|
1785
|
-
const data = await api.get(
|
|
1786
|
-
"/zapier/api/v4/implementations/",
|
|
1787
|
-
{
|
|
1788
|
-
searchParams,
|
|
1789
|
-
customErrorHandler: ({ status }) => {
|
|
1790
|
-
if (status === 401) {
|
|
1791
|
-
return new ZapierAuthenticationError(
|
|
1792
|
-
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
1793
|
-
{ statusCode: status }
|
|
1794
|
-
);
|
|
1795
|
-
}
|
|
1796
|
-
if (status === 403) {
|
|
1797
|
-
return new ZapierAuthenticationError(
|
|
1798
|
-
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
1799
|
-
{ statusCode: status }
|
|
1800
|
-
);
|
|
1801
|
-
}
|
|
1802
|
-
return void 0;
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1776
|
+
async function listActionsPage(options) {
|
|
1777
|
+
const { api, getVersionedImplementationId } = context;
|
|
1778
|
+
const selectedApi = await getVersionedImplementationId(options.appKey);
|
|
1779
|
+
if (!selectedApi) {
|
|
1780
|
+
throw new ZapierConfigurationError(
|
|
1781
|
+
"No current_implementation_id found for app",
|
|
1782
|
+
{ configType: "current_implementation_id" }
|
|
1805
1783
|
);
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1784
|
+
}
|
|
1785
|
+
const searchParams = {
|
|
1786
|
+
global: "true",
|
|
1787
|
+
public_only: "true",
|
|
1788
|
+
selected_apis: selectedApi
|
|
1789
|
+
};
|
|
1790
|
+
const data = await api.get(
|
|
1791
|
+
"/zapier/api/v4/implementations/",
|
|
1792
|
+
{
|
|
1793
|
+
searchParams,
|
|
1794
|
+
customErrorHandler: ({ status }) => {
|
|
1795
|
+
if (status === 401) {
|
|
1796
|
+
return new ZapierAuthenticationError(
|
|
1797
|
+
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
1798
|
+
{ statusCode: status }
|
|
1799
|
+
);
|
|
1815
1800
|
}
|
|
1801
|
+
if (status === 403) {
|
|
1802
|
+
return new ZapierAuthenticationError(
|
|
1803
|
+
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
1804
|
+
{ statusCode: status }
|
|
1805
|
+
);
|
|
1806
|
+
}
|
|
1807
|
+
return void 0;
|
|
1816
1808
|
}
|
|
1817
1809
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1810
|
+
);
|
|
1811
|
+
let allActions = [];
|
|
1812
|
+
for (const implementation of data.results || []) {
|
|
1813
|
+
if (implementation.actions) {
|
|
1814
|
+
for (const action of implementation.actions) {
|
|
1815
|
+
const actionWithContext = {
|
|
1816
|
+
...action,
|
|
1817
|
+
selected_api: action.selected_api || implementation.selected_api
|
|
1818
|
+
};
|
|
1819
|
+
allActions.push(normalizeActionItem(actionWithContext));
|
|
1820
|
+
}
|
|
1822
1821
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1822
|
+
}
|
|
1823
|
+
if (options.actionType) {
|
|
1824
|
+
allActions = allActions.filter(
|
|
1825
|
+
(action) => action.action_type === options.actionType
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
return {
|
|
1829
|
+
data: allActions,
|
|
1830
|
+
nextCursor: void 0
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
const methodName = stripPageSuffix(listActionsPage.name);
|
|
1834
|
+
const listActionsDefinition = createPaginatedFunction(
|
|
1835
|
+
listActionsPage,
|
|
1828
1836
|
ListActionsSchema,
|
|
1829
|
-
createTelemetryCallback(
|
|
1830
|
-
|
|
1831
|
-
"listActions"
|
|
1832
|
-
)
|
|
1837
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
1838
|
+
methodName
|
|
1833
1839
|
);
|
|
1834
1840
|
return {
|
|
1835
|
-
listActions,
|
|
1841
|
+
listActions: listActionsDefinition,
|
|
1836
1842
|
context: {
|
|
1837
1843
|
meta: {
|
|
1838
1844
|
listActions: methodMeta
|
|
@@ -2128,51 +2134,51 @@ function transformNeedsToFields(needs) {
|
|
|
2128
2134
|
return rootFields;
|
|
2129
2135
|
}
|
|
2130
2136
|
var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2137
|
+
async function listInputFieldsPage(options) {
|
|
2138
|
+
const { api, getVersionedImplementationId } = context;
|
|
2139
|
+
const {
|
|
2140
|
+
appKey,
|
|
2141
|
+
actionKey,
|
|
2142
|
+
actionType,
|
|
2143
|
+
authenticationId = null,
|
|
2144
|
+
inputs
|
|
2145
|
+
} = options;
|
|
2146
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
2147
|
+
if (!selectedApi) {
|
|
2148
|
+
throw new ZapierConfigurationError(
|
|
2149
|
+
"No current_implementation_id found for app",
|
|
2150
|
+
{ configType: "current_implementation_id" }
|
|
2151
|
+
);
|
|
2152
|
+
}
|
|
2153
|
+
const { data: action } = await sdk.getAction({
|
|
2154
|
+
appKey,
|
|
2155
|
+
actionType,
|
|
2156
|
+
actionKey
|
|
2157
|
+
});
|
|
2158
|
+
const needsData = await fetchImplementationNeeds({
|
|
2159
|
+
api,
|
|
2160
|
+
selectedApi,
|
|
2161
|
+
action: action.key,
|
|
2162
|
+
actionType,
|
|
2163
|
+
authenticationId,
|
|
2164
|
+
inputs
|
|
2165
|
+
});
|
|
2166
|
+
const rootFieldset = transformNeedsToFields(needsData.needs || []);
|
|
2167
|
+
return {
|
|
2168
|
+
data: rootFieldset,
|
|
2169
|
+
nextCursor: void 0
|
|
2170
|
+
// No pagination needed since we return all input fields
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
const methodName = stripPageSuffix(listInputFieldsPage.name);
|
|
2174
|
+
const listInputFieldsDefinition = createPaginatedFunction(
|
|
2175
|
+
listInputFieldsPage,
|
|
2168
2176
|
ListInputFieldsSchema,
|
|
2169
|
-
createTelemetryCallback(
|
|
2170
|
-
|
|
2171
|
-
"listInputFields"
|
|
2172
|
-
)
|
|
2177
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
2178
|
+
methodName
|
|
2173
2179
|
);
|
|
2174
2180
|
return {
|
|
2175
|
-
listInputFields,
|
|
2181
|
+
listInputFields: listInputFieldsDefinition,
|
|
2176
2182
|
context: {
|
|
2177
2183
|
meta: {
|
|
2178
2184
|
listInputFields: {
|
|
@@ -2254,78 +2260,78 @@ var AuthenticationItemSchema = withFormatter(
|
|
|
2254
2260
|
|
|
2255
2261
|
// src/plugins/listAuthentications/index.ts
|
|
2256
2262
|
var listAuthenticationsPlugin = ({ context }) => {
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
options.appKey
|
|
2264
|
-
);
|
|
2265
|
-
if (implementationId) {
|
|
2266
|
-
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
2267
|
-
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
if (options.authenticationIds && options.authenticationIds.length > 0) {
|
|
2271
|
-
searchParams.ids = options.authenticationIds.join(",");
|
|
2272
|
-
}
|
|
2273
|
-
if (options.search) {
|
|
2274
|
-
searchParams.search = options.search;
|
|
2275
|
-
} else if (options.title) {
|
|
2276
|
-
searchParams.search = options.title;
|
|
2277
|
-
}
|
|
2278
|
-
if (options.accountId) {
|
|
2279
|
-
searchParams.account_id = options.accountId;
|
|
2280
|
-
}
|
|
2281
|
-
if (options.owner) {
|
|
2282
|
-
searchParams.owner = options.owner;
|
|
2283
|
-
}
|
|
2284
|
-
searchParams.limit = options.pageSize.toString();
|
|
2285
|
-
if (options.cursor) {
|
|
2286
|
-
searchParams.offset = options.cursor;
|
|
2287
|
-
}
|
|
2288
|
-
const data = await api.get(
|
|
2289
|
-
"/zapier/api/v4/authentications/",
|
|
2290
|
-
{
|
|
2291
|
-
searchParams,
|
|
2292
|
-
customErrorHandler: ({ status }) => {
|
|
2293
|
-
if (status === 401) {
|
|
2294
|
-
return new ZapierAuthenticationError(
|
|
2295
|
-
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
2296
|
-
{ statusCode: status }
|
|
2297
|
-
);
|
|
2298
|
-
}
|
|
2299
|
-
if (status === 403) {
|
|
2300
|
-
return new ZapierAuthenticationError(
|
|
2301
|
-
`Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${status})`,
|
|
2302
|
-
{ statusCode: status }
|
|
2303
|
-
);
|
|
2304
|
-
}
|
|
2305
|
-
return void 0;
|
|
2306
|
-
},
|
|
2307
|
-
authRequired: true
|
|
2308
|
-
}
|
|
2309
|
-
);
|
|
2310
|
-
let auths = (data.results || []).map(
|
|
2311
|
-
(auth) => normalizeAuthenticationItem(auth)
|
|
2263
|
+
async function listAuthenticationsPage(options) {
|
|
2264
|
+
const { api, getVersionedImplementationId } = context;
|
|
2265
|
+
const searchParams = {};
|
|
2266
|
+
if (options.appKey) {
|
|
2267
|
+
const implementationId = await getVersionedImplementationId(
|
|
2268
|
+
options.appKey
|
|
2312
2269
|
);
|
|
2313
|
-
if (
|
|
2314
|
-
|
|
2270
|
+
if (implementationId) {
|
|
2271
|
+
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
2272
|
+
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
2315
2273
|
}
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2274
|
+
}
|
|
2275
|
+
if (options.authenticationIds && options.authenticationIds.length > 0) {
|
|
2276
|
+
searchParams.ids = options.authenticationIds.join(",");
|
|
2277
|
+
}
|
|
2278
|
+
if (options.search) {
|
|
2279
|
+
searchParams.search = options.search;
|
|
2280
|
+
} else if (options.title) {
|
|
2281
|
+
searchParams.search = options.title;
|
|
2282
|
+
}
|
|
2283
|
+
if (options.accountId) {
|
|
2284
|
+
searchParams.account_id = options.accountId;
|
|
2285
|
+
}
|
|
2286
|
+
if (options.owner) {
|
|
2287
|
+
searchParams.owner = options.owner;
|
|
2288
|
+
}
|
|
2289
|
+
searchParams.limit = options.pageSize.toString();
|
|
2290
|
+
if (options.cursor) {
|
|
2291
|
+
searchParams.offset = options.cursor;
|
|
2292
|
+
}
|
|
2293
|
+
const data = await api.get(
|
|
2294
|
+
"/zapier/api/v4/authentications/",
|
|
2295
|
+
{
|
|
2296
|
+
searchParams,
|
|
2297
|
+
customErrorHandler: ({ status }) => {
|
|
2298
|
+
if (status === 401) {
|
|
2299
|
+
return new ZapierAuthenticationError(
|
|
2300
|
+
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
2301
|
+
{ statusCode: status }
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2304
|
+
if (status === 403) {
|
|
2305
|
+
return new ZapierAuthenticationError(
|
|
2306
|
+
`Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${status})`,
|
|
2307
|
+
{ statusCode: status }
|
|
2308
|
+
);
|
|
2309
|
+
}
|
|
2310
|
+
return void 0;
|
|
2311
|
+
},
|
|
2312
|
+
authRequired: true
|
|
2313
|
+
}
|
|
2314
|
+
);
|
|
2315
|
+
let auths = (data.results || []).map(
|
|
2316
|
+
(auth) => normalizeAuthenticationItem(auth)
|
|
2317
|
+
);
|
|
2318
|
+
if (options.title) {
|
|
2319
|
+
auths = auths.filter((auth) => auth.title === options.title);
|
|
2320
|
+
}
|
|
2321
|
+
return {
|
|
2322
|
+
data: auths,
|
|
2323
|
+
nextCursor: extractCursor(data)
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
const methodName = stripPageSuffix(listAuthenticationsPage.name);
|
|
2327
|
+
const listAuthenticationsDefinition = createPaginatedFunction(
|
|
2328
|
+
listAuthenticationsPage,
|
|
2321
2329
|
ListAuthenticationsSchema,
|
|
2322
|
-
createTelemetryCallback(
|
|
2323
|
-
|
|
2324
|
-
"listAuthentications"
|
|
2325
|
-
)
|
|
2330
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
2331
|
+
methodName
|
|
2326
2332
|
);
|
|
2327
2333
|
return {
|
|
2328
|
-
listAuthentications,
|
|
2334
|
+
listAuthentications: listAuthenticationsDefinition,
|
|
2329
2335
|
context: {
|
|
2330
2336
|
meta: {
|
|
2331
2337
|
listAuthentications: {
|
|
@@ -2350,26 +2356,30 @@ var GetAppSchema = z.object({
|
|
|
2350
2356
|
|
|
2351
2357
|
// src/plugins/getApp/index.ts
|
|
2352
2358
|
var getAppPlugin = ({ sdk, context }) => {
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2359
|
+
async function getApp(options) {
|
|
2360
|
+
const appsIterator = sdk.listApps({
|
|
2361
|
+
appKeys: [options.appKey],
|
|
2362
|
+
_telemetry: { isNested: true }
|
|
2363
|
+
}).items();
|
|
2364
|
+
for await (const app of appsIterator) {
|
|
2365
|
+
return {
|
|
2366
|
+
data: app
|
|
2367
|
+
};
|
|
2368
|
+
}
|
|
2369
|
+
throw new ZapierAppNotFoundError("App not found", {
|
|
2370
|
+
appKey: options.appKey
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
const getAppDefinition = createFunction(
|
|
2374
|
+
getApp,
|
|
2368
2375
|
GetAppSchema,
|
|
2369
|
-
createTelemetryCallback(
|
|
2376
|
+
createTelemetryCallback(
|
|
2377
|
+
context.eventEmission.emitMethodCalled,
|
|
2378
|
+
getApp.name
|
|
2379
|
+
)
|
|
2370
2380
|
);
|
|
2371
2381
|
return {
|
|
2372
|
-
getApp,
|
|
2382
|
+
getApp: getAppDefinition,
|
|
2373
2383
|
context: {
|
|
2374
2384
|
meta: {
|
|
2375
2385
|
getApp: {
|
|
@@ -2394,27 +2404,28 @@ var GetActionSchema = z.object({
|
|
|
2394
2404
|
|
|
2395
2405
|
// src/plugins/getAction/index.ts
|
|
2396
2406
|
var getActionPlugin = ({ sdk, context }) => {
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
return { data: action };
|
|
2403
|
-
}
|
|
2407
|
+
async function getAction(options) {
|
|
2408
|
+
const { actionKey, actionType, appKey } = options;
|
|
2409
|
+
for await (const action of sdk.listActions({ appKey, _telemetry: { isNested: true } }).items()) {
|
|
2410
|
+
if ((action.key === actionKey || action.id === actionKey) && action.action_type === actionType) {
|
|
2411
|
+
return { data: action };
|
|
2404
2412
|
}
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
)
|
|
2409
|
-
|
|
2413
|
+
}
|
|
2414
|
+
throw new ZapierResourceNotFoundError(
|
|
2415
|
+
`Action not found: ${actionKey} with type ${actionType}`,
|
|
2416
|
+
{ resourceType: "Action", resourceId: `${actionKey} (${actionType})` }
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
const getActionDefinition = createFunction(
|
|
2420
|
+
getAction,
|
|
2410
2421
|
GetActionSchema,
|
|
2411
2422
|
createTelemetryCallback(
|
|
2412
2423
|
context.eventEmission.emitMethodCalled,
|
|
2413
|
-
|
|
2424
|
+
getAction.name
|
|
2414
2425
|
)
|
|
2415
2426
|
);
|
|
2416
2427
|
return {
|
|
2417
|
-
getAction,
|
|
2428
|
+
getAction: getActionDefinition,
|
|
2418
2429
|
context: {
|
|
2419
2430
|
meta: {
|
|
2420
2431
|
getAction: {
|
|
@@ -2489,21 +2500,22 @@ z.object({
|
|
|
2489
2500
|
|
|
2490
2501
|
// src/plugins/getAuthentication/index.ts
|
|
2491
2502
|
var getAuthenticationPlugin = ({ context }) => {
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2503
|
+
async function getAuthentication(options) {
|
|
2504
|
+
const { api } = context;
|
|
2505
|
+
return await api.get(
|
|
2506
|
+
`/api/v0/authentications/${options.authenticationId}`
|
|
2507
|
+
);
|
|
2508
|
+
}
|
|
2509
|
+
const getAuthenticationDefinition = createFunction(
|
|
2510
|
+
getAuthentication,
|
|
2499
2511
|
GetAuthenticationOptionsSchema,
|
|
2500
2512
|
createTelemetryCallback(
|
|
2501
2513
|
context.eventEmission.emitMethodCalled,
|
|
2502
|
-
|
|
2514
|
+
getAuthentication.name
|
|
2503
2515
|
)
|
|
2504
2516
|
);
|
|
2505
2517
|
return {
|
|
2506
|
-
getAuthentication,
|
|
2518
|
+
getAuthentication: getAuthenticationDefinition,
|
|
2507
2519
|
context: {
|
|
2508
2520
|
meta: {
|
|
2509
2521
|
getAuthentication: {
|
|
@@ -2532,31 +2544,32 @@ var FindFirstAuthenticationSchema = z.object({
|
|
|
2532
2544
|
|
|
2533
2545
|
// src/plugins/findFirstAuthentication/index.ts
|
|
2534
2546
|
var findFirstAuthenticationPlugin = ({ sdk, context }) => {
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2547
|
+
async function findFirstAuthentication(options = {}) {
|
|
2548
|
+
const authsResponse = await sdk.listAuthentications({
|
|
2549
|
+
...options,
|
|
2550
|
+
maxItems: 1,
|
|
2551
|
+
_telemetry: { isNested: true }
|
|
2552
|
+
});
|
|
2553
|
+
if (authsResponse.data.length === 0) {
|
|
2554
|
+
throw new ZapierResourceNotFoundError(
|
|
2555
|
+
"No authentication found matching the specified criteria",
|
|
2556
|
+
{ resourceType: "Authentication" }
|
|
2557
|
+
);
|
|
2558
|
+
}
|
|
2559
|
+
return {
|
|
2560
|
+
data: authsResponse.data[0]
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
const findFirstAuthenticationDefinition = createFunction(
|
|
2564
|
+
findFirstAuthentication,
|
|
2552
2565
|
FindFirstAuthenticationSchema,
|
|
2553
2566
|
createTelemetryCallback(
|
|
2554
2567
|
context.eventEmission.emitMethodCalled,
|
|
2555
|
-
|
|
2568
|
+
findFirstAuthentication.name
|
|
2556
2569
|
)
|
|
2557
2570
|
);
|
|
2558
2571
|
return {
|
|
2559
|
-
findFirstAuthentication,
|
|
2572
|
+
findFirstAuthentication: findFirstAuthenticationDefinition,
|
|
2560
2573
|
context: {
|
|
2561
2574
|
meta: {
|
|
2562
2575
|
findFirstAuthentication: {
|
|
@@ -2582,37 +2595,38 @@ var FindUniqueAuthenticationSchema = z.object({
|
|
|
2582
2595
|
|
|
2583
2596
|
// src/plugins/findUniqueAuthentication/index.ts
|
|
2584
2597
|
var findUniqueAuthenticationPlugin = ({ sdk, context }) => {
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2598
|
+
async function findUniqueAuthentication(options = {}) {
|
|
2599
|
+
const authsResponse = await sdk.listAuthentications({
|
|
2600
|
+
...options,
|
|
2601
|
+
maxItems: 2,
|
|
2602
|
+
// Get up to 2 to check for uniqueness
|
|
2603
|
+
_telemetry: { isNested: true }
|
|
2604
|
+
});
|
|
2605
|
+
if (authsResponse.data.length === 0) {
|
|
2606
|
+
throw new ZapierResourceNotFoundError(
|
|
2607
|
+
"No authentication found matching the specified criteria",
|
|
2608
|
+
{ resourceType: "Authentication" }
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
if (authsResponse.data.length > 1) {
|
|
2612
|
+
throw new ZapierValidationError(
|
|
2613
|
+
"Multiple authentications found matching the specified criteria. Expected exactly one."
|
|
2614
|
+
);
|
|
2615
|
+
}
|
|
2616
|
+
return {
|
|
2617
|
+
data: authsResponse.data[0]
|
|
2618
|
+
};
|
|
2619
|
+
}
|
|
2620
|
+
const findUniqueAuthenticationDefinition = createFunction(
|
|
2621
|
+
findUniqueAuthentication,
|
|
2608
2622
|
FindUniqueAuthenticationSchema,
|
|
2609
2623
|
createTelemetryCallback(
|
|
2610
2624
|
context.eventEmission.emitMethodCalled,
|
|
2611
|
-
|
|
2625
|
+
findUniqueAuthentication.name
|
|
2612
2626
|
)
|
|
2613
2627
|
);
|
|
2614
2628
|
return {
|
|
2615
|
-
findUniqueAuthentication,
|
|
2629
|
+
findUniqueAuthentication: findUniqueAuthenticationDefinition,
|
|
2616
2630
|
context: {
|
|
2617
2631
|
meta: {
|
|
2618
2632
|
findUniqueAuthentication: {
|
|
@@ -2683,65 +2697,62 @@ async function executeAction(actionOptions) {
|
|
|
2683
2697
|
});
|
|
2684
2698
|
}
|
|
2685
2699
|
var runActionPlugin = ({ sdk, context }) => {
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2700
|
+
async function runActionPage(options) {
|
|
2701
|
+
const { api } = context;
|
|
2702
|
+
const {
|
|
2703
|
+
appKey,
|
|
2704
|
+
actionKey,
|
|
2705
|
+
actionType,
|
|
2706
|
+
authenticationId,
|
|
2707
|
+
inputs = {}
|
|
2708
|
+
} = options;
|
|
2709
|
+
const actionData = await sdk.getAction({
|
|
2710
|
+
appKey,
|
|
2711
|
+
actionKey,
|
|
2712
|
+
actionType,
|
|
2713
|
+
_telemetry: { isNested: true }
|
|
2714
|
+
});
|
|
2715
|
+
if (actionData.data.action_type !== actionType) {
|
|
2716
|
+
throw new ZapierValidationError(
|
|
2717
|
+
`Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`
|
|
2718
|
+
);
|
|
2719
|
+
}
|
|
2720
|
+
const actionId = actionData.data.id;
|
|
2721
|
+
const result = await executeAction({
|
|
2722
|
+
api,
|
|
2723
|
+
context,
|
|
2724
|
+
appKey,
|
|
2725
|
+
// Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
|
|
2726
|
+
// we retrieve actions (probably legacy reasons), so we just pass along all the things!
|
|
2727
|
+
actionId,
|
|
2728
|
+
actionKey,
|
|
2729
|
+
actionType,
|
|
2730
|
+
executionOptions: { inputs },
|
|
2731
|
+
authenticationId});
|
|
2732
|
+
if (result.errors && result.errors.length > 0) {
|
|
2733
|
+
const errorMessage = result.errors.map(
|
|
2734
|
+
(error) => error.detail || error.title || "Unknown error"
|
|
2735
|
+
).join("; ");
|
|
2736
|
+
throw new ZapierActionError(`Action execution failed: ${errorMessage}`, {
|
|
2697
2737
|
appKey,
|
|
2698
|
-
actionKey
|
|
2699
|
-
actionType,
|
|
2700
|
-
_telemetry: { isNested: true }
|
|
2738
|
+
actionKey
|
|
2701
2739
|
});
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
// Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
|
|
2713
|
-
// we retrieve actions (probably legacy reasons), so we just pass along all the things!
|
|
2714
|
-
actionId,
|
|
2715
|
-
actionKey,
|
|
2716
|
-
actionType,
|
|
2717
|
-
executionOptions: { inputs },
|
|
2718
|
-
authenticationId});
|
|
2719
|
-
if (result.errors && result.errors.length > 0) {
|
|
2720
|
-
const errorMessage = result.errors.map(
|
|
2721
|
-
(error) => error.detail || error.title || "Unknown error"
|
|
2722
|
-
).join("; ");
|
|
2723
|
-
throw new ZapierActionError(
|
|
2724
|
-
`Action execution failed: ${errorMessage}`,
|
|
2725
|
-
{
|
|
2726
|
-
appKey,
|
|
2727
|
-
actionKey
|
|
2728
|
-
}
|
|
2729
|
-
);
|
|
2730
|
-
}
|
|
2731
|
-
return {
|
|
2732
|
-
data: result.results || [],
|
|
2733
|
-
nextCursor: void 0
|
|
2734
|
-
// No pagination implemented yet
|
|
2735
|
-
};
|
|
2736
|
-
},
|
|
2740
|
+
}
|
|
2741
|
+
return {
|
|
2742
|
+
data: result.results || [],
|
|
2743
|
+
nextCursor: void 0
|
|
2744
|
+
// No pagination implemented yet
|
|
2745
|
+
};
|
|
2746
|
+
}
|
|
2747
|
+
const methodName = stripPageSuffix(runActionPage.name);
|
|
2748
|
+
const runActionDefinition = createPaginatedFunction(
|
|
2749
|
+
runActionPage,
|
|
2737
2750
|
RunActionSchema,
|
|
2738
|
-
createTelemetryCallback(
|
|
2739
|
-
|
|
2740
|
-
"runAction"
|
|
2741
|
-
)
|
|
2751
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
2752
|
+
methodName
|
|
2742
2753
|
);
|
|
2743
2754
|
return {
|
|
2744
|
-
runAction,
|
|
2755
|
+
runAction: runActionDefinition,
|
|
2745
2756
|
context: {
|
|
2746
2757
|
meta: {
|
|
2747
2758
|
runAction: {
|
|
@@ -2788,46 +2799,50 @@ function transformUrlToRelayPath(url) {
|
|
|
2788
2799
|
return relayPath;
|
|
2789
2800
|
}
|
|
2790
2801
|
var requestPlugin = ({ context }) => {
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
headers[key] = value;
|
|
2809
|
-
}
|
|
2810
|
-
}
|
|
2811
|
-
if (authenticationId) {
|
|
2812
|
-
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
2813
|
-
}
|
|
2814
|
-
if (callbackUrl) {
|
|
2815
|
-
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
2816
|
-
}
|
|
2817
|
-
if (authenticationTemplate) {
|
|
2818
|
-
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
2802
|
+
async function request(options) {
|
|
2803
|
+
const { api } = context;
|
|
2804
|
+
const {
|
|
2805
|
+
url,
|
|
2806
|
+
method = "GET",
|
|
2807
|
+
body,
|
|
2808
|
+
headers: optionsHeaders,
|
|
2809
|
+
authenticationId,
|
|
2810
|
+
callbackUrl,
|
|
2811
|
+
authenticationTemplate
|
|
2812
|
+
} = options;
|
|
2813
|
+
const relayPath = transformUrlToRelayPath(url);
|
|
2814
|
+
const headers = {};
|
|
2815
|
+
if (optionsHeaders) {
|
|
2816
|
+
const headerEntries = optionsHeaders instanceof Headers ? Array.from(optionsHeaders.entries()) : Array.isArray(optionsHeaders) ? optionsHeaders : Object.entries(optionsHeaders);
|
|
2817
|
+
for (const [key, value] of headerEntries) {
|
|
2818
|
+
headers[key] = value;
|
|
2819
2819
|
}
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2820
|
+
}
|
|
2821
|
+
if (authenticationId) {
|
|
2822
|
+
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
2823
|
+
}
|
|
2824
|
+
if (callbackUrl) {
|
|
2825
|
+
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
2826
|
+
}
|
|
2827
|
+
if (authenticationTemplate) {
|
|
2828
|
+
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
2829
|
+
}
|
|
2830
|
+
return await api.fetch(relayPath, {
|
|
2831
|
+
method,
|
|
2832
|
+
body,
|
|
2833
|
+
headers
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
const requestDefinition = createFunction(
|
|
2837
|
+
request,
|
|
2826
2838
|
RelayRequestSchema,
|
|
2827
|
-
createTelemetryCallback(
|
|
2839
|
+
createTelemetryCallback(
|
|
2840
|
+
context.eventEmission.emitMethodCalled,
|
|
2841
|
+
request.name
|
|
2842
|
+
)
|
|
2828
2843
|
);
|
|
2829
2844
|
return {
|
|
2830
|
-
request,
|
|
2845
|
+
request: requestDefinition,
|
|
2831
2846
|
context: {
|
|
2832
2847
|
meta: {
|
|
2833
2848
|
request: {
|
|
@@ -3330,32 +3345,33 @@ var UserProfileItemSchema = withFormatter(
|
|
|
3330
3345
|
|
|
3331
3346
|
// src/plugins/getProfile/index.ts
|
|
3332
3347
|
var getProfilePlugin = ({ context }) => {
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
data
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3348
|
+
async function getProfile() {
|
|
3349
|
+
const profile = await context.api.get(
|
|
3350
|
+
"/zapier/api/v4/profile/",
|
|
3351
|
+
{
|
|
3352
|
+
authRequired: true
|
|
3353
|
+
}
|
|
3354
|
+
);
|
|
3355
|
+
const { user_id: _unusedUserId, ...data } = profile;
|
|
3356
|
+
return {
|
|
3357
|
+
data: {
|
|
3358
|
+
...data,
|
|
3359
|
+
// Pass through all API response fields
|
|
3360
|
+
full_name: `${profile.first_name} ${profile.last_name}`
|
|
3361
|
+
// Computed field
|
|
3362
|
+
}
|
|
3363
|
+
};
|
|
3364
|
+
}
|
|
3365
|
+
const getProfileDefinition = createFunction(
|
|
3366
|
+
getProfile,
|
|
3351
3367
|
GetProfileSchema,
|
|
3352
3368
|
createTelemetryCallback(
|
|
3353
3369
|
context.eventEmission.emitMethodCalled,
|
|
3354
|
-
|
|
3370
|
+
getProfile.name
|
|
3355
3371
|
)
|
|
3356
3372
|
);
|
|
3357
3373
|
return {
|
|
3358
|
-
getProfile,
|
|
3374
|
+
getProfile: getProfileDefinition,
|
|
3359
3375
|
context: {
|
|
3360
3376
|
meta: {
|
|
3361
3377
|
getProfile: {
|
|
@@ -4598,48 +4614,49 @@ var GetInputFieldsSchemaSchema = z.object({
|
|
|
4598
4614
|
|
|
4599
4615
|
// src/plugins/getInputFieldsSchema/index.ts
|
|
4600
4616
|
var getInputFieldsSchemaPlugin = ({ sdk, context }) => {
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4617
|
+
async function getInputFieldsSchema(options) {
|
|
4618
|
+
const { api, getVersionedImplementationId } = context;
|
|
4619
|
+
const {
|
|
4620
|
+
appKey,
|
|
4621
|
+
actionKey,
|
|
4622
|
+
actionType,
|
|
4623
|
+
authenticationId = null,
|
|
4624
|
+
inputs
|
|
4625
|
+
} = options;
|
|
4626
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
4627
|
+
if (!selectedApi) {
|
|
4628
|
+
throw new ZapierConfigurationError(
|
|
4629
|
+
"No current_implementation_id found for app",
|
|
4630
|
+
{ configType: "current_implementation_id" }
|
|
4631
|
+
);
|
|
4632
|
+
}
|
|
4633
|
+
const { data: action } = await sdk.getAction({
|
|
4634
|
+
appKey,
|
|
4635
|
+
actionType,
|
|
4636
|
+
actionKey
|
|
4637
|
+
});
|
|
4638
|
+
const needsData = await fetchImplementationNeeds({
|
|
4639
|
+
api,
|
|
4640
|
+
selectedApi,
|
|
4641
|
+
action: action.key,
|
|
4642
|
+
actionType,
|
|
4643
|
+
authenticationId,
|
|
4644
|
+
inputs
|
|
4645
|
+
});
|
|
4646
|
+
return {
|
|
4647
|
+
data: needsData.schema || {}
|
|
4648
|
+
};
|
|
4649
|
+
}
|
|
4650
|
+
const getInputFieldsSchemaDefinition = createFunction(
|
|
4651
|
+
getInputFieldsSchema,
|
|
4635
4652
|
GetInputFieldsSchemaSchema,
|
|
4636
4653
|
createTelemetryCallback(
|
|
4637
4654
|
context.eventEmission.emitMethodCalled,
|
|
4638
|
-
|
|
4655
|
+
getInputFieldsSchema.name
|
|
4639
4656
|
)
|
|
4640
4657
|
);
|
|
4641
4658
|
return {
|
|
4642
|
-
getInputFieldsSchema,
|
|
4659
|
+
getInputFieldsSchema: getInputFieldsSchemaDefinition,
|
|
4643
4660
|
context: {
|
|
4644
4661
|
meta: {
|
|
4645
4662
|
getInputFieldsSchema: {
|
|
@@ -4708,94 +4725,94 @@ function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
|
4708
4725
|
};
|
|
4709
4726
|
}
|
|
4710
4727
|
var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
{ configType: "current_implementation_id" }
|
|
4729
|
-
);
|
|
4730
|
-
}
|
|
4731
|
-
const { data: action } = await sdk.getAction({
|
|
4732
|
-
appKey,
|
|
4733
|
-
actionType,
|
|
4734
|
-
actionKey
|
|
4735
|
-
});
|
|
4736
|
-
const needsData = await fetchImplementationNeeds({
|
|
4737
|
-
api,
|
|
4738
|
-
selectedApi,
|
|
4739
|
-
action: action.key,
|
|
4740
|
-
actionType,
|
|
4741
|
-
authenticationId,
|
|
4742
|
-
inputs
|
|
4743
|
-
});
|
|
4744
|
-
const targetNeed = needsData.needs?.find(
|
|
4745
|
-
(need) => need.key === inputFieldKey
|
|
4728
|
+
async function listInputFieldChoicesPage(options) {
|
|
4729
|
+
const { api, getVersionedImplementationId } = context;
|
|
4730
|
+
const {
|
|
4731
|
+
appKey,
|
|
4732
|
+
actionType,
|
|
4733
|
+
actionKey,
|
|
4734
|
+
inputFieldKey,
|
|
4735
|
+
authenticationId = null,
|
|
4736
|
+
inputs,
|
|
4737
|
+
page,
|
|
4738
|
+
cursor
|
|
4739
|
+
} = options;
|
|
4740
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
4741
|
+
if (!selectedApi) {
|
|
4742
|
+
throw new ZapierConfigurationError(
|
|
4743
|
+
"No current_implementation_id found for app",
|
|
4744
|
+
{ configType: "current_implementation_id" }
|
|
4746
4745
|
);
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4746
|
+
}
|
|
4747
|
+
const { data: action } = await sdk.getAction({
|
|
4748
|
+
appKey,
|
|
4749
|
+
actionType,
|
|
4750
|
+
actionKey
|
|
4751
|
+
});
|
|
4752
|
+
const needsData = await fetchImplementationNeeds({
|
|
4753
|
+
api,
|
|
4754
|
+
selectedApi,
|
|
4755
|
+
action: action.key,
|
|
4756
|
+
actionType,
|
|
4757
|
+
authenticationId,
|
|
4758
|
+
inputs
|
|
4759
|
+
});
|
|
4760
|
+
const targetNeed = needsData.needs?.find(
|
|
4761
|
+
(need) => need.key === inputFieldKey
|
|
4762
|
+
);
|
|
4763
|
+
if (targetNeed?.choices && targetNeed.choices.length > 0) {
|
|
4764
|
+
return {
|
|
4765
|
+
data: targetNeed.choices.map(
|
|
4766
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
4767
|
+
),
|
|
4768
|
+
nextCursor: void 0
|
|
4769
|
+
};
|
|
4770
|
+
}
|
|
4771
|
+
if (!action.id) {
|
|
4772
|
+
throw new ZapierApiError(
|
|
4773
|
+
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`
|
|
4771
4774
|
);
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4775
|
+
}
|
|
4776
|
+
const requestPage = cursor ? parseInt(cursor, 10) : page ?? 0;
|
|
4777
|
+
const choicesData = await fetchImplementationChoices({
|
|
4778
|
+
api,
|
|
4779
|
+
actionId: action.id,
|
|
4780
|
+
inputFieldId: inputFieldKey,
|
|
4781
|
+
authenticationId,
|
|
4782
|
+
inputs,
|
|
4783
|
+
page: requestPage
|
|
4784
|
+
});
|
|
4785
|
+
const choices = (choicesData.choices || []).map(
|
|
4786
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
4787
|
+
);
|
|
4788
|
+
let nextCursor;
|
|
4789
|
+
if (choicesData.next_page != null) {
|
|
4790
|
+
nextCursor = choicesData.next_page.toString();
|
|
4791
|
+
} else if (choicesData.links?.next) {
|
|
4792
|
+
try {
|
|
4793
|
+
const nextUrl = new URL(choicesData.links.next);
|
|
4794
|
+
const nextPage = nextUrl.searchParams.get("page");
|
|
4795
|
+
if (nextPage) {
|
|
4796
|
+
nextCursor = nextPage;
|
|
4784
4797
|
}
|
|
4798
|
+
} catch {
|
|
4799
|
+
nextCursor = void 0;
|
|
4785
4800
|
}
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
}
|
|
4801
|
+
}
|
|
4802
|
+
return {
|
|
4803
|
+
data: choices,
|
|
4804
|
+
nextCursor
|
|
4805
|
+
};
|
|
4806
|
+
}
|
|
4807
|
+
const methodName = stripPageSuffix(listInputFieldChoicesPage.name);
|
|
4808
|
+
const listInputFieldChoicesDefinition = createPaginatedFunction(
|
|
4809
|
+
listInputFieldChoicesPage,
|
|
4791
4810
|
ListInputFieldChoicesSchema,
|
|
4792
|
-
createTelemetryCallback(
|
|
4793
|
-
|
|
4794
|
-
"listInputFieldChoices"
|
|
4795
|
-
)
|
|
4811
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
4812
|
+
methodName
|
|
4796
4813
|
);
|
|
4797
4814
|
return {
|
|
4798
|
-
listInputFieldChoices,
|
|
4815
|
+
listInputFieldChoices: listInputFieldChoicesDefinition,
|
|
4799
4816
|
context: {
|
|
4800
4817
|
meta: {
|
|
4801
4818
|
listInputFieldChoices: {
|
|
@@ -4969,7 +4986,7 @@ function getCpuTime() {
|
|
|
4969
4986
|
|
|
4970
4987
|
// package.json
|
|
4971
4988
|
var package_default = {
|
|
4972
|
-
version: "0.15.
|
|
4989
|
+
version: "0.15.12"};
|
|
4973
4990
|
|
|
4974
4991
|
// src/plugins/eventEmission/builders.ts
|
|
4975
4992
|
function createBaseEvent(context = {}) {
|