@zapier/zapier-sdk 0.95.0 → 0.97.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 +12 -0
- package/README.md +101 -19
- package/dist/{chunk-Z7BGM75G.cjs → chunk-H24FJYFA.cjs} +352 -22
- package/dist/{chunk-JZDH3POI.mjs → chunk-RTT7PDNL.mjs} +352 -22
- package/dist/experimental.cjs +735 -382
- package/dist/experimental.d.mts +134 -1
- package/dist/experimental.d.ts +134 -1
- package/dist/experimental.mjs +357 -4
- package/dist/index.cjs +276 -276
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/dist/experimental.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineMethod, DEFAULT_PAGE_SIZE, apiPluginRef, workflowIdResolver, openEnum, durableRunIdResolver, defineResolver, ZapierConflictError, extractErrorDetail, workflowVersionIdResolver, workflowDraftIdResolver, ZapierApiError, workflowRunIdResolver, definePlugin, zapierSdkPlugin, ZapierValidationError, createSdk, zapierCoreOptions, CORE_OPTIONS_ID, SDK_OPTIONS_ID } from './chunk-
|
|
2
|
-
export { ACTION_RUNS_PATH, API_ID, ActionKeyPropertySchema, ActionPropertySchema, ActionTimeoutMillisecondsPropertySchema, ActionTimeoutSecondsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AppPropertySchema, AppsPropertySchema, AuthMechanism, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, CONNECTIONS_ID, CONTEXT, CONTEXT_CACHE_MAX_SIZE, CONTEXT_CACHE_TTL_MILLISECONDS, CORE_ERROR_SYMBOL, CORE_OPTIONS_ID, CORE_SIGNAL_SYMBOL, ClientCredentialsObjectSchema, ConnectionEntrySchema, ConnectionIdPropertySchema, ConnectionPropertySchema, ConnectionsMapSchema, ConnectionsPropertySchema, CoreCancelledSignal, CoreDisposeError, CoreErrorCode, CoreSignal, 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, 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, addPlugin, apiPlugin, apiPluginRef, appKeyResolver, appsPlugin, batch, buildApplicationLifecycleEvent, buildCapabilityMessage, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, cleanupEventListeners, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, composePlugins, connectionIdGenericResolver, connectionIdResolver, connectionsPlugin, connectionsPluginRef, createActionRunPlugin, createBaseEvent, createClientCredentialsPlugin, createController, createCorePlugin, createFunction, createMemoryCache, createPaginatedFunction, createPaginatedPluginMethod, createPluginMethod, createPluginStack, createSdk, createTableFieldsPlugin, createTablePlugin, createTableRecordsPlugin, createZapierApi, createZapierSdkWithoutRegistry, declareMethod, declareOptionalProperty, declarePlugin, declareProperty, defineFormatter, defineLegacyMerge, defineMethod, defineMethodOverride, definePlugin, defineProperty, defineResolver, deleteClientCredentialsPlugin, deleteTableFieldsPlugin, deleteTablePlugin, deleteTableRecordsPlugin, disposeSdk, durableRunIdResolver, eventEmissionHookPlugin, eventEmissionPlugin, eventEmissionPluginRef, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, fromFunctionPlugin, generateEventId, getActionInputFieldsSchemaPlugin, getActionPlugin, getActionRunPlugin, getAgent, getAppPlugin, getBaseUrlFromCredentials, getCallerContext, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getContext, getCoreErrorCause, getCoreErrorCode, getCpuTime, getCurrentTimestamp, getMemoryUsage, getNegatable, getOrCreateApiClient, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getRegistryPlugin, getReleaseId, getTablePlugin, getTableRecordPlugin, getTokenFromCliLogin, getTtyContext, getZapierApprovalMode, getZapierDefaultApprovalMode, getZapierOpenAutoModeApprovalsInBrowser, getZapierSdkService, injectCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCoreCancelledSignal, isCoreError, isCoreSignal, isCredentialsFunction, isCredentialsObject, isPermanentHttpError, isPkceCredentials, isPositional, 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, omitExports, operationAnnotatorPlugin, parseConcurrencyEnvVar, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuth, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, resolveCredentialsPlugin, resolveCredentialsPluginRef, resolvePlugin, runActionPlugin, runInMethodScope, runWithCallerContext, runWithTelemetryContext, sdkOptionsPluginRef, selectExports, tableFieldIdsResolver, tableFieldsResolver, tableFiltersResolver, tableIdResolver, tableNameResolver, tableRecordIdResolver, tableRecordIdsResolver, tableRecordsResolver, tableSortResolver, tableUpdateRecordsResolver, toSnakeCase, toTitleCase, triggerInboxResolver, triggerMessagesResolver, updateTableRecordsPlugin, workflowDraftIdResolver, workflowIdResolver, workflowRunIdResolver, workflowVersionIdResolver, zapierAdaptError, zapierCoreOptions, zapierSdkPlugin } from './chunk-
|
|
1
|
+
import { defineMethod, DEFAULT_PAGE_SIZE, apiPluginRef, workflowIdResolver, openEnum, durableRunIdResolver, defineResolver, ZapierConflictError, extractErrorDetail, workflowVersionIdResolver, workflowDraftIdResolver, ZapierApiError, workflowRunIdResolver, definePlugin, zapierSdkPlugin, ZapierValidationError, ZapierConfigurationError, createSdk, zapierCoreOptions, CORE_OPTIONS_ID, SDK_OPTIONS_ID } from './chunk-RTT7PDNL.mjs';
|
|
2
|
+
export { ACTION_RUNS_PATH, API_ID, ActionKeyPropertySchema, ActionPropertySchema, ActionTimeoutMillisecondsPropertySchema, ActionTimeoutSecondsPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AppPropertySchema, AppsPropertySchema, AuthMechanism, AuthenticationIdPropertySchema, BaseSdkOptionsSchema, CONNECTIONS_ID, CONTEXT, CONTEXT_CACHE_MAX_SIZE, CONTEXT_CACHE_TTL_MILLISECONDS, CORE_ERROR_SYMBOL, CORE_OPTIONS_ID, CORE_SIGNAL_SYMBOL, ClientCredentialsObjectSchema, ConnectionEntrySchema, ConnectionIdPropertySchema, ConnectionPropertySchema, ConnectionsMapSchema, ConnectionsPropertySchema, CoreCancelledSignal, CoreDisposeError, CoreErrorCode, CoreSignal, 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, 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, addPlugin, apiPlugin, apiPluginRef, appKeyResolver, appsPlugin, batch, buildApplicationLifecycleEvent, buildCapabilityMessage, buildErrorEvent, buildErrorEventWithContext, buildMethodCalledEvent, cleanupEventListeners, clearTokenCache, clientCredentialsNameResolver, clientIdResolver, composePlugins, connectionIdGenericResolver, connectionIdResolver, connectionsPlugin, connectionsPluginRef, createActionRunPlugin, createBaseEvent, createClientCredentialsPlugin, createController, createCorePlugin, createFunction, createMemoryCache, createPaginatedFunction, createPaginatedPluginMethod, createPluginMethod, createPluginStack, createSdk, createTableFieldsPlugin, createTablePlugin, createTableRecordsPlugin, createZapierApi, createZapierSdkWithoutRegistry, declareMethod, declareOptionalProperty, declarePlugin, declareProperty, defineFormatter, defineLegacyMerge, defineMethod, defineMethodOverride, definePlugin, defineProperty, defineResolver, deleteClientCredentialsPlugin, deleteTableFieldsPlugin, deleteTablePlugin, deleteTableRecordsPlugin, disposeSdk, durableRunIdResolver, eventEmissionHookPlugin, eventEmissionPlugin, eventEmissionPluginRef, fetchPlugin, findFirstConnectionPlugin, findManifestEntry, findUniqueConnectionPlugin, formatErrorMessage, fromFunctionPlugin, generateEventId, getActionInputFieldsSchemaPlugin, getActionPlugin, getActionRunPlugin, getAgent, getAppPlugin, getBaseUrlFromCredentials, getCallerContext, getCiPlatform, getClientIdFromCredentials, getConnectionPlugin, getContext, getCoreErrorCause, getCoreErrorCode, getCpuTime, getCurrentTimestamp, getMemoryUsage, getNegatable, getOrCreateApiClient, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getRegistryPlugin, getReleaseId, getTablePlugin, getTableRecordPlugin, getTokenFromCliLogin, getTtyContext, getZapierApprovalMode, getZapierDefaultApprovalMode, getZapierOpenAutoModeApprovalsInBrowser, getZapierSdkService, injectCliLogin, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, invalidateCachedToken, invalidateCredentialsToken, isCi, isCliLoginAvailable, isClientCredentials, isCoreCancelledSignal, isCoreError, isCoreSignal, isCredentialsFunction, isCredentialsObject, isPermanentHttpError, isPkceCredentials, isPositional, 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, omitExports, operationAnnotatorPlugin, parseConcurrencyEnvVar, readManifestFromFile, registryPlugin, requestPlugin, resetDeprecationWarnings, resolveAuth, resolveAuthToken, resolveCredentials, resolveCredentialsFromEnv, resolveCredentialsPlugin, resolveCredentialsPluginRef, resolvePlugin, runActionPlugin, runInMethodScope, runWithCallerContext, runWithTelemetryContext, sdkOptionsPluginRef, selectExports, tableFieldIdsResolver, tableFieldsResolver, tableFiltersResolver, tableIdResolver, tableNameResolver, tableRecordIdResolver, tableRecordIdsResolver, tableRecordsResolver, tableSortResolver, tableUpdateRecordsResolver, toSnakeCase, toTitleCase, triggerInboxResolver, triggerMessagesResolver, updateTableRecordsPlugin, workflowDraftIdResolver, workflowIdResolver, workflowRunIdResolver, workflowVersionIdResolver, zapierAdaptError, zapierCoreOptions, zapierSdkPlugin } from './chunk-RTT7PDNL.mjs';
|
|
3
3
|
import './chunk-Y6FXYEAI.mjs';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
@@ -1370,6 +1370,7 @@ var createWorkflowDraftPlugin = defineMethod({
|
|
|
1370
1370
|
return { data: CreateWorkflowDraftResponseSchema.parse(raw) };
|
|
1371
1371
|
}
|
|
1372
1372
|
});
|
|
1373
|
+
var TRIGGER_MANUAL_CONFLICT_MESSAGE2 = "Provide `trigger` or `manual: true`, not both \u2014 a trigger together with manual: true is a contradiction.";
|
|
1373
1374
|
var UpdateWorkflowDraftOptionsSchema = z.object({
|
|
1374
1375
|
workflow: z.string().uuid().describe("Durable workflow ID"),
|
|
1375
1376
|
draft: z.string().uuid().describe("Workflow draft ID"),
|
|
@@ -1382,14 +1383,19 @@ var UpdateWorkflowDraftOptionsSchema = z.object({
|
|
|
1382
1383
|
"Expected draft revision for optimistic concurrency. Pass the revision from the last read; the server rejects the save with a conflict if the draft has changed since. Omit to skip the check."
|
|
1383
1384
|
),
|
|
1384
1385
|
trigger: TriggerConfigSchema.nullish().describe(
|
|
1385
|
-
"Trigger configuration. Omit to leave the stored trigger unchanged, pass null to clear it, or pass an object to replace it."
|
|
1386
|
+
"Trigger configuration. Omit to leave the stored trigger unchanged, pass null to clear it, or pass an object to replace it; for an on-demand, triggerless workflow, clear this and pass `manual: true` instead."
|
|
1386
1387
|
),
|
|
1387
1388
|
connections: z.record(z.string(), ConnectionBindingSchema).nullish().describe(
|
|
1388
1389
|
"Map of connection aliases to Zapier connections used by the workflow. Pass `null` to clear an existing binding."
|
|
1389
1390
|
),
|
|
1390
1391
|
appVersions: z.record(z.string(), AppVersionBindingSchema).nullish().describe(
|
|
1391
1392
|
"Map of app keys to pinned app implementation/version used by the workflow. Pass `null` to clear an existing binding."
|
|
1393
|
+
),
|
|
1394
|
+
manual: z.boolean().optional().describe(
|
|
1395
|
+
"Declare this draft on-demand and triggerless. Pass `manual: true` only when omitting `trigger` (or clearing it with `trigger: null`); passing both is a contradiction the API rejects with a 400. Setting a `trigger` later clears a previously stored `manual: true`."
|
|
1392
1396
|
)
|
|
1397
|
+
}).refine(({ trigger, manual }) => manual !== true || trigger == null, {
|
|
1398
|
+
message: TRIGGER_MANUAL_CONFLICT_MESSAGE2
|
|
1393
1399
|
}).describe("Update (autosave) an open workflow draft");
|
|
1394
1400
|
var UpdateWorkflowDraftResponseSchema = WorkflowDraftSchema;
|
|
1395
1401
|
|
|
@@ -1436,6 +1442,9 @@ var updateWorkflowDraftPlugin = defineMethod({
|
|
|
1436
1442
|
} else if (input.appVersions !== void 0) {
|
|
1437
1443
|
body.app_versions = toWireAppVersions(input.appVersions);
|
|
1438
1444
|
}
|
|
1445
|
+
if (input.manual !== void 0) {
|
|
1446
|
+
body.manual = input.manual;
|
|
1447
|
+
}
|
|
1439
1448
|
const raw = await api.put(
|
|
1440
1449
|
`${CODE_SUBSTRATE_WORKFLOWS_API}/workflows/${encodeURIComponent(input.workflow)}/drafts/${encodeURIComponent(input.draft)}`,
|
|
1441
1450
|
body,
|
|
@@ -1511,6 +1520,9 @@ var PublishWorkflowDraftOptionsSchema = z.object({
|
|
|
1511
1520
|
).meta({ negatable: "disabled" }),
|
|
1512
1521
|
draftRevision: z.number().int().min(0).optional().describe(
|
|
1513
1522
|
"Expected draft revision for optimistic concurrency. Pass the revision from the last read; the server rejects the publish with a conflict if the draft has changed since. Omit to skip the check."
|
|
1523
|
+
),
|
|
1524
|
+
manual: z.boolean().optional().describe(
|
|
1525
|
+
"Declare this publish on-demand and triggerless, overriding the draft's stored intent for this publish only. Pass `manual: true` only when the draft has no trigger configured; the API rejects a draft with a trigger published as `manual: true` as a contradiction (400)."
|
|
1514
1526
|
)
|
|
1515
1527
|
}).describe(
|
|
1516
1528
|
"Publish an open draft as a new immutable workflow version. Advances the workflow's live pointer and discards the draft \u2014 publish consumes it, so an open draft always means unpublished work. Continue editing by creating a new draft, which forks from the just-published version."
|
|
@@ -1551,6 +1563,9 @@ var publishWorkflowDraftPlugin = defineMethod({
|
|
|
1551
1563
|
if (input.draftRevision !== void 0) {
|
|
1552
1564
|
body.draft_revision = input.draftRevision;
|
|
1553
1565
|
}
|
|
1566
|
+
if (input.manual !== void 0) {
|
|
1567
|
+
body.manual = input.manual;
|
|
1568
|
+
}
|
|
1554
1569
|
const raw = await api.post(
|
|
1555
1570
|
`${CODE_SUBSTRATE_WORKFLOWS_API}/workflows/${encodeURIComponent(input.workflow)}/drafts/${encodeURIComponent(input.draft)}/publish`,
|
|
1556
1571
|
body,
|
|
@@ -1830,6 +1845,341 @@ var triggerWorkflowPlugin = defineMethod({
|
|
|
1830
1845
|
}
|
|
1831
1846
|
});
|
|
1832
1847
|
|
|
1848
|
+
// src/plugins/humanInput/shared.ts
|
|
1849
|
+
var humanInputDefaults = {
|
|
1850
|
+
categories: ["human-input"],
|
|
1851
|
+
experimental: true
|
|
1852
|
+
};
|
|
1853
|
+
var FORMS_API = "/forms/v0";
|
|
1854
|
+
var FORMS_ACCESS_DENIED_DETAIL = "This user does not yet have access to Forms.";
|
|
1855
|
+
function firstErrorDetail(data) {
|
|
1856
|
+
if (typeof data !== "object" || data === null || !("errors" in data) || !Array.isArray(data.errors)) {
|
|
1857
|
+
return void 0;
|
|
1858
|
+
}
|
|
1859
|
+
const first = data.errors[0];
|
|
1860
|
+
if (typeof first !== "object" || first === null || !("detail" in first)) {
|
|
1861
|
+
return void 0;
|
|
1862
|
+
}
|
|
1863
|
+
return typeof first.detail === "string" ? first.detail : void 0;
|
|
1864
|
+
}
|
|
1865
|
+
function handleFormsAccessError({
|
|
1866
|
+
status,
|
|
1867
|
+
data
|
|
1868
|
+
}) {
|
|
1869
|
+
if (status !== 403 || firstErrorDetail(data) !== FORMS_ACCESS_DENIED_DETAIL) {
|
|
1870
|
+
return void 0;
|
|
1871
|
+
}
|
|
1872
|
+
return new ZapierConfigurationError(
|
|
1873
|
+
`${FORMS_ACCESS_DENIED_DETAIL} Request access through Zapier support at https://zapier.com/app/get-help.`,
|
|
1874
|
+
{ statusCode: status }
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
// src/plugins/humanInput/utils.ts
|
|
1879
|
+
var FORM_DOCUMENT_SCHEMA_VERSION = 4;
|
|
1880
|
+
function omitUndefined(body) {
|
|
1881
|
+
return Object.fromEntries(
|
|
1882
|
+
Object.entries(body).filter(([, value]) => value !== void 0)
|
|
1883
|
+
);
|
|
1884
|
+
}
|
|
1885
|
+
function labelToKey(label) {
|
|
1886
|
+
return label.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
1887
|
+
}
|
|
1888
|
+
function toWireDataSource(dataSource) {
|
|
1889
|
+
return omitUndefined({
|
|
1890
|
+
app: dataSource.app,
|
|
1891
|
+
action_type: dataSource.actionType,
|
|
1892
|
+
resource: dataSource.resource,
|
|
1893
|
+
value_key: dataSource.valueKey,
|
|
1894
|
+
label_key: dataSource.labelKey
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
function toFieldAttrs(field, key) {
|
|
1898
|
+
const base = {
|
|
1899
|
+
key,
|
|
1900
|
+
label: field.label,
|
|
1901
|
+
required: field.required ?? false,
|
|
1902
|
+
field_type: field.type,
|
|
1903
|
+
disabled: field.disabled
|
|
1904
|
+
};
|
|
1905
|
+
switch (field.type) {
|
|
1906
|
+
case "yes_no":
|
|
1907
|
+
return omitUndefined({ ...base, variant: field.variant ?? "checkbox" });
|
|
1908
|
+
case "url":
|
|
1909
|
+
return omitUndefined({ ...base, multi_url: field.multiUrl ?? false });
|
|
1910
|
+
case "date":
|
|
1911
|
+
case "date_range":
|
|
1912
|
+
return omitUndefined({
|
|
1913
|
+
...base,
|
|
1914
|
+
include_time: field.includeTime ?? false
|
|
1915
|
+
});
|
|
1916
|
+
case "currency":
|
|
1917
|
+
return omitUndefined({
|
|
1918
|
+
...base,
|
|
1919
|
+
decimals: field.decimals ?? 2,
|
|
1920
|
+
currency_format: field.currencyFormat
|
|
1921
|
+
});
|
|
1922
|
+
case "phone_number":
|
|
1923
|
+
return omitUndefined({
|
|
1924
|
+
...base,
|
|
1925
|
+
default_country: field.defaultCountry ?? "US",
|
|
1926
|
+
phone_number_format: field.phoneNumberFormat ?? "national",
|
|
1927
|
+
accepted_countries: field.acceptedCountries
|
|
1928
|
+
});
|
|
1929
|
+
case "dropdown":
|
|
1930
|
+
return omitUndefined({
|
|
1931
|
+
...base,
|
|
1932
|
+
options: field.options,
|
|
1933
|
+
multi_select: field.multiSelect ?? false
|
|
1934
|
+
});
|
|
1935
|
+
case "integration_backed":
|
|
1936
|
+
return omitUndefined({
|
|
1937
|
+
...base,
|
|
1938
|
+
data_source: field.dataSource === void 0 ? void 0 : toWireDataSource(field.dataSource)
|
|
1939
|
+
});
|
|
1940
|
+
default:
|
|
1941
|
+
return omitUndefined(base);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
function assertUniqueKeys(keys, fields) {
|
|
1945
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1946
|
+
for (const [index, key] of keys.entries()) {
|
|
1947
|
+
const label = fields[index]?.label ?? "";
|
|
1948
|
+
const previous = seen.get(key);
|
|
1949
|
+
if (previous !== void 0) {
|
|
1950
|
+
throw new ZapierValidationError(
|
|
1951
|
+
`Fields "${previous}" and "${label}" both derive the submission key "${key}". Give them labels that differ by more than punctuation or casing.`,
|
|
1952
|
+
{ details: { key, labels: [previous, label] } }
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
seen.set(key, label);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
function toEndingActionNode(id, title, message) {
|
|
1959
|
+
const trimmedTitle = title?.trim();
|
|
1960
|
+
const trimmedMessage = message?.trim();
|
|
1961
|
+
if (!trimmedTitle && !trimmedMessage) return void 0;
|
|
1962
|
+
return {
|
|
1963
|
+
id,
|
|
1964
|
+
type: "ending_action",
|
|
1965
|
+
attrs: omitUndefined({
|
|
1966
|
+
variant: "success",
|
|
1967
|
+
title: trimmedTitle || void 0,
|
|
1968
|
+
message: trimmedMessage || void 0
|
|
1969
|
+
})
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
function buildFormDocument(input) {
|
|
1973
|
+
const fields = input.fields ?? [];
|
|
1974
|
+
const keys = fields.map(
|
|
1975
|
+
(field, index) => labelToKey(field.label) || `field_${index + 1}`
|
|
1976
|
+
);
|
|
1977
|
+
assertUniqueKeys(keys, fields);
|
|
1978
|
+
const children = fields.map((field, index) => ({
|
|
1979
|
+
id: `@field_${index + 1}`,
|
|
1980
|
+
type: "field",
|
|
1981
|
+
attrs: toFieldAttrs(field, keys[index])
|
|
1982
|
+
}));
|
|
1983
|
+
const endingAction = toEndingActionNode(
|
|
1984
|
+
"@ending_action",
|
|
1985
|
+
input.confirmationTitle,
|
|
1986
|
+
input.confirmationMessage
|
|
1987
|
+
);
|
|
1988
|
+
if (endingAction) children.push(endingAction);
|
|
1989
|
+
return {
|
|
1990
|
+
id: "@root",
|
|
1991
|
+
type: "root",
|
|
1992
|
+
attrs: omitUndefined({
|
|
1993
|
+
schema_version: FORM_DOCUMENT_SCHEMA_VERSION,
|
|
1994
|
+
title: input.title,
|
|
1995
|
+
description: input.description
|
|
1996
|
+
}),
|
|
1997
|
+
children
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
function toWireFormAttributes(input) {
|
|
2001
|
+
return omitUndefined({
|
|
2002
|
+
document: input.document ?? buildFormDocument(input),
|
|
2003
|
+
consumer_auth: input.consumerAuth,
|
|
2004
|
+
callback_url: input.callbackUrl,
|
|
2005
|
+
publish: input.draft === true ? false : void 0
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
var FormFieldTypeSchema = z.enum([
|
|
2009
|
+
"short_text",
|
|
2010
|
+
"long_text",
|
|
2011
|
+
"email",
|
|
2012
|
+
"number",
|
|
2013
|
+
"yes_no",
|
|
2014
|
+
"url",
|
|
2015
|
+
"date",
|
|
2016
|
+
"date_range",
|
|
2017
|
+
"currency",
|
|
2018
|
+
"phone_number",
|
|
2019
|
+
"dropdown",
|
|
2020
|
+
"integration_backed"
|
|
2021
|
+
]);
|
|
2022
|
+
var ConsumerAuthSchema = z.enum(["none", "zapier"]);
|
|
2023
|
+
var DropdownOptionSchema = z.object({
|
|
2024
|
+
value: z.string().min(1).describe("The value submitted when this option is selected."),
|
|
2025
|
+
label: z.string().min(1).describe("Human-readable label shown to the user.")
|
|
2026
|
+
});
|
|
2027
|
+
var FieldDataSourceSchema = z.object({
|
|
2028
|
+
app: z.string().min(1).describe(
|
|
2029
|
+
"Zapier app to pull options from. See `listApps` for the catalog."
|
|
2030
|
+
),
|
|
2031
|
+
actionType: z.enum(["read", "read_bulk"]).describe(
|
|
2032
|
+
"Whether the data source returns a single record (`read`) or a collection (`read_bulk`)."
|
|
2033
|
+
),
|
|
2034
|
+
resource: z.string().min(1).describe(
|
|
2035
|
+
"Resource name within the app \u2014 typically a trigger or search key from the app's definition."
|
|
2036
|
+
),
|
|
2037
|
+
valueKey: z.string().min(1).optional().describe(
|
|
2038
|
+
"Property on each returned record to use as the submitted option value. Defaults to `id`."
|
|
2039
|
+
),
|
|
2040
|
+
labelKey: z.string().min(1).optional().describe(
|
|
2041
|
+
"Property on each returned record to use as the displayed option label. Defaults to a sensible name field."
|
|
2042
|
+
)
|
|
2043
|
+
});
|
|
2044
|
+
var FormFieldBaseSchema = z.object({
|
|
2045
|
+
label: z.string().min(1).describe("Human-readable label shown above the input."),
|
|
2046
|
+
type: FormFieldTypeSchema.describe("The type of field."),
|
|
2047
|
+
required: z.boolean().optional().describe("Whether the field must be answered before the form can submit."),
|
|
2048
|
+
disabled: z.boolean().optional().describe(
|
|
2049
|
+
"When true, the field is rendered read-only \u2014 shown but not editable. A rendering hint only; it is not enforced during submission validation."
|
|
2050
|
+
),
|
|
2051
|
+
variant: z.enum(["checkbox", "radio"]).optional().describe(
|
|
2052
|
+
"For `yes_no` fields: `checkbox` renders a single toggle, `radio` renders explicit yes/no buttons. Defaults to `checkbox`."
|
|
2053
|
+
),
|
|
2054
|
+
multiUrl: z.boolean().optional().describe(
|
|
2055
|
+
"For `url` fields: when true the field accepts a list of URLs, otherwise a single URL. Defaults to false."
|
|
2056
|
+
),
|
|
2057
|
+
includeTime: z.boolean().optional().describe(
|
|
2058
|
+
"For `date` and `date_range` fields: when true the picker also captures a time. Defaults to false."
|
|
2059
|
+
),
|
|
2060
|
+
currencyFormat: z.string().regex(/^[A-Za-z]{3}$/).optional().describe(
|
|
2061
|
+
"For `currency` fields: ISO 4217 currency code (e.g. `usd`, `eur`). Controls the symbol shown in the form UI."
|
|
2062
|
+
),
|
|
2063
|
+
decimals: z.union([z.literal(0), z.literal(2)]).optional().describe(
|
|
2064
|
+
"For `currency` fields: allowed decimal places. `0` for whole numbers, `2` for up to two decimal places. Defaults to `2`."
|
|
2065
|
+
),
|
|
2066
|
+
defaultCountry: z.string().regex(/^[A-Z]{2}$/).optional().describe(
|
|
2067
|
+
"For `phone_number` fields: ISO 3166-1 alpha-2 code for the default selected country (e.g. `US`). Defaults to `US`."
|
|
2068
|
+
),
|
|
2069
|
+
phoneNumberFormat: z.enum(["national", "international"]).optional().describe(
|
|
2070
|
+
"For `phone_number` fields: `national` omits the country-code prefix, `international` includes it. Defaults to `national`."
|
|
2071
|
+
),
|
|
2072
|
+
acceptedCountries: z.array(z.string().regex(/^[A-Z]{2}$/)).optional().describe(
|
|
2073
|
+
"For `phone_number` fields: restrict input to specific ISO 3166-1 alpha-2 country codes. Omit to allow all countries."
|
|
2074
|
+
),
|
|
2075
|
+
options: z.array(DropdownOptionSchema).min(1).optional().describe(
|
|
2076
|
+
"For `dropdown` fields: the selectable options. At least one is required."
|
|
2077
|
+
),
|
|
2078
|
+
multiSelect: z.boolean().optional().describe(
|
|
2079
|
+
"For `dropdown` fields: when true the user may select multiple options. Defaults to false."
|
|
2080
|
+
),
|
|
2081
|
+
dataSource: FieldDataSourceSchema.optional().describe(
|
|
2082
|
+
"For `integration_backed` fields: where to fetch the field's options from at render time."
|
|
2083
|
+
)
|
|
2084
|
+
});
|
|
2085
|
+
var FormFieldSchema = FormFieldBaseSchema.superRefine((field, ctx) => {
|
|
2086
|
+
if (field.type === "dropdown" && field.options === void 0) {
|
|
2087
|
+
ctx.addIssue({
|
|
2088
|
+
code: "custom",
|
|
2089
|
+
path: ["options"],
|
|
2090
|
+
message: "A dropdown field requires `options`."
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
if (field.type === "integration_backed" && field.dataSource === void 0) {
|
|
2094
|
+
ctx.addIssue({
|
|
2095
|
+
code: "custom",
|
|
2096
|
+
path: ["dataSource"],
|
|
2097
|
+
message: "An integration_backed field requires `dataSource`."
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
});
|
|
2101
|
+
var RawFormDocumentSchema = z.object({
|
|
2102
|
+
id: z.string().min(1),
|
|
2103
|
+
type: z.literal("root"),
|
|
2104
|
+
attrs: z.object({
|
|
2105
|
+
schema_version: z.number().int(),
|
|
2106
|
+
title: z.string().min(1)
|
|
2107
|
+
}).loose(),
|
|
2108
|
+
children: z.array(z.unknown()).optional()
|
|
2109
|
+
}).loose();
|
|
2110
|
+
var FormSchema = z.object({
|
|
2111
|
+
id: z.string(),
|
|
2112
|
+
title: z.string(),
|
|
2113
|
+
description: z.string().nullish(),
|
|
2114
|
+
hosted_url: z.string(),
|
|
2115
|
+
submission_count: z.number(),
|
|
2116
|
+
account_id: z.number(),
|
|
2117
|
+
owner_id: z.string(),
|
|
2118
|
+
created_at: z.string(),
|
|
2119
|
+
updated_at: z.string(),
|
|
2120
|
+
document: z.unknown(),
|
|
2121
|
+
last_published_at: z.string().nullable(),
|
|
2122
|
+
consumer_auth: z.unknown(),
|
|
2123
|
+
callback_url: z.unknown()
|
|
2124
|
+
}).loose();
|
|
2125
|
+
|
|
2126
|
+
// src/plugins/humanInput/createForm/schemas.ts
|
|
2127
|
+
var CreateFormDescription = "Create a Zapier Form from a title and optional fields. Forms publish by default and return a shareable `hosted_url`; set `draft` to save without publishing.";
|
|
2128
|
+
var CreateFormSchema = z.object({
|
|
2129
|
+
title: z.string().min(1).describe("The title shown in the Forms UI and on the form."),
|
|
2130
|
+
description: z.string().optional().describe("An optional description of the form."),
|
|
2131
|
+
fields: z.array(FormFieldSchema).optional().describe("Initial fields to add to the form."),
|
|
2132
|
+
draft: z.boolean().optional().describe(
|
|
2133
|
+
"When true, save without publishing. Omit to publish immediately, making `hosted_url` live."
|
|
2134
|
+
),
|
|
2135
|
+
confirmationTitle: z.string().max(200).optional().describe(
|
|
2136
|
+
"Heading shown to the respondent after they submit. Omit to use the form renderer's default."
|
|
2137
|
+
),
|
|
2138
|
+
confirmationMessage: z.string().max(1e3).optional().describe(
|
|
2139
|
+
"Message shown to the respondent after they submit, below the confirmation title. Omit to use the form renderer's default."
|
|
2140
|
+
),
|
|
2141
|
+
callbackUrl: z.string().url().optional().describe(
|
|
2142
|
+
"Absolute http/https URL notified with the submission JSON each time the form is answered."
|
|
2143
|
+
),
|
|
2144
|
+
consumerAuth: ConsumerAuthSchema.optional().describe(
|
|
2145
|
+
"Who may open the published form. `none` (the default) leaves it public to anyone with the link; `zapier` requires the visitor to be signed in to Zapier on the form's owning account."
|
|
2146
|
+
),
|
|
2147
|
+
document: RawFormDocumentSchema.optional().describe(
|
|
2148
|
+
"Escape hatch: a complete form document tree, sent as-is. When supplied it replaces the document built from `fields`, and `title`, `description`, `confirmationTitle`, and `confirmationMessage` are ignored. Use only for structures the flat field list cannot express, such as approval decisions or multi-column row layout."
|
|
2149
|
+
)
|
|
2150
|
+
}).describe(CreateFormDescription);
|
|
2151
|
+
|
|
2152
|
+
// src/plugins/humanInput/createForm/index.ts
|
|
2153
|
+
var createFormPlugin = defineMethod({
|
|
2154
|
+
...humanInputDefaults,
|
|
2155
|
+
name: "createForm",
|
|
2156
|
+
imports: [apiPluginRef],
|
|
2157
|
+
type: "create",
|
|
2158
|
+
itemType: "Form",
|
|
2159
|
+
inputSchema: CreateFormSchema,
|
|
2160
|
+
outputSchema: FormSchema,
|
|
2161
|
+
output: "item",
|
|
2162
|
+
run: async ({ imports, input }) => {
|
|
2163
|
+
const api = imports.api;
|
|
2164
|
+
const body = toWireFormAttributes({
|
|
2165
|
+
title: input.title,
|
|
2166
|
+
description: input.description,
|
|
2167
|
+
confirmationTitle: input.confirmationTitle,
|
|
2168
|
+
confirmationMessage: input.confirmationMessage,
|
|
2169
|
+
consumerAuth: input.consumerAuth,
|
|
2170
|
+
callbackUrl: input.callbackUrl,
|
|
2171
|
+
draft: input.draft,
|
|
2172
|
+
fields: input.fields,
|
|
2173
|
+
document: input.document
|
|
2174
|
+
});
|
|
2175
|
+
const rawResponse = await api.post(`${FORMS_API}/forms`, body, {
|
|
2176
|
+
authRequired: true,
|
|
2177
|
+
customErrorHandler: handleFormsAccessError
|
|
2178
|
+
});
|
|
2179
|
+
return { data: FormSchema.parse(rawResponse) };
|
|
2180
|
+
}
|
|
2181
|
+
});
|
|
2182
|
+
|
|
1833
2183
|
// src/experimental.ts
|
|
1834
2184
|
var zapierExperimentalSdkPlugin = definePlugin({
|
|
1835
2185
|
namespace: "zapier",
|
|
@@ -1862,7 +2212,10 @@ var zapierExperimentalSdkPlugin = definePlugin({
|
|
|
1862
2212
|
runDurablePlugin,
|
|
1863
2213
|
cancelDurableRunPlugin,
|
|
1864
2214
|
triggerWorkflowPlugin,
|
|
1865
|
-
getTriggerRunPlugin
|
|
2215
|
+
getTriggerRunPlugin,
|
|
2216
|
+
// Human input (experimental). Routed through the Public API Gateway
|
|
2217
|
+
// rather than the sdkapi proxy — see the `/forms` entry in api/client.ts.
|
|
2218
|
+
createFormPlugin
|
|
1866
2219
|
]
|
|
1867
2220
|
});
|
|
1868
2221
|
function createZapierSdk(options = {}) {
|