@slates/provider 1.0.0-rc.33 → 1.0.0-rc.34
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 +100 -13
- package/dist/index.d.cts +98 -2
- package/dist/index.d.ts +98 -2
- package/dist/index.module.js +92 -13
- package/package.json +1 -1
- package/src/action/triggerGroup.test.ts +90 -0
- package/src/action/triggerGroup.ts +131 -4
- package/src/crypto/hmac.test.ts +17 -1
- package/src/crypto/hmac.ts +11 -6
- package/src/dedup/index.test.ts +47 -0
- package/src/dedup/index.ts +25 -0
- package/src/error/api.test.ts +22 -0
- package/src/error/api.ts +8 -0
- package/src/error/index.ts +1 -0
- package/src/error/parse.test.ts +29 -0
- package/src/error/parse.ts +14 -0
- package/src/index.ts +2 -0
- package/src/pagination/index.test.ts +21 -0
- package/src/pagination/index.ts +15 -0
- package/src/specification/slate.test.ts +53 -2
- package/src/specification/slate.ts +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -537,6 +537,7 @@ declare let getRuntimeInfo: () => Readonly<SlateRuntimeInfo> | null;
|
|
|
537
537
|
|
|
538
538
|
declare let SlateDefaultPollingIntervalSeconds: number;
|
|
539
539
|
type SlateTriggerRoutingMatcher = Record<string, any>;
|
|
540
|
+
type SlateTriggerGroupSelection = Record<string, any>;
|
|
540
541
|
type SlateWebhookTargetOwnership = 'single_user' | 'multi_user';
|
|
541
542
|
interface SlateWebhookTarget {
|
|
542
543
|
webhookTargetIdentifier: string;
|
|
@@ -549,6 +550,7 @@ interface SlateWebhookTarget {
|
|
|
549
550
|
type SlateTriggerGroupRoutingMatchersHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {}>) => Promise<SlateTriggerRoutingMatcher[]>;
|
|
550
551
|
type SlateTriggerGroupPollHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
551
552
|
state: any | null;
|
|
553
|
+
selection?: SlateTriggerGroupSelection;
|
|
552
554
|
}>) => Promise<{
|
|
553
555
|
events: {
|
|
554
556
|
payload: any;
|
|
@@ -593,6 +595,7 @@ type SlateTriggerGroupGatewayReceiveHandler<ConfigType extends {}, AuthType exte
|
|
|
593
595
|
}>;
|
|
594
596
|
type SlateWebhookTargetListHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
595
597
|
pageToken: any | null;
|
|
598
|
+
selection?: SlateTriggerGroupSelection;
|
|
596
599
|
}>) => Promise<{
|
|
597
600
|
targets: SlateWebhookTarget[];
|
|
598
601
|
nextPageToken: any | null;
|
|
@@ -602,9 +605,40 @@ type SlateWebhookRegisterHandler<ConfigType extends {}, AuthType extends {}> = (
|
|
|
602
605
|
webhookTargetIdentifier: string;
|
|
603
606
|
webhookTargetPayload: any;
|
|
604
607
|
webhookUrl: string;
|
|
605
|
-
|
|
608
|
+
operationId?: string;
|
|
609
|
+
selection?: SlateTriggerGroupSelection;
|
|
610
|
+
deliveryConfig?: unknown;
|
|
611
|
+
}>) => Promise<SlateWebhookRegistrationResult>;
|
|
612
|
+
interface SlateWebhookRegistrationResult {
|
|
613
|
+
webhookRegistrationIdentifier: string;
|
|
614
|
+
webhookRegistrationPayload: any;
|
|
615
|
+
expiresAt?: string | null;
|
|
616
|
+
renewAfter?: string | null;
|
|
617
|
+
/** Identities of this registration on a delivery channel shared with other registrations. */
|
|
618
|
+
routingKeys?: string[];
|
|
619
|
+
}
|
|
620
|
+
type SlateWebhookRenewHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
606
621
|
webhookRegistrationIdentifier: string;
|
|
607
622
|
webhookRegistrationPayload: any;
|
|
623
|
+
webhookUrl: string;
|
|
624
|
+
webhookTargetIdentifier: string;
|
|
625
|
+
webhookTargetPayload: any;
|
|
626
|
+
operationId: string;
|
|
627
|
+
selection?: SlateTriggerGroupSelection;
|
|
628
|
+
deliveryConfig?: unknown;
|
|
629
|
+
}>) => Promise<SlateWebhookRegistrationResult>;
|
|
630
|
+
type SlateWebhookExpandHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
631
|
+
payload: unknown | null;
|
|
632
|
+
state: any | null;
|
|
633
|
+
selection?: SlateTriggerGroupSelection;
|
|
634
|
+
deliveryId: string;
|
|
635
|
+
webhookRegistrationPayload: any;
|
|
636
|
+
}>) => Promise<{
|
|
637
|
+
events: {
|
|
638
|
+
payload: any;
|
|
639
|
+
idempotencyKey?: string;
|
|
640
|
+
}[];
|
|
641
|
+
updatedState?: any;
|
|
608
642
|
}>;
|
|
609
643
|
type SlateWebhookUnregisterHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
610
644
|
webhookRegistrationIdentifier: string;
|
|
@@ -638,6 +672,23 @@ type SlateWebhookProcessHandler = (context: SlateContext<{}, {}, {
|
|
|
638
672
|
interface SlateWebhookSkipped {
|
|
639
673
|
reason: string;
|
|
640
674
|
}
|
|
675
|
+
/**
|
|
676
|
+
* Routing keys name the registrations a request addresses; an empty list acknowledges it
|
|
677
|
+
* without handing it to any. A rejection answers the sender with its status.
|
|
678
|
+
*/
|
|
679
|
+
type SlateWebhookDeliveryAuthentication = {
|
|
680
|
+
routingKeys: string[];
|
|
681
|
+
rejected?: undefined;
|
|
682
|
+
} | {
|
|
683
|
+
rejected: {
|
|
684
|
+
status: number;
|
|
685
|
+
};
|
|
686
|
+
routingKeys?: undefined;
|
|
687
|
+
};
|
|
688
|
+
type SlateWebhookDeliveryAuthenticateHandler = (context: SlateContext<{}, {}, {
|
|
689
|
+
request: Request;
|
|
690
|
+
deliveryConfig: unknown;
|
|
691
|
+
}>) => Promise<SlateWebhookDeliveryAuthentication>;
|
|
641
692
|
interface SlateTriggerGroupPollingParameters<ConfigType extends {}, AuthType extends {}> {
|
|
642
693
|
intervalSeconds: number;
|
|
643
694
|
pollEvents: SlateTriggerGroupPollHandler<ConfigType, AuthType>;
|
|
@@ -649,6 +700,7 @@ interface SlateTriggerGroupGatewayParameters<ConfigType extends {}, AuthType ext
|
|
|
649
700
|
interface SlateTriggerGroupWebhookAutoRegistrationParameters<ConfigType extends {}, AuthType extends {}> {
|
|
650
701
|
webhookTargetList: SlateWebhookTargetListHandler<ConfigType, AuthType>;
|
|
651
702
|
webhookRegister: SlateWebhookRegisterHandler<ConfigType, AuthType>;
|
|
703
|
+
webhookRenew?: SlateWebhookRenewHandler<ConfigType, AuthType>;
|
|
652
704
|
webhookUnregister: SlateWebhookUnregisterHandler<ConfigType, AuthType>;
|
|
653
705
|
}
|
|
654
706
|
interface SlateTriggerGroupWebhookManualRegistrationParameters<UserConfigSchema extends z$1.ZodType<any> = z$1.ZodType<any>, FullConfigSchema extends z$1.ZodType<any> = z$1.ZodType<any>> {
|
|
@@ -657,10 +709,18 @@ interface SlateTriggerGroupWebhookManualRegistrationParameters<UserConfigSchema
|
|
|
657
709
|
setup: SlateWebhookManualSetupHandler<FullConfigSchema>;
|
|
658
710
|
finish?: SlateWebhookManualFinishHandler<UserConfigSchema, FullConfigSchema>;
|
|
659
711
|
}
|
|
712
|
+
/** A delivery setup a person completes once for an automatically registered group. */
|
|
713
|
+
type SlateTriggerGroupWebhookDeliveryConfigParameters<UserConfigSchema extends z$1.ZodType<any> = z$1.ZodType<any>, FullConfigSchema extends z$1.ZodType<any> = z$1.ZodType<any>> = SlateTriggerGroupWebhookManualRegistrationParameters<UserConfigSchema, FullConfigSchema> & {
|
|
714
|
+
finish: SlateWebhookManualFinishHandler<UserConfigSchema, FullConfigSchema>;
|
|
715
|
+
authenticate: SlateWebhookDeliveryAuthenticateHandler;
|
|
716
|
+
};
|
|
660
717
|
interface SlateTriggerGroupWebhookParameters<ConfigType extends {}, AuthType extends {}> {
|
|
661
718
|
autoRegistration?: SlateTriggerGroupWebhookAutoRegistrationParameters<ConfigType, AuthType>;
|
|
662
719
|
manualRegistration?: SlateTriggerGroupWebhookManualRegistrationParameters<any, any>;
|
|
720
|
+
deliveryConfig?: SlateTriggerGroupWebhookDeliveryConfigParameters<any, any>;
|
|
663
721
|
process: SlateWebhookProcessHandler;
|
|
722
|
+
expandWebhook?: SlateWebhookExpandHandler<ConfigType, AuthType>;
|
|
723
|
+
reconcileIntervalSeconds?: number;
|
|
664
724
|
}
|
|
665
725
|
interface SlateTriggerGroupCreateParameters<InputType extends {} = Record<string, unknown>> {
|
|
666
726
|
key: string;
|
|
@@ -668,6 +728,7 @@ interface SlateTriggerGroupCreateParameters<InputType extends {} = Record<string
|
|
|
668
728
|
description?: string;
|
|
669
729
|
metadata?: Record<string, any>;
|
|
670
730
|
eventSchema?: z$1.ZodType<InputType>;
|
|
731
|
+
selectionSchema?: z$1.ZodType<SlateTriggerGroupSelection>;
|
|
671
732
|
}
|
|
672
733
|
interface SlateTriggerGroupParameters<ConfigType extends {}, AuthType extends {}, InputType extends {} = Record<string, unknown>> extends SlateTriggerGroupCreateParameters<InputType> {
|
|
673
734
|
source: 'polling' | 'webhook' | 'gateway';
|
|
@@ -688,6 +749,7 @@ declare class SlateTriggerGroup<ConfigType extends {}, AuthType extends {}, Inpu
|
|
|
688
749
|
get metadata(): Record<string, any> | undefined;
|
|
689
750
|
get eventSchema(): z$1.ZodType<InputType, unknown, z$1.core.$ZodTypeInternals<InputType, unknown>>;
|
|
690
751
|
get source(): "polling" | "webhook" | "gateway";
|
|
752
|
+
get selectionSchema(): z$1.ZodType<SlateTriggerGroupSelection, unknown, z$1.core.$ZodTypeInternals<SlateTriggerGroupSelection, unknown>> | undefined;
|
|
691
753
|
get polling(): SlateTriggerGroupPollingParameters<ConfigType, AuthType> | undefined;
|
|
692
754
|
get webhook(): SlateTriggerGroupWebhookParameters<ConfigType, AuthType> | undefined;
|
|
693
755
|
get gateway(): SlateTriggerGroupGatewayParameters<ConfigType, AuthType> | undefined;
|
|
@@ -706,7 +768,10 @@ declare class SlateTriggerGroupBuilder<ConfigType extends {}, AuthType extends {
|
|
|
706
768
|
webhook<UserConfigSchema extends z$1.ZodType<any> = z$1.ZodType<any>, FullConfigSchema extends z$1.ZodType<any> = z$1.ZodType<any>>(props: {
|
|
707
769
|
autoRegistration?: SlateTriggerGroupWebhookAutoRegistrationParameters<ConfigType, AuthType>;
|
|
708
770
|
manualRegistration?: SlateTriggerGroupWebhookManualRegistrationParameters<UserConfigSchema, FullConfigSchema>;
|
|
771
|
+
deliveryConfig?: SlateTriggerGroupWebhookDeliveryConfigParameters<UserConfigSchema, FullConfigSchema>;
|
|
709
772
|
process: SlateWebhookProcessHandler;
|
|
773
|
+
expandWebhook?: SlateWebhookExpandHandler<ConfigType, AuthType>;
|
|
774
|
+
reconcileIntervalSeconds?: number;
|
|
710
775
|
}): SlateTriggerGroupBuilder<ConfigType, AuthType, InputType>;
|
|
711
776
|
/** Receive events over a platform-managed persistent connection (e.g. a WebSocket gateway). */
|
|
712
777
|
gateway(props: SlateTriggerGroupGatewayParameters<ConfigType, AuthType>): SlateTriggerGroupBuilder<ConfigType, AuthType, InputType>;
|
|
@@ -1009,6 +1074,8 @@ declare let isApiErrorRecord: (value: unknown) => value is Record<string, unknow
|
|
|
1009
1074
|
declare let collectApiErrorDetails: (value: unknown, details: string[], options?: ApiErrorDetailOptions) => void;
|
|
1010
1075
|
declare let getApiErrorResponse: (error: unknown) => ApiErrorResponse | undefined;
|
|
1011
1076
|
declare let getApiErrorStatus: (error: unknown) => ApiErrorStatus | undefined;
|
|
1077
|
+
/** Upstream HTTP status of an HTTP client error or a ServiceError with `upstreamStatus`. */
|
|
1078
|
+
declare let getUpstreamErrorStatus: (error: unknown) => number | undefined;
|
|
1012
1079
|
declare let getApiErrorResponseWithBody: (error: unknown) => ApiErrorResponse | undefined;
|
|
1013
1080
|
declare let API_ERROR_MAX_DETAILS: number;
|
|
1014
1081
|
declare let API_ERROR_MAX_MESSAGE_LENGTH: number;
|
|
@@ -1118,6 +1185,11 @@ declare class SlateDeclarationError extends SlateError {
|
|
|
1118
1185
|
static is(error: unknown): error is SlateDeclarationError;
|
|
1119
1186
|
}
|
|
1120
1187
|
|
|
1188
|
+
/** Parses a saved or received value, throwing a user-facing `ServiceError` on mismatch. */
|
|
1189
|
+
declare let parseWithServiceError: <T extends z$1.ZodType>(schema: T, value: unknown, message: string, options?: {
|
|
1190
|
+
reason?: string;
|
|
1191
|
+
}) => z$1.output<T>;
|
|
1192
|
+
|
|
1121
1193
|
declare let mapServiceErrorCode: (code: string, status?: number) => string;
|
|
1122
1194
|
declare let isServiceErrorData: (value: unknown) => value is SlateServiceErrorData;
|
|
1123
1195
|
declare let getServiceErrorData: (error: unknown) => SlateServiceErrorData | null;
|
|
@@ -1152,14 +1224,38 @@ interface VerifyHmacSignatureOptions extends CreateHmacSignatureOptions {
|
|
|
1152
1224
|
signature: string;
|
|
1153
1225
|
}
|
|
1154
1226
|
declare let createHmacSignature: ({ secret, payload, algorithm, digest, prefix }: CreateHmacSignatureOptions) => string;
|
|
1227
|
+
/** Constant-time secret comparison; an empty expected secret matches nothing. */
|
|
1228
|
+
declare let timingSafeStringEqual: (expected: string, received: string | null | undefined) => boolean;
|
|
1155
1229
|
declare let verifyHmacSignature: (options: VerifyHmacSignatureOptions) => boolean;
|
|
1156
1230
|
|
|
1231
|
+
/** An event a poller already reported, saved so an overlapping read can skip it. */
|
|
1232
|
+
declare let seenEntrySchema: z$1.ZodObject<{
|
|
1233
|
+
key: z$1.ZodString;
|
|
1234
|
+
at: z$1.ZodNumber;
|
|
1235
|
+
}, z$1.core.$strip>;
|
|
1236
|
+
type SeenEntry = z$1.infer<typeof seenEntrySchema>;
|
|
1237
|
+
/** A short stable key for an idempotency key, so remembered events cost little state. */
|
|
1238
|
+
declare let seenEntryKey: (idempotencyKey: string) => string;
|
|
1239
|
+
/** Keeps entries at or after `cutoff` (or `retain`), newest first, at most `maxEntries`. */
|
|
1240
|
+
declare let pruneSeenEntries: (entries: Iterable<SeenEntry & {
|
|
1241
|
+
retain?: boolean;
|
|
1242
|
+
}>, options: {
|
|
1243
|
+
cutoff: number;
|
|
1244
|
+
maxEntries: number;
|
|
1245
|
+
onOverflow?: (dropped: number) => void;
|
|
1246
|
+
}) => SeenEntry[];
|
|
1247
|
+
|
|
1157
1248
|
declare let getResponseHeaderValue: (headers: unknown, name: string) => string | undefined;
|
|
1158
1249
|
declare let getBase64ByteLength: (contentBase64: string) => number;
|
|
1159
1250
|
|
|
1160
1251
|
declare let pickDefined: <T extends object>(value: T) => Partial<T> & Record<string, unknown>;
|
|
1161
1252
|
declare let setIfDefined: (target: Record<string, unknown>, key: string, value: unknown) => Record<string, unknown>;
|
|
1162
1253
|
|
|
1254
|
+
/** Records a page token in `seen`; `false` means it repeated and following it would loop. */
|
|
1255
|
+
declare let rememberPageToken: (seen: Set<string>, token: string) => boolean;
|
|
1256
|
+
/** Throws `repeated()` when a listing returns a page token it already returned. */
|
|
1257
|
+
declare let assertNewPageToken: (seen: Set<string>, token: string | null | undefined, repeated: () => unknown) => void;
|
|
1258
|
+
|
|
1163
1259
|
declare class Slate<ConfigType extends {}, AuthType extends {}> {
|
|
1164
1260
|
private readonly _spec;
|
|
1165
1261
|
private readonly _actions;
|
|
@@ -1215,4 +1311,4 @@ declare let skipWebhook: (reason: string, response?: Response | SlateWebhookHttp
|
|
|
1215
1311
|
response: Response | SlateWebhookHttpResponseInit;
|
|
1216
1312
|
};
|
|
1217
1313
|
|
|
1218
|
-
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, 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 SlateTriggerGroupWebhookAutoRegistrationParameters, type SlateTriggerGroupWebhookManualRegistrationParameters, type SlateTriggerGroupWebhookParameters, type SlateTriggerMappingHandler, type SlateTriggerMatchesHandler, type SlateTriggerParameters, type SlateTriggerRoutingMatcher, type SlateTypedDocsReference, type SlateWebhookHttpResponseInit, type SlateWebhookManualFinishHandler, type SlateWebhookManualSetupHandler, type SlateWebhookProcessHandler, type SlateWebhookRegisterHandler, type SlateWebhookSkipped, type SlateWebhookTarget, type SlateWebhookTargetListHandler, type SlateWebhookTargetOwnership, type SlateWebhookUnregisterHandler, type VerifyHmacSignatureOptions, adapterSpec, allOf, anyOf, 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, graphWebhookHttp, inferSlateErrorFromAxios, isApiErrorRecord, isAxiosErrorLike, isServiceErrorData, isUrlEmbeddedCredential, looksLikeHtmlErrorBody, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, metaWebhookHttp, normalizeOAuthTokenResponse, pickDefined, publicTool, pushBoundedApiErrorDetail, readApiErrorText, redactUrlAttachmentSecrets, requestAxios, requestAxiosData, runWithContext, scopeClause, setIfDefined, skipWebhook, spec, statusLabelForApiError, tool, toolCategory, trigger, triggerGroup, truncateApiErrorMessage, uploadAttachmentDirect, validateScopes, verifyHmacSignature };
|
|
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 };
|
package/dist/index.module.js
CHANGED
|
@@ -1266,6 +1266,11 @@ var getApiErrorResponse = (error) => {
|
|
|
1266
1266
|
};
|
|
1267
1267
|
};
|
|
1268
1268
|
var getApiErrorStatus = (error) => getApiErrorResponse(error)?.status;
|
|
1269
|
+
var getUpstreamErrorStatus = (error) => {
|
|
1270
|
+
let value = error instanceof ServiceError ? error.data.upstreamStatus : getApiErrorStatus(error);
|
|
1271
|
+
let status = Number(value);
|
|
1272
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : void 0;
|
|
1273
|
+
};
|
|
1269
1274
|
var getApiErrorResponseWithBody = (error) => {
|
|
1270
1275
|
let response = getApiErrorResponse(error);
|
|
1271
1276
|
if (response?.data !== void 0) return response;
|
|
@@ -1773,6 +1778,13 @@ var SlateDeclarationError = class _SlateDeclarationError extends SlateError {
|
|
|
1773
1778
|
}
|
|
1774
1779
|
};
|
|
1775
1780
|
|
|
1781
|
+
// src/error/parse.ts
|
|
1782
|
+
var parseWithServiceError = (schema, value, message, options = {}) => {
|
|
1783
|
+
let result = schema.safeParse(value);
|
|
1784
|
+
if (!result.success) throw createApiServiceError(message, options);
|
|
1785
|
+
return result.data;
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1776
1788
|
// src/action/scopes.ts
|
|
1777
1789
|
var scopeClause = (...scopes) => {
|
|
1778
1790
|
assertScopeValues(scopes);
|
|
@@ -2150,6 +2162,9 @@ var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
|
2150
2162
|
get source() {
|
|
2151
2163
|
return this._params.source;
|
|
2152
2164
|
}
|
|
2165
|
+
get selectionSchema() {
|
|
2166
|
+
return this._params.selectionSchema;
|
|
2167
|
+
}
|
|
2153
2168
|
get polling() {
|
|
2154
2169
|
return this._params.polling;
|
|
2155
2170
|
}
|
|
@@ -2197,11 +2212,41 @@ var SlateTriggerGroupBuilder = class {
|
|
|
2197
2212
|
"Webhook trigger groups require exactly one of autoRegistration or manualRegistration"
|
|
2198
2213
|
);
|
|
2199
2214
|
}
|
|
2215
|
+
if (props.deliveryConfig !== void 0) {
|
|
2216
|
+
if (!props.autoRegistration) {
|
|
2217
|
+
throw new SlateDeclarationError(
|
|
2218
|
+
"A webhook delivery config requires automatic webhook registration"
|
|
2219
|
+
);
|
|
2220
|
+
}
|
|
2221
|
+
if (!props.deliveryConfig.finish) {
|
|
2222
|
+
throw new SlateDeclarationError("A webhook delivery config requires a finish handler");
|
|
2223
|
+
}
|
|
2224
|
+
if (!props.deliveryConfig.authenticate) {
|
|
2225
|
+
throw new SlateDeclarationError(
|
|
2226
|
+
"A webhook delivery config requires an authenticate handler"
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
if (props.reconcileIntervalSeconds !== void 0) {
|
|
2231
|
+
if (!Number.isSafeInteger(props.reconcileIntervalSeconds) || props.reconcileIntervalSeconds < 900) {
|
|
2232
|
+
throw new SlateDeclarationError(
|
|
2233
|
+
"Webhook reconciliation interval must be an integer of at least 900 seconds"
|
|
2234
|
+
);
|
|
2235
|
+
}
|
|
2236
|
+
if (!props.expandWebhook) {
|
|
2237
|
+
throw new SlateDeclarationError(
|
|
2238
|
+
"Webhook reconciliation requires an expandWebhook handler"
|
|
2239
|
+
);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2200
2242
|
this.#source = "webhook";
|
|
2201
2243
|
this.#webhook = {
|
|
2202
2244
|
autoRegistration: props.autoRegistration,
|
|
2203
2245
|
manualRegistration: props.manualRegistration,
|
|
2204
|
-
|
|
2246
|
+
deliveryConfig: props.deliveryConfig,
|
|
2247
|
+
process: props.process,
|
|
2248
|
+
expandWebhook: props.expandWebhook,
|
|
2249
|
+
reconcileIntervalSeconds: props.reconcileIntervalSeconds
|
|
2205
2250
|
};
|
|
2206
2251
|
return this;
|
|
2207
2252
|
}
|
|
@@ -2981,13 +3026,29 @@ var createHmacSignature = ({
|
|
|
2981
3026
|
digest,
|
|
2982
3027
|
prefix = ""
|
|
2983
3028
|
}) => `${prefix}${createHmac(algorithm, secret).update(payload).digest(digest)}`;
|
|
2984
|
-
var
|
|
2985
|
-
let expected = createHmacSignature(options);
|
|
3029
|
+
var timingSafeStringEqual = (expected, received) => {
|
|
2986
3030
|
let expectedBytes = Buffer.from(expected);
|
|
2987
|
-
let
|
|
2988
|
-
let lengthsMatch =
|
|
2989
|
-
let
|
|
2990
|
-
return timingSafeEqual(
|
|
3031
|
+
let receivedBytes = Buffer.from(received ?? "");
|
|
3032
|
+
let lengthsMatch = receivedBytes.length === expectedBytes.length;
|
|
3033
|
+
let comparable = lengthsMatch ? receivedBytes : Buffer.alloc(expectedBytes.length);
|
|
3034
|
+
return timingSafeEqual(comparable, expectedBytes) && lengthsMatch && expectedBytes.length > 0;
|
|
3035
|
+
};
|
|
3036
|
+
var verifyHmacSignature = (options) => timingSafeStringEqual(createHmacSignature(options), options.signature);
|
|
3037
|
+
|
|
3038
|
+
// src/dedup/index.ts
|
|
3039
|
+
import { createHash } from "crypto";
|
|
3040
|
+
import { z as z3 } from "zod";
|
|
3041
|
+
var seenEntrySchema = z3.object({ key: z3.string().min(1), at: z3.number().finite() });
|
|
3042
|
+
var seenEntryKey = (idempotencyKey) => createHash("sha256").update(idempotencyKey).digest("base64url").slice(0, 16);
|
|
3043
|
+
var pruneSeenEntries = (entries, options) => {
|
|
3044
|
+
let kept = [];
|
|
3045
|
+
for (let { key, at, retain } of entries) {
|
|
3046
|
+
if (retain || at >= options.cutoff) kept.push({ key, at });
|
|
3047
|
+
}
|
|
3048
|
+
kept.sort((a, b) => b.at - a.at || (a.key < b.key ? -1 : 1));
|
|
3049
|
+
if (kept.length <= options.maxEntries) return kept;
|
|
3050
|
+
options.onOverflow?.(kept.length - options.maxEntries);
|
|
3051
|
+
return kept.slice(0, options.maxEntries);
|
|
2991
3052
|
};
|
|
2992
3053
|
|
|
2993
3054
|
// src/file/index.ts
|
|
@@ -3117,6 +3178,16 @@ var setIfDefined = (target, key, value) => {
|
|
|
3117
3178
|
return target;
|
|
3118
3179
|
};
|
|
3119
3180
|
|
|
3181
|
+
// src/pagination/index.ts
|
|
3182
|
+
var rememberPageToken = (seen, token) => {
|
|
3183
|
+
if (seen.has(token)) return false;
|
|
3184
|
+
seen.add(token);
|
|
3185
|
+
return true;
|
|
3186
|
+
};
|
|
3187
|
+
var assertNewPageToken = (seen, token, repeated) => {
|
|
3188
|
+
if (token && !rememberPageToken(seen, token)) throw repeated();
|
|
3189
|
+
};
|
|
3190
|
+
|
|
3120
3191
|
// src/specification/slate.ts
|
|
3121
3192
|
var Slate = class _Slate {
|
|
3122
3193
|
constructor(_spec, _actions, _adapters, _triggerGroups, _toolCategories, _toolCategoryKeysByActionKey) {
|
|
@@ -3168,12 +3239,12 @@ var Slate = class _Slate {
|
|
|
3168
3239
|
}
|
|
3169
3240
|
seenTriggerGroupKeys.add(group.key);
|
|
3170
3241
|
}
|
|
3171
|
-
let
|
|
3172
|
-
(group) => group.source === "webhook" && group.webhook?.manualRegistration
|
|
3242
|
+
let configuredWebhookTriggerGroups = triggerGroups.filter(
|
|
3243
|
+
(group) => group.source === "webhook" && (group.webhook?.manualRegistration || group.webhook?.deliveryConfig)
|
|
3173
3244
|
);
|
|
3174
|
-
if (
|
|
3245
|
+
if (configuredWebhookTriggerGroups.length > 1) {
|
|
3175
3246
|
throw new SlateDeclarationError(
|
|
3176
|
-
`Only one trigger group may use manual webhook registration, but found: ${
|
|
3247
|
+
`Only one trigger group may use manual webhook registration or a delivery config, but found: ${configuredWebhookTriggerGroups.map((group) => group.key).join(", ")}`
|
|
3177
3248
|
);
|
|
3178
3249
|
}
|
|
3179
3250
|
let toolCategories = params.toolCategories ?? [];
|
|
@@ -3275,7 +3346,7 @@ var resolveToolCategoryMembership = (toolCategories, actions) => {
|
|
|
3275
3346
|
};
|
|
3276
3347
|
|
|
3277
3348
|
// src/specification/specification.ts
|
|
3278
|
-
import
|
|
3349
|
+
import z4 from "zod";
|
|
3279
3350
|
var SlateSpecification = class _SlateSpecification {
|
|
3280
3351
|
constructor(_config, _auth, _params) {
|
|
3281
3352
|
this._config = _config;
|
|
@@ -3292,7 +3363,7 @@ var SlateSpecification = class _SlateSpecification {
|
|
|
3292
3363
|
return this._config.configSchema;
|
|
3293
3364
|
}
|
|
3294
3365
|
get authSchema() {
|
|
3295
|
-
return "outputSchema" in this._auth ? this._auth.outputSchema :
|
|
3366
|
+
return "outputSchema" in this._auth ? this._auth.outputSchema : z4.object({});
|
|
3296
3367
|
}
|
|
3297
3368
|
get config() {
|
|
3298
3369
|
return this._config;
|
|
@@ -3407,6 +3478,7 @@ export {
|
|
|
3407
3478
|
adapterSpec,
|
|
3408
3479
|
allOf,
|
|
3409
3480
|
anyOf,
|
|
3481
|
+
assertNewPageToken,
|
|
3410
3482
|
auth,
|
|
3411
3483
|
axios,
|
|
3412
3484
|
buildApiServiceError,
|
|
@@ -3436,6 +3508,7 @@ export {
|
|
|
3436
3508
|
getResponseHeaderValue,
|
|
3437
3509
|
getRuntimeInfo,
|
|
3438
3510
|
getServiceErrorData,
|
|
3511
|
+
getUpstreamErrorStatus,
|
|
3439
3512
|
graphWebhookHttp,
|
|
3440
3513
|
inferSlateErrorFromAxios,
|
|
3441
3514
|
isApiErrorRecord,
|
|
@@ -3448,19 +3521,25 @@ export {
|
|
|
3448
3521
|
mergeScopes,
|
|
3449
3522
|
metaWebhookHttp,
|
|
3450
3523
|
normalizeOAuthTokenResponse,
|
|
3524
|
+
parseWithServiceError,
|
|
3451
3525
|
pickDefined,
|
|
3526
|
+
pruneSeenEntries,
|
|
3452
3527
|
publicTool,
|
|
3453
3528
|
pushBoundedApiErrorDetail,
|
|
3454
3529
|
readApiErrorText,
|
|
3455
3530
|
redactUrlAttachmentSecrets,
|
|
3531
|
+
rememberPageToken,
|
|
3456
3532
|
requestAxios,
|
|
3457
3533
|
requestAxiosData,
|
|
3458
3534
|
runWithContext,
|
|
3459
3535
|
scopeClause,
|
|
3536
|
+
seenEntryKey,
|
|
3537
|
+
seenEntrySchema,
|
|
3460
3538
|
setIfDefined,
|
|
3461
3539
|
skipWebhook,
|
|
3462
3540
|
spec,
|
|
3463
3541
|
statusLabelForApiError,
|
|
3542
|
+
timingSafeStringEqual,
|
|
3464
3543
|
tool,
|
|
3465
3544
|
toolCategory,
|
|
3466
3545
|
trigger,
|
package/package.json
CHANGED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { SlateAuth } from '../auth';
|
|
4
|
+
import { SlateConfig } from '../config';
|
|
5
|
+
import { SlateSpecification } from '../specification/specification';
|
|
6
|
+
import { triggerGroup } from './triggerGroup';
|
|
7
|
+
|
|
8
|
+
let spec = SlateSpecification.create({
|
|
9
|
+
key: 'demo',
|
|
10
|
+
name: 'Demo',
|
|
11
|
+
config: SlateConfig.create(z.object({})),
|
|
12
|
+
auth: SlateAuth.create<{}>().output(z.object({}))
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
let autoRegistration = {
|
|
16
|
+
webhookTargetList: async () => ({ targets: [], nextPageToken: null }),
|
|
17
|
+
webhookRegister: async () => ({
|
|
18
|
+
webhookRegistrationIdentifier: 'reg',
|
|
19
|
+
webhookRegistrationPayload: {}
|
|
20
|
+
}),
|
|
21
|
+
webhookUnregister: async () => {}
|
|
22
|
+
};
|
|
23
|
+
let setup = async () => ({ webhookSetupDocument: '', partialWebhookRegistrationPayload: {} });
|
|
24
|
+
let manualRegistration = {
|
|
25
|
+
userConfigSchema: z.object({}),
|
|
26
|
+
fullConfigSchema: z.object({}),
|
|
27
|
+
setup
|
|
28
|
+
};
|
|
29
|
+
let deliveryConfig = {
|
|
30
|
+
...manualRegistration,
|
|
31
|
+
finish: async () => ({ webhookRegistrationPayload: {} }),
|
|
32
|
+
authenticate: async () => ({ routingKeys: [] })
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type WebhookProps = Parameters<ReturnType<typeof triggerGroup>['webhook']>[0];
|
|
36
|
+
|
|
37
|
+
let build = (props: Omit<WebhookProps, 'process'>) =>
|
|
38
|
+
triggerGroup(spec, { key: 'group', name: 'Group' })
|
|
39
|
+
.webhook({ ...props, process: async () => ({ events: [] }) })
|
|
40
|
+
.routingMatchers(async () => [])
|
|
41
|
+
.build();
|
|
42
|
+
|
|
43
|
+
describe('webhook trigger group declaration', () => {
|
|
44
|
+
it('builds plain automatic and manual groups as before', () => {
|
|
45
|
+
expect(build({ autoRegistration }).webhook).toMatchObject({
|
|
46
|
+
autoRegistration,
|
|
47
|
+
manualRegistration: undefined,
|
|
48
|
+
deliveryConfig: undefined
|
|
49
|
+
});
|
|
50
|
+
expect(build({ manualRegistration }).webhook).toMatchObject({
|
|
51
|
+
autoRegistration: undefined,
|
|
52
|
+
manualRegistration,
|
|
53
|
+
deliveryConfig: undefined
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('requires exactly one of automatic or manual registration', () => {
|
|
58
|
+
let message =
|
|
59
|
+
'Webhook trigger groups require exactly one of autoRegistration or manualRegistration';
|
|
60
|
+
expect(() => build({})).toThrow(message);
|
|
61
|
+
expect(() => build({ deliveryConfig })).toThrow(message);
|
|
62
|
+
expect(() => build({ autoRegistration, manualRegistration })).toThrow(message);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('allows a delivery config only with automatic registration and its handlers', () => {
|
|
66
|
+
expect(build({ autoRegistration, deliveryConfig }).webhook?.deliveryConfig).toBe(
|
|
67
|
+
deliveryConfig
|
|
68
|
+
);
|
|
69
|
+
expect(() => build({ manualRegistration, deliveryConfig })).toThrow(
|
|
70
|
+
'A webhook delivery config requires automatic webhook registration'
|
|
71
|
+
);
|
|
72
|
+
let { finish: _, ...withoutFinish } = deliveryConfig;
|
|
73
|
+
expect(() =>
|
|
74
|
+
build({
|
|
75
|
+
autoRegistration,
|
|
76
|
+
deliveryConfig: withoutFinish as unknown as typeof deliveryConfig
|
|
77
|
+
})
|
|
78
|
+
).toThrow('A webhook delivery config requires a finish handler');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('requires a delivery config to authenticate the requests it receives', () => {
|
|
82
|
+
let { authenticate: _, ...withoutAuthenticate } = deliveryConfig;
|
|
83
|
+
expect(() =>
|
|
84
|
+
build({
|
|
85
|
+
autoRegistration,
|
|
86
|
+
deliveryConfig: withoutAuthenticate as unknown as typeof deliveryConfig
|
|
87
|
+
})
|
|
88
|
+
).toThrow('A webhook delivery config requires an authenticate handler');
|
|
89
|
+
});
|
|
90
|
+
});
|