@stigg/js-client-sdk
Advanced tools
Comparing version
import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core'; | ||
import { EntitlementQuery, GetEntitlementsQuery } from './generated/types'; | ||
import { FetchEntitlement } from '../models'; | ||
import { GetEntitlementsQuery } from './generated/types'; | ||
declare class EntitlementsApi { | ||
private readonly client; | ||
constructor(client: ApolloClient<NormalizedCacheObject>); | ||
getEntitlement(query: FetchEntitlement): Promise<import("@apollo/client/core").ApolloQueryResult<EntitlementQuery>>; | ||
getEntitlements(customerId: string): Promise<import("@apollo/client/core").ApolloQueryResult<GetEntitlementsQuery>>; | ||
@@ -9,0 +7,0 @@ pollEntitlements(customerId: string, interval: number): import("@apollo/client/core").ObservableQuery<GetEntitlementsQuery, import("./generated/types").Exact<{ |
import { ApolloClient } from '@apollo/client/core'; | ||
declare type ApolloClientConfiguration = { | ||
sdkKey: string; | ||
apiKey: string; | ||
baseUri: string; | ||
}; | ||
declare const initApolloClient: ({ sdkKey, baseUri }: Partial<ApolloClientConfiguration>) => ApolloClient<import("@apollo/client/core").NormalizedCacheObject>; | ||
declare const initApolloClient: ({ apiKey, baseUri }: Partial<ApolloClientConfiguration>) => ApolloClient<import("@apollo/client/core").NormalizedCacheObject>; | ||
export default initApolloClient; |
@@ -1,7 +0,9 @@ | ||
import { EntitlementOptions, Customer, Entitlement, InvalidEntitlement, Plan, FallbackEntitlement } from './models'; | ||
import { Customer, Entitlement, Plan, BooleanEntitlement, NumericEntitlement, MeteredEntitlement, GetBooleanEntitlement, GetNumericEntitlement, GetMeteredEntitlement, GetPaywall } from './models'; | ||
import { ClientConfiguration } from './configuration'; | ||
export interface StiggClient { | ||
getEntitlement: <T extends Entitlement>(featureId: string, options?: EntitlementOptions) => T | InvalidEntitlement | FallbackEntitlement; | ||
setCustomerId: (customerId: string) => void; | ||
getPaywall: (productId?: string) => Promise<Plan[]>; | ||
getBooleanEntitlement: (params: GetBooleanEntitlement) => BooleanEntitlement; | ||
getNumericEntitlement: (params: GetNumericEntitlement) => NumericEntitlement; | ||
getMeteredEntitlement: (params: GetMeteredEntitlement) => MeteredEntitlement; | ||
setCustomerId: (customerId: string) => Promise<void>; | ||
getPaywall: (params?: GetPaywall) => Promise<Plan[]>; | ||
getCustomer: () => Promise<Customer>; | ||
@@ -15,13 +17,58 @@ getEntitlements: () => Promise<Entitlement[]>; | ||
private readonly configuration; | ||
private readonly loggerService; | ||
private entitlementsService; | ||
private readonly modelMapper; | ||
private constructor(); | ||
static initialize(configuration: ClientConfiguration): Promise<StiggClient>; | ||
/** | ||
* Initialize the SDK | ||
* @param {ClientConfiguration} configuration | ||
* @returns {Stigg | null} | ||
*/ | ||
static initialize(configuration: ClientConfiguration): Promise<StiggClient | null>; | ||
/** | ||
* Set the customer ID, usually after the customer signs in or restores a session | ||
* @returns {Promise<void>} | ||
*/ | ||
setCustomerId(customerId: string): Promise<void>; | ||
/** | ||
* Reload entitlements | ||
*/ | ||
refresh(): Promise<void>; | ||
getEntitlement<T extends Entitlement>(featureId: string, options?: EntitlementOptions): T | InvalidEntitlement | FallbackEntitlement; | ||
private handleNoEntitlementFound; | ||
getPaywall(productId?: string): Promise<Plan[]>; | ||
/** | ||
* Get boolean entitlement of feature for a customer | ||
* @param {string} featureId | ||
* @param {BooleanEntitlementOptions} options | ||
* @return {BooleanEntitlement} boolean entitlement | ||
*/ | ||
getBooleanEntitlement({ featureId, options }: GetBooleanEntitlement): BooleanEntitlement; | ||
/** | ||
* Get numeric entitlement of feature for a customer | ||
* @param {string} featureId | ||
* @param {NumericEntitlementOptions} options | ||
* @return {NumericEntitlement} numeric entitlement | ||
*/ | ||
getNumericEntitlement({ featureId, options }: GetNumericEntitlement): NumericEntitlement; | ||
/** | ||
* Get metered entitlement of feature for a customer | ||
* @param {string} featureId | ||
* @param {MeteredEntitlementOptions} options | ||
* @return {MeteredEntitlement} metered entitlement | ||
*/ | ||
getMeteredEntitlement({ featureId, options }: GetMeteredEntitlement): MeteredEntitlement; | ||
/** | ||
* Get a list of plans for rendering the paywall | ||
* @returns {Promise<Plan[]>} | ||
*/ | ||
getPaywall({ productId }?: GetPaywall): Promise<Plan[]>; | ||
/** | ||
* Get a customer | ||
* @returns {Promise<Customer>} | ||
*/ | ||
getCustomer(): Promise<Customer>; | ||
getEntitlements(): Promise<Entitlement[] | never[]>; | ||
/** | ||
* Get a list of entitlements | ||
* @returns {Promise<Entitlement[]>} | ||
*/ | ||
getEntitlements(): Promise<Entitlement[]>; | ||
private withErrorHandling; | ||
} |
@@ -0,9 +1,11 @@ | ||
import { LogConfiguration, LoggerService } from './services/loggerService'; | ||
export declare type ClientConfiguration = { | ||
sdkKey: string; | ||
apiKey: string; | ||
baseUri?: string; | ||
customerId?: string; | ||
entitlementPollingInterval?: number; | ||
logConfiguration?: LogConfiguration; | ||
}; | ||
export declare function validateConfiguration(configuration: ClientConfiguration): void; | ||
export declare function withDefaults(configuration: ClientConfiguration): Required<ClientConfiguration>; | ||
export declare function validateConfiguration(configuration: ClientConfiguration, loggerService: LoggerService): boolean; | ||
export declare function getConfiguration(configuration: ClientConfiguration): Required<ClientConfiguration>; | ||
export declare function ensureCustomerRefIdExists({ customerId }: ClientConfiguration): string; |
@@ -1,6 +0,16 @@ | ||
import { AccessDeniedReason, BillingModel, BillingPeriod, EntitlementResetPeriod, MonthlyAccordingTo, PromotionalEntitlementStatus, SubscriptionStatus, TrialPeriodUnits, WeeklyAccordingTo } from './api/generated/types'; | ||
export { BillingPeriod, BillingModel, ErrorCode, AccessDeniedReason, EntitlementResetPeriod, TrialPeriodUnits, } from './api/generated/types'; | ||
import { BillingModel, BillingPeriod, Currency, PromotionalEntitlementStatus, SubscriptionStatus, TrialPeriodUnits, AccessDeniedReason as ApiAccessDeniedReason } from './api/generated/types'; | ||
export { BillingPeriod, BillingModel, TrialPeriodUnits } from './api/generated/types'; | ||
export declare enum AccessDeniedReason { | ||
InvalidFeatureType = "InvalidFeatureType", | ||
CustomerNotFound = "CustomerNotFound", | ||
FeatureNotFound = "FeatureNotFound", | ||
NoActiveSubscriptions = "NoActiveSubscriptions", | ||
CustomerNotEntitledForFeature = "CustomerNotEntitledForFeature", | ||
RequestedUsageExceedsLimit = "RequestedUsageExceedsLimit", | ||
Unknown = "Unknown" | ||
} | ||
export declare const AccessDeniedReasonMapper: Record<ApiAccessDeniedReason, AccessDeniedReason>; | ||
export declare enum FeatureType { | ||
Boolean = "BOOLEAN", | ||
Number = "NUMBER" | ||
Boolean = "Boolean", | ||
Numeric = "Numeric" | ||
} | ||
@@ -12,58 +22,47 @@ export declare enum MeterType { | ||
} | ||
export declare enum EntitlementResetPeriod { | ||
Daily = "Daily", | ||
Hourly = "Hourly", | ||
Monthly = "Monthly", | ||
Weekly = "Weekly" | ||
} | ||
export declare type EntitlementFeature = { | ||
id: string; | ||
featureType: FeatureType; | ||
displayName: string; | ||
description?: string; | ||
units?: string; | ||
unitsPlural?: string; | ||
meterType?: MeterType.Fluctuating | MeterType.Incremental | MeterType.None; | ||
isMetered?: boolean; | ||
}; | ||
export declare type BaseEntitlement = { | ||
isValid: boolean; | ||
isGranted: boolean; | ||
featureType?: FeatureType; | ||
featureDisplayName?: string; | ||
featureDescription?: string | null; | ||
accessDeniedReason?: AccessDeniedReason | null; | ||
featureId?: string | null; | ||
hasAccess: boolean; | ||
isFallback: boolean; | ||
accessDeniedReason?: AccessDeniedReason; | ||
feature?: EntitlementFeature; | ||
}; | ||
export interface FallbackEntitlement extends BaseEntitlement { | ||
isValid: false; | ||
export declare type BooleanEntitlement = BaseEntitlement; | ||
export interface NumericEntitlement extends BaseEntitlement { | ||
value?: number; | ||
isUnlimited: boolean; | ||
} | ||
export interface InvalidEntitlement extends BaseEntitlement { | ||
isValid: false; | ||
isGranted: false; | ||
accessDeniedReason: AccessDeniedReason.FeatureNotFound | AccessDeniedReason.CustomerNotFound | AccessDeniedReason.Unknown; | ||
} | ||
export interface ValidEntitlement extends BaseEntitlement { | ||
isValid: true; | ||
} | ||
export interface BooleanEntitlement extends ValidEntitlement { | ||
featureType: FeatureType.Boolean; | ||
} | ||
export interface NumberEntitlement extends ValidEntitlement { | ||
featureType: FeatureType.Number; | ||
usageLimit: number; | ||
featureUnits?: string; | ||
featureUnitsPlural?: string; | ||
hasUnlimitedUsage: boolean; | ||
} | ||
export interface MeteredEntitlement extends NumberEntitlement { | ||
featureType: FeatureType.Number; | ||
meterType: MeterType.Fluctuating | MeterType.Incremental | MeterType.None; | ||
export declare type ResetSettings = { | ||
nextResetDate: Date; | ||
resetPeriod: EntitlementResetPeriod; | ||
}; | ||
export interface MeteredEntitlement extends BaseEntitlement { | ||
usageLimit?: number; | ||
isUnlimited: boolean; | ||
currentUsage: number; | ||
requestedUsage: number | null; | ||
resetPeriod?: EntitlementResetPeriod | null; | ||
nextResetDate?: any | null; | ||
resetPeriodConfiguration?: { | ||
__typename: 'MonthlyResetPeriodConfig'; | ||
monthlyAccordingTo?: MonthlyAccordingTo | null | undefined; | ||
} | { | ||
__typename: 'WeeklyResetPeriodConfig'; | ||
weeklyAccordingTo?: WeeklyAccordingTo | null | undefined; | ||
} | null; | ||
requestedUsage: number; | ||
resetSettings?: ResetSettings; | ||
} | ||
export declare type Entitlement = FallbackEntitlement | InvalidEntitlement | BooleanEntitlement | NumberEntitlement | MeteredEntitlement; | ||
export declare const INVALID_ENTITLEMENT: InvalidEntitlement; | ||
export declare type Entitlement = BooleanEntitlement | NumericEntitlement | MeteredEntitlement; | ||
export declare const BOOLEAN_DEFAULT_FALLBACK_ENTITLEMENT: BooleanEntitlement; | ||
export declare const NUMERIC_DEFAULT_FALLBACK_ENTITLEMENT: NumericEntitlement; | ||
export declare const METERED_DEFAULT_FALLBACK_ENTITLEMENT: MeteredEntitlement; | ||
export declare type PackageEntitlement = { | ||
usageLimit: number; | ||
featureType: FeatureType; | ||
featureMeterType?: MeterType | null; | ||
featureUnits?: string | null; | ||
featureUnitsPlural?: string | null; | ||
featureDisplayName: string; | ||
featureDescription?: string | null; | ||
featureId: string; | ||
feature: EntitlementFeature; | ||
hasUnlimitedUsage?: boolean | null; | ||
@@ -74,23 +73,17 @@ resetPeriod?: EntitlementResetPeriod | null; | ||
usageLimit: number; | ||
featureType: FeatureType; | ||
featureMeterType?: MeterType | null; | ||
featureUnits?: string | null; | ||
featureUnitsPlural?: string | null; | ||
featureDisplayName: string; | ||
featureDescription?: string | null; | ||
featureId: string; | ||
feature: EntitlementFeature; | ||
hasUnlimitedUsage?: boolean | null; | ||
resetPeriod?: EntitlementResetPeriod | null; | ||
status: PromotionalEntitlementStatus; | ||
endDate?: Date; | ||
expiresAt?: Date; | ||
hasExpirationDate: boolean; | ||
isVisible: boolean; | ||
}; | ||
export declare type Price = { | ||
billingModel: BillingModel; | ||
pricingModel: BillingModel; | ||
billingPeriod: BillingPeriod; | ||
amount: number; | ||
currency: string; | ||
currency: Currency; | ||
feature?: { | ||
featureUnits?: string | null | undefined; | ||
featureUnitsPlural?: string | null | undefined; | ||
units?: string | null | undefined; | ||
unitsPlural?: string | null | undefined; | ||
displayName: string; | ||
@@ -111,3 +104,3 @@ } | null; | ||
inheritedEntitlements: PackageEntitlement[]; | ||
prices: Price[]; | ||
pricePoints: Price[]; | ||
defaultTrialConfig?: DefaultTrialConfig | null; | ||
@@ -125,12 +118,43 @@ compatibleAddons: Addon[]; | ||
}; | ||
export declare type EntitlementOptions = { | ||
export declare type GetBooleanEntitlement = { | ||
featureId: string; | ||
options?: BooleanEntitlementOptions; | ||
}; | ||
export declare type GetNumericEntitlement = { | ||
featureId: string; | ||
options?: NumericEntitlementOptions; | ||
}; | ||
export declare type GetMeteredEntitlement = { | ||
featureId: string; | ||
options?: MeteredEntitlementOptions; | ||
}; | ||
export declare type GetPaywall = { | ||
productId?: string; | ||
}; | ||
export declare type BooleanEntitlementFallback = { | ||
hasAccess: boolean; | ||
}; | ||
export declare type BooleanEntitlementOptions = { | ||
shouldTrack?: boolean; | ||
fallback?: BooleanEntitlementFallback; | ||
}; | ||
export declare type NumericEntitlementFallback = { | ||
hasAccess: boolean; | ||
value?: number; | ||
isUnlimited?: boolean; | ||
}; | ||
export declare type NumericEntitlementOptions = { | ||
shouldTrack?: boolean; | ||
fallback?: NumericEntitlementFallback; | ||
}; | ||
export declare type MeteredEntitlementFallback = { | ||
hasAccess: boolean; | ||
usageLimit?: number; | ||
isUnlimited?: boolean; | ||
}; | ||
export declare type MeteredEntitlementOptions = { | ||
requestedUsage?: number; | ||
shouldTrack?: boolean; | ||
fallbackGrantedValue?: boolean; | ||
fallback?: MeteredEntitlementFallback; | ||
}; | ||
export declare type FetchEntitlement = { | ||
customerId: string; | ||
featureId: string; | ||
options?: EntitlementOptions; | ||
}; | ||
export declare type Addon = { | ||
@@ -137,0 +161,0 @@ id: string; |
@@ -1,13 +0,7 @@ | ||
import { EntitlementResetPeriod, FeatureType, MeterType } from '../models'; | ||
import { EntitlementFeature, EntitlementResetPeriod } from '../models'; | ||
import { ResetPeriodConfigurationFragment } from '../api/generated/types'; | ||
export interface CalculatedEntitlement { | ||
featureId: string; | ||
featureType: FeatureType; | ||
usageLimit?: number | null; | ||
featureUnits?: string; | ||
featureUnitsPlural?: string; | ||
featureDisplayName?: string; | ||
featureDescription?: string | null; | ||
hasUnlimitedUsage: boolean; | ||
meterType: MeterType.Fluctuating | MeterType.Incremental | MeterType.None; | ||
feature?: EntitlementFeature; | ||
} | ||
@@ -14,0 +8,0 @@ export interface EntitlementUsage { |
import CachedEntitlement from './cachedEntitlement'; | ||
import { AccessDeniedReason } from '../api/generated/types'; | ||
import { AccessDeniedReason } from '../models'; | ||
export declare class EntitlementDecisionService { | ||
@@ -7,4 +7,4 @@ static decideEntitlementPolicy(entitlement?: CachedEntitlement | null, requestUsage?: number): Decision; | ||
export interface Decision { | ||
readonly isGranted: boolean; | ||
readonly hasAccess: boolean; | ||
readonly accessDeniedReason?: AccessDeniedReason; | ||
} |
@@ -0,7 +1,7 @@ | ||
import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core'; | ||
import { EntitlementFragment } from '../api/generated/types'; | ||
import { BooleanEntitlement, MeteredEntitlement, MeteredEntitlementOptions, NumericEntitlement } from '../models'; | ||
import CachedEntitlement from './cachedEntitlement'; | ||
import { CacheService } from './cacheService'; | ||
import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core'; | ||
import { Entitlement, InvalidEntitlement } from '../models'; | ||
import { Decision } from './entitlementDecisionService'; | ||
import CachedEntitlement from './cachedEntitlement'; | ||
import { EntitlementFragment } from '../api/generated/types'; | ||
export declare class EntitlementsService { | ||
@@ -17,7 +17,9 @@ private readonly customerId; | ||
refresh(): Promise<void>; | ||
getEntitlement<T extends Entitlement>(featureRefId: string, requestedUsage?: number): T | InvalidEntitlement; | ||
getBooleanEntitlement(featureId: string): BooleanEntitlement; | ||
getNumericEntitlement(featureId: string): NumericEntitlement; | ||
getMeteredEntitlement(featureId: string, options?: MeteredEntitlementOptions): MeteredEntitlement; | ||
loadEntitlements(): Promise<void>; | ||
private doLoadEntitlements; | ||
protected handleFetchedEntitlements(entitlements: Array<EntitlementFragment>): void; | ||
getEntitlements(): Promise<Entitlement[]>; | ||
private loadEntitlementsFromRemote; | ||
protected storeFetchedEntitlementsInCache(entitlements: EntitlementFragment[]): void; | ||
getEntitlements(): Promise<import("../models").BaseEntitlement[]>; | ||
stopPolling(): void; | ||
@@ -24,0 +26,0 @@ } |
@@ -1,16 +0,18 @@ | ||
import { CustomerFragment, EntitlementFragment, GetPlansQuery, SlimEntitlementFragment } from '../api/generated/types'; | ||
import { Customer, Entitlement, Plan } from '../models'; | ||
import { CustomerFragment, EntitlementFragment, GetPlansQuery, FeatureType as ApiFeatureType, EntitlementResetPeriod as ApiEntitlementResetPeriod } from '../api/generated/types'; | ||
import { BooleanEntitlement, Customer, FeatureType, MeteredEntitlement, NumericEntitlement, Plan, EntitlementResetPeriod } from '../models'; | ||
import CachedEntitlement from '../services/cachedEntitlement'; | ||
import { Decision } from '../services/entitlementDecisionService'; | ||
export declare class ModelMapper { | ||
mapEntitlementByDecision: (decision: Decision, featureId: string, entitlement: CachedEntitlement, requestedUsage?: number | undefined) => Entitlement; | ||
mapSlimEntitlement(entitlement: SlimEntitlementFragment): Entitlement; | ||
mapFullEntitlementByDecision(entitlement: CachedEntitlement, decision: Decision, customerId: string, requestedUsage?: number): Entitlement; | ||
mapFullEntitlement(fullEntitlement: EntitlementFragment): Entitlement; | ||
mapBooleanEntitlement(entitlement: CachedEntitlement, decision: Decision): BooleanEntitlement; | ||
mapNumericEntitlement(entitlement: CachedEntitlement, decision: Decision): NumericEntitlement; | ||
mapMeteredEntitlement(entitlement: CachedEntitlement, decision: Decision, requestedUsage?: number): MeteredEntitlement; | ||
mapEntitlement(entitlement: CachedEntitlement, decision: Decision, requestedUsage?: number): import("../models").BaseEntitlement; | ||
mapFeatureType(featureType: ApiFeatureType): FeatureType; | ||
mapEntitlementResetPeriod(resetPeriod: ApiEntitlementResetPeriod): EntitlementResetPeriod; | ||
mapCachedEntitlement(entitlement: EntitlementFragment, currentUsage?: number, nextResetDate?: number | null): CachedEntitlement; | ||
mapCachedEntitlements(updatedEntitlements: EntitlementFragment[]): Map<string, CachedEntitlement>; | ||
mapPlans(resultData: GetPlansQuery): Plan[]; | ||
mapCustomer(customer: CustomerFragment): Customer; | ||
private mapPrice; | ||
private mapPlan; | ||
mapCustomer(customer: CustomerFragment): Customer; | ||
private mapPackageEntitlement; | ||
@@ -17,0 +19,0 @@ private mapPromotionalEntitlement; |
{ | ||
"name": "@stigg/js-client-sdk", | ||
"version": "0.22.2", | ||
"version": "0.23.0", | ||
"description": "Stigg client-side SDK for Browser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
23
4.55%2118117
-1.55%3437
-17.14%