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