@codeo-engineering/licenserail-youtrack 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -56,7 +56,9 @@ and never return the key or the token.
56
56
  - **Activation, trial, refresh, release:** async HTTP (`postAsync`); the answer is stored in app storage and the page
57
57
  shows the result. The license is refreshed daily; network errors keep it working until its offline period ends.
58
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.
59
+ - **Trials:** one per YouTrack instance, reinstalls included; no key ships with the app. LicenseRail confirms the instance at its
60
+ address first, so it must be reachable from the internet (self-hosted behind a firewall: give a trial key instead). Needs 0.1.2
61
+ or later for trials started from your own code.
60
62
 
61
63
  ## Marketplace listing
62
64
 
@@ -11,6 +11,7 @@
11
11
  "licenserailToken": { "type": "string" },
12
12
  "licenserailLastSeen": { "type": "string" },
13
13
  "licenserailInstallation": { "type": "string" },
14
+ "licenserailBaseUrls": { "type": "string" },
14
15
  "licenserailState": { "type": "string" }
15
16
  },
16
17
  "widget": {
@@ -26,8 +26,8 @@ function body(ctx) {
26
26
  }
27
27
 
28
28
  function remember(ctx) {
29
- const id = body(ctx).installationId;
30
- if (id) licenserail.setInstallation(ctx, id);
29
+ const b = body(ctx);
30
+ if (b.installationId) licenserail.setInstallation(ctx, b.installationId, b.baseUrls);
31
31
  }
32
32
 
33
33
  exports.httpHandler = {
@@ -18,6 +18,7 @@ const PROPERTY = {
18
18
  token: 'licenserailToken',
19
19
  lastSeen: 'licenserailLastSeen',
20
20
  installation: 'licenserailInstallation',
21
+ baseUrls: 'licenserailBaseUrls',
21
22
  state: 'licenserailState',
22
23
  };
23
24
  const PLATFORM = 'youtrack';
@@ -105,10 +106,21 @@ function hasFeature(ctx, code) {
105
106
  return license.valid && license.summary.entitlements.indexOf(code) >= 0;
106
107
  }
107
108
 
108
- /** Remembers this YouTrack instance's id (read by the admin page from /api/config). */
109
- function setInstallation(ctx, id) {
109
+ /** Addresses like https://acme.youtrack.cloud (scheme and host only), at most three. */
110
+ function cleanBaseUrls(baseUrls) {
111
+ return (Array.isArray(baseUrls) ? baseUrls : [])
112
+ .filter(function (u) { return typeof u === 'string' && /^https?:\/\/[^\s/]+$/.test(u); }).slice(0, 3);
113
+ }
114
+
115
+ /**
116
+ * Remembers this YouTrack instance's id (read by the admin page from /api/config) and the addresses the page was opened from,
117
+ * which a trial started later from the app's own code uses.
118
+ */
119
+ function setInstallation(ctx, id, baseUrls) {
110
120
  if (typeof id !== 'string' || !/^[A-Za-z0-9-]{8,64}$/.test(id)) throw new Error('Invalid installation id.');
111
121
  if (props(ctx)[PROPERTY.installation] !== id) props(ctx)[PROPERTY.installation] = id;
122
+ const urls = cleanBaseUrls(baseUrls);
123
+ if (urls.length && props(ctx)[PROPERTY.baseUrls] !== urls.join(' ')) props(ctx)[PROPERTY.baseUrls] = urls.join(' ');
112
124
  }
113
125
 
114
126
  function common(ctx) {
@@ -123,14 +135,14 @@ function activate(ctx) {
123
135
  }
124
136
 
125
137
  /**
126
- * Starts the keyless trial. LicenseRail asks this YouTrack instance for its id at baseUrls (the addresses the admin page was
127
- * opened from) before the trial starts, so the instance must be reachable from the internet.
138
+ * Starts the keyless trial. LicenseRail asks this YouTrack instance for its id at its address before the trial starts, so the
139
+ * instance must be reachable from the internet. Without baseUrls the addresses remembered from the License page are used.
128
140
  */
129
141
  function startTrial(ctx, baseUrls) {
130
142
  const t = target(ctx);
131
143
  if (!t.fingerprint) throw new Error('Open the license page once so the app knows this YouTrack instance.');
132
- const urls = (Array.isArray(baseUrls) ? baseUrls : [])
133
- .filter(function (u) { return typeof u === 'string' && /^https?:\/\/[^\s/]+$/.test(u); }).slice(0, 3);
144
+ let urls = cleanBaseUrls(baseUrls);
145
+ if (!urls.length) urls = cleanBaseUrls(String(props(ctx)[PROPERTY.baseUrls] || '').split(' '));
134
146
  writeState(ctx, { pending: 'trial', lastAttemptAt: new Date().toISOString() });
135
147
  send(ctx, core.trialRequest(Object.assign(t, common(ctx), {
136
148
  keyId: config.keyId, host: { instanceId: installationId(ctx), baseUrls: urls },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeo-engineering/licenserail-youtrack",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "LicenseRail for YouTrack apps: license keys, keyless trials and per-user limits for apps sold outside JetBrains Marketplace billing. Adds readable backend modules and a License admin page to your app.",
5
5
  "license": "MIT",
6
6
  "publishConfig": { "access": "public" },