@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/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +7 -1
- package/dist/contract2.js.map +1 -1
- package/dist/index.d.ts +28 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/listen.mjs +7 -1
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.js +13 -4
- package/dist/runtime-cloudflare.js.map +1 -1
- package/dist/runtime-node.d.mts +20 -20
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +24 -24
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +13 -4
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +13 -4
- package/dist/server.mjs.map +1 -1
- package/package.json +5 -5
- package/src/contract/billing.ts +7 -0
- package/src/contract/index.ts +1 -0
- package/src/server/app/cors.ts +22 -4
- package/src/server/app/index.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-pencil/cloud",
|
|
3
|
-
"version": "0.17.0
|
|
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
|
|
30
|
-
"@open-pencil/kiwi": "^0.17.0
|
|
31
|
-
"@open-pencil/scene-graph": "^0.17.0
|
|
32
|
-
"@open-pencil/std": "^0.17.0
|
|
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",
|
package/src/contract/billing.ts
CHANGED
|
@@ -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
|
package/src/contract/index.ts
CHANGED
package/src/server/app/cors.ts
CHANGED
|
@@ -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.
|
|
24
|
-
*
|
|
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(
|
|
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
|
package/src/server/app/index.ts
CHANGED
|
@@ -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
|
-
|
|
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)
|