@sidub-inc/licensing-client 1.3.45 → 1.4.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
@@ -556,4 +556,5 @@ See [MIGRATION.md](docs/MIGRATION.md) for detailed upgrade instructions. Key cha
556
556
 
557
557
  ## License
558
558
 
559
- MIT © Sidub Inc.
559
+ Proprietary licenses available at https://sidub.ca/
560
+ © Sidub Inc.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,24 @@
1
1
  import React, { ReactNode } from 'react';
2
2
 
3
3
  /**
4
- * Error class for licensing-related errors
4
+ * Error class for licensing-related errors.
5
+ * Thrown when API requests fail, authorization is denied, or network errors occur.
5
6
  */
6
7
  declare class LicensingError extends Error {
7
8
  statusCode?: number | undefined;
8
9
  response?: unknown | undefined;
10
+ /**
11
+ * Creates a new licensing error.
12
+ * @param message A description of the error.
13
+ * @param statusCode The HTTP status code from the server response, if applicable.
14
+ * @param response The raw response body from the server, if available.
15
+ */
9
16
  constructor(message: string, statusCode?: number | undefined, response?: unknown | undefined);
10
17
  }
11
18
 
12
19
  /**
13
- * License classification types
20
+ * License classification types defining the licensing model.
21
+ * Matches the .NET LicenseClassificationType enum.
14
22
  */
15
23
  declare enum LicenseClassificationType {
16
24
  /** Perpetual license with no expiration */
@@ -23,21 +31,32 @@ declare enum LicenseClassificationType {
23
31
  /**
24
32
  * Normalizes a license classification value from server integer or string to the TypeScript enum.
25
33
  * The .NET server serializes enums as integers (0=Trial, 1=Subscription, 2=Perpetual).
34
+ *
35
+ * @param value The raw value from the server response (integer, string, null, or undefined).
36
+ * @returns The normalized enum value, or undefined if the input cannot be mapped.
26
37
  */
27
38
  declare function normalizeLicenseClassificationType(value: number | string | null | undefined): LicenseClassificationType | undefined;
28
39
  /**
29
40
  * Billing interval units for subscription licenses.
30
- * Matches .NET BillingIntervalUnit enum with singular names.
41
+ * Matches the .NET BillingIntervalUnit enum with singular names.
31
42
  */
32
43
  declare enum BillingIntervalUnit {
44
+ /** Hourly billing interval. */
33
45
  Hour = "Hour",
46
+ /** Daily billing interval. */
34
47
  Day = "Day",
48
+ /** Weekly billing interval. */
35
49
  Week = "Week",
50
+ /** Monthly billing interval. */
36
51
  Month = "Month",
52
+ /** Yearly billing interval. */
37
53
  Year = "Year"
38
54
  }
39
55
  /**
40
56
  * Normalizes a billing interval unit value from server integer or string to the TypeScript enum.
57
+ *
58
+ * @param value The raw value from the server response (integer, string, null, or undefined).
59
+ * @returns The normalized enum value, or undefined if the input cannot be mapped.
41
60
  */
42
61
  declare function normalizeBillingIntervalUnit(value: number | string | null | undefined): BillingIntervalUnit | undefined;
43
62
 
@@ -377,25 +396,33 @@ declare abstract class LicenseAssertion<T extends ILicenseFeature = ILicenseFeat
377
396
  }
378
397
 
379
398
  /**
380
- * Service access level types
399
+ * Service access levels for feature authorization.
400
+ * Matches the .NET ServiceAccessLevel enum.
381
401
  */
382
402
  declare enum ServiceAccessLevel {
403
+ /** Access to the feature is denied. */
383
404
  Denied = "Denied",
405
+ /** Access to the feature is allowed. */
384
406
  Allowed = "Allowed"
385
407
  }
386
408
  /**
387
409
  * Normalizes a service access level value from server integer or string to the TypeScript enum.
388
410
  * The .NET server serializes enums as integers (0=Denied, 1=Allowed).
411
+ *
412
+ * @param value The raw value from the server response (integer, string, null, or undefined).
413
+ * @returns The normalized enum value, or undefined if the input cannot be mapped.
389
414
  */
390
415
  declare function normalizeServiceAccessLevel(value: number | string | null | undefined): ServiceAccessLevel | undefined;
391
416
  /**
392
- * Service access license feature with access control
417
+ * Service access license feature with binary access control.
418
+ * Extends the base feature with service type and access level metadata.
393
419
  */
394
420
  interface ServiceAccessLicenseFeature extends ILicenseFeature {
421
+ /** Unique identifier for the feature. */
395
422
  featureId: string;
396
- /** Service type identifier */
423
+ /** Optional service type identifier for finer-grained access control. */
397
424
  serviceType?: string;
398
- /** Access level for this feature */
425
+ /** The access level granted for this feature (Allowed or Denied). */
399
426
  serviceAccessLevel?: ServiceAccessLevel;
400
427
  }
401
428
  /**
@@ -442,23 +469,35 @@ declare class ServiceAccessAssertion extends LicenseAssertion<ServiceAccessLicen
442
469
  declare class RateLimitFeatureState {
443
470
  private metrics;
444
471
  private sampleSeconds;
472
+ /**
473
+ * Creates a new rate limit feature state tracker.
474
+ * @param sampleSeconds The sliding window duration in seconds for rate limit evaluation.
475
+ */
445
476
  constructor(sampleSeconds: number);
446
- /** Records a consumption event with the current timestamp */
477
+ /**
478
+ * Records a consumption event with the current timestamp.
479
+ * @param amount The quantity consumed in this event.
480
+ */
447
481
  consumeRate(amount: number): void;
448
- /** Returns total consumption within the sample window, pruning stale entries */
482
+ /**
483
+ * Returns total consumption within the sample window, pruning stale entries.
484
+ * @returns The sum of all consumption amounts within the sliding window.
485
+ */
449
486
  getConsumption(): number;
450
487
  }
451
488
 
452
489
  /**
453
- * Rate limit license feature with consumption tracking
490
+ * Rate limit license feature with consumption tracking.
491
+ * Extends the base feature with rate limiting metadata and usage counters.
454
492
  */
455
493
  interface RateLimitLicenseFeature extends ILicenseFeature {
494
+ /** Unique identifier for the feature. */
456
495
  featureId: string;
457
- /** Sample period in seconds */
496
+ /** Sliding window duration in seconds for rate limit evaluation. */
458
497
  sampleSeconds?: number;
459
- /** Rate limit (max requests per sample period) */
498
+ /** Maximum allowed consumption within the sample window. */
460
499
  rateLimit?: number;
461
- /** Current consumption count */
500
+ /** Current server-reported consumption count within the sample window. */
462
501
  currentConsumption?: number;
463
502
  }
464
503
  /**
@@ -593,11 +632,15 @@ declare class NotAssertion extends LicenseAssertion {
593
632
  }
594
633
 
595
634
  /**
596
- * Parameters for generating a license authorization
635
+ * Parameters for generating a license authorization request.
636
+ * Sent to the server to retrieve a signed license authorization.
597
637
  */
598
638
  interface GenerateLicenseAuthorizationParameters {
639
+ /** Optional request identifier for tracking and idempotency. */
599
640
  RequestId?: string;
641
+ /** Optional license classification filter. */
600
642
  LicenseClassification?: LicenseClassificationType;
643
+ /** The unique identifier of the license to authorize. */
601
644
  LicenseId: string;
602
645
  }
603
646
  /**
@@ -669,28 +712,37 @@ declare class LicensingClient {
669
712
  */
670
713
  private normalizeSignature;
671
714
  /**
672
- * Asserts whether a license condition is satisfied using the provided assertion.
673
- * This evaluates the assertion against a license authorization.
715
+ * Evaluates a license assertion against a license authorization.
716
+ * Returns whether the assertion condition (feature access, rate limit, etc.) is satisfied.
674
717
  *
675
- * @param assertion The license assertion to evaluate
676
- * @param authorization The license authorization to check against (if not provided, you must call getAuthorization first)
677
- * @returns True if the assertion is satisfied, false otherwise
678
- *
679
- * @example
680
- * ```typescript
681
- * const authorization = await client.getAuthorization('license-id');
682
- * const assertion = ServiceAccessAssertion.create('premium-features');
683
- * const hasAccess = client.assertLicense(assertion, authorization);
684
- * ```
718
+ * @template T The type of license feature the assertion operates on.
719
+ * @param assertion The license assertion to evaluate.
720
+ * @param authorization The license authorization to check against.
721
+ * @returns True if the assertion is satisfied, false otherwise.
685
722
  */
686
723
  assertLicense<T extends ILicenseFeature = ILicenseFeature>(assertion: ILicenseAssertion<T>, authorization: LicenseAuthorization): boolean;
687
- /** Clears all cached authorizations */
724
+ /**
725
+ * Clears all cached authorizations.
726
+ */
688
727
  clearCache(): void;
689
- /** Invalidates all cached authorizations for a specific license */
728
+ /**
729
+ * Invalidates all cached authorizations for a specific license.
730
+ * @param licenseId The license identifier to invalidate.
731
+ */
690
732
  invalidateCache(licenseId: string): void;
691
- /** Gets the local feature state for a license+feature combination */
733
+ /**
734
+ * Gets the local feature state for a license+feature combination.
735
+ * @param licenseId The license identifier.
736
+ * @param featureKey The feature key.
737
+ * @returns The rate limit feature state tracker, or undefined if no state exists.
738
+ */
692
739
  getFeatureState(licenseId: string, featureKey: string): RateLimitFeatureState | undefined;
693
- /** Sets/replaces the local feature state for a license+feature combination */
740
+ /**
741
+ * Sets or replaces the local feature state for a license+feature combination.
742
+ * @param licenseId The license identifier.
743
+ * @param featureKey The feature key.
744
+ * @param state The rate limit feature state tracker to associate.
745
+ */
694
746
  setFeatureState(licenseId: string, featureKey: string, state: RateLimitFeatureState): void;
695
747
  /**
696
748
  * Reports license feature consumption/usage to the server.
@@ -757,12 +809,21 @@ declare class LicensingClient {
757
809
  maxAttempts?: number;
758
810
  }): Promise<CheckoutSessionResult>;
759
811
  /**
760
- * Gets the current configuration
812
+ * Gets the current licensing configuration.
813
+ * @returns A read-only copy of the resolved configuration.
761
814
  */
762
815
  getConfig(): Readonly<LicensingConfig>;
763
816
  }
764
817
 
818
+ /**
819
+ * Error thrown when the licensing client is misconfigured.
820
+ * Indicates missing or invalid configuration values such as a missing license ID or service URI.
821
+ */
765
822
  declare class LicensingConfigurationException extends LicensingError {
823
+ /**
824
+ * Creates a new configuration exception.
825
+ * @param message A description of the configuration error.
826
+ */
766
827
  constructor(message: string);
767
828
  }
768
829
 
@@ -786,6 +847,10 @@ interface CryptoConfig {
786
847
  declare class CryptoService {
787
848
  private publicKey;
788
849
  private readonly config;
850
+ /**
851
+ * Creates a new cryptography service instance.
852
+ * @param config The cryptography configuration containing the public key for verification.
853
+ */
789
854
  constructor(config: CryptoConfig);
790
855
  /**
791
856
  * Gets the service key ID
@@ -811,10 +876,16 @@ declare class CryptoService {
811
876
  private base64ToArrayBuffer;
812
877
  }
813
878
  /**
814
- * Error class for cryptography-related errors
879
+ * Error class for cryptography-related errors.
880
+ * Contains a machine-readable error code for programmatic handling.
815
881
  */
816
882
  declare class CryptoError extends Error {
817
883
  readonly code: 'KEY_IMPORT_FAILED' | 'VERIFICATION_FAILED' | 'NOT_INITIALIZED' | 'INVALID_SIGNATURE';
884
+ /**
885
+ * Creates a new cryptography error.
886
+ * @param message A description of the cryptographic failure.
887
+ * @param code A machine-readable error code identifying the failure type.
888
+ */
818
889
  constructor(message: string, code: 'KEY_IMPORT_FAILED' | 'VERIFICATION_FAILED' | 'NOT_INITIALIZED' | 'INVALID_SIGNATURE');
819
890
  }
820
891
 
@@ -909,20 +980,35 @@ declare class SignatureValidator {
909
980
  declare class AuthorizationCache {
910
981
  private cache;
911
982
  private maxSize;
983
+ /**
984
+ * Creates a new authorization cache.
985
+ * @param maxSize The maximum number of entries to store before evicting the oldest. Defaults to 100.
986
+ */
912
987
  constructor(maxSize?: number);
913
988
  /**
914
989
  * Gets a cached authorization if it exists and has not expired.
915
990
  * On hit, re-inserts the entry to move it to the end (pseudo-LRU freshness).
991
+ *
992
+ * @param licenseId The license identifier.
993
+ * @param serviceKeyId The service key identifier.
994
+ * @returns The cached authorization, or null if not cached or expired.
916
995
  */
917
996
  get(licenseId: string, serviceKeyId: string): LicenseAuthorization | null;
918
997
  /**
919
998
  * Stores an authorization in the cache.
920
999
  * Evicts the oldest entry if max size is reached.
1000
+ *
1001
+ * @param licenseId The license identifier.
1002
+ * @param serviceKeyId The service key identifier.
1003
+ * @param authorization The license authorization to cache.
921
1004
  */
922
1005
  set(licenseId: string, serviceKeyId: string, authorization: LicenseAuthorization): void;
923
1006
  /** Removes all cached entries */
924
1007
  clearCache(): void;
925
- /** Removes all cached entries for a specific license across all service keys */
1008
+ /**
1009
+ * Removes all cached entries for a specific license across all service keys.
1010
+ * @param licenseId The license identifier to invalidate.
1011
+ */
926
1012
  invalidate(licenseId: string): void;
927
1013
  }
928
1014
 
@@ -1013,21 +1099,35 @@ declare const useLicensingContextValue: () => LicensingContextValue;
1013
1099
  * Named LicensingContextType to avoid collision with the React context in LicensingContext.tsx.
1014
1100
  */
1015
1101
  interface LicensingContextType {
1102
+ /** Unique identifier for the license. */
1016
1103
  licenseId: string;
1104
+ /** Unique identifier for the service key used for signature verification. */
1017
1105
  serviceKeyId: string;
1106
+ /** Base64-encoded public key for cryptographic signature verification. */
1018
1107
  serviceKeyPublicMember: string;
1108
+ /** API access key for authenticating requests to the licensing service. */
1019
1109
  apiAccessKey: string;
1110
+ /** Optional billable resource identifier for consumption metering (GUID string). */
1020
1111
  billableResourceId?: string;
1112
+ /** Optional billable plan identifier for consumption metering. */
1021
1113
  billablePlanId?: string;
1022
1114
  }
1023
1115
  /**
1024
1116
  * Creates a LicensingContextType from an encoded credential string.
1025
1117
  * Billable fields are NOT included in the encoding (per .NET behavior) and must be provided separately.
1118
+ *
1119
+ * @param encoded The encoded credential string (SIDUB_LIC_...) to decode.
1120
+ * @param billableResourceId Optional billable resource identifier for consumption metering.
1121
+ * @param billablePlanId Optional billable plan identifier for consumption metering.
1122
+ * @returns A fully-populated licensing context.
1026
1123
  */
1027
1124
  declare function licensingContextFromEncodedString(encoded: string, billableResourceId?: string, billablePlanId?: string): LicensingContextType;
1028
1125
  /**
1029
1126
  * Encodes a LicensingContextType to a portable string.
1030
1127
  * Per .NET behavior: only the 4 credential fields are encoded, NOT billable fields.
1128
+ *
1129
+ * @param context The licensing context to encode.
1130
+ * @returns A portable encoded string prefixed with SIDUB_LIC_.
1031
1131
  */
1032
1132
  declare function licensingContextToEncodedString(context: LicensingContextType): string;
1033
1133
 
@@ -1039,6 +1139,10 @@ declare function licensingContextToEncodedString(context: LicensingContextType):
1039
1139
  * (e.g., per-tenant lookup from database or session store).
1040
1140
  */
1041
1141
  interface ILicensingContextProvider {
1142
+ /**
1143
+ * Resolves the licensing context for the current tenant or user.
1144
+ * @returns The resolved licensing context, or null if no credentials are available.
1145
+ */
1042
1146
  resolveContext(): Promise<LicensingContextType | null>;
1043
1147
  }
1044
1148
 
@@ -1050,7 +1154,16 @@ interface ILicensingContextProvider {
1050
1154
  declare class ConfigurationContextProvider implements ILicensingContextProvider {
1051
1155
  private readonly config;
1052
1156
  private cached;
1157
+ /**
1158
+ * Creates a new configuration-based context provider.
1159
+ * @param config The licensing configuration to extract credentials from.
1160
+ */
1053
1161
  constructor(config: LicensingConfig);
1162
+ /**
1163
+ * Resolves licensing context from the configured credentials.
1164
+ * Returns null if no credentials are available. Caches the result after first call.
1165
+ * @returns The resolved licensing context, or null if no credentials are configured.
1166
+ */
1054
1167
  resolveContext(): Promise<LicensingContextType | null>;
1055
1168
  }
1056
1169