@zapier/zapier-sdk 0.15.1 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.integration.test.d.ts +5 -0
- package/dist/api/client.integration.test.d.ts.map +1 -0
- package/dist/api/client.integration.test.js +318 -0
- package/dist/api/client.js +31 -1
- package/dist/index.cjs +304 -104
- package/dist/index.d.mts +243 -31
- package/dist/index.mjs +304 -104
- package/dist/plugins/getApp/index.test.js +17 -21
- package/dist/plugins/listActions/schemas.d.ts +4 -4
- package/dist/plugins/listApps/index.d.ts +1 -3
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +18 -44
- package/dist/plugins/listApps/index.test.js +89 -288
- package/dist/plugins/listApps/schemas.d.ts +19 -26
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/schemas.js +19 -18
- package/dist/plugins/listAuthentications/schemas.d.ts +4 -4
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
- package/dist/plugins/listInputFields/schemas.d.ts +4 -4
- package/dist/plugins/runAction/schemas.d.ts +4 -4
- package/dist/sdk.d.ts +1 -1
- package/dist/temporary-internal-core/handlers/listApps.d.ts +67 -0
- package/dist/temporary-internal-core/handlers/listApps.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/listApps.js +121 -0
- package/dist/temporary-internal-core/handlers/listApps.test.d.ts +2 -0
- package/dist/temporary-internal-core/handlers/listApps.test.d.ts.map +1 -0
- package/dist/temporary-internal-core/handlers/listApps.test.js +328 -0
- package/dist/temporary-internal-core/index.d.ts +4 -0
- package/dist/temporary-internal-core/index.d.ts.map +1 -1
- package/dist/temporary-internal-core/index.js +5 -1
- package/dist/temporary-internal-core/schemas/apps/index.d.ts +582 -0
- package/dist/temporary-internal-core/schemas/apps/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/apps/index.js +95 -0
- package/dist/temporary-internal-core/schemas/implementations/index.d.ts +511 -0
- package/dist/temporary-internal-core/schemas/implementations/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/schemas/implementations/index.js +79 -0
- package/dist/temporary-internal-core/types/handler.d.ts +51 -0
- package/dist/temporary-internal-core/types/handler.d.ts.map +1 -0
- package/dist/temporary-internal-core/types/handler.js +8 -0
- package/dist/temporary-internal-core/types/index.d.ts +5 -0
- package/dist/temporary-internal-core/types/index.d.ts.map +1 -0
- package/dist/temporary-internal-core/types/index.js +4 -0
- package/dist/temporary-internal-core/utils/app-locators.d.ts +54 -0
- package/dist/temporary-internal-core/utils/app-locators.d.ts.map +1 -0
- package/dist/temporary-internal-core/utils/app-locators.js +83 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts +18 -0
- package/dist/temporary-internal-core/utils/transformations.d.ts.map +1 -0
- package/dist/temporary-internal-core/utils/transformations.js +36 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -688,7 +688,69 @@ function createPaginatedFunction(coreFn, schema) {
|
|
|
688
688
|
};
|
|
689
689
|
return namedFunctions[functionName];
|
|
690
690
|
}
|
|
691
|
-
var
|
|
691
|
+
var ImplementationMetaSchema = z.object({
|
|
692
|
+
id: z.string(),
|
|
693
|
+
name: z.string(),
|
|
694
|
+
slug: z.string(),
|
|
695
|
+
age_in_days: z.number().optional(),
|
|
696
|
+
auth_type: z.string().optional(),
|
|
697
|
+
banner: z.string().optional(),
|
|
698
|
+
categories: z.array(
|
|
699
|
+
z.object({
|
|
700
|
+
id: z.number(),
|
|
701
|
+
name: z.string(),
|
|
702
|
+
slug: z.string()
|
|
703
|
+
})
|
|
704
|
+
).optional(),
|
|
705
|
+
images: z.object({
|
|
706
|
+
url_16x16: z.string().optional(),
|
|
707
|
+
url_32x32: z.string().optional(),
|
|
708
|
+
url_64x64: z.string().optional(),
|
|
709
|
+
url_128x128: z.string().optional()
|
|
710
|
+
}).optional(),
|
|
711
|
+
popularity: z.number().optional(),
|
|
712
|
+
has_filters: z.boolean().optional(),
|
|
713
|
+
has_reads: z.boolean().optional(),
|
|
714
|
+
has_searches: z.boolean().optional(),
|
|
715
|
+
has_searches_or_writes: z.boolean().optional(),
|
|
716
|
+
has_upfront_fields: z.boolean().optional(),
|
|
717
|
+
has_writes: z.boolean().optional(),
|
|
718
|
+
is_beta: z.boolean().optional(),
|
|
719
|
+
is_built_in: z.boolean().optional(),
|
|
720
|
+
is_deprecated: z.boolean().optional(),
|
|
721
|
+
is_featured: z.boolean().optional(),
|
|
722
|
+
is_hidden: z.boolean().optional(),
|
|
723
|
+
is_invite: z.boolean().optional(),
|
|
724
|
+
is_premium: z.boolean().optional(),
|
|
725
|
+
is_public: z.boolean().optional(),
|
|
726
|
+
is_upcoming: z.boolean().optional(),
|
|
727
|
+
version: z.string().optional(),
|
|
728
|
+
visibility: z.string().optional(),
|
|
729
|
+
actions: z.object({
|
|
730
|
+
read: z.number().optional(),
|
|
731
|
+
read_bulk: z.number().optional(),
|
|
732
|
+
write: z.number().optional(),
|
|
733
|
+
search: z.number().optional(),
|
|
734
|
+
search_or_write: z.number().optional(),
|
|
735
|
+
search_and_write: z.number().optional(),
|
|
736
|
+
filter: z.number().optional()
|
|
737
|
+
}).optional(),
|
|
738
|
+
description: z.string().optional(),
|
|
739
|
+
primary_color: z.string().optional(),
|
|
740
|
+
secondary_color: z.string().optional(),
|
|
741
|
+
classification: z.string().optional(),
|
|
742
|
+
api_docs_url: z.string().optional(),
|
|
743
|
+
image: z.string().optional()
|
|
744
|
+
});
|
|
745
|
+
z.object({
|
|
746
|
+
count: z.number(),
|
|
747
|
+
next: z.string().nullable().optional(),
|
|
748
|
+
previous: z.string().nullable().optional(),
|
|
749
|
+
results: z.array(ImplementationMetaSchema)
|
|
750
|
+
});
|
|
751
|
+
|
|
752
|
+
// src/temporary-internal-core/schemas/apps/index.ts
|
|
753
|
+
var ListAppsOptionsSchema = z.object({
|
|
692
754
|
appKeys: z.array(z.string()).optional().describe(
|
|
693
755
|
"Filter apps by app keys (e.g., 'SlackCLIAPI' or slug like 'github')"
|
|
694
756
|
),
|
|
@@ -697,6 +759,34 @@ var ListAppsSchema = z.object({
|
|
|
697
759
|
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
698
760
|
cursor: z.string().optional().describe("Cursor to start from")
|
|
699
761
|
}).describe("List all available apps with optional filtering");
|
|
762
|
+
var AppItemSchema = ImplementationMetaSchema.omit({
|
|
763
|
+
name: true,
|
|
764
|
+
id: true
|
|
765
|
+
}).extend({
|
|
766
|
+
title: z.string(),
|
|
767
|
+
key: z.string(),
|
|
768
|
+
implementation_id: z.string(),
|
|
769
|
+
version: z.string().optional()
|
|
770
|
+
});
|
|
771
|
+
z.object({
|
|
772
|
+
data: z.array(AppItemSchema),
|
|
773
|
+
nextCursor: z.string().optional()
|
|
774
|
+
});
|
|
775
|
+
var ListAppsHandlerRequestSchema = z.object({
|
|
776
|
+
implementationIds: z.union([z.string(), z.array(z.string())]).optional().describe(
|
|
777
|
+
"Pre-resolved implementation IDs - array or comma-separated string"
|
|
778
|
+
),
|
|
779
|
+
search: z.string().optional().describe("Optional search term to augment results"),
|
|
780
|
+
pageSize: z.union([z.string(), z.number()]).optional().describe("Number of apps per page"),
|
|
781
|
+
cursor: z.string().optional().describe("Pagination cursor")
|
|
782
|
+
}).transform((data) => ({
|
|
783
|
+
// Normalize implementationIds to array
|
|
784
|
+
implementationIds: typeof data.implementationIds === "string" ? data.implementationIds === "" ? [] : data.implementationIds.split(",") : data.implementationIds ?? [],
|
|
785
|
+
search: data.search,
|
|
786
|
+
// Normalize pageSize to number
|
|
787
|
+
pageSize: typeof data.pageSize === "string" ? parseInt(data.pageSize, 10) : data.pageSize,
|
|
788
|
+
cursor: data.cursor
|
|
789
|
+
}));
|
|
700
790
|
var NeedChoicesSchema = z.object({
|
|
701
791
|
key: z.string().optional(),
|
|
702
792
|
label: z.string().optional(),
|
|
@@ -985,7 +1075,7 @@ z.object({
|
|
|
985
1075
|
previous: z.string().nullable().optional(),
|
|
986
1076
|
results: z.array(ImplementationSchema)
|
|
987
1077
|
});
|
|
988
|
-
var
|
|
1078
|
+
var ImplementationMetaSchema2 = z.object({
|
|
989
1079
|
id: z.string(),
|
|
990
1080
|
// e.g. "100HiresCLIAPI@1.2.1"
|
|
991
1081
|
name: z.string(),
|
|
@@ -1044,7 +1134,7 @@ z.object({
|
|
|
1044
1134
|
count: z.number(),
|
|
1045
1135
|
next: z.string().nullable().optional(),
|
|
1046
1136
|
previous: z.string().nullable().optional(),
|
|
1047
|
-
results: z.array(
|
|
1137
|
+
results: z.array(ImplementationMetaSchema2)
|
|
1048
1138
|
});
|
|
1049
1139
|
var NeedChoicesResponseMetaSchema = z.object({
|
|
1050
1140
|
page: z.string().nullable().optional()
|
|
@@ -1096,8 +1186,8 @@ function toSnakeCase(input) {
|
|
|
1096
1186
|
}
|
|
1097
1187
|
|
|
1098
1188
|
// src/schemas/App.ts
|
|
1099
|
-
var
|
|
1100
|
-
|
|
1189
|
+
var AppItemSchema2 = withFormatter(
|
|
1190
|
+
ImplementationMetaSchema2.omit({ name: true, id: true }).extend({
|
|
1101
1191
|
title: z.string(),
|
|
1102
1192
|
// Mapped from name
|
|
1103
1193
|
key: z.string(),
|
|
@@ -1126,6 +1216,62 @@ var AppItemSchema = withFormatter(
|
|
|
1126
1216
|
}
|
|
1127
1217
|
);
|
|
1128
1218
|
|
|
1219
|
+
// src/plugins/listApps/index.ts
|
|
1220
|
+
var listAppsPlugin = ({ context }) => {
|
|
1221
|
+
const listApps = createPaginatedFunction(async function listAppsPage(options) {
|
|
1222
|
+
const { api, resolveAppKeys: resolveAppKeys2 } = context;
|
|
1223
|
+
const appKeys = options.appKeys ?? [];
|
|
1224
|
+
const appLocators = await resolveAppKeys2({
|
|
1225
|
+
appKeys: [...appKeys]
|
|
1226
|
+
});
|
|
1227
|
+
const implementationNameToLocator = {};
|
|
1228
|
+
for (const locator of appLocators) {
|
|
1229
|
+
implementationNameToLocator[locator.implementationName] = [
|
|
1230
|
+
...implementationNameToLocator[locator.implementationName] ?? [],
|
|
1231
|
+
locator
|
|
1232
|
+
];
|
|
1233
|
+
}
|
|
1234
|
+
const duplicatedLookupAppKeys = Object.keys(implementationNameToLocator).filter((key) => implementationNameToLocator[key].length > 1).map((key) => implementationNameToLocator[key]).flat().map((locator) => locator.lookupAppKey);
|
|
1235
|
+
if (duplicatedLookupAppKeys.length > 0) {
|
|
1236
|
+
throw new Error(
|
|
1237
|
+
`Duplicate lookup app keys found: ${duplicatedLookupAppKeys.join(", ")}`
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
if (appKeys.length > 0 && appLocators.length === 0 && !options.search) {
|
|
1241
|
+
return {
|
|
1242
|
+
data: [],
|
|
1243
|
+
nextCursor: void 0
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
const implementationIds = appLocators.map((locator) => {
|
|
1247
|
+
const version = locator.version || "latest";
|
|
1248
|
+
return `${locator.implementationName}@${version}`;
|
|
1249
|
+
});
|
|
1250
|
+
return await api.get("/api/v0/apps", {
|
|
1251
|
+
searchParams: {
|
|
1252
|
+
implementationIds: implementationIds.join(","),
|
|
1253
|
+
...options.search && { search: options.search },
|
|
1254
|
+
pageSize: options.pageSize.toString(),
|
|
1255
|
+
...options.cursor && { cursor: options.cursor }
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
}, ListAppsOptionsSchema);
|
|
1259
|
+
return {
|
|
1260
|
+
listApps,
|
|
1261
|
+
context: {
|
|
1262
|
+
meta: {
|
|
1263
|
+
listApps: {
|
|
1264
|
+
categories: ["app"],
|
|
1265
|
+
type: "list",
|
|
1266
|
+
itemType: "App",
|
|
1267
|
+
inputSchema: ListAppsOptionsSchema,
|
|
1268
|
+
outputSchema: AppItemSchema2
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1129
1275
|
// src/utils/domain-utils.ts
|
|
1130
1276
|
function splitVersionedKey(versionedKey) {
|
|
1131
1277
|
const parts = versionedKey.split("@");
|
|
@@ -1245,102 +1391,6 @@ function toAppLocator(appKey) {
|
|
|
1245
1391
|
function isResolvedAppLocator(appLocator) {
|
|
1246
1392
|
return !!appLocator.implementationName;
|
|
1247
1393
|
}
|
|
1248
|
-
function toImplementationId(appLocator) {
|
|
1249
|
-
return `${appLocator.implementationName}@${appLocator.version || "latest"}`;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
// src/plugins/listApps/index.ts
|
|
1253
|
-
var listAppsPlugin = ({ context }) => {
|
|
1254
|
-
const listApps = createPaginatedFunction(async function listAppsPage(options) {
|
|
1255
|
-
const { api, resolveAppKeys: resolveAppKeys2 } = context;
|
|
1256
|
-
const appKeys = options.appKeys ?? [];
|
|
1257
|
-
const appLocators = await resolveAppKeys2({
|
|
1258
|
-
appKeys: [...appKeys]
|
|
1259
|
-
});
|
|
1260
|
-
const implementationNameToLocator = {};
|
|
1261
|
-
for (const locator of appLocators) {
|
|
1262
|
-
implementationNameToLocator[locator.implementationName] = [
|
|
1263
|
-
...implementationNameToLocator[locator.implementationName] ?? [],
|
|
1264
|
-
locator
|
|
1265
|
-
];
|
|
1266
|
-
}
|
|
1267
|
-
const duplicatedLookupAppKeys = Object.keys(implementationNameToLocator).filter((key) => implementationNameToLocator[key].length > 1).map((key) => implementationNameToLocator[key]).flat().map((locator) => locator.lookupAppKey);
|
|
1268
|
-
if (duplicatedLookupAppKeys.length > 0) {
|
|
1269
|
-
throw new Error(
|
|
1270
|
-
`Duplicate lookup app keys found: ${duplicatedLookupAppKeys.join(", ")}`
|
|
1271
|
-
);
|
|
1272
|
-
}
|
|
1273
|
-
if (options.search) {
|
|
1274
|
-
const searchParams2 = {};
|
|
1275
|
-
searchParams2.term = options.search;
|
|
1276
|
-
const searchEnvelope = await api.get(
|
|
1277
|
-
"/zapier/api/v4/implementations-meta/search/",
|
|
1278
|
-
{
|
|
1279
|
-
searchParams: searchParams2
|
|
1280
|
-
}
|
|
1281
|
-
);
|
|
1282
|
-
const implementations = searchEnvelope.results.map(
|
|
1283
|
-
normalizeImplementationMetaToAppItem
|
|
1284
|
-
);
|
|
1285
|
-
const implementationNameSet = new Set(
|
|
1286
|
-
appLocators.map((locator) => locator.implementationName)
|
|
1287
|
-
);
|
|
1288
|
-
for (const implementation of implementations) {
|
|
1289
|
-
const [implementationName] = splitVersionedKey(implementation.key);
|
|
1290
|
-
if (!implementationNameSet.has(implementationName)) {
|
|
1291
|
-
implementationNameSet.add(implementationName);
|
|
1292
|
-
appLocators.push({
|
|
1293
|
-
...toAppLocator(implementation.key),
|
|
1294
|
-
implementationName
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
const searchParams = {};
|
|
1300
|
-
if (options.pageSize) {
|
|
1301
|
-
searchParams.limit = options.pageSize.toString();
|
|
1302
|
-
}
|
|
1303
|
-
if (appLocators.length === 0) {
|
|
1304
|
-
searchParams.latest_only = "true";
|
|
1305
|
-
}
|
|
1306
|
-
if (options.cursor) {
|
|
1307
|
-
searchParams.offset = options.cursor;
|
|
1308
|
-
}
|
|
1309
|
-
searchParams.selected_apis = appLocators.map((locator) => toImplementationId(locator)).join(",");
|
|
1310
|
-
if (appKeys.length > 0 && appLocators.length === 0) {
|
|
1311
|
-
return {
|
|
1312
|
-
data: [],
|
|
1313
|
-
nextCursor: void 0
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
|
-
const implementationsEnvelope = await api.get(
|
|
1317
|
-
"/zapier/api/v4/implementations-meta/lookup/",
|
|
1318
|
-
{
|
|
1319
|
-
searchParams
|
|
1320
|
-
}
|
|
1321
|
-
);
|
|
1322
|
-
return {
|
|
1323
|
-
data: implementationsEnvelope.results.map(
|
|
1324
|
-
normalizeImplementationMetaToAppItem
|
|
1325
|
-
),
|
|
1326
|
-
nextCursor: extractCursor(implementationsEnvelope)
|
|
1327
|
-
};
|
|
1328
|
-
}, ListAppsSchema);
|
|
1329
|
-
return {
|
|
1330
|
-
listApps,
|
|
1331
|
-
context: {
|
|
1332
|
-
meta: {
|
|
1333
|
-
listApps: {
|
|
1334
|
-
categories: ["app"],
|
|
1335
|
-
type: "list",
|
|
1336
|
-
itemType: "App",
|
|
1337
|
-
inputSchema: ListAppsSchema,
|
|
1338
|
-
outputSchema: AppItemSchema
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
};
|
|
1343
|
-
};
|
|
1344
1394
|
var ListActionsSchema = z.object({
|
|
1345
1395
|
appKey: AppKeyPropertySchema.describe(
|
|
1346
1396
|
"App key of actions to list (e.g., 'SlackCLIAPI' or slug like 'github')"
|
|
@@ -2183,7 +2233,7 @@ var getAppPlugin = ({ sdk }) => {
|
|
|
2183
2233
|
type: "item",
|
|
2184
2234
|
itemType: "App",
|
|
2185
2235
|
inputSchema: GetAppSchema,
|
|
2186
|
-
outputSchema:
|
|
2236
|
+
outputSchema: AppItemSchema2,
|
|
2187
2237
|
resolvers: {
|
|
2188
2238
|
appKey: appKeyResolver
|
|
2189
2239
|
}
|
|
@@ -3365,6 +3415,135 @@ function getTrackingBaseUrl({
|
|
|
3365
3415
|
return ZAPIER_BASE_URL;
|
|
3366
3416
|
}
|
|
3367
3417
|
|
|
3418
|
+
// src/temporary-internal-core/utils/app-locators.ts
|
|
3419
|
+
function splitVersionedKey2(versionedKey) {
|
|
3420
|
+
const parts = versionedKey.split("@");
|
|
3421
|
+
if (parts.length >= 2) {
|
|
3422
|
+
const baseKey = parts[0];
|
|
3423
|
+
const version = parts.slice(1).join("@");
|
|
3424
|
+
return [baseKey, version];
|
|
3425
|
+
}
|
|
3426
|
+
return [versionedKey, void 0];
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
// src/temporary-internal-core/utils/transformations.ts
|
|
3430
|
+
function transformImplementationMetaToAppItem(implementationMeta) {
|
|
3431
|
+
const [selectedApi, appVersion] = splitVersionedKey2(implementationMeta.id);
|
|
3432
|
+
const { id, name, ...restOfImplementationMeta } = implementationMeta;
|
|
3433
|
+
return {
|
|
3434
|
+
...restOfImplementationMeta,
|
|
3435
|
+
title: name,
|
|
3436
|
+
key: selectedApi,
|
|
3437
|
+
implementation_id: id,
|
|
3438
|
+
version: appVersion
|
|
3439
|
+
};
|
|
3440
|
+
}
|
|
3441
|
+
function extractPaginationCursor(response) {
|
|
3442
|
+
if (!response.next) {
|
|
3443
|
+
return void 0;
|
|
3444
|
+
}
|
|
3445
|
+
try {
|
|
3446
|
+
const url = new URL(response.next);
|
|
3447
|
+
const offset = url.searchParams.get("offset");
|
|
3448
|
+
return offset || void 0;
|
|
3449
|
+
} catch {
|
|
3450
|
+
return void 0;
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3454
|
+
// src/temporary-internal-core/handlers/listApps.ts
|
|
3455
|
+
var DEFAULT_PAGE_SIZE = 20;
|
|
3456
|
+
async function augmentWithSearchResults({
|
|
3457
|
+
searchTerm,
|
|
3458
|
+
implementationIds,
|
|
3459
|
+
httpClient
|
|
3460
|
+
}) {
|
|
3461
|
+
const searchResponse = await httpClient.get(
|
|
3462
|
+
"/zapier/api/v4/implementations-meta/search/",
|
|
3463
|
+
{
|
|
3464
|
+
searchParams: { term: searchTerm }
|
|
3465
|
+
}
|
|
3466
|
+
);
|
|
3467
|
+
const searchResults = searchResponse.results.map(
|
|
3468
|
+
transformImplementationMetaToAppItem
|
|
3469
|
+
);
|
|
3470
|
+
const implementationNameSet = new Set(
|
|
3471
|
+
implementationIds.map((id) => {
|
|
3472
|
+
const [name] = splitVersionedKey2(id);
|
|
3473
|
+
return name;
|
|
3474
|
+
})
|
|
3475
|
+
);
|
|
3476
|
+
const additionalIds = [];
|
|
3477
|
+
for (const result of searchResults) {
|
|
3478
|
+
const [implementationName] = splitVersionedKey2(result.key);
|
|
3479
|
+
if (!implementationNameSet.has(implementationName)) {
|
|
3480
|
+
implementationNameSet.add(implementationName);
|
|
3481
|
+
additionalIds.push(result.implementation_id);
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
return [...implementationIds, ...additionalIds];
|
|
3485
|
+
}
|
|
3486
|
+
var handleListApps = async ({ request, deps }) => {
|
|
3487
|
+
const validatedRequest = ListAppsHandlerRequestSchema.parse(request);
|
|
3488
|
+
const { httpClient } = deps;
|
|
3489
|
+
let { implementationIds } = validatedRequest;
|
|
3490
|
+
const pageSize = validatedRequest.pageSize ?? DEFAULT_PAGE_SIZE;
|
|
3491
|
+
if (validatedRequest.search) {
|
|
3492
|
+
implementationIds = await augmentWithSearchResults({
|
|
3493
|
+
searchTerm: validatedRequest.search,
|
|
3494
|
+
implementationIds,
|
|
3495
|
+
httpClient
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
if (implementationIds.length === 0) {
|
|
3499
|
+
if (validatedRequest.search) {
|
|
3500
|
+
return {
|
|
3501
|
+
data: [],
|
|
3502
|
+
nextCursor: void 0
|
|
3503
|
+
};
|
|
3504
|
+
}
|
|
3505
|
+
const searchParams2 = {
|
|
3506
|
+
latest_only: "true",
|
|
3507
|
+
selected_apis: "",
|
|
3508
|
+
limit: pageSize.toString()
|
|
3509
|
+
};
|
|
3510
|
+
if (validatedRequest.cursor) {
|
|
3511
|
+
searchParams2.offset = validatedRequest.cursor;
|
|
3512
|
+
}
|
|
3513
|
+
const implementationsResponse2 = await httpClient.get(
|
|
3514
|
+
"/zapier/api/v4/implementations-meta/lookup/",
|
|
3515
|
+
{
|
|
3516
|
+
searchParams: searchParams2
|
|
3517
|
+
}
|
|
3518
|
+
);
|
|
3519
|
+
return {
|
|
3520
|
+
data: implementationsResponse2.results.map(
|
|
3521
|
+
transformImplementationMetaToAppItem
|
|
3522
|
+
),
|
|
3523
|
+
nextCursor: extractPaginationCursor(implementationsResponse2)
|
|
3524
|
+
};
|
|
3525
|
+
}
|
|
3526
|
+
const searchParams = {
|
|
3527
|
+
selected_apis: implementationIds.join(","),
|
|
3528
|
+
limit: pageSize.toString()
|
|
3529
|
+
};
|
|
3530
|
+
if (validatedRequest.cursor) {
|
|
3531
|
+
searchParams.offset = validatedRequest.cursor;
|
|
3532
|
+
}
|
|
3533
|
+
const implementationsResponse = await httpClient.get(
|
|
3534
|
+
"/zapier/api/v4/implementations-meta/lookup/",
|
|
3535
|
+
{
|
|
3536
|
+
searchParams
|
|
3537
|
+
}
|
|
3538
|
+
);
|
|
3539
|
+
return {
|
|
3540
|
+
data: implementationsResponse.results.map(
|
|
3541
|
+
transformImplementationMetaToAppItem
|
|
3542
|
+
),
|
|
3543
|
+
nextCursor: extractPaginationCursor(implementationsResponse)
|
|
3544
|
+
};
|
|
3545
|
+
};
|
|
3546
|
+
|
|
3368
3547
|
// src/api/client.ts
|
|
3369
3548
|
var pathConfig = {
|
|
3370
3549
|
// e.g. /relay -> https://sdkapi.zapier.com/api/v0/sdk/relay/...
|
|
@@ -3376,6 +3555,9 @@ var pathConfig = {
|
|
|
3376
3555
|
"/zapier": {
|
|
3377
3556
|
authHeader: "Authorization",
|
|
3378
3557
|
pathPrefix: "/api/v0/sdk/zapier"
|
|
3558
|
+
},
|
|
3559
|
+
"/api/v0/apps": {
|
|
3560
|
+
handlerOverride: handleListApps
|
|
3379
3561
|
}
|
|
3380
3562
|
};
|
|
3381
3563
|
var ZapierApiClient = class {
|
|
@@ -3533,6 +3715,14 @@ var ZapierApiClient = class {
|
|
|
3533
3715
|
}
|
|
3534
3716
|
return void 0;
|
|
3535
3717
|
}
|
|
3718
|
+
// Helper to check if a path config has a handler override
|
|
3719
|
+
hasHandlerOverride(pathConfig2) {
|
|
3720
|
+
return pathConfig2 !== void 0 && "handlerOverride" in pathConfig2 && typeof pathConfig2.handlerOverride === "function";
|
|
3721
|
+
}
|
|
3722
|
+
// Helper to check if a path config is a standard path config
|
|
3723
|
+
isStandardPathConfig(pathConfig2) {
|
|
3724
|
+
return pathConfig2 !== void 0 && !this.hasHandlerOverride(pathConfig2);
|
|
3725
|
+
}
|
|
3536
3726
|
// Helper to parse API error response
|
|
3537
3727
|
parseErrorResponse(errorInfo) {
|
|
3538
3728
|
const fallbackMessage = `HTTP ${errorInfo.status}: ${errorInfo.statusText}`;
|
|
@@ -3604,7 +3794,7 @@ var ZapierApiClient = class {
|
|
|
3604
3794
|
const headers = new Headers(options.headers ?? {});
|
|
3605
3795
|
const authToken = await this.getAuthToken();
|
|
3606
3796
|
if (authToken) {
|
|
3607
|
-
const authHeaderName = pathConfig2
|
|
3797
|
+
const authHeaderName = this.isStandardPathConfig(pathConfig2) && pathConfig2.authHeader ? pathConfig2.authHeader : "Authorization";
|
|
3608
3798
|
headers.set(authHeaderName, getAuthorizationHeader(authToken));
|
|
3609
3799
|
}
|
|
3610
3800
|
if (options.authRequired) {
|
|
@@ -3618,6 +3808,16 @@ var ZapierApiClient = class {
|
|
|
3618
3808
|
}
|
|
3619
3809
|
// Helper to perform HTTP requests with JSON handling
|
|
3620
3810
|
async fetchJson(method, path, data, options = {}) {
|
|
3811
|
+
const { pathConfig: pathConfig2 } = this.buildUrl(path, options.searchParams);
|
|
3812
|
+
if (this.hasHandlerOverride(pathConfig2)) {
|
|
3813
|
+
const handlerRequest = method === "GET" ? options.searchParams : data;
|
|
3814
|
+
return pathConfig2.handlerOverride({
|
|
3815
|
+
request: handlerRequest,
|
|
3816
|
+
deps: {
|
|
3817
|
+
httpClient: this
|
|
3818
|
+
}
|
|
3819
|
+
});
|
|
3820
|
+
}
|
|
3621
3821
|
const headers = { ...options.headers };
|
|
3622
3822
|
if (data && typeof data === "object") {
|
|
3623
3823
|
headers["Content-Type"] = "application/json";
|
|
@@ -4280,7 +4480,7 @@ function getCpuTime() {
|
|
|
4280
4480
|
|
|
4281
4481
|
// package.json
|
|
4282
4482
|
var package_default = {
|
|
4283
|
-
version: "0.15.
|
|
4483
|
+
version: "0.15.2"};
|
|
4284
4484
|
|
|
4285
4485
|
// src/plugins/eventEmission/builders.ts
|
|
4286
4486
|
function createBaseEvent(context = {}) {
|
|
@@ -39,7 +39,7 @@ describe("getApp plugin", () => {
|
|
|
39
39
|
// Mock the API client to handle both resolveAppKeys and listApps calls
|
|
40
40
|
context.api.get = vi
|
|
41
41
|
.fn()
|
|
42
|
-
// First call: resolveAppKeys
|
|
42
|
+
// First call: resolveAppKeys calls listAppsForSlugsPage which expects raw API format
|
|
43
43
|
.mockResolvedValueOnce({
|
|
44
44
|
results: [
|
|
45
45
|
{
|
|
@@ -49,27 +49,25 @@ describe("getApp plugin", () => {
|
|
|
49
49
|
primary_color: "#4A154B",
|
|
50
50
|
categories: ["communication"],
|
|
51
51
|
slug: "slack",
|
|
52
|
-
key: "SlackCLIAPI",
|
|
53
|
-
version: "1.0.0",
|
|
54
52
|
},
|
|
55
53
|
],
|
|
56
54
|
next: null,
|
|
57
55
|
})
|
|
58
|
-
// Second call: listApps
|
|
56
|
+
// Second call: listApps goes through handler which returns transformed format
|
|
59
57
|
.mockResolvedValueOnce({
|
|
60
|
-
|
|
58
|
+
data: [
|
|
61
59
|
{
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
title: "Slack",
|
|
61
|
+
key: "SlackCLIAPI",
|
|
62
|
+
implementation_id: "SlackCLIAPI@1.0.0",
|
|
64
63
|
description: "Team communication",
|
|
65
64
|
primary_color: "#4A154B",
|
|
66
65
|
categories: ["communication"],
|
|
67
66
|
slug: "slack",
|
|
68
|
-
key: "SlackCLIAPI",
|
|
69
67
|
version: "1.0.0",
|
|
70
68
|
},
|
|
71
69
|
],
|
|
72
|
-
|
|
70
|
+
nextCursor: undefined,
|
|
73
71
|
});
|
|
74
72
|
const result = await sdk.getApp({
|
|
75
73
|
appKey: "slack",
|
|
@@ -92,10 +90,10 @@ describe("getApp plugin", () => {
|
|
|
92
90
|
results: [],
|
|
93
91
|
next: null,
|
|
94
92
|
})
|
|
95
|
-
// Second call: listApps main API call
|
|
93
|
+
// Second call: listApps main API call (returns transformed format)
|
|
96
94
|
.mockResolvedValueOnce({
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
data: [],
|
|
96
|
+
nextCursor: undefined,
|
|
99
97
|
});
|
|
100
98
|
await expect(sdk.getApp({
|
|
101
99
|
appKey: "nonexistent-app",
|
|
@@ -109,7 +107,7 @@ describe("getApp plugin", () => {
|
|
|
109
107
|
// Mock the API client to handle both resolveAppKeys and listApps calls
|
|
110
108
|
context.api.get = vi
|
|
111
109
|
.fn()
|
|
112
|
-
// First call: resolveAppKeys
|
|
110
|
+
// First call: resolveAppKeys calls listAppsForSlugsPage which expects raw API format
|
|
113
111
|
.mockResolvedValueOnce({
|
|
114
112
|
results: [
|
|
115
113
|
{
|
|
@@ -119,27 +117,25 @@ describe("getApp plugin", () => {
|
|
|
119
117
|
primary_color: "#FF0000",
|
|
120
118
|
categories: ["testing"],
|
|
121
119
|
slug: "test",
|
|
122
|
-
key: "TestCLIAPI",
|
|
123
|
-
version: "1.0.0",
|
|
124
120
|
},
|
|
125
121
|
],
|
|
126
122
|
next: null,
|
|
127
123
|
})
|
|
128
|
-
// Second call: listApps
|
|
124
|
+
// Second call: listApps goes through handler which returns transformed format
|
|
129
125
|
.mockResolvedValueOnce({
|
|
130
|
-
|
|
126
|
+
data: [
|
|
131
127
|
{
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
title: "Test App",
|
|
129
|
+
key: "TestCLIAPI",
|
|
130
|
+
implementation_id: "TestCLIAPI@1.0.0",
|
|
134
131
|
description: "Test description",
|
|
135
132
|
primary_color: "#FF0000",
|
|
136
133
|
categories: ["testing"],
|
|
137
134
|
slug: "test",
|
|
138
|
-
key: "TestCLIAPI",
|
|
139
135
|
version: "1.0.0",
|
|
140
136
|
},
|
|
141
137
|
],
|
|
142
|
-
|
|
138
|
+
nextCursor: undefined,
|
|
143
139
|
});
|
|
144
140
|
const result = await sdk.getApp({
|
|
145
141
|
appKey: "test",
|
|
@@ -12,15 +12,15 @@ export declare const ListActionsSchema: z.ZodObject<{
|
|
|
12
12
|
cursor: z.ZodOptional<z.ZodString>;
|
|
13
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
14
|
appKey: string;
|
|
15
|
-
cursor?: string | undefined;
|
|
16
|
-
maxItems?: number | undefined;
|
|
17
15
|
pageSize?: number | undefined;
|
|
16
|
+
maxItems?: number | undefined;
|
|
17
|
+
cursor?: string | undefined;
|
|
18
18
|
actionType?: "search" | "filter" | "read" | "read_bulk" | "run" | "search_and_write" | "search_or_write" | "write" | undefined;
|
|
19
19
|
}, {
|
|
20
20
|
appKey: string;
|
|
21
|
-
cursor?: string | undefined;
|
|
22
|
-
maxItems?: number | undefined;
|
|
23
21
|
pageSize?: number | undefined;
|
|
22
|
+
maxItems?: number | undefined;
|
|
23
|
+
cursor?: string | undefined;
|
|
24
24
|
actionType?: "search" | "filter" | "read" | "read_bulk" | "run" | "search_and_write" | "search_or_write" | "write" | undefined;
|
|
25
25
|
}>;
|
|
26
26
|
export type ListActionsOptions = z.infer<typeof ListActionsSchema>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { GetContextType, Plugin } from "../../types/plugin";
|
|
2
|
-
import { ListAppsSchema } from "./schemas";
|
|
3
|
-
import type { ListAppsOptions } from "./schemas";
|
|
4
|
-
import type { AppItem } from "../../types/domain";
|
|
2
|
+
import { ListAppsSchema, type ListAppsOptions, type AppItem } from "./schemas";
|
|
5
3
|
import type { ManifestPluginProvides } from "../manifest";
|
|
6
4
|
import type { ApiPluginProvides } from "../api";
|
|
7
5
|
export interface ListAppsPluginProvides {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listApps/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listApps/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EAEpB,KAAK,OAAO,EACb,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC;QAC/C,IAAI,EAAE,OAAO,EAAE,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QACxD,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;KACjC,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,QAAQ,EAAE;gBACR,WAAW,EAAE,OAAO,cAAc,CAAC;aACpC,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CACjC,EAAE,EACF,cAAc,CAAC,iBAAiB,GAAG,sBAAsB,CAAC,EAC1D,sBAAsB,CAwEvB,CAAC"}
|