@zapier/zapier-sdk 0.108.0 → 0.109.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 +41 -0
- package/README.md +1 -1
- package/dist/{chunk-ULZVDPAK.mjs → chunk-6QN54DRD.mjs} +449 -357
- package/dist/{chunk-HMEY72T6.cjs → chunk-BU4ANX6G.cjs} +447 -355
- package/dist/experimental.cjs +378 -378
- package/dist/experimental.d.mts +11 -11
- package/dist/experimental.d.ts +11 -11
- package/dist/experimental.mjs +2 -2
- package/dist/{index-wTDIVpGJ.d.mts → index-Cum18GPG.d.mts} +54 -47
- package/dist/{index-wTDIVpGJ.d.ts → index-Cum18GPG.d.ts} +54 -47
- package/dist/index.cjs +279 -279
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __require } from './chunk-Y6FXYEAI.mjs';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { withPositional,
|
|
3
|
+
import { withPositional, createDeprecationLogger, createAsyncContext, declareOptionalProperty, defineProperty, definePlugin, sendHttpRequestPlugin, retryHttpRequestPlugin, declareProperty, defineMethod, coreOptionsPluginRef, createValidator, defineFormatter, declareMethod, defineResolver, concatLists, openEnum, defineHook, getRegistryPlugin, paginate, toSnakeCase, isCoreError, toTitleCase, CORE_ERROR_SYMBOL, CoreErrorCode, CORE_SIGNAL_SYMBOL, isCoreSignal, createSdk, CORE_OPTIONS_ID, resolvePlugin } from '@zapier/kitcore';
|
|
4
4
|
export { CONTEXT, CORE_ERROR_SYMBOL, CORE_OPTIONS_ID, CORE_SIGNAL_SYMBOL, CoreCancelledSignal, CoreDisposeError, CoreErrorCode, CoreSignal, addPlugin, composePlugins, createController, createCorePlugin, createFunction, createPaginatedFunction, createPaginatedPluginMethod, createPluginMethod, createPluginStack, createSdk, declareMethod, declareOptionalProperty, declarePlugin, declareProperty, defineFormatter, defineLegacyMerge, defineMethod, defineMethodOverride, defineOverride, definePlugin, defineProperty, defineResolver, disposeSdk, fromFunctionPlugin, getContext, getCoreErrorCause, getCoreErrorCode, getNegatable, getRegistryPlugin, isCoreCancelledSignal, isCoreError, isCoreSignal, isPositional, omitExports, resolvePlugin, runInMethodScope, runWithTelemetryContext, selectExports, toSnakeCase, toTitleCase } from '@zapier/kitcore';
|
|
5
5
|
import { buildHttpRequestContext, buildActionRunContext } from '@zapier/policy-context';
|
|
6
6
|
import { ListAppsQuerySchema, AppItemSchema as AppItemSchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/apps';
|
|
7
|
-
import { ListConnectionsQuerySchema as ListConnectionsQuerySchema$1, ConnectionSchema, ConnectionItemSchema } from '@zapier/zapier-sdk-core/v0/schemas/connections';
|
|
7
|
+
import { ListConnectionsQuerySchema as ListConnectionsQuerySchema$1, ConnectionSchema, ConnectionsResponseSchema, ConnectionItemSchema } from '@zapier/zapier-sdk-core/v0/schemas/connections';
|
|
8
8
|
import { ListClientCredentialsQuerySchema as ListClientCredentialsQuerySchema$1, ClientCredentialsItemSchema as ClientCredentialsItemSchema$1, CreateClientCredentialsRequestSchema, ClientCredentialsCreatedItemSchema as ClientCredentialsCreatedItemSchema$1 } from '@zapier/zapier-sdk-core/v0/schemas/client-credentials';
|
|
9
9
|
|
|
10
10
|
// src/constants.ts
|
|
@@ -605,6 +605,83 @@ function extractUserIdsFromJwt(token) {
|
|
|
605
605
|
};
|
|
606
606
|
}
|
|
607
607
|
|
|
608
|
+
// src/api/concurrency.ts
|
|
609
|
+
var NO_OP_RELEASE = () => {
|
|
610
|
+
};
|
|
611
|
+
var NO_OP_SEMAPHORE = {
|
|
612
|
+
acquire: async () => NO_OP_RELEASE,
|
|
613
|
+
tryAcquire: () => NO_OP_RELEASE
|
|
614
|
+
};
|
|
615
|
+
function createSemaphore(maxPermits) {
|
|
616
|
+
if (maxPermits === Infinity) {
|
|
617
|
+
return NO_OP_SEMAPHORE;
|
|
618
|
+
}
|
|
619
|
+
if (!Number.isInteger(maxPermits) || maxPermits <= 0) {
|
|
620
|
+
throw new Error(
|
|
621
|
+
`maxPermits must be a positive integer or Infinity, got: ${maxPermits}`
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
let permits = maxPermits;
|
|
625
|
+
const waiters = [];
|
|
626
|
+
const release = () => {
|
|
627
|
+
const next = waiters.shift();
|
|
628
|
+
if (next) {
|
|
629
|
+
next.grant();
|
|
630
|
+
} else {
|
|
631
|
+
permits++;
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
const makeReleaseOnce = () => {
|
|
635
|
+
let released = false;
|
|
636
|
+
return () => {
|
|
637
|
+
if (released) return;
|
|
638
|
+
released = true;
|
|
639
|
+
release();
|
|
640
|
+
};
|
|
641
|
+
};
|
|
642
|
+
return {
|
|
643
|
+
tryAcquire() {
|
|
644
|
+
if (permits > 0) {
|
|
645
|
+
permits--;
|
|
646
|
+
return makeReleaseOnce();
|
|
647
|
+
}
|
|
648
|
+
return null;
|
|
649
|
+
},
|
|
650
|
+
async acquire(signal) {
|
|
651
|
+
if (signal?.aborted) {
|
|
652
|
+
throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
653
|
+
}
|
|
654
|
+
if (permits > 0) {
|
|
655
|
+
permits--;
|
|
656
|
+
return makeReleaseOnce();
|
|
657
|
+
}
|
|
658
|
+
return new Promise((resolve2, reject) => {
|
|
659
|
+
const onAbort = () => {
|
|
660
|
+
const idx = waiters.indexOf(waiter);
|
|
661
|
+
if (idx !== -1) {
|
|
662
|
+
waiters.splice(idx, 1);
|
|
663
|
+
waiter.cancel(
|
|
664
|
+
signal?.reason ?? new DOMException("Aborted", "AbortError")
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
const waiter = {
|
|
669
|
+
grant: () => {
|
|
670
|
+
signal?.removeEventListener("abort", onAbort);
|
|
671
|
+
resolve2(makeReleaseOnce());
|
|
672
|
+
},
|
|
673
|
+
cancel: (reason) => {
|
|
674
|
+
signal?.removeEventListener("abort", onAbort);
|
|
675
|
+
reject(reason);
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
signal?.addEventListener("abort", onAbort);
|
|
679
|
+
waiters.push(waiter);
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
608
685
|
// src/api/debug.ts
|
|
609
686
|
var utilModule = null;
|
|
610
687
|
var utilPromise = null;
|
|
@@ -862,8 +939,16 @@ var processResponse = async (response, successStatus, pendingStatus, isPending,
|
|
|
862
939
|
};
|
|
863
940
|
}
|
|
864
941
|
if (response.status === successStatus) {
|
|
942
|
+
let resultJson;
|
|
943
|
+
try {
|
|
944
|
+
resultJson = await response.json();
|
|
945
|
+
} catch (error) {
|
|
946
|
+
throw new ZapierApiError("Poll response body was not valid JSON", {
|
|
947
|
+
statusCode: response.status,
|
|
948
|
+
cause: error
|
|
949
|
+
});
|
|
950
|
+
}
|
|
865
951
|
try {
|
|
866
|
-
const resultJson = await response.json();
|
|
867
952
|
if (isPending && isPending(resultJson)) {
|
|
868
953
|
return {
|
|
869
954
|
status: "continue" /* Continue */,
|
|
@@ -876,13 +961,7 @@ var processResponse = async (response, successStatus, pendingStatus, isPending,
|
|
|
876
961
|
errorCount: 0
|
|
877
962
|
};
|
|
878
963
|
} catch (error) {
|
|
879
|
-
|
|
880
|
-
"Result extractor failed to parse successful response as JSON",
|
|
881
|
-
{
|
|
882
|
-
statusCode: response.status,
|
|
883
|
-
cause: error
|
|
884
|
-
}
|
|
885
|
-
);
|
|
964
|
+
return { status: "failed" /* Failed */, error, errorCount };
|
|
886
965
|
}
|
|
887
966
|
}
|
|
888
967
|
if (response.status !== pendingStatus) {
|
|
@@ -955,13 +1034,10 @@ async function pollUntilComplete(options) {
|
|
|
955
1034
|
if (signal?.aborted) throw makeAbortError();
|
|
956
1035
|
}
|
|
957
1036
|
attempts++;
|
|
1037
|
+
let terminalThrow;
|
|
958
1038
|
try {
|
|
959
1039
|
const response = await fetchPoll();
|
|
960
|
-
const
|
|
961
|
-
result,
|
|
962
|
-
errorCount: newErrorCount,
|
|
963
|
-
status
|
|
964
|
-
} = await processResponse(
|
|
1040
|
+
const pollResult = await processResponse(
|
|
965
1041
|
response,
|
|
966
1042
|
successStatus,
|
|
967
1043
|
pendingStatus,
|
|
@@ -969,15 +1045,18 @@ async function pollUntilComplete(options) {
|
|
|
969
1045
|
resultExtractor,
|
|
970
1046
|
errorCount
|
|
971
1047
|
);
|
|
972
|
-
errorCount =
|
|
973
|
-
if (status === "
|
|
974
|
-
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1048
|
+
errorCount = pollResult.errorCount;
|
|
1049
|
+
if (pollResult.status === "failed" /* Failed */) {
|
|
1050
|
+
terminalThrow = { error: pollResult.error };
|
|
1051
|
+
} else if (pollResult.status === "success" /* Success */) {
|
|
1052
|
+
return pollResult.result;
|
|
1053
|
+
} else if (errorCount >= MAX_CONSECUTIVE_ERRORS) {
|
|
1054
|
+
terminalThrow = {
|
|
1055
|
+
error: new ZapierApiError(
|
|
1056
|
+
`Poll request failed: ${response.status} ${response.statusText}`,
|
|
1057
|
+
{ statusCode: response.status }
|
|
1058
|
+
)
|
|
1059
|
+
};
|
|
981
1060
|
}
|
|
982
1061
|
} catch (error) {
|
|
983
1062
|
if (isAbortError(error)) throw error;
|
|
@@ -991,89 +1070,25 @@ async function pollUntilComplete(options) {
|
|
|
991
1070
|
);
|
|
992
1071
|
}
|
|
993
1072
|
}
|
|
1073
|
+
if (terminalThrow) throw terminalThrow.error;
|
|
994
1074
|
}
|
|
995
1075
|
}
|
|
996
1076
|
|
|
997
|
-
// src/api/
|
|
998
|
-
var
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
);
|
|
1012
|
-
}
|
|
1013
|
-
let permits = maxPermits;
|
|
1014
|
-
const waiters = [];
|
|
1015
|
-
const release = () => {
|
|
1016
|
-
const next = waiters.shift();
|
|
1017
|
-
if (next) {
|
|
1018
|
-
next.grant();
|
|
1019
|
-
} else {
|
|
1020
|
-
permits++;
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
|
-
const makeReleaseOnce = () => {
|
|
1024
|
-
let released = false;
|
|
1025
|
-
return () => {
|
|
1026
|
-
if (released) return;
|
|
1027
|
-
released = true;
|
|
1028
|
-
release();
|
|
1029
|
-
};
|
|
1030
|
-
};
|
|
1031
|
-
return {
|
|
1032
|
-
tryAcquire() {
|
|
1033
|
-
if (permits > 0) {
|
|
1034
|
-
permits--;
|
|
1035
|
-
return makeReleaseOnce();
|
|
1036
|
-
}
|
|
1037
|
-
return null;
|
|
1038
|
-
},
|
|
1039
|
-
async acquire(signal) {
|
|
1040
|
-
if (signal?.aborted) {
|
|
1041
|
-
throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
1042
|
-
}
|
|
1043
|
-
if (permits > 0) {
|
|
1044
|
-
permits--;
|
|
1045
|
-
return makeReleaseOnce();
|
|
1046
|
-
}
|
|
1047
|
-
return new Promise((resolve2, reject) => {
|
|
1048
|
-
const onAbort = () => {
|
|
1049
|
-
const idx = waiters.indexOf(waiter);
|
|
1050
|
-
if (idx !== -1) {
|
|
1051
|
-
waiters.splice(idx, 1);
|
|
1052
|
-
waiter.cancel(
|
|
1053
|
-
signal?.reason ?? new DOMException("Aborted", "AbortError")
|
|
1054
|
-
);
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
|
-
const waiter = {
|
|
1058
|
-
grant: () => {
|
|
1059
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1060
|
-
resolve2(makeReleaseOnce());
|
|
1061
|
-
},
|
|
1062
|
-
cancel: (reason) => {
|
|
1063
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1064
|
-
reject(reason);
|
|
1065
|
-
}
|
|
1066
|
-
};
|
|
1067
|
-
signal?.addEventListener("abort", onAbort);
|
|
1068
|
-
waiters.push(waiter);
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1077
|
+
// src/api/correlation.ts
|
|
1078
|
+
var CORRELATION_CALL_ID = Symbol(
|
|
1079
|
+
"zapier.correlationCallId"
|
|
1080
|
+
);
|
|
1081
|
+
function resolveCorrelationId({
|
|
1082
|
+
options,
|
|
1083
|
+
callId
|
|
1084
|
+
}) {
|
|
1085
|
+
return options?.correlationId || getZapierCorrelationId() || callId || void 0;
|
|
1086
|
+
}
|
|
1087
|
+
function resolveCausationId({
|
|
1088
|
+
options
|
|
1089
|
+
}) {
|
|
1090
|
+
return options?.causationId || getZapierCausationId();
|
|
1072
1091
|
}
|
|
1073
|
-
var SDK_OPTIONS_ID = "zapier/sdkOptions";
|
|
1074
|
-
var sdkOptionsPluginRef = declareOptionalProperty({
|
|
1075
|
-
id: SDK_OPTIONS_ID
|
|
1076
|
-
});
|
|
1077
1092
|
|
|
1078
1093
|
// src/api/rate-limit.ts
|
|
1079
1094
|
var EPOCH_THRESHOLD_SECONDS = 1e9;
|
|
@@ -1159,99 +1174,6 @@ function createRetryObserver({
|
|
|
1159
1174
|
}
|
|
1160
1175
|
};
|
|
1161
1176
|
}
|
|
1162
|
-
|
|
1163
|
-
// src/plugins/transport/options.ts
|
|
1164
|
-
var RETRYABLE_STATUSES = [429, 500, 502, 503, 504];
|
|
1165
|
-
var NON_IDEMPOTENT_RETRYABLE_STATUSES = [429];
|
|
1166
|
-
function resolveRetryHttpRequestOptions({
|
|
1167
|
-
maxNetworkRetries,
|
|
1168
|
-
maxNetworkRetryDelayMilliseconds,
|
|
1169
|
-
onEvent
|
|
1170
|
-
}) {
|
|
1171
|
-
const retries = maxNetworkRetries ?? ZAPIER_MAX_NETWORK_RETRIES;
|
|
1172
|
-
return {
|
|
1173
|
-
maxAttempts: retries + 1,
|
|
1174
|
-
maxDelayMilliseconds: maxNetworkRetryDelayMilliseconds ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS,
|
|
1175
|
-
retryStatuses: RETRYABLE_STATUSES,
|
|
1176
|
-
nonIdempotentRetryStatuses: NON_IDEMPOTENT_RETRYABLE_STATUSES,
|
|
1177
|
-
onRetry: createRetryObserver({ onEvent, maxNetworkRetries: retries })
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
function resolveNetworkRetryDelayMilliseconds({
|
|
1181
|
-
maxNetworkRetryDelaySeconds,
|
|
1182
|
-
maxNetworkRetryDelayMs
|
|
1183
|
-
}) {
|
|
1184
|
-
return maxNetworkRetryDelaySeconds != null ? maxNetworkRetryDelaySeconds * 1e3 : maxNetworkRetryDelayMs;
|
|
1185
|
-
}
|
|
1186
|
-
function resolveTransportFetch({
|
|
1187
|
-
fetch: customFetch,
|
|
1188
|
-
debug = false
|
|
1189
|
-
}) {
|
|
1190
|
-
const originalFetch = customFetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
1191
|
-
if (!debug) return originalFetch;
|
|
1192
|
-
return createDebugFetch({
|
|
1193
|
-
originalFetch,
|
|
1194
|
-
debugLog: createDebugLogger(debug)
|
|
1195
|
-
});
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
// src/plugins/transport/http-fetch.ts
|
|
1199
|
-
var httpFetchPlugin = defineProperty({
|
|
1200
|
-
namespace: "kitcore",
|
|
1201
|
-
name: "httpFetch",
|
|
1202
|
-
imports: [sdkOptionsPluginRef],
|
|
1203
|
-
setup: ({ imports }) => resolveTransportFetch({
|
|
1204
|
-
fetch: imports.sdkOptions?.fetch,
|
|
1205
|
-
debug: imports.sdkOptions?.debug
|
|
1206
|
-
}),
|
|
1207
|
-
get: ({ state }) => state
|
|
1208
|
-
});
|
|
1209
|
-
|
|
1210
|
-
// src/plugins/transport/standalone.ts
|
|
1211
|
-
function createZapierSendHttpRequest({
|
|
1212
|
-
fetch: customFetch,
|
|
1213
|
-
debug,
|
|
1214
|
-
maxNetworkRetries,
|
|
1215
|
-
maxNetworkRetryDelayMilliseconds,
|
|
1216
|
-
onEvent
|
|
1217
|
-
}) {
|
|
1218
|
-
const sdk = createSdk(
|
|
1219
|
-
definePlugin({
|
|
1220
|
-
name: "zapierStandaloneHttpTransport",
|
|
1221
|
-
imports: [sendHttpRequestPlugin, retryHttpRequestPlugin, httpFetchPlugin],
|
|
1222
|
-
exports: [sendHttpRequestPlugin]
|
|
1223
|
-
}),
|
|
1224
|
-
{
|
|
1225
|
-
configuration: {
|
|
1226
|
-
[SDK_OPTIONS_ID]: { fetch: customFetch, debug },
|
|
1227
|
-
// Filled by configuration rather than the graph's property plugin: the
|
|
1228
|
-
// caller here holds client-shaped ms options, not SDK options.
|
|
1229
|
-
[RETRY_HTTP_REQUEST_OPTIONS_ID]: resolveRetryHttpRequestOptions({
|
|
1230
|
-
maxNetworkRetries,
|
|
1231
|
-
maxNetworkRetryDelayMilliseconds,
|
|
1232
|
-
onEvent
|
|
1233
|
-
})
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
);
|
|
1237
|
-
return sdk.sendHttpRequest;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
// src/api/correlation.ts
|
|
1241
|
-
var CORRELATION_CALL_ID = Symbol(
|
|
1242
|
-
"zapier.correlationCallId"
|
|
1243
|
-
);
|
|
1244
|
-
function resolveCorrelationId({
|
|
1245
|
-
options,
|
|
1246
|
-
callId
|
|
1247
|
-
}) {
|
|
1248
|
-
return options?.correlationId || getZapierCorrelationId() || callId || void 0;
|
|
1249
|
-
}
|
|
1250
|
-
function resolveCausationId({
|
|
1251
|
-
options
|
|
1252
|
-
}) {
|
|
1253
|
-
return options?.causationId || getZapierCausationId();
|
|
1254
|
-
}
|
|
1255
1177
|
var ClientCredentialsObjectSchema = z.object({
|
|
1256
1178
|
type: z.enum(["client_credentials"]).optional().meta({ internal: true }),
|
|
1257
1179
|
clientId: z.string().describe("OAuth client ID for authentication.").meta({ valueHint: "id" }),
|
|
@@ -2875,7 +2797,7 @@ function logRouteOverride({
|
|
|
2875
2797
|
}
|
|
2876
2798
|
|
|
2877
2799
|
// src/sdk-version.ts
|
|
2878
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
2800
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.109.0" : void 0) || "unknown";
|
|
2879
2801
|
|
|
2880
2802
|
// src/utils/open-url.ts
|
|
2881
2803
|
var nodePrefix = "node:";
|
|
@@ -3894,7 +3816,7 @@ var ZapierApiClient = class {
|
|
|
3894
3816
|
}
|
|
3895
3817
|
await openApproval(approval.approval_url);
|
|
3896
3818
|
}
|
|
3897
|
-
const timeoutMs = this.options.approvalTimeoutMilliseconds ??
|
|
3819
|
+
const timeoutMs = this.options.approvalTimeoutMilliseconds ?? DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS;
|
|
3898
3820
|
const approvalDeadline = Date.now() + timeoutMs;
|
|
3899
3821
|
let streamAbortController;
|
|
3900
3822
|
let streamPromise;
|
|
@@ -4062,7 +3984,7 @@ var ZapierApiClient = class {
|
|
|
4062
3984
|
);
|
|
4063
3985
|
}
|
|
4064
3986
|
};
|
|
4065
|
-
var
|
|
3987
|
+
var createApiClient = (options) => {
|
|
4066
3988
|
const { debug = false, fetch: originalFetch = globalThis.fetch } = options;
|
|
4067
3989
|
const routingOptions = parseRoutingOptions({ options });
|
|
4068
3990
|
const debugLog = createDebugLogger(debug);
|
|
@@ -4073,62 +3995,94 @@ var createZapierApi = (options) => {
|
|
|
4073
3995
|
// The credential-exchange transport. Debug-wrapped here rather than in the
|
|
4074
3996
|
// pipeline because `resolveAuthToken` is issued outside it.
|
|
4075
3997
|
fetch: debugFetch,
|
|
4076
|
-
|
|
4077
|
-
// for debug itself, and passing the wrapped one would log twice.
|
|
4078
|
-
sendHttpRequest: options.sendHttpRequest ?? createZapierSendHttpRequest({
|
|
4079
|
-
fetch: options.fetch,
|
|
4080
|
-
debug,
|
|
4081
|
-
onEvent: options.onEvent,
|
|
4082
|
-
maxNetworkRetries: options.maxNetworkRetries,
|
|
4083
|
-
maxNetworkRetryDelayMilliseconds: options.maxNetworkRetryDelayMilliseconds ?? options.maxNetworkRetryDelayMs
|
|
4084
|
-
}),
|
|
3998
|
+
sendHttpRequest: options.sendHttpRequest,
|
|
4085
3999
|
debugLog,
|
|
4086
4000
|
routingOptions
|
|
4087
4001
|
});
|
|
4088
4002
|
};
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4003
|
+
var API_CLIENT_DURATIONS_ID = "zapier/apiClientDurations";
|
|
4004
|
+
var apiClientDurationsPluginRef = declareOptionalProperty({
|
|
4005
|
+
id: API_CLIENT_DURATIONS_ID
|
|
4006
|
+
});
|
|
4007
|
+
function resolveNetworkRetryDelayMilliseconds({
|
|
4008
|
+
apiClientDurations,
|
|
4009
|
+
sdkOptions
|
|
4010
|
+
}) {
|
|
4011
|
+
if (apiClientDurations?.maxNetworkRetryDelayMilliseconds != null) {
|
|
4012
|
+
return apiClientDurations.maxNetworkRetryDelayMilliseconds;
|
|
4095
4013
|
}
|
|
4096
|
-
|
|
4097
|
-
|
|
4014
|
+
if (sdkOptions?.maxNetworkRetryDelaySeconds != null) {
|
|
4015
|
+
return sdkOptions.maxNetworkRetryDelaySeconds * 1e3;
|
|
4016
|
+
}
|
|
4017
|
+
return sdkOptions?.maxNetworkRetryDelayMs;
|
|
4098
4018
|
}
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
token,
|
|
4106
|
-
api: providedApi,
|
|
4107
|
-
debug = false,
|
|
4108
|
-
fetch: customFetch,
|
|
4109
|
-
callerPackage
|
|
4110
|
-
} = config;
|
|
4111
|
-
if (providedApi) {
|
|
4112
|
-
return providedApi;
|
|
4019
|
+
function resolveApprovalTimeoutMilliseconds({
|
|
4020
|
+
apiClientDurations,
|
|
4021
|
+
sdkOptions
|
|
4022
|
+
}) {
|
|
4023
|
+
if (apiClientDurations?.approvalTimeoutMilliseconds != null) {
|
|
4024
|
+
return apiClientDurations.approvalTimeoutMilliseconds;
|
|
4113
4025
|
}
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4026
|
+
if (sdkOptions?.approvalTimeoutSeconds != null) {
|
|
4027
|
+
return sdkOptions.approvalTimeoutSeconds * 1e3;
|
|
4028
|
+
}
|
|
4029
|
+
return sdkOptions?.approvalTimeoutMs;
|
|
4030
|
+
}
|
|
4031
|
+
var SDK_OPTIONS_ID = "zapier/sdkOptions";
|
|
4032
|
+
var sdkOptionsPluginRef = declareOptionalProperty({
|
|
4033
|
+
id: SDK_OPTIONS_ID
|
|
4034
|
+
});
|
|
4035
|
+
|
|
4036
|
+
// src/plugins/transport/options.ts
|
|
4037
|
+
var RETRYABLE_STATUSES = [429, 500, 502, 503, 504];
|
|
4038
|
+
var NON_IDEMPOTENT_RETRYABLE_STATUSES = [429];
|
|
4039
|
+
function resolveRetryHttpRequestOptions({
|
|
4040
|
+
maxNetworkRetries,
|
|
4041
|
+
maxNetworkRetryDelayMilliseconds,
|
|
4042
|
+
onEvent
|
|
4043
|
+
}) {
|
|
4044
|
+
const retries = maxNetworkRetries ?? ZAPIER_MAX_NETWORK_RETRIES;
|
|
4045
|
+
return {
|
|
4046
|
+
maxAttempts: retries + 1,
|
|
4047
|
+
maxDelayMilliseconds: maxNetworkRetryDelayMilliseconds ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS,
|
|
4048
|
+
retryStatuses: RETRYABLE_STATUSES,
|
|
4049
|
+
nonIdempotentRetryStatuses: NON_IDEMPOTENT_RETRYABLE_STATUSES,
|
|
4050
|
+
onRetry: createRetryObserver({ onEvent, maxNetworkRetries: retries })
|
|
4051
|
+
};
|
|
4052
|
+
}
|
|
4053
|
+
function resolveTransportFetch({
|
|
4054
|
+
fetch: customFetch,
|
|
4055
|
+
debug = false
|
|
4056
|
+
}) {
|
|
4057
|
+
const originalFetch = customFetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
4058
|
+
if (!debug) return originalFetch;
|
|
4059
|
+
return createDebugFetch({
|
|
4060
|
+
originalFetch,
|
|
4061
|
+
debugLog: createDebugLogger(debug)
|
|
4121
4062
|
});
|
|
4122
4063
|
}
|
|
4064
|
+
|
|
4065
|
+
// src/plugins/transport/http-fetch.ts
|
|
4066
|
+
var httpFetchPlugin = defineProperty({
|
|
4067
|
+
namespace: "kitcore",
|
|
4068
|
+
name: "httpFetch",
|
|
4069
|
+
imports: [sdkOptionsPluginRef],
|
|
4070
|
+
setup: ({ imports }) => resolveTransportFetch({
|
|
4071
|
+
fetch: imports.sdkOptions?.fetch,
|
|
4072
|
+
debug: imports.sdkOptions?.debug
|
|
4073
|
+
}),
|
|
4074
|
+
get: ({ state }) => state
|
|
4075
|
+
});
|
|
4123
4076
|
var retryHttpRequestOptionsPlugin = defineProperty({
|
|
4124
4077
|
namespace: "kitcore",
|
|
4125
4078
|
name: "retryHttpRequestOptions",
|
|
4126
|
-
imports: [sdkOptionsPluginRef],
|
|
4079
|
+
imports: [sdkOptionsPluginRef, apiClientDurationsPluginRef],
|
|
4127
4080
|
setup: ({ imports }) => resolveRetryHttpRequestOptions({
|
|
4128
4081
|
maxNetworkRetries: imports.sdkOptions?.maxNetworkRetries,
|
|
4129
|
-
maxNetworkRetryDelayMilliseconds: resolveNetworkRetryDelayMilliseconds(
|
|
4130
|
-
imports.
|
|
4131
|
-
|
|
4082
|
+
maxNetworkRetryDelayMilliseconds: resolveNetworkRetryDelayMilliseconds({
|
|
4083
|
+
apiClientDurations: imports.apiClientDurations,
|
|
4084
|
+
sdkOptions: imports.sdkOptions
|
|
4085
|
+
}),
|
|
4132
4086
|
onEvent: imports.sdkOptions?.onEvent
|
|
4133
4087
|
}),
|
|
4134
4088
|
get: ({ state }) => state
|
|
@@ -4172,10 +4126,14 @@ function withCorrelationId({
|
|
|
4172
4126
|
var apiPlugin = defineProperty({
|
|
4173
4127
|
namespace: "zapier",
|
|
4174
4128
|
name: "api",
|
|
4175
|
-
// Import the aggregate so
|
|
4176
|
-
|
|
4177
|
-
|
|
4129
|
+
// Import the aggregate so SDK options and host transport wraps are applied.
|
|
4130
|
+
imports: [
|
|
4131
|
+
sdkOptionsPluginRef,
|
|
4132
|
+
apiClientDurationsPluginRef,
|
|
4133
|
+
zapierHttpTransportPlugin
|
|
4134
|
+
],
|
|
4178
4135
|
setup: ({ imports }) => {
|
|
4136
|
+
const sdkOptions = imports.sdkOptions ?? {};
|
|
4179
4137
|
const {
|
|
4180
4138
|
fetch: customFetch = globalThis.fetch,
|
|
4181
4139
|
baseUrl = ZAPIER_BASE_URL,
|
|
@@ -4183,38 +4141,33 @@ var apiPlugin = defineProperty({
|
|
|
4183
4141
|
token,
|
|
4184
4142
|
onEvent,
|
|
4185
4143
|
debug = false,
|
|
4186
|
-
maxNetworkRetries = ZAPIER_MAX_NETWORK_RETRIES,
|
|
4187
|
-
maxNetworkRetryDelaySeconds,
|
|
4188
|
-
maxNetworkRetryDelayMs,
|
|
4189
4144
|
maxConcurrentRequests = ZAPIER_MAX_CONCURRENT_REQUESTS,
|
|
4190
|
-
approvalTimeoutSeconds,
|
|
4191
|
-
approvalTimeoutMs,
|
|
4192
4145
|
maxApprovalRetries,
|
|
4193
4146
|
approvalMode,
|
|
4194
4147
|
openAutoModeApprovalsInBrowser,
|
|
4195
4148
|
callerPackage,
|
|
4149
|
+
cache,
|
|
4196
4150
|
routeOverrides,
|
|
4197
4151
|
correlationId,
|
|
4198
4152
|
causationId
|
|
4199
|
-
} =
|
|
4200
|
-
return
|
|
4153
|
+
} = sdkOptions;
|
|
4154
|
+
return createApiClient({
|
|
4201
4155
|
baseUrl,
|
|
4202
4156
|
credentials,
|
|
4203
4157
|
token,
|
|
4204
4158
|
debug,
|
|
4205
4159
|
fetch: customFetch,
|
|
4206
4160
|
onEvent,
|
|
4207
|
-
maxNetworkRetries,
|
|
4208
|
-
maxNetworkRetryDelayMilliseconds: resolveNetworkRetryDelayMilliseconds({
|
|
4209
|
-
maxNetworkRetryDelaySeconds,
|
|
4210
|
-
maxNetworkRetryDelayMs
|
|
4211
|
-
}) ?? ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS,
|
|
4212
4161
|
maxConcurrentRequests,
|
|
4213
|
-
approvalTimeoutMilliseconds:
|
|
4162
|
+
approvalTimeoutMilliseconds: resolveApprovalTimeoutMilliseconds({
|
|
4163
|
+
apiClientDurations: imports.apiClientDurations,
|
|
4164
|
+
sdkOptions
|
|
4165
|
+
}),
|
|
4214
4166
|
maxApprovalRetries,
|
|
4215
4167
|
approvalMode,
|
|
4216
4168
|
openAutoModeApprovalsInBrowser,
|
|
4217
4169
|
callerPackage,
|
|
4170
|
+
cache,
|
|
4218
4171
|
routeOverrides,
|
|
4219
4172
|
// Inject the graph-composed transport so host `dispatchHttpRequest` wraps
|
|
4220
4173
|
// apply.
|
|
@@ -8137,7 +8090,7 @@ var ListConnectionsQuerySchema = ListConnectionsQuerySchema$1.omit({
|
|
|
8137
8090
|
"Include connections shared with you. By default, only your own connections are returned (owner=me). Set to true to also include shared connections."
|
|
8138
8091
|
),
|
|
8139
8092
|
// Filters on connection expiry. Not a mirror of a server-side status
|
|
8140
|
-
// field: the API expresses this as the
|
|
8093
|
+
// field: the API expresses this as the stale filter, which we send as
|
|
8141
8094
|
// false for "active", true for "expired", and omit for "all".
|
|
8142
8095
|
status: z.enum(["active", "expired", "all"]).optional().describe(
|
|
8143
8096
|
"Filter connections by expiry: 'active' (default) returns only non-expired connections, 'expired' only expired ones, and 'all' returns both."
|
|
@@ -8154,7 +8107,11 @@ var ListConnectionsQuerySchema = ListConnectionsQuerySchema$1.omit({
|
|
|
8154
8107
|
deprecated: true,
|
|
8155
8108
|
deprecationMessage: "Use --status expired instead to show only expired connections, or --status all for both."
|
|
8156
8109
|
}),
|
|
8157
|
-
// Override pageSize to make optional
|
|
8110
|
+
// Override pageSize to make optional, and deliberately leave it uncapped:
|
|
8111
|
+
// the authentications endpoint accepts a `limit` well above 1000 (it sets
|
|
8112
|
+
// no max_limit of its own), so a local ceiling would reject input the API
|
|
8113
|
+
// takes. The description keeps hedging because the endpoint stays free to
|
|
8114
|
+
// add one.
|
|
8158
8115
|
pageSize: z.number().min(1).optional().describe(
|
|
8159
8116
|
"Number of connections per page. The upstream API may cap this and reject values above its limit."
|
|
8160
8117
|
),
|
|
@@ -8163,13 +8120,86 @@ var ListConnectionsQuerySchema = ListConnectionsQuerySchema$1.omit({
|
|
|
8163
8120
|
// SDK specific property for pagination/iterable helpers
|
|
8164
8121
|
cursor: z.string().optional().describe("Cursor to start from")
|
|
8165
8122
|
}).describe("List available connections with optional filtering");
|
|
8166
|
-
ConnectionSchema.extend({
|
|
8123
|
+
var RawConnectionSchema = ConnectionSchema.extend({
|
|
8167
8124
|
is_stale: z.boolean().optional(),
|
|
8168
8125
|
is_shared: z.boolean().optional(),
|
|
8169
8126
|
members: z.array(z.record(z.string(), z.any())).optional(),
|
|
8170
8127
|
customuser_id: z.number().nullable().optional(),
|
|
8171
8128
|
customuser_public_id: z.string().nullable().optional()
|
|
8172
8129
|
});
|
|
8130
|
+
var RawConnectionsResponseSchema = ConnectionsResponseSchema.extend({
|
|
8131
|
+
results: z.array(RawConnectionSchema)
|
|
8132
|
+
});
|
|
8133
|
+
|
|
8134
|
+
// src/normalizers/shared.ts
|
|
8135
|
+
function fastifyToString(value) {
|
|
8136
|
+
if (value === void 0) {
|
|
8137
|
+
return void 0;
|
|
8138
|
+
}
|
|
8139
|
+
if (typeof value === "string") {
|
|
8140
|
+
return value;
|
|
8141
|
+
}
|
|
8142
|
+
if (value === null) {
|
|
8143
|
+
return "";
|
|
8144
|
+
}
|
|
8145
|
+
if (value instanceof Date) {
|
|
8146
|
+
return value.toISOString();
|
|
8147
|
+
}
|
|
8148
|
+
if (value instanceof RegExp) {
|
|
8149
|
+
return value.source;
|
|
8150
|
+
}
|
|
8151
|
+
try {
|
|
8152
|
+
return String(value.toString());
|
|
8153
|
+
} catch {
|
|
8154
|
+
return "[unserializable]";
|
|
8155
|
+
}
|
|
8156
|
+
}
|
|
8157
|
+
|
|
8158
|
+
// src/normalizers/connection.ts
|
|
8159
|
+
function normalizeConnectionItem({
|
|
8160
|
+
connection,
|
|
8161
|
+
appKey: providedAppKey,
|
|
8162
|
+
appVersion: providedAppVersion,
|
|
8163
|
+
adaptError
|
|
8164
|
+
}) {
|
|
8165
|
+
let appKey = providedAppKey;
|
|
8166
|
+
let appVersion = providedAppVersion;
|
|
8167
|
+
if (connection.selected_api && typeof connection.selected_api === "string") {
|
|
8168
|
+
const [extractedAppKey, extractedVersion] = splitVersionedKey(
|
|
8169
|
+
connection.selected_api
|
|
8170
|
+
);
|
|
8171
|
+
if (!appKey) {
|
|
8172
|
+
appKey = extractedAppKey;
|
|
8173
|
+
}
|
|
8174
|
+
if (!appVersion) {
|
|
8175
|
+
appVersion = extractedVersion;
|
|
8176
|
+
}
|
|
8177
|
+
}
|
|
8178
|
+
const {
|
|
8179
|
+
selected_api: selectedApi,
|
|
8180
|
+
customuser_id: profileId,
|
|
8181
|
+
id,
|
|
8182
|
+
account_id: accountId,
|
|
8183
|
+
...restOfConnection
|
|
8184
|
+
} = connection;
|
|
8185
|
+
const normalized = {
|
|
8186
|
+
...restOfConnection,
|
|
8187
|
+
id: String(id),
|
|
8188
|
+
account_id: String(accountId),
|
|
8189
|
+
implementation_id: selectedApi,
|
|
8190
|
+
title: connection.title || connection.label || void 0,
|
|
8191
|
+
is_stale: fastifyToString(connection.is_stale),
|
|
8192
|
+
is_expired: fastifyToString(connection.is_stale),
|
|
8193
|
+
is_shared: fastifyToString(connection.is_shared),
|
|
8194
|
+
members: fastifyToString(connection.members),
|
|
8195
|
+
customuser_public_id: fastifyToString(connection.customuser_public_id),
|
|
8196
|
+
expired_at: connection.marked_stale_at,
|
|
8197
|
+
app_key: appKey,
|
|
8198
|
+
app_version: appVersion,
|
|
8199
|
+
profile_id: profileId != null ? String(profileId) : void 0
|
|
8200
|
+
};
|
|
8201
|
+
return createValidator(ConnectionItemSchema, { adaptError })(normalized);
|
|
8202
|
+
}
|
|
8173
8203
|
function formatConnectionItem(item) {
|
|
8174
8204
|
const details = [];
|
|
8175
8205
|
const appKey = item.app_key ?? "unknown";
|
|
@@ -8210,7 +8240,8 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8210
8240
|
connectionsPluginRef,
|
|
8211
8241
|
apiPluginRef,
|
|
8212
8242
|
manifestPluginRef,
|
|
8213
|
-
capabilitiesPluginRef
|
|
8243
|
+
capabilitiesPluginRef,
|
|
8244
|
+
coreOptionsPluginRef
|
|
8214
8245
|
],
|
|
8215
8246
|
categories: ["connection"],
|
|
8216
8247
|
itemType: "Connection",
|
|
@@ -8238,18 +8269,17 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8238
8269
|
await imports.capabilities.checkCapability("canIncludeSharedConnections");
|
|
8239
8270
|
}
|
|
8240
8271
|
const searchParams = {};
|
|
8241
|
-
|
|
8242
|
-
searchParams.page_size = input.pageSize.toString();
|
|
8243
|
-
}
|
|
8272
|
+
searchParams.limit = (input.pageSize ?? DEFAULT_PAGE_SIZE).toString();
|
|
8244
8273
|
const appKey = input.app ?? input.appKey;
|
|
8245
8274
|
if (appKey) {
|
|
8246
8275
|
const implementationId = await getVersionedImplementationId(appKey);
|
|
8247
8276
|
if (implementationId) {
|
|
8248
8277
|
annotate({ selectedApi: implementationId });
|
|
8249
8278
|
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
8250
|
-
searchParams.
|
|
8279
|
+
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
8251
8280
|
} else {
|
|
8252
|
-
|
|
8281
|
+
const [versionlessAppKey] = splitVersionedKey(appKey);
|
|
8282
|
+
searchParams.versionless_selected_api = versionlessAppKey;
|
|
8253
8283
|
}
|
|
8254
8284
|
}
|
|
8255
8285
|
const connectionRefs = input.connections;
|
|
@@ -8263,15 +8293,14 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8263
8293
|
})
|
|
8264
8294
|
)
|
|
8265
8295
|
);
|
|
8266
|
-
searchParams.
|
|
8296
|
+
searchParams.ids = resolvedIds.filter((id) => id != null).join(",");
|
|
8267
8297
|
} else if (legacyConnectionIds && legacyConnectionIds.length > 0) {
|
|
8268
|
-
searchParams.
|
|
8298
|
+
searchParams.ids = legacyConnectionIds.join(",");
|
|
8269
8299
|
}
|
|
8270
8300
|
if (input.search) {
|
|
8271
8301
|
searchParams.search = input.search;
|
|
8272
|
-
}
|
|
8273
|
-
|
|
8274
|
-
searchParams.title = input.title;
|
|
8302
|
+
} else if (input.title) {
|
|
8303
|
+
searchParams.search = input.title;
|
|
8275
8304
|
}
|
|
8276
8305
|
const accountId = input.account ?? input.accountId;
|
|
8277
8306
|
if (accountId) {
|
|
@@ -8294,18 +8323,31 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8294
8323
|
}
|
|
8295
8324
|
const status = input.status ?? (expiredFilter ? "expired" : "active");
|
|
8296
8325
|
if (status !== "all") {
|
|
8297
|
-
searchParams.
|
|
8326
|
+
searchParams.stale = (status === "expired").toString();
|
|
8298
8327
|
}
|
|
8299
8328
|
if (input.cursor) {
|
|
8300
8329
|
searchParams.offset = input.cursor;
|
|
8301
8330
|
}
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8331
|
+
searchParams.ordering = "personal_first";
|
|
8332
|
+
const rawResponse = await api.get("/zapier/api/v4/authentications", {
|
|
8333
|
+
searchParams,
|
|
8334
|
+
authRequired: true
|
|
8335
|
+
});
|
|
8336
|
+
const raw = createValidator(RawConnectionsResponseSchema, {
|
|
8337
|
+
adaptError: imports.coreOptions?.adaptError
|
|
8338
|
+
})(rawResponse);
|
|
8339
|
+
let connections = raw.results.map(
|
|
8340
|
+
(connection) => normalizeConnectionItem({
|
|
8341
|
+
connection,
|
|
8342
|
+
adaptError: imports.coreOptions?.adaptError
|
|
8343
|
+
})
|
|
8305
8344
|
);
|
|
8345
|
+
if (input.title) {
|
|
8346
|
+
connections = connections.filter((conn) => conn.title === input.title);
|
|
8347
|
+
}
|
|
8306
8348
|
return {
|
|
8307
|
-
|
|
8308
|
-
|
|
8349
|
+
data: connections.map(transformConnectionItem),
|
|
8350
|
+
next: raw.next ?? null
|
|
8309
8351
|
};
|
|
8310
8352
|
}
|
|
8311
8353
|
});
|
|
@@ -8481,76 +8523,6 @@ var getAppPlugin = defineMethod({
|
|
|
8481
8523
|
throw new ZapierAppNotFoundError("App not found", { appKey });
|
|
8482
8524
|
}
|
|
8483
8525
|
});
|
|
8484
|
-
|
|
8485
|
-
// src/normalizers/shared.ts
|
|
8486
|
-
function fastifyToString(value) {
|
|
8487
|
-
if (value === void 0) {
|
|
8488
|
-
return void 0;
|
|
8489
|
-
}
|
|
8490
|
-
if (typeof value === "string") {
|
|
8491
|
-
return value;
|
|
8492
|
-
}
|
|
8493
|
-
if (value === null) {
|
|
8494
|
-
return "";
|
|
8495
|
-
}
|
|
8496
|
-
if (value instanceof Date) {
|
|
8497
|
-
return value.toISOString();
|
|
8498
|
-
}
|
|
8499
|
-
if (value instanceof RegExp) {
|
|
8500
|
-
return value.source;
|
|
8501
|
-
}
|
|
8502
|
-
try {
|
|
8503
|
-
return String(value.toString());
|
|
8504
|
-
} catch {
|
|
8505
|
-
return "[unserializable]";
|
|
8506
|
-
}
|
|
8507
|
-
}
|
|
8508
|
-
|
|
8509
|
-
// src/normalizers/connection.ts
|
|
8510
|
-
function normalizeConnectionItem({
|
|
8511
|
-
connection,
|
|
8512
|
-
appKey: providedAppKey,
|
|
8513
|
-
appVersion: providedAppVersion,
|
|
8514
|
-
adaptError
|
|
8515
|
-
}) {
|
|
8516
|
-
let appKey = providedAppKey;
|
|
8517
|
-
let appVersion = providedAppVersion;
|
|
8518
|
-
if (connection.selected_api && typeof connection.selected_api === "string") {
|
|
8519
|
-
const [extractedAppKey, extractedVersion] = splitVersionedKey(
|
|
8520
|
-
connection.selected_api
|
|
8521
|
-
);
|
|
8522
|
-
if (!appKey) {
|
|
8523
|
-
appKey = extractedAppKey;
|
|
8524
|
-
}
|
|
8525
|
-
if (!appVersion) {
|
|
8526
|
-
appVersion = extractedVersion;
|
|
8527
|
-
}
|
|
8528
|
-
}
|
|
8529
|
-
const {
|
|
8530
|
-
selected_api: selectedApi,
|
|
8531
|
-
customuser_id: profileId,
|
|
8532
|
-
id,
|
|
8533
|
-
account_id: accountId,
|
|
8534
|
-
...restOfConnection
|
|
8535
|
-
} = connection;
|
|
8536
|
-
const normalized = {
|
|
8537
|
-
...restOfConnection,
|
|
8538
|
-
id: String(id),
|
|
8539
|
-
account_id: String(accountId),
|
|
8540
|
-
implementation_id: selectedApi,
|
|
8541
|
-
title: connection.title || connection.label || void 0,
|
|
8542
|
-
is_stale: fastifyToString(connection.is_stale),
|
|
8543
|
-
is_expired: fastifyToString(connection.is_stale),
|
|
8544
|
-
is_shared: fastifyToString(connection.is_shared),
|
|
8545
|
-
members: fastifyToString(connection.members),
|
|
8546
|
-
customuser_public_id: fastifyToString(connection.customuser_public_id),
|
|
8547
|
-
expired_at: connection.marked_stale_at,
|
|
8548
|
-
app_key: appKey,
|
|
8549
|
-
app_version: appVersion,
|
|
8550
|
-
profile_id: profileId != null ? String(profileId) : void 0
|
|
8551
|
-
};
|
|
8552
|
-
return createValidator(ConnectionItemSchema, { adaptError })(normalized);
|
|
8553
|
-
}
|
|
8554
8526
|
var GetConnectionDescription = "Get details for a specific connection";
|
|
8555
8527
|
var GetConnectionSchema = z.object({
|
|
8556
8528
|
connection: ConnectionPropertySchema
|
|
@@ -8945,7 +8917,7 @@ var WaitForNewConnectionSchema = z.object({
|
|
|
8945
8917
|
"Delay before the first poll request, in ms. Default 3 seconds (3_000). Subsequent polling cadence is managed by the SDK's polling primitive (backoff with sane defaults)."
|
|
8946
8918
|
).meta({ deprecated: true })
|
|
8947
8919
|
}).describe(
|
|
8948
|
-
"Wait for a new connection to appear for the given app. Polls
|
|
8920
|
+
"Wait for a new connection to appear for the given app. Polls the connections list newest-first until the most recent matching row's `date` is at or after the started-at timestamp, then returns it. Pair with `get-connection-start-url` \u2014 that mints the URL the user opens, this waits for the resulting connection to land. Errors with a timeout after the configured timeout (default 5 min). Example (JS):\n\n```ts\nconst { data: { url, app, startedAt } } = await zapier.getConnectionStartUrl({ app: 'slack' });\n// show `url` to the user via the channel they're reading from\nconst { data: conn } = await zapier.waitForNewConnection({ app, startedAt });\n```"
|
|
8949
8921
|
);
|
|
8950
8922
|
var WaitForNewConnectionItemSchema = z.object({
|
|
8951
8923
|
id: z.string().describe(
|
|
@@ -8958,12 +8930,22 @@ var WaitForNewConnectionItemSchema = z.object({
|
|
|
8958
8930
|
"Human-readable connection title set by the auth flow, when available."
|
|
8959
8931
|
)
|
|
8960
8932
|
}).describe("The new connection that was detected.");
|
|
8933
|
+
var WaitForNewConnectionRowSchema = z.object({
|
|
8934
|
+
id: z.union([z.string(), z.number()]),
|
|
8935
|
+
public_id: z.string().optional(),
|
|
8936
|
+
date: z.string().optional(),
|
|
8937
|
+
title: z.string().nullable().optional(),
|
|
8938
|
+
label: z.string().nullable().optional()
|
|
8939
|
+
});
|
|
8940
|
+
var WaitForNewConnectionResponseSchema = z.object({
|
|
8941
|
+
results: z.array(WaitForNewConnectionRowSchema)
|
|
8942
|
+
});
|
|
8961
8943
|
|
|
8962
8944
|
// src/plugins/waitForNewConnection/index.ts
|
|
8963
|
-
var CONNECTIONS_PATH = "/api/
|
|
8945
|
+
var CONNECTIONS_PATH = "/zapier/api/v4/authentications";
|
|
8964
8946
|
var waitForNewConnectionPlugin = defineMethod({
|
|
8965
8947
|
name: "waitForNewConnection",
|
|
8966
|
-
imports: [manifestPluginRef, apiPluginRef],
|
|
8948
|
+
imports: [manifestPluginRef, apiPluginRef, coreOptionsPluginRef],
|
|
8967
8949
|
categories: ["connection"],
|
|
8968
8950
|
itemType: "Connection",
|
|
8969
8951
|
inputSchema: WaitForNewConnectionSchema,
|
|
@@ -8974,27 +8956,31 @@ var waitForNewConnectionPlugin = defineMethod({
|
|
|
8974
8956
|
run: async ({ imports, input, annotate }) => {
|
|
8975
8957
|
const api = imports.api;
|
|
8976
8958
|
const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
|
|
8959
|
+
const validateConnectionsResponse = createValidator(
|
|
8960
|
+
WaitForNewConnectionResponseSchema,
|
|
8961
|
+
{ adaptError: imports.coreOptions?.adaptError }
|
|
8962
|
+
);
|
|
8977
8963
|
const versionedKey = await getVersionedImplementationId(input.app);
|
|
8978
|
-
const appKey = versionedKey
|
|
8964
|
+
const [appKey] = splitVersionedKey(versionedKey ?? input.app);
|
|
8979
8965
|
annotate({ selectedApi: appKey });
|
|
8980
8966
|
try {
|
|
8981
8967
|
const top = await api.poll(CONNECTIONS_PATH, {
|
|
8982
8968
|
searchParams: {
|
|
8983
|
-
|
|
8969
|
+
versionless_selected_api: appKey,
|
|
8984
8970
|
// Scope to the current user's own connections. The connection we're
|
|
8985
8971
|
// waiting on is by definition owned by the caller; without this the
|
|
8986
8972
|
// one-row head-check could match a teammate's freshly created
|
|
8987
8973
|
// connection for the same app.
|
|
8988
8974
|
owner: "me",
|
|
8989
|
-
|
|
8975
|
+
stale: "false",
|
|
8990
8976
|
ordering: "-date",
|
|
8991
|
-
|
|
8977
|
+
limit: "1"
|
|
8992
8978
|
},
|
|
8993
8979
|
authRequired: true,
|
|
8994
8980
|
timeoutMilliseconds: input.timeoutSeconds != null ? input.timeoutSeconds * 1e3 : input.timeoutMs ?? 3e5,
|
|
8995
8981
|
initialDelayMilliseconds: input.pollIntervalMilliseconds ?? input.pollIntervalMs ?? 3e3,
|
|
8996
8982
|
isPending: (body) => {
|
|
8997
|
-
const rows = body.
|
|
8983
|
+
const rows = validateConnectionsResponse(body).results;
|
|
8998
8984
|
const head = rows[0];
|
|
8999
8985
|
if (!head?.date) return true;
|
|
9000
8986
|
const created = Math.floor(new Date(head.date).getTime() / 1e3);
|
|
@@ -9002,14 +8988,14 @@ var waitForNewConnectionPlugin = defineMethod({
|
|
|
9002
8988
|
},
|
|
9003
8989
|
resultExtractor: (body) => (
|
|
9004
8990
|
// `isPending` guaranteed a fresh row at index 0 before this fires.
|
|
9005
|
-
body.
|
|
8991
|
+
validateConnectionsResponse(body).results[0]
|
|
9006
8992
|
)
|
|
9007
8993
|
});
|
|
9008
8994
|
return {
|
|
9009
8995
|
data: WaitForNewConnectionItemSchema.parse({
|
|
9010
8996
|
id: String(top.public_id ?? top.id),
|
|
9011
8997
|
app: appKey,
|
|
9012
|
-
title: top.title
|
|
8998
|
+
title: top.title || top.label || null
|
|
9013
8999
|
})
|
|
9014
9000
|
};
|
|
9015
9001
|
} catch (err) {
|
|
@@ -10481,6 +10467,112 @@ var drainTriggerInboxPlugin = defineMethod({
|
|
|
10481
10467
|
});
|
|
10482
10468
|
}
|
|
10483
10469
|
});
|
|
10470
|
+
var apiClientRootPlugin = definePlugin({
|
|
10471
|
+
namespace: "zapier",
|
|
10472
|
+
name: "apiClientRoot",
|
|
10473
|
+
imports: [apiPlugin],
|
|
10474
|
+
exports: []
|
|
10475
|
+
});
|
|
10476
|
+
function hasStringUrl(request) {
|
|
10477
|
+
return typeof request.url === "string";
|
|
10478
|
+
}
|
|
10479
|
+
function createApiClientGraphConfiguration(options) {
|
|
10480
|
+
const {
|
|
10481
|
+
maxNetworkRetryDelayMilliseconds,
|
|
10482
|
+
maxNetworkRetryDelayMs,
|
|
10483
|
+
approvalTimeoutMilliseconds,
|
|
10484
|
+
approvalTimeoutMs,
|
|
10485
|
+
sendHttpRequest: _sendHttpRequest,
|
|
10486
|
+
...sdkOptions
|
|
10487
|
+
} = options;
|
|
10488
|
+
return {
|
|
10489
|
+
[SDK_OPTIONS_ID]: sdkOptions,
|
|
10490
|
+
[API_CLIENT_DURATIONS_ID]: {
|
|
10491
|
+
maxNetworkRetryDelayMilliseconds: maxNetworkRetryDelayMilliseconds ?? maxNetworkRetryDelayMs,
|
|
10492
|
+
approvalTimeoutMilliseconds: approvalTimeoutMilliseconds ?? approvalTimeoutMs
|
|
10493
|
+
}
|
|
10494
|
+
};
|
|
10495
|
+
}
|
|
10496
|
+
function createApiClientFromSdkGraph(options) {
|
|
10497
|
+
parseRoutingOptions({ options });
|
|
10498
|
+
const configuration = createApiClientGraphConfiguration(options);
|
|
10499
|
+
const { sendHttpRequest } = options;
|
|
10500
|
+
if (!sendHttpRequest) {
|
|
10501
|
+
const sdk2 = createSdk(apiClientRootPlugin, { configuration });
|
|
10502
|
+
return resolvePlugin(sdk2, apiPluginRef);
|
|
10503
|
+
}
|
|
10504
|
+
const replaceSendHttpRequestPlugin = defineHook({
|
|
10505
|
+
namespace: "zapier",
|
|
10506
|
+
name: "replaceApiClientSendHttpRequest",
|
|
10507
|
+
imports: [sendHttpRequestPlugin],
|
|
10508
|
+
wrap: {
|
|
10509
|
+
// Replaces the pipeline rather than wrapping it: `next` is deliberately
|
|
10510
|
+
// unused. A transport supplied through `sendHttpRequest` owns its retry
|
|
10511
|
+
// policy, so running the SDK's stages underneath would nest the caller's
|
|
10512
|
+
// retry loop inside a second one. Dropping them is only safe because the
|
|
10513
|
+
// SDK's retry hook wraps `attemptHttpRequest`, a stage below this seam,
|
|
10514
|
+
// so replacing `sendHttpRequest` removes that loop instead of nesting
|
|
10515
|
+
// inside it. The cost is that the SDK cannot observe retries the caller
|
|
10516
|
+
// performs, and so reports a terminal 429 as zero.
|
|
10517
|
+
sendHttpRequest: ({ input }) => sendHttpRequest(
|
|
10518
|
+
hasStringUrl(input) ? input : { ...input, url: input.url.toString() }
|
|
10519
|
+
)
|
|
10520
|
+
}
|
|
10521
|
+
});
|
|
10522
|
+
const sdk = createSdk(
|
|
10523
|
+
definePlugin({
|
|
10524
|
+
namespace: "zapier",
|
|
10525
|
+
name: "standaloneApiClientRoot",
|
|
10526
|
+
imports: [apiPlugin, replaceSendHttpRequestPlugin],
|
|
10527
|
+
exports: []
|
|
10528
|
+
}),
|
|
10529
|
+
{ configuration }
|
|
10530
|
+
);
|
|
10531
|
+
return resolvePlugin(sdk, apiPluginRef);
|
|
10532
|
+
}
|
|
10533
|
+
|
|
10534
|
+
// src/api/error-classification.ts
|
|
10535
|
+
function isPermanentHttpError(err) {
|
|
10536
|
+
if (!isZapierError(err)) return false;
|
|
10537
|
+
if (isZapierAuthenticationError(err) && err.statusCode === void 0) {
|
|
10538
|
+
return true;
|
|
10539
|
+
}
|
|
10540
|
+
const { statusCode } = err;
|
|
10541
|
+
return statusCode !== void 0 && statusCode >= 400 && statusCode < 500 && statusCode !== 429;
|
|
10542
|
+
}
|
|
10543
|
+
|
|
10544
|
+
// src/api/index.ts
|
|
10545
|
+
function createZapierApi(options) {
|
|
10546
|
+
logDeprecation(
|
|
10547
|
+
"createZapierApi is deprecated and will be removed in a future release. Build an SDK with createSdk and access apiPluginRef with resolvePlugin instead."
|
|
10548
|
+
);
|
|
10549
|
+
return createApiClientFromSdkGraph(options);
|
|
10550
|
+
}
|
|
10551
|
+
function getOrCreateApiClient(config) {
|
|
10552
|
+
logDeprecation(
|
|
10553
|
+
"getOrCreateApiClient is deprecated and will be removed in a future release. Use a provided API client directly, or build an SDK with createSdk and access apiPluginRef with resolvePlugin."
|
|
10554
|
+
);
|
|
10555
|
+
const {
|
|
10556
|
+
baseUrl = ZAPIER_BASE_URL,
|
|
10557
|
+
credentials,
|
|
10558
|
+
token,
|
|
10559
|
+
api: providedApi,
|
|
10560
|
+
debug = false,
|
|
10561
|
+
fetch: customFetch,
|
|
10562
|
+
callerPackage
|
|
10563
|
+
} = config;
|
|
10564
|
+
if (providedApi) {
|
|
10565
|
+
return providedApi;
|
|
10566
|
+
}
|
|
10567
|
+
return createApiClientFromSdkGraph({
|
|
10568
|
+
baseUrl,
|
|
10569
|
+
credentials,
|
|
10570
|
+
token,
|
|
10571
|
+
debug,
|
|
10572
|
+
fetch: customFetch,
|
|
10573
|
+
callerPackage
|
|
10574
|
+
});
|
|
10575
|
+
}
|
|
10484
10576
|
|
|
10485
10577
|
// src/plugins/triggers/watchTriggerInbox/sse.ts
|
|
10486
10578
|
async function* readInboxEvents({
|