@zapier/zapier-sdk 0.15.9 → 0.15.11
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 +12 -0
- package/dist/index.cjs +583 -338
- package/dist/index.d.mts +184 -39
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +583 -339
- package/dist/plugins/eventEmission/builders.d.ts +3 -2
- package/dist/plugins/eventEmission/builders.d.ts.map +1 -1
- package/dist/plugins/eventEmission/builders.js +32 -1
- package/dist/plugins/eventEmission/index.d.ts +4 -2
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +8 -2
- package/dist/plugins/eventEmission/types.d.ts +10 -0
- package/dist/plugins/eventEmission/types.d.ts.map +1 -1
- package/dist/plugins/fetch/index.d.ts +2 -1
- package/dist/plugins/fetch/index.d.ts.map +1 -1
- package/dist/plugins/fetch/index.js +39 -11
- package/dist/plugins/findFirstAuthentication/index.d.ts +2 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.js +4 -2
- package/dist/plugins/findFirstAuthentication/index.test.js +11 -4
- package/dist/plugins/findUniqueAuthentication/index.d.ts +2 -1
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.js +4 -2
- package/dist/plugins/findUniqueAuthentication/index.test.js +9 -2
- package/dist/plugins/getAction/index.d.ts +3 -1
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +6 -3
- package/dist/plugins/getAction/index.test.js +5 -3
- package/dist/plugins/getAction/schemas.d.ts +14 -0
- package/dist/plugins/getAction/schemas.d.ts.map +1 -1
- package/dist/plugins/getAction/schemas.js +2 -0
- package/dist/plugins/getApp/index.d.ts +2 -1
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +9 -3
- package/dist/plugins/getApp/index.test.js +7 -0
- package/dist/plugins/getAuthentication/index.d.ts +3 -1
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +2 -1
- package/dist/plugins/getAuthentication/index.test.js +10 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts +2 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.js +2 -1
- package/dist/plugins/getInputFieldsSchema/index.test.js +3 -0
- package/dist/plugins/getProfile/index.d.ts +3 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +2 -1
- package/dist/plugins/listActions/index.d.ts +2 -1
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +14 -12
- package/dist/plugins/listActions/index.test.js +7 -0
- package/dist/plugins/listActions/schemas.d.ts +18 -4
- package/dist/plugins/listActions/schemas.d.ts.map +1 -1
- package/dist/plugins/listActions/schemas.js +2 -0
- package/dist/plugins/listApps/index.d.ts +2 -1
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +2 -1
- package/dist/plugins/listApps/index.test.js +7 -0
- package/dist/plugins/listAuthentications/index.d.ts +2 -1
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +2 -1
- package/dist/plugins/listAuthentications/index.test.js +7 -0
- package/dist/plugins/listAuthentications/schemas.d.ts +18 -4
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/schemas.js +2 -0
- package/dist/plugins/listInputFieldChoices/index.d.ts +3 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +2 -1
- package/dist/plugins/listInputFieldChoices/index.test.js +5 -2
- package/dist/plugins/listInputFieldChoices/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 +2 -1
- package/dist/plugins/listInputFields/index.test.js +3 -0
- package/dist/plugins/listInputFields/schemas.d.ts +4 -4
- package/dist/plugins/manifest/index.test.js +10 -1
- package/dist/plugins/request/index.d.ts +3 -1
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +2 -1
- package/dist/plugins/request/index.test.js +10 -1
- package/dist/plugins/request/schemas.d.ts +28 -0
- package/dist/plugins/request/schemas.d.ts.map +1 -1
- package/dist/plugins/request/schemas.js +2 -0
- package/dist/plugins/runAction/index.d.ts +3 -1
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +3 -1
- package/dist/plugins/runAction/index.test.js +20 -8
- package/dist/plugins/runAction/schemas.d.ts +4 -4
- package/dist/temporary-internal-core/schemas/apps/index.d.ts +21 -7
- package/dist/temporary-internal-core/schemas/apps/index.d.ts.map +1 -1
- package/dist/temporary-internal-core/schemas/apps/index.js +2 -0
- package/dist/types/telemetry-events.d.ts +31 -2
- package/dist/types/telemetry-events.d.ts.map +1 -1
- package/dist/utils/function-utils.d.ts +42 -3
- package/dist/utils/function-utils.d.ts.map +1 -1
- package/dist/utils/function-utils.js +83 -8
- package/dist/utils/telemetry-utils.d.ts +32 -0
- package/dist/utils/telemetry-utils.d.ts.map +1 -0
- package/dist/utils/telemetry-utils.js +43 -0
- package/dist/utils/telemetry-utils.test.d.ts +2 -0
- package/dist/utils/telemetry-utils.test.d.ts.map +1 -0
- package/dist/utils/telemetry-utils.test.js +94 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -390,24 +390,49 @@ var FetchInitSchema = zod.z.object({
|
|
|
390
390
|
}).optional().describe("Fetch options including authentication");
|
|
391
391
|
|
|
392
392
|
// src/plugins/fetch/index.ts
|
|
393
|
-
var fetchPlugin = ({ sdk }) => {
|
|
393
|
+
var fetchPlugin = ({ sdk, context }) => {
|
|
394
394
|
return {
|
|
395
395
|
fetch: async function fetch2(url, init) {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
396
|
+
const startTime = Date.now();
|
|
397
|
+
try {
|
|
398
|
+
const {
|
|
399
|
+
authenticationId,
|
|
400
|
+
callbackUrl,
|
|
401
|
+
authenticationTemplate,
|
|
402
|
+
...fetchInit
|
|
403
|
+
} = init || {};
|
|
404
|
+
const result = await sdk.request({
|
|
405
|
+
url: url.toString(),
|
|
406
|
+
method: fetchInit.method,
|
|
407
|
+
body: fetchInit.body,
|
|
408
|
+
headers: fetchInit.headers,
|
|
409
|
+
authenticationId,
|
|
410
|
+
callbackUrl,
|
|
411
|
+
authenticationTemplate,
|
|
412
|
+
_telemetry: { isNested: true }
|
|
413
|
+
});
|
|
414
|
+
context.eventEmission.emitMethodCalled({
|
|
415
|
+
method_name: "fetch",
|
|
416
|
+
execution_duration_ms: Date.now() - startTime,
|
|
417
|
+
success_flag: true,
|
|
418
|
+
error_message: null,
|
|
419
|
+
error_type: null,
|
|
420
|
+
argument_count: init ? 2 : 1,
|
|
421
|
+
is_paginated: false
|
|
422
|
+
});
|
|
423
|
+
return result;
|
|
424
|
+
} catch (error) {
|
|
425
|
+
context.eventEmission.emitMethodCalled({
|
|
426
|
+
method_name: "fetch",
|
|
427
|
+
execution_duration_ms: Date.now() - startTime,
|
|
428
|
+
success_flag: false,
|
|
429
|
+
error_message: error instanceof Error ? error.message : String(error),
|
|
430
|
+
error_type: error instanceof Error ? error.constructor.name : "Unknown",
|
|
431
|
+
argument_count: init ? 2 : 1,
|
|
432
|
+
is_paginated: false
|
|
433
|
+
});
|
|
434
|
+
throw error;
|
|
435
|
+
}
|
|
411
436
|
},
|
|
412
437
|
context: {
|
|
413
438
|
meta: {
|
|
@@ -596,6 +621,11 @@ var validateOptions = (schema, options) => {
|
|
|
596
621
|
};
|
|
597
622
|
|
|
598
623
|
// src/utils/function-utils.ts
|
|
624
|
+
var TelemetryMarkerSchema = zod.z.object({
|
|
625
|
+
_telemetry: zod.z.object({
|
|
626
|
+
isNested: zod.z.boolean().optional()
|
|
627
|
+
}).optional()
|
|
628
|
+
});
|
|
599
629
|
function extractCursor(data) {
|
|
600
630
|
if (!data?.next) {
|
|
601
631
|
return void 0;
|
|
@@ -615,22 +645,64 @@ function normalizeError(error) {
|
|
|
615
645
|
const message = error instanceof Error ? error.message : String(error);
|
|
616
646
|
return new ZapierUnknownError(`Unknown error: ${message}`, { cause: error });
|
|
617
647
|
}
|
|
618
|
-
function createFunction(coreFn, schema) {
|
|
648
|
+
function createFunction(coreFn, schema, telemetry) {
|
|
619
649
|
const functionName = coreFn.name;
|
|
620
650
|
const namedFunctions = {
|
|
621
651
|
[functionName]: async function(options) {
|
|
652
|
+
const startTime = Date.now();
|
|
653
|
+
const normalizedOptions = options ?? {};
|
|
654
|
+
const isNested = normalizedOptions?._telemetry?.isNested === true;
|
|
622
655
|
try {
|
|
623
|
-
const normalizedOptions = options ?? {};
|
|
624
656
|
if (schema) {
|
|
625
657
|
const validatedOptions = validateOptions(schema, normalizedOptions);
|
|
626
|
-
|
|
658
|
+
const result2 = await coreFn({
|
|
627
659
|
...normalizedOptions,
|
|
628
660
|
...validatedOptions
|
|
629
661
|
});
|
|
662
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
663
|
+
const argumentCount = Object.keys(
|
|
664
|
+
normalizedOptions
|
|
665
|
+
).filter((k) => k !== "_telemetry").length;
|
|
666
|
+
telemetry.onMethodCalled({
|
|
667
|
+
methodName: functionName,
|
|
668
|
+
durationMs: Date.now() - startTime,
|
|
669
|
+
success: true,
|
|
670
|
+
argumentCount,
|
|
671
|
+
isPaginated: false
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
return result2;
|
|
675
|
+
}
|
|
676
|
+
const result = await coreFn(normalizedOptions);
|
|
677
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
678
|
+
const argumentCount = Object.keys(normalizedOptions).filter(
|
|
679
|
+
(k) => k !== "_telemetry"
|
|
680
|
+
).length;
|
|
681
|
+
telemetry.onMethodCalled({
|
|
682
|
+
methodName: functionName,
|
|
683
|
+
durationMs: Date.now() - startTime,
|
|
684
|
+
success: true,
|
|
685
|
+
argumentCount,
|
|
686
|
+
isPaginated: false
|
|
687
|
+
});
|
|
630
688
|
}
|
|
631
|
-
return
|
|
689
|
+
return result;
|
|
632
690
|
} catch (error) {
|
|
633
|
-
|
|
691
|
+
const normalizedError = normalizeError(error);
|
|
692
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
693
|
+
const argumentCount = Object.keys(normalizedOptions).filter(
|
|
694
|
+
(k) => k !== "_telemetry"
|
|
695
|
+
).length;
|
|
696
|
+
telemetry.onMethodCalled({
|
|
697
|
+
methodName: functionName,
|
|
698
|
+
durationMs: Date.now() - startTime,
|
|
699
|
+
success: false,
|
|
700
|
+
error: normalizedError,
|
|
701
|
+
argumentCount,
|
|
702
|
+
isPaginated: false
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
throw normalizedError;
|
|
634
706
|
}
|
|
635
707
|
}
|
|
636
708
|
};
|
|
@@ -660,13 +732,15 @@ function createPageFunction(coreFn) {
|
|
|
660
732
|
};
|
|
661
733
|
return namedFunctions[functionName];
|
|
662
734
|
}
|
|
663
|
-
function createPaginatedFunction(coreFn, schema) {
|
|
735
|
+
function createPaginatedFunction(coreFn, schema, telemetry) {
|
|
664
736
|
const pageFunction = createPageFunction(coreFn);
|
|
665
737
|
const functionName = coreFn.name;
|
|
666
738
|
const validator = schema ? createValidator(schema) : null;
|
|
667
739
|
const namedFunctions = {
|
|
668
740
|
[functionName]: function(options) {
|
|
741
|
+
const startTime = Date.now();
|
|
669
742
|
const normalizedOptions = options ?? {};
|
|
743
|
+
const isNested = normalizedOptions?._telemetry?.isNested === true;
|
|
670
744
|
const validatedOptions = {
|
|
671
745
|
...normalizedOptions,
|
|
672
746
|
...validator ? validator(normalizedOptions) : normalizedOptions
|
|
@@ -683,6 +757,32 @@ function createPaginatedFunction(coreFn, schema) {
|
|
|
683
757
|
}
|
|
684
758
|
return result.value;
|
|
685
759
|
});
|
|
760
|
+
if (!isNested && telemetry?.onMethodCalled) {
|
|
761
|
+
firstPagePromise.then(() => {
|
|
762
|
+
const argumentCount = Object.keys(
|
|
763
|
+
normalizedOptions
|
|
764
|
+
).filter((k) => k !== "_telemetry").length;
|
|
765
|
+
telemetry.onMethodCalled({
|
|
766
|
+
methodName: functionName,
|
|
767
|
+
durationMs: Date.now() - startTime,
|
|
768
|
+
success: true,
|
|
769
|
+
argumentCount,
|
|
770
|
+
isPaginated: true
|
|
771
|
+
});
|
|
772
|
+
}).catch((error) => {
|
|
773
|
+
const argumentCount = Object.keys(
|
|
774
|
+
normalizedOptions
|
|
775
|
+
).filter((k) => k !== "_telemetry").length;
|
|
776
|
+
telemetry.onMethodCalled({
|
|
777
|
+
methodName: functionName,
|
|
778
|
+
durationMs: Date.now() - startTime,
|
|
779
|
+
success: false,
|
|
780
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
781
|
+
argumentCount,
|
|
782
|
+
isPaginated: true
|
|
783
|
+
});
|
|
784
|
+
});
|
|
785
|
+
}
|
|
686
786
|
return Object.assign(firstPagePromise, {
|
|
687
787
|
[Symbol.asyncIterator]: async function* () {
|
|
688
788
|
yield await firstPagePromise;
|
|
@@ -780,7 +880,7 @@ var ListAppsOptionsSchema = zod.z.object({
|
|
|
780
880
|
pageSize: zod.z.number().min(1).optional().describe("Number of apps per page"),
|
|
781
881
|
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
782
882
|
cursor: zod.z.string().optional().describe("Cursor to start from")
|
|
783
|
-
}).describe("List all available apps with optional filtering");
|
|
883
|
+
}).merge(TelemetryMarkerSchema).describe("List all available apps with optional filtering");
|
|
784
884
|
var AppItemSchema = ImplementationMetaSchema.omit({
|
|
785
885
|
name: true,
|
|
786
886
|
id: true
|
|
@@ -1238,46 +1338,67 @@ var AppItemSchema2 = withFormatter(
|
|
|
1238
1338
|
}
|
|
1239
1339
|
);
|
|
1240
1340
|
|
|
1341
|
+
// src/utils/telemetry-utils.ts
|
|
1342
|
+
function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
1343
|
+
return {
|
|
1344
|
+
onMethodCalled: (data) => {
|
|
1345
|
+
emitMethodCalled({
|
|
1346
|
+
method_name: methodName,
|
|
1347
|
+
execution_duration_ms: data.durationMs,
|
|
1348
|
+
success_flag: data.success,
|
|
1349
|
+
error_message: data.error?.message ?? null,
|
|
1350
|
+
error_type: data.error?.constructor.name ?? null,
|
|
1351
|
+
argument_count: data.argumentCount,
|
|
1352
|
+
is_paginated: data.isPaginated
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1241
1358
|
// src/plugins/listApps/index.ts
|
|
1242
1359
|
var listAppsPlugin = ({ context }) => {
|
|
1243
|
-
const listApps = createPaginatedFunction(
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
const duplicatedLookupAppKeys = Object.keys(implementationNameToLocator).filter((key) => implementationNameToLocator[key].length > 1).map((key) => implementationNameToLocator[key]).flat().map((locator) => locator.lookupAppKey);
|
|
1257
|
-
if (duplicatedLookupAppKeys.length > 0) {
|
|
1258
|
-
throw new Error(
|
|
1259
|
-
`Duplicate lookup app keys found: ${duplicatedLookupAppKeys.join(", ")}`
|
|
1260
|
-
);
|
|
1261
|
-
}
|
|
1262
|
-
if (appKeys.length > 0 && appLocators.length === 0 && !options.search) {
|
|
1263
|
-
return {
|
|
1264
|
-
data: [],
|
|
1265
|
-
nextCursor: void 0
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
const implementationIds = appLocators.map((locator) => {
|
|
1269
|
-
const version = locator.version || "latest";
|
|
1270
|
-
return `${locator.implementationName}@${version}`;
|
|
1271
|
-
});
|
|
1272
|
-
return await api.get("/api/v0/apps", {
|
|
1273
|
-
searchParams: {
|
|
1274
|
-
implementationIds: implementationIds.join(","),
|
|
1275
|
-
...options.search && { search: options.search },
|
|
1276
|
-
pageSize: options.pageSize.toString(),
|
|
1277
|
-
...options.cursor && { cursor: options.cursor }
|
|
1360
|
+
const listApps = createPaginatedFunction(
|
|
1361
|
+
async function listAppsPage(options) {
|
|
1362
|
+
const { api, resolveAppKeys: resolveAppKeys2 } = context;
|
|
1363
|
+
const appKeys = options.appKeys ?? [];
|
|
1364
|
+
const appLocators = await resolveAppKeys2({
|
|
1365
|
+
appKeys: [...appKeys]
|
|
1366
|
+
});
|
|
1367
|
+
const implementationNameToLocator = {};
|
|
1368
|
+
for (const locator of appLocators) {
|
|
1369
|
+
implementationNameToLocator[locator.implementationName] = [
|
|
1370
|
+
...implementationNameToLocator[locator.implementationName] ?? [],
|
|
1371
|
+
locator
|
|
1372
|
+
];
|
|
1278
1373
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1374
|
+
const duplicatedLookupAppKeys = Object.keys(implementationNameToLocator).filter((key) => implementationNameToLocator[key].length > 1).map((key) => implementationNameToLocator[key]).flat().map((locator) => locator.lookupAppKey);
|
|
1375
|
+
if (duplicatedLookupAppKeys.length > 0) {
|
|
1376
|
+
throw new Error(
|
|
1377
|
+
`Duplicate lookup app keys found: ${duplicatedLookupAppKeys.join(", ")}`
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
if (appKeys.length > 0 && appLocators.length === 0 && !options.search) {
|
|
1381
|
+
return {
|
|
1382
|
+
data: [],
|
|
1383
|
+
nextCursor: void 0
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
const implementationIds = appLocators.map((locator) => {
|
|
1387
|
+
const version = locator.version || "latest";
|
|
1388
|
+
return `${locator.implementationName}@${version}`;
|
|
1389
|
+
});
|
|
1390
|
+
return await api.get("/api/v0/apps", {
|
|
1391
|
+
searchParams: {
|
|
1392
|
+
implementationIds: implementationIds.join(","),
|
|
1393
|
+
...options.search && { search: options.search },
|
|
1394
|
+
pageSize: options.pageSize.toString(),
|
|
1395
|
+
...options.cursor && { cursor: options.cursor }
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
},
|
|
1399
|
+
ListAppsOptionsSchema,
|
|
1400
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, "listApps")
|
|
1401
|
+
);
|
|
1281
1402
|
return {
|
|
1282
1403
|
listApps,
|
|
1283
1404
|
context: {
|
|
@@ -1423,7 +1544,7 @@ var ListActionsSchema = zod.z.object({
|
|
|
1423
1544
|
pageSize: zod.z.number().min(1).optional().describe("Number of actions per page"),
|
|
1424
1545
|
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
1425
1546
|
cursor: zod.z.string().optional().describe("Cursor to start from")
|
|
1426
|
-
}).describe("List all actions for a specific app");
|
|
1547
|
+
}).merge(TelemetryMarkerSchema).describe("List all actions for a specific app");
|
|
1427
1548
|
var ActionItemSchema = withFormatter(
|
|
1428
1549
|
ActionSchema.omit({ type: true, name: true, selected_api: true }).extend({
|
|
1429
1550
|
app_key: zod.z.string(),
|
|
@@ -1657,78 +1778,86 @@ var inputFieldKeyResolver = {
|
|
|
1657
1778
|
|
|
1658
1779
|
// src/plugins/listActions/index.ts
|
|
1659
1780
|
var listActionsPlugin = ({ context }) => {
|
|
1660
|
-
const
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1781
|
+
const methodMeta = {
|
|
1782
|
+
categories: ["action"],
|
|
1783
|
+
type: "list",
|
|
1784
|
+
itemType: "Action",
|
|
1785
|
+
inputSchema: ListActionsSchema,
|
|
1786
|
+
outputSchema: ActionItemSchema,
|
|
1787
|
+
resolvers: {
|
|
1788
|
+
appKey: appKeyResolver,
|
|
1789
|
+
actionType: actionTypeResolver
|
|
1668
1790
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1791
|
+
};
|
|
1792
|
+
const listActions = createPaginatedFunction(
|
|
1793
|
+
async function listActionsPage(options) {
|
|
1794
|
+
const { api, getVersionedImplementationId } = context;
|
|
1795
|
+
const selectedApi = await getVersionedImplementationId(options.appKey);
|
|
1796
|
+
if (!selectedApi) {
|
|
1797
|
+
throw new ZapierConfigurationError(
|
|
1798
|
+
"No current_implementation_id found for app",
|
|
1799
|
+
{ configType: "current_implementation_id" }
|
|
1800
|
+
);
|
|
1801
|
+
}
|
|
1802
|
+
const searchParams = {
|
|
1803
|
+
global: "true",
|
|
1804
|
+
public_only: "true",
|
|
1805
|
+
selected_apis: selectedApi
|
|
1806
|
+
};
|
|
1807
|
+
const data = await api.get(
|
|
1808
|
+
"/zapier/api/v4/implementations/",
|
|
1809
|
+
{
|
|
1810
|
+
searchParams,
|
|
1811
|
+
customErrorHandler: ({ status }) => {
|
|
1812
|
+
if (status === 401) {
|
|
1813
|
+
return new ZapierAuthenticationError(
|
|
1814
|
+
`Authentication failed. Your token may not have permission to access implementations or may be expired. (HTTP ${status})`,
|
|
1815
|
+
{ statusCode: status }
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1818
|
+
if (status === 403) {
|
|
1819
|
+
return new ZapierAuthenticationError(
|
|
1820
|
+
`Access forbidden. Your token may not have the required scopes to list implementations. (HTTP ${status})`,
|
|
1821
|
+
{ statusCode: status }
|
|
1822
|
+
);
|
|
1823
|
+
}
|
|
1824
|
+
return void 0;
|
|
1684
1825
|
}
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1826
|
+
}
|
|
1827
|
+
);
|
|
1828
|
+
let allActions = [];
|
|
1829
|
+
for (const implementation of data.results || []) {
|
|
1830
|
+
if (implementation.actions) {
|
|
1831
|
+
for (const action of implementation.actions) {
|
|
1832
|
+
const actionWithContext = {
|
|
1833
|
+
...action,
|
|
1834
|
+
selected_api: action.selected_api || implementation.selected_api
|
|
1835
|
+
};
|
|
1836
|
+
allActions.push(normalizeActionItem(actionWithContext));
|
|
1690
1837
|
}
|
|
1691
|
-
return void 0;
|
|
1692
1838
|
}
|
|
1693
1839
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
for (const action of implementation.actions) {
|
|
1699
|
-
const actionWithContext = {
|
|
1700
|
-
...action,
|
|
1701
|
-
selected_api: action.selected_api || implementation.selected_api
|
|
1702
|
-
};
|
|
1703
|
-
allActions.push(normalizeActionItem(actionWithContext));
|
|
1704
|
-
}
|
|
1840
|
+
if (options.actionType) {
|
|
1841
|
+
allActions = allActions.filter(
|
|
1842
|
+
(action) => action.action_type === options.actionType
|
|
1843
|
+
);
|
|
1705
1844
|
}
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1845
|
+
return {
|
|
1846
|
+
data: allActions,
|
|
1847
|
+
nextCursor: void 0
|
|
1848
|
+
};
|
|
1849
|
+
},
|
|
1850
|
+
ListActionsSchema,
|
|
1851
|
+
createTelemetryCallback(
|
|
1852
|
+
context.eventEmission.emitMethodCalled,
|
|
1853
|
+
"listActions"
|
|
1854
|
+
)
|
|
1855
|
+
);
|
|
1717
1856
|
return {
|
|
1718
1857
|
listActions,
|
|
1719
1858
|
context: {
|
|
1720
1859
|
meta: {
|
|
1721
|
-
listActions:
|
|
1722
|
-
categories: ["action"],
|
|
1723
|
-
type: "list",
|
|
1724
|
-
itemType: "Action",
|
|
1725
|
-
inputSchema: ListActionsSchema,
|
|
1726
|
-
outputSchema: ActionItemSchema,
|
|
1727
|
-
resolvers: {
|
|
1728
|
-
appKey: appKeyResolver,
|
|
1729
|
-
actionType: actionTypeResolver
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1860
|
+
listActions: methodMeta
|
|
1732
1861
|
}
|
|
1733
1862
|
}
|
|
1734
1863
|
};
|
|
@@ -2058,7 +2187,11 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
2058
2187
|
// No pagination needed since we return all input fields
|
|
2059
2188
|
};
|
|
2060
2189
|
},
|
|
2061
|
-
ListInputFieldsSchema
|
|
2190
|
+
ListInputFieldsSchema,
|
|
2191
|
+
createTelemetryCallback(
|
|
2192
|
+
context.eventEmission.emitMethodCalled,
|
|
2193
|
+
"listInputFields"
|
|
2194
|
+
)
|
|
2062
2195
|
);
|
|
2063
2196
|
return {
|
|
2064
2197
|
listInputFields,
|
|
@@ -2096,7 +2229,7 @@ var ListAuthenticationsSchema = zod.z.object({
|
|
|
2096
2229
|
pageSize: zod.z.number().min(1).optional().describe("Number of authentications per page"),
|
|
2097
2230
|
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
2098
2231
|
cursor: zod.z.string().optional().describe("Cursor to start from")
|
|
2099
|
-
}).describe("List available authentications with optional filtering");
|
|
2232
|
+
}).merge(TelemetryMarkerSchema).describe("List available authentications with optional filtering");
|
|
2100
2233
|
var AuthenticationItemSchema = withFormatter(
|
|
2101
2234
|
AuthenticationSchema.omit({ selected_api: true, customuser_id: true }).extend(
|
|
2102
2235
|
{
|
|
@@ -2207,7 +2340,11 @@ var listAuthenticationsPlugin = ({ context }) => {
|
|
|
2207
2340
|
nextCursor: extractCursor(data)
|
|
2208
2341
|
};
|
|
2209
2342
|
},
|
|
2210
|
-
ListAuthenticationsSchema
|
|
2343
|
+
ListAuthenticationsSchema,
|
|
2344
|
+
createTelemetryCallback(
|
|
2345
|
+
context.eventEmission.emitMethodCalled,
|
|
2346
|
+
"listAuthentications"
|
|
2347
|
+
)
|
|
2211
2348
|
);
|
|
2212
2349
|
return {
|
|
2213
2350
|
listAuthentications,
|
|
@@ -2234,18 +2371,25 @@ var GetAppSchema = zod.z.object({
|
|
|
2234
2371
|
}).describe("Get detailed information about a specific app");
|
|
2235
2372
|
|
|
2236
2373
|
// src/plugins/getApp/index.ts
|
|
2237
|
-
var getAppPlugin = ({ sdk }) => {
|
|
2238
|
-
const getApp = createFunction(
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
};
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2374
|
+
var getAppPlugin = ({ sdk, context }) => {
|
|
2375
|
+
const getApp = createFunction(
|
|
2376
|
+
async function getApp2(options) {
|
|
2377
|
+
const appsIterator = sdk.listApps({
|
|
2378
|
+
appKeys: [options.appKey],
|
|
2379
|
+
_telemetry: { isNested: true }
|
|
2380
|
+
}).items();
|
|
2381
|
+
for await (const app of appsIterator) {
|
|
2382
|
+
return {
|
|
2383
|
+
data: app
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
throw new ZapierAppNotFoundError("App not found", {
|
|
2387
|
+
appKey: options.appKey
|
|
2388
|
+
});
|
|
2389
|
+
},
|
|
2390
|
+
GetAppSchema,
|
|
2391
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, "getApp")
|
|
2392
|
+
);
|
|
2249
2393
|
return {
|
|
2250
2394
|
getApp,
|
|
2251
2395
|
context: {
|
|
@@ -2268,22 +2412,29 @@ var GetActionSchema = zod.z.object({
|
|
|
2268
2412
|
appKey: AppKeyPropertySchema,
|
|
2269
2413
|
actionType: ActionTypePropertySchema,
|
|
2270
2414
|
actionKey: ActionKeyPropertySchema
|
|
2271
|
-
}).describe("Get detailed information about a specific action");
|
|
2415
|
+
}).merge(TelemetryMarkerSchema).describe("Get detailed information about a specific action");
|
|
2272
2416
|
|
|
2273
2417
|
// src/plugins/getAction/index.ts
|
|
2274
|
-
var getActionPlugin = ({ sdk }) => {
|
|
2275
|
-
const getAction = createFunction(
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2418
|
+
var getActionPlugin = ({ sdk, context }) => {
|
|
2419
|
+
const getAction = createFunction(
|
|
2420
|
+
async function getAction2(options) {
|
|
2421
|
+
const { actionKey, actionType, appKey } = options;
|
|
2422
|
+
for await (const action of sdk.listActions({ appKey, _telemetry: { isNested: true } }).items()) {
|
|
2423
|
+
if ((action.key === actionKey || action.id === actionKey) && action.action_type === actionType) {
|
|
2424
|
+
return { data: action };
|
|
2425
|
+
}
|
|
2280
2426
|
}
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2427
|
+
throw new ZapierResourceNotFoundError(
|
|
2428
|
+
`Action not found: ${actionKey} with type ${actionType}`,
|
|
2429
|
+
{ resourceType: "Action", resourceId: `${actionKey} (${actionType})` }
|
|
2430
|
+
);
|
|
2431
|
+
},
|
|
2432
|
+
GetActionSchema,
|
|
2433
|
+
createTelemetryCallback(
|
|
2434
|
+
context.eventEmission.emitMethodCalled,
|
|
2435
|
+
"getAction"
|
|
2436
|
+
)
|
|
2437
|
+
);
|
|
2287
2438
|
return {
|
|
2288
2439
|
getAction,
|
|
2289
2440
|
context: {
|
|
@@ -2360,12 +2511,19 @@ zod.z.object({
|
|
|
2360
2511
|
|
|
2361
2512
|
// src/plugins/getAuthentication/index.ts
|
|
2362
2513
|
var getAuthenticationPlugin = ({ context }) => {
|
|
2363
|
-
const getAuthentication = createFunction(
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2514
|
+
const getAuthentication = createFunction(
|
|
2515
|
+
async function getAuthentication2(options) {
|
|
2516
|
+
const { api } = context;
|
|
2517
|
+
return await api.get(
|
|
2518
|
+
`/api/v0/authentications/${options.authenticationId}`
|
|
2519
|
+
);
|
|
2520
|
+
},
|
|
2521
|
+
GetAuthenticationOptionsSchema,
|
|
2522
|
+
createTelemetryCallback(
|
|
2523
|
+
context.eventEmission.emitMethodCalled,
|
|
2524
|
+
"getAuthentication"
|
|
2525
|
+
)
|
|
2526
|
+
);
|
|
2369
2527
|
return {
|
|
2370
2528
|
getAuthentication,
|
|
2371
2529
|
context: {
|
|
@@ -2395,12 +2553,13 @@ var FindFirstAuthenticationSchema = zod.z.object({
|
|
|
2395
2553
|
}).describe("Find the first authentication matching the criteria");
|
|
2396
2554
|
|
|
2397
2555
|
// src/plugins/findFirstAuthentication/index.ts
|
|
2398
|
-
var findFirstAuthenticationPlugin = ({ sdk }) => {
|
|
2556
|
+
var findFirstAuthenticationPlugin = ({ sdk, context }) => {
|
|
2399
2557
|
const findFirstAuthentication = createFunction(
|
|
2400
2558
|
async function findFirstAuthentication2(options = {}) {
|
|
2401
2559
|
const authsResponse = await sdk.listAuthentications({
|
|
2402
2560
|
...options,
|
|
2403
|
-
maxItems: 1
|
|
2561
|
+
maxItems: 1,
|
|
2562
|
+
_telemetry: { isNested: true }
|
|
2404
2563
|
});
|
|
2405
2564
|
if (authsResponse.data.length === 0) {
|
|
2406
2565
|
throw new ZapierResourceNotFoundError(
|
|
@@ -2412,7 +2571,11 @@ var findFirstAuthenticationPlugin = ({ sdk }) => {
|
|
|
2412
2571
|
data: authsResponse.data[0]
|
|
2413
2572
|
};
|
|
2414
2573
|
},
|
|
2415
|
-
FindFirstAuthenticationSchema
|
|
2574
|
+
FindFirstAuthenticationSchema,
|
|
2575
|
+
createTelemetryCallback(
|
|
2576
|
+
context.eventEmission.emitMethodCalled,
|
|
2577
|
+
"findFirstAuthentication"
|
|
2578
|
+
)
|
|
2416
2579
|
);
|
|
2417
2580
|
return {
|
|
2418
2581
|
findFirstAuthentication,
|
|
@@ -2440,13 +2603,14 @@ var FindUniqueAuthenticationSchema = zod.z.object({
|
|
|
2440
2603
|
}).describe("Find a unique authentication matching the criteria");
|
|
2441
2604
|
|
|
2442
2605
|
// src/plugins/findUniqueAuthentication/index.ts
|
|
2443
|
-
var findUniqueAuthenticationPlugin = ({ sdk }) => {
|
|
2606
|
+
var findUniqueAuthenticationPlugin = ({ sdk, context }) => {
|
|
2444
2607
|
const findUniqueAuthentication = createFunction(
|
|
2445
2608
|
async function findUniqueAuthentication2(options = {}) {
|
|
2446
2609
|
const authsResponse = await sdk.listAuthentications({
|
|
2447
2610
|
...options,
|
|
2448
|
-
maxItems: 2
|
|
2611
|
+
maxItems: 2,
|
|
2449
2612
|
// Get up to 2 to check for uniqueness
|
|
2613
|
+
_telemetry: { isNested: true }
|
|
2450
2614
|
});
|
|
2451
2615
|
if (authsResponse.data.length === 0) {
|
|
2452
2616
|
throw new ZapierResourceNotFoundError(
|
|
@@ -2463,7 +2627,11 @@ var findUniqueAuthenticationPlugin = ({ sdk }) => {
|
|
|
2463
2627
|
data: authsResponse.data[0]
|
|
2464
2628
|
};
|
|
2465
2629
|
},
|
|
2466
|
-
FindUniqueAuthenticationSchema
|
|
2630
|
+
FindUniqueAuthenticationSchema,
|
|
2631
|
+
createTelemetryCallback(
|
|
2632
|
+
context.eventEmission.emitMethodCalled,
|
|
2633
|
+
"findUniqueAuthentication"
|
|
2634
|
+
)
|
|
2467
2635
|
);
|
|
2468
2636
|
return {
|
|
2469
2637
|
findUniqueAuthentication,
|
|
@@ -2537,52 +2705,63 @@ async function executeAction(actionOptions) {
|
|
|
2537
2705
|
});
|
|
2538
2706
|
}
|
|
2539
2707
|
var runActionPlugin = ({ sdk, context }) => {
|
|
2540
|
-
const runAction = createPaginatedFunction(
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
actionKey,
|
|
2545
|
-
actionType,
|
|
2546
|
-
authenticationId,
|
|
2547
|
-
inputs = {}
|
|
2548
|
-
} = options;
|
|
2549
|
-
const actionData = await sdk.getAction({
|
|
2550
|
-
appKey,
|
|
2551
|
-
actionKey,
|
|
2552
|
-
actionType
|
|
2553
|
-
});
|
|
2554
|
-
if (actionData.data.action_type !== actionType) {
|
|
2555
|
-
throw new ZapierValidationError(
|
|
2556
|
-
`Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`
|
|
2557
|
-
);
|
|
2558
|
-
}
|
|
2559
|
-
const actionId = actionData.data.id;
|
|
2560
|
-
const result = await executeAction({
|
|
2561
|
-
api,
|
|
2562
|
-
context,
|
|
2563
|
-
appKey,
|
|
2564
|
-
// Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
|
|
2565
|
-
// we retrieve actions (probably legacy reasons), so we just pass along all the things!
|
|
2566
|
-
actionId,
|
|
2567
|
-
actionKey,
|
|
2568
|
-
actionType,
|
|
2569
|
-
executionOptions: { inputs },
|
|
2570
|
-
authenticationId});
|
|
2571
|
-
if (result.errors && result.errors.length > 0) {
|
|
2572
|
-
const errorMessage = result.errors.map(
|
|
2573
|
-
(error) => error.detail || error.title || "Unknown error"
|
|
2574
|
-
).join("; ");
|
|
2575
|
-
throw new ZapierActionError(`Action execution failed: ${errorMessage}`, {
|
|
2708
|
+
const runAction = createPaginatedFunction(
|
|
2709
|
+
async function runActionPage(options) {
|
|
2710
|
+
const { api } = context;
|
|
2711
|
+
const {
|
|
2576
2712
|
appKey,
|
|
2577
|
-
actionKey
|
|
2713
|
+
actionKey,
|
|
2714
|
+
actionType,
|
|
2715
|
+
authenticationId,
|
|
2716
|
+
inputs = {}
|
|
2717
|
+
} = options;
|
|
2718
|
+
const actionData = await sdk.getAction({
|
|
2719
|
+
appKey,
|
|
2720
|
+
actionKey,
|
|
2721
|
+
actionType,
|
|
2722
|
+
_telemetry: { isNested: true }
|
|
2578
2723
|
});
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2724
|
+
if (actionData.data.action_type !== actionType) {
|
|
2725
|
+
throw new ZapierValidationError(
|
|
2726
|
+
`Action type mismatch: expected ${actionType}, got ${actionData.data.action_type}`
|
|
2727
|
+
);
|
|
2728
|
+
}
|
|
2729
|
+
const actionId = actionData.data.id;
|
|
2730
|
+
const result = await executeAction({
|
|
2731
|
+
api,
|
|
2732
|
+
context,
|
|
2733
|
+
appKey,
|
|
2734
|
+
// Some actions require the action ID to run them, but technically the ID is not guaranteed to be available when
|
|
2735
|
+
// we retrieve actions (probably legacy reasons), so we just pass along all the things!
|
|
2736
|
+
actionId,
|
|
2737
|
+
actionKey,
|
|
2738
|
+
actionType,
|
|
2739
|
+
executionOptions: { inputs },
|
|
2740
|
+
authenticationId});
|
|
2741
|
+
if (result.errors && result.errors.length > 0) {
|
|
2742
|
+
const errorMessage = result.errors.map(
|
|
2743
|
+
(error) => error.detail || error.title || "Unknown error"
|
|
2744
|
+
).join("; ");
|
|
2745
|
+
throw new ZapierActionError(
|
|
2746
|
+
`Action execution failed: ${errorMessage}`,
|
|
2747
|
+
{
|
|
2748
|
+
appKey,
|
|
2749
|
+
actionKey
|
|
2750
|
+
}
|
|
2751
|
+
);
|
|
2752
|
+
}
|
|
2753
|
+
return {
|
|
2754
|
+
data: result.results || [],
|
|
2755
|
+
nextCursor: void 0
|
|
2756
|
+
// No pagination implemented yet
|
|
2757
|
+
};
|
|
2758
|
+
},
|
|
2759
|
+
RunActionSchema,
|
|
2760
|
+
createTelemetryCallback(
|
|
2761
|
+
context.eventEmission.emitMethodCalled,
|
|
2762
|
+
"runAction"
|
|
2763
|
+
)
|
|
2764
|
+
);
|
|
2586
2765
|
return {
|
|
2587
2766
|
runAction,
|
|
2588
2767
|
context: {
|
|
@@ -2621,7 +2800,7 @@ var RelayRequestSchema = zod.z.object({
|
|
|
2621
2800
|
]).optional().describe("Request headers")
|
|
2622
2801
|
}).extend({
|
|
2623
2802
|
relayBaseUrl: zod.z.string().optional().describe("Base URL for Relay service")
|
|
2624
|
-
}).describe("Make authenticated HTTP requests through Zapier's Relay service");
|
|
2803
|
+
}).merge(TelemetryMarkerSchema).describe("Make authenticated HTTP requests through Zapier's Relay service");
|
|
2625
2804
|
var RelayFetchSchema = RelayRequestSchema;
|
|
2626
2805
|
|
|
2627
2806
|
// src/plugins/request/index.ts
|
|
@@ -2631,40 +2810,44 @@ function transformUrlToRelayPath(url) {
|
|
|
2631
2810
|
return relayPath;
|
|
2632
2811
|
}
|
|
2633
2812
|
var requestPlugin = ({ context }) => {
|
|
2634
|
-
const request = createFunction(
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2813
|
+
const request = createFunction(
|
|
2814
|
+
async function request2(options) {
|
|
2815
|
+
const { api } = context;
|
|
2816
|
+
const {
|
|
2817
|
+
url,
|
|
2818
|
+
method = "GET",
|
|
2819
|
+
body,
|
|
2820
|
+
headers: optionsHeaders,
|
|
2821
|
+
authenticationId,
|
|
2822
|
+
callbackUrl,
|
|
2823
|
+
authenticationTemplate
|
|
2824
|
+
} = options;
|
|
2825
|
+
const relayPath = transformUrlToRelayPath(url);
|
|
2826
|
+
const headers = {};
|
|
2827
|
+
if (optionsHeaders) {
|
|
2828
|
+
const headerEntries = optionsHeaders instanceof Headers ? Array.from(optionsHeaders.entries()) : Array.isArray(optionsHeaders) ? optionsHeaders : Object.entries(optionsHeaders);
|
|
2829
|
+
for (const [key, value] of headerEntries) {
|
|
2830
|
+
headers[key] = value;
|
|
2831
|
+
}
|
|
2651
2832
|
}
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
}
|
|
2667
|
-
|
|
2833
|
+
if (authenticationId) {
|
|
2834
|
+
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
2835
|
+
}
|
|
2836
|
+
if (callbackUrl) {
|
|
2837
|
+
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
2838
|
+
}
|
|
2839
|
+
if (authenticationTemplate) {
|
|
2840
|
+
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
2841
|
+
}
|
|
2842
|
+
return await api.fetch(relayPath, {
|
|
2843
|
+
method,
|
|
2844
|
+
body,
|
|
2845
|
+
headers
|
|
2846
|
+
});
|
|
2847
|
+
},
|
|
2848
|
+
RelayRequestSchema,
|
|
2849
|
+
createTelemetryCallback(context.eventEmission.emitMethodCalled, "request")
|
|
2850
|
+
);
|
|
2668
2851
|
return {
|
|
2669
2852
|
request,
|
|
2670
2853
|
context: {
|
|
@@ -3169,23 +3352,30 @@ var UserProfileItemSchema = withFormatter(
|
|
|
3169
3352
|
|
|
3170
3353
|
// src/plugins/getProfile/index.ts
|
|
3171
3354
|
var getProfilePlugin = ({ context }) => {
|
|
3172
|
-
const getProfile = createFunction(
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3355
|
+
const getProfile = createFunction(
|
|
3356
|
+
async function getProfile2() {
|
|
3357
|
+
const profile = await context.api.get(
|
|
3358
|
+
"/zapier/api/v4/profile/",
|
|
3359
|
+
{
|
|
3360
|
+
authRequired: true
|
|
3361
|
+
}
|
|
3362
|
+
);
|
|
3363
|
+
const { user_id: _unusedUserId, ...data } = profile;
|
|
3364
|
+
return {
|
|
3365
|
+
data: {
|
|
3366
|
+
...data,
|
|
3367
|
+
// Pass through all API response fields
|
|
3368
|
+
full_name: `${profile.first_name} ${profile.last_name}`
|
|
3369
|
+
// Computed field
|
|
3370
|
+
}
|
|
3371
|
+
};
|
|
3372
|
+
},
|
|
3373
|
+
GetProfileSchema,
|
|
3374
|
+
createTelemetryCallback(
|
|
3375
|
+
context.eventEmission.emitMethodCalled,
|
|
3376
|
+
"getProfile"
|
|
3377
|
+
)
|
|
3378
|
+
);
|
|
3189
3379
|
return {
|
|
3190
3380
|
getProfile,
|
|
3191
3381
|
context: {
|
|
@@ -4464,7 +4654,11 @@ var getInputFieldsSchemaPlugin = ({ sdk, context }) => {
|
|
|
4464
4654
|
data: needsData.schema || {}
|
|
4465
4655
|
};
|
|
4466
4656
|
},
|
|
4467
|
-
GetInputFieldsSchemaSchema
|
|
4657
|
+
GetInputFieldsSchemaSchema,
|
|
4658
|
+
createTelemetryCallback(
|
|
4659
|
+
context.eventEmission.emitMethodCalled,
|
|
4660
|
+
"getInputFieldsSchema"
|
|
4661
|
+
)
|
|
4468
4662
|
);
|
|
4469
4663
|
return {
|
|
4470
4664
|
getInputFieldsSchema,
|
|
@@ -4536,85 +4730,92 @@ function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
|
4536
4730
|
};
|
|
4537
4731
|
}
|
|
4538
4732
|
var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
4539
|
-
const listInputFieldChoices = createPaginatedFunction(
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4733
|
+
const listInputFieldChoices = createPaginatedFunction(
|
|
4734
|
+
async function listInputFieldChoicesPage(options) {
|
|
4735
|
+
const { api, getVersionedImplementationId } = context;
|
|
4736
|
+
const {
|
|
4737
|
+
appKey,
|
|
4738
|
+
actionType,
|
|
4739
|
+
actionKey,
|
|
4740
|
+
inputFieldKey,
|
|
4741
|
+
authenticationId = null,
|
|
4742
|
+
inputs,
|
|
4743
|
+
page,
|
|
4744
|
+
cursor
|
|
4745
|
+
} = options;
|
|
4746
|
+
const selectedApi = await getVersionedImplementationId(appKey);
|
|
4747
|
+
if (!selectedApi) {
|
|
4748
|
+
throw new ZapierConfigurationError(
|
|
4749
|
+
"No current_implementation_id found for app",
|
|
4750
|
+
{ configType: "current_implementation_id" }
|
|
4751
|
+
);
|
|
4752
|
+
}
|
|
4753
|
+
const { data: action } = await sdk.getAction({
|
|
4754
|
+
appKey,
|
|
4755
|
+
actionType,
|
|
4756
|
+
actionKey
|
|
4757
|
+
});
|
|
4758
|
+
const needsData = await fetchImplementationNeeds({
|
|
4759
|
+
api,
|
|
4760
|
+
selectedApi,
|
|
4761
|
+
action: action.key,
|
|
4762
|
+
actionType,
|
|
4763
|
+
authenticationId,
|
|
4764
|
+
inputs
|
|
4765
|
+
});
|
|
4766
|
+
const targetNeed = needsData.needs?.find(
|
|
4767
|
+
(need) => need.key === inputFieldKey
|
|
4556
4768
|
);
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
}
|
|
4582
|
-
if (!action.id) {
|
|
4583
|
-
throw new ZapierApiError(
|
|
4584
|
-
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`
|
|
4769
|
+
if (targetNeed?.choices && targetNeed.choices.length > 0) {
|
|
4770
|
+
return {
|
|
4771
|
+
data: targetNeed.choices.map(
|
|
4772
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
4773
|
+
),
|
|
4774
|
+
nextCursor: void 0
|
|
4775
|
+
};
|
|
4776
|
+
}
|
|
4777
|
+
if (!action.id) {
|
|
4778
|
+
throw new ZapierApiError(
|
|
4779
|
+
`Action ${actionKey} does not have an ID - cannot retrieve input field choices`
|
|
4780
|
+
);
|
|
4781
|
+
}
|
|
4782
|
+
const requestPage = cursor ? parseInt(cursor, 10) : page ?? 0;
|
|
4783
|
+
const choicesData = await fetchImplementationChoices({
|
|
4784
|
+
api,
|
|
4785
|
+
actionId: action.id,
|
|
4786
|
+
inputFieldId: inputFieldKey,
|
|
4787
|
+
authenticationId,
|
|
4788
|
+
inputs,
|
|
4789
|
+
page: requestPage
|
|
4790
|
+
});
|
|
4791
|
+
const choices = (choicesData.choices || []).map(
|
|
4792
|
+
transformNeedChoicesToInputFieldChoiceItem
|
|
4585
4793
|
);
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
);
|
|
4599
|
-
let nextCursor;
|
|
4600
|
-
if (choicesData.next_page != null) {
|
|
4601
|
-
nextCursor = choicesData.next_page.toString();
|
|
4602
|
-
} else if (choicesData.links?.next) {
|
|
4603
|
-
try {
|
|
4604
|
-
const nextUrl = new URL(choicesData.links.next);
|
|
4605
|
-
const nextPage = nextUrl.searchParams.get("page");
|
|
4606
|
-
if (nextPage) {
|
|
4607
|
-
nextCursor = nextPage;
|
|
4794
|
+
let nextCursor;
|
|
4795
|
+
if (choicesData.next_page != null) {
|
|
4796
|
+
nextCursor = choicesData.next_page.toString();
|
|
4797
|
+
} else if (choicesData.links?.next) {
|
|
4798
|
+
try {
|
|
4799
|
+
const nextUrl = new URL(choicesData.links.next);
|
|
4800
|
+
const nextPage = nextUrl.searchParams.get("page");
|
|
4801
|
+
if (nextPage) {
|
|
4802
|
+
nextCursor = nextPage;
|
|
4803
|
+
}
|
|
4804
|
+
} catch {
|
|
4805
|
+
nextCursor = void 0;
|
|
4608
4806
|
}
|
|
4609
|
-
} catch {
|
|
4610
|
-
nextCursor = void 0;
|
|
4611
4807
|
}
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
}
|
|
4617
|
-
|
|
4808
|
+
return {
|
|
4809
|
+
data: choices,
|
|
4810
|
+
nextCursor
|
|
4811
|
+
};
|
|
4812
|
+
},
|
|
4813
|
+
ListInputFieldChoicesSchema,
|
|
4814
|
+
createTelemetryCallback(
|
|
4815
|
+
context.eventEmission.emitMethodCalled,
|
|
4816
|
+
"listInputFieldChoices"
|
|
4817
|
+
)
|
|
4818
|
+
);
|
|
4618
4819
|
return {
|
|
4619
4820
|
listInputFieldChoices,
|
|
4620
4821
|
context: {
|
|
@@ -4790,7 +4991,7 @@ function getCpuTime() {
|
|
|
4790
4991
|
|
|
4791
4992
|
// package.json
|
|
4792
4993
|
var package_default = {
|
|
4793
|
-
version: "0.15.
|
|
4994
|
+
version: "0.15.11"};
|
|
4794
4995
|
|
|
4795
4996
|
// src/plugins/eventEmission/builders.ts
|
|
4796
4997
|
function createBaseEvent(context = {}) {
|
|
@@ -4829,7 +5030,6 @@ function buildApplicationLifecycleEvent(data, context = {}) {
|
|
|
4829
5030
|
sdk_version: package_default.version,
|
|
4830
5031
|
cli_version: null,
|
|
4831
5032
|
memory_usage_bytes: data.memory_usage_bytes ?? getMemoryUsage(),
|
|
4832
|
-
peak_memory_usage_bytes: data.peak_memory_usage_bytes ?? getMemoryUsage(),
|
|
4833
5033
|
cpu_time_ms: data.cpu_time_ms ?? getCpuTime(),
|
|
4834
5034
|
os_platform: osInfo.platform,
|
|
4835
5035
|
os_release: osInfo.release,
|
|
@@ -4859,11 +5059,44 @@ function buildErrorEventWithContext(data, context = {}) {
|
|
|
4859
5059
|
...data
|
|
4860
5060
|
};
|
|
4861
5061
|
}
|
|
5062
|
+
function buildMethodCalledEvent(data, context = {}) {
|
|
5063
|
+
return {
|
|
5064
|
+
...createBaseEvent(context),
|
|
5065
|
+
method_name: data.method_name ?? null,
|
|
5066
|
+
method_module: data.method_module ?? null,
|
|
5067
|
+
execution_duration_ms: data.execution_duration_ms,
|
|
5068
|
+
success_flag: data.success_flag,
|
|
5069
|
+
error_message: data.error_message ?? null,
|
|
5070
|
+
error_type: data.error_type ?? null,
|
|
5071
|
+
argument_count: data.argument_count,
|
|
5072
|
+
is_paginated: data.is_paginated ?? false,
|
|
5073
|
+
sdk_version: package_default.version,
|
|
5074
|
+
environment: context.environment ?? (process?.env?.NODE_ENV || null),
|
|
5075
|
+
selected_api: context.selected_api ?? null,
|
|
5076
|
+
app_id: context.app_id ?? null,
|
|
5077
|
+
app_version_id: context.app_version_id ?? null,
|
|
5078
|
+
zap_id: context.zap_id ?? null,
|
|
5079
|
+
node_id: context.node_id ?? null,
|
|
5080
|
+
operation_type: null,
|
|
5081
|
+
operation_key: null,
|
|
5082
|
+
call_context: null,
|
|
5083
|
+
is_retry: false,
|
|
5084
|
+
retry_attempt: null,
|
|
5085
|
+
argument_types: null,
|
|
5086
|
+
return_type: null,
|
|
5087
|
+
caller_method: null,
|
|
5088
|
+
call_stack_depth: null,
|
|
5089
|
+
is_synchronous: false,
|
|
5090
|
+
cpu_time_ms: null,
|
|
5091
|
+
memory_usage_bytes: null
|
|
5092
|
+
};
|
|
5093
|
+
}
|
|
4862
5094
|
|
|
4863
5095
|
// src/plugins/eventEmission/index.ts
|
|
4864
5096
|
var TELEMETRY_EMIT_TIMEOUT_MS = 300;
|
|
4865
5097
|
var APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
|
|
4866
5098
|
var ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
|
|
5099
|
+
var METHOD_CALLED_EVENT_SUBJECT = "platform.sdk.MethodCalledEvent";
|
|
4867
5100
|
var transportStates = /* @__PURE__ */ new WeakMap();
|
|
4868
5101
|
async function silentEmit(transport, subject, event, userContextPromise) {
|
|
4869
5102
|
try {
|
|
@@ -4965,7 +5198,9 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4965
5198
|
identity_id: null,
|
|
4966
5199
|
visitor_id: null,
|
|
4967
5200
|
correlation_id: null
|
|
4968
|
-
})
|
|
5201
|
+
}),
|
|
5202
|
+
emitMethodCalled: () => {
|
|
5203
|
+
}
|
|
4969
5204
|
}
|
|
4970
5205
|
}
|
|
4971
5206
|
};
|
|
@@ -5117,7 +5352,16 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
5117
5352
|
emit: (subject, event) => {
|
|
5118
5353
|
silentEmit(transport, subject, event, getUserContext);
|
|
5119
5354
|
},
|
|
5120
|
-
createBaseEvent: createBaseEventHelper
|
|
5355
|
+
createBaseEvent: createBaseEventHelper,
|
|
5356
|
+
emitMethodCalled: (data) => {
|
|
5357
|
+
const event = buildMethodCalledEvent(data);
|
|
5358
|
+
silentEmit(
|
|
5359
|
+
transport,
|
|
5360
|
+
METHOD_CALLED_EVENT_SUBJECT,
|
|
5361
|
+
event,
|
|
5362
|
+
getUserContext
|
|
5363
|
+
);
|
|
5364
|
+
}
|
|
5121
5365
|
}
|
|
5122
5366
|
}
|
|
5123
5367
|
};
|
|
@@ -5216,6 +5460,7 @@ exports.batch = batch;
|
|
|
5216
5460
|
exports.buildApplicationLifecycleEvent = buildApplicationLifecycleEvent;
|
|
5217
5461
|
exports.buildErrorEvent = buildErrorEvent;
|
|
5218
5462
|
exports.buildErrorEventWithContext = buildErrorEventWithContext;
|
|
5463
|
+
exports.buildMethodCalledEvent = buildMethodCalledEvent;
|
|
5219
5464
|
exports.createBaseEvent = createBaseEvent;
|
|
5220
5465
|
exports.createFunction = createFunction;
|
|
5221
5466
|
exports.createSdk = createSdk;
|