@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-pencil/cloud",
3
- "version": "0.17.0-beta.7",
3
+ "version": "0.17.0",
4
4
  "license": "Apache-2.0 AND MIT",
5
5
  "funding": "https://ko-fi.com/dannote",
6
6
  "files": [
@@ -26,10 +26,10 @@
26
26
  "@internationalized/date": "^3.12.3",
27
27
  "@nanostores/i18n": "^1.3.3",
28
28
  "@noble/hashes": "^2.4.0",
29
- "@open-pencil/fig": "^0.17.0-beta.7",
30
- "@open-pencil/kiwi": "^0.17.0-beta.7",
31
- "@open-pencil/scene-graph": "^0.17.0-beta.7",
32
- "@open-pencil/std": "^0.17.0-beta.7",
29
+ "@open-pencil/fig": "^0.17.0",
30
+ "@open-pencil/kiwi": "^0.17.0",
31
+ "@open-pencil/scene-graph": "^0.17.0",
32
+ "@open-pencil/std": "^0.17.0",
33
33
  "@openfeature/server-sdk": "^1.23.0",
34
34
  "@vue-email/components": "^0.0.21",
35
35
  "@vue-email/render": "^0.0.9",
@@ -29,6 +29,13 @@ export const CLOUD_ACCOUNT_PLAN_PATH = '/account/plan' as const
29
29
  */
30
30
  export const CLOUD_ACCOUNT_BILLING_PATH = `${CLOUD_ACCOUNT_PLAN_PATH}?open=billing` as const
31
31
 
32
+ /**
33
+ * Where a Cloud server signs a billing token for whoever is signed in. Billing's own pages, at the
34
+ * discovered `endpoint`'s origin, may ask for one with the visitor's Cloud session, so a visitor
35
+ * already signed in to Cloud is signed in to billing as its pages open; no other page may.
36
+ */
37
+ export const CLOUD_BILLING_TOKEN_PATH = '/api/billing/token' as const
38
+
32
39
  /**
33
40
  * The billing service's own pages, below the discovered `endpoint`: where Cloud's plan page sends
34
41
  * the signed-in person, posting a billing token as the form field `token` to `session`, and the
@@ -60,6 +60,7 @@ export {
60
60
  CLOUD_BILLING_PAGE_PATHS,
61
61
  CLOUD_BILLING_CONTRACT_VERSION,
62
62
  CLOUD_BILLING_TOKEN_AUDIENCE,
63
+ CLOUD_BILLING_TOKEN_PATH,
63
64
  billingAccountSchema,
64
65
  billingCatalogSchema,
65
66
  billingErrorCodeSchema,
@@ -1,4 +1,4 @@
1
- import { CLOUD_DISCOVERY_PATH } from '#cloud/contract'
1
+ import { CLOUD_BILLING_TOKEN_PATH, CLOUD_DISCOVERY_PATH } from '#cloud/contract'
2
2
  import type { MiddlewareHandler } from 'hono'
3
3
  import { cors } from 'hono/cors'
4
4
 
@@ -20,10 +20,15 @@ function isOpenRead(method: string, path: string): boolean {
20
20
 
21
21
  /**
22
22
  * Cross-origin access to the server. Its own pages and the origins it trusts send their account
23
- * with every request. Any other page, such as the documentation site's landing showing the tour,
24
- * may read the discovery and the gallery without one, and nothing else.
23
+ * with every request. The billing service the server advertises, at `billingOrigin`, may ask for a
24
+ * billing token with the visitor's account, and nothing else. Any other page, such as the
25
+ * documentation site's landing showing the tour, may read the discovery and the gallery without
26
+ * one, and nothing else.
25
27
  */
26
- export function createCloudCORS(allowedOrigins: ReadonlySet<string>): MiddlewareHandler {
28
+ export function createCloudCORS(
29
+ allowedOrigins: ReadonlySet<string>,
30
+ billingOrigin?: string
31
+ ): MiddlewareHandler {
27
32
  const trusted = cors({
28
33
  origin: (origin) => (allowedOrigins.has(origin) ? origin : null),
29
34
  allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
@@ -32,8 +37,21 @@ export function createCloudCORS(allowedOrigins: ReadonlySet<string>): Middleware
32
37
  maxAge: 600
33
38
  })
34
39
  const openRead = cors({ origin: '*', allowMethods: ['GET', 'HEAD'], maxAge: 600 })
40
+ const billingToken = cors({
41
+ origin: (origin) => (origin === billingOrigin ? origin : null),
42
+ allowMethods: ['POST'],
43
+ credentials: true,
44
+ maxAge: 600
45
+ })
35
46
  return (context, next) => {
36
47
  const origin = context.req.header('Origin')
48
+ if (
49
+ billingOrigin &&
50
+ origin === billingOrigin &&
51
+ context.req.path === CLOUD_BILLING_TOKEN_PATH
52
+ ) {
53
+ return billingToken(context, next)
54
+ }
37
55
  const anyPage = origin !== undefined && !allowedOrigins.has(origin)
38
56
  // A preflight names the method it asks for; a request is its own.
39
57
  const method = context.req.header('Access-Control-Request-Method') ?? context.req.method
@@ -39,7 +39,9 @@ export function createCloudApp(services: CloudServices) {
39
39
  const allowedOrigins = new Set(
40
40
  [config.publicURL, ...config.trustedOrigins].map((origin) => new URL(origin).origin)
41
41
  )
42
- const cloudCORS = createCloudCORS(allowedOrigins)
42
+ // Billing's pages sign a visitor in with their Cloud session as they open (`CLOUD_BILLING_TOKEN_PATH`).
43
+ const billingOrigin = config.billingEndpoint && new URL(config.billingEndpoint).origin
44
+ const cloudCORS = createCloudCORS(allowedOrigins, billingOrigin || undefined)
43
45
  const app = createAppServices(services)
44
46
  const resolvers = createRequestResolvers(services)
45
47
  const checks = createRequestChecks(services, resolvers)