@sidub-inc/licensing-client 1.4.0 → 1.5.51
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/index.d.ts +181 -6
- package/dist/index.esm.js +516 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +520 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,26 @@ declare class LicensingError extends Error {
|
|
|
16
16
|
constructor(message: string, statusCode?: number | undefined, response?: unknown | undefined);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* SEM-03 / Phase 11 D-14: thrown by `LicensingClient.assertLicense` when a
|
|
21
|
+
* rate-limited feature's assertion evaluates false.
|
|
22
|
+
*
|
|
23
|
+
* Distinguishable from transient network errors by type alone:
|
|
24
|
+
* `catch (e) { if (e instanceof RateLimitError) { ... } }`
|
|
25
|
+
*
|
|
26
|
+
* Matches the .NET `Sidub.Licensing.Client.Exceptions.RateLimitException` shape.
|
|
27
|
+
* Minimal surface — only `featureKey` and `message`. No retry-after, no counters.
|
|
28
|
+
*/
|
|
29
|
+
declare class RateLimitError extends Error {
|
|
30
|
+
readonly featureKey: string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new RateLimitError.
|
|
33
|
+
* @param featureKey The key of the feature whose rate limit was exceeded.
|
|
34
|
+
* @param message A human-readable description of the violation.
|
|
35
|
+
*/
|
|
36
|
+
constructor(featureKey: string, message: string);
|
|
37
|
+
}
|
|
38
|
+
|
|
19
39
|
/**
|
|
20
40
|
* License classification types defining the licensing model.
|
|
21
41
|
* Matches the .NET LicenseClassificationType enum.
|
|
@@ -201,6 +221,46 @@ interface ClientLicenseConfiguration {
|
|
|
201
221
|
/** Configuration metadata */
|
|
202
222
|
metadata?: Record<string, unknown>;
|
|
203
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Per-feature view returned by LicensingClient.getState().
|
|
226
|
+
*/
|
|
227
|
+
interface FeatureView {
|
|
228
|
+
/** Unique feature key (matches the key used in assertions). */
|
|
229
|
+
featureKey: string;
|
|
230
|
+
/** Human-readable display name for the feature. */
|
|
231
|
+
displayName: string;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Per-feature consumption snapshot for rate-limited features.
|
|
235
|
+
* `percentage` is a RAW number 0..100+ — no bucketing applied.
|
|
236
|
+
*/
|
|
237
|
+
interface ConsumptionView {
|
|
238
|
+
/** Feature key this measurement belongs to. */
|
|
239
|
+
featureKey: string;
|
|
240
|
+
/** Local consumption count within the current sliding window. */
|
|
241
|
+
currentUsage: number;
|
|
242
|
+
/** Maximum allowed within the window (from authorization). */
|
|
243
|
+
limit: number;
|
|
244
|
+
/** Sliding-window duration in seconds. */
|
|
245
|
+
windowSeconds: number;
|
|
246
|
+
/** Ratio of currentUsage to limit expressed as a percentage (may exceed 100). */
|
|
247
|
+
percentage: number;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Composite license-state snapshot returned by LicensingClient.getState().
|
|
251
|
+
* Provides a framework-agnostic read-model suitable for display or serialization
|
|
252
|
+
* without exposing internal SKU IDs, pricing, or other-customer PII.
|
|
253
|
+
*/
|
|
254
|
+
interface LicenseStateView {
|
|
255
|
+
/** Unique identifier of the active license. */
|
|
256
|
+
licenseId: string;
|
|
257
|
+
/** All features granted by the license. */
|
|
258
|
+
features: FeatureView[];
|
|
259
|
+
/** Consumption data for rate-limited features only (empty when none are active). */
|
|
260
|
+
consumption: ConsumptionView[];
|
|
261
|
+
/** Authorization expiry, or null if the authorization has no expiry. */
|
|
262
|
+
expiry: Date | null;
|
|
263
|
+
}
|
|
204
264
|
|
|
205
265
|
/**
|
|
206
266
|
* Licensing credential containing the essential license identification and authentication values.
|
|
@@ -465,15 +525,21 @@ declare class ServiceAccessAssertion extends LicenseAssertion<ServiceAccessLicen
|
|
|
465
525
|
*
|
|
466
526
|
* Entries older than sampleSeconds are pruned on every getConsumption() call.
|
|
467
527
|
* Local state is additive/conservative — may over-count (safer than under-counting).
|
|
528
|
+
*
|
|
529
|
+
* When a storageKey is provided, metrics are persisted to localStorage and restored
|
|
530
|
+
* on construction, surviving page refreshes. Cross-tab sync is available via onSync().
|
|
468
531
|
*/
|
|
469
532
|
declare class RateLimitFeatureState {
|
|
470
533
|
private metrics;
|
|
471
534
|
private sampleSeconds;
|
|
535
|
+
private storageKey;
|
|
536
|
+
private unsubscribe;
|
|
472
537
|
/**
|
|
473
538
|
* Creates a new rate limit feature state tracker.
|
|
474
539
|
* @param sampleSeconds The sliding window duration in seconds for rate limit evaluation.
|
|
540
|
+
* @param storageKey Optional localStorage key for persisting metrics across page refreshes.
|
|
475
541
|
*/
|
|
476
|
-
constructor(sampleSeconds: number);
|
|
542
|
+
constructor(sampleSeconds: number, storageKey?: string);
|
|
477
543
|
/**
|
|
478
544
|
* Records a consumption event with the current timestamp.
|
|
479
545
|
* @param amount The quantity consumed in this event.
|
|
@@ -484,6 +550,18 @@ declare class RateLimitFeatureState {
|
|
|
484
550
|
* @returns The sum of all consumption amounts within the sliding window.
|
|
485
551
|
*/
|
|
486
552
|
getConsumption(): number;
|
|
553
|
+
/**
|
|
554
|
+
* Registers a cross-tab sync listener. When another tab modifies the same storageKey,
|
|
555
|
+
* the in-memory metrics are replaced with the new values and the callback is invoked.
|
|
556
|
+
*
|
|
557
|
+
* @param callback Invoked after in-memory state is updated from another tab.
|
|
558
|
+
* @returns An unsubscribe function to remove the listener.
|
|
559
|
+
*/
|
|
560
|
+
onSync(callback: () => void): () => void;
|
|
561
|
+
/**
|
|
562
|
+
* Removes the cross-tab sync listener if active.
|
|
563
|
+
*/
|
|
564
|
+
dispose(): void;
|
|
487
565
|
}
|
|
488
566
|
|
|
489
567
|
/**
|
|
@@ -651,20 +729,32 @@ interface GenerateLicenseAuthorizationParameters {
|
|
|
651
729
|
*/
|
|
652
730
|
declare class LicensingClient {
|
|
653
731
|
private config;
|
|
654
|
-
private
|
|
732
|
+
private credential;
|
|
655
733
|
private signatureValidator;
|
|
656
734
|
private validateSignatures;
|
|
657
735
|
private readonly authorizationCache;
|
|
658
736
|
private readonly cacheEnabled;
|
|
659
737
|
private readonly featureStates;
|
|
660
738
|
private readonly featureMetadata;
|
|
739
|
+
private readonly disposables;
|
|
661
740
|
private contextResolved;
|
|
662
741
|
private contextResolutionPromise;
|
|
742
|
+
private static readonly METADATA_STORAGE_KEY;
|
|
743
|
+
private static readonly CONSUMPTION_STORAGE_PREFIX;
|
|
744
|
+
private static readonly AUTH_STORAGE_PREFIX;
|
|
663
745
|
/**
|
|
664
746
|
* Creates a new instance of the LicensingClient
|
|
665
747
|
* @param config Configuration for the licensing service
|
|
666
748
|
*/
|
|
667
749
|
constructor(config: LicensingConfig);
|
|
750
|
+
/**
|
|
751
|
+
* Restores RateLimitFeatureState instances from localStorage for all known features.
|
|
752
|
+
*/
|
|
753
|
+
private restoreFeatureStates;
|
|
754
|
+
/**
|
|
755
|
+
* Persists the featureMetadata map to localStorage.
|
|
756
|
+
*/
|
|
757
|
+
private persistFeatureMetadata;
|
|
668
758
|
/**
|
|
669
759
|
* Ensures context provider has been resolved before making API calls.
|
|
670
760
|
* Called once per client lifetime; concurrent callers share the same promise.
|
|
@@ -720,6 +810,23 @@ declare class LicensingClient {
|
|
|
720
810
|
* @param authorization The license authorization to check against.
|
|
721
811
|
* @returns True if the assertion is satisfied, false otherwise.
|
|
722
812
|
*/
|
|
813
|
+
/**
|
|
814
|
+
* Phase 11 D-01 (LCYC-02): Composes an in-memory LicenseStateView from the current
|
|
815
|
+
* authorization. Returns null when no license is configured or the authorization cannot
|
|
816
|
+
* be retrieved.
|
|
817
|
+
*/
|
|
818
|
+
getState(): Promise<LicenseStateView | null>;
|
|
819
|
+
/**
|
|
820
|
+
* Phase 11 D-11 (LCYC-06): Invalidates all cached state and rebuilds internal credential
|
|
821
|
+
* configuration from a new encodedCredential — without requiring a React component remount.
|
|
822
|
+
*
|
|
823
|
+
* Call this from a useEffect keyed on the credential string; the `key={credential}` idiom
|
|
824
|
+
* is a deprecated fallback.
|
|
825
|
+
*
|
|
826
|
+
* @param newConfig A LicensingConfig carrying the updated encodedCredential (all other
|
|
827
|
+
* fields are merged; explicit fields on newConfig take precedence).
|
|
828
|
+
*/
|
|
829
|
+
refresh(newConfig: LicensingConfig): Promise<void>;
|
|
723
830
|
assertLicense<T extends ILicenseFeature = ILicenseFeature>(assertion: ILicenseAssertion<T>, authorization: LicenseAuthorization): boolean;
|
|
724
831
|
/**
|
|
725
832
|
* Clears all cached authorizations.
|
|
@@ -730,6 +837,12 @@ declare class LicensingClient {
|
|
|
730
837
|
* @param licenseId The license identifier to invalidate.
|
|
731
838
|
*/
|
|
732
839
|
invalidateCache(licenseId: string): void;
|
|
840
|
+
/**
|
|
841
|
+
* Releases all resources held by this client instance:
|
|
842
|
+
* removes cross-tab StorageEvent listeners and disposes cache/state objects.
|
|
843
|
+
* Call this when the client is no longer needed (e.g., on component unmount).
|
|
844
|
+
*/
|
|
845
|
+
dispose(): void;
|
|
733
846
|
/**
|
|
734
847
|
* Gets the local feature state for a license+feature combination.
|
|
735
848
|
* @param licenseId The license identifier.
|
|
@@ -973,18 +1086,24 @@ declare class SignatureValidator {
|
|
|
973
1086
|
}
|
|
974
1087
|
|
|
975
1088
|
/**
|
|
976
|
-
*
|
|
1089
|
+
* Authorization cache with TTL-based expiry, pseudo-LRU eviction, and localStorage persistence.
|
|
977
1090
|
* Cache key format: {licenseId}.{serviceKeyId}
|
|
978
1091
|
* One cache instance per LicensingClient — no singletons.
|
|
1092
|
+
*
|
|
1093
|
+
* When a storagePrefix is provided, entries are persisted to localStorage and restored
|
|
1094
|
+
* on construction, surviving page refreshes. Cross-tab sync is available via onSync().
|
|
979
1095
|
*/
|
|
980
1096
|
declare class AuthorizationCache {
|
|
981
1097
|
private cache;
|
|
982
1098
|
private maxSize;
|
|
1099
|
+
private storagePrefix;
|
|
1100
|
+
private unsubscribe;
|
|
983
1101
|
/**
|
|
984
1102
|
* Creates a new authorization cache.
|
|
985
1103
|
* @param maxSize The maximum number of entries to store before evicting the oldest. Defaults to 100.
|
|
1104
|
+
* @param storagePrefix Optional localStorage key prefix for persisting entries across page refreshes.
|
|
986
1105
|
*/
|
|
987
|
-
constructor(maxSize?: number);
|
|
1106
|
+
constructor(maxSize?: number, storagePrefix?: string);
|
|
988
1107
|
/**
|
|
989
1108
|
* Gets a cached authorization if it exists and has not expired.
|
|
990
1109
|
* On hit, re-inserts the entry to move it to the end (pseudo-LRU freshness).
|
|
@@ -1010,8 +1129,64 @@ declare class AuthorizationCache {
|
|
|
1010
1129
|
* @param licenseId The license identifier to invalidate.
|
|
1011
1130
|
*/
|
|
1012
1131
|
invalidate(licenseId: string): void;
|
|
1132
|
+
/**
|
|
1133
|
+
* Registers a cross-tab sync listener. When another tab modifies auth cache entries,
|
|
1134
|
+
* the in-memory cache is updated and the callback is invoked.
|
|
1135
|
+
*
|
|
1136
|
+
* @param callback Invoked after in-memory state is updated from another tab.
|
|
1137
|
+
* @returns An unsubscribe function to remove the listener.
|
|
1138
|
+
*/
|
|
1139
|
+
onSync(callback: () => void): () => void;
|
|
1140
|
+
/**
|
|
1141
|
+
* Removes the cross-tab sync listener if active.
|
|
1142
|
+
*/
|
|
1143
|
+
dispose(): void;
|
|
1144
|
+
/**
|
|
1145
|
+
* Serializes a cache entry for localStorage storage.
|
|
1146
|
+
* Converts Date objects to epoch numbers for safe JSON round-tripping.
|
|
1147
|
+
*/
|
|
1148
|
+
private serializeEntry;
|
|
1149
|
+
/**
|
|
1150
|
+
* Deserializes a cache entry from localStorage, reconstructing Date objects.
|
|
1151
|
+
*/
|
|
1152
|
+
private deserializeEntry;
|
|
1013
1153
|
}
|
|
1014
1154
|
|
|
1155
|
+
/**
|
|
1156
|
+
* Thin localStorage abstraction for persisting SDK state across page refreshes.
|
|
1157
|
+
* All methods are SSR-safe — they no-op when `window`/`localStorage` is unavailable.
|
|
1158
|
+
*
|
|
1159
|
+
* Used by RateLimitFeatureState and AuthorizationCache for transparent persistence.
|
|
1160
|
+
*/
|
|
1161
|
+
/**
|
|
1162
|
+
* Serializes and stores a value under the given key.
|
|
1163
|
+
* No-op in SSR/Node environments.
|
|
1164
|
+
*/
|
|
1165
|
+
declare function save<T>(key: string, data: T): void;
|
|
1166
|
+
/**
|
|
1167
|
+
* Loads and deserializes a value from the given key.
|
|
1168
|
+
* Returns null if the key is missing, the value cannot be parsed, or in SSR.
|
|
1169
|
+
*/
|
|
1170
|
+
declare function load<T>(key: string): T | null;
|
|
1171
|
+
/**
|
|
1172
|
+
* Removes a value from localStorage.
|
|
1173
|
+
* No-op in SSR/Node environments.
|
|
1174
|
+
*/
|
|
1175
|
+
declare function remove(key: string): void;
|
|
1176
|
+
/**
|
|
1177
|
+
* Returns all localStorage keys that start with the given prefix.
|
|
1178
|
+
* Returns an empty array in SSR/Node environments.
|
|
1179
|
+
*/
|
|
1180
|
+
declare function listKeys(prefix: string): string[];
|
|
1181
|
+
/**
|
|
1182
|
+
* Registers a listener for localStorage changes from OTHER tabs.
|
|
1183
|
+
* Filters events by key prefix and calls the callback with the full key and new value.
|
|
1184
|
+
*
|
|
1185
|
+
* Returns an unsubscribe function that removes the listener.
|
|
1186
|
+
* Returns a no-op in SSR/Node environments.
|
|
1187
|
+
*/
|
|
1188
|
+
declare function onStorageChange(prefix: string, callback: (key: string, newValue: string | null) => void): () => void;
|
|
1189
|
+
|
|
1015
1190
|
/**
|
|
1016
1191
|
* Context for providing the LicensingClient to React components
|
|
1017
1192
|
*/
|
|
@@ -1167,5 +1342,5 @@ declare class ConfigurationContextProvider implements ILicensingContextProvider
|
|
|
1167
1342
|
resolveContext(): Promise<LicensingContextType | null>;
|
|
1168
1343
|
}
|
|
1169
1344
|
|
|
1170
|
-
export { AuthorizationCache, BillingIntervalUnit, CompositeAssertion, ConfigurationContextProvider, CryptoError, CryptoService, FeatureExistsAssertion, LicenseAssertion, LicenseClassificationType, LicensingClient, LicensingConfigurationException, LicensingError, LicensingProvider, NotAssertion, RateLimitAssertion, RateLimitFeatureState, ServiceAccessAssertion, ServiceAccessLevel, SignatureValidator, decodeCredential, encodeCredential, findFeatureByKey, getFeatureKey, hasFeature, hasValidCryptoConfig, licensingContextFromEncodedString, licensingContextToEncodedString, matchesFeatureKey, normalizeBillingIntervalUnit, normalizeLicenseClassificationType, normalizeServiceAccessLevel, tryDecodeCredential, useLicensingContext, useLicensingContextValue };
|
|
1171
|
-
export type { CheckoutRequest, CheckoutSession, CheckoutSessionResult, CheckoutSessionStatus, ClientLicenseConfiguration, CryptoConfig, GenerateLicenseAuthorizationParameters, ILicenseAssertion, ILicenseFeature, ILicensingContextProvider, License, LicenseAuthorization, LicenseFeatureStateOperation, LicensingConfig, LicensingContextType, LicensingCredential, LicensingProviderProps, RateAgreement, RateLimitLicenseFeature, RawAuthorizationResponse, ServerFeature, ServiceAccessLicenseFeature, SignatureValidationOptions, SignatureValidationResult };
|
|
1345
|
+
export { AuthorizationCache, BillingIntervalUnit, CompositeAssertion, ConfigurationContextProvider, CryptoError, CryptoService, FeatureExistsAssertion, LicenseAssertion, LicenseClassificationType, LicensingClient, LicensingConfigurationException, LicensingError, LicensingProvider, NotAssertion, RateLimitAssertion, RateLimitError, RateLimitFeatureState, ServiceAccessAssertion, ServiceAccessLevel, SignatureValidator, decodeCredential, encodeCredential, findFeatureByKey, getFeatureKey, hasFeature, hasValidCryptoConfig, licensingContextFromEncodedString, licensingContextToEncodedString, listKeys, load, matchesFeatureKey, normalizeBillingIntervalUnit, normalizeLicenseClassificationType, normalizeServiceAccessLevel, onStorageChange, remove, save, tryDecodeCredential, useLicensingContext, useLicensingContextValue };
|
|
1346
|
+
export type { CheckoutRequest, CheckoutSession, CheckoutSessionResult, CheckoutSessionStatus, ClientLicenseConfiguration, ConsumptionView, CryptoConfig, FeatureView, GenerateLicenseAuthorizationParameters, ILicenseAssertion, ILicenseFeature, ILicensingContextProvider, License, LicenseAuthorization, LicenseFeatureStateOperation, LicenseStateView, LicensingConfig, LicensingContextType, LicensingCredential, LicensingProviderProps, RateAgreement, RateLimitLicenseFeature, RawAuthorizationResponse, ServerFeature, ServiceAccessLicenseFeature, SignatureValidationOptions, SignatureValidationResult };
|