@zapier/zapier-sdk 0.42.0 → 0.43.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 +12 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +309 -35
- package/dist/api/types.d.ts +29 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/constants.d.ts +25 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +32 -0
- package/dist/index.cjs +616 -197
- package/dist/index.d.mts +241 -408
- 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 +611 -198
- package/dist/plugins/api/index.d.ts +5 -1
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +6 -3
- package/dist/plugins/apps/index.d.ts +2 -3
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/apps/index.js +1 -1
- package/dist/plugins/capabilities/index.d.ts +8 -6
- package/dist/plugins/capabilities/index.d.ts.map +1 -1
- package/dist/plugins/capabilities/index.js +3 -3
- package/dist/plugins/connections/index.d.ts +3 -1
- package/dist/plugins/connections/index.d.ts.map +1 -1
- package/dist/plugins/connections/index.js +2 -3
- package/dist/plugins/createClientCredentials/index.d.ts +6 -4
- package/dist/plugins/createClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/createClientCredentials/index.js +4 -3
- package/dist/plugins/createClientCredentials/schemas.d.ts +1 -0
- package/dist/plugins/createClientCredentials/schemas.d.ts.map +1 -1
- package/dist/plugins/createClientCredentials/schemas.js +6 -0
- package/dist/plugins/deleteClientCredentials/index.d.ts +6 -4
- package/dist/plugins/deleteClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/deleteClientCredentials/index.js +3 -3
- package/dist/plugins/deprecated/authentications.d.ts +9 -9
- package/dist/plugins/deprecated/authentications.d.ts.map +1 -1
- package/dist/plugins/deprecated/authentications.js +4 -4
- package/dist/plugins/eventEmission/index.d.ts +4 -5
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +8 -7
- package/dist/plugins/fetch/index.d.ts +6 -6
- package/dist/plugins/fetch/index.d.ts.map +1 -1
- package/dist/plugins/fetch/index.js +20 -6
- package/dist/plugins/findFirstConnection/index.d.ts +3 -4
- package/dist/plugins/findFirstConnection/index.d.ts.map +1 -1
- package/dist/plugins/findFirstConnection/index.js +2 -2
- package/dist/plugins/findUniqueConnection/index.d.ts +3 -4
- package/dist/plugins/findUniqueConnection/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueConnection/index.js +2 -2
- package/dist/plugins/getAction/index.d.ts +7 -7
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +2 -2
- package/dist/plugins/getApp/index.d.ts +2 -3
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +2 -2
- package/dist/plugins/getConnection/index.d.ts +6 -6
- package/dist/plugins/getConnection/index.d.ts.map +1 -1
- package/dist/plugins/getConnection/index.js +3 -3
- package/dist/plugins/getInputFieldsSchema/index.d.ts +8 -6
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +1 -1
- package/dist/plugins/getInputFieldsSchema/index.js +4 -4
- package/dist/plugins/getProfile/index.d.ts +6 -6
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +3 -3
- package/dist/plugins/listActions/index.d.ts +8 -6
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +3 -3
- package/dist/plugins/listApps/index.d.ts +3 -3
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +3 -3
- package/dist/plugins/listClientCredentials/index.d.ts +6 -4
- package/dist/plugins/listClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/listClientCredentials/index.js +3 -3
- package/dist/plugins/listConnections/index.d.ts +8 -6
- package/dist/plugins/listConnections/index.d.ts.map +1 -1
- package/dist/plugins/listConnections/index.js +5 -5
- package/dist/plugins/listInputFieldChoices/index.d.ts +9 -8
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +4 -4
- package/dist/plugins/listInputFields/index.d.ts +8 -8
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +4 -4
- package/dist/plugins/manifest/index.d.ts +8 -3
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +2 -3
- package/dist/plugins/registry/index.d.ts +1 -2
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +3 -3
- package/dist/plugins/request/index.d.ts +3 -4
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +2 -2
- package/dist/plugins/runAction/index.d.ts +8 -8
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +17 -6
- package/dist/plugins/tables/createTable/index.d.ts +3 -5
- package/dist/plugins/tables/createTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTable/index.js +3 -3
- package/dist/plugins/tables/createTableFields/index.d.ts +3 -5
- package/dist/plugins/tables/createTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTableFields/index.js +3 -3
- package/dist/plugins/tables/createTableRecords/index.d.ts +3 -5
- package/dist/plugins/tables/createTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/createTableRecords/index.js +3 -3
- package/dist/plugins/tables/deleteTable/index.d.ts +5 -5
- package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTable/index.js +4 -4
- package/dist/plugins/tables/deleteTableFields/index.d.ts +3 -5
- package/dist/plugins/tables/deleteTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableFields/index.js +3 -3
- package/dist/plugins/tables/deleteTableRecords/index.d.ts +3 -5
- package/dist/plugins/tables/deleteTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/deleteTableRecords/index.js +3 -3
- package/dist/plugins/tables/getTable/index.d.ts +3 -5
- package/dist/plugins/tables/getTable/index.d.ts.map +1 -1
- package/dist/plugins/tables/getTable/index.js +3 -3
- package/dist/plugins/tables/getTableRecord/index.d.ts +3 -5
- package/dist/plugins/tables/getTableRecord/index.d.ts.map +1 -1
- package/dist/plugins/tables/getTableRecord/index.js +3 -3
- package/dist/plugins/tables/listTableFields/index.d.ts +3 -5
- package/dist/plugins/tables/listTableFields/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTableFields/index.js +3 -3
- package/dist/plugins/tables/listTableRecords/index.d.ts +3 -3
- package/dist/plugins/tables/listTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTableRecords/index.js +3 -3
- package/dist/plugins/tables/listTables/index.d.ts +5 -3
- package/dist/plugins/tables/listTables/index.d.ts.map +1 -1
- package/dist/plugins/tables/listTables/index.js +4 -4
- package/dist/plugins/tables/updateTableRecords/index.d.ts +3 -5
- package/dist/plugins/tables/updateTableRecords/index.d.ts.map +1 -1
- package/dist/plugins/tables/updateTableRecords/index.js +3 -3
- package/dist/resolvers/connectionId.js +1 -1
- package/dist/resolvers/tableId.js +1 -1
- package/dist/sdk.d.ts +29 -257
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +33 -43
- package/dist/types/errors.d.ts +37 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +18 -0
- package/dist/types/plugin.d.ts +29 -48
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/plugin.js +7 -3
- package/dist/types/sdk.d.ts +9 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/sdk.js +20 -0
- package/dist/utils/open-approval.d.ts +2 -0
- package/dist/utils/open-approval.d.ts.map +1 -0
- package/dist/utils/open-approval.js +13 -0
- package/dist/utils/open-url.d.ts +3 -0
- package/dist/utils/open-url.d.ts.map +1 -0
- package/dist/utils/open-url.js +72 -0
- package/package.json +3 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { buildHttpRequestContext, buildActionRunContext } from '@zapier/policy-context';
|
|
2
3
|
import { ListAppsQuerySchema, AppItemSchema as AppItemSchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/apps';
|
|
3
4
|
import { ListConnectionsQuerySchema as ListConnectionsQuerySchema$1, ConnectionItemSchema as ConnectionItemSchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/connections';
|
|
4
5
|
import { ListClientCredentialsQuerySchema as ListClientCredentialsQuerySchema$1, CreateClientCredentialsRequestSchema, ClientCredentialsItemSchema as ClientCredentialsItemSchema$1, ClientCredentialsCreatedItemSchema as ClientCredentialsCreatedItemSchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/client-credentials';
|
|
@@ -56,6 +57,16 @@ function parseIntEnvVar(name) {
|
|
|
56
57
|
}
|
|
57
58
|
var ZAPIER_MAX_NETWORK_RETRIES = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRIES") ?? 3;
|
|
58
59
|
var ZAPIER_MAX_NETWORK_RETRY_DELAY_MS = parseIntEnvVar("ZAPIER_MAX_NETWORK_RETRY_DELAY_MS") ?? 6e4;
|
|
60
|
+
function getZapierIsInteractive() {
|
|
61
|
+
return globalThis.process?.env?.ZAPIER_IS_INTERACTIVE === "true";
|
|
62
|
+
}
|
|
63
|
+
function getZapierApprovalMode() {
|
|
64
|
+
const value = globalThis.process?.env?.ZAPIER_APPROVAL_MODE;
|
|
65
|
+
if (value === "poll" || value === "fail") return value;
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
var DEFAULT_APPROVAL_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
69
|
+
var DEFAULT_MAX_APPROVAL_RETRIES = 2;
|
|
59
70
|
|
|
60
71
|
// src/types/properties.ts
|
|
61
72
|
var AppKeyPropertySchema = withPositional(
|
|
@@ -224,6 +235,17 @@ var ZapierRateLimitError = class extends ZapierError {
|
|
|
224
235
|
this.retries = options.retries ?? 0;
|
|
225
236
|
}
|
|
226
237
|
};
|
|
238
|
+
var ZapierApprovalError = class extends ZapierError {
|
|
239
|
+
constructor(message, options = {}) {
|
|
240
|
+
super(message, options);
|
|
241
|
+
this.name = "ZapierApprovalError";
|
|
242
|
+
this.code = "ZAPIER_APPROVAL_ERROR";
|
|
243
|
+
this.approvalId = options.approvalId;
|
|
244
|
+
this.approvalStatus = options.status;
|
|
245
|
+
this.approvalUrl = options.approvalUrl;
|
|
246
|
+
this.pollUrl = options.pollUrl;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
227
249
|
var ZapierRelayError = class extends ZapierError {
|
|
228
250
|
constructor(message, options = {}) {
|
|
229
251
|
super(message, options);
|
|
@@ -268,6 +290,10 @@ ${context.join(", ")}`;
|
|
|
268
290
|
if (error instanceof ZapierBundleError && error.buildErrors && error.buildErrors.length > 0) {
|
|
269
291
|
message += "\n\nBuild errors:\n" + error.buildErrors.map((err) => ` \u2022 ${err}`).join("\n");
|
|
270
292
|
}
|
|
293
|
+
if (error instanceof ZapierApprovalError && error.approvalUrl) {
|
|
294
|
+
message += `
|
|
295
|
+
Approval URL: ${error.approvalUrl}`;
|
|
296
|
+
}
|
|
271
297
|
if (error instanceof ZapierRateLimitError) {
|
|
272
298
|
const { limit, remaining, retryAfterMs } = error.rateLimit;
|
|
273
299
|
const parts = [];
|
|
@@ -515,7 +541,7 @@ function createAppsProxy(options) {
|
|
|
515
541
|
});
|
|
516
542
|
return appsProxy;
|
|
517
543
|
}
|
|
518
|
-
var appsPlugin = (
|
|
544
|
+
var appsPlugin = (sdk) => {
|
|
519
545
|
return {
|
|
520
546
|
apps: createAppsProxy({ sdk }),
|
|
521
547
|
context: {
|
|
@@ -925,11 +951,11 @@ function buildAbortHandle({
|
|
|
925
951
|
}
|
|
926
952
|
var FetchInitSdkValidationSchema = z.looseObject(FetchInitZapierFieldsSchema.shape).optional();
|
|
927
953
|
var validateFetchInit = createValidator(FetchInitSdkValidationSchema);
|
|
928
|
-
var fetchPlugin = (
|
|
954
|
+
var fetchPlugin = (sdk) => {
|
|
929
955
|
return {
|
|
930
956
|
fetch: async function fetch2(url, init) {
|
|
931
957
|
return runWithTelemetryContext(async () => {
|
|
932
|
-
const { api } = context;
|
|
958
|
+
const { api } = sdk.context;
|
|
933
959
|
const startTime = Date.now();
|
|
934
960
|
const isNested = isTelemetryNested();
|
|
935
961
|
try {
|
|
@@ -948,7 +974,7 @@ var fetchPlugin = ({ context }) => {
|
|
|
948
974
|
connectionId,
|
|
949
975
|
connection,
|
|
950
976
|
authenticationId,
|
|
951
|
-
resolveConnection: context.resolveConnection,
|
|
977
|
+
resolveConnection: sdk.context.resolveConnection,
|
|
952
978
|
label: "fetch"
|
|
953
979
|
});
|
|
954
980
|
const relayPath = transformUrlToRelayPath(url);
|
|
@@ -975,18 +1001,27 @@ var fetchPlugin = ({ context }) => {
|
|
|
975
1001
|
if (maxTime !== void 0) {
|
|
976
1002
|
headers["X-Zapier-Sdk-Max-Time"] = String(maxTime);
|
|
977
1003
|
}
|
|
1004
|
+
const upstreamUrl = new URL(url).toString();
|
|
1005
|
+
const method = (fetchInit.method ?? "GET").toUpperCase();
|
|
978
1006
|
const abortHandle = buildAbortHandle({
|
|
979
1007
|
maxTimeSeconds: maxTime,
|
|
980
1008
|
callerSignal: fetchInit.signal
|
|
981
1009
|
});
|
|
982
1010
|
try {
|
|
983
1011
|
const result = await api.fetch(relayPath, {
|
|
984
|
-
method
|
|
1012
|
+
method,
|
|
985
1013
|
body: fetchInit.body,
|
|
986
1014
|
headers,
|
|
987
1015
|
redirect: fetchInit.redirect,
|
|
988
1016
|
signal: abortHandle?.signal,
|
|
989
|
-
authRequired: true
|
|
1017
|
+
authRequired: true,
|
|
1018
|
+
approvalContext: () => buildHttpRequestContext({
|
|
1019
|
+
method,
|
|
1020
|
+
url: upstreamUrl,
|
|
1021
|
+
headers,
|
|
1022
|
+
body: typeof fetchInit.body === "string" ? fetchInit.body : void 0,
|
|
1023
|
+
connection_id: resolvedConnectionId ? String(resolvedConnectionId) : void 0
|
|
1024
|
+
})
|
|
990
1025
|
});
|
|
991
1026
|
const relayError = result.headers.get("x-relay-error");
|
|
992
1027
|
if (relayError) {
|
|
@@ -995,7 +1030,7 @@ var fetchPlugin = ({ context }) => {
|
|
|
995
1030
|
});
|
|
996
1031
|
}
|
|
997
1032
|
if (!isNested) {
|
|
998
|
-
context.eventEmission.emitMethodCalled({
|
|
1033
|
+
sdk.context.eventEmission.emitMethodCalled({
|
|
999
1034
|
method_name: "fetch",
|
|
1000
1035
|
execution_duration_ms: Date.now() - startTime,
|
|
1001
1036
|
success_flag: true,
|
|
@@ -1017,7 +1052,7 @@ var fetchPlugin = ({ context }) => {
|
|
|
1017
1052
|
}
|
|
1018
1053
|
} catch (error) {
|
|
1019
1054
|
if (!isNested) {
|
|
1020
|
-
context.eventEmission.emitMethodCalled({
|
|
1055
|
+
sdk.context.eventEmission.emitMethodCalled({
|
|
1021
1056
|
method_name: "fetch",
|
|
1022
1057
|
execution_duration_ms: Date.now() - startTime,
|
|
1023
1058
|
success_flag: false,
|
|
@@ -1581,9 +1616,9 @@ function createTelemetryCallback(emitMethodCalled, methodName) {
|
|
|
1581
1616
|
}
|
|
1582
1617
|
|
|
1583
1618
|
// src/plugins/listApps/index.ts
|
|
1584
|
-
var listAppsPlugin = (
|
|
1619
|
+
var listAppsPlugin = (sdk) => {
|
|
1585
1620
|
async function listAppsPage(options) {
|
|
1586
|
-
const { api, resolveAppKeys: resolveAppKeys2 } = context;
|
|
1621
|
+
const { api, resolveAppKeys: resolveAppKeys2 } = sdk.context;
|
|
1587
1622
|
const appKeys = options.apps ?? options.appKeys ?? [];
|
|
1588
1623
|
const appLocators = await resolveAppKeys2({
|
|
1589
1624
|
appKeys: [...appKeys]
|
|
@@ -1627,7 +1662,10 @@ var listAppsPlugin = ({ context }) => {
|
|
|
1627
1662
|
const listAppsDefinition = createPaginatedFunction(
|
|
1628
1663
|
listAppsPage,
|
|
1629
1664
|
ListAppsSchema,
|
|
1630
|
-
createTelemetryCallback(
|
|
1665
|
+
createTelemetryCallback(
|
|
1666
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
1667
|
+
methodName
|
|
1668
|
+
),
|
|
1631
1669
|
methodName,
|
|
1632
1670
|
DEFAULT_PAGE_SIZE
|
|
1633
1671
|
);
|
|
@@ -2068,7 +2106,7 @@ var actionKeyResolver = {
|
|
|
2068
2106
|
|
|
2069
2107
|
// src/resolvers/connectionId.ts
|
|
2070
2108
|
async function fetchConnections(sdk, resolvedParams) {
|
|
2071
|
-
const context = sdk.
|
|
2109
|
+
const context = sdk.context;
|
|
2072
2110
|
const includeShared = await context.hasCapability?.(
|
|
2073
2111
|
"canIncludeSharedConnections"
|
|
2074
2112
|
);
|
|
@@ -2236,7 +2274,7 @@ var tableIdResolver = {
|
|
|
2236
2274
|
type: "dynamic",
|
|
2237
2275
|
requireCapabilities: ["canIncludeSharedTables"],
|
|
2238
2276
|
fetch: async (sdk) => {
|
|
2239
|
-
const context = sdk.
|
|
2277
|
+
const context = sdk.context;
|
|
2240
2278
|
const includeShared = await context.hasCapability?.(
|
|
2241
2279
|
"canIncludeSharedTables"
|
|
2242
2280
|
);
|
|
@@ -2876,7 +2914,7 @@ var tableSortResolver = {
|
|
|
2876
2914
|
};
|
|
2877
2915
|
|
|
2878
2916
|
// src/plugins/listActions/index.ts
|
|
2879
|
-
var listActionsPlugin = (
|
|
2917
|
+
var listActionsPlugin = (sdk) => {
|
|
2880
2918
|
const methodMeta = {
|
|
2881
2919
|
categories: ["action"],
|
|
2882
2920
|
type: "list",
|
|
@@ -2889,7 +2927,7 @@ var listActionsPlugin = ({ context }) => {
|
|
|
2889
2927
|
}
|
|
2890
2928
|
};
|
|
2891
2929
|
async function listActionsPage(options) {
|
|
2892
|
-
const { api, getVersionedImplementationId } = context;
|
|
2930
|
+
const { api, getVersionedImplementationId } = sdk.context;
|
|
2893
2931
|
const appKey = "app" in options ? options.app : options.appKey;
|
|
2894
2932
|
const selectedApi = await getVersionedImplementationId(appKey);
|
|
2895
2933
|
if (!selectedApi) {
|
|
@@ -2954,7 +2992,10 @@ var listActionsPlugin = ({ context }) => {
|
|
|
2954
2992
|
const listActionsDefinition = createPaginatedFunction(
|
|
2955
2993
|
listActionsPage,
|
|
2956
2994
|
ListActionsInputSchema,
|
|
2957
|
-
createTelemetryCallback(
|
|
2995
|
+
createTelemetryCallback(
|
|
2996
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
2997
|
+
methodName
|
|
2998
|
+
),
|
|
2958
2999
|
methodName,
|
|
2959
3000
|
DEFAULT_PAGE_SIZE
|
|
2960
3001
|
);
|
|
@@ -3277,9 +3318,9 @@ function transformNeedsToFields(needs) {
|
|
|
3277
3318
|
}
|
|
3278
3319
|
return rootFields;
|
|
3279
3320
|
}
|
|
3280
|
-
var listInputFieldsPlugin = (
|
|
3321
|
+
var listInputFieldsPlugin = (sdk) => {
|
|
3281
3322
|
async function listInputFieldsPage(options) {
|
|
3282
|
-
const { api, getVersionedImplementationId } = context;
|
|
3323
|
+
const { api, getVersionedImplementationId } = sdk.context;
|
|
3283
3324
|
const appKey = "app" in options ? options.app : options.appKey;
|
|
3284
3325
|
const actionKey = "action" in options ? options.action : options.actionKey;
|
|
3285
3326
|
const { actionType, connection, connectionId, authenticationId, inputs } = options;
|
|
@@ -3287,7 +3328,7 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
3287
3328
|
connection,
|
|
3288
3329
|
connectionId,
|
|
3289
3330
|
authenticationId,
|
|
3290
|
-
resolveConnection: context.resolveConnection
|
|
3331
|
+
resolveConnection: sdk.context.resolveConnection
|
|
3291
3332
|
});
|
|
3292
3333
|
const selectedApi = await getVersionedImplementationId(appKey);
|
|
3293
3334
|
if (!selectedApi) {
|
|
@@ -3325,7 +3366,10 @@ var listInputFieldsPlugin = ({ sdk, context }) => {
|
|
|
3325
3366
|
const listInputFieldsDefinition = createPaginatedFunction(
|
|
3326
3367
|
listInputFieldsPage,
|
|
3327
3368
|
ListInputFieldsInputSchema,
|
|
3328
|
-
createTelemetryCallback(
|
|
3369
|
+
createTelemetryCallback(
|
|
3370
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3371
|
+
methodName
|
|
3372
|
+
),
|
|
3329
3373
|
methodName,
|
|
3330
3374
|
DEFAULT_PAGE_SIZE
|
|
3331
3375
|
);
|
|
@@ -3428,12 +3472,12 @@ var ConnectionItemSchema = withFormatter(ConnectionItemSchema$1, {
|
|
|
3428
3472
|
});
|
|
3429
3473
|
|
|
3430
3474
|
// src/plugins/listConnections/index.ts
|
|
3431
|
-
var listConnectionsPlugin = (
|
|
3475
|
+
var listConnectionsPlugin = (sdk) => {
|
|
3432
3476
|
async function listConnectionsPage(options) {
|
|
3433
3477
|
if (options.includeShared) {
|
|
3434
|
-
await context.checkCapability("canIncludeSharedConnections");
|
|
3478
|
+
await sdk.context.checkCapability("canIncludeSharedConnections");
|
|
3435
3479
|
}
|
|
3436
|
-
const { api, getVersionedImplementationId } = context;
|
|
3480
|
+
const { api, getVersionedImplementationId } = sdk.context;
|
|
3437
3481
|
const searchParams = {};
|
|
3438
3482
|
if (options.pageSize !== void 0) {
|
|
3439
3483
|
searchParams.page_size = options.pageSize.toString();
|
|
@@ -3456,7 +3500,7 @@ var listConnectionsPlugin = ({ context }) => {
|
|
|
3456
3500
|
connectionRefs.map(
|
|
3457
3501
|
(ref) => resolveConnectionId({
|
|
3458
3502
|
connection: ref,
|
|
3459
|
-
resolveConnection: context.resolveConnection
|
|
3503
|
+
resolveConnection: sdk.context.resolveConnection
|
|
3460
3504
|
})
|
|
3461
3505
|
)
|
|
3462
3506
|
);
|
|
@@ -3522,7 +3566,10 @@ var listConnectionsPlugin = ({ context }) => {
|
|
|
3522
3566
|
const listConnectionsDefinition = createPaginatedFunction(
|
|
3523
3567
|
listConnectionsPage,
|
|
3524
3568
|
ListConnectionsQuerySchema,
|
|
3525
|
-
createTelemetryCallback(
|
|
3569
|
+
createTelemetryCallback(
|
|
3570
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3571
|
+
methodName
|
|
3572
|
+
),
|
|
3526
3573
|
methodName,
|
|
3527
3574
|
DEFAULT_PAGE_SIZE
|
|
3528
3575
|
);
|
|
@@ -3598,9 +3645,9 @@ var ClientCredentialsCreatedItemSchema = withFormatter(
|
|
|
3598
3645
|
);
|
|
3599
3646
|
|
|
3600
3647
|
// src/plugins/listClientCredentials/index.ts
|
|
3601
|
-
var listClientCredentialsPlugin = (
|
|
3648
|
+
var listClientCredentialsPlugin = (sdk) => {
|
|
3602
3649
|
async function listClientCredentialsPage(options) {
|
|
3603
|
-
const { api } = context;
|
|
3650
|
+
const { api } = sdk.context;
|
|
3604
3651
|
const searchParams = {};
|
|
3605
3652
|
if (options.pageSize !== void 0) {
|
|
3606
3653
|
searchParams.pageSize = options.pageSize.toString();
|
|
@@ -3637,7 +3684,10 @@ var listClientCredentialsPlugin = ({ context }) => {
|
|
|
3637
3684
|
const listClientCredentialsDefinition = createPaginatedFunction(
|
|
3638
3685
|
listClientCredentialsPage,
|
|
3639
3686
|
ListClientCredentialsQuerySchema,
|
|
3640
|
-
createTelemetryCallback(
|
|
3687
|
+
createTelemetryCallback(
|
|
3688
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3689
|
+
methodName
|
|
3690
|
+
),
|
|
3641
3691
|
methodName,
|
|
3642
3692
|
DEFAULT_PAGE_SIZE
|
|
3643
3693
|
);
|
|
@@ -3657,18 +3707,21 @@ var listClientCredentialsPlugin = ({ context }) => {
|
|
|
3657
3707
|
};
|
|
3658
3708
|
};
|
|
3659
3709
|
var CreateClientCredentialsSchema = CreateClientCredentialsRequestSchema.omit({ allowed_scopes: true }).extend({
|
|
3660
|
-
allowedScopes: z.array(z.enum(["credentials", "external"])).default(["external"]).describe("Scopes to allow for these credentials")
|
|
3710
|
+
allowedScopes: z.array(z.enum(["credentials", "external"])).default(["external"]).describe("Scopes to allow for these credentials"),
|
|
3711
|
+
// Temporarily hidden while we finalise work to make approvals/policies customer-facing.
|
|
3712
|
+
policy: z.record(z.string(), z.unknown()).optional().describe("Policy document (JSON) to attach to the credentials").meta({ deprecated: true })
|
|
3661
3713
|
}).describe("Create new client credentials for the authenticated user");
|
|
3662
3714
|
|
|
3663
3715
|
// src/plugins/createClientCredentials/index.ts
|
|
3664
|
-
var createClientCredentialsPlugin = (
|
|
3716
|
+
var createClientCredentialsPlugin = (sdk) => {
|
|
3665
3717
|
async function createClientCredentials(options) {
|
|
3666
|
-
const { api } = context;
|
|
3718
|
+
const { api } = sdk.context;
|
|
3667
3719
|
const response = await api.post(
|
|
3668
3720
|
"/api/v0/client-credentials",
|
|
3669
3721
|
{
|
|
3670
3722
|
name: options.name,
|
|
3671
|
-
allowed_scopes: options.allowedScopes
|
|
3723
|
+
allowed_scopes: options.allowedScopes,
|
|
3724
|
+
...options.policy && { policy: options.policy }
|
|
3672
3725
|
},
|
|
3673
3726
|
{
|
|
3674
3727
|
customErrorHandler: ({ status }) => {
|
|
@@ -3698,7 +3751,7 @@ var createClientCredentialsPlugin = ({ context }) => {
|
|
|
3698
3751
|
createClientCredentials,
|
|
3699
3752
|
CreateClientCredentialsSchema,
|
|
3700
3753
|
createTelemetryCallback(
|
|
3701
|
-
context.eventEmission.emitMethodCalled,
|
|
3754
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3702
3755
|
createClientCredentials.name
|
|
3703
3756
|
)
|
|
3704
3757
|
);
|
|
@@ -3726,9 +3779,9 @@ var DeleteClientCredentialsSchema = z.object({
|
|
|
3726
3779
|
}).describe("Delete client credentials by client ID");
|
|
3727
3780
|
|
|
3728
3781
|
// src/plugins/deleteClientCredentials/index.ts
|
|
3729
|
-
var deleteClientCredentialsPlugin = (
|
|
3782
|
+
var deleteClientCredentialsPlugin = (sdk) => {
|
|
3730
3783
|
async function deleteClientCredentials(options) {
|
|
3731
|
-
const { api } = context;
|
|
3784
|
+
const { api } = sdk.context;
|
|
3732
3785
|
await api.delete(
|
|
3733
3786
|
`/api/v0/client-credentials/${options.clientId}`,
|
|
3734
3787
|
void 0,
|
|
@@ -3760,7 +3813,7 @@ var deleteClientCredentialsPlugin = ({ context }) => {
|
|
|
3760
3813
|
deleteClientCredentials,
|
|
3761
3814
|
DeleteClientCredentialsSchema,
|
|
3762
3815
|
createTelemetryCallback(
|
|
3763
|
-
context.eventEmission.emitMethodCalled,
|
|
3816
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3764
3817
|
deleteClientCredentials.name
|
|
3765
3818
|
)
|
|
3766
3819
|
);
|
|
@@ -3791,7 +3844,7 @@ var GetAppSchemaDeprecated = z.object({
|
|
|
3791
3844
|
var GetAppInputSchema = z.union([GetAppSchema, GetAppSchemaDeprecated]).describe(GetAppDescription);
|
|
3792
3845
|
|
|
3793
3846
|
// src/plugins/getApp/index.ts
|
|
3794
|
-
var getAppPlugin = (
|
|
3847
|
+
var getAppPlugin = (sdk) => {
|
|
3795
3848
|
async function getApp(options) {
|
|
3796
3849
|
const appKey = "app" in options ? options.app : options.appKey;
|
|
3797
3850
|
const appsIterable = sdk.listApps({
|
|
@@ -3810,7 +3863,7 @@ var getAppPlugin = ({ sdk, context }) => {
|
|
|
3810
3863
|
getApp,
|
|
3811
3864
|
GetAppInputSchema,
|
|
3812
3865
|
createTelemetryCallback(
|
|
3813
|
-
context.eventEmission.emitMethodCalled,
|
|
3866
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3814
3867
|
getApp.name
|
|
3815
3868
|
)
|
|
3816
3869
|
);
|
|
@@ -3846,7 +3899,7 @@ var GetActionSchemaDeprecated = z.object({
|
|
|
3846
3899
|
var GetActionInputSchema = z.union([GetActionSchema, GetActionSchemaDeprecated]).describe(GetActionDescription);
|
|
3847
3900
|
|
|
3848
3901
|
// src/plugins/getAction/index.ts
|
|
3849
|
-
var getActionPlugin = (
|
|
3902
|
+
var getActionPlugin = (sdk) => {
|
|
3850
3903
|
async function getAction(options) {
|
|
3851
3904
|
const appKey = "app" in options ? options.app : options.appKey;
|
|
3852
3905
|
const actionKey = "action" in options ? options.action : options.actionKey;
|
|
@@ -3869,7 +3922,7 @@ var getActionPlugin = ({ sdk, context }) => {
|
|
|
3869
3922
|
getAction,
|
|
3870
3923
|
GetActionInputSchema,
|
|
3871
3924
|
createTelemetryCallback(
|
|
3872
|
-
context.eventEmission.emitMethodCalled,
|
|
3925
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3873
3926
|
getAction.name
|
|
3874
3927
|
)
|
|
3875
3928
|
);
|
|
@@ -3906,9 +3959,9 @@ var GetConnectionParamSchema = z.object({
|
|
|
3906
3959
|
});
|
|
3907
3960
|
|
|
3908
3961
|
// src/plugins/getConnection/index.ts
|
|
3909
|
-
var getConnectionPlugin = (
|
|
3962
|
+
var getConnectionPlugin = (sdk) => {
|
|
3910
3963
|
async function getConnection(options) {
|
|
3911
|
-
const { api } = context;
|
|
3964
|
+
const { api } = sdk.context;
|
|
3912
3965
|
const resolvedConnectionId = options.connection ?? options.connectionId ?? options.authenticationId;
|
|
3913
3966
|
if (!resolvedConnectionId) {
|
|
3914
3967
|
throw new Error("connection is required");
|
|
@@ -3925,7 +3978,7 @@ var getConnectionPlugin = ({ context }) => {
|
|
|
3925
3978
|
getConnection,
|
|
3926
3979
|
GetConnectionParamSchema,
|
|
3927
3980
|
createTelemetryCallback(
|
|
3928
|
-
context.eventEmission.emitMethodCalled,
|
|
3981
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3929
3982
|
getConnection.name
|
|
3930
3983
|
)
|
|
3931
3984
|
);
|
|
@@ -3959,7 +4012,7 @@ var FindFirstConnectionSchema = ListConnectionsQuerySchema.omit({
|
|
|
3959
4012
|
}).describe("Find the first connection matching the criteria");
|
|
3960
4013
|
|
|
3961
4014
|
// src/plugins/findFirstConnection/index.ts
|
|
3962
|
-
var findFirstConnectionPlugin = (
|
|
4015
|
+
var findFirstConnectionPlugin = (sdk) => {
|
|
3963
4016
|
async function findFirstConnection(options = {}) {
|
|
3964
4017
|
const connectionsResponse = await sdk.listConnections({
|
|
3965
4018
|
...options,
|
|
@@ -3979,7 +4032,7 @@ var findFirstConnectionPlugin = ({ sdk, context }) => {
|
|
|
3979
4032
|
findFirstConnection,
|
|
3980
4033
|
FindFirstConnectionSchema,
|
|
3981
4034
|
createTelemetryCallback(
|
|
3982
|
-
context.eventEmission.emitMethodCalled,
|
|
4035
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
3983
4036
|
findFirstConnection.name
|
|
3984
4037
|
)
|
|
3985
4038
|
);
|
|
@@ -4010,7 +4063,7 @@ var FindUniqueConnectionSchema = ListConnectionsQuerySchema.omit({
|
|
|
4010
4063
|
}).describe("Find a unique connection matching the criteria");
|
|
4011
4064
|
|
|
4012
4065
|
// src/plugins/findUniqueConnection/index.ts
|
|
4013
|
-
var findUniqueConnectionPlugin = (
|
|
4066
|
+
var findUniqueConnectionPlugin = (sdk) => {
|
|
4014
4067
|
async function findUniqueConnection(options = {}) {
|
|
4015
4068
|
const connectionsResponse = await sdk.listConnections({
|
|
4016
4069
|
...options,
|
|
@@ -4036,7 +4089,7 @@ var findUniqueConnectionPlugin = ({ sdk, context }) => {
|
|
|
4036
4089
|
findUniqueConnection,
|
|
4037
4090
|
FindUniqueConnectionSchema,
|
|
4038
4091
|
createTelemetryCallback(
|
|
4039
|
-
context.eventEmission.emitMethodCalled,
|
|
4092
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
4040
4093
|
findUniqueConnection.name
|
|
4041
4094
|
)
|
|
4042
4095
|
);
|
|
@@ -4091,8 +4144,6 @@ var RunActionSchemaDeprecated = z.object({
|
|
|
4091
4144
|
actionKey: ActionKeyPropertySchema
|
|
4092
4145
|
}).merge(RunActionBaseSchema);
|
|
4093
4146
|
var RunActionInputSchema = z.union([RunActionSchema, RunActionSchemaDeprecated]).describe(RunActionDescription);
|
|
4094
|
-
|
|
4095
|
-
// src/plugins/runAction/index.ts
|
|
4096
4147
|
async function executeAction(actionOptions) {
|
|
4097
4148
|
const {
|
|
4098
4149
|
api,
|
|
@@ -4123,7 +4174,18 @@ async function executeAction(actionOptions) {
|
|
|
4123
4174
|
};
|
|
4124
4175
|
const runData = await api.post(
|
|
4125
4176
|
"/zapier/api/actions/v1/runs",
|
|
4126
|
-
runRequest
|
|
4177
|
+
runRequest,
|
|
4178
|
+
{
|
|
4179
|
+
approvalContext: () => buildActionRunContext({
|
|
4180
|
+
selected_api: selectedApi,
|
|
4181
|
+
action_type: actionType,
|
|
4182
|
+
action_key: actionKey,
|
|
4183
|
+
connection_id: connectionId != null ? String(connectionId) : void 0,
|
|
4184
|
+
// Cast: inputs is Record<string, unknown> at the SDK surface, but
|
|
4185
|
+
// buildActionRunContext coerces to JsonValue at runtime via zod.
|
|
4186
|
+
inputs: executionOptions.inputs ?? {}
|
|
4187
|
+
})
|
|
4188
|
+
}
|
|
4127
4189
|
);
|
|
4128
4190
|
const runId = runData.data.id;
|
|
4129
4191
|
return await api.poll(`/zapier/api/actions/v1/runs/${runId}`, {
|
|
@@ -4139,7 +4201,7 @@ async function executeAction(actionOptions) {
|
|
|
4139
4201
|
}
|
|
4140
4202
|
var CONTEXT_CACHE_TTL_MS = 6e4;
|
|
4141
4203
|
var CONTEXT_CACHE_MAX_SIZE = 500;
|
|
4142
|
-
var runActionPlugin = (
|
|
4204
|
+
var runActionPlugin = (sdk) => {
|
|
4143
4205
|
const runActionContextCache = /* @__PURE__ */ new Map();
|
|
4144
4206
|
function evictIfNeeded() {
|
|
4145
4207
|
if (runActionContextCache.size < CONTEXT_CACHE_MAX_SIZE) return;
|
|
@@ -4183,7 +4245,7 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
4183
4245
|
}
|
|
4184
4246
|
async function resolveRunActionContext(options) {
|
|
4185
4247
|
const { appKey, actionKey, actionType } = options;
|
|
4186
|
-
const selectedApi = await context.getVersionedImplementationId(appKey);
|
|
4248
|
+
const selectedApi = await sdk.context.getVersionedImplementationId(appKey);
|
|
4187
4249
|
if (!selectedApi) {
|
|
4188
4250
|
throw new ZapierConfigurationError(
|
|
4189
4251
|
"No current_implementation_id found for app",
|
|
@@ -4203,7 +4265,7 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
4203
4265
|
return { selectedApi, actionId: actionData.data.id };
|
|
4204
4266
|
}
|
|
4205
4267
|
async function runActionPage(options) {
|
|
4206
|
-
const { api } = context;
|
|
4268
|
+
const { api } = sdk.context;
|
|
4207
4269
|
const appKey = "app" in options ? options.app : options.appKey;
|
|
4208
4270
|
const actionKey = "action" in options ? options.action : options.actionKey;
|
|
4209
4271
|
const {
|
|
@@ -4219,7 +4281,7 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
4219
4281
|
connectionId,
|
|
4220
4282
|
connection,
|
|
4221
4283
|
authenticationId,
|
|
4222
|
-
resolveConnection: context.resolveConnection
|
|
4284
|
+
resolveConnection: sdk.context.resolveConnection
|
|
4223
4285
|
});
|
|
4224
4286
|
const { selectedApi, actionId } = await getRunActionContext({
|
|
4225
4287
|
appKey,
|
|
@@ -4262,7 +4324,10 @@ var runActionPlugin = ({ sdk, context }) => {
|
|
|
4262
4324
|
const runActionDefinition = createPaginatedFunction(
|
|
4263
4325
|
runActionPage,
|
|
4264
4326
|
RunActionInputSchema,
|
|
4265
|
-
createTelemetryCallback(
|
|
4327
|
+
createTelemetryCallback(
|
|
4328
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
4329
|
+
methodName
|
|
4330
|
+
),
|
|
4266
4331
|
methodName
|
|
4267
4332
|
);
|
|
4268
4333
|
return {
|
|
@@ -4322,7 +4387,7 @@ function resetDeprecationWarnings() {
|
|
|
4322
4387
|
}
|
|
4323
4388
|
|
|
4324
4389
|
// src/plugins/request/index.ts
|
|
4325
|
-
var requestPlugin = (
|
|
4390
|
+
var requestPlugin = (sdk) => {
|
|
4326
4391
|
async function request(options) {
|
|
4327
4392
|
logDeprecation("request() is deprecated. Use fetch() instead.");
|
|
4328
4393
|
const {
|
|
@@ -4347,7 +4412,7 @@ var requestPlugin = ({ sdk, context }) => {
|
|
|
4347
4412
|
request,
|
|
4348
4413
|
RelayRequestSchema,
|
|
4349
4414
|
createTelemetryCallback(
|
|
4350
|
-
context.eventEmission.emitMethodCalled,
|
|
4415
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
4351
4416
|
request.name
|
|
4352
4417
|
)
|
|
4353
4418
|
);
|
|
@@ -4656,9 +4721,8 @@ async function resolveAppKeys({
|
|
|
4656
4721
|
});
|
|
4657
4722
|
return slugResolvedLocators.filter(isResolvedAppLocator);
|
|
4658
4723
|
}
|
|
4659
|
-
var manifestPlugin = (
|
|
4660
|
-
const {
|
|
4661
|
-
const { api, options } = context;
|
|
4724
|
+
var manifestPlugin = (sdk) => {
|
|
4725
|
+
const { api, options } = sdk.context;
|
|
4662
4726
|
const { manifestPath = DEFAULT_CONFIG_PATH, manifest } = options || {};
|
|
4663
4727
|
let resolvedManifest;
|
|
4664
4728
|
async function resolveManifest() {
|
|
@@ -4869,9 +4933,9 @@ var UserProfileItemSchema = withFormatter(
|
|
|
4869
4933
|
);
|
|
4870
4934
|
|
|
4871
4935
|
// src/plugins/getProfile/index.ts
|
|
4872
|
-
var getProfilePlugin = (
|
|
4936
|
+
var getProfilePlugin = (sdk) => {
|
|
4873
4937
|
async function getProfile() {
|
|
4874
|
-
const profile = await context.api.get(
|
|
4938
|
+
const profile = await sdk.context.api.get(
|
|
4875
4939
|
"/zapier/api/v4/profile/",
|
|
4876
4940
|
{
|
|
4877
4941
|
authRequired: true
|
|
@@ -4893,7 +4957,7 @@ var getProfilePlugin = ({ context }) => {
|
|
|
4893
4957
|
getProfile,
|
|
4894
4958
|
GetProfileSchema,
|
|
4895
4959
|
createTelemetryCallback(
|
|
4896
|
-
context.eventEmission.emitMethodCalled,
|
|
4960
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
4897
4961
|
getProfile.name
|
|
4898
4962
|
)
|
|
4899
4963
|
);
|
|
@@ -5670,7 +5734,89 @@ async function invalidateCredentialsToken(options) {
|
|
|
5670
5734
|
}
|
|
5671
5735
|
}
|
|
5672
5736
|
|
|
5673
|
-
// src/
|
|
5737
|
+
// src/utils/open-url.ts
|
|
5738
|
+
var nodePrefix = "node:";
|
|
5739
|
+
async function loadChildProcess() {
|
|
5740
|
+
return import(`${nodePrefix}child_process`);
|
|
5741
|
+
}
|
|
5742
|
+
async function loadProcess() {
|
|
5743
|
+
return import(`${nodePrefix}process`);
|
|
5744
|
+
}
|
|
5745
|
+
var openUrl = async (url) => {
|
|
5746
|
+
if (typeof url !== "string") {
|
|
5747
|
+
throw new TypeError("Expected `url` to be a string");
|
|
5748
|
+
}
|
|
5749
|
+
let parsed;
|
|
5750
|
+
try {
|
|
5751
|
+
parsed = new URL(url);
|
|
5752
|
+
} catch {
|
|
5753
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
5754
|
+
}
|
|
5755
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
5756
|
+
throw new Error(`Refusing to open non-http(s) URL: ${parsed.protocol}`);
|
|
5757
|
+
}
|
|
5758
|
+
const target = parsed.toString();
|
|
5759
|
+
if (typeof globalThis.window !== "undefined" && typeof globalThis.window.open === "function") {
|
|
5760
|
+
globalThis.window.open(target, "_blank", "noopener");
|
|
5761
|
+
return;
|
|
5762
|
+
}
|
|
5763
|
+
let spawn;
|
|
5764
|
+
let platform;
|
|
5765
|
+
try {
|
|
5766
|
+
const [cp, proc] = await Promise.all([loadChildProcess(), loadProcess()]);
|
|
5767
|
+
spawn = cp.spawn;
|
|
5768
|
+
platform = proc.platform;
|
|
5769
|
+
} catch {
|
|
5770
|
+
throw new Error(
|
|
5771
|
+
"openUrl: no supported runtime. window.open is unavailable and node:child_process could not be loaded."
|
|
5772
|
+
);
|
|
5773
|
+
}
|
|
5774
|
+
if (typeof spawn !== "function") {
|
|
5775
|
+
throw new Error(
|
|
5776
|
+
"openUrl: child_process.spawn is not available in this runtime"
|
|
5777
|
+
);
|
|
5778
|
+
}
|
|
5779
|
+
let command;
|
|
5780
|
+
let args;
|
|
5781
|
+
if (platform === "darwin") {
|
|
5782
|
+
command = "open";
|
|
5783
|
+
args = [target];
|
|
5784
|
+
} else if (platform === "win32") {
|
|
5785
|
+
command = "rundll32";
|
|
5786
|
+
args = ["url.dll,FileProtocolHandler", target];
|
|
5787
|
+
} else {
|
|
5788
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
5789
|
+
}
|
|
5790
|
+
const child = spawn(command, args, {
|
|
5791
|
+
stdio: "ignore",
|
|
5792
|
+
detached: true,
|
|
5793
|
+
windowsHide: true
|
|
5794
|
+
});
|
|
5795
|
+
child.once("error", () => {
|
|
5796
|
+
});
|
|
5797
|
+
child.unref();
|
|
5798
|
+
};
|
|
5799
|
+
var open_url_default = openUrl;
|
|
5800
|
+
|
|
5801
|
+
// src/utils/open-approval.ts
|
|
5802
|
+
async function openApproval(url) {
|
|
5803
|
+
console.error(`Approval required. Opening browser: ${url}`);
|
|
5804
|
+
try {
|
|
5805
|
+
await open_url_default(url);
|
|
5806
|
+
} catch {
|
|
5807
|
+
}
|
|
5808
|
+
}
|
|
5809
|
+
var ApprovalStatusSchema = z.enum(["pending_approval", "approved", "denied"]);
|
|
5810
|
+
var CreateApprovalResponseSchema = z.object({
|
|
5811
|
+
status: ApprovalStatusSchema,
|
|
5812
|
+
approval_id: z.string(),
|
|
5813
|
+
approval_url: z.string().url(),
|
|
5814
|
+
poll_url: z.string().url()
|
|
5815
|
+
});
|
|
5816
|
+
var PollApprovalResponseSchema = z.object({
|
|
5817
|
+
status: ApprovalStatusSchema,
|
|
5818
|
+
approval_id: z.string()
|
|
5819
|
+
});
|
|
5674
5820
|
function parseRateLimitHeaders(response) {
|
|
5675
5821
|
const info = {};
|
|
5676
5822
|
const retryAfter = response.headers.get("retry-after");
|
|
@@ -5731,16 +5877,23 @@ var pathConfig = {
|
|
|
5731
5877
|
var ZapierApiClient = class {
|
|
5732
5878
|
constructor(options) {
|
|
5733
5879
|
this.options = options;
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5880
|
+
/**
|
|
5881
|
+
* Perform a request against an already-resolved URL.
|
|
5882
|
+
*
|
|
5883
|
+
* Does auth, header merging, and 429 retry — all the cross-cutting
|
|
5884
|
+
* concerns that every Zapier-bound HTTP call needs. Callers that have a
|
|
5885
|
+
* path (e.g. `/relay/...`) should use `rawFetch` instead, which does
|
|
5886
|
+
* path → URL resolution and delegates here.
|
|
5887
|
+
*
|
|
5888
|
+
* Exposed as a separate helper so call sites with a server-supplied
|
|
5889
|
+
* absolute URL (e.g. an approval poll URL) can still share the same
|
|
5890
|
+
* auth/retry pipeline instead of reaching for `this.options.fetch`
|
|
5891
|
+
* directly and drifting.
|
|
5892
|
+
*/
|
|
5893
|
+
this.rawFetchUrl = async (url, init, pathConfig2) => {
|
|
5740
5894
|
if (init?.body && (isPlainObject(init.body) || Array.isArray(init.body))) {
|
|
5741
5895
|
init.body = JSON.stringify(init.body);
|
|
5742
5896
|
}
|
|
5743
|
-
const { url, pathConfig: pathConfig2 } = this.buildUrl(path, init?.searchParams);
|
|
5744
5897
|
const builtHeaders = await this.buildHeaders(
|
|
5745
5898
|
init,
|
|
5746
5899
|
pathConfig2
|
|
@@ -5759,30 +5912,114 @@ var ZapierApiClient = class {
|
|
|
5759
5912
|
...init,
|
|
5760
5913
|
headers: mergedHeaders
|
|
5761
5914
|
});
|
|
5762
|
-
if (response.status
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5915
|
+
if (response.status !== 429) {
|
|
5916
|
+
return response;
|
|
5917
|
+
}
|
|
5918
|
+
const rateLimitInfo = parseRateLimitHeaders(response);
|
|
5919
|
+
const delayMs = rateLimitInfo.retryAfterMs ?? calculateExponentialBackoffMs(retries + 1);
|
|
5920
|
+
if (delayMs > this.maxNetworkRetryDelayMs || retries >= this.maxNetworkRetries) {
|
|
5921
|
+
throw new ZapierRateLimitError("Rate limited", {
|
|
5922
|
+
statusCode: 429,
|
|
5923
|
+
rateLimit: rateLimitInfo,
|
|
5924
|
+
retries
|
|
5925
|
+
});
|
|
5926
|
+
}
|
|
5927
|
+
retries++;
|
|
5928
|
+
this.emitEvent("api:rate_limit_retry", {
|
|
5929
|
+
retry: retries,
|
|
5930
|
+
maxNetworkRetries: this.maxNetworkRetries,
|
|
5931
|
+
delayMs,
|
|
5932
|
+
path: url,
|
|
5933
|
+
method: init?.method ?? "GET",
|
|
5934
|
+
rateLimit: rateLimitInfo
|
|
5935
|
+
});
|
|
5936
|
+
await sleep(delayMs);
|
|
5937
|
+
}
|
|
5938
|
+
};
|
|
5939
|
+
/**
|
|
5940
|
+
* Perform a request with auth, header merging, and rate-limit (429) retries.
|
|
5941
|
+
* Does NOT handle 403 approval_required — that's routed by `fetch`.
|
|
5942
|
+
*/
|
|
5943
|
+
this.rawFetch = async (path, init) => {
|
|
5944
|
+
if (!path.startsWith("/")) {
|
|
5945
|
+
throw new ZapierValidationError(
|
|
5946
|
+
`fetch expects a path starting with '/', got: ${path}`
|
|
5947
|
+
);
|
|
5948
|
+
}
|
|
5949
|
+
const { url, pathConfig: pathConfig2 } = this.buildUrl(path, init?.searchParams);
|
|
5950
|
+
return this.rawFetchUrl(url, init, pathConfig2);
|
|
5951
|
+
};
|
|
5952
|
+
/**
|
|
5953
|
+
* Approval-aware HTTP fetch.
|
|
5954
|
+
*
|
|
5955
|
+
* Wraps `rawFetch` with the backend's just-in-time approval protocol. The
|
|
5956
|
+
* backend signals approval state via a 403 response with an
|
|
5957
|
+
* `x-zapier-error-type` header:
|
|
5958
|
+
*
|
|
5959
|
+
* - `request_denied_by_policy` → a policy rule permanently blocks the
|
|
5960
|
+
* request; no human can approve it. Throw.
|
|
5961
|
+
* - `approval_required` → the request needs human approval; the
|
|
5962
|
+
* SDK creates an approval, opens the URL
|
|
5963
|
+
* (poll mode), waits for resolution, and
|
|
5964
|
+
* retries the original request.
|
|
5965
|
+
* - anything else → not our concern, pass through.
|
|
5966
|
+
*
|
|
5967
|
+
* The retry loop exists because a single user action can legitimately
|
|
5968
|
+
* require multiple sequential approvals (e.g. policies that approve one
|
|
5969
|
+
* step at a time). Each iteration is either a first attempt or a post-
|
|
5970
|
+
* approval retry; `maxApprovalRetries` bounds the loop as a runaway-loop
|
|
5971
|
+
* safeguard.
|
|
5972
|
+
*
|
|
5973
|
+
* Loop accounting: `attempt` counts rawFetch calls, not approval rounds.
|
|
5974
|
+
* With `maxRetries = N` we perform up to `N + 1` rawFetch calls and at
|
|
5975
|
+
* most `N` approval rounds. The `attempt === maxRetries` guard ensures we
|
|
5976
|
+
* don't run an (N+1)th approval round we'll never consume — if the final
|
|
5977
|
+
* retry still returns `approval_required`, we break out and throw
|
|
5978
|
+
* `max_retries_exceeded` instead.
|
|
5979
|
+
*/
|
|
5980
|
+
this.fetch = async (path, init) => {
|
|
5981
|
+
const maxRetries = this.options.maxApprovalRetries ?? DEFAULT_MAX_APPROVAL_RETRIES;
|
|
5982
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
5983
|
+
const response = await this.rawFetch(path, init);
|
|
5984
|
+
if (response.status !== 403) return response;
|
|
5985
|
+
const errorType = response.headers.get("x-zapier-error-type");
|
|
5986
|
+
if (errorType === "request_denied_by_policy") {
|
|
5987
|
+
const { data } = await this.parseResult(response);
|
|
5988
|
+
const { message, errors } = this.parseErrorResponse({
|
|
5989
|
+
status: response.status,
|
|
5990
|
+
statusText: response.statusText,
|
|
5991
|
+
data
|
|
5780
5992
|
});
|
|
5781
|
-
|
|
5782
|
-
|
|
5993
|
+
throw new ZapierApprovalError(
|
|
5994
|
+
message || "Request explicitly denied by policy",
|
|
5995
|
+
{
|
|
5996
|
+
status: "policy_denied",
|
|
5997
|
+
statusCode: response.status,
|
|
5998
|
+
errors
|
|
5999
|
+
}
|
|
6000
|
+
);
|
|
6001
|
+
}
|
|
6002
|
+
if (errorType !== "approval_required") return response;
|
|
6003
|
+
if (attempt === maxRetries) break;
|
|
6004
|
+
const isInteractive = this.options.isInteractive ?? getZapierIsInteractive();
|
|
6005
|
+
if (!isInteractive) {
|
|
6006
|
+
throw new ZapierApprovalError(
|
|
6007
|
+
"Approval required but session is not interactive",
|
|
6008
|
+
{ status: "approval_required" }
|
|
6009
|
+
);
|
|
5783
6010
|
}
|
|
5784
|
-
|
|
6011
|
+
if (!init?.approvalContext) {
|
|
6012
|
+
throw new ZapierApiError(
|
|
6013
|
+
`Received 403 approval_required for ${path}, but the caller did not provide an approvalContext builder. Every approval-capable request must pass approvalContext so the SDK can create the approval with the correct policy context.`,
|
|
6014
|
+
{ statusCode: 403 }
|
|
6015
|
+
);
|
|
6016
|
+
}
|
|
6017
|
+
await this.runOneApprovalRound(init.approvalContext);
|
|
5785
6018
|
}
|
|
6019
|
+
throw new ZapierApprovalError(
|
|
6020
|
+
`Exceeded maximum approval retries (${maxRetries}) for ${path}`,
|
|
6021
|
+
{ status: "max_retries_exceeded" }
|
|
6022
|
+
);
|
|
5786
6023
|
};
|
|
5787
6024
|
this.get = async (path, options = {}) => {
|
|
5788
6025
|
return this.fetchJson("GET", path, void 0, options);
|
|
@@ -6067,6 +6304,156 @@ var ZapierApiClient = class {
|
|
|
6067
6304
|
}
|
|
6068
6305
|
return result;
|
|
6069
6306
|
}
|
|
6307
|
+
/**
|
|
6308
|
+
* Run a single approval round: create the approval, open the URL (poll mode)
|
|
6309
|
+
* or throw (fail mode), poll until resolved, and emit events. Throws on
|
|
6310
|
+
* denied/timeout/unexpected status. Returns on approved.
|
|
6311
|
+
*/
|
|
6312
|
+
async runOneApprovalRound(buildContext) {
|
|
6313
|
+
const context = buildContext();
|
|
6314
|
+
let approvalResponse;
|
|
6315
|
+
try {
|
|
6316
|
+
approvalResponse = await this.rawFetch("/api/v0/approvals", {
|
|
6317
|
+
method: "POST",
|
|
6318
|
+
headers: {
|
|
6319
|
+
"Content-Type": "application/json",
|
|
6320
|
+
Accept: "application/json"
|
|
6321
|
+
},
|
|
6322
|
+
body: JSON.stringify({ context })
|
|
6323
|
+
});
|
|
6324
|
+
} catch (err) {
|
|
6325
|
+
throw new ZapierApiError("Failed to create approval request", {
|
|
6326
|
+
statusCode: 0,
|
|
6327
|
+
cause: err
|
|
6328
|
+
});
|
|
6329
|
+
}
|
|
6330
|
+
if (!approvalResponse.ok) {
|
|
6331
|
+
const body2 = await approvalResponse.text().catch(() => void 0);
|
|
6332
|
+
throw new ZapierApiError(
|
|
6333
|
+
`Failed to create approval request: ${approvalResponse.status}`,
|
|
6334
|
+
{ statusCode: approvalResponse.status, response: body2 }
|
|
6335
|
+
);
|
|
6336
|
+
}
|
|
6337
|
+
let body;
|
|
6338
|
+
try {
|
|
6339
|
+
body = await approvalResponse.text();
|
|
6340
|
+
} catch (err) {
|
|
6341
|
+
throw new ZapierApiError("Failed to read approval response body", {
|
|
6342
|
+
statusCode: approvalResponse.status,
|
|
6343
|
+
cause: err
|
|
6344
|
+
});
|
|
6345
|
+
}
|
|
6346
|
+
let approval;
|
|
6347
|
+
try {
|
|
6348
|
+
approval = CreateApprovalResponseSchema.parse(JSON.parse(body));
|
|
6349
|
+
} catch (err) {
|
|
6350
|
+
throw new ZapierApiError(`Failed to parse approval response: ${body}`, {
|
|
6351
|
+
statusCode: approvalResponse.status,
|
|
6352
|
+
cause: err,
|
|
6353
|
+
response: body
|
|
6354
|
+
});
|
|
6355
|
+
}
|
|
6356
|
+
const sdkapiOrigin = new URL(this.buildUrl("/api/v0/approvals").url).origin;
|
|
6357
|
+
const browserOrigin = getZapierBaseUrl(this.options.baseUrl) ?? sdkapiOrigin;
|
|
6358
|
+
const assertApprovalOrigin = (url, expectedOrigin, label) => {
|
|
6359
|
+
let parsed;
|
|
6360
|
+
try {
|
|
6361
|
+
parsed = new URL(url);
|
|
6362
|
+
} catch {
|
|
6363
|
+
throw new ZapierApiError(`Invalid approval ${label}: ${url}`, {
|
|
6364
|
+
statusCode: approvalResponse.status,
|
|
6365
|
+
response: body
|
|
6366
|
+
});
|
|
6367
|
+
}
|
|
6368
|
+
if (parsed.origin !== expectedOrigin) {
|
|
6369
|
+
throw new ZapierApiError(
|
|
6370
|
+
`Approval ${label} origin ${parsed.origin} does not match expected ${expectedOrigin}`,
|
|
6371
|
+
{ statusCode: approvalResponse.status, response: body }
|
|
6372
|
+
);
|
|
6373
|
+
}
|
|
6374
|
+
};
|
|
6375
|
+
assertApprovalOrigin(approval.poll_url, sdkapiOrigin, "poll_url");
|
|
6376
|
+
assertApprovalOrigin(approval.approval_url, browserOrigin, "approval_url");
|
|
6377
|
+
this.emitEvent("approval:required", {
|
|
6378
|
+
approvalId: approval.approval_id,
|
|
6379
|
+
approvalUrl: approval.approval_url
|
|
6380
|
+
});
|
|
6381
|
+
const approvalMode = this.options.approvalMode ?? getZapierApprovalMode();
|
|
6382
|
+
if (approvalMode === "fail") {
|
|
6383
|
+
throw new ZapierApprovalError("This request requires approval.", {
|
|
6384
|
+
approvalId: approval.approval_id,
|
|
6385
|
+
approvalUrl: approval.approval_url,
|
|
6386
|
+
pollUrl: approval.poll_url,
|
|
6387
|
+
status: "pending"
|
|
6388
|
+
});
|
|
6389
|
+
}
|
|
6390
|
+
await openApproval(approval.approval_url);
|
|
6391
|
+
const timeoutMs = this.options.approvalTimeoutMs ?? DEFAULT_APPROVAL_TIMEOUT_MS;
|
|
6392
|
+
let rawPollResult;
|
|
6393
|
+
try {
|
|
6394
|
+
rawPollResult = await pollUntilComplete({
|
|
6395
|
+
// poll_url is an absolute URL supplied by the server, so we use
|
|
6396
|
+
// rawFetchUrl directly (skipping path resolution) but still share
|
|
6397
|
+
// auth + interactive-header + 429-retry with the rest of the SDK.
|
|
6398
|
+
fetchPoll: () => this.rawFetchUrl(approval.poll_url, {
|
|
6399
|
+
method: "GET",
|
|
6400
|
+
headers: { Accept: "application/json" }
|
|
6401
|
+
}),
|
|
6402
|
+
timeoutMs,
|
|
6403
|
+
isPending: (body2) => {
|
|
6404
|
+
const parsed = PollApprovalResponseSchema.safeParse(body2);
|
|
6405
|
+
return parsed.success && parsed.data.status === "pending_approval";
|
|
6406
|
+
}
|
|
6407
|
+
});
|
|
6408
|
+
} catch (err) {
|
|
6409
|
+
if (!(err instanceof ZapierTimeoutError)) {
|
|
6410
|
+
throw err;
|
|
6411
|
+
}
|
|
6412
|
+
this.emitEvent("approval:timeout", {
|
|
6413
|
+
approvalId: approval.approval_id
|
|
6414
|
+
});
|
|
6415
|
+
throw new ZapierApprovalError(
|
|
6416
|
+
`Approval timed out after ${timeoutMs / 1e3} seconds`,
|
|
6417
|
+
{
|
|
6418
|
+
approvalId: approval.approval_id,
|
|
6419
|
+
approvalUrl: approval.approval_url,
|
|
6420
|
+
pollUrl: approval.poll_url,
|
|
6421
|
+
status: "timeout",
|
|
6422
|
+
cause: err
|
|
6423
|
+
}
|
|
6424
|
+
);
|
|
6425
|
+
}
|
|
6426
|
+
const pollParse = PollApprovalResponseSchema.safeParse(rawPollResult);
|
|
6427
|
+
if (!pollParse.success) {
|
|
6428
|
+
const bodyPreview = typeof rawPollResult === "string" ? rawPollResult : JSON.stringify(rawPollResult);
|
|
6429
|
+
throw new ZapierApiError(
|
|
6430
|
+
`Failed to parse approval poll response: ${bodyPreview}`,
|
|
6431
|
+
{
|
|
6432
|
+
statusCode: 0,
|
|
6433
|
+
cause: pollParse.error,
|
|
6434
|
+
response: rawPollResult
|
|
6435
|
+
}
|
|
6436
|
+
);
|
|
6437
|
+
}
|
|
6438
|
+
const pollResult = pollParse.data;
|
|
6439
|
+
if (pollResult.status === "denied") {
|
|
6440
|
+
this.emitEvent("approval:denied", {
|
|
6441
|
+
approvalId: approval.approval_id
|
|
6442
|
+
});
|
|
6443
|
+
throw new ZapierApprovalError("Request denied by user", {
|
|
6444
|
+
approvalId: approval.approval_id,
|
|
6445
|
+
status: "denied"
|
|
6446
|
+
});
|
|
6447
|
+
}
|
|
6448
|
+
if (pollResult.status !== "approved") {
|
|
6449
|
+
throw new ZapierApiError(
|
|
6450
|
+
`Unexpected approval status received: ${pollResult.status}`
|
|
6451
|
+
);
|
|
6452
|
+
}
|
|
6453
|
+
this.emitEvent("approval:approved", {
|
|
6454
|
+
approvalId: approval.approval_id
|
|
6455
|
+
});
|
|
6456
|
+
}
|
|
6070
6457
|
};
|
|
6071
6458
|
var createZapierApi = (options) => {
|
|
6072
6459
|
const { debug = false, fetch: originalFetch = globalThis.fetch } = options;
|
|
@@ -6080,7 +6467,7 @@ var createZapierApi = (options) => {
|
|
|
6080
6467
|
};
|
|
6081
6468
|
|
|
6082
6469
|
// src/plugins/api/index.ts
|
|
6083
|
-
var apiPlugin = (
|
|
6470
|
+
var apiPlugin = (sdk) => {
|
|
6084
6471
|
const {
|
|
6085
6472
|
fetch: customFetch = globalThis.fetch,
|
|
6086
6473
|
baseUrl = ZAPIER_BASE_URL,
|
|
@@ -6089,8 +6476,12 @@ var apiPlugin = (params) => {
|
|
|
6089
6476
|
onEvent,
|
|
6090
6477
|
debug = false,
|
|
6091
6478
|
maxNetworkRetries = ZAPIER_MAX_NETWORK_RETRIES,
|
|
6092
|
-
maxNetworkRetryDelayMs = ZAPIER_MAX_NETWORK_RETRY_DELAY_MS
|
|
6093
|
-
|
|
6479
|
+
maxNetworkRetryDelayMs = ZAPIER_MAX_NETWORK_RETRY_DELAY_MS,
|
|
6480
|
+
isInteractive,
|
|
6481
|
+
approvalTimeoutMs,
|
|
6482
|
+
maxApprovalRetries,
|
|
6483
|
+
approvalMode
|
|
6484
|
+
} = sdk.context.options;
|
|
6094
6485
|
const api = createZapierApi({
|
|
6095
6486
|
baseUrl,
|
|
6096
6487
|
credentials,
|
|
@@ -6099,7 +6490,11 @@ var apiPlugin = (params) => {
|
|
|
6099
6490
|
fetch: customFetch,
|
|
6100
6491
|
onEvent,
|
|
6101
6492
|
maxNetworkRetries,
|
|
6102
|
-
maxNetworkRetryDelayMs
|
|
6493
|
+
maxNetworkRetryDelayMs,
|
|
6494
|
+
isInteractive,
|
|
6495
|
+
approvalTimeoutMs,
|
|
6496
|
+
maxApprovalRetries,
|
|
6497
|
+
approvalMode
|
|
6103
6498
|
});
|
|
6104
6499
|
return {
|
|
6105
6500
|
context: {
|
|
@@ -6205,12 +6600,11 @@ async function batch(tasks, options = {}) {
|
|
|
6205
6600
|
}
|
|
6206
6601
|
|
|
6207
6602
|
// src/plugins/connections/index.ts
|
|
6208
|
-
var connectionsPlugin = (
|
|
6209
|
-
const { context } = params;
|
|
6603
|
+
var connectionsPlugin = (sdk) => {
|
|
6210
6604
|
let cachedMap;
|
|
6211
6605
|
async function loadConnectionsMap() {
|
|
6212
6606
|
if (cachedMap === void 0) {
|
|
6213
|
-
cachedMap = await context.getManifestConnections() ?? null;
|
|
6607
|
+
cachedMap = await sdk.context.getManifestConnections() ?? null;
|
|
6214
6608
|
}
|
|
6215
6609
|
return cachedMap;
|
|
6216
6610
|
}
|
|
@@ -6257,12 +6651,12 @@ function isEnabledByEnv(key) {
|
|
|
6257
6651
|
if (value === "false" || value === "0") return false;
|
|
6258
6652
|
return void 0;
|
|
6259
6653
|
}
|
|
6260
|
-
var capabilitiesPlugin = (
|
|
6261
|
-
const options = context.options ?? {};
|
|
6654
|
+
var capabilitiesPlugin = (sdk) => {
|
|
6655
|
+
const options = sdk.context.options ?? {};
|
|
6262
6656
|
let cached;
|
|
6263
6657
|
async function resolveFlags() {
|
|
6264
6658
|
if (cached) return cached;
|
|
6265
|
-
const manifest = await context.getResolvedManifest();
|
|
6659
|
+
const manifest = await sdk.context.getResolvedManifest();
|
|
6266
6660
|
cached = {};
|
|
6267
6661
|
for (const flag of GATED_FLAGS) {
|
|
6268
6662
|
cached[flag] = Boolean(
|
|
@@ -6348,12 +6742,12 @@ function extractNextCursor(links) {
|
|
|
6348
6742
|
return void 0;
|
|
6349
6743
|
}
|
|
6350
6744
|
}
|
|
6351
|
-
var listTablesPlugin = (
|
|
6745
|
+
var listTablesPlugin = (sdk) => {
|
|
6352
6746
|
async function listTablesPage(options) {
|
|
6353
6747
|
if (options.includeShared) {
|
|
6354
|
-
await context.checkCapability("canIncludeSharedTables");
|
|
6748
|
+
await sdk.context.checkCapability("canIncludeSharedTables");
|
|
6355
6749
|
}
|
|
6356
|
-
const { api } = context;
|
|
6750
|
+
const { api } = sdk.context;
|
|
6357
6751
|
const searchParams = {};
|
|
6358
6752
|
if (options.pageSize !== void 0) {
|
|
6359
6753
|
searchParams.limit = options.pageSize.toString();
|
|
@@ -6418,7 +6812,10 @@ var listTablesPlugin = ({ context }) => {
|
|
|
6418
6812
|
const listTablesDefinition = createPaginatedFunction(
|
|
6419
6813
|
listTablesPage,
|
|
6420
6814
|
ListTablesOptionsSchema,
|
|
6421
|
-
createTelemetryCallback(
|
|
6815
|
+
createTelemetryCallback(
|
|
6816
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6817
|
+
methodName
|
|
6818
|
+
),
|
|
6422
6819
|
methodName,
|
|
6423
6820
|
DEFAULT_PAGE_SIZE
|
|
6424
6821
|
);
|
|
@@ -6450,9 +6847,9 @@ var GetTableOptionsSchemaDeprecated = z.object({
|
|
|
6450
6847
|
var GetTableOptionsInputSchema = z.union([GetTableOptionsSchema, GetTableOptionsSchemaDeprecated]).describe(GetTableDescription);
|
|
6451
6848
|
|
|
6452
6849
|
// src/plugins/tables/getTable/index.ts
|
|
6453
|
-
var getTablePlugin = (
|
|
6850
|
+
var getTablePlugin = (sdk) => {
|
|
6454
6851
|
async function getTable(options) {
|
|
6455
|
-
const { api } = context;
|
|
6852
|
+
const { api } = sdk.context;
|
|
6456
6853
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
6457
6854
|
const rawResponse = await api.get(`/tables/api/v1/tables/${tableId}`, {
|
|
6458
6855
|
customErrorHandler: ({ status }) => {
|
|
@@ -6484,7 +6881,7 @@ var getTablePlugin = ({ context }) => {
|
|
|
6484
6881
|
getTable,
|
|
6485
6882
|
GetTableOptionsInputSchema,
|
|
6486
6883
|
createTelemetryCallback(
|
|
6487
|
-
context.eventEmission.emitMethodCalled,
|
|
6884
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6488
6885
|
getTable.name
|
|
6489
6886
|
)
|
|
6490
6887
|
);
|
|
@@ -6515,9 +6912,9 @@ var CreateTableOptionsSchema = z.object({
|
|
|
6515
6912
|
}).describe("Create a new table");
|
|
6516
6913
|
|
|
6517
6914
|
// src/plugins/tables/createTable/index.ts
|
|
6518
|
-
var createTablePlugin = (
|
|
6915
|
+
var createTablePlugin = (sdk) => {
|
|
6519
6916
|
async function createTable(options) {
|
|
6520
|
-
const { api } = context;
|
|
6917
|
+
const { api } = sdk.context;
|
|
6521
6918
|
const rawResponse = await api.post(
|
|
6522
6919
|
"/tables/api/v1/tables",
|
|
6523
6920
|
{
|
|
@@ -6552,7 +6949,7 @@ var createTablePlugin = ({ context }) => {
|
|
|
6552
6949
|
createTable,
|
|
6553
6950
|
CreateTableOptionsSchema,
|
|
6554
6951
|
createTelemetryCallback(
|
|
6555
|
-
context.eventEmission.emitMethodCalled,
|
|
6952
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6556
6953
|
createTable.name
|
|
6557
6954
|
)
|
|
6558
6955
|
);
|
|
@@ -6584,10 +6981,10 @@ var DeleteTableOptionsSchemaDeprecated = z.object({
|
|
|
6584
6981
|
var DeleteTableOptionsInputSchema = z.union([DeleteTableOptionsSchema, DeleteTableOptionsSchemaDeprecated]).describe(DeleteTableDescription);
|
|
6585
6982
|
|
|
6586
6983
|
// src/plugins/tables/deleteTable/index.ts
|
|
6587
|
-
var deleteTablePlugin = (
|
|
6984
|
+
var deleteTablePlugin = (sdk) => {
|
|
6588
6985
|
async function deleteTable(options) {
|
|
6589
|
-
await context.checkCapability("canDeleteTables");
|
|
6590
|
-
const { api } = context;
|
|
6986
|
+
await sdk.context.checkCapability("canDeleteTables");
|
|
6987
|
+
const { api } = sdk.context;
|
|
6591
6988
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
6592
6989
|
await api.delete(`/tables/api/v1/tables/${tableId}`, void 0, {
|
|
6593
6990
|
customErrorHandler: ({ status }) => {
|
|
@@ -6615,7 +7012,7 @@ var deleteTablePlugin = ({ context }) => {
|
|
|
6615
7012
|
deleteTable,
|
|
6616
7013
|
DeleteTableOptionsInputSchema,
|
|
6617
7014
|
createTelemetryCallback(
|
|
6618
|
-
context.eventEmission.emitMethodCalled,
|
|
7015
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6619
7016
|
deleteTable.name
|
|
6620
7017
|
)
|
|
6621
7018
|
);
|
|
@@ -6639,9 +7036,9 @@ var deleteTablePlugin = ({ context }) => {
|
|
|
6639
7036
|
};
|
|
6640
7037
|
|
|
6641
7038
|
// src/plugins/tables/listTableFields/index.ts
|
|
6642
|
-
var listTableFieldsPlugin = (
|
|
7039
|
+
var listTableFieldsPlugin = (sdk) => {
|
|
6643
7040
|
async function listTableFields(options) {
|
|
6644
|
-
const { api } = context;
|
|
7041
|
+
const { api } = sdk.context;
|
|
6645
7042
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
6646
7043
|
const fieldKeys = "fields" in options ? options.fields : options.fieldKeys;
|
|
6647
7044
|
const searchParams = {};
|
|
@@ -6687,7 +7084,7 @@ var listTableFieldsPlugin = ({ context }) => {
|
|
|
6687
7084
|
listTableFields,
|
|
6688
7085
|
ListTableFieldsOptionsInputSchema,
|
|
6689
7086
|
createTelemetryCallback(
|
|
6690
|
-
context.eventEmission.emitMethodCalled,
|
|
7087
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6691
7088
|
listTableFields.name
|
|
6692
7089
|
)
|
|
6693
7090
|
);
|
|
@@ -6742,9 +7139,9 @@ var CreateTableFieldsOptionsInputSchema = z.union([
|
|
|
6742
7139
|
]).describe(CreateTableFieldsDescription);
|
|
6743
7140
|
|
|
6744
7141
|
// src/plugins/tables/createTableFields/index.ts
|
|
6745
|
-
var createTableFieldsPlugin = (
|
|
7142
|
+
var createTableFieldsPlugin = (sdk) => {
|
|
6746
7143
|
async function createTableFields(options) {
|
|
6747
|
-
const { api } = context;
|
|
7144
|
+
const { api } = sdk.context;
|
|
6748
7145
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
6749
7146
|
const rawResponse = await api.post(
|
|
6750
7147
|
`/tables/api/v1/tables/${tableId}/fields`,
|
|
@@ -6779,7 +7176,7 @@ var createTableFieldsPlugin = ({ context }) => {
|
|
|
6779
7176
|
createTableFields,
|
|
6780
7177
|
CreateTableFieldsOptionsInputSchema,
|
|
6781
7178
|
createTelemetryCallback(
|
|
6782
|
-
context.eventEmission.emitMethodCalled,
|
|
7179
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6783
7180
|
createTableFields.name
|
|
6784
7181
|
)
|
|
6785
7182
|
);
|
|
@@ -6819,9 +7216,9 @@ var DeleteTableFieldsOptionsInputSchema = z.union([
|
|
|
6819
7216
|
]).describe(DeleteTableFieldsDescription);
|
|
6820
7217
|
|
|
6821
7218
|
// src/plugins/tables/deleteTableFields/index.ts
|
|
6822
|
-
var deleteTableFieldsPlugin = (
|
|
7219
|
+
var deleteTableFieldsPlugin = (sdk) => {
|
|
6823
7220
|
async function deleteTableFields(options) {
|
|
6824
|
-
const { api } = context;
|
|
7221
|
+
const { api } = sdk.context;
|
|
6825
7222
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
6826
7223
|
const fieldKeys = "fields" in options ? options.fields : options.fieldKeys;
|
|
6827
7224
|
const numericFieldIds = await resolveFieldKeys({
|
|
@@ -6859,7 +7256,7 @@ var deleteTableFieldsPlugin = ({ context }) => {
|
|
|
6859
7256
|
deleteTableFields,
|
|
6860
7257
|
DeleteTableFieldsOptionsInputSchema,
|
|
6861
7258
|
createTelemetryCallback(
|
|
6862
|
-
context.eventEmission.emitMethodCalled,
|
|
7259
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6863
7260
|
deleteTableFields.name
|
|
6864
7261
|
)
|
|
6865
7262
|
);
|
|
@@ -6946,9 +7343,9 @@ var tableRecordFormatter = {
|
|
|
6946
7343
|
};
|
|
6947
7344
|
|
|
6948
7345
|
// src/plugins/tables/getTableRecord/index.ts
|
|
6949
|
-
var getTableRecordPlugin = (
|
|
7346
|
+
var getTableRecordPlugin = (sdk) => {
|
|
6950
7347
|
async function getTableRecord(options) {
|
|
6951
|
-
const { api } = context;
|
|
7348
|
+
const { api } = sdk.context;
|
|
6952
7349
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
6953
7350
|
const recordId = "record" in options ? options.record : options.recordId;
|
|
6954
7351
|
const rawResponse = await api.get(
|
|
@@ -6992,7 +7389,7 @@ var getTableRecordPlugin = ({ context }) => {
|
|
|
6992
7389
|
getTableRecord,
|
|
6993
7390
|
GetTableRecordOptionsInputSchema,
|
|
6994
7391
|
createTelemetryCallback(
|
|
6995
|
-
context.eventEmission.emitMethodCalled,
|
|
7392
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
6996
7393
|
getTableRecord.name
|
|
6997
7394
|
)
|
|
6998
7395
|
);
|
|
@@ -7080,9 +7477,9 @@ function extractNextCursor2(meta) {
|
|
|
7080
7477
|
}
|
|
7081
7478
|
return meta.pagination.end_cursor;
|
|
7082
7479
|
}
|
|
7083
|
-
var listTableRecordsPlugin = (
|
|
7480
|
+
var listTableRecordsPlugin = (sdk) => {
|
|
7084
7481
|
async function listTableRecordsPage(options) {
|
|
7085
|
-
const { api } = context;
|
|
7482
|
+
const { api } = sdk.context;
|
|
7086
7483
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
7087
7484
|
const translator = await createFieldKeyTranslator({
|
|
7088
7485
|
api,
|
|
@@ -7154,7 +7551,10 @@ var listTableRecordsPlugin = ({ context }) => {
|
|
|
7154
7551
|
const listTableRecordsDefinition = createPaginatedFunction(
|
|
7155
7552
|
listTableRecordsPage,
|
|
7156
7553
|
ListTableRecordsOptionsInputSchema,
|
|
7157
|
-
createTelemetryCallback(
|
|
7554
|
+
createTelemetryCallback(
|
|
7555
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
7556
|
+
methodName
|
|
7557
|
+
),
|
|
7158
7558
|
methodName,
|
|
7159
7559
|
DEFAULT_PAGE_SIZE
|
|
7160
7560
|
);
|
|
@@ -7209,9 +7609,9 @@ var CreateTableRecordsOptionsInputSchema = z.union([
|
|
|
7209
7609
|
]).describe(CreateTableRecordsDescription);
|
|
7210
7610
|
|
|
7211
7611
|
// src/plugins/tables/createTableRecords/index.ts
|
|
7212
|
-
var createTableRecordsPlugin = (
|
|
7612
|
+
var createTableRecordsPlugin = (sdk) => {
|
|
7213
7613
|
async function createTableRecords(options) {
|
|
7214
|
-
const { api } = context;
|
|
7614
|
+
const { api } = sdk.context;
|
|
7215
7615
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
7216
7616
|
const translator = await createFieldKeyTranslator({
|
|
7217
7617
|
api,
|
|
@@ -7263,7 +7663,7 @@ var createTableRecordsPlugin = ({ context }) => {
|
|
|
7263
7663
|
createTableRecords,
|
|
7264
7664
|
CreateTableRecordsOptionsInputSchema,
|
|
7265
7665
|
createTelemetryCallback(
|
|
7266
|
-
context.eventEmission.emitMethodCalled,
|
|
7666
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
7267
7667
|
createTableRecords.name
|
|
7268
7668
|
)
|
|
7269
7669
|
);
|
|
@@ -7302,9 +7702,9 @@ var DeleteTableRecordsOptionsInputSchema = z.union([
|
|
|
7302
7702
|
]).describe(DeleteTableRecordsDescription);
|
|
7303
7703
|
|
|
7304
7704
|
// src/plugins/tables/deleteTableRecords/index.ts
|
|
7305
|
-
var deleteTableRecordsPlugin = (
|
|
7705
|
+
var deleteTableRecordsPlugin = (sdk) => {
|
|
7306
7706
|
async function deleteTableRecords(options) {
|
|
7307
|
-
const { api } = context;
|
|
7707
|
+
const { api } = sdk.context;
|
|
7308
7708
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
7309
7709
|
const recordIds = "records" in options ? options.records : options.recordIds;
|
|
7310
7710
|
await api.delete(
|
|
@@ -7337,7 +7737,7 @@ var deleteTableRecordsPlugin = ({ context }) => {
|
|
|
7337
7737
|
deleteTableRecords,
|
|
7338
7738
|
DeleteTableRecordsOptionsInputSchema,
|
|
7339
7739
|
createTelemetryCallback(
|
|
7340
|
-
context.eventEmission.emitMethodCalled,
|
|
7740
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
7341
7741
|
deleteTableRecords.name
|
|
7342
7742
|
)
|
|
7343
7743
|
);
|
|
@@ -7391,9 +7791,9 @@ var UpdateTableRecordsOptionsInputSchema = z.union([
|
|
|
7391
7791
|
]).describe(UpdateTableRecordsDescription);
|
|
7392
7792
|
|
|
7393
7793
|
// src/plugins/tables/updateTableRecords/index.ts
|
|
7394
|
-
var updateTableRecordsPlugin = (
|
|
7794
|
+
var updateTableRecordsPlugin = (sdk) => {
|
|
7395
7795
|
async function updateTableRecords(options) {
|
|
7396
|
-
const { api } = context;
|
|
7796
|
+
const { api } = sdk.context;
|
|
7397
7797
|
const tableId = "table" in options ? options.table : options.tableId;
|
|
7398
7798
|
const translator = await createFieldKeyTranslator({
|
|
7399
7799
|
api,
|
|
@@ -7446,7 +7846,7 @@ var updateTableRecordsPlugin = ({ context }) => {
|
|
|
7446
7846
|
updateTableRecords,
|
|
7447
7847
|
UpdateTableRecordsOptionsInputSchema,
|
|
7448
7848
|
createTelemetryCallback(
|
|
7449
|
-
context.eventEmission.emitMethodCalled,
|
|
7849
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
7450
7850
|
updateTableRecords.name
|
|
7451
7851
|
)
|
|
7452
7852
|
);
|
|
@@ -7472,8 +7872,8 @@ var updateTableRecordsPlugin = ({ context }) => {
|
|
|
7472
7872
|
};
|
|
7473
7873
|
|
|
7474
7874
|
// src/plugins/registry/index.ts
|
|
7475
|
-
var registryPlugin = (
|
|
7476
|
-
const metaKeys = Object.keys(context.meta || {});
|
|
7875
|
+
var registryPlugin = (sdk) => {
|
|
7876
|
+
const metaKeys = Object.keys(sdk.context.meta || {});
|
|
7477
7877
|
const categoryDefinitions = {
|
|
7478
7878
|
account: {
|
|
7479
7879
|
title: "Account"
|
|
@@ -7518,7 +7918,7 @@ var registryPlugin = ({ sdk, context }) => {
|
|
|
7518
7918
|
}
|
|
7519
7919
|
return false;
|
|
7520
7920
|
}).map((key) => {
|
|
7521
|
-
const meta = context.meta[key];
|
|
7921
|
+
const meta = sdk.context.meta[key];
|
|
7522
7922
|
return {
|
|
7523
7923
|
name: key,
|
|
7524
7924
|
description: meta.description,
|
|
@@ -7586,7 +7986,7 @@ var registryPlugin = ({ sdk, context }) => {
|
|
|
7586
7986
|
};
|
|
7587
7987
|
|
|
7588
7988
|
// src/plugins/deprecated/authentications.ts
|
|
7589
|
-
var listAuthenticationsPlugin = (
|
|
7989
|
+
var listAuthenticationsPlugin = (sdk) => ({
|
|
7590
7990
|
listAuthentications: sdk.listConnections,
|
|
7591
7991
|
context: {
|
|
7592
7992
|
meta: {
|
|
@@ -7601,7 +8001,7 @@ var listAuthenticationsPlugin = ({ sdk }) => ({
|
|
|
7601
8001
|
}
|
|
7602
8002
|
}
|
|
7603
8003
|
});
|
|
7604
|
-
var getAuthenticationPlugin = (
|
|
8004
|
+
var getAuthenticationPlugin = (sdk) => ({
|
|
7605
8005
|
getAuthentication: sdk.getConnection,
|
|
7606
8006
|
context: {
|
|
7607
8007
|
meta: {
|
|
@@ -7616,7 +8016,7 @@ var getAuthenticationPlugin = ({ sdk }) => ({
|
|
|
7616
8016
|
}
|
|
7617
8017
|
}
|
|
7618
8018
|
});
|
|
7619
|
-
var findFirstAuthenticationPlugin = (
|
|
8019
|
+
var findFirstAuthenticationPlugin = (sdk) => ({
|
|
7620
8020
|
findFirstAuthentication: sdk.findFirstConnection,
|
|
7621
8021
|
context: {
|
|
7622
8022
|
meta: {
|
|
@@ -7631,7 +8031,7 @@ var findFirstAuthenticationPlugin = ({ sdk }) => ({
|
|
|
7631
8031
|
}
|
|
7632
8032
|
}
|
|
7633
8033
|
});
|
|
7634
|
-
var findUniqueAuthenticationPlugin = (
|
|
8034
|
+
var findUniqueAuthenticationPlugin = (sdk) => ({
|
|
7635
8035
|
findUniqueAuthentication: sdk.findUniqueConnection,
|
|
7636
8036
|
context: {
|
|
7637
8037
|
meta: {
|
|
@@ -7694,9 +8094,9 @@ var GetInputFieldsSchemaSchemaDeprecated = z.object({
|
|
|
7694
8094
|
var GetInputFieldsSchemaInputSchema = z.union([GetInputFieldsSchemaSchema, GetInputFieldsSchemaSchemaDeprecated]).describe(GetInputFieldsSchemaDescription);
|
|
7695
8095
|
|
|
7696
8096
|
// src/plugins/getInputFieldsSchema/index.ts
|
|
7697
|
-
var getInputFieldsSchemaPlugin = (
|
|
8097
|
+
var getInputFieldsSchemaPlugin = (sdk) => {
|
|
7698
8098
|
async function getInputFieldsSchema(options) {
|
|
7699
|
-
const { api, getVersionedImplementationId } = context;
|
|
8099
|
+
const { api, getVersionedImplementationId } = sdk.context;
|
|
7700
8100
|
const appKey = "app" in options ? options.app : options.appKey;
|
|
7701
8101
|
const actionKey = "action" in options ? options.action : options.actionKey;
|
|
7702
8102
|
const { actionType, connection, connectionId, authenticationId, inputs } = options;
|
|
@@ -7704,7 +8104,7 @@ var getInputFieldsSchemaPlugin = ({ sdk, context }) => {
|
|
|
7704
8104
|
connection,
|
|
7705
8105
|
connectionId,
|
|
7706
8106
|
authenticationId,
|
|
7707
|
-
resolveConnection: context.resolveConnection
|
|
8107
|
+
resolveConnection: sdk.context.resolveConnection
|
|
7708
8108
|
});
|
|
7709
8109
|
const selectedApi = await getVersionedImplementationId(appKey);
|
|
7710
8110
|
if (!selectedApi) {
|
|
@@ -7739,7 +8139,7 @@ var getInputFieldsSchemaPlugin = ({ sdk, context }) => {
|
|
|
7739
8139
|
getInputFieldsSchema,
|
|
7740
8140
|
GetInputFieldsSchemaInputSchema,
|
|
7741
8141
|
createTelemetryCallback(
|
|
7742
|
-
context.eventEmission.emitMethodCalled,
|
|
8142
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
7743
8143
|
getInputFieldsSchema.name
|
|
7744
8144
|
)
|
|
7745
8145
|
);
|
|
@@ -7833,9 +8233,9 @@ function transformNeedChoicesToInputFieldChoiceItem(choice) {
|
|
|
7833
8233
|
value: choice.value
|
|
7834
8234
|
};
|
|
7835
8235
|
}
|
|
7836
|
-
var listInputFieldChoicesPlugin = (
|
|
8236
|
+
var listInputFieldChoicesPlugin = (sdk) => {
|
|
7837
8237
|
async function listInputFieldChoicesPage(options) {
|
|
7838
|
-
const { api, getVersionedImplementationId } = context;
|
|
8238
|
+
const { api, getVersionedImplementationId } = sdk.context;
|
|
7839
8239
|
const appKey = "app" in options ? options.app : options.appKey;
|
|
7840
8240
|
const actionKey = "action" in options ? options.action : options.actionKey;
|
|
7841
8241
|
const inputFieldKey = "inputField" in options ? options.inputField : options.inputFieldKey;
|
|
@@ -7852,7 +8252,7 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
|
7852
8252
|
connection,
|
|
7853
8253
|
connectionId,
|
|
7854
8254
|
authenticationId,
|
|
7855
|
-
resolveConnection: context.resolveConnection
|
|
8255
|
+
resolveConnection: sdk.context.resolveConnection
|
|
7856
8256
|
});
|
|
7857
8257
|
const selectedApi = await getVersionedImplementationId(appKey);
|
|
7858
8258
|
if (!selectedApi) {
|
|
@@ -7930,7 +8330,10 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
|
7930
8330
|
const listInputFieldChoicesDefinition = createPaginatedFunction(
|
|
7931
8331
|
listInputFieldChoicesPage,
|
|
7932
8332
|
ListInputFieldChoicesInputSchema,
|
|
7933
|
-
createTelemetryCallback(
|
|
8333
|
+
createTelemetryCallback(
|
|
8334
|
+
sdk.context.eventEmission.emitMethodCalled,
|
|
8335
|
+
methodName
|
|
8336
|
+
),
|
|
7934
8337
|
methodName,
|
|
7935
8338
|
DEFAULT_PAGE_SIZE
|
|
7936
8339
|
);
|
|
@@ -8302,19 +8705,20 @@ function getTransportConfig(options) {
|
|
|
8302
8705
|
endpoint
|
|
8303
8706
|
};
|
|
8304
8707
|
}
|
|
8305
|
-
var eventEmissionPlugin = (
|
|
8708
|
+
var eventEmissionPlugin = (sdk) => {
|
|
8709
|
+
const options = sdk.context.options ?? {};
|
|
8306
8710
|
const defaultTransport = getTransportConfig({
|
|
8307
|
-
trackingBaseUrl:
|
|
8308
|
-
baseUrl:
|
|
8711
|
+
trackingBaseUrl: options.trackingBaseUrl,
|
|
8712
|
+
baseUrl: options.baseUrl
|
|
8309
8713
|
});
|
|
8310
8714
|
const config = {
|
|
8311
|
-
enabled:
|
|
8312
|
-
callContext:
|
|
8715
|
+
enabled: options.eventEmission?.enabled ?? true,
|
|
8716
|
+
callContext: options.eventEmission?.callContext,
|
|
8313
8717
|
transport: (
|
|
8314
8718
|
// If env var is set, use it (defaultTransport will be from env)
|
|
8315
8719
|
globalThis.process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
|
|
8316
8720
|
// Otherwise, use option transport or default
|
|
8317
|
-
|
|
8721
|
+
options.eventEmission?.transport ?? defaultTransport
|
|
8318
8722
|
)
|
|
8319
8723
|
)
|
|
8320
8724
|
};
|
|
@@ -8322,7 +8726,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
8322
8726
|
if (config.enabled) {
|
|
8323
8727
|
try {
|
|
8324
8728
|
const token = await resolveAuthToken({
|
|
8325
|
-
...
|
|
8729
|
+
...options
|
|
8326
8730
|
});
|
|
8327
8731
|
if (token) {
|
|
8328
8732
|
return extractUserIdsFromJwt(token);
|
|
@@ -8572,55 +8976,54 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
8572
8976
|
};
|
|
8573
8977
|
|
|
8574
8978
|
// src/sdk.ts
|
|
8575
|
-
function
|
|
8979
|
+
function createOptionsPlugin(options) {
|
|
8980
|
+
return () => ({ context: { options } });
|
|
8981
|
+
}
|
|
8982
|
+
function createSdk() {
|
|
8983
|
+
return buildSdk({}, { meta: {} });
|
|
8984
|
+
}
|
|
8985
|
+
function buildSdk(properties, context) {
|
|
8986
|
+
const frozenContext = Object.freeze(context);
|
|
8576
8987
|
return {
|
|
8577
|
-
...
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8988
|
+
...properties,
|
|
8989
|
+
get context() {
|
|
8990
|
+
return frozenContext;
|
|
8991
|
+
},
|
|
8992
|
+
getContext: () => frozenContext,
|
|
8993
|
+
// runtime compat shim, not in types
|
|
8994
|
+
addPlugin(plugin) {
|
|
8584
8995
|
const pluginResult = plugin({
|
|
8585
|
-
|
|
8586
|
-
context:
|
|
8587
|
-
...initialContext,
|
|
8588
|
-
// Add the options that createSdk was called with to context
|
|
8589
|
-
options
|
|
8590
|
-
},
|
|
8591
|
-
...addPluginOptions
|
|
8996
|
+
...properties,
|
|
8997
|
+
context: frozenContext
|
|
8592
8998
|
});
|
|
8593
|
-
const { context: pluginContext, ...
|
|
8594
|
-
const
|
|
8595
|
-
let
|
|
8596
|
-
...
|
|
8597
|
-
|
|
8598
|
-
meta: initialContext.meta || {}
|
|
8999
|
+
const { context: pluginContext, ...pluginProperties } = pluginResult;
|
|
9000
|
+
const mergedProperties = { ...properties, ...pluginProperties };
|
|
9001
|
+
let mergedContext = {
|
|
9002
|
+
...context,
|
|
9003
|
+
meta: context.meta || {}
|
|
8599
9004
|
};
|
|
8600
9005
|
if (pluginContext) {
|
|
8601
|
-
const { meta: pluginMeta, ...
|
|
8602
|
-
|
|
8603
|
-
...
|
|
8604
|
-
...
|
|
9006
|
+
const { meta: pluginMeta, ...pluginContextRest } = pluginContext;
|
|
9007
|
+
mergedContext = {
|
|
9008
|
+
...mergedContext,
|
|
9009
|
+
...pluginContextRest
|
|
8605
9010
|
};
|
|
8606
9011
|
if (pluginMeta) {
|
|
8607
|
-
|
|
8608
|
-
...
|
|
8609
|
-
meta: {
|
|
8610
|
-
...newContext.meta,
|
|
8611
|
-
// Existing meta (now guaranteed to exist)
|
|
8612
|
-
...pluginMeta
|
|
8613
|
-
// New meta from plugin
|
|
8614
|
-
}
|
|
9012
|
+
mergedContext = {
|
|
9013
|
+
...mergedContext,
|
|
9014
|
+
meta: { ...mergedContext.meta, ...pluginMeta }
|
|
8615
9015
|
};
|
|
8616
9016
|
}
|
|
8617
9017
|
}
|
|
8618
|
-
return
|
|
9018
|
+
return buildSdk(
|
|
9019
|
+
mergedProperties,
|
|
9020
|
+
mergedContext
|
|
9021
|
+
);
|
|
8619
9022
|
}
|
|
8620
9023
|
};
|
|
8621
9024
|
}
|
|
8622
9025
|
function createZapierSdkWithoutRegistry(options = {}) {
|
|
8623
|
-
return createSdk(options).addPlugin(eventEmissionPlugin).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(capabilitiesPlugin).addPlugin(connectionsPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(getInputFieldsSchemaPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listConnectionsPlugin).addPlugin(getConnectionPlugin).addPlugin(findFirstConnectionPlugin).addPlugin(findUniqueConnectionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(listClientCredentialsPlugin).addPlugin(createClientCredentialsPlugin).addPlugin(deleteClientCredentialsPlugin).addPlugin(fetchPlugin).addPlugin(requestPlugin).addPlugin(listTablesPlugin).addPlugin(getTablePlugin).addPlugin(deleteTablePlugin).addPlugin(createTablePlugin).addPlugin(listTableFieldsPlugin).addPlugin(createTableFieldsPlugin).addPlugin(deleteTableFieldsPlugin).addPlugin(getTableRecordPlugin).addPlugin(listTableRecordsPlugin).addPlugin(createTableRecordsPlugin).addPlugin(deleteTableRecordsPlugin).addPlugin(updateTableRecordsPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
|
|
9026
|
+
return createSdk().addPlugin(createOptionsPlugin(options)).addPlugin(eventEmissionPlugin).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(capabilitiesPlugin).addPlugin(connectionsPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(getInputFieldsSchemaPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listConnectionsPlugin).addPlugin(getConnectionPlugin).addPlugin(findFirstConnectionPlugin).addPlugin(findUniqueConnectionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(listClientCredentialsPlugin).addPlugin(createClientCredentialsPlugin).addPlugin(deleteClientCredentialsPlugin).addPlugin(fetchPlugin).addPlugin(requestPlugin).addPlugin(listTablesPlugin).addPlugin(getTablePlugin).addPlugin(deleteTablePlugin).addPlugin(createTablePlugin).addPlugin(listTableFieldsPlugin).addPlugin(createTableFieldsPlugin).addPlugin(deleteTableFieldsPlugin).addPlugin(getTableRecordPlugin).addPlugin(listTableRecordsPlugin).addPlugin(createTableRecordsPlugin).addPlugin(deleteTableRecordsPlugin).addPlugin(updateTableRecordsPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
|
|
8624
9027
|
}
|
|
8625
9028
|
function createZapierSdk(options = {}) {
|
|
8626
9029
|
return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
|
|
@@ -8643,6 +9046,16 @@ var BaseSdkOptionsSchema = z.object({
|
|
|
8643
9046
|
* Default is 60000 (60 seconds).
|
|
8644
9047
|
*/
|
|
8645
9048
|
maxNetworkRetryDelayMs: z.number().optional().describe("Max delay in ms to wait for retry (default: 60000).").meta({ valueHint: "ms" }),
|
|
9049
|
+
isInteractive: z.boolean().optional().describe(
|
|
9050
|
+
"Whether this session is interactive (user can visit approval URLs). Defaults to ZAPIER_IS_INTERACTIVE env var."
|
|
9051
|
+
).meta({ internal: true }),
|
|
9052
|
+
approvalTimeoutMs: z.number().optional().describe("Timeout in ms for approval polling. Default: 600000 (10 min).").meta({ valueHint: "ms", internal: true }),
|
|
9053
|
+
maxApprovalRetries: z.number().optional().describe(
|
|
9054
|
+
"Maximum number of sequential approval rounds per request (one per gating policy) before giving up. Default: 2."
|
|
9055
|
+
).meta({ internal: true }),
|
|
9056
|
+
approvalMode: z.enum(["poll", "fail"]).optional().describe(
|
|
9057
|
+
'Approval flow behavior. "poll" opens browser and polls (default). "fail" creates the approval and throws immediately with the approval URL.'
|
|
9058
|
+
).meta({ internal: true }),
|
|
8646
9059
|
// Internal
|
|
8647
9060
|
manifestPath: z.string().optional().describe("Path to a .zapierrc manifest file for app version locking.").meta({ internal: true }),
|
|
8648
9061
|
manifest: z.custom().optional().describe("Manifest for app version locking.").meta({ internal: true }),
|
|
@@ -8657,4 +9070,4 @@ var BaseSdkOptionsSchema = z.object({
|
|
|
8657
9070
|
// Use credentials instead
|
|
8658
9071
|
});
|
|
8659
9072
|
|
|
8660
|
-
export { ActionKeyPropertySchema, ActionPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AppPropertySchema, AppsPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, CONTEXT_CACHE_MAX_SIZE, CONTEXT_CACHE_TTL_MS, ClientCredentialsObjectSchema, ConnectionEntrySchema, ConnectionIdPropertySchema, ConnectionPropertySchema, ConnectionsMapSchema, ConnectionsPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DEFAULT_PAGE_SIZE, DebugPropertySchema, FieldsPropertySchema, InputFieldPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RecordPropertySchema, RecordsPropertySchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, TablePropertySchema, TablesPropertySchema, ZAPIER_BASE_URL, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierRelayError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildCapabilityMessage, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, connectionsPlugin, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createTableFieldsPlugin, createTablePlugin, createTableRecordsPlugin, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, deleteTableFieldsPlugin, deleteTablePlugin, deleteTableRecordsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTablePlugin, getTableRecordPlugin, getTokenFromCliLogin, injectCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, listTableFieldsPlugin, listTableRecordsPlugin, listTablesPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, runWithTelemetryContext, tableFieldIdsResolver, tableFieldsResolver, tableFiltersResolver, tableIdResolver, tableNameResolver, tableRecordIdResolver, tableRecordIdsResolver, tableRecordsResolver, tableSortResolver, tableUpdateRecordsResolver, toSnakeCase, toTitleCase, updateTableRecordsPlugin };
|
|
9073
|
+
export { ActionKeyPropertySchema, ActionPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AppPropertySchema, AppsPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, CONTEXT_CACHE_MAX_SIZE, CONTEXT_CACHE_TTL_MS, ClientCredentialsObjectSchema, ConnectionEntrySchema, ConnectionIdPropertySchema, ConnectionPropertySchema, ConnectionsMapSchema, ConnectionsPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_APPROVAL_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DEFAULT_MAX_APPROVAL_RETRIES, DEFAULT_PAGE_SIZE, DebugPropertySchema, FieldsPropertySchema, InputFieldPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RecordPropertySchema, RecordsPropertySchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, TablePropertySchema, TablesPropertySchema, ZAPIER_BASE_URL, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierApprovalError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierRelayError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildCapabilityMessage, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, connectionsPlugin, createBaseEvent, createClientCredentialsPlugin, createFunction, createOptionsPlugin, createSdk, createTableFieldsPlugin, createTablePlugin, createTableRecordsPlugin, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, deleteTableFieldsPlugin, deleteTablePlugin, deleteTableRecordsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTablePlugin, getTableRecordPlugin, getTokenFromCliLogin, getZapierApprovalMode, getZapierIsInteractive, injectCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, listTableFieldsPlugin, listTableRecordsPlugin, listTablesPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, runWithTelemetryContext, tableFieldIdsResolver, tableFieldsResolver, tableFiltersResolver, tableIdResolver, tableNameResolver, tableRecordIdResolver, tableRecordIdsResolver, tableRecordsResolver, tableSortResolver, tableUpdateRecordsResolver, toSnakeCase, toTitleCase, updateTableRecordsPlugin };
|