@slates/provider 1.0.0-rc.16 → 1.0.0-rc.17

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.d.cts CHANGED
@@ -145,6 +145,7 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
145
145
  docs?: SlateAuthDocsReference[];
146
146
  getOutput: (ctx: {
147
147
  input: InputType;
148
+ config?: SlateAuthCallbackConfig;
148
149
  }) => Promise<{
149
150
  output: OutputType;
150
151
  scopes?: string[];
@@ -159,6 +160,8 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
159
160
  getProfile?: (ctx: {
160
161
  output: OutputType;
161
162
  input: InputType;
163
+ scopes: string[];
164
+ config?: SlateAuthCallbackConfig;
162
165
  }) => Promise<{
163
166
  profile: Record<string, any>;
164
167
  }>;
@@ -171,6 +174,7 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
171
174
  docs?: SlateAuthDocsReference[];
172
175
  getOutput: (ctx: {
173
176
  input: InputType;
177
+ config?: SlateAuthCallbackConfig;
174
178
  }) => Promise<{
175
179
  output: OutputType;
176
180
  scopes?: string[];
@@ -185,6 +189,8 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
185
189
  getProfile?: (ctx: {
186
190
  output: OutputType;
187
191
  input: InputType;
192
+ scopes: string[];
193
+ config?: SlateAuthCallbackConfig;
188
194
  }) => Promise<{
189
195
  profile: Record<string, any>;
190
196
  }>;
@@ -197,6 +203,7 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
197
203
  docs?: SlateAuthDocsReference[];
198
204
  getOutput: (ctx: {
199
205
  input: InputType;
206
+ config?: SlateAuthCallbackConfig;
200
207
  }) => Promise<{
201
208
  output: OutputType;
202
209
  scopes?: string[];
@@ -207,6 +214,7 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
207
214
  clientId: string;
208
215
  clientSecret: string;
209
216
  scopes: string[];
217
+ config?: SlateAuthCallbackConfig;
210
218
  }) => Promise<{
211
219
  output: OutputType;
212
220
  input?: InputType;
@@ -221,6 +229,8 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
221
229
  getProfile?: (ctx: {
222
230
  output: OutputType;
223
231
  input: InputType;
232
+ scopes: string[];
233
+ config?: SlateAuthCallbackConfig;
224
234
  }) => Promise<{
225
235
  profile: Record<string, any>;
226
236
  }>;
@@ -264,6 +274,34 @@ declare class SlateAuth<OutputType extends {} = {}> {
264
274
  }
265
275
  declare let auth: <OutputType extends {} = {}>() => SlateAuth<OutputType>;
266
276
 
277
+ type OAuthTokenResponse = {
278
+ access_token?: unknown;
279
+ refresh_token?: unknown;
280
+ expires_in?: unknown;
281
+ [key: string]: unknown;
282
+ };
283
+ type OAuthRefreshTokenFallbackMode = 'nullish' | 'falsy';
284
+ type OAuthExpiresAtOptions = {
285
+ nowMs?: number;
286
+ providerLabel?: string;
287
+ operation?: string;
288
+ required?: boolean;
289
+ expiresInType?: 'number' | 'numberLike';
290
+ message?: string;
291
+ };
292
+ type NormalizeOAuthTokenResponseOptions = OAuthExpiresAtOptions & {
293
+ previousRefreshToken?: string;
294
+ refreshTokenFallbackMode?: OAuthRefreshTokenFallbackMode;
295
+ accessTokenMessage?: string;
296
+ expiresInMessage?: string;
297
+ };
298
+ declare let getOAuthExpiresAtFromExpiresIn: (expiresIn: unknown, options?: OAuthExpiresAtOptions) => string | undefined;
299
+ declare let normalizeOAuthTokenResponse: (data: unknown, options?: NormalizeOAuthTokenResponseOptions) => {
300
+ token: string;
301
+ refreshToken: string | undefined;
302
+ expiresAt: string | undefined;
303
+ };
304
+
267
305
  declare class SlateConfig<ConfigType extends {}> {
268
306
  #private;
269
307
  private constructor();
@@ -331,6 +369,7 @@ declare class SlateContext<ConfigType extends {}, AuthType extends {}, InputType
331
369
  get event(): Readonly<InputType>;
332
370
  get state(): "state" extends keyof InputType ? InputType["state"] : never;
333
371
  get request(): "request" extends keyof InputType ? InputType["request"] : never;
372
+ get registrationDetails(): "registrationDetails" extends keyof InputType ? InputType["registrationDetails"] : never;
334
373
  get auth(): Readonly<AuthType>;
335
374
  recordHttpTrace(trace: SlateHttpTrace): void;
336
375
  getHttpTraces(): {
@@ -418,12 +457,41 @@ type SlateTriggerPollingHandler<ConfigType extends {}, AuthType extends {}, Inpu
418
457
  inputs: InputType[];
419
458
  updatedState?: any;
420
459
  }>;
460
+ interface SlateWebhookHttpResponseInit {
461
+ status?: number;
462
+ headers?: Record<string, string>;
463
+ body?: string | Uint8Array | null;
464
+ }
465
+ type SlateWebhookHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
466
+ interface SlateWebhookRequestMatcher {
467
+ method?: string;
468
+ hasQueryParam?: string;
469
+ hasHeader?: string;
470
+ jsonBodyField?: {
471
+ path: string;
472
+ equals?: string;
473
+ };
474
+ formBodyField?: {
475
+ path: string;
476
+ equals?: string;
477
+ };
478
+ }
479
+ interface SlateWebhookHttpOptions {
480
+ methods?: SlateWebhookHttpMethod[];
481
+ sync?: {
482
+ mode: 'never' | 'match' | 'always';
483
+ match?: SlateWebhookRequestMatcher[];
484
+ timeoutMs?: number;
485
+ };
486
+ }
421
487
  type SlateTriggerWebhookRequestHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}> = (context: SlateContext<ConfigType, AuthType, {
422
488
  request: Request;
423
489
  state: any | null;
490
+ registrationDetails: any | null;
424
491
  }>) => Promise<{
425
492
  inputs: InputType[];
426
493
  updatedState?: any;
494
+ response?: Response | SlateWebhookHttpResponseInit;
427
495
  }>;
428
496
  type SlateTriggerWebhookAutoRegistrationHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
429
497
  webhookBaseUrl: string;
@@ -449,6 +517,7 @@ interface SlateActionParametersTrigger<ConfigType extends {}, AuthType extends {
449
517
  polling?: SlatePollingOptions;
450
518
  handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
451
519
  handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
520
+ http?: SlateWebhookHttpOptions;
452
521
  pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
453
522
  autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
454
523
  autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
@@ -505,6 +574,7 @@ declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extend
505
574
  handleRequest: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
506
575
  autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
507
576
  autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
577
+ http?: SlateWebhookHttpOptions;
508
578
  }): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result>;
509
579
  polling(props: {
510
580
  options?: SlatePollingOptions;
@@ -543,6 +613,7 @@ interface SlateTriggerParameters<ConfigType extends {}, AuthType extends {}, Inp
543
613
  polling?: SlatePollingOptions;
544
614
  handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
545
615
  handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
616
+ http?: SlateWebhookHttpOptions;
546
617
  pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
547
618
  autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
548
619
  autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
@@ -557,12 +628,69 @@ declare class SlateTrigger<ConfigType extends {}, AuthType extends {}, InputType
557
628
  get source(): "polling" | "webhook";
558
629
  get handleEvent(): SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
559
630
  get handleRequest(): SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType> | undefined;
631
+ get http(): SlateWebhookHttpOptions | undefined;
560
632
  get pollEvents(): SlateTriggerPollingHandler<ConfigType, AuthType, InputType> | undefined;
561
633
  get autoRegisterWebhook(): SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType> | undefined;
562
634
  get autoUnregisterWebhook(): SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType> | undefined;
563
635
  }
564
636
  declare let trigger: <ConfigType extends {}, AuthType extends {}>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters) => SlateActionBuilder<"trigger", ConfigType, AuthType, {}, {}, SlateTrigger<any, any, any, any>>;
565
637
 
638
+ type ApiErrorStatus = number | string;
639
+ type ApiServiceError = ServiceError<ErrorRecord<any, any>>;
640
+ type ApiErrorResponse = {
641
+ status?: ApiErrorStatus;
642
+ statusText?: string;
643
+ data?: unknown;
644
+ };
645
+ type ApiErrorDetailOptions = {
646
+ detailKeys?: readonly string[];
647
+ nestedKeys?: readonly string[];
648
+ includeNumbers?: boolean;
649
+ separator?: string;
650
+ fallbackMessage?: string;
651
+ };
652
+ type ApiErrorBuildHelpers = {
653
+ collectDetails: (value: unknown, details: string[], options?: ApiErrorDetailOptions) => void;
654
+ extractMessage: (error: unknown, options?: ApiErrorDetailOptions) => string;
655
+ getResponse: (error: unknown) => ApiErrorResponse | undefined;
656
+ getStatus: (error: unknown) => ApiErrorStatus | undefined;
657
+ isRecord: (value: unknown) => value is Record<string, unknown>;
658
+ statusLabelFor: (status?: ApiErrorStatus, statusText?: string) => string;
659
+ };
660
+ type BuildApiServiceErrorOptions = ApiErrorDetailOptions & {
661
+ providerLabel: string;
662
+ reason: string;
663
+ operation?: string;
664
+ extractMessage?: (error: unknown, helpers: ApiErrorBuildHelpers) => string | undefined;
665
+ extractResponse?: (error: unknown, helpers: ApiErrorBuildHelpers) => ApiErrorResponse | undefined;
666
+ extractStatus?: (error: unknown, response: ApiErrorResponse | undefined, helpers: ApiErrorBuildHelpers) => ApiErrorStatus | undefined;
667
+ extractUpstreamCode?: (error: unknown, response: ApiErrorResponse | undefined, helpers: ApiErrorBuildHelpers) => string | undefined;
668
+ formatMessage?: (parts: {
669
+ providerLabel: string;
670
+ operation: string;
671
+ statusLabel: string;
672
+ message: string;
673
+ response?: ApiErrorResponse;
674
+ status?: ApiErrorStatus;
675
+ }) => string;
676
+ parent?: unknown;
677
+ };
678
+ declare let isApiErrorRecord: (value: unknown) => value is Record<string, unknown>;
679
+ declare let collectApiErrorDetails: (value: unknown, details: string[], options?: ApiErrorDetailOptions) => void;
680
+ declare let getApiErrorResponse: (error: unknown) => ApiErrorResponse | undefined;
681
+ declare let getApiErrorStatus: (error: unknown) => ApiErrorStatus | undefined;
682
+ declare let statusLabelForApiError: (status?: ApiErrorStatus, statusText?: string) => string;
683
+ declare let extractApiErrorMessage: (error: unknown, options?: ApiErrorDetailOptions & {
684
+ response?: ApiErrorResponse;
685
+ }) => string;
686
+ declare let createApiServiceError: (message: string, options?: {
687
+ reason?: string;
688
+ upstreamStatus?: ApiErrorStatus;
689
+ upstreamCode?: string;
690
+ parent?: unknown;
691
+ }) => ServiceError<ErrorRecord<"bad_request", 400>>;
692
+ declare let buildApiServiceError: (error: unknown, options: BuildApiServiceErrorOptions) => ServiceError<ErrorRecord<"bad_request", 400>>;
693
+
566
694
  declare class SlateError extends Error {
567
695
  cause?: unknown;
568
696
  data: SlateErrorResponse;
@@ -648,9 +776,40 @@ declare let mapServiceErrorToSlateErrorInput: (error: ServiceError<ErrorRecord<a
648
776
  interface SlateAxiosDefaults extends CreateAxiosDefaults {
649
777
  errorMapping?: SlateAxiosErrorOptions;
650
778
  }
779
+ type SlateAxiosErrorAdapter = (error: unknown, operation: string) => unknown;
780
+ interface SlateAuthenticatedAxiosDefaults extends SlateAxiosDefaults {
781
+ authHeader?: {
782
+ name?: string;
783
+ value: string;
784
+ };
785
+ contentType?: string | false;
786
+ errorAdapter?: (error: unknown) => unknown;
787
+ }
651
788
  declare let createAxios: (config?: SlateAxiosDefaults) => AxiosInstance;
789
+ declare let createAuthenticatedAxios: (config: SlateAuthenticatedAxiosDefaults) => AxiosInstance;
790
+ declare let requestAxios: <T = unknown>(operation: string, request: () => Promise<AxiosResponse<T>>, errorAdapter: SlateAxiosErrorAdapter) => Promise<AxiosResponse<T, any, {}>>;
791
+ declare let requestAxiosData: <T = unknown>(operation: string, request: () => Promise<AxiosResponse<T>>, errorAdapter: SlateAxiosErrorAdapter) => Promise<T>;
652
792
  declare let axios: AxiosInstance;
653
793
 
794
+ interface CreateHmacSignatureOptions {
795
+ secret: string | Uint8Array;
796
+ payload: string | Uint8Array;
797
+ algorithm?: string;
798
+ digest: 'hex' | 'base64';
799
+ prefix?: string;
800
+ }
801
+ interface VerifyHmacSignatureOptions extends CreateHmacSignatureOptions {
802
+ signature: string;
803
+ }
804
+ declare let createHmacSignature: ({ secret, payload, algorithm, digest, prefix }: CreateHmacSignatureOptions) => string;
805
+ declare let verifyHmacSignature: (options: VerifyHmacSignatureOptions) => boolean;
806
+
807
+ declare let getResponseHeaderValue: (headers: unknown, name: string) => string | undefined;
808
+ declare let getBase64ByteLength: (contentBase64: string) => number;
809
+
810
+ declare let pickDefined: <T extends object>(value: T) => Partial<T> & Record<string, unknown>;
811
+ declare let setIfDefined: (target: Record<string, unknown>, key: string, value: unknown) => Record<string, unknown>;
812
+
654
813
  declare class Slate<ConfigType extends {}, AuthType extends {}> {
655
814
  private readonly _spec;
656
815
  private readonly _actions;
@@ -664,4 +823,27 @@ declare class Slate<ConfigType extends {}, AuthType extends {}> {
664
823
  get actions(): (SlateTrigger<ConfigType, AuthType, any, any> | SlateTool<ConfigType, AuthType, any, any>)[];
665
824
  }
666
825
 
667
- export { 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, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthDocsReference, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAxiosDefaults, type SlateAxiosErrorOptions, SlateConfig, type SlateConfigDocsReference, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, type SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateProviderDocsReference, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, type SlateTypedDocsReference, allOf, anyOf, auth, axios, config, createAxios, createBase64Attachment, createSlateError, createTextAttachment, createUrlAttachment, getCurrentContext, getServiceErrorData, inferSlateErrorFromAxios, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, runWithContext, scopeClause, spec, tool, trigger, validateScopes };
826
+ declare const graphWebhookHttp: {
827
+ methods: "POST"[];
828
+ sync: {
829
+ mode: "match";
830
+ match: {
831
+ hasQueryParam: string;
832
+ }[];
833
+ };
834
+ };
835
+ declare let getGraphWebhookValidationResponse: (request: Request) => SlateWebhookHttpResponseInit | null;
836
+
837
+ declare const metaWebhookHttp: {
838
+ methods: ("GET" | "POST")[];
839
+ sync: {
840
+ mode: "match";
841
+ match: {
842
+ method: string;
843
+ hasQueryParam: string;
844
+ }[];
845
+ };
846
+ };
847
+ declare let getMetaWebhookVerificationResponse: (request: Request, expectedVerifyToken: string | undefined) => SlateWebhookHttpResponseInit | null;
848
+
849
+ export { type ApiErrorBuildHelpers, type ApiErrorDetailOptions, type ApiErrorResponse, type ApiErrorStatus, type ApiServiceError, type BuildApiServiceErrorOptions, type CreateHmacSignatureOptions, 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, type SlateAttachment, type SlateAttachmentInlineContent, 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 SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateProviderDocsReference, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, type SlateTypedDocsReference, type SlateWebhookHttpMethod, type SlateWebhookHttpOptions, type SlateWebhookHttpResponseInit, type SlateWebhookRequestMatcher, type VerifyHmacSignatureOptions, allOf, anyOf, auth, axios, buildApiServiceError, collectApiErrorDetails, config, createApiServiceError, createAuthenticatedAxios, createAxios, createBase64Attachment, createHmacSignature, createSlateError, createTextAttachment, createUrlAttachment, extractApiErrorMessage, getApiErrorResponse, getApiErrorStatus, getBase64ByteLength, getCurrentContext, getGraphWebhookValidationResponse, getMetaWebhookVerificationResponse, getOAuthExpiresAtFromExpiresIn, getResponseHeaderValue, getServiceErrorData, graphWebhookHttp, inferSlateErrorFromAxios, isApiErrorRecord, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, metaWebhookHttp, normalizeOAuthTokenResponse, pickDefined, requestAxios, requestAxiosData, runWithContext, scopeClause, setIfDefined, spec, statusLabelForApiError, tool, trigger, validateScopes, verifyHmacSignature };
package/dist/index.d.ts CHANGED
@@ -145,6 +145,7 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
145
145
  docs?: SlateAuthDocsReference[];
146
146
  getOutput: (ctx: {
147
147
  input: InputType;
148
+ config?: SlateAuthCallbackConfig;
148
149
  }) => Promise<{
149
150
  output: OutputType;
150
151
  scopes?: string[];
@@ -159,6 +160,8 @@ type SlateAuthWithToken<InputType extends {}, OutputType extends {
159
160
  getProfile?: (ctx: {
160
161
  output: OutputType;
161
162
  input: InputType;
163
+ scopes: string[];
164
+ config?: SlateAuthCallbackConfig;
162
165
  }) => Promise<{
163
166
  profile: Record<string, any>;
164
167
  }>;
@@ -171,6 +174,7 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
171
174
  docs?: SlateAuthDocsReference[];
172
175
  getOutput: (ctx: {
173
176
  input: InputType;
177
+ config?: SlateAuthCallbackConfig;
174
178
  }) => Promise<{
175
179
  output: OutputType;
176
180
  scopes?: string[];
@@ -185,6 +189,8 @@ type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> =
185
189
  getProfile?: (ctx: {
186
190
  output: OutputType;
187
191
  input: InputType;
192
+ scopes: string[];
193
+ config?: SlateAuthCallbackConfig;
188
194
  }) => Promise<{
189
195
  profile: Record<string, any>;
190
196
  }>;
@@ -197,6 +203,7 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
197
203
  docs?: SlateAuthDocsReference[];
198
204
  getOutput: (ctx: {
199
205
  input: InputType;
206
+ config?: SlateAuthCallbackConfig;
200
207
  }) => Promise<{
201
208
  output: OutputType;
202
209
  scopes?: string[];
@@ -207,6 +214,7 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
207
214
  clientId: string;
208
215
  clientSecret: string;
209
216
  scopes: string[];
217
+ config?: SlateAuthCallbackConfig;
210
218
  }) => Promise<{
211
219
  output: OutputType;
212
220
  input?: InputType;
@@ -221,6 +229,8 @@ type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
221
229
  getProfile?: (ctx: {
222
230
  output: OutputType;
223
231
  input: InputType;
232
+ scopes: string[];
233
+ config?: SlateAuthCallbackConfig;
224
234
  }) => Promise<{
225
235
  profile: Record<string, any>;
226
236
  }>;
@@ -264,6 +274,34 @@ declare class SlateAuth<OutputType extends {} = {}> {
264
274
  }
265
275
  declare let auth: <OutputType extends {} = {}>() => SlateAuth<OutputType>;
266
276
 
277
+ type OAuthTokenResponse = {
278
+ access_token?: unknown;
279
+ refresh_token?: unknown;
280
+ expires_in?: unknown;
281
+ [key: string]: unknown;
282
+ };
283
+ type OAuthRefreshTokenFallbackMode = 'nullish' | 'falsy';
284
+ type OAuthExpiresAtOptions = {
285
+ nowMs?: number;
286
+ providerLabel?: string;
287
+ operation?: string;
288
+ required?: boolean;
289
+ expiresInType?: 'number' | 'numberLike';
290
+ message?: string;
291
+ };
292
+ type NormalizeOAuthTokenResponseOptions = OAuthExpiresAtOptions & {
293
+ previousRefreshToken?: string;
294
+ refreshTokenFallbackMode?: OAuthRefreshTokenFallbackMode;
295
+ accessTokenMessage?: string;
296
+ expiresInMessage?: string;
297
+ };
298
+ declare let getOAuthExpiresAtFromExpiresIn: (expiresIn: unknown, options?: OAuthExpiresAtOptions) => string | undefined;
299
+ declare let normalizeOAuthTokenResponse: (data: unknown, options?: NormalizeOAuthTokenResponseOptions) => {
300
+ token: string;
301
+ refreshToken: string | undefined;
302
+ expiresAt: string | undefined;
303
+ };
304
+
267
305
  declare class SlateConfig<ConfigType extends {}> {
268
306
  #private;
269
307
  private constructor();
@@ -331,6 +369,7 @@ declare class SlateContext<ConfigType extends {}, AuthType extends {}, InputType
331
369
  get event(): Readonly<InputType>;
332
370
  get state(): "state" extends keyof InputType ? InputType["state"] : never;
333
371
  get request(): "request" extends keyof InputType ? InputType["request"] : never;
372
+ get registrationDetails(): "registrationDetails" extends keyof InputType ? InputType["registrationDetails"] : never;
334
373
  get auth(): Readonly<AuthType>;
335
374
  recordHttpTrace(trace: SlateHttpTrace): void;
336
375
  getHttpTraces(): {
@@ -418,12 +457,41 @@ type SlateTriggerPollingHandler<ConfigType extends {}, AuthType extends {}, Inpu
418
457
  inputs: InputType[];
419
458
  updatedState?: any;
420
459
  }>;
460
+ interface SlateWebhookHttpResponseInit {
461
+ status?: number;
462
+ headers?: Record<string, string>;
463
+ body?: string | Uint8Array | null;
464
+ }
465
+ type SlateWebhookHttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
466
+ interface SlateWebhookRequestMatcher {
467
+ method?: string;
468
+ hasQueryParam?: string;
469
+ hasHeader?: string;
470
+ jsonBodyField?: {
471
+ path: string;
472
+ equals?: string;
473
+ };
474
+ formBodyField?: {
475
+ path: string;
476
+ equals?: string;
477
+ };
478
+ }
479
+ interface SlateWebhookHttpOptions {
480
+ methods?: SlateWebhookHttpMethod[];
481
+ sync?: {
482
+ mode: 'never' | 'match' | 'always';
483
+ match?: SlateWebhookRequestMatcher[];
484
+ timeoutMs?: number;
485
+ };
486
+ }
421
487
  type SlateTriggerWebhookRequestHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}> = (context: SlateContext<ConfigType, AuthType, {
422
488
  request: Request;
423
489
  state: any | null;
490
+ registrationDetails: any | null;
424
491
  }>) => Promise<{
425
492
  inputs: InputType[];
426
493
  updatedState?: any;
494
+ response?: Response | SlateWebhookHttpResponseInit;
427
495
  }>;
428
496
  type SlateTriggerWebhookAutoRegistrationHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
429
497
  webhookBaseUrl: string;
@@ -449,6 +517,7 @@ interface SlateActionParametersTrigger<ConfigType extends {}, AuthType extends {
449
517
  polling?: SlatePollingOptions;
450
518
  handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
451
519
  handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
520
+ http?: SlateWebhookHttpOptions;
452
521
  pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
453
522
  autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
454
523
  autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
@@ -505,6 +574,7 @@ declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extend
505
574
  handleRequest: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
506
575
  autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
507
576
  autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
577
+ http?: SlateWebhookHttpOptions;
508
578
  }): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result>;
509
579
  polling(props: {
510
580
  options?: SlatePollingOptions;
@@ -543,6 +613,7 @@ interface SlateTriggerParameters<ConfigType extends {}, AuthType extends {}, Inp
543
613
  polling?: SlatePollingOptions;
544
614
  handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
545
615
  handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
616
+ http?: SlateWebhookHttpOptions;
546
617
  pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
547
618
  autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
548
619
  autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
@@ -557,12 +628,69 @@ declare class SlateTrigger<ConfigType extends {}, AuthType extends {}, InputType
557
628
  get source(): "polling" | "webhook";
558
629
  get handleEvent(): SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
559
630
  get handleRequest(): SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType> | undefined;
631
+ get http(): SlateWebhookHttpOptions | undefined;
560
632
  get pollEvents(): SlateTriggerPollingHandler<ConfigType, AuthType, InputType> | undefined;
561
633
  get autoRegisterWebhook(): SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType> | undefined;
562
634
  get autoUnregisterWebhook(): SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType> | undefined;
563
635
  }
564
636
  declare let trigger: <ConfigType extends {}, AuthType extends {}>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters) => SlateActionBuilder<"trigger", ConfigType, AuthType, {}, {}, SlateTrigger<any, any, any, any>>;
565
637
 
638
+ type ApiErrorStatus = number | string;
639
+ type ApiServiceError = ServiceError<ErrorRecord<any, any>>;
640
+ type ApiErrorResponse = {
641
+ status?: ApiErrorStatus;
642
+ statusText?: string;
643
+ data?: unknown;
644
+ };
645
+ type ApiErrorDetailOptions = {
646
+ detailKeys?: readonly string[];
647
+ nestedKeys?: readonly string[];
648
+ includeNumbers?: boolean;
649
+ separator?: string;
650
+ fallbackMessage?: string;
651
+ };
652
+ type ApiErrorBuildHelpers = {
653
+ collectDetails: (value: unknown, details: string[], options?: ApiErrorDetailOptions) => void;
654
+ extractMessage: (error: unknown, options?: ApiErrorDetailOptions) => string;
655
+ getResponse: (error: unknown) => ApiErrorResponse | undefined;
656
+ getStatus: (error: unknown) => ApiErrorStatus | undefined;
657
+ isRecord: (value: unknown) => value is Record<string, unknown>;
658
+ statusLabelFor: (status?: ApiErrorStatus, statusText?: string) => string;
659
+ };
660
+ type BuildApiServiceErrorOptions = ApiErrorDetailOptions & {
661
+ providerLabel: string;
662
+ reason: string;
663
+ operation?: string;
664
+ extractMessage?: (error: unknown, helpers: ApiErrorBuildHelpers) => string | undefined;
665
+ extractResponse?: (error: unknown, helpers: ApiErrorBuildHelpers) => ApiErrorResponse | undefined;
666
+ extractStatus?: (error: unknown, response: ApiErrorResponse | undefined, helpers: ApiErrorBuildHelpers) => ApiErrorStatus | undefined;
667
+ extractUpstreamCode?: (error: unknown, response: ApiErrorResponse | undefined, helpers: ApiErrorBuildHelpers) => string | undefined;
668
+ formatMessage?: (parts: {
669
+ providerLabel: string;
670
+ operation: string;
671
+ statusLabel: string;
672
+ message: string;
673
+ response?: ApiErrorResponse;
674
+ status?: ApiErrorStatus;
675
+ }) => string;
676
+ parent?: unknown;
677
+ };
678
+ declare let isApiErrorRecord: (value: unknown) => value is Record<string, unknown>;
679
+ declare let collectApiErrorDetails: (value: unknown, details: string[], options?: ApiErrorDetailOptions) => void;
680
+ declare let getApiErrorResponse: (error: unknown) => ApiErrorResponse | undefined;
681
+ declare let getApiErrorStatus: (error: unknown) => ApiErrorStatus | undefined;
682
+ declare let statusLabelForApiError: (status?: ApiErrorStatus, statusText?: string) => string;
683
+ declare let extractApiErrorMessage: (error: unknown, options?: ApiErrorDetailOptions & {
684
+ response?: ApiErrorResponse;
685
+ }) => string;
686
+ declare let createApiServiceError: (message: string, options?: {
687
+ reason?: string;
688
+ upstreamStatus?: ApiErrorStatus;
689
+ upstreamCode?: string;
690
+ parent?: unknown;
691
+ }) => ServiceError<ErrorRecord<"bad_request", 400>>;
692
+ declare let buildApiServiceError: (error: unknown, options: BuildApiServiceErrorOptions) => ServiceError<ErrorRecord<"bad_request", 400>>;
693
+
566
694
  declare class SlateError extends Error {
567
695
  cause?: unknown;
568
696
  data: SlateErrorResponse;
@@ -648,9 +776,40 @@ declare let mapServiceErrorToSlateErrorInput: (error: ServiceError<ErrorRecord<a
648
776
  interface SlateAxiosDefaults extends CreateAxiosDefaults {
649
777
  errorMapping?: SlateAxiosErrorOptions;
650
778
  }
779
+ type SlateAxiosErrorAdapter = (error: unknown, operation: string) => unknown;
780
+ interface SlateAuthenticatedAxiosDefaults extends SlateAxiosDefaults {
781
+ authHeader?: {
782
+ name?: string;
783
+ value: string;
784
+ };
785
+ contentType?: string | false;
786
+ errorAdapter?: (error: unknown) => unknown;
787
+ }
651
788
  declare let createAxios: (config?: SlateAxiosDefaults) => AxiosInstance;
789
+ declare let createAuthenticatedAxios: (config: SlateAuthenticatedAxiosDefaults) => AxiosInstance;
790
+ declare let requestAxios: <T = unknown>(operation: string, request: () => Promise<AxiosResponse<T>>, errorAdapter: SlateAxiosErrorAdapter) => Promise<AxiosResponse<T, any, {}>>;
791
+ declare let requestAxiosData: <T = unknown>(operation: string, request: () => Promise<AxiosResponse<T>>, errorAdapter: SlateAxiosErrorAdapter) => Promise<T>;
652
792
  declare let axios: AxiosInstance;
653
793
 
794
+ interface CreateHmacSignatureOptions {
795
+ secret: string | Uint8Array;
796
+ payload: string | Uint8Array;
797
+ algorithm?: string;
798
+ digest: 'hex' | 'base64';
799
+ prefix?: string;
800
+ }
801
+ interface VerifyHmacSignatureOptions extends CreateHmacSignatureOptions {
802
+ signature: string;
803
+ }
804
+ declare let createHmacSignature: ({ secret, payload, algorithm, digest, prefix }: CreateHmacSignatureOptions) => string;
805
+ declare let verifyHmacSignature: (options: VerifyHmacSignatureOptions) => boolean;
806
+
807
+ declare let getResponseHeaderValue: (headers: unknown, name: string) => string | undefined;
808
+ declare let getBase64ByteLength: (contentBase64: string) => number;
809
+
810
+ declare let pickDefined: <T extends object>(value: T) => Partial<T> & Record<string, unknown>;
811
+ declare let setIfDefined: (target: Record<string, unknown>, key: string, value: unknown) => Record<string, unknown>;
812
+
654
813
  declare class Slate<ConfigType extends {}, AuthType extends {}> {
655
814
  private readonly _spec;
656
815
  private readonly _actions;
@@ -664,4 +823,27 @@ declare class Slate<ConfigType extends {}, AuthType extends {}> {
664
823
  get actions(): (SlateTrigger<ConfigType, AuthType, any, any> | SlateTool<ConfigType, AuthType, any, any>)[];
665
824
  }
666
825
 
667
- export { 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, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthDocsReference, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAxiosDefaults, type SlateAxiosErrorOptions, SlateConfig, type SlateConfigDocsReference, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, type SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateProviderDocsReference, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, type SlateTypedDocsReference, allOf, anyOf, auth, axios, config, createAxios, createBase64Attachment, createSlateError, createTextAttachment, createUrlAttachment, getCurrentContext, getServiceErrorData, inferSlateErrorFromAxios, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, runWithContext, scopeClause, spec, tool, trigger, validateScopes };
826
+ declare const graphWebhookHttp: {
827
+ methods: "POST"[];
828
+ sync: {
829
+ mode: "match";
830
+ match: {
831
+ hasQueryParam: string;
832
+ }[];
833
+ };
834
+ };
835
+ declare let getGraphWebhookValidationResponse: (request: Request) => SlateWebhookHttpResponseInit | null;
836
+
837
+ declare const metaWebhookHttp: {
838
+ methods: ("GET" | "POST")[];
839
+ sync: {
840
+ mode: "match";
841
+ match: {
842
+ method: string;
843
+ hasQueryParam: string;
844
+ }[];
845
+ };
846
+ };
847
+ declare let getMetaWebhookVerificationResponse: (request: Request, expectedVerifyToken: string | undefined) => SlateWebhookHttpResponseInit | null;
848
+
849
+ export { type ApiErrorBuildHelpers, type ApiErrorDetailOptions, type ApiErrorResponse, type ApiErrorStatus, type ApiServiceError, type BuildApiServiceErrorOptions, type CreateHmacSignatureOptions, 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, type SlateAttachment, type SlateAttachmentInlineContent, 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 SlateDocsReference, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateProviderDocsReference, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, type SlateTypedDocsReference, type SlateWebhookHttpMethod, type SlateWebhookHttpOptions, type SlateWebhookHttpResponseInit, type SlateWebhookRequestMatcher, type VerifyHmacSignatureOptions, allOf, anyOf, auth, axios, buildApiServiceError, collectApiErrorDetails, config, createApiServiceError, createAuthenticatedAxios, createAxios, createBase64Attachment, createHmacSignature, createSlateError, createTextAttachment, createUrlAttachment, extractApiErrorMessage, getApiErrorResponse, getApiErrorStatus, getBase64ByteLength, getCurrentContext, getGraphWebhookValidationResponse, getMetaWebhookVerificationResponse, getOAuthExpiresAtFromExpiresIn, getResponseHeaderValue, getServiceErrorData, graphWebhookHttp, inferSlateErrorFromAxios, isApiErrorRecord, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, metaWebhookHttp, normalizeOAuthTokenResponse, pickDefined, requestAxios, requestAxiosData, runWithContext, scopeClause, setIfDefined, spec, statusLabelForApiError, tool, trigger, validateScopes, verifyHmacSignature };