@zapier/zapier-sdk 0.108.0 → 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 +31 -0
- package/README.md +1 -1
- package/dist/{chunk-HMEY72T6.cjs → chunk-OS45HFVJ.cjs} +159 -123
- package/dist/{chunk-ULZVDPAK.mjs → chunk-S7XDZGKJ.mjs} +160 -124
- package/dist/experimental.cjs +378 -378
- package/dist/experimental.d.mts +10 -10
- package/dist/experimental.d.ts +10 -10
- package/dist/experimental.mjs +2 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @zapier/zapier-sdk
|
|
2
2
|
|
|
3
|
+
## 0.108.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 47a61ba: `listConnections` and `waitForNewConnection` now:
|
|
8
|
+
- Raise a `ZapierValidationError` (`ZAPIER_VALIDATION_ERROR`) when a response or
|
|
9
|
+
connection row doesn't match the expected shape; previously the list path
|
|
10
|
+
did not validate rows. `waitForNewConnection` surfaces it on the first
|
|
11
|
+
malformed successful response — any number of pending responses may precede
|
|
12
|
+
it — rather than after exhausting its poll retries.
|
|
13
|
+
- Preserve error status codes and messages. Previously, some 4xx messages were
|
|
14
|
+
replaced with generic text and some 5xx responses were reported as generic
|
|
15
|
+
502 errors.
|
|
16
|
+
- Match an `app` filter with an explicit version (e.g. `"github@1.2.3"`) even
|
|
17
|
+
when it can't be resolved through the manifest, instead of failing to match
|
|
18
|
+
anything.
|
|
19
|
+
|
|
20
|
+
`waitForNewConnection` now checks the most recently created connection.
|
|
21
|
+
Previously the row it checked was not the newest, so it could keep waiting past
|
|
22
|
+
a connection that had already been created, or settle on a different one.
|
|
23
|
+
|
|
24
|
+
`ApiClient.poll` now propagates a throw from a caller's `isPending` or
|
|
25
|
+
`resultExtractor` unchanged and stops polling, instead of retrying it three
|
|
26
|
+
times and rebranding it as a JSON parse failure. Return `true` from `isPending`
|
|
27
|
+
to keep polling; throw only to abandon the poll. An unreadable response body
|
|
28
|
+
still retries, now reported as "Poll response body was not valid JSON".
|
|
29
|
+
Consecutive HTTP error responses that exhaust polling retries now preserve
|
|
30
|
+
the upstream status code and are no longer counted and wrapped twice.
|
|
31
|
+
|
|
32
|
+
Output is unchanged for conforming responses.
|
|
33
|
+
|
|
3
34
|
## 0.108.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -2854,7 +2854,7 @@ for await (const connection of zapier.listConnections().items()) {
|
|
|
2854
2854
|
|
|
2855
2855
|
#### `waitForNewConnection`
|
|
2856
2856
|
|
|
2857
|
-
Wait for a new connection to appear for the given app. Polls
|
|
2857
|
+
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` — 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):
|
|
2858
2858
|
|
|
2859
2859
|
```ts
|
|
2860
2860
|
const {
|
|
@@ -863,8 +863,16 @@ var processResponse = async (response, successStatus, pendingStatus, isPending,
|
|
|
863
863
|
};
|
|
864
864
|
}
|
|
865
865
|
if (response.status === successStatus) {
|
|
866
|
+
let resultJson;
|
|
867
|
+
try {
|
|
868
|
+
resultJson = await response.json();
|
|
869
|
+
} catch (error) {
|
|
870
|
+
throw new ZapierApiError("Poll response body was not valid JSON", {
|
|
871
|
+
statusCode: response.status,
|
|
872
|
+
cause: error
|
|
873
|
+
});
|
|
874
|
+
}
|
|
866
875
|
try {
|
|
867
|
-
const resultJson = await response.json();
|
|
868
876
|
if (isPending && isPending(resultJson)) {
|
|
869
877
|
return {
|
|
870
878
|
status: "continue" /* Continue */,
|
|
@@ -877,13 +885,7 @@ var processResponse = async (response, successStatus, pendingStatus, isPending,
|
|
|
877
885
|
errorCount: 0
|
|
878
886
|
};
|
|
879
887
|
} catch (error) {
|
|
880
|
-
|
|
881
|
-
"Result extractor failed to parse successful response as JSON",
|
|
882
|
-
{
|
|
883
|
-
statusCode: response.status,
|
|
884
|
-
cause: error
|
|
885
|
-
}
|
|
886
|
-
);
|
|
888
|
+
return { status: "failed" /* Failed */, error, errorCount };
|
|
887
889
|
}
|
|
888
890
|
}
|
|
889
891
|
if (response.status !== pendingStatus) {
|
|
@@ -956,13 +958,10 @@ async function pollUntilComplete(options) {
|
|
|
956
958
|
if (signal?.aborted) throw makeAbortError();
|
|
957
959
|
}
|
|
958
960
|
attempts++;
|
|
961
|
+
let terminalThrow;
|
|
959
962
|
try {
|
|
960
963
|
const response = await fetchPoll();
|
|
961
|
-
const
|
|
962
|
-
result,
|
|
963
|
-
errorCount: newErrorCount,
|
|
964
|
-
status
|
|
965
|
-
} = await processResponse(
|
|
964
|
+
const pollResult = await processResponse(
|
|
966
965
|
response,
|
|
967
966
|
successStatus,
|
|
968
967
|
pendingStatus,
|
|
@@ -970,15 +969,18 @@ async function pollUntilComplete(options) {
|
|
|
970
969
|
resultExtractor,
|
|
971
970
|
errorCount
|
|
972
971
|
);
|
|
973
|
-
errorCount =
|
|
974
|
-
if (status === "
|
|
975
|
-
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
972
|
+
errorCount = pollResult.errorCount;
|
|
973
|
+
if (pollResult.status === "failed" /* Failed */) {
|
|
974
|
+
terminalThrow = { error: pollResult.error };
|
|
975
|
+
} else if (pollResult.status === "success" /* Success */) {
|
|
976
|
+
return pollResult.result;
|
|
977
|
+
} else if (errorCount >= MAX_CONSECUTIVE_ERRORS) {
|
|
978
|
+
terminalThrow = {
|
|
979
|
+
error: new ZapierApiError(
|
|
980
|
+
`Poll request failed: ${response.status} ${response.statusText}`,
|
|
981
|
+
{ statusCode: response.status }
|
|
982
|
+
)
|
|
983
|
+
};
|
|
982
984
|
}
|
|
983
985
|
} catch (error) {
|
|
984
986
|
if (isAbortError(error)) throw error;
|
|
@@ -992,6 +994,7 @@ async function pollUntilComplete(options) {
|
|
|
992
994
|
);
|
|
993
995
|
}
|
|
994
996
|
}
|
|
997
|
+
if (terminalThrow) throw terminalThrow.error;
|
|
995
998
|
}
|
|
996
999
|
}
|
|
997
1000
|
|
|
@@ -2876,7 +2879,7 @@ function logRouteOverride({
|
|
|
2876
2879
|
}
|
|
2877
2880
|
|
|
2878
2881
|
// src/sdk-version.ts
|
|
2879
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.108.
|
|
2882
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.108.1" : void 0) || "unknown";
|
|
2880
2883
|
|
|
2881
2884
|
// src/utils/open-url.ts
|
|
2882
2885
|
var nodePrefix = "node:";
|
|
@@ -8138,7 +8141,7 @@ var ListConnectionsQuerySchema = connections.ListConnectionsQuerySchema.omit({
|
|
|
8138
8141
|
"Include connections shared with you. By default, only your own connections are returned (owner=me). Set to true to also include shared connections."
|
|
8139
8142
|
),
|
|
8140
8143
|
// Filters on connection expiry. Not a mirror of a server-side status
|
|
8141
|
-
// field: the API expresses this as the
|
|
8144
|
+
// field: the API expresses this as the stale filter, which we send as
|
|
8142
8145
|
// false for "active", true for "expired", and omit for "all".
|
|
8143
8146
|
status: zod.z.enum(["active", "expired", "all"]).optional().describe(
|
|
8144
8147
|
"Filter connections by expiry: 'active' (default) returns only non-expired connections, 'expired' only expired ones, and 'all' returns both."
|
|
@@ -8155,7 +8158,11 @@ var ListConnectionsQuerySchema = connections.ListConnectionsQuerySchema.omit({
|
|
|
8155
8158
|
deprecated: true,
|
|
8156
8159
|
deprecationMessage: "Use --status expired instead to show only expired connections, or --status all for both."
|
|
8157
8160
|
}),
|
|
8158
|
-
// Override pageSize to make optional
|
|
8161
|
+
// Override pageSize to make optional, and deliberately leave it uncapped:
|
|
8162
|
+
// the authentications endpoint accepts a `limit` well above 1000 (it sets
|
|
8163
|
+
// no max_limit of its own), so a local ceiling would reject input the API
|
|
8164
|
+
// takes. The description keeps hedging because the endpoint stays free to
|
|
8165
|
+
// add one.
|
|
8159
8166
|
pageSize: zod.z.number().min(1).optional().describe(
|
|
8160
8167
|
"Number of connections per page. The upstream API may cap this and reject values above its limit."
|
|
8161
8168
|
),
|
|
@@ -8164,13 +8171,86 @@ var ListConnectionsQuerySchema = connections.ListConnectionsQuerySchema.omit({
|
|
|
8164
8171
|
// SDK specific property for pagination/iterable helpers
|
|
8165
8172
|
cursor: zod.z.string().optional().describe("Cursor to start from")
|
|
8166
8173
|
}).describe("List available connections with optional filtering");
|
|
8167
|
-
connections.ConnectionSchema.extend({
|
|
8174
|
+
var RawConnectionSchema = connections.ConnectionSchema.extend({
|
|
8168
8175
|
is_stale: zod.z.boolean().optional(),
|
|
8169
8176
|
is_shared: zod.z.boolean().optional(),
|
|
8170
8177
|
members: zod.z.array(zod.z.record(zod.z.string(), zod.z.any())).optional(),
|
|
8171
8178
|
customuser_id: zod.z.number().nullable().optional(),
|
|
8172
8179
|
customuser_public_id: zod.z.string().nullable().optional()
|
|
8173
8180
|
});
|
|
8181
|
+
var RawConnectionsResponseSchema = connections.ConnectionsResponseSchema.extend({
|
|
8182
|
+
results: zod.z.array(RawConnectionSchema)
|
|
8183
|
+
});
|
|
8184
|
+
|
|
8185
|
+
// src/normalizers/shared.ts
|
|
8186
|
+
function fastifyToString(value) {
|
|
8187
|
+
if (value === void 0) {
|
|
8188
|
+
return void 0;
|
|
8189
|
+
}
|
|
8190
|
+
if (typeof value === "string") {
|
|
8191
|
+
return value;
|
|
8192
|
+
}
|
|
8193
|
+
if (value === null) {
|
|
8194
|
+
return "";
|
|
8195
|
+
}
|
|
8196
|
+
if (value instanceof Date) {
|
|
8197
|
+
return value.toISOString();
|
|
8198
|
+
}
|
|
8199
|
+
if (value instanceof RegExp) {
|
|
8200
|
+
return value.source;
|
|
8201
|
+
}
|
|
8202
|
+
try {
|
|
8203
|
+
return String(value.toString());
|
|
8204
|
+
} catch {
|
|
8205
|
+
return "[unserializable]";
|
|
8206
|
+
}
|
|
8207
|
+
}
|
|
8208
|
+
|
|
8209
|
+
// src/normalizers/connection.ts
|
|
8210
|
+
function normalizeConnectionItem({
|
|
8211
|
+
connection,
|
|
8212
|
+
appKey: providedAppKey,
|
|
8213
|
+
appVersion: providedAppVersion,
|
|
8214
|
+
adaptError
|
|
8215
|
+
}) {
|
|
8216
|
+
let appKey = providedAppKey;
|
|
8217
|
+
let appVersion = providedAppVersion;
|
|
8218
|
+
if (connection.selected_api && typeof connection.selected_api === "string") {
|
|
8219
|
+
const [extractedAppKey, extractedVersion] = splitVersionedKey(
|
|
8220
|
+
connection.selected_api
|
|
8221
|
+
);
|
|
8222
|
+
if (!appKey) {
|
|
8223
|
+
appKey = extractedAppKey;
|
|
8224
|
+
}
|
|
8225
|
+
if (!appVersion) {
|
|
8226
|
+
appVersion = extractedVersion;
|
|
8227
|
+
}
|
|
8228
|
+
}
|
|
8229
|
+
const {
|
|
8230
|
+
selected_api: selectedApi,
|
|
8231
|
+
customuser_id: profileId,
|
|
8232
|
+
id,
|
|
8233
|
+
account_id: accountId,
|
|
8234
|
+
...restOfConnection
|
|
8235
|
+
} = connection;
|
|
8236
|
+
const normalized = {
|
|
8237
|
+
...restOfConnection,
|
|
8238
|
+
id: String(id),
|
|
8239
|
+
account_id: String(accountId),
|
|
8240
|
+
implementation_id: selectedApi,
|
|
8241
|
+
title: connection.title || connection.label || void 0,
|
|
8242
|
+
is_stale: fastifyToString(connection.is_stale),
|
|
8243
|
+
is_expired: fastifyToString(connection.is_stale),
|
|
8244
|
+
is_shared: fastifyToString(connection.is_shared),
|
|
8245
|
+
members: fastifyToString(connection.members),
|
|
8246
|
+
customuser_public_id: fastifyToString(connection.customuser_public_id),
|
|
8247
|
+
expired_at: connection.marked_stale_at,
|
|
8248
|
+
app_key: appKey,
|
|
8249
|
+
app_version: appVersion,
|
|
8250
|
+
profile_id: profileId != null ? String(profileId) : void 0
|
|
8251
|
+
};
|
|
8252
|
+
return kitcore.createValidator(connections.ConnectionItemSchema, { adaptError })(normalized);
|
|
8253
|
+
}
|
|
8174
8254
|
function formatConnectionItem(item) {
|
|
8175
8255
|
const details = [];
|
|
8176
8256
|
const appKey = item.app_key ?? "unknown";
|
|
@@ -8211,7 +8291,8 @@ var listConnectionsPlugin = kitcore.defineMethod({
|
|
|
8211
8291
|
connectionsPluginRef,
|
|
8212
8292
|
apiPluginRef,
|
|
8213
8293
|
manifestPluginRef,
|
|
8214
|
-
capabilitiesPluginRef
|
|
8294
|
+
capabilitiesPluginRef,
|
|
8295
|
+
kitcore.coreOptionsPluginRef
|
|
8215
8296
|
],
|
|
8216
8297
|
categories: ["connection"],
|
|
8217
8298
|
itemType: "Connection",
|
|
@@ -8239,18 +8320,17 @@ var listConnectionsPlugin = kitcore.defineMethod({
|
|
|
8239
8320
|
await imports.capabilities.checkCapability("canIncludeSharedConnections");
|
|
8240
8321
|
}
|
|
8241
8322
|
const searchParams = {};
|
|
8242
|
-
|
|
8243
|
-
searchParams.page_size = input.pageSize.toString();
|
|
8244
|
-
}
|
|
8323
|
+
searchParams.limit = (input.pageSize ?? DEFAULT_PAGE_SIZE).toString();
|
|
8245
8324
|
const appKey = input.app ?? input.appKey;
|
|
8246
8325
|
if (appKey) {
|
|
8247
8326
|
const implementationId = await getVersionedImplementationId(appKey);
|
|
8248
8327
|
if (implementationId) {
|
|
8249
8328
|
annotate({ selectedApi: implementationId });
|
|
8250
8329
|
const [versionlessSelectedApi] = splitVersionedKey(implementationId);
|
|
8251
|
-
searchParams.
|
|
8330
|
+
searchParams.versionless_selected_api = versionlessSelectedApi;
|
|
8252
8331
|
} else {
|
|
8253
|
-
|
|
8332
|
+
const [versionlessAppKey] = splitVersionedKey(appKey);
|
|
8333
|
+
searchParams.versionless_selected_api = versionlessAppKey;
|
|
8254
8334
|
}
|
|
8255
8335
|
}
|
|
8256
8336
|
const connectionRefs = input.connections;
|
|
@@ -8264,15 +8344,14 @@ var listConnectionsPlugin = kitcore.defineMethod({
|
|
|
8264
8344
|
})
|
|
8265
8345
|
)
|
|
8266
8346
|
);
|
|
8267
|
-
searchParams.
|
|
8347
|
+
searchParams.ids = resolvedIds.filter((id) => id != null).join(",");
|
|
8268
8348
|
} else if (legacyConnectionIds && legacyConnectionIds.length > 0) {
|
|
8269
|
-
searchParams.
|
|
8349
|
+
searchParams.ids = legacyConnectionIds.join(",");
|
|
8270
8350
|
}
|
|
8271
8351
|
if (input.search) {
|
|
8272
8352
|
searchParams.search = input.search;
|
|
8273
|
-
}
|
|
8274
|
-
|
|
8275
|
-
searchParams.title = input.title;
|
|
8353
|
+
} else if (input.title) {
|
|
8354
|
+
searchParams.search = input.title;
|
|
8276
8355
|
}
|
|
8277
8356
|
const accountId = input.account ?? input.accountId;
|
|
8278
8357
|
if (accountId) {
|
|
@@ -8295,18 +8374,31 @@ var listConnectionsPlugin = kitcore.defineMethod({
|
|
|
8295
8374
|
}
|
|
8296
8375
|
const status = input.status ?? (expiredFilter ? "expired" : "active");
|
|
8297
8376
|
if (status !== "all") {
|
|
8298
|
-
searchParams.
|
|
8377
|
+
searchParams.stale = (status === "expired").toString();
|
|
8299
8378
|
}
|
|
8300
8379
|
if (input.cursor) {
|
|
8301
8380
|
searchParams.offset = input.cursor;
|
|
8302
8381
|
}
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8382
|
+
searchParams.ordering = "personal_first";
|
|
8383
|
+
const rawResponse = await api.get("/zapier/api/v4/authentications", {
|
|
8384
|
+
searchParams,
|
|
8385
|
+
authRequired: true
|
|
8386
|
+
});
|
|
8387
|
+
const raw = kitcore.createValidator(RawConnectionsResponseSchema, {
|
|
8388
|
+
adaptError: imports.coreOptions?.adaptError
|
|
8389
|
+
})(rawResponse);
|
|
8390
|
+
let connections = raw.results.map(
|
|
8391
|
+
(connection) => normalizeConnectionItem({
|
|
8392
|
+
connection,
|
|
8393
|
+
adaptError: imports.coreOptions?.adaptError
|
|
8394
|
+
})
|
|
8306
8395
|
);
|
|
8396
|
+
if (input.title) {
|
|
8397
|
+
connections = connections.filter((conn) => conn.title === input.title);
|
|
8398
|
+
}
|
|
8307
8399
|
return {
|
|
8308
|
-
|
|
8309
|
-
|
|
8400
|
+
data: connections.map(transformConnectionItem),
|
|
8401
|
+
next: raw.next ?? null
|
|
8310
8402
|
};
|
|
8311
8403
|
}
|
|
8312
8404
|
});
|
|
@@ -8482,76 +8574,6 @@ var getAppPlugin = kitcore.defineMethod({
|
|
|
8482
8574
|
throw new ZapierAppNotFoundError("App not found", { appKey });
|
|
8483
8575
|
}
|
|
8484
8576
|
});
|
|
8485
|
-
|
|
8486
|
-
// src/normalizers/shared.ts
|
|
8487
|
-
function fastifyToString(value) {
|
|
8488
|
-
if (value === void 0) {
|
|
8489
|
-
return void 0;
|
|
8490
|
-
}
|
|
8491
|
-
if (typeof value === "string") {
|
|
8492
|
-
return value;
|
|
8493
|
-
}
|
|
8494
|
-
if (value === null) {
|
|
8495
|
-
return "";
|
|
8496
|
-
}
|
|
8497
|
-
if (value instanceof Date) {
|
|
8498
|
-
return value.toISOString();
|
|
8499
|
-
}
|
|
8500
|
-
if (value instanceof RegExp) {
|
|
8501
|
-
return value.source;
|
|
8502
|
-
}
|
|
8503
|
-
try {
|
|
8504
|
-
return String(value.toString());
|
|
8505
|
-
} catch {
|
|
8506
|
-
return "[unserializable]";
|
|
8507
|
-
}
|
|
8508
|
-
}
|
|
8509
|
-
|
|
8510
|
-
// src/normalizers/connection.ts
|
|
8511
|
-
function normalizeConnectionItem({
|
|
8512
|
-
connection,
|
|
8513
|
-
appKey: providedAppKey,
|
|
8514
|
-
appVersion: providedAppVersion,
|
|
8515
|
-
adaptError
|
|
8516
|
-
}) {
|
|
8517
|
-
let appKey = providedAppKey;
|
|
8518
|
-
let appVersion = providedAppVersion;
|
|
8519
|
-
if (connection.selected_api && typeof connection.selected_api === "string") {
|
|
8520
|
-
const [extractedAppKey, extractedVersion] = splitVersionedKey(
|
|
8521
|
-
connection.selected_api
|
|
8522
|
-
);
|
|
8523
|
-
if (!appKey) {
|
|
8524
|
-
appKey = extractedAppKey;
|
|
8525
|
-
}
|
|
8526
|
-
if (!appVersion) {
|
|
8527
|
-
appVersion = extractedVersion;
|
|
8528
|
-
}
|
|
8529
|
-
}
|
|
8530
|
-
const {
|
|
8531
|
-
selected_api: selectedApi,
|
|
8532
|
-
customuser_id: profileId,
|
|
8533
|
-
id,
|
|
8534
|
-
account_id: accountId,
|
|
8535
|
-
...restOfConnection
|
|
8536
|
-
} = connection;
|
|
8537
|
-
const normalized = {
|
|
8538
|
-
...restOfConnection,
|
|
8539
|
-
id: String(id),
|
|
8540
|
-
account_id: String(accountId),
|
|
8541
|
-
implementation_id: selectedApi,
|
|
8542
|
-
title: connection.title || connection.label || void 0,
|
|
8543
|
-
is_stale: fastifyToString(connection.is_stale),
|
|
8544
|
-
is_expired: fastifyToString(connection.is_stale),
|
|
8545
|
-
is_shared: fastifyToString(connection.is_shared),
|
|
8546
|
-
members: fastifyToString(connection.members),
|
|
8547
|
-
customuser_public_id: fastifyToString(connection.customuser_public_id),
|
|
8548
|
-
expired_at: connection.marked_stale_at,
|
|
8549
|
-
app_key: appKey,
|
|
8550
|
-
app_version: appVersion,
|
|
8551
|
-
profile_id: profileId != null ? String(profileId) : void 0
|
|
8552
|
-
};
|
|
8553
|
-
return kitcore.createValidator(connections.ConnectionItemSchema, { adaptError })(normalized);
|
|
8554
|
-
}
|
|
8555
8577
|
var GetConnectionDescription = "Get details for a specific connection";
|
|
8556
8578
|
var GetConnectionSchema = zod.z.object({
|
|
8557
8579
|
connection: ConnectionPropertySchema
|
|
@@ -8946,7 +8968,7 @@ var WaitForNewConnectionSchema = zod.z.object({
|
|
|
8946
8968
|
"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)."
|
|
8947
8969
|
).meta({ deprecated: true })
|
|
8948
8970
|
}).describe(
|
|
8949
|
-
"Wait for a new connection to appear for the given app. Polls
|
|
8971
|
+
"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```"
|
|
8950
8972
|
);
|
|
8951
8973
|
var WaitForNewConnectionItemSchema = zod.z.object({
|
|
8952
8974
|
id: zod.z.string().describe(
|
|
@@ -8959,12 +8981,22 @@ var WaitForNewConnectionItemSchema = zod.z.object({
|
|
|
8959
8981
|
"Human-readable connection title set by the auth flow, when available."
|
|
8960
8982
|
)
|
|
8961
8983
|
}).describe("The new connection that was detected.");
|
|
8984
|
+
var WaitForNewConnectionRowSchema = zod.z.object({
|
|
8985
|
+
id: zod.z.union([zod.z.string(), zod.z.number()]),
|
|
8986
|
+
public_id: zod.z.string().optional(),
|
|
8987
|
+
date: zod.z.string().optional(),
|
|
8988
|
+
title: zod.z.string().nullable().optional(),
|
|
8989
|
+
label: zod.z.string().nullable().optional()
|
|
8990
|
+
});
|
|
8991
|
+
var WaitForNewConnectionResponseSchema = zod.z.object({
|
|
8992
|
+
results: zod.z.array(WaitForNewConnectionRowSchema)
|
|
8993
|
+
});
|
|
8962
8994
|
|
|
8963
8995
|
// src/plugins/waitForNewConnection/index.ts
|
|
8964
|
-
var CONNECTIONS_PATH = "/api/
|
|
8996
|
+
var CONNECTIONS_PATH = "/zapier/api/v4/authentications";
|
|
8965
8997
|
var waitForNewConnectionPlugin = kitcore.defineMethod({
|
|
8966
8998
|
name: "waitForNewConnection",
|
|
8967
|
-
imports: [manifestPluginRef, apiPluginRef],
|
|
8999
|
+
imports: [manifestPluginRef, apiPluginRef, kitcore.coreOptionsPluginRef],
|
|
8968
9000
|
categories: ["connection"],
|
|
8969
9001
|
itemType: "Connection",
|
|
8970
9002
|
inputSchema: WaitForNewConnectionSchema,
|
|
@@ -8975,27 +9007,31 @@ var waitForNewConnectionPlugin = kitcore.defineMethod({
|
|
|
8975
9007
|
run: async ({ imports, input, annotate }) => {
|
|
8976
9008
|
const api = imports.api;
|
|
8977
9009
|
const getVersionedImplementationId = imports.manifest.getVersionedImplementationId;
|
|
9010
|
+
const validateConnectionsResponse = kitcore.createValidator(
|
|
9011
|
+
WaitForNewConnectionResponseSchema,
|
|
9012
|
+
{ adaptError: imports.coreOptions?.adaptError }
|
|
9013
|
+
);
|
|
8978
9014
|
const versionedKey = await getVersionedImplementationId(input.app);
|
|
8979
|
-
const appKey = versionedKey
|
|
9015
|
+
const [appKey] = splitVersionedKey(versionedKey ?? input.app);
|
|
8980
9016
|
annotate({ selectedApi: appKey });
|
|
8981
9017
|
try {
|
|
8982
9018
|
const top = await api.poll(CONNECTIONS_PATH, {
|
|
8983
9019
|
searchParams: {
|
|
8984
|
-
|
|
9020
|
+
versionless_selected_api: appKey,
|
|
8985
9021
|
// Scope to the current user's own connections. The connection we're
|
|
8986
9022
|
// waiting on is by definition owned by the caller; without this the
|
|
8987
9023
|
// one-row head-check could match a teammate's freshly created
|
|
8988
9024
|
// connection for the same app.
|
|
8989
9025
|
owner: "me",
|
|
8990
|
-
|
|
9026
|
+
stale: "false",
|
|
8991
9027
|
ordering: "-date",
|
|
8992
|
-
|
|
9028
|
+
limit: "1"
|
|
8993
9029
|
},
|
|
8994
9030
|
authRequired: true,
|
|
8995
9031
|
timeoutMilliseconds: input.timeoutSeconds != null ? input.timeoutSeconds * 1e3 : input.timeoutMs ?? 3e5,
|
|
8996
9032
|
initialDelayMilliseconds: input.pollIntervalMilliseconds ?? input.pollIntervalMs ?? 3e3,
|
|
8997
9033
|
isPending: (body) => {
|
|
8998
|
-
const rows = body.
|
|
9034
|
+
const rows = validateConnectionsResponse(body).results;
|
|
8999
9035
|
const head = rows[0];
|
|
9000
9036
|
if (!head?.date) return true;
|
|
9001
9037
|
const created = Math.floor(new Date(head.date).getTime() / 1e3);
|
|
@@ -9003,14 +9039,14 @@ var waitForNewConnectionPlugin = kitcore.defineMethod({
|
|
|
9003
9039
|
},
|
|
9004
9040
|
resultExtractor: (body) => (
|
|
9005
9041
|
// `isPending` guaranteed a fresh row at index 0 before this fires.
|
|
9006
|
-
body.
|
|
9042
|
+
validateConnectionsResponse(body).results[0]
|
|
9007
9043
|
)
|
|
9008
9044
|
});
|
|
9009
9045
|
return {
|
|
9010
9046
|
data: WaitForNewConnectionItemSchema.parse({
|
|
9011
9047
|
id: String(top.public_id ?? top.id),
|
|
9012
9048
|
app: appKey,
|
|
9013
|
-
title: top.title
|
|
9049
|
+
title: top.title || top.label || null
|
|
9014
9050
|
})
|
|
9015
9051
|
};
|
|
9016
9052
|
} catch (err) {
|