@palbase/backend 21.0.0 → 22.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.
@@ -1,4 +1,4 @@
1
- export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-Br9P7yRu.cjs';
1
+ export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-B4W6d2VJ.cjs';
2
2
  import '../endpoint-B0LpZixz.cjs';
3
3
  import '../db/env.cjs';
4
4
  import 'node:async_hooks';
@@ -1,4 +1,4 @@
1
- export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-BeHLq2i-.js';
1
+ export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-BCNtlG1w.js';
2
2
  import '../endpoint-B0LpZixz.js';
3
3
  import '../db/env.js';
4
4
  import 'node:async_hooks';
@@ -16,7 +16,7 @@ import {
16
16
  quoteIdent,
17
17
  scrubSecrets,
18
18
  withTables
19
- } from "../chunk-PFQJYW6C.js";
19
+ } from "../chunk-QYOHMVUW.js";
20
20
  import "../chunk-POYAFBLF.js";
21
21
  import "../chunk-W5ODXPY3.js";
22
22
  import "../chunk-QMVK4X3V.js";
@@ -304,6 +304,20 @@ interface EngineConfig {
304
304
  /** Base URL of the module surface (`/v1/*`, `/auth/*`). Empty ⇒ module
305
305
  * singletons throw a named error on first use rather than silently no-op. */
306
306
  moduleBaseUrl: string;
307
+ /**
308
+ * The address CLIENTS reach this stack at — `https://<ref>.palbase.studio` in
309
+ * the cloud, whatever domain the certificate is for when self-hosted.
310
+ *
311
+ * NOT `moduleBaseUrl`, and the distinction is the whole point: that one is
312
+ * this process's internal route to palsvc (`http://127.0.0.1:8080`), which
313
+ * resolves nowhere outside the pod. A public object URL has to survive
314
+ * leaving the response body, so it cannot be built from the internal one.
315
+ *
316
+ * Only the operator knows this value, so only the operator sets it
317
+ * (`PALBASE_PUBLIC_ORIGIN`). Empty ⇒ `Storage…getPublicUrl()` throws a named
318
+ * error, the same way an unconfigured module does.
319
+ */
320
+ publicOrigin: string;
307
321
  /** Shared secret storage signs its internal upload calls with. Empty means
308
322
  * uploads are not wired, and those calls are refused. */
309
323
  uploadSecret: string;
@@ -304,6 +304,20 @@ interface EngineConfig {
304
304
  /** Base URL of the module surface (`/v1/*`, `/auth/*`). Empty ⇒ module
305
305
  * singletons throw a named error on first use rather than silently no-op. */
306
306
  moduleBaseUrl: string;
307
+ /**
308
+ * The address CLIENTS reach this stack at — `https://<ref>.palbase.studio` in
309
+ * the cloud, whatever domain the certificate is for when self-hosted.
310
+ *
311
+ * NOT `moduleBaseUrl`, and the distinction is the whole point: that one is
312
+ * this process's internal route to palsvc (`http://127.0.0.1:8080`), which
313
+ * resolves nowhere outside the pod. A public object URL has to survive
314
+ * leaving the response body, so it cannot be built from the internal one.
315
+ *
316
+ * Only the operator knows this value, so only the operator sets it
317
+ * (`PALBASE_PUBLIC_ORIGIN`). Empty ⇒ `Storage…getPublicUrl()` throws a named
318
+ * error, the same way an unconfigured module does.
319
+ */
320
+ publicOrigin: string;
307
321
  /** Shared secret storage signs its internal upload calls with. Empty means
308
322
  * uploads are not wired, and those calls are refused. */
309
323
  uploadSecret: string;
package/dist/index.cjs CHANGED
@@ -1658,7 +1658,7 @@ function mapResponse(res, map) {
1658
1658
  }
1659
1659
  return { data: map(res.data), error: null, status: res.status };
1660
1660
  }
1661
- function buildBucketClient(http, bucketName) {
1661
+ function buildBucketClient(http, bucketName, publicOrigin) {
1662
1662
  const objectPath = (path) => `/v1/storage/object/${bucketName}/${path}`;
1663
1663
  return {
1664
1664
  async upload(path, file, options) {
@@ -1681,7 +1681,12 @@ function buildBucketClient(http, bucketName) {
1681
1681
  getPublicUrl(path, options) {
1682
1682
  validateStoragePath(path);
1683
1683
  const variant = options?.variant ? `?variant=${encodeURIComponent(options.variant)}` : "";
1684
- return `/v1/files/${bucketName}/${path}${variant}`;
1684
+ if (!publicOrigin) {
1685
+ throw new Error(
1686
+ `Storage.bucket("${bucketName}").getPublicUrl() needs this stack's public origin, and it was not configured. Set PALBASE_PUBLIC_ORIGIN to the address clients reach this stack at (e.g. https://myproject.palbase.studio).`
1687
+ );
1688
+ }
1689
+ return `${publicOrigin}/v1/files/${bucketName}/${path}${variant}`;
1685
1690
  },
1686
1691
  async createSignedUrl(path, options) {
1687
1692
  validateStoragePath(path);
@@ -1723,13 +1728,13 @@ function buildBucketClient(http, bucketName) {
1723
1728
  }
1724
1729
  };
1725
1730
  }
1726
- function buildStorageClient(http) {
1731
+ function buildStorageClient(http, publicOrigin) {
1727
1732
  return {
1728
1733
  bucket(name) {
1729
1734
  if (!BUCKET_NAME_RE.test(name)) {
1730
1735
  throw new Error(`Invalid bucket name: "${name}". Bucket names must match ${BUCKET_NAME_RE.source}`);
1731
1736
  }
1732
- return buildBucketClient(http, name);
1737
+ return buildBucketClient(http, name, publicOrigin.replace(/\/+$/, ""));
1733
1738
  }
1734
1739
  };
1735
1740
  }
@@ -1742,7 +1747,7 @@ function buildModuleClients(cfg) {
1742
1747
  const http = makeHttpClient({ baseUrl, apiKey, fetchImpl: cfg.fetchImpl });
1743
1748
  return {
1744
1749
  Documents: buildDocumentsClient(http),
1745
- Storage: buildStorageClient(http),
1750
+ Storage: buildStorageClient(http, cfg.publicOrigin),
1746
1751
  Notifications: buildNotificationsClient(http),
1747
1752
  Flags: buildFlagsClient(http, { getCurrentUserId: cfg.getCurrentUserId }),
1748
1753
  Realtime: buildRealtimeClient({