@zapier/zapier-sdk 0.15.11 → 0.15.13
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 +14 -0
- package/LICENSE +2 -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 +3 -3
package/dist/index.cjs
CHANGED
|
@@ -732,9 +732,9 @@ function createPageFunction(coreFn) {
|
|
|
732
732
|
};
|
|
733
733
|
return namedFunctions[functionName];
|
|
734
734
|
}
|
|
735
|
-
function createPaginatedFunction(coreFn, schema, telemetry) {
|
|
735
|
+
function createPaginatedFunction(coreFn, schema, telemetry, explicitFunctionName) {
|
|
736
736
|
const pageFunction = createPageFunction(coreFn);
|
|
737
|
-
const functionName = coreFn.name;
|
|
737
|
+
const functionName = explicitFunctionName || coreFn.name;
|
|
738
738
|
const validator = schema ? createValidator(schema) : null;
|
|
739
739
|
const namedFunctions = {
|
|
740
740
|
[functionName]: function(options) {
|
|
@@ -1306,6 +1306,9 @@ function toSnakeCase(input) {
|
|
|
1306
1306
|
}
|
|
1307
1307
|
return result;
|
|
1308
1308
|
}
|
|
1309
|
+
function stripPageSuffix(functionName) {
|
|
1310
|
+
return functionName.replace(/Page$/, "");
|
|
1311
|
+
}
|
|
1309
1312
|
|
|
1310
1313
|
// src/schemas/App.ts
|
|
1311
1314
|
var AppItemSchema2 = withFormatter(
|
|
@@ -1357,50 +1360,53 @@ function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
|
1357
1360
|
|
|
1358
1361
|
// src/plugins/listApps/index.ts
|
|
1359
1362
|
var listAppsPlugin = ({ context }) => {
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
implementationNameToLocator[locator.implementationName]
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1363
|
+
async function listAppsPage(options) {
|
|
1364
|
+
const { api, resolveAppKeys: resolveAppKeys2 } = context;
|
|
1365
|
+
const appKeys = options.appKeys ?? [];
|
|
1366
|
+
const appLocators = await resolveAppKeys2({
|
|
1367
|
+
appKeys: [...appKeys]
|
|
1368
|
+
});
|
|
1369
|
+
const implementationNameToLocator = {};
|
|
1370
|
+
for (const locator of appLocators) {
|
|
1371
|
+
implementationNameToLocator[locator.implementationName] = [
|
|
1372
|
+
...implementationNameToLocator[locator.implementationName] ?? [],
|
|
1373
|
+
locator
|
|
1374
|
+
];
|
|
1375
|
+
}
|
|
1376
|
+
const duplicatedLookupAppKeys = Object.keys(implementationNameToLocator).filter((key) => implementationNameToLocator[key].length > 1).map((key) => implementationNameToLocator[key]).flat().map((locator) => locator.lookupAppKey);
|
|
1377
|
+
if (duplicatedLookupAppKeys.length > 0) {
|
|
1378
|
+
throw new Error(
|
|
1379
|
+
`Duplicate lookup app keys found: ${duplicatedLookupAppKeys.join(", ")}`
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1382
|
+
if (appKeys.length > 0 && appLocators.length === 0 && !options.search) {
|
|
1383
|
+
return {
|
|
1384
|
+
data: [],
|
|
1385
|
+
nextCursor: void 0
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
const implementationIds = appLocators.map((locator) => {
|
|
1389
|
+
const version = locator.version || "latest";
|
|
1390
|
+
return `${locator.implementationName}@${version}`;
|
|
1391
|
+
});
|
|
1392
|
+
return await api.get("/api/v0/apps", {
|
|
1393
|
+
searchParams: {
|
|
1394
|
+
implementationIds: implementationIds.join(","),
|
|
1395
|
+
...options.search && { search: options.search },
|
|
1396
|
+
pageSize: options.pageSize.toString(),
|
|
1397
|
+
...options.cursor && { cursor: options.cursor }
|
|
1385
1398
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
searchParams: {
|
|
1392
|
-
implementationIds: implementationIds.join(","),
|
|
1393
|
-
...options.search && { search: options.search },
|
|
1394
|
-
pageSize: options.pageSize.toString(),
|
|
1395
|
-
...options.cursor && { cursor: options.cursor }
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
},
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
const methodName = stripPageSuffix(listAppsPage.name);
|
|
1402
|
+
const listAppsDefinition = createPaginatedFunction(
|
|
1403
|
+
listAppsPage,
|
|
1399
1404
|
ListAppsOptionsSchema,
|
|
1400
|
-
createTelemetryCallback(context.eventEmission.emitMethodCalled,
|
|
1405
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
1406
|
+
methodName
|
|
1401
1407
|
);
|
|
1402
1408
|
return {
|
|
1403
|
-
listApps,
|
|
1409
|
+
listApps: listAppsDefinition,
|
|
1404
1410
|
context: {
|
|
1405
1411
|
meta: {
|
|
1406
1412
|
listApps: {
|
|
@@ -1789,72 +1795,72 @@ var listActionsPlugin = ({ context }) => {
|
|
|
1789
1795
|
actionType: actionTypeResolver
|
|
1790
1796
|
}
|
|
1791
1797
|
};
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
{ configType: "current_implementation_id" }
|
|
1800
|
-
);
|
|
1801
|
-
}
|
|
1802
|
-
const searchParams = {
|
|
1803
|
-
global: "true",
|
|
1804
|
-
public_only: "true",
|
|
1805
|
-
selected_apis: selectedApi
|
|
1806
|
-
};
|
|
1807
|
-
const data = await api.get(
|
|
1808
|
-
"/zapier/api/v4/implementations/",
|
|
1809
|
-
{
|
|
1810
|
-
searchParams,
|
|
1811
|
-
customErrorHandler: ({ status }) => {
|
|
1812
|
-
if (status === 401) {
|
|
1813
|
-
return new ZapierAuthenticationError(
|
|
1814
|
-
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
1815
|
-
{ statusCode: status }
|
|
1816
|
-
);
|
|
1817
|
-
}
|
|
1818
|
-
if (status === 403) {
|
|
1819
|
-
return new ZapierAuthenticationError(
|
|
1820
|
-
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
1821
|
-
{ statusCode: status }
|
|
1822
|
-
);
|
|
1823
|
-
}
|
|
1824
|
-
return void 0;
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1798
|
+
async function listActionsPage(options) {
|
|
1799
|
+
const { api, getVersionedImplementationId } = context;
|
|
1800
|
+
const selectedApi = await getVersionedImplementationId(options.appKey);
|
|
1801
|
+
if (!selectedApi) {
|
|
1802
|
+
throw new ZapierConfigurationError(
|
|
1803
|
+
"No current_implementation_id found for app",
|
|
1804
|
+
{ configType: "current_implementation_id" }
|
|
1827
1805
|
);
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1806
|
+
}
|
|
1807
|
+
const searchParams = {
|
|
1808
|
+
global: "true",
|
|
1809
|
+
public_only: "true",
|
|
1810
|
+
selected_apis: selectedApi
|
|
1811
|
+
};
|
|
1812
|
+
const data = await api.get(
|
|
1813
|
+
"/zapier/api/v4/implementations/",
|
|
1814
|
+
{
|
|
1815
|
+
searchParams,
|
|
1816
|
+
customErrorHandler: ({ status }) => {
|
|
1817
|
+
if (status === 401) {
|
|
1818
|
+
return new ZapierAuthenticationError(
|
|
1819
|
+
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
1820
|
+
{ statusCode: status }
|
|
1821
|
+
);
|
|
1837
1822
|
}
|
|
1823
|
+
if (status === 403) {
|
|
1824
|
+
return new ZapierAuthenticationError(
|
|
1825
|
+
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
1826
|
+
{ statusCode: status }
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
return void 0;
|
|
1838
1830
|
}
|
|
1839
1831
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1832
|
+
);
|
|
1833
|
+
let allActions = [];
|
|
1834
|
+
for (const implementation of data.results || []) {
|
|
1835
|
+
if (implementation.actions) {
|
|
1836
|
+
for (const action of implementation.actions) {
|
|
1837
|
+
const actionWithContext = {
|
|
1838
|
+
...action,
|
|
1839
|
+
selected_api: action.selected_api || implementation.selected_api
|
|
1840
|
+
};
|
|
1841
|
+
allActions.push(normalizeActionItem(actionWithContext));
|
|
1842
|
+
}
|
|
1844
1843
|
}
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1844
|
+
}
|
|
1845
|
+
if (options.actionType) {
|
|
1846
|
+
allActions = allActions.filter(
|
|
1847
|
+
(action) => action.action_type === options.actionType
|
|
1848
|
+
);
|
|
1849
|
+
}
|
|
1850
|
+
return {
|
|
1851
|
+
data: allActions,
|
|
1852
|
+
nextCursor: void 0
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
const methodName = stripPageSuffix(listActionsPage.name);
|
|
1856
|
+
const listActionsDefinition = createPaginatedFunction(
|
|
1857
|
+
listActionsPage,
|
|
1850
1858
|
ListActionsSchema,
|
|
1851
|
-
createTelemetryCallback(
|
|
1852
|
-
|
|
1853
|
-
"listActions"
|
|
1854
|
-
)
|
|
1859
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
1860
|
+
methodName
|
|
1855
1861
|
);
|
|
1856
1862
|
return {
|
|
1857
|
-
listActions,
|
|
1863
|
+
listActions: listActionsDefinition,
|
|
1858
1864
|
context: {
|
|
1859
1865
|
meta: {
|
|
1860
1866
|
listActions: methodMeta
|
|
@@ -2150,51 +2156,51 @@ function transformNeedsToFields(needs) {
|
|
|
2150
2156
|
return rootFields;
|
|
2151
2157
|
}
|
|
2152
2158
|
var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2159
|
+
async function listInputFieldsPage(options) {
|
|
2160
|
+
const { api, getVersionedImplementationId } = context;
|
|
2161
|
+
const {
|
|
2162
|
+
appKey,
|
|
2163
|
+
actionKey,
|
|
2164
|
+
actionType,
|
|
2165
|
+
authenticationId = null,
|
|
2166
|
+
inputs
|
|
2167
|
+
} = options;
|
|
2168
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
2169
|
+
if (!selectedApi) {
|
|
2170
|
+
throw new ZapierConfigurationError(
|
|
2171
|
+
"No current_implementation_id found for app",
|
|
2172
|
+
{ configType: "current_implementation_id" }
|
|
2173
|
+
);
|
|
2174
|
+
}
|
|
2175
|
+
const { data: action } = await sdk.getAction({
|
|
2176
|
+
appKey,
|
|
2177
|
+
actionType,
|
|
2178
|
+
actionKey
|
|
2179
|
+
});
|
|
2180
|
+
const needsData = await fetchImplementationNeeds({
|
|
2181
|
+
api,
|
|
2182
|
+
selectedApi,
|
|
2183
|
+
action: action.key,
|
|
2184
|
+
actionType,
|
|
2185
|
+
authenticationId,
|
|
2186
|
+
inputs
|
|
2187
|
+
});
|
|
2188
|
+
const rootFieldset = transformNeedsToFields(needsData.needs || []);
|
|
2189
|
+
return {
|
|
2190
|
+
data: rootFieldset,
|
|
2191
|
+
nextCursor: void 0
|
|
2192
|
+
// No pagination needed since we return all input fields
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
const methodName = stripPageSuffix(listInputFieldsPage.name);
|
|
2196
|
+
const listInputFieldsDefinition = createPaginatedFunction(
|
|
2197
|
+
listInputFieldsPage,
|
|
2190
2198
|
ListInputFieldsSchema,
|
|
2191
|
-
createTelemetryCallback(
|
|
2192
|
-
|
|
2193
|
-
"listInputFields"
|
|
2194
|
-
)
|
|
2199
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
2200
|
+
methodName
|
|
2195
2201
|
);
|
|
2196
2202
|
return {
|
|
2197
|
-
listInputFields,
|
|
2203
|
+
listInputFields: listInputFieldsDefinition,
|
|
2198
2204
|
context: {
|
|
2199
2205
|
meta: {
|
|
2200
2206
|
listInputFields: {
|
|
@@ -2276,78 +2282,78 @@ var AuthenticationItemSchema = withFormatter(
|
|
|
2276
2282
|
|
|
2277
2283
|
// src/plugins/listAuthentications/index.ts
|
|
2278
2284
|
var listAuthenticationsPlugin = ({ context }) => {
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
options.appKey
|
|
2286
|
-
);
|
|
2287
|
-
if (implementationId) {
|
|
2288
|
-
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
2289
|
-
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
if (options.authenticationIds && options.authenticationIds.length > 0) {
|
|
2293
|
-
searchParams.ids = options.authenticationIds.join(",");
|
|
2294
|
-
}
|
|
2295
|
-
if (options.search) {
|
|
2296
|
-
searchParams.search = options.search;
|
|
2297
|
-
} else if (options.title) {
|
|
2298
|
-
searchParams.search = options.title;
|
|
2299
|
-
}
|
|
2300
|
-
if (options.accountId) {
|
|
2301
|
-
searchParams.account_id = options.accountId;
|
|
2302
|
-
}
|
|
2303
|
-
if (options.owner) {
|
|
2304
|
-
searchParams.owner = options.owner;
|
|
2305
|
-
}
|
|
2306
|
-
searchParams.limit = options.pageSize.toString();
|
|
2307
|
-
if (options.cursor) {
|
|
2308
|
-
searchParams.offset = options.cursor;
|
|
2309
|
-
}
|
|
2310
|
-
const data = await api.get(
|
|
2311
|
-
"/zapier/api/v4/authentications/",
|
|
2312
|
-
{
|
|
2313
|
-
searchParams,
|
|
2314
|
-
customErrorHandler: ({ status }) => {
|
|
2315
|
-
if (status === 401) {
|
|
2316
|
-
return new ZapierAuthenticationError(
|
|
2317
|
-
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
2318
|
-
{ statusCode: status }
|
|
2319
|
-
);
|
|
2320
|
-
}
|
|
2321
|
-
if (status === 403) {
|
|
2322
|
-
return new ZapierAuthenticationError(
|
|
2323
|
-
`Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${status})`,
|
|
2324
|
-
{ statusCode: status }
|
|
2325
|
-
);
|
|
2326
|
-
}
|
|
2327
|
-
return void 0;
|
|
2328
|
-
},
|
|
2329
|
-
authRequired: true
|
|
2330
|
-
}
|
|
2331
|
-
);
|
|
2332
|
-
let auths = (data.results || []).map(
|
|
2333
|
-
(auth) => normalizeAuthenticationItem(auth)
|
|
2285
|
+
async function listAuthenticationsPage(options) {
|
|
2286
|
+
const { api, getVersionedImplementationId } = context;
|
|
2287
|
+
const searchParams = {};
|
|
2288
|
+
if (options.appKey) {
|
|
2289
|
+
const implementationId = await getVersionedImplementationId(
|
|
2290
|
+
options.appKey
|
|
2334
2291
|
);
|
|
2335
|
-
if (
|
|
2336
|
-
|
|
2292
|
+
if (implementationId) {
|
|
2293
|
+
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
2294
|
+
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
2337
2295
|
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2296
|
+
}
|
|
2297
|
+
if (options.authenticationIds && options.authenticationIds.length > 0) {
|
|
2298
|
+
searchParams.ids = options.authenticationIds.join(",");
|
|
2299
|
+
}
|
|
2300
|
+
if (options.search) {
|
|
2301
|
+
searchParams.search = options.search;
|
|
2302
|
+
} else if (options.title) {
|
|
2303
|
+
searchParams.search = options.title;
|
|
2304
|
+
}
|
|
2305
|
+
if (options.accountId) {
|
|
2306
|
+
searchParams.account_id = options.accountId;
|
|
2307
|
+
}
|
|
2308
|
+
if (options.owner) {
|
|
2309
|
+
searchParams.owner = options.owner;
|
|
2310
|
+
}
|
|
2311
|
+
searchParams.limit = options.pageSize.toString();
|
|
2312
|
+
if (options.cursor) {
|
|
2313
|
+
searchParams.offset = options.cursor;
|
|
2314
|
+
}
|
|
2315
|
+
const data = await api.get(
|
|
2316
|
+
"/zapier/api/v4/authentications/",
|
|
2317
|
+
{
|
|
2318
|
+
searchParams,
|
|
2319
|
+
customErrorHandler: ({ status }) => {
|
|
2320
|
+
if (status === 401) {
|
|
2321
|
+
return new ZapierAuthenticationError(
|
|
2322
|
+
`Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
|
|
2323
|
+
{ statusCode: status }
|
|
2324
|
+
);
|
|
2325
|
+
}
|
|
2326
|
+
if (status === 403) {
|
|
2327
|
+
return new ZapierAuthenticationError(
|
|
2328
|
+
`Access forbidden. Your token may not have the required scopes to list authentications. (HTTP ${status})`,
|
|
2329
|
+
{ statusCode: status }
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
return void 0;
|
|
2333
|
+
},
|
|
2334
|
+
authRequired: true
|
|
2335
|
+
}
|
|
2336
|
+
);
|
|
2337
|
+
let auths = (data.results || []).map(
|
|
2338
|
+
(auth) => normalizeAuthenticationItem(auth)
|
|
2339
|
+
);
|
|
2340
|
+
if (options.title) {
|
|
2341
|
+
auths = auths.filter((auth) => auth.title === options.title);
|
|
2342
|
+
}
|
|
2343
|
+
return {
|
|
2344
|
+
data: auths,
|
|
2345
|
+
nextCursor: extractCursor(data)
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
const methodName = stripPageSuffix(listAuthenticationsPage.name);
|
|
2349
|
+
const listAuthenticationsDefinition = createPaginatedFunction(
|
|
2350
|
+
listAuthenticationsPage,
|
|
2343
2351
|
ListAuthenticationsSchema,
|
|
2344
|
-
createTelemetryCallback(
|
|
2345
|
-
|
|
2346
|
-
"listAuthentications"
|
|
2347
|
-
)
|
|
2352
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
2353
|
+
methodName
|
|
2348
2354
|
);
|
|
2349
2355
|
return {
|
|
2350
|
-
listAuthentications,
|
|
2356
|
+
listAuthentications: listAuthenticationsDefinition,
|
|
2351
2357
|
context: {
|
|
2352
2358
|
meta: {
|
|
2353
2359
|
listAuthentications: {
|
|
@@ -2372,26 +2378,30 @@ var GetAppSchema = zod.z.object({
|
|
|
2372
2378
|
|
|
2373
2379
|
// src/plugins/getApp/index.ts
|
|
2374
2380
|
var getAppPlugin = ({ sdk, context }) => {
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2381
|
+
async function getApp(options) {
|
|
2382
|
+
const appsIterator = sdk.listApps({
|
|
2383
|
+
appKeys: [options.appKey],
|
|
2384
|
+
_telemetry: { isNested: true }
|
|
2385
|
+
}).items();
|
|
2386
|
+
for await (const app of appsIterator) {
|
|
2387
|
+
return {
|
|
2388
|
+
data: app
|
|
2389
|
+
};
|
|
2390
|
+
}
|
|
2391
|
+
throw new ZapierAppNotFoundError("App not found", {
|
|
2392
|
+
appKey: options.appKey
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2395
|
+
const getAppDefinition = createFunction(
|
|
2396
|
+
getApp,
|
|
2390
2397
|
GetAppSchema,
|
|
2391
|
-
createTelemetryCallback(
|
|
2398
|
+
createTelemetryCallback(
|
|
2399
|
+
context.eventEmission.emitMethodCalled,
|
|
2400
|
+
getApp.name
|
|
2401
|
+
)
|
|
2392
2402
|
);
|
|
2393
2403
|
return {
|
|
2394
|
-
getApp,
|
|
2404
|
+
getApp: getAppDefinition,
|
|
2395
2405
|
context: {
|
|
2396
2406
|
meta: {
|
|
2397
2407
|
getApp: {
|
|
@@ -2416,27 +2426,28 @@ var GetActionSchema = zod.z.object({
|
|
|
2416
2426
|
|
|
2417
2427
|
// src/plugins/getAction/index.ts
|
|
2418
2428
|
var getActionPlugin = ({ sdk, context }) => {
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
return { data: action };
|
|
2425
|
-
}
|
|
2429
|
+
async function getAction(options) {
|
|
2430
|
+
const { actionKey, actionType, appKey } = options;
|
|
2431
|
+
for await (const action of sdk.listActions({ appKey, _telemetry: { isNested: true } }).items()) {
|
|
2432
|
+
if ((action.key === actionKey || action.id === actionKey) && action.action_type === actionType) {
|
|
2433
|
+
return { data: action };
|
|
2426
2434
|
}
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
)
|
|
2431
|
-
|
|
2435
|
+
}
|
|
2436
|
+
throw new ZapierResourceNotFoundError(
|
|
2437
|
+
`Action not found: ${actionKey} with type ${actionType}`,
|
|
2438
|
+
{ resourceType: "Action", resourceId: `${actionKey} (${actionType})` }
|
|
2439
|
+
);
|
|
2440
|
+
}
|
|
2441
|
+
const getActionDefinition = createFunction(
|
|
2442
|
+
getAction,
|
|
2432
2443
|
GetActionSchema,
|
|
2433
2444
|
createTelemetryCallback(
|
|
2434
2445
|
context.eventEmission.emitMethodCalled,
|
|
2435
|
-
|
|
2446
|
+
getAction.name
|
|
2436
2447
|
)
|
|
2437
2448
|
);
|
|
2438
2449
|
return {
|
|
2439
|
-
getAction,
|
|
2450
|
+
getAction: getActionDefinition,
|
|
2440
2451
|
context: {
|
|
2441
2452
|
meta: {
|
|
2442
2453
|
getAction: {
|
|
@@ -2511,21 +2522,22 @@ zod.z.object({
|
|
|
2511
2522
|
|
|
2512
2523
|
// src/plugins/getAuthentication/index.ts
|
|
2513
2524
|
var getAuthenticationPlugin = ({ context }) => {
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2525
|
+
async function getAuthentication(options) {
|
|
2526
|
+
const { api } = context;
|
|
2527
|
+
return await api.get(
|
|
2528
|
+
`/api/v0/authentications/${options.authenticationId}`
|
|
2529
|
+
);
|
|
2530
|
+
}
|
|
2531
|
+
const getAuthenticationDefinition = createFunction(
|
|
2532
|
+
getAuthentication,
|
|
2521
2533
|
GetAuthenticationOptionsSchema,
|
|
2522
2534
|
createTelemetryCallback(
|
|
2523
2535
|
context.eventEmission.emitMethodCalled,
|
|
2524
|
-
|
|
2536
|
+
getAuthentication.name
|
|
2525
2537
|
)
|
|
2526
2538
|
);
|
|
2527
2539
|
return {
|
|
2528
|
-
getAuthentication,
|
|
2540
|
+
getAuthentication: getAuthenticationDefinition,
|
|
2529
2541
|
context: {
|
|
2530
2542
|
meta: {
|
|
2531
2543
|
getAuthentication: {
|
|
@@ -2554,31 +2566,32 @@ var FindFirstAuthenticationSchema = zod.z.object({
|
|
|
2554
2566
|
|
|
2555
2567
|
// src/plugins/findFirstAuthentication/index.ts
|
|
2556
2568
|
var findFirstAuthenticationPlugin = ({ sdk, context }) => {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2569
|
+
async function findFirstAuthentication(options = {}) {
|
|
2570
|
+
const authsResponse = await sdk.listAuthentications({
|
|
2571
|
+
...options,
|
|
2572
|
+
maxItems: 1,
|
|
2573
|
+
_telemetry: { isNested: true }
|
|
2574
|
+
});
|
|
2575
|
+
if (authsResponse.data.length === 0) {
|
|
2576
|
+
throw new ZapierResourceNotFoundError(
|
|
2577
|
+
"No authentication found matching the specified criteria",
|
|
2578
|
+
{ resourceType: "Authentication" }
|
|
2579
|
+
);
|
|
2580
|
+
}
|
|
2581
|
+
return {
|
|
2582
|
+
data: authsResponse.data[0]
|
|
2583
|
+
};
|
|
2584
|
+
}
|
|
2585
|
+
const findFirstAuthenticationDefinition = createFunction(
|
|
2586
|
+
findFirstAuthentication,
|
|
2574
2587
|
FindFirstAuthenticationSchema,
|
|
2575
2588
|
createTelemetryCallback(
|
|
2576
2589
|
context.eventEmission.emitMethodCalled,
|
|
2577
|
-
|
|
2590
|
+
findFirstAuthentication.name
|
|
2578
2591
|
)
|
|
2579
2592
|
);
|
|
2580
2593
|
return {
|
|
2581
|
-
findFirstAuthentication,
|
|
2594
|
+
findFirstAuthentication: findFirstAuthenticationDefinition,
|
|
2582
2595
|
context: {
|
|
2583
2596
|
meta: {
|
|
2584
2597
|
findFirstAuthentication: {
|
|
@@ -2604,37 +2617,38 @@ var FindUniqueAuthenticationSchema = zod.z.object({
|
|
|
2604
2617
|
|
|
2605
2618
|
// src/plugins/findUniqueAuthentication/index.ts
|
|
2606
2619
|
var findUniqueAuthenticationPlugin = ({ sdk, context }) => {
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2620
|
+
async function findUniqueAuthentication(options = {}) {
|
|
2621
|
+
const authsResponse = await sdk.listAuthentications({
|
|
2622
|
+
...options,
|
|
2623
|
+
maxItems: 2,
|
|
2624
|
+
// Get up to 2 to check for uniqueness
|
|
2625
|
+
_telemetry: { isNested: true }
|
|
2626
|
+
});
|
|
2627
|
+
if (authsResponse.data.length === 0) {
|
|
2628
|
+
throw new ZapierResourceNotFoundError(
|
|
2629
|
+
"No authentication found matching the specified criteria",
|
|
2630
|
+
{ resourceType: "Authentication" }
|
|
2631
|
+
);
|
|
2632
|
+
}
|
|
2633
|
+
if (authsResponse.data.length > 1) {
|
|
2634
|
+
throw new ZapierValidationError(
|
|
2635
|
+
"Multiple authentications found matching the specified criteria. Expected exactly one."
|
|
2636
|
+
);
|
|
2637
|
+
}
|
|
2638
|
+
return {
|
|
2639
|
+
data: authsResponse.data[0]
|
|
2640
|
+
};
|
|
2641
|
+
}
|
|
2642
|
+
const findUniqueAuthenticationDefinition = createFunction(
|
|
2643
|
+
findUniqueAuthentication,
|
|
2630
2644
|
FindUniqueAuthenticationSchema,
|
|
2631
2645
|
createTelemetryCallback(
|
|
2632
2646
|
context.eventEmission.emitMethodCalled,
|
|
2633
|
-
|
|
2647
|
+
findUniqueAuthentication.name
|
|
2634
2648
|
)
|
|
2635
2649
|
);
|
|
2636
2650
|
return {
|
|
2637
|
-
findUniqueAuthentication,
|
|
2651
|
+
findUniqueAuthentication: findUniqueAuthenticationDefinition,
|
|
2638
2652
|
context: {
|
|
2639
2653
|
meta: {
|
|
2640
2654
|
findUniqueAuthentication: {
|
|
@@ -2705,65 +2719,62 @@ async function executeAction(actionOptions) {
|
|
|
2705
2719
|
});
|
|
2706
2720
|
}
|
|
2707
2721
|
var runActionPlugin = ({ sdk, context }) => {
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2722
|
+
async function runActionPage(options) {
|
|
2723
|
+
const { api } = context;
|
|
2724
|
+
const {
|
|
2725
|
+
appKey,
|
|
2726
|
+
actionKey,
|
|
2727
|
+
actionType,
|
|
2728
|
+
authenticationId,
|
|
2729
|
+
inputs = {}
|
|
2730
|
+
} = options;
|
|
2731
|
+
const actionData = await sdk.getAction({
|
|
2732
|
+
appKey,
|
|
2733
|
+
actionKey,
|
|
2734
|
+
actionType,
|
|
2735
|
+
_telemetry: { isNested: true }
|
|
2736
|
+
});
|
|
2737
|
+
if (actionData.data.action_type !== actionType) {
|
|
2738
|
+
throw new ZapierValidationError(
|
|
2739
|
+
`Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`
|
|
2740
|
+
);
|
|
2741
|
+
}
|
|
2742
|
+
const actionId = actionData.data.id;
|
|
2743
|
+
const result = await executeAction({
|
|
2744
|
+
api,
|
|
2745
|
+
context,
|
|
2746
|
+
appKey,
|
|
2747
|
+
// Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
|
|
2748
|
+
// we retrieve actions (probably legacy reasons), so we just pass along all the things!
|
|
2749
|
+
actionId,
|
|
2750
|
+
actionKey,
|
|
2751
|
+
actionType,
|
|
2752
|
+
executionOptions: { inputs },
|
|
2753
|
+
authenticationId});
|
|
2754
|
+
if (result.errors && result.errors.length > 0) {
|
|
2755
|
+
const errorMessage = result.errors.map(
|
|
2756
|
+
(error) => error.detail || error.title || "Unknown error"
|
|
2757
|
+
).join("; ");
|
|
2758
|
+
throw new ZapierActionError(`Action execution failed: ${errorMessage}`, {
|
|
2719
2759
|
appKey,
|
|
2720
|
-
actionKey
|
|
2721
|
-
actionType,
|
|
2722
|
-
_telemetry: { isNested: true }
|
|
2760
|
+
actionKey
|
|
2723
2761
|
});
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
// Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
|
|
2735
|
-
// we retrieve actions (probably legacy reasons), so we just pass along all the things!
|
|
2736
|
-
actionId,
|
|
2737
|
-
actionKey,
|
|
2738
|
-
actionType,
|
|
2739
|
-
executionOptions: { inputs },
|
|
2740
|
-
authenticationId});
|
|
2741
|
-
if (result.errors && result.errors.length > 0) {
|
|
2742
|
-
const errorMessage = result.errors.map(
|
|
2743
|
-
(error) => error.detail || error.title || "Unknown error"
|
|
2744
|
-
).join("; ");
|
|
2745
|
-
throw new ZapierActionError(
|
|
2746
|
-
`Action execution failed: ${errorMessage}`,
|
|
2747
|
-
{
|
|
2748
|
-
appKey,
|
|
2749
|
-
actionKey
|
|
2750
|
-
}
|
|
2751
|
-
);
|
|
2752
|
-
}
|
|
2753
|
-
return {
|
|
2754
|
-
data: result.results || [],
|
|
2755
|
-
nextCursor: void 0
|
|
2756
|
-
// No pagination implemented yet
|
|
2757
|
-
};
|
|
2758
|
-
},
|
|
2762
|
+
}
|
|
2763
|
+
return {
|
|
2764
|
+
data: result.results || [],
|
|
2765
|
+
nextCursor: void 0
|
|
2766
|
+
// No pagination implemented yet
|
|
2767
|
+
};
|
|
2768
|
+
}
|
|
2769
|
+
const methodName = stripPageSuffix(runActionPage.name);
|
|
2770
|
+
const runActionDefinition = createPaginatedFunction(
|
|
2771
|
+
runActionPage,
|
|
2759
2772
|
RunActionSchema,
|
|
2760
|
-
createTelemetryCallback(
|
|
2761
|
-
|
|
2762
|
-
"runAction"
|
|
2763
|
-
)
|
|
2773
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
2774
|
+
methodName
|
|
2764
2775
|
);
|
|
2765
2776
|
return {
|
|
2766
|
-
runAction,
|
|
2777
|
+
runAction: runActionDefinition,
|
|
2767
2778
|
context: {
|
|
2768
2779
|
meta: {
|
|
2769
2780
|
runAction: {
|
|
@@ -2810,46 +2821,50 @@ function transformUrlToRelayPath(url) {
|
|
|
2810
2821
|
return relayPath;
|
|
2811
2822
|
}
|
|
2812
2823
|
var requestPlugin = ({ context }) => {
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
headers[key] = value;
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
if (authenticationId) {
|
|
2834
|
-
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
2835
|
-
}
|
|
2836
|
-
if (callbackUrl) {
|
|
2837
|
-
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
2838
|
-
}
|
|
2839
|
-
if (authenticationTemplate) {
|
|
2840
|
-
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
2824
|
+
async function request(options) {
|
|
2825
|
+
const { api } = context;
|
|
2826
|
+
const {
|
|
2827
|
+
url,
|
|
2828
|
+
method = "GET",
|
|
2829
|
+
body,
|
|
2830
|
+
headers: optionsHeaders,
|
|
2831
|
+
authenticationId,
|
|
2832
|
+
callbackUrl,
|
|
2833
|
+
authenticationTemplate
|
|
2834
|
+
} = options;
|
|
2835
|
+
const relayPath = transformUrlToRelayPath(url);
|
|
2836
|
+
const headers = {};
|
|
2837
|
+
if (optionsHeaders) {
|
|
2838
|
+
const headerEntries = optionsHeaders instanceof Headers ? Array.from(optionsHeaders.entries()) : Array.isArray(optionsHeaders) ? optionsHeaders : Object.entries(optionsHeaders);
|
|
2839
|
+
for (const [key, value] of headerEntries) {
|
|
2840
|
+
headers[key] = value;
|
|
2841
2841
|
}
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2842
|
+
}
|
|
2843
|
+
if (authenticationId) {
|
|
2844
|
+
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
2845
|
+
}
|
|
2846
|
+
if (callbackUrl) {
|
|
2847
|
+
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
2848
|
+
}
|
|
2849
|
+
if (authenticationTemplate) {
|
|
2850
|
+
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
2851
|
+
}
|
|
2852
|
+
return await api.fetch(relayPath, {
|
|
2853
|
+
method,
|
|
2854
|
+
body,
|
|
2855
|
+
headers
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
const requestDefinition = createFunction(
|
|
2859
|
+
request,
|
|
2848
2860
|
RelayRequestSchema,
|
|
2849
|
-
createTelemetryCallback(
|
|
2861
|
+
createTelemetryCallback(
|
|
2862
|
+
context.eventEmission.emitMethodCalled,
|
|
2863
|
+
request.name
|
|
2864
|
+
)
|
|
2850
2865
|
);
|
|
2851
2866
|
return {
|
|
2852
|
-
request,
|
|
2867
|
+
request: requestDefinition,
|
|
2853
2868
|
context: {
|
|
2854
2869
|
meta: {
|
|
2855
2870
|
request: {
|
|
@@ -3352,32 +3367,33 @@ var UserProfileItemSchema = withFormatter(
|
|
|
3352
3367
|
|
|
3353
3368
|
// src/plugins/getProfile/index.ts
|
|
3354
3369
|
var getProfilePlugin = ({ context }) => {
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
data
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3370
|
+
async function getProfile() {
|
|
3371
|
+
const profile = await context.api.get(
|
|
3372
|
+
"/zapier/api/v4/profile/",
|
|
3373
|
+
{
|
|
3374
|
+
authRequired: true
|
|
3375
|
+
}
|
|
3376
|
+
);
|
|
3377
|
+
const { user_id: _unusedUserId, ...data } = profile;
|
|
3378
|
+
return {
|
|
3379
|
+
data: {
|
|
3380
|
+
...data,
|
|
3381
|
+
// Pass through all API response fields
|
|
3382
|
+
full_name: `${profile.first_name} ${profile.last_name}`
|
|
3383
|
+
// Computed field
|
|
3384
|
+
}
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
const getProfileDefinition = createFunction(
|
|
3388
|
+
getProfile,
|
|
3373
3389
|
GetProfileSchema,
|
|
3374
3390
|
createTelemetryCallback(
|
|
3375
3391
|
context.eventEmission.emitMethodCalled,
|
|
3376
|
-
|
|
3392
|
+
getProfile.name
|
|
3377
3393
|
)
|
|
3378
3394
|
);
|
|
3379
3395
|
return {
|
|
3380
|
-
getProfile,
|
|
3396
|
+
getProfile: getProfileDefinition,
|
|
3381
3397
|
context: {
|
|
3382
3398
|
meta: {
|
|
3383
3399
|
getProfile: {
|
|
@@ -4620,48 +4636,49 @@ var GetInputFieldsSchemaSchema = zod.z.object({
|
|
|
4620
4636
|
|
|
4621
4637
|
// src/plugins/getInputFieldsSchema/index.ts
|
|
4622
4638
|
var getInputFieldsSchemaPlugin = ({ sdk, context }) => {
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4639
|
+
async function getInputFieldsSchema(options) {
|
|
4640
|
+
const { api, getVersionedImplementationId } = context;
|
|
4641
|
+
const {
|
|
4642
|
+
appKey,
|
|
4643
|
+
actionKey,
|
|
4644
|
+
actionType,
|
|
4645
|
+
authenticationId = null,
|
|
4646
|
+
inputs
|
|
4647
|
+
} = options;
|
|
4648
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
4649
|
+
if (!selectedApi) {
|
|
4650
|
+
throw new ZapierConfigurationError(
|
|
4651
|
+
"No current_implementation_id found for app",
|
|
4652
|
+
{ configType: "current_implementation_id" }
|
|
4653
|
+
);
|
|
4654
|
+
}
|
|
4655
|
+
const { data: action } = await sdk.getAction({
|
|
4656
|
+
appKey,
|
|
4657
|
+
actionType,
|
|
4658
|
+
actionKey
|
|
4659
|
+
});
|
|
4660
|
+
const needsData = await fetchImplementationNeeds({
|
|
4661
|
+
api,
|
|
4662
|
+
selectedApi,
|
|
4663
|
+
action: action.key,
|
|
4664
|
+
actionType,
|
|
4665
|
+
authenticationId,
|
|
4666
|
+
inputs
|
|
4667
|
+
});
|
|
4668
|
+
return {
|
|
4669
|
+
data: needsData.schema || {}
|
|
4670
|
+
};
|
|
4671
|
+
}
|
|
4672
|
+
const getInputFieldsSchemaDefinition = createFunction(
|
|
4673
|
+
getInputFieldsSchema,
|
|
4657
4674
|
GetInputFieldsSchemaSchema,
|
|
4658
4675
|
createTelemetryCallback(
|
|
4659
4676
|
context.eventEmission.emitMethodCalled,
|
|
4660
|
-
|
|
4677
|
+
getInputFieldsSchema.name
|
|
4661
4678
|
)
|
|
4662
4679
|
);
|
|
4663
4680
|
return {
|
|
4664
|
-
getInputFieldsSchema,
|
|
4681
|
+
getInputFieldsSchema: getInputFieldsSchemaDefinition,
|
|
4665
4682
|
context: {
|
|
4666
4683
|
meta: {
|
|
4667
4684
|
getInputFieldsSchema: {
|
|
@@ -4730,94 +4747,94 @@ function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
|
4730
4747
|
};
|
|
4731
4748
|
}
|
|
4732
4749
|
var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
{ configType: "current_implementation_id" }
|
|
4751
|
-
);
|
|
4752
|
-
}
|
|
4753
|
-
const { data: action } = await sdk.getAction({
|
|
4754
|
-
appKey,
|
|
4755
|
-
actionType,
|
|
4756
|
-
actionKey
|
|
4757
|
-
});
|
|
4758
|
-
const needsData = await fetchImplementationNeeds({
|
|
4759
|
-
api,
|
|
4760
|
-
selectedApi,
|
|
4761
|
-
action: action.key,
|
|
4762
|
-
actionType,
|
|
4763
|
-
authenticationId,
|
|
4764
|
-
inputs
|
|
4765
|
-
});
|
|
4766
|
-
const targetNeed = needsData.needs?.find(
|
|
4767
|
-
(need) => need.key === inputFieldKey
|
|
4750
|
+
async function listInputFieldChoicesPage(options) {
|
|
4751
|
+
const { api, getVersionedImplementationId } = context;
|
|
4752
|
+
const {
|
|
4753
|
+
appKey,
|
|
4754
|
+
actionType,
|
|
4755
|
+
actionKey,
|
|
4756
|
+
inputFieldKey,
|
|
4757
|
+
authenticationId = null,
|
|
4758
|
+
inputs,
|
|
4759
|
+
page,
|
|
4760
|
+
cursor
|
|
4761
|
+
} = options;
|
|
4762
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
4763
|
+
if (!selectedApi) {
|
|
4764
|
+
throw new ZapierConfigurationError(
|
|
4765
|
+
"No current_implementation_id found for app",
|
|
4766
|
+
{ configType: "current_implementation_id" }
|
|
4768
4767
|
);
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4768
|
+
}
|
|
4769
|
+
const { data: action } = await sdk.getAction({
|
|
4770
|
+
appKey,
|
|
4771
|
+
actionType,
|
|
4772
|
+
actionKey
|
|
4773
|
+
});
|
|
4774
|
+
const needsData = await fetchImplementationNeeds({
|
|
4775
|
+
api,
|
|
4776
|
+
selectedApi,
|
|
4777
|
+
action: action.key,
|
|
4778
|
+
actionType,
|
|
4779
|
+
authenticationId,
|
|
4780
|
+
inputs
|
|
4781
|
+
});
|
|
4782
|
+
const targetNeed = needsData.needs?.find(
|
|
4783
|
+
(need) => need.key === inputFieldKey
|
|
4784
|
+
);
|
|
4785
|
+
if (targetNeed?.choices && targetNeed.choices.length > 0) {
|
|
4786
|
+
return {
|
|
4787
|
+
data: targetNeed.choices.map(
|
|
4788
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
4789
|
+
),
|
|
4790
|
+
nextCursor: void 0
|
|
4791
|
+
};
|
|
4792
|
+
}
|
|
4793
|
+
if (!action.id) {
|
|
4794
|
+
throw new ZapierApiError(
|
|
4795
|
+
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`
|
|
4793
4796
|
);
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4797
|
+
}
|
|
4798
|
+
const requestPage = cursor ? parseInt(cursor, 10) : page ?? 0;
|
|
4799
|
+
const choicesData = await fetchImplementationChoices({
|
|
4800
|
+
api,
|
|
4801
|
+
actionId: action.id,
|
|
4802
|
+
inputFieldId: inputFieldKey,
|
|
4803
|
+
authenticationId,
|
|
4804
|
+
inputs,
|
|
4805
|
+
page: requestPage
|
|
4806
|
+
});
|
|
4807
|
+
const choices = (choicesData.choices || []).map(
|
|
4808
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
4809
|
+
);
|
|
4810
|
+
let nextCursor;
|
|
4811
|
+
if (choicesData.next_page != null) {
|
|
4812
|
+
nextCursor = choicesData.next_page.toString();
|
|
4813
|
+
} else if (choicesData.links?.next) {
|
|
4814
|
+
try {
|
|
4815
|
+
const nextUrl = new URL(choicesData.links.next);
|
|
4816
|
+
const nextPage = nextUrl.searchParams.get("page");
|
|
4817
|
+
if (nextPage) {
|
|
4818
|
+
nextCursor = nextPage;
|
|
4806
4819
|
}
|
|
4820
|
+
} catch {
|
|
4821
|
+
nextCursor = void 0;
|
|
4807
4822
|
}
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
}
|
|
4823
|
+
}
|
|
4824
|
+
return {
|
|
4825
|
+
data: choices,
|
|
4826
|
+
nextCursor
|
|
4827
|
+
};
|
|
4828
|
+
}
|
|
4829
|
+
const methodName = stripPageSuffix(listInputFieldChoicesPage.name);
|
|
4830
|
+
const listInputFieldChoicesDefinition = createPaginatedFunction(
|
|
4831
|
+
listInputFieldChoicesPage,
|
|
4813
4832
|
ListInputFieldChoicesSchema,
|
|
4814
|
-
createTelemetryCallback(
|
|
4815
|
-
|
|
4816
|
-
"listInputFieldChoices"
|
|
4817
|
-
)
|
|
4833
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, methodName),
|
|
4834
|
+
methodName
|
|
4818
4835
|
);
|
|
4819
4836
|
return {
|
|
4820
|
-
listInputFieldChoices,
|
|
4837
|
+
listInputFieldChoices: listInputFieldChoicesDefinition,
|
|
4821
4838
|
context: {
|
|
4822
4839
|
meta: {
|
|
4823
4840
|
listInputFieldChoices: {
|
|
@@ -4991,7 +5008,7 @@ function getCpuTime() {
|
|
|
4991
5008
|
|
|
4992
5009
|
// package.json
|
|
4993
5010
|
var package_default = {
|
|
4994
|
-
version: "0.15.
|
|
5011
|
+
version: "0.15.13"};
|
|
4995
5012
|
|
|
4996
5013
|
// src/plugins/eventEmission/builders.ts
|
|
4997
5014
|
function createBaseEvent(context = {}) {
|