@zapier/zapier-sdk 0.69.3 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +10 -1
- package/dist/api/error-classification.d.ts +7 -0
- package/dist/api/error-classification.d.ts.map +1 -1
- package/dist/api/error-classification.js +15 -2
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/sse-parser.d.ts +34 -0
- package/dist/api/sse-parser.d.ts.map +1 -1
- package/dist/api/sse-parser.js +28 -0
- package/dist/api/types.d.ts +9 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +2 -2
- package/dist/experimental.cjs +117 -34
- package/dist/experimental.d.mts +2 -2
- package/dist/experimental.mjs +117 -34
- package/dist/{index-DuFFW71E.d.mts → index-C0bQ5snd.d.mts} +33 -1
- package/dist/{index-DuFFW71E.d.ts → index-C0bQ5snd.d.ts} +33 -1
- package/dist/index.cjs +32 -5
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +32 -5
- package/dist/plugins/triggers/drainTriggerInbox/index.d.ts +4 -2
- package/dist/plugins/triggers/drainTriggerInbox/index.d.ts.map +1 -1
- package/dist/plugins/triggers/drainTriggerInbox/index.js +39 -6
- package/dist/plugins/triggers/watchTriggerInbox/index.d.ts +4 -2
- package/dist/plugins/triggers/watchTriggerInbox/index.d.ts.map +1 -1
- package/dist/plugins/triggers/watchTriggerInbox/index.js +100 -16
- package/dist/plugins/triggers/watchTriggerInbox/sse.d.ts +8 -6
- package/dist/plugins/triggers/watchTriggerInbox/sse.d.ts.map +1 -1
- package/dist/plugins/triggers/watchTriggerInbox/sse.js +11 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6488,13 +6488,16 @@ async function exchangeClientCredentials(options) {
|
|
|
6488
6488
|
},
|
|
6489
6489
|
timestamp: Date.now()
|
|
6490
6490
|
});
|
|
6491
|
-
throw new
|
|
6492
|
-
`Client credentials exchange failed: ${response.status} ${response.statusText}
|
|
6491
|
+
throw new ZapierAuthenticationError(
|
|
6492
|
+
`Client credentials exchange failed: ${response.status} ${response.statusText}`,
|
|
6493
|
+
{ statusCode: response.status }
|
|
6493
6494
|
);
|
|
6494
6495
|
}
|
|
6495
6496
|
const data = await response.json();
|
|
6496
6497
|
if (!data.access_token) {
|
|
6497
|
-
throw new
|
|
6498
|
+
throw new ZapierAuthenticationError(
|
|
6499
|
+
"Client credentials response missing access_token"
|
|
6500
|
+
);
|
|
6498
6501
|
}
|
|
6499
6502
|
onEvent?.({
|
|
6500
6503
|
type: "auth_success",
|
|
@@ -6717,6 +6720,17 @@ async function invalidateCredentialsToken(options) {
|
|
|
6717
6720
|
}
|
|
6718
6721
|
|
|
6719
6722
|
// src/api/sse-parser.ts
|
|
6723
|
+
async function* jsonFrames(source) {
|
|
6724
|
+
for await (const { data } of source) {
|
|
6725
|
+
let frame;
|
|
6726
|
+
try {
|
|
6727
|
+
frame = { parsed: true, data: JSON.parse(data), raw: data };
|
|
6728
|
+
} catch {
|
|
6729
|
+
frame = { parsed: false, data: null, raw: data };
|
|
6730
|
+
}
|
|
6731
|
+
yield frame;
|
|
6732
|
+
}
|
|
6733
|
+
}
|
|
6720
6734
|
function createSseParserStream() {
|
|
6721
6735
|
let buffer = "";
|
|
6722
6736
|
let data = "";
|
|
@@ -6764,7 +6778,7 @@ function createSseParserStream() {
|
|
|
6764
6778
|
}
|
|
6765
6779
|
|
|
6766
6780
|
// src/sdk-version.ts
|
|
6767
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
6781
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.70.0" : void 0) || "unknown";
|
|
6768
6782
|
|
|
6769
6783
|
// src/utils/open-url.ts
|
|
6770
6784
|
var nodePrefix = "node:";
|
|
@@ -7139,6 +7153,15 @@ var ZapierApiClient = class {
|
|
|
7139
7153
|
* never pins a slot — see `withSemaphore`.
|
|
7140
7154
|
*/
|
|
7141
7155
|
this.fetchStream = (path, init) => this.streamSse(path, init);
|
|
7156
|
+
/**
|
|
7157
|
+
* Like `fetchStream`, but parses each frame's `data` as JSON. Diverges from
|
|
7158
|
+
* `fetchJson` deliberately: that throws on invalid JSON, but a long-lived
|
|
7159
|
+
* stream must survive a single malformed frame, so a parse failure is yielded
|
|
7160
|
+
* as `{ parsed: false, data: null, raw }` rather than thrown. A non-ok
|
|
7161
|
+
* response still throws the shared `ZapierError` (from `fetchStream`, before
|
|
7162
|
+
* any frame), so transport / auth failures surface as usual.
|
|
7163
|
+
*/
|
|
7164
|
+
this.fetchJsonStream = (path, init) => jsonFrames(this.fetchStream(path, init));
|
|
7142
7165
|
this.get = async (path, options = {}) => {
|
|
7143
7166
|
return this.fetchJson("GET", path, void 0, options);
|
|
7144
7167
|
};
|
|
@@ -7704,7 +7727,11 @@ var createZapierApi = (options) => {
|
|
|
7704
7727
|
|
|
7705
7728
|
// src/api/error-classification.ts
|
|
7706
7729
|
function isPermanentHttpError(err) {
|
|
7707
|
-
|
|
7730
|
+
if (!(err instanceof ZapierError)) return false;
|
|
7731
|
+
if (err instanceof ZapierAuthenticationError && err.statusCode === void 0) {
|
|
7732
|
+
return true;
|
|
7733
|
+
}
|
|
7734
|
+
const { statusCode } = err;
|
|
7708
7735
|
return statusCode !== void 0 && statusCode >= 400 && statusCode < 500 && statusCode !== 429;
|
|
7709
7736
|
}
|
|
7710
7737
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { x as Action, f as ActionEntry, cb as ActionExecutionOptions, I as ActionExecutionResult, J as ActionField, K as ActionFieldChoice, aP as ActionItem, bp as ActionKeyProperty, aZ as ActionKeyPropertySchema, bq as ActionProperty, a_ as ActionPropertySchema, aE as ActionResolverItem, bB as ActionTimeoutMsProperty, b9 as ActionTimeoutMsPropertySchema, aF as ActionTypeItem, bo as ActionTypeProperty, aY as ActionTypePropertySchema, d as AddActionEntryOptions, e as AddActionEntryResult, A as ApiClient, c7 as ApiError, dB as ApiEvent, cV as ApiPluginOptions, cX as ApiPluginProvides, y as App, cc as AppFactoryInput, aN as AppItem, bm as AppKeyProperty, aW as AppKeyPropertySchema, bn as AppProperty, aX as AppPropertySchema, eK as ApplicationLifecycleEventData, c3 as ApprovalStatus, ca as AppsPluginProvides, bG as AppsProperty, be as AppsPropertySchema, a5 as ArrayResolver, dA as AuthEvent, bu as AuthenticationIdProperty, b1 as AuthenticationIdPropertySchema, eS as BaseEvent, as as BaseSdkOptionsSchema, ag as BatchOptions, cI as CONTEXT_CACHE_MAX_SIZE, cH as CONTEXT_CACHE_TTL_MS, aw as CORE_ERROR_SYMBOL, H as Choice, dH as ClientCredentialsObject, dS as ClientCredentialsObjectSchema, V as Connection, d_ as ConnectionEntry, dZ as ConnectionEntrySchema, bs as ConnectionIdProperty, b0 as ConnectionIdPropertySchema, aO as ConnectionItem, bt as ConnectionProperty, b2 as ConnectionPropertySchema, e0 as ConnectionsMap, d$ as ConnectionsMapSchema, e2 as ConnectionsPluginProvides, bI as ConnectionsProperty, bg as ConnectionsPropertySchema, X as ConnectionsResponse, ax as CoreErrorCode, cu as CreateClientCredentialsPluginProvides, es as CreateTableFieldsPluginProvides, em as CreateTablePluginProvides, eA as CreateTableRecordsPluginProvides, dE as Credentials, dX as CredentialsFunction, dW as CredentialsFunctionSchema, dG as CredentialsObject, dU as CredentialsObjectSchema, dY as CredentialsSchema, e7 as DEFAULT_ACTION_TIMEOUT_MS, ef as DEFAULT_APPROVAL_TIMEOUT_MS, cR as DEFAULT_CONFIG_PATH, eg as DEFAULT_MAX_APPROVAL_RETRIES, e6 as DEFAULT_PAGE_SIZE, bz as DebugProperty, b7 as DebugPropertySchema, cw as DeleteClientCredentialsPluginProvides, eu as DeleteTableFieldsPluginProvides, eo as DeleteTablePluginProvides, eC as DeleteTableRecordsPluginProvides, s as DrainTriggerInboxCallback, t as DrainTriggerInboxErrorObserver, D as DrainTriggerInboxOptions, a8 as DynamicListResolver, l as DynamicResolver, a9 as DynamicSearchResolver, eL as EnhancedErrorEventData, bO as ErrorOptions, dD as EventCallback, eJ as EventContext, eG as EventEmissionConfig, E as EventEmissionContext, eI as EventEmissionProvides, ce as FetchPluginProvides, z as Field, bF as FieldsProperty, bd as FieldsPropertySchema, aa as FieldsResolver, F as FieldsetItem, v as FindFirstAuthenticationPluginProvides, cE as FindFirstConnectionPluginProvides, w as FindUniqueAuthenticationPluginProvides, cG as FindUniqueConnectionPluginProvides, a3 as FormattedItem, ar as FunctionDeprecation, aq as FunctionRegistryEntry, co as GetActionInputFieldsSchemaPluginProvides, cA as GetActionPluginProvides, cy as GetAppPluginProvides, G as GetAuthenticationPluginProvides, cC as GetConnectionPluginProvides, cU as GetProfilePluginProvides, ek as GetTablePluginProvides, ew as GetTableRecordPluginProvides, aR as InfoFieldItem, aQ as InputFieldItem, br as InputFieldProperty, a$ as InputFieldPropertySchema, bv as InputsProperty, b3 as InputsPropertySchema, bN as LeaseLimitProperty, bl as LeaseLimitPropertySchema, bL as LeaseProperty, bj as LeasePropertySchema, bM as LeaseSecondsProperty, bk as LeaseSecondsPropertySchema, L as LeasedTriggerMessageItem, bw as LimitProperty, b4 as LimitPropertySchema, cm as ListActionInputFieldChoicesPluginProvides, ck as ListActionInputFieldsPluginProvides, ci as ListActionsPluginProvides, cg as ListAppsPluginProvides, u as ListAuthenticationsPluginProvides, cs as ListClientCredentialsPluginProvides, cq as ListConnectionsPluginProvides, eq as ListTableFieldsPluginProvides, ey as ListTableRecordsPluginProvides, ei as ListTablesPluginProvides, dC as LoadingEvent, ea as MAX_CONCURRENCY_LIMIT, e5 as MAX_PAGE_LIMIT, b as Manifest, cS as ManifestEntry, cN as ManifestPluginOptions, cQ as ManifestPluginProvides, eT as MethodCalledEvent, eM as MethodCalledEventData, N as Need, Q as NeedsRequest, S as NeedsResponse, bx as OffsetProperty, b5 as OffsetPropertySchema, O as OutputFormatter, by as OutputProperty, b6 as OutputPropertySchema, aV as PaginatedSdkFunction, i as PaginatedSdkResult, bA as ParamsProperty, b8 as ParamsPropertySchema, dI as PkceCredentialsObject, dT as PkceCredentialsObjectSchema, ay as Plugin, a as PluginMeta, az as PluginProvides, aI as PollOptions, j as PositionalMetadata, c1 as RateLimitInfo, bD as RecordProperty, bb as RecordPropertySchema, bE as RecordsProperty, bc as RecordsPropertySchema, al as RelayFetchSchema, ak as RelayRequestSchema, aH as RequestOptions, cM as RequestPluginProvides, dm as ResolveAuthTokenOptions, dN as ResolveCredentialsOptions, R as ResolvedAppLocator, dF as ResolvedCredentials, dV as ResolvedCredentialsSchema, a4 as Resolver, a6 as ResolverMetadata, aS as RootFieldItem, cK as RunActionPluginProvides, dz as SdkEvent, aU as SdkPage, aM as SseMessage, a7 as StaticResolver, bC as TableProperty, ba as TablePropertySchema, bH as TablesProperty, bf as TablesPropertySchema, bK as TriggerInboxNameProperty, bi as TriggerInboxNamePropertySchema, bJ as TriggerInboxProperty, bh as TriggerInboxPropertySchema, T as TriggerMessageStatus, U as UpdateManifestEntryOptions, c as UpdateManifestEntryResult, eE as UpdateTableRecordsPluginProvides, Y as UserProfile, aT as UserProfileItem, W as WatchTriggerInboxOptions, o as WithAddPlugin, e3 as ZAPIER_BASE_URL, ec as ZAPIER_MAX_CONCURRENT_REQUESTS, e8 as ZAPIER_MAX_NETWORK_RETRIES, e9 as ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, p as ZapierAbortDrainSignal, b$ as ZapierActionError, bU as ZapierApiError, bV as ZapierAppNotFoundError, c4 as ZapierApprovalError, bS as ZapierAuthenticationError, bZ as ZapierBundleError, dv as ZapierCache, dw as ZapierCacheEntry, dx as ZapierCacheSetOptions, bY as ZapierConfigurationError, c0 as ZapierConflictError, bP as ZapierError, k as ZapierFetchInitOptions, bW as ZapierNotFoundError, c2 as ZapierRateLimitError, c5 as ZapierRelayError, q as ZapierReleaseTriggerMessageSignal, bX as ZapierResourceNotFoundError, f3 as ZapierSdk, n as ZapierSdkApps, Z as ZapierSdkOptions, c8 as ZapierSignal, b_ as ZapierTimeoutError, bR as ZapierUnknownError, bQ as ZapierValidationError, c_ as actionKeyResolver, cZ as actionTypeResolver, a2 as addPlugin, cW as apiPlugin, cY as appKeyResolver, c9 as appsPlugin, d0 as authenticationIdGenericResolver, c$ as authenticationIdResolver, af as batch, eN as buildApplicationLifecycleEvent, ah as buildCapabilityMessage, eP as buildErrorEvent, eO as buildErrorEventWithContext, eR as buildMethodCalledEvent, eF as cleanupEventListeners, dn as clearTokenCache, d4 as clientCredentialsNameResolver, d5 as clientIdResolver, aD as composePlugins, d0 as connectionIdGenericResolver, c$ as connectionIdResolver, e1 as connectionsPlugin, eQ as createBaseEvent, ct as createClientCredentialsPlugin, a1 as createCorePlugin, $ as createFunction, dy as createMemoryCache, ao as createOptionsPlugin, aC as createPaginatedPluginMethod, aB as createPluginMethod, a0 as createPluginStack, an as createSdk, er as createTableFieldsPlugin, el as createTablePlugin, ez as createTableRecordsPlugin, aJ as createZapierApi, ap as createZapierCoreStack, f1 as createZapierSdk, f2 as createZapierSdkStack, am as createZapierSdkWithoutRegistry, aA as definePlugin, cv as deleteClientCredentialsPlugin, et as deleteTableFieldsPlugin, en as deleteTablePlugin, eB as deleteTableRecordsPlugin, d9 as durableRunIdResolver, eH as eventEmissionPlugin, cd as fetchPlugin, cD as findFirstConnectionPlugin, g as findManifestEntry, cF as findUniqueConnectionPlugin, c6 as formatErrorMessage, eU as generateEventId, cn as getActionInputFieldsSchemaPlugin, cz as getActionPlugin, cx as getAppPlugin, dQ as getBaseUrlFromCredentials, e_ as getCiPlatform, dR as getClientIdFromCredentials, cB as getConnectionPlugin, av as getCoreErrorCause, au as getCoreErrorCode, f0 as getCpuTime, eV as getCurrentTimestamp, e$ as getMemoryUsage, aK as getOrCreateApiClient, eX as getOsInfo, eY as getPlatformVersions, cO as getPreferredManifestEntryKey, cT as getProfilePlugin, eW as getReleaseId, ej as getTablePlugin, ev as getTableRecordPlugin, ds as getTokenFromCliLogin, ed as getZapierApprovalMode, ee as getZapierDefaultApprovalMode, e4 as getZapierSdkService, dq as injectCliLogin, d3 as inputFieldKeyResolver, d2 as inputsAllOptionalResolver, d1 as inputsResolver, dp as invalidateCachedToken, du as invalidateCredentialsToken, eZ as isCi, dr as isCliLoginAvailable, dJ as isClientCredentials, at as isCoreError, dM as isCredentialsFunction, dL as isCredentialsObject, aL as isPermanentHttpError, dK as isPkceCredentials, _ as isPositional, cl as listActionInputFieldChoicesPlugin, cj as listActionInputFieldsPlugin, ch as listActionsPlugin, cf as listAppsPlugin, cr as listClientCredentialsPlugin, cp as listConnectionsPlugin, ep as listTableFieldsPlugin, ex as listTableRecordsPlugin, eh as listTablesPlugin, ai as logDeprecation, cP as manifestPlugin, eb as parseConcurrencyEnvVar, r as readManifestFromFile, aG as registryPlugin, cL as requestPlugin, aj as resetDeprecationWarnings, dt as resolveAuthToken, dP as resolveCredentials, dO as resolveCredentialsFromEnv, cJ as runActionPlugin, ab as runInMethodScope, ac as runWithTelemetryContext, df as tableFieldIdsResolver, dh as tableFieldsResolver, dk as tableFiltersResolver, d6 as tableIdResolver, dg as tableNameResolver, dd as tableRecordIdResolver, de as tableRecordIdsResolver, di as tableRecordsResolver, dl as tableSortResolver, dj as tableUpdateRecordsResolver, ad as toSnakeCase, ae as toTitleCase, d7 as triggerInboxResolver, dc as triggerMessagesResolver, eD as updateTableRecordsPlugin, d8 as workflowIdResolver, db as workflowRunIdResolver, da as workflowVersionIdResolver, bT as zapierAdaptError } from './index-DuFFW71E.mjs';
|
|
1
|
+
export { x as Action, f as ActionEntry, cc as ActionExecutionOptions, I as ActionExecutionResult, J as ActionField, K as ActionFieldChoice, aQ as ActionItem, bq as ActionKeyProperty, a_ as ActionKeyPropertySchema, br as ActionProperty, a$ as ActionPropertySchema, aE as ActionResolverItem, bC as ActionTimeoutMsProperty, ba as ActionTimeoutMsPropertySchema, aF as ActionTypeItem, bp as ActionTypeProperty, aZ as ActionTypePropertySchema, d as AddActionEntryOptions, e as AddActionEntryResult, A as ApiClient, c8 as ApiError, dC as ApiEvent, cW as ApiPluginOptions, cY as ApiPluginProvides, y as App, cd as AppFactoryInput, aO as AppItem, bn as AppKeyProperty, aX as AppKeyPropertySchema, bo as AppProperty, aY as AppPropertySchema, eL as ApplicationLifecycleEventData, c4 as ApprovalStatus, cb as AppsPluginProvides, bH as AppsProperty, bf as AppsPropertySchema, a5 as ArrayResolver, dB as AuthEvent, bv as AuthenticationIdProperty, b2 as AuthenticationIdPropertySchema, eT as BaseEvent, as as BaseSdkOptionsSchema, ag as BatchOptions, cJ as CONTEXT_CACHE_MAX_SIZE, cI as CONTEXT_CACHE_TTL_MS, aw as CORE_ERROR_SYMBOL, H as Choice, dI as ClientCredentialsObject, dT as ClientCredentialsObjectSchema, V as Connection, d$ as ConnectionEntry, d_ as ConnectionEntrySchema, bt as ConnectionIdProperty, b1 as ConnectionIdPropertySchema, aP as ConnectionItem, bu as ConnectionProperty, b3 as ConnectionPropertySchema, e1 as ConnectionsMap, e0 as ConnectionsMapSchema, e3 as ConnectionsPluginProvides, bJ as ConnectionsProperty, bh as ConnectionsPropertySchema, X as ConnectionsResponse, ax as CoreErrorCode, cv as CreateClientCredentialsPluginProvides, et as CreateTableFieldsPluginProvides, en as CreateTablePluginProvides, eB as CreateTableRecordsPluginProvides, dF as Credentials, dY as CredentialsFunction, dX as CredentialsFunctionSchema, dH as CredentialsObject, dV as CredentialsObjectSchema, dZ as CredentialsSchema, e8 as DEFAULT_ACTION_TIMEOUT_MS, eg as DEFAULT_APPROVAL_TIMEOUT_MS, cS as DEFAULT_CONFIG_PATH, eh as DEFAULT_MAX_APPROVAL_RETRIES, e7 as DEFAULT_PAGE_SIZE, bA as DebugProperty, b8 as DebugPropertySchema, cx as DeleteClientCredentialsPluginProvides, ev as DeleteTableFieldsPluginProvides, ep as DeleteTablePluginProvides, eD as DeleteTableRecordsPluginProvides, s as DrainTriggerInboxCallback, t as DrainTriggerInboxErrorObserver, D as DrainTriggerInboxOptions, a8 as DynamicListResolver, l as DynamicResolver, a9 as DynamicSearchResolver, eM as EnhancedErrorEventData, bP as ErrorOptions, dE as EventCallback, eK as EventContext, eH as EventEmissionConfig, E as EventEmissionContext, eJ as EventEmissionProvides, cf as FetchPluginProvides, z as Field, bG as FieldsProperty, be as FieldsPropertySchema, aa as FieldsResolver, F as FieldsetItem, v as FindFirstAuthenticationPluginProvides, cF as FindFirstConnectionPluginProvides, w as FindUniqueAuthenticationPluginProvides, cH as FindUniqueConnectionPluginProvides, a3 as FormattedItem, ar as FunctionDeprecation, aq as FunctionRegistryEntry, cp as GetActionInputFieldsSchemaPluginProvides, cB as GetActionPluginProvides, cz as GetAppPluginProvides, G as GetAuthenticationPluginProvides, cD as GetConnectionPluginProvides, cV as GetProfilePluginProvides, el as GetTablePluginProvides, ex as GetTableRecordPluginProvides, aS as InfoFieldItem, aR as InputFieldItem, bs as InputFieldProperty, b0 as InputFieldPropertySchema, bw as InputsProperty, b4 as InputsPropertySchema, aN as JsonSseMessage, bO as LeaseLimitProperty, bm as LeaseLimitPropertySchema, bM as LeaseProperty, bk as LeasePropertySchema, bN as LeaseSecondsProperty, bl as LeaseSecondsPropertySchema, L as LeasedTriggerMessageItem, bx as LimitProperty, b5 as LimitPropertySchema, cn as ListActionInputFieldChoicesPluginProvides, cl as ListActionInputFieldsPluginProvides, cj as ListActionsPluginProvides, ch as ListAppsPluginProvides, u as ListAuthenticationsPluginProvides, ct as ListClientCredentialsPluginProvides, cr as ListConnectionsPluginProvides, er as ListTableFieldsPluginProvides, ez as ListTableRecordsPluginProvides, ej as ListTablesPluginProvides, dD as LoadingEvent, eb as MAX_CONCURRENCY_LIMIT, e6 as MAX_PAGE_LIMIT, b as Manifest, cT as ManifestEntry, cO as ManifestPluginOptions, cR as ManifestPluginProvides, eU as MethodCalledEvent, eN as MethodCalledEventData, N as Need, Q as NeedsRequest, S as NeedsResponse, by as OffsetProperty, b6 as OffsetPropertySchema, O as OutputFormatter, bz as OutputProperty, b7 as OutputPropertySchema, aW as PaginatedSdkFunction, i as PaginatedSdkResult, bB as ParamsProperty, b9 as ParamsPropertySchema, dJ as PkceCredentialsObject, dU as PkceCredentialsObjectSchema, ay as Plugin, a as PluginMeta, az as PluginProvides, aI as PollOptions, j as PositionalMetadata, c2 as RateLimitInfo, bE as RecordProperty, bc as RecordPropertySchema, bF as RecordsProperty, bd as RecordsPropertySchema, al as RelayFetchSchema, ak as RelayRequestSchema, aH as RequestOptions, cN as RequestPluginProvides, dn as ResolveAuthTokenOptions, dO as ResolveCredentialsOptions, R as ResolvedAppLocator, dG as ResolvedCredentials, dW as ResolvedCredentialsSchema, a4 as Resolver, a6 as ResolverMetadata, aT as RootFieldItem, cL as RunActionPluginProvides, dA as SdkEvent, aV as SdkPage, aM as SseMessage, a7 as StaticResolver, bD as TableProperty, bb as TablePropertySchema, bI as TablesProperty, bg as TablesPropertySchema, bL as TriggerInboxNameProperty, bj as TriggerInboxNamePropertySchema, bK as TriggerInboxProperty, bi as TriggerInboxPropertySchema, T as TriggerMessageStatus, U as UpdateManifestEntryOptions, c as UpdateManifestEntryResult, eF as UpdateTableRecordsPluginProvides, Y as UserProfile, aU as UserProfileItem, W as WatchTriggerInboxOptions, o as WithAddPlugin, e4 as ZAPIER_BASE_URL, ed as ZAPIER_MAX_CONCURRENT_REQUESTS, e9 as ZAPIER_MAX_NETWORK_RETRIES, ea as ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, p as ZapierAbortDrainSignal, c0 as ZapierActionError, bV as ZapierApiError, bW as ZapierAppNotFoundError, c5 as ZapierApprovalError, bT as ZapierAuthenticationError, b_ as ZapierBundleError, dw as ZapierCache, dx as ZapierCacheEntry, dy as ZapierCacheSetOptions, bZ as ZapierConfigurationError, c1 as ZapierConflictError, bQ as ZapierError, k as ZapierFetchInitOptions, bX as ZapierNotFoundError, c3 as ZapierRateLimitError, c6 as ZapierRelayError, q as ZapierReleaseTriggerMessageSignal, bY as ZapierResourceNotFoundError, f4 as ZapierSdk, n as ZapierSdkApps, Z as ZapierSdkOptions, c9 as ZapierSignal, b$ as ZapierTimeoutError, bS as ZapierUnknownError, bR as ZapierValidationError, c$ as actionKeyResolver, c_ as actionTypeResolver, a2 as addPlugin, cX as apiPlugin, cZ as appKeyResolver, ca as appsPlugin, d1 as authenticationIdGenericResolver, d0 as authenticationIdResolver, af as batch, eO as buildApplicationLifecycleEvent, ah as buildCapabilityMessage, eQ as buildErrorEvent, eP as buildErrorEventWithContext, eS as buildMethodCalledEvent, eG as cleanupEventListeners, dp as clearTokenCache, d5 as clientCredentialsNameResolver, d6 as clientIdResolver, aD as composePlugins, d1 as connectionIdGenericResolver, d0 as connectionIdResolver, e2 as connectionsPlugin, eR as createBaseEvent, cu as createClientCredentialsPlugin, a1 as createCorePlugin, $ as createFunction, dz as createMemoryCache, ao as createOptionsPlugin, aC as createPaginatedPluginMethod, aB as createPluginMethod, a0 as createPluginStack, an as createSdk, es as createTableFieldsPlugin, em as createTablePlugin, eA as createTableRecordsPlugin, aJ as createZapierApi, ap as createZapierCoreStack, f2 as createZapierSdk, f3 as createZapierSdkStack, am as createZapierSdkWithoutRegistry, aA as definePlugin, cw as deleteClientCredentialsPlugin, eu as deleteTableFieldsPlugin, eo as deleteTablePlugin, eC as deleteTableRecordsPlugin, da as durableRunIdResolver, eI as eventEmissionPlugin, ce as fetchPlugin, cE as findFirstConnectionPlugin, g as findManifestEntry, cG as findUniqueConnectionPlugin, c7 as formatErrorMessage, eV as generateEventId, co as getActionInputFieldsSchemaPlugin, cA as getActionPlugin, cy as getAppPlugin, dR as getBaseUrlFromCredentials, e$ as getCiPlatform, dS as getClientIdFromCredentials, cC as getConnectionPlugin, av as getCoreErrorCause, au as getCoreErrorCode, f1 as getCpuTime, eW as getCurrentTimestamp, f0 as getMemoryUsage, aK as getOrCreateApiClient, eY as getOsInfo, eZ as getPlatformVersions, cP as getPreferredManifestEntryKey, cU as getProfilePlugin, eX as getReleaseId, ek as getTablePlugin, ew as getTableRecordPlugin, dt as getTokenFromCliLogin, ee as getZapierApprovalMode, ef as getZapierDefaultApprovalMode, e5 as getZapierSdkService, dr as injectCliLogin, d4 as inputFieldKeyResolver, d3 as inputsAllOptionalResolver, d2 as inputsResolver, dq as invalidateCachedToken, dv as invalidateCredentialsToken, e_ as isCi, ds as isCliLoginAvailable, dK as isClientCredentials, at as isCoreError, dN as isCredentialsFunction, dM as isCredentialsObject, aL as isPermanentHttpError, dL as isPkceCredentials, _ as isPositional, cm as listActionInputFieldChoicesPlugin, ck as listActionInputFieldsPlugin, ci as listActionsPlugin, cg as listAppsPlugin, cs as listClientCredentialsPlugin, cq as listConnectionsPlugin, eq as listTableFieldsPlugin, ey as listTableRecordsPlugin, ei as listTablesPlugin, ai as logDeprecation, cQ as manifestPlugin, ec as parseConcurrencyEnvVar, r as readManifestFromFile, aG as registryPlugin, cM as requestPlugin, aj as resetDeprecationWarnings, du as resolveAuthToken, dQ as resolveCredentials, dP as resolveCredentialsFromEnv, cK as runActionPlugin, ab as runInMethodScope, ac as runWithTelemetryContext, dg as tableFieldIdsResolver, di as tableFieldsResolver, dl as tableFiltersResolver, d7 as tableIdResolver, dh as tableNameResolver, de as tableRecordIdResolver, df as tableRecordIdsResolver, dj as tableRecordsResolver, dm as tableSortResolver, dk as tableUpdateRecordsResolver, ad as toSnakeCase, ae as toTitleCase, d8 as triggerInboxResolver, dd as triggerMessagesResolver, eE as updateTableRecordsPlugin, d9 as workflowIdResolver, dc as workflowRunIdResolver, db as workflowVersionIdResolver, bU as zapierAdaptError } from './index-C0bQ5snd.mjs';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import 'zod/v4/core';
|
|
4
4
|
import '@zapier/zapier-sdk-core/v0/schemas/connections';
|
package/dist/index.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export { registryPlugin } from "./plugins/registry";
|
|
|
73
73
|
export type { ApiClient, RequestOptions, PollOptions } from "./api/types";
|
|
74
74
|
export { createZapierApi, getOrCreateApiClient } from "./api";
|
|
75
75
|
export { isPermanentHttpError } from "./api";
|
|
76
|
-
export type { SseMessage } from "./api";
|
|
76
|
+
export type { SseMessage, JsonSseMessage } from "./api";
|
|
77
77
|
export type { ZapierSdk } from "./sdk";
|
|
78
78
|
export * from "./plugins/eventEmission";
|
|
79
79
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,sBAAsB,EACtB,iCAAiC,GAClC,MAAM,8CAA8C,CAAC;AACtD,YAAY,EACV,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,8CAA8C,CAAC;AACtD,YAAY,EACV,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAG/C,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CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAGxD,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,cAAc,yBAAyB,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -6486,13 +6486,16 @@ async function exchangeClientCredentials(options) {
|
|
|
6486
6486
|
},
|
|
6487
6487
|
timestamp: Date.now()
|
|
6488
6488
|
});
|
|
6489
|
-
throw new
|
|
6490
|
-
`Client credentials exchange failed: ${response.status} ${response.statusText}
|
|
6489
|
+
throw new ZapierAuthenticationError(
|
|
6490
|
+
`Client credentials exchange failed: ${response.status} ${response.statusText}`,
|
|
6491
|
+
{ statusCode: response.status }
|
|
6491
6492
|
);
|
|
6492
6493
|
}
|
|
6493
6494
|
const data = await response.json();
|
|
6494
6495
|
if (!data.access_token) {
|
|
6495
|
-
throw new
|
|
6496
|
+
throw new ZapierAuthenticationError(
|
|
6497
|
+
"Client credentials response missing access_token"
|
|
6498
|
+
);
|
|
6496
6499
|
}
|
|
6497
6500
|
onEvent?.({
|
|
6498
6501
|
type: "auth_success",
|
|
@@ -6715,6 +6718,17 @@ async function invalidateCredentialsToken(options) {
|
|
|
6715
6718
|
}
|
|
6716
6719
|
|
|
6717
6720
|
// src/api/sse-parser.ts
|
|
6721
|
+
async function* jsonFrames(source) {
|
|
6722
|
+
for await (const { data } of source) {
|
|
6723
|
+
let frame;
|
|
6724
|
+
try {
|
|
6725
|
+
frame = { parsed: true, data: JSON.parse(data), raw: data };
|
|
6726
|
+
} catch {
|
|
6727
|
+
frame = { parsed: false, data: null, raw: data };
|
|
6728
|
+
}
|
|
6729
|
+
yield frame;
|
|
6730
|
+
}
|
|
6731
|
+
}
|
|
6718
6732
|
function createSseParserStream() {
|
|
6719
6733
|
let buffer = "";
|
|
6720
6734
|
let data = "";
|
|
@@ -6762,7 +6776,7 @@ function createSseParserStream() {
|
|
|
6762
6776
|
}
|
|
6763
6777
|
|
|
6764
6778
|
// src/sdk-version.ts
|
|
6765
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
6779
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.70.0" : void 0) || "unknown";
|
|
6766
6780
|
|
|
6767
6781
|
// src/utils/open-url.ts
|
|
6768
6782
|
var nodePrefix = "node:";
|
|
@@ -7137,6 +7151,15 @@ var ZapierApiClient = class {
|
|
|
7137
7151
|
* never pins a slot — see `withSemaphore`.
|
|
7138
7152
|
*/
|
|
7139
7153
|
this.fetchStream = (path, init) => this.streamSse(path, init);
|
|
7154
|
+
/**
|
|
7155
|
+
* Like `fetchStream`, but parses each frame's `data` as JSON. Diverges from
|
|
7156
|
+
* `fetchJson` deliberately: that throws on invalid JSON, but a long-lived
|
|
7157
|
+
* stream must survive a single malformed frame, so a parse failure is yielded
|
|
7158
|
+
* as `{ parsed: false, data: null, raw }` rather than thrown. A non-ok
|
|
7159
|
+
* response still throws the shared `ZapierError` (from `fetchStream`, before
|
|
7160
|
+
* any frame), so transport / auth failures surface as usual.
|
|
7161
|
+
*/
|
|
7162
|
+
this.fetchJsonStream = (path, init) => jsonFrames(this.fetchStream(path, init));
|
|
7140
7163
|
this.get = async (path, options = {}) => {
|
|
7141
7164
|
return this.fetchJson("GET", path, void 0, options);
|
|
7142
7165
|
};
|
|
@@ -7702,7 +7725,11 @@ var createZapierApi = (options) => {
|
|
|
7702
7725
|
|
|
7703
7726
|
// src/api/error-classification.ts
|
|
7704
7727
|
function isPermanentHttpError(err) {
|
|
7705
|
-
|
|
7728
|
+
if (!(err instanceof ZapierError)) return false;
|
|
7729
|
+
if (err instanceof ZapierAuthenticationError && err.statusCode === void 0) {
|
|
7730
|
+
return true;
|
|
7731
|
+
}
|
|
7732
|
+
const { statusCode } = err;
|
|
7706
7733
|
return statusCode !== void 0 && statusCode >= 400 && statusCode < 500 && statusCode !== 429;
|
|
7707
7734
|
}
|
|
7708
7735
|
|
|
@@ -5,6 +5,8 @@ import type { AckTriggerInboxMessagesPluginProvides } from "../ackTriggerInboxMe
|
|
|
5
5
|
import type { ReleaseTriggerInboxMessagesPluginProvides } from "../releaseTriggerInboxMessages";
|
|
6
6
|
import type { LeasedTriggerMessageItem } from "../../../schemas/TriggerMessage";
|
|
7
7
|
export { ZapierAbortDrainSignal, ZapierReleaseTriggerMessageSignal, } from "./schemas";
|
|
8
|
+
export declare function markNonRetryableDrainError<E>(err: E): E;
|
|
9
|
+
export declare function isNonRetryableDrainError(err: unknown): boolean;
|
|
8
10
|
interface RunDrainPassOptions {
|
|
9
11
|
sdk: ApiPluginProvides & LeaseTriggerInboxMessagesPluginProvides & AckTriggerInboxMessagesPluginProvides & ReleaseTriggerInboxMessagesPluginProvides;
|
|
10
12
|
inboxId: string;
|
|
@@ -28,8 +30,8 @@ export interface RunDrainPassOutcome {
|
|
|
28
30
|
/**
|
|
29
31
|
* One drain pass through `runBatchedDrainPipeline`. Used directly by
|
|
30
32
|
* `drainTriggerInbox` (single pass) and as the inner loop body of
|
|
31
|
-
* `watchTriggerInbox` (called
|
|
32
|
-
*
|
|
33
|
+
* `watchTriggerInbox` (called once per drain request, with bounded error
|
|
34
|
+
* backoff between passes that fail with a transient error).
|
|
33
35
|
*/
|
|
34
36
|
export declare function runDrainPass(options: RunDrainPassOptions): Promise<RunDrainPassOutcome>;
|
|
35
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/drainTriggerInbox/index.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC9B,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,KAAK,EAAE,q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 @@ import { resolveTriggerInboxId } from "../utils";
|
|
|
8
8
|
import { triggersDefaults } from "../shared";
|
|
9
9
|
import { isAbortError } from "../../../utils/abort-utils";
|
|
10
10
|
export { ZapierAbortDrainSignal, ZapierReleaseTriggerMessageSignal, } from "./schemas";
|
|
11
|
+
/**
|
|
12
|
+
* Drain errors that must NOT be retried, by error identity: a fail-fast handler
|
|
13
|
+
* error (the user's own failure — retrying would re-run a handler that already
|
|
14
|
+
* chose to stop) and an `initialization_failure` (a permanent inbox setup
|
|
15
|
+
* problem). The watch loop retries transient infrastructure errors but consults
|
|
16
|
+
* this set to leave these fatal. A WeakSet rather than a marker property because
|
|
17
|
+
* handler errors are the user's own values and must reach their catch
|
|
18
|
+
* unmodified. `markNonRetryableDrainError` no-ops on a non-object throw (it
|
|
19
|
+
* can't be weakly held), but that case is still fatal without this set: the
|
|
20
|
+
* watch loop classifies any non-object thrown value as non-retryable on its own,
|
|
21
|
+
* since the API client only ever throws Error objects, so a primitive can only
|
|
22
|
+
* be a user fail-fast throw. Permanent HTTP errors are non-retryable too, but
|
|
23
|
+
* the caller classifies those by status code, not via this set.
|
|
24
|
+
*/
|
|
25
|
+
const nonRetryableDrainErrors = new WeakSet();
|
|
26
|
+
export function markNonRetryableDrainError(err) {
|
|
27
|
+
if (typeof err === "object" && err !== null) {
|
|
28
|
+
nonRetryableDrainErrors.add(err);
|
|
29
|
+
}
|
|
30
|
+
return err;
|
|
31
|
+
}
|
|
32
|
+
export function isNonRetryableDrainError(err) {
|
|
33
|
+
return (typeof err === "object" && err !== null && nonRetryableDrainErrors.has(err));
|
|
34
|
+
}
|
|
11
35
|
/**
|
|
12
36
|
* Server returns 400 lease_expired when a UUIDv7 timestamp is in the
|
|
13
37
|
* past. The API atomically quarantines messages that have hit
|
|
@@ -23,13 +47,17 @@ function isLeaseExpiredError(err) {
|
|
|
23
47
|
/**
|
|
24
48
|
* One drain pass through `runBatchedDrainPipeline`. Used directly by
|
|
25
49
|
* `drainTriggerInbox` (single pass) and as the inner loop body of
|
|
26
|
-
* `watchTriggerInbox` (called
|
|
27
|
-
*
|
|
50
|
+
* `watchTriggerInbox` (called once per drain request, with bounded error
|
|
51
|
+
* backoff between passes that fail with a transient error).
|
|
28
52
|
*/
|
|
29
53
|
export async function runDrainPass(options) {
|
|
30
54
|
const { sdk, inboxId, onMessage, concurrency, leaseLimit, leaseSeconds, maxMessages, releaseOnError, continueOnError, onError, signal, } = options;
|
|
31
55
|
let firstFetch = options.firstFetch;
|
|
32
56
|
let abortedFromCallback = false;
|
|
57
|
+
// A boolean rather than a `firstHandlerError !== undefined` sentinel so a
|
|
58
|
+
// handler that throws a falsy value (`throw undefined` / `throw null`) is still
|
|
59
|
+
// captured and surfaced as fatal, not silently swallowed.
|
|
60
|
+
let handlerErrorCaptured = false;
|
|
33
61
|
let firstHandlerError = undefined;
|
|
34
62
|
const outcomes = await runBatchedDrainPipeline({
|
|
35
63
|
concurrency,
|
|
@@ -59,7 +87,7 @@ export async function runDrainPass(options) {
|
|
|
59
87
|
if (lease.results.length === 0) {
|
|
60
88
|
if (firstFetch &&
|
|
61
89
|
lease.inbox_attributes.status === "initialization_failure") {
|
|
62
|
-
throw new ZapierApiError(`Trigger inbox ${inboxId} is in initialization_failure state — inspect via getTriggerInbox.`);
|
|
90
|
+
throw markNonRetryableDrainError(new ZapierApiError(`Trigger inbox ${inboxId} is in initialization_failure state — inspect via getTriggerInbox.`));
|
|
63
91
|
}
|
|
64
92
|
firstFetch = false;
|
|
65
93
|
return "exhausted";
|
|
@@ -108,8 +136,10 @@ export async function runDrainPass(options) {
|
|
|
108
136
|
// Fail-fast: capture the first real error and tell the
|
|
109
137
|
// pipeline to abort. continueOnError keeps it running.
|
|
110
138
|
if (!continueOnError && !(err instanceof ZapierSignal)) {
|
|
111
|
-
if (
|
|
139
|
+
if (!handlerErrorCaptured) {
|
|
112
140
|
firstHandlerError = err;
|
|
141
|
+
handlerErrorCaptured = true;
|
|
142
|
+
}
|
|
113
143
|
abort = true;
|
|
114
144
|
}
|
|
115
145
|
return { value: message, action, abort };
|
|
@@ -142,8 +172,11 @@ export async function runDrainPass(options) {
|
|
|
142
172
|
}
|
|
143
173
|
},
|
|
144
174
|
});
|
|
145
|
-
|
|
146
|
-
|
|
175
|
+
// Mark so the watch loop treats this as fatal and never retries it (a
|
|
176
|
+
// fail-fast handler error means the user already chose to stop).
|
|
177
|
+
if (handlerErrorCaptured) {
|
|
178
|
+
throw markNonRetryableDrainError(firstHandlerError);
|
|
179
|
+
}
|
|
147
180
|
return { abortedFromCallback, processed: outcomes.length };
|
|
148
181
|
}
|
|
149
182
|
/**
|
|
@@ -26,8 +26,10 @@ export declare function createDrainLatch(): DrainLatch;
|
|
|
26
26
|
* `maxDrainIntervalSeconds` seconds (default: 300) to guarantee
|
|
27
27
|
* forward progress if SSE events are missed or the connection drops
|
|
28
28
|
* undetected. Resolves cleanly on `signal` abort or when a callback
|
|
29
|
-
* throws `ZapierAbortDrainSignal
|
|
30
|
-
*
|
|
29
|
+
* throws `ZapierAbortDrainSignal`. Transient drain failures (5xx, 429,
|
|
30
|
+
* network blips) are retried indefinitely with bounded backoff until they
|
|
31
|
+
* succeed or the watch is aborted; it rejects only on a fail-fast handler
|
|
32
|
+
* error, an `initialization_failure`, or a permanent HTTP error.
|
|
31
33
|
*/
|
|
32
34
|
export declare const watchTriggerInboxPlugin: (sdk: {
|
|
33
35
|
context: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/watchTriggerInbox/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/watchTriggerInbox/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,8BAA8B,CAAC;AAoBtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAoCzD,MAAM,WAAW,UAAU;IACzB,8EAA8E;IAC9E,OAAO,IAAI,IAAI,CAAC;IAChB,sEAAsE;IACtE,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,CA2B7C;AAqQD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAMnB;QAAE,OAAO,EAAE,cAAc,CAAA;KAAE;;;;;;iCAI7B,wBAAwB,KAChC,OAAO,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuHnB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,UAAU,CACtD,OAAO,uBAAuB,CAC/B,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { definePlugin } from "kitcore";
|
|
2
2
|
import { WatchTriggerInboxSchema, } from "../drainTriggerInbox/schemas";
|
|
3
|
-
import { requireOnMessage, resolveConcurrencyAndLease, runDrainPass, } from "../drainTriggerInbox";
|
|
3
|
+
import { requireOnMessage, resolveConcurrencyAndLease, runDrainPass, isNonRetryableDrainError, } from "../drainTriggerInbox";
|
|
4
4
|
import { resolveTriggerInboxId } from "../utils";
|
|
5
5
|
import { triggerInboxResolver } from "../../../resolvers";
|
|
6
6
|
import { triggersDefaults } from "../shared";
|
|
7
7
|
import { isAbortError, combineAbortSignals } from "../../../utils/abort-utils";
|
|
8
|
-
import { sleep } from "../../../utils/retry-utils";
|
|
8
|
+
import { sleep, calculateErrorBackoffMs, BASE_ERROR_BACKOFF_MS, } from "../../../utils/retry-utils";
|
|
9
9
|
import { isPermanentHttpError } from "../../../api";
|
|
10
10
|
import { ZapierError } from "../../../types/errors";
|
|
11
11
|
import { readInboxEvents } from "./sse";
|
|
@@ -22,6 +22,14 @@ const DEFAULT_SAFETY_DRAIN_INTERVAL_MS = 300000; // 5 minutes
|
|
|
22
22
|
// recovery from routine server-side cycling (e.g. JWT expiry); a stream that
|
|
23
23
|
// closes sooner is treated as unstable and escalates like any other.
|
|
24
24
|
const SSE_HEALTHY_CONNECTION_MS = 5000;
|
|
25
|
+
// Consecutive transient drain failures escalate the backoff via
|
|
26
|
+
// calculateErrorBackoffMs, whose error term saturates at errorCount 4 (capped at
|
|
27
|
+
// 2x the base interval). Past that the delay no longer grows, so we cap the
|
|
28
|
+
// counter that feeds the backoff there, holding the steady-state ~3.5 s retry
|
|
29
|
+
// cadence. (The separate, intentionally uncapped errorAttempts counter in
|
|
30
|
+
// drainRunner is what the diagnostics report; its unbounded growth is harmless
|
|
31
|
+
// since it only feeds a log string, never the backoff math.)
|
|
32
|
+
const ERROR_BACKOFF_CAP = 4;
|
|
25
33
|
/**
|
|
26
34
|
* Coalescing wake latch between the drain producers (SSE connect, SSE frames,
|
|
27
35
|
* the safety timer, abort) and the single drain consumer. A `request()` that
|
|
@@ -61,11 +69,29 @@ export function createDrainLatch() {
|
|
|
61
69
|
/**
|
|
62
70
|
* Sole caller of `runDrainPass`, so drains are serial and never overlap. Waits
|
|
63
71
|
* for a request, drains the inbox to empty, repeats. The first pass carries
|
|
64
|
-
* `firstFetch: true` (preserving the initialization_failure check).
|
|
65
|
-
*
|
|
72
|
+
* `firstFetch: true` (preserving the initialization_failure check).
|
|
73
|
+
*
|
|
74
|
+
* Transient infrastructure failures (5xx, 429, network blips on lease / ack /
|
|
75
|
+
* release) are retried indefinitely with bounded backoff until they succeed or
|
|
76
|
+
* the watch is aborted — a watch is a "consume until aborted" loop, so a blip (or
|
|
77
|
+
* even a multi-minute outage) must not kill it, mirroring the SSE loop's
|
|
78
|
+
* resilience. The backoff escalates with consecutive failures and resets on the
|
|
79
|
+
* first success. Once retries saturate the backoff, a single warning prints to
|
|
80
|
+
* stderr (re-armed on the next success), mirroring the SSE loop's degraded-state
|
|
81
|
+
* notice; per-retry diagnostics print only under `debug`. A fail-fast handler
|
|
82
|
+
* error, an `initialization_failure`, or a permanent HTTP error is fatal
|
|
83
|
+
* immediately. Returns how the watch ended so the caller can resolve or re-throw.
|
|
66
84
|
*/
|
|
67
|
-
async function drainRunner({ drainOptions, drainRequest, signal, }) {
|
|
85
|
+
async function drainRunner({ drainOptions, drainRequest, signal, inboxId, debug, }) {
|
|
68
86
|
let firstFetch = true;
|
|
87
|
+
let consecutiveErrors = 0;
|
|
88
|
+
// Uncapped, unlike consecutiveErrors: reports the true consecutive-failure count
|
|
89
|
+
// in diagnostics so a long outage doesn't freeze the logged attempt at the
|
|
90
|
+
// backoff cap. Reset on a successful pass.
|
|
91
|
+
let errorAttempts = 0;
|
|
92
|
+
// Mirrors the SSE loop's `degraded`: warn once when retries saturate the
|
|
93
|
+
// backoff, re-armed (silently) on the first successful pass.
|
|
94
|
+
let drainDegraded = false;
|
|
69
95
|
while (!signal.aborted) {
|
|
70
96
|
await drainRequest.waitForRequest();
|
|
71
97
|
if (signal.aborted)
|
|
@@ -78,19 +104,69 @@ async function drainRunner({ drainOptions, drainRequest, signal, }) {
|
|
|
78
104
|
}));
|
|
79
105
|
}
|
|
80
106
|
catch (error) {
|
|
81
|
-
|
|
107
|
+
// Abort is intent, not failure — surface it as a clean stop, uncounted.
|
|
108
|
+
// `signal.aborted` alone is the predicate: every abort of THIS watch has
|
|
109
|
+
// set it by the time the catch runs, so an abort-shaped error arriving
|
|
110
|
+
// without it can only be someone else's (e.g. the user's onMessage leaking
|
|
111
|
+
// its own aborted fetch) — that's a fail-fast handler error and must
|
|
112
|
+
// reject below, not resolve the watch as a clean stop.
|
|
113
|
+
if (signal.aborted)
|
|
114
|
+
return { kind: "aborted" };
|
|
115
|
+
// Fatal, never retried: fail-fast handler errors and initialization_failure
|
|
116
|
+
// are tagged non-retryable; permanent HTTP (4xx — auth / permission /
|
|
117
|
+
// not-found) won't fix itself; and a non-object thrown value can only be a
|
|
118
|
+
// user onMessage fail-fast throw (the API client only throws Error objects),
|
|
119
|
+
// which is the user's own failure. Everything else (5xx, 429, network blip)
|
|
120
|
+
// is transient and retried below.
|
|
121
|
+
const isNonObjectThrow = typeof error !== "object" || error === null;
|
|
122
|
+
if (isNonObjectThrow ||
|
|
123
|
+
isNonRetryableDrainError(error) ||
|
|
124
|
+
isPermanentHttpError(error)) {
|
|
125
|
+
return { kind: "error", error };
|
|
126
|
+
}
|
|
127
|
+
// Transient: retry indefinitely (a watch runs until aborted). The counter
|
|
128
|
+
// only escalates the backoff and is capped where the backoff saturates, so
|
|
129
|
+
// a long outage can't grow it unbounded; a successful pass resets it below.
|
|
130
|
+
consecutiveErrors = Math.min(consecutiveErrors + 1, ERROR_BACKOFF_CAP);
|
|
131
|
+
errorAttempts += 1;
|
|
132
|
+
const delay = calculateErrorBackoffMs(BASE_ERROR_BACKOFF_MS, consecutiveErrors);
|
|
133
|
+
const statusCode = errorStatusCode(error);
|
|
134
|
+
const httpPart = statusCode !== undefined ? ` (HTTP ${statusCode})` : "";
|
|
135
|
+
// Once retries saturate the backoff the watch is making no forward
|
|
136
|
+
// progress, so surface it once on stderr even without `debug` (re-armed on
|
|
137
|
+
// recovery), mirroring how the SSE loop warns when real-time wake-ups pause.
|
|
138
|
+
if (!drainDegraded && consecutiveErrors >= ERROR_BACKOFF_CAP) {
|
|
139
|
+
console.warn(`[zapier-sdk] Draining inbox ${inboxId}${httpPart} is failing ` +
|
|
140
|
+
`repeatedly: ${errorMessage(error)}. Continuing to retry with backoff.`);
|
|
141
|
+
drainDegraded = true;
|
|
142
|
+
}
|
|
143
|
+
if (debug) {
|
|
144
|
+
console.error(`[zapier-sdk] Retrying drain for inbox ${inboxId} ` +
|
|
145
|
+
`(attempt ${errorAttempts}, retry in ${delay}ms)${httpPart}: ${errorMessage(error)}`);
|
|
146
|
+
}
|
|
147
|
+
await sleep(delay, signal);
|
|
148
|
+
if (signal.aborted)
|
|
149
|
+
return { kind: "aborted" };
|
|
150
|
+
// Re-arm the latch so the loop drains again even without an external
|
|
151
|
+
// wake-up (SSE frame / safety timer). firstFetch stays set so a retry of
|
|
152
|
+
// the first pass still runs the initialization_failure check.
|
|
153
|
+
drainRequest.request();
|
|
154
|
+
continue;
|
|
82
155
|
}
|
|
83
156
|
firstFetch = false;
|
|
157
|
+
consecutiveErrors = 0;
|
|
158
|
+
errorAttempts = 0;
|
|
159
|
+
drainDegraded = false;
|
|
84
160
|
if (abortedFromCallback)
|
|
85
161
|
return { kind: "abortedFromCallback" };
|
|
86
162
|
}
|
|
87
163
|
return { kind: "aborted" };
|
|
88
164
|
}
|
|
89
165
|
/** statusCode off any ZapierError (ZapierApiError, ZapierApprovalError, …). */
|
|
90
|
-
function
|
|
166
|
+
function errorStatusCode(err) {
|
|
91
167
|
return err instanceof ZapierError ? err.statusCode : undefined;
|
|
92
168
|
}
|
|
93
|
-
function
|
|
169
|
+
function errorMessage(err) {
|
|
94
170
|
return err instanceof Error ? err.message : String(err);
|
|
95
171
|
}
|
|
96
172
|
/**
|
|
@@ -152,8 +228,8 @@ async function sseLoop({ api, inboxId, drainRequest, safetyDrainMs, signal, debu
|
|
|
152
228
|
return;
|
|
153
229
|
if (isPermanentHttpError(err)) {
|
|
154
230
|
if (!degraded) {
|
|
155
|
-
const statusCode =
|
|
156
|
-
const errorMsg =
|
|
231
|
+
const statusCode = errorStatusCode(err);
|
|
232
|
+
const errorMsg = errorMessage(err);
|
|
157
233
|
const httpPart = statusCode !== undefined ? ` (HTTP ${statusCode})` : "";
|
|
158
234
|
console.warn(`[zapier-sdk] Real-time wake-ups for inbox ${inboxId}${httpPart} ` +
|
|
159
235
|
`paused: ${errorMsg}. Falling back to the periodic safety drain.`);
|
|
@@ -176,8 +252,8 @@ async function sseLoop({ api, inboxId, drainRequest, safetyDrainMs, signal, debu
|
|
|
176
252
|
const delay = SSE_RECONNECT_BACKOFF_MS[Math.min(attempt, SSE_RECONNECT_BACKOFF_MS.length - 1)];
|
|
177
253
|
attempt = Math.min(attempt + 1, SSE_RECONNECT_BACKOFF_MS.length - 1);
|
|
178
254
|
if (transientError !== undefined && debug) {
|
|
179
|
-
const statusCode =
|
|
180
|
-
const errorMsg =
|
|
255
|
+
const statusCode = errorStatusCode(transientError);
|
|
256
|
+
const errorMsg = errorMessage(transientError);
|
|
181
257
|
const httpPart = statusCode !== undefined ? ` (HTTP ${statusCode})` : "";
|
|
182
258
|
console.error(`[zapier-sdk] Reconnecting real-time wake-ups for inbox ${inboxId} ` +
|
|
183
259
|
`(attempt ${attempt}, retry in ${delay}ms)${httpPart}: ${errorMsg}`);
|
|
@@ -209,8 +285,10 @@ async function safetyTimerLoop({ safetyDrainMs, drainRequest, signal, }) {
|
|
|
209
285
|
* `maxDrainIntervalSeconds` seconds (default: 300) to guarantee
|
|
210
286
|
* forward progress if SSE events are missed or the connection drops
|
|
211
287
|
* undetected. Resolves cleanly on `signal` abort or when a callback
|
|
212
|
-
* throws `ZapierAbortDrainSignal
|
|
213
|
-
*
|
|
288
|
+
* throws `ZapierAbortDrainSignal`. Transient drain failures (5xx, 429,
|
|
289
|
+
* network blips) are retried indefinitely with bounded backoff until they
|
|
290
|
+
* succeed or the watch is aborted; it rejects only on a fail-fast handler
|
|
291
|
+
* error, an `initialization_failure`, or a permanent HTTP error.
|
|
214
292
|
*/
|
|
215
293
|
export const watchTriggerInboxPlugin = definePlugin((sdk) => {
|
|
216
294
|
async function watchTriggerInbox(options) {
|
|
@@ -265,7 +343,13 @@ export const watchTriggerInboxPlugin = definePlugin((sdk) => {
|
|
|
265
343
|
// in the inbox even if SSE never connects (e.g. a permanent 4xx). SSE and
|
|
266
344
|
// the safety timer then layer on additional catch-up drains.
|
|
267
345
|
drainRequest.request();
|
|
268
|
-
const runnerDone = drainRunner({
|
|
346
|
+
const runnerDone = drainRunner({
|
|
347
|
+
drainOptions,
|
|
348
|
+
drainRequest,
|
|
349
|
+
signal,
|
|
350
|
+
inboxId,
|
|
351
|
+
debug,
|
|
352
|
+
});
|
|
269
353
|
const sseDone = sseLoop({
|
|
270
354
|
api: sdk.context.api,
|
|
271
355
|
inboxId,
|
|
@@ -300,7 +384,7 @@ export const watchTriggerInboxPlugin = definePlugin((sdk) => {
|
|
|
300
384
|
watchTriggerInbox: {
|
|
301
385
|
...triggersDefaults,
|
|
302
386
|
type: "create",
|
|
303
|
-
description: "Continuously consume a trigger inbox: drain currently-available messages via onMessage, then subscribe to SSE notifications for new arrivals until aborted. A periodic safety drain runs every maxDrainIntervalSeconds (default: 300) to guarantee forward progress if SSE events are missed. Resolves cleanly on signal abort or ZapierAbortDrainSignal from a handler
|
|
387
|
+
description: "Continuously consume a trigger inbox: drain currently-available messages via onMessage, then subscribe to SSE notifications for new arrivals until aborted. A periodic safety drain runs every maxDrainIntervalSeconds (default: 300) to guarantee forward progress if SSE events are missed. Resolves cleanly on signal abort or ZapierAbortDrainSignal from a handler. Transient drain failures (5xx, 429, network blips) retry indefinitely with bounded backoff until they succeed or the watch is aborted; it rejects on a fail-fast handler error, an initialization_failure, or a permanent HTTP error. Real-time wake-up health is reported on stderr: a warning when wake-ups pause and the watch falls back to the safety drain, plus (with debug) transient reconnect notices. Persistent drain failures likewise warn once on stderr while bounded-backoff retries continue.",
|
|
304
388
|
itemType: "void",
|
|
305
389
|
// See drainTriggerInbox: override the doc generator's default
|
|
306
390
|
// suffix so the rendered return type is Promise<void>, not
|
|
@@ -5,9 +5,10 @@ interface InboxSseEvent {
|
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Streams the trigger inbox events endpoint and yields the notification frames
|
|
8
|
-
* for this inbox. The transport (SSE connection, parsing, reconnect-able
|
|
9
|
-
* mapping, abort/cleanup) lives in `api.
|
|
10
|
-
* URL and the `inbox_id` filter
|
|
8
|
+
* for this inbox. The transport (SSE connection, JSON parsing, reconnect-able
|
|
9
|
+
* error mapping, abort/cleanup) lives in `api.fetchJsonStream`; this only adds
|
|
10
|
+
* the inbox URL and the `inbox_id` filter, skipping any frame whose data was
|
|
11
|
+
* not valid JSON.
|
|
11
12
|
*
|
|
12
13
|
* `onOpen` fires once the connection is live (response ok, body present) and
|
|
13
14
|
* before the first frame. The endpoint is edge-triggered with no replay, so a
|
|
@@ -16,9 +17,10 @@ interface InboxSseEvent {
|
|
|
16
17
|
*
|
|
17
18
|
* The generator returns (without throwing) when the signal is aborted, when
|
|
18
19
|
* the server closes the connection (JWT expiry, clean shutdown), or when the
|
|
19
|
-
* body is empty. For a non-ok response `api.
|
|
20
|
-
* carrying the HTTP `statusCode`; `isPermanentHttpError`
|
|
21
|
-
* caller can tell permanent (4xx) failures from transient
|
|
20
|
+
* body is empty. For a non-ok response `api.fetchJsonStream` throws a
|
|
21
|
+
* `ZapierError` carrying the HTTP `statusCode`; `isPermanentHttpError`
|
|
22
|
+
* classifies it so the caller can tell permanent (4xx) failures from transient
|
|
23
|
+
* ones.
|
|
22
24
|
*/
|
|
23
25
|
export declare function readInboxEvents({ api, inboxId, signal, onOpen, }: {
|
|
24
26
|
api: ApiClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/watchTriggerInbox/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,UAAU,aAAa;IACrB,QAAQ,EAAE,MAAM,CAAC;IAIjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../../src/plugins/triggers/watchTriggerInbox/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,UAAU,aAAa;IACrB,QAAQ,EAAE,MAAM,CAAC;IAIjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAuB,eAAe,CAAC,EACrC,GAAG,EACH,OAAO,EACP,MAAM,EACN,MAAM,GACP,EAAE;IACD,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB,GAAG,cAAc,CAAC,aAAa,CAAC,CAqBhC"}
|