@zapier/zapier-sdk 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +10 -33
- package/dist/index.cjs +346 -219
- package/dist/index.d.mts +181 -185
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.mjs +343 -218
- package/dist/plugins/apps/index.d.ts +4 -0
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.d.ts +2 -7
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +9 -9
- package/dist/plugins/getApp/index.test.js +1 -1
- package/dist/plugins/getAuthentication/index.test.js +1 -1
- package/dist/plugins/listActions/index.d.ts +2 -4
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +1 -1
- package/dist/plugins/listActions/index.test.js +4 -4
- package/dist/plugins/listApps/index.d.ts +4 -7
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +33 -17
- package/dist/plugins/listApps/index.test.js +22 -2
- package/dist/plugins/listAuthentications/index.d.ts +2 -4
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +4 -0
- package/dist/plugins/listAuthentications/index.test.js +39 -13
- package/dist/plugins/listAuthentications/schemas.d.ts +3 -0
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/schemas.js +4 -0
- package/dist/plugins/manifest/index.d.ts +25 -9
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +239 -67
- package/dist/plugins/manifest/index.test.js +426 -171
- package/dist/plugins/manifest/schemas.d.ts +5 -1
- package/dist/plugins/manifest/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/schemas.js +1 -0
- package/dist/sdk.d.ts +5 -11
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -4
- package/dist/types/plugin.d.ts +1 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +6 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/domain-utils.d.ts +16 -0
- package/dist/utils/domain-utils.d.ts.map +1 -1
- package/dist/utils/domain-utils.js +46 -27
- package/dist/utils/domain-utils.test.js +157 -3
- package/dist/utils/file-utils.d.ts +4 -0
- package/dist/utils/file-utils.d.ts.map +1 -0
- package/dist/utils/file-utils.js +74 -0
- package/dist/utils/file-utils.test.d.ts +2 -0
- package/dist/utils/file-utils.test.d.ts.map +1 -0
- package/dist/utils/file-utils.test.js +51 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/plugins/apps/index.ts +9 -2
- package/src/plugins/getApp/index.test.ts +1 -1
- package/src/plugins/getApp/index.ts +12 -14
- package/src/plugins/getAuthentication/index.test.ts +1 -1
- package/src/plugins/listActions/index.test.ts +8 -7
- package/src/plugins/listActions/index.ts +3 -3
- package/src/plugins/listApps/index.test.ts +23 -2
- package/src/plugins/listApps/index.ts +46 -25
- package/src/plugins/listAuthentications/index.test.ts +52 -15
- package/src/plugins/listAuthentications/index.ts +7 -2
- package/src/plugins/listAuthentications/schemas.ts +4 -0
- package/src/plugins/manifest/index.test.ts +503 -197
- package/src/plugins/manifest/index.ts +338 -82
- package/src/plugins/manifest/schemas.ts +9 -2
- package/src/sdk.ts +1 -5
- package/src/types/plugin.ts +3 -0
- package/src/types/sdk.ts +26 -21
- package/src/utils/domain-utils.test.ts +196 -2
- package/src/utils/domain-utils.ts +68 -35
- package/src/utils/file-utils.test.ts +73 -0
- package/src/utils/file-utils.ts +94 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/plugins/lockVersion/index.d.ts +0 -24
- package/dist/plugins/lockVersion/index.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.js +0 -72
- package/dist/plugins/lockVersion/index.test.d.ts +0 -2
- package/dist/plugins/lockVersion/index.test.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.test.js +0 -129
- package/dist/plugins/lockVersion/schemas.d.ts +0 -10
- package/dist/plugins/lockVersion/schemas.d.ts.map +0 -1
- package/dist/plugins/lockVersion/schemas.js +0 -6
- package/src/plugins/lockVersion/index.test.ts +0 -176
- package/src/plugins/lockVersion/index.ts +0 -112
- package/src/plugins/lockVersion/schemas.ts +0 -9
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { readFileSync, existsSync, writeFileSync } from 'fs';
|
|
3
|
-
import { resolve } from 'path';
|
|
4
2
|
import { setTimeout } from 'timers/promises';
|
|
5
3
|
|
|
6
4
|
// src/types/properties.ts
|
|
@@ -652,16 +650,6 @@ function splitVersionedKey(versionedKey) {
|
|
|
652
650
|
}
|
|
653
651
|
return [versionedKey, void 0];
|
|
654
652
|
}
|
|
655
|
-
function normalizeImplementationToAppItem(implementation) {
|
|
656
|
-
const [selectedApi, appVersion] = implementation.selected_api ? splitVersionedKey(implementation.selected_api) : [implementation.selected_api || "", void 0];
|
|
657
|
-
return {
|
|
658
|
-
title: implementation.name || selectedApi,
|
|
659
|
-
key: selectedApi,
|
|
660
|
-
current_implementation_id: implementation.selected_api || "",
|
|
661
|
-
version: appVersion
|
|
662
|
-
// Extract version separately
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
653
|
function normalizeImplementationMetaToAppItem(implementationMeta) {
|
|
666
654
|
const [selectedApi, appVersion] = splitVersionedKey(implementationMeta.id);
|
|
667
655
|
return {
|
|
@@ -723,50 +711,8 @@ function normalizeActionItem(action) {
|
|
|
723
711
|
type: "action"
|
|
724
712
|
};
|
|
725
713
|
}
|
|
726
|
-
function
|
|
727
|
-
|
|
728
|
-
selectedApi: [],
|
|
729
|
-
slug: []
|
|
730
|
-
};
|
|
731
|
-
const seenSelectedApi = /* @__PURE__ */ new Set();
|
|
732
|
-
const seenSlugs = /* @__PURE__ */ new Set();
|
|
733
|
-
for (const key of appKeys) {
|
|
734
|
-
const [keyWithoutVersion, version] = splitVersionedKey(key);
|
|
735
|
-
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
736
|
-
if (uuidRegex.test(keyWithoutVersion)) {
|
|
737
|
-
throw new Error(
|
|
738
|
-
`UUID app keys are not supported. Use app slug or implementation ID instead of: ${key}`
|
|
739
|
-
);
|
|
740
|
-
}
|
|
741
|
-
if (isSnakeCasedSlug(keyWithoutVersion)) {
|
|
742
|
-
const dashified = dashifySnakeCasedSlug(keyWithoutVersion);
|
|
743
|
-
const slugWithVersion = version ? `${dashified}@${version}` : dashified;
|
|
744
|
-
if (!seenSlugs.has(slugWithVersion)) {
|
|
745
|
-
seenSlugs.add(slugWithVersion);
|
|
746
|
-
result.slug.push(slugWithVersion);
|
|
747
|
-
}
|
|
748
|
-
continue;
|
|
749
|
-
}
|
|
750
|
-
if (keyWithoutVersion.match(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)) {
|
|
751
|
-
seenSlugs.add(key);
|
|
752
|
-
result.slug.push(key);
|
|
753
|
-
continue;
|
|
754
|
-
}
|
|
755
|
-
if (!seenSelectedApi.has(key)) {
|
|
756
|
-
seenSelectedApi.add(key);
|
|
757
|
-
result.selectedApi.push(key);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
return result;
|
|
761
|
-
}
|
|
762
|
-
function groupAppKeysByType(appKeys) {
|
|
763
|
-
const grouped = groupVersionedAppKeysByType(appKeys);
|
|
764
|
-
return {
|
|
765
|
-
selectedApi: [
|
|
766
|
-
...new Set(grouped.selectedApi.map((key) => key.split("@")[0]))
|
|
767
|
-
],
|
|
768
|
-
slug: [...new Set(grouped.slug.map((key) => key.split("@")[0]))]
|
|
769
|
-
};
|
|
714
|
+
function isSlug(slug) {
|
|
715
|
+
return !!slug.match(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
770
716
|
}
|
|
771
717
|
function isSnakeCasedSlug(slug) {
|
|
772
718
|
if (slug.match(/^_[0-9]/)) {
|
|
@@ -783,15 +729,54 @@ function dashifySnakeCasedSlug(slug) {
|
|
|
783
729
|
}
|
|
784
730
|
return slug.replace(/_/g, "-");
|
|
785
731
|
}
|
|
732
|
+
function isUuid(appKey) {
|
|
733
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
734
|
+
appKey
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
function toAppLocator(appKey) {
|
|
738
|
+
const [appKeyWithoutVersion, version] = splitVersionedKey(appKey);
|
|
739
|
+
if (isUuid(appKeyWithoutVersion)) {
|
|
740
|
+
throw new Error(
|
|
741
|
+
`UUID app keys are not supported. Use app slug or implementation ID instead of: ${appKey}`
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
const slug = isSlug(appKeyWithoutVersion) ? appKeyWithoutVersion : isSnakeCasedSlug(appKeyWithoutVersion) ? dashifySnakeCasedSlug(appKeyWithoutVersion) : void 0;
|
|
745
|
+
return {
|
|
746
|
+
lookupAppKey: appKeyWithoutVersion,
|
|
747
|
+
slug,
|
|
748
|
+
implementationName: slug ? void 0 : appKeyWithoutVersion,
|
|
749
|
+
version
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
function isResolvedAppLocator(appLocator) {
|
|
753
|
+
return !!appLocator.implementationName;
|
|
754
|
+
}
|
|
755
|
+
function toImplementationId(appLocator) {
|
|
756
|
+
return `${appLocator.implementationName}@${appLocator.version || "latest"}`;
|
|
757
|
+
}
|
|
786
758
|
|
|
787
759
|
// src/plugins/listApps/index.ts
|
|
788
760
|
var listAppsPlugin = ({ context }) => {
|
|
789
761
|
const listApps = createPaginatedFunction(async function listAppsPage(options) {
|
|
790
762
|
const api = context.api;
|
|
791
763
|
const opts = options;
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
);
|
|
764
|
+
const appLocators = await context.resolveAppKeys({
|
|
765
|
+
appKeys: [...opts.appKeys ?? []]
|
|
766
|
+
});
|
|
767
|
+
const implementationNameToLocator = {};
|
|
768
|
+
for (const locator of appLocators) {
|
|
769
|
+
implementationNameToLocator[locator.implementationName] = [
|
|
770
|
+
...implementationNameToLocator[locator.implementationName] ?? [],
|
|
771
|
+
locator
|
|
772
|
+
];
|
|
773
|
+
}
|
|
774
|
+
const duplicatedLookupAppKeys = Object.keys(implementationNameToLocator).filter((key) => implementationNameToLocator[key].length > 1).map((key) => implementationNameToLocator[key]).flat().map((locator) => locator.lookupAppKey);
|
|
775
|
+
if (duplicatedLookupAppKeys.length > 0) {
|
|
776
|
+
throw new Error(
|
|
777
|
+
`Duplicate lookup app keys found: ${duplicatedLookupAppKeys.join(", ")}`
|
|
778
|
+
);
|
|
779
|
+
}
|
|
795
780
|
if (opts.search) {
|
|
796
781
|
const searchParams2 = {};
|
|
797
782
|
searchParams2.term = opts.search;
|
|
@@ -804,11 +789,17 @@ var listAppsPlugin = ({ context }) => {
|
|
|
804
789
|
const implementations = searchEnvelope.results.map(
|
|
805
790
|
normalizeImplementationMetaToAppItem
|
|
806
791
|
);
|
|
807
|
-
const
|
|
792
|
+
const implementationNameSet = new Set(
|
|
793
|
+
appLocators.map((locator) => locator.implementationName)
|
|
794
|
+
);
|
|
808
795
|
for (const implementation of implementations) {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
796
|
+
const [implementationName] = splitVersionedKey(implementation.key);
|
|
797
|
+
if (!implementationNameSet.has(implementationName)) {
|
|
798
|
+
implementationNameSet.add(implementationName);
|
|
799
|
+
appLocators.push({
|
|
800
|
+
...toAppLocator(implementation.key),
|
|
801
|
+
implementationName
|
|
802
|
+
});
|
|
812
803
|
}
|
|
813
804
|
}
|
|
814
805
|
}
|
|
@@ -816,19 +807,13 @@ var listAppsPlugin = ({ context }) => {
|
|
|
816
807
|
if (opts.pageSize) {
|
|
817
808
|
searchParams.limit = opts.pageSize.toString();
|
|
818
809
|
}
|
|
819
|
-
|
|
810
|
+
if (appLocators.length === 0) {
|
|
811
|
+
searchParams.latest_only = "true";
|
|
812
|
+
}
|
|
820
813
|
if (opts.cursor) {
|
|
821
814
|
searchParams.offset = opts.cursor;
|
|
822
815
|
}
|
|
823
|
-
|
|
824
|
-
const groupedAppKeys = groupAppKeysByType(appKeys);
|
|
825
|
-
if (groupedAppKeys.selectedApi.length > 0) {
|
|
826
|
-
searchParams.selected_apis = groupedAppKeys.selectedApi.join(",");
|
|
827
|
-
}
|
|
828
|
-
if (groupedAppKeys.slug.length > 0) {
|
|
829
|
-
searchParams.slugs = groupedAppKeys.slug.join(",");
|
|
830
|
-
}
|
|
831
|
-
}
|
|
816
|
+
searchParams.selected_apis = appLocators.map((locator) => toImplementationId(locator)).join(",");
|
|
832
817
|
const implementationsEnvelope = await api.get(
|
|
833
818
|
"/api/v4/implementations-meta/lookup/",
|
|
834
819
|
{
|
|
@@ -1475,6 +1460,7 @@ var ListAuthenticationsSchema = z.object({
|
|
|
1475
1460
|
appKey: AppKeyPropertySchema.optional().describe(
|
|
1476
1461
|
"App key of authentications to list (e.g., 'SlackCLIAPI')"
|
|
1477
1462
|
),
|
|
1463
|
+
authenticationIds: z.array(z.string()).optional().describe("List of authentication IDs to filter by"),
|
|
1478
1464
|
search: z.string().optional().describe("Search term to filter authentications by title"),
|
|
1479
1465
|
title: z.string().optional().describe("Filter authentications by exact title match"),
|
|
1480
1466
|
accountId: z.string().optional().describe("Filter by account ID"),
|
|
@@ -1498,6 +1484,9 @@ var listAuthenticationsPlugin = ({ context }) => {
|
|
|
1498
1484
|
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
1499
1485
|
}
|
|
1500
1486
|
}
|
|
1487
|
+
if (options.authenticationIds && options.authenticationIds.length > 0) {
|
|
1488
|
+
searchParams.ids = options.authenticationIds.join(",");
|
|
1489
|
+
}
|
|
1501
1490
|
if (options.search) {
|
|
1502
1491
|
searchParams.search = options.search;
|
|
1503
1492
|
} else if (options.title) {
|
|
@@ -1570,17 +1559,17 @@ var GetAppSchema = withOutputSchema(
|
|
|
1570
1559
|
);
|
|
1571
1560
|
|
|
1572
1561
|
// src/plugins/getApp/index.ts
|
|
1573
|
-
var getAppPlugin = ({
|
|
1562
|
+
var getAppPlugin = ({ sdk }) => {
|
|
1574
1563
|
const getApp = createFunction(async function getApp2(options) {
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
}
|
|
1564
|
+
const appsIterator = sdk.listApps({ appKeys: [options.appKey] }).items();
|
|
1565
|
+
for await (const app of appsIterator) {
|
|
1566
|
+
return {
|
|
1567
|
+
data: app
|
|
1568
|
+
};
|
|
1580
1569
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
};
|
|
1570
|
+
throw new ZapierAppNotFoundError("App not found", {
|
|
1571
|
+
appKey: options.appKey
|
|
1572
|
+
});
|
|
1584
1573
|
}, GetAppSchema);
|
|
1585
1574
|
return {
|
|
1586
1575
|
getApp,
|
|
@@ -1946,6 +1935,67 @@ var requestPlugin = ({ context }) => {
|
|
|
1946
1935
|
}
|
|
1947
1936
|
};
|
|
1948
1937
|
};
|
|
1938
|
+
|
|
1939
|
+
// src/utils/file-utils.ts
|
|
1940
|
+
var inMemoryFiles = {};
|
|
1941
|
+
var fsPromises = null;
|
|
1942
|
+
var pathModule = null;
|
|
1943
|
+
async function loadFsPromises() {
|
|
1944
|
+
if (fsPromises) return fsPromises;
|
|
1945
|
+
try {
|
|
1946
|
+
fsPromises = await import('fs/promises');
|
|
1947
|
+
return fsPromises;
|
|
1948
|
+
} catch {
|
|
1949
|
+
return null;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
async function loadPathModule() {
|
|
1953
|
+
if (pathModule) return pathModule;
|
|
1954
|
+
try {
|
|
1955
|
+
pathModule = await import('path');
|
|
1956
|
+
return pathModule;
|
|
1957
|
+
} catch {
|
|
1958
|
+
return null;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
async function resolve(path, basePath = "/") {
|
|
1962
|
+
const pathModule2 = await loadPathModule();
|
|
1963
|
+
if (pathModule2) {
|
|
1964
|
+
return pathModule2.resolve(path);
|
|
1965
|
+
}
|
|
1966
|
+
if (path.startsWith("/")) {
|
|
1967
|
+
return path;
|
|
1968
|
+
}
|
|
1969
|
+
if (path.startsWith("./")) {
|
|
1970
|
+
const cleanPath = path.slice(2);
|
|
1971
|
+
return basePath.endsWith("/") ? basePath + cleanPath : basePath + "/" + cleanPath;
|
|
1972
|
+
}
|
|
1973
|
+
if (path.startsWith("../")) {
|
|
1974
|
+
const cleanPath = path.replace(/^(\.\.\/)+/, "");
|
|
1975
|
+
return basePath.endsWith("/") ? basePath + cleanPath : basePath + "/" + cleanPath;
|
|
1976
|
+
}
|
|
1977
|
+
return basePath.endsWith("/") ? basePath + path : basePath + "/" + path;
|
|
1978
|
+
}
|
|
1979
|
+
async function writeFile(filePath, content) {
|
|
1980
|
+
const fs = await loadFsPromises();
|
|
1981
|
+
if (fs) {
|
|
1982
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
inMemoryFiles[filePath] = content;
|
|
1986
|
+
}
|
|
1987
|
+
async function readFile(filePath) {
|
|
1988
|
+
const fs = await loadFsPromises();
|
|
1989
|
+
if (fs) {
|
|
1990
|
+
return await fs.readFile(filePath, "utf8");
|
|
1991
|
+
}
|
|
1992
|
+
const content = inMemoryFiles[filePath];
|
|
1993
|
+
if (content !== void 0) {
|
|
1994
|
+
return content;
|
|
1995
|
+
}
|
|
1996
|
+
throw new Error(`File not found: ${filePath}`);
|
|
1997
|
+
}
|
|
1998
|
+
var DEFAULT_CONFIG_PATH = ".zapierrc";
|
|
1949
1999
|
var ManifestSchema = z.object({
|
|
1950
2000
|
apps: z.record(
|
|
1951
2001
|
z.string(),
|
|
@@ -1968,6 +2018,15 @@ z.object({
|
|
|
1968
2018
|
).optional().describe("Direct manifest object")
|
|
1969
2019
|
});
|
|
1970
2020
|
|
|
2021
|
+
// src/utils/array-utils.ts
|
|
2022
|
+
async function toArrayFromAsync(asyncIterable) {
|
|
2023
|
+
const result = [];
|
|
2024
|
+
for await (const item of asyncIterable) {
|
|
2025
|
+
result.push(item);
|
|
2026
|
+
}
|
|
2027
|
+
return result;
|
|
2028
|
+
}
|
|
2029
|
+
|
|
1971
2030
|
// src/plugins/manifest/index.ts
|
|
1972
2031
|
function parseManifestContent(content, source) {
|
|
1973
2032
|
try {
|
|
@@ -1985,169 +2044,235 @@ function parseManifestContent(content, source) {
|
|
|
1985
2044
|
return null;
|
|
1986
2045
|
}
|
|
1987
2046
|
}
|
|
1988
|
-
function
|
|
2047
|
+
async function readManifestFromFile(filePath) {
|
|
1989
2048
|
try {
|
|
1990
|
-
const resolvedPath = resolve(filePath);
|
|
1991
|
-
const content =
|
|
2049
|
+
const resolvedPath = await resolve(filePath);
|
|
2050
|
+
const content = await readFile(resolvedPath);
|
|
1992
2051
|
return parseManifestContent(content, resolvedPath);
|
|
1993
2052
|
} catch {
|
|
1994
|
-
console.warn(`\u26A0\uFE0F Failed to
|
|
2053
|
+
console.warn(`\u26A0\uFE0F Failed to read manifest from ${filePath}`);
|
|
1995
2054
|
return null;
|
|
1996
2055
|
}
|
|
1997
2056
|
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2057
|
+
async function writeManifestToFile(manifest, filePath) {
|
|
2058
|
+
const resolvedPath = await resolve(filePath);
|
|
2059
|
+
await writeFile(resolvedPath, JSON.stringify(manifest, null, 2));
|
|
2060
|
+
}
|
|
2061
|
+
async function getPreferredManifestEntryKey({
|
|
2062
|
+
appKey,
|
|
2063
|
+
api
|
|
2064
|
+
}) {
|
|
2065
|
+
const locator = toAppLocator(appKey);
|
|
2066
|
+
if (locator.slug) {
|
|
2067
|
+
return locator.slug;
|
|
2068
|
+
}
|
|
2069
|
+
if (locator.implementationName) {
|
|
2070
|
+
try {
|
|
2071
|
+
const implementationsEnvelope = await api.get(`/api/v4/implementations-meta/lookup/`, {
|
|
2072
|
+
searchParams: {
|
|
2073
|
+
selected_apis: locator.implementationName
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
if (implementationsEnvelope.results.length > 0 && implementationsEnvelope.results[0].slug) {
|
|
2077
|
+
return implementationsEnvelope.results[0].slug;
|
|
2078
|
+
}
|
|
2079
|
+
} catch {
|
|
2080
|
+
}
|
|
2081
|
+
return locator.implementationName;
|
|
2082
|
+
}
|
|
2083
|
+
return locator.lookupAppKey;
|
|
2084
|
+
}
|
|
2085
|
+
async function listAppsForSlugsPage({
|
|
2086
|
+
slugs,
|
|
2087
|
+
cursor,
|
|
2088
|
+
api
|
|
2089
|
+
}) {
|
|
2090
|
+
const searchParams = {};
|
|
2091
|
+
if (slugs.length > 0) {
|
|
2092
|
+
searchParams.slugs = slugs.join(",");
|
|
2093
|
+
}
|
|
2094
|
+
if (cursor) {
|
|
2095
|
+
searchParams.offset = cursor;
|
|
2096
|
+
}
|
|
2097
|
+
const implementationsEnvelope = await api.get(
|
|
2098
|
+
"/api/v4/implementations-meta/lookup/",
|
|
2099
|
+
{
|
|
2100
|
+
searchParams
|
|
2101
|
+
}
|
|
2005
2102
|
);
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2103
|
+
return {
|
|
2104
|
+
data: implementationsEnvelope.results.map(
|
|
2105
|
+
normalizeImplementationMetaToAppItem
|
|
2106
|
+
),
|
|
2107
|
+
nextCursor: extractCursor(implementationsEnvelope)
|
|
2108
|
+
};
|
|
2109
|
+
}
|
|
2110
|
+
function findManifestEntry({
|
|
2111
|
+
appKey,
|
|
2112
|
+
manifest
|
|
2113
|
+
}) {
|
|
2114
|
+
const [appKeyWithoutVersion] = splitVersionedKey(appKey);
|
|
2115
|
+
if (manifest.apps[appKeyWithoutVersion]) {
|
|
2116
|
+
return [appKeyWithoutVersion, manifest.apps[appKeyWithoutVersion]];
|
|
2117
|
+
}
|
|
2118
|
+
if (isSnakeCasedSlug(appKey)) {
|
|
2119
|
+
const slug = dashifySnakeCasedSlug(appKey);
|
|
2120
|
+
if (manifest.apps[slug]) {
|
|
2121
|
+
return [slug, manifest.apps[slug]];
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
for (const [key, entry] of Object.entries(manifest.apps)) {
|
|
2125
|
+
if (entry.implementationName === appKeyWithoutVersion) {
|
|
2126
|
+
return [key, entry];
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
return null;
|
|
2130
|
+
}
|
|
2131
|
+
async function resolveAppKeys({
|
|
2132
|
+
appKeys,
|
|
2133
|
+
api,
|
|
2134
|
+
manifest
|
|
2135
|
+
}) {
|
|
2136
|
+
const locators = appKeys.map(toAppLocator);
|
|
2137
|
+
const locatorsWithManifest = locators.map((locator) => {
|
|
2138
|
+
const manifestEntryResult = findManifestEntry({
|
|
2139
|
+
appKey: locator.lookupAppKey,
|
|
2140
|
+
manifest
|
|
2141
|
+
});
|
|
2142
|
+
if (manifestEntryResult) {
|
|
2143
|
+
const [, manifestEntry] = manifestEntryResult;
|
|
2144
|
+
const resolvedVersion = locator.version || manifestEntry.version;
|
|
2145
|
+
const resolvedLocator = {
|
|
2146
|
+
...locator,
|
|
2147
|
+
implementationName: manifestEntry.implementationName,
|
|
2148
|
+
version: resolvedVersion
|
|
2149
|
+
};
|
|
2150
|
+
return resolvedLocator;
|
|
2151
|
+
}
|
|
2152
|
+
return locator;
|
|
2153
|
+
});
|
|
2154
|
+
const unresolvedLocators = locatorsWithManifest.filter(
|
|
2155
|
+
(locator) => !isResolvedAppLocator(locator)
|
|
2009
2156
|
);
|
|
2010
|
-
|
|
2157
|
+
const slugsToResolve = unresolvedLocators.map((locator) => locator.slug).filter((slug) => !!slug).filter((slug, index, array) => array.indexOf(slug) === index);
|
|
2158
|
+
if (slugsToResolve.length === 0) {
|
|
2159
|
+
return locatorsWithManifest.filter(isResolvedAppLocator);
|
|
2160
|
+
}
|
|
2161
|
+
const iterator = paginate(listAppsForSlugsPage, {
|
|
2162
|
+
slugs: slugsToResolve,
|
|
2163
|
+
api
|
|
2164
|
+
});
|
|
2165
|
+
const pages = await toArrayFromAsync(iterator);
|
|
2166
|
+
const apps = pages.flatMap((page) => page.data);
|
|
2167
|
+
const slugToAppData = /* @__PURE__ */ new Map();
|
|
2168
|
+
for (const app of apps) {
|
|
2169
|
+
if (app.slug) {
|
|
2170
|
+
slugToAppData.set(app.slug, app);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
const slugResolvedLocators = locatorsWithManifest.map((locator) => {
|
|
2174
|
+
if (isResolvedAppLocator(locator)) {
|
|
2175
|
+
return locator;
|
|
2176
|
+
}
|
|
2177
|
+
if (locator.slug) {
|
|
2178
|
+
const appData = slugToAppData.get(locator.slug);
|
|
2179
|
+
if (appData) {
|
|
2180
|
+
const manifestEntryByImplementationName = findManifestEntry({
|
|
2181
|
+
appKey: appData.key,
|
|
2182
|
+
// appData.key is the implementation name
|
|
2183
|
+
manifest
|
|
2184
|
+
});
|
|
2185
|
+
let version = locator.version;
|
|
2186
|
+
if (!version) {
|
|
2187
|
+
version = manifestEntryByImplementationName ? manifestEntryByImplementationName[1].version || appData.version : appData.version;
|
|
2188
|
+
}
|
|
2189
|
+
return {
|
|
2190
|
+
...locator,
|
|
2191
|
+
implementationName: appData.key,
|
|
2192
|
+
version
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
return locator;
|
|
2197
|
+
});
|
|
2198
|
+
return slugResolvedLocators.filter(isResolvedAppLocator);
|
|
2199
|
+
}
|
|
2011
2200
|
var manifestPlugin = (params) => {
|
|
2012
|
-
const {
|
|
2201
|
+
const { context } = params;
|
|
2013
2202
|
const { api, options } = context;
|
|
2014
|
-
const { manifestPath =
|
|
2203
|
+
const { manifestPath = DEFAULT_CONFIG_PATH, manifest } = options || {};
|
|
2015
2204
|
let resolvedManifest;
|
|
2016
|
-
function resolveManifest() {
|
|
2205
|
+
async function resolveManifest() {
|
|
2017
2206
|
if (manifest) {
|
|
2018
2207
|
return manifest;
|
|
2019
2208
|
}
|
|
2020
2209
|
if (manifestPath) {
|
|
2021
|
-
return
|
|
2210
|
+
return await readManifestFromFile(manifestPath);
|
|
2022
2211
|
}
|
|
2023
2212
|
return null;
|
|
2024
2213
|
}
|
|
2025
|
-
const getResolvedManifest = () => {
|
|
2214
|
+
const getResolvedManifest = async () => {
|
|
2026
2215
|
if (typeof resolvedManifest === "undefined") {
|
|
2027
|
-
resolvedManifest = resolveManifest() ?? null;
|
|
2216
|
+
resolvedManifest = await resolveManifest() ?? null;
|
|
2028
2217
|
}
|
|
2029
2218
|
return resolvedManifest;
|
|
2030
2219
|
};
|
|
2031
|
-
const
|
|
2032
|
-
|
|
2220
|
+
const getVersionedImplementationId = async (appKey) => {
|
|
2221
|
+
const resolvedApps = await resolveAppKeys({
|
|
2222
|
+
appKeys: [appKey],
|
|
2223
|
+
api,
|
|
2224
|
+
manifest: await getResolvedManifest() ?? { apps: {} }
|
|
2225
|
+
});
|
|
2226
|
+
const resolvedApp = resolvedApps[0];
|
|
2227
|
+
if (!resolvedApp) return null;
|
|
2228
|
+
return `${resolvedApp.implementationName}@${resolvedApp.version || "latest"}`;
|
|
2033
2229
|
};
|
|
2034
|
-
const
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2230
|
+
const updateManifestEntry = async (appKey, entry, configPath = DEFAULT_CONFIG_PATH) => {
|
|
2231
|
+
const manifest2 = await readManifestFromFile(configPath) || { apps: {} };
|
|
2232
|
+
let existingEntry = findManifestEntry({
|
|
2233
|
+
appKey,
|
|
2234
|
+
manifest: manifest2
|
|
2235
|
+
});
|
|
2236
|
+
if (!existingEntry) {
|
|
2237
|
+
try {
|
|
2238
|
+
const resolvedApps = await resolveAppKeys({
|
|
2239
|
+
appKeys: [appKey],
|
|
2240
|
+
api,
|
|
2241
|
+
manifest: manifest2
|
|
2242
|
+
});
|
|
2243
|
+
if (resolvedApps.length > 0) {
|
|
2244
|
+
const resolvedImplementationName = resolvedApps[0].implementationName;
|
|
2245
|
+
existingEntry = findManifestEntry({
|
|
2246
|
+
appKey: resolvedImplementationName,
|
|
2247
|
+
manifest: manifest2
|
|
2248
|
+
});
|
|
2051
2249
|
}
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
if (!implementationResults) return null;
|
|
2055
|
-
return normalizeImplementationToAppItem(implementationResults);
|
|
2056
|
-
}
|
|
2057
|
-
emitWarning(appKey);
|
|
2058
|
-
const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
|
|
2059
|
-
const apps = [];
|
|
2060
|
-
for await (const app2 of appsIterator) {
|
|
2061
|
-
apps.push(app2);
|
|
2062
|
-
break;
|
|
2063
|
-
}
|
|
2064
|
-
if (apps.length === 0) {
|
|
2065
|
-
return null;
|
|
2066
|
-
}
|
|
2067
|
-
const app = apps[0];
|
|
2068
|
-
return app;
|
|
2069
|
-
};
|
|
2070
|
-
const getVersionedImplementationId = async (appKey) => {
|
|
2071
|
-
const manifestEntry = getManifestEntry(appKey);
|
|
2072
|
-
if (manifestEntry) {
|
|
2073
|
-
return `${manifestEntry.implementationName}@${manifestEntry.version || "latest"}`;
|
|
2250
|
+
} catch {
|
|
2251
|
+
}
|
|
2074
2252
|
}
|
|
2075
|
-
|
|
2076
|
-
if (
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
getImplementation
|
|
2253
|
+
let manifestKey;
|
|
2254
|
+
if (existingEntry) {
|
|
2255
|
+
manifestKey = existingEntry[0];
|
|
2256
|
+
} else {
|
|
2257
|
+
manifestKey = await getPreferredManifestEntryKey({
|
|
2258
|
+
appKey,
|
|
2259
|
+
api
|
|
2260
|
+
});
|
|
2084
2261
|
}
|
|
2262
|
+
manifest2.apps[manifestKey] = entry;
|
|
2263
|
+
await writeManifestToFile(manifest2, configPath);
|
|
2264
|
+
resolvedManifest = void 0;
|
|
2265
|
+
return [manifestKey, entry];
|
|
2085
2266
|
};
|
|
2086
|
-
};
|
|
2087
|
-
var LockVersionSchema = z.object({
|
|
2088
|
-
appKey: z.string().describe("The app key to lock version for (e.g., 'slack', 'gmail')")
|
|
2089
|
-
});
|
|
2090
|
-
var lockVersionPlugin = ({ sdk }) => {
|
|
2091
|
-
const lockVersion = createFunction(
|
|
2092
|
-
async function lockVersion2(options) {
|
|
2093
|
-
const { appKey, configPath = ".zapierrc" } = options;
|
|
2094
|
-
const resolvedPath = resolve(configPath);
|
|
2095
|
-
const appsIterator = sdk.listApps({ appKeys: [appKey] }).items();
|
|
2096
|
-
const apps = [];
|
|
2097
|
-
for await (const app2 of appsIterator) {
|
|
2098
|
-
apps.push(app2);
|
|
2099
|
-
break;
|
|
2100
|
-
}
|
|
2101
|
-
const app = apps[0];
|
|
2102
|
-
const currentImplementationId = app.current_implementation_id;
|
|
2103
|
-
const [implementationName, version] = currentImplementationId.split("@");
|
|
2104
|
-
if (!implementationName || !version) {
|
|
2105
|
-
throw new Error(
|
|
2106
|
-
`Invalid implementation ID format: ${currentImplementationId}. Expected format: <implementationName>@<version>`
|
|
2107
|
-
);
|
|
2108
|
-
}
|
|
2109
|
-
let config = { apps: {} };
|
|
2110
|
-
if (existsSync(resolvedPath)) {
|
|
2111
|
-
try {
|
|
2112
|
-
const configContent = readFileSync(resolvedPath, "utf8");
|
|
2113
|
-
config = JSON.parse(configContent);
|
|
2114
|
-
if (!config.apps) {
|
|
2115
|
-
config.apps = {};
|
|
2116
|
-
}
|
|
2117
|
-
} catch (error) {
|
|
2118
|
-
console.warn(
|
|
2119
|
-
`\u26A0\uFE0F Failed to parse existing config file, creating new one: ${error}`
|
|
2120
|
-
);
|
|
2121
|
-
config = { apps: {} };
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
config.apps[appKey] = {
|
|
2125
|
-
implementationName,
|
|
2126
|
-
version
|
|
2127
|
-
};
|
|
2128
|
-
writeFileSync(resolvedPath, JSON.stringify(config, null, 2));
|
|
2129
|
-
return {
|
|
2130
|
-
data: {
|
|
2131
|
-
...app,
|
|
2132
|
-
implementationName,
|
|
2133
|
-
version
|
|
2134
|
-
},
|
|
2135
|
-
configPath: resolvedPath
|
|
2136
|
-
};
|
|
2137
|
-
},
|
|
2138
|
-
LockVersionSchema.extend({
|
|
2139
|
-
configPath: z.string().optional().describe("Path to .zapierrc file (defaults to '.zapierrc')")
|
|
2140
|
-
})
|
|
2141
|
-
);
|
|
2142
2267
|
return {
|
|
2143
|
-
lockVersion,
|
|
2144
2268
|
context: {
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2269
|
+
getVersionedImplementationId,
|
|
2270
|
+
resolveAppKeys: async ({ appKeys }) => resolveAppKeys({
|
|
2271
|
+
appKeys,
|
|
2272
|
+
api,
|
|
2273
|
+
manifest: await getResolvedManifest() ?? { apps: {} }
|
|
2274
|
+
}),
|
|
2275
|
+
updateManifestEntry
|
|
2151
2276
|
}
|
|
2152
2277
|
};
|
|
2153
2278
|
};
|
|
@@ -3195,10 +3320,10 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
|
|
|
3195
3320
|
};
|
|
3196
3321
|
}
|
|
3197
3322
|
function createZapierSdkWithoutRegistry(options = {}) {
|
|
3198
|
-
return createSdk(options).addPlugin(apiPlugin).addPlugin(
|
|
3323
|
+
return createSdk(options).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
|
|
3199
3324
|
}
|
|
3200
3325
|
function createZapierSdk(options = {}) {
|
|
3201
3326
|
return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
|
|
3202
3327
|
}
|
|
3203
3328
|
|
|
3204
|
-
export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdResolver, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findUniqueAuthenticationPlugin, formatErrorMessage, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getProfilePlugin, getResolutionOrder, getResolutionOrderForParams, getResolvableParams, getResolver, getResolversForMissingParams, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, hasResolver, inputsResolver, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin,
|
|
3329
|
+
export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdResolver, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getPreferredManifestEntryKey, getProfilePlugin, getResolutionOrder, getResolutionOrderForParams, getResolvableParams, getResolver, getResolversForMissingParams, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, hasResolver, inputsResolver, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resolverRegistry, runActionPlugin };
|