@codeo-engineering/licenserail-youtrack 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Codeo Solutions Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # @codeo-engineering/licenserail-youtrack
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Sell your YouTrack app with LicenseRail license keys: activation per YouTrack instance, keyless trials, per-user limits
4
+ and a ready **License** page in the administration menu. Built on [`@codeo-engineering/licenserail-embedded`](../embedded); everything that
5
+ ends up in your app is readable JavaScript, as JetBrains Marketplace requires.
6
+
7
+ Needs YouTrack 2026.2 or later (async HTTP).
8
+
9
+ ## Add it to your app
10
+
11
+ ```sh
12
+ npx @codeo-engineering/licenserail-youtrack add ./my-app \
13
+ --vendor ten_... --product my-app --key-id <key id> --public-key public-key.pem
14
+ ```
15
+
16
+ Take the values from the LicenseRail dashboard: the organization id from Settings, the key id and public key from API keys.
17
+ The command:
18
+
19
+ - copies `licenserail-core.js`, `licenserail.js`, `licenserail-license.js` and the `widgets/licenserail-license` page,
20
+ - writes `licenserail-config.js` (once; none of its values is a secret),
21
+ - adds the secret `licenseKey` setting to `settings.json`, the storage fields to `entity-extensions.json`, and the License
22
+ page to `manifest.json` (and raises `minYouTrackVersion` to 2026.2).
23
+
24
+ Run it again to update the LicenseRail files. For apps built with Vite, pass `--backend src` (the folder that holds your
25
+ backend `.js` files).
26
+
27
+ ## Check the license in your handlers
28
+
29
+ ```js
30
+ const licenserail = require('./licenserail');
31
+
32
+ exports.httpHandler = {
33
+ endpoints: [{
34
+ method: 'GET', path: 'summary',
35
+ handle(ctx) {
36
+ const license = licenserail.check(ctx); // offline: no network call
37
+ if (!license.valid) { ctx.response.statusCode = 402; ctx.response.json({ error: 'license_required' }); return; }
38
+ if (licenserail.hasFeature(ctx, 'advanced-reports')) { /* ... */ }
39
+ },
40
+ }],
41
+ asyncFunctions: licenserail.asyncFunctions, // lets check() schedule the daily refresh
42
+ };
43
+ ```
44
+
45
+ `check(ctx)` returns `{ valid, status, summary }`; `summary` has `isTrial`, `expiresAt`, `entitlements`, `metadata`,
46
+ `maxHostUsers`, `hostUserPolicy` and `hostUsersOverLimit`. The License page and its endpoints are for administrators only
47
+ and never return the key or the token.
48
+
49
+ ## How it works
50
+
51
+ - **Installation:** the License page reads the instance id (`/api/config` → `uuid`) and the backend licenses that instance.
52
+ The backend can't read the id itself, so activation and trials start once an administrator has opened the page. If the id
53
+ ever changes (a move or a restore), activate again and release the old instance in LicenseRail.
54
+ - **License key:** the administrator enters it in the app's settings (a secret setting). YouTrack sends it only as
55
+ `Authorization: Bearer`; scripts never see it.
56
+ - **Activation, trial, refresh, release:** async HTTP (`postAsync`); the answer is stored in app storage and the page
57
+ shows the result. The license is refreshed daily; network errors keep it working until its offline period ends.
58
+ - **Users:** the instance's user count is sent with activations and refreshes; the license decides (block, warn or report).
59
+ - **Trials:** one per YouTrack instance, reinstalls included; no key ships with the app.
60
+
61
+ ## Marketplace listing
62
+
63
+ JetBrains asks you to disclose calls to a license server. Suggested text: *"The app contacts LicenseRail
64
+ (api.licenserail.com), operated by Codeo Solutions Limited, to activate and verify its license. It sends the license key,
65
+ the app version, the number of users of this YouTrack instance, and a hashed identifier of the instance."* Link your
66
+ privacy policy, and use a custom license (EULA) rather than an open-source one; see the end-user license template in the
67
+ LicenseRail docs.
68
+
69
+ ## Develop and test
70
+
71
+ `npm test` builds `dist/app-files` and runs the app files against a fake YouTrack runtime (async HTTP, storage, settings,
72
+ permissions), including a run without web or Node globals. `example/` is a minimal app; add LicenseRail to it with the
73
+ command above.
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ // Adds LicenseRail to a YouTrack app:
3
+ // npx @codeo-engineering/licenserail-youtrack add <app folder> [--vendor ten_...] [--product code] [--key-id id] [--public-key key.pem]
4
+ // [--api-url https://api.licenserail.com] [--backend <folder of backend .js files>]
5
+ // Copies the backend modules and the License page, merges settings.json, entity-extensions.json and manifest.json, and
6
+ // writes licenserail-config.js (only if it doesn't exist yet). Running it again updates the LicenseRail files.
7
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
8
+ import { dirname, join, resolve } from 'node:path'
9
+ import { fileURLToPath } from 'node:url'
10
+
11
+ const here = dirname(fileURLToPath(import.meta.url))
12
+ const files = join(here, '..', 'dist', 'app-files')
13
+ const fragments = JSON.parse(readFileSync(join(files, 'fragments.json'), 'utf8'))
14
+
15
+ // Not cpSync: Node 22's crashes on Windows when the path has non-ASCII characters (e.g. the user's name).
16
+ function copyFolder(from, to) {
17
+ mkdirSync(to, { recursive: true })
18
+ for (const f of readdirSync(from, { withFileTypes: true })) {
19
+ if (f.isDirectory()) copyFolder(join(from, f.name), join(to, f.name))
20
+ else writeFileSync(join(to, f.name), readFileSync(join(from, f.name)))
21
+ }
22
+ }
23
+
24
+ function usage(message) {
25
+ if (message) console.error(message)
26
+ console.error('Usage: licenserail-youtrack add <app folder> [--vendor ten_...] [--product code] [--key-id id] [--public-key key.pem] [--api-url url] [--backend folder]')
27
+ process.exit(1)
28
+ }
29
+
30
+ const args = process.argv.slice(2)
31
+ if (args[0] !== 'add' || !args[1]) usage()
32
+ const appDir = resolve(args[1])
33
+ const opt = {}
34
+ for (let i = 2; i < args.length; i += 2) {
35
+ if (!args[i].startsWith('--') || args[i + 1] === undefined) usage(`Unexpected argument: ${args[i]}`)
36
+ opt[args[i].slice(2)] = args[i + 1]
37
+ }
38
+ const manifestPath = join(appDir, 'manifest.json')
39
+ if (!existsSync(manifestPath)) usage(`No manifest.json in ${appDir}`)
40
+ const backend = resolve(appDir, opt.backend ?? '.')
41
+
42
+ const readJson = (path, fallback) => (existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : fallback)
43
+ const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n')
44
+
45
+ // Backend modules and the License page (always replaced, so updates land).
46
+ for (const name of ['licenserail-core.js', 'licenserail.js', 'licenserail-license.js']) writeFileSync(join(backend, name), readFileSync(join(files, name)))
47
+ copyFolder(join(files, 'widgets', 'licenserail-license'), join(backend, 'widgets', 'licenserail-license'))
48
+
49
+ // Configuration (kept once written).
50
+ const configPath = join(backend, 'licenserail-config.js')
51
+ if (!existsSync(configPath)) {
52
+ let config = readFileSync(join(files, 'licenserail-config.js'), 'utf8')
53
+ const pem = opt['public-key'] ? readFileSync(resolve(opt['public-key']), 'utf8').trim() : null
54
+ if (opt['api-url']) config = config.replace('https://api.licenserail.com', opt['api-url'])
55
+ if (opt.vendor) config = config.replace('__VENDOR_ID__', opt.vendor)
56
+ if (opt.product) config = config.replace('__PRODUCT_CODE__', opt.product)
57
+ if (opt['key-id']) config = config.replace('__KEY_ID__', opt['key-id'])
58
+ if (pem) config = config.replace("'__PUBLIC_KEY_PEM__'", JSON.stringify(pem + '\n'))
59
+ writeFileSync(configPath, config)
60
+ }
61
+
62
+ // settings.json: the secret license key setting.
63
+ const settingsPath = join(backend, 'settings.json')
64
+ const settings = readJson(settingsPath, { $schema: 'http://json-schema.org/draft-07/schema#', type: 'object', properties: {} })
65
+ settings.properties = Object.assign({}, fragments.settings, settings.properties ?? {})
66
+ writeJson(settingsPath, settings)
67
+
68
+ // entity-extensions.json: where the token and state are kept.
69
+ const extensionsPath = join(backend, 'entity-extensions.json')
70
+ const extensions = readJson(extensionsPath, { entityTypeExtensions: [] })
71
+ let storage = extensions.entityTypeExtensions.find((e) => e.entityType === 'AppGlobalStorage')
72
+ if (!storage) extensions.entityTypeExtensions.push((storage = { entityType: 'AppGlobalStorage', properties: {} }))
73
+ storage.properties = Object.assign({}, storage.properties ?? {}, fragments.appGlobalStorage)
74
+ writeJson(extensionsPath, extensions)
75
+
76
+ // manifest.json: the License page and the minimum YouTrack version (async HTTP needs 2026.2).
77
+ const manifest = readJson(manifestPath, {})
78
+ manifest.widgets = (manifest.widgets ?? []).filter((w) => w.key !== fragments.widget.key)
79
+ const widget = { ...fragments.widget }
80
+ if (backend !== appDir) widget.indexPath = join(backend.slice(appDir.length + 1), widget.indexPath).replace(/\\/g, '/')
81
+ manifest.widgets.push(widget)
82
+ const version = (v) => (v ?? '0').split('.').map(Number)
83
+ const [a1, a2] = version(manifest.minYouTrackVersion), [b1, b2] = version(fragments.minYouTrackVersion)
84
+ if (a1 < b1 || (a1 === b1 && (a2 ?? 0) < b2)) manifest.minYouTrackVersion = fragments.minYouTrackVersion
85
+ writeJson(manifestPath, manifest)
86
+
87
+ console.log(`LicenseRail added to ${appDir}`)
88
+ if (readFileSync(configPath, 'utf8').includes('__')) console.log(`Fill in ${configPath} with the values from the LicenseRail dashboard.`)
89
+ console.log('In your handlers: const licenserail = require(\'./licenserail\'); licenserail.check(ctx).valid; asyncFunctions: licenserail.asyncFunctions')
@@ -0,0 +1,25 @@
1
+ {
2
+ "settings": {
3
+ "licenseKey": {
4
+ "type": "string",
5
+ "format": "secret",
6
+ "title": "License key",
7
+ "description": "The license key you received when you bought the app."
8
+ }
9
+ },
10
+ "appGlobalStorage": {
11
+ "licenserailToken": { "type": "string" },
12
+ "licenserailLastSeen": { "type": "string" },
13
+ "licenserailInstallation": { "type": "string" },
14
+ "licenserailState": { "type": "string" }
15
+ },
16
+ "widget": {
17
+ "key": "licenserail-license",
18
+ "name": "License",
19
+ "description": "License status, activation and trial",
20
+ "indexPath": "widgets/licenserail-license/index.html",
21
+ "extensionPoint": "ADMINISTRATION_MENU_ITEM",
22
+ "permissions": ["ADMIN_UPDATE_APP"]
23
+ },
24
+ "minYouTrackVersion": "2026.2"
25
+ }
@@ -0,0 +1,15 @@
1
+ // LicenseRail settings for this app. Copy the values from the dashboard (Settings, Products, API keys). None of them is a
2
+ // secret: the license key is entered by the customer's administrator in the app settings, never here.
3
+ module.exports = {
4
+ apiUrl: 'https://api.licenserail.com',
5
+ /** Your organization id (ten_...). */
6
+ vendor: '__VENDOR_ID__',
7
+ /** The product code from the dashboard. */
8
+ product: '__PRODUCT_CODE__',
9
+ /** The environment's signing key id (for keyless trials). */
10
+ keyId: '__KEY_ID__',
11
+ /** The environment's public key (PEM). */
12
+ publicKeyPem: '__PUBLIC_KEY_PEM__',
13
+ /** Your app's version, reported with activations. */
14
+ appVersion: '1.0.0',
15
+ };