@moonbase.sh/licensing 3.5.2 → 3.6.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/README.md CHANGED
@@ -65,6 +65,20 @@ await licensing.store.storeLocalLicense(license)
65
65
  console.log('License stored locally')
66
66
  ```
67
67
 
68
+ ## Start a trial
69
+
70
+ A product that allows trials without an account can start one on the device directly, without the browser.
71
+ When the app knows the marketing it came from, such as the UTM tags of the link its installer was downloaded
72
+ from, pass them along: Moonbase puts the trial down to them, so the merchant can see which marketing brings
73
+ trials. Without them, a trial is put down to how its signed-in customer first came to the store.
74
+
75
+ ```ts
76
+ const trial = await licensing.client.requestTrial({
77
+ utm: { source: 'newsletter', medium: 'email', campaign: 'spring-launch' },
78
+ })
79
+ await licensing.store.storeLocalLicense(trial)
80
+ ```
81
+
68
82
  ## Validate on startup
69
83
 
70
84
  Only delete the stored license when Moonbase says the license is gone. Deleting it on any error makes
package/dist/index.cjs CHANGED
@@ -75,7 +75,7 @@ __export(index_exports, {
75
75
  module.exports = __toCommonJS(index_exports);
76
76
 
77
77
  // package.json
78
- var version = "3.5.2";
78
+ var version = "3.6.0";
79
79
 
80
80
  // src/activation/controller.ts
81
81
  var import_promises4 = __toESM(require("fs/promises"), 1);
@@ -579,12 +579,14 @@ var LicenseClient = class {
579
579
  return null;
580
580
  return await this.handleLicenseResponse(response);
581
581
  }
582
- async requestTrial() {
582
+ async requestTrial(options) {
583
+ var _a;
583
584
  const content = {
584
585
  deviceName: await this.deviceIdResolver.resolveDeviceName(),
585
586
  deviceSignature: await this.deviceIdResolver.resolveDeviceId()
586
587
  };
587
- const response = await (0, import_cross_fetch2.default)(`${this.configuration.endpoint}/api/client/trials/${this.configuration.productId}/request${this.buildQueryString()}`, {
588
+ const utm = Object.entries((_a = options == null ? void 0 : options.utm) != null ? _a : {}).filter(([_, value]) => !!value).map(([key, value]) => `utm_${key}=${encodeURIComponent(value)}`);
589
+ const response = await (0, import_cross_fetch2.default)(`${this.configuration.endpoint}/api/client/trials/${this.configuration.productId}/request${this.buildQueryString(utm)}`, {
588
590
  ...this.defaultFetchOptions,
589
591
  method: "POST",
590
592
  headers: {
@@ -683,7 +685,7 @@ var LicenseClient = class {
683
685
  }
684
686
  return await this.licenseValidator.validateLicense(await response.text());
685
687
  }
686
- buildQueryString() {
688
+ buildQueryString(extra = []) {
687
689
  const parts = ["format=JWT"];
688
690
  const { platform, appVersion, metadata } = this.configuration;
689
691
  if (platform)
@@ -699,6 +701,7 @@ var LicenseClient = class {
699
701
  }
700
702
  if (this.configuration.autoActivateSubProducts === false)
701
703
  parts.push("autoActivateSubProducts=false");
704
+ parts.push(...extra);
702
705
  return `?${parts.join("&")}`;
703
706
  }
704
707
  };
package/dist/index.d.cts CHANGED
@@ -1448,6 +1448,23 @@ declare enum ActivationMethod {
1448
1448
  }
1449
1449
  type Metadata = Record<string, string>;
1450
1450
  type Platform = 'Windows' | 'Linux' | 'Mac';
1451
+ /** The UTM tags of a link, and the site that referred the visitor to it. */
1452
+ interface UrchinTrackingModule {
1453
+ source?: string;
1454
+ medium?: string;
1455
+ campaign?: string;
1456
+ term?: string;
1457
+ content?: string;
1458
+ referrer?: string;
1459
+ }
1460
+ interface RequestTrialOptions {
1461
+ /**
1462
+ * The marketing the trial came from, when the app knows it: the tags of the link its installer was
1463
+ * downloaded from, say. Moonbase puts the trial down to them, so the merchant can see which marketing
1464
+ * brings trials; without them, to how the signed-in customer first came to the store.
1465
+ */
1466
+ utm?: UrchinTrackingModule;
1467
+ }
1451
1468
  type License = z.infer<typeof licenseSchema>;
1452
1469
  type ReleaseAccess = z.infer<typeof releaseAccessSchema>;
1453
1470
  type SubProduct = z.infer<typeof subProductSchema>;
@@ -1493,9 +1510,10 @@ interface ILicenseClient {
1493
1510
  * the browser activation process. This currently requires that
1494
1511
  * the product allows anonymous trials, since there is no authentication.
1495
1512
  *
1513
+ * @param options The marketing the trial came from, when the app knows it
1496
1514
  * @returns The allocated trial license, throws if the trial license cannot be allocated (e.g. user already had a trial) or if the request failed
1497
1515
  */
1498
- requestTrial: () => Promise<License>;
1516
+ requestTrial: (options?: RequestTrialOptions) => Promise<License>;
1499
1517
  /**
1500
1518
  * Takes a seat of one of the product's sub-products (add-ons) for this
1501
1519
  * device, from the license the device holds for the product, and returns
@@ -1583,7 +1601,7 @@ declare class LicenseClient implements ILicenseClient {
1583
1601
  constructor(configuration: MoonbaseConfiguration, deviceIdResolver: IDeviceIdResolver, licenseValidator: ILicenseValidator);
1584
1602
  requestActivation(): Promise<ActivationRequestResponse>;
1585
1603
  getRequestedActivation(request: ActivationRequestResponse): Promise<License | null>;
1586
- requestTrial(): Promise<License>;
1604
+ requestTrial(options?: RequestTrialOptions): Promise<License>;
1587
1605
  activateSubProduct(license: License, subProductId: string): Promise<License>;
1588
1606
  requestSubProductTrial(license: License, subProductId: string): Promise<License>;
1589
1607
  listSubProducts(license: License): Promise<SubProductCatalog>;
@@ -2596,4 +2614,4 @@ declare function isNewerVersion(current: string, latest: string): boolean;
2596
2614
  /** This SDK's version, as it names itself to Moonbase. */
2597
2615
  declare const licensingVersion: string;
2598
2616
 
2599
- export { ActivationController, type ActivationControllerOptions, ActivationError, type ActivationErrorKind, type ActivationFailure, type ActivationLogger, ActivationMethod, type ActivationRequestResponse, type ActivationScreen, type ActivationState, type ActivationStatus, type ActivationStrings, type ActivationUiOptions, type AddOnsPhase, type AddOnsState, type AppVersion, DEVICE_ID_SOURCE_TAGS, type DeviceIdDescription, type DeviceIdSource, type DeviceIdStamp, type DeviceIdentity, type DeviceIdentityReader, type DeviceInfo, type DeviceToken, type DownloadTarget, ErrorType, FINGERPRINT_PREFIX, FINGERPRINT_VERSION, FileLicenseStore, type FingerprintParam, IDENTIFYING_PARAM_NAMES, type IDescribableDeviceIdResolver, type IDeviceIdResolver, type ILicenseClient, type ILicenseStore, type ILicenseValidator, type IMigratingDeviceIdResolver, InMemoryLicenseStore, InsufficientDeviceIdentityError, InventoryClient, LegacyDeviceIdResolver, type License, LicenseClient, type LicenseValidationOptions, LicenseValidator, type LicenseView, type LockReason, MAX_VALUE_LENGTH, type Metadata, MigratingDeviceIdResolver, type MoonbaseConfiguration, MoonbaseDeviceIdResolver, type MoonbaseDeviceIdResolverOptions, MoonbaseError, MoonbaseLicensing, type NotCoveredView, type PendingActivation, type Platform, type PlatformTag, type Product, type ReleaseAccess, type ReleaseInfo, type ReleaseNotCoveredDetails, ReleaseNotCoveredError, type SubProduct, type SubProductCatalog, type SubProductCatalogEntry, type TrialFeature, type UpdateHint, type UpdateInfo, type User, buildFingerprintMaterial, canDownload, canonicalizeParams, canonicalizeValue, coversVersion, defaultDeviceIdentityReader, filenameFromDownloadUrl, fingerprintDeviceId, fingerprintDigest, hasSubProduct, identitySource, isNewerVersion, licensingVersion, parseAppVersion, parseDeviceIdStamp, parseIoregPlatformUuid, parseSmbiosParams, platformTag, selectMachineId, stampDeviceId };
2617
+ export { ActivationController, type ActivationControllerOptions, ActivationError, type ActivationErrorKind, type ActivationFailure, type ActivationLogger, ActivationMethod, type ActivationRequestResponse, type ActivationScreen, type ActivationState, type ActivationStatus, type ActivationStrings, type ActivationUiOptions, type AddOnsPhase, type AddOnsState, type AppVersion, DEVICE_ID_SOURCE_TAGS, type DeviceIdDescription, type DeviceIdSource, type DeviceIdStamp, type DeviceIdentity, type DeviceIdentityReader, type DeviceInfo, type DeviceToken, type DownloadTarget, ErrorType, FINGERPRINT_PREFIX, FINGERPRINT_VERSION, FileLicenseStore, type FingerprintParam, IDENTIFYING_PARAM_NAMES, type IDescribableDeviceIdResolver, type IDeviceIdResolver, type ILicenseClient, type ILicenseStore, type ILicenseValidator, type IMigratingDeviceIdResolver, InMemoryLicenseStore, InsufficientDeviceIdentityError, InventoryClient, LegacyDeviceIdResolver, type License, LicenseClient, type LicenseValidationOptions, LicenseValidator, type LicenseView, type LockReason, MAX_VALUE_LENGTH, type Metadata, MigratingDeviceIdResolver, type MoonbaseConfiguration, MoonbaseDeviceIdResolver, type MoonbaseDeviceIdResolverOptions, MoonbaseError, MoonbaseLicensing, type NotCoveredView, type PendingActivation, type Platform, type PlatformTag, type Product, type ReleaseAccess, type ReleaseInfo, type ReleaseNotCoveredDetails, ReleaseNotCoveredError, type RequestTrialOptions, type SubProduct, type SubProductCatalog, type SubProductCatalogEntry, type TrialFeature, type UpdateHint, type UpdateInfo, type UrchinTrackingModule, type User, buildFingerprintMaterial, canDownload, canonicalizeParams, canonicalizeValue, coversVersion, defaultDeviceIdentityReader, filenameFromDownloadUrl, fingerprintDeviceId, fingerprintDigest, hasSubProduct, identitySource, isNewerVersion, licensingVersion, parseAppVersion, parseDeviceIdStamp, parseIoregPlatformUuid, parseSmbiosParams, platformTag, selectMachineId, stampDeviceId };
package/dist/index.d.ts CHANGED
@@ -1448,6 +1448,23 @@ declare enum ActivationMethod {
1448
1448
  }
1449
1449
  type Metadata = Record<string, string>;
1450
1450
  type Platform = 'Windows' | 'Linux' | 'Mac';
1451
+ /** The UTM tags of a link, and the site that referred the visitor to it. */
1452
+ interface UrchinTrackingModule {
1453
+ source?: string;
1454
+ medium?: string;
1455
+ campaign?: string;
1456
+ term?: string;
1457
+ content?: string;
1458
+ referrer?: string;
1459
+ }
1460
+ interface RequestTrialOptions {
1461
+ /**
1462
+ * The marketing the trial came from, when the app knows it: the tags of the link its installer was
1463
+ * downloaded from, say. Moonbase puts the trial down to them, so the merchant can see which marketing
1464
+ * brings trials; without them, to how the signed-in customer first came to the store.
1465
+ */
1466
+ utm?: UrchinTrackingModule;
1467
+ }
1451
1468
  type License = z.infer<typeof licenseSchema>;
1452
1469
  type ReleaseAccess = z.infer<typeof releaseAccessSchema>;
1453
1470
  type SubProduct = z.infer<typeof subProductSchema>;
@@ -1493,9 +1510,10 @@ interface ILicenseClient {
1493
1510
  * the browser activation process. This currently requires that
1494
1511
  * the product allows anonymous trials, since there is no authentication.
1495
1512
  *
1513
+ * @param options The marketing the trial came from, when the app knows it
1496
1514
  * @returns The allocated trial license, throws if the trial license cannot be allocated (e.g. user already had a trial) or if the request failed
1497
1515
  */
1498
- requestTrial: () => Promise<License>;
1516
+ requestTrial: (options?: RequestTrialOptions) => Promise<License>;
1499
1517
  /**
1500
1518
  * Takes a seat of one of the product's sub-products (add-ons) for this
1501
1519
  * device, from the license the device holds for the product, and returns
@@ -1583,7 +1601,7 @@ declare class LicenseClient implements ILicenseClient {
1583
1601
  constructor(configuration: MoonbaseConfiguration, deviceIdResolver: IDeviceIdResolver, licenseValidator: ILicenseValidator);
1584
1602
  requestActivation(): Promise<ActivationRequestResponse>;
1585
1603
  getRequestedActivation(request: ActivationRequestResponse): Promise<License | null>;
1586
- requestTrial(): Promise<License>;
1604
+ requestTrial(options?: RequestTrialOptions): Promise<License>;
1587
1605
  activateSubProduct(license: License, subProductId: string): Promise<License>;
1588
1606
  requestSubProductTrial(license: License, subProductId: string): Promise<License>;
1589
1607
  listSubProducts(license: License): Promise<SubProductCatalog>;
@@ -2596,4 +2614,4 @@ declare function isNewerVersion(current: string, latest: string): boolean;
2596
2614
  /** This SDK's version, as it names itself to Moonbase. */
2597
2615
  declare const licensingVersion: string;
2598
2616
 
2599
- export { ActivationController, type ActivationControllerOptions, ActivationError, type ActivationErrorKind, type ActivationFailure, type ActivationLogger, ActivationMethod, type ActivationRequestResponse, type ActivationScreen, type ActivationState, type ActivationStatus, type ActivationStrings, type ActivationUiOptions, type AddOnsPhase, type AddOnsState, type AppVersion, DEVICE_ID_SOURCE_TAGS, type DeviceIdDescription, type DeviceIdSource, type DeviceIdStamp, type DeviceIdentity, type DeviceIdentityReader, type DeviceInfo, type DeviceToken, type DownloadTarget, ErrorType, FINGERPRINT_PREFIX, FINGERPRINT_VERSION, FileLicenseStore, type FingerprintParam, IDENTIFYING_PARAM_NAMES, type IDescribableDeviceIdResolver, type IDeviceIdResolver, type ILicenseClient, type ILicenseStore, type ILicenseValidator, type IMigratingDeviceIdResolver, InMemoryLicenseStore, InsufficientDeviceIdentityError, InventoryClient, LegacyDeviceIdResolver, type License, LicenseClient, type LicenseValidationOptions, LicenseValidator, type LicenseView, type LockReason, MAX_VALUE_LENGTH, type Metadata, MigratingDeviceIdResolver, type MoonbaseConfiguration, MoonbaseDeviceIdResolver, type MoonbaseDeviceIdResolverOptions, MoonbaseError, MoonbaseLicensing, type NotCoveredView, type PendingActivation, type Platform, type PlatformTag, type Product, type ReleaseAccess, type ReleaseInfo, type ReleaseNotCoveredDetails, ReleaseNotCoveredError, type SubProduct, type SubProductCatalog, type SubProductCatalogEntry, type TrialFeature, type UpdateHint, type UpdateInfo, type User, buildFingerprintMaterial, canDownload, canonicalizeParams, canonicalizeValue, coversVersion, defaultDeviceIdentityReader, filenameFromDownloadUrl, fingerprintDeviceId, fingerprintDigest, hasSubProduct, identitySource, isNewerVersion, licensingVersion, parseAppVersion, parseDeviceIdStamp, parseIoregPlatformUuid, parseSmbiosParams, platformTag, selectMachineId, stampDeviceId };
2617
+ export { ActivationController, type ActivationControllerOptions, ActivationError, type ActivationErrorKind, type ActivationFailure, type ActivationLogger, ActivationMethod, type ActivationRequestResponse, type ActivationScreen, type ActivationState, type ActivationStatus, type ActivationStrings, type ActivationUiOptions, type AddOnsPhase, type AddOnsState, type AppVersion, DEVICE_ID_SOURCE_TAGS, type DeviceIdDescription, type DeviceIdSource, type DeviceIdStamp, type DeviceIdentity, type DeviceIdentityReader, type DeviceInfo, type DeviceToken, type DownloadTarget, ErrorType, FINGERPRINT_PREFIX, FINGERPRINT_VERSION, FileLicenseStore, type FingerprintParam, IDENTIFYING_PARAM_NAMES, type IDescribableDeviceIdResolver, type IDeviceIdResolver, type ILicenseClient, type ILicenseStore, type ILicenseValidator, type IMigratingDeviceIdResolver, InMemoryLicenseStore, InsufficientDeviceIdentityError, InventoryClient, LegacyDeviceIdResolver, type License, LicenseClient, type LicenseValidationOptions, LicenseValidator, type LicenseView, type LockReason, MAX_VALUE_LENGTH, type Metadata, MigratingDeviceIdResolver, type MoonbaseConfiguration, MoonbaseDeviceIdResolver, type MoonbaseDeviceIdResolverOptions, MoonbaseError, MoonbaseLicensing, type NotCoveredView, type PendingActivation, type Platform, type PlatformTag, type Product, type ReleaseAccess, type ReleaseInfo, type ReleaseNotCoveredDetails, ReleaseNotCoveredError, type RequestTrialOptions, type SubProduct, type SubProductCatalog, type SubProductCatalogEntry, type TrialFeature, type UpdateHint, type UpdateInfo, type UrchinTrackingModule, type User, buildFingerprintMaterial, canDownload, canonicalizeParams, canonicalizeValue, coversVersion, defaultDeviceIdentityReader, filenameFromDownloadUrl, fingerprintDeviceId, fingerprintDigest, hasSubProduct, identitySource, isNewerVersion, licensingVersion, parseAppVersion, parseDeviceIdStamp, parseIoregPlatformUuid, parseSmbiosParams, platformTag, selectMachineId, stampDeviceId };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "3.5.2";
2
+ var version = "3.6.0";
3
3
 
4
4
  // src/activation/controller.ts
5
5
  import fs4 from "fs/promises";
@@ -503,12 +503,14 @@ var LicenseClient = class {
503
503
  return null;
504
504
  return await this.handleLicenseResponse(response);
505
505
  }
506
- async requestTrial() {
506
+ async requestTrial(options) {
507
+ var _a;
507
508
  const content = {
508
509
  deviceName: await this.deviceIdResolver.resolveDeviceName(),
509
510
  deviceSignature: await this.deviceIdResolver.resolveDeviceId()
510
511
  };
511
- const response = await fetch3(`${this.configuration.endpoint}/api/client/trials/${this.configuration.productId}/request${this.buildQueryString()}`, {
512
+ const utm = Object.entries((_a = options == null ? void 0 : options.utm) != null ? _a : {}).filter(([_, value]) => !!value).map(([key, value]) => `utm_${key}=${encodeURIComponent(value)}`);
513
+ const response = await fetch3(`${this.configuration.endpoint}/api/client/trials/${this.configuration.productId}/request${this.buildQueryString(utm)}`, {
512
514
  ...this.defaultFetchOptions,
513
515
  method: "POST",
514
516
  headers: {
@@ -607,7 +609,7 @@ var LicenseClient = class {
607
609
  }
608
610
  return await this.licenseValidator.validateLicense(await response.text());
609
611
  }
610
- buildQueryString() {
612
+ buildQueryString(extra = []) {
611
613
  const parts = ["format=JWT"];
612
614
  const { platform, appVersion, metadata } = this.configuration;
613
615
  if (platform)
@@ -623,6 +625,7 @@ var LicenseClient = class {
623
625
  }
624
626
  if (this.configuration.autoActivateSubProducts === false)
625
627
  parts.push("autoActivateSubProducts=false");
628
+ parts.push(...extra);
626
629
  return `?${parts.join("&")}`;
627
630
  }
628
631
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/licensing",
3
3
  "type": "module",
4
- "version": "3.5.2",
4
+ "version": "3.6.0",
5
5
  "description": "Package to add sotftware licensing using Moonbase.sh to your node.js apps",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",