@zapier/zapier-sdk 0.114.4 → 0.115.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 +14 -0
- package/README.md +1 -1
- package/dist/beta.cjs +282 -278
- package/dist/beta.d.mts +2 -2
- package/dist/beta.d.ts +2 -2
- package/dist/beta.mjs +2 -2
- package/dist/{chunk-BRFMIXJZ.cjs → chunk-24GCCCDH.cjs} +4 -4
- package/dist/{chunk-B4DVAMYI.cjs → chunk-LO3VMFOP.cjs} +123 -11
- package/dist/{chunk-A2GMUMK3.mjs → chunk-NVVSKZ3Y.mjs} +123 -12
- package/dist/{chunk-ICFP2AO2.mjs → chunk-Q7ECOKIG.mjs} +1 -1
- package/dist/experimental.cjs +387 -383
- package/dist/experimental.d.mts +269 -269
- package/dist/experimental.d.ts +269 -269
- package/dist/experimental.mjs +3 -3
- package/dist/{index-BCJAutN8.d.mts → index-BrhSgvFN.d.mts} +23 -2
- package/dist/{index-BCJAutN8.d.ts → index-BrhSgvFN.d.ts} +23 -2
- package/dist/index.cjs +280 -276
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -512,7 +512,9 @@ var WatchTriggerInboxSchema = TriggerInboxCommandBaseSchema.extend({
|
|
|
512
512
|
"Continuously consume a trigger inbox: drain currently-available messages, then subscribe to SSE notifications for new arrivals, until aborted. Stop via the `signal` AbortSignal or by throwing `ZapierAbortDrainSignal` from a handler. Transient drain failures (5xx, 429, network blips) retry indefinitely with bounded backoff; real-time wake-up and drain health warnings print to stderr. Resolves cleanly on abort; rejects on a fatal error or a fail-fast handler error."
|
|
513
513
|
);
|
|
514
514
|
var ActionExecutionInputSchema = z.object({
|
|
515
|
-
inputs:
|
|
515
|
+
inputs: InputsPropertySchema.optional().describe(
|
|
516
|
+
"Input parameters for the action"
|
|
517
|
+
),
|
|
516
518
|
/** @deprecated Use `connection` instead. */
|
|
517
519
|
connectionId: ConnectionIdPropertySchema.optional().meta({
|
|
518
520
|
deprecated: true
|
|
@@ -720,7 +722,7 @@ function createDebugLogger(enabled) {
|
|
|
720
722
|
function censorHeaders(headers) {
|
|
721
723
|
if (!headers) return headers;
|
|
722
724
|
const headersObj = new Headers(headers);
|
|
723
|
-
const authKeys = ["authorization", "x-api-key"];
|
|
725
|
+
const authKeys = ["authorization", "x-api-key", "x-zapier-approval-token"];
|
|
724
726
|
for (const [key, value] of headersObj.entries()) {
|
|
725
727
|
if (authKeys.some((authKey) => key.toLowerCase() === authKey)) {
|
|
726
728
|
const spaceIndex = value.indexOf(" ");
|
|
@@ -2818,7 +2820,7 @@ function logRouteOverride({
|
|
|
2818
2820
|
}
|
|
2819
2821
|
|
|
2820
2822
|
// src/sdk-version.ts
|
|
2821
|
-
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.
|
|
2823
|
+
var SDK_VERSION = (typeof process !== "undefined" && process.env ? "0.115.0" : void 0) || "unknown";
|
|
2822
2824
|
|
|
2823
2825
|
// src/utils/open-url.ts
|
|
2824
2826
|
var nodePrefix = "node:";
|
|
@@ -2911,6 +2913,8 @@ var CreateApprovalResponseSchema = z.object({
|
|
|
2911
2913
|
approval_url: z.string().url(),
|
|
2912
2914
|
poll_url: z.string().url(),
|
|
2913
2915
|
stream_url: z.string().url().optional(),
|
|
2916
|
+
// Present when the approval mints one-time tokens; absent on legacy/manual approvals.
|
|
2917
|
+
tokens_url: z.string().url().optional(),
|
|
2914
2918
|
reason: z.string().optional()
|
|
2915
2919
|
}).transform((approval, ctx) => {
|
|
2916
2920
|
const id = approval.id ?? approval.approval_id;
|
|
@@ -2923,6 +2927,14 @@ var CreateApprovalResponseSchema = z.object({
|
|
|
2923
2927
|
}
|
|
2924
2928
|
return { ...approval, id };
|
|
2925
2929
|
});
|
|
2930
|
+
var APPROVAL_TOKEN_HANDLE_PATTERN = /^zat_[0-9A-Za-z]{24}$/;
|
|
2931
|
+
var MAX_APPROVAL_TOKEN_HANDLES = 20;
|
|
2932
|
+
var ApprovalTokenSchema = z.object({
|
|
2933
|
+
handle: z.string().regex(APPROVAL_TOKEN_HANDLE_PATTERN)
|
|
2934
|
+
});
|
|
2935
|
+
var ApprovalTokensResponseSchema = z.object({
|
|
2936
|
+
tokens: z.array(z.unknown())
|
|
2937
|
+
});
|
|
2926
2938
|
var PollApprovalResponseSchema = z.object({
|
|
2927
2939
|
id: z.string().optional(),
|
|
2928
2940
|
status: ApprovalStatusSchema,
|
|
@@ -3087,6 +3099,25 @@ var ZapierApiClient = class {
|
|
|
3087
3099
|
return { response };
|
|
3088
3100
|
}
|
|
3089
3101
|
const errorType = response.headers.get("x-zapier-error-type");
|
|
3102
|
+
if (errorType === "approval_token_invalid") {
|
|
3103
|
+
const { data } = await this.parseResult(response);
|
|
3104
|
+
const { message, errors } = this.parseErrorResponse({
|
|
3105
|
+
status: response.status,
|
|
3106
|
+
statusText: response.statusText,
|
|
3107
|
+
data
|
|
3108
|
+
});
|
|
3109
|
+
return {
|
|
3110
|
+
response,
|
|
3111
|
+
approvalRoundError: new ZapierApprovalError(
|
|
3112
|
+
message || "Approval token rejected by the server",
|
|
3113
|
+
{
|
|
3114
|
+
status: "approval_token_invalid",
|
|
3115
|
+
statusCode: response.status,
|
|
3116
|
+
errors
|
|
3117
|
+
}
|
|
3118
|
+
)
|
|
3119
|
+
};
|
|
3120
|
+
}
|
|
3090
3121
|
if (errorType !== "approval_required") {
|
|
3091
3122
|
return { response };
|
|
3092
3123
|
}
|
|
@@ -3103,8 +3134,9 @@ var ZapierApiClient = class {
|
|
|
3103
3134
|
"x-zapier-ask-statement-ids"
|
|
3104
3135
|
);
|
|
3105
3136
|
const askStatementIds = askStatementIdsHeader ? JSON.parse(askStatementIdsHeader) : void 0;
|
|
3137
|
+
let approvalTokens;
|
|
3106
3138
|
try {
|
|
3107
|
-
await this.runOneApprovalRound({
|
|
3139
|
+
approvalTokens = await this.runOneApprovalRound({
|
|
3108
3140
|
buildContext: approvalContext,
|
|
3109
3141
|
mode: approvalMode,
|
|
3110
3142
|
signal: init?.signal ?? void 0,
|
|
@@ -3114,6 +3146,13 @@ var ZapierApiClient = class {
|
|
|
3114
3146
|
} catch (error) {
|
|
3115
3147
|
return { response, approvalRoundError: error };
|
|
3116
3148
|
}
|
|
3149
|
+
const nextHeaders = new Headers(init?.headers);
|
|
3150
|
+
if (approvalTokens.length > 0) {
|
|
3151
|
+
nextHeaders.set("x-zapier-approval-token", approvalTokens.join(","));
|
|
3152
|
+
} else {
|
|
3153
|
+
nextHeaders.delete("x-zapier-approval-token");
|
|
3154
|
+
}
|
|
3155
|
+
init = { ...init, headers: nextHeaders };
|
|
3117
3156
|
}
|
|
3118
3157
|
throw new ZapierApiError("Approval retry loop ended unexpectedly");
|
|
3119
3158
|
};
|
|
@@ -3127,9 +3166,10 @@ var ZapierApiClient = class {
|
|
|
3127
3166
|
* - `request_denied_by_policy` → a policy rule permanently blocks the
|
|
3128
3167
|
* request; no human can approve it. Throw.
|
|
3129
3168
|
* - `approval_required` → the request needs human approval; the
|
|
3130
|
-
* SDK creates an approval,
|
|
3131
|
-
*
|
|
3132
|
-
*
|
|
3169
|
+
* SDK creates an approval, waits for
|
|
3170
|
+
* resolution, then retries with any
|
|
3171
|
+
* minted one-time token(s) attached.
|
|
3172
|
+
* - `approval_token_invalid` → a retried token was rejected. Terminal.
|
|
3133
3173
|
* - anything else → not our concern, pass through.
|
|
3134
3174
|
*
|
|
3135
3175
|
* The retry loop exists because a single user action can legitimately
|
|
@@ -3187,6 +3227,9 @@ var ZapierApiClient = class {
|
|
|
3187
3227
|
);
|
|
3188
3228
|
}
|
|
3189
3229
|
if (errorType !== "approval_required") {
|
|
3230
|
+
if (approvalRoundError) {
|
|
3231
|
+
throw approvalRoundError;
|
|
3232
|
+
}
|
|
3190
3233
|
return response;
|
|
3191
3234
|
}
|
|
3192
3235
|
if (approvalRoundError) {
|
|
@@ -3693,9 +3736,48 @@ var ZapierApiClient = class {
|
|
|
3693
3736
|
}
|
|
3694
3737
|
}
|
|
3695
3738
|
/**
|
|
3696
|
-
*
|
|
3697
|
-
*
|
|
3698
|
-
*
|
|
3739
|
+
* Fetch every token handle minted for a resolved approval. Fails open
|
|
3740
|
+
* (returns [], emits approval:error) on any non-200, malformed body, or
|
|
3741
|
+
* network error, so a token-fetch failure never blocks the retry. Aborts
|
|
3742
|
+
* propagate.
|
|
3743
|
+
*/
|
|
3744
|
+
async fetchApprovalTokens(approvalId, tokensUrl, signal, callId) {
|
|
3745
|
+
const failOpen = (message) => {
|
|
3746
|
+
this.emitEvent("approval:error", { approvalId, message });
|
|
3747
|
+
return [];
|
|
3748
|
+
};
|
|
3749
|
+
try {
|
|
3750
|
+
const response = await this.withSemaphore(
|
|
3751
|
+
{ url: tokensUrl, method: "GET", signal },
|
|
3752
|
+
() => this.rawFetchUrl(tokensUrl, {
|
|
3753
|
+
method: "GET",
|
|
3754
|
+
headers: { Accept: "application/json" },
|
|
3755
|
+
signal,
|
|
3756
|
+
[CORRELATION_CALL_ID]: callId
|
|
3757
|
+
})
|
|
3758
|
+
);
|
|
3759
|
+
if (!response.ok) {
|
|
3760
|
+
return failOpen(`Failed to fetch approval tokens: ${response.status}`);
|
|
3761
|
+
}
|
|
3762
|
+
const { data } = await this.parseResult(response);
|
|
3763
|
+
const body = ApprovalTokensResponseSchema.safeParse(data);
|
|
3764
|
+
if (!body.success) {
|
|
3765
|
+
return failOpen("Failed to parse approval tokens response");
|
|
3766
|
+
}
|
|
3767
|
+
return body.data.tokens.map((t) => ApprovalTokenSchema.safeParse(t)).filter((parsed) => parsed.success).map((parsed) => parsed.data.handle).slice(0, MAX_APPROVAL_TOKEN_HANDLES);
|
|
3768
|
+
} catch (err) {
|
|
3769
|
+
if (signal?.aborted || isAbortError(err)) throw err;
|
|
3770
|
+
return failOpen(
|
|
3771
|
+
`Failed to fetch approval tokens: ${err instanceof Error ? err.message : String(err)}`
|
|
3772
|
+
);
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
/**
|
|
3776
|
+
* Run a single approval round: create the approval, open the URL (poll
|
|
3777
|
+
* mode) or throw (throw mode), poll until resolved, and emit events.
|
|
3778
|
+
* Throws on denied/failed/timeout/unexpected status. Returns on approved
|
|
3779
|
+
* with every one-time token handle the approval minted (via tokens_url),
|
|
3780
|
+
* or [] when no tokens_url is present (legacy/manual policy-sync path).
|
|
3699
3781
|
*
|
|
3700
3782
|
* Caller is responsible for passing a non-"disabled" mode; this method
|
|
3701
3783
|
* unconditionally creates an approval.
|
|
@@ -3785,6 +3867,13 @@ var ZapierApiClient = class {
|
|
|
3785
3867
|
if (approval.stream_url) {
|
|
3786
3868
|
assertApprovalOrigin(approval.stream_url, sdkapiOrigin, "stream_url");
|
|
3787
3869
|
}
|
|
3870
|
+
if (approval.tokens_url) {
|
|
3871
|
+
assertApprovalOrigin(
|
|
3872
|
+
approval.tokens_url,
|
|
3873
|
+
approvalsOrigin,
|
|
3874
|
+
"tokens_url"
|
|
3875
|
+
);
|
|
3876
|
+
}
|
|
3788
3877
|
assertApprovalOrigin(
|
|
3789
3878
|
approval.approval_url,
|
|
3790
3879
|
browserOrigin,
|
|
@@ -3806,7 +3895,12 @@ var ZapierApiClient = class {
|
|
|
3806
3895
|
this.emitEvent("approval:approved", {
|
|
3807
3896
|
approvalId: approval.id
|
|
3808
3897
|
});
|
|
3809
|
-
return
|
|
3898
|
+
return approval.tokens_url ? this.fetchApprovalTokens(
|
|
3899
|
+
approval.id,
|
|
3900
|
+
approval.tokens_url,
|
|
3901
|
+
signal,
|
|
3902
|
+
callId
|
|
3903
|
+
) : [];
|
|
3810
3904
|
}
|
|
3811
3905
|
if (approval.status === "denied") {
|
|
3812
3906
|
this.emitEvent("approval:denied", {
|
|
@@ -3998,6 +4092,12 @@ var ZapierApiClient = class {
|
|
|
3998
4092
|
this.emitEvent("approval:approved", {
|
|
3999
4093
|
approvalId: approval.id
|
|
4000
4094
|
});
|
|
4095
|
+
return approval.tokens_url ? this.fetchApprovalTokens(
|
|
4096
|
+
approval.id,
|
|
4097
|
+
approval.tokens_url,
|
|
4098
|
+
signal,
|
|
4099
|
+
callId
|
|
4100
|
+
) : [];
|
|
4001
4101
|
}
|
|
4002
4102
|
throwApprovalFailed({
|
|
4003
4103
|
approvalId,
|
|
@@ -13293,4 +13393,15 @@ function describeThrown(error) {
|
|
|
13293
13393
|
}
|
|
13294
13394
|
}
|
|
13295
13395
|
|
|
13296
|
-
|
|
13396
|
+
// src/utils/schema-description.ts
|
|
13397
|
+
function descriptionFor(schema) {
|
|
13398
|
+
let current = schema;
|
|
13399
|
+
while (current) {
|
|
13400
|
+
const own = current.description;
|
|
13401
|
+
if (own) return own;
|
|
13402
|
+
current = current._zod?.def?.innerType;
|
|
13403
|
+
}
|
|
13404
|
+
return void 0;
|
|
13405
|
+
}
|
|
13406
|
+
|
|
13407
|
+
export { ACTION_RUNS_PATH, API_ID, ActionKeyPropertySchema, ActionPropertySchema, ActionTimeoutMillisecondsPropertySchema, ActionTimeoutSecondsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AppPropertySchema, AppsPropertySchema, AuthMechanism, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, CONNECTIONS_ID, CONTEXT_CACHE_MAX_SIZE, CONTEXT_CACHE_TTL_MILLISECONDS, ClientCredentialsObjectSchema, ConnectionEntrySchema, ConnectionIdPropertySchema, ConnectionPropertySchema, ConnectionsMapSchema, ConnectionsPropertySchema, CredentialsFunctionSchema, CredentialsObjectSchema, CredentialsSchema, DEFAULT_ACTION_TIMEOUT_MILLISECONDS, DEFAULT_APPROVAL_TIMEOUT_MILLISECONDS, DEFAULT_CONFIG_PATH, DEFAULT_MAX_APPROVAL_RETRIES, DEFAULT_PAGE_SIZE, DEPRECATION_NOTICE_EVENT, DebugPropertySchema, DrainTriggerInboxSchema, EVENT_EMISSION_ID, FieldsPropertySchema, InputFieldPropertySchema, InputsPropertySchema, LeaseLimitPropertySchema, LeasePropertySchema, LeaseSecondsPropertySchema, LimitPropertySchema, MANIFEST_ID, MAX_CONCURRENCY_LIMIT, MAX_PAGE_LIMIT, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, PkceCredentialsObjectSchema, RESOLVE_CREDENTIALS_ID, RecordPropertySchema, RecordsPropertySchema, RelayFetchSchema, RelayRequestSchema, ResolvedCredentialsSchema, SDK_OPTIONS_ID, SDK_VERSION, STABILITY_DEFINITIONS, TablePropertySchema, TablesPropertySchema, TriggerInboxKeyPropertySchema, TriggerInboxNamePropertySchema, TriggerInboxPropertySchema, WatchTriggerInboxSchema, ZAPIER_BASE_URL, ZAPIER_MAX_CONCURRENT_REQUESTS, ZAPIER_MAX_NETWORK_RETRIES, ZAPIER_MAX_NETWORK_RETRY_DELAY_MILLISECONDS, ZapierAbortDrainSignal, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierApprovalError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierConflictError, ZapierError, ZapierNotFoundError, ZapierRateLimitError, ZapierRelayError, ZapierReleaseTriggerMessageSignal, ZapierResourceNotFoundError, ZapierSignal, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, apiPluginRef, appKeyResolver, appsPlugin, batch, buildApplicationLifecycleEvent, buildCapabilityMessage, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, cleanupEventListeners, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, connectionIdGenericResolver, connectionIdResolver, connectionsPlugin, connectionsPluginRef, createActionRunPlugin, createBaseEvent, createClientCredentialsPlugin, createMemoryCache, createTableFieldsPlugin, createTablePlugin, createTableRecordsPlugin, createZapierApi, createZapierSdk, createZapierSdkWithoutRegistry, deleteClientCredentialsPlugin, deleteTableFieldsPlugin, deleteTablePlugin, deleteTableRecordsPlugin, descriptionFor, durableRunIdResolver, eventEmissionHookPlugin, eventEmissionPlugin, eventEmissionPluginRef, extractErrorDetail, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, formatExtensionPluginFailure, generateEventId, getActionInputFieldsSchemaPlugin, getActionPlugin, getActionRunPlugin, getAgent, getAppPlugin, getBaseUrlFromCredentials, getCallerContext, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOrCreateApiClient, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTablePlugin, getTableRecordPlugin, getTokenFromCliLogin, getTtyContext, getZapierApprovalMode, getZapierCausationId, getZapierCorrelationId, getZapierDefaultApprovalMode, getZapierOpenAutoModeApprovalsInBrowser, getZapierSdkService, injectCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCredentialsFunction, isCredentialsObject, isPermanentHttpError, isPkceCredentials, isZapierAbortDrainSignal, isZapierActionError, isZapierAppNotFoundError, isZapierApprovalError, isZapierAuthenticationError, isZapierBundleError, isZapierConflictError, isZapierError, isZapierNotFoundError, isZapierRateLimitError, isZapierReleaseTriggerMessageSignal, isZapierResourceNotFoundError, isZapierSignal, isZapierTimeoutError, isZapierValidationError, listActionInputFieldChoicesPlugin, listActionInputFieldsPlugin, listActionsPlugin, listAppsPlugin, listClientCredentialsPlugin, listConnectionsPlugin, listTableFieldsPlugin, listTableRecordsPlugin, listTablesPlugin, logDeprecation, manifestPlugin, manifestPluginRef, operationAnnotatorPlugin, parseConcurrencyEnvVar, readManifestFromFile, requestPlugin, resetDeprecationWarnings, resolveAuth, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, resolveCredentialsPlugin, resolveCredentialsPluginRef, runActionPlugin, runWithCallerContext, sdkOptionsPluginRef, tableFieldIdsResolver, tableFieldsResolver, tableFiltersResolver, tableIdResolver, tableNameResolver, tableRecordIdResolver, tableRecordIdsResolver, tableRecordsResolver, tableSortResolver, tableUpdateRecordsResolver, triggerInboxResolver, triggerMessagesResolver, updateTableRecordsPlugin, workflowDraftIdResolver, workflowDraftRevisionResolver, workflowIdResolver, workflowRunIdResolver, workflowVersionIdResolver, zapierAdaptError, zapierCoreOptions, zapierSdkPlugin };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { zapierSdkPlugin, zapierCoreOptions, SDK_OPTIONS_ID } from './chunk-
|
|
1
|
+
import { zapierSdkPlugin, zapierCoreOptions, SDK_OPTIONS_ID } from './chunk-NVVSKZ3Y.mjs';
|
|
2
2
|
import { definePlugin, createSdk, CORE_OPTIONS_ID } from '@zapier/kitcore';
|
|
3
3
|
|
|
4
4
|
var zapierBetaSdkPlugin = definePlugin({
|