@zapier/zapier-sdk 0.107.2 → 0.108.1
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 +39 -0
- package/README.md +320 -1
- package/dist/{chunk-Y7CGEGII.cjs → chunk-OS45HFVJ.cjs} +168 -123
- package/dist/{chunk-HYFM3H36.mjs → chunk-S7XDZGKJ.mjs} +169 -124
- package/dist/experimental.cjs +849 -370
- package/dist/experimental.d.mts +598 -19
- package/dist/experimental.d.ts +598 -19
- package/dist/experimental.mjs +483 -4
- package/dist/{index-wTDIVpGJ.d.mts → index-BUYztqGh.d.mts} +20 -12
- package/dist/{index-wTDIVpGJ.d.ts → index-BUYztqGh.d.ts} +20 -12
- 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
|
@@ -4,7 +4,7 @@ import { withPositional, declareOptionalProperty, defineProperty, createDeprecat
|
|
|
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
|
|
@@ -862,8 +862,16 @@ var processResponse = async (response, successStatus, pendingStatus, isPending,
|
|
|
862
862
|
};
|
|
863
863
|
}
|
|
864
864
|
if (response.status === successStatus) {
|
|
865
|
+
let resultJson;
|
|
866
|
+
try {
|
|
867
|
+
resultJson = await response.json();
|
|
868
|
+
} catch (error) {
|
|
869
|
+
throw new ZapierApiError("Poll response body was not valid JSON", {
|
|
870
|
+
statusCode: response.status,
|
|
871
|
+
cause: error
|
|
872
|
+
});
|
|
873
|
+
}
|
|
865
874
|
try {
|
|
866
|
-
const resultJson = await response.json();
|
|
867
875
|
if (isPending && isPending(resultJson)) {
|
|
868
876
|
return {
|
|
869
877
|
status: "continue" /* Continue */,
|
|
@@ -876,13 +884,7 @@ var processResponse = async (response, successStatus, pendingStatus, isPending,
|
|
|
876
884
|
errorCount: 0
|
|
877
885
|
};
|
|
878
886
|
} catch (error) {
|
|
879
|
-
|
|
880
|
-
"Result extractor failed to parse successful response as JSON",
|
|
881
|
-
{
|
|
882
|
-
statusCode: response.status,
|
|
883
|
-
cause: error
|
|
884
|
-
}
|
|
885
|
-
);
|
|
887
|
+
return { status: "failed" /* Failed */, error, errorCount };
|
|
886
888
|
}
|
|
887
889
|
}
|
|
888
890
|
if (response.status !== pendingStatus) {
|
|
@@ -955,13 +957,10 @@ async function pollUntilComplete(options) {
|
|
|
955
957
|
if (signal?.aborted) throw makeAbortError();
|
|
956
958
|
}
|
|
957
959
|
attempts++;
|
|
960
|
+
let terminalThrow;
|
|
958
961
|
try {
|
|
959
962
|
const response = await fetchPoll();
|
|
960
|
-
const
|
|
961
|
-
result,
|
|
962
|
-
errorCount: newErrorCount,
|
|
963
|
-
status
|
|
964
|
-
} = await processResponse(
|
|
963
|
+
const pollResult = await processResponse(
|
|
965
964
|
response,
|
|
966
965
|
successStatus,
|
|
967
966
|
pendingStatus,
|
|
@@ -969,15 +968,18 @@ async function pollUntilComplete(options) {
|
|
|
969
968
|
resultExtractor,
|
|
970
969
|
errorCount
|
|
971
970
|
);
|
|
972
|
-
errorCount =
|
|
973
|
-
if (status === "
|
|
974
|
-
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
971
|
+
errorCount = pollResult.errorCount;
|
|
972
|
+
if (pollResult.status === "failed" /* Failed */) {
|
|
973
|
+
terminalThrow = { error: pollResult.error };
|
|
974
|
+
} else if (pollResult.status === "success" /* Success */) {
|
|
975
|
+
return pollResult.result;
|
|
976
|
+
} else if (errorCount >= MAX_CONSECUTIVE_ERRORS) {
|
|
977
|
+
terminalThrow = {
|
|
978
|
+
error: new ZapierApiError(
|
|
979
|
+
`Poll request failed: ${response.status} ${response.statusText}`,
|
|
980
|
+
{ statusCode: response.status }
|
|
981
|
+
)
|
|
982
|
+
};
|
|
981
983
|
}
|
|
982
984
|
} catch (error) {
|
|
983
985
|
if (isAbortError(error)) throw error;
|
|
@@ -991,6 +993,7 @@ async function pollUntilComplete(options) {
|
|
|
991
993
|
);
|
|
992
994
|
}
|
|
993
995
|
}
|
|
996
|
+
if (terminalThrow) throw terminalThrow.error;
|
|
994
997
|
}
|
|
995
998
|
}
|
|
996
999
|
|
|
@@ -2332,6 +2335,15 @@ var pathConfig = {
|
|
|
2332
2335
|
"/agentic-management": {
|
|
2333
2336
|
authHeader: "Authorization",
|
|
2334
2337
|
subdomain: "api"
|
|
2338
|
+
},
|
|
2339
|
+
// e.g. /vfs/v1/files -> https://api.zapier.com/vfs/v1/files
|
|
2340
|
+
// The VFS API is registered on the Public API Gateway and has no sdkapi
|
|
2341
|
+
// proxy route, so it goes straight to the gateway. Its governance metadata
|
|
2342
|
+
// rewrites /vfs/v1/... to the backend's /api/v1/fs/..., which is why no
|
|
2343
|
+
// pathPrefix is applied here.
|
|
2344
|
+
"/vfs": {
|
|
2345
|
+
authHeader: "Authorization",
|
|
2346
|
+
subdomain: "api"
|
|
2335
2347
|
}
|
|
2336
2348
|
};
|
|
2337
2349
|
|
|
@@ -2866,7 +2878,7 @@ function logRouteOverride({
|
|
|
2866
2878
|
}
|
|
2867
2879
|
|
|
2868
2880
|
// src/sdk-version.ts
|
|
2869
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
2881
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.108.1" : void 0) || "unknown";
|
|
2870
2882
|
|
|
2871
2883
|
// src/utils/open-url.ts
|
|
2872
2884
|
var nodePrefix = "node:";
|
|
@@ -8128,7 +8140,7 @@ var ListConnectionsQuerySchema = ListConnectionsQuerySchema$1.omit({
|
|
|
8128
8140
|
"Include connections shared with you. By default, only your own connections are returned (owner=me). Set to true to also include shared connections."
|
|
8129
8141
|
),
|
|
8130
8142
|
// Filters on connection expiry. Not a mirror of a server-side status
|
|
8131
|
-
// field: the API expresses this as the
|
|
8143
|
+
// field: the API expresses this as the stale filter, which we send as
|
|
8132
8144
|
// false for "active", true for "expired", and omit for "all".
|
|
8133
8145
|
status: z.enum(["active", "expired", "all"]).optional().describe(
|
|
8134
8146
|
"Filter connections by expiry: 'active' (default) returns only non-expired connections, 'expired' only expired ones, and 'all' returns both."
|
|
@@ -8145,7 +8157,11 @@ var ListConnectionsQuerySchema = ListConnectionsQuerySchema$1.omit({
|
|
|
8145
8157
|
deprecated: true,
|
|
8146
8158
|
deprecationMessage: "Use --status expired instead to show only expired connections, or --status all for both."
|
|
8147
8159
|
}),
|
|
8148
|
-
// Override pageSize to make optional
|
|
8160
|
+
// Override pageSize to make optional, and deliberately leave it uncapped:
|
|
8161
|
+
// the authentications endpoint accepts a `limit` well above 1000 (it sets
|
|
8162
|
+
// no max_limit of its own), so a local ceiling would reject input the API
|
|
8163
|
+
// takes. The description keeps hedging because the endpoint stays free to
|
|
8164
|
+
// add one.
|
|
8149
8165
|
pageSize: z.number().min(1).optional().describe(
|
|
8150
8166
|
"Number of connections per page. The upstream API may cap this and reject values above its limit."
|
|
8151
8167
|
),
|
|
@@ -8154,13 +8170,86 @@ var ListConnectionsQuerySchema = ListConnectionsQuerySchema$1.omit({
|
|
|
8154
8170
|
// SDK specific property for pagination/iterable helpers
|
|
8155
8171
|
cursor: z.string().optional().describe("Cursor to start from")
|
|
8156
8172
|
}).describe("List available connections with optional filtering");
|
|
8157
|
-
ConnectionSchema.extend({
|
|
8173
|
+
var RawConnectionSchema = ConnectionSchema.extend({
|
|
8158
8174
|
is_stale: z.boolean().optional(),
|
|
8159
8175
|
is_shared: z.boolean().optional(),
|
|
8160
8176
|
members: z.array(z.record(z.string(), z.any())).optional(),
|
|
8161
8177
|
customuser_id: z.number().nullable().optional(),
|
|
8162
8178
|
customuser_public_id: z.string().nullable().optional()
|
|
8163
8179
|
});
|
|
8180
|
+
var RawConnectionsResponseSchema = ConnectionsResponseSchema.extend({
|
|
8181
|
+
results: z.array(RawConnectionSchema)
|
|
8182
|
+
});
|
|
8183
|
+
|
|
8184
|
+
// src/normalizers/shared.ts
|
|
8185
|
+
function fastifyToString(value) {
|
|
8186
|
+
if (value === void 0) {
|
|
8187
|
+
return void 0;
|
|
8188
|
+
}
|
|
8189
|
+
if (typeof value === "string") {
|
|
8190
|
+
return value;
|
|
8191
|
+
}
|
|
8192
|
+
if (value === null) {
|
|
8193
|
+
return "";
|
|
8194
|
+
}
|
|
8195
|
+
if (value instanceof Date) {
|
|
8196
|
+
return value.toISOString();
|
|
8197
|
+
}
|
|
8198
|
+
if (value instanceof RegExp) {
|
|
8199
|
+
return value.source;
|
|
8200
|
+
}
|
|
8201
|
+
try {
|
|
8202
|
+
return String(value.toString());
|
|
8203
|
+
} catch {
|
|
8204
|
+
return "[unserializable]";
|
|
8205
|
+
}
|
|
8206
|
+
}
|
|
8207
|
+
|
|
8208
|
+
// src/normalizers/connection.ts
|
|
8209
|
+
function normalizeConnectionItem({
|
|
8210
|
+
connection,
|
|
8211
|
+
appKey: providedAppKey,
|
|
8212
|
+
appVersion: providedAppVersion,
|
|
8213
|
+
adaptError
|
|
8214
|
+
}) {
|
|
8215
|
+
let appKey = providedAppKey;
|
|
8216
|
+
let appVersion = providedAppVersion;
|
|
8217
|
+
if (connection.selected_api && typeof connection.selected_api === "string") {
|
|
8218
|
+
const [extractedAppKey, extractedVersion] = splitVersionedKey(
|
|
8219
|
+
connection.selected_api
|
|
8220
|
+
);
|
|
8221
|
+
if (!appKey) {
|
|
8222
|
+
appKey = extractedAppKey;
|
|
8223
|
+
}
|
|
8224
|
+
if (!appVersion) {
|
|
8225
|
+
appVersion = extractedVersion;
|
|
8226
|
+
}
|
|
8227
|
+
}
|
|
8228
|
+
const {
|
|
8229
|
+
selected_api: selectedApi,
|
|
8230
|
+
customuser_id: profileId,
|
|
8231
|
+
id,
|
|
8232
|
+
account_id: accountId,
|
|
8233
|
+
...restOfConnection
|
|
8234
|
+
} = connection;
|
|
8235
|
+
const normalized = {
|
|
8236
|
+
...restOfConnection,
|
|
8237
|
+
id: String(id),
|
|
8238
|
+
account_id: String(accountId),
|
|
8239
|
+
implementation_id: selectedApi,
|
|
8240
|
+
title: connection.title || connection.label || void 0,
|
|
8241
|
+
is_stale: fastifyToString(connection.is_stale),
|
|
8242
|
+
is_expired: fastifyToString(connection.is_stale),
|
|
8243
|
+
is_shared: fastifyToString(connection.is_shared),
|
|
8244
|
+
members: fastifyToString(connection.members),
|
|
8245
|
+
customuser_public_id: fastifyToString(connection.customuser_public_id),
|
|
8246
|
+
expired_at: connection.marked_stale_at,
|
|
8247
|
+
app_key: appKey,
|
|
8248
|
+
app_version: appVersion,
|
|
8249
|
+
profile_id: profileId != null ? String(profileId) : void 0
|
|
8250
|
+
};
|
|
8251
|
+
return createValidator(ConnectionItemSchema, { adaptError })(normalized);
|
|
8252
|
+
}
|
|
8164
8253
|
function formatConnectionItem(item) {
|
|
8165
8254
|
const details = [];
|
|
8166
8255
|
const appKey = item.app_key ?? "unknown";
|
|
@@ -8201,7 +8290,8 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8201
8290
|
connectionsPluginRef,
|
|
8202
8291
|
apiPluginRef,
|
|
8203
8292
|
manifestPluginRef,
|
|
8204
|
-
capabilitiesPluginRef
|
|
8293
|
+
capabilitiesPluginRef,
|
|
8294
|
+
coreOptionsPluginRef
|
|
8205
8295
|
],
|
|
8206
8296
|
categories: ["connection"],
|
|
8207
8297
|
itemType: "Connection",
|
|
@@ -8229,18 +8319,17 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8229
8319
|
await imports.capabilities.checkCapability("canIncludeSharedConnections");
|
|
8230
8320
|
}
|
|
8231
8321
|
const searchParams = {};
|
|
8232
|
-
|
|
8233
|
-
searchParams.page_size = input.pageSize.toString();
|
|
8234
|
-
}
|
|
8322
|
+
searchParams.limit = (input.pageSize ?? DEFAULT_PAGE_SIZE).toString();
|
|
8235
8323
|
const appKey = input.app ?? input.appKey;
|
|
8236
8324
|
if (appKey) {
|
|
8237
8325
|
const implementationId = await getVersionedImplementationId(appKey);
|
|
8238
8326
|
if (implementationId) {
|
|
8239
8327
|
annotate({ selectedApi: implementationId });
|
|
8240
8328
|
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
8241
|
-
searchParams.
|
|
8329
|
+
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
8242
8330
|
} else {
|
|
8243
|
-
|
|
8331
|
+
const [versionlessAppKey] = splitVersionedKey(appKey);
|
|
8332
|
+
searchParams.versionless_selected_api = versionlessAppKey;
|
|
8244
8333
|
}
|
|
8245
8334
|
}
|
|
8246
8335
|
const connectionRefs = input.connections;
|
|
@@ -8254,15 +8343,14 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8254
8343
|
})
|
|
8255
8344
|
)
|
|
8256
8345
|
);
|
|
8257
|
-
searchParams.
|
|
8346
|
+
searchParams.ids = resolvedIds.filter((id) => id != null).join(",");
|
|
8258
8347
|
} else if (legacyConnectionIds && legacyConnectionIds.length > 0) {
|
|
8259
|
-
searchParams.
|
|
8348
|
+
searchParams.ids = legacyConnectionIds.join(",");
|
|
8260
8349
|
}
|
|
8261
8350
|
if (input.search) {
|
|
8262
8351
|
searchParams.search = input.search;
|
|
8263
|
-
}
|
|
8264
|
-
|
|
8265
|
-
searchParams.title = input.title;
|
|
8352
|
+
} else if (input.title) {
|
|
8353
|
+
searchParams.search = input.title;
|
|
8266
8354
|
}
|
|
8267
8355
|
const accountId = input.account ?? input.accountId;
|
|
8268
8356
|
if (accountId) {
|
|
@@ -8285,18 +8373,31 @@ var listConnectionsPlugin = defineMethod({
|
|
|
8285
8373
|
}
|
|
8286
8374
|
const status = input.status ?? (expiredFilter ? "expired" : "active");
|
|
8287
8375
|
if (status !== "all") {
|
|
8288
|
-
searchParams.
|
|
8376
|
+
searchParams.stale = (status === "expired").toString();
|
|
8289
8377
|
}
|
|
8290
8378
|
if (input.cursor) {
|
|
8291
8379
|
searchParams.offset = input.cursor;
|
|
8292
8380
|
}
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8381
|
+
searchParams.ordering = "personal_first";
|
|
8382
|
+
const rawResponse = await api.get("/zapier/api/v4/authentications", {
|
|
8383
|
+
searchParams,
|
|
8384
|
+
authRequired: true
|
|
8385
|
+
});
|
|
8386
|
+
const raw = createValidator(RawConnectionsResponseSchema, {
|
|
8387
|
+
adaptError: imports.coreOptions?.adaptError
|
|
8388
|
+
})(rawResponse);
|
|
8389
|
+
let connections = raw.results.map(
|
|
8390
|
+
(connection) => normalizeConnectionItem({
|
|
8391
|
+
connection,
|
|
8392
|
+
adaptError: imports.coreOptions?.adaptError
|
|
8393
|
+
})
|
|
8296
8394
|
);
|
|
8395
|
+
if (input.title) {
|
|
8396
|
+
connections = connections.filter((conn) => conn.title === input.title);
|
|
8397
|
+
}
|
|
8297
8398
|
return {
|
|
8298
|
-
|
|
8299
|
-
|
|
8399
|
+
data: connections.map(transformConnectionItem),
|
|
8400
|
+
next: raw.next ?? null
|
|
8300
8401
|
};
|
|
8301
8402
|
}
|
|
8302
8403
|
});
|
|
@@ -8472,76 +8573,6 @@ var getAppPlugin = defineMethod({
|
|
|
8472
8573
|
throw new ZapierAppNotFoundError("App not found", { appKey });
|
|
8473
8574
|
}
|
|
8474
8575
|
});
|
|
8475
|
-
|
|
8476
|
-
// src/normalizers/shared.ts
|
|
8477
|
-
function fastifyToString(value) {
|
|
8478
|
-
if (value === void 0) {
|
|
8479
|
-
return void 0;
|
|
8480
|
-
}
|
|
8481
|
-
if (typeof value === "string") {
|
|
8482
|
-
return value;
|
|
8483
|
-
}
|
|
8484
|
-
if (value === null) {
|
|
8485
|
-
return "";
|
|
8486
|
-
}
|
|
8487
|
-
if (value instanceof Date) {
|
|
8488
|
-
return value.toISOString();
|
|
8489
|
-
}
|
|
8490
|
-
if (value instanceof RegExp) {
|
|
8491
|
-
return value.source;
|
|
8492
|
-
}
|
|
8493
|
-
try {
|
|
8494
|
-
return String(value.toString());
|
|
8495
|
-
} catch {
|
|
8496
|
-
return "[unserializable]";
|
|
8497
|
-
}
|
|
8498
|
-
}
|
|
8499
|
-
|
|
8500
|
-
// src/normalizers/connection.ts
|
|
8501
|
-
function normalizeConnectionItem({
|
|
8502
|
-
connection,
|
|
8503
|
-
appKey: providedAppKey,
|
|
8504
|
-
appVersion: providedAppVersion,
|
|
8505
|
-
adaptError
|
|
8506
|
-
}) {
|
|
8507
|
-
let appKey = providedAppKey;
|
|
8508
|
-
let appVersion = providedAppVersion;
|
|
8509
|
-
if (connection.selected_api && typeof connection.selected_api === "string") {
|
|
8510
|
-
const [extractedAppKey, extractedVersion] = splitVersionedKey(
|
|
8511
|
-
connection.selected_api
|
|
8512
|
-
);
|
|
8513
|
-
if (!appKey) {
|
|
8514
|
-
appKey = extractedAppKey;
|
|
8515
|
-
}
|
|
8516
|
-
if (!appVersion) {
|
|
8517
|
-
appVersion = extractedVersion;
|
|
8518
|
-
}
|
|
8519
|
-
}
|
|
8520
|
-
const {
|
|
8521
|
-
selected_api: selectedApi,
|
|
8522
|
-
customuser_id: profileId,
|
|
8523
|
-
id,
|
|
8524
|
-
account_id: accountId,
|
|
8525
|
-
...restOfConnection
|
|
8526
|
-
} = connection;
|
|
8527
|
-
const normalized = {
|
|
8528
|
-
...restOfConnection,
|
|
8529
|
-
id: String(id),
|
|
8530
|
-
account_id: String(accountId),
|
|
8531
|
-
implementation_id: selectedApi,
|
|
8532
|
-
title: connection.title || connection.label || void 0,
|
|
8533
|
-
is_stale: fastifyToString(connection.is_stale),
|
|
8534
|
-
is_expired: fastifyToString(connection.is_stale),
|
|
8535
|
-
is_shared: fastifyToString(connection.is_shared),
|
|
8536
|
-
members: fastifyToString(connection.members),
|
|
8537
|
-
customuser_public_id: fastifyToString(connection.customuser_public_id),
|
|
8538
|
-
expired_at: connection.marked_stale_at,
|
|
8539
|
-
app_key: appKey,
|
|
8540
|
-
app_version: appVersion,
|
|
8541
|
-
profile_id: profileId != null ? String(profileId) : void 0
|
|
8542
|
-
};
|
|
8543
|
-
return createValidator(ConnectionItemSchema, { adaptError })(normalized);
|
|
8544
|
-
}
|
|
8545
8576
|
var GetConnectionDescription = "Get details for a specific connection";
|
|
8546
8577
|
var GetConnectionSchema = z.object({
|
|
8547
8578
|
connection: ConnectionPropertySchema
|
|
@@ -8936,7 +8967,7 @@ var WaitForNewConnectionSchema = z.object({
|
|
|
8936
8967
|
"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)."
|
|
8937
8968
|
).meta({ deprecated: true })
|
|
8938
8969
|
}).describe(
|
|
8939
|
-
"Wait for a new connection to appear for the given app. Polls
|
|
8970
|
+
"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```"
|
|
8940
8971
|
);
|
|
8941
8972
|
var WaitForNewConnectionItemSchema = z.object({
|
|
8942
8973
|
id: z.string().describe(
|
|
@@ -8949,12 +8980,22 @@ var WaitForNewConnectionItemSchema = z.object({
|
|
|
8949
8980
|
"Human-readable connection title set by the auth flow, when available."
|
|
8950
8981
|
)
|
|
8951
8982
|
}).describe("The new connection that was detected.");
|
|
8983
|
+
var WaitForNewConnectionRowSchema = z.object({
|
|
8984
|
+
id: z.union([z.string(), z.number()]),
|
|
8985
|
+
public_id: z.string().optional(),
|
|
8986
|
+
date: z.string().optional(),
|
|
8987
|
+
title: z.string().nullable().optional(),
|
|
8988
|
+
label: z.string().nullable().optional()
|
|
8989
|
+
});
|
|
8990
|
+
var WaitForNewConnectionResponseSchema = z.object({
|
|
8991
|
+
results: z.array(WaitForNewConnectionRowSchema)
|
|
8992
|
+
});
|
|
8952
8993
|
|
|
8953
8994
|
// src/plugins/waitForNewConnection/index.ts
|
|
8954
|
-
var CONNECTIONS_PATH = "/api/
|
|
8995
|
+
var CONNECTIONS_PATH = "/zapier/api/v4/authentications";
|
|
8955
8996
|
var waitForNewConnectionPlugin = defineMethod({
|
|
8956
8997
|
name: "waitForNewConnection",
|
|
8957
|
-
imports: [manifestPluginRef, apiPluginRef],
|
|
8998
|
+
imports: [manifestPluginRef, apiPluginRef, coreOptionsPluginRef],
|
|
8958
8999
|
categories: ["connection"],
|
|
8959
9000
|
itemType: "Connection",
|
|
8960
9001
|
inputSchema: WaitForNewConnectionSchema,
|
|
@@ -8965,27 +9006,31 @@ var waitForNewConnectionPlugin = defineMethod({
|
|
|
8965
9006
|
run: async ({ imports, input, annotate }) => {
|
|
8966
9007
|
const api = imports.api;
|
|
8967
9008
|
const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
|
|
9009
|
+
const validateConnectionsResponse = createValidator(
|
|
9010
|
+
WaitForNewConnectionResponseSchema,
|
|
9011
|
+
{ adaptError: imports.coreOptions?.adaptError }
|
|
9012
|
+
);
|
|
8968
9013
|
const versionedKey = await getVersionedImplementationId(input.app);
|
|
8969
|
-
const appKey = versionedKey
|
|
9014
|
+
const [appKey] = splitVersionedKey(versionedKey ?? input.app);
|
|
8970
9015
|
annotate({ selectedApi: appKey });
|
|
8971
9016
|
try {
|
|
8972
9017
|
const top = await api.poll(CONNECTIONS_PATH, {
|
|
8973
9018
|
searchParams: {
|
|
8974
|
-
|
|
9019
|
+
versionless_selected_api: appKey,
|
|
8975
9020
|
// Scope to the current user's own connections. The connection we're
|
|
8976
9021
|
// waiting on is by definition owned by the caller; without this the
|
|
8977
9022
|
// one-row head-check could match a teammate's freshly created
|
|
8978
9023
|
// connection for the same app.
|
|
8979
9024
|
owner: "me",
|
|
8980
|
-
|
|
9025
|
+
stale: "false",
|
|
8981
9026
|
ordering: "-date",
|
|
8982
|
-
|
|
9027
|
+
limit: "1"
|
|
8983
9028
|
},
|
|
8984
9029
|
authRequired: true,
|
|
8985
9030
|
timeoutMilliseconds: input.timeoutSeconds != null ? input.timeoutSeconds * 1e3 : input.timeoutMs ?? 3e5,
|
|
8986
9031
|
initialDelayMilliseconds: input.pollIntervalMilliseconds ?? input.pollIntervalMs ?? 3e3,
|
|
8987
9032
|
isPending: (body) => {
|
|
8988
|
-
const rows = body.
|
|
9033
|
+
const rows = validateConnectionsResponse(body).results;
|
|
8989
9034
|
const head = rows[0];
|
|
8990
9035
|
if (!head?.date) return true;
|
|
8991
9036
|
const created = Math.floor(new Date(head.date).getTime() / 1e3);
|
|
@@ -8993,14 +9038,14 @@ var waitForNewConnectionPlugin = defineMethod({
|
|
|
8993
9038
|
},
|
|
8994
9039
|
resultExtractor: (body) => (
|
|
8995
9040
|
// `isPending` guaranteed a fresh row at index 0 before this fires.
|
|
8996
|
-
body.
|
|
9041
|
+
validateConnectionsResponse(body).results[0]
|
|
8997
9042
|
)
|
|
8998
9043
|
});
|
|
8999
9044
|
return {
|
|
9000
9045
|
data: WaitForNewConnectionItemSchema.parse({
|
|
9001
9046
|
id: String(top.public_id ?? top.id),
|
|
9002
9047
|
app: appKey,
|
|
9003
|
-
title: top.title
|
|
9048
|
+
title: top.title || top.label || null
|
|
9004
9049
|
})
|
|
9005
9050
|
};
|
|
9006
9051
|
} catch (err) {
|