@zapier/zapier-sdk 0.31.2 → 0.31.4
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 +12 -0
- package/dist/index.cjs +19 -2
- package/dist/index.d.mts +10 -1
- package/dist/index.mjs +19 -3
- package/dist/plugins/eventEmission/builders.test.js +9 -0
- package/dist/plugins/eventEmission/index.d.ts +1 -0
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +5 -1
- package/dist/plugins/eventEmission/index.test.js +89 -7
- package/dist/plugins/fetch/index.d.ts.map +1 -1
- package/dist/plugins/fetch/index.js +7 -0
- package/dist/plugins/fetch/index.test.js +41 -0
- package/dist/types/errors.d.ts +8 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @zapier/zapier-sdk
|
|
2
2
|
|
|
3
|
+
## 0.31.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 026ae46: Properly capture and type errors from downstream proxy service.
|
|
8
|
+
|
|
9
|
+
## 0.31.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- c98008a: Add callContext option to EventEmissionConfig to track where SDK method calls originate. MethodCalledEvent telemetry events now populate call_context with "sdk", "cli", or "mcp" instead of null.
|
|
14
|
+
|
|
3
15
|
## 0.31.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -214,6 +214,12 @@ var ZapierRateLimitError = class extends ZapierError {
|
|
|
214
214
|
this.retries = options.retries ?? 0;
|
|
215
215
|
}
|
|
216
216
|
};
|
|
217
|
+
var ZapierRelayError = class extends ZapierError {
|
|
218
|
+
constructor(message, options = {}) {
|
|
219
|
+
super(message, options);
|
|
220
|
+
this.name = "ZapierRelayError";
|
|
221
|
+
}
|
|
222
|
+
};
|
|
217
223
|
function formatErrorMessage(error) {
|
|
218
224
|
let message = error.message;
|
|
219
225
|
if (error.errors && error.errors.length > 0) {
|
|
@@ -581,6 +587,12 @@ var fetchPlugin = ({ context }) => {
|
|
|
581
587
|
signal: fetchInit.signal,
|
|
582
588
|
authRequired: true
|
|
583
589
|
});
|
|
590
|
+
const relayError = result.headers.get("x-relay-error");
|
|
591
|
+
if (relayError) {
|
|
592
|
+
throw new ZapierRelayError(relayError, {
|
|
593
|
+
statusCode: result.status
|
|
594
|
+
});
|
|
595
|
+
}
|
|
584
596
|
if (!isNested) {
|
|
585
597
|
context.eventEmission.emitMethodCalled({
|
|
586
598
|
method_name: "fetch",
|
|
@@ -5487,7 +5499,7 @@ function getCpuTime() {
|
|
|
5487
5499
|
|
|
5488
5500
|
// package.json
|
|
5489
5501
|
var package_default = {
|
|
5490
|
-
version: "0.31.
|
|
5502
|
+
version: "0.31.4"};
|
|
5491
5503
|
|
|
5492
5504
|
// src/plugins/eventEmission/builders.ts
|
|
5493
5505
|
function createBaseEvent(context = {}) {
|
|
@@ -5666,6 +5678,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
5666
5678
|
});
|
|
5667
5679
|
const config = {
|
|
5668
5680
|
enabled: context.options.eventEmission?.enabled ?? true,
|
|
5681
|
+
callContext: context.options.eventEmission?.callContext,
|
|
5669
5682
|
transport: (
|
|
5670
5683
|
// If env var is set, use it (defaultTransport will be from env)
|
|
5671
5684
|
process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
|
|
@@ -5879,7 +5892,10 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
5879
5892
|
},
|
|
5880
5893
|
createBaseEvent: createBaseEventHelper,
|
|
5881
5894
|
emitMethodCalled: (data) => {
|
|
5882
|
-
const event =
|
|
5895
|
+
const event = {
|
|
5896
|
+
...buildMethodCalledEvent(data),
|
|
5897
|
+
call_context: config.callContext ?? "sdk"
|
|
5898
|
+
};
|
|
5883
5899
|
silentEmit(
|
|
5884
5900
|
transport,
|
|
5885
5901
|
METHOD_CALLED_EVENT_SUBJECT,
|
|
@@ -6019,6 +6035,7 @@ exports.ZapierConfigurationError = ZapierConfigurationError;
|
|
|
6019
6035
|
exports.ZapierError = ZapierError;
|
|
6020
6036
|
exports.ZapierNotFoundError = ZapierNotFoundError;
|
|
6021
6037
|
exports.ZapierRateLimitError = ZapierRateLimitError;
|
|
6038
|
+
exports.ZapierRelayError = ZapierRelayError;
|
|
6022
6039
|
exports.ZapierResourceNotFoundError = ZapierResourceNotFoundError;
|
|
6023
6040
|
exports.ZapierTimeoutError = ZapierTimeoutError;
|
|
6024
6041
|
exports.ZapierUnknownError = ZapierUnknownError;
|
package/dist/index.d.mts
CHANGED
|
@@ -378,6 +378,7 @@ declare function getCpuTime(): number | null;
|
|
|
378
378
|
interface EventEmissionConfig {
|
|
379
379
|
enabled?: boolean;
|
|
380
380
|
transport?: TransportConfig;
|
|
381
|
+
callContext?: "sdk" | "cli" | "mcp";
|
|
381
382
|
}
|
|
382
383
|
interface EventEmissionContext {
|
|
383
384
|
eventEmission: {
|
|
@@ -1214,6 +1215,14 @@ declare class ZapierRateLimitError extends ZapierError {
|
|
|
1214
1215
|
retries?: number;
|
|
1215
1216
|
});
|
|
1216
1217
|
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Error thrown when Relay itself encounters an error (as opposed to the upstream partner API returning an error).
|
|
1220
|
+
* Indicated by the presence of the X-Relay-Error response header.
|
|
1221
|
+
*/
|
|
1222
|
+
declare class ZapierRelayError extends ZapierError {
|
|
1223
|
+
readonly name = "ZapierRelayError";
|
|
1224
|
+
constructor(message: string, options?: ErrorOptions);
|
|
1225
|
+
}
|
|
1217
1226
|
/**
|
|
1218
1227
|
* Utility function to format error messages for display
|
|
1219
1228
|
*/
|
|
@@ -2953,4 +2962,4 @@ declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk
|
|
|
2953
2962
|
}>;
|
|
2954
2963
|
declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
|
2955
2964
|
|
|
2956
|
-
export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTimeoutMsProperty, ActionTimeoutMsPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type BaseEvent, BaseSdkOptionsSchema, type BatchOptions, type Choice, type ClientCredentialsObject, ClientCredentialsObjectSchema, type Connection, type ConnectionIdProperty, ConnectionIdPropertySchema, type ConnectionItem, type ConnectionsResponse, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsFunction, CredentialsFunctionSchema, type CredentialsObject, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindFirstConnectionPluginProvides, type FindUniqueAuthenticationPluginProvides, type FindUniqueConnectionPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetConnectionPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListConnectionsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, PkceCredentialsObjectSchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, type RateLimitInfo, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, ResolvedCredentialsSchema, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type StaticResolver, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
2965
|
+
export { type Action, type ActionEntry, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTimeoutMsProperty, ActionTimeoutMsPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type AddActionEntryOptions, type AddActionEntryResult, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type ApplicationLifecycleEventData, type AppsPluginProvides, type AuthEvent, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type BaseEvent, BaseSdkOptionsSchema, type BatchOptions, type Choice, type ClientCredentialsObject, ClientCredentialsObjectSchema, type Connection, type ConnectionIdProperty, ConnectionIdPropertySchema, type ConnectionItem, type ConnectionsResponse, type CreateClientCredentialsPluginProvides, type Credentials, type CredentialsFunction, CredentialsFunctionSchema, type CredentialsObject, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type DeleteClientCredentialsPluginProvides, type EnhancedErrorEventData, type ErrorOptions, type EventCallback, type EventContext, type EventEmissionContext, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindFirstConnectionPluginProvides, type FindUniqueAuthenticationPluginProvides, type FindUniqueConnectionPluginProvides, type FormatMetadata, type FormattedItem, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetConnectionPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListClientCredentialsPluginProvides, type ListConnectionsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, MAX_PAGE_LIMIT, type Manifest, type ManifestEntry, type ManifestPluginOptions, type ManifestPluginProvides, type MethodCalledEvent, type MethodCalledEventData, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type PkceCredentialsObject, PkceCredentialsObjectSchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, type RateLimitInfo, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type ResolveAuthTokenOptions, type ResolveCredentialsOptions, type ResolvedCredentials, ResolvedCredentialsSchema, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type StaticResolver, type UpdateManifestEntryOptions, type UpdateManifestEntryResult, type UserProfile, type UserProfileItem, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierRateLimitError, ZapierRelayError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
package/dist/index.mjs
CHANGED
|
@@ -192,6 +192,12 @@ var ZapierRateLimitError = class extends ZapierError {
|
|
|
192
192
|
this.retries = options.retries ?? 0;
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
|
+
var ZapierRelayError = class extends ZapierError {
|
|
196
|
+
constructor(message, options = {}) {
|
|
197
|
+
super(message, options);
|
|
198
|
+
this.name = "ZapierRelayError";
|
|
199
|
+
}
|
|
200
|
+
};
|
|
195
201
|
function formatErrorMessage(error) {
|
|
196
202
|
let message = error.message;
|
|
197
203
|
if (error.errors && error.errors.length > 0) {
|
|
@@ -559,6 +565,12 @@ var fetchPlugin = ({ context }) => {
|
|
|
559
565
|
signal: fetchInit.signal,
|
|
560
566
|
authRequired: true
|
|
561
567
|
});
|
|
568
|
+
const relayError = result.headers.get("x-relay-error");
|
|
569
|
+
if (relayError) {
|
|
570
|
+
throw new ZapierRelayError(relayError, {
|
|
571
|
+
statusCode: result.status
|
|
572
|
+
});
|
|
573
|
+
}
|
|
562
574
|
if (!isNested) {
|
|
563
575
|
context.eventEmission.emitMethodCalled({
|
|
564
576
|
method_name: "fetch",
|
|
@@ -5465,7 +5477,7 @@ function getCpuTime() {
|
|
|
5465
5477
|
|
|
5466
5478
|
// package.json
|
|
5467
5479
|
var package_default = {
|
|
5468
|
-
version: "0.31.
|
|
5480
|
+
version: "0.31.4"};
|
|
5469
5481
|
|
|
5470
5482
|
// src/plugins/eventEmission/builders.ts
|
|
5471
5483
|
function createBaseEvent(context = {}) {
|
|
@@ -5644,6 +5656,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
5644
5656
|
});
|
|
5645
5657
|
const config = {
|
|
5646
5658
|
enabled: context.options.eventEmission?.enabled ?? true,
|
|
5659
|
+
callContext: context.options.eventEmission?.callContext,
|
|
5647
5660
|
transport: (
|
|
5648
5661
|
// If env var is set, use it (defaultTransport will be from env)
|
|
5649
5662
|
process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
|
|
@@ -5857,7 +5870,10 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
5857
5870
|
},
|
|
5858
5871
|
createBaseEvent: createBaseEventHelper,
|
|
5859
5872
|
emitMethodCalled: (data) => {
|
|
5860
|
-
const event =
|
|
5873
|
+
const event = {
|
|
5874
|
+
...buildMethodCalledEvent(data),
|
|
5875
|
+
call_context: config.callContext ?? "sdk"
|
|
5876
|
+
};
|
|
5861
5877
|
silentEmit(
|
|
5862
5878
|
transport,
|
|
5863
5879
|
METHOD_CALLED_EVENT_SUBJECT,
|
|
@@ -5953,4 +5969,4 @@ var BaseSdkOptionsSchema = z.object({
|
|
|
5953
5969
|
// Use credentials instead
|
|
5954
5970
|
});
|
|
5955
5971
|
|
|
5956
|
-
export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
5972
|
+
export { ActionKeyPropertySchema, ActionTimeoutMsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, ClientCredentialsObjectSchema, ConnectionIdPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, ZAPIER_AUTH_BASE_URL, ZAPIER_AUTH_CLIENT_ID, ZAPIER_BASE_URL, ZAPIER_CREDENTIALS, ZAPIER_CREDENTIALS_BASE_URL, ZAPIER_CREDENTIALS_CLIENT_ID, ZAPIER_CREDENTIALS_CLIENT_SECRET, ZAPIER_CREDENTIALS_SCOPE, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MS, ZAPIER_TOKEN, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierRelayError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, connectionIdGenericResolver as authenticationIdGenericResolver, connectionIdResolver as authenticationIdResolver, batch, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, createBaseEvent, createClientCredentialsPlugin, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getBaseUrlFromCredentials, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPkceCredentials, isPositional, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listInputFieldsPlugin, logDeprecation, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, runActionPlugin, toSnakeCase, toTitleCase };
|
|
@@ -53,4 +53,13 @@ describe("buildMethodCalledEvent", () => {
|
|
|
53
53
|
}, { selected_api: "SlackCLIAPI@1.0.0" });
|
|
54
54
|
expect(event.selected_api).toBe("SlackCLIAPI@1.0.0");
|
|
55
55
|
});
|
|
56
|
+
it("should default call_context to null (plugin layer overrides this)", () => {
|
|
57
|
+
const event = buildMethodCalledEvent({
|
|
58
|
+
method_name: "listApps",
|
|
59
|
+
execution_duration_ms: 50,
|
|
60
|
+
success_flag: true,
|
|
61
|
+
argument_count: 0,
|
|
62
|
+
});
|
|
63
|
+
expect(event.call_context).toBeNull();
|
|
64
|
+
});
|
|
56
65
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAWnE,OAAO,KAAK,EAAgB,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAsCnE;;;GAGG;AACH,wBAAgB,qBAAqB,SAEpC;AAGD,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pl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L,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,eAAe,EACf,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,cAAc,SAAS,CAAC"}
|
|
@@ -110,6 +110,7 @@ export const eventEmissionPlugin = ({ context }) => {
|
|
|
110
110
|
// Merge config: env var takes precedence over options, options take precedence over defaults
|
|
111
111
|
const config = {
|
|
112
112
|
enabled: context.options.eventEmission?.enabled ?? true,
|
|
113
|
+
callContext: context.options.eventEmission?.callContext,
|
|
113
114
|
transport:
|
|
114
115
|
// If env var is set, use it (defaultTransport will be from env)
|
|
115
116
|
process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT
|
|
@@ -354,7 +355,10 @@ export const eventEmissionPlugin = ({ context }) => {
|
|
|
354
355
|
},
|
|
355
356
|
createBaseEvent: createBaseEventHelper,
|
|
356
357
|
emitMethodCalled: (data) => {
|
|
357
|
-
const event =
|
|
358
|
+
const event = {
|
|
359
|
+
...buildMethodCalledEvent(data),
|
|
360
|
+
call_context: config.callContext ?? "sdk",
|
|
361
|
+
};
|
|
358
362
|
silentEmit(transport, METHOD_CALLED_EVENT_SUBJECT, event, getUserContext);
|
|
359
363
|
},
|
|
360
364
|
},
|
|
@@ -4,16 +4,19 @@
|
|
|
4
4
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
5
5
|
import { eventEmissionPlugin, cleanupEventListeners } from "./index";
|
|
6
6
|
import { createTransport } from "./transport";
|
|
7
|
-
|
|
8
|
-
const mockTransport = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { clearTokenCache } from "../../auth";
|
|
8
|
+
const { mockTransport, mockGetToken } = vi.hoisted(() => ({
|
|
9
|
+
mockTransport: {
|
|
10
|
+
emit: vi.fn().mockResolvedValue(undefined),
|
|
11
|
+
close: vi.fn().mockResolvedValue(undefined),
|
|
12
|
+
},
|
|
13
|
+
mockGetToken: vi.fn().mockResolvedValue(undefined),
|
|
14
|
+
}));
|
|
12
15
|
vi.mock("./transport", () => ({
|
|
13
16
|
createTransport: vi.fn(() => mockTransport),
|
|
14
17
|
}));
|
|
15
|
-
// Mock CLI login
|
|
16
|
-
|
|
18
|
+
// Mock both CLI login import paths (SDK tries @zapier/zapier-sdk-cli/login
|
|
19
|
+
// first, then falls back to @zapier/zapier-sdk-cli-login)
|
|
17
20
|
vi.mock("@zapier/zapier-sdk-cli/login", () => ({
|
|
18
21
|
getToken: mockGetToken,
|
|
19
22
|
}));
|
|
@@ -23,6 +26,7 @@ vi.mock("@zapier/zapier-sdk-cli-login", () => ({
|
|
|
23
26
|
describe("eventEmissionPlugin", () => {
|
|
24
27
|
beforeEach(() => {
|
|
25
28
|
vi.clearAllMocks();
|
|
29
|
+
clearTokenCache();
|
|
26
30
|
// Reset to default behavior - no token available
|
|
27
31
|
mockGetToken.mockResolvedValue(undefined);
|
|
28
32
|
});
|
|
@@ -67,6 +71,10 @@ describe("eventEmissionPlugin", () => {
|
|
|
67
71
|
},
|
|
68
72
|
},
|
|
69
73
|
});
|
|
74
|
+
// Ensure getUserContext has resolved (startup event also awaits it)
|
|
75
|
+
await plugin.context.eventEmission.createBaseEvent();
|
|
76
|
+
// Clear startup event calls so we only assert on our test event
|
|
77
|
+
mockTransport.emit.mockClear();
|
|
70
78
|
const testEvent = {
|
|
71
79
|
test_data: "example",
|
|
72
80
|
value: 123,
|
|
@@ -579,6 +587,80 @@ describe("eventEmissionPlugin", () => {
|
|
|
579
587
|
expect(mockGetToken).toHaveBeenCalled();
|
|
580
588
|
});
|
|
581
589
|
});
|
|
590
|
+
describe("emitMethodCalled call_context", () => {
|
|
591
|
+
beforeEach(() => {
|
|
592
|
+
vi.clearAllMocks();
|
|
593
|
+
mockGetToken.mockResolvedValue(undefined);
|
|
594
|
+
});
|
|
595
|
+
it("should default call_context to 'sdk' when callContext is not configured", async () => {
|
|
596
|
+
const plugin = eventEmissionPlugin({
|
|
597
|
+
sdk: {},
|
|
598
|
+
context: {
|
|
599
|
+
meta: {},
|
|
600
|
+
options: {
|
|
601
|
+
eventEmission: {
|
|
602
|
+
enabled: true,
|
|
603
|
+
transport: { type: "console" },
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
});
|
|
608
|
+
plugin.context.eventEmission.emitMethodCalled({
|
|
609
|
+
method_name: "listApps",
|
|
610
|
+
execution_duration_ms: 50,
|
|
611
|
+
success_flag: true,
|
|
612
|
+
argument_count: 0,
|
|
613
|
+
});
|
|
614
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
615
|
+
expect(mockTransport.emit).toHaveBeenCalledWith("platform.sdk.MethodCalledEvent", expect.objectContaining({ call_context: "sdk" }));
|
|
616
|
+
});
|
|
617
|
+
it("should set call_context to 'cli' when callContext is 'cli'", async () => {
|
|
618
|
+
const plugin = eventEmissionPlugin({
|
|
619
|
+
sdk: {},
|
|
620
|
+
context: {
|
|
621
|
+
meta: {},
|
|
622
|
+
options: {
|
|
623
|
+
eventEmission: {
|
|
624
|
+
enabled: true,
|
|
625
|
+
transport: { type: "console" },
|
|
626
|
+
callContext: "cli",
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
plugin.context.eventEmission.emitMethodCalled({
|
|
632
|
+
method_name: "listApps",
|
|
633
|
+
execution_duration_ms: 50,
|
|
634
|
+
success_flag: true,
|
|
635
|
+
argument_count: 0,
|
|
636
|
+
});
|
|
637
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
638
|
+
expect(mockTransport.emit).toHaveBeenCalledWith("platform.sdk.MethodCalledEvent", expect.objectContaining({ call_context: "cli" }));
|
|
639
|
+
});
|
|
640
|
+
it("should set call_context to 'mcp' when callContext is 'mcp'", async () => {
|
|
641
|
+
const plugin = eventEmissionPlugin({
|
|
642
|
+
sdk: {},
|
|
643
|
+
context: {
|
|
644
|
+
meta: {},
|
|
645
|
+
options: {
|
|
646
|
+
eventEmission: {
|
|
647
|
+
enabled: true,
|
|
648
|
+
transport: { type: "console" },
|
|
649
|
+
callContext: "mcp",
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
});
|
|
654
|
+
plugin.context.eventEmission.emitMethodCalled({
|
|
655
|
+
method_name: "listApps",
|
|
656
|
+
execution_duration_ms: 50,
|
|
657
|
+
success_flag: true,
|
|
658
|
+
argument_count: 0,
|
|
659
|
+
});
|
|
660
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
661
|
+
expect(mockTransport.emit).toHaveBeenCalledWith("platform.sdk.MethodCalledEvent", expect.objectContaining({ call_context: "mcp" }));
|
|
662
|
+
});
|
|
663
|
+
});
|
|
582
664
|
describe("Process Listener Cleanup", () => {
|
|
583
665
|
beforeEach(() => {
|
|
584
666
|
// Clean up any listeners from previous tests
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAoE7D,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,CACL,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,WAAW,GAAG;QACnB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC/B,2CAA2C;QAC3C,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACnC,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,KACE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvB,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,KAAK,EAAE;gBACL,WAAW,EAAE,MAAM,CAAC;gBACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;gBACnB,UAAU,EAAE,MAAM,EAAE,CAAC;gBACrB,UAAU,EAAE,MAAM,CAAC;gBACnB,eAAe,EAAE,KAAK,CAAC;oBAAE,IAAI,EAAE,MAAM,CAAC;oBAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAA;iBAAE,CAAC,CAAC;aAC/D,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAC9B,EAAE,EAAE,sBAAsB;AAC1B,AADI,sBAAsB;AAC1B;IAAE,GAAG,EAAE,SAAS,CAAA;CAAE,GAAG,oBAAoB,EAAE,0CAA0C;AACrF,mBAAmB,CAyHpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,WAAW,GAAG;IACjD,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ZapierRelayError } from "../../types/errors";
|
|
1
2
|
import { FetchUrlSchema, FetchInitSchema } from "./schemas";
|
|
2
3
|
import { coerceToNumericId } from "../../utils/id-utils";
|
|
3
4
|
import { isPlainObject } from "../../utils/type-guard-utils";
|
|
@@ -90,6 +91,12 @@ export const fetchPlugin = ({ context }) => {
|
|
|
90
91
|
signal: fetchInit.signal,
|
|
91
92
|
authRequired: true,
|
|
92
93
|
});
|
|
94
|
+
const relayError = result.headers.get("x-relay-error");
|
|
95
|
+
if (relayError) {
|
|
96
|
+
throw new ZapierRelayError(relayError, {
|
|
97
|
+
statusCode: result.status,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
93
100
|
if (!isNested) {
|
|
94
101
|
context.eventEmission.emitMethodCalled({
|
|
95
102
|
method_name: "fetch",
|
|
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
2
2
|
import { fetchPlugin } from "./index";
|
|
3
3
|
import { createSdk } from "../../sdk";
|
|
4
4
|
import { eventEmissionPlugin } from "../eventEmission";
|
|
5
|
+
import { ZapierRelayError } from "../../types/errors";
|
|
5
6
|
describe("fetch plugin", () => {
|
|
6
7
|
let mockApiClient;
|
|
7
8
|
let mockFetch;
|
|
@@ -363,6 +364,46 @@ describe("fetch plugin", () => {
|
|
|
363
364
|
await expect(sdk.fetch("https://api.example.com/data")).rejects.toThrow("Network error");
|
|
364
365
|
});
|
|
365
366
|
});
|
|
367
|
+
describe("relay errors", () => {
|
|
368
|
+
it("should throw ZapierRelayError with the x-relay-error header message", async () => {
|
|
369
|
+
const friendlyMessage = "Ashby does not support direct HTTP requests. Use zapier.apps.{appKey} or zapier.runAction() to use Actions built for this app.";
|
|
370
|
+
mockFetch.mockResolvedValue(new Response("", {
|
|
371
|
+
status: 404,
|
|
372
|
+
headers: { "x-relay-error": friendlyMessage },
|
|
373
|
+
}));
|
|
374
|
+
const sdk = createTestSdk();
|
|
375
|
+
const error = await sdk
|
|
376
|
+
.fetch("https://api.example.com/data")
|
|
377
|
+
.catch((e) => e);
|
|
378
|
+
expect(error).toBeInstanceOf(ZapierRelayError);
|
|
379
|
+
expect(error.message).toBe(friendlyMessage);
|
|
380
|
+
expect(error.statusCode).toBe(404);
|
|
381
|
+
});
|
|
382
|
+
it("should throw ZapierRelayError for non-matching x-relay-error", async () => {
|
|
383
|
+
mockFetch.mockResolvedValue(new Response("", {
|
|
384
|
+
status: 404,
|
|
385
|
+
headers: { "x-relay-error": "Some other relay error" },
|
|
386
|
+
}));
|
|
387
|
+
const sdk = createTestSdk();
|
|
388
|
+
const error = await sdk
|
|
389
|
+
.fetch("https://api.example.com/data")
|
|
390
|
+
.catch((e) => e);
|
|
391
|
+
expect(error).toBeInstanceOf(ZapierRelayError);
|
|
392
|
+
expect(error.message).toBe("Some other relay error");
|
|
393
|
+
});
|
|
394
|
+
it("should throw ZapierRelayError regardless of status code", async () => {
|
|
395
|
+
mockFetch.mockResolvedValue(new Response("", {
|
|
396
|
+
status: 502,
|
|
397
|
+
headers: { "x-relay-error": "upstream timeout" },
|
|
398
|
+
}));
|
|
399
|
+
const sdk = createTestSdk();
|
|
400
|
+
const error = await sdk
|
|
401
|
+
.fetch("https://api.example.com/data")
|
|
402
|
+
.catch((e) => e);
|
|
403
|
+
expect(error).toBeInstanceOf(ZapierRelayError);
|
|
404
|
+
expect(error.statusCode).toBe(502);
|
|
405
|
+
});
|
|
406
|
+
});
|
|
366
407
|
describe("context and metadata", () => {
|
|
367
408
|
it("should provide context with meta information", () => {
|
|
368
409
|
const sdk = createTestSdk();
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -161,6 +161,14 @@ export declare class ZapierRateLimitError extends ZapierError {
|
|
|
161
161
|
retries?: number;
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Error thrown when Relay itself encounters an error (as opposed to the upstream partner API returning an error).
|
|
166
|
+
* Indicated by the presence of the X-Relay-Error response header.
|
|
167
|
+
*/
|
|
168
|
+
export declare class ZapierRelayError extends ZapierError {
|
|
169
|
+
readonly name = "ZapierRelayError";
|
|
170
|
+
constructor(message: string, options?: ErrorOptions);
|
|
171
|
+
}
|
|
164
172
|
/**
|
|
165
173
|
* Utility function to format error messages for display
|
|
166
174
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AA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ED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;IAC/C,QAAQ,CAAC,IAAI,sBAAsB;gBAEvB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;CAGxD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CA8D7D"}
|
package/dist/types/errors.js
CHANGED
|
@@ -138,6 +138,16 @@ export class ZapierRateLimitError extends ZapierError {
|
|
|
138
138
|
this.retries = options.retries ?? 0;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Error thrown when Relay itself encounters an error (as opposed to the upstream partner API returning an error).
|
|
143
|
+
* Indicated by the presence of the X-Relay-Error response header.
|
|
144
|
+
*/
|
|
145
|
+
export class ZapierRelayError extends ZapierError {
|
|
146
|
+
constructor(message, options = {}) {
|
|
147
|
+
super(message, options);
|
|
148
|
+
this.name = "ZapierRelayError";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
141
151
|
/**
|
|
142
152
|
* Utility function to format error messages for display
|
|
143
153
|
*/
|