@stacksjs/defaults 0.75.544 → 0.75.548

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.
Files changed (34) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +1 -1
  2. package/ai/skills/stacks-auto-imports/SKILL.md +1 -1
  3. package/ai/skills/stacks-commerce/SKILL.md +6 -3
  4. package/ai/skills/stacks-database/SKILL.md +1 -1
  5. package/ai/skills/stacks-desktop/SKILL.md +188 -3
  6. package/ai/skills/stacks-licensing/SKILL.md +214 -0
  7. package/ai/skills/stacks-migrations/SKILL.md +2 -2
  8. package/ai/skills/stacks-models/SKILL.md +2 -2
  9. package/ai/skills/stacks-native/CATALOG.md +6 -6
  10. package/ai/skills/stacks-orm/SKILL.md +2 -2
  11. package/ai/skills/stacks-payments/SKILL.md +1 -0
  12. package/ai/skills/stacks-writing-for-agents/SKILL.md +1 -1
  13. package/app/Actions/Commerce/Licensing/LicenseActivateAction.ts +36 -0
  14. package/app/Actions/Commerce/Licensing/LicenseCheckAction.ts +31 -0
  15. package/app/Actions/Commerce/Licensing/LicenseDeactivateAction.ts +20 -0
  16. package/app/Actions/Commerce/Licensing/LicenseResendAction.ts +47 -0
  17. package/app/Actions/Commerce/Licensing/LicenseSeatDestroyAction.ts +25 -0
  18. package/app/Actions/Commerce/Licensing/LicenseSeatIndexAction.ts +20 -0
  19. package/app/Actions/Commerce/Licensing/LicenseSeatStoreAction.ts +28 -0
  20. package/app/Actions/Commerce/Licensing/LicenseTransferAction.ts +32 -0
  21. package/app/Actions/Commerce/Licensing/license-response.ts +34 -0
  22. package/app/Actions/Commerce/Licensing/license-seat-access.ts +31 -0
  23. package/app/Actions/Desktop/UpdateFeedAction.ts +35 -0
  24. package/app/Mail/LicenseEmail.ts +80 -0
  25. package/app/Models/commerce/LicenseActivation.ts +98 -0
  26. package/app/Models/commerce/LicenseKey.ts +149 -7
  27. package/app/Models/commerce/LicenseSeat.ts +56 -0
  28. package/bootstrap.ts +35 -0
  29. package/ide/vscode/package.json +1 -1
  30. package/package.json +3 -3
  31. package/resources/emails/license.stx +52 -0
  32. package/routes/desktop-updates.ts +11 -0
  33. package/routes/licensing.ts +35 -0
  34. package/routes/payments.ts +9 -1
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: stacks-orm
3
- description: Use when querying or writing Stacks models, using transactions and relationships, preserving inferred model types, or enabling native model traits. Covers @stacksjs/orm, the model runtime, and 108 built-in models.
3
+ description: Use when querying or writing Stacks models, using transactions and relationships, preserving inferred model types, or enabling native model traits. Covers @stacksjs/orm, the model runtime, and 110 built-in models.
4
4
  license: MIT
5
5
  compatibility: Bun >= 1.3.0, TypeScript
6
6
  allowed-tools: Read Edit Write Bash Grep Glob
@@ -10,7 +10,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
10
10
 
11
11
  `defineModel` produces an immediately usable query surface over
12
12
  `bun-query-builder`. Model-driven migrations change the schema; there are no
13
- per-model ORM classes to generate. The framework declares 108 models on disk,
13
+ per-model ORM classes to generate. The framework declares 110 models on disk,
14
14
  but optional feature gates determine which built-ins load in a running app.
15
15
 
16
16
  ## Definitions and typed rows
@@ -35,6 +35,7 @@ Nothing throws at import, by design, so an app missing the SDK starts clean and
35
35
  - The Stripe driver delegates to the existing billable modules, so idempotency keys and `stripe_id` handling are unchanged.
36
36
  - Webhook route: the `payments` default route bundle (mounted with the `commerce` feature) serves `POST /webhooks/payments` through `orders.receivePaymentWebhook(request)`: 401 `missing-config` while the driver's secret is unset (`WebhookNotConfiguredError`), 400 `invalid-signature` (`WebhookSignatureError`), otherwise applies the events and answers with `acknowledgeWebhook()`.
37
37
  - Commerce: `orders.handleCommercePaymentEvent(event)` from `@stacksjs/commerce` applies `payment.succeeded` / `payment.failed` (reason into `payments.failure_reason`) / `refund.succeeded` (added to `refund_amount`; `refunded` + order REFUNDED only when it covers the payment, else `partiallyRefunded`) to the order, deduplicated in `payment_webhook_events` (the `PaymentWebhookEvent` model) in the same transaction.
38
+ - Licensing: the same webhook calls `licensing.handleLicensePaymentEvent(event)`. A checkout whose `reference` is `licensing.licensePurchaseReference({ tier })` is issued a license once when it is paid, on any driver, and a refund of that payment revokes it. See `stacks-licensing`.
38
39
  - The Payment facade's neutral functions go through this driver; its Stripe-only functions and everything Stripe-level below return Stripe objects.
39
40
 
40
41
  ## Key Paths
@@ -13,7 +13,7 @@ project `AGENTS.md`, a doc reached by a pointer. The packaging differs, the
13
13
  writing does not. The same levers make each one predictable, because the agent
14
14
  takes the same *process* every run rather than producing the same output.
15
15
 
16
- Stacks ships 210 skills and expects projects to add their own under
16
+ Stacks ships 211 skills and expects projects to add their own under
17
17
  `app/Skills/`, so this is the skill that keeps that set from turning to sludge.
18
18
  The Stacks-specific mechanics (frontmatter, invocation, the override model,
19
19
  what `buddy setup:ai` does with the result) are in
@@ -0,0 +1,36 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { response } from '@stacksjs/router'
5
+ import { answer, refusal } from './license-response'
6
+
7
+ /**
8
+ * Activate a license key on a device.
9
+ *
10
+ * The key is the credential: whoever holds it may use one of its device
11
+ * slots. The device is named only by the SHA-256 of an id the app chose.
12
+ * Answers the signed token the app keeps for offline use, or, beyond the
13
+ * device limit, a 409 naming the devices holding the slots.
14
+ */
15
+ export default new Action({
16
+ name: 'License Activate',
17
+ description: 'Activate a license key on a device and answer its signed offline token.',
18
+ method: 'POST',
19
+ apiResponse: true,
20
+
21
+ async handle(request: RequestInstance) {
22
+ return answer(async () => {
23
+ const result = await licensing.activateLicense({
24
+ key: request.get('key'),
25
+ deviceHash: request.get('deviceHash'),
26
+ deviceName: request.get('deviceName'),
27
+ platform: request.get('platform'),
28
+ appVersion: request.get('appVersion'),
29
+ email: request.get('email'),
30
+ })
31
+ if (!result.ok)
32
+ return refusal(result.reason, result.message, result.devices ? { devices: result.devices } : {})
33
+ return response.json({ ok: true, valid: true, key: result.key, token: result.token, license: result.license })
34
+ })
35
+ },
36
+ })
@@ -0,0 +1,31 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { response } from '@stacksjs/router'
5
+ import { answer } from './license-response'
6
+
7
+ /**
8
+ * Where a license stands for a device, with a fresh token when it is good.
9
+ *
10
+ * Always a 200 when the question could be answered: `valid: false` with a
11
+ * reason (`revoked`, `refunded`, `expired`, `released`, `not-found`) is an
12
+ * answer, and a client drops its stored token on it. Only a 5xx means "ask
13
+ * again later", which is why a refusal is not an error status here.
14
+ */
15
+ export default new Action({
16
+ name: 'License Check',
17
+ description: 'Answer a license\'s standing for a device, with a fresh signed token.',
18
+ method: 'POST',
19
+ apiResponse: true,
20
+
21
+ async handle(request: RequestInstance) {
22
+ return answer(async () => {
23
+ const result = await licensing.checkLicense({
24
+ key: request.get('key'),
25
+ deviceHash: request.get('deviceHash'),
26
+ appVersion: request.get('appVersion'),
27
+ })
28
+ return response.json({ ok: true, ...result })
29
+ })
30
+ },
31
+ })
@@ -0,0 +1,20 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { response } from '@stacksjs/router'
5
+ import { refusal } from './license-response'
6
+
7
+ /** Release a device's slot on a license, so another device can take it. */
8
+ export default new Action({
9
+ name: 'License Deactivate',
10
+ description: 'Release a device from a license key.',
11
+ method: 'POST',
12
+ apiResponse: true,
13
+
14
+ async handle(request: RequestInstance) {
15
+ const result = await licensing.deactivateLicense({ key: request.get('key'), deviceHash: request.get('deviceHash') })
16
+ if (!result.ok)
17
+ return refusal('not-found', 'That license key was not found.')
18
+ return response.json({ ok: true, released: result.released })
19
+ },
20
+ })
@@ -0,0 +1,47 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { rateLimit, response } from '@stacksjs/router'
5
+ import { sendLicenseKeys } from '../../../Mail/LicenseEmail'
6
+
7
+ /** Take a slot in a resend bucket; false once it is full. */
8
+ async function allow(bucket: 'ip' | 'email', identity?: string): Promise<boolean> {
9
+ const limit = licensing.RESEND_LIMITS[bucket]
10
+ try {
11
+ // No identity for the IP bucket: the limiter reads the client address itself.
12
+ await rateLimit(`license-resend-${bucket}`, limit.max, bucket === 'email' ? { identity: `email:${identity}` } : {}).over(limit.windowSeconds)
13
+ return true
14
+ }
15
+ catch (error) {
16
+ if ((error as { status?: number, statusCode?: number })?.status === 429 || (error as { statusCode?: number })?.statusCode === 429)
17
+ return false
18
+ throw error
19
+ }
20
+ }
21
+
22
+ /**
23
+ * "Email me my license key again."
24
+ *
25
+ * The answer is the same whether or not the address bought anything, and is
26
+ * given before the lookup runs, so neither the body nor the timing says which.
27
+ * Keys only ever go to the address on the license.
28
+ */
29
+ export default new Action({
30
+ name: 'License Resend',
31
+ description: 'Send the license keys bought with an address to that address again.',
32
+ method: 'POST',
33
+ apiResponse: true,
34
+
35
+ async handle(request: RequestInstance) {
36
+ const { outcome } = await licensing.requestLicenseResend(request.get('email'), {
37
+ allow,
38
+ active: email => licensing.activeLicensesFor(email),
39
+ send: licenses => sendLicenseKeys(licenses),
40
+ })
41
+ if (outcome === 'invalid')
42
+ return response.json({ ok: false, reason: 'invalid-email', message: 'Enter the email address you bought with.' }, 422)
43
+ if (outcome === 'limited')
44
+ return response.json({ ok: false, reason: 'limited', message: 'Too many requests. Try again in an hour.' }, 429)
45
+ return response.json({ ok: true, message: 'If that address has a license, its key is on the way.' })
46
+ },
47
+ })
@@ -0,0 +1,25 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { response } from '@stacksjs/router'
5
+ import { seatLicense } from './license-seat-access'
6
+
7
+ /** Take a member's seat back, releasing the devices activated under it. */
8
+ export default new Action({
9
+ name: 'License Seat Destroy',
10
+ description: 'Remove a member\'s seat on a team license.',
11
+ method: 'DELETE',
12
+ apiResponse: true,
13
+
14
+ async handle(request: RequestInstance) {
15
+ const access = await seatLicense(request)
16
+ if (access.error)
17
+ return access.error
18
+ const userId = Number(request.get('userId'))
19
+ if (!Number.isSafeInteger(userId) || userId < 1)
20
+ return response.json({ ok: false, reason: 'invalid-user', message: 'userId must be a team member\'s user id.' }, 422)
21
+
22
+ const result = await licensing.unassignLicenseSeat({ key: access.license.key, userId })
23
+ return response.json({ ok: true, removed: result.removed })
24
+ },
25
+ })
@@ -0,0 +1,20 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { response } from '@stacksjs/router'
5
+ import { seatLicense } from './license-seat-access'
6
+
7
+ /** Who holds a seat on a team license, for the team's owner or admin. */
8
+ export default new Action({
9
+ name: 'License Seat Index',
10
+ description: 'List the seats assigned on a team license.',
11
+ method: 'GET',
12
+ apiResponse: true,
13
+
14
+ async handle(request: RequestInstance) {
15
+ const access = await seatLicense(request)
16
+ if (access.error)
17
+ return access.error
18
+ return response.json({ ok: true, seats: access.license.seats, assigned: await licensing.licenseSeats(access.license.key) })
19
+ },
20
+ })
@@ -0,0 +1,28 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { response } from '@stacksjs/router'
5
+ import { refusal } from './license-response'
6
+ import { seatLicense } from './license-seat-access'
7
+
8
+ /** Give a member of the license's team a seat. */
9
+ export default new Action({
10
+ name: 'License Seat Store',
11
+ description: 'Assign a team license seat to a member of its team.',
12
+ method: 'POST',
13
+ apiResponse: true,
14
+
15
+ async handle(request: RequestInstance) {
16
+ const access = await seatLicense(request)
17
+ if (access.error)
18
+ return access.error
19
+ const userId = Number(request.get('userId'))
20
+ if (!Number.isSafeInteger(userId) || userId < 1)
21
+ return response.json({ ok: false, reason: 'invalid-user', message: 'userId must be a team member\'s user id.' }, 422)
22
+
23
+ const result = await licensing.assignLicenseSeat({ key: access.license.key, userId })
24
+ if (!result.ok)
25
+ return refusal(result.reason, result.message)
26
+ return response.json({ ok: true, seat: result.seat })
27
+ },
28
+ })
@@ -0,0 +1,32 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import { Action } from '@stacksjs/actions/runtime'
3
+ import { licensing } from '@stacksjs/commerce'
4
+ import { response } from '@stacksjs/router'
5
+ import { refusal } from './license-response'
6
+
7
+ /**
8
+ * Hand a license to another person.
9
+ *
10
+ * The caller names the key and the address it is registered to. Every device
11
+ * is released and the key is emailed to the new owner.
12
+ */
13
+ export default new Action({
14
+ name: 'License Transfer',
15
+ description: 'Transfer a license key to a new owner\'s email address.',
16
+ method: 'POST',
17
+ apiResponse: true,
18
+
19
+ async handle(request: RequestInstance) {
20
+ const result = await licensing.transferLicense({
21
+ key: request.get('key'),
22
+ fromEmail: request.get('email'),
23
+ toEmail: request.get('toEmail'),
24
+ })
25
+ if (!result.ok) {
26
+ // "No such key" and "not yours" are one answer, so a key cannot be probed for its owner.
27
+ const reason = result.reason === 'not-owner' ? 'not-found' : result.reason
28
+ return refusal(reason, result.message)
29
+ }
30
+ return response.json({ ok: true, email: result.license.email })
31
+ },
32
+ })
@@ -0,0 +1,34 @@
1
+ import type { ResponseStatus } from '@stacksjs/bun-router'
2
+ import { licensing } from '@stacksjs/commerce'
3
+ import { response } from '@stacksjs/router'
4
+
5
+ /** The HTTP status each refusal answers with. Anything unlisted is a 403. */
6
+ const STATUSES: Record<string, ResponseStatus> = {
7
+ 'not-found': 404,
8
+ 'invalid-device': 422,
9
+ 'invalid-email': 422,
10
+ 'device-limit': 409,
11
+ 'seat-limit': 409,
12
+ }
13
+
14
+ export function refusal(reason: string, message: string, extra: Record<string, unknown> = {}): Response {
15
+ return response.json({ ok: false, reason, message, ...extra }, STATUSES[reason] ?? 403)
16
+ }
17
+
18
+ /**
19
+ * Run a licensing call, answering 503 when the app has no signing key yet
20
+ * instead of a stack trace: a misconfigured server is not the caller's fault,
21
+ * and a client treats a 5xx as "try again later", keeping its stored token.
22
+ */
23
+ export async function answer(run: () => Promise<Response>): Promise<Response> {
24
+ try {
25
+ return await run()
26
+ }
27
+ catch (error) {
28
+ if (error instanceof licensing.LicensingNotConfiguredError) {
29
+ console.error(`[licensing] ${error.message}`)
30
+ return response.json({ reason: 'not-configured', message: 'Licensing is not configured on this server.' }, 503)
31
+ }
32
+ throw error
33
+ }
34
+ }
@@ -0,0 +1,31 @@
1
+ import type { RequestInstance } from '@stacksjs/types'
2
+ import type { License } from '@stacksjs/commerce'
3
+ import { resolveAuthenticatedUser } from '@stacksjs/auth'
4
+ import { licensing } from '@stacksjs/commerce'
5
+ import { db } from '@stacksjs/database/runtime'
6
+ import { response } from '@stacksjs/router'
7
+
8
+ /**
9
+ * The team license a seat request is about, once the caller is known to run
10
+ * its team. Seats are managed by an active `owner` or `admin` of the `Team`
11
+ * the license belongs to, and by nobody else, key or no key.
12
+ */
13
+ export async function seatLicense(request: RequestInstance): Promise<{ license: License, error?: undefined } | { error: Response, license?: undefined }> {
14
+ const user = await resolveAuthenticatedUser(request as any)
15
+ if (!user?.id)
16
+ return { error: response.json({ ok: false, reason: 'unauthenticated', message: 'Sign in to manage seats.' }, 401) }
17
+
18
+ const license = await licensing.findLicenseByKey(request.get('key'))
19
+ const member = license?.teamId
20
+ ? await db.selectFrom('team_members')
21
+ .where('team_id', '=', license.teamId)
22
+ .where('user_id', '=', Number(user.id))
23
+ .where('status', '=', 'active')
24
+ .select(['id', 'role'])
25
+ .executeTakeFirst()
26
+ : null
27
+ // One answer for "no such license" and "not your team's".
28
+ if (!license || license.tier !== 'team' || !member || !['owner', 'admin'].includes(String(member.role)))
29
+ return { error: response.json({ ok: false, reason: 'not-found', message: 'That team license was not found.' }, 404) }
30
+ return { license }
31
+ }
@@ -0,0 +1,35 @@
1
+ import { Action } from '@stacksjs/actions/runtime'
2
+
3
+ /**
4
+ * The update feed of the desktop app this project builds
5
+ * (`desktop.webview.updates` in config/desktop.ts):
6
+ * `GET /api/updates/{platform}/{arch}`.
7
+ *
8
+ * It serves the manifest `buddy release:desktop` published for that platform
9
+ * and architecture, exactly as stored. The manifest is signed with a key this
10
+ * server never holds, so nothing here can make an app accept an update the
11
+ * releaser did not sign. `?current=<version>` gets 204 when there is nothing
12
+ * newer; `?channel=beta` reads another channel.
13
+ *
14
+ * Mounted by the framework when `webview.updates` is configured. To change the
15
+ * path, mount it yourself in routes/api.ts:
16
+ *
17
+ * route.get('/desktop/feed/{platform}/{arch}', 'Actions/Desktop/UpdateFeedAction')
18
+ */
19
+ export default new Action({
20
+ name: 'DesktopUpdateFeedAction',
21
+ description: 'Serves the signed update manifest for a desktop platform and architecture.',
22
+ method: 'GET',
23
+
24
+ async handle(request: RequestInstance) {
25
+ const { answerUpdateFeed } = await import('@stacksjs/desktop-build/update-feed')
26
+ const channel = request.get('channel')
27
+ const current = request.get('current')
28
+ return answerUpdateFeed({
29
+ platform: String(request.getParam('platform') ?? ''),
30
+ architecture: String(request.getParam('arch') ?? ''),
31
+ channel: typeof channel === 'string' ? channel : null,
32
+ currentVersion: typeof current === 'string' ? current : null,
33
+ })
34
+ },
35
+ })
@@ -0,0 +1,80 @@
1
+ import type { License } from '@stacksjs/commerce'
2
+ import { config } from '@stacksjs/config'
3
+ import { mail, template } from '@stacksjs/email'
4
+
5
+ /**
6
+ * The email that carries license keys, in two variants of one design
7
+ * (`resources/emails/license.stx`): the purchase email, sent once when a
8
+ * purchase becomes a license, and the resend, sent when someone asks for the
9
+ * keys bought with an address.
10
+ *
11
+ * To send your own, copy the template to your app's `resources/emails/`, or
12
+ * replace the mailer outright with `licensing.configureLicensing({ onIssued })`.
13
+ */
14
+
15
+ const TIER_NAMES: Record<License['tier'], string> = {
16
+ standard: 'Pro',
17
+ lifetime: 'Pro Lifetime',
18
+ team: 'Team',
19
+ }
20
+
21
+ function day(iso: string | null): string {
22
+ return iso ? new Date(iso).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }) : ''
23
+ }
24
+
25
+ /** What a license includes, in a sentence. */
26
+ export function licenseTerms(license: License): string {
27
+ const devices = `${license.maxDevices} ${license.maxDevices === 1 ? 'device' : 'devices'}`
28
+ if (license.tier === 'lifetime')
29
+ return `Every update, for good, on up to ${devices}.`
30
+ if (license.tier === 'team')
31
+ return `${license.seats} ${license.seats === 1 ? 'seat' : 'seats'}, ${devices} each${license.expiresAt ? `, until ${day(license.expiresAt)}` : ''}.`
32
+ if (license.updatesUntil)
33
+ return `Updates until ${day(license.updatesUntil)}, on up to ${devices}. Every version released by then is yours to keep.`
34
+ return `On up to ${devices}.`
35
+ }
36
+
37
+ async function send(to: string, licenses: License[], variant: 'purchase' | 'resend'): Promise<void> {
38
+ const appName = config.app.name || 'Stacks'
39
+ const several = licenses.length > 1
40
+ const subject = several ? `Your ${appName} license keys` : `Your ${appName} license key`
41
+ const { html, text } = await template('license', {
42
+ variables: {
43
+ appName,
44
+ appUrl: config.app.url ? `https://${String(config.app.url).replace(/^https?:\/\//, '')}` : '',
45
+ variant,
46
+ keys: licenses.map(license => ({ name: TIER_NAMES[license.tier], key: license.key, terms: licenseTerms(license) })),
47
+ subject,
48
+ },
49
+ subject,
50
+ })
51
+
52
+ await mail.sendOrFail({
53
+ to: [to],
54
+ from: {
55
+ name: config.email.from?.name || appName,
56
+ address: config.email.from?.address || 'hello@stacksjs.com',
57
+ },
58
+ subject,
59
+ html,
60
+ text,
61
+ })
62
+ }
63
+
64
+ /** The purchase email: one key, to the address on the license. */
65
+ export async function sendLicenseEmail(license: License): Promise<void> {
66
+ if (license.email)
67
+ await send(license.email, [license], 'purchase')
68
+ }
69
+
70
+ /**
71
+ * The resend: every key given, to the address they share. Takes licenses
72
+ * rather than an address, so keys cannot be directed anywhere else.
73
+ */
74
+ export async function sendLicenseKeys(licenses: License[]): Promise<void> {
75
+ const to = licenses[0]?.email
76
+ if (to)
77
+ await send(to, licenses.filter(license => license.email === to), 'resend')
78
+ }
79
+
80
+ export default sendLicenseEmail
@@ -0,0 +1,98 @@
1
+ import { defineModel } from '@stacksjs/orm'
2
+ import { schema } from '@stacksjs/validation/runtime'
3
+
4
+ /**
5
+ * One device using a license.
6
+ *
7
+ * A license allows `maxDevices` of these at a time (per seat, for a team
8
+ * license). The device is known only by the SHA-256 of an id the app chose,
9
+ * plus the name its owner sees when the limit is reached. Releasing a device
10
+ * sets `releasedAt` and frees its slot; activating it again clears it.
11
+ */
12
+ export default defineModel({
13
+ name: 'LicenseActivation',
14
+ table: 'license_activations',
15
+ primaryKey: 'id',
16
+ autoIncrement: true,
17
+
18
+ indexes: [
19
+ {
20
+ name: 'license_activations_license_device_unique',
21
+ columns: ['license_key_id', 'device_hash'],
22
+ unique: true,
23
+ },
24
+ ],
25
+
26
+ // Written by the license routes for a key holder, never for a signed-in caller.
27
+ ownership: false,
28
+
29
+ belongsTo: ['LicenseKey'],
30
+
31
+ traits: {
32
+ useTimestamps: true,
33
+ useSeeder: { count: 0 },
34
+ },
35
+
36
+ attributes: {
37
+ /** SHA-256 of the device id, hex. */
38
+ deviceHash: {
39
+ required: true,
40
+ fillable: true,
41
+ validation: {
42
+ rule: schema.string().required().max(64),
43
+ },
44
+ },
45
+ deviceName: {
46
+ fillable: true,
47
+ nullable: true,
48
+ validation: {
49
+ rule: schema.string().max(255),
50
+ },
51
+ },
52
+ platform: {
53
+ fillable: true,
54
+ nullable: true,
55
+ validation: {
56
+ rule: schema.string().max(32),
57
+ },
58
+ },
59
+ appVersion: {
60
+ fillable: true,
61
+ nullable: true,
62
+ validation: {
63
+ rule: schema.string().max(64),
64
+ },
65
+ },
66
+ /** The seat this device is activated under, for a team license. */
67
+ licenseSeatId: {
68
+ fillable: true,
69
+ nullable: true,
70
+ validation: {
71
+ rule: schema.number(),
72
+ },
73
+ },
74
+ firstSeenAt: {
75
+ required: true,
76
+ fillable: true,
77
+ validation: {
78
+ rule: schema.timestamp().required(),
79
+ },
80
+ },
81
+ lastSeenAt: {
82
+ required: true,
83
+ fillable: true,
84
+ validation: {
85
+ rule: schema.timestamp().required(),
86
+ },
87
+ },
88
+ releasedAt: {
89
+ fillable: true,
90
+ nullable: true,
91
+ validation: {
92
+ rule: schema.timestamp(),
93
+ },
94
+ },
95
+ },
96
+
97
+ dashboard: { enabled: false },
98
+ } as const)