@zapier/zapier-sdk 0.81.1 → 0.82.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 +6 -0
- package/README.md +38 -40
- package/dist/experimental.cjs +3445 -3446
- package/dist/experimental.d.mts +2 -6
- package/dist/experimental.d.ts +2 -6
- package/dist/experimental.mjs +3445 -3446
- package/dist/{index-CWi_XjB4.d.mts → index-BEIqfOJR.d.mts} +3352 -1519
- package/dist/{index-CWi_XjB4.d.ts → index-BEIqfOJR.d.ts} +3352 -1519
- package/dist/index.cjs +1664 -12
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1664 -12
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3138,14 +3138,14 @@ var TriggerInboxCommandBaseSchema = z.object({
|
|
|
3138
3138
|
"Abort signal. Aborting cancels in-flight HTTP, releases unprocessed messages, and resolves cleanly. Errors during shutdown still reject."
|
|
3139
3139
|
)
|
|
3140
3140
|
});
|
|
3141
|
-
TriggerInboxCommandBaseSchema.extend({
|
|
3141
|
+
var DrainTriggerInboxSchema = TriggerInboxCommandBaseSchema.extend({
|
|
3142
3142
|
maxMessages: z.number().int().min(1).optional().describe(
|
|
3143
3143
|
"Cap total messages drained. Defaults to draining the inbox until empty."
|
|
3144
3144
|
)
|
|
3145
3145
|
}).describe(
|
|
3146
3146
|
"Drain an existing trigger inbox: lease currently-available messages and process them via onMessage. Returns when the inbox is empty, maxMessages is reached, the abort signal fires, or a fatal error rejects."
|
|
3147
3147
|
);
|
|
3148
|
-
TriggerInboxCommandBaseSchema.extend({
|
|
3148
|
+
var WatchTriggerInboxSchema = TriggerInboxCommandBaseSchema.extend({
|
|
3149
3149
|
maxDrainIntervalSeconds: z.number().int().min(1).optional().describe(
|
|
3150
3150
|
"Maximum seconds between safety drain attempts (default: 300). The watcher subscribes to SSE notifications for near-real-time wake-ups; this interval is the backstop that guarantees forward progress if SSE events are missed or the connection drops undetected."
|
|
3151
3151
|
)
|
|
@@ -6783,11 +6783,11 @@ var runActionPlugin = definePlugin(
|
|
|
6783
6783
|
timeoutMs
|
|
6784
6784
|
});
|
|
6785
6785
|
if (result.errors && result.errors.length > 0) {
|
|
6786
|
-
const
|
|
6786
|
+
const errorMessage2 = result.errors.map(
|
|
6787
6787
|
(error) => error.detail || error.title || "Unknown error"
|
|
6788
6788
|
).join("; ");
|
|
6789
6789
|
throw new ZapierActionError(
|
|
6790
|
-
`Action execution failed: ${
|
|
6790
|
+
`Action execution failed: ${errorMessage2}`,
|
|
6791
6791
|
{ appKey, actionKey }
|
|
6792
6792
|
);
|
|
6793
6793
|
}
|
|
@@ -8750,7 +8750,7 @@ function parseDeprecationDate(value) {
|
|
|
8750
8750
|
}
|
|
8751
8751
|
|
|
8752
8752
|
// src/sdk-version.ts
|
|
8753
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
8753
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.82.0" : void 0) || "unknown";
|
|
8754
8754
|
|
|
8755
8755
|
// src/utils/open-url.ts
|
|
8756
8756
|
var nodePrefix = "node:";
|
|
@@ -9454,16 +9454,16 @@ var ZapierApiClient = class {
|
|
|
9454
9454
|
if (typeof errorInfo.data === "string") {
|
|
9455
9455
|
return { message: `${fallbackMessage}: ${errorInfo.data}` };
|
|
9456
9456
|
}
|
|
9457
|
-
const
|
|
9457
|
+
const errorMessage2 = this.extractErrorMessage(errorInfo.data) || fallbackMessage;
|
|
9458
9458
|
if (this.hasErrorArray(errorInfo.data)) {
|
|
9459
9459
|
if (this.isApiErrorArray(errorInfo.data.errors)) {
|
|
9460
9460
|
return {
|
|
9461
|
-
message:
|
|
9461
|
+
message: errorMessage2,
|
|
9462
9462
|
errors: errorInfo.data.errors
|
|
9463
9463
|
};
|
|
9464
9464
|
} else {
|
|
9465
9465
|
return {
|
|
9466
|
-
message:
|
|
9466
|
+
message: errorMessage2,
|
|
9467
9467
|
errors: errorInfo.data.errors.map((e) => ({
|
|
9468
9468
|
status: errorInfo.status,
|
|
9469
9469
|
code: String(errorInfo.status),
|
|
@@ -9473,7 +9473,7 @@ var ZapierApiClient = class {
|
|
|
9473
9473
|
};
|
|
9474
9474
|
}
|
|
9475
9475
|
}
|
|
9476
|
-
return { message:
|
|
9476
|
+
return { message: errorMessage2 };
|
|
9477
9477
|
} catch {
|
|
9478
9478
|
return { message: fallbackMessage };
|
|
9479
9479
|
}
|
|
@@ -10496,6 +10496,1658 @@ var getInputFieldsSchemaDeprecatedPlugin = definePlugin(
|
|
|
10496
10496
|
}
|
|
10497
10497
|
})
|
|
10498
10498
|
);
|
|
10499
|
+
var TriggerInboxStatusSchema = z.union([
|
|
10500
|
+
z.enum([
|
|
10501
|
+
"initializing",
|
|
10502
|
+
"active",
|
|
10503
|
+
"paused",
|
|
10504
|
+
"deleting",
|
|
10505
|
+
"initialization_failure"
|
|
10506
|
+
]),
|
|
10507
|
+
z.string()
|
|
10508
|
+
]).describe("Inbox lifecycle status");
|
|
10509
|
+
var TriggerInboxPausedReasonSchema = z.union([
|
|
10510
|
+
z.enum([
|
|
10511
|
+
"user",
|
|
10512
|
+
"authentication",
|
|
10513
|
+
"authentication_access_revoked",
|
|
10514
|
+
"partner_revoked",
|
|
10515
|
+
"subscribe_failed",
|
|
10516
|
+
"migrate_failed",
|
|
10517
|
+
"abandoned",
|
|
10518
|
+
"unknown",
|
|
10519
|
+
"upstream_failures"
|
|
10520
|
+
]),
|
|
10521
|
+
z.string()
|
|
10522
|
+
]).describe("Why the inbox was paused, if applicable");
|
|
10523
|
+
var TriggerSubscriptionApiSchema = z.object({
|
|
10524
|
+
connection_id: z.union([z.string(), z.number(), z.null()]),
|
|
10525
|
+
app_key: z.string(),
|
|
10526
|
+
action_key: z.string(),
|
|
10527
|
+
inputs: z.record(z.string(), z.unknown())
|
|
10528
|
+
});
|
|
10529
|
+
var TriggerInboxItemSchema = z.object({
|
|
10530
|
+
id: z.string(),
|
|
10531
|
+
created_at: z.string(),
|
|
10532
|
+
// `key` is an API-layer alias over the same nullable `name` column, so it's
|
|
10533
|
+
// always present but can be null — null means no natural key (inbox created
|
|
10534
|
+
// without one, or key cleared on delete).
|
|
10535
|
+
key: z.string().nullable(),
|
|
10536
|
+
/** @deprecated Use `key` instead. */
|
|
10537
|
+
name: z.string().nullable(),
|
|
10538
|
+
status: TriggerInboxStatusSchema,
|
|
10539
|
+
paused_reason: TriggerInboxPausedReasonSchema.nullable(),
|
|
10540
|
+
notification_url: z.string().nullable(),
|
|
10541
|
+
subscription: TriggerSubscriptionApiSchema
|
|
10542
|
+
});
|
|
10543
|
+
|
|
10544
|
+
// src/plugins/triggers/createTriggerInbox/schemas.ts
|
|
10545
|
+
var CreateTriggerInboxDescription = "Create a new trigger inbox subscription. Always creates a new inbox; use ensureTriggerInbox for get-or-create on a stable key.";
|
|
10546
|
+
var CreateTriggerInboxSchema = z.object({
|
|
10547
|
+
key: TriggerInboxKeyPropertySchema.optional().describe(
|
|
10548
|
+
"Optional inbox key. Auto-generated when omitted. Throws a conflict error if the key is already in use by another subscription."
|
|
10549
|
+
),
|
|
10550
|
+
/** @deprecated Use `key` instead. */
|
|
10551
|
+
name: TriggerInboxNamePropertySchema.optional().describe(
|
|
10552
|
+
"Optional inbox name. Auto-generated when omitted. Throws a conflict error if the name is already in use by another subscription."
|
|
10553
|
+
).meta({ deprecated: true }),
|
|
10554
|
+
app: AppPropertySchema,
|
|
10555
|
+
action: ActionPropertySchema,
|
|
10556
|
+
connection: ConnectionPropertySchema.nullable().optional().describe(
|
|
10557
|
+
"Connection alias or connection ID. Optional for triggers that don't require auth."
|
|
10558
|
+
),
|
|
10559
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
10560
|
+
"Input parameters for the trigger subscription"
|
|
10561
|
+
),
|
|
10562
|
+
notificationUrl: z.string().url().optional().describe("Webhook URL to POST to when new messages arrive")
|
|
10563
|
+
}).describe(CreateTriggerInboxDescription);
|
|
10564
|
+
|
|
10565
|
+
// src/formatters/triggerInbox.ts
|
|
10566
|
+
var triggerInboxItemFormatter = {
|
|
10567
|
+
format: (item) => {
|
|
10568
|
+
const details = [
|
|
10569
|
+
{
|
|
10570
|
+
text: `Status: ${item.status}`,
|
|
10571
|
+
style: item.status === "active" ? "accent" : "dim"
|
|
10572
|
+
},
|
|
10573
|
+
{
|
|
10574
|
+
text: `Subscription: ${item.subscription.app_key} / ${item.subscription.action_key}`,
|
|
10575
|
+
style: "dim"
|
|
10576
|
+
}
|
|
10577
|
+
];
|
|
10578
|
+
if (item.paused_reason) {
|
|
10579
|
+
details.push({
|
|
10580
|
+
text: `Paused reason: ${item.paused_reason}`,
|
|
10581
|
+
style: "warning"
|
|
10582
|
+
});
|
|
10583
|
+
}
|
|
10584
|
+
if (item.notification_url) {
|
|
10585
|
+
details.push({
|
|
10586
|
+
text: `Notify: ${item.notification_url}`,
|
|
10587
|
+
style: "dim"
|
|
10588
|
+
});
|
|
10589
|
+
}
|
|
10590
|
+
return {
|
|
10591
|
+
title: item.key ?? item.name ?? `Trigger Inbox ${item.id}`,
|
|
10592
|
+
id: item.id,
|
|
10593
|
+
details
|
|
10594
|
+
};
|
|
10595
|
+
}
|
|
10596
|
+
};
|
|
10597
|
+
|
|
10598
|
+
// src/plugins/triggers/shared.ts
|
|
10599
|
+
var triggersDefaults = {
|
|
10600
|
+
categories: ["trigger"]
|
|
10601
|
+
};
|
|
10602
|
+
|
|
10603
|
+
// src/plugins/triggers/utils.ts
|
|
10604
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10605
|
+
async function resolveTriggerInboxId({
|
|
10606
|
+
api,
|
|
10607
|
+
inbox
|
|
10608
|
+
}) {
|
|
10609
|
+
if (UUID_REGEX.test(inbox)) {
|
|
10610
|
+
return inbox;
|
|
10611
|
+
}
|
|
10612
|
+
const rawResponse = await api.get("/trigger-inbox/api/v1/inboxes", {
|
|
10613
|
+
searchParams: { key: inbox, limit: "1" },
|
|
10614
|
+
authRequired: true
|
|
10615
|
+
});
|
|
10616
|
+
const response = rawResponse;
|
|
10617
|
+
const id = response.results?.[0]?.id;
|
|
10618
|
+
if (!id) {
|
|
10619
|
+
throw new ZapierResourceNotFoundError(
|
|
10620
|
+
`No trigger inbox with key "${inbox}" found.`,
|
|
10621
|
+
{ resourceType: "trigger_inbox", resourceId: inbox }
|
|
10622
|
+
);
|
|
10623
|
+
}
|
|
10624
|
+
return id;
|
|
10625
|
+
}
|
|
10626
|
+
function extractErrorDetail(data) {
|
|
10627
|
+
if (typeof data !== "object" || data === null) return void 0;
|
|
10628
|
+
const errors = data.errors;
|
|
10629
|
+
if (!Array.isArray(errors) || errors.length === 0) return void 0;
|
|
10630
|
+
const first = errors[0];
|
|
10631
|
+
if (typeof first !== "object" || first === null) return void 0;
|
|
10632
|
+
const detail = first.detail;
|
|
10633
|
+
return typeof detail === "string" ? detail : void 0;
|
|
10634
|
+
}
|
|
10635
|
+
|
|
10636
|
+
// src/plugins/triggers/createTriggerInbox/index.ts
|
|
10637
|
+
var createTriggerInboxPlugin = definePlugin(
|
|
10638
|
+
(sdk) => createPluginMethod(sdk, {
|
|
10639
|
+
...triggersDefaults,
|
|
10640
|
+
name: "createTriggerInbox",
|
|
10641
|
+
type: "create",
|
|
10642
|
+
itemType: "TriggerInbox",
|
|
10643
|
+
inputSchema: CreateTriggerInboxSchema,
|
|
10644
|
+
outputSchema: TriggerInboxItemSchema,
|
|
10645
|
+
formatter: triggerInboxItemFormatter,
|
|
10646
|
+
// actionKeyResolver and inputsResolver depend on actionType, which is
|
|
10647
|
+
// always "read" for triggers. Pin it as a constant resolver so it's
|
|
10648
|
+
// seeded into resolvedParams without polluting the user-facing schema
|
|
10649
|
+
// (where it would leak into the SDK method signature and CLI flags).
|
|
10650
|
+
resolvers: {
|
|
10651
|
+
key: { type: "static", inputType: "text" },
|
|
10652
|
+
app: appKeyResolver,
|
|
10653
|
+
action: actionKeyResolver,
|
|
10654
|
+
connection: connectionIdResolver,
|
|
10655
|
+
inputs: inputsResolver,
|
|
10656
|
+
actionType: { type: "constant", value: "read" }
|
|
10657
|
+
},
|
|
10658
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
10659
|
+
const { api } = sdk2.context;
|
|
10660
|
+
const {
|
|
10661
|
+
app: appKey,
|
|
10662
|
+
action: actionKey,
|
|
10663
|
+
connection,
|
|
10664
|
+
inputs = {},
|
|
10665
|
+
notificationUrl
|
|
10666
|
+
} = options;
|
|
10667
|
+
const key2 = options.key ?? options.name;
|
|
10668
|
+
const resolvedConnectionId = await resolveConnectionId({
|
|
10669
|
+
connection,
|
|
10670
|
+
resolveConnection: sdk2.context.resolveConnection
|
|
10671
|
+
});
|
|
10672
|
+
const selectedApi = await sdk2.context.getVersionedImplementationId(appKey);
|
|
10673
|
+
if (!selectedApi) {
|
|
10674
|
+
throw new ZapierConfigurationError(
|
|
10675
|
+
`No current_implementation_id found for app "${appKey}"`,
|
|
10676
|
+
{ configType: "current_implementation_id" }
|
|
10677
|
+
);
|
|
10678
|
+
}
|
|
10679
|
+
const requestBody = {
|
|
10680
|
+
subscription: {
|
|
10681
|
+
app_key: selectedApi,
|
|
10682
|
+
action_key: actionKey,
|
|
10683
|
+
inputs,
|
|
10684
|
+
connection_id: resolvedConnectionId ?? null
|
|
10685
|
+
}
|
|
10686
|
+
};
|
|
10687
|
+
if (key2 !== void 0) {
|
|
10688
|
+
requestBody.key = key2;
|
|
10689
|
+
}
|
|
10690
|
+
if (notificationUrl !== void 0) {
|
|
10691
|
+
requestBody.notification_url = notificationUrl;
|
|
10692
|
+
}
|
|
10693
|
+
const rawResponse = await api.post(
|
|
10694
|
+
"/trigger-inbox/api/v1/inboxes",
|
|
10695
|
+
requestBody,
|
|
10696
|
+
{
|
|
10697
|
+
authRequired: true,
|
|
10698
|
+
customErrorHandler: ({ status, data }) => {
|
|
10699
|
+
if (status === 409) {
|
|
10700
|
+
const detail = extractErrorDetail(data);
|
|
10701
|
+
return new ZapierConflictError(
|
|
10702
|
+
detail ?? `An inbox with key "${key2}" already exists with a different subscription.`,
|
|
10703
|
+
{ statusCode: status, resourceType: "trigger_inbox" }
|
|
10704
|
+
);
|
|
10705
|
+
}
|
|
10706
|
+
return void 0;
|
|
10707
|
+
}
|
|
10708
|
+
}
|
|
10709
|
+
);
|
|
10710
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
10711
|
+
}
|
|
10712
|
+
})
|
|
10713
|
+
);
|
|
10714
|
+
var EnsureTriggerInboxDescription = "Get-or-create a trigger inbox by key. Idempotent on (user, account, key): returns the existing inbox if a matching subscription is registered, creates a new one otherwise. Throws ZapierConflictError if the key exists with a different subscription.";
|
|
10715
|
+
var EnsureTriggerInboxBaseSchema = z.object({
|
|
10716
|
+
app: AppPropertySchema,
|
|
10717
|
+
action: ActionPropertySchema,
|
|
10718
|
+
connection: ConnectionPropertySchema.nullable().optional().describe(
|
|
10719
|
+
"Connection alias or connection ID. Optional for triggers that don't require auth."
|
|
10720
|
+
),
|
|
10721
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
10722
|
+
"Input parameters for the trigger subscription"
|
|
10723
|
+
),
|
|
10724
|
+
notificationUrl: z.string().url().optional().describe("Webhook URL to POST to when new messages arrive")
|
|
10725
|
+
});
|
|
10726
|
+
var EnsureTriggerInboxSchema = z.object({
|
|
10727
|
+
key: TriggerInboxKeyPropertySchema.describe(
|
|
10728
|
+
"Inbox key; serves as the idempotency key. Required for ensureTriggerInbox \u2014 without one, the API mints a fresh inbox each call (use createTriggerInbox for that path)."
|
|
10729
|
+
)
|
|
10730
|
+
}).merge(EnsureTriggerInboxBaseSchema).describe(EnsureTriggerInboxDescription).meta({ aliases: { name: "key" } });
|
|
10731
|
+
var EnsureTriggerInboxSchemaDeprecated = z.object({
|
|
10732
|
+
name: TriggerInboxNamePropertySchema.describe(
|
|
10733
|
+
"Inbox name; serves as the idempotency key. Required for ensureTriggerInbox \u2014 without one, the API mints a fresh inbox each call (use createTriggerInbox for that path)."
|
|
10734
|
+
)
|
|
10735
|
+
}).merge(EnsureTriggerInboxBaseSchema);
|
|
10736
|
+
var EnsureTriggerInboxInputSchema = z.union([EnsureTriggerInboxSchema, EnsureTriggerInboxSchemaDeprecated]).describe(EnsureTriggerInboxDescription);
|
|
10737
|
+
|
|
10738
|
+
// src/plugins/triggers/ensureTriggerInbox/index.ts
|
|
10739
|
+
var ensureTriggerInboxPlugin = definePlugin(
|
|
10740
|
+
(sdk) => createPluginMethod(sdk, {
|
|
10741
|
+
...triggersDefaults,
|
|
10742
|
+
name: "ensureTriggerInbox",
|
|
10743
|
+
type: "create",
|
|
10744
|
+
itemType: "TriggerInbox",
|
|
10745
|
+
inputSchema: EnsureTriggerInboxInputSchema,
|
|
10746
|
+
outputSchema: TriggerInboxItemSchema,
|
|
10747
|
+
formatter: triggerInboxItemFormatter,
|
|
10748
|
+
// actionKeyResolver and inputsResolver depend on actionType, which is
|
|
10749
|
+
// always "read" for triggers. Pin it as a constant resolver so it's
|
|
10750
|
+
// seeded into resolvedParams without polluting the user-facing schema.
|
|
10751
|
+
resolvers: {
|
|
10752
|
+
key: { type: "static", inputType: "text" },
|
|
10753
|
+
app: appKeyResolver,
|
|
10754
|
+
action: actionKeyResolver,
|
|
10755
|
+
connection: connectionIdResolver,
|
|
10756
|
+
inputs: inputsResolver,
|
|
10757
|
+
actionType: { type: "constant", value: "read" }
|
|
10758
|
+
},
|
|
10759
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
10760
|
+
const { api } = sdk2.context;
|
|
10761
|
+
const {
|
|
10762
|
+
app: appKey,
|
|
10763
|
+
action: actionKey,
|
|
10764
|
+
connection,
|
|
10765
|
+
inputs = {},
|
|
10766
|
+
notificationUrl
|
|
10767
|
+
} = options;
|
|
10768
|
+
const key2 = "key" in options ? options.key : options.name;
|
|
10769
|
+
const resolvedConnectionId = await resolveConnectionId({
|
|
10770
|
+
connection,
|
|
10771
|
+
resolveConnection: sdk2.context.resolveConnection
|
|
10772
|
+
});
|
|
10773
|
+
const selectedApi = await sdk2.context.getVersionedImplementationId(appKey);
|
|
10774
|
+
if (!selectedApi) {
|
|
10775
|
+
throw new ZapierConfigurationError(
|
|
10776
|
+
`No current_implementation_id found for app "${appKey}"`,
|
|
10777
|
+
{ configType: "current_implementation_id" }
|
|
10778
|
+
);
|
|
10779
|
+
}
|
|
10780
|
+
const requestBody = {
|
|
10781
|
+
key: key2,
|
|
10782
|
+
subscription: {
|
|
10783
|
+
app_key: selectedApi,
|
|
10784
|
+
action_key: actionKey,
|
|
10785
|
+
inputs,
|
|
10786
|
+
connection_id: resolvedConnectionId ?? null
|
|
10787
|
+
}
|
|
10788
|
+
};
|
|
10789
|
+
if (notificationUrl !== void 0) {
|
|
10790
|
+
requestBody.notification_url = notificationUrl;
|
|
10791
|
+
}
|
|
10792
|
+
const rawResponse = await api.put(
|
|
10793
|
+
"/trigger-inbox/api/v1/inboxes",
|
|
10794
|
+
requestBody,
|
|
10795
|
+
{
|
|
10796
|
+
authRequired: true,
|
|
10797
|
+
customErrorHandler: ({ status, data }) => {
|
|
10798
|
+
if (status === 409) {
|
|
10799
|
+
const detail = extractErrorDetail(data);
|
|
10800
|
+
return new ZapierConflictError(
|
|
10801
|
+
detail ?? `An inbox with key "${key2}" already exists with a different subscription.`,
|
|
10802
|
+
{ statusCode: status, resourceType: "trigger_inbox" }
|
|
10803
|
+
);
|
|
10804
|
+
}
|
|
10805
|
+
return void 0;
|
|
10806
|
+
}
|
|
10807
|
+
}
|
|
10808
|
+
);
|
|
10809
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
10810
|
+
}
|
|
10811
|
+
})
|
|
10812
|
+
);
|
|
10813
|
+
var ListTriggerInboxesSchema = z.object({
|
|
10814
|
+
key: z.string().min(1).optional().describe(
|
|
10815
|
+
"Filter by inbox key (exact match). Keys are unique per (user, account), so this returns at most one inbox."
|
|
10816
|
+
),
|
|
10817
|
+
/** @deprecated Use `key` instead. */
|
|
10818
|
+
name: z.string().min(1).optional().describe(
|
|
10819
|
+
"Filter by inbox name (exact match). Names are unique per (user, account), so this returns at most one inbox."
|
|
10820
|
+
).meta({ deprecated: true }),
|
|
10821
|
+
status: TriggerInboxStatusSchema.optional().describe(
|
|
10822
|
+
"Filter by inbox status"
|
|
10823
|
+
),
|
|
10824
|
+
pageSize: z.number().int().min(1).optional().describe("Number of inboxes per page"),
|
|
10825
|
+
maxItems: z.number().int().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
10826
|
+
cursor: z.string().optional().describe("Cursor (offset) to start from for pagination")
|
|
10827
|
+
}).describe("List all trigger inboxes for the authenticated user");
|
|
10828
|
+
var ListTriggerInboxesApiResponseSchema = z.object({
|
|
10829
|
+
count: z.number().int(),
|
|
10830
|
+
next: z.string().nullable().optional(),
|
|
10831
|
+
previous: z.string().nullable().optional(),
|
|
10832
|
+
results: z.array(TriggerInboxItemSchema)
|
|
10833
|
+
});
|
|
10834
|
+
|
|
10835
|
+
// src/plugins/triggers/listTriggerInboxes/index.ts
|
|
10836
|
+
var listTriggerInboxesPlugin = definePlugin(
|
|
10837
|
+
(sdk) => createPaginatedPluginMethod(sdk, {
|
|
10838
|
+
...triggersDefaults,
|
|
10839
|
+
...zapierPagination,
|
|
10840
|
+
name: "listTriggerInboxes",
|
|
10841
|
+
type: "list",
|
|
10842
|
+
itemType: "TriggerInbox",
|
|
10843
|
+
inputSchema: ListTriggerInboxesSchema,
|
|
10844
|
+
outputSchema: TriggerInboxItemSchema,
|
|
10845
|
+
formatter: triggerInboxItemFormatter,
|
|
10846
|
+
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
10847
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
10848
|
+
const { api } = sdk2.context;
|
|
10849
|
+
const searchParams = {};
|
|
10850
|
+
if (options.pageSize !== void 0) {
|
|
10851
|
+
searchParams.limit = options.pageSize.toString();
|
|
10852
|
+
}
|
|
10853
|
+
if (options.cursor) {
|
|
10854
|
+
searchParams.offset = options.cursor;
|
|
10855
|
+
}
|
|
10856
|
+
if (options.status) {
|
|
10857
|
+
searchParams.status = options.status;
|
|
10858
|
+
}
|
|
10859
|
+
const keyFilter = options.key ?? options.name;
|
|
10860
|
+
if (keyFilter) {
|
|
10861
|
+
searchParams.key = keyFilter;
|
|
10862
|
+
}
|
|
10863
|
+
const rawResponse = await api.get("/trigger-inbox/api/v1/inboxes", {
|
|
10864
|
+
searchParams,
|
|
10865
|
+
authRequired: true
|
|
10866
|
+
});
|
|
10867
|
+
const response = ListTriggerInboxesApiResponseSchema.parse(rawResponse);
|
|
10868
|
+
return {
|
|
10869
|
+
data: response.results,
|
|
10870
|
+
next: response.next ?? null
|
|
10871
|
+
};
|
|
10872
|
+
}
|
|
10873
|
+
})
|
|
10874
|
+
);
|
|
10875
|
+
var GetTriggerInboxSchema = z.object({
|
|
10876
|
+
inbox: TriggerInboxPropertySchema
|
|
10877
|
+
}).describe("Get details of a trigger inbox by ID");
|
|
10878
|
+
|
|
10879
|
+
// src/plugins/triggers/getTriggerInbox/index.ts
|
|
10880
|
+
var getTriggerInboxPlugin = definePlugin(
|
|
10881
|
+
(sdk) => createPluginMethod(sdk, {
|
|
10882
|
+
...triggersDefaults,
|
|
10883
|
+
name: "getTriggerInbox",
|
|
10884
|
+
type: "item",
|
|
10885
|
+
itemType: "TriggerInbox",
|
|
10886
|
+
inputSchema: GetTriggerInboxSchema,
|
|
10887
|
+
outputSchema: TriggerInboxItemSchema,
|
|
10888
|
+
formatter: triggerInboxItemFormatter,
|
|
10889
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
10890
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
10891
|
+
const { inbox } = options;
|
|
10892
|
+
const inboxId = await resolveTriggerInboxId({
|
|
10893
|
+
api: sdk2.context.api,
|
|
10894
|
+
inbox
|
|
10895
|
+
});
|
|
10896
|
+
const rawResponse = await sdk2.context.api.get(
|
|
10897
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}`,
|
|
10898
|
+
{
|
|
10899
|
+
authRequired: true,
|
|
10900
|
+
resource: { type: "trigger_inbox", id: inboxId }
|
|
10901
|
+
}
|
|
10902
|
+
);
|
|
10903
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
10904
|
+
}
|
|
10905
|
+
})
|
|
10906
|
+
);
|
|
10907
|
+
var UpdateTriggerInboxSchema = z.object({
|
|
10908
|
+
inbox: TriggerInboxPropertySchema,
|
|
10909
|
+
notificationUrl: z.string().url().nullable().optional().describe(
|
|
10910
|
+
"Webhook URL to POST to when new messages arrive. Pass null to clear."
|
|
10911
|
+
)
|
|
10912
|
+
}).describe("Update settings on an existing trigger inbox");
|
|
10913
|
+
|
|
10914
|
+
// src/plugins/triggers/updateTriggerInbox/index.ts
|
|
10915
|
+
var updateTriggerInboxPlugin = definePlugin(
|
|
10916
|
+
(sdk) => createPluginMethod(sdk, {
|
|
10917
|
+
...triggersDefaults,
|
|
10918
|
+
name: "updateTriggerInbox",
|
|
10919
|
+
type: "update",
|
|
10920
|
+
itemType: "TriggerInbox",
|
|
10921
|
+
inputSchema: UpdateTriggerInboxSchema,
|
|
10922
|
+
outputSchema: TriggerInboxItemSchema,
|
|
10923
|
+
formatter: triggerInboxItemFormatter,
|
|
10924
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
10925
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
10926
|
+
const { inbox, notificationUrl } = options;
|
|
10927
|
+
const inboxId = await resolveTriggerInboxId({
|
|
10928
|
+
api: sdk2.context.api,
|
|
10929
|
+
inbox
|
|
10930
|
+
});
|
|
10931
|
+
const requestBody = {};
|
|
10932
|
+
if (notificationUrl !== void 0) {
|
|
10933
|
+
requestBody.notification_url = notificationUrl;
|
|
10934
|
+
}
|
|
10935
|
+
const rawResponse = await sdk2.context.api.patch(
|
|
10936
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}`,
|
|
10937
|
+
requestBody,
|
|
10938
|
+
{
|
|
10939
|
+
authRequired: true,
|
|
10940
|
+
resource: { type: "trigger_inbox", id: inboxId }
|
|
10941
|
+
}
|
|
10942
|
+
);
|
|
10943
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
10944
|
+
}
|
|
10945
|
+
})
|
|
10946
|
+
);
|
|
10947
|
+
var DeleteTriggerInboxSchema = z.object({
|
|
10948
|
+
inbox: TriggerInboxPropertySchema
|
|
10949
|
+
}).describe("Mark a trigger inbox for deletion");
|
|
10950
|
+
|
|
10951
|
+
// src/plugins/triggers/deleteTriggerInbox/index.ts
|
|
10952
|
+
var deleteTriggerInboxPlugin = definePlugin(
|
|
10953
|
+
(sdk) => createPluginMethod(sdk, {
|
|
10954
|
+
...triggersDefaults,
|
|
10955
|
+
name: "deleteTriggerInbox",
|
|
10956
|
+
type: "delete",
|
|
10957
|
+
itemType: "TriggerInbox",
|
|
10958
|
+
inputSchema: DeleteTriggerInboxSchema,
|
|
10959
|
+
outputSchema: TriggerInboxItemSchema,
|
|
10960
|
+
formatter: triggerInboxItemFormatter,
|
|
10961
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
10962
|
+
confirm: "delete",
|
|
10963
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
10964
|
+
const { inbox } = options;
|
|
10965
|
+
const inboxId = await resolveTriggerInboxId({
|
|
10966
|
+
api: sdk2.context.api,
|
|
10967
|
+
inbox
|
|
10968
|
+
});
|
|
10969
|
+
const rawResponse = await sdk2.context.api.delete(
|
|
10970
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}`,
|
|
10971
|
+
void 0,
|
|
10972
|
+
{
|
|
10973
|
+
authRequired: true,
|
|
10974
|
+
resource: { type: "trigger_inbox", id: inboxId }
|
|
10975
|
+
}
|
|
10976
|
+
);
|
|
10977
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
10978
|
+
}
|
|
10979
|
+
})
|
|
10980
|
+
);
|
|
10981
|
+
var PauseTriggerInboxSchema = z.object({
|
|
10982
|
+
inbox: TriggerInboxPropertySchema
|
|
10983
|
+
}).describe("Pause a trigger inbox; events stop being collected");
|
|
10984
|
+
|
|
10985
|
+
// src/plugins/triggers/pauseTriggerInbox/index.ts
|
|
10986
|
+
var pauseTriggerInboxPlugin = definePlugin(
|
|
10987
|
+
(sdk) => createPluginMethod(sdk, {
|
|
10988
|
+
...triggersDefaults,
|
|
10989
|
+
name: "pauseTriggerInbox",
|
|
10990
|
+
type: "update",
|
|
10991
|
+
itemType: "TriggerInbox",
|
|
10992
|
+
inputSchema: PauseTriggerInboxSchema,
|
|
10993
|
+
outputSchema: TriggerInboxItemSchema,
|
|
10994
|
+
formatter: triggerInboxItemFormatter,
|
|
10995
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
10996
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
10997
|
+
const { inbox } = options;
|
|
10998
|
+
const inboxId = await resolveTriggerInboxId({
|
|
10999
|
+
api: sdk2.context.api,
|
|
11000
|
+
inbox
|
|
11001
|
+
});
|
|
11002
|
+
const rawResponse = await sdk2.context.api.post(
|
|
11003
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/pause`,
|
|
11004
|
+
void 0,
|
|
11005
|
+
{
|
|
11006
|
+
authRequired: true,
|
|
11007
|
+
resource: { type: "trigger_inbox", id: inboxId }
|
|
11008
|
+
}
|
|
11009
|
+
);
|
|
11010
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
11011
|
+
}
|
|
11012
|
+
})
|
|
11013
|
+
);
|
|
11014
|
+
var ResumeTriggerInboxSchema = z.object({
|
|
11015
|
+
inbox: TriggerInboxPropertySchema
|
|
11016
|
+
}).describe("Resume a paused trigger inbox; events resume being collected");
|
|
11017
|
+
|
|
11018
|
+
// src/plugins/triggers/resumeTriggerInbox/index.ts
|
|
11019
|
+
var resumeTriggerInboxPlugin = definePlugin(
|
|
11020
|
+
(sdk) => createPluginMethod(sdk, {
|
|
11021
|
+
...triggersDefaults,
|
|
11022
|
+
name: "resumeTriggerInbox",
|
|
11023
|
+
type: "update",
|
|
11024
|
+
itemType: "TriggerInbox",
|
|
11025
|
+
inputSchema: ResumeTriggerInboxSchema,
|
|
11026
|
+
outputSchema: TriggerInboxItemSchema,
|
|
11027
|
+
formatter: triggerInboxItemFormatter,
|
|
11028
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
11029
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
11030
|
+
const { inbox } = options;
|
|
11031
|
+
const inboxId = await resolveTriggerInboxId({
|
|
11032
|
+
api: sdk2.context.api,
|
|
11033
|
+
inbox
|
|
11034
|
+
});
|
|
11035
|
+
const rawResponse = await sdk2.context.api.post(
|
|
11036
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/resume`,
|
|
11037
|
+
void 0,
|
|
11038
|
+
{
|
|
11039
|
+
authRequired: true,
|
|
11040
|
+
resource: { type: "trigger_inbox", id: inboxId }
|
|
11041
|
+
}
|
|
11042
|
+
);
|
|
11043
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
11044
|
+
}
|
|
11045
|
+
})
|
|
11046
|
+
);
|
|
11047
|
+
var TriggerMessageStatusSchema = z.union([z.enum(["available", "leased", "acked", "quarantined"]), z.string()]).describe("Message lifecycle status");
|
|
11048
|
+
var TriggerMessageAttributesSchema = z.object({
|
|
11049
|
+
lease_count: z.number().int(),
|
|
11050
|
+
error_message: z.string().nullable(),
|
|
11051
|
+
possible_duplicate_data: z.boolean()
|
|
11052
|
+
});
|
|
11053
|
+
var TriggerMessageItemSchema = z.object({
|
|
11054
|
+
id: z.string(),
|
|
11055
|
+
created_at: z.string(),
|
|
11056
|
+
status: TriggerMessageStatusSchema,
|
|
11057
|
+
message_attributes: TriggerMessageAttributesSchema
|
|
11058
|
+
});
|
|
11059
|
+
var LeasedTriggerMessageItemSchema = TriggerMessageItemSchema.extend({
|
|
11060
|
+
payload: z.record(z.string(), z.unknown())
|
|
11061
|
+
});
|
|
11062
|
+
|
|
11063
|
+
// src/plugins/triggers/listTriggerInboxMessages/schemas.ts
|
|
11064
|
+
var ListTriggerInboxMessagesSchema = z.object({
|
|
11065
|
+
inbox: TriggerInboxPropertySchema,
|
|
11066
|
+
pageSize: z.number().int().min(1).optional().describe("Number of messages per page"),
|
|
11067
|
+
maxItems: z.number().int().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
11068
|
+
cursor: z.string().optional().describe("Pagination cursor")
|
|
11069
|
+
}).describe("List messages in a trigger inbox (no payload, status-only)");
|
|
11070
|
+
var ListTriggerInboxMessagesApiResponseSchema = z.object({
|
|
11071
|
+
next: z.string().nullable().optional(),
|
|
11072
|
+
previous: z.string().nullable().optional(),
|
|
11073
|
+
results: z.array(TriggerMessageItemSchema)
|
|
11074
|
+
});
|
|
11075
|
+
|
|
11076
|
+
// src/formatters/triggerMessage.ts
|
|
11077
|
+
function buildBaseDetails(item) {
|
|
11078
|
+
const details = [
|
|
11079
|
+
{ text: `Status: ${item.status}`, style: "dim" },
|
|
11080
|
+
{
|
|
11081
|
+
text: `Lease count: ${item.message_attributes.lease_count}`,
|
|
11082
|
+
style: "dim"
|
|
11083
|
+
}
|
|
11084
|
+
];
|
|
11085
|
+
if (item.message_attributes.error_message) {
|
|
11086
|
+
details.push({
|
|
11087
|
+
text: `Error: ${item.message_attributes.error_message}`,
|
|
11088
|
+
style: "warning"
|
|
11089
|
+
});
|
|
11090
|
+
}
|
|
11091
|
+
if (item.message_attributes.possible_duplicate_data) {
|
|
11092
|
+
details.push({ text: "Possible duplicate data", style: "warning" });
|
|
11093
|
+
}
|
|
11094
|
+
return details;
|
|
11095
|
+
}
|
|
11096
|
+
var triggerMessageItemFormatter = {
|
|
11097
|
+
format: (item) => ({
|
|
11098
|
+
title: `Message ${item.id}`,
|
|
11099
|
+
id: item.id,
|
|
11100
|
+
details: buildBaseDetails(item)
|
|
11101
|
+
})
|
|
11102
|
+
};
|
|
11103
|
+
|
|
11104
|
+
// src/plugins/triggers/listTriggerInboxMessages/index.ts
|
|
11105
|
+
var listTriggerInboxMessagesPlugin = definePlugin(
|
|
11106
|
+
(sdk) => createPaginatedPluginMethod(sdk, {
|
|
11107
|
+
...triggersDefaults,
|
|
11108
|
+
...zapierPagination,
|
|
11109
|
+
name: "listTriggerInboxMessages",
|
|
11110
|
+
type: "list",
|
|
11111
|
+
itemType: "TriggerMessage",
|
|
11112
|
+
inputSchema: ListTriggerInboxMessagesSchema,
|
|
11113
|
+
outputSchema: TriggerMessageItemSchema,
|
|
11114
|
+
formatter: triggerMessageItemFormatter,
|
|
11115
|
+
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
11116
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
11117
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
11118
|
+
const { inbox, cursor, pageSize } = options;
|
|
11119
|
+
const inboxId = await resolveTriggerInboxId({
|
|
11120
|
+
api: sdk2.context.api,
|
|
11121
|
+
inbox
|
|
11122
|
+
});
|
|
11123
|
+
const searchParams = {};
|
|
11124
|
+
if (pageSize !== void 0) {
|
|
11125
|
+
searchParams.limit = pageSize.toString();
|
|
11126
|
+
}
|
|
11127
|
+
if (cursor) {
|
|
11128
|
+
searchParams.cursor = cursor;
|
|
11129
|
+
}
|
|
11130
|
+
const rawResponse = await sdk2.context.api.get(
|
|
11131
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/messages`,
|
|
11132
|
+
{ searchParams, authRequired: true }
|
|
11133
|
+
);
|
|
11134
|
+
const response = ListTriggerInboxMessagesApiResponseSchema.parse(rawResponse);
|
|
11135
|
+
return {
|
|
11136
|
+
data: response.results,
|
|
11137
|
+
next: response.next ?? null
|
|
11138
|
+
};
|
|
11139
|
+
}
|
|
11140
|
+
})
|
|
11141
|
+
);
|
|
11142
|
+
var LeaseTriggerInboxMessagesSchema = z.object({
|
|
11143
|
+
inbox: TriggerInboxPropertySchema,
|
|
11144
|
+
leaseLimit: LeaseLimitPropertySchema.optional(),
|
|
11145
|
+
leaseSeconds: LeaseSecondsPropertySchema.optional(),
|
|
11146
|
+
signal: z.custom((v) => v instanceof AbortSignal).optional().describe(
|
|
11147
|
+
"Abort signal forwarded to the lease HTTP request. Aborting causes the in-flight request to reject with AbortError."
|
|
11148
|
+
)
|
|
11149
|
+
}).describe(
|
|
11150
|
+
"Lease up to N messages from a trigger inbox. Returns messages plus a lease ID; ack within the lease window to remove from the inbox."
|
|
11151
|
+
);
|
|
11152
|
+
var InboxAttributesSchema = z.object({
|
|
11153
|
+
status: TriggerInboxStatusSchema,
|
|
11154
|
+
paused_reason: TriggerInboxPausedReasonSchema.nullable()
|
|
11155
|
+
});
|
|
11156
|
+
var LeaseTriggerInboxMessagesItemSchema = z.object({
|
|
11157
|
+
lease_id: z.string().nullable(),
|
|
11158
|
+
leased_until: z.string().nullable(),
|
|
11159
|
+
results: z.array(LeasedTriggerMessageItemSchema),
|
|
11160
|
+
inbox_attributes: InboxAttributesSchema
|
|
11161
|
+
});
|
|
11162
|
+
|
|
11163
|
+
// src/plugins/triggers/leaseTriggerInboxMessages/index.ts
|
|
11164
|
+
function parseLeaseConflict(data) {
|
|
11165
|
+
if (typeof data !== "object" || data === null) return {};
|
|
11166
|
+
const detail = data.detail;
|
|
11167
|
+
const inboxAttributes = data.inbox_attributes;
|
|
11168
|
+
let pausedReason;
|
|
11169
|
+
if (typeof inboxAttributes === "object" && inboxAttributes !== null) {
|
|
11170
|
+
const pr = inboxAttributes.paused_reason;
|
|
11171
|
+
if (typeof pr === "string" && pr.length > 0) pausedReason = pr;
|
|
11172
|
+
}
|
|
11173
|
+
return {
|
|
11174
|
+
detail: typeof detail === "string" ? detail : void 0,
|
|
11175
|
+
pausedReason
|
|
11176
|
+
};
|
|
11177
|
+
}
|
|
11178
|
+
var leaseTriggerInboxMessagesPlugin = definePlugin(
|
|
11179
|
+
(sdk) => createPluginMethod(sdk, {
|
|
11180
|
+
...triggersDefaults,
|
|
11181
|
+
name: "leaseTriggerInboxMessages",
|
|
11182
|
+
type: "create",
|
|
11183
|
+
itemType: "TriggerInboxLease",
|
|
11184
|
+
inputSchema: LeaseTriggerInboxMessagesSchema,
|
|
11185
|
+
outputSchema: LeaseTriggerInboxMessagesItemSchema,
|
|
11186
|
+
resolvers: {
|
|
11187
|
+
inbox: triggerInboxResolver,
|
|
11188
|
+
leaseLimit: { type: "static", inputType: "text" },
|
|
11189
|
+
leaseSeconds: { type: "static", inputType: "text" }
|
|
11190
|
+
},
|
|
11191
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
11192
|
+
const { inbox, leaseLimit, leaseSeconds, signal } = options;
|
|
11193
|
+
const inboxId = await resolveTriggerInboxId({
|
|
11194
|
+
api: sdk2.context.api,
|
|
11195
|
+
inbox
|
|
11196
|
+
});
|
|
11197
|
+
const requestBody = {};
|
|
11198
|
+
if (leaseLimit !== void 0) {
|
|
11199
|
+
requestBody.lease_limit = leaseLimit;
|
|
11200
|
+
}
|
|
11201
|
+
if (leaseSeconds !== void 0) {
|
|
11202
|
+
requestBody.lease_seconds = leaseSeconds;
|
|
11203
|
+
}
|
|
11204
|
+
const rawResponse = await sdk2.context.api.post(
|
|
11205
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/messages/lease`,
|
|
11206
|
+
requestBody,
|
|
11207
|
+
{
|
|
11208
|
+
authRequired: true,
|
|
11209
|
+
signal,
|
|
11210
|
+
customErrorHandler: ({ status, data }) => {
|
|
11211
|
+
if (status !== 409) return void 0;
|
|
11212
|
+
const { detail, pausedReason } = parseLeaseConflict(data);
|
|
11213
|
+
const baseMessage = detail ?? "Inbox is paused and fully drained";
|
|
11214
|
+
const message = pausedReason ? `${baseMessage} (paused_reason: ${pausedReason})` : baseMessage;
|
|
11215
|
+
return new ZapierConflictError(message, {
|
|
11216
|
+
statusCode: status,
|
|
11217
|
+
resourceType: "trigger_inbox"
|
|
11218
|
+
});
|
|
11219
|
+
}
|
|
11220
|
+
}
|
|
11221
|
+
);
|
|
11222
|
+
return { data: LeaseTriggerInboxMessagesItemSchema.parse(rawResponse) };
|
|
11223
|
+
}
|
|
11224
|
+
})
|
|
11225
|
+
);
|
|
11226
|
+
var AckTriggerInboxMessagesSchema = z.object({
|
|
11227
|
+
inbox: TriggerInboxPropertySchema,
|
|
11228
|
+
lease: LeasePropertySchema,
|
|
11229
|
+
messages: z.array(z.string().min(1)).optional().describe(
|
|
11230
|
+
"Specific message IDs to ack. Omit to ack every message in the lease."
|
|
11231
|
+
)
|
|
11232
|
+
}).describe(
|
|
11233
|
+
"Acknowledge messages from a lease. Acked messages are removed from the inbox; unacked ones return to the available pool when the lease expires."
|
|
11234
|
+
);
|
|
11235
|
+
var AckTriggerInboxMessagesItemSchema = z.object({
|
|
11236
|
+
acked_id: z.string().nullable(),
|
|
11237
|
+
results: z.array(TriggerMessageItemSchema)
|
|
11238
|
+
});
|
|
11239
|
+
|
|
11240
|
+
// src/plugins/triggers/ackTriggerInboxMessages/index.ts
|
|
11241
|
+
var ackTriggerInboxMessagesPlugin = definePlugin(
|
|
11242
|
+
(sdk) => createPluginMethod(sdk, {
|
|
11243
|
+
...triggersDefaults,
|
|
11244
|
+
name: "ackTriggerInboxMessages",
|
|
11245
|
+
type: "create",
|
|
11246
|
+
itemType: "TriggerInboxAck",
|
|
11247
|
+
inputSchema: AckTriggerInboxMessagesSchema,
|
|
11248
|
+
outputSchema: AckTriggerInboxMessagesItemSchema,
|
|
11249
|
+
resolvers: {
|
|
11250
|
+
inbox: triggerInboxResolver,
|
|
11251
|
+
// No way to look up a lease — leases are short-lived, only the
|
|
11252
|
+
// most recent leaseTriggerInboxMessages caller knows the ID.
|
|
11253
|
+
// Static resolver prompts for free-text input.
|
|
11254
|
+
lease: { type: "static", inputType: "text" },
|
|
11255
|
+
messages: triggerMessagesResolver
|
|
11256
|
+
},
|
|
11257
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
11258
|
+
const { inbox, lease, messages } = options;
|
|
11259
|
+
const inboxId = await resolveTriggerInboxId({
|
|
11260
|
+
api: sdk2.context.api,
|
|
11261
|
+
inbox
|
|
11262
|
+
});
|
|
11263
|
+
const requestBody = {
|
|
11264
|
+
lease_id: lease
|
|
11265
|
+
};
|
|
11266
|
+
if (messages !== void 0) {
|
|
11267
|
+
requestBody.message_ids = messages;
|
|
11268
|
+
}
|
|
11269
|
+
const rawResponse = await sdk2.context.api.post(
|
|
11270
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/messages/ack`,
|
|
11271
|
+
requestBody,
|
|
11272
|
+
{ authRequired: true }
|
|
11273
|
+
);
|
|
11274
|
+
return { data: AckTriggerInboxMessagesItemSchema.parse(rawResponse) };
|
|
11275
|
+
}
|
|
11276
|
+
})
|
|
11277
|
+
);
|
|
11278
|
+
var ReleaseTriggerInboxMessagesSchema = z.object({
|
|
11279
|
+
inbox: TriggerInboxPropertySchema,
|
|
11280
|
+
lease: LeasePropertySchema,
|
|
11281
|
+
messages: z.array(z.string().min(1)).optional().describe(
|
|
11282
|
+
"Specific message IDs to release. Omit to release every message in the lease."
|
|
11283
|
+
)
|
|
11284
|
+
}).describe(
|
|
11285
|
+
"Release messages from a lease back to the inbox without acknowledging them. Released messages become immediately available for re-leasing. The lease attempt still counts against the per-message lease limit; releasing does not refund the attempt."
|
|
11286
|
+
);
|
|
11287
|
+
var ReleaseTriggerInboxMessagesItemSchema = z.object({
|
|
11288
|
+
released_id: z.string().nullable(),
|
|
11289
|
+
results: z.array(TriggerMessageItemSchema)
|
|
11290
|
+
});
|
|
11291
|
+
|
|
11292
|
+
// src/plugins/triggers/releaseTriggerInboxMessages/index.ts
|
|
11293
|
+
var releaseTriggerInboxMessagesPlugin = definePlugin(
|
|
11294
|
+
(sdk) => createPluginMethod(sdk, {
|
|
11295
|
+
...triggersDefaults,
|
|
11296
|
+
name: "releaseTriggerInboxMessages",
|
|
11297
|
+
type: "create",
|
|
11298
|
+
itemType: "TriggerInboxRelease",
|
|
11299
|
+
inputSchema: ReleaseTriggerInboxMessagesSchema,
|
|
11300
|
+
outputSchema: ReleaseTriggerInboxMessagesItemSchema,
|
|
11301
|
+
resolvers: {
|
|
11302
|
+
inbox: triggerInboxResolver,
|
|
11303
|
+
// No way to look up a lease — leases are short-lived, only the
|
|
11304
|
+
// most recent leaseTriggerInboxMessages caller knows the ID.
|
|
11305
|
+
// Static resolver prompts for free-text input.
|
|
11306
|
+
lease: { type: "static", inputType: "text" },
|
|
11307
|
+
messages: triggerMessagesResolver
|
|
11308
|
+
},
|
|
11309
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
11310
|
+
const { inbox, lease, messages } = options;
|
|
11311
|
+
const inboxId = await resolveTriggerInboxId({
|
|
11312
|
+
api: sdk2.context.api,
|
|
11313
|
+
inbox
|
|
11314
|
+
});
|
|
11315
|
+
const requestBody = {
|
|
11316
|
+
lease_id: lease
|
|
11317
|
+
};
|
|
11318
|
+
if (messages !== void 0) {
|
|
11319
|
+
requestBody.message_ids = messages;
|
|
11320
|
+
}
|
|
11321
|
+
const rawResponse = await sdk2.context.api.post(
|
|
11322
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/messages/release`,
|
|
11323
|
+
requestBody,
|
|
11324
|
+
{ authRequired: true }
|
|
11325
|
+
);
|
|
11326
|
+
return {
|
|
11327
|
+
data: ReleaseTriggerInboxMessagesItemSchema.parse(rawResponse)
|
|
11328
|
+
};
|
|
11329
|
+
}
|
|
11330
|
+
})
|
|
11331
|
+
);
|
|
11332
|
+
|
|
11333
|
+
// src/plugins/triggers/drainTriggerInbox/pipeline.ts
|
|
11334
|
+
function createBatchTracker() {
|
|
11335
|
+
const batches = /* @__PURE__ */ new Map();
|
|
11336
|
+
return {
|
|
11337
|
+
addBatch(id, total) {
|
|
11338
|
+
batches.set(id, { total, inFlight: 0, completed: 0 });
|
|
11339
|
+
},
|
|
11340
|
+
markInFlight(id) {
|
|
11341
|
+
const e = batches.get(id);
|
|
11342
|
+
if (e) e.inFlight++;
|
|
11343
|
+
},
|
|
11344
|
+
/** Decrement inFlight and increment completed. Paired with markInFlight. */
|
|
11345
|
+
markCompleted(id) {
|
|
11346
|
+
const e = batches.get(id);
|
|
11347
|
+
if (!e) return;
|
|
11348
|
+
e.inFlight--;
|
|
11349
|
+
e.completed++;
|
|
11350
|
+
},
|
|
11351
|
+
/** Drop the batch once all items completed; tracker stays small over long drains. */
|
|
11352
|
+
finalizeIfDone(id) {
|
|
11353
|
+
const e = batches.get(id);
|
|
11354
|
+
if (e && e.completed === e.total) batches.delete(id);
|
|
11355
|
+
},
|
|
11356
|
+
inFlightTotal() {
|
|
11357
|
+
let n = 0;
|
|
11358
|
+
for (const e of batches.values()) n += e.inFlight;
|
|
11359
|
+
return n;
|
|
11360
|
+
},
|
|
11361
|
+
/** Items leased but not yet completed (queued + in-flight). */
|
|
11362
|
+
pipelineSize() {
|
|
11363
|
+
let n = 0;
|
|
11364
|
+
for (const e of batches.values()) n += e.total - e.completed;
|
|
11365
|
+
return n;
|
|
11366
|
+
}
|
|
11367
|
+
};
|
|
11368
|
+
}
|
|
11369
|
+
function createWaiter() {
|
|
11370
|
+
const make = () => {
|
|
11371
|
+
let signal;
|
|
11372
|
+
const promise = new Promise((r) => {
|
|
11373
|
+
signal = r;
|
|
11374
|
+
});
|
|
11375
|
+
return { promise, signal };
|
|
11376
|
+
};
|
|
11377
|
+
let current = make();
|
|
11378
|
+
return {
|
|
11379
|
+
wait: () => current.promise,
|
|
11380
|
+
notifyAll: () => {
|
|
11381
|
+
const prev = current;
|
|
11382
|
+
current = make();
|
|
11383
|
+
prev.signal();
|
|
11384
|
+
}
|
|
11385
|
+
};
|
|
11386
|
+
}
|
|
11387
|
+
function addToMap(m, key2, value) {
|
|
11388
|
+
const existing = m.get(key2) ?? [];
|
|
11389
|
+
m.set(key2, [...existing, value]);
|
|
11390
|
+
}
|
|
11391
|
+
async function runBatchedDrainPipeline(options) {
|
|
11392
|
+
const {
|
|
11393
|
+
concurrency,
|
|
11394
|
+
maxItems,
|
|
11395
|
+
leaseSize,
|
|
11396
|
+
fetchBatch,
|
|
11397
|
+
processItem,
|
|
11398
|
+
ackItem,
|
|
11399
|
+
releaseItems
|
|
11400
|
+
} = options;
|
|
11401
|
+
const tracker = createBatchTracker();
|
|
11402
|
+
const waiter = createWaiter();
|
|
11403
|
+
const accumulated = [];
|
|
11404
|
+
const pendingReleases = /* @__PURE__ */ new Map();
|
|
11405
|
+
const queue = [];
|
|
11406
|
+
let totalProcessed = 0;
|
|
11407
|
+
let aborted = false;
|
|
11408
|
+
let exhausted = false;
|
|
11409
|
+
let fetchInProgress = false;
|
|
11410
|
+
let fetchError = void 0;
|
|
11411
|
+
async function tryFetch() {
|
|
11412
|
+
if (fetchInProgress || exhausted || aborted) return;
|
|
11413
|
+
const remainingCap = maxItems !== void 0 ? maxItems - totalProcessed - tracker.pipelineSize() : Number.POSITIVE_INFINITY;
|
|
11414
|
+
if (remainingCap <= 0) return;
|
|
11415
|
+
const requestedSize = Math.min(remainingCap, leaseSize);
|
|
11416
|
+
fetchInProgress = true;
|
|
11417
|
+
try {
|
|
11418
|
+
const result = await fetchBatch(requestedSize);
|
|
11419
|
+
if (result === "exhausted") {
|
|
11420
|
+
exhausted = true;
|
|
11421
|
+
return;
|
|
11422
|
+
}
|
|
11423
|
+
tracker.addBatch(result.id, result.items.length);
|
|
11424
|
+
for (const item of result.items) {
|
|
11425
|
+
queue.push({ item, batchId: result.id });
|
|
11426
|
+
}
|
|
11427
|
+
} catch (err) {
|
|
11428
|
+
fetchError = err;
|
|
11429
|
+
exhausted = true;
|
|
11430
|
+
} finally {
|
|
11431
|
+
fetchInProgress = false;
|
|
11432
|
+
waiter.notifyAll();
|
|
11433
|
+
}
|
|
11434
|
+
}
|
|
11435
|
+
async function processQueueEntry(entry) {
|
|
11436
|
+
tracker.markInFlight(entry.batchId);
|
|
11437
|
+
try {
|
|
11438
|
+
const result = await processItem(entry.item);
|
|
11439
|
+
accumulated.push(result.value);
|
|
11440
|
+
totalProcessed++;
|
|
11441
|
+
if (result.action === "release") {
|
|
11442
|
+
addToMap(pendingReleases, entry.batchId, entry.item.id);
|
|
11443
|
+
}
|
|
11444
|
+
if (result.abort) aborted = true;
|
|
11445
|
+
if (result.action === "ack") {
|
|
11446
|
+
await ackItem(entry.batchId, entry.item.id);
|
|
11447
|
+
}
|
|
11448
|
+
} finally {
|
|
11449
|
+
tracker.markCompleted(entry.batchId);
|
|
11450
|
+
tracker.finalizeIfDone(entry.batchId);
|
|
11451
|
+
waiter.notifyAll();
|
|
11452
|
+
}
|
|
11453
|
+
}
|
|
11454
|
+
async function worker() {
|
|
11455
|
+
while (true) {
|
|
11456
|
+
if (aborted) return;
|
|
11457
|
+
if (maxItems !== void 0 && totalProcessed >= maxItems) return;
|
|
11458
|
+
const entry = queue.shift();
|
|
11459
|
+
if (entry !== void 0) {
|
|
11460
|
+
if (tracker.pipelineSize() < concurrency && !fetchInProgress && !exhausted) {
|
|
11461
|
+
void tryFetch();
|
|
11462
|
+
}
|
|
11463
|
+
await processQueueEntry(entry);
|
|
11464
|
+
continue;
|
|
11465
|
+
}
|
|
11466
|
+
if (!exhausted && !fetchInProgress) void tryFetch();
|
|
11467
|
+
if (queue.length === 0 && !fetchInProgress && (exhausted || aborted) && tracker.inFlightTotal() === 0) {
|
|
11468
|
+
return;
|
|
11469
|
+
}
|
|
11470
|
+
await waiter.wait();
|
|
11471
|
+
}
|
|
11472
|
+
}
|
|
11473
|
+
await tryFetch();
|
|
11474
|
+
if (fetchError !== void 0) throw fetchError;
|
|
11475
|
+
let cleanupError = void 0;
|
|
11476
|
+
try {
|
|
11477
|
+
if (!exhausted || queue.length > 0) {
|
|
11478
|
+
let firstWorkerError = void 0;
|
|
11479
|
+
const workers = Array.from(
|
|
11480
|
+
{ length: concurrency },
|
|
11481
|
+
() => worker().catch((err) => {
|
|
11482
|
+
if (firstWorkerError === void 0) firstWorkerError = err;
|
|
11483
|
+
})
|
|
11484
|
+
);
|
|
11485
|
+
await Promise.all(workers);
|
|
11486
|
+
if (firstWorkerError !== void 0) throw firstWorkerError;
|
|
11487
|
+
}
|
|
11488
|
+
if (fetchError !== void 0) throw fetchError;
|
|
11489
|
+
} finally {
|
|
11490
|
+
while (queue.length > 0) {
|
|
11491
|
+
const entry = queue.shift();
|
|
11492
|
+
addToMap(pendingReleases, entry.batchId, entry.item.id);
|
|
11493
|
+
}
|
|
11494
|
+
for (const [batchId, itemIds] of pendingReleases) {
|
|
11495
|
+
try {
|
|
11496
|
+
await releaseItems(batchId, itemIds);
|
|
11497
|
+
} catch (err) {
|
|
11498
|
+
cleanupError ?? (cleanupError = err);
|
|
11499
|
+
}
|
|
11500
|
+
}
|
|
11501
|
+
}
|
|
11502
|
+
if (cleanupError !== void 0) throw cleanupError;
|
|
11503
|
+
return accumulated;
|
|
11504
|
+
}
|
|
11505
|
+
|
|
11506
|
+
// src/plugins/triggers/drainTriggerInbox/index.ts
|
|
11507
|
+
var nonRetryableDrainErrors = /* @__PURE__ */ new WeakSet();
|
|
11508
|
+
function markNonRetryableDrainError(err) {
|
|
11509
|
+
if (typeof err === "object" && err !== null) {
|
|
11510
|
+
nonRetryableDrainErrors.add(err);
|
|
11511
|
+
}
|
|
11512
|
+
return err;
|
|
11513
|
+
}
|
|
11514
|
+
function isNonRetryableDrainError(err) {
|
|
11515
|
+
return typeof err === "object" && err !== null && nonRetryableDrainErrors.has(err);
|
|
11516
|
+
}
|
|
11517
|
+
function isLeaseExpiredError(err) {
|
|
11518
|
+
if (!(err instanceof ZapierValidationError)) return false;
|
|
11519
|
+
return err.errors?.some((e) => e.code === "lease_expired") ?? false;
|
|
11520
|
+
}
|
|
11521
|
+
async function runDrainPass(options) {
|
|
11522
|
+
const {
|
|
11523
|
+
sdk,
|
|
11524
|
+
inboxId,
|
|
11525
|
+
onMessage,
|
|
11526
|
+
concurrency,
|
|
11527
|
+
leaseLimit,
|
|
11528
|
+
leaseSeconds,
|
|
11529
|
+
maxMessages,
|
|
11530
|
+
releaseOnError,
|
|
11531
|
+
continueOnError,
|
|
11532
|
+
onError,
|
|
11533
|
+
signal
|
|
11534
|
+
} = options;
|
|
11535
|
+
let firstFetch = options.firstFetch;
|
|
11536
|
+
let abortedFromCallback = false;
|
|
11537
|
+
let handlerErrorCaptured = false;
|
|
11538
|
+
let firstHandlerError = void 0;
|
|
11539
|
+
const outcomes = await runBatchedDrainPipeline({
|
|
11540
|
+
concurrency,
|
|
11541
|
+
maxItems: maxMessages,
|
|
11542
|
+
leaseSize: leaseLimit,
|
|
11543
|
+
fetchBatch: async (requestedSize) => {
|
|
11544
|
+
if (signal?.aborted) return "exhausted";
|
|
11545
|
+
let lease;
|
|
11546
|
+
try {
|
|
11547
|
+
({ data: lease } = await sdk.leaseTriggerInboxMessages({
|
|
11548
|
+
inbox: inboxId,
|
|
11549
|
+
leaseLimit: requestedSize,
|
|
11550
|
+
leaseSeconds,
|
|
11551
|
+
signal
|
|
11552
|
+
}));
|
|
11553
|
+
} catch (err) {
|
|
11554
|
+
if (signal?.aborted && isAbortError(err)) return "exhausted";
|
|
11555
|
+
throw err;
|
|
11556
|
+
}
|
|
11557
|
+
if (lease.results.length === 0) {
|
|
11558
|
+
if (firstFetch && lease.inbox_attributes.status === "initialization_failure") {
|
|
11559
|
+
throw markNonRetryableDrainError(
|
|
11560
|
+
new ZapierApiError(
|
|
11561
|
+
`Trigger inbox ${inboxId} is in initialization_failure state \u2014 inspect via getTriggerInbox.`
|
|
11562
|
+
)
|
|
11563
|
+
);
|
|
11564
|
+
}
|
|
11565
|
+
firstFetch = false;
|
|
11566
|
+
return "exhausted";
|
|
11567
|
+
}
|
|
11568
|
+
firstFetch = false;
|
|
11569
|
+
if (!lease.lease_id) return "exhausted";
|
|
11570
|
+
return { id: lease.lease_id, items: lease.results };
|
|
11571
|
+
},
|
|
11572
|
+
processItem: async (message) => {
|
|
11573
|
+
if (signal?.aborted) {
|
|
11574
|
+
return {
|
|
11575
|
+
value: message,
|
|
11576
|
+
action: "release",
|
|
11577
|
+
abort: true
|
|
11578
|
+
};
|
|
11579
|
+
}
|
|
11580
|
+
try {
|
|
11581
|
+
await onMessage(message);
|
|
11582
|
+
return { value: message, action: "ack" };
|
|
11583
|
+
} catch (err) {
|
|
11584
|
+
let action = "ignore";
|
|
11585
|
+
let abort = false;
|
|
11586
|
+
if (err instanceof ZapierAbortDrainSignal) {
|
|
11587
|
+
abort = true;
|
|
11588
|
+
abortedFromCallback = true;
|
|
11589
|
+
if (releaseOnError) action = "release";
|
|
11590
|
+
} else if (err instanceof ZapierReleaseTriggerMessageSignal) {
|
|
11591
|
+
action = "release";
|
|
11592
|
+
} else if (releaseOnError) {
|
|
11593
|
+
action = "release";
|
|
11594
|
+
}
|
|
11595
|
+
if (onError && !(err instanceof ZapierSignal)) {
|
|
11596
|
+
try {
|
|
11597
|
+
await onError(err, message);
|
|
11598
|
+
} catch {
|
|
11599
|
+
}
|
|
11600
|
+
}
|
|
11601
|
+
if (!continueOnError && !(err instanceof ZapierSignal)) {
|
|
11602
|
+
if (!handlerErrorCaptured) {
|
|
11603
|
+
firstHandlerError = err;
|
|
11604
|
+
handlerErrorCaptured = true;
|
|
11605
|
+
}
|
|
11606
|
+
abort = true;
|
|
11607
|
+
}
|
|
11608
|
+
return { value: message, action, abort };
|
|
11609
|
+
}
|
|
11610
|
+
},
|
|
11611
|
+
ackItem: async (leaseId, messageId) => {
|
|
11612
|
+
try {
|
|
11613
|
+
await sdk.ackTriggerInboxMessages({
|
|
11614
|
+
inbox: inboxId,
|
|
11615
|
+
lease: leaseId,
|
|
11616
|
+
messages: [messageId]
|
|
11617
|
+
});
|
|
11618
|
+
} catch (err) {
|
|
11619
|
+
if (!isLeaseExpiredError(err)) throw err;
|
|
11620
|
+
}
|
|
11621
|
+
},
|
|
11622
|
+
releaseItems: async (leaseId, messageIds) => {
|
|
11623
|
+
try {
|
|
11624
|
+
await sdk.releaseTriggerInboxMessages({
|
|
11625
|
+
inbox: inboxId,
|
|
11626
|
+
lease: leaseId,
|
|
11627
|
+
messages: messageIds
|
|
11628
|
+
});
|
|
11629
|
+
} catch (err) {
|
|
11630
|
+
if (!isLeaseExpiredError(err)) throw err;
|
|
11631
|
+
}
|
|
11632
|
+
}
|
|
11633
|
+
});
|
|
11634
|
+
if (handlerErrorCaptured) {
|
|
11635
|
+
throw markNonRetryableDrainError(firstHandlerError);
|
|
11636
|
+
}
|
|
11637
|
+
return { abortedFromCallback, processed: outcomes.length };
|
|
11638
|
+
}
|
|
11639
|
+
function requireOnMessage(onMessage) {
|
|
11640
|
+
if (typeof onMessage !== "function") {
|
|
11641
|
+
throw new ZapierValidationError("onMessage is required.");
|
|
11642
|
+
}
|
|
11643
|
+
return onMessage;
|
|
11644
|
+
}
|
|
11645
|
+
function resolveConcurrencyAndLease(options) {
|
|
11646
|
+
const concurrency = options.concurrency ?? options.leaseLimit ?? 1;
|
|
11647
|
+
const leaseLimit = options.leaseLimit ?? concurrency;
|
|
11648
|
+
return { concurrency, leaseLimit };
|
|
11649
|
+
}
|
|
11650
|
+
var drainTriggerInboxPlugin = definePlugin(
|
|
11651
|
+
(sdk) => {
|
|
11652
|
+
async function drainTriggerInbox(options) {
|
|
11653
|
+
const onMessage = requireOnMessage(options.onMessage);
|
|
11654
|
+
const { concurrency, leaseLimit } = resolveConcurrencyAndLease(options);
|
|
11655
|
+
const inboxId = await resolveTriggerInboxId({
|
|
11656
|
+
api: sdk.context.api,
|
|
11657
|
+
inbox: options.inbox
|
|
11658
|
+
});
|
|
11659
|
+
await runDrainPass({
|
|
11660
|
+
sdk,
|
|
11661
|
+
inboxId,
|
|
11662
|
+
onMessage,
|
|
11663
|
+
concurrency,
|
|
11664
|
+
leaseLimit,
|
|
11665
|
+
leaseSeconds: options.leaseSeconds,
|
|
11666
|
+
maxMessages: options.maxMessages,
|
|
11667
|
+
releaseOnError: options.releaseOnError ?? false,
|
|
11668
|
+
continueOnError: options.continueOnError ?? false,
|
|
11669
|
+
onError: options.onError,
|
|
11670
|
+
signal: options.signal,
|
|
11671
|
+
firstFetch: true
|
|
11672
|
+
});
|
|
11673
|
+
}
|
|
11674
|
+
return {
|
|
11675
|
+
drainTriggerInbox,
|
|
11676
|
+
context: {
|
|
11677
|
+
meta: {
|
|
11678
|
+
drainTriggerInbox: {
|
|
11679
|
+
...triggersDefaults,
|
|
11680
|
+
type: "create",
|
|
11681
|
+
description: "Drain an existing trigger inbox: lease currently-available messages, process each via onMessage, return when the inbox is empty, maxMessages is reached, or the abort signal fires.",
|
|
11682
|
+
itemType: "void",
|
|
11683
|
+
// The doc generator's default for type="create" + itemType
|
|
11684
|
+
// appends "Item" (e.g. "RecordItem"), which would render
|
|
11685
|
+
// "voidItem" here. drainTriggerInbox returns Promise<void>,
|
|
11686
|
+
// so we override.
|
|
11687
|
+
returnType: "void",
|
|
11688
|
+
inputSchema: DrainTriggerInboxSchema,
|
|
11689
|
+
resolvers: {
|
|
11690
|
+
inbox: triggerInboxResolver
|
|
11691
|
+
},
|
|
11692
|
+
// Returns Promise<void>; the CLI ships a hand-written
|
|
11693
|
+
// drain-trigger-inbox plugin that adds presentation flags
|
|
11694
|
+
// (interactive, --json, etc.) around this command.
|
|
11695
|
+
packages: ["sdk"]
|
|
11696
|
+
}
|
|
11697
|
+
}
|
|
11698
|
+
}
|
|
11699
|
+
};
|
|
11700
|
+
}
|
|
11701
|
+
);
|
|
11702
|
+
|
|
11703
|
+
// src/plugins/triggers/watchTriggerInbox/sse.ts
|
|
11704
|
+
async function* readInboxEvents({
|
|
11705
|
+
api,
|
|
11706
|
+
inboxId,
|
|
11707
|
+
signal,
|
|
11708
|
+
onOpen
|
|
11709
|
+
}) {
|
|
11710
|
+
for await (const message of api.fetchJsonStream(
|
|
11711
|
+
`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/events`,
|
|
11712
|
+
{ method: "GET", signal, authRequired: true, onOpen }
|
|
11713
|
+
)) {
|
|
11714
|
+
if (!message.parsed) continue;
|
|
11715
|
+
const parsed = message.data;
|
|
11716
|
+
if (typeof parsed === "object" && parsed !== null && typeof parsed.inbox_id === "string" && // Only wake on a frame for this inbox. Case-insensitive: the endpoint
|
|
11717
|
+
// echoes the canonical lowercase UUID, but resolveTriggerInboxId passes
|
|
11718
|
+
// a UUID-shaped `inbox` through unchanged, so its casing may differ.
|
|
11719
|
+
parsed.inbox_id.toLowerCase() === inboxId.toLowerCase()) {
|
|
11720
|
+
yield parsed;
|
|
11721
|
+
}
|
|
11722
|
+
}
|
|
11723
|
+
}
|
|
11724
|
+
|
|
11725
|
+
// src/plugins/triggers/watchTriggerInbox/index.ts
|
|
11726
|
+
var SSE_RECONNECT_BACKOFF_MS = [500, 1e3, 2e3, 5e3];
|
|
11727
|
+
var DEFAULT_SAFETY_DRAIN_INTERVAL_MS = 3e5;
|
|
11728
|
+
var SSE_HEALTHY_CONNECTION_MS = 5e3;
|
|
11729
|
+
var ERROR_BACKOFF_CAP = 4;
|
|
11730
|
+
function createDrainLatch() {
|
|
11731
|
+
let pending = false;
|
|
11732
|
+
const make = () => {
|
|
11733
|
+
let resolve2;
|
|
11734
|
+
const promise = new Promise((r) => {
|
|
11735
|
+
resolve2 = r;
|
|
11736
|
+
});
|
|
11737
|
+
return { promise, resolve: resolve2 };
|
|
11738
|
+
};
|
|
11739
|
+
let current = make();
|
|
11740
|
+
return {
|
|
11741
|
+
request() {
|
|
11742
|
+
pending = true;
|
|
11743
|
+
const prev = current;
|
|
11744
|
+
current = make();
|
|
11745
|
+
prev.resolve();
|
|
11746
|
+
},
|
|
11747
|
+
async waitForRequest() {
|
|
11748
|
+
if (pending) {
|
|
11749
|
+
pending = false;
|
|
11750
|
+
return;
|
|
11751
|
+
}
|
|
11752
|
+
await current.promise;
|
|
11753
|
+
pending = false;
|
|
11754
|
+
}
|
|
11755
|
+
};
|
|
11756
|
+
}
|
|
11757
|
+
async function drainRunner({
|
|
11758
|
+
drainOptions,
|
|
11759
|
+
drainRequest,
|
|
11760
|
+
signal,
|
|
11761
|
+
inboxId,
|
|
11762
|
+
debug
|
|
11763
|
+
}) {
|
|
11764
|
+
let firstFetch = true;
|
|
11765
|
+
let consecutiveErrors = 0;
|
|
11766
|
+
let errorAttempts = 0;
|
|
11767
|
+
let drainDegraded = false;
|
|
11768
|
+
while (!signal.aborted) {
|
|
11769
|
+
await drainRequest.waitForRequest();
|
|
11770
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
11771
|
+
let abortedFromCallback = false;
|
|
11772
|
+
try {
|
|
11773
|
+
({ abortedFromCallback } = await runDrainPass({
|
|
11774
|
+
...drainOptions,
|
|
11775
|
+
firstFetch
|
|
11776
|
+
}));
|
|
11777
|
+
} catch (error) {
|
|
11778
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
11779
|
+
const isNonObjectThrow = typeof error !== "object" || error === null;
|
|
11780
|
+
if (isNonObjectThrow || isNonRetryableDrainError(error) || isPermanentHttpError(error)) {
|
|
11781
|
+
return { kind: "error", error };
|
|
11782
|
+
}
|
|
11783
|
+
consecutiveErrors = Math.min(consecutiveErrors + 1, ERROR_BACKOFF_CAP);
|
|
11784
|
+
errorAttempts += 1;
|
|
11785
|
+
const delay = calculateErrorBackoffMs(
|
|
11786
|
+
BASE_ERROR_BACKOFF_MS,
|
|
11787
|
+
consecutiveErrors
|
|
11788
|
+
);
|
|
11789
|
+
const statusCode = errorStatusCode(error);
|
|
11790
|
+
const httpPart = statusCode !== void 0 ? ` (HTTP ${statusCode})` : "";
|
|
11791
|
+
if (!drainDegraded && consecutiveErrors >= ERROR_BACKOFF_CAP) {
|
|
11792
|
+
console.warn(
|
|
11793
|
+
`[zapier-sdk] Draining inbox ${inboxId}${httpPart} is failing repeatedly: ${errorMessage(error)}. Continuing to retry with backoff.`
|
|
11794
|
+
);
|
|
11795
|
+
drainDegraded = true;
|
|
11796
|
+
}
|
|
11797
|
+
if (debug) {
|
|
11798
|
+
console.error(
|
|
11799
|
+
`[zapier-sdk] Retrying drain for inbox ${inboxId} (attempt ${errorAttempts}, retry in ${delay}ms)${httpPart}: ${errorMessage(error)}`
|
|
11800
|
+
);
|
|
11801
|
+
}
|
|
11802
|
+
await sleep(delay, signal);
|
|
11803
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
11804
|
+
drainRequest.request();
|
|
11805
|
+
continue;
|
|
11806
|
+
}
|
|
11807
|
+
firstFetch = false;
|
|
11808
|
+
consecutiveErrors = 0;
|
|
11809
|
+
errorAttempts = 0;
|
|
11810
|
+
drainDegraded = false;
|
|
11811
|
+
if (abortedFromCallback) return { kind: "abortedFromCallback" };
|
|
11812
|
+
}
|
|
11813
|
+
return { kind: "aborted" };
|
|
11814
|
+
}
|
|
11815
|
+
function errorStatusCode(err) {
|
|
11816
|
+
return err instanceof ZapierError ? err.statusCode : void 0;
|
|
11817
|
+
}
|
|
11818
|
+
function errorMessage(err) {
|
|
11819
|
+
return err instanceof Error ? err.message : String(err);
|
|
11820
|
+
}
|
|
11821
|
+
async function sseLoop({
|
|
11822
|
+
api,
|
|
11823
|
+
inboxId,
|
|
11824
|
+
drainRequest,
|
|
11825
|
+
safetyDrainMs,
|
|
11826
|
+
signal,
|
|
11827
|
+
debug
|
|
11828
|
+
}) {
|
|
11829
|
+
let attempt = 0;
|
|
11830
|
+
let degraded = false;
|
|
11831
|
+
while (!signal.aborted) {
|
|
11832
|
+
let connected = false;
|
|
11833
|
+
let connectedAt = 0;
|
|
11834
|
+
let transientError;
|
|
11835
|
+
try {
|
|
11836
|
+
for await (const _event of readInboxEvents({
|
|
11837
|
+
api,
|
|
11838
|
+
inboxId,
|
|
11839
|
+
signal,
|
|
11840
|
+
// SSE is edge-triggered with no replay, so draining on connect is the
|
|
11841
|
+
// only way to pick up messages that arrived before this connection —
|
|
11842
|
+
// including the window left by a prior disconnect.
|
|
11843
|
+
onOpen: () => {
|
|
11844
|
+
connected = true;
|
|
11845
|
+
connectedAt = Date.now();
|
|
11846
|
+
degraded = false;
|
|
11847
|
+
drainRequest.request();
|
|
11848
|
+
}
|
|
11849
|
+
})) {
|
|
11850
|
+
drainRequest.request();
|
|
11851
|
+
}
|
|
11852
|
+
if (connected && Date.now() - connectedAt >= SSE_HEALTHY_CONNECTION_MS) {
|
|
11853
|
+
attempt = 0;
|
|
11854
|
+
}
|
|
11855
|
+
} catch (err) {
|
|
11856
|
+
if (signal.aborted || isAbortError(err)) return;
|
|
11857
|
+
if (isPermanentHttpError(err)) {
|
|
11858
|
+
if (!degraded) {
|
|
11859
|
+
const statusCode = errorStatusCode(err);
|
|
11860
|
+
const errorMsg = errorMessage(err);
|
|
11861
|
+
const httpPart = statusCode !== void 0 ? ` (HTTP ${statusCode})` : "";
|
|
11862
|
+
console.warn(
|
|
11863
|
+
`[zapier-sdk] Real-time wake-ups for inbox ${inboxId}${httpPart} paused: ${errorMsg}. Falling back to the periodic safety drain.`
|
|
11864
|
+
);
|
|
11865
|
+
degraded = true;
|
|
11866
|
+
}
|
|
11867
|
+
attempt = 0;
|
|
11868
|
+
if (signal.aborted) return;
|
|
11869
|
+
await sleep(safetyDrainMs, signal);
|
|
11870
|
+
continue;
|
|
11871
|
+
}
|
|
11872
|
+
if (connected) attempt = 0;
|
|
11873
|
+
transientError = err;
|
|
11874
|
+
}
|
|
11875
|
+
if (signal.aborted) return;
|
|
11876
|
+
const delay = SSE_RECONNECT_BACKOFF_MS[Math.min(attempt, SSE_RECONNECT_BACKOFF_MS.length - 1)];
|
|
11877
|
+
attempt = Math.min(attempt + 1, SSE_RECONNECT_BACKOFF_MS.length - 1);
|
|
11878
|
+
if (transientError !== void 0 && debug) {
|
|
11879
|
+
const statusCode = errorStatusCode(transientError);
|
|
11880
|
+
const errorMsg = errorMessage(transientError);
|
|
11881
|
+
const httpPart = statusCode !== void 0 ? ` (HTTP ${statusCode})` : "";
|
|
11882
|
+
console.error(
|
|
11883
|
+
`[zapier-sdk] Reconnecting real-time wake-ups for inbox ${inboxId} (attempt ${attempt}, retry in ${delay}ms)${httpPart}: ${errorMsg}`
|
|
11884
|
+
);
|
|
11885
|
+
}
|
|
11886
|
+
await sleep(delay, signal);
|
|
11887
|
+
}
|
|
11888
|
+
}
|
|
11889
|
+
async function safetyTimerLoop({
|
|
11890
|
+
safetyDrainMs,
|
|
11891
|
+
drainRequest,
|
|
11892
|
+
signal
|
|
11893
|
+
}) {
|
|
11894
|
+
while (!signal.aborted) {
|
|
11895
|
+
await sleep(safetyDrainMs, signal);
|
|
11896
|
+
if (signal.aborted) return;
|
|
11897
|
+
drainRequest.request();
|
|
11898
|
+
}
|
|
11899
|
+
}
|
|
11900
|
+
var watchTriggerInboxPlugin = definePlugin(
|
|
11901
|
+
(sdk) => {
|
|
11902
|
+
async function watchTriggerInbox(options) {
|
|
11903
|
+
const onMessage = requireOnMessage(options.onMessage);
|
|
11904
|
+
const { concurrency, leaseLimit } = resolveConcurrencyAndLease(options);
|
|
11905
|
+
const inboxId = await resolveTriggerInboxId({
|
|
11906
|
+
api: sdk.context.api,
|
|
11907
|
+
inbox: options.inbox
|
|
11908
|
+
});
|
|
11909
|
+
if (options.signal?.aborted) return;
|
|
11910
|
+
const safetyDrainMs = options.maxDrainIntervalSeconds !== void 0 ? options.maxDrainIntervalSeconds * 1e3 : DEFAULT_SAFETY_DRAIN_INTERVAL_MS;
|
|
11911
|
+
const stop = new AbortController();
|
|
11912
|
+
const combined = combineAbortSignals({
|
|
11913
|
+
handles: [
|
|
11914
|
+
...options.signal ? [{ signal: options.signal, dispose: () => {
|
|
11915
|
+
} }] : [],
|
|
11916
|
+
{ signal: stop.signal, dispose: () => {
|
|
11917
|
+
} }
|
|
11918
|
+
]
|
|
11919
|
+
});
|
|
11920
|
+
const signal = combined?.signal ?? stop.signal;
|
|
11921
|
+
const drainRequest = createDrainLatch();
|
|
11922
|
+
signal.addEventListener("abort", () => drainRequest.request(), {
|
|
11923
|
+
once: true
|
|
11924
|
+
});
|
|
11925
|
+
const debug = sdk.context.options.debug === true;
|
|
11926
|
+
const drainOptions = {
|
|
11927
|
+
sdk,
|
|
11928
|
+
inboxId,
|
|
11929
|
+
onMessage,
|
|
11930
|
+
concurrency,
|
|
11931
|
+
leaseLimit,
|
|
11932
|
+
leaseSeconds: options.leaseSeconds,
|
|
11933
|
+
maxMessages: void 0,
|
|
11934
|
+
releaseOnError: options.releaseOnError ?? false,
|
|
11935
|
+
continueOnError: options.continueOnError ?? false,
|
|
11936
|
+
onError: options.onError,
|
|
11937
|
+
signal
|
|
11938
|
+
};
|
|
11939
|
+
drainRequest.request();
|
|
11940
|
+
const runnerDone = drainRunner({
|
|
11941
|
+
drainOptions,
|
|
11942
|
+
drainRequest,
|
|
11943
|
+
signal,
|
|
11944
|
+
inboxId,
|
|
11945
|
+
debug
|
|
11946
|
+
});
|
|
11947
|
+
const sseDone = sseLoop({
|
|
11948
|
+
api: sdk.context.api,
|
|
11949
|
+
inboxId,
|
|
11950
|
+
drainRequest,
|
|
11951
|
+
safetyDrainMs,
|
|
11952
|
+
signal,
|
|
11953
|
+
debug
|
|
11954
|
+
}).catch(() => {
|
|
11955
|
+
});
|
|
11956
|
+
const safetyDone = safetyTimerLoop({
|
|
11957
|
+
safetyDrainMs,
|
|
11958
|
+
drainRequest,
|
|
11959
|
+
signal
|
|
11960
|
+
}).catch(() => {
|
|
11961
|
+
});
|
|
11962
|
+
let end;
|
|
11963
|
+
try {
|
|
11964
|
+
end = await runnerDone;
|
|
11965
|
+
} finally {
|
|
11966
|
+
stop.abort();
|
|
11967
|
+
await Promise.all([sseDone, safetyDone]);
|
|
11968
|
+
combined?.dispose();
|
|
11969
|
+
}
|
|
11970
|
+
if (end.kind === "error") throw end.error;
|
|
11971
|
+
}
|
|
11972
|
+
return {
|
|
11973
|
+
watchTriggerInbox,
|
|
11974
|
+
context: {
|
|
11975
|
+
meta: {
|
|
11976
|
+
watchTriggerInbox: {
|
|
11977
|
+
...triggersDefaults,
|
|
11978
|
+
type: "create",
|
|
11979
|
+
description: "Continuously consume a trigger inbox: drain currently-available messages via onMessage, then subscribe to SSE notifications for new arrivals until aborted. A periodic safety drain runs every maxDrainIntervalSeconds (default: 300) to guarantee forward progress if SSE events are missed. Resolves cleanly on signal abort or ZapierAbortDrainSignal from a handler. Transient drain failures (5xx, 429, network blips) retry indefinitely with bounded backoff until they succeed or the watch is aborted; it rejects on a fail-fast handler error, an initialization_failure, or a permanent HTTP error. Real-time wake-up health is reported on stderr: a warning when wake-ups pause and the watch falls back to the safety drain, plus (with debug) transient reconnect notices. Persistent drain failures likewise warn once on stderr while bounded-backoff retries continue.",
|
|
11980
|
+
itemType: "void",
|
|
11981
|
+
// See drainTriggerInbox: override the doc generator's default
|
|
11982
|
+
// suffix so the rendered return type is Promise<void>, not
|
|
11983
|
+
// Promise<voidItem>.
|
|
11984
|
+
returnType: "void",
|
|
11985
|
+
inputSchema: WatchTriggerInboxSchema,
|
|
11986
|
+
resolvers: {
|
|
11987
|
+
inbox: triggerInboxResolver
|
|
11988
|
+
},
|
|
11989
|
+
packages: ["sdk"]
|
|
11990
|
+
}
|
|
11991
|
+
}
|
|
11992
|
+
}
|
|
11993
|
+
};
|
|
11994
|
+
}
|
|
11995
|
+
);
|
|
11996
|
+
var ListTriggersSchema = z.object({
|
|
11997
|
+
app: AppPropertySchema.describe(
|
|
11998
|
+
"App key of triggers to list (e.g., 'SlackCLIAPI' or slug like 'github')"
|
|
11999
|
+
),
|
|
12000
|
+
pageSize: z.number().min(1).optional().describe("Number of triggers per page"),
|
|
12001
|
+
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
12002
|
+
cursor: z.string().optional().describe("Cursor to start from")
|
|
12003
|
+
}).describe("List all triggers for a specific app");
|
|
12004
|
+
|
|
12005
|
+
// src/plugins/triggers/listTriggers/index.ts
|
|
12006
|
+
var listTriggersPlugin = definePlugin(
|
|
12007
|
+
(sdk) => createPaginatedPluginMethod(sdk, {
|
|
12008
|
+
...triggersDefaults,
|
|
12009
|
+
name: "listTriggers",
|
|
12010
|
+
type: "list",
|
|
12011
|
+
itemType: "Action",
|
|
12012
|
+
inputSchema: ListTriggersSchema,
|
|
12013
|
+
outputSchema: ActionItemSchema,
|
|
12014
|
+
formatter: actionItemFormatter,
|
|
12015
|
+
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
12016
|
+
resolvers: { app: appKeyResolver },
|
|
12017
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
12018
|
+
return await sdk2.listActions({
|
|
12019
|
+
...options,
|
|
12020
|
+
actionType: "read"
|
|
12021
|
+
});
|
|
12022
|
+
}
|
|
12023
|
+
})
|
|
12024
|
+
);
|
|
12025
|
+
var ListTriggerInputFieldsSchema = z.object({
|
|
12026
|
+
app: AppPropertySchema,
|
|
12027
|
+
action: ActionPropertySchema,
|
|
12028
|
+
connection: ConnectionPropertySchema.optional().describe(
|
|
12029
|
+
"Connection alias or connection ID. Required if the trigger needs a connection to determine available fields."
|
|
12030
|
+
),
|
|
12031
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
12032
|
+
"Current input values that may affect available fields"
|
|
12033
|
+
),
|
|
12034
|
+
pageSize: z.number().min(1).optional().describe("Number of input fields per page"),
|
|
12035
|
+
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
12036
|
+
cursor: z.string().optional().describe("Cursor to start from")
|
|
12037
|
+
}).describe("Get the input fields required for a specific trigger");
|
|
12038
|
+
|
|
12039
|
+
// src/plugins/triggers/listTriggerInputFields/index.ts
|
|
12040
|
+
var listTriggerInputFieldsPlugin = definePlugin(
|
|
12041
|
+
(sdk) => createPaginatedPluginMethod(sdk, {
|
|
12042
|
+
...triggersDefaults,
|
|
12043
|
+
name: "listTriggerInputFields",
|
|
12044
|
+
type: "list",
|
|
12045
|
+
itemType: "RootField",
|
|
12046
|
+
inputSchema: ListTriggerInputFieldsSchema,
|
|
12047
|
+
outputSchema: RootFieldItemSchema,
|
|
12048
|
+
formatter: rootFieldItemFormatter,
|
|
12049
|
+
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
12050
|
+
// actionKeyResolver and inputsAllOptionalResolver depend on actionType.
|
|
12051
|
+
// Pin it to "read" so they resolve correctly without the user setting it.
|
|
12052
|
+
resolvers: {
|
|
12053
|
+
app: appKeyResolver,
|
|
12054
|
+
action: actionKeyResolver,
|
|
12055
|
+
connection: connectionIdResolver,
|
|
12056
|
+
inputs: inputsAllOptionalResolver,
|
|
12057
|
+
actionType: { type: "constant", value: "read" }
|
|
12058
|
+
},
|
|
12059
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
12060
|
+
return await sdk2.listActionInputFields({
|
|
12061
|
+
...options,
|
|
12062
|
+
actionType: "read"
|
|
12063
|
+
});
|
|
12064
|
+
}
|
|
12065
|
+
})
|
|
12066
|
+
);
|
|
12067
|
+
var ListTriggerInputFieldChoicesSchema = z.object({
|
|
12068
|
+
app: AppPropertySchema,
|
|
12069
|
+
action: ActionPropertySchema,
|
|
12070
|
+
inputField: InputFieldPropertySchema,
|
|
12071
|
+
connection: ConnectionPropertySchema.optional().describe(
|
|
12072
|
+
"Connection alias or connection ID. Required if the trigger needs a connection to populate dynamic dropdown options."
|
|
12073
|
+
),
|
|
12074
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
12075
|
+
"Current input values that may affect available choices"
|
|
12076
|
+
),
|
|
12077
|
+
page: z.number().int().min(0).optional().describe("Page number for paginated results"),
|
|
12078
|
+
pageSize: z.number().min(1).optional().describe("Number of choices per page"),
|
|
12079
|
+
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages"),
|
|
12080
|
+
cursor: z.string().optional().describe("Cursor to start from")
|
|
12081
|
+
}).describe(
|
|
12082
|
+
"Get the available choices for a dynamic dropdown input field on a trigger"
|
|
12083
|
+
);
|
|
12084
|
+
|
|
12085
|
+
// src/plugins/triggers/listTriggerInputFieldChoices/index.ts
|
|
12086
|
+
var listTriggerInputFieldChoicesPlugin = definePlugin(
|
|
12087
|
+
(sdk) => createPaginatedPluginMethod(sdk, {
|
|
12088
|
+
...triggersDefaults,
|
|
12089
|
+
name: "listTriggerInputFieldChoices",
|
|
12090
|
+
type: "list",
|
|
12091
|
+
itemType: "InputFieldChoice",
|
|
12092
|
+
inputSchema: ListTriggerInputFieldChoicesSchema,
|
|
12093
|
+
outputSchema: InputFieldChoiceItemSchema,
|
|
12094
|
+
formatter: inputFieldChoiceItemFormatter,
|
|
12095
|
+
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
12096
|
+
resolvers: {
|
|
12097
|
+
app: appKeyResolver,
|
|
12098
|
+
action: actionKeyResolver,
|
|
12099
|
+
connection: connectionIdResolver,
|
|
12100
|
+
inputField: inputFieldKeyResolver,
|
|
12101
|
+
inputs: inputsAllOptionalResolver,
|
|
12102
|
+
actionType: { type: "constant", value: "read" }
|
|
12103
|
+
},
|
|
12104
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
12105
|
+
return await sdk2.listActionInputFieldChoices({
|
|
12106
|
+
...options,
|
|
12107
|
+
actionType: "read"
|
|
12108
|
+
});
|
|
12109
|
+
}
|
|
12110
|
+
})
|
|
12111
|
+
);
|
|
12112
|
+
var GetTriggerInputFieldsSchemaSchema = z.object({
|
|
12113
|
+
app: AppPropertySchema.describe(
|
|
12114
|
+
"App key (e.g., 'SlackCLIAPI' or slug like 'github') to get the input schema for"
|
|
12115
|
+
),
|
|
12116
|
+
action: ActionPropertySchema.describe(
|
|
12117
|
+
"Trigger action key to get the input schema for"
|
|
12118
|
+
),
|
|
12119
|
+
connection: ConnectionPropertySchema.optional().describe(
|
|
12120
|
+
"Connection alias or connection ID. Required if the trigger needs a connection to determine available fields."
|
|
12121
|
+
),
|
|
12122
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
12123
|
+
"Current input values that may affect the schema (e.g., when fields depend on other field values)"
|
|
12124
|
+
)
|
|
12125
|
+
}).describe(
|
|
12126
|
+
"Get the JSON Schema representation of input fields for a trigger. Returns a JSON Schema object describing the structure, types, and validation rules for the trigger's input parameters."
|
|
12127
|
+
);
|
|
12128
|
+
|
|
12129
|
+
// src/plugins/triggers/getTriggerInputFieldsSchema/index.ts
|
|
12130
|
+
var getTriggerInputFieldsSchemaPlugin = definePlugin(
|
|
12131
|
+
(sdk) => createPluginMethod(sdk, {
|
|
12132
|
+
...triggersDefaults,
|
|
12133
|
+
name: "getTriggerInputFieldsSchema",
|
|
12134
|
+
type: "function",
|
|
12135
|
+
inputSchema: GetTriggerInputFieldsSchemaSchema,
|
|
12136
|
+
resolvers: {
|
|
12137
|
+
app: appKeyResolver,
|
|
12138
|
+
action: actionKeyResolver,
|
|
12139
|
+
connection: connectionIdResolver,
|
|
12140
|
+
inputs: inputsAllOptionalResolver,
|
|
12141
|
+
actionType: { type: "constant", value: "read" }
|
|
12142
|
+
},
|
|
12143
|
+
handler: async ({ sdk: sdk2, options }) => {
|
|
12144
|
+
return sdk2.getActionInputFieldsSchema({
|
|
12145
|
+
...options,
|
|
12146
|
+
actionType: "read"
|
|
12147
|
+
});
|
|
12148
|
+
}
|
|
12149
|
+
})
|
|
12150
|
+
);
|
|
10499
12151
|
var TableApiItemSchema = z.object({
|
|
10500
12152
|
id: z.string(),
|
|
10501
12153
|
name: z.string(),
|
|
@@ -11948,10 +13600,10 @@ var eventEmissionPlugin = definePlugin(
|
|
|
11948
13600
|
registeredListeners.uncaughtException = uncaughtExceptionHandler;
|
|
11949
13601
|
globalThis.process.on("uncaughtException", uncaughtExceptionHandler);
|
|
11950
13602
|
const unhandledRejectionHandler = async (reason, promise) => {
|
|
11951
|
-
const
|
|
13603
|
+
const errorMessage2 = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
|
|
11952
13604
|
const errorStack = reason instanceof Error ? reason.stack : null;
|
|
11953
13605
|
let errorEvent = buildErrorEventWithContext({
|
|
11954
|
-
error_message:
|
|
13606
|
+
error_message: errorMessage2,
|
|
11955
13607
|
error_type: "UnhandledRejection",
|
|
11956
13608
|
error_stack_trace: errorStack,
|
|
11957
13609
|
error_severity: "critical",
|
|
@@ -12077,7 +13729,7 @@ function createZapierSdkWithoutRegistry(options = {}) {
|
|
|
12077
13729
|
return createZapierSdk(options);
|
|
12078
13730
|
}
|
|
12079
13731
|
function createZapierSdkStack(options = {}) {
|
|
12080
|
-
return createZapierCoreStack().use(createOptionsPlugin(options)).use(eventEmissionPlugin).use(apiPlugin).use(manifestPlugin).use(capabilitiesPlugin).use(connectionsPlugin).use(listAppsPlugin).use(getAppPlugin).use(listConnectionsPlugin).use(getConnectionPlugin).use(findFirstConnectionPlugin).use(findUniqueConnectionPlugin).use(getConnectionStartUrlPlugin).use(waitForNewConnectionPlugin).use(createConnectionPlugin).use(listActionsPlugin).use(getActionPlugin).use(listActionInputFieldsPlugin).use(getActionInputFieldsSchemaPlugin).use(listActionInputFieldChoicesPlugin).use(listInputFieldsDeprecatedPlugin).use(getInputFieldsSchemaDeprecatedPlugin).use(listInputFieldChoicesDeprecatedPlugin).use(runActionPlugin).use(listAuthenticationsPlugin).use(getAuthenticationPlugin).use(findFirstAuthenticationPlugin).use(findUniqueAuthenticationPlugin).use(listClientCredentialsPlugin).use(createClientCredentialsPlugin).use(deleteClientCredentialsPlugin).use(fetchPlugin).use(requestPlugin).use(listTablesPlugin).use(getTablePlugin).use(deleteTablePlugin).use(createTablePlugin).use(listTableFieldsPlugin).use(createTableFieldsPlugin).use(deleteTableFieldsPlugin).use(listTableRecordsPlugin).use(getTableRecordPlugin).use(createTableRecordsPlugin).use(deleteTableRecordsPlugin).use(updateTableRecordsPlugin).use(appsPlugin);
|
|
13732
|
+
return createZapierCoreStack().use(createOptionsPlugin(options)).use(eventEmissionPlugin).use(apiPlugin).use(manifestPlugin).use(capabilitiesPlugin).use(connectionsPlugin).use(listAppsPlugin).use(getAppPlugin).use(listConnectionsPlugin).use(getConnectionPlugin).use(findFirstConnectionPlugin).use(findUniqueConnectionPlugin).use(getConnectionStartUrlPlugin).use(waitForNewConnectionPlugin).use(createConnectionPlugin).use(listActionsPlugin).use(getActionPlugin).use(listActionInputFieldsPlugin).use(getActionInputFieldsSchemaPlugin).use(listActionInputFieldChoicesPlugin).use(listInputFieldsDeprecatedPlugin).use(getInputFieldsSchemaDeprecatedPlugin).use(listInputFieldChoicesDeprecatedPlugin).use(runActionPlugin).use(listAuthenticationsPlugin).use(getAuthenticationPlugin).use(findFirstAuthenticationPlugin).use(findUniqueAuthenticationPlugin).use(listClientCredentialsPlugin).use(createClientCredentialsPlugin).use(deleteClientCredentialsPlugin).use(fetchPlugin).use(requestPlugin).use(listTriggerInboxesPlugin).use(createTriggerInboxPlugin).use(ensureTriggerInboxPlugin).use(getTriggerInboxPlugin).use(updateTriggerInboxPlugin).use(deleteTriggerInboxPlugin).use(pauseTriggerInboxPlugin).use(resumeTriggerInboxPlugin).use(listTriggerInboxMessagesPlugin).use(leaseTriggerInboxMessagesPlugin).use(ackTriggerInboxMessagesPlugin).use(releaseTriggerInboxMessagesPlugin).use(drainTriggerInboxPlugin).use(watchTriggerInboxPlugin).use(listTriggersPlugin).use(listTriggerInputFieldsPlugin).use(listTriggerInputFieldChoicesPlugin).use(getTriggerInputFieldsSchemaPlugin).use(listTablesPlugin).use(getTablePlugin).use(deleteTablePlugin).use(createTablePlugin).use(listTableFieldsPlugin).use(createTableFieldsPlugin).use(deleteTableFieldsPlugin).use(listTableRecordsPlugin).use(getTableRecordPlugin).use(createTableRecordsPlugin).use(deleteTableRecordsPlugin).use(updateTableRecordsPlugin).use(appsPlugin);
|
|
12081
13733
|
}
|
|
12082
13734
|
var zapierSdkPlugin = definePlugin({
|
|
12083
13735
|
namespace: "zapier",
|