@tldraw/editor 3.16.0-canary.1647ca5bba28 → 3.16.0-canary.1e91d2e19e07
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/dist-cjs/index.d.ts +17 -0
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +1 -1
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +3 -2
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +10 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
- package/dist-cjs/lib/license/LicenseManager.js +128 -35
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/LicenseProvider.js +36 -3
- package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +68 -6
- package/dist-cjs/lib/license/Watermark.js.map +3 -3
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +24 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Group2d.js +5 -1
- package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +17 -0
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +1 -1
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +3 -2
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +10 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseManager.mjs +129 -36
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseProvider.mjs +36 -4
- package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +68 -6
- package/dist-esm/lib/license/Watermark.mjs.map +3 -3
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +24 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Group2d.mjs +5 -1
- package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +8 -3
- package/package.json +7 -7
- package/src/index.ts +1 -0
- package/src/lib/TldrawEditor.tsx +1 -2
- package/src/lib/editor/Editor.ts +4 -2
- package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
- package/src/lib/editor/shapes/ShapeUtil.ts +11 -0
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
- package/src/lib/license/LicenseManager.test.ts +687 -387
- package/src/lib/license/LicenseManager.ts +180 -44
- package/src/lib/license/LicenseProvider.tsx +69 -5
- package/src/lib/license/Watermark.tsx +73 -6
- package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
- package/src/lib/primitives/geometry/Geometry2d.ts +29 -2
- package/src/lib/primitives/geometry/Group2d.ts +6 -1
- package/src/version.ts +3 -3
|
@@ -52,337 +52,464 @@ describe('LicenseManager', () => {
|
|
|
52
52
|
window.location = new URL('https://www.example.com')
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
describe('Basic license validation', () => {
|
|
56
|
+
it('Fails if no key provided', async () => {
|
|
57
|
+
const result = await licenseManager.getLicenseFromKey('')
|
|
58
|
+
expect(result).toMatchObject({ isLicenseParseable: false, reason: 'no-key-provided' })
|
|
59
|
+
})
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
it('Signals that it is development mode when appropriate', async () => {
|
|
62
|
+
const schemes = ['http', 'https']
|
|
63
|
+
for (const scheme of schemes) {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
delete window.location
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
window.location = new URL(`${scheme}://localhost:3000`)
|
|
68
|
+
|
|
69
|
+
const testEnvLicenseManager = new LicenseManager('', keyPair.publicKey, 'development')
|
|
70
|
+
const licenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
71
|
+
const result = await testEnvLicenseManager.getLicenseFromKey(licenseKey)
|
|
72
|
+
expect(result).toMatchObject({
|
|
73
|
+
isLicenseParseable: true,
|
|
74
|
+
isDomainValid: false,
|
|
75
|
+
isDevelopment: true,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('Cleanses out valid keys that accidentally have zero-width characters or newlines', async () => {
|
|
81
|
+
const cleanLicenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
82
|
+
const dirtyLicenseKey = cleanLicenseKey + '\u200B\u200D\uFEFF\n\r'
|
|
83
|
+
const result = await licenseManager.getLicenseFromKey(dirtyLicenseKey)
|
|
84
|
+
expect(result.isLicenseParseable).toBe(true)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('Fails if garbage key provided', async () => {
|
|
88
|
+
const badPublicKeyLicenseManager = new LicenseManager('', 'badpublickey', 'production')
|
|
89
|
+
const invalidLicenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
90
|
+
const result = await badPublicKeyLicenseManager.getLicenseFromKey(invalidLicenseKey)
|
|
91
|
+
expect(result).toMatchObject({ isLicenseParseable: false, reason: 'invalid-license-key' })
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('Fails if non-JSON parseable message is provided', async () => {
|
|
95
|
+
const invalidMessage = await generateLicenseKey('asdfsad', keyPair)
|
|
96
|
+
const result = await licenseManager.getLicenseFromKey(invalidMessage)
|
|
97
|
+
expect(result).toMatchObject({ isLicenseParseable: false, reason: 'invalid-license-key' })
|
|
98
|
+
})
|
|
67
99
|
|
|
68
|
-
|
|
100
|
+
it('Succeeds if valid key provided', async () => {
|
|
69
101
|
const licenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
70
|
-
const result = await
|
|
102
|
+
const result = await licenseManager.getLicenseFromKey(licenseKey)
|
|
71
103
|
expect(result).toMatchObject({
|
|
72
104
|
isLicenseParseable: true,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
105
|
+
license: {
|
|
106
|
+
id: 'id',
|
|
107
|
+
hosts: ['www.example.com'],
|
|
108
|
+
flags: FLAGS.ANNUAL_LICENSE,
|
|
109
|
+
expiryDate,
|
|
110
|
+
},
|
|
111
|
+
isDomainValid: true,
|
|
112
|
+
isAnnualLicense: true,
|
|
113
|
+
isAnnualLicenseExpired: false,
|
|
114
|
+
isPerpetualLicense: false,
|
|
115
|
+
isPerpetualLicenseExpired: false,
|
|
116
|
+
isInternalLicense: false,
|
|
117
|
+
isEvaluationLicense: false,
|
|
118
|
+
isEvaluationLicenseExpired: false,
|
|
119
|
+
daysSinceExpiry: 0,
|
|
120
|
+
} as ValidLicenseKeyResult)
|
|
121
|
+
})
|
|
77
122
|
})
|
|
78
123
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
124
|
+
describe('Domain validation', () => {
|
|
125
|
+
it('Fails with invalid host', async () => {
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
delete window.location
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
window.location = new URL('https://www.foo.com')
|
|
85
130
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
131
|
+
const expiredLicenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
132
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
133
|
+
expiredLicenseKey
|
|
134
|
+
)) as ValidLicenseKeyResult
|
|
135
|
+
expect(result.isDomainValid).toBe(false)
|
|
136
|
+
})
|
|
92
137
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
138
|
+
it('Succeeds if hosts is equal to only "*"', async () => {
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
delete window.location
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
window.location = new URL('https://www.foo.com')
|
|
143
|
+
|
|
144
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
145
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['*']
|
|
146
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
147
|
+
JSON.stringify(permissiveHostsInfo),
|
|
148
|
+
keyPair
|
|
149
|
+
)
|
|
150
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
151
|
+
permissiveLicenseKey
|
|
152
|
+
)) as ValidLicenseKeyResult
|
|
153
|
+
expect(result.isDomainValid).toBe(true)
|
|
154
|
+
})
|
|
98
155
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
} as ValidLicenseKeyResult)
|
|
117
|
-
})
|
|
156
|
+
it('Succeeds if has an apex domain specified', async () => {
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
delete window.location
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
window.location = new URL('https://www.example.com')
|
|
161
|
+
|
|
162
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
163
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['example.com']
|
|
164
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
165
|
+
JSON.stringify(permissiveHostsInfo),
|
|
166
|
+
keyPair
|
|
167
|
+
)
|
|
168
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
169
|
+
permissiveLicenseKey
|
|
170
|
+
)) as ValidLicenseKeyResult
|
|
171
|
+
expect(result.isDomainValid).toBe(true)
|
|
172
|
+
})
|
|
118
173
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
174
|
+
it('Succeeds if has an www domain specified, but at the apex domain', async () => {
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
delete window.location
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
window.location = new URL('https://example.com')
|
|
179
|
+
|
|
180
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
181
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['www.example.com']
|
|
182
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
183
|
+
JSON.stringify(permissiveHostsInfo),
|
|
184
|
+
keyPair
|
|
185
|
+
)
|
|
186
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
187
|
+
permissiveLicenseKey
|
|
188
|
+
)) as ValidLicenseKeyResult
|
|
189
|
+
expect(result.isDomainValid).toBe(true)
|
|
190
|
+
})
|
|
129
191
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
192
|
+
it('Succeeds if has a subdomain wildcard', async () => {
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
delete window.location
|
|
195
|
+
// @ts-ignore
|
|
196
|
+
window.location = new URL('https://sub.example.com')
|
|
197
|
+
|
|
198
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
199
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['*.example.com']
|
|
200
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
201
|
+
JSON.stringify(permissiveHostsInfo),
|
|
202
|
+
keyPair
|
|
203
|
+
)
|
|
204
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
205
|
+
permissiveLicenseKey
|
|
206
|
+
)) as ValidLicenseKeyResult
|
|
207
|
+
expect(result.isDomainValid).toBe(true)
|
|
208
|
+
})
|
|
143
209
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
expect(result.isPerpetualLicenseExpired).toBe(false)
|
|
162
|
-
})
|
|
210
|
+
it('Succeeds if has a sub-subdomain wildcard', async () => {
|
|
211
|
+
// @ts-ignore
|
|
212
|
+
delete window.location
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
window.location = new URL('https://pr-2408.sub.example.com')
|
|
215
|
+
|
|
216
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
217
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['*.example.com']
|
|
218
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
219
|
+
JSON.stringify(permissiveHostsInfo),
|
|
220
|
+
keyPair
|
|
221
|
+
)
|
|
222
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
223
|
+
permissiveLicenseKey
|
|
224
|
+
)) as ValidLicenseKeyResult
|
|
225
|
+
expect(result.isDomainValid).toBe(true)
|
|
226
|
+
})
|
|
163
227
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
})
|
|
228
|
+
it('Succeeds if has a subdomain wildcard but on an apex domain', async () => {
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
delete window.location
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
window.location = new URL('https://example.com')
|
|
233
|
+
|
|
234
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
235
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['*.example.com']
|
|
236
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
237
|
+
JSON.stringify(permissiveHostsInfo),
|
|
238
|
+
keyPair
|
|
239
|
+
)
|
|
240
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
241
|
+
permissiveLicenseKey
|
|
242
|
+
)) as ValidLicenseKeyResult
|
|
243
|
+
expect(result.isDomainValid).toBe(true)
|
|
244
|
+
})
|
|
182
245
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
246
|
+
it('Fails if has a subdomain wildcard isnt for the same base domain', async () => {
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
delete window.location
|
|
249
|
+
// @ts-ignore
|
|
250
|
+
window.location = new URL('https://sub.example.com')
|
|
251
|
+
|
|
252
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
253
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['*.foo.com']
|
|
254
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
255
|
+
JSON.stringify(permissiveHostsInfo),
|
|
256
|
+
keyPair
|
|
257
|
+
)
|
|
258
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
259
|
+
permissiveLicenseKey
|
|
260
|
+
)) as ValidLicenseKeyResult
|
|
261
|
+
expect(result.isDomainValid).toBe(false)
|
|
262
|
+
})
|
|
188
263
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
264
|
+
it('Succeeds if it is a vscode extension', async () => {
|
|
265
|
+
// @ts-ignore
|
|
266
|
+
delete window.location
|
|
267
|
+
// @ts-ignore
|
|
268
|
+
window.location = new URL(
|
|
269
|
+
'vscode-webview:vscode-webview://1ipd8pun8ud7nd7hv9d112g7evi7m10vak9vviuvia66ou6aibp3/index.html?id=6ec2dc7a-afe9-45d9-bd71-1749f9568d28&origin=955b256f-37e1-4a72-a2f4-ad633e88239c&swVersion=4&extensionId=tldraw-org.tldraw-vscode&platform=electron&vscode-resource-base-authority=vscode-resource.vscode-cdn.net&parentOrigin=vscode-file%3A%2F%2Fvscode-app'
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
273
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['tldraw-org.tldraw-vscode']
|
|
274
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
275
|
+
JSON.stringify(permissiveHostsInfo),
|
|
276
|
+
keyPair
|
|
277
|
+
)
|
|
278
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
279
|
+
permissiveLicenseKey
|
|
280
|
+
)) as ValidLicenseKeyResult
|
|
281
|
+
expect(result.isDomainValid).toBe(true)
|
|
282
|
+
})
|
|
195
283
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
284
|
+
it('Fails if it is a vscode extension with the wrong id', async () => {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
delete window.location
|
|
287
|
+
// @ts-ignore
|
|
288
|
+
window.location = new URL(
|
|
289
|
+
'vscode-webview:vscode-webview://1ipd8pun8ud7nd7hv9d112g7evi7m10vak9vviuvia66ou6aibp3/index.html?id=6ec2dc7a-afe9-45d9-bd71-1749f9568d28&origin=955b256f-37e1-4a72-a2f4-ad633e88239c&swVersion=4&extensionId=tldraw-org.tldraw-vscode&platform=electron&vscode-resource-base-authority=vscode-resource.vscode-cdn.net&parentOrigin=vscode-file%3A%2F%2Fvscode-app'
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
293
|
+
permissiveHostsInfo[PROPERTIES.HOSTS] = ['blah-org.blah-vscode']
|
|
294
|
+
const permissiveLicenseKey = await generateLicenseKey(
|
|
295
|
+
JSON.stringify(permissiveHostsInfo),
|
|
296
|
+
keyPair
|
|
297
|
+
)
|
|
298
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
299
|
+
permissiveLicenseKey
|
|
300
|
+
)) as ValidLicenseKeyResult
|
|
301
|
+
expect(result.isDomainValid).toBe(false)
|
|
302
|
+
})
|
|
213
303
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
304
|
+
it('Succeeds if it is a native app', async () => {
|
|
305
|
+
// @ts-ignore
|
|
306
|
+
delete window.location
|
|
307
|
+
// @ts-ignore
|
|
308
|
+
window.location = new URL('app-bundle://app/index.html')
|
|
309
|
+
|
|
310
|
+
const nativeLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
311
|
+
nativeLicenseInfo[PROPERTIES.FLAGS] = FLAGS.NATIVE_LICENSE
|
|
312
|
+
nativeLicenseInfo[PROPERTIES.HOSTS] = ['app-bundle:']
|
|
313
|
+
const nativeLicenseKey = await generateLicenseKey(JSON.stringify(nativeLicenseInfo), keyPair)
|
|
314
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
315
|
+
nativeLicenseKey
|
|
316
|
+
)) as ValidLicenseKeyResult
|
|
317
|
+
expect(result.isDomainValid).toBe(true)
|
|
318
|
+
})
|
|
219
319
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
320
|
+
it('Fails if it is a native app with the wrong protocol', async () => {
|
|
321
|
+
// @ts-ignore
|
|
322
|
+
delete window.location
|
|
323
|
+
// @ts-ignore
|
|
324
|
+
window.location = new URL('blah-blundle://app/index.html')
|
|
325
|
+
|
|
326
|
+
const nativeLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
327
|
+
nativeLicenseInfo[PROPERTIES.FLAGS] = FLAGS.NATIVE_LICENSE
|
|
328
|
+
nativeLicenseInfo[PROPERTIES.HOSTS] = ['app-bundle:']
|
|
329
|
+
const nativeLicenseKey = await generateLicenseKey(JSON.stringify(nativeLicenseInfo), keyPair)
|
|
330
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
331
|
+
nativeLicenseKey
|
|
332
|
+
)) as ValidLicenseKeyResult
|
|
333
|
+
expect(result.isDomainValid).toBe(false)
|
|
334
|
+
})
|
|
230
335
|
})
|
|
231
336
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
permissiveLicenseKey
|
|
246
|
-
)) as ValidLicenseKeyResult
|
|
247
|
-
expect(result.isDomainValid).toBe(true)
|
|
248
|
-
})
|
|
337
|
+
describe('License types and flags', () => {
|
|
338
|
+
it('Checks for internal license', async () => {
|
|
339
|
+
const internalLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
340
|
+
internalLicenseInfo[PROPERTIES.FLAGS] = FLAGS.INTERNAL_LICENSE
|
|
341
|
+
const internalLicenseKey = await generateLicenseKey(
|
|
342
|
+
JSON.stringify(internalLicenseInfo),
|
|
343
|
+
keyPair
|
|
344
|
+
)
|
|
345
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
346
|
+
internalLicenseKey
|
|
347
|
+
)) as ValidLicenseKeyResult
|
|
348
|
+
expect(result.isInternalLicense).toBe(true)
|
|
349
|
+
})
|
|
249
350
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
window.location = new URL('https://sub.example.com')
|
|
255
|
-
|
|
256
|
-
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
257
|
-
permissiveHostsInfo[PROPERTIES.HOSTS] = ['*.example.com']
|
|
258
|
-
const permissiveLicenseKey = await generateLicenseKey(
|
|
259
|
-
JSON.stringify(permissiveHostsInfo),
|
|
260
|
-
keyPair
|
|
261
|
-
)
|
|
262
|
-
const result = (await licenseManager.getLicenseFromKey(
|
|
263
|
-
permissiveLicenseKey
|
|
264
|
-
)) as ValidLicenseKeyResult
|
|
265
|
-
expect(result.isDomainValid).toBe(true)
|
|
266
|
-
})
|
|
351
|
+
it('Checks for native license', async () => {
|
|
352
|
+
const nativeLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
353
|
+
nativeLicenseInfo[PROPERTIES.FLAGS] = FLAGS.NATIVE_LICENSE
|
|
354
|
+
const nativeLicenseKey = await generateLicenseKey(JSON.stringify(nativeLicenseInfo), keyPair)
|
|
267
355
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const permissiveHostsInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
275
|
-
permissiveHostsInfo[PROPERTIES.HOSTS] = ['*.example.com']
|
|
276
|
-
const permissiveLicenseKey = await generateLicenseKey(
|
|
277
|
-
JSON.stringify(permissiveHostsInfo),
|
|
278
|
-
keyPair
|
|
279
|
-
)
|
|
280
|
-
const result = (await licenseManager.getLicenseFromKey(
|
|
281
|
-
permissiveLicenseKey
|
|
282
|
-
)) as ValidLicenseKeyResult
|
|
283
|
-
expect(result.isDomainValid).toBe(true)
|
|
284
|
-
})
|
|
356
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
357
|
+
nativeLicenseKey
|
|
358
|
+
)) as ValidLicenseKeyResult
|
|
359
|
+
expect(result.isNativeLicense).toBe(true)
|
|
360
|
+
})
|
|
285
361
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
)
|
|
298
|
-
const result = (await licenseManager.getLicenseFromKey(
|
|
299
|
-
permissiveLicenseKey
|
|
300
|
-
)) as ValidLicenseKeyResult
|
|
301
|
-
expect(result.isDomainValid).toBe(true)
|
|
302
|
-
})
|
|
362
|
+
it('Checks for license with watermark', async () => {
|
|
363
|
+
const withWatermarkLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
364
|
+
withWatermarkLicenseInfo[PROPERTIES.FLAGS] |= FLAGS.WITH_WATERMARK
|
|
365
|
+
const withWatermarkLicenseKey = await generateLicenseKey(
|
|
366
|
+
JSON.stringify(withWatermarkLicenseInfo),
|
|
367
|
+
keyPair
|
|
368
|
+
)
|
|
369
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
370
|
+
withWatermarkLicenseKey
|
|
371
|
+
)) as ValidLicenseKeyResult
|
|
372
|
+
expect(result.isLicensedWithWatermark).toBe(true)
|
|
373
|
+
})
|
|
303
374
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
permissiveLicenseKey
|
|
318
|
-
)) as ValidLicenseKeyResult
|
|
319
|
-
expect(result.isDomainValid).toBe(false)
|
|
320
|
-
})
|
|
375
|
+
it('Checks for evaluation license', async () => {
|
|
376
|
+
const evaluationLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
377
|
+
evaluationLicenseInfo[PROPERTIES.FLAGS] = FLAGS.EVALUATION_LICENSE
|
|
378
|
+
const evaluationLicenseKey = await generateLicenseKey(
|
|
379
|
+
JSON.stringify(evaluationLicenseInfo),
|
|
380
|
+
keyPair
|
|
381
|
+
)
|
|
382
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
383
|
+
evaluationLicenseKey
|
|
384
|
+
)) as ValidLicenseKeyResult
|
|
385
|
+
expect(result.isEvaluationLicense).toBe(true)
|
|
386
|
+
expect(result.isEvaluationLicenseExpired).toBe(false)
|
|
387
|
+
})
|
|
321
388
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
389
|
+
it('Detects when evaluation license has expired', async () => {
|
|
390
|
+
const expiredEvaluationLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
391
|
+
expiredEvaluationLicenseInfo[PROPERTIES.FLAGS] = FLAGS.EVALUATION_LICENSE
|
|
392
|
+
const expiredDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1) // 1 day ago
|
|
393
|
+
expiredEvaluationLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiredDate.toISOString()
|
|
394
|
+
|
|
395
|
+
const expiredEvaluationLicenseKey = await generateLicenseKey(
|
|
396
|
+
JSON.stringify(expiredEvaluationLicenseInfo),
|
|
397
|
+
keyPair
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
// The getLicenseFromKey should return the expired state
|
|
401
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
402
|
+
expiredEvaluationLicenseKey
|
|
403
|
+
)) as ValidLicenseKeyResult
|
|
404
|
+
expect(result.isEvaluationLicense).toBe(true)
|
|
405
|
+
expect(result.isEvaluationLicenseExpired).toBe(true)
|
|
406
|
+
})
|
|
340
407
|
})
|
|
341
408
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
409
|
+
describe('License expiry and grace period', () => {
|
|
410
|
+
it('Fails if the license key has expired beyond grace period', async () => {
|
|
411
|
+
const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
412
|
+
const expiryDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 40) // 40 days ago (beyond 30-day grace period)
|
|
413
|
+
expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiryDate
|
|
414
|
+
const expiredLicenseKey = await generateLicenseKey(
|
|
415
|
+
JSON.stringify(expiredLicenseInfo),
|
|
416
|
+
keyPair
|
|
417
|
+
)
|
|
418
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
419
|
+
expiredLicenseKey
|
|
420
|
+
)) as ValidLicenseKeyResult
|
|
421
|
+
expect(result.isAnnualLicenseExpired).toBe(true)
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
it('Allows a grace period for expired licenses', async () => {
|
|
425
|
+
const almostExpiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
426
|
+
const expiryDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 5) // 5 days ago
|
|
427
|
+
almostExpiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiryDate
|
|
428
|
+
const almostExpiredLicenseKey = await generateLicenseKey(
|
|
429
|
+
JSON.stringify(almostExpiredLicenseInfo),
|
|
430
|
+
keyPair
|
|
431
|
+
)
|
|
432
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
433
|
+
almostExpiredLicenseKey
|
|
434
|
+
)) as ValidLicenseKeyResult
|
|
435
|
+
expect(result.isAnnualLicenseExpired).toBe(false)
|
|
436
|
+
})
|
|
361
437
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
438
|
+
it('Handles grace period correctly - 20 days expired should still be within grace period', async () => {
|
|
439
|
+
const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
440
|
+
const expiredDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 20) // 20 days ago
|
|
441
|
+
expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiredDate.toISOString()
|
|
442
|
+
|
|
443
|
+
const expiredLicenseKey = await generateLicenseKey(
|
|
444
|
+
JSON.stringify(expiredLicenseInfo),
|
|
445
|
+
keyPair
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
// Test the getLicenseFromKey method to verify grace period calculation
|
|
449
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
450
|
+
expiredLicenseKey
|
|
451
|
+
)) as ValidLicenseKeyResult
|
|
452
|
+
expect(result.isAnnualLicense).toBe(true)
|
|
453
|
+
expect(result.isAnnualLicenseExpired).toBe(false) // Within 30-day grace period
|
|
454
|
+
expect(result.daysSinceExpiry).toBe(20)
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
it('Calculates days since expiry correctly', async () => {
|
|
458
|
+
const expiredLicenseInfo = JSON.parse(STANDARD_LICENSE_INFO)
|
|
459
|
+
const expiredDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 15) // 15 days ago
|
|
460
|
+
expiredLicenseInfo[PROPERTIES.EXPIRY_DATE] = expiredDate.toISOString()
|
|
461
|
+
|
|
462
|
+
const expiredLicenseKey = await generateLicenseKey(
|
|
463
|
+
JSON.stringify(expiredLicenseInfo),
|
|
464
|
+
keyPair
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
468
|
+
expiredLicenseKey
|
|
469
|
+
)) as ValidLicenseKeyResult
|
|
470
|
+
expect(result.daysSinceExpiry).toBe(15)
|
|
471
|
+
})
|
|
373
472
|
})
|
|
374
473
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
474
|
+
describe('Perpetual licenses', () => {
|
|
475
|
+
// We mock the patch version to be in 2030 above.
|
|
476
|
+
it('Succeeds for perpetual license with correct version (and patch does not matter)', async () => {
|
|
477
|
+
const majorDate = new Date(publishDates.major)
|
|
478
|
+
const expiryDate = new Date(
|
|
479
|
+
majorDate.getFullYear(),
|
|
480
|
+
majorDate.getMonth(),
|
|
481
|
+
majorDate.getDate() + 100
|
|
482
|
+
)
|
|
483
|
+
const perpetualLicenseInfo = ['id', ['www.example.com'], FLAGS.PERPETUAL_LICENSE, expiryDate]
|
|
484
|
+
const almostExpiredLicenseKey = await generateLicenseKey(
|
|
485
|
+
JSON.stringify(perpetualLicenseInfo),
|
|
486
|
+
keyPair
|
|
487
|
+
)
|
|
488
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
489
|
+
almostExpiredLicenseKey
|
|
490
|
+
)) as ValidLicenseKeyResult
|
|
491
|
+
expect(result.isPerpetualLicense).toBe(true)
|
|
492
|
+
expect(result.isPerpetualLicenseExpired).toBe(false)
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
it('Fails for perpetual license past the release version', async () => {
|
|
496
|
+
const majorDate = new Date(publishDates.major)
|
|
497
|
+
const expiryDate = new Date(
|
|
498
|
+
majorDate.getFullYear(),
|
|
499
|
+
majorDate.getMonth(),
|
|
500
|
+
majorDate.getDate() - 100
|
|
501
|
+
)
|
|
502
|
+
const perpetualLicenseInfo = ['id', ['www.example.com'], FLAGS.PERPETUAL_LICENSE, expiryDate]
|
|
503
|
+
const almostExpiredLicenseKey = await generateLicenseKey(
|
|
504
|
+
JSON.stringify(perpetualLicenseInfo),
|
|
505
|
+
keyPair
|
|
506
|
+
)
|
|
507
|
+
const result = (await licenseManager.getLicenseFromKey(
|
|
508
|
+
almostExpiredLicenseKey
|
|
509
|
+
)) as ValidLicenseKeyResult
|
|
510
|
+
expect(result.isPerpetualLicense).toBe(true)
|
|
511
|
+
expect(result.isPerpetualLicenseExpired).toBe(true)
|
|
512
|
+
})
|
|
386
513
|
})
|
|
387
514
|
})
|
|
388
515
|
|
|
@@ -469,12 +596,16 @@ function getDefaultLicenseResult(overrides: Partial<ValidLicenseKeyResult>): Val
|
|
|
469
596
|
isAnnualLicense: true,
|
|
470
597
|
isAnnualLicenseExpired: false,
|
|
471
598
|
isInternalLicense: false,
|
|
599
|
+
isNativeLicense: false,
|
|
472
600
|
isDevelopment: false,
|
|
473
601
|
isDomainValid: true,
|
|
474
602
|
isPerpetualLicense: false,
|
|
475
603
|
isPerpetualLicenseExpired: false,
|
|
476
604
|
isLicenseParseable: true as const,
|
|
477
605
|
isLicensedWithWatermark: false,
|
|
606
|
+
isEvaluationLicense: false,
|
|
607
|
+
isEvaluationLicenseExpired: false,
|
|
608
|
+
daysSinceExpiry: 0,
|
|
478
609
|
// WatermarkManager does not check these fields, it relies on the calculated values like isAnnualLicenseExpired
|
|
479
610
|
license: {
|
|
480
611
|
id: 'id',
|
|
@@ -488,121 +619,290 @@ function getDefaultLicenseResult(overrides: Partial<ValidLicenseKeyResult>): Val
|
|
|
488
619
|
}
|
|
489
620
|
|
|
490
621
|
describe('getLicenseState', () => {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
622
|
+
describe('Development mode', () => {
|
|
623
|
+
it('returns "unlicensed" for unparseable license in development', () => {
|
|
624
|
+
const licenseResult = getDefaultLicenseResult({
|
|
625
|
+
// @ts-ignore
|
|
626
|
+
isLicenseParseable: false,
|
|
627
|
+
})
|
|
628
|
+
expect(getLicenseState(licenseResult, () => {}, true)).toBe('unlicensed')
|
|
495
629
|
})
|
|
496
|
-
expect(getLicenseState(licenseResult)).toBe('unlicensed')
|
|
497
|
-
})
|
|
498
630
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
631
|
+
it('returns "licensed" for invalid domain in development mode', () => {
|
|
632
|
+
const licenseResult = getDefaultLicenseResult({
|
|
633
|
+
isDomainValid: false,
|
|
634
|
+
isDevelopment: true,
|
|
635
|
+
})
|
|
636
|
+
expect(getLicenseState(licenseResult, () => {}, true)).toBe('licensed')
|
|
503
637
|
})
|
|
504
|
-
expect(getLicenseState(licenseResult)).toBe('unlicensed')
|
|
505
|
-
})
|
|
506
638
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
639
|
+
it('returns "licensed" for valid license in development mode', () => {
|
|
640
|
+
const licenseResult = getDefaultLicenseResult({
|
|
641
|
+
isDevelopment: true,
|
|
642
|
+
})
|
|
643
|
+
expect(getLicenseState(licenseResult, () => {}, true)).toBe('licensed')
|
|
511
644
|
})
|
|
512
|
-
expect(getLicenseState(licenseResult)).toBe('licensed')
|
|
513
|
-
})
|
|
514
645
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
646
|
+
it('returns "unlicensed" for no license key in development (localhost)', () => {
|
|
647
|
+
const licenseResult = getDefaultLicenseResult({
|
|
648
|
+
// @ts-ignore
|
|
649
|
+
isLicenseParseable: false,
|
|
650
|
+
reason: 'no-key-provided',
|
|
651
|
+
})
|
|
652
|
+
expect(getLicenseState(licenseResult, () => {}, true)).toBe('unlicensed')
|
|
520
653
|
})
|
|
521
|
-
expect(getLicenseState(licenseResult)).toBe('unlicensed')
|
|
522
654
|
})
|
|
523
655
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
656
|
+
describe('Production mode - unlicensed states', () => {
|
|
657
|
+
it('returns "unlicensed-production" for unparseable license in production (invalid-license-key)', () => {
|
|
658
|
+
const messages: string[][] = []
|
|
659
|
+
const licenseResult = getDefaultLicenseResult({
|
|
660
|
+
// @ts-ignore
|
|
661
|
+
isLicenseParseable: false,
|
|
662
|
+
reason: 'invalid-license-key',
|
|
663
|
+
})
|
|
664
|
+
const result = getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)
|
|
665
|
+
expect(result).toBe('unlicensed-production')
|
|
666
|
+
|
|
667
|
+
expect(messages).toHaveLength(1)
|
|
668
|
+
expect(messages[0]).toEqual([
|
|
669
|
+
'Invalid license key. tldraw requires a valid license for production use.',
|
|
670
|
+
'Please reach out to sales@tldraw.com to purchase a license.',
|
|
671
|
+
])
|
|
530
672
|
})
|
|
531
|
-
expect(getLicenseState(licenseResult)).toBe('unlicensed')
|
|
532
|
-
})
|
|
533
673
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
674
|
+
it('returns "unlicensed-production" for no license key in production', () => {
|
|
675
|
+
const messages: string[][] = []
|
|
676
|
+
const licenseResult = getDefaultLicenseResult({
|
|
677
|
+
// @ts-ignore
|
|
678
|
+
isLicenseParseable: false,
|
|
679
|
+
reason: 'no-key-provided',
|
|
680
|
+
})
|
|
681
|
+
const result = getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)
|
|
682
|
+
expect(result).toBe('unlicensed-production')
|
|
683
|
+
|
|
684
|
+
expect(messages).toHaveLength(1)
|
|
685
|
+
expect(messages[0]).toEqual([
|
|
686
|
+
'No tldraw license key provided!',
|
|
687
|
+
'A license is required for production deployments.',
|
|
688
|
+
'Please reach out to sales@tldraw.com to purchase a license.',
|
|
689
|
+
])
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
it('returns "unlicensed-production" for invalid license key in production', () => {
|
|
693
|
+
const messages: string[][] = []
|
|
694
|
+
const licenseResult = getDefaultLicenseResult({
|
|
695
|
+
// @ts-ignore
|
|
696
|
+
isLicenseParseable: false,
|
|
697
|
+
reason: 'invalid-license-key',
|
|
698
|
+
})
|
|
699
|
+
const result = getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)
|
|
700
|
+
expect(result).toBe('unlicensed-production')
|
|
701
|
+
|
|
702
|
+
expect(messages).toHaveLength(1)
|
|
703
|
+
expect(messages[0]).toEqual([
|
|
704
|
+
'Invalid license key. tldraw requires a valid license for production use.',
|
|
705
|
+
'Please reach out to sales@tldraw.com to purchase a license.',
|
|
706
|
+
])
|
|
539
707
|
})
|
|
540
|
-
expect(getLicenseState(licenseResult)).toBe('unlicensed')
|
|
541
|
-
})
|
|
542
708
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
709
|
+
it('returns "unlicensed-production" for invalid domain in production', () => {
|
|
710
|
+
const messages: string[][] = []
|
|
711
|
+
const licenseResult = getDefaultLicenseResult({
|
|
712
|
+
isDomainValid: false,
|
|
713
|
+
isDevelopment: false,
|
|
714
|
+
})
|
|
715
|
+
const result = getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)
|
|
716
|
+
expect(result).toBe('unlicensed-production')
|
|
717
|
+
|
|
718
|
+
expect(messages).toHaveLength(1)
|
|
719
|
+
expect(messages[0]).toEqual([
|
|
720
|
+
'License key is not valid for this domain.',
|
|
721
|
+
'A license is required for production deployments.',
|
|
722
|
+
'Please reach out to sales@tldraw.com to purchase a license.',
|
|
723
|
+
])
|
|
551
724
|
})
|
|
552
|
-
expect(getLicenseState(licenseResult)).toBe('internal-expired')
|
|
553
|
-
})
|
|
554
725
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
726
|
+
it('returns "unlicensed-production" for expired internal license with invalid domain', () => {
|
|
727
|
+
const messages: string[][] = []
|
|
728
|
+
const expiryDate = new Date(2023, 1, 1)
|
|
729
|
+
const licenseResult = getDefaultLicenseResult({
|
|
730
|
+
isAnnualLicense: true,
|
|
731
|
+
isAnnualLicenseExpired: true,
|
|
732
|
+
isInternalLicense: true,
|
|
733
|
+
isDomainValid: false,
|
|
734
|
+
expiryDate,
|
|
735
|
+
})
|
|
736
|
+
const result = getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)
|
|
737
|
+
expect(result).toBe('unlicensed-production')
|
|
738
|
+
|
|
739
|
+
expect(messages).toHaveLength(1)
|
|
740
|
+
expect(messages[0]).toEqual([
|
|
741
|
+
'License key is not valid for this domain.',
|
|
742
|
+
'A license is required for production deployments.',
|
|
743
|
+
'Please reach out to sales@tldraw.com to purchase a license.',
|
|
744
|
+
])
|
|
563
745
|
})
|
|
564
|
-
expect(getLicenseState(licenseResult)).toBe('internal-expired')
|
|
565
746
|
})
|
|
566
747
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
expiryDate,
|
|
748
|
+
describe('Valid licenses', () => {
|
|
749
|
+
it('returns "licensed" for valid annual license', () => {
|
|
750
|
+
const licenseResult = getDefaultLicenseResult({
|
|
751
|
+
isAnnualLicense: true,
|
|
752
|
+
isAnnualLicenseExpired: false,
|
|
753
|
+
})
|
|
754
|
+
expect(getLicenseState(licenseResult, () => {}, false)).toBe('licensed')
|
|
575
755
|
})
|
|
576
|
-
expect(getLicenseState(licenseResult)).toBe('unlicensed')
|
|
577
|
-
})
|
|
578
756
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
757
|
+
it('returns "licensed" for valid perpetual license', () => {
|
|
758
|
+
const licenseResult = getDefaultLicenseResult({
|
|
759
|
+
isPerpetualLicense: true,
|
|
760
|
+
isPerpetualLicenseExpired: false,
|
|
761
|
+
})
|
|
762
|
+
expect(getLicenseState(licenseResult, () => {}, false)).toBe('licensed')
|
|
582
763
|
})
|
|
583
|
-
expect(getLicenseState(licenseResult)).toBe('licensed-with-watermark')
|
|
584
|
-
})
|
|
585
764
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
765
|
+
it('returns "licensed-with-watermark" for watermarked license', () => {
|
|
766
|
+
const licenseResult = getDefaultLicenseResult({
|
|
767
|
+
isLicensedWithWatermark: true,
|
|
768
|
+
})
|
|
769
|
+
expect(getLicenseState(licenseResult, () => {}, false)).toBe('licensed-with-watermark')
|
|
770
|
+
})
|
|
771
|
+
|
|
772
|
+
it('returns "licensed" for valid evaluation license', () => {
|
|
773
|
+
const licenseResult = getDefaultLicenseResult({
|
|
774
|
+
isEvaluationLicense: true,
|
|
775
|
+
isLicensedWithWatermark: false, // Evaluation license doesn't need WITH_WATERMARK flag
|
|
776
|
+
isAnnualLicense: false,
|
|
777
|
+
isPerpetualLicense: false,
|
|
778
|
+
})
|
|
779
|
+
|
|
780
|
+
// Evaluation license should be licensed but tracked (no watermark shown)
|
|
781
|
+
expect(getLicenseState(licenseResult, () => {}, false)).toBe('licensed')
|
|
782
|
+
|
|
783
|
+
// Verify evaluation license properties
|
|
784
|
+
expect(licenseResult.isEvaluationLicense).toBe(true)
|
|
785
|
+
expect(licenseResult.isLicensedWithWatermark).toBe(false) // No explicit watermark flag needed
|
|
786
|
+
expect(licenseResult.isAnnualLicense).toBe(false)
|
|
787
|
+
expect(licenseResult.isPerpetualLicense).toBe(false)
|
|
590
788
|
})
|
|
591
|
-
expect(getLicenseState(licenseResult)).toBe('licensed')
|
|
592
789
|
})
|
|
593
790
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
791
|
+
describe('Grace period handling', () => {
|
|
792
|
+
it('returns "licensed" for license 0-30 days past expiry', () => {
|
|
793
|
+
const messages: string[][] = []
|
|
794
|
+
const licenseResult = getDefaultLicenseResult({
|
|
795
|
+
isAnnualLicense: true,
|
|
796
|
+
isAnnualLicenseExpired: false, // Still within 30-day grace period
|
|
797
|
+
daysSinceExpiry: 20, // 20 days past expiry
|
|
798
|
+
isInternalLicense: false,
|
|
799
|
+
})
|
|
800
|
+
|
|
801
|
+
expect(getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)).toBe('licensed')
|
|
802
|
+
|
|
803
|
+
expect(messages).toHaveLength(1)
|
|
804
|
+
expect(messages[0]).toEqual([
|
|
805
|
+
'Your tldraw license has expired.',
|
|
806
|
+
'License expired 20 days ago.',
|
|
807
|
+
'Please reach out to sales@tldraw.com to renew your license.',
|
|
808
|
+
])
|
|
598
809
|
})
|
|
599
|
-
expect(getLicenseState(licenseResult)).toBe('licensed')
|
|
600
810
|
})
|
|
601
811
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
812
|
+
describe('Expired licenses', () => {
|
|
813
|
+
it('returns "expired" for license 30+ days past expiry', () => {
|
|
814
|
+
const messages: string[][] = []
|
|
815
|
+
const licenseResult = getDefaultLicenseResult({
|
|
816
|
+
isAnnualLicense: true,
|
|
817
|
+
isAnnualLicenseExpired: true, // Beyond 30-day grace period
|
|
818
|
+
daysSinceExpiry: 35, // 35 days past expiry
|
|
819
|
+
isInternalLicense: false,
|
|
820
|
+
})
|
|
821
|
+
|
|
822
|
+
expect(getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)).toBe('expired')
|
|
823
|
+
|
|
824
|
+
expect(messages).toHaveLength(1)
|
|
825
|
+
expect(messages[0]).toEqual([
|
|
826
|
+
'Your tldraw license has been expired for more than 30 days!',
|
|
827
|
+
'Please reach out to sales@tldraw.com to renew your license.',
|
|
828
|
+
])
|
|
829
|
+
})
|
|
830
|
+
|
|
831
|
+
it('returns "expired" for expired annual license even in dev mode', () => {
|
|
832
|
+
const licenseResult = getDefaultLicenseResult({
|
|
833
|
+
isAnnualLicense: true,
|
|
834
|
+
isAnnualLicenseExpired: true,
|
|
835
|
+
isDevelopment: true,
|
|
836
|
+
isInternalLicense: false,
|
|
837
|
+
})
|
|
838
|
+
expect(getLicenseState(licenseResult, () => {}, true)).toBe('expired')
|
|
839
|
+
})
|
|
840
|
+
|
|
841
|
+
it('returns "expired" for expired perpetual license', () => {
|
|
842
|
+
const licenseResult = getDefaultLicenseResult({
|
|
843
|
+
isPerpetualLicense: true,
|
|
844
|
+
isPerpetualLicenseExpired: true,
|
|
845
|
+
isInternalLicense: false,
|
|
846
|
+
})
|
|
847
|
+
expect(getLicenseState(licenseResult, () => {}, false)).toBe('expired')
|
|
848
|
+
})
|
|
849
|
+
|
|
850
|
+
it('returns "expired" for expired evaluation license', () => {
|
|
851
|
+
const messages: string[][] = []
|
|
852
|
+
const licenseResult = getDefaultLicenseResult({
|
|
853
|
+
isEvaluationLicense: true,
|
|
854
|
+
isEvaluationLicenseExpired: true,
|
|
855
|
+
isAnnualLicense: false,
|
|
856
|
+
isPerpetualLicense: false,
|
|
857
|
+
})
|
|
858
|
+
|
|
859
|
+
expect(getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)).toBe('expired')
|
|
860
|
+
|
|
861
|
+
expect(messages).toHaveLength(1)
|
|
862
|
+
expect(messages[0]).toEqual([
|
|
863
|
+
'Your tldraw evaluation license has expired!',
|
|
864
|
+
'Please reach out to sales@tldraw.com to purchase a full license.',
|
|
865
|
+
])
|
|
866
|
+
})
|
|
867
|
+
|
|
868
|
+
it('returns "expired" for expired internal annual license with valid domain', () => {
|
|
869
|
+
const messages: string[][] = []
|
|
870
|
+
const expiryDate = new Date(2023, 1, 1)
|
|
871
|
+
const licenseResult = getDefaultLicenseResult({
|
|
872
|
+
isAnnualLicense: true,
|
|
873
|
+
isAnnualLicenseExpired: true,
|
|
874
|
+
isInternalLicense: true,
|
|
875
|
+
isDomainValid: true,
|
|
876
|
+
expiryDate,
|
|
877
|
+
})
|
|
878
|
+
|
|
879
|
+
expect(getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)).toBe('expired')
|
|
880
|
+
|
|
881
|
+
expect(messages).toHaveLength(1)
|
|
882
|
+
expect(messages[0]).toEqual([
|
|
883
|
+
'Your tldraw license has been expired for more than 30 days!',
|
|
884
|
+
'Please reach out to sales@tldraw.com to renew your license.',
|
|
885
|
+
])
|
|
886
|
+
})
|
|
887
|
+
|
|
888
|
+
it('returns "expired" for expired internal perpetual license with valid domain', () => {
|
|
889
|
+
const messages: string[][] = []
|
|
890
|
+
const expiryDate = new Date(2023, 1, 1)
|
|
891
|
+
const licenseResult = getDefaultLicenseResult({
|
|
892
|
+
isPerpetualLicense: true,
|
|
893
|
+
isPerpetualLicenseExpired: true,
|
|
894
|
+
isInternalLicense: true,
|
|
895
|
+
isDomainValid: true,
|
|
896
|
+
expiryDate,
|
|
897
|
+
})
|
|
898
|
+
|
|
899
|
+
expect(getLicenseState(licenseResult, (msgs) => messages.push(msgs), false)).toBe('expired')
|
|
900
|
+
|
|
901
|
+
expect(messages).toHaveLength(1)
|
|
902
|
+
expect(messages[0]).toEqual([
|
|
903
|
+
'Your tldraw license has been expired for more than 30 days!',
|
|
904
|
+
'Please reach out to sales@tldraw.com to renew your license.',
|
|
905
|
+
])
|
|
605
906
|
})
|
|
606
|
-
expect(getLicenseState(licenseResult)).toBe('licensed')
|
|
607
907
|
})
|
|
608
908
|
})
|