@zapier/zapier-sdk 0.5.2 → 0.6.1
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 +17 -0
- package/README.md +107 -83
- package/dist/index.cjs +320 -50
- package/dist/index.d.mts +409 -340
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.mjs +320 -50
- package/dist/plugins/api/index.js +1 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.js +1 -0
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.js +1 -0
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +1 -0
- package/dist/plugins/getAction/index.test.js +1 -1
- package/dist/plugins/getApp/index.d.ts +6 -3
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +8 -18
- package/dist/plugins/getApp/index.test.js +2 -0
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +1 -0
- package/dist/plugins/getAuthentication/index.test.js +12 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +1 -0
- package/dist/plugins/listActions/index.d.ts +5 -3
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +6 -6
- package/dist/plugins/listActions/index.test.js +26 -74
- package/dist/plugins/listActions/schemas.d.ts +4 -4
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +1 -0
- package/dist/plugins/listApps/schemas.d.ts +2 -2
- package/dist/plugins/listAuthentications/index.d.ts +4 -2
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +9 -12
- package/dist/plugins/listAuthentications/index.test.js +33 -40
- package/dist/plugins/listAuthentications/schemas.d.ts +4 -4
- package/dist/plugins/listInputFields/index.d.ts +3 -1
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +5 -5
- package/dist/plugins/listInputFields/index.test.js +10 -8
- package/dist/plugins/listInputFields/schemas.d.ts +4 -4
- package/dist/plugins/lockVersion/index.d.ts +24 -0
- package/dist/plugins/lockVersion/index.d.ts.map +1 -0
- package/dist/plugins/lockVersion/index.js +72 -0
- package/dist/plugins/lockVersion/index.test.d.ts +2 -0
- package/dist/plugins/lockVersion/index.test.d.ts.map +1 -0
- package/dist/plugins/lockVersion/index.test.js +129 -0
- package/dist/plugins/lockVersion/schemas.d.ts +10 -0
- package/dist/plugins/lockVersion/schemas.d.ts.map +1 -0
- package/dist/plugins/lockVersion/schemas.js +6 -0
- package/dist/plugins/manifest/index.d.ts +24 -0
- package/dist/plugins/manifest/index.d.ts.map +1 -0
- package/dist/plugins/manifest/index.js +119 -0
- package/dist/plugins/manifest/index.test.d.ts +2 -0
- package/dist/plugins/manifest/index.test.d.ts.map +1 -0
- package/dist/plugins/manifest/index.test.js +331 -0
- package/dist/plugins/manifest/schemas.d.ts +64 -0
- package/dist/plugins/manifest/schemas.d.ts.map +1 -0
- package/dist/plugins/manifest/schemas.js +25 -0
- package/dist/plugins/registry/index.d.ts +9 -1
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +68 -3
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +1 -0
- package/dist/plugins/request/index.test.js +6 -1
- package/dist/plugins/request/schemas.d.ts +4 -4
- package/dist/plugins/runAction/index.d.ts +2 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +5 -5
- package/dist/plugins/runAction/index.test.js +9 -8
- package/dist/plugins/runAction/schemas.d.ts +4 -4
- package/dist/sdk.d.ts +3 -3
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +18 -7
- package/dist/sdk.test.js +1 -1
- package/dist/types/plugin.d.ts +10 -2
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +13 -2
- package/dist/types/sdk.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/plugins/api/index.ts +1 -1
- package/src/plugins/findFirstAuthentication/index.ts +1 -0
- package/src/plugins/findUniqueAuthentication/index.ts +1 -0
- package/src/plugins/getAction/index.test.ts +1 -1
- package/src/plugins/getAction/index.ts +1 -0
- package/src/plugins/getApp/index.test.ts +2 -0
- package/src/plugins/getApp/index.ts +12 -24
- package/src/plugins/getAuthentication/index.test.ts +13 -3
- package/src/plugins/getAuthentication/index.ts +1 -0
- package/src/plugins/getProfile/index.ts +1 -0
- package/src/plugins/listActions/index.test.ts +30 -89
- package/src/plugins/listActions/index.ts +13 -9
- package/src/plugins/listApps/index.ts +1 -0
- package/src/plugins/listAuthentications/index.test.ts +38 -47
- package/src/plugins/listAuthentications/index.ts +21 -18
- package/src/plugins/listInputFields/index.test.ts +12 -9
- package/src/plugins/listInputFields/index.ts +10 -6
- package/src/plugins/lockVersion/index.test.ts +176 -0
- package/src/plugins/lockVersion/index.ts +112 -0
- package/src/plugins/lockVersion/schemas.ts +9 -0
- package/src/plugins/manifest/index.test.ts +438 -0
- package/src/plugins/manifest/index.ts +171 -0
- package/src/plugins/manifest/schemas.ts +53 -0
- package/src/plugins/registry/index.ts +89 -8
- package/src/plugins/request/index.test.ts +8 -4
- package/src/plugins/request/index.ts +1 -0
- package/src/plugins/runAction/index.test.ts +9 -8
- package/src/plugins/runAction/index.ts +13 -7
- package/src/sdk.test.ts +1 -1
- package/src/sdk.ts +22 -7
- package/src/types/plugin.ts +14 -2
- package/src/types/sdk.ts +15 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
4
6
|
|
|
5
7
|
// src/types/properties.ts
|
|
6
8
|
function withFormatter(schema, formatMeta) {
|
|
@@ -527,15 +529,67 @@ var RelayFetchSchema = RelayRequestSchema;
|
|
|
527
529
|
// src/plugins/registry/index.ts
|
|
528
530
|
var registryPlugin = ({ sdk, context }) => {
|
|
529
531
|
const metaKeys = Object.keys(context.meta || {});
|
|
530
|
-
const
|
|
532
|
+
const categoryDefinitions = {
|
|
533
|
+
app: {
|
|
534
|
+
title: "App",
|
|
535
|
+
titlePlural: "Apps"
|
|
536
|
+
},
|
|
537
|
+
authentication: {
|
|
538
|
+
title: "Authentication"
|
|
539
|
+
},
|
|
540
|
+
action: {
|
|
541
|
+
title: "Action"
|
|
542
|
+
},
|
|
543
|
+
http: {
|
|
544
|
+
title: "HTTP Request"
|
|
545
|
+
},
|
|
546
|
+
user: {
|
|
547
|
+
title: "User"
|
|
548
|
+
},
|
|
549
|
+
utility: {
|
|
550
|
+
title: "Utility",
|
|
551
|
+
titlePlural: "Utilities"
|
|
552
|
+
},
|
|
553
|
+
other: {
|
|
554
|
+
title: "Other"
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const functions = metaKeys.filter((key) => typeof sdk[key] === "function").map((key) => {
|
|
531
558
|
return {
|
|
532
559
|
...context.meta[key],
|
|
533
|
-
|
|
534
|
-
|
|
560
|
+
categories: context.meta[key].categories || [],
|
|
561
|
+
name: key
|
|
562
|
+
};
|
|
563
|
+
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
564
|
+
const knownCategories = Object.keys(categoryDefinitions);
|
|
565
|
+
const categories = knownCategories.sort((a, b) => {
|
|
566
|
+
if (a === "other") return 1;
|
|
567
|
+
if (b === "other") return -1;
|
|
568
|
+
const titleA = categoryDefinitions[a].title;
|
|
569
|
+
const titleB = categoryDefinitions[b].title;
|
|
570
|
+
return titleA.localeCompare(titleB);
|
|
571
|
+
}).map((categoryKey) => {
|
|
572
|
+
const categoryFunctions = functions.filter(
|
|
573
|
+
(f) => f.categories.includes(categoryKey) || // If the category is "other" and the function is not in any other category, include it
|
|
574
|
+
categoryKey === "other" && !f.categories.some((c) => knownCategories.includes(c))
|
|
575
|
+
).map((f) => f.name).sort();
|
|
576
|
+
const definition = categoryDefinitions[categoryKey];
|
|
577
|
+
const title = definition.title;
|
|
578
|
+
return {
|
|
579
|
+
key: categoryKey,
|
|
580
|
+
title,
|
|
581
|
+
titlePlural: definition.titlePlural ?? `${title}s`,
|
|
582
|
+
functions: categoryFunctions
|
|
535
583
|
};
|
|
536
584
|
});
|
|
585
|
+
function getRegistry() {
|
|
586
|
+
return {
|
|
587
|
+
functions,
|
|
588
|
+
categories
|
|
589
|
+
};
|
|
590
|
+
}
|
|
537
591
|
return {
|
|
538
|
-
|
|
592
|
+
getRegistry
|
|
539
593
|
};
|
|
540
594
|
};
|
|
541
595
|
|
|
@@ -624,7 +678,7 @@ async function pollUntilComplete(options) {
|
|
|
624
678
|
} else if (response.status === pendingStatus) {
|
|
625
679
|
errorCount = 0;
|
|
626
680
|
if (attempt < maxAttempts - 1) {
|
|
627
|
-
await new Promise((
|
|
681
|
+
await new Promise((resolve3) => setTimeout(resolve3, delay));
|
|
628
682
|
delay = Math.min(delay * 2, maxDelay);
|
|
629
683
|
continue;
|
|
630
684
|
}
|
|
@@ -637,7 +691,7 @@ async function pollUntilComplete(options) {
|
|
|
637
691
|
);
|
|
638
692
|
}
|
|
639
693
|
if (attempt < maxAttempts - 1) {
|
|
640
|
-
await new Promise((
|
|
694
|
+
await new Promise((resolve3) => setTimeout(resolve3, delay));
|
|
641
695
|
delay = Math.min(delay * 2, maxDelay);
|
|
642
696
|
continue;
|
|
643
697
|
}
|
|
@@ -961,7 +1015,7 @@ var apiPlugin = (params) => {
|
|
|
961
1015
|
getToken,
|
|
962
1016
|
onEvent,
|
|
963
1017
|
debug = false
|
|
964
|
-
} = params;
|
|
1018
|
+
} = params.context.options;
|
|
965
1019
|
const api = createZapierApi({
|
|
966
1020
|
baseUrl,
|
|
967
1021
|
token,
|
|
@@ -1654,6 +1708,7 @@ var getProfilePlugin = ({ context }) => {
|
|
|
1654
1708
|
context: {
|
|
1655
1709
|
meta: {
|
|
1656
1710
|
getProfile: {
|
|
1711
|
+
categories: ["user"],
|
|
1657
1712
|
inputSchema: GetProfileSchema
|
|
1658
1713
|
}
|
|
1659
1714
|
}
|
|
@@ -1708,6 +1763,16 @@ function splitVersionedKey(versionedKey) {
|
|
|
1708
1763
|
}
|
|
1709
1764
|
return [versionedKey, void 0];
|
|
1710
1765
|
}
|
|
1766
|
+
function normalizeImplementationToAppItem(implementation) {
|
|
1767
|
+
const [selectedApi, appVersion] = implementation.selected_api ? splitVersionedKey(implementation.selected_api) : [implementation.selected_api || "", void 0];
|
|
1768
|
+
return {
|
|
1769
|
+
title: implementation.name || selectedApi,
|
|
1770
|
+
key: selectedApi,
|
|
1771
|
+
current_implementation_id: implementation.selected_api || "",
|
|
1772
|
+
version: appVersion
|
|
1773
|
+
// Extract version separately
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1711
1776
|
function normalizeImplementationMetaToAppItem(implementationMeta) {
|
|
1712
1777
|
const [selectedApi, appVersion] = splitVersionedKey(implementationMeta.id);
|
|
1713
1778
|
return {
|
|
@@ -1893,6 +1958,7 @@ var listAppsPlugin = ({ context }) => {
|
|
|
1893
1958
|
context: {
|
|
1894
1959
|
meta: {
|
|
1895
1960
|
listApps: {
|
|
1961
|
+
categories: ["app"],
|
|
1896
1962
|
inputSchema: ListAppsSchema
|
|
1897
1963
|
}
|
|
1898
1964
|
}
|
|
@@ -1909,23 +1975,16 @@ var GetAppSchema = withOutputSchema(
|
|
|
1909
1975
|
);
|
|
1910
1976
|
|
|
1911
1977
|
// src/plugins/getApp/index.ts
|
|
1912
|
-
var getAppPlugin = ({
|
|
1978
|
+
var getAppPlugin = ({ context }) => {
|
|
1913
1979
|
const getApp = createFunction(async function getApp2(options) {
|
|
1914
|
-
const
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
const apps = [];
|
|
1920
|
-
for await (const app of appsIterator) {
|
|
1921
|
-
apps.push(app);
|
|
1922
|
-
break;
|
|
1923
|
-
}
|
|
1924
|
-
if (apps.length === 0) {
|
|
1925
|
-
throw new ZapierAppNotFoundError(appKey);
|
|
1980
|
+
const app = await context.getImplementation(options.appKey);
|
|
1981
|
+
if (!app) {
|
|
1982
|
+
throw new ZapierAppNotFoundError("App not found", {
|
|
1983
|
+
appKey: options.appKey
|
|
1984
|
+
});
|
|
1926
1985
|
}
|
|
1927
1986
|
return {
|
|
1928
|
-
data:
|
|
1987
|
+
data: app
|
|
1929
1988
|
};
|
|
1930
1989
|
}, GetAppSchema);
|
|
1931
1990
|
return {
|
|
@@ -1933,6 +1992,7 @@ var getAppPlugin = ({ sdk }) => {
|
|
|
1933
1992
|
context: {
|
|
1934
1993
|
meta: {
|
|
1935
1994
|
getApp: {
|
|
1995
|
+
categories: ["app"],
|
|
1936
1996
|
inputSchema: GetAppSchema
|
|
1937
1997
|
}
|
|
1938
1998
|
}
|
|
@@ -1991,12 +2051,11 @@ var ListActionsSchema = withOutputSchema(
|
|
|
1991
2051
|
);
|
|
1992
2052
|
|
|
1993
2053
|
// src/plugins/listActions/index.ts
|
|
1994
|
-
var listActionsPlugin = ({
|
|
2054
|
+
var listActionsPlugin = ({ context }) => {
|
|
1995
2055
|
const listActions = createPaginatedFunction(async function listActionsPage(options) {
|
|
1996
|
-
const { api } = context;
|
|
1997
|
-
const
|
|
1998
|
-
|
|
1999
|
-
if (!implementationId) {
|
|
2056
|
+
const { api, getVersionedImplementationId } = context;
|
|
2057
|
+
const selectedApi = await getVersionedImplementationId(options.appKey);
|
|
2058
|
+
if (!selectedApi) {
|
|
2000
2059
|
throw new ZapierConfigurationError(
|
|
2001
2060
|
"No current_implementation_id found for app",
|
|
2002
2061
|
{ configType: "current_implementation_id" }
|
|
@@ -2005,7 +2064,7 @@ var listActionsPlugin = ({ sdk, context }) => {
|
|
|
2005
2064
|
const searchParams = {
|
|
2006
2065
|
global: "true",
|
|
2007
2066
|
public_only: "true",
|
|
2008
|
-
selected_apis:
|
|
2067
|
+
selected_apis: selectedApi
|
|
2009
2068
|
};
|
|
2010
2069
|
const data = await api.get(
|
|
2011
2070
|
"/api/v4/implementations/",
|
|
@@ -2055,6 +2114,7 @@ var listActionsPlugin = ({ sdk, context }) => {
|
|
|
2055
2114
|
context: {
|
|
2056
2115
|
meta: {
|
|
2057
2116
|
listActions: {
|
|
2117
|
+
categories: ["action"],
|
|
2058
2118
|
inputSchema: ListActionsSchema
|
|
2059
2119
|
}
|
|
2060
2120
|
}
|
|
@@ -2087,6 +2147,7 @@ var getActionPlugin = ({ sdk }) => {
|
|
|
2087
2147
|
context: {
|
|
2088
2148
|
meta: {
|
|
2089
2149
|
getAction: {
|
|
2150
|
+
categories: ["action"],
|
|
2090
2151
|
inputSchema: GetActionSchema
|
|
2091
2152
|
}
|
|
2092
2153
|
}
|
|
@@ -2109,15 +2170,14 @@ var RunActionSchema = zod.z.object({
|
|
|
2109
2170
|
async function executeAction(actionOptions) {
|
|
2110
2171
|
const {
|
|
2111
2172
|
api,
|
|
2112
|
-
|
|
2173
|
+
context,
|
|
2113
2174
|
appKey,
|
|
2114
2175
|
actionKey,
|
|
2115
2176
|
actionType,
|
|
2116
2177
|
executionOptions,
|
|
2117
2178
|
authenticationId
|
|
2118
2179
|
} = actionOptions;
|
|
2119
|
-
const
|
|
2120
|
-
const selectedApi = appData.data.current_implementation_id;
|
|
2180
|
+
const selectedApi = await context.getVersionedImplementationId(appKey);
|
|
2121
2181
|
if (!selectedApi) {
|
|
2122
2182
|
throw new ZapierConfigurationError(
|
|
2123
2183
|
"No current_implementation_id found for app",
|
|
@@ -2169,7 +2229,7 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
2169
2229
|
}
|
|
2170
2230
|
const result = await executeAction({
|
|
2171
2231
|
api,
|
|
2172
|
-
|
|
2232
|
+
context,
|
|
2173
2233
|
appKey,
|
|
2174
2234
|
actionKey,
|
|
2175
2235
|
actionType,
|
|
@@ -2195,6 +2255,7 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
2195
2255
|
context: {
|
|
2196
2256
|
meta: {
|
|
2197
2257
|
runAction: {
|
|
2258
|
+
categories: ["action"],
|
|
2198
2259
|
inputSchema: RunActionSchema
|
|
2199
2260
|
}
|
|
2200
2261
|
}
|
|
@@ -2214,19 +2275,18 @@ var ListAuthenticationsSchema = zod.z.object({
|
|
|
2214
2275
|
}).describe("List available authentications with optional filtering");
|
|
2215
2276
|
|
|
2216
2277
|
// src/plugins/listAuthentications/index.ts
|
|
2217
|
-
var listAuthenticationsPlugin = ({
|
|
2278
|
+
var listAuthenticationsPlugin = ({ context }) => {
|
|
2218
2279
|
const listAuthentications = createPaginatedFunction(
|
|
2219
2280
|
async function listAuthenticationsPage(options) {
|
|
2220
|
-
const { api } = context;
|
|
2281
|
+
const { api, getVersionedImplementationId } = context;
|
|
2221
2282
|
const searchParams = {};
|
|
2222
2283
|
if (options.appKey) {
|
|
2223
|
-
const
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
searchParams.versionless_selected_api = versionlessApi;
|
|
2284
|
+
const implementationId = await getVersionedImplementationId(
|
|
2285
|
+
options.appKey
|
|
2286
|
+
);
|
|
2287
|
+
if (implementationId) {
|
|
2288
|
+
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
2289
|
+
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
2230
2290
|
}
|
|
2231
2291
|
}
|
|
2232
2292
|
if (options.search) {
|
|
@@ -2244,6 +2304,7 @@ var listAuthenticationsPlugin = ({ sdk, context }) => {
|
|
|
2244
2304
|
if (options.cursor) {
|
|
2245
2305
|
searchParams.offset = options.cursor;
|
|
2246
2306
|
}
|
|
2307
|
+
console.log({ searchParams });
|
|
2247
2308
|
const data = await api.get(
|
|
2248
2309
|
"/api/v4/authentications/",
|
|
2249
2310
|
{
|
|
@@ -2284,6 +2345,7 @@ var listAuthenticationsPlugin = ({ sdk, context }) => {
|
|
|
2284
2345
|
context: {
|
|
2285
2346
|
meta: {
|
|
2286
2347
|
listAuthentications: {
|
|
2348
|
+
categories: ["authentication"],
|
|
2287
2349
|
inputSchema: ListAuthenticationsSchema
|
|
2288
2350
|
}
|
|
2289
2351
|
}
|
|
@@ -2338,6 +2400,7 @@ var getAuthenticationPlugin = ({ context }) => {
|
|
|
2338
2400
|
context: {
|
|
2339
2401
|
meta: {
|
|
2340
2402
|
getAuthentication: {
|
|
2403
|
+
categories: ["authentication"],
|
|
2341
2404
|
inputSchema: GetAuthenticationSchema
|
|
2342
2405
|
}
|
|
2343
2406
|
}
|
|
@@ -2373,6 +2436,7 @@ var findFirstAuthenticationPlugin = ({ sdk }) => {
|
|
|
2373
2436
|
context: {
|
|
2374
2437
|
meta: {
|
|
2375
2438
|
findFirstAuthentication: {
|
|
2439
|
+
categories: ["authentication"],
|
|
2376
2440
|
inputSchema: FindFirstAuthenticationSchema
|
|
2377
2441
|
}
|
|
2378
2442
|
}
|
|
@@ -2420,6 +2484,7 @@ var findUniqueAuthenticationPlugin = ({ sdk }) => {
|
|
|
2420
2484
|
context: {
|
|
2421
2485
|
meta: {
|
|
2422
2486
|
findUniqueAuthentication: {
|
|
2487
|
+
categories: ["authentication"],
|
|
2423
2488
|
inputSchema: FindUniqueAuthenticationSchema
|
|
2424
2489
|
}
|
|
2425
2490
|
}
|
|
@@ -2496,13 +2561,12 @@ function transformNeedToInputFieldItem(need) {
|
|
|
2496
2561
|
items: itemsType ? { type: itemsType } : void 0
|
|
2497
2562
|
};
|
|
2498
2563
|
}
|
|
2499
|
-
var listInputFieldsPlugin = ({
|
|
2564
|
+
var listInputFieldsPlugin = ({ context }) => {
|
|
2500
2565
|
const listInputFields = createPaginatedFunction(
|
|
2501
2566
|
async function listInputFieldsPage(options) {
|
|
2502
|
-
const { api } = context;
|
|
2567
|
+
const { api, getVersionedImplementationId } = context;
|
|
2503
2568
|
const { appKey, actionKey, actionType, authenticationId, inputs } = options;
|
|
2504
|
-
const
|
|
2505
|
-
const selectedApi = appData.data.current_implementation_id;
|
|
2569
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
2506
2570
|
if (!selectedApi) {
|
|
2507
2571
|
throw new ZapierConfigurationError(
|
|
2508
2572
|
"No current_implementation_id found for app",
|
|
@@ -2543,6 +2607,7 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
2543
2607
|
context: {
|
|
2544
2608
|
meta: {
|
|
2545
2609
|
listInputFields: {
|
|
2610
|
+
categories: ["action"],
|
|
2546
2611
|
inputSchema: ListInputFieldsSchema
|
|
2547
2612
|
}
|
|
2548
2613
|
}
|
|
@@ -2596,32 +2661,237 @@ var requestPlugin = ({ context }) => {
|
|
|
2596
2661
|
context: {
|
|
2597
2662
|
meta: {
|
|
2598
2663
|
request: {
|
|
2664
|
+
categories: ["http"],
|
|
2599
2665
|
inputSchema: RelayRequestSchema
|
|
2600
2666
|
}
|
|
2601
2667
|
}
|
|
2602
2668
|
}
|
|
2603
2669
|
};
|
|
2604
2670
|
};
|
|
2671
|
+
var ManifestSchema = zod.z.object({
|
|
2672
|
+
apps: zod.z.record(
|
|
2673
|
+
zod.z.string(),
|
|
2674
|
+
zod.z.object({
|
|
2675
|
+
implementationName: zod.z.string().describe(
|
|
2676
|
+
"Base implementation name without version (e.g., 'SlackCLIAPI')"
|
|
2677
|
+
),
|
|
2678
|
+
version: zod.z.string().describe("Version string (e.g., '1.21.1')")
|
|
2679
|
+
})
|
|
2680
|
+
)
|
|
2681
|
+
}).describe("Manifest mapping app keys to version information");
|
|
2682
|
+
zod.z.object({
|
|
2683
|
+
manifestPath: zod.z.string().optional().describe("Path to manifest file"),
|
|
2684
|
+
manifest: zod.z.record(
|
|
2685
|
+
zod.z.string(),
|
|
2686
|
+
zod.z.object({
|
|
2687
|
+
implementationName: zod.z.string(),
|
|
2688
|
+
version: zod.z.string().optional()
|
|
2689
|
+
})
|
|
2690
|
+
).optional().describe("Direct manifest object")
|
|
2691
|
+
});
|
|
2692
|
+
|
|
2693
|
+
// src/plugins/manifest/index.ts
|
|
2694
|
+
function parseManifestContent(content, source) {
|
|
2695
|
+
try {
|
|
2696
|
+
const parsed = JSON.parse(content);
|
|
2697
|
+
if (parsed?.apps && typeof parsed?.apps === "object") {
|
|
2698
|
+
const result = ManifestSchema.safeParse(parsed);
|
|
2699
|
+
if (result.success) {
|
|
2700
|
+
return result.data;
|
|
2701
|
+
}
|
|
2702
|
+
console.warn(`\u26A0\uFE0F Invalid manifest format in ${source}: ${result.error}`);
|
|
2703
|
+
}
|
|
2704
|
+
return null;
|
|
2705
|
+
} catch (error) {
|
|
2706
|
+
console.warn(`\u26A0\uFE0F Failed to parse manifest from ${source}:`, error);
|
|
2707
|
+
return null;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
function loadManifestFromFile(filePath) {
|
|
2711
|
+
try {
|
|
2712
|
+
const resolvedPath = path.resolve(filePath);
|
|
2713
|
+
const content = fs.readFileSync(resolvedPath, "utf8");
|
|
2714
|
+
return parseManifestContent(content, resolvedPath);
|
|
2715
|
+
} catch {
|
|
2716
|
+
console.warn(`\u26A0\uFE0F Failed to load manifest from ${filePath}`);
|
|
2717
|
+
return null;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
var emitWarning = (appKey) => {
|
|
2721
|
+
console.warn(
|
|
2722
|
+
`
|
|
2723
|
+
${"\u26A0\uFE0F".padEnd(3)} ${"WARNING".padEnd(8)} No manifest version found for '${appKey}'`
|
|
2724
|
+
);
|
|
2725
|
+
console.warn(
|
|
2726
|
+
` ${"\u21B3".padEnd(3)} Using a manifest ensures version locking and prevents unexpected behavior due to version changes.`
|
|
2727
|
+
);
|
|
2728
|
+
console.warn(
|
|
2729
|
+
` ${"\u21B3".padEnd(3)} Generate/update the manifest with: \`zapier-sdk update-manifest ${appKey}\`
|
|
2730
|
+
`
|
|
2731
|
+
);
|
|
2732
|
+
};
|
|
2733
|
+
var manifestPlugin = (params) => {
|
|
2734
|
+
const { sdk, context } = params;
|
|
2735
|
+
const { api, options } = context;
|
|
2736
|
+
const { manifestPath = ".zapierrc", manifest } = options || {};
|
|
2737
|
+
const resolvedManifest = (() => {
|
|
2738
|
+
if (manifest) {
|
|
2739
|
+
return manifest;
|
|
2740
|
+
}
|
|
2741
|
+
if (manifestPath) {
|
|
2742
|
+
return loadManifestFromFile(manifestPath);
|
|
2743
|
+
}
|
|
2744
|
+
return null;
|
|
2745
|
+
})();
|
|
2746
|
+
const getManifestEntry = (appKey) => {
|
|
2747
|
+
return resolvedManifest?.apps?.[appKey] || null;
|
|
2748
|
+
};
|
|
2749
|
+
const getImplementation = async (appKey) => {
|
|
2750
|
+
let selectedApi = null;
|
|
2751
|
+
const manifestImplementation = resolvedManifest?.apps?.[appKey];
|
|
2752
|
+
const [versionlessAppKey, version] = splitVersionedKey(appKey);
|
|
2753
|
+
if (version) {
|
|
2754
|
+
selectedApi = `${versionlessAppKey}@${version}`;
|
|
2755
|
+
} else if (manifestImplementation) {
|
|
2756
|
+
selectedApi = `${manifestImplementation.implementationName}@${manifestImplementation.version || "latest"}`;
|
|
2757
|
+
}
|
|
2758
|
+
if (selectedApi) {
|
|
2759
|
+
const searchParams = {
|
|
2760
|
+
selected_apis: selectedApi
|
|
2761
|
+
};
|
|
2762
|
+
const implementationData = await api.get(
|
|
2763
|
+
"/api/v4/implementations/",
|
|
2764
|
+
{
|
|
2765
|
+
searchParams
|
|
2766
|
+
}
|
|
2767
|
+
);
|
|
2768
|
+
const implementationResults = implementationData.results[0];
|
|
2769
|
+
if (!implementationResults) return null;
|
|
2770
|
+
return normalizeImplementationToAppItem(implementationResults);
|
|
2771
|
+
}
|
|
2772
|
+
emitWarning(appKey);
|
|
2773
|
+
const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
|
|
2774
|
+
const apps = [];
|
|
2775
|
+
for await (const app2 of appsIterator) {
|
|
2776
|
+
apps.push(app2);
|
|
2777
|
+
break;
|
|
2778
|
+
}
|
|
2779
|
+
if (apps.length === 0) {
|
|
2780
|
+
return null;
|
|
2781
|
+
}
|
|
2782
|
+
const app = apps[0];
|
|
2783
|
+
return app;
|
|
2784
|
+
};
|
|
2785
|
+
const getVersionedImplementationId = async (appKey) => {
|
|
2786
|
+
const manifestEntry = getManifestEntry(appKey);
|
|
2787
|
+
if (manifestEntry) {
|
|
2788
|
+
return `${manifestEntry.implementationName}@${manifestEntry.version || "latest"}`;
|
|
2789
|
+
}
|
|
2790
|
+
const implementation = await getImplementation(appKey);
|
|
2791
|
+
if (!implementation) return null;
|
|
2792
|
+
return implementation.current_implementation_id;
|
|
2793
|
+
};
|
|
2794
|
+
return {
|
|
2795
|
+
context: {
|
|
2796
|
+
manifest: resolvedManifest,
|
|
2797
|
+
getVersionedImplementationId,
|
|
2798
|
+
getManifestEntry,
|
|
2799
|
+
getImplementation
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
};
|
|
2803
|
+
var LockVersionSchema = zod.z.object({
|
|
2804
|
+
appKey: zod.z.string().describe("The app key to lock version for (e.g., 'slack', 'gmail')")
|
|
2805
|
+
});
|
|
2806
|
+
var lockVersionPlugin = ({ sdk }) => {
|
|
2807
|
+
const lockVersion = createFunction(
|
|
2808
|
+
async function lockVersion2(options) {
|
|
2809
|
+
const { appKey, configPath = ".zapierrc" } = options;
|
|
2810
|
+
const resolvedPath = path.resolve(configPath);
|
|
2811
|
+
const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
|
|
2812
|
+
const apps = [];
|
|
2813
|
+
for await (const app2 of appsIterator) {
|
|
2814
|
+
apps.push(app2);
|
|
2815
|
+
break;
|
|
2816
|
+
}
|
|
2817
|
+
const app = apps[0];
|
|
2818
|
+
const currentImplementationId = app.current_implementation_id;
|
|
2819
|
+
const [implementationName, version] = currentImplementationId.split("@");
|
|
2820
|
+
if (!implementationName || !version) {
|
|
2821
|
+
throw new Error(
|
|
2822
|
+
`Invalid implementation ID format: ${currentImplementationId}. Expected format: <implementationName>@<version>`
|
|
2823
|
+
);
|
|
2824
|
+
}
|
|
2825
|
+
let config = { apps: {} };
|
|
2826
|
+
if (fs.existsSync(resolvedPath)) {
|
|
2827
|
+
try {
|
|
2828
|
+
const configContent = fs.readFileSync(resolvedPath, "utf8");
|
|
2829
|
+
config = JSON.parse(configContent);
|
|
2830
|
+
if (!config.apps) {
|
|
2831
|
+
config.apps = {};
|
|
2832
|
+
}
|
|
2833
|
+
} catch (error) {
|
|
2834
|
+
console.warn(
|
|
2835
|
+
`\u26A0\uFE0F Failed to parse existing config file, creating new one: ${error}`
|
|
2836
|
+
);
|
|
2837
|
+
config = { apps: {} };
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
config.apps[appKey] = {
|
|
2841
|
+
implementationName,
|
|
2842
|
+
version
|
|
2843
|
+
};
|
|
2844
|
+
fs.writeFileSync(resolvedPath, JSON.stringify(config, null, 2));
|
|
2845
|
+
return {
|
|
2846
|
+
data: {
|
|
2847
|
+
...app,
|
|
2848
|
+
implementationName,
|
|
2849
|
+
version
|
|
2850
|
+
},
|
|
2851
|
+
configPath: resolvedPath
|
|
2852
|
+
};
|
|
2853
|
+
},
|
|
2854
|
+
LockVersionSchema.extend({
|
|
2855
|
+
configPath: zod.z.string().optional().describe("Path to .zapierrc file (defaults to '.zapierrc')")
|
|
2856
|
+
})
|
|
2857
|
+
);
|
|
2858
|
+
return {
|
|
2859
|
+
lockVersion,
|
|
2860
|
+
context: {
|
|
2861
|
+
meta: {
|
|
2862
|
+
lockVersion: {
|
|
2863
|
+
categories: ["utility"],
|
|
2864
|
+
inputSchema: LockVersionSchema
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
};
|
|
2605
2870
|
|
|
2606
2871
|
// src/sdk.ts
|
|
2607
|
-
function createSdk(initialSdk = {}, initialContext = { meta: {} }) {
|
|
2872
|
+
function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} }) {
|
|
2608
2873
|
return {
|
|
2609
2874
|
...initialSdk,
|
|
2610
2875
|
getContext: () => initialContext,
|
|
2611
|
-
addPlugin(plugin,
|
|
2876
|
+
addPlugin(plugin, addPluginOptions = {}) {
|
|
2612
2877
|
const currentSdkWithContext = {
|
|
2613
2878
|
...initialSdk,
|
|
2614
2879
|
getContext: () => initialContext
|
|
2615
2880
|
};
|
|
2616
2881
|
const pluginResult = plugin({
|
|
2617
2882
|
sdk: currentSdkWithContext,
|
|
2618
|
-
context:
|
|
2619
|
-
|
|
2883
|
+
context: {
|
|
2884
|
+
...initialContext,
|
|
2885
|
+
// Add the options that createSdk was called with to context
|
|
2886
|
+
options
|
|
2887
|
+
},
|
|
2888
|
+
...addPluginOptions
|
|
2620
2889
|
});
|
|
2621
2890
|
const { context: pluginContext, ...sdkProperties } = pluginResult;
|
|
2622
2891
|
const newSdk = { ...initialSdk, ...sdkProperties };
|
|
2623
2892
|
let newContext = {
|
|
2624
2893
|
...initialContext,
|
|
2894
|
+
...addPluginOptions,
|
|
2625
2895
|
meta: initialContext.meta || {}
|
|
2626
2896
|
};
|
|
2627
2897
|
if (pluginContext) {
|
|
@@ -2642,12 +2912,12 @@ function createSdk(initialSdk = {}, initialContext = { meta: {} }) {
|
|
|
2642
2912
|
};
|
|
2643
2913
|
}
|
|
2644
2914
|
}
|
|
2645
|
-
return createSdk(newSdk, newContext);
|
|
2915
|
+
return createSdk(options, newSdk, newContext);
|
|
2646
2916
|
}
|
|
2647
2917
|
};
|
|
2648
2918
|
}
|
|
2649
2919
|
function createZapierSdk(options = {}) {
|
|
2650
|
-
return createSdk().addPlugin(apiPlugin
|
|
2920
|
+
return createSdk(options).addPlugin(apiPlugin).addPlugin(listAppsPlugin).addPlugin(manifestPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(runActionPlugin).addPlugin(lockVersionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin).addPlugin(registryPlugin);
|
|
2651
2921
|
}
|
|
2652
2922
|
|
|
2653
2923
|
exports.ActionKeyPropertySchema = ActionKeyPropertySchema;
|