This repository has been archived by the owner on Mar 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
99 lines (85 loc) · 2.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<script>
const { prompt, confirm, alert } = require('smalltalk')
const KEYGEN_ACCOUNT_ID = '1fddcec8-8dd3-4d8d-9b16-215cac0f9b52' // Available at https://app.keygen.sh/settings
const KEYGEN_PRODUCT_ID = '5499e2ec-47e6-44cb-91e9-b5d5d65c5590'
async function activateAppWithLicenseKey(key) {
const res = await fetch(`https://api.keygen.sh/v1/accounts/${KEYGEN_ACCOUNT_ID}/licenses/actions/validate-key`, {
method: 'POST',
headers: {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json'
},
body: JSON.stringify({
meta: {
scope: { product: KEYGEN_PRODUCT_ID },
key
}
})
})
const { meta, data, errors } = await res.json()
if (errors) {
await alert('API Error', `There was an error: ${errors.map(e => `${e.title}: ${e.detail}`)}`)
return
}
if (!meta.valid) {
await alert('Invalid License', `Your license is invalid: ${meta.detail}`)
// Ask the user if they'd like to retry inputting their license key
confirm('Try Again', 'Do you want to try again?')
.then(boopApp)
return
}
// Render the app
const template = document.createElement('template')
template.innerHTML = `
<h1>
Hello World!
</h1>
<p>
Your license information:
</p>
<table>
<tbody>
<tr>
<td><strong>ID</strong></td>
<td>${data.id}</td>
</tr>
<tr>
<td><strong>Key</strong></td>
<td>${data.attributes.key}</td>
</tr>
<tr>
<td><strong>Expiry</strong></td>
<td>${data.attributes.expiry}</td>
</tr>
<tr>
<td><strong>Policy</strong></td>
<td>${data.relationships.policy.data.id}</td>
</tr>
</tbody>
</table>
<button onclick='boopApp()'>
Restart
</button>
`.trim()
for (let node of template.content.childNodes) {
document.body.appendChild(node)
}
}
async function boopApp() {
document.body.innerHTML = ''
// Prompt the user for their license key
const key = await prompt('License Required', 'Please enter your license key:', 'demo')
// Attempt to activate the app by validating the license key
await activateAppWithLicenseKey(key)
}
boopApp()
</script>
</body>
</html>