@nangohq/runner-sdk 0.70.9 → 0.71.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,254 @@
1
+ /* eslint-disable @typescript-eslint/unbound-method */
2
+ import { describe, expect, expectTypeOf, it } from 'vitest';
3
+ import * as z from 'zod';
4
+ import { createFunction } from './function.js';
5
+ describe('createFunction', () => {
6
+ describe('schedule (sync)', () => {
7
+ it('computes capabilities and exposes records + checkpoint + metadata + proxy', () => {
8
+ const fn = createFunction({
9
+ description: 'Fetch issues from GitHub',
10
+ data: {
11
+ models: { GithubIssue: z.object({ id: z.string(), title: z.string() }) },
12
+ checkpoint: z.object({ lastId: z.string() }),
13
+ metadata: z.object({ org: z.string() })
14
+ },
15
+ trigger: { kind: 'schedule', frequency: 'every 2h', autoStart: true },
16
+ exec: async (nango, trigger) => {
17
+ await nango.batchSave([{ id: '1', title: 't' }], 'GithubIssue');
18
+ await nango.batchUpdate([{ id: '1', title: 't' }], 'GithubIssue');
19
+ await nango.batchDelete([{ id: '1', title: 't' }], 'GithubIssue');
20
+ await nango.trackDeletesStart('GithubIssue');
21
+ await nango.trackDeletesEnd('GithubIssue');
22
+ const cp = await nango.getCheckpoint();
23
+ await nango.saveCheckpoint({ lastId: '1' });
24
+ await nango.getMetadata();
25
+ expectTypeOf().toEqualTypeOf();
26
+ expectTypeOf(nango.batchSave).parameter(1).toEqualTypeOf();
27
+ expectTypeOf(cp).toEqualTypeOf();
28
+ expectTypeOf(nango.getMetadata()).toEqualTypeOf();
29
+ expectTypeOf(trigger.kind).toEqualTypeOf();
30
+ expectTypeOf(trigger.input).toEqualTypeOf();
31
+ }
32
+ });
33
+ expect(fn.type).toBe('function');
34
+ expect(fn.capabilities).toStrictEqual({
35
+ usesRecords: true,
36
+ usesCheckpoints: true,
37
+ usesMetadata: true,
38
+ usesOutbound: true,
39
+ usesInvoke: false
40
+ });
41
+ });
42
+ it('disallows a declared input on schedule and event triggers', () => {
43
+ createFunction({
44
+ description: 'schedule cannot declare input',
45
+ // @ts-expect-error schedule triggers carry no caller input
46
+ input: z.object({ since: z.string() }),
47
+ trigger: { kind: 'schedule', frequency: 'every hour' },
48
+ exec: (_nango, trigger) => {
49
+ expectTypeOf(trigger.input).toEqualTypeOf();
50
+ }
51
+ });
52
+ createFunction({
53
+ description: 'event cannot declare input',
54
+ // @ts-expect-error event triggers carry no caller input
55
+ input: z.object({ since: z.string() }),
56
+ trigger: { kind: 'event', events: ['pre-connection-deletion'] },
57
+ exec: (_nango, trigger) => {
58
+ expectTypeOf(trigger.input).toEqualTypeOf();
59
+ }
60
+ });
61
+ });
62
+ });
63
+ describe('http with models (webhook)', () => {
64
+ it('exposes record capability and types the http payload from the trigger input', () => {
65
+ const fn = createFunction({
66
+ description: 'Handle GitHub issue webhooks',
67
+ input: z.object({ action: z.string() }),
68
+ data: { models: { GithubIssue: z.object({ id: z.string() }) } },
69
+ trigger: { kind: 'http', subscriptions: ['issues.opened'] },
70
+ exec: async (nango, trigger) => {
71
+ await nango.batchSave([{ id: '1' }], 'GithubIssue');
72
+ expectTypeOf().toEqualTypeOf();
73
+ expectTypeOf(trigger.kind).toEqualTypeOf();
74
+ expectTypeOf(trigger.input).toEqualTypeOf();
75
+ expectTypeOf(trigger.request.headers).toEqualTypeOf();
76
+ }
77
+ });
78
+ expect(fn.capabilities).toStrictEqual({
79
+ usesRecords: true,
80
+ usesCheckpoints: false,
81
+ usesMetadata: false,
82
+ usesOutbound: true,
83
+ usesInvoke: false
84
+ });
85
+ });
86
+ it('types the input as an array when debounce take is "all"', () => {
87
+ createFunction({
88
+ description: 'Handle coalesced webhooks',
89
+ input: z.object({ action: z.string() }),
90
+ trigger: { kind: 'http', debounce: { windowMs: 5000, take: 'all' } },
91
+ exec: (_nango, trigger) => {
92
+ expectTypeOf(trigger.input).toEqualTypeOf();
93
+ }
94
+ });
95
+ createFunction({
96
+ description: 'Handle latest webhook',
97
+ input: z.object({ action: z.string() }),
98
+ trigger: { kind: 'http', debounce: { windowMs: 5000, take: 'latest' } },
99
+ exec: (_nango, trigger) => {
100
+ expectTypeOf(trigger.input).toEqualTypeOf();
101
+ }
102
+ });
103
+ });
104
+ });
105
+ describe('http without models (action)', () => {
106
+ it('has no record methods, types input and output', () => {
107
+ const fn = createFunction({
108
+ description: 'Create a GitHub issue',
109
+ input: z.object({ title: z.string() }),
110
+ output: z.object({ issueId: z.string() }),
111
+ trigger: { kind: 'http' },
112
+ exec: (_nango, trigger) => {
113
+ expectTypeOf().toEqualTypeOf();
114
+ expectTypeOf().toEqualTypeOf();
115
+ expectTypeOf(trigger.input).toEqualTypeOf();
116
+ return { issueId: '123' };
117
+ }
118
+ });
119
+ expect(fn.capabilities.usesRecords).toBe(false);
120
+ expect(fn.capabilities.usesOutbound).toBe(true);
121
+ });
122
+ });
123
+ describe('event', () => {
124
+ it('exposes the lifecycle event payload', () => {
125
+ const fn = createFunction({
126
+ description: 'Run before a connection is deleted',
127
+ trigger: { kind: 'event', events: ['pre-connection-deletion'] },
128
+ exec: async (nango, trigger) => {
129
+ await nango.log('executed');
130
+ expectTypeOf(trigger.kind).toEqualTypeOf();
131
+ expectTypeOf(trigger.input).toEqualTypeOf();
132
+ }
133
+ });
134
+ expect(fn.capabilities.usesRecords).toBe(false);
135
+ });
136
+ });
137
+ describe('requires', () => {
138
+ it('exposes invoke and removes proxy when requires disables it', () => {
139
+ const child = createFunction({
140
+ description: 'child',
141
+ input: z.object({ q: z.string() }),
142
+ output: z.object({ n: z.number() }),
143
+ exec: (_nango, trigger) => {
144
+ expectTypeOf(trigger.kind).toEqualTypeOf();
145
+ expectTypeOf(trigger.input).toEqualTypeOf();
146
+ return { n: 1 };
147
+ }
148
+ });
149
+ const fn = createFunction({
150
+ description: 'dispatcher',
151
+ requires: { outbound: false, invoke: true },
152
+ trigger: { kind: 'schedule', frequency: 'every hour' },
153
+ exec: async (nango) => {
154
+ expectTypeOf().toEqualTypeOf();
155
+ expectTypeOf().toEqualTypeOf();
156
+ const res = await nango.invoke(child, { input: { q: 'x' } });
157
+ expectTypeOf(res).toEqualTypeOf();
158
+ }
159
+ });
160
+ expect(fn.capabilities).toStrictEqual({
161
+ usesRecords: false,
162
+ usesCheckpoints: false,
163
+ usesMetadata: false,
164
+ usesOutbound: false,
165
+ usesInvoke: true
166
+ });
167
+ });
168
+ it('invoke types its input from the target, regardless of trigger kind', () => {
169
+ const httpFn = createFunction({
170
+ description: 'http target',
171
+ input: z.object({ title: z.string() }),
172
+ output: z.object({ ok: z.boolean() }),
173
+ trigger: { kind: 'http', debounce: { windowMs: 1000, take: 'all' } },
174
+ exec: () => ({ ok: true })
175
+ });
176
+ const scheduleFn = createFunction({
177
+ description: 'schedule target',
178
+ trigger: { kind: 'schedule', frequency: 'every hour' },
179
+ exec: () => { }
180
+ });
181
+ createFunction({
182
+ description: 'dispatcher',
183
+ requires: { outbound: false, invoke: true },
184
+ trigger: { kind: 'schedule', frequency: 'every hour' },
185
+ exec: async (nango) => {
186
+ // http target: invoke passes the single declared input (not the coalesced array)
187
+ const httpRes = await nango.invoke(httpFn, { input: { title: 'x' } });
188
+ expectTypeOf(httpRes).toEqualTypeOf();
189
+ // @ts-expect-error http input must match the declared input schema
190
+ await nango.invoke(httpFn, { input: { wrong: 1 } });
191
+ // @ts-expect-error required input cannot be skipped
192
+ await nango.invoke(httpFn);
193
+ // schedule target: no declared input
194
+ await nango.invoke(scheduleFn);
195
+ // a widened/opaque function reference is rejected
196
+ const opaque = httpFn;
197
+ // @ts-expect-error opaque reference does not satisfy the invoke target constraint
198
+ await nango.invoke(opaque, { input: { title: 'x' } });
199
+ }
200
+ });
201
+ });
202
+ it('connection-less function can only searchConnections and invoke', () => {
203
+ createFunction({
204
+ description: 'resolves connections at runtime',
205
+ requires: { connection: false, invoke: true },
206
+ trigger: { kind: 'schedule', frequency: 'every hour' },
207
+ exec: async (nango) => {
208
+ await nango.searchConnections({ provider: 'github' });
209
+ expectTypeOf().toEqualTypeOf();
210
+ expectTypeOf().toEqualTypeOf();
211
+ expectTypeOf().toEqualTypeOf();
212
+ expectTypeOf().toEqualTypeOf();
213
+ }
214
+ });
215
+ });
216
+ });
217
+ describe('no models', () => {
218
+ it('does not expose record/checkpoint/metadata methods', () => {
219
+ createFunction({
220
+ description: 'no models',
221
+ trigger: { kind: 'schedule', frequency: 'every hour' },
222
+ exec: (_nango) => {
223
+ expectTypeOf().toEqualTypeOf();
224
+ expectTypeOf().toEqualTypeOf();
225
+ expectTypeOf().toEqualTypeOf();
226
+ }
227
+ });
228
+ });
229
+ });
230
+ describe('limits.concurrency.perConnection', () => {
231
+ it('is fixed to 1 for schedule triggers and a ConcurrencyLimit otherwise', () => {
232
+ createFunction({
233
+ description: 'scheduled',
234
+ trigger: { kind: 'schedule', frequency: 'every hour' },
235
+ limits: { concurrency: { perConnection: 1 } },
236
+ exec: () => { }
237
+ });
238
+ createFunction({
239
+ description: 'http can overlap runs for a connection',
240
+ trigger: { kind: 'http' },
241
+ limits: { concurrency: { perConnection: 'max' } },
242
+ exec: () => { }
243
+ });
244
+ createFunction({
245
+ description: 'schedule function cannot overlap',
246
+ trigger: { kind: 'schedule', frequency: 'every hour' },
247
+ // @ts-expect-error schedule triggers are pinned to perConnection: 1
248
+ limits: { concurrency: { perConnection: 'max' } },
249
+ exec: () => { }
250
+ });
251
+ });
252
+ });
253
+ });
254
+ //# sourceMappingURL=function.unit.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.unit.test.js","sourceRoot":"","sources":["../lib/function.unit.test.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAM/C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAA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E,SAAS,EAAE,YAAY,EAAE;gBACtD,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,EAAE;gBAC7C,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;YAEH,cAAc,CAAC;gBACX,WAAW,EAAE,wCAAwC;gBACrD,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;gBACzB,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE;gBACjD,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;YAEH,cAAc,CAAC;gBACX,WAAW,EAAE,kCAAkC;gBAC/C,OAAO,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE;gBACtD,oEAAoE;gBACpE,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE;gBACjD,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;aACjB,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ export * from './errors.js';
6
6
  export * from './sync.js';
7
7
  export * from './scripts.js';
8
8
  export * from './checkpoint.js';
9
+ export { createFunction, deriveFunctionCapabilities } from './function.js';
10
+ export type { CreateFunctionProps, CreateFunctionResponse, Requires, TriggerDefinition } from './function.js';
9
11
  export { executeUncontrolledFetch } from './uncontrolledFetch.js';
10
12
  export type { UncontrolledFetchOptions } from './uncontrolledFetch.js';
11
13
  export { isBaseUrlOverridePolicyEnabledFromEnv, resolveProxyBaseUrlOverrideDenylist } from './baseUrlOverrideDenylist.js';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './errors.js';
5
5
  export * from './sync.js';
6
6
  export * from './scripts.js';
7
7
  export * from './checkpoint.js';
8
+ export { createFunction, deriveFunctionCapabilities } from './function.js';
8
9
  export { executeUncontrolledFetch } from './uncontrolledFetch.js';
9
10
  export { isBaseUrlOverridePolicyEnabledFromEnv, resolveProxyBaseUrlOverrideDenylist } from './baseUrlOverrideDenylist.js';
10
11
  export { PaginationService };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAGtD,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,qCAAqC,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AAE1H,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAGtD,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,qCAAqC,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AAE1H,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
package/dist/scripts.d.ts CHANGED
@@ -4,7 +4,7 @@ import type { ZodCheckpoint, ZodMetadata, ZodModel } from './types.js';
4
4
  import type { NangoSyncEndpointV2 } from '@nangohq/types';
5
5
  import type { MaybePromise } from 'rollup';
6
6
  import type * as z from 'zod';
7
- export type CreateAnyResponse = CreateSyncResponse<any, ZodMetadata, ZodCheckpoint> | CreateActionResponse<any, any, ZodMetadata, ZodCheckpoint> | CreateOnEventResponse<ZodMetadata, ZodCheckpoint> | CreateFunctionResponse<any, any, any, ZodMetadata, ZodCheckpoint>;
7
+ export type CreateAnyResponse = CreateSyncResponse<any, ZodMetadata, ZodCheckpoint> | CreateActionResponse<any, any, ZodMetadata, ZodCheckpoint> | CreateOnEventResponse<ZodMetadata, ZodCheckpoint>;
8
8
  export type { ActionError } from './errors.js';
9
9
  export type { NangoActionBase as NangoAction, ProxyConfiguration } from './action.js';
10
10
  export type { NangoSyncBase as NangoSync } from './sync.js';
@@ -362,217 +362,3 @@ export interface CreateOnEventResponse<TMetadata extends ZodMetadata = undefined
362
362
  * Create an onEvent script
363
363
  */
364
364
  export declare function createOnEvent<TMetadata extends ZodMetadata = undefined, TCheckpoint extends ZodCheckpoint = undefined>(params: CreateOnEventProps<TMetadata, TCheckpoint>): CreateOnEventResponse<TMetadata, TCheckpoint>;
365
- /**
366
- * The kind of declared trigger that initiated a function run.
367
- * - `http`: an incoming http call or webhook request
368
- * - `schedule`: a periodic schedule
369
- * - `event`: an internal Nango event
370
- *
371
- * On-demand invocation (`nango.triggerFunction()`, the REST API, the CLI, or the UI) is always
372
- * available regardless of declared triggers — it is not a trigger type. Such runs leave
373
- * `FunctionEvent.trigger` undefined.
374
- */
375
- export type FunctionTriggerType = 'http' | 'schedule' | 'event';
376
- /**
377
- * Declares where the debounce/coalescing key is extracted from.
378
- * - `{ body: '$.portalId' }` — dot-notation path into the normalized body
379
- * - `{ header: 'x-goog-resource-id' }` — flat, case-insensitive header lookup
380
- */
381
- export type DebounceKeySource = {
382
- body: string;
383
- } | {
384
- header: string;
385
- };
386
- /**
387
- * Coalesces multiple inbound events into a single function run within a sliding window.
388
- */
389
- export interface WebhookDebounceConfig {
390
- key?: DebounceKeySource;
391
- /** Sliding window in milliseconds. */
392
- windowMs: number;
393
- /** Hard ceiling for the window regardless of incoming events. */
394
- maxWindowMs?: number;
395
- /** When exceeded, the window stops sliding and `event.coalesced.overflowed` is set. */
396
- maxEntities?: number;
397
- /** Whether the handler receives only the latest payload or every coalesced payload. */
398
- payloadMode?: 'latest' | 'all';
399
- }
400
- /** Read-only request view passed to ingress hooks. No SDK, no I/O, hard timeout. */
401
- export interface IngressEvent {
402
- rawBody: string;
403
- headers: Record<string, string>;
404
- query: Record<string, string | string[] | undefined>;
405
- }
406
- /**
407
- * Runs synchronously at ingress before enqueueing. Return a response object to short-circuit
408
- * the HTTP exchange (provider handshake), or `undefined` to let the request proceed.
409
- */
410
- export type IngressChallenge = (event: IngressEvent) => MaybePromise<{
411
- status?: number;
412
- body?: unknown;
413
- headers?: Record<string, string>;
414
- } | undefined | void>;
415
- /**
416
- * Runs synchronously at ingress before enqueueing. Return `true` to accept the event,
417
- * or `false` (or throw) to reject it with a 401.
418
- */
419
- export type IngressValidation = (event: IngressEvent) => MaybePromise<boolean>;
420
- export interface HttpTrigger {
421
- type: 'http';
422
- /** Maps to the webhook URL path segment. Defaults to the file basename. */
423
- name?: string;
424
- /** `connection` opts into connection-level URLs (`/:webhookName/:targetToken`). */
425
- scope?: 'integration' | 'connection';
426
- ingressChallenge?: IngressChallenge;
427
- ingressValidation?: IngressValidation;
428
- debounce?: WebhookDebounceConfig;
429
- }
430
- export interface ScheduleTrigger {
431
- type: 'schedule';
432
- /** e.g. 'every hour', 'every 2 minutes'. */
433
- schedule: string;
434
- }
435
- export interface EventTrigger {
436
- type: 'event';
437
- event: string;
438
- }
439
- export type FunctionTrigger = HttpTrigger | ScheduleTrigger | EventTrigger;
440
- /** Coalescing summary, present on the event when `debounce` is configured. */
441
- export interface CoalescedInfo {
442
- count: number;
443
- firstSeenAt: Date;
444
- lastSeenAt: Date;
445
- overflowed: boolean;
446
- }
447
- /**
448
- * The event a function `exec` receives. Distinct from `(nango, input)` for actions —
449
- * functions are trigger-driven, so the second argument describes the trigger and its payload.
450
- */
451
- export interface FunctionEvent<TPayload = unknown> {
452
- /**
453
- * Which declared trigger fired, and (for named triggers) its name.
454
- * Undefined when the run was started on-demand (`nango.triggerFunction()`, the REST API, the CLI, or the UI).
455
- */
456
- trigger?: {
457
- type: FunctionTriggerType;
458
- name?: string;
459
- };
460
- /**
461
- * The payload that initiated the run. Typed as the function's `input` schema when declared,
462
- * otherwise `unknown`. For http triggers this is the provider's body (not validated against
463
- * `input` at runtime), and it is an array of `TPayload` when `payloadMode: 'all'` is set and debounced.
464
- */
465
- payload: TPayload;
466
- /** Raw headers from the provider (http trigger only). */
467
- headers?: Record<string, string>;
468
- /** Original request body as received by ingress (http trigger only). */
469
- rawBody?: string;
470
- /** Coalescing summary when `debounce` is configured. */
471
- coalesced?: CoalescedInfo;
472
- /**
473
- * Pre-populated when the run was started with connection context (connection-level URL,
474
- * `triggerFunction({ connectionId })`, or CLI `--connection`). Undefined for connection-less runs.
475
- */
476
- connection?: {
477
- connection_id: string;
478
- provider_config_key: string;
479
- };
480
- }
481
- export interface CreateFunctionProps<TModels extends Record<string, ZodModel>, TInput extends z.ZodTypeAny = z.ZodUnknown, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TMetadata extends ZodMetadata = undefined, TCheckpoint extends ZodCheckpoint = undefined> {
482
- /**
483
- * The version of the function. Use it to track changes inside Nango's UI.
484
- * Supports semver (e.g. `'1.0.0'`)
485
- * If omitted, Nango auto-manages it: `1` on first deploy, and auto-increments for subsequent deploys.
486
- */
487
- version?: string;
488
- /** The description of the function. */
489
- description?: string;
490
- /**
491
- * What can initiate execution. A function can have multiple triggers of different types
492
- * (e.g. a webhook trigger plus a scheduled safety net). Any function can also be started
493
- * on-demand via `nango.triggerFunction()` or the API regardless of declared triggers.
494
- */
495
- triggers: FunctionTrigger[];
496
- /** Models the function can `batchSave`/`batchUpdate`/`batchDelete` against. */
497
- models?: TModels;
498
- /** Optional input schema. When set, it types `event.payload` and is used for API invocation. */
499
- input?: TInput;
500
- /** Optional typed output schema (reserved; unused for webhooks today). */
501
- output?: TOutput;
502
- metadata?: TMetadata;
503
- checkpoint?: TCheckpoint;
504
- scopes?: string[];
505
- /**
506
- * The handler. Runs on the customer runner with full SDK access.
507
- * @example
508
- * ```ts
509
- * exec: async (nango, event) => {
510
- * const connections = await nango.searchConnections({ tags: { portalId: event.payload.portalId } });
511
- * for (const connection of connections) {
512
- * await nango.triggerSync(connection.provider_config_key, connection.connection_id, 'contacts');
513
- * }
514
- * }
515
- * ```
516
- */
517
- exec: (nango: NangoSyncBase<TModels, TMetadata, TCheckpoint>, event: FunctionEvent<z.infer<TInput>>) => MaybePromise<void>;
518
- }
519
- export interface CreateFunctionResponse<TModels extends Record<string, ZodModel>, TInput extends z.ZodTypeAny = z.ZodUnknown, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TMetadata extends ZodMetadata = undefined, TCheckpoint extends ZodCheckpoint = undefined> extends CreateFunctionProps<TModels, TInput, TOutput, TMetadata, TCheckpoint> {
520
- type: 'function';
521
- /** Set when authored via `createWebhook()`; mirrors the http trigger name. */
522
- name?: string;
523
- }
524
- /**
525
- * Create a function — the trigger-agnostic primitive.
526
- *
527
- * Use this directly when you need multiple trigger types (e.g. webhook + cron).
528
- * For a single webhook trigger, prefer the `createWebhook()` sugar.
529
- *
530
- * @example
531
- * ```ts
532
- * export default createFunction({
533
- * triggers: [
534
- * { type: 'http', name: 'contacts-updated', debounce: { key: { body: '$.objectId' }, windowMs: 5000 } },
535
- * { type: 'schedule', schedule: 'every hour' }
536
- * ],
537
- * exec: async (nango, event) => { ... }
538
- * });
539
- * ```
540
- */
541
- export declare function createFunction<TModels extends Record<string, ZodModel> = Record<never, ZodModel>, TInput extends z.ZodTypeAny = z.ZodUnknown, TOutput extends z.ZodTypeAny = z.ZodTypeAny, TMetadata extends ZodMetadata = undefined, TCheckpoint extends ZodCheckpoint = undefined>(params: CreateFunctionProps<TModels, TInput, TOutput, TMetadata, TCheckpoint>): CreateFunctionResponse<TModels, TInput, TOutput, TMetadata, TCheckpoint>;
542
- export interface CreateWebhookProps<TModels extends Record<string, ZodModel>, TMetadata extends ZodMetadata = undefined, TCheckpoint extends ZodCheckpoint = undefined> {
543
- /** Maps to the webhook URL path segment. Defaults to the file basename. */
544
- name?: string;
545
- version?: string;
546
- description?: string;
547
- /** `connection` opts into connection-level URLs (`/:webhookName/:targetToken`). */
548
- scope?: 'integration' | 'connection';
549
- ingressChallenge?: IngressChallenge;
550
- ingressValidation?: IngressValidation;
551
- debounce?: WebhookDebounceConfig;
552
- models?: TModels;
553
- metadata?: TMetadata;
554
- checkpoint?: TCheckpoint;
555
- exec: (nango: NangoSyncBase<TModels, TMetadata, TCheckpoint>, event: FunctionEvent) => MaybePromise<void>;
556
- }
557
- /**
558
- * Create a webhook handler — sugar for a function with a single implicit `http` trigger.
559
- *
560
- * Routing lives entirely in `exec` (customer-owned, runs on your runner). Provider protocol
561
- * mechanics (handshake, signature verification) live in `ingressChallenge` / `ingressValidation`,
562
- * which run synchronously at ingress with no SDK access.
563
- *
564
- * @example
565
- * ```ts
566
- * export default createWebhook({
567
- * name: 'contacts-updated',
568
- * debounce: { key: { body: '$.portalId' }, windowMs: 5000 },
569
- * exec: async (nango, event) => {
570
- * const connections = await nango.searchConnections({ tags: { portalId: event.payload.portalId } });
571
- * for (const connection of connections) {
572
- * await nango.triggerSync(connection.provider_config_key, connection.connection_id, 'contacts');
573
- * }
574
- * }
575
- * });
576
- * ```
577
- */
578
- export declare function createWebhook<TModels extends Record<string, ZodModel> = Record<never, ZodModel>, TMetadata extends ZodMetadata = undefined, TCheckpoint extends ZodCheckpoint = undefined>(params: CreateWebhookProps<TModels, TMetadata, TCheckpoint>): CreateFunctionResponse<TModels, z.ZodTypeAny, z.ZodTypeAny, TMetadata, TCheckpoint>;
package/dist/scripts.js CHANGED
@@ -48,62 +48,4 @@ export function createAction(params) {
48
48
  export function createOnEvent(params) {
49
49
  return { type: 'onEvent', ...params };
50
50
  }
51
- /**
52
- * Create a function — the trigger-agnostic primitive.
53
- *
54
- * Use this directly when you need multiple trigger types (e.g. webhook + cron).
55
- * For a single webhook trigger, prefer the `createWebhook()` sugar.
56
- *
57
- * @example
58
- * ```ts
59
- * export default createFunction({
60
- * triggers: [
61
- * { type: 'http', name: 'contacts-updated', debounce: { key: { body: '$.objectId' }, windowMs: 5000 } },
62
- * { type: 'schedule', schedule: 'every hour' }
63
- * ],
64
- * exec: async (nango, event) => { ... }
65
- * });
66
- * ```
67
- */
68
- export function createFunction(params) {
69
- return { type: 'function', ...params };
70
- }
71
- /**
72
- * Create a webhook handler — sugar for a function with a single implicit `http` trigger.
73
- *
74
- * Routing lives entirely in `exec` (customer-owned, runs on your runner). Provider protocol
75
- * mechanics (handshake, signature verification) live in `ingressChallenge` / `ingressValidation`,
76
- * which run synchronously at ingress with no SDK access.
77
- *
78
- * @example
79
- * ```ts
80
- * export default createWebhook({
81
- * name: 'contacts-updated',
82
- * debounce: { key: { body: '$.portalId' }, windowMs: 5000 },
83
- * exec: async (nango, event) => {
84
- * const connections = await nango.searchConnections({ tags: { portalId: event.payload.portalId } });
85
- * for (const connection of connections) {
86
- * await nango.triggerSync(connection.provider_config_key, connection.connection_id, 'contacts');
87
- * }
88
- * }
89
- * });
90
- * ```
91
- */
92
- export function createWebhook(params) {
93
- const { name, scope, ingressChallenge, ingressValidation, debounce, ...rest } = params;
94
- const trigger = {
95
- type: 'http',
96
- ...(name !== undefined ? { name } : {}),
97
- ...(scope !== undefined ? { scope } : {}),
98
- ...(ingressChallenge !== undefined ? { ingressChallenge } : {}),
99
- ...(ingressValidation !== undefined ? { ingressValidation } : {}),
100
- ...(debounce !== undefined ? { debounce } : {})
101
- };
102
- return {
103
- type: 'function',
104
- ...rest,
105
- ...(name !== undefined ? { name } : {}),
106
- triggers: [trigger]
107
- };
108
- }
109
51
  //# sourceMappingURL=scripts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scripts.js","sourceRoot":"","sources":["../lib/sc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