@open-pencil/cloud 0.17.0-beta.7 → 0.17.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/server.mjs CHANGED
@@ -14800,10 +14800,12 @@ function isOpenRead(method, path) {
14800
14800
  }
14801
14801
  /**
14802
14802
  * Cross-origin access to the server. Its own pages and the origins it trusts send their account
14803
- * with every request. Any other page, such as the documentation site's landing showing the tour,
14804
- * may read the discovery and the gallery without one, and nothing else.
14803
+ * with every request. The billing service the server advertises, at `billingOrigin`, may ask for a
14804
+ * billing token with the visitor's account, and nothing else. Any other page, such as the
14805
+ * documentation site's landing showing the tour, may read the discovery and the gallery without
14806
+ * one, and nothing else.
14805
14807
  */
14806
- function createCloudCORS(allowedOrigins) {
14808
+ function createCloudCORS(allowedOrigins, billingOrigin) {
14807
14809
  const trusted = cors({
14808
14810
  origin: (origin) => allowedOrigins.has(origin) ? origin : null,
14809
14811
  allowMethods: [
@@ -14823,8 +14825,15 @@ function createCloudCORS(allowedOrigins) {
14823
14825
  allowMethods: ["GET", "HEAD"],
14824
14826
  maxAge: 600
14825
14827
  });
14828
+ const billingToken = cors({
14829
+ origin: (origin) => origin === billingOrigin ? origin : null,
14830
+ allowMethods: ["POST"],
14831
+ credentials: true,
14832
+ maxAge: 600
14833
+ });
14826
14834
  return (context, next) => {
14827
14835
  const origin = context.req.header("Origin");
14836
+ if (billingOrigin && origin === billingOrigin && context.req.path === "/api/billing/token") return billingToken(context, next);
14828
14837
  const anyPage = origin !== void 0 && !allowedOrigins.has(origin);
14829
14838
  const method = context.req.header("Access-Control-Request-Method") ?? context.req.method;
14830
14839
  return anyPage && isOpenRead(method, context.req.path) ? openRead(context, next) : trusted(context, next);
@@ -15372,7 +15381,7 @@ function createCloudApp(services) {
15372
15381
  const { config } = services;
15373
15382
  const discovery = cloudDiscoveryFromConfig(config);
15374
15383
  const allowedOrigins = new Set([config.publicURL, ...config.trustedOrigins].map((origin) => new URL(origin).origin));
15375
- const cloudCORS = createCloudCORS(allowedOrigins);
15384
+ const cloudCORS = createCloudCORS(allowedOrigins, config.billingEndpoint && new URL(config.billingEndpoint).origin || void 0);
15376
15385
  const app = createAppServices(services);
15377
15386
  const resolvers = createRequestResolvers(services);
15378
15387
  const checks = createRequestChecks(services, resolvers);