@zapier/zapier-sdk 0.48.1 → 0.50.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 +21 -0
- package/README.md +832 -81
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +27 -16
- package/dist/api/polling.d.ts +7 -0
- package/dist/api/polling.d.ts.map +1 -1
- package/dist/api/polling.js +29 -4
- package/dist/api/types.d.ts +15 -7
- package/dist/api/types.d.ts.map +1 -1
- package/dist/constants.d.ts +8 -9
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +8 -11
- package/dist/experimental.cjs +10383 -0
- package/dist/experimental.d.mts +2292 -0
- package/dist/experimental.d.ts +2308 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +155 -0
- package/dist/experimental.mjs +10202 -0
- package/dist/index-BQ2ii0Bs.d.mts +9538 -0
- package/dist/index-BQ2ii0Bs.d.ts +9538 -0
- package/dist/index.cjs +718 -513
- package/dist/index.d.mts +6 -8562
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.mjs +706 -512
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/api/index.js +1 -2
- package/dist/plugins/apps/index.d.ts +1 -1
- package/dist/plugins/deprecated/inputFields.d.ts +468 -0
- package/dist/plugins/deprecated/inputFields.d.ts.map +1 -0
- package/dist/plugins/deprecated/inputFields.js +73 -0
- package/dist/plugins/fetch/index.d.ts +1 -1
- package/dist/plugins/fetch/schemas.d.ts +1 -1
- package/dist/plugins/{getInputFieldsSchema → getActionInputFieldsSchema}/index.d.ts +4 -4
- package/dist/plugins/getActionInputFieldsSchema/index.d.ts.map +1 -0
- package/dist/plugins/{getInputFieldsSchema → getActionInputFieldsSchema}/index.js +4 -4
- package/dist/plugins/{getInputFieldsSchema → getActionInputFieldsSchema}/schemas.d.ts +8 -8
- package/dist/plugins/getActionInputFieldsSchema/schemas.d.ts.map +1 -0
- package/dist/plugins/{getInputFieldsSchema → getActionInputFieldsSchema}/schemas.js +13 -10
- package/dist/plugins/{listInputFieldChoices → listActionInputFieldChoices}/index.d.ts +4 -4
- package/dist/plugins/listActionInputFieldChoices/index.d.ts.map +1 -0
- package/dist/plugins/{listInputFieldChoices → listActionInputFieldChoices}/index.js +4 -4
- package/dist/plugins/{listInputFieldChoices → listActionInputFieldChoices}/schemas.d.ts +10 -10
- package/dist/plugins/listActionInputFieldChoices/schemas.d.ts.map +1 -0
- package/dist/plugins/{listInputFieldChoices → listActionInputFieldChoices}/schemas.js +13 -10
- package/dist/plugins/{listInputFields → listActionInputFields}/index.d.ts +4 -4
- package/dist/plugins/listActionInputFields/index.d.ts.map +1 -0
- package/dist/plugins/{listInputFields → listActionInputFields}/index.js +4 -4
- package/dist/plugins/{listInputFields → listActionInputFields}/schemas.d.ts +9 -9
- package/dist/plugins/listActionInputFields/schemas.d.ts.map +1 -0
- package/dist/plugins/{listInputFields → listActionInputFields}/schemas.js +7 -7
- package/dist/plugins/request/index.d.ts +2 -2
- package/dist/plugins/request/schemas.d.ts +2 -2
- package/dist/plugins/triggers/ackTriggerInboxMessages/index.d.ts +51 -0
- package/dist/plugins/triggers/ackTriggerInboxMessages/index.d.ts.map +1 -0
- package/dist/plugins/triggers/ackTriggerInboxMessages/index.js +35 -0
- package/dist/plugins/triggers/ackTriggerInboxMessages/schemas.d.ts +34 -0
- package/dist/plugins/triggers/ackTriggerInboxMessages/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/ackTriggerInboxMessages/schemas.js +17 -0
- package/dist/plugins/triggers/createTriggerInbox/index.d.ts +62 -0
- package/dist/plugins/triggers/createTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/createTriggerInbox/index.js +54 -0
- package/dist/plugins/triggers/createTriggerInbox/schemas.d.ts +20 -0
- package/dist/plugins/triggers/createTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/createTriggerInbox/schemas.js +20 -0
- package/dist/plugins/triggers/deleteTriggerInbox/index.d.ts +50 -0
- package/dist/plugins/triggers/deleteTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/deleteTriggerInbox/index.js +27 -0
- package/dist/plugins/triggers/deleteTriggerInbox/schemas.d.ts +14 -0
- package/dist/plugins/triggers/deleteTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/deleteTriggerInbox/schemas.js +9 -0
- package/dist/plugins/triggers/drainTriggerInbox/index.d.ts +213 -0
- package/dist/plugins/triggers/drainTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/drainTriggerInbox/index.js +227 -0
- package/dist/plugins/triggers/drainTriggerInbox/pipeline.d.ts +56 -0
- package/dist/plugins/triggers/drainTriggerInbox/pipeline.d.ts.map +1 -0
- package/dist/plugins/triggers/drainTriggerInbox/pipeline.js +225 -0
- package/dist/plugins/triggers/drainTriggerInbox/schemas.d.ts +104 -0
- package/dist/plugins/triggers/drainTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/drainTriggerInbox/schemas.js +102 -0
- package/dist/plugins/triggers/ensureTriggerInbox/index.d.ts +63 -0
- package/dist/plugins/triggers/ensureTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/ensureTriggerInbox/index.js +77 -0
- package/dist/plugins/triggers/ensureTriggerInbox/schemas.d.ts +21 -0
- package/dist/plugins/triggers/ensureTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/ensureTriggerInbox/schemas.js +21 -0
- package/dist/plugins/triggers/getTriggerInbox/index.d.ts +50 -0
- package/dist/plugins/triggers/getTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/getTriggerInbox/index.js +26 -0
- package/dist/plugins/triggers/getTriggerInbox/schemas.d.ts +14 -0
- package/dist/plugins/triggers/getTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/getTriggerInbox/schemas.js +9 -0
- package/dist/plugins/triggers/getTriggerInputFieldsSchema/index.d.ts +48 -0
- package/dist/plugins/triggers/getTriggerInputFieldsSchema/index.d.ts.map +1 -0
- package/dist/plugins/triggers/getTriggerInputFieldsSchema/index.js +23 -0
- package/dist/plugins/triggers/getTriggerInputFieldsSchema/schemas.d.ts +13 -0
- package/dist/plugins/triggers/getTriggerInputFieldsSchema/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/getTriggerInputFieldsSchema/schemas.js +10 -0
- package/dist/plugins/triggers/leaseTriggerInboxMessages/index.d.ts +58 -0
- package/dist/plugins/triggers/leaseTriggerInboxMessages/index.d.ts.map +1 -0
- package/dist/plugins/triggers/leaseTriggerInboxMessages/index.js +70 -0
- package/dist/plugins/triggers/leaseTriggerInboxMessages/schemas.d.ts +57 -0
- package/dist/plugins/triggers/leaseTriggerInboxMessages/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/leaseTriggerInboxMessages/schemas.js +25 -0
- package/dist/plugins/triggers/listTriggerInboxMessages/index.d.ts +51 -0
- package/dist/plugins/triggers/listTriggerInboxMessages/index.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInboxMessages/index.js +48 -0
- package/dist/plugins/triggers/listTriggerInboxMessages/schemas.d.ts +37 -0
- package/dist/plugins/triggers/listTriggerInboxMessages/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInboxMessages/schemas.js +27 -0
- package/dist/plugins/triggers/listTriggerInboxes/index.d.ts +56 -0
- package/dist/plugins/triggers/listTriggerInboxes/index.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInboxes/index.js +51 -0
- package/dist/plugins/triggers/listTriggerInboxes/schemas.d.ts +58 -0
- package/dist/plugins/triggers/listTriggerInboxes/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInboxes/schemas.js +35 -0
- package/dist/plugins/triggers/listTriggerInputFieldChoices/index.d.ts +77 -0
- package/dist/plugins/triggers/listTriggerInputFieldChoices/index.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInputFieldChoices/index.js +30 -0
- package/dist/plugins/triggers/listTriggerInputFieldChoices/schemas.d.ts +20 -0
- package/dist/plugins/triggers/listTriggerInputFieldChoices/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInputFieldChoices/schemas.js +28 -0
- package/dist/plugins/triggers/listTriggerInputFields/index.d.ts +101 -0
- package/dist/plugins/triggers/listTriggerInputFields/index.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInputFields/index.js +33 -0
- package/dist/plugins/triggers/listTriggerInputFields/schemas.d.ts +16 -0
- package/dist/plugins/triggers/listTriggerInputFields/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/listTriggerInputFields/schemas.js +21 -0
- package/dist/plugins/triggers/pauseTriggerInbox/index.d.ts +50 -0
- package/dist/plugins/triggers/pauseTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/pauseTriggerInbox/index.js +26 -0
- package/dist/plugins/triggers/pauseTriggerInbox/schemas.d.ts +14 -0
- package/dist/plugins/triggers/pauseTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/pauseTriggerInbox/schemas.js +9 -0
- package/dist/plugins/triggers/releaseTriggerInboxMessages/index.d.ts +51 -0
- package/dist/plugins/triggers/releaseTriggerInboxMessages/index.d.ts.map +1 -0
- package/dist/plugins/triggers/releaseTriggerInboxMessages/index.js +37 -0
- package/dist/plugins/triggers/releaseTriggerInboxMessages/schemas.d.ts +34 -0
- package/dist/plugins/triggers/releaseTriggerInboxMessages/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/releaseTriggerInboxMessages/schemas.js +17 -0
- package/dist/plugins/triggers/resumeTriggerInbox/index.d.ts +50 -0
- package/dist/plugins/triggers/resumeTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/resumeTriggerInbox/index.js +26 -0
- package/dist/plugins/triggers/resumeTriggerInbox/schemas.d.ts +14 -0
- package/dist/plugins/triggers/resumeTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/resumeTriggerInbox/schemas.js +9 -0
- package/dist/plugins/triggers/shared.d.ts +17 -0
- package/dist/plugins/triggers/shared.d.ts.map +1 -0
- package/dist/plugins/triggers/shared.js +16 -0
- package/dist/plugins/triggers/updateTriggerInbox/index.d.ts +51 -0
- package/dist/plugins/triggers/updateTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/updateTriggerInbox/index.js +30 -0
- package/dist/plugins/triggers/updateTriggerInbox/schemas.d.ts +15 -0
- package/dist/plugins/triggers/updateTriggerInbox/schemas.d.ts.map +1 -0
- package/dist/plugins/triggers/updateTriggerInbox/schemas.js +15 -0
- package/dist/plugins/triggers/utils.d.ts +17 -0
- package/dist/plugins/triggers/utils.d.ts.map +1 -0
- package/dist/plugins/triggers/utils.js +28 -0
- package/dist/plugins/triggers/watchTriggerInbox/index.d.ts +163 -0
- package/dist/plugins/triggers/watchTriggerInbox/index.d.ts.map +1 -0
- package/dist/plugins/triggers/watchTriggerInbox/index.js +111 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +2 -0
- package/dist/resolvers/actionKey.d.ts +1 -0
- package/dist/resolvers/actionKey.d.ts.map +1 -1
- package/dist/resolvers/actionKey.js +1 -1
- package/dist/resolvers/index.d.ts +2 -2
- package/dist/resolvers/index.d.ts.map +1 -1
- package/dist/resolvers/index.js +2 -2
- package/dist/resolvers/triggerInbox.d.ts +4 -0
- package/dist/resolvers/triggerInbox.d.ts.map +1 -0
- package/dist/resolvers/triggerInbox.js +18 -0
- package/dist/schemas/TriggerInbox.d.ts +59 -0
- package/dist/schemas/TriggerInbox.d.ts.map +1 -0
- package/dist/schemas/TriggerInbox.js +81 -0
- package/dist/schemas/TriggerMessage.d.ts +48 -0
- package/dist/schemas/TriggerMessage.d.ts.map +1 -0
- package/dist/schemas/TriggerMessage.js +79 -0
- package/dist/sdk.d.ts +621 -17
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +26 -9
- package/dist/types/errors.d.ts +18 -5
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +16 -0
- package/dist/types/plugin.d.ts +12 -1
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/properties.d.ts +12 -0
- package/dist/types/properties.d.ts.map +1 -1
- package/dist/types/properties.js +25 -0
- package/dist/types/registry.d.ts +5 -0
- package/dist/types/registry.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +4 -4
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/sdk.js +4 -11
- package/dist/types/signals.d.ts +20 -0
- package/dist/types/signals.d.ts.map +1 -0
- package/dist/types/signals.js +21 -0
- package/dist/utils/abort-utils.d.ts +13 -0
- package/dist/utils/abort-utils.d.ts.map +1 -1
- package/dist/utils/abort-utils.js +15 -0
- package/dist/utils/retry-utils.d.ts +6 -2
- package/dist/utils/retry-utils.d.ts.map +1 -1
- package/dist/utils/retry-utils.js +22 -3
- package/dist/utils/schema-utils.d.ts +19 -1
- package/dist/utils/schema-utils.d.ts.map +1 -1
- package/package.json +12 -1
- package/dist/plugins/getInputFieldsSchema/index.d.ts.map +0 -1
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts.map +0 -1
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +0 -1
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +0 -1
- package/dist/plugins/listInputFields/index.d.ts.map +0 -1
- package/dist/plugins/listInputFields/schemas.d.ts.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { TriggerInboxPropertySchema, LeaseSecondsPropertySchema, } from "../../../types/properties";
|
|
3
|
+
import { ZapierSignal } from "../../../types/signals";
|
|
4
|
+
/**
|
|
5
|
+
* Signal an `onMessage` callback can throw to release the current
|
|
6
|
+
* message back to the inbox immediately (status returns to
|
|
7
|
+
* `available`) rather than leaving it leased until the lease
|
|
8
|
+
* timeout. The actual release call is deferred to the end of the
|
|
9
|
+
* drain so the same drain doesn't immediately re-lease it.
|
|
10
|
+
*
|
|
11
|
+
* Always triggers release regardless of `releaseOnError`.
|
|
12
|
+
*/
|
|
13
|
+
export class ZapierReleaseTriggerMessageSignal extends ZapierSignal {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.name = "ZapierReleaseTriggerMessageSignal";
|
|
17
|
+
this.code = "ZAPIER_RELEASE_TRIGGER_MESSAGE_SIGNAL";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Signal an `onMessage` callback can throw to stop the drain after
|
|
22
|
+
* the current batch — no further leases, no further callbacks. The
|
|
23
|
+
* triggering message gets the same release-or-leave treatment as any
|
|
24
|
+
* thrown error (per `releaseOnError`). Other in-flight messages in
|
|
25
|
+
* the same batch finish normally before the command returns.
|
|
26
|
+
* Already-leased-but-not-yet-started messages are released so
|
|
27
|
+
* they're available for re-lease.
|
|
28
|
+
*/
|
|
29
|
+
export class ZapierAbortDrainSignal extends ZapierSignal {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.name = "ZapierAbortDrainSignal";
|
|
33
|
+
this.code = "ZAPIER_ABORT_DRAIN_SIGNAL";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Source-level options shared by `drainTriggerInbox` and
|
|
38
|
+
* `watchTriggerInbox`. Both methods are eager commands that lease,
|
|
39
|
+
* process via `onMessage`, and return when done.
|
|
40
|
+
*
|
|
41
|
+
* `onMessage` is required. There's no identity default, since "lease
|
|
42
|
+
* and ack everything in this inbox" is a footgun that destroys data
|
|
43
|
+
* on a casual call. Subprocess-style handlers (spawn a binary per
|
|
44
|
+
* message, pipe message JSON to stdin) live as CLI-only flags
|
|
45
|
+
* (`--exec`, `--exec-shell`); the CLI wraps them into an `onMessage`
|
|
46
|
+
* before calling the SDK. Programmatic SDK callers that want the
|
|
47
|
+
* same behavior compose their own `onMessage` around `child_process`.
|
|
48
|
+
*/
|
|
49
|
+
const TriggerInboxCommandBaseSchema = z.object({
|
|
50
|
+
inbox: TriggerInboxPropertySchema,
|
|
51
|
+
onMessage: z
|
|
52
|
+
.function()
|
|
53
|
+
.optional()
|
|
54
|
+
.meta({ exampleRequired: true })
|
|
55
|
+
.describe("Per-message handler. Resolves to ack; rejects to release-or-leave per `releaseOnError`. Throw `ZapierReleaseTriggerMessageSignal` to release explicitly, or `ZapierAbortDrainSignal` to stop after the current batch."),
|
|
56
|
+
concurrency: z
|
|
57
|
+
.number()
|
|
58
|
+
.int()
|
|
59
|
+
.min(1)
|
|
60
|
+
.optional()
|
|
61
|
+
.describe("Per-message handler workers running in parallel. Defaults to `leaseLimit`, or 1 if neither is set."),
|
|
62
|
+
leaseLimit: z
|
|
63
|
+
.number()
|
|
64
|
+
.int()
|
|
65
|
+
.min(1)
|
|
66
|
+
.max(100)
|
|
67
|
+
.optional()
|
|
68
|
+
.describe("Per-lease HTTP batch size. Defaults to `concurrency`, or 1 if neither is set."),
|
|
69
|
+
leaseSeconds: LeaseSecondsPropertySchema.optional(),
|
|
70
|
+
releaseOnError: z
|
|
71
|
+
.boolean()
|
|
72
|
+
.optional()
|
|
73
|
+
.describe("If true, errors immediately release the message. If false (default), errors leave it leased until the lease timeout. `ZapierReleaseTriggerMessageSignal` always releases regardless."),
|
|
74
|
+
continueOnError: z
|
|
75
|
+
.boolean()
|
|
76
|
+
.optional()
|
|
77
|
+
.describe("If false (default, fail-fast), the first handler error rejects and stops the drain. If true, handler errors are observed via `onError` and the drain continues. SDK-level errors (lease / ack / release) reject regardless."),
|
|
78
|
+
onError: z
|
|
79
|
+
.function()
|
|
80
|
+
.optional()
|
|
81
|
+
.describe("Per-message error observer for `continueOnError: true`. Called with the failure and the message; control-flow signals are filtered out. Throws from `onError` are swallowed."),
|
|
82
|
+
signal: z
|
|
83
|
+
.custom((v) => v instanceof AbortSignal)
|
|
84
|
+
.optional()
|
|
85
|
+
.describe("Abort signal. Aborting cancels in-flight HTTP, releases unprocessed messages, and resolves cleanly. Errors during shutdown still reject."),
|
|
86
|
+
});
|
|
87
|
+
export const DrainTriggerInboxSchema = TriggerInboxCommandBaseSchema.extend({
|
|
88
|
+
maxMessages: z
|
|
89
|
+
.number()
|
|
90
|
+
.int()
|
|
91
|
+
.min(1)
|
|
92
|
+
.optional()
|
|
93
|
+
.describe("Cap total messages drained. Defaults to draining the inbox until empty."),
|
|
94
|
+
}).describe("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.");
|
|
95
|
+
export const WatchTriggerInboxSchema = TriggerInboxCommandBaseSchema.extend({
|
|
96
|
+
maxDrainIntervalSeconds: z
|
|
97
|
+
.number()
|
|
98
|
+
.int()
|
|
99
|
+
.min(1)
|
|
100
|
+
.optional()
|
|
101
|
+
.describe("Maximum seconds between empty-inbox poll attempts (default: 60). Caps the back-off cadence."),
|
|
102
|
+
}).describe("Continuously consume a trigger inbox: drain currently-available messages, then poll with backoff for new arrivals, until aborted. Stop via the `signal` AbortSignal or by throwing `ZapierAbortDrainSignal` from a handler. Resolves cleanly on abort; rejects on a fatal error or a fail-fast handler error.");
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EnsureTriggerInboxSchema } from "./schemas";
|
|
2
|
+
import type { GetVersionedImplementationId } from "../../manifest/schemas";
|
|
3
|
+
import type { ConnectionsPluginProvides } from "../../connections";
|
|
4
|
+
export declare const ensureTriggerInboxPlugin: (sdk: {
|
|
5
|
+
context: {
|
|
6
|
+
api: import("../../..").ApiClient;
|
|
7
|
+
resolveCredentials: () => Promise<string | {
|
|
8
|
+
clientId: string;
|
|
9
|
+
clientSecret: string;
|
|
10
|
+
type?: "client_credentials" | undefined;
|
|
11
|
+
baseUrl?: string | undefined;
|
|
12
|
+
scope?: string | undefined;
|
|
13
|
+
} | {
|
|
14
|
+
clientId: string;
|
|
15
|
+
type?: "pkce" | undefined;
|
|
16
|
+
baseUrl?: string | undefined;
|
|
17
|
+
scope?: string | undefined;
|
|
18
|
+
} | undefined>;
|
|
19
|
+
};
|
|
20
|
+
} & {
|
|
21
|
+
context: import("../../eventEmission").EventEmissionContext;
|
|
22
|
+
} & {
|
|
23
|
+
context: {
|
|
24
|
+
getVersionedImplementationId: GetVersionedImplementationId;
|
|
25
|
+
} & ConnectionsPluginProvides["context"];
|
|
26
|
+
} & {
|
|
27
|
+
context: {
|
|
28
|
+
meta: Record<string, import("../../..").PluginMeta>;
|
|
29
|
+
};
|
|
30
|
+
}) => {
|
|
31
|
+
ensureTriggerInbox: (options?: {
|
|
32
|
+
name: string;
|
|
33
|
+
app: string;
|
|
34
|
+
action: string;
|
|
35
|
+
connection?: string | number | null | undefined;
|
|
36
|
+
inputs?: Record<string, unknown> | undefined;
|
|
37
|
+
notificationUrl?: string | undefined;
|
|
38
|
+
} | undefined) => Promise<{
|
|
39
|
+
data: {
|
|
40
|
+
id: string;
|
|
41
|
+
created_at: string;
|
|
42
|
+
name: string | null;
|
|
43
|
+
status: string;
|
|
44
|
+
paused_reason: string | null;
|
|
45
|
+
notification_url: string | null;
|
|
46
|
+
subscription: {
|
|
47
|
+
connection_id: string | number | null;
|
|
48
|
+
app_key: string;
|
|
49
|
+
action_key: string;
|
|
50
|
+
inputs: Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
} & {
|
|
55
|
+
context: {
|
|
56
|
+
meta: {
|
|
57
|
+
ensureTriggerInbox: import("../../..").PluginMeta;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export type EnsureTriggerInboxPluginProvides = ReturnType<typeof ensureTriggerInboxPlugin>;
|
|
62
|
+
export { EnsureTriggerInboxSchema };
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/ensureTriggerInbox/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAA0B,MAAM,WAAW,CAAC;AAa7E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAcnE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;aAIpB;QACP,4BAA4B,EAAE,4BAA4B,CAAC;KAC5D,GAAG,yBAAyB,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgG/C,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,UAAU,CACvD,OAAO,wBAAwB,CAChC,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { definePlugin, createPluginMethod } from "../../../utils/plugin-utils";
|
|
2
|
+
import { EnsureTriggerInboxSchema, TriggerInboxItemSchema } from "./schemas";
|
|
3
|
+
import { ZapierConfigurationError, ZapierConflictError, } from "../../../types/errors";
|
|
4
|
+
import { appKeyResolver, actionKeyResolver, connectionIdResolver, inputsResolver, } from "../../../resolvers";
|
|
5
|
+
import { resolveConnectionId } from "../../../utils/domain-utils";
|
|
6
|
+
import { triggersDefaults } from "../shared";
|
|
7
|
+
function extractErrorDetail(data) {
|
|
8
|
+
if (typeof data !== "object" || data === null)
|
|
9
|
+
return undefined;
|
|
10
|
+
const errors = data.errors;
|
|
11
|
+
if (!Array.isArray(errors) || errors.length === 0)
|
|
12
|
+
return undefined;
|
|
13
|
+
const first = errors[0];
|
|
14
|
+
if (typeof first !== "object" || first === null)
|
|
15
|
+
return undefined;
|
|
16
|
+
const detail = first.detail;
|
|
17
|
+
return typeof detail === "string" ? detail : undefined;
|
|
18
|
+
}
|
|
19
|
+
export const ensureTriggerInboxPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
|
|
20
|
+
...triggersDefaults,
|
|
21
|
+
name: "ensureTriggerInbox",
|
|
22
|
+
type: "create",
|
|
23
|
+
itemType: "TriggerInbox",
|
|
24
|
+
inputSchema: EnsureTriggerInboxSchema,
|
|
25
|
+
outputSchema: TriggerInboxItemSchema,
|
|
26
|
+
// actionKeyResolver and inputsResolver depend on actionType, which is
|
|
27
|
+
// always "read" for triggers. Pin it as a constant resolver so it's
|
|
28
|
+
// seeded into resolvedParams without polluting the user-facing schema.
|
|
29
|
+
resolvers: {
|
|
30
|
+
name: { type: "static", inputType: "text" },
|
|
31
|
+
app: appKeyResolver,
|
|
32
|
+
action: actionKeyResolver,
|
|
33
|
+
connection: connectionIdResolver,
|
|
34
|
+
inputs: inputsResolver,
|
|
35
|
+
actionType: { type: "constant", value: "read" },
|
|
36
|
+
},
|
|
37
|
+
handler: async ({ sdk, options }) => {
|
|
38
|
+
const { api } = sdk.context;
|
|
39
|
+
const { app: appKey, action: actionKey, connection, inputs = {}, name, notificationUrl, } = options;
|
|
40
|
+
const resolvedConnectionId = await resolveConnectionId({
|
|
41
|
+
connection,
|
|
42
|
+
resolveConnection: sdk.context.resolveConnection,
|
|
43
|
+
});
|
|
44
|
+
const selectedApi = await sdk.context.getVersionedImplementationId(appKey);
|
|
45
|
+
if (!selectedApi) {
|
|
46
|
+
throw new ZapierConfigurationError(`No current_implementation_id found for app "${appKey}"`, { configType: "current_implementation_id" });
|
|
47
|
+
}
|
|
48
|
+
const requestBody = {
|
|
49
|
+
name,
|
|
50
|
+
subscription: {
|
|
51
|
+
app_key: selectedApi,
|
|
52
|
+
action_key: actionKey,
|
|
53
|
+
inputs,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
if (notificationUrl !== undefined) {
|
|
57
|
+
requestBody.notification_url = notificationUrl;
|
|
58
|
+
}
|
|
59
|
+
if (resolvedConnectionId !== undefined &&
|
|
60
|
+
resolvedConnectionId !== null) {
|
|
61
|
+
requestBody.subscription.connection_id = resolvedConnectionId;
|
|
62
|
+
}
|
|
63
|
+
const rawResponse = await api.post("/trigger-inbox/api/v1/inboxes", requestBody, {
|
|
64
|
+
authRequired: true,
|
|
65
|
+
customErrorHandler: ({ status, data }) => {
|
|
66
|
+
if (status === 409) {
|
|
67
|
+
const detail = extractErrorDetail(data);
|
|
68
|
+
return new ZapierConflictError(detail ??
|
|
69
|
+
`An inbox named "${name}" already exists with a different subscription.`, { statusCode: status, resourceType: "trigger_inbox" });
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
75
|
+
},
|
|
76
|
+
}));
|
|
77
|
+
export { EnsureTriggerInboxSchema };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { FunctionOptions } from "../../../types/functions";
|
|
3
|
+
import { TriggerInboxItemSchema, type TriggerInboxItem } from "../../../schemas/TriggerInbox";
|
|
4
|
+
export declare const EnsureTriggerInboxSchema: z.ZodObject<{
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
app: z.ZodString & {
|
|
7
|
+
_def: z.core.$ZodStringDef & import("../../..").PositionalMetadata;
|
|
8
|
+
};
|
|
9
|
+
action: z.ZodString & {
|
|
10
|
+
_def: z.core.$ZodStringDef & import("../../..").PositionalMetadata;
|
|
11
|
+
};
|
|
12
|
+
connection: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
13
|
+
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
14
|
+
notificationUrl: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type EnsureTriggerInboxOptions = z.infer<typeof EnsureTriggerInboxSchema> & FunctionOptions;
|
|
17
|
+
export interface EnsureTriggerInboxResult {
|
|
18
|
+
data: TriggerInboxItem;
|
|
19
|
+
}
|
|
20
|
+
export { TriggerInboxItemSchema };
|
|
21
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/ensureTriggerInbox/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAQhE,OAAO,EACL,sBAAsB,EACtB,KAAK,gBAAgB,EACtB,MAAM,+BAA+B,CAAC;AAKvC,eAAO,MAAM,wBAAwB;;;;;;;;;;;iBAqBK,CAAC;AAE3C,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,wBAAwB,CAChC,GACC,eAAe,CAAC;AAElB,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AppPropertySchema, ActionPropertySchema, ConnectionPropertySchema, InputsPropertySchema, TriggerInboxNamePropertySchema, } from "../../../types/properties";
|
|
3
|
+
import { TriggerInboxItemSchema, } from "../../../schemas/TriggerInbox";
|
|
4
|
+
const EnsureTriggerInboxDescription = "Get-or-create a trigger inbox by name. Idempotent on (user, account, name): returns the existing inbox if a matching subscription is registered, creates a new one otherwise. Throws ZapierConflictError if the name exists with a different subscription.";
|
|
5
|
+
export const EnsureTriggerInboxSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
name: TriggerInboxNamePropertySchema.describe("Inbox name; serves as the idempotency key. Required for ensureTriggerInbox — without one, the API mints a fresh inbox each call (use createTriggerInbox for that path)."),
|
|
8
|
+
app: AppPropertySchema,
|
|
9
|
+
action: ActionPropertySchema,
|
|
10
|
+
connection: ConnectionPropertySchema.nullable()
|
|
11
|
+
.optional()
|
|
12
|
+
.describe("Connection alias or connection ID. Optional for triggers that don't require auth."),
|
|
13
|
+
inputs: InputsPropertySchema.optional().describe("Input parameters for the trigger subscription"),
|
|
14
|
+
notificationUrl: z
|
|
15
|
+
.string()
|
|
16
|
+
.url()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Webhook URL to POST to when new messages arrive"),
|
|
19
|
+
})
|
|
20
|
+
.describe(EnsureTriggerInboxDescription);
|
|
21
|
+
export { TriggerInboxItemSchema };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const getTriggerInboxPlugin: (sdk: {
|
|
2
|
+
context: {
|
|
3
|
+
api: import("../../..").ApiClient;
|
|
4
|
+
resolveCredentials: () => Promise<string | {
|
|
5
|
+
clientId: string;
|
|
6
|
+
clientSecret: string;
|
|
7
|
+
type?: "client_credentials" | undefined;
|
|
8
|
+
baseUrl?: string | undefined;
|
|
9
|
+
scope?: string | undefined;
|
|
10
|
+
} | {
|
|
11
|
+
clientId: string;
|
|
12
|
+
type?: "pkce" | undefined;
|
|
13
|
+
baseUrl?: string | undefined;
|
|
14
|
+
scope?: string | undefined;
|
|
15
|
+
} | undefined>;
|
|
16
|
+
};
|
|
17
|
+
} & {
|
|
18
|
+
context: import("../../eventEmission").EventEmissionContext;
|
|
19
|
+
} & {
|
|
20
|
+
context: {
|
|
21
|
+
meta: Record<string, import("../../..").PluginMeta>;
|
|
22
|
+
};
|
|
23
|
+
}) => {
|
|
24
|
+
getTriggerInbox: (options?: {
|
|
25
|
+
inbox: string;
|
|
26
|
+
} | undefined) => Promise<{
|
|
27
|
+
data: {
|
|
28
|
+
id: string;
|
|
29
|
+
created_at: string;
|
|
30
|
+
name: string | null;
|
|
31
|
+
status: string;
|
|
32
|
+
paused_reason: string | null;
|
|
33
|
+
notification_url: string | null;
|
|
34
|
+
subscription: {
|
|
35
|
+
connection_id: string | number | null;
|
|
36
|
+
app_key: string;
|
|
37
|
+
action_key: string;
|
|
38
|
+
inputs: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}>;
|
|
42
|
+
} & {
|
|
43
|
+
context: {
|
|
44
|
+
meta: {
|
|
45
|
+
getTriggerInbox: import("../../..").PluginMeta;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export type GetTriggerInboxPluginProvides = ReturnType<typeof getTriggerInboxPlugin>;
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/getTriggerInbox/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BjC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,UAAU,CACpD,OAAO,qBAAqB,CAC7B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { definePlugin, createPluginMethod } from "../../../utils/plugin-utils";
|
|
2
|
+
import { GetTriggerInboxSchema, TriggerInboxItemSchema } from "./schemas";
|
|
3
|
+
import { triggerInboxResolver } from "../../../resolvers";
|
|
4
|
+
import { resolveTriggerInboxId } from "../utils";
|
|
5
|
+
import { triggersDefaults } from "../shared";
|
|
6
|
+
export const getTriggerInboxPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
|
|
7
|
+
...triggersDefaults,
|
|
8
|
+
name: "getTriggerInbox",
|
|
9
|
+
type: "item",
|
|
10
|
+
itemType: "TriggerInbox",
|
|
11
|
+
inputSchema: GetTriggerInboxSchema,
|
|
12
|
+
outputSchema: TriggerInboxItemSchema,
|
|
13
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
14
|
+
handler: async ({ sdk, options }) => {
|
|
15
|
+
const { inbox } = options;
|
|
16
|
+
const inboxId = await resolveTriggerInboxId({
|
|
17
|
+
api: sdk.context.api,
|
|
18
|
+
inbox,
|
|
19
|
+
});
|
|
20
|
+
const rawResponse = await sdk.context.api.get(`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}`, {
|
|
21
|
+
authRequired: true,
|
|
22
|
+
resource: { type: "trigger_inbox", id: inboxId },
|
|
23
|
+
});
|
|
24
|
+
return { data: TriggerInboxItemSchema.parse(rawResponse) };
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { FunctionOptions } from "../../../types/functions";
|
|
3
|
+
import { TriggerInboxItemSchema, type TriggerInboxItem } from "../../../schemas/TriggerInbox";
|
|
4
|
+
export declare const GetTriggerInboxSchema: z.ZodObject<{
|
|
5
|
+
inbox: z.ZodString & {
|
|
6
|
+
_def: z.core.$ZodStringDef & import("../../..").PositionalMetadata;
|
|
7
|
+
};
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type GetTriggerInboxOptions = z.infer<typeof GetTriggerInboxSchema> & FunctionOptions;
|
|
10
|
+
export interface GetTriggerInboxResult {
|
|
11
|
+
data: TriggerInboxItem;
|
|
12
|
+
}
|
|
13
|
+
export { TriggerInboxItemSchema };
|
|
14
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/getTriggerInbox/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EACL,sBAAsB,EACtB,KAAK,gBAAgB,EACtB,MAAM,+BAA+B,CAAC;AAEvC,eAAO,MAAM,qBAAqB;;;;iBAIiB,CAAC;AAEpD,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GACxE,eAAe,CAAC;AAElB,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { TriggerInboxPropertySchema } from "../../../types/properties";
|
|
3
|
+
import { TriggerInboxItemSchema, } from "../../../schemas/TriggerInbox";
|
|
4
|
+
export const GetTriggerInboxSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
inbox: TriggerInboxPropertySchema,
|
|
7
|
+
})
|
|
8
|
+
.describe("Get details of a trigger inbox by ID");
|
|
9
|
+
export { TriggerInboxItemSchema };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const getTriggerInputFieldsSchemaPlugin: (sdk: {
|
|
2
|
+
getActionInputFieldsSchema: (options?: {
|
|
3
|
+
app: string;
|
|
4
|
+
actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
|
|
5
|
+
action: string;
|
|
6
|
+
connection?: string | number | undefined;
|
|
7
|
+
connectionId?: string | number | null | undefined;
|
|
8
|
+
authenticationId?: string | number | null | undefined;
|
|
9
|
+
inputs?: Record<string, unknown> | undefined;
|
|
10
|
+
} | {
|
|
11
|
+
appKey: string;
|
|
12
|
+
actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
|
|
13
|
+
actionKey: string;
|
|
14
|
+
connection?: string | number | undefined;
|
|
15
|
+
connectionId?: string | number | null | undefined;
|
|
16
|
+
authenticationId?: string | number | null | undefined;
|
|
17
|
+
inputs?: Record<string, unknown> | undefined;
|
|
18
|
+
} | undefined) => Promise<{
|
|
19
|
+
data: Record<string, unknown>;
|
|
20
|
+
}>;
|
|
21
|
+
} & {
|
|
22
|
+
context: {
|
|
23
|
+
meta: {
|
|
24
|
+
getActionInputFieldsSchema: import("../../..").PluginMeta;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
} & {
|
|
28
|
+
context: {
|
|
29
|
+
meta: Record<string, import("../../..").PluginMeta>;
|
|
30
|
+
};
|
|
31
|
+
}) => {
|
|
32
|
+
getTriggerInputFieldsSchema: (options?: {
|
|
33
|
+
app: string;
|
|
34
|
+
action: string;
|
|
35
|
+
connection?: string | number | undefined;
|
|
36
|
+
inputs?: Record<string, unknown> | undefined;
|
|
37
|
+
} | undefined) => Promise<{
|
|
38
|
+
data: Record<string, unknown>;
|
|
39
|
+
}>;
|
|
40
|
+
} & {
|
|
41
|
+
context: {
|
|
42
|
+
meta: {
|
|
43
|
+
getTriggerInputFieldsSchema: import("../../..").PluginMeta;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type GetTriggerInputFieldsSchemaPluginProvides = ReturnType<typeof getTriggerInputFieldsSchemaPlugin>;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/getTriggerInputFieldsSchema/index.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqB7C,CAAC;AAEF,MAAM,MAAM,yCAAyC,GAAG,UAAU,CAChE,OAAO,iCAAiC,CACzC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { definePlugin, createPluginMethod } from "../../../utils/plugin-utils";
|
|
2
|
+
import { GetTriggerInputFieldsSchemaSchema } from "./schemas";
|
|
3
|
+
import { appKeyResolver, actionKeyResolver, connectionIdResolver, inputsAllOptionalResolver, } from "../../../resolvers";
|
|
4
|
+
import { triggersDefaults } from "../shared";
|
|
5
|
+
export const getTriggerInputFieldsSchemaPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
|
|
6
|
+
...triggersDefaults,
|
|
7
|
+
name: "getTriggerInputFieldsSchema",
|
|
8
|
+
type: "function",
|
|
9
|
+
inputSchema: GetTriggerInputFieldsSchemaSchema,
|
|
10
|
+
resolvers: {
|
|
11
|
+
app: appKeyResolver,
|
|
12
|
+
action: actionKeyResolver,
|
|
13
|
+
connection: connectionIdResolver,
|
|
14
|
+
inputs: inputsAllOptionalResolver,
|
|
15
|
+
actionType: { type: "constant", value: "read" },
|
|
16
|
+
},
|
|
17
|
+
handler: async ({ sdk, options }) => {
|
|
18
|
+
return sdk.getActionInputFieldsSchema({
|
|
19
|
+
...options,
|
|
20
|
+
actionType: "read",
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const GetTriggerInputFieldsSchemaSchema: z.ZodObject<{
|
|
3
|
+
app: z.ZodString & {
|
|
4
|
+
_def: z.core.$ZodStringDef & import("../../..").PositionalMetadata;
|
|
5
|
+
};
|
|
6
|
+
action: z.ZodString & {
|
|
7
|
+
_def: z.core.$ZodStringDef & import("../../..").PositionalMetadata;
|
|
8
|
+
};
|
|
9
|
+
connection: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
10
|
+
inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export type GetTriggerInputFieldsSchemaOptions = z.infer<typeof GetTriggerInputFieldsSchemaSchema>;
|
|
13
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/getTriggerInputFieldsSchema/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,iCAAiC;;;;;;;;;iBAiB3C,CAAC;AAEJ,MAAM,MAAM,kCAAkC,GAAG,CAAC,CAAC,KAAK,CACtD,OAAO,iCAAiC,CACzC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AppPropertySchema, ActionPropertySchema, ConnectionPropertySchema, InputsPropertySchema, } from "../../../types/properties";
|
|
3
|
+
export const GetTriggerInputFieldsSchemaSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
app: AppPropertySchema.describe("App key (e.g., 'SlackCLIAPI' or slug like 'github') to get the input schema for"),
|
|
6
|
+
action: ActionPropertySchema.describe("Trigger action key to get the input schema for"),
|
|
7
|
+
connection: ConnectionPropertySchema.optional().describe("Connection alias or connection ID. Required if the trigger needs a connection to determine available fields."),
|
|
8
|
+
inputs: InputsPropertySchema.optional().describe("Current input values that may affect the schema (e.g., when fields depend on other field values)"),
|
|
9
|
+
})
|
|
10
|
+
.describe("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.");
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare const leaseTriggerInboxMessagesPlugin: (sdk: {
|
|
2
|
+
context: {
|
|
3
|
+
api: import("../../..").ApiClient;
|
|
4
|
+
resolveCredentials: () => Promise<string | {
|
|
5
|
+
clientId: string;
|
|
6
|
+
clientSecret: string;
|
|
7
|
+
type?: "client_credentials" | undefined;
|
|
8
|
+
baseUrl?: string | undefined;
|
|
9
|
+
scope?: string | undefined;
|
|
10
|
+
} | {
|
|
11
|
+
clientId: string;
|
|
12
|
+
type?: "pkce" | undefined;
|
|
13
|
+
baseUrl?: string | undefined;
|
|
14
|
+
scope?: string | undefined;
|
|
15
|
+
} | undefined>;
|
|
16
|
+
};
|
|
17
|
+
} & {
|
|
18
|
+
context: import("../../eventEmission").EventEmissionContext;
|
|
19
|
+
} & {
|
|
20
|
+
context: {
|
|
21
|
+
meta: Record<string, import("../../..").PluginMeta>;
|
|
22
|
+
};
|
|
23
|
+
}) => {
|
|
24
|
+
leaseTriggerInboxMessages: (options?: {
|
|
25
|
+
inbox: string;
|
|
26
|
+
leaseLimit?: number | undefined;
|
|
27
|
+
leaseSeconds?: number | undefined;
|
|
28
|
+
signal?: AbortSignal | undefined;
|
|
29
|
+
} | undefined) => Promise<{
|
|
30
|
+
data: {
|
|
31
|
+
lease_id: string | null;
|
|
32
|
+
leased_until: string | null;
|
|
33
|
+
results: {
|
|
34
|
+
id: string;
|
|
35
|
+
created_at: string;
|
|
36
|
+
status: string;
|
|
37
|
+
message_attributes: {
|
|
38
|
+
lease_count: number;
|
|
39
|
+
error_message: string | null;
|
|
40
|
+
possible_duplicate_data: boolean;
|
|
41
|
+
};
|
|
42
|
+
payload: Record<string, unknown>;
|
|
43
|
+
}[];
|
|
44
|
+
inbox_attributes: {
|
|
45
|
+
status: string;
|
|
46
|
+
paused_reason: string | null;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
} & {
|
|
51
|
+
context: {
|
|
52
|
+
meta: {
|
|
53
|
+
leaseTriggerInboxMessages: import("../../..").PluginMeta;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type LeaseTriggerInboxMessagesPluginProvides = ReturnType<typeof leaseTriggerInboxMessagesPlugin>;
|
|
58
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/leaseTriggerInboxMessages/index.ts"],"names":[],"mappings":"AAqCA,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkD3C,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG,UAAU,CAC9D,OAAO,+BAA+B,CACvC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { definePlugin, createPluginMethod } from "../../../utils/plugin-utils";
|
|
2
|
+
import { LeaseTriggerInboxMessagesSchema, LeaseTriggerInboxMessagesItemSchema, } from "./schemas";
|
|
3
|
+
import { ZapierConflictError } from "../../../types/errors";
|
|
4
|
+
import { triggerInboxResolver } from "../../../resolvers";
|
|
5
|
+
import { resolveTriggerInboxId } from "../utils";
|
|
6
|
+
import { triggersDefaults } from "../shared";
|
|
7
|
+
// The trigger-inbox API returns 409 from /messages/lease when the inbox
|
|
8
|
+
// is paused and fully drained, with the shape:
|
|
9
|
+
// { detail: "...", inbox_attributes: { status, paused_reason, paused_at } }
|
|
10
|
+
// (note: top-level `detail`, NOT the standard `{ errors: [...] }`). The
|
|
11
|
+
// SDK's generic error parser doesn't recognize this shape, so without a
|
|
12
|
+
// customErrorHandler the user gets a vague "HTTP 409" with no reason.
|
|
13
|
+
function parseLeaseConflict(data) {
|
|
14
|
+
if (typeof data !== "object" || data === null)
|
|
15
|
+
return {};
|
|
16
|
+
const detail = data.detail;
|
|
17
|
+
const inboxAttributes = data
|
|
18
|
+
.inbox_attributes;
|
|
19
|
+
let pausedReason;
|
|
20
|
+
if (typeof inboxAttributes === "object" && inboxAttributes !== null) {
|
|
21
|
+
const pr = inboxAttributes.paused_reason;
|
|
22
|
+
if (typeof pr === "string" && pr.length > 0)
|
|
23
|
+
pausedReason = pr;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
detail: typeof detail === "string" ? detail : undefined,
|
|
27
|
+
pausedReason,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export const leaseTriggerInboxMessagesPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
|
|
31
|
+
...triggersDefaults,
|
|
32
|
+
name: "leaseTriggerInboxMessages",
|
|
33
|
+
type: "create",
|
|
34
|
+
itemType: "TriggerInboxLease",
|
|
35
|
+
inputSchema: LeaseTriggerInboxMessagesSchema,
|
|
36
|
+
outputSchema: LeaseTriggerInboxMessagesItemSchema,
|
|
37
|
+
resolvers: { inbox: triggerInboxResolver },
|
|
38
|
+
handler: async ({ sdk, options }) => {
|
|
39
|
+
const { inbox, leaseLimit, leaseSeconds, signal } = options;
|
|
40
|
+
const inboxId = await resolveTriggerInboxId({
|
|
41
|
+
api: sdk.context.api,
|
|
42
|
+
inbox,
|
|
43
|
+
});
|
|
44
|
+
const requestBody = {};
|
|
45
|
+
if (leaseLimit !== undefined) {
|
|
46
|
+
requestBody.lease_limit = leaseLimit;
|
|
47
|
+
}
|
|
48
|
+
if (leaseSeconds !== undefined) {
|
|
49
|
+
requestBody.lease_seconds = leaseSeconds;
|
|
50
|
+
}
|
|
51
|
+
const rawResponse = await sdk.context.api.post(`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/messages/lease`, requestBody, {
|
|
52
|
+
authRequired: true,
|
|
53
|
+
signal,
|
|
54
|
+
customErrorHandler: ({ status, data }) => {
|
|
55
|
+
if (status !== 409)
|
|
56
|
+
return undefined;
|
|
57
|
+
const { detail, pausedReason } = parseLeaseConflict(data);
|
|
58
|
+
const baseMessage = detail ?? "Inbox is paused and fully drained";
|
|
59
|
+
const message = pausedReason
|
|
60
|
+
? `${baseMessage} (paused_reason: ${pausedReason})`
|
|
61
|
+
: baseMessage;
|
|
62
|
+
return new ZapierConflictError(message, {
|
|
63
|
+
statusCode: status,
|
|
64
|
+
resourceType: "trigger_inbox",
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return { data: LeaseTriggerInboxMessagesItemSchema.parse(rawResponse) };
|
|
69
|
+
},
|
|
70
|
+
}));
|