@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.
@@ -16461,10 +16461,12 @@ function isOpenRead(method, path) {
16461
16461
  }
16462
16462
  /**
16463
16463
  * Cross-origin access to the server. Its own pages and the origins it trusts send their account
16464
- * with every request. Any other page, such as the documentation site's landing showing the tour,
16465
- * may read the discovery and the gallery without one, and nothing else.
16464
+ * with every request. The billing service the server advertises, at `billingOrigin`, may ask for a
16465
+ * billing token with the visitor's account, and nothing else. Any other page, such as the
16466
+ * documentation site's landing showing the tour, may read the discovery and the gallery without
16467
+ * one, and nothing else.
16466
16468
  */
16467
- function createCloudCORS(allowedOrigins) {
16469
+ function createCloudCORS(allowedOrigins, billingOrigin) {
16468
16470
  const trusted = cors({
16469
16471
  origin: (origin) => allowedOrigins.has(origin) ? origin : null,
16470
16472
  allowMethods: [
@@ -16484,8 +16486,15 @@ function createCloudCORS(allowedOrigins) {
16484
16486
  allowMethods: ["GET", "HEAD"],
16485
16487
  maxAge: 600
16486
16488
  });
16489
+ const billingToken = cors({
16490
+ origin: (origin) => origin === billingOrigin ? origin : null,
16491
+ allowMethods: ["POST"],
16492
+ credentials: true,
16493
+ maxAge: 600
16494
+ });
16487
16495
  return (context, next) => {
16488
16496
  const origin = context.req.header("Origin");
16497
+ if (billingOrigin && origin === billingOrigin && context.req.path === "/api/billing/token") return billingToken(context, next);
16489
16498
  const anyPage = origin !== void 0 && !allowedOrigins.has(origin);
16490
16499
  const method = context.req.header("Access-Control-Request-Method") ?? context.req.method;
16491
16500
  return anyPage && isOpenRead(method, context.req.path) ? openRead(context, next) : trusted(context, next);
@@ -17033,7 +17042,7 @@ function createCloudApp(services) {
17033
17042
  const { config } = services;
17034
17043
  const discovery = cloudDiscoveryFromConfig(config);
17035
17044
  const allowedOrigins = new Set([config.publicURL, ...config.trustedOrigins].map((origin) => new URL(origin).origin));
17036
- const cloudCORS = createCloudCORS(allowedOrigins);
17045
+ const cloudCORS = createCloudCORS(allowedOrigins, config.billingEndpoint && new URL(config.billingEndpoint).origin || void 0);
17037
17046
  const app = createAppServices(services);
17038
17047
  const resolvers = createRequestResolvers(services);
17039
17048
  const checks = createRequestChecks(services, resolvers);