@polarityio/integration-types 3.1.0 → 3.2.2

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/dist/context.d.ts CHANGED
@@ -264,7 +264,9 @@ export interface IntegrationContext {
264
264
  /**
265
265
  * Starts a named poller that was defined in the integration's `poll` export.
266
266
  *
267
- * If the poller is already running, this call is a no-op.
267
+ * Acts only on the pod (Polarity server instance) that handles this call: other
268
+ * pods keep their own pollers as they are. If the poller is already scheduled on
269
+ * this pod, for example because it has `autostart: true`, this call is a no-op.
268
270
  *
269
271
  * @param pollName - The key from the integration's `poll` record identifying
270
272
  * which poller to start.
@@ -272,9 +274,9 @@ export interface IntegrationContext {
272
274
  * immediately before the first scheduled interval or cron tick. When `false`,
273
275
  * the first execution waits for the next scheduled tick.
274
276
  *
275
- * @example Start a poller and fire immediately
277
+ * @example Start a poller defined with `autostart: false`, and fire immediately
276
278
  * ```typescript
277
- * context.startPolling('refreshTokens');
279
+ * context.startPolling('backfill');
278
280
  * ```
279
281
  *
280
282
  * @example Start a poller but wait for the first scheduled tick
@@ -286,15 +288,17 @@ export interface IntegrationContext {
286
288
  /**
287
289
  * Stops a named poller that is currently running.
288
290
  *
289
- * If the poller is not running, this call is a no-op. A stopped poller can be
290
- * restarted later via `startPolling()`.
291
+ * Acts only on the pod (Polarity server instance) that handles this call: other
292
+ * pods keep polling, and every pod starts its `autostart` pollers again the next
293
+ * time the integration loads. If the poller is not running, this call is a no-op.
294
+ * A stopped poller can be restarted later via `startPolling()`.
291
295
  *
292
296
  * @param pollName - The key from the integration's `poll` record identifying
293
297
  * which poller to stop.
294
298
  *
295
299
  * @example
296
300
  * ```typescript
297
- * context.stopPolling('refreshTokens');
301
+ * context.stopPolling('refreshFeed');
298
302
  * ```
299
303
  */
300
304
  stopPolling: (pollName: string) => void;
package/dist/entity.d.ts CHANGED
@@ -8,7 +8,7 @@ export interface Channel {
8
8
  /**
9
9
  * List of supported standard entity type values.
10
10
  */
11
- export type StandardEntityType = 'IPv4' | 'IPv4CIDR' | 'IPv6' | 'MAC' | 'MD5' | 'SHA1' | 'SHA256' | 'cve' | 'domain' | 'email' | 'string' | 'url';
11
+ export type StandardEntityType = 'IPv4' | 'IPv4CIDR' | 'IPv6' | 'MAC' | 'MD5' | 'SHA1' | 'SHA256' | 'cve' | 'domain' | 'email' | 'string' | 'threat_actor' | 'url';
12
12
  /**
13
13
  * Entity types including custom types.
14
14
  *
@@ -20,8 +20,8 @@ export type EntityType = StandardEntityType | 'IP' | 'hash' | `custom.${string}`
20
20
  *
21
21
  * This includes every {@link StandardEntityType} value (`'IPv4'`, `'IPv4CIDR'`,
22
22
  * `'IPv6'`, `'MAC'`, `'MD5'`, `'SHA1'`, `'SHA256'`, `'cve'`, `'domain'`,
23
- * `'email'`, `'string'`, `'url'`), plus `'hash'` for any hash type and
24
- * `'custom'` for custom entity types.
23
+ * `'email'`, `'string'`, `'threat_actor'`, `'url'`), plus `'hash'` for any hash
24
+ * type and `'custom'` for custom entity types.
25
25
  */
26
26
  export type EntityTypeIdentifier = StandardEntityType | 'hash' | 'custom';
27
27
  /**
package/dist/limiter.d.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  /**
2
- * Strategy for handling jobs when `highWater` is reached.
3
- * - `1` (LEAK) — Drop the oldest job in the queue.
4
- * - `2` (OVERFLOW_PRIORITY) — Drop the lowest-priority job.
5
- * - `3` (OVERFLOW) — Drop the incoming job (reject it immediately).
6
- * - `4` (BLOCK) — Block until a slot opens.
2
+ * Strategy for handling jobs when `highWater` is reached (Bottleneck's numbering).
3
+ * Priority runs from 0 (highest) to 9 (lowest); see {@link ScheduleOptions.priority}.
4
+ * - `1` (LEAK) — Drop the oldest job of the lowest priority queued, among jobs with
5
+ * the same or a lower priority than the incoming one. If every queued job has a
6
+ * higher priority, the incoming job is dropped instead.
7
+ * - `2` (OVERFLOW) — Drop the incoming job (reject it immediately). The platform default.
8
+ * - `3` (BLOCK) — Drop every queued job and reject new ones until the penalty
9
+ * period has passed with no new jobs. The penalty defaults to 15 × `minTime`
10
+ * (1.5 s with the platform's `minTime` of 100), or 5 s when `minTime` is 0.
11
+ * - `4` (OVERFLOW_PRIORITY) — Like LEAK, but only among jobs with a strictly lower
12
+ * priority than the incoming one. If there is none, the incoming job is dropped
13
+ * instead, so a job never displaces one of equal priority.
7
14
  */
8
15
  export type ThrottleStrategy = 1 | 2 | 3 | 4;
9
16
  /**
@@ -11,13 +18,17 @@ export type ThrottleStrategy = 1 | 2 | 3 | 4;
11
18
  * job priority and identification within the throttle queue.
12
19
  */
13
20
  export interface ScheduleOptions {
14
- /** Priority of the job (1 = highest, 9 = lowest). Default is 5. */
21
+ /** Priority of the job (0 = highest, 9 = lowest). Default is 5. */
15
22
  priority?: number;
16
23
  /** Optional identifier for the scheduled job (useful for debugging). */
17
24
  id?: string;
18
25
  /** Weight of the job against the `maxConcurrent` limit. Default is 1. */
19
26
  weight?: number;
20
- /** Maximum time (ms) a job can stay in the queue before being dropped. */
27
+ /**
28
+ * Maximum time (ms) a job may **run** once it has started. A job still running
29
+ * after this time is failed with a `BottleneckError`. It does not limit time spent
30
+ * waiting in the queue: Bottleneck cannot remove a queued job.
31
+ */
21
32
  expiration?: number | null;
22
33
  }
23
34
  /**
@@ -57,12 +68,9 @@ export interface ThrottleSettings {
57
68
  */
58
69
  highWater?: number;
59
70
  /**
60
- * Strategy for handling jobs when `highWater` is reached.
61
- * - `1` (LEAK): Drop the oldest job in the queue.
62
- * - `2` (OVERFLOW_PRIORITY): Drop the lowest-priority job.
63
- * - `3` (OVERFLOW): Drop the incoming job (reject it immediately).
64
- * - `4` (BLOCK): Block until a slot opens.
65
- * @default 3 (OVERFLOW)
71
+ * Strategy for handling jobs when `highWater` is reached: `1` LEAK, `2` OVERFLOW,
72
+ * `3` BLOCK or `4` OVERFLOW_PRIORITY. See {@link ThrottleStrategy} for what each does.
73
+ * @default 2 (OVERFLOW)
66
74
  */
67
75
  strategy?: ThrottleStrategy;
68
76
  /**
package/dist/polling.d.ts CHANGED
@@ -9,15 +9,19 @@ import type { IntegrationContext } from './context';
9
9
  *
10
10
  * ### Execution Model
11
11
  *
12
- * Poll functions run in a **dedicated polling worker** that is separate from the
13
- * integration workers handling `doLookup`, `onMessage`, and `onDetails` dispatches.
14
- * Each poll function executes **once per integration** — not once per worker instance.
15
- * This means poll functions are singletons: even if multiple integration workers are
16
- * running, only one instance of each poller is active at any time.
12
+ * Each poller is scheduled **once per Polarity server instance (pod)**, not once per
13
+ * integration worker. When several pods run, each pod runs its own copy of every
14
+ * poller, on its own schedule. During a rolling deploy, the old and new pods both run
15
+ * it for a short time. Poll functions must therefore be safe to run concurrently on
16
+ * different pods (for example, idempotent writes to `context.cache`).
17
17
  *
18
- * Because the polling worker is isolated, poll functions do not share in-memory state
19
- * with integration dispatch workers. Use `context.cache` to exchange data between
20
- * poll functions and dispatch handlers.
18
+ * Each run checks out a worker from the same pool that serves `doLookup`, `onMessage`
19
+ * and `onDetails`, and holds it until the run finishes. A long poll reduces the
20
+ * capacity available for lookups, so keep runs short and set `timeout` on the spec
21
+ * (interval or cron) for heavy work.
22
+ *
23
+ * Poll functions do not share in-memory state with dispatch handlers. Use
24
+ * `context.cache` (or local storage) to exchange data between them.
21
25
  *
22
26
  * @param options - Admin-only (global) user options for the integration.
23
27
  * @param context - The integration context providing cache, logger, limiter, and network utilities.
@@ -26,12 +30,26 @@ export type PollFunction = (options: DoLookupUserOptions, context: IntegrationCo
26
30
  /**
27
31
  * Strategy the runtime uses when a poll function throws an unhandled error.
28
32
  *
29
- * - `'retry'` — The runtime catches the error and retries the poll function on
30
- * the next scheduled tick. Useful for transient failures (e.g., network timeouts).
33
+ * Always set `failureStrategy` explicitly: the default, `'retry'`, suits few polls.
34
+ *
35
+ * - `'retry'` (the default) — The runtime retries the failed run with a linear
36
+ * backoff (2 s, 4 s, 6 s, …) and returns to the normal schedule once a run
37
+ * succeeds. There is no retry limit, so a persistent failure (invalid
38
+ * credentials, an unreachable host) keeps retrying instead of waiting for the next
39
+ * scheduled run. A run that exceeds its `timeout` counts as a failure, so a poll
40
+ * that always runs too long holds a worker for its full timeout on every attempt.
41
+ * The one exception: when no worker is free, the runtime gives up after 5
42
+ * attempts and waits for the next scheduled run. A poll with no next run
43
+ * (`runImmediately: true` with `autostart: false`) then does not run again, and
44
+ * no error is shown. Use `'retry'` only for work that is expected to succeed on a
45
+ * later attempt, such as the one-time initialization shown on {@link Poll}.
31
46
  * - `'shutdown'` — The runtime stops the integration entirely and surfaces the
32
47
  * error to the Polarity frontend. Use for unrecoverable failures where continued
33
48
  * polling would be harmful.
34
- * - `'skip'` — The runtime logs the error and continues polling on its normal schedule (no retry is performed for the failed run). Use when individual poll failures are acceptable and polling should continue uninterrupted.
49
+ * - `'skip'` — The runtime records the error and continues polling on its normal
50
+ * schedule (no retry is performed for the failed run). The right choice for most
51
+ * recurring polls, such as refreshing a feed: a failed run keeps the current data
52
+ * and the next scheduled run tries again.
35
53
  */
36
54
  export type PollFailureStrategy = 'retry' | 'shutdown' | 'skip';
37
55
  /**
@@ -45,29 +63,33 @@ interface BasePollSpec {
45
63
  */
46
64
  function: PollFunction;
47
65
  /**
48
- * Whether to start this poller automatically when the integration is loaded
66
+ * Whether to schedule this poller automatically when the integration is loaded
49
67
  * by the runtime.
50
68
  *
51
- * - `true` — Polling begins immediately after the integration's `startup`
52
- * hook completes.
53
- * - `false` (default) — Polling does not begin until explicitly started via
54
- * `context.startPolling(pollName)`.
69
+ * - `true` — The poller is scheduled after the integration's `startup` hook
70
+ * completes.
71
+ * - `false` (default) — The poller is not scheduled until it is started via
72
+ * `context.startPolling(pollName)`. If `runImmediately` is `true`, it still
73
+ * runs once on load (see `runImmediately`).
55
74
  *
56
75
  * @default false
57
76
  */
58
77
  autostart?: boolean;
59
78
  /**
60
- * Whether to execute the poll function immediately when the poller starts,
61
- * before waiting for the first interval tick or cron trigger.
79
+ * Whether to run the poll function once when the integration loads, before the
80
+ * first interval tick or cron trigger.
62
81
  *
63
- * - `true` — The poll function fires once immediately on start, then
64
- * continues on its normal schedule.
65
- * - `false` (default) — The first execution occurs after the first
66
- * interval/cron tick.
82
+ * - `true` — The runtime runs the poll on load, whatever `autostart` is:
83
+ * - With `autostart: true`, it then continues on its schedule.
84
+ * - With `autostart: false`, it runs once and is **not scheduled** afterwards.
85
+ * It runs on a schedule only after `context.startPolling()` is called. Don't
86
+ * use this for one-time initialization: if the run fails for lack of a free
87
+ * worker, the poll does not run again. Use the pattern on {@link Poll}
88
+ * instead.
89
+ * - `false` (default) — The first run happens on the first interval or cron tick.
67
90
  *
68
- * This applies to automatic start (when `autostart` is `true`). When a poller
69
- * is started manually via `context.startPolling()`, the method's own
70
- * `runImmediately` parameter takes precedence over this spec-level value.
91
+ * When a poller is started manually via `context.startPolling()`, the method's
92
+ * own `runImmediately` parameter takes precedence over this spec-level value.
71
93
  *
72
94
  * @default false
73
95
  */
@@ -75,10 +97,30 @@ interface BasePollSpec {
75
97
  /**
76
98
  * Strategy to use when the poll function throws an unhandled error.
77
99
  *
100
+ * **Always set this explicitly.** For a recurring poll, such as refreshing a feed,
101
+ * set `'skip'`. See {@link PollFailureStrategy} for why the `'retry'` default suits
102
+ * few polls.
103
+ *
78
104
  * @default 'retry'
79
105
  * @see {@link PollFailureStrategy}
80
106
  */
81
107
  failureStrategy?: PollFailureStrategy;
108
+ /**
109
+ * Maximum run time for one invocation, in **seconds**.
110
+ *
111
+ * Poll functions often do heavy work (large downloads, database rebuilds) that
112
+ * takes longer than the standard request timeout, which applies when this is not
113
+ * set. Values above 300 seconds (5 minutes) are clamped to 300, because a running
114
+ * poll holds a worker from the shared pool. A value of 0 or less, or one that is not
115
+ * a number, is ignored and the standard request timeout applies.
116
+ *
117
+ * The timeout covers the whole poll function, not each HTTP request in it. A run
118
+ * that exceeds it counts as a failure and is handled by `failureStrategy` (see
119
+ * {@link PollFailureStrategy}). When a run times out, the runtime stops waiting,
120
+ * but requests the function started keep running until they settle, so give each
121
+ * request its own timeout too.
122
+ */
123
+ timeout?: number;
82
124
  }
83
125
  /**
84
126
  * A poll specification that runs on a fixed time interval.
@@ -90,11 +132,12 @@ interface BasePollSpec {
90
132
  * @example
91
133
  * ```typescript
92
134
  * const spec: IntervalPollSpec = {
93
- * function: doRefreshTokens,
94
- * interval: 60, // every 60 seconds
135
+ * function: refreshFeed,
136
+ * interval: 3600, // an hour after the previous run finished
95
137
  * autostart: true,
96
138
  * runImmediately: true, // fire once immediately on start
97
- * failureStrategy: 'retry'
139
+ * failureStrategy: 'skip',
140
+ * timeout: 300 // seconds
98
141
  * };
99
142
  * ```
100
143
  */
@@ -120,7 +163,7 @@ export interface IntervalPollSpec extends BasePollSpec {
120
163
  * const spec: CronPollSpec = {
121
164
  * function: doWeeklyReport,
122
165
  * cron: '0 9 * * 1', // every Monday at 09:00 UTC
123
- * failureStrategy: 'shutdown'
166
+ * failureStrategy: 'skip' // a failed report waits for next Monday
124
167
  * };
125
168
  * ```
126
169
  */
@@ -159,27 +202,29 @@ export type PollSpec = IntervalPollSpec | CronPollSpec;
159
202
  *
160
203
  * ### Runtime Behavior
161
204
  *
162
- * Pollers execute in a **dedicated polling worker** that is independent of the
163
- * integration workers handling lookup and message dispatches. Regardless of how
164
- * many integration worker instances are running, each poller runs exactly **once
165
- * per integration** — ensuring that scheduled tasks (e.g., token refresh, report
166
- * generation) are not duplicated across workers.
205
+ * Each poller runs **once per Polarity server instance (pod)**, regardless of how
206
+ * many integration workers that pod runs. With several pods, each pod runs its own
207
+ * copy, so a poller is not a cluster-wide singleton. `context.startPolling()` and
208
+ * `context.stopPolling()` act only on the pod that handles the call. See
209
+ * {@link PollFunction}.
167
210
  *
168
211
  * @example Basic polling configuration
169
212
  * ```typescript
170
213
  * import type { Poll } from '@polarityio/integration-types';
171
214
  *
172
215
  * const poll: Poll = {
173
- * refreshTokens: {
174
- * function: doRefreshTokens,
175
- * interval: 30, // every 30 seconds
216
+ * refreshFeed: {
217
+ * function: refreshFeed,
218
+ * interval: 3600, // an hour after the previous run finished
176
219
  * autostart: true,
177
- * runImmediately: true
220
+ * runImmediately: true,
221
+ * failureStrategy: 'skip',
222
+ * timeout: 300 // seconds
178
223
  * },
179
224
  * weeklyReport: {
180
225
  * function: doWeeklyReport,
181
226
  * cron: '0 9 * * 1', // Mondays at 09:00 UTC
182
- * failureStrategy: 'shutdown'
227
+ * failureStrategy: 'skip'
183
228
  * }
184
229
  * };
185
230
  *
@@ -188,10 +233,10 @@ export type PollSpec = IntervalPollSpec | CronPollSpec;
188
233
  *
189
234
  * @example One-time initialization pattern
190
235
  *
191
- * Because poll functions are singletons (one instance per integration), you can
192
- * use a poller with `runImmediately: true` and `autostart: true` to guarantee a
193
- * function runs exactly once across all integration workers. The function stops
194
- * itself after the first execution by calling `context.stopPolling()`.
236
+ * A poller with `runImmediately: true` and `autostart: true` that stops itself with
237
+ * `context.stopPolling()` runs once per pod each time the integration loads, not once
238
+ * across the deployment. With several pods, or after a restart, it runs again, so
239
+ * the work must be idempotent.
195
240
  *
196
241
  * ```typescript
197
242
  * import type { Poll, PollFunction } from '@polarityio/integration-types';
@@ -200,16 +245,17 @@ export type PollSpec = IntervalPollSpec | CronPollSpec;
200
245
  * // Perform one-time setup (e.g., seed cache, register webhooks)
201
246
  * await seedIntegrationCache(options, context);
202
247
  *
203
- * // Stop the poller — this function will never run again
248
+ * // Stop the poller on this pod
204
249
  * context.stopPolling('initialize');
205
250
  * };
206
251
  *
207
252
  * const poll: Poll = {
208
253
  * initialize: {
209
254
  * function: initializeOnce,
210
- * interval: 60, // interval is required but irrelevant here
255
+ * interval: 60, // retried a minute later if no worker was free
211
256
  * autostart: true,
212
- * runImmediately: true // fire immediately on integration load
257
+ * runImmediately: true, // fire immediately on integration load
258
+ * failureStrategy: 'retry' // retried until it succeeds
213
259
  * }
214
260
  * };
215
261
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polarityio/integration-types",
3
- "version": "3.1.0",
3
+ "version": "3.2.2",
4
4
  "description": "TypeScript type definitions for Polarity Integrations",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git+https://github.com/polarityio/integration-types.git"
26
+ "url": "git+https://github.com/DMCD-Integrations/integration-types.git"
27
27
  },
28
28
  "author": "Polarity IO <support@polarity.io>",
29
29
  "license": "MIT",
@@ -31,9 +31,9 @@
31
31
  "access": "public"
32
32
  },
33
33
  "bugs": {
34
- "url": "https://github.com/polarityio/integration-types/issues"
34
+ "url": "https://github.com/DMCD-Integrations/integration-types/issues"
35
35
  },
36
- "homepage": "https://github.com/polarityio/integration-types#readme",
36
+ "homepage": "https://github.com/DMCD-Integrations/integration-types#readme",
37
37
  "devDependencies": {
38
38
  "@eslint/js": "^10.0.1",
39
39
  "eslint": "^10.2.0",