@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,4 +1,5 @@
|
|
|
1
1
|
import type { FileDocumentReportInput } from '#cloud/contract'
|
|
2
|
+
import type { EmailLocale } from '#cloud/email'
|
|
2
3
|
import type { CloudActor } from '#cloud/server/auth'
|
|
3
4
|
import type { CloudDatabase } from '#cloud/server/db'
|
|
4
5
|
import type { TransactionalEmailService } from '#cloud/server/email'
|
|
@@ -41,7 +42,13 @@ export function createDocumentReportService(
|
|
|
41
42
|
* tells the deployment's administrators. It answers nothing about the document, so a report
|
|
42
43
|
* never tells its reporter more than the link already did.
|
|
43
44
|
*/
|
|
44
|
-
async file(
|
|
45
|
+
async file(
|
|
46
|
+
shareId: string,
|
|
47
|
+
input: FileDocumentReportInput,
|
|
48
|
+
actor?: CloudActor,
|
|
49
|
+
/** The language the reporter's browser asked for, to reply in without an account's own. */
|
|
50
|
+
replyLocale: EmailLocale | null = null
|
|
51
|
+
): Promise<void> {
|
|
45
52
|
const resolved = await options.sharing.resolveShare(
|
|
46
53
|
shareId,
|
|
47
54
|
{ secret: input.secret, guestId: input.guestId },
|
|
@@ -80,6 +87,7 @@ export function createDocumentReportService(
|
|
|
80
87
|
throw new DocumentReportLimitError()
|
|
81
88
|
}
|
|
82
89
|
const id = crypto.randomUUID()
|
|
90
|
+
const replyEmail = input.replyEmail ?? actor?.email ?? null
|
|
83
91
|
await transaction
|
|
84
92
|
.insertInto('documentReport')
|
|
85
93
|
.values({
|
|
@@ -88,7 +96,8 @@ export function createDocumentReportService(
|
|
|
88
96
|
shareId,
|
|
89
97
|
reporterUserId,
|
|
90
98
|
reporterGuestId,
|
|
91
|
-
replyEmail
|
|
99
|
+
replyEmail,
|
|
100
|
+
replyLocale,
|
|
92
101
|
reason: input.reason,
|
|
93
102
|
description: input.description
|
|
94
103
|
})
|
|
@@ -99,6 +108,19 @@ export function createDocumentReportService(
|
|
|
99
108
|
.select('name')
|
|
100
109
|
.where('id', '=', resolved.documentId)
|
|
101
110
|
.executeTakeFirstOrThrow()
|
|
111
|
+
// Whoever left an address hears that the report arrived, and later what was decided.
|
|
112
|
+
if (replyEmail) {
|
|
113
|
+
await options.email.enqueue(
|
|
114
|
+
{
|
|
115
|
+
idempotencyKey: `document-report-received/${id}`,
|
|
116
|
+
kind: 'document-report-received',
|
|
117
|
+
recipientEmail: replyEmail,
|
|
118
|
+
fallbackLocale: replyLocale,
|
|
119
|
+
payload: { documentName: document.name }
|
|
120
|
+
},
|
|
121
|
+
transaction
|
|
122
|
+
)
|
|
123
|
+
}
|
|
102
124
|
for (const recipientEmail of options.adminRecipients) {
|
|
103
125
|
await options.email.enqueue(
|
|
104
126
|
{
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
UpdateDocumentShareInput
|
|
7
7
|
} from '#cloud/contract'
|
|
8
8
|
import type { CloudActor } from '#cloud/server/auth'
|
|
9
|
-
import type
|
|
9
|
+
import { isBannedNow, type CloudDatabase } from '#cloud/server/db'
|
|
10
10
|
import { DocumentNotFoundError } from '#cloud/server/documents/errors'
|
|
11
11
|
import { CLOUD_FEATURE_KEYS } from '#cloud/server/policy/keys'
|
|
12
12
|
import type { CloudPolicy } from '#cloud/server/policy/policy'
|
|
@@ -39,8 +39,7 @@ async function anyBanned(database: Kysely<CloudDatabase>, userIds: string[]): Pr
|
|
|
39
39
|
.selectFrom('user')
|
|
40
40
|
.select('id')
|
|
41
41
|
.where('id', 'in', accounts)
|
|
42
|
-
.where(
|
|
43
|
-
.where((user) => user.or([user('banExpires', 'is', null), user('banExpires', '>', new Date())]))
|
|
42
|
+
.where(isBannedNow)
|
|
44
43
|
.executeTakeFirst()
|
|
45
44
|
return banned !== undefined
|
|
46
45
|
}
|
|
@@ -13,6 +13,7 @@ import type { CloudDatabase } from '#cloud/server/db'
|
|
|
13
13
|
import { DocumentNotFoundError } from '#cloud/server/documents/errors'
|
|
14
14
|
import {
|
|
15
15
|
spendInvitationBudget,
|
|
16
|
+
type DocumentInvitationMessage,
|
|
16
17
|
type InvitationDelivery,
|
|
17
18
|
type InvitationOutbox
|
|
18
19
|
} from '#cloud/server/invitations'
|
|
@@ -140,26 +141,35 @@ export function createInvitationService(
|
|
|
140
141
|
? await Promise.all([
|
|
141
142
|
database
|
|
142
143
|
.selectFrom('user')
|
|
143
|
-
.select('name')
|
|
144
|
+
.select(['name', 'locale'])
|
|
144
145
|
.where('id', '=', userId)
|
|
145
146
|
.executeTakeFirst(),
|
|
146
147
|
database
|
|
147
148
|
.selectFrom('document')
|
|
148
149
|
.select('name')
|
|
149
150
|
.where('id', '=', documentId)
|
|
150
|
-
.executeTakeFirstOrThrow()
|
|
151
|
+
.executeTakeFirstOrThrow(),
|
|
152
|
+
database
|
|
153
|
+
.selectFrom('user')
|
|
154
|
+
.select('locale')
|
|
155
|
+
.where((expression) =>
|
|
156
|
+
expression(expression.fn('lower', [expression.ref('email')]), '=', input.email)
|
|
157
|
+
)
|
|
158
|
+
.executeTakeFirst()
|
|
151
159
|
])
|
|
152
160
|
: null
|
|
153
161
|
const acceptanceURL =
|
|
154
162
|
deliveryContext && options.publicURL
|
|
155
163
|
? cloudInvitationURL(options.publicURL, id, token)
|
|
156
164
|
: null
|
|
157
|
-
const message =
|
|
165
|
+
const message: DocumentInvitationMessage | null =
|
|
158
166
|
deliveryContext && acceptanceURL
|
|
159
167
|
? {
|
|
160
168
|
deliveryId: id,
|
|
161
169
|
recipientEmail: input.email,
|
|
162
|
-
|
|
170
|
+
// Someone without an account yet reads the inviter's language.
|
|
171
|
+
locale: deliveryContext[2]?.locale ?? deliveryContext[0]?.locale ?? 'en',
|
|
172
|
+
inviterName: deliveryContext[0]?.name ?? null,
|
|
163
173
|
documentName: deliveryContext[1].name,
|
|
164
174
|
permission: input.permission,
|
|
165
175
|
expiresAt: expiresAt.toISOString(),
|
package/src/server/validation.ts
CHANGED
|
@@ -68,6 +68,9 @@ export const workspaceMemberParams = validatedParams(
|
|
|
68
68
|
)
|
|
69
69
|
export const accountParams = validatedParams(v.object({ userId: uuidParamSchema }))
|
|
70
70
|
export const shareParams = validatedParams(v.object({ shareId: uuidParamSchema }))
|
|
71
|
+
export const communityThumbnailParams = validatedParams(
|
|
72
|
+
v.object({ documentId: uuidParamSchema, revisionId: uuidParamSchema })
|
|
73
|
+
)
|
|
71
74
|
export const invitationParams = validatedParams(v.object({ invitationId: uuidParamSchema }))
|
|
72
75
|
export const invitationContinuationParams = validatedParams(
|
|
73
76
|
v.object({ continuationId: textParamSchema })
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
import { cloudInvitationURL } from '#cloud/contract'
|
|
11
11
|
import type { CloudActor } from '#cloud/server/auth'
|
|
12
12
|
import { workspaceRoleCan, type AccessRequest } from '#cloud/server/auth/access-control'
|
|
13
|
-
import type
|
|
13
|
+
import { userIdText, type CloudDatabase } from '#cloud/server/db'
|
|
14
14
|
import type { TransactionalEmailService } from '#cloud/server/email/types'
|
|
15
15
|
import { spendInvitationBudget } from '#cloud/server/invitations'
|
|
16
16
|
import { lockStorageAllowance } from '#cloud/server/quota/storage'
|
|
@@ -199,15 +199,7 @@ export function createWorkspaceMemberService(
|
|
|
199
199
|
function memberUsers(workspaceId: string) {
|
|
200
200
|
return database
|
|
201
201
|
.selectFrom('workspaceMember')
|
|
202
|
-
.innerJoin('user', (join) =>
|
|
203
|
-
join.on((expression) =>
|
|
204
|
-
expression(
|
|
205
|
-
expression.cast(expression.ref('user.id'), 'text'),
|
|
206
|
-
'=',
|
|
207
|
-
expression.ref('workspaceMember.userId')
|
|
208
|
-
)
|
|
209
|
-
)
|
|
210
|
-
)
|
|
202
|
+
.innerJoin('user', (join) => join.onRef(userIdText, '=', 'workspaceMember.userId'))
|
|
211
203
|
.where('workspaceMember.workspaceId', '=', workspaceId)
|
|
212
204
|
}
|
|
213
205
|
|
|
@@ -231,7 +223,7 @@ export function createWorkspaceMemberService(
|
|
|
231
223
|
if (existing) throw new WorkspaceAlreadyMemberError()
|
|
232
224
|
const inviter = await database
|
|
233
225
|
.selectFrom('user')
|
|
234
|
-
.select('name')
|
|
226
|
+
.select(['name', 'locale'])
|
|
235
227
|
.where('id', '=', userId)
|
|
236
228
|
.executeTakeFirst()
|
|
237
229
|
const id = crypto.randomUUID()
|
|
@@ -268,8 +260,10 @@ export function createWorkspaceMemberService(
|
|
|
268
260
|
idempotencyKey: `workspace-invitation/${id}`,
|
|
269
261
|
kind: 'workspace-invitation',
|
|
270
262
|
recipientEmail: input.email,
|
|
263
|
+
// Someone without an account yet reads the inviter's language.
|
|
264
|
+
fallbackLocale: inviter?.locale,
|
|
271
265
|
payload: {
|
|
272
|
-
inviterName: inviter?.name ??
|
|
266
|
+
inviterName: inviter?.name ?? null,
|
|
273
267
|
workspaceName: workspace.name,
|
|
274
268
|
role: input.role,
|
|
275
269
|
expiresAt: expiresAt.toISOString(),
|
|
@@ -314,13 +308,7 @@ export function createWorkspaceMemberService(
|
|
|
314
308
|
? await database
|
|
315
309
|
.selectFrom('workspaceInvitation')
|
|
316
310
|
.leftJoin('user', (join) =>
|
|
317
|
-
join.
|
|
318
|
-
expression(
|
|
319
|
-
expression.cast(expression.ref('user.id'), 'text'),
|
|
320
|
-
'=',
|
|
321
|
-
expression.ref('workspaceInvitation.invitedBy')
|
|
322
|
-
)
|
|
323
|
-
)
|
|
311
|
+
join.onRef(userIdText, '=', 'workspaceInvitation.invitedBy')
|
|
324
312
|
)
|
|
325
313
|
.select([
|
|
326
314
|
'workspaceInvitation.id',
|
package/src/services/app.ts
CHANGED
|
@@ -232,9 +232,7 @@ export function createServicesApp(services: ServicesAppDependencies) {
|
|
|
232
232
|
await usage.record({
|
|
233
233
|
id: crypto.randomUUID(),
|
|
234
234
|
workspaceId: claims.workspaceId,
|
|
235
|
-
|
|
236
|
-
// workspace, and once Cloud upgrades, for that workspace's owner as well.
|
|
237
|
-
accountId: claims.accountId ?? null,
|
|
235
|
+
accountId: claims.accountId,
|
|
238
236
|
userId: claims.sub,
|
|
239
237
|
modelId: model.id,
|
|
240
238
|
inputTokens: tokens.inputTokens,
|
package/src/services/config.ts
CHANGED
|
@@ -112,6 +112,7 @@ export function parseServicesConfig(
|
|
|
112
112
|
maximumConcurrentRequests: config.relay.max_concurrent_requests,
|
|
113
113
|
maximumRequestBytes: config.relay.max_request_bytes,
|
|
114
114
|
databaseURL: requiredSecret(environment, config.database.url.from_env),
|
|
115
|
+
// Every trailing slash: ufo's withoutTrailingSlash removes only one.
|
|
115
116
|
upstreamURL: config.upstream.base_url.replace(/\/+$/, ''),
|
|
116
117
|
upstreamKey: requiredSecret(environment, config.upstream.api_key.from_env),
|
|
117
118
|
catalog: catalogFrom(config.catalog)
|
package/src/services/usage.ts
CHANGED
|
@@ -38,29 +38,21 @@ export class ServicesUsageCursorError extends Error {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
* Who a request spends for: the account whose allowance it draws on, and the workspace it came
|
|
43
|
-
* from, whose requests recorded before accounts carry no account and still count this month.
|
|
44
|
-
*/
|
|
41
|
+
/** Who a request spends for: the account whose allowance it draws on, and its workspace. */
|
|
45
42
|
export type CreditSpender = { accountId: string; workspaceId: string }
|
|
46
43
|
|
|
47
|
-
/** The spender a token names
|
|
48
|
-
export function spender(claims:
|
|
49
|
-
return { accountId: claims.accountId
|
|
44
|
+
/** The spender a token names. */
|
|
45
|
+
export function spender(claims: CreditSpender): CreditSpender {
|
|
46
|
+
return { accountId: claims.accountId, workspaceId: claims.workspaceId }
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
export function createServicesUsageStore(database: Kysely<ServicesDatabase>) {
|
|
53
|
-
async function spent({ accountId
|
|
50
|
+
async function spent({ accountId }: CreditSpender, now: Date): Promise<number> {
|
|
54
51
|
const { start, end } = usagePeriod(now)
|
|
55
52
|
const row = await database
|
|
56
53
|
.selectFrom('servicesUsage')
|
|
57
54
|
.select((query) => query.fn.sum<string | number | null>('credits').as('credits'))
|
|
58
|
-
.where(
|
|
59
|
-
usage.or([
|
|
60
|
-
usage('accountId', '=', accountId),
|
|
61
|
-
usage.and([usage('accountId', 'is', null), usage('workspaceId', '=', workspaceId)])
|
|
62
|
-
])
|
|
63
|
-
)
|
|
55
|
+
.where('accountId', '=', accountId)
|
|
64
56
|
.where('createdAt', '>=', start)
|
|
65
57
|
.where('createdAt', '<', end)
|
|
66
58
|
.executeTakeFirst()
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { defineComponent, type PropType } from 'vue'
|
|
2
|
-
|
|
3
|
-
import { transactionalEmailLayout } from './layout'
|
|
4
|
-
|
|
5
|
-
export type DocumentInvitationEmailProps = {
|
|
6
|
-
inviterName: string
|
|
7
|
-
documentName: string
|
|
8
|
-
permissionLabel: string
|
|
9
|
-
expiresAt: string
|
|
10
|
-
acceptanceURL: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const DocumentInvitationEmail = defineComponent({
|
|
14
|
-
props: {
|
|
15
|
-
inviterName: { type: String, required: true },
|
|
16
|
-
documentName: { type: String, required: true },
|
|
17
|
-
permissionLabel: { type: String, required: true },
|
|
18
|
-
expiresAt: { type: String, required: true },
|
|
19
|
-
acceptanceURL: { type: String, required: true }
|
|
20
|
-
} satisfies Record<
|
|
21
|
-
keyof DocumentInvitationEmailProps,
|
|
22
|
-
{ type: PropType<string>; required: true }
|
|
23
|
-
>,
|
|
24
|
-
setup(props) {
|
|
25
|
-
return () =>
|
|
26
|
-
transactionalEmailLayout({
|
|
27
|
-
preview: `${props.inviterName} invited you to ${props.permissionLabel} a document`,
|
|
28
|
-
heading: 'OpenPencil invitation',
|
|
29
|
-
message: `${props.inviterName} invited you to ${props.permissionLabel} “${props.documentName}”.`,
|
|
30
|
-
actionLabel: 'Open document',
|
|
31
|
-
actionURL: props.acceptanceURL,
|
|
32
|
-
footer: `This invitation expires ${props.expiresAt}.`
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { defineComponent, type PropType } from 'vue'
|
|
2
|
-
|
|
3
|
-
import { transactionalEmailLayout } from './layout'
|
|
4
|
-
|
|
5
|
-
export type EnrollmentEmailProps = {
|
|
6
|
-
heading: string
|
|
7
|
-
preview: string
|
|
8
|
-
message: string
|
|
9
|
-
actionLabel: string
|
|
10
|
-
actionURL: string
|
|
11
|
-
/** Small print under the button. */
|
|
12
|
-
footer?: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const EnrollmentEmail = defineComponent({
|
|
16
|
-
props: {
|
|
17
|
-
heading: { type: String, required: true },
|
|
18
|
-
preview: { type: String, required: true },
|
|
19
|
-
message: { type: String, required: true },
|
|
20
|
-
actionLabel: { type: String, required: true },
|
|
21
|
-
actionURL: { type: String, required: true },
|
|
22
|
-
footer: { type: String, required: false }
|
|
23
|
-
} satisfies Record<keyof EnrollmentEmailProps, { type: PropType<string>; required: boolean }>,
|
|
24
|
-
setup(props) {
|
|
25
|
-
return () => transactionalEmailLayout(props)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { VNode } from 'vue'
|
|
2
|
-
|
|
3
|
-
import { emailLayout } from './brand'
|
|
4
|
-
|
|
5
|
-
export type TransactionalEmailLayout = {
|
|
6
|
-
preview: string
|
|
7
|
-
heading: string
|
|
8
|
-
message: string
|
|
9
|
-
actionLabel: string
|
|
10
|
-
actionURL: string
|
|
11
|
-
footer?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Cloud's mail in the same branded layout as the waitlist's, so people know who wrote. */
|
|
15
|
-
export function transactionalEmailLayout(props: TransactionalEmailLayout): VNode {
|
|
16
|
-
const { footer, ...content } = props
|
|
17
|
-
return emailLayout({ ...content, note: footer ? { text: footer } : undefined })
|
|
18
|
-
}
|