@brickkit/core 0.15.0 → 0.16.0-beta.1
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/chunks/client.d.ts +6 -3
- package/dist/chunks/client.js +22 -4
- package/dist/chunks/client.js.map +1 -1
- package/dist/chunks/server.d.ts +17 -13
- package/dist/chunks/server.js +2699 -679
- package/dist/chunks/server.js.map +1 -1
- package/dist/chunks/types.d.ts +1123 -298
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +210 -14
- package/dist/index.js +253 -252
- package/dist/index.js.map +1 -1
- package/dist/pg.d.ts +2 -3
- package/dist/pg.js +1 -1
- package/dist/tanstack-query.d.ts +1 -2
- package/dist/testing.d.ts +1 -2
- package/dist/testing.js +1 -1
- package/dist/workflow.d.ts +2 -3
- package/package.json +11 -11
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as BrickSocketClient, Ft as STANDARD_ERRORS, Q as BrickClientSocket, Rt as isControlEvent, at as BrickSocketReconnectOptions, ct as BrickSocketStatus, it as BrickSocketHandlerError, nt as BrickSocketError, pt as SocketEventArgs, st as BrickSocketSender, tt as BrickSocketConnectOptions } from "./chunks/types.js";
|
|
2
2
|
import { a as BrickClientOptions, c as BrickTransportError, d as InferActionInput, f as InferActionOutput, g as ATTR, h as isBrickTransportError, i as BrickClientAction, l as InferActionErrorCodes, m as isBrickServerError, n as BrickCallOptions, o as BrickServerError, p as createBrickClient, r as BrickClient, s as BrickServices, t as BrickActionCaller, u as InferActionFailure, v as SPAN, y as kebabCase } from "./chunks/client.js";
|
|
3
3
|
export { ATTR, BrickActionCaller, BrickCallOptions, BrickClient, BrickClientAction, BrickClientOptions, type BrickClientSocket, BrickServerError, BrickServices, type BrickSocketClient, type BrickSocketConnectOptions, BrickSocketError, type BrickSocketHandlerError, type BrickSocketReconnectOptions, type BrickSocketSender, type BrickSocketStatus, BrickTransportError, InferActionErrorCodes, InferActionFailure, InferActionInput, InferActionOutput, SPAN, STANDARD_ERRORS, type SocketEventArgs, createBrickClient, isBrickServerError, isBrickTransportError, isControlEvent, kebabCase };
|
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { H as ATTR, t as BrickServerError, o as BrickSocketError, n as BrickTransportError, W as SPAN, A as STANDARD_ERRORS, r as createBrickClient, i as isBrickServerError, a as isBrickTransportError, P as isControlEvent, S as kebabCase } from "./chunks/client.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { $n as
|
|
1
|
+
import { $n as PluginInfo, $r as listSecrets, $t as createPostgresDatabase, A as PreparationContribution, An as WebhookRequest, Ar as ScheduleWorkflowRun, At as DashboardIdentity, B as ResourceTypeOptions, Bn as OutboxTable, Br as CallFiles, Bt as Sensitive, C as DuplicateNameError, Cn as ResourcePluginContext, Cr as ServiceEvents, Ct as OutboxCounts, D as InferTableRow, Dn as ActionAccessInfo, Dr as ScheduleConfig, Dt as Identity, E as InferTableInsert, En as ServicePluginContext, Er as Schedule, Et as clientAddress, F as ResourceActionConfig, Fn as SQLiteScheduleTable, Fr as EventRefs, G as Tool, Gn as PostgresAuditTable, Gr as ScopedFiles, Gt as DatabaseHandle, H as ServiceOptions, Hn as SQLiteOutboxTable, Hr as FileStorage, Ht as hasSensitive, I as ResourceActionInput, In as ScheduleRunRecord, Ir as crudEventName, J as ToolConfigWithoutAuthorize, Jn as isAuditTable, Jr as SecretOptions, Jt as SQLiteDefinition, K as ToolAnnotations, Kn as SQLiteAuditTable, Kr as StoredFile, Kt as EnvInput, L as ResourceChild, Ln as ScheduleTable, Lr as crudEventSource, Lt as WireError, M as RateLimits, Mn as isWebhook, Mr as CrudEventOperation, Mt as dashboardKey, N as Resource, Nr as EventCatalog, Nt as dashboardUser, O as Logger, On as ResourceActionInfo, Or as ScheduleRun, Ot as DASHBOARD_IDENTITY_HEADER, P as ResourceActionAccess, Pn as PostgresScheduleTable, Pr as EventRef, Pt as signDashboardIdentity, Q as BrickClientSocket, Qn as PluginFactory, Qr as envSource, Qt as PostgresDatabaseConfig, R as ResourceConfig, Rn as scheduleTable, Rr as isCrudEvent, S as DefaultServiceContext, Sn as ResourcePluginAPI, Sr as RetryDecision, St as Dispatcher, T as ErrorDetails, Tn as ServicePlugin, Tr as WorkflowsOptions, Tt as RateLimit, U as ServiceSchema, Un as outboxTable, Ur as RawDeps, Ut as redact, V as Service, Vn as PostgresOutboxTable, Vr as FileDriver, W as StandardErrorMap, Wn as AuditTable, Wr as S3StorageOptions, Wt as DatabaseDefinition, X as ValidationError, Xn as PluginAppContext, Xr as SecretSource, Xt as isDatabaseHandle, Y as ToolOptions, Yn as recordAudit, Yr as SecretRef, Yt as defineDatabase, Z as ValidationErrorItem, Zn as PluginContext, Zr as defineSecret, Zt as PostgresDatabase, _ as CommandChildren, _n as PluginRouteMethod, _r as EventRecorder, _t as EventsDefinition, a as ActionConfigWithoutAuthorize, an as foreignKey, ar as PluginSetupContext, b as CommandErrors, bn as PluginRoutes, br as EventsWorld, bt as stopAllEvents, c as ActionExecutionError, cn as primaryKey, cr as HostHooks, d as AuditConfig, dn as text, dr as getHostHooks, dt as SocketEmitArgs, ei as overrideSecret, en as BrickSQLiteDatabase, er as PluginInstallOptions, et as BrickSocketConfig, f as BaseActionConfig, fn as uniqueIndex, fr as CrudEventPayload, ft as SocketEmitOptions, g as Command, gn as PluginEndpointContext, gr as EventListener, gt as SocketSchemas, h as ChildChanges, hn as PLUGIN_KIND, hr as EventEnvelope, ht as SocketReplay, i as ActionConfigWithAuthorize, in as createSQLiteDatabase, ir as PluginServiceContext, j as ProxyOptions, jn as WebhookVerifier, jr as defineSchedule, jt as DashboardUser, k as NarrowAuthorizedContext, kn as WebhookConfig, kr as ScheduleWorkflow, kt as DASHBOARD_KEY_ENV, l as ActionSchema, ln as real, lr as PluginHookArgs, lt as SocketBroker, m as CallContext, mn as InstalledPlugin, mr as EventDelivery, mt as SocketPayloads, n as ActionAccessPolicy, ni as resolveSecrets, nn as SQLiteDatabaseConfig, nr as PluginLifecycleContext, o as ActionContext, on as index, or as definePlugin, ot as BrickSocketSchema, p as BaseContext, pn as ContextOf, pr as DispatchOptions, pt as SocketEventArgs, q as ToolConfigWithAuthorize, qn as auditTable, qr as s3, qt as PostgresDefinition, r as ActionConfig, ri as HttpMethod, rn as blob, rr as PluginManifest, rt as BrickSocketHandle, s as ActionErrorDefinition, sn as integer, sr as PluginTableBuilders, st as BrickSocketSender, t as Action, ti as resetSecrets, tn as BunSQLiteDatabase, tr as PluginInstance, u as ArchitectureSchema, un as sqliteTable, ur as PluginHooks, ut as SocketBrokerMessage, v as CommandConfig, vn as PluginRouteRegistrar, vr as EventWorkflow, vt as EventsHub, w as ErrorBuilder, wn as ResourcePluginTypes, wr as WorkflowEvent, wt as ClientIp, x as CommandRow, xn as ResourcePlugin, xr as ListenerFailure, xt as ScheduleState, y as CommandDecision, yn as PluginRouteScope, yr as EventsOptions, yt as ScheduleControl, z as ResourceIdentity, zn as OutboxStatus, zr as CallDeps, zt as Reveal } from "./chunks/types.js";
|
|
2
2
|
import { A as scalarDocsHTML, C as ApiDocument, D as ReferenceOptions, E as ReferenceDocument, M as RouteIR, N as RouteMethod, O as referencePlugin, S as DashboardOptions, T as OpenApiDocument, _ as EndpointContext, a as RequestLoggingOptions, b as EndpointMethod, c as CompiledRoute, d as loadCompiledBrickApp, f as CompiledHandler, g as BrickApp, h as deny, i as CorsOrigin, j as BrickIR, k as registerReferenceRoute, l as bindCompiledApplication, m as HandlerFactory, n as brick, o as requestLoggingPlugin, p as CompiledRoutePlan, r as CorsOptions, s as CompiledApplication, t as CreateServerOptions, u as compileBrickApplication, v as EndpointDefinition, w as DocumentationOptions, x as DashboardAuth, y as EndpointLogger } from "./chunks/server.js";
|
|
3
3
|
import { _ as GLOBAL_SYMBOL, a as BrickClientOptions, c as BrickTransportError, d as InferActionInput, f as InferActionOutput, g as ATTR, h as isBrickTransportError, i as BrickClientAction, l as InferActionErrorCodes, m as isBrickServerError, n as BrickCallOptions, o as BrickServerError, p as createBrickClient, r as BrickClient, s as BrickServices, t as BrickActionCaller, u as InferActionFailure, v as SPAN, y as kebabCase } from "./chunks/client.js";
|
|
4
4
|
import { StepErrorBuilder, defineError, stepErrors, stepFailure } from "./workflow.js";
|
|
5
|
-
import
|
|
5
|
+
import "@opentelemetry/api";
|
|
6
6
|
import { SchemaOptions, Static, TArray, TSchema, TSchema as TSchema$1, TUnsafe } from "@sinclair/typebox";
|
|
7
7
|
import "@sinclair/typebox/compiler";
|
|
8
8
|
import { Column, Table, Table as Table$1, and, asc, desc, eq, getTableColumns, getTableName, gt, gte, ilike, inArray, is, isNotNull, isNull, like, lt, lte, ne, not, notInArray, or, relations, sql } from "drizzle-orm";
|
|
@@ -266,9 +266,11 @@ export declare function useService<const N extends string = string>(service: {
|
|
|
266
266
|
* @param name - Unique name. It is the service's segment of every action route
|
|
267
267
|
* (`/api/<name>/<action>`) and appears in OpenAPI and the dashboard. Defining it
|
|
268
268
|
* again from the same file (a dev reload) replaces it; from another file throws.
|
|
269
|
-
* @param options - `database` (a handle from `defineDatabase`), `deps` (
|
|
270
|
-
*
|
|
269
|
+
* @param options - `database` (a handle from `defineDatabase`), `deps` (the
|
|
270
|
+
* values the service's code uses, such as clients, read as `ctx.deps`),
|
|
271
271
|
* `context` (adds fields such as the signed-in user to every action's `ctx`),
|
|
272
|
+
* `identity` (who the caller is and their tenant, from that `ctx`, for the
|
|
273
|
+
* features that need it),
|
|
272
274
|
* `events` (the event catalog: a payload schema per event name, recorded as
|
|
273
275
|
* `<service>.<name>` and offered as `service.events.<name>`).
|
|
274
276
|
* @returns The service.
|
|
@@ -291,11 +293,10 @@ export declare function useService<const N extends string = string>(service: {
|
|
|
291
293
|
* ctx.db.select().from(pages).limit(input.limit ?? 20),
|
|
292
294
|
* });
|
|
293
295
|
*/
|
|
294
|
-
export declare function defineService<TDb = BunSQLiteDatabase<Record<string, unknown>>, TServiceContext extends Record<string, any> = Record<string, any>, const TEvents extends EventCatalog = {}, const TName extends string = string,
|
|
296
|
+
export declare function defineService<TDb = BunSQLiteDatabase<Record<string, unknown>>, TServiceContext extends Record<string, any> = Record<string, any>, const TEvents extends EventCatalog = {}, const TName extends string = string, TDeps extends object = {}>(name: TName, options?: ServiceOptions<TServiceContext, TDb, TDeps> & {
|
|
295
297
|
events?: TEvents;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
deps: DepsOf<TPorts>;
|
|
298
|
+
}): Service<TDb, [keyof TDeps] extends [never] ? TServiceContext : TServiceContext & {
|
|
299
|
+
deps: CallDeps<TDeps>;
|
|
299
300
|
}, TEvents> & NamedService<TName>;
|
|
300
301
|
/** Keep validators browser-safe and reject schemas whose behavior cannot cross JSON. */
|
|
301
302
|
export declare function serializeSocketSchema(schema: TSchema$1, path?: string): unknown;
|
|
@@ -334,11 +335,18 @@ export declare function setActionAccess(action: object, info: ActionAccessInfo):
|
|
|
334
335
|
* @returns `hasAuthorize`, `hasScope`, and `policy`.
|
|
335
336
|
*/
|
|
336
337
|
export declare function getActionAccess(action: Action | object): ActionAccessInfo;
|
|
338
|
+
/**
|
|
339
|
+
* Say how the audit log records an action a plugin owns: `"inline"` when the
|
|
340
|
+
* plugin writes in its own transaction and records the write there with a
|
|
341
|
+
* host hook, `"none"` when it never writes. Without this, an action that is not
|
|
342
|
+
* a `GET` is recorded after it runs, as a plain action is.
|
|
343
|
+
*/
|
|
344
|
+
export declare function setActionAudit(action: object, mode: "inline" | "none"): void;
|
|
337
345
|
/**
|
|
338
346
|
* The `error` helpers an action receives: one function per error code that
|
|
339
347
|
* throws an `ActionExecutionError` with that code and status. The standard HTTP
|
|
340
348
|
* codes (`BAD_REQUEST`, `UNAUTHORIZED`, `FORBIDDEN`, `NOT_FOUND`, `CONFLICT`,
|
|
341
|
-
* `INTERNAL_SERVER_ERROR`) are always there; the action's own `errors` add to
|
|
349
|
+
* `RATE_LIMITED`, `INTERNAL_SERVER_ERROR`) are always there; the action's own `errors` add to
|
|
342
350
|
* them or replace one.
|
|
343
351
|
*
|
|
344
352
|
* @param errorsDef - The action's `errors`: for each code, its `message` and
|
|
@@ -446,6 +454,118 @@ export declare function actionOwners(action: Action<any, any, any, any>): {
|
|
|
446
454
|
plugin?: string;
|
|
447
455
|
resource?: string;
|
|
448
456
|
};
|
|
457
|
+
type ServiceDeps<S> = S extends Service<any, infer C, any> ? C extends {
|
|
458
|
+
deps: infer D;
|
|
459
|
+
} ? Readonly<RawDeps<D>> : Readonly<Record<string, unknown>> : never;
|
|
460
|
+
/**
|
|
461
|
+
* The deps of a service, for code that has no `ctx`: listeners, schedules and
|
|
462
|
+
* workflow steps. Actions, tools and socket handlers read `ctx.deps` instead.
|
|
463
|
+
*
|
|
464
|
+
* `useDeps(service)` returns that service's deps, typed from it, anywhere.
|
|
465
|
+
* Without an argument it returns what the running listener, schedule or step
|
|
466
|
+
* sees: in one a plugin added, the deps of that install; in the app's own, the
|
|
467
|
+
* deps of all the app's services by name, for code that cannot import the
|
|
468
|
+
* service (one built in a factory). A name two services give different values
|
|
469
|
+
* has no single answer, so reading it throws.
|
|
470
|
+
*
|
|
471
|
+
* @param service - The service whose deps to return.
|
|
472
|
+
* @returns The deps.
|
|
473
|
+
* @throws Without `service`: when called outside a listener, schedule or
|
|
474
|
+
* workflow step of a Brick app, or on reading a name two services give
|
|
475
|
+
* different values.
|
|
476
|
+
* @example
|
|
477
|
+
* async function bookCarrier(orderId: string) {
|
|
478
|
+
* "use step";
|
|
479
|
+
* return useDeps(orders).carrier.book(orderId);
|
|
480
|
+
* }
|
|
481
|
+
*/
|
|
482
|
+
export declare function useDeps<S extends Service<any, any, any>>(service: S): ServiceDeps<S>;
|
|
483
|
+
export declare function useDeps<T = Record<string, unknown>>(): T;
|
|
484
|
+
/** What `increment` returns: the count after this hit, and when the counter expires. */
|
|
485
|
+
interface Counter {
|
|
486
|
+
count: number;
|
|
487
|
+
expiresInMs: number;
|
|
488
|
+
}
|
|
489
|
+
/** What `putIfAbsent` returns: whether this call stored its value, and the value now stored. */
|
|
490
|
+
interface PutIfAbsentResult {
|
|
491
|
+
stored: boolean;
|
|
492
|
+
value: string;
|
|
493
|
+
}
|
|
494
|
+
/** Key-value methods: values are strings, durations are milliseconds. */
|
|
495
|
+
interface KeyValueMethods {
|
|
496
|
+
/** The value, or `null` when the key is missing or expired. */
|
|
497
|
+
get(key: string): Promise<string | null>;
|
|
498
|
+
/** Stores the value; without `ttlMs` it never expires. */
|
|
499
|
+
put(key: string, value: string, ttlMs?: number): Promise<void>;
|
|
500
|
+
/** Stores the value unless the key exists; says whether it did, and the value now stored. Atomic. */
|
|
501
|
+
putIfAbsent(key: string, value: string, ttlMs: number): Promise<PutIfAbsentResult>;
|
|
502
|
+
/** Adds 1 to a counter that expires `ttlMs` after its first hit. Atomic. Throws on a key that holds something other than an integer. */
|
|
503
|
+
increment(key: string, ttlMs: number): Promise<Counter>;
|
|
504
|
+
delete(key: string): Promise<void>;
|
|
505
|
+
/** Closes the connection, if any. The next call opens a new one. */
|
|
506
|
+
close(): Promise<void>;
|
|
507
|
+
}
|
|
508
|
+
/** A driver for key-value storage, such as `redis()` or `memory()`. It sees full keys. */
|
|
509
|
+
interface KeyValueDriver extends KeyValueMethods {
|
|
510
|
+
readonly kind: "key-value";
|
|
511
|
+
/** Deletes the key only while it holds exactly `expected`; says whether it did. Atomic. */
|
|
512
|
+
compareAndDelete(key: string, expected: string): Promise<boolean>;
|
|
513
|
+
}
|
|
514
|
+
/** Every kind of storage driver; `kind` decides the handle `defineStorage` returns. */
|
|
515
|
+
type StorageDriver = KeyValueDriver | FileDriver;
|
|
516
|
+
/** The handle of a key-value storage. App keys live apart from Brick's own. */
|
|
517
|
+
interface KeyValueStorage extends KeyValueMethods {
|
|
518
|
+
readonly kind: "key-value";
|
|
519
|
+
}
|
|
520
|
+
/** The handle `defineStorage` returns for a driver. */
|
|
521
|
+
type StorageOf<D extends StorageDriver> = D extends KeyValueDriver ? KeyValueStorage : D extends FileDriver ? FileStorage : never;
|
|
522
|
+
/** A storage could not be reached, or did not answer in time. Thrown by every call while it is down. A write that rejects with it may still have been applied. */
|
|
523
|
+
export declare class StorageUnavailableError extends Error {
|
|
524
|
+
readonly name = "StorageUnavailableError";
|
|
525
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Declare a storage. The driver decides its kind: `redis()` and `memory()` make
|
|
529
|
+
* key-value storage, `s3()` file storage kept per tenant. Pass it to a service
|
|
530
|
+
* as a dep, and read it as `ctx.deps.<name>`. Nothing connects until the first call.
|
|
531
|
+
*
|
|
532
|
+
* @param options - `driver`: `redis({ url })`, or `memory()` for tests and local
|
|
533
|
+
* development; `s3({ bucket, prefix, local })` for files.
|
|
534
|
+
* @returns The handle. Key-value: `get`, `put`, `putIfAbsent`, `increment`,
|
|
535
|
+
* `delete` and `close`. File: `put`, `url`, `get`, `delete` in the caller's
|
|
536
|
+
* tenant, and `in(tenant)` outside a request.
|
|
537
|
+
* @example
|
|
538
|
+
* export const cache = defineStorage({ driver: redis({ url: process.env.REDIS_URL }) });
|
|
539
|
+
* export const auth = defineService("auth", { deps: { cache } });
|
|
540
|
+
* // in an action
|
|
541
|
+
* await ctx.deps.cache.put(`otp:${input.email}`, code, 5 * 60_000);
|
|
542
|
+
*/
|
|
543
|
+
export declare function defineStorage<D extends StorageDriver>(options: {
|
|
544
|
+
driver: D;
|
|
545
|
+
}): StorageOf<D>;
|
|
546
|
+
/** Options of the `redis()` storage driver. */
|
|
547
|
+
interface RedisStorageOptions {
|
|
548
|
+
/** Defaults to `REDIS_URL`, then `redis://localhost:6379`. */
|
|
549
|
+
url?: string;
|
|
550
|
+
/** Put in front of every key, Brick's own included, so two apps or environments can share one Redis database. */
|
|
551
|
+
prefix?: string;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Key-value storage in Redis, through Bun's built-in client. Connects on first
|
|
555
|
+
* use and reconnects by itself. While Redis is unreachable, calls reject with
|
|
556
|
+
* `StorageUnavailableError`: the first after about a second, the rest at once.
|
|
557
|
+
* A command Redis doesn't answer within a second rejects the same way, and the
|
|
558
|
+
* connection is dropped so the next call opens a fresh one.
|
|
559
|
+
*
|
|
560
|
+
* @param options - `url`: defaults to `REDIS_URL`, then `redis://localhost:6379`.
|
|
561
|
+
* `prefix`: put in front of every key, to share one Redis database between apps.
|
|
562
|
+
*/
|
|
563
|
+
export declare function redis(options?: RedisStorageOptions): KeyValueDriver;
|
|
564
|
+
/**
|
|
565
|
+
* Key-value storage in this process's memory, for tests and local development.
|
|
566
|
+
* Lost on restart and not shared between processes.
|
|
567
|
+
*/
|
|
568
|
+
export declare function memory(): KeyValueDriver;
|
|
449
569
|
type EventOn = EventRef<any> | readonly EventRef<any>[];
|
|
450
570
|
type PayloadOf<O> = O extends EventRef<infer P> ? P : O extends readonly EventRef<infer P>[] ? P : never;
|
|
451
571
|
type ListenerConfig<TPayload, TOn = string | readonly string[], TErrors extends Record<string, ActionErrorDefinition> = {}> = {
|
|
@@ -663,20 +783,27 @@ declare function Json(options?: SchemaOptions): import("@sinclair/typebox").TRec
|
|
|
663
783
|
interface FileOptions {
|
|
664
784
|
/** The largest file accepted, in bytes. Also caps the request body before it is read. */
|
|
665
785
|
maxSize?: number;
|
|
786
|
+
/**
|
|
787
|
+
* The content types accepted, such as `"application/pdf"` or `"image/*"`;
|
|
788
|
+
* `"*\/*"` accepts any. Over HTTP, Bun takes a file's type from the
|
|
789
|
+
* extension of its file name, not from the part's `Content-Type`.
|
|
790
|
+
*/
|
|
791
|
+
accept?: string[];
|
|
666
792
|
description?: string;
|
|
667
793
|
}
|
|
668
|
-
/** A file from a `multipart/form-data` body: a `File` (a `Blob`), at most `maxSize` bytes
|
|
794
|
+
/** A file from a `multipart/form-data` body: a `File` (a `Blob`), at most `maxSize` bytes, of a type in `accept`. */
|
|
669
795
|
declare function File(options?: FileOptions): TUnsafe<File>;
|
|
670
796
|
/** Several files under one form field. */
|
|
671
797
|
declare function Files(options?: FileOptions & {
|
|
672
798
|
minItems?: number;
|
|
673
799
|
maxItems?: number;
|
|
674
800
|
}): TArray<TUnsafe<File>>;
|
|
675
|
-
/** TypeBox's `Type` plus Brick's `Json`, `File` and `
|
|
801
|
+
/** TypeBox's `Type` plus Brick's `Json`, `File`, `Files` and `Sensitive`. */
|
|
676
802
|
export declare const Type: import("@sinclair/typebox").JavaScriptTypeBuilder & {
|
|
677
803
|
Json: typeof Json;
|
|
678
804
|
File: typeof File;
|
|
679
805
|
Files: typeof Files;
|
|
806
|
+
Sensitive: typeof Sensitive;
|
|
680
807
|
};
|
|
681
808
|
/**
|
|
682
809
|
* Check a value against a schema, the way actions check their input and output.
|
|
@@ -684,7 +811,8 @@ export declare const Type: import("@sinclair/typebox").JavaScriptTypeBuilder & {
|
|
|
684
811
|
* @param schema - A TypeBox schema, or `undefined` to accept anything.
|
|
685
812
|
* @param value - The value to check.
|
|
686
813
|
* @returns `{ success: true, data }`, or `{ success: false, errors }` with a
|
|
687
|
-
* `path`, `message
|
|
814
|
+
* `path`, `message` and `type` for each problem. The offending value is
|
|
815
|
+
* left out so a rejected secret is never echoed or logged.
|
|
688
816
|
*/
|
|
689
817
|
export declare function validateWithSchema<T extends TSchema>(schema: T | undefined, value: unknown): {
|
|
690
818
|
success: true;
|
|
@@ -778,6 +906,12 @@ interface McpHandlerOptions {
|
|
|
778
906
|
};
|
|
779
907
|
/** Versions supported by this transport, newest first. */
|
|
780
908
|
protocolVersions?: readonly string[];
|
|
909
|
+
/**
|
|
910
|
+
* Where the client address is, for a tool's `rateLimit: { per: "ip" }`, as
|
|
911
|
+
* `brick({ clientIp })`. Mounted on a Brick app, the handler already uses
|
|
912
|
+
* the app's; this one replaces it.
|
|
913
|
+
*/
|
|
914
|
+
clientIp?: ClientIp;
|
|
781
915
|
}
|
|
782
916
|
/** Stateless MCP JSON-RPC POST handler. Wrap with the app's authentication. */
|
|
783
917
|
export declare function createMcpHandler(options: McpHandlerOptions): (request: Request, ctx?: Partial<ActionContext>) => Promise<Response>;
|
|
@@ -785,5 +919,67 @@ export declare function createMcpHandler(options: McpHandlerOptions): (request:
|
|
|
785
919
|
interface ErrorEnvelope extends WireError {
|
|
786
920
|
requestId: string;
|
|
787
921
|
}
|
|
788
|
-
|
|
789
|
-
|
|
922
|
+
type SecretInput = string | SecretRef<string>;
|
|
923
|
+
/** One secret, or several so a secret can be rotated: any one that verifies accepts. */
|
|
924
|
+
type WebhookSecret = SecretInput | readonly SecretInput[];
|
|
925
|
+
interface HmacSignatureOptions {
|
|
926
|
+
/** The secret the provider signs with; a list accepts any of them, to rotate. */
|
|
927
|
+
secret: WebhookSecret;
|
|
928
|
+
/** The header that carries the signature, such as `x-hub-signature-256`. */
|
|
929
|
+
header: string;
|
|
930
|
+
/** What the header puts before the signature, such as `sha256=`. A header without it is refused. */
|
|
931
|
+
prefix?: string;
|
|
932
|
+
/** Default `"sha256"`. */
|
|
933
|
+
algorithm?: "sha1" | "sha256" | "sha384" | "sha512";
|
|
934
|
+
/** How the signature is written in the header: default `"hex"`. */
|
|
935
|
+
encoding?: "hex" | "base64";
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Verifies an HMAC of the raw body, compared in constant time with a header.
|
|
939
|
+
* It signs the body alone and checks no timestamp. Give the webhook an
|
|
940
|
+
* `eventId`: it stops a replayed capture only when it comes from the signed body.
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* verify: hmacSignature({ secret: githubSecret, header: "x-hub-signature-256", prefix: "sha256=" })
|
|
944
|
+
*/
|
|
945
|
+
export declare function hmacSignature(options: HmacSignatureOptions): WebhookVerifier;
|
|
946
|
+
interface StandardWebhooksOptions {
|
|
947
|
+
/** The `whsec_…` secret; a list accepts any of them, to rotate. */
|
|
948
|
+
secret: WebhookSecret;
|
|
949
|
+
/** How far the timestamp may be from now, either way. Default 5 minutes. */
|
|
950
|
+
toleranceMs?: number;
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Verifies the Standard Webhooks scheme (standardwebhooks.com): a base64
|
|
954
|
+
* HMAC-SHA256 of `id.timestamp.body` in `webhook-signature`, as `v1,<signature>`
|
|
955
|
+
* entries separated by spaces, with the timestamp in `webhook-timestamp`.
|
|
956
|
+
* Svix's `svix-id`, `svix-timestamp` and `svix-signature` are read the same way.
|
|
957
|
+
* The id header is the event id, so the webhook needs no `eventId`.
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* verify: standardWebhooks({ secret: billingSecret })
|
|
961
|
+
*/
|
|
962
|
+
export declare function standardWebhooks(options: StandardWebhooksOptions): WebhookVerifier;
|
|
963
|
+
interface TwilioSignatureOptions {
|
|
964
|
+
/** The account's auth token; a list accepts any of them, to rotate. */
|
|
965
|
+
authToken: WebhookSecret;
|
|
966
|
+
/**
|
|
967
|
+
* The URL Twilio called, exactly as Twilio signed it (the scheme, host,
|
|
968
|
+
* path and query). The server cannot know it behind a proxy, so the app says.
|
|
969
|
+
* Twilio drops the port from the URL it signs for HTTPS voice callbacks.
|
|
970
|
+
*/
|
|
971
|
+
url: string | ((request: WebhookRequest) => string | Promise<string>);
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Verifies Twilio's `X-Twilio-Signature`: a base64 HMAC-SHA1, keyed with the
|
|
975
|
+
* auth token, of the URL followed by the form parameters sorted by name, each
|
|
976
|
+
* as name and value. For a JSON body, Twilio signs the URL alone and puts the
|
|
977
|
+
* body's SHA-256 (hex) in its `bodySHA256` query parameter, which is checked
|
|
978
|
+
* against the body. For a GET, it signs the URL alone,
|
|
979
|
+
* and a request whose query is not the signed URL's is refused. It supplies no event id: give the webhook an `eventId`.
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* verify: twilioSignature({ authToken, url: "https://api.example.com/api/telephony/voice-status" })
|
|
983
|
+
*/
|
|
984
|
+
export declare function twilioSignature(options: TwilioSignatureOptions): WebhookVerifier;
|
|
985
|
+
export { ATTR, Action, type ActionAccessInfo, ActionAccessPolicy, ActionConfig, ActionConfigWithAuthorize, ActionConfigWithoutAuthorize, ActionContext, ActionErrorDefinition, ActionExecutionError, type ActionRoute, ActionSchema, type ApiDocument, ArchitectureSchema, AuditConfig, type AuditTable, BaseActionConfig, BaseContext, type BrickActionCaller, type BrickApp, type BrickCallOptions, type BrickClient, type BrickClientAction, type BrickClientOptions, type BrickIR, BrickSQLiteDatabase, BrickServerError, type BrickServices, type BrickSocketConfig, type BrickSocketHandle, type BrickSocketSchema, type BrickSocketSender, BrickTransportError, type BunSQLiteDatabase, CallContext, type CallDeps, type CallFiles, ChildChanges, type ClientIp, Command, CommandChildren, CommandConfig, CommandDecision, CommandErrors, CommandRow, type CompiledApplication, type CompiledHandler, type CompiledRoute, type CompiledRoutePlan, type CorsOptions, type CorsOrigin, type Counter, type CreateServerOptions, type CrudEventOperation, type CrudEventPayload, DASHBOARD_IDENTITY_HEADER, DASHBOARD_KEY_ENV, type DashboardAuth, type DashboardIdentity, type DashboardOptions, type DashboardUser, DatabaseDefinition, DatabaseHandle, DefaultServiceContext, type DispatchOptions, Dispatcher, type DocumentationOptions, DuplicateNameError, type EndpointContext, type EndpointDefinition, type EndpointLogger, type EndpointMethod, EnvInput, ErrorBuilder, ErrorDetails, type ErrorEnvelope, type EventCatalog, type EventDelivery, type EventEnvelope, type EventListener, type EventRecorder, type EventRef, type EventRefs, type EventWorkflow, type EventsDefinition, type EventsHub, type EventsOptions, type EventsWorld, type FileDriver, type FileStorage, GLOBAL_SYMBOL, type HandlerFactory, type HmacSignatureOptions, type HostHooks, type HttpMethod, type Identity, type InferActionErrorCodes, type InferActionFailure, type InferActionInput, type InferActionOutput, InferTableInsert, InferTableRow, type InstalledPlugin, type KeyValueDriver, type KeyValueStorage, type ListenerFailure, Logger, type McpHandlerOptions, type McpRegistry, type McpRegistryOptions, type McpToolDefinition, NarrowAuthorizedContext, type OpenApiDocument, type OpenApiGeneratorOptions, type OutboxCounts, type OutboxStatus, type OutboxTable, type PluginAppContext, type PluginContext, type PluginEndpointContext, type PluginFactory, type PluginHookArgs, type PluginHooks, type PluginInfo, type PluginInstallOptions, type PluginInstance, type PluginLifecycleContext, type PluginManifest, type PluginRouteMethod, type PluginRouteRegistrar, type PluginRouteScope, type PluginRoutes, type PluginServiceContext, type PluginSetupContext, type PluginTableBuilders, type PostgresAuditTable, PostgresDatabase, PostgresDatabaseConfig, PostgresDefinition, type PostgresOutboxTable, type PostgresScheduleTable, PreparationContribution, ProxyOptions, type PutIfAbsentResult, type RateLimit, RateLimits, type RedisBrokerOptions, type RedisStorageOptions, type ReferenceDocument, type ReferenceOptions, type RequestLoggingOptions, Resource, ResourceActionAccess, ResourceActionConfig, type ResourceActionInfo, ResourceActionInput, ResourceChild, ResourceConfig, ResourceIdentity, type ResourcePlugin, type ResourcePluginAPI, type ResourcePluginContext, type ResourcePluginTypes, ResourceTypeOptions, type RetryDecision, type Reveal, type RouteIR, type RouteMethod, type S3StorageOptions, SPAN, type SQLiteAuditTable, SQLiteDatabaseConfig, SQLiteDefinition, type SQLiteOutboxTable, type SQLiteScheduleTable, type Schedule, type ScheduleConfig, type ScheduleControl, type ScheduleRun, type ScheduleRunRecord, type ScheduleState, type ScheduleTable, type ScheduleWorkflow, type ScheduleWorkflowRun, type ScopedFiles, type SecretOptions, SecretRef, type SecretSource, Service, type ServiceActionCaller, type ServiceClient, type ServiceEvents, ServiceOptions, type ServicePlugin, type ServicePluginContext, type ServiceRegistry, ServiceSchema, type SocketBroker, type SocketBrokerMessage, type SocketEmitArgs, type SocketEmitOptions, type SocketEventArgs, type SocketPayloads, type SocketReplay, type SocketSchemas, StandardErrorMap, type StandardWebhooksOptions, type Static, type StepErrorBuilder, type StorageDriver, type StorageOf, type StoredFile, type TSchema, type Table, Tool, ToolAnnotations, ToolConfigWithAuthorize, ToolConfigWithoutAuthorize, ToolOptions, type TwilioSignatureOptions, Type as t, type UntypedServiceClient, ValidationError, ValidationErrorItem, type WebhookConfig, type WebhookRequest, type WebhookSecret, type WebhookVerifier, type WorkflowEvent, type WorkflowsOptions, and, asc, auditTable, bindCompiledApplication, blob, brick, clientAddress, compileBrickApplication, createBrickClient, createPostgresDatabase, createSQLiteDatabase, crudEventName, crudEventSource, dashboardKey, dashboardUser, defineDatabase, defineError, definePlugin, defineSchedule, defineSecret, deny, desc, envSource, eq, foreignKey, getHostHooks, getTableColumns, getTableName, gt, gte, hasSensitive, ilike, inArray, index, integer, is, isAuditTable, isBrickServerError, isBrickTransportError, isCrudEvent, isDatabaseHandle, isNotNull, isNull, isWebhook, kebabCase, like, listSecrets, loadCompiledBrickApp, lt, lte, ne, not, notInArray, or, outboxTable, overrideSecret, primaryKey, real, recordAudit, redact, referencePlugin, registerReferenceRoute, relations, requestLoggingPlugin, resetSecrets, resolveSecrets, s3, scalarDocsHTML, scheduleTable, signDashboardIdentity, sql, sqliteTable, stepErrors, stepFailure, stopAllEvents, text, uniqueIndex };
|