@slates/provider 1.0.0-rc.34 → 1.0.0-rc.35
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/dist/index.cjs +193 -10
- package/dist/index.d.cts +71 -1
- package/dist/index.d.ts +71 -1
- package/dist/index.module.js +191 -10
- package/package.json +1 -1
- package/src/action/action.ts +1 -0
- package/src/action/builder.ts +73 -1
- package/src/action/index.ts +1 -0
- package/src/action/optionList.ts +94 -0
- package/src/action/trigger.test.ts +132 -0
- package/src/action/trigger.ts +7 -0
- package/src/action/triggerGroup.test.ts +82 -0
- package/src/action/triggerGroup.ts +117 -1
- package/src/specification/slate.test.ts +70 -1
- package/src/specification/slate.ts +27 -3
package/dist/index.d.ts
CHANGED
|
@@ -535,6 +535,40 @@ declare let runWithContext: <InputType extends {}, RV>(context: SlatePublicConte
|
|
|
535
535
|
declare let getCurrentContext: <ConfigType extends {}, AuthType extends {}, InputType extends {}>() => SlateContext<ConfigType, AuthType, InputType>;
|
|
536
536
|
declare let getRuntimeInfo: () => Readonly<SlateRuntimeInfo> | null;
|
|
537
537
|
|
|
538
|
+
interface SlateOption {
|
|
539
|
+
value: string | number;
|
|
540
|
+
label: string;
|
|
541
|
+
description?: string;
|
|
542
|
+
}
|
|
543
|
+
interface SlateOptionListPage {
|
|
544
|
+
options: SlateOption[];
|
|
545
|
+
nextPageToken?: any | null;
|
|
546
|
+
}
|
|
547
|
+
type SlateOptionListHandler<ConfigType extends {}, AuthType extends {}, ParamsType extends {} = {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
548
|
+
query: string | null;
|
|
549
|
+
pageToken: any | null;
|
|
550
|
+
params: ParamsType;
|
|
551
|
+
}>) => Promise<SlateOptionListPage>;
|
|
552
|
+
interface SlateOptionListParameters<ConfigType extends {}, AuthType extends {}, ParamsSchema extends z$1.ZodObject<any> = z$1.ZodObject<{}>> {
|
|
553
|
+
key: string;
|
|
554
|
+
/** Made strict when declared, so params with a key the schema does not name are rejected. */
|
|
555
|
+
paramsSchema?: ParamsSchema;
|
|
556
|
+
list: SlateOptionListHandler<ConfigType, AuthType, z$1.output<ParamsSchema>>;
|
|
557
|
+
}
|
|
558
|
+
/** A list of options other integrations can link their selection fields to. */
|
|
559
|
+
declare class SlateOptionList<ConfigType extends {}, AuthType extends {}, ParamsSchema extends z$1.ZodObject<any> = z$1.ZodObject<{}>> {
|
|
560
|
+
private readonly _spec;
|
|
561
|
+
private readonly _params;
|
|
562
|
+
private readonly _paramsSchema;
|
|
563
|
+
private constructor();
|
|
564
|
+
static create<ConfigType extends {}, AuthType extends {}, ParamsSchema extends z$1.ZodObject<any> = z$1.ZodObject<{}>>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateOptionListParameters<ConfigType, AuthType, ParamsSchema>): SlateOptionList<ConfigType, AuthType, ParamsSchema>;
|
|
565
|
+
get spec(): SlateSpecification<ConfigType, AuthType>;
|
|
566
|
+
get key(): string;
|
|
567
|
+
get paramsSchema(): z$1.ZodObject<any, z$1.core.$strip>;
|
|
568
|
+
get list(): SlateOptionListHandler<ConfigType, AuthType, z$1.core.output<ParamsSchema>>;
|
|
569
|
+
}
|
|
570
|
+
declare let optionList: <ConfigType extends {}, AuthType extends {}, ParamsSchema extends z$1.ZodObject<any> = z$1.ZodObject<{}>>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateOptionListParameters<ConfigType, AuthType, ParamsSchema>) => SlateOptionList<ConfigType, AuthType, ParamsSchema>;
|
|
571
|
+
|
|
538
572
|
declare let SlateDefaultPollingIntervalSeconds: number;
|
|
539
573
|
type SlateTriggerRoutingMatcher = Record<string, any>;
|
|
540
574
|
type SlateTriggerGroupSelection = Record<string, any>;
|
|
@@ -548,6 +582,23 @@ interface SlateWebhookTarget {
|
|
|
548
582
|
targetOwnership: SlateWebhookTargetOwnership;
|
|
549
583
|
}
|
|
550
584
|
type SlateTriggerGroupRoutingMatchersHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {}>) => Promise<SlateTriggerRoutingMatcher[]>;
|
|
585
|
+
/** Lists the values an account can pick for one selection field. `selection` holds what is entered so far and may be incomplete. */
|
|
586
|
+
type SlateTriggerGroupSelectionOptionsHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
587
|
+
query: string | null;
|
|
588
|
+
pageToken: any | null;
|
|
589
|
+
selection: SlateTriggerGroupSelection;
|
|
590
|
+
}>) => Promise<SlateOptionListPage>;
|
|
591
|
+
/** An option list exported by another integration, run with that integration's connection for the same account. */
|
|
592
|
+
interface SlateLinkedOptionList {
|
|
593
|
+
/** Registry name of the integration, as `<scope>/<name>`. */
|
|
594
|
+
slate: string;
|
|
595
|
+
optionList: string;
|
|
596
|
+
params?: Record<string, any>;
|
|
597
|
+
}
|
|
598
|
+
interface SlateTriggerGroupSelectionOptionsSources<ConfigType extends {}, AuthType extends {}> {
|
|
599
|
+
list?: SlateTriggerGroupSelectionOptionsHandler<ConfigType, AuthType>;
|
|
600
|
+
linked?: SlateLinkedOptionList;
|
|
601
|
+
}
|
|
551
602
|
type SlateTriggerGroupPollHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
552
603
|
state: any | null;
|
|
553
604
|
selection?: SlateTriggerGroupSelection;
|
|
@@ -736,6 +787,7 @@ interface SlateTriggerGroupParameters<ConfigType extends {}, AuthType extends {}
|
|
|
736
787
|
webhook?: SlateTriggerGroupWebhookParameters<ConfigType, AuthType>;
|
|
737
788
|
gateway?: SlateTriggerGroupGatewayParameters<ConfigType, AuthType>;
|
|
738
789
|
routingMatchers: SlateTriggerGroupRoutingMatchersHandler<ConfigType, AuthType>;
|
|
790
|
+
selectionOptions?: Record<string, SlateTriggerGroupSelectionOptionsSources<ConfigType, AuthType>>;
|
|
739
791
|
}
|
|
740
792
|
declare class SlateTriggerGroup<ConfigType extends {}, AuthType extends {}, InputType extends {} = Record<string, unknown>> {
|
|
741
793
|
private readonly _spec;
|
|
@@ -754,6 +806,7 @@ declare class SlateTriggerGroup<ConfigType extends {}, AuthType extends {}, Inpu
|
|
|
754
806
|
get webhook(): SlateTriggerGroupWebhookParameters<ConfigType, AuthType> | undefined;
|
|
755
807
|
get gateway(): SlateTriggerGroupGatewayParameters<ConfigType, AuthType> | undefined;
|
|
756
808
|
get routingMatchers(): SlateTriggerGroupRoutingMatchersHandler<ConfigType, AuthType>;
|
|
809
|
+
get selectionOptions(): Record<string, SlateTriggerGroupSelectionOptionsSources<ConfigType, AuthType>>;
|
|
757
810
|
}
|
|
758
811
|
declare class SlateTriggerGroupBuilder<ConfigType extends {}, AuthType extends {}, InputType extends {} = Record<string, unknown>> {
|
|
759
812
|
#private;
|
|
@@ -776,6 +829,12 @@ declare class SlateTriggerGroupBuilder<ConfigType extends {}, AuthType extends {
|
|
|
776
829
|
/** Receive events over a platform-managed persistent connection (e.g. a WebSocket gateway). */
|
|
777
830
|
gateway(props: SlateTriggerGroupGatewayParameters<ConfigType, AuthType>): SlateTriggerGroupBuilder<ConfigType, AuthType, InputType>;
|
|
778
831
|
routingMatchers(handler: SlateTriggerGroupRoutingMatchersHandler<ConfigType, AuthType>): SlateTriggerGroupBuilder<ConfigType, AuthType, InputType>;
|
|
832
|
+
/**
|
|
833
|
+
* Lets the dashboard offer a list for these selection fields instead of a typed-in value.
|
|
834
|
+
* Each field must be a top-level property of the selection schema, which must be a zod object.
|
|
835
|
+
* For an array property the listed options are values for its items.
|
|
836
|
+
*/
|
|
837
|
+
selectionOptions(declarations: Record<string, SlateTriggerGroupSelectionOptionsSources<ConfigType, AuthType>>): SlateTriggerGroupBuilder<ConfigType, AuthType, InputType>;
|
|
779
838
|
build(): SlateTriggerGroup<ConfigType, AuthType, InputType>;
|
|
780
839
|
}
|
|
781
840
|
declare let triggerGroup: <ConfigType extends {}, AuthType extends {}, InputType extends {} = Record<string, unknown>>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateTriggerGroupCreateParameters<InputType>) => SlateTriggerGroupBuilder<ConfigType, AuthType, InputType>;
|
|
@@ -835,6 +894,7 @@ interface SlateActionParametersTrigger<ConfigType extends {}, AuthType extends {
|
|
|
835
894
|
triggerGroup: SlateTriggerGroup<ConfigType, AuthType>;
|
|
836
895
|
matches: SlateTriggerMatchesHandler;
|
|
837
896
|
map: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
897
|
+
eventAttributes?: string[];
|
|
838
898
|
}
|
|
839
899
|
type SlateActionParametersAny<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = SlateActionParametersTool<ConfigType, AuthType, InputType, OutputType> | SlateActionParametersTrigger<ConfigType, AuthType, InputType, OutputType>;
|
|
840
900
|
type SlateActionCreateParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = SlateActionParametersAny<ConfigType, AuthType, InputType, OutputType> & SlateActionParameters & {
|
|
@@ -890,6 +950,11 @@ declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extend
|
|
|
890
950
|
triggerGroup(group: SlateTriggerGroup<ConfigType, AuthType>): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic>;
|
|
891
951
|
matches(handler: SlateTriggerMatchesHandler): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic>;
|
|
892
952
|
map(handler: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic>;
|
|
953
|
+
/**
|
|
954
|
+
* Returns the values of these top-level output fields with every mapped event, so events
|
|
955
|
+
* can be filtered by them. Strings, finite numbers, booleans and arrays of those are used.
|
|
956
|
+
*/
|
|
957
|
+
eventAttributes(fields: (keyof OutputType & string)[]): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic>;
|
|
893
958
|
build(): Result;
|
|
894
959
|
}
|
|
895
960
|
|
|
@@ -970,6 +1035,7 @@ interface SlateTriggerParameters<ConfigType extends {}, AuthType extends {}, Inp
|
|
|
970
1035
|
triggerGroup: SlateTriggerGroup<ConfigType, AuthType>;
|
|
971
1036
|
matches: SlateTriggerMatchesHandler;
|
|
972
1037
|
map: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
1038
|
+
eventAttributes?: string[];
|
|
973
1039
|
}
|
|
974
1040
|
declare class SlateTrigger<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {
|
|
975
1041
|
type: string;
|
|
@@ -980,6 +1046,7 @@ declare class SlateTrigger<ConfigType extends {}, AuthType extends {}, InputType
|
|
|
980
1046
|
get triggerGroup(): SlateTriggerGroup<ConfigType, AuthType, Record<string, unknown>>;
|
|
981
1047
|
get matches(): SlateTriggerMatchesHandler;
|
|
982
1048
|
get map(): SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
1049
|
+
get eventAttributes(): string[];
|
|
983
1050
|
}
|
|
984
1051
|
declare let trigger: <ConfigType extends {}, AuthType extends {}>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters) => SlateActionBuilder<"trigger", ConfigType, AuthType, {}, {}, SlateTrigger<any, any, any, any>, false>;
|
|
985
1052
|
|
|
@@ -1263,6 +1330,7 @@ declare class Slate<ConfigType extends {}, AuthType extends {}> {
|
|
|
1263
1330
|
private readonly _triggerGroups;
|
|
1264
1331
|
private readonly _toolCategories;
|
|
1265
1332
|
private readonly _toolCategoryKeysByActionKey;
|
|
1333
|
+
private readonly _optionLists;
|
|
1266
1334
|
private constructor();
|
|
1267
1335
|
static create<ConfigType extends {}, AuthType extends {}>(params: {
|
|
1268
1336
|
spec: SlateSpecification<ConfigType, AuthType>;
|
|
@@ -1271,12 +1339,14 @@ declare class Slate<ConfigType extends {}, AuthType extends {}> {
|
|
|
1271
1339
|
adapters?: SlateAdapter<ConfigType, AuthType>[];
|
|
1272
1340
|
triggerGroups?: SlateTriggerGroup<ConfigType, AuthType>[];
|
|
1273
1341
|
toolCategories?: SlateToolCategory[];
|
|
1342
|
+
optionLists?: SlateOptionList<ConfigType, AuthType, any>[];
|
|
1274
1343
|
}): Slate<ConfigType, AuthType>;
|
|
1275
1344
|
get spec(): SlateSpecification<ConfigType, AuthType>;
|
|
1276
1345
|
get actions(): (SlateTrigger<ConfigType, AuthType, any, any> | SlateTool<ConfigType, AuthType, any, any>)[];
|
|
1277
1346
|
get adapters(): SlateAdapter<ConfigType, AuthType>[];
|
|
1278
1347
|
get triggerGroups(): SlateTriggerGroup<ConfigType, AuthType, Record<string, unknown>>[];
|
|
1279
1348
|
get toolCategories(): SlateToolCategory[];
|
|
1349
|
+
get optionLists(): SlateOptionList<ConfigType, AuthType, any>[];
|
|
1280
1350
|
getToolCategoryKeys(actionKey: string): string[];
|
|
1281
1351
|
}
|
|
1282
1352
|
|
|
@@ -1311,4 +1381,4 @@ declare let skipWebhook: (reason: string, response?: Response | SlateWebhookHttp
|
|
|
1311
1381
|
response: Response | SlateWebhookHttpResponseInit;
|
|
1312
1382
|
};
|
|
1313
1383
|
|
|
1314
|
-
export { API_ERROR_MAX_DETAILS, API_ERROR_MAX_MESSAGE_LENGTH, API_ERROR_TRUNCATED_PLACEHOLDER, AUTH_CONFIG_SECRET_PLACEHOLDER_PREFIX, type ApiErrorBuildHelpers, type ApiErrorDetailOptions, type ApiErrorResponse, type ApiErrorStatus, type ApiErrorTextOptions, type ApiServiceError, type AuthConfigSecretFilter, AuthConfigSecretRedactor, type BoundedApiErrorDetailOptions, type BuildApiServiceErrorOptions, type CreateHmacSignatureOptions, type DecodeApiErrorBodyOptions, GET_FILE_URL_TOOL_ID, type GetFileUrlHandler, type GetFileUrlToolInput, type GetFileUrlToolOutput, type NormalizeOAuthTokenResponseOptions, type OAuthExpiresAtOptions, type OAuthRefreshTokenFallbackMode, type OAuthTokenResponse, type SeenEntry, Slate, SlateAction, SlateActionBuilder, type SlateActionCreateParameters, type SlateActionDocsReference, type SlateActionParameters, type SlateActionParametersAny, type SlateActionParametersTool, type SlateActionParametersTrigger, type SlateActionScopeClause, type SlateActionScopeClauseInput, type SlateActionScopeValue, type SlateActionScopes, type SlateActionScopesInput, type SlateActionType, SlateAdapter, type SlateAdapterCapability, SlateAdapterSpec, type SlateAdapterSpecParameters, type SlateAddAttachmentContent, type SlateAddAttachmentInput, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUploadReferenceContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthDocsReference, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAuthenticatedAxiosDefaults, type SlateAxiosDefaults, type SlateAxiosErrorAdapter, type SlateAxiosErrorOptions, SlateConfig, type SlateConfigDocsReference, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, type SlateDirectUploadInput, type SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateGatewayEvent, type SlateLiveInvocationInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlateProviderDocsReference, SlatePublicContext, SlatePublicTool, type SlatePublicToolInvocationHandler, type SlatePublicToolParameters, type SlateRuntimeInfo, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, SlateToolCategory, type SlateToolCategoryParameters, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, SlateTriggerGroup, SlateTriggerGroupBuilder, type SlateTriggerGroupCreateParameters, type SlateTriggerGroupGatewayConnectHandler, type SlateTriggerGroupGatewayParameters, type SlateTriggerGroupGatewayReceiveHandler, type SlateTriggerGroupParameters, type SlateTriggerGroupPollHandler, type SlateTriggerGroupPollingParameters, type SlateTriggerGroupRoutingMatchersHandler, type SlateTriggerGroupSelection, type SlateTriggerGroupWebhookAutoRegistrationParameters, type SlateTriggerGroupWebhookDeliveryConfigParameters, type SlateTriggerGroupWebhookManualRegistrationParameters, type SlateTriggerGroupWebhookParameters, type SlateTriggerMappingHandler, type SlateTriggerMatchesHandler, type SlateTriggerParameters, type SlateTriggerRoutingMatcher, type SlateTypedDocsReference, type SlateWebhookDeliveryAuthenticateHandler, type SlateWebhookDeliveryAuthentication, type SlateWebhookExpandHandler, type SlateWebhookHttpResponseInit, type SlateWebhookManualFinishHandler, type SlateWebhookManualSetupHandler, type SlateWebhookProcessHandler, type SlateWebhookRegisterHandler, type SlateWebhookRegistrationResult, type SlateWebhookRenewHandler, type SlateWebhookSkipped, type SlateWebhookTarget, type SlateWebhookTargetListHandler, type SlateWebhookTargetOwnership, type SlateWebhookUnregisterHandler, type VerifyHmacSignatureOptions, adapterSpec, allOf, anyOf, assertNewPageToken, auth, axios, buildApiServiceError, collectApiErrorDetails, config, createApiServiceError, createAuthenticatedAxios, createAxios, createBase64Attachment, createHmacSignature, createSlateError, createTextAttachment, createUrlAttachment, decodeApiErrorBody, extractApiErrorMessage, getApiErrorResponse, getApiErrorResponseWithBody, getApiErrorStatus, getBase64ByteLength, getCurrentContext, getFileUrlTool, getFileUrlToolInputSchema, getFileUrlToolOutputSchema, getGraphWebhookValidationResponse, getMetaWebhookVerificationResponse, getOAuthExpiresAtFromExpiresIn, getResponseHeaderValue, getRuntimeInfo, getServiceErrorData, getUpstreamErrorStatus, graphWebhookHttp, inferSlateErrorFromAxios, isApiErrorRecord, isAxiosErrorLike, isServiceErrorData, isUrlEmbeddedCredential, looksLikeHtmlErrorBody, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, metaWebhookHttp, normalizeOAuthTokenResponse, parseWithServiceError, pickDefined, pruneSeenEntries, publicTool, pushBoundedApiErrorDetail, readApiErrorText, redactUrlAttachmentSecrets, rememberPageToken, requestAxios, requestAxiosData, runWithContext, scopeClause, seenEntryKey, seenEntrySchema, setIfDefined, skipWebhook, spec, statusLabelForApiError, timingSafeStringEqual, tool, toolCategory, trigger, triggerGroup, truncateApiErrorMessage, uploadAttachmentDirect, validateScopes, verifyHmacSignature };
|
|
1384
|
+
export { API_ERROR_MAX_DETAILS, API_ERROR_MAX_MESSAGE_LENGTH, API_ERROR_TRUNCATED_PLACEHOLDER, AUTH_CONFIG_SECRET_PLACEHOLDER_PREFIX, type ApiErrorBuildHelpers, type ApiErrorDetailOptions, type ApiErrorResponse, type ApiErrorStatus, type ApiErrorTextOptions, type ApiServiceError, type AuthConfigSecretFilter, AuthConfigSecretRedactor, type BoundedApiErrorDetailOptions, type BuildApiServiceErrorOptions, type CreateHmacSignatureOptions, type DecodeApiErrorBodyOptions, GET_FILE_URL_TOOL_ID, type GetFileUrlHandler, type GetFileUrlToolInput, type GetFileUrlToolOutput, type NormalizeOAuthTokenResponseOptions, type OAuthExpiresAtOptions, type OAuthRefreshTokenFallbackMode, type OAuthTokenResponse, type SeenEntry, Slate, SlateAction, SlateActionBuilder, type SlateActionCreateParameters, type SlateActionDocsReference, type SlateActionParameters, type SlateActionParametersAny, type SlateActionParametersTool, type SlateActionParametersTrigger, type SlateActionScopeClause, type SlateActionScopeClauseInput, type SlateActionScopeValue, type SlateActionScopes, type SlateActionScopesInput, type SlateActionType, SlateAdapter, type SlateAdapterCapability, SlateAdapterSpec, type SlateAdapterSpecParameters, type SlateAddAttachmentContent, type SlateAddAttachmentInput, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUploadReferenceContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthDocsReference, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAuthenticatedAxiosDefaults, type SlateAxiosDefaults, type SlateAxiosErrorAdapter, type SlateAxiosErrorOptions, SlateConfig, type SlateConfigDocsReference, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, type SlateDirectUploadInput, type SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateGatewayEvent, type SlateLinkedOptionList, type SlateLiveInvocationInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlateOption, SlateOptionList, type SlateOptionListHandler, type SlateOptionListPage, type SlateOptionListParameters, type SlateProviderDocsReference, SlatePublicContext, SlatePublicTool, type SlatePublicToolInvocationHandler, type SlatePublicToolParameters, type SlateRuntimeInfo, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, SlateToolCategory, type SlateToolCategoryParameters, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, SlateTriggerGroup, SlateTriggerGroupBuilder, type SlateTriggerGroupCreateParameters, type SlateTriggerGroupGatewayConnectHandler, type SlateTriggerGroupGatewayParameters, type SlateTriggerGroupGatewayReceiveHandler, type SlateTriggerGroupParameters, type SlateTriggerGroupPollHandler, type SlateTriggerGroupPollingParameters, type SlateTriggerGroupRoutingMatchersHandler, type SlateTriggerGroupSelection, type SlateTriggerGroupSelectionOptionsHandler, type SlateTriggerGroupSelectionOptionsSources, type SlateTriggerGroupWebhookAutoRegistrationParameters, type SlateTriggerGroupWebhookDeliveryConfigParameters, type SlateTriggerGroupWebhookManualRegistrationParameters, type SlateTriggerGroupWebhookParameters, type SlateTriggerMappingHandler, type SlateTriggerMatchesHandler, type SlateTriggerParameters, type SlateTriggerRoutingMatcher, type SlateTypedDocsReference, type SlateWebhookDeliveryAuthenticateHandler, type SlateWebhookDeliveryAuthentication, type SlateWebhookExpandHandler, type SlateWebhookHttpResponseInit, type SlateWebhookManualFinishHandler, type SlateWebhookManualSetupHandler, type SlateWebhookProcessHandler, type SlateWebhookRegisterHandler, type SlateWebhookRegistrationResult, type SlateWebhookRenewHandler, type SlateWebhookSkipped, type SlateWebhookTarget, type SlateWebhookTargetListHandler, type SlateWebhookTargetOwnership, type SlateWebhookUnregisterHandler, type VerifyHmacSignatureOptions, adapterSpec, allOf, anyOf, assertNewPageToken, auth, axios, buildApiServiceError, collectApiErrorDetails, config, createApiServiceError, createAuthenticatedAxios, createAxios, createBase64Attachment, createHmacSignature, createSlateError, createTextAttachment, createUrlAttachment, decodeApiErrorBody, extractApiErrorMessage, getApiErrorResponse, getApiErrorResponseWithBody, getApiErrorStatus, getBase64ByteLength, getCurrentContext, getFileUrlTool, getFileUrlToolInputSchema, getFileUrlToolOutputSchema, getGraphWebhookValidationResponse, getMetaWebhookVerificationResponse, getOAuthExpiresAtFromExpiresIn, getResponseHeaderValue, getRuntimeInfo, getServiceErrorData, getUpstreamErrorStatus, graphWebhookHttp, inferSlateErrorFromAxios, isApiErrorRecord, isAxiosErrorLike, isServiceErrorData, isUrlEmbeddedCredential, looksLikeHtmlErrorBody, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, metaWebhookHttp, normalizeOAuthTokenResponse, optionList, parseWithServiceError, pickDefined, pruneSeenEntries, publicTool, pushBoundedApiErrorDetail, readApiErrorText, redactUrlAttachmentSecrets, rememberPageToken, requestAxios, requestAxiosData, runWithContext, scopeClause, seenEntryKey, seenEntrySchema, setIfDefined, skipWebhook, spec, statusLabelForApiError, timingSafeStringEqual, tool, toolCategory, trigger, triggerGroup, truncateApiErrorMessage, uploadAttachmentDirect, validateScopes, verifyHmacSignature };
|
package/dist/index.module.js
CHANGED
|
@@ -1853,6 +1853,45 @@ var isClause = (value) => typeof value === "object" && value !== null && "OR" in
|
|
|
1853
1853
|
var isScopes = (value) => typeof value === "object" && value !== null && "AND" in value && Array.isArray(value.AND);
|
|
1854
1854
|
|
|
1855
1855
|
// src/action/builder.ts
|
|
1856
|
+
var EVENT_ATTRIBUTE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
1857
|
+
var EVENT_ATTRIBUTE_MAX_KEYS = 8;
|
|
1858
|
+
var checkEventAttributeNames = (fields) => {
|
|
1859
|
+
if (!Array.isArray(fields)) {
|
|
1860
|
+
throw new SlateDeclarationError("Event attributes must be a list of output field names");
|
|
1861
|
+
}
|
|
1862
|
+
if (fields.length > EVENT_ATTRIBUTE_MAX_KEYS) {
|
|
1863
|
+
throw new SlateDeclarationError(
|
|
1864
|
+
`A trigger can declare at most ${EVENT_ATTRIBUTE_MAX_KEYS} event attributes`
|
|
1865
|
+
);
|
|
1866
|
+
}
|
|
1867
|
+
let seen = /* @__PURE__ */ new Set();
|
|
1868
|
+
for (let field of fields) {
|
|
1869
|
+
if (typeof field !== "string" || !EVENT_ATTRIBUTE_KEY_PATTERN.test(field)) {
|
|
1870
|
+
throw new SlateDeclarationError(
|
|
1871
|
+
`Event attribute "${field}" must start with a letter and contain only letters, digits and underscores (at most 64 characters)`
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
if (seen.has(field)) {
|
|
1875
|
+
throw new SlateDeclarationError(`Event attribute "${field}" is declared more than once`);
|
|
1876
|
+
}
|
|
1877
|
+
seen.add(field);
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
var checkEventAttributeFields = (fields, outputSchema) => {
|
|
1881
|
+
if (outputSchema._zod?.def?.type !== "object") {
|
|
1882
|
+
throw new SlateDeclarationError(
|
|
1883
|
+
"Event attributes require the output schema to be a zod object"
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
let shape = outputSchema.shape;
|
|
1887
|
+
for (let field of fields) {
|
|
1888
|
+
if (!Object.hasOwn(shape, field)) {
|
|
1889
|
+
throw new SlateDeclarationError(
|
|
1890
|
+
`Event attribute "${field}" is not a top-level property of the output schema`
|
|
1891
|
+
);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1856
1895
|
var SlateActionBuilder = class {
|
|
1857
1896
|
constructor(type, spec2, params, factory, isPublicTool = false) {
|
|
1858
1897
|
this.type = type;
|
|
@@ -1878,6 +1917,7 @@ var SlateActionBuilder = class {
|
|
|
1878
1917
|
#triggerGroup = null;
|
|
1879
1918
|
#triggerMatches = null;
|
|
1880
1919
|
#triggerMap = null;
|
|
1920
|
+
#eventAttributes = null;
|
|
1881
1921
|
#interfaceLocked = false;
|
|
1882
1922
|
input(schema) {
|
|
1883
1923
|
if (this.#interfaceLocked) {
|
|
@@ -1948,6 +1988,21 @@ var SlateActionBuilder = class {
|
|
|
1948
1988
|
this.#triggerMap = handler;
|
|
1949
1989
|
return this;
|
|
1950
1990
|
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Returns the values of these top-level output fields with every mapped event, so events
|
|
1993
|
+
* can be filtered by them. Strings, finite numbers, booleans and arrays of those are used.
|
|
1994
|
+
*/
|
|
1995
|
+
eventAttributes(fields) {
|
|
1996
|
+
if (this.type !== "trigger") {
|
|
1997
|
+
throw new SlateDeclarationError("eventAttributes can only be set for trigger actions");
|
|
1998
|
+
}
|
|
1999
|
+
checkEventAttributeNames(fields);
|
|
2000
|
+
if (this.#outputSchema) {
|
|
2001
|
+
checkEventAttributeFields(fields, this.#outputSchema);
|
|
2002
|
+
}
|
|
2003
|
+
this.#eventAttributes = [...fields];
|
|
2004
|
+
return this;
|
|
2005
|
+
}
|
|
1951
2006
|
build() {
|
|
1952
2007
|
let scopes = this.#scopes ?? this.params.scopes;
|
|
1953
2008
|
if (scopes) {
|
|
@@ -1975,11 +2030,15 @@ var SlateActionBuilder = class {
|
|
|
1975
2030
|
if (this.type === "trigger" && !this.#triggerMap) {
|
|
1976
2031
|
throw new SlateDeclarationError("Trigger map handler is not defined");
|
|
1977
2032
|
}
|
|
2033
|
+
if (this.#eventAttributes) {
|
|
2034
|
+
checkEventAttributeFields(this.#eventAttributes, this.#outputSchema);
|
|
2035
|
+
}
|
|
1978
2036
|
let triggerParams = this.type === "trigger" ? {
|
|
1979
2037
|
type: "trigger",
|
|
1980
2038
|
triggerGroup: this.#triggerGroup,
|
|
1981
2039
|
matches: this.#triggerMatches,
|
|
1982
|
-
map: this.#triggerMap
|
|
2040
|
+
map: this.#triggerMap,
|
|
2041
|
+
...this.#eventAttributes?.length ? { eventAttributes: this.#eventAttributes } : {}
|
|
1983
2042
|
} : null;
|
|
1984
2043
|
return this.factory({
|
|
1985
2044
|
...this.params,
|
|
@@ -2051,6 +2110,41 @@ var getFileUrlTool = (spec2, handleGetFileUrl) => tool(spec2, {
|
|
|
2051
2110
|
};
|
|
2052
2111
|
}).build();
|
|
2053
2112
|
|
|
2113
|
+
// src/action/optionList.ts
|
|
2114
|
+
import { z as z2 } from "zod";
|
|
2115
|
+
var SlateOptionList = class _SlateOptionList {
|
|
2116
|
+
constructor(_spec, _params, _paramsSchema) {
|
|
2117
|
+
this._spec = _spec;
|
|
2118
|
+
this._params = _params;
|
|
2119
|
+
this._paramsSchema = _paramsSchema;
|
|
2120
|
+
}
|
|
2121
|
+
_spec;
|
|
2122
|
+
_params;
|
|
2123
|
+
_paramsSchema;
|
|
2124
|
+
static create(spec2, params) {
|
|
2125
|
+
let paramsSchema = params.paramsSchema ?? z2.object({});
|
|
2126
|
+
if (paramsSchema?._zod?.def?.type !== "object") {
|
|
2127
|
+
throw new SlateDeclarationError(
|
|
2128
|
+
`Option list "${params.key}" params schema must be a zod object`
|
|
2129
|
+
);
|
|
2130
|
+
}
|
|
2131
|
+
return new _SlateOptionList(spec2, params, paramsSchema.strict());
|
|
2132
|
+
}
|
|
2133
|
+
get spec() {
|
|
2134
|
+
return this._spec;
|
|
2135
|
+
}
|
|
2136
|
+
get key() {
|
|
2137
|
+
return this._params.key;
|
|
2138
|
+
}
|
|
2139
|
+
get paramsSchema() {
|
|
2140
|
+
return this._paramsSchema;
|
|
2141
|
+
}
|
|
2142
|
+
get list() {
|
|
2143
|
+
return this._params.list;
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
var optionList = (spec2, params) => SlateOptionList.create(spec2, params);
|
|
2147
|
+
|
|
2054
2148
|
// src/action/publicTool.ts
|
|
2055
2149
|
var SlatePublicTool = class {
|
|
2056
2150
|
constructor() {
|
|
@@ -2104,11 +2198,13 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
2104
2198
|
#triggerGroup;
|
|
2105
2199
|
#matches;
|
|
2106
2200
|
#map;
|
|
2201
|
+
#eventAttributes;
|
|
2107
2202
|
constructor(spec2, inputSchema, outputSchema, params) {
|
|
2108
2203
|
super("trigger", spec2, inputSchema, outputSchema, params);
|
|
2109
2204
|
this.#triggerGroup = params.triggerGroup;
|
|
2110
2205
|
this.#matches = params.matches;
|
|
2111
2206
|
this.#map = params.map;
|
|
2207
|
+
this.#eventAttributes = params.eventAttributes ?? [];
|
|
2112
2208
|
}
|
|
2113
2209
|
static create(spec2, params) {
|
|
2114
2210
|
return new SlateActionBuilder("trigger", spec2, params, (params2) => {
|
|
@@ -2125,12 +2221,53 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
2125
2221
|
get map() {
|
|
2126
2222
|
return this.#map;
|
|
2127
2223
|
}
|
|
2224
|
+
get eventAttributes() {
|
|
2225
|
+
return [...this.#eventAttributes];
|
|
2226
|
+
}
|
|
2128
2227
|
};
|
|
2129
2228
|
var trigger = (spec2, params) => SlateTrigger.create(spec2, params);
|
|
2130
2229
|
|
|
2131
2230
|
// src/action/triggerGroup.ts
|
|
2132
|
-
import { z as
|
|
2231
|
+
import { z as z3 } from "zod";
|
|
2133
2232
|
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
2233
|
+
var LINKED_SLATE_PATTERN = /^[^/\s]+\/[^/\s]+$/;
|
|
2234
|
+
var checkSelectionOptions = (field, sources, shape) => {
|
|
2235
|
+
if (!Object.hasOwn(shape, field)) {
|
|
2236
|
+
throw new SlateDeclarationError(
|
|
2237
|
+
`Selection field "${field}" is not a top-level property of the selection schema`
|
|
2238
|
+
);
|
|
2239
|
+
}
|
|
2240
|
+
if (typeof sources !== "object" || sources === null) {
|
|
2241
|
+
throw new SlateDeclarationError(
|
|
2242
|
+
`Selection field "${field}" must be declared as { list, linked }`
|
|
2243
|
+
);
|
|
2244
|
+
}
|
|
2245
|
+
let { list, linked } = sources;
|
|
2246
|
+
if (!list && !linked) {
|
|
2247
|
+
throw new SlateDeclarationError(
|
|
2248
|
+
`Selection field "${field}" needs its own options list, a linked option list, or both`
|
|
2249
|
+
);
|
|
2250
|
+
}
|
|
2251
|
+
if (list !== void 0 && typeof list !== "function") {
|
|
2252
|
+
throw new SlateDeclarationError(`Selection field "${field}" list must be a function`);
|
|
2253
|
+
}
|
|
2254
|
+
if (linked) {
|
|
2255
|
+
if (typeof linked.slate !== "string" || !LINKED_SLATE_PATTERN.test(linked.slate)) {
|
|
2256
|
+
throw new SlateDeclarationError(
|
|
2257
|
+
`Selection field "${field}" links to slate "${linked.slate}", which must be written as <scope>/<name>`
|
|
2258
|
+
);
|
|
2259
|
+
}
|
|
2260
|
+
if (typeof linked.optionList !== "string" || !linked.optionList.trim()) {
|
|
2261
|
+
throw new SlateDeclarationError(
|
|
2262
|
+
`Selection field "${field}" must name the option list it links to`
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
return {
|
|
2267
|
+
...list ? { list } : {},
|
|
2268
|
+
...linked ? { linked } : {}
|
|
2269
|
+
};
|
|
2270
|
+
};
|
|
2134
2271
|
var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
2135
2272
|
constructor(_spec, _params) {
|
|
2136
2273
|
this._spec = _spec;
|
|
@@ -2157,7 +2294,7 @@ var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
|
2157
2294
|
return this._params.metadata;
|
|
2158
2295
|
}
|
|
2159
2296
|
get eventSchema() {
|
|
2160
|
-
return this._params.eventSchema ??
|
|
2297
|
+
return this._params.eventSchema ?? z3.object({}).passthrough();
|
|
2161
2298
|
}
|
|
2162
2299
|
get source() {
|
|
2163
2300
|
return this._params.source;
|
|
@@ -2177,6 +2314,9 @@ var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
|
2177
2314
|
get routingMatchers() {
|
|
2178
2315
|
return this._params.routingMatchers;
|
|
2179
2316
|
}
|
|
2317
|
+
get selectionOptions() {
|
|
2318
|
+
return this._params.selectionOptions ?? {};
|
|
2319
|
+
}
|
|
2180
2320
|
};
|
|
2181
2321
|
var SlateTriggerGroupBuilder = class {
|
|
2182
2322
|
constructor(spec2, params, factory) {
|
|
@@ -2192,6 +2332,7 @@ var SlateTriggerGroupBuilder = class {
|
|
|
2192
2332
|
#webhook = null;
|
|
2193
2333
|
#gateway = null;
|
|
2194
2334
|
#routingMatchers = null;
|
|
2335
|
+
#selectionOptions = {};
|
|
2195
2336
|
polling(props) {
|
|
2196
2337
|
if (this.#source) {
|
|
2197
2338
|
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
@@ -2263,6 +2404,27 @@ var SlateTriggerGroupBuilder = class {
|
|
|
2263
2404
|
this.#routingMatchers = handler;
|
|
2264
2405
|
return this;
|
|
2265
2406
|
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Lets the dashboard offer a list for these selection fields instead of a typed-in value.
|
|
2409
|
+
* Each field must be a top-level property of the selection schema, which must be a zod object.
|
|
2410
|
+
* For an array property the listed options are values for its items.
|
|
2411
|
+
*/
|
|
2412
|
+
selectionOptions(declarations) {
|
|
2413
|
+
let schema = this.params.selectionSchema;
|
|
2414
|
+
if (!schema) {
|
|
2415
|
+
throw new SlateDeclarationError("Selection options require a selection schema");
|
|
2416
|
+
}
|
|
2417
|
+
if (schema._zod?.def?.type !== "object") {
|
|
2418
|
+
throw new SlateDeclarationError(
|
|
2419
|
+
"Selection options require the selection schema to be a zod object"
|
|
2420
|
+
);
|
|
2421
|
+
}
|
|
2422
|
+
let shape = schema.shape;
|
|
2423
|
+
for (let [field, sources] of Object.entries(declarations)) {
|
|
2424
|
+
this.#selectionOptions[field] = checkSelectionOptions(field, sources, shape);
|
|
2425
|
+
}
|
|
2426
|
+
return this;
|
|
2427
|
+
}
|
|
2266
2428
|
build() {
|
|
2267
2429
|
if (!this.#source) {
|
|
2268
2430
|
throw new SlateDeclarationError(
|
|
@@ -2278,7 +2440,8 @@ var SlateTriggerGroupBuilder = class {
|
|
|
2278
2440
|
polling: this.#polling ?? void 0,
|
|
2279
2441
|
webhook: this.#webhook ?? void 0,
|
|
2280
2442
|
gateway: this.#gateway ?? void 0,
|
|
2281
|
-
routingMatchers: this.#routingMatchers
|
|
2443
|
+
routingMatchers: this.#routingMatchers,
|
|
2444
|
+
selectionOptions: this.#selectionOptions
|
|
2282
2445
|
});
|
|
2283
2446
|
}
|
|
2284
2447
|
};
|
|
@@ -3037,8 +3200,8 @@ var verifyHmacSignature = (options) => timingSafeStringEqual(createHmacSignature
|
|
|
3037
3200
|
|
|
3038
3201
|
// src/dedup/index.ts
|
|
3039
3202
|
import { createHash } from "crypto";
|
|
3040
|
-
import { z as
|
|
3041
|
-
var seenEntrySchema =
|
|
3203
|
+
import { z as z4 } from "zod";
|
|
3204
|
+
var seenEntrySchema = z4.object({ key: z4.string().min(1), at: z4.number().finite() });
|
|
3042
3205
|
var seenEntryKey = (idempotencyKey) => createHash("sha256").update(idempotencyKey).digest("base64url").slice(0, 16);
|
|
3043
3206
|
var pruneSeenEntries = (entries, options) => {
|
|
3044
3207
|
let kept = [];
|
|
@@ -3190,13 +3353,14 @@ var assertNewPageToken = (seen, token, repeated) => {
|
|
|
3190
3353
|
|
|
3191
3354
|
// src/specification/slate.ts
|
|
3192
3355
|
var Slate = class _Slate {
|
|
3193
|
-
constructor(_spec, _actions, _adapters, _triggerGroups, _toolCategories, _toolCategoryKeysByActionKey) {
|
|
3356
|
+
constructor(_spec, _actions, _adapters, _triggerGroups, _toolCategories, _toolCategoryKeysByActionKey, _optionLists) {
|
|
3194
3357
|
this._spec = _spec;
|
|
3195
3358
|
this._actions = _actions;
|
|
3196
3359
|
this._adapters = _adapters;
|
|
3197
3360
|
this._triggerGroups = _triggerGroups;
|
|
3198
3361
|
this._toolCategories = _toolCategories;
|
|
3199
3362
|
this._toolCategoryKeysByActionKey = _toolCategoryKeysByActionKey;
|
|
3363
|
+
this._optionLists = _optionLists;
|
|
3200
3364
|
}
|
|
3201
3365
|
_spec;
|
|
3202
3366
|
_actions;
|
|
@@ -3204,6 +3368,7 @@ var Slate = class _Slate {
|
|
|
3204
3368
|
_triggerGroups;
|
|
3205
3369
|
_toolCategories;
|
|
3206
3370
|
_toolCategoryKeysByActionKey;
|
|
3371
|
+
_optionLists;
|
|
3207
3372
|
static create(params) {
|
|
3208
3373
|
let adapters = params.adapters ?? [];
|
|
3209
3374
|
let actions = [...params.triggers, ...params.tools];
|
|
@@ -3247,6 +3412,16 @@ var Slate = class _Slate {
|
|
|
3247
3412
|
`Only one trigger group may use manual webhook registration or a delivery config, but found: ${configuredWebhookTriggerGroups.map((group) => group.key).join(", ")}`
|
|
3248
3413
|
);
|
|
3249
3414
|
}
|
|
3415
|
+
let optionLists = params.optionLists ?? [];
|
|
3416
|
+
let seenOptionListKeys = /* @__PURE__ */ new Set();
|
|
3417
|
+
for (let list of optionLists) {
|
|
3418
|
+
if (seenOptionListKeys.has(list.key)) {
|
|
3419
|
+
throw new SlateDeclarationError(
|
|
3420
|
+
`Option list "${list.key}" is registered more than once`
|
|
3421
|
+
);
|
|
3422
|
+
}
|
|
3423
|
+
seenOptionListKeys.add(list.key);
|
|
3424
|
+
}
|
|
3250
3425
|
let toolCategories = params.toolCategories ?? [];
|
|
3251
3426
|
let toolCategoryKeysByActionKey = resolveToolCategoryMembership(toolCategories, actions);
|
|
3252
3427
|
return new _Slate(
|
|
@@ -3255,7 +3430,8 @@ var Slate = class _Slate {
|
|
|
3255
3430
|
adapters,
|
|
3256
3431
|
triggerGroups,
|
|
3257
3432
|
toolCategories,
|
|
3258
|
-
toolCategoryKeysByActionKey
|
|
3433
|
+
toolCategoryKeysByActionKey,
|
|
3434
|
+
optionLists
|
|
3259
3435
|
);
|
|
3260
3436
|
}
|
|
3261
3437
|
get spec() {
|
|
@@ -3273,6 +3449,9 @@ var Slate = class _Slate {
|
|
|
3273
3449
|
get toolCategories() {
|
|
3274
3450
|
return this._toolCategories ?? [];
|
|
3275
3451
|
}
|
|
3452
|
+
get optionLists() {
|
|
3453
|
+
return this._optionLists ?? [];
|
|
3454
|
+
}
|
|
3276
3455
|
// Keys of the tool categories an action belongs to, in declared category order.
|
|
3277
3456
|
getToolCategoryKeys(actionKey) {
|
|
3278
3457
|
return [...this._toolCategoryKeysByActionKey?.get(actionKey) ?? []];
|
|
@@ -3346,7 +3525,7 @@ var resolveToolCategoryMembership = (toolCategories, actions) => {
|
|
|
3346
3525
|
};
|
|
3347
3526
|
|
|
3348
3527
|
// src/specification/specification.ts
|
|
3349
|
-
import
|
|
3528
|
+
import z5 from "zod";
|
|
3350
3529
|
var SlateSpecification = class _SlateSpecification {
|
|
3351
3530
|
constructor(_config, _auth, _params) {
|
|
3352
3531
|
this._config = _config;
|
|
@@ -3363,7 +3542,7 @@ var SlateSpecification = class _SlateSpecification {
|
|
|
3363
3542
|
return this._config.configSchema;
|
|
3364
3543
|
}
|
|
3365
3544
|
get authSchema() {
|
|
3366
|
-
return "outputSchema" in this._auth ? this._auth.outputSchema :
|
|
3545
|
+
return "outputSchema" in this._auth ? this._auth.outputSchema : z5.object({});
|
|
3367
3546
|
}
|
|
3368
3547
|
get config() {
|
|
3369
3548
|
return this._config;
|
|
@@ -3467,6 +3646,7 @@ export {
|
|
|
3467
3646
|
SlateDefaultPollingIntervalSeconds,
|
|
3468
3647
|
SlateError,
|
|
3469
3648
|
SlateLogger,
|
|
3649
|
+
SlateOptionList,
|
|
3470
3650
|
SlatePublicContext,
|
|
3471
3651
|
SlatePublicTool,
|
|
3472
3652
|
SlateSpecification,
|
|
@@ -3521,6 +3701,7 @@ export {
|
|
|
3521
3701
|
mergeScopes,
|
|
3522
3702
|
metaWebhookHttp,
|
|
3523
3703
|
normalizeOAuthTokenResponse,
|
|
3704
|
+
optionList,
|
|
3524
3705
|
parseWithServiceError,
|
|
3525
3706
|
pickDefined,
|
|
3526
3707
|
pruneSeenEntries,
|
package/package.json
CHANGED
package/src/action/action.ts
CHANGED
|
@@ -92,6 +92,7 @@ export interface SlateActionParametersTrigger<
|
|
|
92
92
|
triggerGroup: SlateTriggerGroup<ConfigType, AuthType>;
|
|
93
93
|
matches: SlateTriggerMatchesHandler;
|
|
94
94
|
map: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
95
|
+
eventAttributes?: string[];
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
export type SlateActionParametersAny<
|
package/src/action/builder.ts
CHANGED
|
@@ -17,6 +17,51 @@ import type {
|
|
|
17
17
|
import { validateScopes } from './scopes';
|
|
18
18
|
import type { SlateTriggerGroup } from './triggerGroup';
|
|
19
19
|
|
|
20
|
+
// Mirrors the event attribute limits in @slates/proto.
|
|
21
|
+
let EVENT_ATTRIBUTE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
22
|
+
let EVENT_ATTRIBUTE_MAX_KEYS = 8;
|
|
23
|
+
|
|
24
|
+
let checkEventAttributeNames = (fields: string[]) => {
|
|
25
|
+
if (!Array.isArray(fields)) {
|
|
26
|
+
throw new SlateDeclarationError('Event attributes must be a list of output field names');
|
|
27
|
+
}
|
|
28
|
+
if (fields.length > EVENT_ATTRIBUTE_MAX_KEYS) {
|
|
29
|
+
throw new SlateDeclarationError(
|
|
30
|
+
`A trigger can declare at most ${EVENT_ATTRIBUTE_MAX_KEYS} event attributes`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let seen = new Set<string>();
|
|
35
|
+
for (let field of fields) {
|
|
36
|
+
if (typeof field !== 'string' || !EVENT_ATTRIBUTE_KEY_PATTERN.test(field)) {
|
|
37
|
+
throw new SlateDeclarationError(
|
|
38
|
+
`Event attribute "${field}" must start with a letter and contain only letters, digits and underscores (at most 64 characters)`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (seen.has(field)) {
|
|
42
|
+
throw new SlateDeclarationError(`Event attribute "${field}" is declared more than once`);
|
|
43
|
+
}
|
|
44
|
+
seen.add(field);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
let checkEventAttributeFields = (fields: string[], outputSchema: z.ZodType<any>) => {
|
|
49
|
+
if ((outputSchema as any)._zod?.def?.type !== 'object') {
|
|
50
|
+
throw new SlateDeclarationError(
|
|
51
|
+
'Event attributes require the output schema to be a zod object'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let shape = (outputSchema as z.ZodObject<any>).shape;
|
|
56
|
+
for (let field of fields) {
|
|
57
|
+
if (!Object.hasOwn(shape, field)) {
|
|
58
|
+
throw new SlateDeclarationError(
|
|
59
|
+
`Event attribute "${field}" is not a top-level property of the output schema`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
20
65
|
export class SlateActionBuilder<
|
|
21
66
|
Type extends SlateActionType,
|
|
22
67
|
ConfigType extends {},
|
|
@@ -39,6 +84,7 @@ export class SlateActionBuilder<
|
|
|
39
84
|
#triggerMatches: SlateTriggerMatchesHandler | null = null;
|
|
40
85
|
#triggerMap: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType> | null =
|
|
41
86
|
null;
|
|
87
|
+
#eventAttributes: string[] | null = null;
|
|
42
88
|
#interfaceLocked = false;
|
|
43
89
|
|
|
44
90
|
constructor(
|
|
@@ -190,6 +236,26 @@ export class SlateActionBuilder<
|
|
|
190
236
|
return this;
|
|
191
237
|
}
|
|
192
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Returns the values of these top-level output fields with every mapped event, so events
|
|
241
|
+
* can be filtered by them. Strings, finite numbers, booleans and arrays of those are used.
|
|
242
|
+
*/
|
|
243
|
+
eventAttributes(
|
|
244
|
+
fields: (keyof OutputType & string)[]
|
|
245
|
+
): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic> {
|
|
246
|
+
if (this.type !== 'trigger') {
|
|
247
|
+
throw new SlateDeclarationError('eventAttributes can only be set for trigger actions');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
checkEventAttributeNames(fields);
|
|
251
|
+
if (this.#outputSchema) {
|
|
252
|
+
checkEventAttributeFields(fields, this.#outputSchema);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
this.#eventAttributes = [...fields];
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
|
|
193
259
|
build() {
|
|
194
260
|
let scopes = this.#scopes ?? this.params.scopes;
|
|
195
261
|
if (scopes) {
|
|
@@ -219,6 +285,9 @@ export class SlateActionBuilder<
|
|
|
219
285
|
if (this.type === 'trigger' && !this.#triggerMap) {
|
|
220
286
|
throw new SlateDeclarationError('Trigger map handler is not defined');
|
|
221
287
|
}
|
|
288
|
+
if (this.#eventAttributes) {
|
|
289
|
+
checkEventAttributeFields(this.#eventAttributes, this.#outputSchema);
|
|
290
|
+
}
|
|
222
291
|
|
|
223
292
|
let triggerParams: SlateActionParametersTrigger<
|
|
224
293
|
ConfigType,
|
|
@@ -231,7 +300,10 @@ export class SlateActionBuilder<
|
|
|
231
300
|
type: 'trigger',
|
|
232
301
|
triggerGroup: this.#triggerGroup!,
|
|
233
302
|
matches: this.#triggerMatches!,
|
|
234
|
-
map: this.#triggerMap! as any
|
|
303
|
+
map: this.#triggerMap! as any,
|
|
304
|
+
...(this.#eventAttributes?.length
|
|
305
|
+
? { eventAttributes: this.#eventAttributes }
|
|
306
|
+
: {})
|
|
235
307
|
}
|
|
236
308
|
: null;
|
|
237
309
|
|