@palbase/backend 12.0.1 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-XATG7BRC.js → chunk-I72YYSEI.js} +1 -3
- package/dist/chunk-I72YYSEI.js.map +1 -0
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.ts +2 -2
- package/dist/{endpoint-Ck4hER_7.d.cts → endpoint-CAWdScEH.d.cts} +14 -8
- package/dist/{endpoint-Ck4hER_7.d.ts → endpoint-CAWdScEH.d.ts} +14 -8
- package/dist/{index-BJAf1uPC.d.cts → index-CaRM7qe_.d.cts} +1 -1
- package/dist/{index-l7DhBDtn.d.ts → index-EAlQyErf.d.ts} +1 -1
- package/dist/index.cjs +75 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -71
- package/dist/index.d.ts +40 -71
- package/dist/index.js +73 -71
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +0 -6
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +1 -2
- package/dist/test/index.d.ts +1 -2
- package/dist/test/index.js +1 -6
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +2 -4
- package/docs/auth.md +111 -0
- package/docs/background.md +15 -39
- package/docs/config.md +51 -10
- package/docs/database.md +11 -3
- package/docs/events.md +6 -2
- package/docs/llms-full.txt +375 -69
- package/docs/llms.txt +3 -1
- package/docs/migrations.md +30 -0
- package/docs/resources.md +12 -9
- package/docs/schema.md +31 -3
- package/docs/services.md +0 -9
- package/package.json +4 -2
- package/dist/chunk-XATG7BRC.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CacheClient, b as PalbaseDocsClient, c as PalbaseFlagsClient, L as Logger, d as PalbaseNotificationsClient,
|
|
2
|
-
export { g as AuthConfig, B as BadRequest, h as ClientInfo, i as Conflict, j as DBOps, E as ErrorDef, k as ErrorMap, l as ErrorThrowers, F as FileContext, m as Forbidden, n as HttpMethod, M as Materialized, o as Middleware, p as MiddlewareContext, q as MiddlewareHandler, N as NotFound, P as PBRequest, r as PalError, s as PalbaseAnalyticsClient, t as PalbaseAnalyticsManagementNamespace, u as PalbaseAnalyticsProperties, v as PalbaseAnalyticsQueryNamespace, w as PalbaseAttestAndroidParams, x as PalbaseAttestAndroidResult, y as PalbaseAttestiOSParams, z as PalbaseAttestiOSResult, G as PalbaseAuthClient, I as PalbaseBatchOverrideOperation, J as PalbaseBatchSetOverridesResult, K as PalbaseBindDeviceParams, O as PalbaseBucketClient,
|
|
1
|
+
import { C as CacheClient, b as PalbaseDocsClient, c as PalbaseFlagsClient, L as Logger, d as PalbaseNotificationsClient, e as PalbaseRealtimeClient, D as DBClient, f as PalbaseStorageClient, A as AuthSpec, R as RateLimitConfig, H as HttpError } from './endpoint-CAWdScEH.cjs';
|
|
2
|
+
export { g as AuthConfig, B as BadRequest, h as ClientInfo, i as Conflict, j as DBOps, E as ErrorDef, k as ErrorMap, l as ErrorThrowers, F as FileContext, m as Forbidden, n as HttpMethod, M as Materialized, o as Middleware, p as MiddlewareContext, q as MiddlewareHandler, N as NotFound, P as PBRequest, r as PalError, s as PalbaseAnalyticsClient, t as PalbaseAnalyticsManagementNamespace, u as PalbaseAnalyticsProperties, v as PalbaseAnalyticsQueryNamespace, w as PalbaseAttestAndroidParams, x as PalbaseAttestAndroidResult, y as PalbaseAttestiOSParams, z as PalbaseAttestiOSResult, G as PalbaseAuthClient, I as PalbaseBatchOverrideOperation, J as PalbaseBatchSetOverridesResult, K as PalbaseBindDeviceParams, O as PalbaseBucketClient, Q as PalbaseClearAllOverridesResult, S as PalbaseClearOverrideResult, T as PalbaseCohortQueryInput, V as PalbaseCohortResult, W as PalbaseCollectionRef, X as PalbaseCountQueryInput, Y as PalbaseCountResult, Z as PalbaseCreateLinkParams, _ as PalbaseDeviceInfo, $ as PalbaseDeviceTokenView, a0 as PalbaseDocumentRef, a1 as PalbaseDocumentSnapshot, a2 as PalbaseEmailClient, a3 as PalbaseEmailSendParams, a4 as PalbaseEmailSendResponse, a5 as PalbaseEventNamesResult, a6 as PalbaseEventsQueryInput, a7 as PalbaseEventsResult, a8 as PalbaseFileObject, a9 as PalbaseFlag, aa as PalbaseFlagContext, ab as PalbaseFlagSource, ac as PalbaseFlagValue, ad as PalbaseFlagVariant, ae as PalbaseFlagsServiceClient, af as PalbaseFunctionsClient, ag as PalbaseFunnelQueryInput, ah as PalbaseFunnelResult, ai as PalbaseIdentifyTraits, aj as PalbaseInboxClient, ak as PalbaseInboxListOptions, al as PalbaseInboxListResult, am as PalbaseInboxMessage, an as PalbaseInboxSendParams, ao as PalbaseInboxSendResponse, ap as PalbaseInitialLink, aq as PalbaseInvokeOptions, ar as PalbaseLink, as as PalbaseLinkAnalytics, at as PalbaseLinkDetails, au as PalbaseLinksClient, av as PalbaseListLinksOptions, aw as PalbaseListLinksResult, ax as PalbaseListOptions, ay as PalbaseMatchParams, az as PalbaseMultiChannelResponse, aA as PalbaseOverviewResult, aB as PalbasePreferences, aC as PalbasePreferencesClient, aD as PalbasePublicUrlResponse, aE as PalbasePushClient, aF as PalbasePushSendParams, aG as PalbasePushSendResponse, aH as PalbaseQrCodeOptions, aI as PalbaseQuerySnapshot, aJ as PalbaseRegisterDeviceParams, aK as PalbaseResult, aL as PalbaseRetentionQueryInput, aM as PalbaseRetentionResult, aN as PalbaseSession, aO as PalbaseSetOverrideResult, aP as PalbaseSetOverridesResult, aQ as PalbaseSignedUrlResponse, aR as PalbaseSmsClient, aS as PalbaseSmsSendParams, aT as PalbaseSmsSendResponse, aU as PalbaseTransformOptions, aV as PalbaseUpdateLinkParams, aW as PalbaseUploadOptions, aX as PalbaseUser, aY as PalbaseUserDetailResult, aZ as PalbaseUsersQueryInput, a_ as PalbaseUsersResult, a$ as PalbaseVerifyRequestSignatureParams, b0 as PalbaseWhereOperator, b1 as Ref, b2 as TooManyRequests, b3 as TxColumnExpr, b4 as TxInsertShape, b5 as TxInsertValue, b6 as TxNow, b7 as TxPlanBody, b8 as TxPlanError, b9 as TxPlanHandle, ba as TxPlanOpResult, bb as TxPlanRejection, bc as TxPlanResponse, bd as TxRefError, be as TxRow, bf as TxRows, bg as TxSelectOptions, bh as TxSetShape, bi as TxSetValue, bj as TxTable, bk as TxWhere, bl as TxWireExpr, bm as TxWireGuard, bn as TxWireOp, bo as TxWireRef, bp as TxWireValue, bq as Unauthorized, U as UserT, br as VerifiedDevice, bs as dec, bt as defineMiddleware, bu as inc, bv as now } from './endpoint-CAWdScEH.cjs';
|
|
3
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
-
import { E as EnvTypedDatabase, S as SchemaDef } from './index-
|
|
5
|
-
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, f as EnvTables, g as EnvTypedTable, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, h as PalbaseExtension, i as PolicyBuilder, j as PolicyCommand, k as PolicyDef, l as PolicyMode, R as RawConstraintDef, m as RowShape, n as SchemaInput, T as TableDef, o as TableInput, p as TxPlan, q as TxTables, r as TypedDB, s as TypedTable, t as TypedTx, u as bigint, v as boolean, w as defineSchema, x as enumType, y as integer, z as isPalbaseExtension, A as jsonb, B as makeTypedDB, D as numeric, F as policy, G as raw, H as text, J as timestamp, K as uuid } from './index-
|
|
4
|
+
import { E as EnvTypedDatabase, S as SchemaDef } from './index-CaRM7qe_.cjs';
|
|
5
|
+
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, f as EnvTables, g as EnvTypedTable, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, h as PalbaseExtension, i as PolicyBuilder, j as PolicyCommand, k as PolicyDef, l as PolicyMode, R as RawConstraintDef, m as RowShape, n as SchemaInput, T as TableDef, o as TableInput, p as TxPlan, q as TxTables, r as TypedDB, s as TypedTable, t as TypedTx, u as bigint, v as boolean, w as defineSchema, x as enumType, y as integer, z as isPalbaseExtension, A as jsonb, B as makeTypedDB, D as numeric, F as policy, G as raw, H as text, J as timestamp, K as uuid } from './index-CaRM7qe_.cjs';
|
|
6
6
|
import { EntitlementKey, LimitKey } from './purchases/keys.cjs';
|
|
7
7
|
import { TableTypes, Tables } from './db/env.cjs';
|
|
8
8
|
import { ZodTypeAny, z } from 'zod';
|
|
@@ -117,7 +117,6 @@ interface RuntimeServices {
|
|
|
117
117
|
Documents: PalbaseDocsClient;
|
|
118
118
|
Storage: PalbaseStorageClient;
|
|
119
119
|
Cache: CacheClient;
|
|
120
|
-
Queue: QueueClient;
|
|
121
120
|
Log: Logger;
|
|
122
121
|
Notifications: PalbaseNotificationsClient;
|
|
123
122
|
Flags: PalbaseFlagsClient;
|
|
@@ -199,8 +198,6 @@ declare const Documents: PalbaseDocsClient;
|
|
|
199
198
|
declare const Storage: PalbaseStorageClient;
|
|
200
199
|
/** JSON-typed cache (get/set/incr/getOrSet). */
|
|
201
200
|
declare const Cache: CacheClient;
|
|
202
|
-
/** Background job queue. */
|
|
203
|
-
declare const Queue: QueueClient;
|
|
204
201
|
/** Structured logger. */
|
|
205
202
|
declare const Log: Logger;
|
|
206
203
|
/** Push / email / SMS / in-app notifications. */
|
|
@@ -504,18 +501,20 @@ declare function defineStorage(input: StorageInput): StorageConfig;
|
|
|
504
501
|
/**
|
|
505
502
|
* egress.ts — the tenant outbound-HTTP allowlist config-as-code DSL.
|
|
506
503
|
*
|
|
507
|
-
* `defineEgress({ hosts })` declares the external hosts a backend may
|
|
508
|
-
* config/egress.ts default-exports
|
|
509
|
-
* (SchemaExtractor.EvaluateConfigFile →
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
504
|
+
* `defineEgress({ hosts, timeoutMs })` declares the external hosts a backend may
|
|
505
|
+
* fetch(), and how long a single call may take. config/egress.ts default-exports
|
|
506
|
+
* it; the deploy evals it to JSON (SchemaExtractor.EvaluateConfigFile →
|
|
507
|
+
* config_extract.js) and bakes both into the artifact manifest → the isolate
|
|
508
|
+
* loader → Tenant.egressAllow / Tenant.egressTimeoutMs. The tenantFetch
|
|
509
|
+
* capability rejects any host NOT on the list. NO config/egress.ts (or an empty
|
|
510
|
+
* list) ⇒ the backend has NO outbound network — fail-closed.
|
|
513
511
|
*
|
|
514
512
|
* @example
|
|
515
513
|
* // config/egress.ts
|
|
516
514
|
* import { defineEgress } from "@palbase/backend";
|
|
517
515
|
* export default defineEgress({
|
|
518
|
-
* hosts: ["api.
|
|
516
|
+
* hosts: ["api.openai.com"],
|
|
517
|
+
* timeoutMs: 90_000, // a slow LLM call; default 30_000
|
|
519
518
|
* });
|
|
520
519
|
*
|
|
521
520
|
* Each host is a bare hostname (no scheme/port/path/wildcard). A leading dot,
|
|
@@ -523,18 +522,43 @@ declare function defineStorage(input: StorageInput): StorageConfig;
|
|
|
523
522
|
* https-only on :443; the deploy REJECTS a malformed / IP-literal / internal host
|
|
524
523
|
* (fail-closed — a security allowlist is never best-effort).
|
|
525
524
|
*
|
|
526
|
-
*
|
|
525
|
+
* `timeoutMs` is a CEILING, not a grant: the call still ends when the INVOCATION
|
|
526
|
+
* ends. A job may run up to its own `@Job({ timeout })` (max 300s), while a
|
|
527
|
+
* request is additionally bounded by the gateway. Setting 300_000 on a route
|
|
528
|
+
* whose request dies earlier buys nothing — size it to the caller.
|
|
529
|
+
*
|
|
530
|
+
* Response bodies are BUFFERED whole (5 MB cap) before your fetch() resolves, so
|
|
531
|
+
* a streaming/SSE upstream gives you no partial output and no earlier
|
|
532
|
+
* first-byte: the entire stream must complete inside `timeoutMs`.
|
|
533
|
+
*
|
|
534
|
+
* Emits: { __config: "egress", hosts: [...], timeoutMs?: number }
|
|
527
535
|
*/
|
|
528
536
|
/** The discriminant written under `__config` so the deploy eval knows the kind. */
|
|
529
537
|
declare const EGRESS_CONFIG_KIND: "egress";
|
|
538
|
+
/**
|
|
539
|
+
* Bounds on `timeoutMs`, duplicated (deliberately) in the deploy's
|
|
540
|
+
* ParseEgressConfig. This copy shapes the authoring error; that one is
|
|
541
|
+
* authoritative and fail-closed. They must agree — a value this accepts and the
|
|
542
|
+
* deploy rejects is a broken deploy the author cannot see coming.
|
|
543
|
+
*/
|
|
544
|
+
declare const EGRESS_TIMEOUT_MIN_MS = 1000;
|
|
545
|
+
declare const EGRESS_TIMEOUT_MAX_MS = 300000;
|
|
546
|
+
/** Applied when `timeoutMs` is omitted. Also spelled in the isolate capability. */
|
|
547
|
+
declare const EGRESS_TIMEOUT_DEFAULT_MS = 30000;
|
|
530
548
|
/** The author-facing input to defineEgress. */
|
|
531
549
|
interface EgressInput {
|
|
532
550
|
hosts: string[];
|
|
551
|
+
/**
|
|
552
|
+
* Per-call ceiling for an outbound fetch, in milliseconds.
|
|
553
|
+
* 1_000..300_000; omitted ⇒ 30_000.
|
|
554
|
+
*/
|
|
555
|
+
timeoutMs?: number;
|
|
533
556
|
}
|
|
534
557
|
/** The evaluated config/egress.ts default export (what the deploy reads). */
|
|
535
558
|
interface EgressConfig {
|
|
536
559
|
__config: typeof EGRESS_CONFIG_KIND;
|
|
537
560
|
hosts: string[];
|
|
561
|
+
timeoutMs?: number;
|
|
538
562
|
}
|
|
539
563
|
/**
|
|
540
564
|
* Declare the backend's outbound-HTTP allowlist. Client-side this only shapes +
|
|
@@ -1396,61 +1420,6 @@ interface DefinedError {
|
|
|
1396
1420
|
declare function defineError<S extends ZodTypeAny>(code: string, status: number, dataSchema: S): DefinedErrorWithData<S>;
|
|
1397
1421
|
declare function defineError(code: string, status: number): DefinedError;
|
|
1398
1422
|
|
|
1399
|
-
/** Non-service, per-invocation data for background worker handlers.
|
|
1400
|
-
* Services (Database, Log, …) are imported as singletons, not passed here. */
|
|
1401
|
-
interface WorkerMeta {
|
|
1402
|
-
/** Environment-scoped env vars. */
|
|
1403
|
-
env: Record<string, string>;
|
|
1404
|
-
/** The user that enqueued the job, if any (background jobs are usually system-initiated). */
|
|
1405
|
-
user: User$1 | null;
|
|
1406
|
-
/** Per-invocation id for correlation. */
|
|
1407
|
-
requestId: string;
|
|
1408
|
-
/** The globally unique Environment runtime identifier. */
|
|
1409
|
-
environmentId: string;
|
|
1410
|
-
}
|
|
1411
|
-
/** Backoff strategy for worker retries. */
|
|
1412
|
-
type BackoffStrategy = "exponential" | "linear" | "fixed";
|
|
1413
|
-
/** Configuration for a background worker. */
|
|
1414
|
-
interface WorkerConfig<TPayload = unknown> {
|
|
1415
|
-
/** Worker name — must be unique across the project. */
|
|
1416
|
-
name: string;
|
|
1417
|
-
/** Maximum number of retries before sending to dead letter queue. Defaults to 3. */
|
|
1418
|
-
retry?: number;
|
|
1419
|
-
/** Execution timeout in seconds. Defaults to 30. */
|
|
1420
|
-
timeout?: number;
|
|
1421
|
-
/** Backoff strategy between retries. Defaults to "exponential". */
|
|
1422
|
-
backoff?: BackoffStrategy;
|
|
1423
|
-
/** Handler function that processes the job payload. */
|
|
1424
|
-
handler: (payload: TPayload, meta: WorkerMeta) => Promise<void>;
|
|
1425
|
-
}
|
|
1426
|
-
/** Resolved worker configuration with defaults applied. */
|
|
1427
|
-
interface ResolvedWorkerConfig<TPayload = unknown> {
|
|
1428
|
-
name: string;
|
|
1429
|
-
retry: number;
|
|
1430
|
-
timeout: number;
|
|
1431
|
-
backoff: BackoffStrategy;
|
|
1432
|
-
handler: (payload: TPayload, meta: WorkerMeta) => Promise<void>;
|
|
1433
|
-
}
|
|
1434
|
-
/**
|
|
1435
|
-
* Define a background worker that processes jobs from the queue.
|
|
1436
|
-
*
|
|
1437
|
-
* Workers are placed in the `workers/` directory and auto-discovered at deploy time.
|
|
1438
|
-
*
|
|
1439
|
-
* @example
|
|
1440
|
-
* ```ts
|
|
1441
|
-
* export default defineWorker({
|
|
1442
|
-
* name: "send-email",
|
|
1443
|
-
* retry: 5,
|
|
1444
|
-
* timeout: 60,
|
|
1445
|
-
* backoff: "exponential",
|
|
1446
|
-
* handler: async (payload: { to: string; subject: string }, meta) => {
|
|
1447
|
-
* await sendEmail(payload.to, payload.subject);
|
|
1448
|
-
* },
|
|
1449
|
-
* });
|
|
1450
|
-
* ```
|
|
1451
|
-
*/
|
|
1452
|
-
declare function defineWorker<TPayload = unknown>(config: WorkerConfig<TPayload>): ResolvedWorkerConfig<TPayload>;
|
|
1453
|
-
|
|
1454
1423
|
/** Non-service, per-invocation data for job handlers.
|
|
1455
1424
|
* Services (Database, Log, …) are imported as singletons, not passed here. */
|
|
1456
1425
|
interface JobMeta {
|
|
@@ -1746,4 +1715,4 @@ declare const documents: {
|
|
|
1746
1715
|
onDocumentDeleted(handler: HookHandler<DocumentDeletedEvent>): ResolvedHook<DocumentDeletedEvent>;
|
|
1747
1716
|
};
|
|
1748
1717
|
|
|
1749
|
-
export { type AcsOptions, type ApnsOptions,
|
|
1718
|
+
export { type AcsOptions, type ApnsOptions, Body, type BucketDef, type BucketOptions, Cache, CacheClient, Client, Controller, type ControllerOptions, DBClient, Database, type DefinedError, type DefinedErrorWithData, Delete, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentUpdatedEvent, Documents, EGRESS_CONFIG_KIND, EGRESS_TIMEOUT_DEFAULT_MS, EGRESS_TIMEOUT_MAX_MS, EGRESS_TIMEOUT_MIN_MS, type EgressConfig, type EgressInput, EntitlementKey, EnvTypedDatabase, FLAGS_CONFIG_KIND, type FcmOptions, type FileDeletedEvent, type FileUploadedEvent, type FlagDef, type FlagJsonObject, type FlagJsonValue, type FlagOptions, type FlagType, type FlagValue, Flags, type FlagsConfig, type FlagsInput, Get, Headers, type HookHandler, type HookMeta, HttpError, type HttpMethodUpper, Job, type JobMeta, type JobOptions, LimitKey, type LimitState, Log, Logger, NOTIFICATIONS_CONFIG_KIND, Notifications, type NotificationsConfig, type NotificationsInput, On, OptionalUser, type OwnedTablesOf, PROVIDER_CATALOG, PalbaseDocsClient, PalbaseFlagsClient, PalbaseNotificationsClient, PalbaseRealtimeClient, PalbaseStorageClient, Param, type ParamKind, type ParamMeta, type PasswordResetEvent, Patch, Post, type ProviderCatalogEntry, type ProviderDef, type ProviderName, type ProviderOptions, Purchases, type PurchasesManifest, type PurchasesService, Put, Query, QueryParams, RESERVED_SECRET_PREFIX, RateLimitConfig, Realtime, type RegisteredError, Req, RequestId, type RequestStore, RequireEntitlement, type ResolvedHook, type ResolvedJob, type ResolvedWebhook, Resource, type ResourceEnv, type RouteMeta, type RouteOptions, type RuntimeServices, STORAGE_CONFIG_KIND, SchemaDef, type Seed, type SeedFor, type SeedJson, type SeedRowFor, type SendgridOptions, type SesOptions, type SignInEvent, type SignOutEvent, type SignatureSpec, type SmtpOptions, Spend, type SpendMeta, type SpendOptions, Storage, type StorageConfig, type StorageInput, type StoreEnv, TEST_USERS_CONFIG_KIND, type TableGraph, TableTypes, Tables, type TestUserDef, type TestUserOptions, type TestUsersConfig, type TestUsersInput, type ThrowDescriptor, TraceId, type TwilioOptions, Upload, type UploadConfig, UploadedObject, User, type UserCreatedEvent, Webhook, type WebhookEventHandler, type WebhookMeta, type WebhookOptions, type WebhookProvider, type WebhookRequest, __getRuntime, __registerResource, __requestALS, __runResourceBoot, __runWithRuntime, __setRuntime, __shutdownResources, auth, bucket, buildProvider, defineEgress, defineError, defineFlags, defineNotifications, defineStorage, defineTestUsers, documents, entitlementFor, flag, getErrorRegistry, getJobConfig, getRoutes, getWebhookConfig, makeEnvDts, makePurchasesDts, parseFileSizeLimit, recordThrows, reservedSecretKey, spendFor, storage, testUser, validateUploadAgainstStorage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CacheClient, b as PalbaseDocsClient, c as PalbaseFlagsClient, L as Logger, d as PalbaseNotificationsClient,
|
|
2
|
-
export { g as AuthConfig, B as BadRequest, h as ClientInfo, i as Conflict, j as DBOps, E as ErrorDef, k as ErrorMap, l as ErrorThrowers, F as FileContext, m as Forbidden, n as HttpMethod, M as Materialized, o as Middleware, p as MiddlewareContext, q as MiddlewareHandler, N as NotFound, P as PBRequest, r as PalError, s as PalbaseAnalyticsClient, t as PalbaseAnalyticsManagementNamespace, u as PalbaseAnalyticsProperties, v as PalbaseAnalyticsQueryNamespace, w as PalbaseAttestAndroidParams, x as PalbaseAttestAndroidResult, y as PalbaseAttestiOSParams, z as PalbaseAttestiOSResult, G as PalbaseAuthClient, I as PalbaseBatchOverrideOperation, J as PalbaseBatchSetOverridesResult, K as PalbaseBindDeviceParams, O as PalbaseBucketClient,
|
|
1
|
+
import { C as CacheClient, b as PalbaseDocsClient, c as PalbaseFlagsClient, L as Logger, d as PalbaseNotificationsClient, e as PalbaseRealtimeClient, D as DBClient, f as PalbaseStorageClient, A as AuthSpec, R as RateLimitConfig, H as HttpError } from './endpoint-CAWdScEH.js';
|
|
2
|
+
export { g as AuthConfig, B as BadRequest, h as ClientInfo, i as Conflict, j as DBOps, E as ErrorDef, k as ErrorMap, l as ErrorThrowers, F as FileContext, m as Forbidden, n as HttpMethod, M as Materialized, o as Middleware, p as MiddlewareContext, q as MiddlewareHandler, N as NotFound, P as PBRequest, r as PalError, s as PalbaseAnalyticsClient, t as PalbaseAnalyticsManagementNamespace, u as PalbaseAnalyticsProperties, v as PalbaseAnalyticsQueryNamespace, w as PalbaseAttestAndroidParams, x as PalbaseAttestAndroidResult, y as PalbaseAttestiOSParams, z as PalbaseAttestiOSResult, G as PalbaseAuthClient, I as PalbaseBatchOverrideOperation, J as PalbaseBatchSetOverridesResult, K as PalbaseBindDeviceParams, O as PalbaseBucketClient, Q as PalbaseClearAllOverridesResult, S as PalbaseClearOverrideResult, T as PalbaseCohortQueryInput, V as PalbaseCohortResult, W as PalbaseCollectionRef, X as PalbaseCountQueryInput, Y as PalbaseCountResult, Z as PalbaseCreateLinkParams, _ as PalbaseDeviceInfo, $ as PalbaseDeviceTokenView, a0 as PalbaseDocumentRef, a1 as PalbaseDocumentSnapshot, a2 as PalbaseEmailClient, a3 as PalbaseEmailSendParams, a4 as PalbaseEmailSendResponse, a5 as PalbaseEventNamesResult, a6 as PalbaseEventsQueryInput, a7 as PalbaseEventsResult, a8 as PalbaseFileObject, a9 as PalbaseFlag, aa as PalbaseFlagContext, ab as PalbaseFlagSource, ac as PalbaseFlagValue, ad as PalbaseFlagVariant, ae as PalbaseFlagsServiceClient, af as PalbaseFunctionsClient, ag as PalbaseFunnelQueryInput, ah as PalbaseFunnelResult, ai as PalbaseIdentifyTraits, aj as PalbaseInboxClient, ak as PalbaseInboxListOptions, al as PalbaseInboxListResult, am as PalbaseInboxMessage, an as PalbaseInboxSendParams, ao as PalbaseInboxSendResponse, ap as PalbaseInitialLink, aq as PalbaseInvokeOptions, ar as PalbaseLink, as as PalbaseLinkAnalytics, at as PalbaseLinkDetails, au as PalbaseLinksClient, av as PalbaseListLinksOptions, aw as PalbaseListLinksResult, ax as PalbaseListOptions, ay as PalbaseMatchParams, az as PalbaseMultiChannelResponse, aA as PalbaseOverviewResult, aB as PalbasePreferences, aC as PalbasePreferencesClient, aD as PalbasePublicUrlResponse, aE as PalbasePushClient, aF as PalbasePushSendParams, aG as PalbasePushSendResponse, aH as PalbaseQrCodeOptions, aI as PalbaseQuerySnapshot, aJ as PalbaseRegisterDeviceParams, aK as PalbaseResult, aL as PalbaseRetentionQueryInput, aM as PalbaseRetentionResult, aN as PalbaseSession, aO as PalbaseSetOverrideResult, aP as PalbaseSetOverridesResult, aQ as PalbaseSignedUrlResponse, aR as PalbaseSmsClient, aS as PalbaseSmsSendParams, aT as PalbaseSmsSendResponse, aU as PalbaseTransformOptions, aV as PalbaseUpdateLinkParams, aW as PalbaseUploadOptions, aX as PalbaseUser, aY as PalbaseUserDetailResult, aZ as PalbaseUsersQueryInput, a_ as PalbaseUsersResult, a$ as PalbaseVerifyRequestSignatureParams, b0 as PalbaseWhereOperator, b1 as Ref, b2 as TooManyRequests, b3 as TxColumnExpr, b4 as TxInsertShape, b5 as TxInsertValue, b6 as TxNow, b7 as TxPlanBody, b8 as TxPlanError, b9 as TxPlanHandle, ba as TxPlanOpResult, bb as TxPlanRejection, bc as TxPlanResponse, bd as TxRefError, be as TxRow, bf as TxRows, bg as TxSelectOptions, bh as TxSetShape, bi as TxSetValue, bj as TxTable, bk as TxWhere, bl as TxWireExpr, bm as TxWireGuard, bn as TxWireOp, bo as TxWireRef, bp as TxWireValue, bq as Unauthorized, U as UserT, br as VerifiedDevice, bs as dec, bt as defineMiddleware, bu as inc, bv as now } from './endpoint-CAWdScEH.js';
|
|
3
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
-
import { E as EnvTypedDatabase, S as SchemaDef } from './index-
|
|
5
|
-
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, f as EnvTables, g as EnvTypedTable, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, h as PalbaseExtension, i as PolicyBuilder, j as PolicyCommand, k as PolicyDef, l as PolicyMode, R as RawConstraintDef, m as RowShape, n as SchemaInput, T as TableDef, o as TableInput, p as TxPlan, q as TxTables, r as TypedDB, s as TypedTable, t as TypedTx, u as bigint, v as boolean, w as defineSchema, x as enumType, y as integer, z as isPalbaseExtension, A as jsonb, B as makeTypedDB, D as numeric, F as policy, G as raw, H as text, J as timestamp, K as uuid } from './index-
|
|
4
|
+
import { E as EnvTypedDatabase, S as SchemaDef } from './index-EAlQyErf.js';
|
|
5
|
+
export { C as ColumnBuilder, a as ColumnDef, b as ColumnMap, c as ColumnType, d as EXTENSION_DEPENDENCIES, e as EnvServiceDatabase, f as EnvTables, g as EnvTypedTable, I as InsertShape, O as OnDeleteAction, P as PALBASE_EXTENSIONS, h as PalbaseExtension, i as PolicyBuilder, j as PolicyCommand, k as PolicyDef, l as PolicyMode, R as RawConstraintDef, m as RowShape, n as SchemaInput, T as TableDef, o as TableInput, p as TxPlan, q as TxTables, r as TypedDB, s as TypedTable, t as TypedTx, u as bigint, v as boolean, w as defineSchema, x as enumType, y as integer, z as isPalbaseExtension, A as jsonb, B as makeTypedDB, D as numeric, F as policy, G as raw, H as text, J as timestamp, K as uuid } from './index-EAlQyErf.js';
|
|
6
6
|
import { EntitlementKey, LimitKey } from './purchases/keys.js';
|
|
7
7
|
import { TableTypes, Tables } from './db/env.js';
|
|
8
8
|
import { ZodTypeAny, z } from 'zod';
|
|
@@ -117,7 +117,6 @@ interface RuntimeServices {
|
|
|
117
117
|
Documents: PalbaseDocsClient;
|
|
118
118
|
Storage: PalbaseStorageClient;
|
|
119
119
|
Cache: CacheClient;
|
|
120
|
-
Queue: QueueClient;
|
|
121
120
|
Log: Logger;
|
|
122
121
|
Notifications: PalbaseNotificationsClient;
|
|
123
122
|
Flags: PalbaseFlagsClient;
|
|
@@ -199,8 +198,6 @@ declare const Documents: PalbaseDocsClient;
|
|
|
199
198
|
declare const Storage: PalbaseStorageClient;
|
|
200
199
|
/** JSON-typed cache (get/set/incr/getOrSet). */
|
|
201
200
|
declare const Cache: CacheClient;
|
|
202
|
-
/** Background job queue. */
|
|
203
|
-
declare const Queue: QueueClient;
|
|
204
201
|
/** Structured logger. */
|
|
205
202
|
declare const Log: Logger;
|
|
206
203
|
/** Push / email / SMS / in-app notifications. */
|
|
@@ -504,18 +501,20 @@ declare function defineStorage(input: StorageInput): StorageConfig;
|
|
|
504
501
|
/**
|
|
505
502
|
* egress.ts — the tenant outbound-HTTP allowlist config-as-code DSL.
|
|
506
503
|
*
|
|
507
|
-
* `defineEgress({ hosts })` declares the external hosts a backend may
|
|
508
|
-
* config/egress.ts default-exports
|
|
509
|
-
* (SchemaExtractor.EvaluateConfigFile →
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
504
|
+
* `defineEgress({ hosts, timeoutMs })` declares the external hosts a backend may
|
|
505
|
+
* fetch(), and how long a single call may take. config/egress.ts default-exports
|
|
506
|
+
* it; the deploy evals it to JSON (SchemaExtractor.EvaluateConfigFile →
|
|
507
|
+
* config_extract.js) and bakes both into the artifact manifest → the isolate
|
|
508
|
+
* loader → Tenant.egressAllow / Tenant.egressTimeoutMs. The tenantFetch
|
|
509
|
+
* capability rejects any host NOT on the list. NO config/egress.ts (or an empty
|
|
510
|
+
* list) ⇒ the backend has NO outbound network — fail-closed.
|
|
513
511
|
*
|
|
514
512
|
* @example
|
|
515
513
|
* // config/egress.ts
|
|
516
514
|
* import { defineEgress } from "@palbase/backend";
|
|
517
515
|
* export default defineEgress({
|
|
518
|
-
* hosts: ["api.
|
|
516
|
+
* hosts: ["api.openai.com"],
|
|
517
|
+
* timeoutMs: 90_000, // a slow LLM call; default 30_000
|
|
519
518
|
* });
|
|
520
519
|
*
|
|
521
520
|
* Each host is a bare hostname (no scheme/port/path/wildcard). A leading dot,
|
|
@@ -523,18 +522,43 @@ declare function defineStorage(input: StorageInput): StorageConfig;
|
|
|
523
522
|
* https-only on :443; the deploy REJECTS a malformed / IP-literal / internal host
|
|
524
523
|
* (fail-closed — a security allowlist is never best-effort).
|
|
525
524
|
*
|
|
526
|
-
*
|
|
525
|
+
* `timeoutMs` is a CEILING, not a grant: the call still ends when the INVOCATION
|
|
526
|
+
* ends. A job may run up to its own `@Job({ timeout })` (max 300s), while a
|
|
527
|
+
* request is additionally bounded by the gateway. Setting 300_000 on a route
|
|
528
|
+
* whose request dies earlier buys nothing — size it to the caller.
|
|
529
|
+
*
|
|
530
|
+
* Response bodies are BUFFERED whole (5 MB cap) before your fetch() resolves, so
|
|
531
|
+
* a streaming/SSE upstream gives you no partial output and no earlier
|
|
532
|
+
* first-byte: the entire stream must complete inside `timeoutMs`.
|
|
533
|
+
*
|
|
534
|
+
* Emits: { __config: "egress", hosts: [...], timeoutMs?: number }
|
|
527
535
|
*/
|
|
528
536
|
/** The discriminant written under `__config` so the deploy eval knows the kind. */
|
|
529
537
|
declare const EGRESS_CONFIG_KIND: "egress";
|
|
538
|
+
/**
|
|
539
|
+
* Bounds on `timeoutMs`, duplicated (deliberately) in the deploy's
|
|
540
|
+
* ParseEgressConfig. This copy shapes the authoring error; that one is
|
|
541
|
+
* authoritative and fail-closed. They must agree — a value this accepts and the
|
|
542
|
+
* deploy rejects is a broken deploy the author cannot see coming.
|
|
543
|
+
*/
|
|
544
|
+
declare const EGRESS_TIMEOUT_MIN_MS = 1000;
|
|
545
|
+
declare const EGRESS_TIMEOUT_MAX_MS = 300000;
|
|
546
|
+
/** Applied when `timeoutMs` is omitted. Also spelled in the isolate capability. */
|
|
547
|
+
declare const EGRESS_TIMEOUT_DEFAULT_MS = 30000;
|
|
530
548
|
/** The author-facing input to defineEgress. */
|
|
531
549
|
interface EgressInput {
|
|
532
550
|
hosts: string[];
|
|
551
|
+
/**
|
|
552
|
+
* Per-call ceiling for an outbound fetch, in milliseconds.
|
|
553
|
+
* 1_000..300_000; omitted ⇒ 30_000.
|
|
554
|
+
*/
|
|
555
|
+
timeoutMs?: number;
|
|
533
556
|
}
|
|
534
557
|
/** The evaluated config/egress.ts default export (what the deploy reads). */
|
|
535
558
|
interface EgressConfig {
|
|
536
559
|
__config: typeof EGRESS_CONFIG_KIND;
|
|
537
560
|
hosts: string[];
|
|
561
|
+
timeoutMs?: number;
|
|
538
562
|
}
|
|
539
563
|
/**
|
|
540
564
|
* Declare the backend's outbound-HTTP allowlist. Client-side this only shapes +
|
|
@@ -1396,61 +1420,6 @@ interface DefinedError {
|
|
|
1396
1420
|
declare function defineError<S extends ZodTypeAny>(code: string, status: number, dataSchema: S): DefinedErrorWithData<S>;
|
|
1397
1421
|
declare function defineError(code: string, status: number): DefinedError;
|
|
1398
1422
|
|
|
1399
|
-
/** Non-service, per-invocation data for background worker handlers.
|
|
1400
|
-
* Services (Database, Log, …) are imported as singletons, not passed here. */
|
|
1401
|
-
interface WorkerMeta {
|
|
1402
|
-
/** Environment-scoped env vars. */
|
|
1403
|
-
env: Record<string, string>;
|
|
1404
|
-
/** The user that enqueued the job, if any (background jobs are usually system-initiated). */
|
|
1405
|
-
user: User$1 | null;
|
|
1406
|
-
/** Per-invocation id for correlation. */
|
|
1407
|
-
requestId: string;
|
|
1408
|
-
/** The globally unique Environment runtime identifier. */
|
|
1409
|
-
environmentId: string;
|
|
1410
|
-
}
|
|
1411
|
-
/** Backoff strategy for worker retries. */
|
|
1412
|
-
type BackoffStrategy = "exponential" | "linear" | "fixed";
|
|
1413
|
-
/** Configuration for a background worker. */
|
|
1414
|
-
interface WorkerConfig<TPayload = unknown> {
|
|
1415
|
-
/** Worker name — must be unique across the project. */
|
|
1416
|
-
name: string;
|
|
1417
|
-
/** Maximum number of retries before sending to dead letter queue. Defaults to 3. */
|
|
1418
|
-
retry?: number;
|
|
1419
|
-
/** Execution timeout in seconds. Defaults to 30. */
|
|
1420
|
-
timeout?: number;
|
|
1421
|
-
/** Backoff strategy between retries. Defaults to "exponential". */
|
|
1422
|
-
backoff?: BackoffStrategy;
|
|
1423
|
-
/** Handler function that processes the job payload. */
|
|
1424
|
-
handler: (payload: TPayload, meta: WorkerMeta) => Promise<void>;
|
|
1425
|
-
}
|
|
1426
|
-
/** Resolved worker configuration with defaults applied. */
|
|
1427
|
-
interface ResolvedWorkerConfig<TPayload = unknown> {
|
|
1428
|
-
name: string;
|
|
1429
|
-
retry: number;
|
|
1430
|
-
timeout: number;
|
|
1431
|
-
backoff: BackoffStrategy;
|
|
1432
|
-
handler: (payload: TPayload, meta: WorkerMeta) => Promise<void>;
|
|
1433
|
-
}
|
|
1434
|
-
/**
|
|
1435
|
-
* Define a background worker that processes jobs from the queue.
|
|
1436
|
-
*
|
|
1437
|
-
* Workers are placed in the `workers/` directory and auto-discovered at deploy time.
|
|
1438
|
-
*
|
|
1439
|
-
* @example
|
|
1440
|
-
* ```ts
|
|
1441
|
-
* export default defineWorker({
|
|
1442
|
-
* name: "send-email",
|
|
1443
|
-
* retry: 5,
|
|
1444
|
-
* timeout: 60,
|
|
1445
|
-
* backoff: "exponential",
|
|
1446
|
-
* handler: async (payload: { to: string; subject: string }, meta) => {
|
|
1447
|
-
* await sendEmail(payload.to, payload.subject);
|
|
1448
|
-
* },
|
|
1449
|
-
* });
|
|
1450
|
-
* ```
|
|
1451
|
-
*/
|
|
1452
|
-
declare function defineWorker<TPayload = unknown>(config: WorkerConfig<TPayload>): ResolvedWorkerConfig<TPayload>;
|
|
1453
|
-
|
|
1454
1423
|
/** Non-service, per-invocation data for job handlers.
|
|
1455
1424
|
* Services (Database, Log, …) are imported as singletons, not passed here. */
|
|
1456
1425
|
interface JobMeta {
|
|
@@ -1746,4 +1715,4 @@ declare const documents: {
|
|
|
1746
1715
|
onDocumentDeleted(handler: HookHandler<DocumentDeletedEvent>): ResolvedHook<DocumentDeletedEvent>;
|
|
1747
1716
|
};
|
|
1748
1717
|
|
|
1749
|
-
export { type AcsOptions, type ApnsOptions,
|
|
1718
|
+
export { type AcsOptions, type ApnsOptions, Body, type BucketDef, type BucketOptions, Cache, CacheClient, Client, Controller, type ControllerOptions, DBClient, Database, type DefinedError, type DefinedErrorWithData, Delete, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentUpdatedEvent, Documents, EGRESS_CONFIG_KIND, EGRESS_TIMEOUT_DEFAULT_MS, EGRESS_TIMEOUT_MAX_MS, EGRESS_TIMEOUT_MIN_MS, type EgressConfig, type EgressInput, EntitlementKey, EnvTypedDatabase, FLAGS_CONFIG_KIND, type FcmOptions, type FileDeletedEvent, type FileUploadedEvent, type FlagDef, type FlagJsonObject, type FlagJsonValue, type FlagOptions, type FlagType, type FlagValue, Flags, type FlagsConfig, type FlagsInput, Get, Headers, type HookHandler, type HookMeta, HttpError, type HttpMethodUpper, Job, type JobMeta, type JobOptions, LimitKey, type LimitState, Log, Logger, NOTIFICATIONS_CONFIG_KIND, Notifications, type NotificationsConfig, type NotificationsInput, On, OptionalUser, type OwnedTablesOf, PROVIDER_CATALOG, PalbaseDocsClient, PalbaseFlagsClient, PalbaseNotificationsClient, PalbaseRealtimeClient, PalbaseStorageClient, Param, type ParamKind, type ParamMeta, type PasswordResetEvent, Patch, Post, type ProviderCatalogEntry, type ProviderDef, type ProviderName, type ProviderOptions, Purchases, type PurchasesManifest, type PurchasesService, Put, Query, QueryParams, RESERVED_SECRET_PREFIX, RateLimitConfig, Realtime, type RegisteredError, Req, RequestId, type RequestStore, RequireEntitlement, type ResolvedHook, type ResolvedJob, type ResolvedWebhook, Resource, type ResourceEnv, type RouteMeta, type RouteOptions, type RuntimeServices, STORAGE_CONFIG_KIND, SchemaDef, type Seed, type SeedFor, type SeedJson, type SeedRowFor, type SendgridOptions, type SesOptions, type SignInEvent, type SignOutEvent, type SignatureSpec, type SmtpOptions, Spend, type SpendMeta, type SpendOptions, Storage, type StorageConfig, type StorageInput, type StoreEnv, TEST_USERS_CONFIG_KIND, type TableGraph, TableTypes, Tables, type TestUserDef, type TestUserOptions, type TestUsersConfig, type TestUsersInput, type ThrowDescriptor, TraceId, type TwilioOptions, Upload, type UploadConfig, UploadedObject, User, type UserCreatedEvent, Webhook, type WebhookEventHandler, type WebhookMeta, type WebhookOptions, type WebhookProvider, type WebhookRequest, __getRuntime, __registerResource, __requestALS, __runResourceBoot, __runWithRuntime, __setRuntime, __shutdownResources, auth, bucket, buildProvider, defineEgress, defineError, defineFlags, defineNotifications, defineStorage, defineTestUsers, documents, entitlementFor, flag, getErrorRegistry, getJobConfig, getRoutes, getWebhookConfig, makeEnvDts, makePurchasesDts, parseFileSizeLimit, recordThrows, reservedSecretKey, spendFor, storage, testUser, validateUploadAgainstStorage };
|
package/dist/index.js
CHANGED
|
@@ -6,14 +6,13 @@ import {
|
|
|
6
6
|
Log,
|
|
7
7
|
Notifications,
|
|
8
8
|
Purchases,
|
|
9
|
-
Queue,
|
|
10
9
|
Realtime,
|
|
11
10
|
Storage,
|
|
12
11
|
__getRuntime,
|
|
13
12
|
__requestALS,
|
|
14
13
|
__runWithRuntime,
|
|
15
14
|
__setRuntime
|
|
16
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-I72YYSEI.js";
|
|
17
16
|
import {
|
|
18
17
|
EXTENSION_DEPENDENCIES,
|
|
19
18
|
PALBASE_EXTENSIONS,
|
|
@@ -320,7 +319,13 @@ function baseTsType(def) {
|
|
|
320
319
|
return "string";
|
|
321
320
|
case "integer":
|
|
322
321
|
return "number";
|
|
322
|
+
// Both are exact-precision in Postgres and lossy as a JSON number, so the
|
|
323
|
+
// database proxy serializes them as strings — measured: 9007199254740993
|
|
324
|
+
// used to arrive as ...992 and 41.00821234567890123 as 41.0082123456789.
|
|
325
|
+
// numeric had no case at all and fell through to `unknown`, which typed
|
|
326
|
+
// every numeric column out of existence.
|
|
323
327
|
case "bigint":
|
|
328
|
+
case "numeric":
|
|
324
329
|
return "string";
|
|
325
330
|
case "boolean":
|
|
326
331
|
return "boolean";
|
|
@@ -512,6 +517,9 @@ function defineStorage(input) {
|
|
|
512
517
|
|
|
513
518
|
// src/config/egress.ts
|
|
514
519
|
var EGRESS_CONFIG_KIND = "egress";
|
|
520
|
+
var EGRESS_TIMEOUT_MIN_MS = 1e3;
|
|
521
|
+
var EGRESS_TIMEOUT_MAX_MS = 3e5;
|
|
522
|
+
var EGRESS_TIMEOUT_DEFAULT_MS = 3e4;
|
|
515
523
|
function defineEgress(input) {
|
|
516
524
|
if (input === null || typeof input !== "object" || !Array.isArray(input.hosts)) {
|
|
517
525
|
throw new Error("defineEgress expects { hosts: string[] }");
|
|
@@ -523,7 +531,19 @@ function defineEgress(input) {
|
|
|
523
531
|
}
|
|
524
532
|
hosts.push(h.trim().toLowerCase());
|
|
525
533
|
}
|
|
526
|
-
|
|
534
|
+
if (input.timeoutMs === void 0) {
|
|
535
|
+
return { __config: EGRESS_CONFIG_KIND, hosts };
|
|
536
|
+
}
|
|
537
|
+
const timeoutMs = input.timeoutMs;
|
|
538
|
+
if (typeof timeoutMs !== "number" || !Number.isInteger(timeoutMs)) {
|
|
539
|
+
throw new Error("defineEgress: timeoutMs must be an integer number of milliseconds");
|
|
540
|
+
}
|
|
541
|
+
if (timeoutMs < EGRESS_TIMEOUT_MIN_MS || timeoutMs > EGRESS_TIMEOUT_MAX_MS) {
|
|
542
|
+
throw new Error(
|
|
543
|
+
`defineEgress: timeoutMs must be between ${EGRESS_TIMEOUT_MIN_MS} and ${EGRESS_TIMEOUT_MAX_MS} (got ${timeoutMs})`
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
return { __config: EGRESS_CONFIG_KIND, hosts, timeoutMs };
|
|
527
547
|
}
|
|
528
548
|
|
|
529
549
|
// src/config/notifications.ts
|
|
@@ -839,38 +859,6 @@ function defineFlags(input) {
|
|
|
839
859
|
return { __config: FLAGS_CONFIG_KIND, flags };
|
|
840
860
|
}
|
|
841
861
|
|
|
842
|
-
// src/decorators/controller.ts
|
|
843
|
-
var CONTROLLER_META = /* @__PURE__ */ Symbol.for("palbase.backend.controllerMeta");
|
|
844
|
-
function Controller(basePath, options = {}) {
|
|
845
|
-
return function(ctor) {
|
|
846
|
-
const normalized = basePath.replace(/\/+$/, "");
|
|
847
|
-
if (normalized === "/webhooks" || normalized.startsWith("/webhooks/")) {
|
|
848
|
-
throw new Error(
|
|
849
|
-
`@Controller("${basePath}") uses the reserved /webhooks path \u2014 inbound webhooks are served there`
|
|
850
|
-
);
|
|
851
|
-
}
|
|
852
|
-
const carrier = ctor;
|
|
853
|
-
const meta = {
|
|
854
|
-
__palbase: "controller",
|
|
855
|
-
basePath,
|
|
856
|
-
...options.auth !== void 0 ? { defaultAuth: options.auth } : {}
|
|
857
|
-
};
|
|
858
|
-
Object.defineProperty(carrier, CONTROLLER_META, {
|
|
859
|
-
value: meta,
|
|
860
|
-
enumerable: false,
|
|
861
|
-
configurable: true,
|
|
862
|
-
writable: false
|
|
863
|
-
});
|
|
864
|
-
Object.defineProperty(carrier, "__palbase", {
|
|
865
|
-
value: "controller",
|
|
866
|
-
enumerable: false,
|
|
867
|
-
configurable: true,
|
|
868
|
-
writable: false
|
|
869
|
-
});
|
|
870
|
-
return ctor;
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
|
|
874
862
|
// src/decorators/registry.ts
|
|
875
863
|
var ROUTES = /* @__PURE__ */ Symbol.for("palbase.backend.routes");
|
|
876
864
|
var PARAM_BUFFER = /* @__PURE__ */ Symbol.for("palbase.backend.paramBuffer");
|
|
@@ -963,6 +951,48 @@ function getRoutes(ctor) {
|
|
|
963
951
|
}));
|
|
964
952
|
}
|
|
965
953
|
|
|
954
|
+
// src/decorators/controller.ts
|
|
955
|
+
var CONTROLLER_META = /* @__PURE__ */ Symbol.for("palbase.backend.controllerMeta");
|
|
956
|
+
var RESERVED_FIRST_SEGMENT = "webhooks";
|
|
957
|
+
function assertNotReserved(path, subject) {
|
|
958
|
+
const [first] = path.split("/").filter(Boolean);
|
|
959
|
+
if (first === RESERVED_FIRST_SEGMENT) {
|
|
960
|
+
throw new Error(
|
|
961
|
+
`${subject} resolves under the reserved /${RESERVED_FIRST_SEGMENT} path \u2014 inbound webhooks are served there and would shadow this route`
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
function Controller(basePath, options = {}) {
|
|
966
|
+
return function(ctor) {
|
|
967
|
+
assertNotReserved(basePath, `@Controller("${basePath}")`);
|
|
968
|
+
for (const route of getRoutes(ctor)) {
|
|
969
|
+
assertNotReserved(
|
|
970
|
+
`${basePath}${route.subpath}`,
|
|
971
|
+
`@${route.method}("${route.subpath}") in @Controller("${basePath}")`
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
const carrier = ctor;
|
|
975
|
+
const meta = {
|
|
976
|
+
__palbase: "controller",
|
|
977
|
+
basePath,
|
|
978
|
+
...options.auth !== void 0 ? { defaultAuth: options.auth } : {}
|
|
979
|
+
};
|
|
980
|
+
Object.defineProperty(carrier, CONTROLLER_META, {
|
|
981
|
+
value: meta,
|
|
982
|
+
enumerable: false,
|
|
983
|
+
configurable: true,
|
|
984
|
+
writable: false
|
|
985
|
+
});
|
|
986
|
+
Object.defineProperty(carrier, "__palbase", {
|
|
987
|
+
value: "controller",
|
|
988
|
+
enumerable: false,
|
|
989
|
+
configurable: true,
|
|
990
|
+
writable: false
|
|
991
|
+
});
|
|
992
|
+
return ctor;
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
|
|
966
996
|
// src/decorators/methods.ts
|
|
967
997
|
function makeMethodDecorator(method) {
|
|
968
998
|
return function(subpath, options = {}) {
|
|
@@ -1206,40 +1236,6 @@ function humanize(code) {
|
|
|
1206
1236
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
1207
1237
|
}
|
|
1208
1238
|
|
|
1209
|
-
// src/worker.ts
|
|
1210
|
-
var VALID_WORKER_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
1211
|
-
var WORKER_DEFAULTS = {
|
|
1212
|
-
retry: 3,
|
|
1213
|
-
timeout: 30,
|
|
1214
|
-
backoff: "exponential"
|
|
1215
|
-
};
|
|
1216
|
-
function defineWorker(config) {
|
|
1217
|
-
if (!config.name || config.name.trim() === "") {
|
|
1218
|
-
throw new Error("Worker name is required");
|
|
1219
|
-
}
|
|
1220
|
-
if (!VALID_WORKER_NAME.test(config.name)) {
|
|
1221
|
-
throw new Error(
|
|
1222
|
-
`Invalid worker name "${config.name}": must match [a-zA-Z0-9_-]+`
|
|
1223
|
-
);
|
|
1224
|
-
}
|
|
1225
|
-
if (config.retry !== void 0 && (config.retry < 0 || !Number.isInteger(config.retry))) {
|
|
1226
|
-
throw new Error("Worker retry must be a non-negative integer");
|
|
1227
|
-
}
|
|
1228
|
-
if (config.timeout !== void 0 && config.timeout <= 0) {
|
|
1229
|
-
throw new Error("Worker timeout must be a positive number");
|
|
1230
|
-
}
|
|
1231
|
-
if (config.backoff !== void 0 && !["exponential", "linear", "fixed"].includes(config.backoff)) {
|
|
1232
|
-
throw new Error(`Invalid backoff strategy: ${config.backoff}`);
|
|
1233
|
-
}
|
|
1234
|
-
return {
|
|
1235
|
-
name: config.name,
|
|
1236
|
-
retry: config.retry ?? WORKER_DEFAULTS.retry,
|
|
1237
|
-
timeout: config.timeout ?? WORKER_DEFAULTS.timeout,
|
|
1238
|
-
backoff: config.backoff ?? WORKER_DEFAULTS.backoff,
|
|
1239
|
-
handler: config.handler
|
|
1240
|
-
};
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
1239
|
// src/decorators/webhook.ts
|
|
1244
1240
|
var WEBHOOK_META = /* @__PURE__ */ Symbol.for("palbase.backend.webhookMeta");
|
|
1245
1241
|
var WEBHOOK_EVENTS = /* @__PURE__ */ Symbol.for("palbase.backend.webhookEvents");
|
|
@@ -1292,6 +1288,11 @@ function getWebhookConfig(ctor) {
|
|
|
1292
1288
|
"@Webhook requires either a `provider` preset or an explicit `signature` \u2014 an endpoint with no verification would accept forged deliveries"
|
|
1293
1289
|
);
|
|
1294
1290
|
}
|
|
1291
|
+
if (meta.provider && meta.signature) {
|
|
1292
|
+
throw new Error(
|
|
1293
|
+
"@Webhook declares BOTH a `provider` preset and an explicit `signature` \u2014 these are alternatives; keep the one that describes the sender, because only `provider` would be used"
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1295
1296
|
if (meta.signature) {
|
|
1296
1297
|
const sig = meta.signature;
|
|
1297
1298
|
if (!sig.header) {
|
|
@@ -1544,6 +1545,9 @@ export {
|
|
|
1544
1545
|
Delete,
|
|
1545
1546
|
Documents,
|
|
1546
1547
|
EGRESS_CONFIG_KIND,
|
|
1548
|
+
EGRESS_TIMEOUT_DEFAULT_MS,
|
|
1549
|
+
EGRESS_TIMEOUT_MAX_MS,
|
|
1550
|
+
EGRESS_TIMEOUT_MIN_MS,
|
|
1547
1551
|
EXTENSION_DEPENDENCIES,
|
|
1548
1552
|
FLAGS_CONFIG_KIND,
|
|
1549
1553
|
Flags,
|
|
@@ -1569,7 +1573,6 @@ export {
|
|
|
1569
1573
|
Put,
|
|
1570
1574
|
Query,
|
|
1571
1575
|
QueryParams,
|
|
1572
|
-
Queue,
|
|
1573
1576
|
RESERVED_SECRET_PREFIX,
|
|
1574
1577
|
Realtime,
|
|
1575
1578
|
Req,
|
|
@@ -1610,7 +1613,6 @@ export {
|
|
|
1610
1613
|
defineSchema,
|
|
1611
1614
|
defineStorage,
|
|
1612
1615
|
defineTestUsers,
|
|
1613
|
-
defineWorker,
|
|
1614
1616
|
documents,
|
|
1615
1617
|
entitlementFor,
|
|
1616
1618
|
enumType,
|