@stigg/js-client-sdk 3.105.1 → 4.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/dist/client.d.ts +13 -4
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +8 -147
- package/dist/offlineClient.d.ts +3 -2
- package/dist/services/entitlementsService.d.ts +8 -8
- package/dist/services/eventEmitter.d.ts +2 -2
- package/dist/services/inMemoryCacheService.d.ts +7 -14
- package/dist/services/loggerService.d.ts +6 -7
- package/dist/utils/ModelMapper.d.ts +2 -16
- package/package.json +3 -1
- package/dist/services/cacheService.d.ts +0 -14
- package/dist/services/cachedEntitlement.d.ts +0 -45
- package/dist/services/entitlementDecisionService.d.ts +0 -10
- package/dist/utils/calculateUsagePeriod.d.ts +0 -5
- package/dist/utils/dateUtils.d.ts +0 -1
- package/dist/utils/isMetered.d.ts +0 -7
- package/dist/utils/mapGetEntitlementsFallback.d.ts +0 -35
package/dist/models.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { BillingCadence, BillingModel, BillingPeriod, Currency, PricingType, PromotionalEntitlementStatus, SubscriptionStatus, SubscriptionQueryFragment, TrialPeriodUnits, ExperimentGroupType, CustomerPortalEntitlementFragment, CustomerPortalPromotionalEntitlementFragment, CustomerPortalSubscriptionFragment, CustomerPortalSubscriptionAddonFragment, CustomerPortalBillingInformationFragment, PaywallConfigurationFragment, CustomerPortalConfigurationFragment, WidgetType, CustomerPortalSubscriptionScheduledUpdateDataFragment, DiscountType, DiscountDurationType, PackageEntitlementFragment, PageInfoFragment, PaywallCurrencyFragment, FeatureType, MeterType, EntitlementResetPeriod,
|
|
1
|
+
import { BillingCadence, BillingModel, BillingPeriod, Currency, PricingType, PromotionalEntitlementStatus, SubscriptionStatus, SubscriptionQueryFragment, TrialPeriodUnits, ExperimentGroupType, CustomerPortalEntitlementFragment, CustomerPortalPromotionalEntitlementFragment, CustomerPortalSubscriptionFragment, CustomerPortalSubscriptionAddonFragment, CustomerPortalBillingInformationFragment, PaywallConfigurationFragment, CustomerPortalConfigurationFragment, WidgetType, CustomerPortalSubscriptionScheduledUpdateDataFragment, DiscountType, DiscountDurationType, PackageEntitlementFragment, PageInfoFragment, PaywallCurrencyFragment, FeatureType, MeterType, EntitlementResetPeriod, PaywallCalculatedPricePointsFragment, SubscriptionInvoiceFragment, PaymentCollection, PlanFragment, BillingVendorIdentifier, TiersMode, SubscriptionFutureUpdateDataFragment, PriceTierFragment, TotalPriceFragment, CheckoutConfigurationFragment, TypographyConfigurationFragment, BillingAddress, ScheduleStrategy, PaymentCollectionMethod, BudgetConfigurationInput, SubscriptionProrationBehavior, SubscriptionBillingCycleAnchor, PaymentSessionInput, CreditBalanceSummaryInput, StripeCheckoutCredentialsFragment, ZuoraCheckoutCredentialsFragment, GetCreditGrantsInput as GetCreditGrantsInputGenerated, CreditLedgerInput, CreditUsageInput, CreditGrantFragment, CreditLedgerFragment, AutoRechargeSettingsFragment, GetAutoRechargeSettingsInput, SaveAutoRechargeSettingsInput, PackageEntitlementUnionFragment, EntitlementUnionFragment } from '@stigg/api-client-js';
|
|
2
|
+
export { BaseEntitlement, BooleanEntitlement, EnumEntitlement, NumericEntitlement, MeteredEntitlement, CreditEntitlement, Entitlement, EntitlementV2, CustomerEntitlementsResult, CustomerEntitlementsResultV2, BOOLEAN_DEFAULT_FALLBACK_ENTITLEMENT, NUMERIC_DEFAULT_FALLBACK_ENTITLEMENT, METERED_DEFAULT_FALLBACK_ENTITLEMENT, ENUM_DEFAULT_FALLBACK_ENTITLEMENT, CREDIT_DEFAULT_FALLBACK_ENTITLEMENT, BooleanEntitlementFallback, BooleanEntitlementOptions, NumericEntitlementFallback, NumericEntitlementOptions, MeteredEntitlementFallback, MeteredEntitlementOptions, EnumEntitlementFallback, EnumEntitlementOptions, CreditEntitlementFallback, CreditEntitlementOptions, EntitlementsFallback, } from '@stigg/sdk-core';
|
|
3
|
+
import type { GetBooleanEntitlement as SdkCoreGetBooleanEntitlement, GetNumericEntitlement as SdkCoreGetNumericEntitlement, GetMeteredEntitlement as SdkCoreGetMeteredEntitlement, GetEnumEntitlement as SdkCoreGetEnumEntitlement, GetCreditEntitlement as SdkCoreGetCreditEntitlement } from '@stigg/sdk-core';
|
|
2
4
|
export * from '@stigg/api-client-js';
|
|
3
5
|
interface Metadata {
|
|
4
6
|
[key: string]: string;
|
|
@@ -14,90 +16,7 @@ export type EntitlementFeature = {
|
|
|
14
16
|
isMetered?: boolean;
|
|
15
17
|
metadata?: Record<string, string>;
|
|
16
18
|
};
|
|
17
|
-
export type
|
|
18
|
-
hasAccess: boolean;
|
|
19
|
-
isFallback: boolean;
|
|
20
|
-
accessDeniedReason?: AccessDeniedReason;
|
|
21
|
-
feature?: EntitlementFeature;
|
|
22
|
-
};
|
|
23
|
-
export interface BooleanEntitlement extends BaseEntitlement {
|
|
24
|
-
}
|
|
25
|
-
export interface EnumEntitlement extends BaseEntitlement {
|
|
26
|
-
enumValues: string[];
|
|
27
|
-
requestedValues?: string[];
|
|
28
|
-
}
|
|
29
|
-
export interface NumericEntitlement extends BaseEntitlement {
|
|
30
|
-
value?: number;
|
|
31
|
-
isUnlimited: boolean;
|
|
32
|
-
}
|
|
33
|
-
/** @deprecated - fields were moved into {@link MeteredEntitlement} */
|
|
34
|
-
export type ResetSettings = {
|
|
35
|
-
/** @deprecated - renamed to {@link MeteredEntitlement.usagePeriodEnd} */
|
|
36
|
-
nextResetDate: Date;
|
|
37
|
-
/** @deprecated - renamed to {@link MeteredEntitlement.resetPeriod} */
|
|
38
|
-
resetPeriod: EntitlementResetPeriod;
|
|
39
|
-
};
|
|
40
|
-
export interface MeteredEntitlement extends BaseEntitlement {
|
|
41
|
-
usageLimit?: number;
|
|
42
|
-
isUnlimited: boolean;
|
|
43
|
-
currentUsage: number;
|
|
44
|
-
requestedUsage: number;
|
|
45
|
-
resetPeriod?: EntitlementResetPeriod;
|
|
46
|
-
/** The anchor for calculating the usage period for metered entitlements with a reset period configured */
|
|
47
|
-
usagePeriodAnchor?: Date;
|
|
48
|
-
/** The start date of the usage period for metered entitlements with a reset period configured */
|
|
49
|
-
usagePeriodStart?: Date;
|
|
50
|
-
/** The end date of the usage period for metered entitlements with a reset period configured */
|
|
51
|
-
usagePeriodEnd?: Date;
|
|
52
|
-
/** @deprecated fields were moved into {@link MeteredEntitlement} */
|
|
53
|
-
resetSettings?: ResetSettings;
|
|
54
|
-
}
|
|
55
|
-
export type Entitlement = BooleanEntitlement | NumericEntitlement | MeteredEntitlement;
|
|
56
|
-
export type EntitlementsState = {
|
|
57
|
-
entitlements: Entitlement[];
|
|
58
|
-
accessDeniedReason: EntitlementsStateAccessDeniedReason | null;
|
|
59
|
-
};
|
|
60
|
-
/** @internal */
|
|
61
|
-
export declare const BOOLEAN_DEFAULT_FALLBACK_ENTITLEMENT: BooleanEntitlement;
|
|
62
|
-
/** @internal */
|
|
63
|
-
export declare const NUMERIC_DEFAULT_FALLBACK_ENTITLEMENT: NumericEntitlement;
|
|
64
|
-
/** @internal */
|
|
65
|
-
export declare const METERED_DEFAULT_FALLBACK_ENTITLEMENT: MeteredEntitlement;
|
|
66
|
-
/** @internal */
|
|
67
|
-
export declare const ENUM_DEFAULT_FALLBACK_ENTITLEMENT: EnumEntitlement;
|
|
68
|
-
export type CreditEntitlementCurrency = {
|
|
69
|
-
currencyId: string;
|
|
70
|
-
displayName?: string;
|
|
71
|
-
description?: string;
|
|
72
|
-
unitSingular?: string;
|
|
73
|
-
unitPlural?: string;
|
|
74
|
-
additionalMetaData?: Record<string, unknown>;
|
|
75
|
-
};
|
|
76
|
-
export interface CreditEntitlement {
|
|
77
|
-
hasAccess: boolean;
|
|
78
|
-
isFallback: boolean;
|
|
79
|
-
accessDeniedReason?: AccessDeniedReason;
|
|
80
|
-
currency: CreditEntitlementCurrency;
|
|
81
|
-
usageLimit: number;
|
|
82
|
-
currentUsage: number;
|
|
83
|
-
remaining: number;
|
|
84
|
-
usagePeriodEnd?: Date;
|
|
85
|
-
}
|
|
86
|
-
/** @internal */
|
|
87
|
-
export declare const CREDIT_DEFAULT_FALLBACK_ENTITLEMENT: CreditEntitlement;
|
|
88
|
-
export type GetCreditEntitlement = {
|
|
89
|
-
currencyId: string;
|
|
90
|
-
resourceId?: string;
|
|
91
|
-
options?: CreditEntitlementOptions;
|
|
92
|
-
};
|
|
93
|
-
export type CreditEntitlementOptions = {
|
|
94
|
-
fallback?: CreditEntitlementFallback;
|
|
95
|
-
};
|
|
96
|
-
export type CreditEntitlementFallback = {
|
|
97
|
-
hasAccess?: boolean;
|
|
98
|
-
usageLimit?: number;
|
|
99
|
-
currentUsage?: number;
|
|
100
|
-
};
|
|
19
|
+
export type GetCreditEntitlement = Omit<SdkCoreGetCreditEntitlement, 'customerId'>;
|
|
101
20
|
export type PackageEntitlement = {
|
|
102
21
|
usageLimit: number;
|
|
103
22
|
feature?: EntitlementFeature;
|
|
@@ -201,26 +120,10 @@ export type DefaultTrialConfig = {
|
|
|
201
120
|
limit: BudgetConfigurationInput['limit'];
|
|
202
121
|
};
|
|
203
122
|
};
|
|
204
|
-
export type GetBooleanEntitlement =
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
209
|
-
export type GetNumericEntitlement = {
|
|
210
|
-
featureId: string;
|
|
211
|
-
options?: NumericEntitlementOptions;
|
|
212
|
-
resourceId?: string;
|
|
213
|
-
};
|
|
214
|
-
export type GetMeteredEntitlement = {
|
|
215
|
-
featureId: string;
|
|
216
|
-
options?: MeteredEntitlementOptions;
|
|
217
|
-
resourceId?: string;
|
|
218
|
-
};
|
|
219
|
-
export type GetEnumEntitlement = {
|
|
220
|
-
featureId: string;
|
|
221
|
-
resourceId?: string;
|
|
222
|
-
options?: EnumEntitlementOptions;
|
|
223
|
-
};
|
|
123
|
+
export type GetBooleanEntitlement = Omit<SdkCoreGetBooleanEntitlement, 'customerId'>;
|
|
124
|
+
export type GetNumericEntitlement = Omit<SdkCoreGetNumericEntitlement, 'customerId'>;
|
|
125
|
+
export type GetMeteredEntitlement = Omit<SdkCoreGetMeteredEntitlement, 'customerId'>;
|
|
126
|
+
export type GetEnumEntitlement = Omit<SdkCoreGetEnumEntitlement, 'customerId'>;
|
|
224
127
|
export type PaginatedResult<T> = {
|
|
225
128
|
data: T[];
|
|
226
129
|
pageInfo: PageInfoFragment;
|
|
@@ -300,48 +203,6 @@ export type SubscriptionBillingInfo = {
|
|
|
300
203
|
export type ApplySubscriptionResults = {
|
|
301
204
|
subscription?: Subscription;
|
|
302
205
|
};
|
|
303
|
-
export type EntitlementsFallback = {
|
|
304
|
-
[featureId: string]: BooleanEntitlementFallback | NumericEntitlementFallback | MeteredEntitlementFallback | EnumEntitlementFallback;
|
|
305
|
-
};
|
|
306
|
-
export type BooleanEntitlementFallback = {
|
|
307
|
-
hasAccess: boolean;
|
|
308
|
-
};
|
|
309
|
-
export type BooleanEntitlementOptions = {
|
|
310
|
-
/** @deprecated not in use anymore */
|
|
311
|
-
shouldTrack?: boolean;
|
|
312
|
-
fallback?: BooleanEntitlementFallback;
|
|
313
|
-
};
|
|
314
|
-
export type NumericEntitlementFallback = {
|
|
315
|
-
hasAccess: boolean;
|
|
316
|
-
value?: number;
|
|
317
|
-
isUnlimited?: boolean;
|
|
318
|
-
};
|
|
319
|
-
export type NumericEntitlementOptions = {
|
|
320
|
-
/** @deprecated not in use anymore */
|
|
321
|
-
shouldTrack?: boolean;
|
|
322
|
-
fallback?: NumericEntitlementFallback;
|
|
323
|
-
};
|
|
324
|
-
export type MeteredEntitlementFallback = {
|
|
325
|
-
hasAccess: boolean;
|
|
326
|
-
usageLimit?: number;
|
|
327
|
-
isUnlimited?: boolean;
|
|
328
|
-
};
|
|
329
|
-
export type EnumEntitlementFallback = {
|
|
330
|
-
hasAccess: boolean;
|
|
331
|
-
enumValues?: string[];
|
|
332
|
-
};
|
|
333
|
-
export type EnumEntitlementOptions = {
|
|
334
|
-
requestedValues?: string[];
|
|
335
|
-
/** @deprecated not in use anymore */
|
|
336
|
-
shouldTrack?: boolean;
|
|
337
|
-
fallback?: EnumEntitlementFallback;
|
|
338
|
-
};
|
|
339
|
-
export type MeteredEntitlementOptions = {
|
|
340
|
-
requestedUsage?: number;
|
|
341
|
-
/** @deprecated not in use anymore */
|
|
342
|
-
shouldTrack?: boolean;
|
|
343
|
-
fallback?: MeteredEntitlementFallback;
|
|
344
|
-
};
|
|
345
206
|
export type CompatiblePackageGroupOptions = {
|
|
346
207
|
minItems?: number;
|
|
347
208
|
freeItems?: number;
|
package/dist/offlineClient.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Stigg, StiggClient } from './client';
|
|
2
2
|
import { ClientConfiguration } from './configuration';
|
|
3
3
|
import { LoggerService } from './services/loggerService';
|
|
4
|
-
import { ApplySubscriptionResults, AutomaticRechargeConfiguration, BooleanEntitlement, Coupon, CreditEntitlement, CreditsBalanceSummaryFragment, CreditUsageFragment, Customer, CustomerPortal, Entitlement,
|
|
4
|
+
import { ApplySubscriptionResults, AutomaticRechargeConfiguration, BooleanEntitlement, Coupon, CreditEntitlement, CreditsBalanceSummaryFragment, CreditUsageFragment, Customer, CustomerPortal, Entitlement, CustomerEntitlementsResult, CustomerEntitlementsResultV2, EnumEntitlement, GetAutomaticRechargeConfigurationInput, GetBooleanEntitlement, GetCheckoutStateResults, GetCreditEntitlement, GetCreditGrantsResult, GetCreditLedgerResult, GetEnumEntitlement, GetMeteredEntitlement, GetNumericEntitlement, GetSubscriptionsResult, MeteredEntitlement, NumericEntitlement, PaymentSessionFragment, Paywall, SaveAutomaticRechargeConfigurationInput, SlimSubscriptionFragmentV2Fragment, Subscription, SubscriptionInvoicePreviewFragment, SubscriptionPreview, SubscriptionPreviewV2, UsageHistoryPoint, UsageHistoryV2Fragment } from './models';
|
|
5
5
|
export declare class OfflineStigg extends Stigg {
|
|
6
6
|
static createOffline(config: Required<ClientConfiguration>, loggerService: LoggerService): OfflineStigg;
|
|
7
7
|
getBooleanEntitlement({ featureId, options }: GetBooleanEntitlement): BooleanEntitlement;
|
|
@@ -10,7 +10,8 @@ export declare class OfflineStigg extends Stigg {
|
|
|
10
10
|
getEnumEntitlement({ featureId, options }: GetEnumEntitlement): EnumEntitlement;
|
|
11
11
|
getCreditEntitlement({ currencyId, options }: GetCreditEntitlement): CreditEntitlement;
|
|
12
12
|
getEntitlements(): Promise<Entitlement[]>;
|
|
13
|
-
getEntitlementsState(): Promise<
|
|
13
|
+
getEntitlementsState(): Promise<CustomerEntitlementsResult>;
|
|
14
|
+
getEntitlementsStateV2(): Promise<CustomerEntitlementsResultV2>;
|
|
14
15
|
addListener(): void;
|
|
15
16
|
clearCustomer(): void;
|
|
16
17
|
clearResource(): void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core';
|
|
2
|
-
import {
|
|
3
|
-
import { BooleanEntitlement, BooleanEntitlementOptions, CreditEntitlement,
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
2
|
+
import { EntitlementUnionFragment, EntitlementsStateAccessDeniedReason } from '@stigg/api-client-js';
|
|
3
|
+
import { BooleanEntitlement, BooleanEntitlementOptions, CreditEntitlement, CustomerEntitlementsResultV2, EnumEntitlement, EnumEntitlementOptions, MeteredEntitlement, MeteredEntitlementOptions, NumericEntitlement, NumericEntitlementOptions } from '../models';
|
|
4
|
+
import { CacheableEntitlement } from '@stigg/sdk-core';
|
|
5
|
+
import { InMemoryCacheService } from './inMemoryCacheService';
|
|
6
6
|
import { LoggerService } from './loggerService';
|
|
7
7
|
import { EdgeApiClient } from '../api/EdgeApiClient';
|
|
8
8
|
export declare class EntitlementsService {
|
|
@@ -12,15 +12,14 @@ export declare class EntitlementsService {
|
|
|
12
12
|
private loggerService;
|
|
13
13
|
private onEntitlementsUpdated;
|
|
14
14
|
private readonly entitlementsApi;
|
|
15
|
-
private readonly
|
|
15
|
+
private readonly evaluator;
|
|
16
16
|
private loadingEntitlements;
|
|
17
|
-
constructor(customerId: string, resourceId: string | undefined, cacheService:
|
|
17
|
+
constructor(customerId: string, resourceId: string | undefined, cacheService: InMemoryCacheService<CacheableEntitlement>, client: ApolloClient<NormalizedCacheObject>, edgeApiClient: EdgeApiClient | null, loggerService: LoggerService, onEntitlementsUpdated: (data: CustomerEntitlementsResultV2) => void);
|
|
18
18
|
refresh(): Promise<void>;
|
|
19
19
|
get isInitialized(): boolean;
|
|
20
20
|
getBooleanEntitlement(featureId: string, fallbackEntitlement: BooleanEntitlement, _options?: BooleanEntitlementOptions): BooleanEntitlement;
|
|
21
21
|
getNumericEntitlement(featureId: string, fallbackEntitlement: NumericEntitlement, _options?: NumericEntitlementOptions): NumericEntitlement;
|
|
22
22
|
getMeteredEntitlement(featureId: string, fallbackEntitlement: MeteredEntitlement, options?: MeteredEntitlementOptions): MeteredEntitlement;
|
|
23
|
-
private handleUsagePeriodOver;
|
|
24
23
|
getEnumEntitlement(featureId: string, fallbackEntitlement: EnumEntitlement, options?: EnumEntitlementOptions): EnumEntitlement;
|
|
25
24
|
getCreditEntitlement(currencyId: string, fallbackEntitlement: CreditEntitlement): CreditEntitlement;
|
|
26
25
|
loadEntitlements(skipEdge?: boolean): Promise<void>;
|
|
@@ -28,7 +27,8 @@ export declare class EntitlementsService {
|
|
|
28
27
|
protected storeFetchedEntitlementsInCache(entitlements: EntitlementUnionFragment[], accessDeniedReason: EntitlementsStateAccessDeniedReason | null): void;
|
|
29
28
|
private getLastEntitlementsUpdate;
|
|
30
29
|
private getEntitlement;
|
|
31
|
-
|
|
30
|
+
getCustomerEntitlements(): Promise<CustomerEntitlementsResultV2>;
|
|
31
|
+
private evaluateCustomerEntitlements;
|
|
32
32
|
private renewOutdatedCache;
|
|
33
33
|
renewOutdatedCacheInBackground(): void;
|
|
34
34
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
2
|
-
import
|
|
2
|
+
import { CustomerEntitlementsResultV2 } from '../models';
|
|
3
3
|
export interface Events {
|
|
4
4
|
initializeSuccessfully: () => void;
|
|
5
5
|
initializeFailed: (err: any) => void;
|
|
6
|
-
entitlementsUpdated: (data:
|
|
6
|
+
entitlementsUpdated: (data: CustomerEntitlementsResultV2) => void;
|
|
7
7
|
}
|
|
8
8
|
export type EventNames = keyof Events;
|
|
9
9
|
export declare class TypedEventEmitter extends TypedEmitter<Events> {
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { InMemoryCacheService as BaseInMemoryCacheService, CacheMapper, EntitlementsMap, SetCustomerParams } from '@stigg/cache-core';
|
|
2
|
+
/**
|
|
3
|
+
* Extends shared InMemoryCacheService with TTL tracking and stale-write prevention.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InMemoryCacheService<Input> extends BaseInMemoryCacheService<Input> {
|
|
4
6
|
private readonly ttlMs;
|
|
5
|
-
private entitlementsState;
|
|
6
|
-
private creditEntitlements;
|
|
7
7
|
private lastUpdate;
|
|
8
8
|
private lastChecked;
|
|
9
|
-
|
|
10
|
-
constructor(ttlMs?: number);
|
|
11
|
-
getEntitlement(featureId: string): CachedEntitlement | null;
|
|
12
|
-
validateFeature(featureId: string): boolean;
|
|
13
|
-
setFeatures: (features: string[]) => Set<string>;
|
|
9
|
+
constructor(cacheMapper: CacheMapper<Input>, ttlMs?: number);
|
|
14
10
|
updateLastChecked(): void;
|
|
15
|
-
|
|
16
|
-
getEntitlements(): CachedEntitlementsState;
|
|
11
|
+
setCustomer(params: SetCustomerParams<Input>): EntitlementsMap;
|
|
17
12
|
getLastUpdate(): Date | null;
|
|
18
13
|
isLoaded(): boolean;
|
|
19
14
|
isOutdated(): boolean;
|
|
20
|
-
getCreditEntitlement(currencyId: string): CachedCreditEntitlement | null;
|
|
21
|
-
setCreditEntitlements(creditEntitlements: Map<string, CachedCreditEntitlement>): void;
|
|
22
15
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
error: (message: string, error?: Record<string, string>) => void;
|
|
1
|
+
import { SlimLogger, LoggerExtra } from '@stigg/cache-core';
|
|
2
|
+
/** Public logger interface — consumers implement this to provide custom logging. Extends SlimLogger for cache-core compatibility. */
|
|
3
|
+
export interface Logger extends SlimLogger {
|
|
5
4
|
}
|
|
6
5
|
export interface LogConfiguration {
|
|
7
6
|
logger: Logger;
|
|
@@ -17,7 +16,7 @@ export declare class LoggerService implements Logger {
|
|
|
17
16
|
private readonly logger;
|
|
18
17
|
private readonly logLevel;
|
|
19
18
|
constructor(logger: Logger, logLevel: LogLevel);
|
|
20
|
-
error(message: string, error?:
|
|
21
|
-
log(message: string, object?:
|
|
22
|
-
debug(message: string, object?:
|
|
19
|
+
error(message: string, error?: LoggerExtra): void;
|
|
20
|
+
log(message: string, object?: LoggerExtra): void;
|
|
21
|
+
debug(message: string, object?: LoggerExtra): void;
|
|
23
22
|
}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { ApplySubscriptionMutation, CustomerFragment, CustomerPortalFragment, CustomerResourceFragment, CheckoutStateFragment, GetCouponsQuery, GetMockPaywallQuery, GetPaywallQuery, SubscriptionFragment, SubscriptionPreviewFragment, UsageHistoryFragment, SubscriptionPreviewV2Fragment, SubscriptionPreviewInvoiceFragment, ImmediateSubscriptionPreviewInvoiceFragment, SlimCustomerFragment
|
|
2
|
-
import {
|
|
3
|
-
import CachedEntitlement, { CachedCreditEntitlement } from '../services/cachedEntitlement';
|
|
4
|
-
import { Decision } from '../services/entitlementDecisionService';
|
|
1
|
+
import { ApplySubscriptionMutation, CustomerFragment, CustomerPortalFragment, CustomerResourceFragment, CheckoutStateFragment, GetCouponsQuery, GetMockPaywallQuery, GetPaywallQuery, SubscriptionFragment, SubscriptionPreviewFragment, UsageHistoryFragment, SubscriptionPreviewV2Fragment, SubscriptionPreviewInvoiceFragment, ImmediateSubscriptionPreviewInvoiceFragment, SlimCustomerFragment } from '@stigg/api-client-js';
|
|
2
|
+
import { ApplySubscriptionResults, Coupon, Customer, CustomerPortal, CustomerResource, GetCheckoutStateResults, Money, Paywall, Plan, Subscription, SubscriptionPreview, SubscriptionPreviewDiscount, UsageHistoryPoint, SubscriptionPreviewV2, SubscriptionPreviewInvoice, SlimCustomer, SubscriptionPreviewCredits } from '../models';
|
|
5
3
|
export declare class ModelMapper {
|
|
6
|
-
mapBooleanEntitlement(entitlement: CachedEntitlement, decision: Decision): BooleanEntitlement;
|
|
7
|
-
mapNumericEntitlement(entitlement: CachedEntitlement, decision: Decision): NumericEntitlement;
|
|
8
|
-
mapMeteredEntitlement(entitlement: CachedEntitlement, decision: Decision, requestedUsage?: number): MeteredEntitlement;
|
|
9
|
-
mapEnumEntitlement(entitlement: CachedEntitlement, decision: Decision, requestedValues?: string[]): EnumEntitlement;
|
|
10
|
-
mapEntitlement(entitlement: CachedEntitlement, decision: Decision, requestedUsage?: number): BooleanEntitlement;
|
|
11
|
-
mapCachedEntitlement(entitlement: FeatureEntitlementFragment): CachedEntitlement;
|
|
12
4
|
mapPlans(resultData: GetPaywallQuery): Plan[];
|
|
13
5
|
mapPaywall(resultData: GetPaywallQuery): Paywall;
|
|
14
6
|
mapMockPlans(resultData: GetMockPaywallQuery): Paywall;
|
|
@@ -49,10 +41,4 @@ export declare class ModelMapper {
|
|
|
49
41
|
private getPriceCurrency;
|
|
50
42
|
private mapCompatiblePackageGroups;
|
|
51
43
|
private mapDependencyAddon;
|
|
52
|
-
mapCachedCreditEntitlement(creditEntitlement: CreditEntitlementFragment): CachedCreditEntitlement;
|
|
53
|
-
mapCachedEntitlements(entitlements: EntitlementUnionFragment[]): {
|
|
54
|
-
featureEntitlements: Map<string, CachedEntitlement>;
|
|
55
|
-
creditEntitlements: Map<string, CachedCreditEntitlement>;
|
|
56
|
-
};
|
|
57
|
-
mapCreditEntitlement(cachedCreditEntitlement: CachedCreditEntitlement, decision: Decision): CreditEntitlement;
|
|
58
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigg/js-client-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Stigg client-side SDK for Browser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
"@apollo/client": "^3.4.17",
|
|
38
38
|
"@sentry/browser": "^7.11.1",
|
|
39
39
|
"@stigg/api-client-js": "6.10.1",
|
|
40
|
+
"@stigg/cache-core": "1.11.1",
|
|
41
|
+
"@stigg/sdk-core": "2.1.0",
|
|
40
42
|
"cross-fetch": "^3.1.6",
|
|
41
43
|
"dayjs": "^1.11.13",
|
|
42
44
|
"fetch-retry": "^5.0.6",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import CachedEntitlement, { CachedCreditEntitlement, CachedEntitlementsState } from './cachedEntitlement';
|
|
2
|
-
export interface CacheService {
|
|
3
|
-
isLoaded(): boolean;
|
|
4
|
-
getLastUpdate(): Date | null;
|
|
5
|
-
updateLastChecked(): void;
|
|
6
|
-
isOutdated(): boolean;
|
|
7
|
-
setEntitlements(entitlementsState: CachedEntitlementsState, lastUpdate: Date): void;
|
|
8
|
-
getEntitlement(featureId: string): CachedEntitlement | null;
|
|
9
|
-
getEntitlements(): CachedEntitlementsState;
|
|
10
|
-
validateFeature(featureId: string): boolean;
|
|
11
|
-
setFeatures(features: string[]): void;
|
|
12
|
-
getCreditEntitlement(currencyId: string): CachedCreditEntitlement | null;
|
|
13
|
-
setCreditEntitlements(creditEntitlements: Map<string, CachedCreditEntitlement>): void;
|
|
14
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { CreditEntitlementCurrency, EntitlementFeature, EntitlementResetPeriod } from '../models';
|
|
2
|
-
import { AccessDeniedReason, EntitlementsStateAccessDeniedReason, ResetPeriodConfigurationFragment } from '@stigg/api-client-js';
|
|
3
|
-
export interface CalculatedEntitlement {
|
|
4
|
-
usageLimit?: number | null;
|
|
5
|
-
hasUnlimitedUsage: boolean;
|
|
6
|
-
hasSoftLimit: boolean;
|
|
7
|
-
feature?: EntitlementFeature;
|
|
8
|
-
accessDeniedReason?: AccessDeniedReason;
|
|
9
|
-
enumValues?: string[];
|
|
10
|
-
}
|
|
11
|
-
export interface EntitlementUsage {
|
|
12
|
-
currentUsage: number;
|
|
13
|
-
usagePeriodAnchor?: Date;
|
|
14
|
-
usagePeriodStart?: Date;
|
|
15
|
-
usagePeriodEnd?: Date;
|
|
16
|
-
resetPeriod?: EntitlementResetPeriod | null;
|
|
17
|
-
resetPeriodConfiguration?: ResetPeriodConfigurationFragment | null;
|
|
18
|
-
}
|
|
19
|
-
export declare class CachedEntitlementsState {
|
|
20
|
-
readonly entitlements: Map<string, CachedEntitlement>;
|
|
21
|
-
readonly accessDeniedReason: EntitlementsStateAccessDeniedReason | null;
|
|
22
|
-
constructor(entitlements: Map<string, CachedEntitlement>, accessDeniedReason: EntitlementsStateAccessDeniedReason | null);
|
|
23
|
-
}
|
|
24
|
-
export default class CachedEntitlement {
|
|
25
|
-
readonly calculatedEntitlement: CalculatedEntitlement;
|
|
26
|
-
readonly featureUsage: EntitlementUsage;
|
|
27
|
-
constructor(calculatedEntitlement: CalculatedEntitlement, featureUsage: EntitlementUsage);
|
|
28
|
-
}
|
|
29
|
-
export interface CachedCreditEntitlementData {
|
|
30
|
-
currency: CreditEntitlementCurrency;
|
|
31
|
-
isGranted: boolean;
|
|
32
|
-
accessDeniedReason?: AccessDeniedReason;
|
|
33
|
-
usageLimit: number;
|
|
34
|
-
currentUsage: number;
|
|
35
|
-
usagePeriodEnd?: Date;
|
|
36
|
-
}
|
|
37
|
-
export declare class CachedCreditEntitlement {
|
|
38
|
-
readonly currency: CreditEntitlementCurrency;
|
|
39
|
-
readonly isGranted: boolean;
|
|
40
|
-
readonly accessDeniedReason?: AccessDeniedReason;
|
|
41
|
-
readonly usageLimit: number;
|
|
42
|
-
readonly currentUsage: number;
|
|
43
|
-
readonly usagePeriodEnd?: Date;
|
|
44
|
-
constructor(data: CachedCreditEntitlementData);
|
|
45
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import CachedEntitlement, { CachedCreditEntitlement } from './cachedEntitlement';
|
|
2
|
-
import { AccessDeniedReason } from '../models';
|
|
3
|
-
export declare class EntitlementDecisionService {
|
|
4
|
-
static decideCreditEntitlementPolicy(creditEntitlement?: CachedCreditEntitlement | null): Decision;
|
|
5
|
-
static decideEntitlementPolicy(entitlement?: CachedEntitlement | null, requestUsage?: number, requestedValues?: string[]): Decision;
|
|
6
|
-
}
|
|
7
|
-
export interface Decision {
|
|
8
|
-
readonly hasAccess: boolean;
|
|
9
|
-
readonly accessDeniedReason?: AccessDeniedReason;
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const mapDate: (date?: string | number | null) => Date | undefined;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { AccessDeniedReason, EntitlementsFallback } from '../models';
|
|
2
|
-
export declare function mapGetEntitlementsFallback(entitlementsFallback?: EntitlementsFallback): ({
|
|
3
|
-
hasAccess: boolean;
|
|
4
|
-
isFallback: boolean;
|
|
5
|
-
accessDeniedReason: AccessDeniedReason;
|
|
6
|
-
feature: {
|
|
7
|
-
id: string;
|
|
8
|
-
};
|
|
9
|
-
} | {
|
|
10
|
-
hasAccess: boolean;
|
|
11
|
-
value?: number;
|
|
12
|
-
isUnlimited?: boolean;
|
|
13
|
-
isFallback: boolean;
|
|
14
|
-
accessDeniedReason: AccessDeniedReason;
|
|
15
|
-
feature: {
|
|
16
|
-
id: string;
|
|
17
|
-
};
|
|
18
|
-
} | {
|
|
19
|
-
hasAccess: boolean;
|
|
20
|
-
usageLimit?: number;
|
|
21
|
-
isUnlimited?: boolean;
|
|
22
|
-
isFallback: boolean;
|
|
23
|
-
accessDeniedReason: AccessDeniedReason;
|
|
24
|
-
feature: {
|
|
25
|
-
id: string;
|
|
26
|
-
};
|
|
27
|
-
} | {
|
|
28
|
-
hasAccess: boolean;
|
|
29
|
-
enumValues?: string[];
|
|
30
|
-
isFallback: boolean;
|
|
31
|
-
accessDeniedReason: AccessDeniedReason;
|
|
32
|
-
feature: {
|
|
33
|
-
id: string;
|
|
34
|
-
};
|
|
35
|
-
})[];
|