@open-pencil/cloud 0.17.0-beta.2 → 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 +3 -2
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/{ai-relay.mjs → services.mjs} +9 -9
- package/dist/bin/services.mjs.map +1 -0
- package/dist/client.d.ts +525 -66
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1257 -654
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +1028 -481
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +1780 -31
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +3556 -325
- 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 +929 -72
- 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 +802 -927
- 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 +7166 -3101
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/runtime-node.mjs +6 -5
- package/dist/runtime-node.mjs.map +1 -1
- package/dist/server.d.ts +6525 -2205
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12500 -7613
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +8625 -2878
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +101 -79
- package/dist/server2.mjs.map +1 -1
- package/package.json +27 -9
- package/src/admin/api/routes.ts +59 -0
- package/src/admin/audit/service.ts +27 -8
- package/src/admin/documents/service.ts +431 -0
- package/src/admin/errors.ts +9 -1
- package/src/admin/index.ts +6 -0
- package/src/admin/operations/service.ts +7 -0
- package/src/admin/reports/service.ts +153 -0
- package/src/admin/schema.ts +6 -0
- package/src/client/api.ts +28 -461
- package/src/client/auth/client.ts +22 -3
- package/src/client/auth/navigation.ts +6 -5
- 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 +14 -7
- package/src/client/portal/account.ts +79 -2
- package/src/client/portal/administration.ts +56 -0
- 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 +118 -0
- package/src/client/sharing.ts +262 -0
- package/src/client/versions.ts +104 -0
- package/src/contract/account.ts +108 -2
- package/src/contract/admin/index.ts +67 -3
- package/src/contract/billing.ts +166 -0
- package/src/contract/collaboration.ts +11 -1
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +83 -4
- package/src/contract/documents.ts +27 -0
- package/src/contract/entitlements.ts +12 -2
- package/src/contract/index.ts +114 -39
- package/src/contract/links.ts +57 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/relay.ts +6 -0
- package/src/contract/reports.ts +42 -0
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +235 -0
- package/src/contract/sharing.ts +3 -9
- 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 +138 -246
- package/src/email/samples.ts +115 -0
- package/src/email/schema.ts +79 -5
- 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/errors/posthog.ts +80 -0
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/environment.ts +22 -11
- package/src/runtime/cloudflare/index.ts +1 -1
- package/src/runtime/cloudflare/logging.ts +15 -0
- package/src/runtime/cloudflare/maintenance.ts +31 -0
- package/src/runtime/cloudflare/relay/index.ts +69 -15
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +46 -13
- package/src/runtime/node/application.ts +5 -3
- package/src/runtime/node/bootstrap.ts +15 -4
- package/src/runtime/node/cleanup.ts +20 -3
- package/src/runtime/node/email/transport.ts +13 -10
- package/src/runtime/node/entitlements/main.ts +14 -11
- package/src/runtime/node/index.ts +1 -1
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/migrate.ts +5 -1
- package/src/runtime/node/relay.ts +8 -2
- package/src/runtime/node/request-id.ts +13 -0
- package/src/runtime/node/server.ts +50 -16
- package/src/runtime/node/{ai-relay → services}/main.ts +7 -7
- package/src/runtime/node/{ai-relay → services}/server.ts +18 -18
- package/src/runtime/postgres/database.ts +20 -1
- package/src/runtime/posthog/errors.ts +15 -30
- package/src/runtime/s3/objects.ts +41 -1
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +49 -6
- package/src/server/account/actions.ts +5 -0
- package/src/server/account/deletion.ts +304 -0
- package/src/server/account/routes.ts +281 -206
- package/src/server/account/terms.ts +42 -0
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +32 -5
- package/src/server/api/types.ts +2 -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-control.ts +63 -0
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/adapter.ts +32 -1
- package/src/server/auth/email.ts +4 -1
- package/src/server/auth/endpoints.ts +5 -1
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +116 -132
- package/src/server/auth/index.ts +10 -1
- 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 +27 -7
- package/src/server/cleanup/documents.ts +165 -71
- package/src/server/cleanup/revisions.ts +16 -5
- package/src/server/cleanup/uploads.ts +8 -2
- package/src/server/cleanup/worker.ts +15 -3
- package/src/server/collaboration/relay/connection.ts +4 -3
- package/src/server/collaboration/relay/documents.ts +13 -10
- package/src/server/collaboration/relay/hub.ts +77 -122
- package/src/server/collaboration/relay/log.ts +5 -2
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/service.ts +48 -33
- 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 +41 -9
- package/src/server/config/index.ts +1 -1
- package/src/server/config/public.ts +11 -4
- package/src/server/config/schema.ts +91 -277
- package/src/server/config/toml/schema.ts +307 -0
- package/src/server/db/expressions.ts +15 -1
- package/src/server/db/index.ts +1 -0
- package/src/server/db/migrate.ts +46 -116
- package/src/server/db/migrations/001_accounts.ts +79 -0
- package/src/server/db/migrations/002_workspaces.ts +48 -0
- package/src/server/db/migrations/003_storage.ts +44 -0
- package/src/server/db/migrations/004_documents.ts +193 -0
- package/src/server/db/migrations/005_sharing.ts +95 -0
- package/src/server/db/migrations/006_operations.ts +110 -0
- package/src/server/db/migrations/007_trash.ts +33 -0
- package/src/server/db/migrations/008_terms.ts +18 -0
- 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 +96 -0
- package/src/server/db/tables.ts +82 -4
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/access.ts +66 -55
- package/src/server/documents/errors.ts +7 -0
- package/src/server/documents/images.ts +2 -1
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +14 -8
- package/src/server/documents/purge.ts +75 -0
- package/src/server/documents/repository.ts +2 -0
- package/src/server/documents/routes.ts +26 -0
- package/src/server/documents/service.ts +30 -406
- package/src/server/documents/summary.ts +1 -0
- package/src/server/documents/trash.ts +203 -0
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/checkpoint.ts +2 -1
- package/src/server/documents/versions/history.ts +11 -7
- package/src/server/documents/versions/service.ts +94 -28
- 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 +51 -16
- package/src/server/index.ts +52 -16
- package/src/server/internal/index.ts +3 -3
- package/src/server/internal/routes.ts +7 -10
- package/src/server/internal/schema.ts +1 -1
- package/src/server/internal/service.ts +17 -23
- package/src/server/invitations/budget.ts +66 -0
- package/src/server/invitations/index.ts +1 -0
- package/src/server/invitations/types.ts +5 -1
- package/src/server/logging.ts +76 -0
- package/src/server/objects/types.ts +5 -0
- package/src/server/pictures/service.ts +2 -1
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +52 -27
- package/src/server/policy/index.ts +2 -1
- package/src/server/policy/keys.ts +5 -2
- package/src/server/policy/policy.ts +40 -12
- package/src/server/policy/schema.ts +2 -2
- package/src/server/policy/service.ts +78 -56
- package/src/server/policy/static.ts +5 -5
- package/src/server/policy/storage.ts +33 -0
- package/src/server/policy/workspace.ts +41 -0
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/reconcile.ts +2 -0
- package/src/server/quota/storage.ts +74 -31
- package/src/server/rate-limit/cleanup.ts +17 -5
- package/src/server/rate-limit/middleware.ts +6 -2
- package/src/server/reports/index.ts +9 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +39 -0
- package/src/server/reports/service.ts +145 -0
- package/src/server/services/errors.ts +7 -0
- package/src/server/services/index.ts +8 -0
- package/src/server/{ai → services}/keys.ts +11 -11
- package/src/server/services/routes.ts +47 -0
- package/src/server/{ai/service.ts → services/tokens.ts} +23 -20
- package/src/server/sharing/capabilities/service.ts +68 -23
- package/src/server/sharing/grants/service.ts +11 -18
- package/src/server/sharing/http.ts +4 -0
- package/src/server/sharing/invitations/service.ts +35 -15
- package/src/server/sharing/policy.ts +9 -14
- package/src/server/sharing/routes.ts +0 -16
- package/src/server/sharing/service.ts +1 -17
- package/src/server/validation.ts +4 -0
- package/src/server/workspaces/index.ts +1 -0
- package/src/server/workspaces/members.ts +91 -52
- package/src/server/workspaces/repository.ts +2 -1
- package/src/server/workspaces/routes.ts +4 -0
- package/src/{ai-relay → services}/app.ts +46 -44
- package/src/{ai-relay → services}/config.ts +26 -19
- package/src/services/db/index.ts +10 -0
- package/src/services/db/migrate.ts +37 -0
- package/src/{ai-relay/db/migrations/001_usage.ts → services/db/migrations/001_baseline.ts} +18 -7
- package/src/services/db/schema.ts +22 -0
- package/src/services/index.ts +18 -0
- package/src/{ai-relay → services}/metering.ts +2 -2
- package/src/{ai-relay → services}/usage.ts +35 -19
- package/dist/bin/ai-relay.mjs.map +0 -1
- package/src/ai-relay/db/index.ts +0 -10
- package/src/ai-relay/db/migrate.ts +0 -32
- package/src/ai-relay/db/schema.ts +0 -20
- package/src/ai-relay/index.ts +0 -18
- package/src/client/ai.ts +0 -96
- package/src/contract/ai.ts +0 -150
- 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/ai/errors.ts +0 -7
- package/src/server/ai/index.ts +0 -4
- package/src/server/ai/routes.ts +0 -43
- package/src/server/app.ts +0 -379
- package/src/server/auth/workspace-access.ts +0 -23
- package/src/server/db/migrations/001_foundation.ts +0 -164
- package/src/server/db/migrations/002_upload_cleanup_claims.ts +0 -34
- package/src/server/db/migrations/003_document_cleanup_claims.ts +0 -23
- package/src/server/db/migrations/004_document_sharing.ts +0 -82
- package/src/server/db/migrations/005_document_collaboration_epoch.ts +0 -13
- package/src/server/db/migrations/006_invitation_continuation.ts +0 -27
- package/src/server/db/migrations/007_collaboration_state.ts +0 -25
- package/src/server/db/migrations/008_storage_reservations.ts +0 -37
- package/src/server/db/migrations/009_workspace_entitlements.ts +0 -22
- package/src/server/db/migrations/010_upload_finalization.ts +0 -22
- package/src/server/db/migrations/011_upload_finalization_lease.ts +0 -12
- package/src/server/db/migrations/012_transactional_email.ts +0 -48
- package/src/server/db/migrations/013_admin_enrollment.ts +0 -54
- package/src/server/db/migrations/014_enrollment_email_kinds.ts +0 -30
- package/src/server/db/migrations/015_cloud_rate_limit.ts +0 -22
- package/src/server/db/migrations/016_auth_schema.ts +0 -16
- package/src/server/db/migrations/017_authentication_email_kinds.ts +0 -32
- package/src/server/db/migrations/018_authentication_mfa.ts +0 -78
- package/src/server/db/migrations/019_better_auth_account_issuer.ts +0 -42
- package/src/server/db/migrations/020_workspace_invitations.ts +0 -57
- package/src/server/db/migrations/021_document_versions.ts +0 -66
- package/src/server/db/migrations/022_entitlement_external_version.ts +0 -17
- package/src/server/db/migrations/023_document_images.ts +0 -61
- package/src/server/db/migrations/024_account_activity.ts +0 -66
- package/src/server/db/migrations/025_table_names.ts +0 -58
- package/src/server/db/migrations/026_user_picture.ts +0 -30
- package/src/server/db/migrations/027_document_kind.ts +0 -19
- package/src/server/db/migrations/028_collaboration_updates.ts +0 -84
- package/src/server/db/migrations/helpers.ts +0 -78
- /package/dist/bin/{ai-relay.d.mts → services.d.mts} +0 -0
package/src/client/api.ts
CHANGED
|
@@ -1,101 +1,28 @@
|
|
|
1
1
|
import type { CloudFetch } from '#cloud/client/discovery'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
accountEntitlementsResponseSchema,
|
|
4
|
+
servicesTokenSchema,
|
|
5
|
+
billingTokenSchema,
|
|
5
6
|
cloudSessionSchema,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
documentDownloadSchema,
|
|
11
|
-
objectUploadSchema,
|
|
12
|
-
documentGrantSchema,
|
|
13
|
-
documentInvitationSchema,
|
|
14
|
-
documentShareSchema,
|
|
15
|
-
documentSummarySchema,
|
|
16
|
-
documentVersionDownloadSchema,
|
|
17
|
-
documentVersionResponseSchema,
|
|
18
|
-
documentVersionsSchema,
|
|
19
|
-
restoredDocumentSchema,
|
|
20
|
-
sharedDocumentSchema,
|
|
21
|
-
invitationContinuationSchema,
|
|
22
|
-
invitationPreviewSchema,
|
|
23
|
-
resolvedDocumentShareSchema,
|
|
24
|
-
type AcceptDocumentInvitationInput,
|
|
25
|
-
type AIToken,
|
|
26
|
-
type CloudSession,
|
|
27
|
-
type CloudUserProfile,
|
|
28
|
-
type CollaborationTicket,
|
|
29
|
-
type CreateInvitationContinuationInput,
|
|
30
|
-
type InvitationContinuation,
|
|
31
|
-
type CommitUploadRequest,
|
|
32
|
-
type CreateDocumentRequest,
|
|
33
|
-
type CreateDocumentInvitationInput,
|
|
34
|
-
type CreateDocumentShareInput,
|
|
35
|
-
type CreateUploadInput,
|
|
36
|
-
type DocumentAccess,
|
|
37
|
-
type DocumentDownload,
|
|
38
|
-
type DocumentGrant,
|
|
39
|
-
type DocumentInvitation,
|
|
40
|
-
type DocumentShare,
|
|
41
|
-
type DocumentSummary,
|
|
42
|
-
type DocumentVersion,
|
|
43
|
-
type DocumentVersionDownload,
|
|
44
|
-
type DocumentVersions,
|
|
45
|
-
type DuplicateDocumentVersionInput,
|
|
46
|
-
type SaveDocumentVersionInput,
|
|
47
|
-
type UpdateDocumentVersionInput,
|
|
48
|
-
type SharedDocument,
|
|
49
|
-
type InvitationPreview,
|
|
50
|
-
type LookupCloudUserInput,
|
|
51
|
-
type PutDocumentGrantInput,
|
|
52
|
-
type ResolveDocumentShareInput,
|
|
53
|
-
type UpdateDocumentShareInput,
|
|
54
|
-
type AcceptedInvitation
|
|
7
|
+
type AccountEntitlements,
|
|
8
|
+
type ServicesToken,
|
|
9
|
+
type BillingToken,
|
|
10
|
+
type CloudSession
|
|
55
11
|
} from '#cloud/contract'
|
|
56
12
|
import type { CloudAPI, PublicCloudAPI } from '#cloud/server/api'
|
|
57
|
-
import { pickBy } from 'es-toolkit/object'
|
|
58
13
|
import { hc } from 'hono/client'
|
|
59
14
|
import * as v from 'valibot'
|
|
60
15
|
|
|
16
|
+
import { createCommunityRequests } from './community'
|
|
17
|
+
import { createDocumentRequests } from './documents'
|
|
61
18
|
import { createImageRequests } from './images'
|
|
62
19
|
import { CloudAPIError, parseResponse, responseBody, type CloudClientDiagnostic } from './response'
|
|
20
|
+
import { createSharingRequests } from './sharing'
|
|
21
|
+
import { createVersionRequests } from './versions'
|
|
63
22
|
import { createWorkspaceRequests } from './workspaces'
|
|
64
23
|
|
|
65
24
|
export { CloudAPIError, type CloudClientDiagnostic } from './response'
|
|
66
|
-
|
|
67
|
-
const documentsResponseSchema = v.object({ documents: v.array(documentSummarySchema) })
|
|
68
|
-
const sharedDocumentsResponseSchema = v.object({ documents: v.array(sharedDocumentSchema) })
|
|
69
|
-
const documentResponseSchema = v.object({ document: documentSummarySchema })
|
|
70
|
-
const downloadResponseSchema = v.object({ document: documentDownloadSchema })
|
|
71
|
-
const accessResponseSchema = v.object({ access: documentAccessSchema })
|
|
72
|
-
const sharesResponseSchema = v.object({ shares: v.array(documentShareSchema) })
|
|
73
|
-
const shareResponseSchema = v.object({ share: documentShareSchema })
|
|
74
|
-
const shareCapabilityResponseSchema = v.object({
|
|
75
|
-
share: documentShareSchema,
|
|
76
|
-
secret: v.string(),
|
|
77
|
-
path: v.string()
|
|
78
|
-
})
|
|
79
|
-
const grantsResponseSchema = v.object({ grants: v.array(documentGrantSchema) })
|
|
80
|
-
const grantResponseSchema = v.object({ grant: documentGrantSchema })
|
|
81
|
-
const acceptedResponseSchema = v.object({ accepted: acceptedInvitationSchema })
|
|
82
|
-
const invitationPreviewResponseSchema = v.object({ invitation: invitationPreviewSchema })
|
|
83
|
-
const invitationsResponseSchema = v.object({ invitations: v.array(documentInvitationSchema) })
|
|
84
|
-
const invitationCapabilityResponseSchema = v.object({
|
|
85
|
-
invitation: documentInvitationSchema,
|
|
86
|
-
token: v.string()
|
|
87
|
-
})
|
|
88
|
-
const collaborationTicketResponseSchema = v.object({ ticket: collaborationTicketSchema })
|
|
89
|
-
const resolvedShareResponseSchema = v.object({ resolution: resolvedDocumentShareSchema })
|
|
90
|
-
const sharedDocumentResponseSchema = v.object({
|
|
91
|
-
resolution: resolvedDocumentShareSchema,
|
|
92
|
-
document: documentDownloadSchema
|
|
93
|
-
})
|
|
94
|
-
const userLookupResponseSchema = v.object({ user: v.nullable(cloudUserProfileSchema) })
|
|
95
|
-
const uploadResponseSchema = v.object({
|
|
96
|
-
id: v.pipe(v.string(), v.uuid()),
|
|
97
|
-
upload: objectUploadSchema
|
|
98
|
-
})
|
|
25
|
+
export type { CloudUpload } from './documents'
|
|
99
26
|
|
|
100
27
|
export type CloudRequestOptions = {
|
|
101
28
|
fetch?: CloudFetch
|
|
@@ -104,8 +31,6 @@ export type CloudRequestOptions = {
|
|
|
104
31
|
onDiagnostic?: CloudClientDiagnostic
|
|
105
32
|
}
|
|
106
33
|
|
|
107
|
-
export type CloudUpload = v.InferOutput<typeof uploadResponseSchema>
|
|
108
|
-
|
|
109
34
|
function apiURL(baseURL: string): string {
|
|
110
35
|
const url = new URL(baseURL)
|
|
111
36
|
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
@@ -137,391 +62,33 @@ export function createCloudAPIClient(baseURL: string, options: CloudRequestOptio
|
|
|
137
62
|
if (response.status === 401) return null
|
|
138
63
|
return v.parse(cloudSessionSchema, await responseBody(response, options.onDiagnostic))
|
|
139
64
|
},
|
|
140
|
-
/** A short-lived token for the deployment's
|
|
141
|
-
async
|
|
65
|
+
/** A short-lived token for the deployment's services, on the workspace's behalf. */
|
|
66
|
+
async requestServicesToken(workspaceId: string): Promise<ServicesToken> {
|
|
142
67
|
return parseResponse(
|
|
143
|
-
client.
|
|
144
|
-
|
|
68
|
+
client.services.token.$post({ json: { workspaceId } }),
|
|
69
|
+
servicesTokenSchema,
|
|
145
70
|
options.onDiagnostic
|
|
146
71
|
)
|
|
147
72
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
): Promise<CloudUserProfile | null> {
|
|
152
|
-
const response = await parseResponse(
|
|
153
|
-
client.documents[':documentId'].users.lookup.$post({
|
|
154
|
-
param: { documentId },
|
|
155
|
-
json: input
|
|
156
|
-
}),
|
|
157
|
-
userLookupResponseSchema,
|
|
158
|
-
options.onDiagnostic
|
|
159
|
-
)
|
|
160
|
-
return response.user
|
|
73
|
+
/** A short-lived token for the deployment's billing, for the signed-in person's own account. */
|
|
74
|
+
async requestBillingToken(): Promise<BillingToken> {
|
|
75
|
+
return parseResponse(client.billing.token.$post(), billingTokenSchema, options.onDiagnostic)
|
|
161
76
|
},
|
|
162
|
-
|
|
77
|
+
/** The signed-in account's plan, and the storage its workspaces hold together. */
|
|
78
|
+
async getAccountEntitlements(): Promise<AccountEntitlements> {
|
|
163
79
|
const response = await parseResponse(
|
|
164
|
-
client.
|
|
165
|
-
|
|
166
|
-
}),
|
|
167
|
-
userLookupResponseSchema,
|
|
80
|
+
client.account.entitlements.$get(),
|
|
81
|
+
accountEntitlementsResponseSchema,
|
|
168
82
|
options.onDiagnostic
|
|
169
83
|
)
|
|
170
|
-
return response.
|
|
84
|
+
return response.entitlements
|
|
171
85
|
},
|
|
172
86
|
...createWorkspaceRequests(client, options.onDiagnostic),
|
|
173
87
|
...createImageRequests(client, publicClient, options.onDiagnostic),
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
sharedDocumentsResponseSchema,
|
|
179
|
-
options.onDiagnostic
|
|
180
|
-
)
|
|
181
|
-
return response.documents
|
|
182
|
-
},
|
|
183
|
-
async listDocuments(workspaceId: string): Promise<DocumentSummary[]> {
|
|
184
|
-
const response = await parseResponse(
|
|
185
|
-
client.workspaces[':workspaceId'].documents.$get({
|
|
186
|
-
param: { workspaceId }
|
|
187
|
-
}),
|
|
188
|
-
documentsResponseSchema,
|
|
189
|
-
options.onDiagnostic
|
|
190
|
-
)
|
|
191
|
-
return response.documents
|
|
192
|
-
},
|
|
193
|
-
async createDocument(
|
|
194
|
-
workspaceId: string,
|
|
195
|
-
input: CreateDocumentRequest
|
|
196
|
-
): Promise<DocumentSummary> {
|
|
197
|
-
const response = await parseResponse(
|
|
198
|
-
client.workspaces[':workspaceId'].documents.$post({
|
|
199
|
-
param: { workspaceId },
|
|
200
|
-
json: { ...input, kind: input.kind ?? 'design' }
|
|
201
|
-
}),
|
|
202
|
-
documentResponseSchema,
|
|
203
|
-
options.onDiagnostic
|
|
204
|
-
)
|
|
205
|
-
return response.document
|
|
206
|
-
},
|
|
207
|
-
async deleteDocument(documentId: string): Promise<void> {
|
|
208
|
-
await responseBody(
|
|
209
|
-
await client.documents[':documentId'].$delete({ param: { documentId } }),
|
|
210
|
-
options.onDiagnostic
|
|
211
|
-
)
|
|
212
|
-
},
|
|
213
|
-
async getDocument(documentId: string): Promise<DocumentDownload> {
|
|
214
|
-
const response = await parseResponse(
|
|
215
|
-
client.documents[':documentId'].$get({ param: { documentId } }),
|
|
216
|
-
downloadResponseSchema,
|
|
217
|
-
options.onDiagnostic
|
|
218
|
-
)
|
|
219
|
-
return response.document
|
|
220
|
-
},
|
|
221
|
-
async getDocumentAccess(documentId: string): Promise<DocumentAccess> {
|
|
222
|
-
const response = await parseResponse(
|
|
223
|
-
client.documents[':documentId'].access.$get({ param: { documentId } }),
|
|
224
|
-
accessResponseSchema,
|
|
225
|
-
options.onDiagnostic
|
|
226
|
-
)
|
|
227
|
-
return response.access
|
|
228
|
-
},
|
|
229
|
-
async listDocumentShares(documentId: string): Promise<DocumentShare[]> {
|
|
230
|
-
const response = await parseResponse(
|
|
231
|
-
client.documents[':documentId'].shares.$get({ param: { documentId } }),
|
|
232
|
-
sharesResponseSchema,
|
|
233
|
-
options.onDiagnostic
|
|
234
|
-
)
|
|
235
|
-
return response.shares
|
|
236
|
-
},
|
|
237
|
-
async createDocumentShare(documentId: string, input: CreateDocumentShareInput) {
|
|
238
|
-
return parseResponse(
|
|
239
|
-
client.documents[':documentId'].shares.$post({
|
|
240
|
-
param: { documentId },
|
|
241
|
-
json: input
|
|
242
|
-
}),
|
|
243
|
-
shareCapabilityResponseSchema,
|
|
244
|
-
options.onDiagnostic
|
|
245
|
-
)
|
|
246
|
-
},
|
|
247
|
-
async updateDocumentShare(
|
|
248
|
-
documentId: string,
|
|
249
|
-
shareId: string,
|
|
250
|
-
input: UpdateDocumentShareInput
|
|
251
|
-
): Promise<DocumentShare> {
|
|
252
|
-
const response = await parseResponse(
|
|
253
|
-
client.documents[':documentId'].shares[':shareId'].$patch({
|
|
254
|
-
param: { documentId, shareId },
|
|
255
|
-
json: input
|
|
256
|
-
}),
|
|
257
|
-
shareResponseSchema,
|
|
258
|
-
options.onDiagnostic
|
|
259
|
-
)
|
|
260
|
-
return response.share
|
|
261
|
-
},
|
|
262
|
-
async rotateDocumentShare(documentId: string, shareId: string) {
|
|
263
|
-
return parseResponse(
|
|
264
|
-
client.documents[':documentId'].shares[':shareId'].rotate.$post({
|
|
265
|
-
param: { documentId, shareId }
|
|
266
|
-
}),
|
|
267
|
-
shareCapabilityResponseSchema,
|
|
268
|
-
options.onDiagnostic
|
|
269
|
-
)
|
|
270
|
-
},
|
|
271
|
-
async revokeDocumentShare(documentId: string, shareId: string): Promise<void> {
|
|
272
|
-
await responseBody(
|
|
273
|
-
await client.documents[':documentId'].shares[':shareId'].$delete({
|
|
274
|
-
param: { documentId, shareId }
|
|
275
|
-
}),
|
|
276
|
-
options.onDiagnostic
|
|
277
|
-
)
|
|
278
|
-
},
|
|
279
|
-
async listDocumentGrants(documentId: string): Promise<DocumentGrant[]> {
|
|
280
|
-
const response = await parseResponse(
|
|
281
|
-
client.documents[':documentId'].grants.$get({ param: { documentId } }),
|
|
282
|
-
grantsResponseSchema,
|
|
283
|
-
options.onDiagnostic
|
|
284
|
-
)
|
|
285
|
-
return response.grants
|
|
286
|
-
},
|
|
287
|
-
async putDocumentGrant(
|
|
288
|
-
documentId: string,
|
|
289
|
-
userId: string,
|
|
290
|
-
input: PutDocumentGrantInput
|
|
291
|
-
): Promise<DocumentGrant> {
|
|
292
|
-
const response = await parseResponse(
|
|
293
|
-
client.documents[':documentId'].grants[':userId'].$put({
|
|
294
|
-
param: { documentId, userId },
|
|
295
|
-
json: input
|
|
296
|
-
}),
|
|
297
|
-
grantResponseSchema,
|
|
298
|
-
options.onDiagnostic
|
|
299
|
-
)
|
|
300
|
-
return response.grant
|
|
301
|
-
},
|
|
302
|
-
async revokeDocumentGrant(documentId: string, userId: string): Promise<void> {
|
|
303
|
-
await responseBody(
|
|
304
|
-
await client.documents[':documentId'].grants[':userId'].$delete({
|
|
305
|
-
param: { documentId, userId }
|
|
306
|
-
}),
|
|
307
|
-
options.onDiagnostic
|
|
308
|
-
)
|
|
309
|
-
},
|
|
310
|
-
async listDocumentInvitations(documentId: string): Promise<DocumentInvitation[]> {
|
|
311
|
-
const response = await parseResponse(
|
|
312
|
-
client.documents[':documentId'].invitations.$get({ param: { documentId } }),
|
|
313
|
-
invitationsResponseSchema,
|
|
314
|
-
options.onDiagnostic
|
|
315
|
-
)
|
|
316
|
-
return response.invitations
|
|
317
|
-
},
|
|
318
|
-
async createDocumentInvitation(documentId: string, input: CreateDocumentInvitationInput) {
|
|
319
|
-
return parseResponse(
|
|
320
|
-
client.documents[':documentId'].invitations.$post({
|
|
321
|
-
param: { documentId },
|
|
322
|
-
json: input
|
|
323
|
-
}),
|
|
324
|
-
invitationCapabilityResponseSchema,
|
|
325
|
-
options.onDiagnostic
|
|
326
|
-
)
|
|
327
|
-
},
|
|
328
|
-
async createInvitationContinuation(
|
|
329
|
-
input: CreateInvitationContinuationInput
|
|
330
|
-
): Promise<InvitationContinuation> {
|
|
331
|
-
return parseResponse(
|
|
332
|
-
publicClient.invitations.continuations.$post({ json: input }),
|
|
333
|
-
invitationContinuationSchema,
|
|
334
|
-
options.onDiagnostic
|
|
335
|
-
)
|
|
336
|
-
},
|
|
337
|
-
async consumeInvitationContinuation(id: string): Promise<CreateInvitationContinuationInput> {
|
|
338
|
-
return parseResponse(
|
|
339
|
-
publicClient.invitations.continuations[':continuationId'].consume.$post({
|
|
340
|
-
param: { continuationId: id }
|
|
341
|
-
}),
|
|
342
|
-
createInvitationContinuationSchema,
|
|
343
|
-
options.onDiagnostic
|
|
344
|
-
)
|
|
345
|
-
},
|
|
346
|
-
async previewInvitation(
|
|
347
|
-
invitationId: string,
|
|
348
|
-
input: AcceptDocumentInvitationInput
|
|
349
|
-
): Promise<InvitationPreview> {
|
|
350
|
-
const response = await parseResponse(
|
|
351
|
-
publicClient.invitations[':invitationId'].preview.$post({
|
|
352
|
-
param: { invitationId },
|
|
353
|
-
json: input
|
|
354
|
-
}),
|
|
355
|
-
invitationPreviewResponseSchema,
|
|
356
|
-
options.onDiagnostic
|
|
357
|
-
)
|
|
358
|
-
return response.invitation
|
|
359
|
-
},
|
|
360
|
-
/** Accepts a document or workspace invitation, and says which it was. */
|
|
361
|
-
async acceptInvitation(
|
|
362
|
-
invitationId: string,
|
|
363
|
-
input: AcceptDocumentInvitationInput
|
|
364
|
-
): Promise<AcceptedInvitation> {
|
|
365
|
-
const response = await parseResponse(
|
|
366
|
-
client.invitations[':invitationId'].accept.$post({
|
|
367
|
-
param: { invitationId },
|
|
368
|
-
json: input
|
|
369
|
-
}),
|
|
370
|
-
acceptedResponseSchema,
|
|
371
|
-
options.onDiagnostic
|
|
372
|
-
)
|
|
373
|
-
return response.accepted
|
|
374
|
-
},
|
|
375
|
-
async revokeDocumentInvitation(documentId: string, invitationId: string): Promise<void> {
|
|
376
|
-
await responseBody(
|
|
377
|
-
await client.documents[':documentId'].invitations[':invitationId'].$delete({
|
|
378
|
-
param: { documentId, invitationId }
|
|
379
|
-
}),
|
|
380
|
-
options.onDiagnostic
|
|
381
|
-
)
|
|
382
|
-
},
|
|
383
|
-
async resolveDocumentShare(shareId: string, input: ResolveDocumentShareInput) {
|
|
384
|
-
const response = await parseResponse(
|
|
385
|
-
publicClient.shares[':shareId'].resolve.$post({
|
|
386
|
-
param: { shareId },
|
|
387
|
-
json: input
|
|
388
|
-
}),
|
|
389
|
-
resolvedShareResponseSchema,
|
|
390
|
-
options.onDiagnostic
|
|
391
|
-
)
|
|
392
|
-
return response.resolution
|
|
393
|
-
},
|
|
394
|
-
async getSharedDocument(shareId: string, input: ResolveDocumentShareInput) {
|
|
395
|
-
return parseResponse(
|
|
396
|
-
publicClient.shares[':shareId'].document.$post({
|
|
397
|
-
param: { shareId },
|
|
398
|
-
json: input
|
|
399
|
-
}),
|
|
400
|
-
sharedDocumentResponseSchema,
|
|
401
|
-
options.onDiagnostic
|
|
402
|
-
)
|
|
403
|
-
},
|
|
404
|
-
async getSharedCollaborationTicket(
|
|
405
|
-
shareId: string,
|
|
406
|
-
input: ResolveDocumentShareInput
|
|
407
|
-
): Promise<CollaborationTicket> {
|
|
408
|
-
const response = await parseResponse(
|
|
409
|
-
publicClient.shares[':shareId']['collaboration-ticket'].$post({
|
|
410
|
-
param: { shareId },
|
|
411
|
-
json: input
|
|
412
|
-
}),
|
|
413
|
-
collaborationTicketResponseSchema,
|
|
414
|
-
options.onDiagnostic
|
|
415
|
-
)
|
|
416
|
-
return response.ticket
|
|
417
|
-
},
|
|
418
|
-
async getCollaborationTicket(documentId: string): Promise<CollaborationTicket> {
|
|
419
|
-
const response = await parseResponse(
|
|
420
|
-
client.documents[':documentId']['collaboration-ticket'].$post({
|
|
421
|
-
param: { documentId }
|
|
422
|
-
}),
|
|
423
|
-
collaborationTicketResponseSchema,
|
|
424
|
-
options.onDiagnostic
|
|
425
|
-
)
|
|
426
|
-
return response.ticket
|
|
427
|
-
},
|
|
428
|
-
async createUpload(documentId: string, input: CreateUploadInput): Promise<CloudUpload> {
|
|
429
|
-
return parseResponse(
|
|
430
|
-
client.documents[':documentId'].uploads.$post({
|
|
431
|
-
param: { documentId },
|
|
432
|
-
json: input
|
|
433
|
-
}),
|
|
434
|
-
uploadResponseSchema,
|
|
435
|
-
options.onDiagnostic
|
|
436
|
-
)
|
|
437
|
-
},
|
|
438
|
-
async commitUpload(uploadId: string, input: CommitUploadRequest): Promise<DocumentSummary> {
|
|
439
|
-
const response = await parseResponse(
|
|
440
|
-
client.uploads[':uploadId'].commit.$post({
|
|
441
|
-
param: { uploadId },
|
|
442
|
-
json: { ...input, images: input.images ?? [] }
|
|
443
|
-
}),
|
|
444
|
-
documentResponseSchema,
|
|
445
|
-
options.onDiagnostic
|
|
446
|
-
)
|
|
447
|
-
return response.document
|
|
448
|
-
},
|
|
449
|
-
/** A page of the document's version history, newest first. */
|
|
450
|
-
async listDocumentVersions(
|
|
451
|
-
documentId: string,
|
|
452
|
-
page: { before?: string; limit?: number } = {}
|
|
453
|
-
): Promise<DocumentVersions> {
|
|
454
|
-
return parseResponse(
|
|
455
|
-
client.documents[':documentId'].versions.$get({
|
|
456
|
-
param: { documentId },
|
|
457
|
-
query: pickBy(page, (value) => value !== undefined)
|
|
458
|
-
}),
|
|
459
|
-
documentVersionsSchema,
|
|
460
|
-
options.onDiagnostic
|
|
461
|
-
)
|
|
462
|
-
},
|
|
463
|
-
async saveDocumentVersion(
|
|
464
|
-
documentId: string,
|
|
465
|
-
input: SaveDocumentVersionInput
|
|
466
|
-
): Promise<DocumentVersion> {
|
|
467
|
-
const response = await parseResponse(
|
|
468
|
-
client.documents[':documentId'].versions.$post({ param: { documentId }, json: input }),
|
|
469
|
-
documentVersionResponseSchema,
|
|
470
|
-
options.onDiagnostic
|
|
471
|
-
)
|
|
472
|
-
return response.version
|
|
473
|
-
},
|
|
474
|
-
async updateDocumentVersion(
|
|
475
|
-
documentId: string,
|
|
476
|
-
versionId: string,
|
|
477
|
-
input: UpdateDocumentVersionInput
|
|
478
|
-
): Promise<DocumentVersion> {
|
|
479
|
-
const response = await parseResponse(
|
|
480
|
-
client.documents[':documentId'].versions[':versionId'].$patch({
|
|
481
|
-
param: { documentId, versionId },
|
|
482
|
-
json: input
|
|
483
|
-
}),
|
|
484
|
-
documentVersionResponseSchema,
|
|
485
|
-
options.onDiagnostic
|
|
486
|
-
)
|
|
487
|
-
return response.version
|
|
488
|
-
},
|
|
489
|
-
async getDocumentVersion(
|
|
490
|
-
documentId: string,
|
|
491
|
-
versionId: string
|
|
492
|
-
): Promise<DocumentVersionDownload> {
|
|
493
|
-
return parseResponse(
|
|
494
|
-
client.documents[':documentId'].versions[':versionId'].$get({
|
|
495
|
-
param: { documentId, versionId }
|
|
496
|
-
}),
|
|
497
|
-
documentVersionDownloadSchema,
|
|
498
|
-
options.onDiagnostic
|
|
499
|
-
)
|
|
500
|
-
},
|
|
501
|
-
async restoreDocumentVersion(documentId: string, versionId: string) {
|
|
502
|
-
return parseResponse(
|
|
503
|
-
client.documents[':documentId'].versions[':versionId'].restore.$post({
|
|
504
|
-
param: { documentId, versionId }
|
|
505
|
-
}),
|
|
506
|
-
restoredDocumentSchema,
|
|
507
|
-
options.onDiagnostic
|
|
508
|
-
)
|
|
509
|
-
},
|
|
510
|
-
async duplicateDocumentVersion(
|
|
511
|
-
documentId: string,
|
|
512
|
-
versionId: string,
|
|
513
|
-
input: DuplicateDocumentVersionInput
|
|
514
|
-
): Promise<DocumentSummary> {
|
|
515
|
-
const response = await parseResponse(
|
|
516
|
-
client.documents[':documentId'].versions[':versionId'].duplicate.$post({
|
|
517
|
-
param: { documentId, versionId },
|
|
518
|
-
json: input
|
|
519
|
-
}),
|
|
520
|
-
documentResponseSchema,
|
|
521
|
-
options.onDiagnostic
|
|
522
|
-
)
|
|
523
|
-
return response.document
|
|
524
|
-
}
|
|
88
|
+
...createDocumentRequests(client, options.onDiagnostic),
|
|
89
|
+
...createVersionRequests(client, options.onDiagnostic),
|
|
90
|
+
...createSharingRequests(client, publicClient, options.onDiagnostic),
|
|
91
|
+
...createCommunityRequests(publicClient, options.onDiagnostic)
|
|
525
92
|
}
|
|
526
93
|
}
|
|
527
94
|
|
|
@@ -23,11 +23,20 @@ export type CloudAuthClient = Pick<
|
|
|
23
23
|
| 'getSession'
|
|
24
24
|
| 'signIn'
|
|
25
25
|
| 'signOut'
|
|
26
|
-
| 'signUp'
|
|
27
26
|
| 'sendVerificationEmail'
|
|
28
27
|
| 'requestPasswordReset'
|
|
29
28
|
| 'resetPassword'
|
|
30
29
|
> & {
|
|
30
|
+
signUp: {
|
|
31
|
+
/** Also takes the language the server writes to the account in, a field Cloud adds. */
|
|
32
|
+
email(input: {
|
|
33
|
+
name: string
|
|
34
|
+
email: string
|
|
35
|
+
password: string
|
|
36
|
+
locale: string
|
|
37
|
+
callbackURL?: string
|
|
38
|
+
}): Promise<{ data: unknown; error: { code?: string; status: number } | null }>
|
|
39
|
+
}
|
|
31
40
|
signIn: ReturnType<typeof createAuthClient>['signIn'] & {
|
|
32
41
|
passkey(): Promise<{
|
|
33
42
|
data: unknown
|
|
@@ -157,10 +166,19 @@ export async function signInToCloudWithEmail(
|
|
|
157
166
|
return { ok: true, value: { status: 'signed-in', token: result.data.token } }
|
|
158
167
|
}
|
|
159
168
|
|
|
160
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Creates an account; the server emails a link that opens `verifiedURL` once it is confirmed,
|
|
171
|
+
* written in `locale`, the app's language.
|
|
172
|
+
*/
|
|
161
173
|
export async function signUpToCloudWithEmail(
|
|
162
174
|
discovery: CloudDiscovery,
|
|
163
|
-
input: {
|
|
175
|
+
input: {
|
|
176
|
+
name: string
|
|
177
|
+
email: string
|
|
178
|
+
password: string
|
|
179
|
+
verifiedURL: string
|
|
180
|
+
locale: string
|
|
181
|
+
},
|
|
164
182
|
options: CloudEmailAuthOptions = {}
|
|
165
183
|
): Promise<CloudAuthResult> {
|
|
166
184
|
const result = await createCloudAuthClient(discovery, options)
|
|
@@ -168,6 +186,7 @@ export async function signUpToCloudWithEmail(
|
|
|
168
186
|
name: input.name,
|
|
169
187
|
email: input.email,
|
|
170
188
|
password: input.password,
|
|
189
|
+
locale: input.locale,
|
|
171
190
|
callbackURL: input.verifiedURL
|
|
172
191
|
})
|
|
173
192
|
.catch(() => null)
|
|
@@ -18,18 +18,19 @@ export function cloudEditorReturnURL(discovery: CloudDiscovery, value: string):
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* The server's sign-in page, coming back to `returnURL` on its
|
|
22
|
-
* starts that provider's sign-in at once, while the server's pages
|
|
23
|
-
* and approval before the return.
|
|
21
|
+
* The server's sign-in page, or with `page` its sign-up page, coming back to `returnURL` on its
|
|
22
|
+
* editor afterwards. A `provider` starts that provider's sign-in at once, while the server's pages
|
|
23
|
+
* still handle two-step sign-in and approval before the return.
|
|
24
24
|
*/
|
|
25
25
|
export function cloudSignInURL(
|
|
26
26
|
discovery: CloudDiscovery,
|
|
27
27
|
returnURL: string,
|
|
28
|
-
provider?: CloudSocialProvider
|
|
28
|
+
provider?: CloudSocialProvider,
|
|
29
|
+
page: 'sign-in' | 'sign-up' = 'sign-in'
|
|
29
30
|
): string {
|
|
30
31
|
const offered = provider && discovery.authentication.socialProviders.includes(provider)
|
|
31
32
|
// The pages are at the server's root, whatever path the auth API has.
|
|
32
|
-
return withQuery(new URL(
|
|
33
|
+
return withQuery(new URL(`/auth/${page}`, discovery.authURL).href, {
|
|
33
34
|
redirect: withQuery('/auth/return', { editor: cloudEditorReturnURL(discovery, returnURL) }),
|
|
34
35
|
provider: offered ? provider : undefined
|
|
35
36
|
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { CloudFetch } from '#cloud/client/discovery'
|
|
2
|
+
import { serviceJSON } from '#cloud/client/response'
|
|
3
|
+
import { cloudServicesFetch, type CloudServicesTokenSource } from '#cloud/client/services'
|
|
4
|
+
import {
|
|
5
|
+
billingAccountSchema,
|
|
6
|
+
billingCatalogSchema,
|
|
7
|
+
billingErrorSchema,
|
|
8
|
+
billingRedirectSchema,
|
|
9
|
+
type BillingAccount,
|
|
10
|
+
type BillingCatalog,
|
|
11
|
+
type BillingErrorCode,
|
|
12
|
+
type CheckoutRequest,
|
|
13
|
+
type CloudBillingAPI
|
|
14
|
+
} from '#cloud/contract'
|
|
15
|
+
import { hc } from 'hono/client'
|
|
16
|
+
import { withoutTrailingSlash } from 'ufo'
|
|
17
|
+
import * as v from 'valibot'
|
|
18
|
+
|
|
19
|
+
export class CloudBillingError extends Error {
|
|
20
|
+
override readonly name = 'CloudBillingError'
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
readonly status: number,
|
|
24
|
+
readonly code?: BillingErrorCode
|
|
25
|
+
) {
|
|
26
|
+
super(`OpenPencil billing request failed with HTTP ${status}`)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const errorBodySchema = v.pipe(v.string(), v.parseJson(), billingErrorSchema)
|
|
31
|
+
|
|
32
|
+
function refused(status: number, body: string): CloudBillingError {
|
|
33
|
+
const error = v.safeParse(errorBodySchema, body)
|
|
34
|
+
return new CloudBillingError(status, error.success ? error.output.error.code : undefined)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type CloudBillingClientOptions = {
|
|
38
|
+
/** The billing service's endpoint, as Cloud's discovery names it. */
|
|
39
|
+
endpoint: string
|
|
40
|
+
/** Billing tokens for the signed-in person, from `requestBillingToken`. */
|
|
41
|
+
tokens: CloudServicesTokenSource
|
|
42
|
+
fetch: CloudFetch
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The billing a Cloud advertises: what it sells, the account's subscription, and where to buy or
|
|
47
|
+
* manage it. Checkout and the portal answer with the payment provider's page to open, so a token
|
|
48
|
+
* never travels in a URL.
|
|
49
|
+
*/
|
|
50
|
+
export function createCloudBillingClient(options: CloudBillingClientOptions) {
|
|
51
|
+
const endpoint = withoutTrailingSlash(options.endpoint)
|
|
52
|
+
// Answers are parsed rather than trusted: the service is deployed apart from this client.
|
|
53
|
+
const { v1 } = hc<CloudBillingAPI>(endpoint, {
|
|
54
|
+
fetch: cloudServicesFetch(options.tokens, options.fetch)
|
|
55
|
+
})
|
|
56
|
+
return {
|
|
57
|
+
async catalog(): Promise<BillingCatalog> {
|
|
58
|
+
return serviceJSON(await v1.catalog.$get(), billingCatalogSchema, refused)
|
|
59
|
+
},
|
|
60
|
+
async account(): Promise<BillingAccount> {
|
|
61
|
+
return serviceJSON(await v1.account.$get(), billingAccountSchema, refused)
|
|
62
|
+
},
|
|
63
|
+
/** The checkout page that buys `request` for the account. */
|
|
64
|
+
async checkout(request: CheckoutRequest): Promise<string> {
|
|
65
|
+
return (
|
|
66
|
+
await serviceJSON(
|
|
67
|
+
await v1.checkout.$post({ json: request }),
|
|
68
|
+
billingRedirectSchema,
|
|
69
|
+
refused
|
|
70
|
+
)
|
|
71
|
+
).url
|
|
72
|
+
},
|
|
73
|
+
/** The page where the account cancels, changes its card, and reads its invoices. */
|
|
74
|
+
async portal(): Promise<string> {
|
|
75
|
+
return (await serviceJSON(await v1.portal.$post(), billingRedirectSchema, refused)).url
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type CloudBillingClient = ReturnType<typeof createCloudBillingClient>
|