@prismatic-io/spectral 10.18.7 → 10.18.9-preview.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.
@@ -4,13 +4,15 @@ import type { ComponentRegistry, ConfigVarExpression, TriggerReference, ValueExp
4
4
  import type { ConfigPages, UserLevelConfigPages } from "./ConfigPages";
5
5
  import type { ConfigVars } from "./ConfigVars";
6
6
  import type { FlowDefinitionFlowSchema } from "./FlowSchemas";
7
+ import type { HttpResponse } from "./HttpResponse";
7
8
  import type { Inputs } from "./Inputs";
8
9
  import type { PollingTriggerPerformFunction } from "./PollingTriggerDefinition";
9
10
  import type { ScopedConfigVarMap } from "./ScopedConfigVars";
11
+ import type { BatchConfig, WithDiscoveryState } from "./TriggerDefinition";
10
12
  import type { TriggerEventFunction } from "./TriggerEventFunction";
11
13
  import type { TriggerPayload } from "./TriggerPayload";
12
14
  import type { TriggerPerformFunction } from "./TriggerPerformFunction";
13
- import type { TriggerResult } from "./TriggerResult";
15
+ import type { TriggerBaseResult, TriggerResult } from "./TriggerResult";
14
16
  /**
15
17
  * Defines attributes of a code-native integration. See
16
18
  * https://prismatic.io/docs/integrations/code-native/
@@ -46,8 +48,13 @@ export type IntegrationDefinition<TInputs extends Inputs = Inputs, TActionInputs
46
48
  /**
47
49
  * Flows for this integration. See
48
50
  * https://prismatic.io/docs/integrations/code-native/flows/
51
+ *
52
+ * The trailing `any`s for `TItem`/`TDiscoveryState`/`TTriggerPayload` let flows with
53
+ * different resolver item and cursor types live in one array. `integration` only holds
54
+ * and serializes these flows (it never invokes `onExecution`), so the precise — and
55
+ * per-flow distinct — `onExecution` param type does not need to be preserved here.
49
56
  */
50
- flows: Flow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult>[];
57
+ flows: Flow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult, any, any, any>[];
51
58
  /**
52
59
  * Config wizard pages for this integration. See
53
60
  * https://prismatic.io/docs/integrations/code-native/config-wizard/
@@ -70,12 +77,66 @@ export type IntegrationDefinition<TInputs extends Inputs = Inputs, TActionInputs
70
77
  */
71
78
  componentRegistry?: ComponentRegistry;
72
79
  };
73
- export type FlowOnExecution<TTriggerPayload extends TriggerPayload> = ActionPerformFunction<{
80
+ /**
81
+ * The trigger payload as `onExecution` sees it. When a `triggerResolver` is in
82
+ * play, the platform replaces `body.data` with this execution's batch slice —
83
+ * a single `TItem` when `batchSize` is 1, otherwise a `TItem[]`. When no item
84
+ * type is known (`TItem` defaults to `unknown`), the payload is left untouched.
85
+ */
86
+ export type BatchedTriggerPayload<TPayload extends TriggerPayload, TItem> = unknown extends TItem ? TPayload : Omit<TPayload, "body"> & {
87
+ body: {
88
+ data: TItem | TItem[];
89
+ contentType?: string;
90
+ };
91
+ };
92
+ /**
93
+ * The page of records a batched trigger fire (`onTrigger`/`onDeploy`) returns. The author
94
+ * returns just the items; spectral wraps them into the wire trigger payload (`body.data`)
95
+ * and synthesizes the resolver that extracts them. Returning `items` is the whole contract —
96
+ * there is no `payload` to thread by hand.
97
+ */
98
+ export interface BatchedTriggerReturn<TItem> {
99
+ /** The records produced by this trigger fire. Chunked into batches of the flow's `batchConfig.batchSize`. */
100
+ items: TItem[];
101
+ /** Optional HTTP response to the request that invoked the integration. */
102
+ response?: HttpResponse;
103
+ }
104
+ /**
105
+ * The pagination callback for a batched trigger fire. Returns the state for the next page,
106
+ * or `null` to stop. A non-null return re-invokes the corresponding trigger with this object
107
+ * stamped onto `payload.discoveryState`; the loop ends when it returns `null`.
108
+ */
109
+ export type BatchPaginationStateFunction<TPaginationState extends Record<string, unknown>> = (context: ActionContext<ConfigVars>, result: TriggerBaseResult<WithDiscoveryState<TriggerPayload, TPaginationState>>) => TPaginationState | null;
110
+ /**
111
+ * A batched trigger built by {@link batchFlowTrigger}. Bundles the normal and on-deploy trigger
112
+ * fires (each returning just `items`) with their pagination callbacks. The two type parameters
113
+ * — supplied explicitly to `batchTrigger<TItem, TPaginationState>(...)` — flow through to the
114
+ * rest of the flow: `TItem` types `onExecution`'s `params.onTrigger.results.body.data`, and
115
+ * `TPaginationState` types `payload.discoveryState` and the pagination callbacks' return.
116
+ */
117
+ export interface BatchTrigger<TItem, TPaginationState extends Record<string, unknown> = Record<string, unknown>> {
118
+ /**
119
+ * The trigger function for this flow. Fetches a page of records and returns them as `items`.
120
+ * Re-invoked once per pagination round (see `getNextOnTriggerPaginationState`); read the
121
+ * cursor for the current page from `payload.discoveryState`.
122
+ */
123
+ onTrigger: (context: ActionContext<ConfigVars>, payload: TriggerPayload<TPaginationState>) => Promise<BatchedTriggerReturn<TItem>>;
124
+ /**
125
+ * The on-deploy trigger fire, run once on initial instance deploy. Same shape as `onTrigger`;
126
+ * pair with `getNextOnDeployPaginationState` to paginate.
127
+ */
128
+ onDeploy?: (context: ActionContext<ConfigVars>, payload: TriggerPayload<TPaginationState>) => Promise<BatchedTriggerReturn<TItem>>;
129
+ /** Pagination for `onTrigger`: return the next page's state, or `null` to stop. */
130
+ getNextOnTriggerPaginationState?: BatchPaginationStateFunction<TPaginationState>;
131
+ /** Pagination for `onDeploy`: return the next page's state, or `null` to stop. */
132
+ getNextOnDeployPaginationState?: BatchPaginationStateFunction<TPaginationState>;
133
+ }
134
+ export type FlowOnExecution<TTriggerPayload extends TriggerPayload, TItem = unknown> = ActionPerformFunction<{
74
135
  onTrigger: {
75
136
  type: "data";
76
137
  label: string;
77
138
  clean: (value: unknown) => {
78
- results: TTriggerPayload;
139
+ results: BatchedTriggerPayload<TTriggerPayload, TItem>;
79
140
  };
80
141
  };
81
142
  }, ConfigVars, {
@@ -85,8 +146,56 @@ export type FlowExecutionContext = ActionContext<ConfigVars, {
85
146
  [Key in keyof ComponentRegistry]: ComponentRegistry[Key]["actions"];
86
147
  }>;
87
148
  export type FlowExecutionContextActions = FlowExecutionContext["components"];
149
+ /**
150
+ * The batch-discriminated fields of a flow. A flow either batches or it does not, and
151
+ * the presence of `batchConfig` is the discriminant TypeScript uses to choose a member:
152
+ *
153
+ * - {@link BatchFields}: `batchConfig` is present, which requires a batched `trigger`
154
+ * (built with {@link batchFlowTrigger}). The flat `onTrigger`/`onDeployTrigger` are
155
+ * forbidden — the trigger fires live inside the `trigger` object.
156
+ * - {@link NonBatchFields}: `batchConfig`/`trigger` are absent; the flow uses the plain
157
+ * `onTrigger`/`onDeployTrigger` on its variant.
158
+ *
159
+ * Discrimination is structural — it depends only on whether the object literal you write
160
+ * has a `batchConfig` key — so it works without TypeScript having to infer any type
161
+ * parameter from the value. The batched-vs-not shape of `onExecution`'s payload is handled
162
+ * separately, on `FlowBase`, via `TItem`: when a `trigger` is present `TItem` is inferred
163
+ * (so `onExecution` sees `TItem | TItem[]`); otherwise it stays `unknown` and the payload
164
+ * is left untouched (see {@link BatchedTriggerPayload}). Keeping `onExecution` out of this
165
+ * union is deliberate — a function property living in a union member loses contextual
166
+ * parameter typing, which would make `onExecution`'s `context`/`params` implicitly `any`.
167
+ */
168
+ interface BatchFields<TItem, TDiscoveryState extends Record<string, unknown>> {
169
+ /**
170
+ * Batch-dispatch config for this flow. Items returned by the `trigger`'s fires are chunked
171
+ * into batches of `batchSize`. For a CNI flow this value is authoritative (what's written
172
+ * here is what's used). Its presence requires a batched `trigger`.
173
+ */
174
+ batchConfig: BatchConfig;
175
+ /**
176
+ * The batched trigger for this flow, built with {@link batchFlowTrigger}. Its fires
177
+ * (`onTrigger`/`onDeploy`) return just `items`; spectral synthesizes the resolver that
178
+ * extracts them and maps the pagination callbacks. Required when `batchConfig` is set.
179
+ */
180
+ trigger: BatchTrigger<TItem, TDiscoveryState>;
181
+ /** A batched flow's trigger fires live inside `trigger`; the flat `onTrigger` is forbidden. */
182
+ onTrigger?: never;
183
+ /** A batched flow's on-deploy fire lives inside `trigger`; the flat `onDeployTrigger` is forbidden. */
184
+ onDeployTrigger?: never;
185
+ }
186
+ interface NonBatchFields {
187
+ /** A non-batching flow may not declare batch config. */
188
+ batchConfig?: never;
189
+ /** A non-batching flow may not declare a batched trigger. */
190
+ trigger?: never;
191
+ }
192
+ /**
193
+ * The discriminated union coupling `batchConfig` and the batched `trigger`. Intersected
194
+ * into each flow variant at {@link Flow}.
195
+ */
196
+ type BatchDiscriminant<TItem, TDiscoveryState extends Record<string, unknown>> = BatchFields<TItem, TDiscoveryState> | NonBatchFields;
88
197
  /** Base properties shared by all flow types. */
89
- interface FlowBase<TTriggerPayload extends TriggerPayload = TriggerPayload> {
198
+ interface FlowBase<TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown> {
90
199
  /** The unique name for this flow. */
91
200
  name: string;
92
201
  /** A unique, unchanging value that is used to maintain identity for the flow even if the name changes. */
@@ -143,23 +252,33 @@ interface FlowBase<TTriggerPayload extends TriggerPayload = TriggerPayload> {
143
252
  /** Function to execute for webhook teardown. */
144
253
  delete: TriggerEventFunction<Inputs, ConfigVars>;
145
254
  };
146
- /** Specifies the main function for this flow which is run when this flow is invoked. */
147
- onExecution: FlowOnExecution<TTriggerPayload>;
255
+ /**
256
+ * Specifies the main function for this flow which is run when this flow is invoked.
257
+ * When the flow batches (has a `triggerResolver`/`onDeployResolver`, so `TItem` is
258
+ * inferred), `params.onTrigger.results.body.data` is typed as the resolved item type
259
+ * (`TItem | TItem[]`); otherwise the trigger payload is left untouched.
260
+ */
261
+ onExecution: FlowOnExecution<TTriggerPayload, TItem>;
148
262
  }
149
263
  export type StandardTriggerType = "standard";
150
264
  /** A standard flow with a webhook or scheduled trigger (non-polling). */
151
- interface StandardFlow<TInputs extends Inputs = Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = false, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload> extends FlowBase<TTriggerPayload> {
265
+ interface StandardFlow<TInputs extends Inputs = Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = false, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> extends FlowBase<TTriggerPayload, TItem> {
152
266
  triggerType?: StandardTriggerType;
153
267
  /** Schedule configuration that defines the frequency with which this flow will be automatically executed. */
154
268
  schedule?: (ValueExpression<string> | ConfigVarExpression) & {
155
269
  timezone?: string;
156
270
  };
157
271
  /** Specifies the trigger function for this flow, which returns a payload and optional HTTP response. */
158
- onTrigger?: TriggerReference | TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult>;
272
+ onTrigger?: TriggerReference | TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult, TDiscoveryState>;
273
+ /**
274
+ * Function to execute on initial instance deploy, in addition to (and independent of) `onTrigger`.
275
+ * Typically used to backfill baseline records for systems whose webhooks only emit future events.
276
+ */
277
+ onDeployTrigger?: TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult, TDiscoveryState>;
159
278
  }
160
279
  export type PollingTriggerType = "polling";
161
280
  /** A polling flow that runs on a schedule and has access to polling context (getState/setState). */
162
- interface PollingFlow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload> extends FlowBase<TTriggerPayload> {
281
+ interface PollingFlow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> extends FlowBase<TTriggerPayload, TItem> {
163
282
  /**
164
283
  * Type of trigger for this flow. A "polling" trigger runs on a schedule
165
284
  * and can use context.polling.* functions. Requires schedule to be set.
@@ -173,9 +292,14 @@ interface PollingFlow<TInputs extends Inputs, TActionInputs extends Inputs, TPay
173
292
  * Specifies the trigger function for this flow.
174
293
  */
175
294
  onTrigger: PollingTriggerPerformFunction<TInputs, TActionInputs, ConfigVars, TPayload, TAllowsBranching, TResult>;
295
+ /**
296
+ * Function to execute on initial instance deploy, in addition to (and independent of) `onTrigger`.
297
+ * Typically used to backfill baseline records for systems whose webhooks only emit future events.
298
+ */
299
+ onDeployTrigger?: TriggerPerformFunction<TInputs, ConfigVars, TAllowsBranching, TResult, TDiscoveryState>;
176
300
  }
177
301
  /** Defines attributes of a flow of a code-native integration. */
178
- export type Flow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload> = StandardFlow<TInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload> | PollingFlow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload>;
302
+ export type Flow<TInputs extends Inputs, TActionInputs extends Inputs, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TTriggerPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> = (StandardFlow<TInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload, TItem, TDiscoveryState> & BatchDiscriminant<TItem, TDiscoveryState>) | (PollingFlow<TInputs, TActionInputs, TPayload, TAllowsBranching, TResult, TTriggerPayload, TItem, TDiscoveryState> & BatchDiscriminant<TItem, TDiscoveryState>);
179
303
  export type FlowTriggerType = PollingTriggerType | StandardTriggerType;
180
304
  /** Defines attributes of a Preprocess flow Configuration used by a flow of an integration. */
181
305
  export type PreprocessFlowConfig = {
@@ -4,6 +4,7 @@ import type { ActionContext } from "./ActionPerformFunction";
4
4
  import type { ActionPerformReturn } from "./ActionPerformReturn";
5
5
  import type { ActionDisplayDefinition } from "./DisplayDefinition";
6
6
  import type { ConfigVarResultCollection, Inputs } from "./Inputs";
7
+ import type { BatchConfig, OnDeployDecl, TriggerResolverDecl } from "./TriggerDefinition";
7
8
  import type { TriggerEventFunction } from "./TriggerEventFunction";
8
9
  import type { TriggerPayload } from "./TriggerPayload";
9
10
  import type { TriggerResult } from "./TriggerResult";
@@ -18,11 +19,21 @@ export type PollingTriggerPerformFunction<TInputs extends Inputs, TActionInputs
18
19
  /**
19
20
  * PollingTriggerDefinition is the type of the object that is passed in to `pollingTrigger` function to
20
21
  * define a component trigger.
22
+ *
23
+ * Composed from `PollingTriggerDefinitionBase` plus `TriggerResolverDecl` (resolver support)
24
+ * and `OnDeployDecl` (the on-deploy perform/resolver relationship), enforced at the type level.
21
25
  */
22
- export interface PollingTriggerDefinition<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TActionInputs extends Inputs = Inputs, TAction extends ActionDefinition<TActionInputs> = ActionDefinition<TActionInputs>, TCombinedInputs extends TInputs & TActionInputs = TInputs & TActionInputs> {
26
+ export type PollingTriggerDefinition<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TActionInputs extends Inputs = Inputs, TAction extends ActionDefinition<TActionInputs> = ActionDefinition<TActionInputs>, TCombinedInputs extends TInputs & TActionInputs = TInputs & TActionInputs> = PollingTriggerDefinitionBase<TInputs, TConfigVars, TPayload, TAllowsBranching, TResult, TActionInputs, TAction, TCombinedInputs> & TriggerResolverDecl<TConfigVars, TPayload> & OnDeployDecl<TInputs, TConfigVars, TPayload, TAllowsBranching, TResult>;
27
+ interface PollingTriggerDefinitionBase<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>, TActionInputs extends Inputs = Inputs, TAction extends ActionDefinition<TActionInputs> = ActionDefinition<TActionInputs>, TCombinedInputs extends TInputs & TActionInputs = TInputs & TActionInputs> {
23
28
  triggerType?: "polling";
24
29
  /** Defines how the Action is displayed in the Prismatic interface. */
25
30
  display: ActionDisplayDefinition;
31
+ /**
32
+ * Default batch-dispatch config shared by `triggerResolver` and `onDeployResolver`.
33
+ * Required when this trigger declares either (a `triggerResolver` with
34
+ * `triggerResolverSupport` `"valid"`/`"required"`, or an `onDeployResolver`).
35
+ */
36
+ batchConfig?: BatchConfig;
26
37
  /** Defines your trigger's polling behavior. */
27
38
  pollAction?: TAction;
28
39
  /** Function to perform when this Trigger is invoked. A default perform will be provided for most polling triggers but defining this allows for custom behavior. */
@@ -39,3 +50,4 @@ export interface PollingTriggerDefinition<TInputs extends Inputs = Inputs, TConf
39
50
  examplePayload?: Awaited<ReturnType<this["perform"]>>;
40
51
  }
41
52
  export declare const isPollingTriggerDefinition: (ref: unknown) => ref is PollingTriggerDefinition;
53
+ export {};
@@ -1,22 +1,119 @@
1
+ import type { ActionContext } from "./ActionPerformFunction";
1
2
  import type { ActionDisplayDefinition } from "./DisplayDefinition";
2
3
  import type { ConfigVarResultCollection, Inputs } from "./Inputs";
3
4
  import type { TriggerEventFunction } from "./TriggerEventFunction";
4
5
  import type { TriggerPayload } from "./TriggerPayload";
5
6
  import type { TriggerPerformFunction } from "./TriggerPerformFunction";
6
- import type { TriggerResult } from "./TriggerResult";
7
+ import type { TriggerBaseResult, TriggerResult } from "./TriggerResult";
8
+ /**
9
+ * Encodes the relationship between `triggerResolverSupport` and `triggerResolver`:
10
+ * - absent or `"invalid"`: no resolver allowed
11
+ * - `"valid"`: resolver optional
12
+ * - `"required"`: resolver required
13
+ *
14
+ * `triggerResolver` is the resolver *behavior* only; batch sizing comes from the
15
+ * trigger's shared `batchConfig` (see `TriggerDefinition`).
16
+ */
17
+ export type TriggerResolverDecl<TConfigVars extends ConfigVarResultCollection, TPayload extends TriggerPayload, TItem = unknown, TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> = {
18
+ triggerResolverSupport?: "invalid" | undefined;
19
+ triggerResolver?: undefined;
20
+ } | {
21
+ triggerResolverSupport: "valid";
22
+ triggerResolver?: TriggerResolverBehavior<TConfigVars, TPayload, TItem, TDiscoveryState>;
23
+ } | {
24
+ triggerResolverSupport: "required";
25
+ triggerResolver: TriggerResolverBehavior<TConfigVars, TPayload, TItem, TDiscoveryState>;
26
+ };
27
+ /**
28
+ * Encodes the relationship between `onDeployPerform` and `onDeployResolver`. On-deploy is
29
+ * presence-driven — there is no separate support flag: a trigger fires on deploy if it
30
+ * defines `onDeployPerform`, and batches that fire if it also defines an `onDeployResolver`.
31
+ * An `onDeployResolver` therefore requires an `onDeployPerform`.
32
+ *
33
+ * `onDeployPerform` is the component-trigger sibling to `perform`. A CNI flow names the
34
+ * same on-deploy fire `onDeployTrigger` (sibling to its `onTrigger`); both flatten to
35
+ * `onDeployPerform` on the wire.
36
+ */
37
+ export type OnDeployDecl<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TPayload extends TriggerPayload, TAllowsBranching extends boolean, TResult extends TriggerResult<TAllowsBranching, TPayload>, TItem = unknown, TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> = {
38
+ onDeployPerform?: undefined;
39
+ onDeployResolver?: undefined;
40
+ } | {
41
+ onDeployPerform: TriggerPerformFunction<TInputs, TConfigVars, TAllowsBranching, TResult>;
42
+ onDeployResolver?: TriggerResolverBehavior<TConfigVars, TPayload, TItem, TDiscoveryState>;
43
+ };
7
44
  declare const optionChoices: readonly ["invalid", "valid", "required"];
8
45
  export type TriggerOptionChoice = (typeof optionChoices)[number];
9
46
  export declare const TriggerOptionChoices: TriggerOptionChoice[];
47
+ /**
48
+ * The batching/pagination behavior shared by every resolver surface — component
49
+ * triggers (`TriggerResolver`), CNI flows (`TriggerResolverConfig`), and the
50
+ * on-deploy variants. Defining it once keeps the contract from drifting across
51
+ * those surfaces.
52
+ *
53
+ * The two type variables ARE the data that flows through the batch chain:
54
+ *
55
+ * perform ──▶ resolveItems ──▶ [batch of TItem] ──▶ onExecution
56
+ * │
57
+ * └─ getNextDiscoveryState ──▶ payload.discoveryState ──▶ next perform
58
+ *
59
+ * @typeParam TItem - element produced by `resolveItems`. With `batchSize: 1`
60
+ * each execution receives one `TItem` as its trigger data; with `batchSize > 1`
61
+ * it receives a `TItem[]` slice.
62
+ * @typeParam TDiscoveryState - the pagination cursor. Whatever
63
+ * `getNextDiscoveryState` returns is what the next round reads back on
64
+ * `payload.discoveryState` (see {@link TriggerPayload}). The `result.payload`
65
+ * passed to both callbacks has its `discoveryState` narrowed to this type, so
66
+ * the cursor round-trip is checked end to end.
67
+ */
68
+ export interface TriggerResolverBehavior<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TItem = unknown, TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> {
69
+ /** Extracts the items to dispatch from one trigger result. Receives the same context as the trigger's perform function. With `batchSize: 1` each item is delivered to its own execution; with `batchSize > 1` items are grouped into `TItem[]` slices. */
70
+ resolveItems?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<WithDiscoveryState<TPayload, TDiscoveryState>>) => TItem[];
71
+ /** Returns the cursor for the next page, or `null` to stop. A non-null return re-invokes the trigger with this object stamped onto `payload.discoveryState`. */
72
+ getNextDiscoveryState?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<WithDiscoveryState<TPayload, TDiscoveryState>>) => TDiscoveryState | null;
73
+ }
74
+ /**
75
+ * A trigger payload with its `discoveryState` field narrowed to `TDiscoveryState`,
76
+ * leaving every other field of `TPayload` intact. Lets a resolver type the cursor
77
+ * it reads back independently of how the base payload was parameterized.
78
+ */
79
+ export type WithDiscoveryState<TPayload extends TriggerPayload, TDiscoveryState extends Record<string, unknown>> = Omit<TPayload, "discoveryState"> & {
80
+ discoveryState?: TDiscoveryState;
81
+ };
82
+ /**
83
+ * The single batch-dispatch config shared by a trigger's `triggerResolver` and
84
+ * `onDeployResolver` — they always batch the same way. One place for batch settings.
85
+ *
86
+ * On a CNI flow (`flow.batchConfig`) this value is authoritative. On a component trigger
87
+ * (`TriggerDefinition.batchConfig`) it's the default the platform seeds, which a low-code
88
+ * user may override per instance.
89
+ */
90
+ export interface BatchConfig {
91
+ /** Number of items per batch. Must be an integer >= 1. `1` dispatches each item individually; `>1` groups items into batches. */
92
+ batchSize: number;
93
+ /** Max batches of a single execution dispatched concurrently. Must be an integer >= 1 when set. Omit for unlimited. */
94
+ concurrentBatchLimit?: number;
95
+ }
10
96
  /**
11
97
  * TriggerDefinition is the type of the object that is passed in to `trigger` function to
12
98
  * define a component trigger. See
13
99
  * https://prismatic.io/docs/custom-connectors/triggers/
100
+ *
101
+ * Composed from `TriggerDefinitionBase` (static fields) plus `TriggerResolverDecl` (the
102
+ * resolver support relationship) and `OnDeployDecl` (the on-deploy perform/resolver
103
+ * relationship), which enforce those constraints at the type level.
14
104
  */
15
- export interface TriggerDefinition<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TriggerPayload> = TriggerResult<TAllowsBranching, TriggerPayload>> {
105
+ export type TriggerDefinition<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TriggerPayload> = TriggerResult<TAllowsBranching, TriggerPayload>> = TriggerDefinitionBase<TInputs, TConfigVars, TAllowsBranching, TResult> & TriggerResolverDecl<TConfigVars, TriggerPayload> & OnDeployDecl<TInputs, TConfigVars, TriggerPayload, TAllowsBranching, TResult>;
106
+ interface TriggerDefinitionBase<TInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TriggerPayload> = TriggerResult<TAllowsBranching, TriggerPayload>> {
16
107
  /** Defines how the trigger is displayed in the Prismatic UI. */
17
108
  display: ActionDisplayDefinition;
18
109
  /** Function to perform when this trigger is invoked. */
19
110
  perform: TriggerPerformFunction<TInputs, TConfigVars, TAllowsBranching, TResult>;
111
+ /**
112
+ * Default batch-dispatch config shared by `triggerResolver` and `onDeployResolver`.
113
+ * Required when this trigger declares either (a `triggerResolver` with
114
+ * `triggerResolverSupport` `"valid"`/`"required"`, or an `onDeployResolver`).
115
+ */
116
+ batchConfig?: BatchConfig;
20
117
  /**
21
118
  * Function to execute when an instance of an integration with a flow that uses this trigger is deployed. See
22
119
  * https://prismatic.io/docs/custom-connectors/triggers/#instance-deploy-and-delete-events-for-triggers
@@ -3,8 +3,13 @@ import type { FlowAttributes } from "./FlowAttributes";
3
3
  import type { InstanceAttributes } from "./InstanceAttributes";
4
4
  import type { IntegrationAttributes } from "./IntegrationAttributes";
5
5
  import type { UserAttributes } from "./UserAttributes";
6
- /** Represents a Trigger Payload, which is data passed into a Trigger to invoke an Integration execution. */
7
- export interface TriggerPayload {
6
+ /** Represents a Trigger Payload, which is data passed into a Trigger to invoke an Integration execution.
7
+ *
8
+ * The optional `TDiscoveryState` parameter types the `discoveryState` field, so authors who
9
+ * declare a pagination-state shape on their `getNextDiscoveryState` resolver can read back
10
+ * the same shape on the next round's payload. Defaults to `Record<string, unknown>`.
11
+ */
12
+ export interface TriggerPayload<TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> {
8
13
  /** The headers sent in the webhook request. */
9
14
  headers: {
10
15
  [key: string]: string;
@@ -50,4 +55,8 @@ export interface TriggerPayload {
50
55
  startedAt: string;
51
56
  /** Determines whether the execution will run in debug mode. */
52
57
  globalDebug: boolean;
58
+ /** Managed by the execution when this trigger invocation is a paginated re-run.
59
+ * Contains the object returned by `getNextDiscoveryState` from the previous round.
60
+ * Absent on the initial invocation. */
61
+ discoveryState?: TDiscoveryState;
53
62
  }
@@ -4,4 +4,4 @@ import type { ConfigVarResultCollection, Inputs } from "./Inputs";
4
4
  import type { TriggerPayload } from "./TriggerPayload";
5
5
  import type { TriggerResult } from "./TriggerResult";
6
6
  /** Definition of the function to perform when a Trigger is invoked. */
7
- export type TriggerPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean | undefined, TResult extends TriggerResult<TAllowsBranching, TriggerPayload>> = (context: ActionContext<TConfigVars>, payload: TriggerPayload, params: ActionInputParameters<TInputs>) => Promise<TResult>;
7
+ export type TriggerPerformFunction<TInputs extends Inputs, TConfigVars extends ConfigVarResultCollection, TAllowsBranching extends boolean | undefined, TResult extends TriggerResult<TAllowsBranching, TriggerPayload>, TDiscoveryState extends Record<string, unknown> = Record<string, unknown>> = (context: ActionContext<TConfigVars>, payload: TriggerPayload<TDiscoveryState>, params: ActionInputParameters<TInputs>) => Promise<TResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "10.18.7",
3
+ "version": "10.18.9-preview.0",
4
4
  "description": "Utility library for building Prismatic connectors and code-native integrations",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -44,8 +44,8 @@
44
44
  "dependencies": {
45
45
  "axios": "^1.16.1",
46
46
  "axios-retry": "^4.5.0",
47
- "date-fns": "^4.1.0",
48
- "ejs": "^5.0.2",
47
+ "date-fns": "^4.4.0",
48
+ "ejs": "^6.0.1",
49
49
  "form-data": "^4.0.5",
50
50
  "fs-extra": "^11.3.5",
51
51
  "jest-mock": "^30.4.1",
@@ -62,14 +62,14 @@
62
62
  "@types/ejs": "3.1.5",
63
63
  "@types/fs-extra": "11.0.4",
64
64
  "@types/lodash": "^4.17.24",
65
- "@types/node": "^25.7.0",
65
+ "@types/node": "^25.9.1",
66
66
  "@types/prettier": "^3.0.0",
67
67
  "@types/sax": "^1.2.7",
68
68
  "@types/valid-url": "^1.0.7",
69
- "@vitest/ui": "^4.1.6",
69
+ "@vitest/ui": "^4.1.8",
70
70
  "copyfiles": "2.4.1",
71
71
  "fast-check": "^4.8.0",
72
72
  "typescript": "6.0.3",
73
- "vitest": "^4.1.6"
73
+ "vitest": "^4.1.8"
74
74
  }
75
75
  }