@zapier/zapier-sdk 0.70.4 → 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.
Files changed (81) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +149 -31
  3. package/dist/api/approval-review-stream.d.ts +25 -0
  4. package/dist/api/approval-review-stream.d.ts.map +1 -0
  5. package/dist/api/approval-review-stream.js +104 -0
  6. package/dist/api/client.d.ts.map +1 -1
  7. package/dist/api/client.js +215 -27
  8. package/dist/api/types.d.ts +13 -3
  9. package/dist/api/types.d.ts.map +1 -1
  10. package/dist/constants.d.ts +1 -0
  11. package/dist/constants.d.ts.map +1 -1
  12. package/dist/constants.js +6 -0
  13. package/dist/experimental.cjs +602 -37
  14. package/dist/experimental.d.mts +88 -2
  15. package/dist/experimental.d.ts +90 -4
  16. package/dist/experimental.d.ts.map +1 -1
  17. package/dist/experimental.js +10 -0
  18. package/dist/experimental.mjs +602 -38
  19. package/dist/{index-BNaiNmM-.d.mts → index-B43uST61.d.mts} +181 -12
  20. package/dist/{index-BNaiNmM-.d.ts → index-B43uST61.d.ts} +181 -12
  21. package/dist/index.cjs +592 -32
  22. package/dist/index.d.mts +1 -1
  23. package/dist/index.mjs +592 -33
  24. package/dist/plugins/api/index.d.ts.map +1 -1
  25. package/dist/plugins/api/index.js +2 -1
  26. package/dist/plugins/codeSubstrate/createWorkflow/index.d.ts +1 -0
  27. package/dist/plugins/codeSubstrate/createWorkflow/index.d.ts.map +1 -1
  28. package/dist/plugins/codeSubstrate/createWorkflow/index.js +3 -2
  29. package/dist/plugins/codeSubstrate/createWorkflow/schemas.d.ts +1 -0
  30. package/dist/plugins/codeSubstrate/createWorkflow/schemas.d.ts.map +1 -1
  31. package/dist/plugins/codeSubstrate/createWorkflow/schemas.js +7 -1
  32. package/dist/plugins/codeSubstrate/deleteWorkflow/index.d.ts +1 -1
  33. package/dist/plugins/codeSubstrate/disableWorkflow/index.d.ts +1 -1
  34. package/dist/plugins/codeSubstrate/enableWorkflow/index.d.ts +1 -1
  35. package/dist/plugins/codeSubstrate/getDurableRun/schemas.d.ts +4 -4
  36. package/dist/plugins/codeSubstrate/getWorkflow/index.d.ts +2 -2
  37. package/dist/plugins/codeSubstrate/getWorkflow/schemas.d.ts +1 -1
  38. package/dist/plugins/codeSubstrate/getWorkflowRun/index.d.ts +1 -1
  39. package/dist/plugins/codeSubstrate/getWorkflowVersion/index.d.ts +1 -1
  40. package/dist/plugins/codeSubstrate/listWorkflowRuns/index.d.ts +1 -1
  41. package/dist/plugins/codeSubstrate/listWorkflowVersions/index.d.ts +1 -1
  42. package/dist/plugins/codeSubstrate/listWorkflows/index.d.ts +1 -1
  43. package/dist/plugins/codeSubstrate/listWorkflows/schemas.d.ts +2 -2
  44. package/dist/plugins/codeSubstrate/publishWorkflowVersion/index.d.ts +1 -1
  45. package/dist/plugins/codeSubstrate/runDurable/schemas.js +1 -1
  46. package/dist/plugins/codeSubstrate/shared-schemas.d.ts +2 -2
  47. package/dist/plugins/codeSubstrate/triggerWorkflow/index.d.ts +1 -1
  48. package/dist/plugins/codeSubstrate/updateWorkflow/index.d.ts +1 -1
  49. package/dist/plugins/createConnection/index.d.ts +189 -0
  50. package/dist/plugins/createConnection/index.d.ts.map +1 -0
  51. package/dist/plugins/createConnection/index.js +71 -0
  52. package/dist/plugins/createConnection/schemas.d.ts +21 -0
  53. package/dist/plugins/createConnection/schemas.d.ts.map +1 -0
  54. package/dist/plugins/createConnection/schemas.js +38 -0
  55. package/dist/plugins/getConnectionStartUrl/index.d.ts +206 -0
  56. package/dist/plugins/getConnectionStartUrl/index.d.ts.map +1 -0
  57. package/dist/plugins/getConnectionStartUrl/index.js +39 -0
  58. package/dist/plugins/getConnectionStartUrl/schemas.d.ts +15 -0
  59. package/dist/plugins/getConnectionStartUrl/schemas.d.ts.map +1 -0
  60. package/dist/plugins/getConnectionStartUrl/schemas.js +23 -0
  61. package/dist/plugins/waitForNewConnection/index.d.ts +209 -0
  62. package/dist/plugins/waitForNewConnection/index.d.ts.map +1 -0
  63. package/dist/plugins/waitForNewConnection/index.js +75 -0
  64. package/dist/plugins/waitForNewConnection/schemas.d.ts +17 -0
  65. package/dist/plugins/waitForNewConnection/schemas.d.ts.map +1 -0
  66. package/dist/plugins/waitForNewConnection/schemas.js +39 -0
  67. package/dist/sdk.d.ts +126 -0
  68. package/dist/sdk.d.ts.map +1 -1
  69. package/dist/sdk.js +8 -0
  70. package/dist/types/errors.d.ts +13 -4
  71. package/dist/types/errors.d.ts.map +1 -1
  72. package/dist/types/errors.js +2 -0
  73. package/dist/types/sdk.d.ts +1 -0
  74. package/dist/types/sdk.d.ts.map +1 -1
  75. package/dist/types/sdk.js +5 -1
  76. package/dist/utils/open-url.d.ts.map +1 -1
  77. package/dist/utils/open-url.js +7 -0
  78. package/dist/utils/should-open-browser.d.ts +24 -0
  79. package/dist/utils/should-open-browser.d.ts.map +1 -0
  80. package/dist/utils/should-open-browser.js +55 -0
  81. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.71.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 2521624: Rename `createWorkflow`'s `is_private` input to `private` to match `runDurable`, keeping `is_private` as a deprecated alias; the wire field stays `is_private`. Clarify the `run-durable` connections param description to show the required object shape.
8
+
9
+ ## 0.71.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 3474ff3: Add `createConnection` and two lower-level building blocks for connecting an app from code, end to end:
14
+ - `createConnection({ app, browser?, timeoutMs?, pollIntervalMs? })` — high-level: mints a connection URL, prints it (and opens it in a browser when it's safe to do so), waits for the user to finish, and returns the new connection. `browser` is `"auto"` (default — opens locally, skips CI / SSH / headless Linux), `"always"`, or `"never"`. The URL is always printed, so a skipped or failed open falls back to copy/paste.
15
+ - `getConnectionStartUrl({ app })` — low-level: mints a short-lived, signed start URL bound to the current user/account. Returns `{ url, startedAt, expiresAt, app }`.
16
+ - `waitForNewConnection({ app, startedAt, timeoutMs?, pollIntervalMs? })` — low-level: polls until a connection for the app created at or after `startedAt` appears, then returns `{ id, app, title? }`. Throws `ZapierTimeoutError` after `timeoutMs` (default 5 minutes).
17
+
18
+ `createConnection` is the right call for most cases. Reach for the two low-level methods when you want to hand off the URL without blocking (call `getConnectionStartUrl` alone), or do something custom between minting the URL and waiting — email it, post it to Slack, render a QR code — then call `waitForNewConnection`.
19
+
20
+ ### Patch Changes
21
+
22
+ - 5ca445d: Add private-beta support for streaming auto-mode approval review messages and handling terminal failed approvals through the SDK and CLI. Auto mode is only enabled service-side for approved beta users.
23
+
3
24
  ## 0.70.4
4
25
 
5
26
  ### Patch Changes
package/README.md CHANGED
@@ -46,10 +46,13 @@
46
46
  - [`triggerWorkflow`](#triggerworkflow--experimental)
47
47
  - [`updateWorkflow`](#updateworkflow--experimental)
48
48
  - [Connections](#connections)
49
+ - [`createConnection`](#createconnection)
49
50
  - [`findFirstConnection`](#findfirstconnection)
50
51
  - [`findUniqueConnection`](#finduniqueconnection)
51
52
  - [`getConnection`](#getconnection)
53
+ - [`getConnectionStartUrl`](#getconnectionstarturl)
52
54
  - [`listConnections`](#listconnections)
55
+ - [`waitForNewConnection`](#waitfornewconnection)
53
56
  - [HTTP Requests](#http-requests)
54
57
  - [`fetch`](#fetch)
55
58
  - [Tables](#tables)
@@ -349,21 +352,22 @@ console.log(emojiData.emoji);
349
352
 
350
353
  The `createZapierSdk(...)` factory function is the main entry point for the SDK. It provides methods for managing connections, listing apps, running actions, and more.
351
354
 
352
- | Name | Type | Required | Default | Possible Values | Description |
353
- | ----------------------------- | -------------------------- | -------- | ------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
354
- | `credentials` | `string, object, function` | ❌ | — | — | Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those. |
355
- | `debug` | `boolean` | ❌ | — | — | Enable debug logging. |
356
- | `baseUrl` | `string` | ❌ | — | — | Base URL for Zapier API endpoints. |
357
- | `trackingBaseUrl` | `string` | ❌ | — | — | Base URL for Zapier tracking endpoints. |
358
- | `maxNetworkRetries` | `number` | ❌ | — | — | Max retries for rate-limited requests (default: 3). |
359
- | `maxNetworkRetryDelayMs` | `number` | ❌ | — | — | Max delay in ms to wait for retry (default: 60000). |
360
- | `maxConcurrentRequests` | `number, literal` | ❌ | — | — | Max concurrent in-flight HTTP requests (default: 200, max: 10000). |
361
- | `approvalTimeoutMs` | `number` | ❌ | — | — | Timeout in ms for approval polling. Default: 600000 (10 min). |
362
- | `maxApprovalRetries` | `number` | ❌ | — | — | Maximum number of sequential approval rounds per request (one per gating policy) before giving up. Default: 2. |
363
- | `approvalMode` | `string` | ❌ | — | `disabled`, `poll`, `throw` | Approval flow behavior. "poll" creates the approval, opens it in a browser, polls until resolved, and retries the original request. "throw" creates the approval and throws a ZapierApprovalError with the approval URL so the caller can surface it. "disabled" throws a ZapierApprovalError on approval-required responses without creating an approval. Resolution order is: explicit option, then ZAPIER_APPROVAL_MODE, then the default behavior (poll for interactive TTY, throw otherwise). |
364
- | `canIncludeSharedConnections` | `boolean` | ❌ | — | — | Allow listing shared connections. |
365
- | `canIncludeSharedTables` | `boolean` | ❌ | — | — | Allow listing shared tables. |
366
- | `canDeleteTables` | `boolean` | ❌ | — | — | Allow deleting tables. |
355
+ | Name | Type | Required | Default | Possible Values | Description |
356
+ | -------------------------------- | -------------------------- | -------- | ------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
357
+ | `credentials` | `string, object, function` | ❌ | — | — | Authentication credentials. Can be a string (token or API key), a client credentials object ({ clientId, clientSecret }), a PKCE object ({ clientId }), or a function returning any of those. |
358
+ | `debug` | `boolean` | ❌ | — | — | Enable debug logging. |
359
+ | `baseUrl` | `string` | ❌ | — | — | Base URL for Zapier API endpoints. |
360
+ | `trackingBaseUrl` | `string` | ❌ | — | — | Base URL for Zapier tracking endpoints. |
361
+ | `maxNetworkRetries` | `number` | ❌ | — | — | Max retries for rate-limited requests (default: 3). |
362
+ | `maxNetworkRetryDelayMs` | `number` | ❌ | — | — | Max delay in ms to wait for retry (default: 60000). |
363
+ | `maxConcurrentRequests` | `number, literal` | ❌ | — | — | Max concurrent in-flight HTTP requests (default: 200, max: 10000). |
364
+ | `approvalTimeoutMs` | `number` | ❌ | — | — | Timeout in ms for approval polling. Default: 600000 (10 min). |
365
+ | `maxApprovalRetries` | `number` | ❌ | — | — | Maximum number of sequential approval rounds per request (one per gating policy) before giving up. Default: 2. |
366
+ | `approvalMode` | `string` | ❌ | — | `disabled`, `poll`, `throw` | Approval flow behavior for manual approvals. "poll" creates the approval, opens it in a browser, polls until resolved, and retries the original request. "throw" creates the manual approval and throws a ZapierApprovalError with the approval URL so the caller can surface it. Server-created auto-mode approvals always poll until they reach a terminal status and retry the original request on approval, even when this option is "throw". "disabled" throws a ZapierApprovalError on approval-required responses without creating an approval. Resolution order is: explicit option, then ZAPIER_APPROVAL_MODE, then the default behavior (poll for interactive TTY, throw otherwise). |
367
+ | `openAutoModeApprovalsInBrowser` | `boolean` | ❌ | — | — | By default, auto-mode approvals do not open in a browser. Enable this option to open the approval URL and watch the approval process. Resolution order is: explicit option, then ZAPIER_OPEN_AUTO_MODE_APPROVALS_IN_BROWSER, then false. |
368
+ | `canIncludeSharedConnections` | `boolean` | ❌ | — | — | Allow listing shared connections. |
369
+ | `canIncludeSharedTables` | `boolean` | ❌ | — | — | Allow listing shared tables. |
370
+ | `canDeleteTables` | `boolean` | ❌ | — | — | Allow deleting tables. |
367
371
 
368
372
  ## Named Connections
369
373
 
@@ -1141,7 +1145,7 @@ Create a durable workflow container. Starts disabled with no version; publish a
1141
1145
  | `options` | `object` | ✅ | — | — | |
1142
1146
  | ​ ↳ `name` | `string` | ✅ | — | — | Workflow name |
1143
1147
  | ​ ↳ `description` | `string` | ❌ | — | — | Optional description for the workflow |
1144
- | ​ ↳ `is_private` | `boolean` | ❌ | — | — | If true, only the creating user can see or manage this workflow. Defaults to false (account-visible). |
1148
+ | ​ ↳ `private` | `boolean` | ❌ | — | — | If true, only the creating user can see or manage this workflow. Defaults to false (account-visible). |
1145
1149
 
1146
1150
  **Returns:** `Promise<WorkflowItem>`
1147
1151
 
@@ -1701,21 +1705,21 @@ Run a workflow source file as a run-once durable run on sdkdurableapi (no deploy
1701
1705
 
1702
1706
  **Parameters:**
1703
1707
 
1704
- | Name | Type | Required | Default | Possible Values | Description |
1705
- | ---------------------------- | ---------- | -------- | ------- | --------------- | --------------------------------------------------------------------------------------------------------------- |
1706
- | `options` | `object` | ✅ | — | — | |
1707
- | ​ ↳ `source_files` | `object` | ✅ | — | — | Source files keyed by filename → contents |
1708
- | ​ ↳ `input` | `unknown` | ❌ | — | — | Input data passed to the run |
1709
- | ​ ↳ `dependencies` | `object` | ❌ | — | — | Optional npm package dependencies |
1710
- | ​ ↳ `zapier_durable_version` | `string` | ❌ | — | — | Exact semver of @zapier/zapier-durable to use (e.g. "1.2.3"). Defaults to server-configured version if omitted. |
1711
- | ​ ↳ `connections` | `object` | ❌ | — | — | Named connection aliases. Maps alias names to Zapier connection IDs. |
1712
- | ​ ↳ `app_versions` | `object` | ❌ | — | — | Pinned app versions. Maps app keys (slugs) to implementation names and versions. |
1713
- | ​ ↳ `private` | `boolean` | ❌ | — | — | Only the creating user can see the run (default false) |
1714
- | ​ ↳ `notifications[]` | `object[]` | ❌ | — | — | Webhook subscribers for run lifecycle events. Each entry specifies a URL and the events it subscribes to. |
1715
- | ​   ↳ `type` | `string` | ❌ | — | `webhook` | Notification transport. Webhook is the only supported type. |
1716
- | ​   ↳ `url` | `string` | ✅ | — | — | URL to POST event notifications to. Payload is `{run_id, event}`. |
1717
- | ​   ↳ `max_retries` | `number` | ❌ | — | — | Max delivery attempts with exponential backoff. Defaults to 3 server-side. |
1718
- | ​   ↳ `events` | `array` | ✅ | — | — | One or more lifecycle events to subscribe this URL to. |
1708
+ | Name | Type | Required | Default | Possible Values | Description |
1709
+ | ---------------------------- | ---------- | -------- | ------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
1710
+ | `options` | `object` | ✅ | — | — | |
1711
+ | ​ ↳ `source_files` | `object` | ✅ | — | — | Source files keyed by filename → contents |
1712
+ | ​ ↳ `input` | `unknown` | ❌ | — | — | Input data passed to the run |
1713
+ | ​ ↳ `dependencies` | `object` | ❌ | — | — | Optional npm package dependencies |
1714
+ | ​ ↳ `zapier_durable_version` | `string` | ❌ | — | — | Exact semver of @zapier/zapier-durable to use (e.g. "1.2.3"). Defaults to server-configured version if omitted. |
1715
+ | ​ ↳ `connections` | `object` | ❌ | — | — | Named connection aliases. Maps each alias to an object holding its Zapier connection ID, e.g. `{ "slack": { "connection_id": "123" } }`. |
1716
+ | ​ ↳ `app_versions` | `object` | ❌ | — | — | Pinned app versions. Maps app keys (slugs) to implementation names and versions. |
1717
+ | ​ ↳ `private` | `boolean` | ❌ | — | — | Only the creating user can see the run (default false) |
1718
+ | ​ ↳ `notifications[]` | `object[]` | ❌ | — | — | Webhook subscribers for run lifecycle events. Each entry specifies a URL and the events it subscribes to. |
1719
+ | ​   ↳ `type` | `string` | ❌ | — | `webhook` | Notification transport. Webhook is the only supported type. |
1720
+ | ​   ↳ `url` | `string` | ✅ | — | — | URL to POST event notifications to. Payload is `{run_id, event}`. |
1721
+ | ​   ↳ `max_retries` | `number` | ❌ | — | — | Max delivery attempts with exponential backoff. Defaults to 3 server-side. |
1722
+ | ​   ↳ `events` | `array` | ✅ | — | — | One or more lifecycle events to subscribe this URL to. |
1719
1723
 
1720
1724
  **Returns:** `Promise<DurableRunItem>`
1721
1725
 
@@ -1802,6 +1806,39 @@ const result = await zapier.updateWorkflow({
1802
1806
 
1803
1807
  ### Connections
1804
1808
 
1809
+ #### `createConnection`
1810
+
1811
+ Create a new app connection, end-to-end. Mints the start URL via `get-connection-start-url`, prints it to stderr, opportunistically opens it in a browser when it looks safe to do so (skipping CI / SSH / headless-Linux by default — pass `--browser always` to force, `--browser never` to suppress), then polls via `wait-for-new-connection` until the user completes OAuth and the new connection appears. Returns the connection.
1812
+
1813
+ This is the right command for most callers. Reach for the lower-level building blocks when you want either of: (a) hand off the URL and _not_ block on completion — call `get-connection-start-url` alone, no `wait-for-new-connection` needed, or (b) do something custom between minting the URL and waiting — call `get-connection-start-url`, do your work (email or DM the URL, render a QR code, etc.), then `wait-for-new-connection`.
1814
+
1815
+ **Parameters:**
1816
+
1817
+ | Name | Type | Required | Default | Possible Values | Description |
1818
+ | -------------------- | -------- | -------- | -------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1819
+ | `options` | `object` | ✅ | — | — | |
1820
+ | ​ ↳ `app` | `string` | ✅ | — | — | App slug (e.g., 'github'), implementation name (e.g., 'SlackCLIAPI'), or versioned ID (e.g., 'github@1.2.3') |
1821
+ | ​ ↳ `browser` | `string` | ❌ | `"auto"` | `auto`, `always`, `never` | When to auto-open the URL in a browser. `auto` (default) opens in local sessions and skips opening in CI / SSH / headless-Linux. `always` forces the open attempt. `never` skips it. The URL is always printed to stderr regardless — a failed or skipped open degrades gracefully to copy-paste. |
1822
+ | ​ ↳ `timeoutMs` | `number` | ❌ | — | — | How long to wait for the user to complete the connection flow before giving up. Default 5 minutes (300_000). |
1823
+ | ​ ↳ `pollIntervalMs` | `number` | ❌ | — | — | Delay before the first poll request, in ms. Default 3 seconds (3_000). Subsequent polling cadence is managed by the SDK's polling primitive (backoff with sane defaults). |
1824
+
1825
+ **Returns:** `Promise<ConnectionItem>`
1826
+
1827
+ | Name | Type | Required | Possible Values | Description |
1828
+ | ----------- | -------- | -------- | --------------- | ------------------------------------------------------------------------------------ |
1829
+ | `data` | `object` | ✅ | — | |
1830
+ | ​ ↳ `id` | `string` | ✅ | — | The new connection's ID. Public UUID when available, falling back to the numeric ID. |
1831
+ | ​ ↳ `app` | `string` | ✅ | — | Versionless app key the connection was created for (e.g., 'SlackCLIAPI'). |
1832
+ | ​ ↳ `title` | `string` | ❌ | — | Human-readable connection title set by the auth flow, when available. |
1833
+
1834
+ **Example:**
1835
+
1836
+ ```typescript
1837
+ const result = await zapier.createConnection({
1838
+ app: "example-app",
1839
+ });
1840
+ ```
1841
+
1805
1842
  #### `findFirstConnection`
1806
1843
 
1807
1844
  Find the first connection matching the criteria
@@ -1964,6 +2001,47 @@ Execute getConnection
1964
2001
  const { data: connection } = await zapier.getConnection();
1965
2002
  ```
1966
2003
 
2004
+ #### `getConnectionStartUrl`
2005
+
2006
+ Mint a short-lived URL that begins an SDK-initiated connection flow. The URL is signed by zapier.com and bound to the current user/account — opening it in a different browser session will fail the binding check. Returns the URL as data so the caller decides what to do with it.
2007
+
2008
+ Use this directly (rather than the higher-level `create-connection`) when you want either of: (a) hand off the URL and _not_ block waiting for completion — call this alone, skip `wait-for-new-connection` entirely, or (b) do something custom between minting the URL and waiting for the connection — call this, then email or DM the URL, render it as a QR code for mobile sign-in, etc., then call `wait-for-new-connection`. For the common case where you'd just print and poll back-to-back, `create-connection` is one call.
2009
+
2010
+ Pair with `wait-for-new-connection` to detect completion: pass the `startedAt` returned here straight through (it's the server's mint time, so polling isn't affected by client clock skew). Example (JS):
2011
+
2012
+ ```ts
2013
+ const {
2014
+ data: { url, app, startedAt },
2015
+ } = await zapier.getConnectionStartUrl({ app: "slack" });
2016
+ // hand `url` off — print it, DM it, email it, render a button, whatever
2017
+ const { data: conn } = await zapier.waitForNewConnection({ app, startedAt });
2018
+ ```
2019
+
2020
+ **Parameters:**
2021
+
2022
+ | Name | Type | Required | Default | Possible Values | Description |
2023
+ | --------- | -------- | -------- | ------- | --------------- | ------------------------------------------------------------------------------------------------------------ |
2024
+ | `options` | `object` | ✅ | — | — | |
2025
+ | ​ ↳ `app` | `string` | ✅ | — | — | App slug (e.g., 'github'), implementation name (e.g., 'SlackCLIAPI'), or versioned ID (e.g., 'github@1.2.3') |
2026
+
2027
+ **Returns:** `Promise<ConnectionStartUrlItem>`
2028
+
2029
+ | Name | Type | Required | Possible Values | Description |
2030
+ | --------------- | -------- | -------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2031
+ | `data` | `object` | ✅ | — | |
2032
+ | ​ ↳ `url` | `string` | ✅ | — | URL the user should open in their browser to complete the auth flow. Single-use, time-limited. |
2033
+ | ​ ↳ `expiresAt` | `number` | ✅ | — | Unix timestamp (seconds) after which the URL's signature is rejected by zapier.com. |
2034
+ | ​ ↳ `startedAt` | `number` | ✅ | — | Unix timestamp (seconds) when the server minted the URL. Use it as the `startedAt` for `wait-for-new-connection` so polling is anchored to server time rather than a possibly-skewed client clock. |
2035
+ | ​ ↳ `app` | `string` | ✅ | — | Versionless app key the URL was minted for (e.g., 'SlackCLIAPI'). Useful for downstream filtering. |
2036
+
2037
+ **Example:**
2038
+
2039
+ ```typescript
2040
+ const result = await zapier.getConnectionStartUrl({
2041
+ app: "example-app",
2042
+ });
2043
+ ```
2044
+
1967
2045
  #### `listConnections`
1968
2046
 
1969
2047
  List available connections with optional filtering
@@ -2036,6 +2114,46 @@ for await (const connection of zapier.listConnections().items()) {
2036
2114
  }
2037
2115
  ```
2038
2116
 
2117
+ #### `waitForNewConnection`
2118
+
2119
+ Wait for a new connection to appear for the given app. Polls `/api/v0/connections` with server-side `ordering=-date` until the most recent matching row's `date` is at or after the started-at timestamp, then returns it. Pair with `get-connection-start-url` — that mints the URL the user opens, this waits for the resulting connection to land. Errors with a timeout after the configured timeout (default 5 min). Example (JS):
2120
+
2121
+ ```ts
2122
+ const {
2123
+ data: { url, app, startedAt },
2124
+ } = await zapier.getConnectionStartUrl({ app: "slack" });
2125
+ // show `url` to the user via the channel they're reading from
2126
+ const { data: conn } = await zapier.waitForNewConnection({ app, startedAt });
2127
+ ```
2128
+
2129
+ **Parameters:**
2130
+
2131
+ | Name | Type | Required | Default | Possible Values | Description |
2132
+ | -------------------- | -------- | -------- | ------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2133
+ | `options` | `object` | ✅ | — | — | |
2134
+ | ​ ↳ `app` | `string` | ✅ | — | — | App slug (e.g., 'github'), implementation name (e.g., 'SlackCLIAPI'), or versioned ID (e.g., 'github@1.2.3') |
2135
+ | ​ ↳ `startedAt` | `number` | ✅ | — | — | Unix timestamp (seconds). Only connections whose `date` is at or after this value count as 'new'. Prefer the `startedAt` returned by `get-connection-start-url` — it's server-stamped, so the comparison isn't thrown off by client clock skew. If you mint the timestamp yourself, capture it _before_ showing the start URL so a fast OAuth completion isn't missed. |
2136
+ | ​ ↳ `timeoutMs` | `number` | ❌ | — | — | How long to wait before giving up. Default 5 minutes (300_000). |
2137
+ | ​ ↳ `pollIntervalMs` | `number` | ❌ | — | — | Delay before the first poll request, in ms. Default 3 seconds (3_000). Subsequent polling cadence is managed by the SDK's polling primitive (backoff with sane defaults). |
2138
+
2139
+ **Returns:** `Promise<ConnectionItem>`
2140
+
2141
+ | Name | Type | Required | Possible Values | Description |
2142
+ | ----------- | -------- | -------- | --------------- | ------------------------------------------------------------------------------------ |
2143
+ | `data` | `object` | ✅ | — | |
2144
+ | ​ ↳ `id` | `string` | ✅ | — | The new connection's ID. Public UUID when available, falling back to the numeric ID. |
2145
+ | ​ ↳ `app` | `string` | ✅ | — | Versionless app key the connection was created for (e.g., 'SlackCLIAPI'). |
2146
+ | ​ ↳ `title` | `string` | ❌ | — | Human-readable connection title set by the auth flow, when available. |
2147
+
2148
+ **Example:**
2149
+
2150
+ ```typescript
2151
+ const { data: connection } = await zapier.waitForNewConnection({
2152
+ app: "example-app",
2153
+ startedAt: 100,
2154
+ });
2155
+ ```
2156
+
2039
2157
  ### HTTP Requests
2040
2158
 
2041
2159
  #### `fetch`
@@ -0,0 +1,25 @@
1
+ import type { FetchStreamInit } from "./types";
2
+ import type { JsonSseMessage } from "./sse-parser";
3
+ interface ApprovalReviewMessagePayload {
4
+ kind: "message";
5
+ message: string;
6
+ data: unknown;
7
+ }
8
+ interface ApprovalReviewDecisionPayload {
9
+ kind: "decision";
10
+ decision: "approved" | "denied";
11
+ reason?: string;
12
+ data: unknown;
13
+ }
14
+ export type ApprovalReviewStreamPayload = ApprovalReviewMessagePayload | ApprovalReviewDecisionPayload;
15
+ interface ConsumeApprovalReviewStreamOptions {
16
+ approvalId: string;
17
+ streamUrl: string;
18
+ signal: AbortSignal;
19
+ stream: (url: string, init?: FetchStreamInit) => AsyncGenerator<JsonSseMessage>;
20
+ emitEvent: (type: string, payload: Record<string, unknown>) => void;
21
+ }
22
+ export declare function consumeApprovalReviewStream({ approvalId, streamUrl, signal, stream, emitEvent, }: ConsumeApprovalReviewStreamOptions): Promise<void>;
23
+ export declare function parseApprovalReviewStreamPayload(parsed: unknown, toolNames: Map<string, string>): ApprovalReviewStreamPayload | undefined;
24
+ export {};
25
+ //# sourceMappingURL=approval-review-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-review-stream.d.ts","sourceRoot":"","sources":["../../src/api/approval-review-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAmCnD,UAAU,4BAA4B;IACpC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,UAAU,6BAA6B;IACrC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,UAAU,GAAG,QAAQ,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,2BAA2B,GACnC,4BAA4B,GAC5B,6BAA6B,CAAC;AAElC,UAAU,kCAAkC;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,EAAE,CACN,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,eAAe,KACnB,cAAc,CAAC,cAAc,CAAC,CAAC;IACpC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACrE;AAED,wBAAsB,2BAA2B,CAAC,EAChD,UAAU,EACV,SAAS,EACT,MAAM,EACN,MAAM,EACN,SAAS,GACV,EAAE,kCAAkC,GAAG,OAAO,CAAC,IAAI,CAAC,CA0CpD;AAED,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,2BAA2B,GAAG,SAAS,CA8BzC"}
@@ -0,0 +1,104 @@
1
+ import { isAbortError } from "../utils/abort-utils";
2
+ import { z } from "zod";
3
+ const ApprovalReviewChunkSchema = z.discriminatedUnion("type", [
4
+ z
5
+ .object({
6
+ type: z.literal("text-delta"),
7
+ delta: z.string(),
8
+ })
9
+ .passthrough(),
10
+ z
11
+ .object({
12
+ type: z.literal("tool-input-available"),
13
+ toolCallId: z.string(),
14
+ toolName: z.string(),
15
+ })
16
+ .passthrough(),
17
+ z
18
+ .object({
19
+ type: z.literal("tool-output-available"),
20
+ toolCallId: z.string(),
21
+ output: z.unknown(),
22
+ })
23
+ .passthrough(),
24
+ ]);
25
+ const ReportDecisionOutputSchema = z
26
+ .object({
27
+ success: z.boolean().optional(),
28
+ decision: z.enum(["approved", "denied"]),
29
+ reason: z.string().optional(),
30
+ })
31
+ .passthrough();
32
+ export async function consumeApprovalReviewStream({ approvalId, streamUrl, signal, stream, emitEvent, }) {
33
+ try {
34
+ const toolNames = new Map();
35
+ for await (const frame of stream(streamUrl, {
36
+ method: "GET",
37
+ headers: {
38
+ "Accept-Encoding": "identity",
39
+ },
40
+ signal,
41
+ })) {
42
+ if (!frame.parsed)
43
+ continue;
44
+ const payload = parseApprovalReviewStreamPayload(frame.data, toolNames);
45
+ if (!payload)
46
+ continue;
47
+ if (payload.kind === "message") {
48
+ emitEvent("approval:review_message", {
49
+ approvalId,
50
+ streamUrl,
51
+ data: payload.data,
52
+ message: payload.message,
53
+ });
54
+ continue;
55
+ }
56
+ emitEvent("approval:review_decision", {
57
+ approvalId,
58
+ streamUrl,
59
+ data: payload.data,
60
+ decision: payload.decision,
61
+ ...(payload.reason ? { reason: payload.reason } : {}),
62
+ });
63
+ }
64
+ }
65
+ catch (err) {
66
+ if (isAbortError(err) || signal.aborted)
67
+ return;
68
+ emitEvent("approval:review_stream_error", {
69
+ approvalId,
70
+ streamUrl,
71
+ message: err instanceof Error ? err.message : String(err),
72
+ });
73
+ }
74
+ }
75
+ export function parseApprovalReviewStreamPayload(parsed, toolNames) {
76
+ const chunk = ApprovalReviewChunkSchema.safeParse(parsed);
77
+ if (!chunk.success)
78
+ return undefined;
79
+ switch (chunk.data.type) {
80
+ case "text-delta": {
81
+ const message = chunk.data.delta.trim();
82
+ return message.length > 0
83
+ ? { kind: "message", data: parsed, message }
84
+ : undefined;
85
+ }
86
+ case "tool-input-available":
87
+ toolNames.set(chunk.data.toolCallId, chunk.data.toolName);
88
+ return undefined;
89
+ case "tool-output-available": {
90
+ if (toolNames.get(chunk.data.toolCallId) !== "report_decision") {
91
+ return undefined;
92
+ }
93
+ const decision = ReportDecisionOutputSchema.safeParse(chunk.data.output);
94
+ if (!decision.success)
95
+ return undefined;
96
+ return {
97
+ kind: "decision",
98
+ data: parsed,
99
+ decision: decision.data.decision,
100
+ ...(decision.data.reason ? { reason: decision.data.reason } : {}),
101
+ };
102
+ }
103
+ }
104
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAIjB,MAAM,SAAS,CAAC;AAk0CjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAIjB,MAAM,SAAS,CAAC;AA2jDjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAW3D,CAAC"}