@stacksjs/defaults 0.75.543 → 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.
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-auto-imports/SKILL.md +1 -1
- package/ai/skills/stacks-commerce/SKILL.md +6 -3
- package/ai/skills/stacks-database/SKILL.md +1 -1
- package/ai/skills/stacks-deploy/SKILL.md +7 -0
- package/ai/skills/stacks-desktop/SKILL.md +188 -3
- package/ai/skills/stacks-licensing/SKILL.md +214 -0
- package/ai/skills/stacks-migrations/SKILL.md +2 -2
- package/ai/skills/stacks-models/SKILL.md +2 -2
- package/ai/skills/stacks-native/CATALOG.md +6 -6
- package/ai/skills/stacks-orm/SKILL.md +2 -2
- package/ai/skills/stacks-payments/SKILL.md +1 -0
- package/ai/skills/stacks-writing-for-agents/SKILL.md +1 -1
- package/app/Actions/Commerce/Licensing/LicenseActivateAction.ts +36 -0
- package/app/Actions/Commerce/Licensing/LicenseCheckAction.ts +31 -0
- package/app/Actions/Commerce/Licensing/LicenseDeactivateAction.ts +20 -0
- package/app/Actions/Commerce/Licensing/LicenseResendAction.ts +47 -0
- package/app/Actions/Commerce/Licensing/LicenseSeatDestroyAction.ts +25 -0
- package/app/Actions/Commerce/Licensing/LicenseSeatIndexAction.ts +20 -0
- package/app/Actions/Commerce/Licensing/LicenseSeatStoreAction.ts +28 -0
- package/app/Actions/Commerce/Licensing/LicenseTransferAction.ts +32 -0
- package/app/Actions/Commerce/Licensing/license-response.ts +34 -0
- package/app/Actions/Commerce/Licensing/license-seat-access.ts +31 -0
- package/app/Actions/Desktop/UpdateFeedAction.ts +35 -0
- package/app/Mail/LicenseEmail.ts +80 -0
- package/app/Models/commerce/LicenseActivation.ts +98 -0
- package/app/Models/commerce/LicenseKey.ts +149 -7
- package/app/Models/commerce/LicenseSeat.ts +56 -0
- package/bootstrap.ts +35 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +3 -3
- package/resources/emails/license.stx +52 -0
- package/routes/desktop-updates.ts +11 -0
- package/routes/licensing.ts +35 -0
- package/routes/payments.ts +9 -1
|
@@ -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)
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { customerOwnership, defineModel } from '@stacksjs/orm'
|
|
2
2
|
import { schema } from '@stacksjs/validation/runtime'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A software license: a key a customer was sold or handed, what it entitles
|
|
6
|
+
* them to, and where it stands.
|
|
7
|
+
*
|
|
8
|
+
* The same row serves two uses. As a deliverable it is a key attached to an
|
|
9
|
+
* order (the dashboard's license keys, `template`, `expiryDate`). As a license
|
|
10
|
+
* for an app (`@stacksjs/commerce` `licensing`) it also carries a `tier`, the
|
|
11
|
+
* last release it unlocks (`updatesUntil`, null for every release), how many
|
|
12
|
+
* devices and seats it covers, and the purchase it was issued for.
|
|
13
|
+
*/
|
|
4
14
|
export default defineModel({
|
|
5
15
|
name: 'LicenseKey',
|
|
6
16
|
table: 'license_keys',
|
|
@@ -16,10 +26,10 @@ export default defineModel({
|
|
|
16
26
|
useUuid: true,
|
|
17
27
|
useTimestamps: true,
|
|
18
28
|
useSearch: {
|
|
19
|
-
displayable: ['id', 'key', 'template', 'expiryDate', 'status'],
|
|
20
|
-
searchable: ['key'],
|
|
21
|
-
sortable: ['template', 'expiryDate', 'status', 'createdAt', 'updatedAt'],
|
|
22
|
-
filterable: ['status', 'template'],
|
|
29
|
+
displayable: ['id', 'key', 'template', 'tier', 'expiryDate', 'updatesUntil', 'status'],
|
|
30
|
+
searchable: ['key', 'email'],
|
|
31
|
+
sortable: ['template', 'tier', 'expiryDate', 'updatesUntil', 'status', 'createdAt', 'updatedAt'],
|
|
32
|
+
filterable: ['status', 'template', 'tier'],
|
|
23
33
|
},
|
|
24
34
|
|
|
25
35
|
useSeeder: {
|
|
@@ -34,7 +44,8 @@ export default defineModel({
|
|
|
34
44
|
observe: true,
|
|
35
45
|
},
|
|
36
46
|
|
|
37
|
-
belongsTo: ['Customer', 'Product', 'Order'],
|
|
47
|
+
belongsTo: ['Customer', 'Product', 'Order', 'Team'],
|
|
48
|
+
hasMany: ['LicenseActivation', 'LicenseSeat'],
|
|
38
49
|
|
|
39
50
|
attributes: {
|
|
40
51
|
key: {
|
|
@@ -62,11 +73,14 @@ export default defineModel({
|
|
|
62
73
|
factory: faker => faker.helpers.arrayElement(['Standard License', 'Premium License', 'Enterprise License']),
|
|
63
74
|
},
|
|
64
75
|
|
|
76
|
+
// Null for a license that never ends: standard and lifetime are owned
|
|
77
|
+
// outright, and only `updatesUntil` limits what a standard one unlocks.
|
|
65
78
|
expiryDate: {
|
|
66
79
|
order: 3,
|
|
67
80
|
fillable: true,
|
|
81
|
+
nullable: true,
|
|
68
82
|
validation: {
|
|
69
|
-
rule: schema.timestamp()
|
|
83
|
+
rule: schema.timestamp(),
|
|
70
84
|
message: {
|
|
71
85
|
timestamp: 'Expiry date must be a valid timestamp',
|
|
72
86
|
},
|
|
@@ -82,10 +96,138 @@ export default defineModel({
|
|
|
82
96
|
order: 4,
|
|
83
97
|
fillable: true,
|
|
84
98
|
validation: {
|
|
85
|
-
rule: schema.enum(['active', 'inactive', 'unassigned']),
|
|
99
|
+
rule: schema.enum(['active', 'inactive', 'unassigned', 'revoked', 'refunded']),
|
|
86
100
|
},
|
|
87
101
|
factory: faker => faker.helpers.arrayElement(['active', 'inactive', 'unassigned']),
|
|
88
102
|
},
|
|
103
|
+
|
|
104
|
+
/** What was bought: a year of updates, every update, or seats for a team. */
|
|
105
|
+
tier: {
|
|
106
|
+
default: 'standard',
|
|
107
|
+
order: 5,
|
|
108
|
+
fillable: true,
|
|
109
|
+
validation: {
|
|
110
|
+
rule: schema.enum(['standard', 'lifetime', 'team']),
|
|
111
|
+
},
|
|
112
|
+
factory: () => 'standard',
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The last release date this license unlocks. Builds released on or before
|
|
117
|
+
* it stay unlocked for good; null unlocks every build.
|
|
118
|
+
*/
|
|
119
|
+
updatesUntil: {
|
|
120
|
+
order: 6,
|
|
121
|
+
fillable: true,
|
|
122
|
+
nullable: true,
|
|
123
|
+
validation: {
|
|
124
|
+
rule: schema.timestamp(),
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/** Devices one holder may have active at once. */
|
|
129
|
+
maxDevices: {
|
|
130
|
+
default: 2,
|
|
131
|
+
order: 7,
|
|
132
|
+
fillable: true,
|
|
133
|
+
validation: {
|
|
134
|
+
rule: schema.number().min(1),
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
/** People a team license covers. One for a personal license. */
|
|
139
|
+
seats: {
|
|
140
|
+
default: 1,
|
|
141
|
+
order: 8,
|
|
142
|
+
fillable: true,
|
|
143
|
+
validation: {
|
|
144
|
+
rule: schema.number().min(1),
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/** Where the key is sent, and the address a resend is asked for. */
|
|
149
|
+
email: {
|
|
150
|
+
order: 9,
|
|
151
|
+
fillable: true,
|
|
152
|
+
nullable: true,
|
|
153
|
+
personal: true,
|
|
154
|
+
validation: {
|
|
155
|
+
rule: schema.string().max(254),
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Your reference for the purchase this license was issued for, echoed by
|
|
161
|
+
* the payment provider's webhook. Unique, so a purchase issues one license
|
|
162
|
+
* however many times its events arrive.
|
|
163
|
+
*/
|
|
164
|
+
purchaseReference: {
|
|
165
|
+
order: 10,
|
|
166
|
+
fillable: true,
|
|
167
|
+
nullable: true,
|
|
168
|
+
unique: true,
|
|
169
|
+
validation: {
|
|
170
|
+
rule: schema.string().max(255),
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
/** The provider's id for the payment, which is what a refund names. */
|
|
175
|
+
paymentReference: {
|
|
176
|
+
order: 11,
|
|
177
|
+
fillable: true,
|
|
178
|
+
nullable: true,
|
|
179
|
+
validation: {
|
|
180
|
+
rule: schema.string().max(255),
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
/** The payment driver the purchase came through. */
|
|
185
|
+
provider: {
|
|
186
|
+
order: 12,
|
|
187
|
+
fillable: true,
|
|
188
|
+
nullable: true,
|
|
189
|
+
validation: {
|
|
190
|
+
rule: schema.string().max(64),
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
/** Minor units (cents). */
|
|
195
|
+
amountPaid: {
|
|
196
|
+
order: 13,
|
|
197
|
+
fillable: true,
|
|
198
|
+
nullable: true,
|
|
199
|
+
validation: {
|
|
200
|
+
rule: schema.number().min(0),
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
/** Minor units (cents). A license is revoked once this covers `amountPaid`. */
|
|
205
|
+
amountRefunded: {
|
|
206
|
+
default: 0,
|
|
207
|
+
order: 14,
|
|
208
|
+
fillable: true,
|
|
209
|
+
validation: {
|
|
210
|
+
rule: schema.number().min(0),
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
currency: {
|
|
215
|
+
order: 15,
|
|
216
|
+
fillable: true,
|
|
217
|
+
nullable: true,
|
|
218
|
+
validation: {
|
|
219
|
+
rule: schema.string().max(3),
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
revokedAt: {
|
|
224
|
+
order: 16,
|
|
225
|
+
fillable: true,
|
|
226
|
+
nullable: true,
|
|
227
|
+
validation: {
|
|
228
|
+
rule: schema.timestamp(),
|
|
229
|
+
},
|
|
230
|
+
},
|
|
89
231
|
},
|
|
90
232
|
|
|
91
233
|
dashboard: {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { defineModel } from '@stacksjs/orm'
|
|
2
|
+
import { schema } from '@stacksjs/validation/runtime'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One person's place on a team license.
|
|
6
|
+
*
|
|
7
|
+
* A team license covers `seats` people. Each seat belongs to a member of the
|
|
8
|
+
* license's team (`TeamMember`), is found by that member's email when they
|
|
9
|
+
* activate a device, and allows the license's `maxDevices` devices of its own.
|
|
10
|
+
*/
|
|
11
|
+
export default defineModel({
|
|
12
|
+
name: 'LicenseSeat',
|
|
13
|
+
table: 'license_seats',
|
|
14
|
+
primaryKey: 'id',
|
|
15
|
+
autoIncrement: true,
|
|
16
|
+
|
|
17
|
+
indexes: [
|
|
18
|
+
{
|
|
19
|
+
name: 'license_seats_license_user_unique',
|
|
20
|
+
columns: ['license_key_id', 'user_id'],
|
|
21
|
+
unique: true,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
|
|
25
|
+
// Assigned by a team's owner or admin through the license routes.
|
|
26
|
+
ownership: false,
|
|
27
|
+
|
|
28
|
+
belongsTo: ['LicenseKey', 'TeamMember', 'User'],
|
|
29
|
+
|
|
30
|
+
traits: {
|
|
31
|
+
gdpr: { erasure: 'delete', basis: 'contract', purpose: 'License seat assignment' },
|
|
32
|
+
useTimestamps: true,
|
|
33
|
+
useSeeder: { count: 0 },
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
attributes: {
|
|
37
|
+
/** The member's address when the seat was assigned, lower-cased. */
|
|
38
|
+
email: {
|
|
39
|
+
required: true,
|
|
40
|
+
fillable: true,
|
|
41
|
+
personal: true,
|
|
42
|
+
validation: {
|
|
43
|
+
rule: schema.string().required().max(254),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
assignedAt: {
|
|
47
|
+
required: true,
|
|
48
|
+
fillable: true,
|
|
49
|
+
validation: {
|
|
50
|
+
rule: schema.timestamp().required(),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
dashboard: { enabled: false },
|
|
56
|
+
} as const)
|
package/bootstrap.ts
CHANGED
|
@@ -188,6 +188,18 @@ async function registerDefaultBundles(): Promise<void> {
|
|
|
188
188
|
await route.register(frameworkPath('defaults/routes/paddle.ts'))
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
// Software licensing: activate, check, release, resend, transfer and team
|
|
192
|
+
// seats (`@stacksjs/commerce` `licensing`). An opt-in bundle like `social`:
|
|
193
|
+
// an app that named its bundles decides outright, and an app that said
|
|
194
|
+
// nothing gets it exactly when it has a license signing key, since without
|
|
195
|
+
// one no token can be issued and the routes are surface for nothing.
|
|
196
|
+
const mountLicensing = selection?.explicit
|
|
197
|
+
? selection.bundles.has('licensing')
|
|
198
|
+
: Boolean(process.env.LICENSE_SIGNING_KEY)
|
|
199
|
+
if (mountLicensing) {
|
|
200
|
+
await route.register(frameworkPath('defaults/routes/licensing.ts'))
|
|
201
|
+
}
|
|
202
|
+
|
|
191
203
|
// Social sign-in: `/auth/{provider}` + `/auth/{provider}/callback`
|
|
192
204
|
// (stacksjs/stacks#2276). An opt-in bundle, NOT part of the implicit default
|
|
193
205
|
// set or `all` — OAuth callback URLs in an app that configured no provider
|
|
@@ -203,6 +215,29 @@ async function registerDefaultBundles(): Promise<void> {
|
|
|
203
215
|
if (mountSocial) {
|
|
204
216
|
await route.register(frameworkPath('defaults/routes/socials.ts'))
|
|
205
217
|
}
|
|
218
|
+
|
|
219
|
+
// The desktop update feed (`/api/updates/{platform}/{arch}`): what an
|
|
220
|
+
// installed desktop app asks for a newer version. Like `social`, it exists
|
|
221
|
+
// exactly when the app configured it - `webview.updates` in
|
|
222
|
+
// config/desktop.ts - so no existing app gains a route. The config file is
|
|
223
|
+
// read directly: the desktop build package is not loaded at server boot.
|
|
224
|
+
if (await publishesDesktopUpdates()) {
|
|
225
|
+
await route.register(frameworkPath('defaults/routes/desktop-updates.ts'))
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function publishesDesktopUpdates(): Promise<boolean> {
|
|
230
|
+
const { existsSync } = await import('node:fs')
|
|
231
|
+
const { projectPath } = await import('@stacksjs/path')
|
|
232
|
+
const file = projectPath('config/desktop.ts')
|
|
233
|
+
if (!existsSync(file)) return false
|
|
234
|
+
try {
|
|
235
|
+
const desktop = (await import(file) as { default?: { webview?: { updates?: unknown } } }).default
|
|
236
|
+
return Boolean(desktop?.webview?.updates)
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return false
|
|
240
|
+
}
|
|
206
241
|
}
|
|
207
242
|
|
|
208
243
|
// Register the bundles, withholding any route whose framework action depends
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.548",
|
|
6
6
|
"description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/defaults",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.548",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@iconify-json/f7": "^1.2.2",
|
|
47
47
|
"@iconify-json/hugeicons": "^1.2.35",
|
|
48
|
-
"@stacksjs/mobile": "0.75.
|
|
48
|
+
"@stacksjs/mobile": "0.75.548",
|
|
49
49
|
"@stacksjs/sanitizer": "^0.2.842",
|
|
50
50
|
"@stacksjs/stx": "^0.2.842",
|
|
51
|
-
"@stacksjs/strings": "0.75.
|
|
51
|
+
"@stacksjs/strings": "0.75.548",
|
|
52
52
|
"@xterm/addon-fit": "^0.11.0",
|
|
53
53
|
"@xterm/xterm": "^6.0.0",
|
|
54
54
|
"ts-qr-codes": "^0.1.8"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
// The email that carries license keys (app/Mail/LicenseEmail.ts), in two
|
|
3
|
+
// variants of one design:
|
|
4
|
+
// - the purchase email, sent once when a purchase becomes a license.
|
|
5
|
+
// - `variant: 'resend'`, sent when someone asks for the keys bought with an
|
|
6
|
+
// address: every key still good for it, and no word on any other.
|
|
7
|
+
const appName = props.appName || 'Stacks'
|
|
8
|
+
const appUrl = props.appUrl || ''
|
|
9
|
+
const accent = props.accent || '#3451b2'
|
|
10
|
+
const resend = props.variant === 'resend'
|
|
11
|
+
// One entry per key: its tier's name, the key, and what it includes.
|
|
12
|
+
const keys = Array.isArray(props.keys) ? props.keys : []
|
|
13
|
+
const several = keys.length > 1
|
|
14
|
+
const subject = props.subject || `Your ${appName} license key`
|
|
15
|
+
|
|
16
|
+
const heading = resend
|
|
17
|
+
? (several ? `Here are your ${appName} keys again.` : `Here is your ${appName} key again.`)
|
|
18
|
+
: `Thank you for buying ${appName}.`
|
|
19
|
+
const preheader = several
|
|
20
|
+
? `Your ${keys.length} ${appName} license keys, as asked.`
|
|
21
|
+
: `Your license key is inside. ${appName} asks for it once per device.`
|
|
22
|
+
const footer = resend
|
|
23
|
+
? `You are getting this because someone asked for the ${appName} keys bought with this address. They are only ever sent here.`
|
|
24
|
+
: `You are getting this because you bought ${appName}. Keep it: it is how you find your key again.`
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<EmailLayout
|
|
28
|
+
title="{{ subject }}"
|
|
29
|
+
preheader="{{ preheader }}"
|
|
30
|
+
brand="{{ appName }}"
|
|
31
|
+
brandUrl="{{ appUrl }}"
|
|
32
|
+
accent="{{ accent }}"
|
|
33
|
+
footer="{{ footer }}"
|
|
34
|
+
>
|
|
35
|
+
<EmailText size="heading">{{ heading }}</EmailText>
|
|
36
|
+
@if(resend)
|
|
37
|
+
<EmailText>Someone asked for the license {{ several ? 'keys' : 'key' }} bought with this address. If that was not you, you can ignore this email. Nobody else can see {{ several ? 'them' : 'it' }}.</EmailText>
|
|
38
|
+
@else
|
|
39
|
+
<EmailText>Here is your license key. Open {{ appName }}, choose Enter License, and paste it in. It is asked for once per device.</EmailText>
|
|
40
|
+
@endif
|
|
41
|
+
|
|
42
|
+
@foreach(keys as entry)
|
|
43
|
+
<EmailText size="sm" spacing="8px"><strong>{{ appName }} {{ entry.name }}</strong></EmailText>
|
|
44
|
+
<EmailCode>{{ entry.key }}</EmailCode>
|
|
45
|
+
<EmailText size="sm">{{ entry.terms }}</EmailText>
|
|
46
|
+
@endforeach
|
|
47
|
+
|
|
48
|
+
<EmailDivider />
|
|
49
|
+
|
|
50
|
+
<EmailText size="sm">Moving to a new computer? Release the old one from {{ appName }}'s license settings, then activate the new one with the same key.</EmailText>
|
|
51
|
+
<EmailText size="sm" spacing="0">Keep this email. It is the record of your purchase and the quickest way back to your key.</EmailText>
|
|
52
|
+
</EmailLayout>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { route } from '@stacksjs/router'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The desktop update feed: what an installed desktop app (`desktop.webview`)
|
|
5
|
+
* asks for a newer version. Mounted while `config/desktop.ts` has
|
|
6
|
+
* `webview.updates`. An app route at the same path registers first and wins.
|
|
7
|
+
*
|
|
8
|
+
* Public on purpose: an app checks before anyone has signed in, and the
|
|
9
|
+
* manifest it gets is only as good as its signature.
|
|
10
|
+
*/
|
|
11
|
+
route.get('/api/updates/{platform}/{arch}', 'Actions/Desktop/UpdateFeedAction')
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { licensing } from '@stacksjs/commerce'
|
|
2
|
+
import { route } from '@stacksjs/router'
|
|
3
|
+
import { sendLicenseEmail } from '../app/Mail/LicenseEmail'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Software licensing endpoints (`@stacksjs/commerce` `licensing`).
|
|
7
|
+
*
|
|
8
|
+
* The first three are what a desktop app's license client calls
|
|
9
|
+
* (`@stacksjs/commerce/licensing/client`): the license key is the credential,
|
|
10
|
+
* so they are CSRF-exempt and rate limited instead. Resend and transfer are
|
|
11
|
+
* for a page on the app's site. Seats are for a signed-in owner or admin of
|
|
12
|
+
* the team a team license belongs to.
|
|
13
|
+
*
|
|
14
|
+
* An opt-in bundle: mounted when `LICENSE_SIGNING_KEY` is set, or when
|
|
15
|
+
* `STACKS_DEFAULT_ROUTES` names `licensing`. Issuing needs no route of its
|
|
16
|
+
* own; it rides the payment webhook (`routes/payments.ts`).
|
|
17
|
+
*
|
|
18
|
+
* To override a route, define the same method and path in `routes/api.ts`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// An app that set its own `onIssued` keeps it; this is only the fallback.
|
|
22
|
+
licensing.registerDefaultLicenseMailer(sendLicenseEmail)
|
|
23
|
+
|
|
24
|
+
route.post('/licenses/activate', 'Actions/Commerce/Licensing/LicenseActivateAction').skipCsrf().rateLimit(20, 'minute')
|
|
25
|
+
route.post('/licenses/deactivate', 'Actions/Commerce/Licensing/LicenseDeactivateAction').skipCsrf().rateLimit(20, 'minute')
|
|
26
|
+
route.post('/licenses/check', 'Actions/Commerce/Licensing/LicenseCheckAction').skipCsrf().rateLimit(60, 'minute')
|
|
27
|
+
|
|
28
|
+
// The per-address and per-IP hourly limits live in the action, where the
|
|
29
|
+
// address is known; this is the coarse brake in front of it.
|
|
30
|
+
route.post('/licenses/resend', 'Actions/Commerce/Licensing/LicenseResendAction').rateLimit(10, 'minute')
|
|
31
|
+
route.post('/licenses/transfer', 'Actions/Commerce/Licensing/LicenseTransferAction').rateLimit(5, 'minute')
|
|
32
|
+
|
|
33
|
+
route.get('/licenses/seats', 'Actions/Commerce/Licensing/LicenseSeatIndexAction').middleware('auth')
|
|
34
|
+
route.post('/licenses/seats', 'Actions/Commerce/Licensing/LicenseSeatStoreAction').middleware('auth')
|
|
35
|
+
route.delete('/licenses/seats', 'Actions/Commerce/Licensing/LicenseSeatDestroyAction').middleware('auth')
|
package/routes/payments.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { orders } from '@stacksjs/commerce'
|
|
1
|
+
import { licensing, orders } from '@stacksjs/commerce'
|
|
2
2
|
import { route } from '@stacksjs/router'
|
|
3
|
+
import { sendLicenseEmail } from '../app/Mail/LicenseEmail'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The payment provider's webhook (stacksjs/stacks#665, #1879 Co-17).
|
|
@@ -13,8 +14,15 @@ import { route } from '@stacksjs/router'
|
|
|
13
14
|
* Payments and refunds then reach their orders without app code; orders used
|
|
14
15
|
* to sit at PENDING whenever the webhook was the only news of a payment.
|
|
15
16
|
*
|
|
17
|
+
* A paid checkout started with `licensing.licensePurchaseReference()` as its
|
|
18
|
+
* `reference` is issued a license here too, once, and emailed its key; a
|
|
19
|
+
* refund of that payment revokes it (`@stacksjs/commerce` `licensing`).
|
|
20
|
+
*
|
|
16
21
|
* Unconfigured, it answers 401 and applies nothing. CSRF-exempt, since the
|
|
17
22
|
* provider calls it; the signature is what authenticates it. An app route at
|
|
18
23
|
* the same path registers first and wins.
|
|
19
24
|
*/
|
|
25
|
+
// An app that set its own `onIssued` keeps it; this is only the fallback.
|
|
26
|
+
licensing.registerDefaultLicenseMailer(sendLicenseEmail)
|
|
27
|
+
|
|
20
28
|
route.post('/webhooks/payments', request => orders.receivePaymentWebhook(request)).skipCsrf()
|