@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.5
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/README.md +2 -1
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/services.mjs +1 -1
- package/dist/bin/services.mjs.map +1 -1
- package/dist/client.d.ts +296 -27
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +649 -295
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +331 -21
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +1773 -32
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3478 -288
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +466 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +35 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +447 -290
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +89 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +15667 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +2963 -294
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +3473 -842
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12187 -8244
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +7739 -3548
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +5 -5
- package/dist/server2.mjs.map +1 -1
- package/package.json +22 -5
- package/src/admin/audit/service.ts +2 -2
- package/src/admin/documents/service.ts +76 -6
- package/src/admin/reports/service.ts +7 -1
- package/src/client/api.ts +23 -471
- package/src/client/auth/client.ts +22 -3
- package/src/client/billing.ts +80 -0
- package/src/client/community.ts +40 -0
- package/src/client/discovery.ts +35 -9
- package/src/client/documents.ts +160 -0
- package/src/client/index.ts +7 -0
- package/src/client/portal/account.ts +54 -2
- package/src/client/portal/request.ts +2 -0
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +23 -18
- package/src/client/sharing.ts +262 -0
- package/src/client/versions.ts +104 -0
- package/src/contract/account.ts +50 -0
- package/src/contract/billing.ts +166 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +63 -2
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +54 -5
- package/src/contract/links.ts +57 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +18 -16
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +141 -0
- package/src/email/locales/de.json +141 -0
- package/src/email/locales/es.json +141 -0
- package/src/email/locales/fr.json +141 -0
- package/src/email/locales/it.json +141 -0
- package/src/email/locales/ja.json +141 -0
- package/src/email/locales/pl.json +141 -0
- package/src/email/locales/pt-br.json +141 -0
- package/src/email/locales/ru.json +141 -0
- package/src/email/locales/zh-cn.json +141 -0
- package/src/email/messages.ts +200 -0
- package/src/email/render.ts +142 -276
- package/src/email/samples.ts +115 -0
- package/src/email/schema.ts +70 -6
- package/src/email/templates/BrandEmail.vue +54 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +32 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +9 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/relay/index.ts +7 -1
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +8 -1
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/transport.ts +13 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +12 -2
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +2 -1
- package/src/runtime/s3/objects.ts +17 -0
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +17 -1
- package/src/server/account/deletion.ts +2 -0
- package/src/server/account/routes.ts +271 -240
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +23 -0
- package/src/server/app/checks.ts +84 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +114 -0
- package/src/server/app/services.ts +185 -0
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/adapter.ts +21 -1
- package/src/server/auth/email.ts +4 -1
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +88 -131
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/mfa-assurance.ts +51 -0
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/session.ts +2 -0
- package/src/server/billing/index.ts +6 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- package/src/server/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/hub.ts +25 -142
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/service.ts +21 -2
- package/src/server/community/index.ts +2 -0
- package/src/server/community/routes.ts +93 -0
- package/src/server/community/service.ts +134 -0
- package/src/server/config/deployment.ts +17 -5
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +7 -1
- package/src/server/config/schema.ts +40 -292
- package/src/server/config/toml/schema.ts +307 -0
- package/src/server/db/index.ts +1 -0
- package/src/server/db/migrate.ts +13 -1
- package/src/server/db/migrations/009_access_tokens.ts +47 -0
- package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
- package/src/server/db/migrations/011_account_ids.ts +30 -0
- package/src/server/db/migrations/012_email_locales.ts +34 -0
- package/src/server/db/migrations/013_document_block_emails.ts +40 -0
- package/src/server/db/migrations/014_report_replies.ts +28 -0
- package/src/server/db/migrations/schema.ts +26 -1
- package/src/server/db/tables.ts +30 -1
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/service.ts +12 -402
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/service.ts +81 -24
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +31 -4
- package/src/server/email/types.ts +12 -0
- package/src/server/errors/index.ts +1 -9
- package/src/server/index.ts +12 -5
- package/src/server/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +13 -2
- package/src/server/policy/policy.ts +39 -12
- package/src/server/policy/service.ts +71 -52
- package/src/server/policy/storage.ts +33 -0
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/storage.ts +5 -0
- package/src/server/rate-limit/middleware.ts +4 -0
- package/src/server/reports/index.ts +1 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +3 -1
- package/src/server/reports/service.ts +24 -2
- package/src/server/sharing/capabilities/service.ts +2 -3
- package/src/server/sharing/invitations/service.ts +14 -4
- package/src/server/validation.ts +3 -0
- package/src/server/workspaces/members.ts +7 -19
- package/src/services/app.ts +1 -3
- package/src/services/config.ts +1 -0
- package/src/services/usage.ts +6 -14
- package/src/email/templates/document-invitation.ts +0 -35
- package/src/email/templates/enrollment.ts +0 -27
- package/src/email/templates/layout.ts +0 -18
- package/src/server/app.ts +0 -453
- /package/src/{server/errors → errors}/posthog.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as v from 'valibot'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { cloudBillingDiscoverySchema } from './billing'
|
|
4
|
+
import { cloudServicesDiscoverySchema } from './services'
|
|
4
5
|
|
|
5
6
|
export const CLOUD_PROTOCOL_VERSION = '1' as const
|
|
6
7
|
export const CLOUD_DISCOVERY_PATH = '/.well-known/openpencil' as const
|
|
@@ -46,6 +47,33 @@ export type CloudCapabilities = v.InferOutput<typeof cloudCapabilitiesSchema>
|
|
|
46
47
|
/** A released editor version, `major.minor.patch`. */
|
|
47
48
|
export const cloudEditorVersionSchema = v.pipe(v.string(), v.regex(/^\d+\.\d+\.\d+$/))
|
|
48
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The header desktop editors send with each request, naming their version, so a server can refuse
|
|
52
|
+
* an editor older than its `minimumEditorVersion`. Browser editors leave it out: the server serves
|
|
53
|
+
* them, and an older server's CORS rules would refuse a header they don't list.
|
|
54
|
+
*/
|
|
55
|
+
export const CLOUD_EDITOR_VERSION_HEADER = 'X-OpenPencil-Editor-Version' as const
|
|
56
|
+
|
|
57
|
+
function editorVersionParts(version: string): number[] | null {
|
|
58
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version)
|
|
59
|
+
return match ? match.slice(1).map(Number) : null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether `version` is `minimum` or later, comparing `major.minor.patch` numerically; a prerelease
|
|
64
|
+
* counts as its release. A version that isn't one, on either side, is not at least anything.
|
|
65
|
+
*/
|
|
66
|
+
export function isEditorVersionAtLeast(version: string, minimum: string): boolean {
|
|
67
|
+
const have = editorVersionParts(version)
|
|
68
|
+
const need = editorVersionParts(minimum)
|
|
69
|
+
if (!have || !need) return false
|
|
70
|
+
for (let index = 0; index < need.length; index++) {
|
|
71
|
+
const difference = (have[index] ?? 0) - (need[index] ?? 0)
|
|
72
|
+
if (difference !== 0) return difference > 0
|
|
73
|
+
}
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
|
|
49
77
|
/**
|
|
50
78
|
* Whether editors offer this server to everyone, and from which editor version on. Only the
|
|
51
79
|
* official server's listing is read: it turns the Cloud entry points on without an editor release,
|
|
@@ -71,6 +99,31 @@ export const cloudLegalDiscoverySchema = v.object({
|
|
|
71
99
|
})
|
|
72
100
|
export type CloudLegalDiscovery = v.InferOutput<typeof cloudLegalDiscoverySchema>
|
|
73
101
|
|
|
102
|
+
/** A web address a page may link or load: `http` or `https` only, never a script or data URL. */
|
|
103
|
+
const webURLSchema = v.pipe(
|
|
104
|
+
v.string(),
|
|
105
|
+
v.url(),
|
|
106
|
+
v.check((value) => ['http:', 'https:'].includes(new URL(value).protocol))
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* How a self-hosted server names itself on its public pages: the operator's name and logo in the
|
|
111
|
+
* bar, and where its people get help. The official server is OpenPencil's own and names none.
|
|
112
|
+
*/
|
|
113
|
+
export const cloudBrandingSchema = v.object({
|
|
114
|
+
name: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80))),
|
|
115
|
+
logoURL: v.optional(webURLSchema),
|
|
116
|
+
helpURL: v.optional(webURLSchema)
|
|
117
|
+
})
|
|
118
|
+
export type CloudBranding = v.InferOutput<typeof cloudBrandingSchema>
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The server's community gallery: the workspace whose documents anyone may open read-only.
|
|
122
|
+
* Saving to it publishes, so editors never choose it for anyone and say so when it is chosen.
|
|
123
|
+
*/
|
|
124
|
+
export const cloudCommunityDiscoverySchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) })
|
|
125
|
+
export type CloudCommunityDiscovery = v.InferOutput<typeof cloudCommunityDiscoverySchema>
|
|
126
|
+
|
|
74
127
|
export const cloudDiscoverySchema = v.object({
|
|
75
128
|
protocolVersion: v.literal(CLOUD_PROTOCOL_VERSION),
|
|
76
129
|
deployment: cloudDeploymentSchema,
|
|
@@ -81,11 +134,19 @@ export const cloudDiscoverySchema = v.object({
|
|
|
81
134
|
authentication: cloudAuthenticationSchema,
|
|
82
135
|
capabilities: cloudCapabilitiesSchema,
|
|
83
136
|
listing: v.optional(cloudListingSchema),
|
|
137
|
+
/**
|
|
138
|
+
* The oldest editor version the server works with. Older editors ask to be updated instead of
|
|
139
|
+
* connecting, and the server refuses their requests.
|
|
140
|
+
*/
|
|
141
|
+
minimumEditorVersion: v.optional(cloudEditorVersionSchema),
|
|
84
142
|
/** The services editors reach with Cloud-signed tokens; absent when the deployment has none. */
|
|
85
143
|
services: v.optional(cloudServicesDiscoverySchema),
|
|
86
144
|
/** Where people manage their plan and buy credits; absent when the deployment does not bill. */
|
|
87
145
|
billing: v.optional(cloudBillingDiscoverySchema),
|
|
88
|
-
|
|
146
|
+
/** The community gallery; absent when the deployment has none. */
|
|
147
|
+
community: v.optional(cloudCommunityDiscoverySchema),
|
|
148
|
+
legal: v.optional(cloudLegalDiscoverySchema),
|
|
149
|
+
branding: v.optional(cloudBrandingSchema)
|
|
89
150
|
})
|
|
90
151
|
export type CloudDiscovery = v.InferOutput<typeof cloudDiscoverySchema>
|
|
91
152
|
|
|
@@ -26,3 +26,13 @@ export const workspaceEntitlementsSchema = v.object({
|
|
|
26
26
|
})
|
|
27
27
|
})
|
|
28
28
|
export type WorkspaceEntitlements = v.InferOutput<typeof workspaceEntitlementsSchema>
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An account's own plan and the storage its workspaces hold together. A workspace reports the
|
|
32
|
+
* same for its owner, so the two read alike.
|
|
33
|
+
*/
|
|
34
|
+
export const accountEntitlementsSchema = workspaceEntitlementsSchema
|
|
35
|
+
export type AccountEntitlements = WorkspaceEntitlements
|
|
36
|
+
export const accountEntitlementsResponseSchema = v.object({
|
|
37
|
+
entitlements: accountEntitlementsSchema
|
|
38
|
+
})
|
package/src/contract/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './account'
|
|
2
|
+
export * from './locale'
|
|
2
3
|
export {
|
|
3
4
|
SERVICE_ERROR_STATUS,
|
|
4
5
|
serviceCatalogSchema,
|
|
@@ -23,7 +24,6 @@ export {
|
|
|
23
24
|
CLOUD_SERVICES_JWKS_PATH,
|
|
24
25
|
CLOUD_SERVICES_TOKEN_AUDIENCE,
|
|
25
26
|
cloudServicesDiscoverySchema,
|
|
26
|
-
cloudBillingDiscoverySchema,
|
|
27
27
|
createServicesTokenSchema,
|
|
28
28
|
parseUsageQuery,
|
|
29
29
|
parseSearchRequest,
|
|
@@ -45,11 +45,42 @@ export {
|
|
|
45
45
|
type SearchResult,
|
|
46
46
|
type SearchResponse,
|
|
47
47
|
type CloudServicesDiscovery,
|
|
48
|
-
type CloudBillingDiscovery,
|
|
49
48
|
type CreateServicesTokenInput,
|
|
50
49
|
type CloudServicesAPI,
|
|
51
|
-
type CloudServicesSchema
|
|
50
|
+
type CloudServicesSchema,
|
|
51
|
+
sendsTokenSafely
|
|
52
52
|
} from './services'
|
|
53
|
+
export {
|
|
54
|
+
BILLING_ERROR_STATUS,
|
|
55
|
+
CLOUD_ACCOUNT_PLAN_PATH,
|
|
56
|
+
CLOUD_BILLING_API_PATHS,
|
|
57
|
+
CLOUD_BILLING_CONTRACT_VERSION,
|
|
58
|
+
CLOUD_BILLING_TOKEN_AUDIENCE,
|
|
59
|
+
billingAccountSchema,
|
|
60
|
+
billingCatalogSchema,
|
|
61
|
+
billingErrorCodeSchema,
|
|
62
|
+
billingErrorSchema,
|
|
63
|
+
billingPlanSchema,
|
|
64
|
+
billingRedirectSchema,
|
|
65
|
+
billingTokenClaimsSchema,
|
|
66
|
+
billingTokenSchema,
|
|
67
|
+
checkoutRequestSchema,
|
|
68
|
+
cloudBillingDiscoverySchema,
|
|
69
|
+
creditPackSchema,
|
|
70
|
+
type BillingAccount,
|
|
71
|
+
type BillingCatalog,
|
|
72
|
+
type BillingError,
|
|
73
|
+
type BillingErrorCode,
|
|
74
|
+
type BillingPlan,
|
|
75
|
+
type BillingRedirect,
|
|
76
|
+
type BillingToken,
|
|
77
|
+
type BillingTokenClaims,
|
|
78
|
+
type CheckoutRequest,
|
|
79
|
+
type CloudBillingAPI,
|
|
80
|
+
type CloudBillingDiscovery,
|
|
81
|
+
type CloudBillingSchema,
|
|
82
|
+
type CreditPack
|
|
83
|
+
} from './billing'
|
|
53
84
|
export * from './admin'
|
|
54
85
|
export {
|
|
55
86
|
cloudPresenceSchema,
|
|
@@ -60,22 +91,34 @@ export {
|
|
|
60
91
|
type CollaborationTicket
|
|
61
92
|
} from './collaboration'
|
|
62
93
|
export * from './relay'
|
|
63
|
-
export {
|
|
94
|
+
export {
|
|
95
|
+
accountEntitlementsResponseSchema,
|
|
96
|
+
accountEntitlementsSchema,
|
|
97
|
+
workspaceEntitlementsSchema,
|
|
98
|
+
type AccountEntitlements,
|
|
99
|
+
type WorkspaceEntitlements
|
|
100
|
+
} from './entitlements'
|
|
64
101
|
export {
|
|
65
102
|
CLOUD_DISCOVERY_PATH,
|
|
103
|
+
CLOUD_EDITOR_VERSION_HEADER,
|
|
66
104
|
CLOUD_PROTOCOL_VERSION,
|
|
67
105
|
cloudAuthenticationSchema,
|
|
106
|
+
cloudBrandingSchema,
|
|
68
107
|
cloudCapabilitiesSchema,
|
|
69
108
|
cloudDeploymentSchema,
|
|
109
|
+
cloudCommunityDiscoverySchema,
|
|
70
110
|
cloudDiscoverySchema,
|
|
71
111
|
cloudEditorVersionSchema,
|
|
72
112
|
cloudLegalDiscoverySchema,
|
|
73
113
|
cloudListingSchema,
|
|
74
114
|
cloudServerOrigin,
|
|
115
|
+
isEditorVersionAtLeast,
|
|
75
116
|
parseCloudDiscovery,
|
|
76
117
|
type CloudAuthentication,
|
|
118
|
+
type CloudBranding,
|
|
77
119
|
type CloudCapabilities,
|
|
78
120
|
type CloudDeployment,
|
|
121
|
+
type CloudCommunityDiscovery,
|
|
79
122
|
type CloudDiscovery,
|
|
80
123
|
type CloudLegalDiscovery,
|
|
81
124
|
type CloudListing
|
|
@@ -208,17 +251,23 @@ export {
|
|
|
208
251
|
type WorkspaceSummary
|
|
209
252
|
} from './workspaces'
|
|
210
253
|
export {
|
|
254
|
+
CLOUD_COMMUNITY_PATH,
|
|
255
|
+
cloudCommunityDesktopLinkURL,
|
|
256
|
+
cloudCommunityPagePath,
|
|
211
257
|
cloudDesktopLinkURL,
|
|
212
258
|
cloudDocumentPath,
|
|
213
259
|
cloudDocumentURL,
|
|
214
260
|
cloudInvitationURL,
|
|
215
261
|
cloudShareURL,
|
|
216
262
|
parseCloudLinkPath,
|
|
263
|
+
cloudCommunityPath,
|
|
264
|
+
cloudCommunityURL,
|
|
217
265
|
type CloudLinkKind,
|
|
218
266
|
type CloudLinkPathKind
|
|
219
267
|
} from './links'
|
|
220
|
-
export { CLOUD_PORTAL_PAGE_ROOTS, isCloudPortalPage } from './portal'
|
|
268
|
+
export { CLOUD_PORTAL_COMMUNITY_PAGES, CLOUD_PORTAL_PAGE_ROOTS, isCloudPortalPage } from './portal'
|
|
221
269
|
export * from './versions'
|
|
270
|
+
export * from './community'
|
|
222
271
|
export {
|
|
223
272
|
DOCUMENT_REPORT_DESCRIPTION_MAX,
|
|
224
273
|
documentReportReasonSchema,
|
package/src/contract/links.ts
CHANGED
|
@@ -3,10 +3,18 @@ import { encodeParam, parseURL, withFragment, withQuery } from 'ufo'
|
|
|
3
3
|
/** The two kinds of Cloud link that carry a secret: invitations and documents shared by link. */
|
|
4
4
|
export type CloudLinkKind = 'invitations' | 'share'
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Every kind of Cloud link: those that carry a secret, a document's address for members, and a
|
|
8
|
+
* document of the server's community gallery, which anyone may open.
|
|
9
|
+
*/
|
|
10
|
+
export type CloudLinkPathKind = CloudLinkKind | 'documents' | 'community'
|
|
8
11
|
|
|
9
12
|
const CLOUD_LINK_PATH = /^\/(invitations|share|documents)\/([^/]+)$/
|
|
13
|
+
/** A community document opened in the editor; `/community/:id` alone is its page. */
|
|
14
|
+
const COMMUNITY_EDITOR_PATH = /^\/community\/([^/]+)\/open$/
|
|
15
|
+
|
|
16
|
+
/** The server's community gallery: every document in it, each with a page of its own. */
|
|
17
|
+
export const CLOUD_COMMUNITY_PATH = '/community'
|
|
10
18
|
|
|
11
19
|
/**
|
|
12
20
|
* A link on the server's own editor. The server is the link's own address, so the link needs
|
|
@@ -55,6 +63,29 @@ export function cloudDocumentPath(documentId: string): string {
|
|
|
55
63
|
return `/documents/${encodeParam(documentId)}`
|
|
56
64
|
}
|
|
57
65
|
|
|
66
|
+
/**
|
|
67
|
+
* A document of the server's community gallery opened in the editor, `/community/:id/open`, or
|
|
68
|
+
* one of its named versions with `?version=…`, which anyone opens read-only without signing in.
|
|
69
|
+
*/
|
|
70
|
+
export function cloudCommunityURL(
|
|
71
|
+
serverURL: string,
|
|
72
|
+
documentId: string,
|
|
73
|
+
versionId: string | null = null
|
|
74
|
+
): string {
|
|
75
|
+
return serverLink(serverURL, cloudCommunityPath(documentId), {
|
|
76
|
+
version: versionId ?? undefined
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function cloudCommunityPath(documentId: string): string {
|
|
81
|
+
return `${cloudCommunityPagePath(documentId)}/open`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A community document's page on the server: its preview, versions, and ways to open it. */
|
|
85
|
+
export function cloudCommunityPagePath(documentId: string): string {
|
|
86
|
+
return `${CLOUD_COMMUNITY_PATH}/${encodeParam(documentId)}`
|
|
87
|
+
}
|
|
88
|
+
|
|
58
89
|
/**
|
|
59
90
|
* The kind and ID of a Cloud link's path, or null for any other path. The ID is decoded; a broken
|
|
60
91
|
* escape such as `%E0` is no link.
|
|
@@ -62,8 +93,16 @@ export function cloudDocumentPath(documentId: string): string {
|
|
|
62
93
|
export function parseCloudLinkPath(
|
|
63
94
|
pathname: string
|
|
64
95
|
): { kind: CloudLinkPathKind; id: string } | null {
|
|
65
|
-
const
|
|
66
|
-
|
|
96
|
+
const community = pathname.match(COMMUNITY_EDITOR_PATH)
|
|
97
|
+
const [, kind, id] = community
|
|
98
|
+
? [pathname, 'community' as const, community[1]]
|
|
99
|
+
: (pathname.match(CLOUD_LINK_PATH) ?? [])
|
|
100
|
+
if (
|
|
101
|
+
(kind !== 'invitations' && kind !== 'share' && kind !== 'documents' && kind !== 'community') ||
|
|
102
|
+
!id
|
|
103
|
+
) {
|
|
104
|
+
return null
|
|
105
|
+
}
|
|
67
106
|
try {
|
|
68
107
|
return { kind, id: decodeURIComponent(id) }
|
|
69
108
|
} catch {
|
|
@@ -85,3 +124,17 @@ export function cloudDesktopLinkURL(
|
|
|
85
124
|
const link = serverLink(serverURL, `/${kind}/${encodeParam(id)}`)
|
|
86
125
|
return withFragment(withQuery('openpencil://cloud', { url: link }), secret)
|
|
87
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The desktop app's form of a community document's link, `openpencil://cloud?url=<link>`: the
|
|
130
|
+
* editor's address for it, with the named version it asks for, if any. It carries no secret.
|
|
131
|
+
*/
|
|
132
|
+
export function cloudCommunityDesktopLinkURL(
|
|
133
|
+
documentId: string,
|
|
134
|
+
serverURL: string,
|
|
135
|
+
versionId: string | null = null
|
|
136
|
+
): string {
|
|
137
|
+
return withQuery('openpencil://cloud', {
|
|
138
|
+
url: cloudCommunityURL(serverURL, documentId, versionId)
|
|
139
|
+
})
|
|
140
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
/** Whether `tag` is a well-formed BCP 47 language tag: `de`, `pt-BR`, `zh-Hant-TW`. */
|
|
4
|
+
function isLanguageTag(tag: string): boolean {
|
|
5
|
+
try {
|
|
6
|
+
return Intl.getCanonicalLocales(tag).length === 1
|
|
7
|
+
} catch {
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A language as the app names it, which the server writes email in when it has that language, or
|
|
14
|
+
* the nearest it has, and otherwise in English.
|
|
15
|
+
*/
|
|
16
|
+
export const cloudLanguageTagSchema = v.pipe(
|
|
17
|
+
v.string(),
|
|
18
|
+
v.maxLength(35),
|
|
19
|
+
v.check(isLanguageTag, 'Not a language tag')
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
/** The language an account's email is written in, as the app last said it uses. */
|
|
23
|
+
export const cloudLocaleUpdateSchema = v.object({ locale: cloudLanguageTagSchema })
|
|
24
|
+
|
|
25
|
+
export function parseCloudLocaleUpdate(input: unknown) {
|
|
26
|
+
return v.parse(cloudLocaleUpdateSchema, input)
|
|
27
|
+
}
|
package/src/contract/portal.ts
CHANGED
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export const CLOUD_PORTAL_PAGE_ROOTS = ['/welcome', '/auth', '/account', '/admin'] as const
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* The community gallery's pages, which the portal serves too: the gallery at `/community` and a
|
|
11
|
+
* document's page at `/community/:id`. The editor opens a document at `/community/:id/open`.
|
|
12
|
+
*/
|
|
13
|
+
export const CLOUD_PORTAL_COMMUNITY_PAGES = ['/community', '/community/:documentId'] as const
|
|
14
|
+
|
|
15
|
+
const COMMUNITY_PAGE = /^\/community(?:\/[^/]+)?\/?$/
|
|
16
|
+
|
|
9
17
|
export function isCloudPortalPage(path: string): boolean {
|
|
10
|
-
return
|
|
18
|
+
return (
|
|
19
|
+
COMMUNITY_PAGE.test(path) ||
|
|
20
|
+
CLOUD_PORTAL_PAGE_ROOTS.some((root) => path === root || path.startsWith(`${root}/`))
|
|
21
|
+
)
|
|
11
22
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TypedResponse } from 'hono'
|
|
2
|
+
import type { BlankInput, ToSchema } from 'hono/types'
|
|
3
|
+
|
|
4
|
+
/** A route's input, and the JSON it answers with a 200, as a contract's typed Hono schema names it. */
|
|
5
|
+
export type JSONRoute<
|
|
6
|
+
Method extends string,
|
|
7
|
+
Path extends string,
|
|
8
|
+
Input extends BlankInput,
|
|
9
|
+
Output
|
|
10
|
+
> = ToSchema<Method, Path, Input, TypedResponse<Output, 200, 'json'>>
|
package/src/contract/services.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { Hono
|
|
2
|
-
import type { BlankEnv, BlankInput
|
|
1
|
+
import type { Hono } from 'hono'
|
|
2
|
+
import type { BlankEnv, BlankInput } from 'hono/types'
|
|
3
3
|
import * as v from 'valibot'
|
|
4
4
|
|
|
5
|
+
import type { JSONRoute } from './routes'
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* The contract between editors, Cloud, and the services Cloud advertises: AI models today, and
|
|
7
9
|
* other paid capabilities such as image generation and search as they arrive. Cloud only
|
|
@@ -37,9 +39,6 @@ export const cloudServicesDiscoverySchema = v.object({
|
|
|
37
39
|
})
|
|
38
40
|
export type CloudServicesDiscovery = v.InferOutput<typeof cloudServicesDiscoverySchema>
|
|
39
41
|
|
|
40
|
-
export const cloudBillingDiscoverySchema = v.object({ portalURL: urlSchema })
|
|
41
|
-
export type CloudBillingDiscovery = v.InferOutput<typeof cloudBillingDiscoverySchema>
|
|
42
|
-
|
|
43
42
|
export const createServicesTokenSchema = v.object({ workspaceId: v.pipe(v.string(), v.uuid()) })
|
|
44
43
|
export type CreateServicesTokenInput = v.InferOutput<typeof createServicesTokenSchema>
|
|
45
44
|
|
|
@@ -61,10 +60,9 @@ export const servicesTokenClaimsSchema = v.object({
|
|
|
61
60
|
workspaceId: v.pipe(v.string(), v.uuid()),
|
|
62
61
|
/**
|
|
63
62
|
* The account whose credits the request spends: the workspace's owner, whose allowance every
|
|
64
|
-
* workspace they own shares.
|
|
65
|
-
* a relay takes as the workspace's own allowance, as such a Cloud meant.
|
|
63
|
+
* workspace they own shares.
|
|
66
64
|
*/
|
|
67
|
-
accountId: v.
|
|
65
|
+
accountId: v.pipe(v.string(), v.minLength(1)),
|
|
68
66
|
/** Credits the owner's plan grants each month; `null` when Cloud sets no allowance. */
|
|
69
67
|
monthlyCreditAllowance: v.nullable(creditsSchema),
|
|
70
68
|
iat: v.pipe(v.number(), v.integer()),
|
|
@@ -202,14 +200,6 @@ export const SERVICE_ERROR_STATUS = {
|
|
|
202
200
|
rate_limited: 429
|
|
203
201
|
} as const satisfies Record<ServiceErrorCode, number>
|
|
204
202
|
|
|
205
|
-
/** A route's input, and the JSON it answers with a 200. */
|
|
206
|
-
type JSONRoute<
|
|
207
|
-
Method extends string,
|
|
208
|
-
Path extends string,
|
|
209
|
-
Input extends BlankInput,
|
|
210
|
-
Output
|
|
211
|
-
> = ToSchema<Method, Path, Input, TypedResponse<Output, 200, 'json'>>
|
|
212
|
-
|
|
213
203
|
/**
|
|
214
204
|
* Every route a service answers besides chat completions, which OpenAI-compatible clients call
|
|
215
205
|
* themselves. Editors build a typed client from it with Hono's `hc`; a service's own app must
|
|
@@ -231,3 +221,15 @@ export type CloudServicesSchema = JSONRoute<
|
|
|
231
221
|
>
|
|
232
222
|
|
|
233
223
|
export type CloudServicesAPI = Hono<BlankEnv, CloudServicesSchema>
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Whether a bearer token may travel to `url`: over HTTPS, or in the clear only to a loopback
|
|
227
|
+
* address, for development. Only literal addresses count, since a name such as `localhost` is
|
|
228
|
+
* whatever the resolver answers. Services and billing tokens act as the account until they expire.
|
|
229
|
+
*/
|
|
230
|
+
export function sendsTokenSafely(url: string | URL): boolean {
|
|
231
|
+
const { protocol, hostname } = new URL(url)
|
|
232
|
+
if (protocol === 'https:') return true
|
|
233
|
+
if (protocol !== 'http:') return false
|
|
234
|
+
return hostname === '[::1]' || /^127(\.\d{1,3}){3}$/.test(hostname)
|
|
235
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createI18n, type Components, type Messages } from '@nanostores/i18n'
|
|
2
|
+
import { mapValues } from 'es-toolkit'
|
|
3
|
+
import { parseAccept } from 'hono/utils/accept'
|
|
4
|
+
import { atom, type StoreValue } from 'nanostores'
|
|
5
|
+
|
|
6
|
+
import ar from './locales/ar.json'
|
|
7
|
+
import de from './locales/de.json'
|
|
8
|
+
import es from './locales/es.json'
|
|
9
|
+
import fr from './locales/fr.json'
|
|
10
|
+
import it from './locales/it.json'
|
|
11
|
+
import ja from './locales/ja.json'
|
|
12
|
+
import pl from './locales/pl.json'
|
|
13
|
+
import ptBR from './locales/pt-br.json'
|
|
14
|
+
import ru from './locales/ru.json'
|
|
15
|
+
import zhCN from './locales/zh-cn.json'
|
|
16
|
+
import { emailMessageDefaults } from './messages'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Each language's translations of `emailMessageDefaults`, bundled so a Worker reads no files. They
|
|
20
|
+
* are what Cloud writes in: a language is supported once its file is here.
|
|
21
|
+
*/
|
|
22
|
+
const TRANSLATIONS = {
|
|
23
|
+
ar,
|
|
24
|
+
de,
|
|
25
|
+
es,
|
|
26
|
+
fr,
|
|
27
|
+
it,
|
|
28
|
+
ja,
|
|
29
|
+
pl,
|
|
30
|
+
'pt-BR': ptBR,
|
|
31
|
+
ru,
|
|
32
|
+
'zh-CN': zhCN
|
|
33
|
+
} satisfies Record<string, Record<string, string>>
|
|
34
|
+
|
|
35
|
+
/** A language Cloud writes email in: English, or one it has translations for. */
|
|
36
|
+
export type EmailLocale = 'en' | keyof typeof TRANSLATIONS
|
|
37
|
+
|
|
38
|
+
/** Every language Cloud writes email in, English first. */
|
|
39
|
+
export const EMAIL_LOCALES: readonly EmailLocale[] = ['en', ...typedKeys(TRANSLATIONS)]
|
|
40
|
+
|
|
41
|
+
function typedKeys<Value extends object>(value: Value): Array<keyof Value & string> {
|
|
42
|
+
return Object.keys(value).filter((key): key is keyof Value & string => key in value)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isEmailLocale(value: unknown): value is EmailLocale {
|
|
46
|
+
return EMAIL_LOCALES.some((code) => code === value)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A tag's language and script, as Unicode's likely subtags fill them in: `zh-TW` is `zh-Hant`. */
|
|
50
|
+
function languageScript(tag: string): string | null {
|
|
51
|
+
try {
|
|
52
|
+
const { language, script } = new Intl.Locale(tag).maximize()
|
|
53
|
+
return `${language}-${script ?? ''}`
|
|
54
|
+
} catch {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The first of someone's languages Cloud writes in: the same tag, or the same language in the same
|
|
61
|
+
* script, so `de-AT` reads German and `zh-TW`, written in Traditional, doesn't read Simplified.
|
|
62
|
+
*/
|
|
63
|
+
export function emailLocale(languages: readonly string[]): EmailLocale | null {
|
|
64
|
+
const byTag = new Map(EMAIL_LOCALES.map((code) => [code.toLowerCase(), code]))
|
|
65
|
+
const byScript = new Map(EMAIL_LOCALES.map((code) => [languageScript(code), code]))
|
|
66
|
+
for (const language of languages) {
|
|
67
|
+
const match = byTag.get(language.toLowerCase()) ?? byScript.get(languageScript(language))
|
|
68
|
+
if (match) return match
|
|
69
|
+
}
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Locales written right to left. */
|
|
74
|
+
const RIGHT_TO_LEFT: ReadonlySet<EmailLocale> = new Set<EmailLocale>(['ar'])
|
|
75
|
+
|
|
76
|
+
const RIGHT_TO_LEFT_MARK = String.fromCodePoint(0x200f)
|
|
77
|
+
const FIRST_STRONG_ISOLATE = String.fromCodePoint(0x2068)
|
|
78
|
+
const POP_DIRECTIONAL_ISOLATE = String.fromCodePoint(0x2069)
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Right-to-left messages as the app shows them: each between right-to-left marks, so punctuation
|
|
82
|
+
* after a Latin name ends the sentence on its left, and each placeholder isolated, so a name or
|
|
83
|
+
* address put into it keeps its own order: `report.pdf`, not `pdf.report`.
|
|
84
|
+
*/
|
|
85
|
+
function directed(messages: Record<string, string>): Record<string, string> {
|
|
86
|
+
return mapValues(messages, (message) => {
|
|
87
|
+
const isolated = message.replaceAll(
|
|
88
|
+
/\{\w+\}/g,
|
|
89
|
+
(placeholder) => `${FIRST_STRONG_ISOLATE}${placeholder}${POP_DIRECTIONAL_ISOLATE}`
|
|
90
|
+
)
|
|
91
|
+
return `${RIGHT_TO_LEFT_MARK}${isolated}${RIGHT_TO_LEFT_MARK}`
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type EmailMessages = StoreValue<Messages<typeof emailMessageDefaults>>
|
|
96
|
+
|
|
97
|
+
/** The words, formats, and direction of email written in one locale. */
|
|
98
|
+
export type EmailLocalization = {
|
|
99
|
+
locale: EmailLocale
|
|
100
|
+
dir: 'ltr' | 'rtl'
|
|
101
|
+
t: EmailMessages
|
|
102
|
+
/** A moment in UTC, as Cloud doesn't know the reader's time zone: 13 November 2026, 10:00 UTC. */
|
|
103
|
+
dateTime: (iso: string) => string
|
|
104
|
+
/** Bytes in binary units, as the portal shows them: 300 MB, 10 GB. */
|
|
105
|
+
storage: (bytes: number) => string
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const STORAGE_UNITS = [
|
|
109
|
+
{ unit: 'gigabyte', bytes: 1024 ** 3 },
|
|
110
|
+
{ unit: 'megabyte', bytes: 1024 ** 2 },
|
|
111
|
+
{ unit: 'kilobyte', bytes: 1024 }
|
|
112
|
+
] as const
|
|
113
|
+
|
|
114
|
+
function messages(locale: EmailLocale): EmailMessages {
|
|
115
|
+
const translations: Record<string, Components> =
|
|
116
|
+
locale === 'en'
|
|
117
|
+
? {}
|
|
118
|
+
: {
|
|
119
|
+
[locale]: {
|
|
120
|
+
email: RIGHT_TO_LEFT.has(locale) ? directed(TRANSLATIONS[locale]) : TRANSLATIONS[locale]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Every translation is in the cache, so nothing is ever fetched.
|
|
124
|
+
const i18n = createI18n(atom(locale), {
|
|
125
|
+
baseLocale: 'en',
|
|
126
|
+
cache: translations,
|
|
127
|
+
get: async () => ({})
|
|
128
|
+
})
|
|
129
|
+
return i18n('email', emailMessageDefaults).get()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const localizations = new Map<EmailLocale, EmailLocalization>()
|
|
133
|
+
|
|
134
|
+
export function emailLocalization(locale: EmailLocale): EmailLocalization {
|
|
135
|
+
const cached = localizations.get(locale)
|
|
136
|
+
if (cached) return cached
|
|
137
|
+
const dateTime = new Intl.DateTimeFormat(locale, {
|
|
138
|
+
year: 'numeric',
|
|
139
|
+
month: 'long',
|
|
140
|
+
day: 'numeric',
|
|
141
|
+
hour: 'numeric',
|
|
142
|
+
minute: '2-digit',
|
|
143
|
+
timeZone: 'UTC',
|
|
144
|
+
timeZoneName: 'short'
|
|
145
|
+
})
|
|
146
|
+
const localization: EmailLocalization = {
|
|
147
|
+
locale,
|
|
148
|
+
dir: RIGHT_TO_LEFT.has(locale) ? 'rtl' : 'ltr',
|
|
149
|
+
t: messages(locale),
|
|
150
|
+
dateTime: (iso) => dateTime.format(new Date(iso)),
|
|
151
|
+
storage: (bytes) => {
|
|
152
|
+
const { unit, bytes: size } = STORAGE_UNITS.find((step) => bytes >= step.bytes) ?? {
|
|
153
|
+
unit: 'byte',
|
|
154
|
+
bytes: 1
|
|
155
|
+
}
|
|
156
|
+
return new Intl.NumberFormat(locale, {
|
|
157
|
+
style: 'unit',
|
|
158
|
+
unit,
|
|
159
|
+
unitDisplay: 'short',
|
|
160
|
+
maximumFractionDigits: 1
|
|
161
|
+
}).format(bytes / size)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
localizations.set(locale, localization)
|
|
165
|
+
return localization
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The language an `Accept-Language` header prefers among Cloud's, or null when it names none. */
|
|
169
|
+
export function acceptedLocale(header: string | null | undefined): EmailLocale | null {
|
|
170
|
+
const languages = parseAccept(header ?? '')
|
|
171
|
+
.filter((language) => language.q > 0)
|
|
172
|
+
.map((language) => language.type)
|
|
173
|
+
return emailLocale(languages)
|
|
174
|
+
}
|
package/src/email/index.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
acceptedLocale,
|
|
3
|
+
EMAIL_LOCALES,
|
|
4
|
+
emailLocale,
|
|
5
|
+
emailLocalization,
|
|
6
|
+
isEmailLocale,
|
|
7
|
+
type EmailLocale,
|
|
8
|
+
type EmailLocalization,
|
|
9
|
+
type EmailMessages
|
|
10
|
+
} from './i18n'
|
|
11
|
+
export { emailMessageDefaults } from './messages'
|
|
12
|
+
export { renderTransactionalEmail, renderWaitlistConfirmation } from './render'
|
|
13
|
+
export { EMAIL_SAMPLE_URL, EMAIL_SAMPLES } from './samples'
|
|
3
14
|
export { transactionalEmailContentSchema } from './schema'
|
|
4
15
|
export type {
|
|
5
16
|
AdminEnrollmentNotificationPayload,
|