@stigg/js-client-sdk 0.22.2 → 0.25.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/models.d.ts CHANGED
@@ -1,96 +1,92 @@
1
- import { AccessDeniedReason, BillingModel, BillingPeriod, EntitlementResetPeriod, MonthlyAccordingTo, PromotionalEntitlementStatus, SubscriptionStatus, TrialPeriodUnits, WeeklyAccordingTo } from './api/generated/types';
2
- export { BillingPeriod, BillingModel, ErrorCode, AccessDeniedReason, EntitlementResetPeriod, TrialPeriodUnits, } from './api/generated/types';
1
+ import { BillingModel, BillingPeriod, Currency, PromotionalEntitlementStatus, SubscriptionStatus, TrialPeriodUnits } from './api/generated/types';
2
+ export { SubscriptionStatus, PromotionalEntitlementStatus, Currency, BillingPeriod, BillingModel, TrialPeriodUnits, } from './api/generated/types';
3
+ export declare enum AccessDeniedReason {
4
+ InvalidFeatureType = "InvalidFeatureType",
5
+ CustomerNotFound = "CustomerNotFound",
6
+ FeatureNotFound = "FeatureNotFound",
7
+ NoActiveSubscriptions = "NoActiveSubscriptions",
8
+ CustomerNotEntitledForFeature = "CustomerNotEntitledForFeature",
9
+ RequestedUsageExceedsLimit = "RequestedUsageExceedsLimit",
10
+ Unknown = "Unknown"
11
+ }
3
12
  export declare enum FeatureType {
4
- Boolean = "BOOLEAN",
5
- Number = "NUMBER"
13
+ Boolean = "Boolean",
14
+ Numeric = "Numeric"
6
15
  }
7
16
  export declare enum MeterType {
8
17
  Fluctuating = "Fluctuating",
9
18
  Incremental = "Incremental",
10
19
  None = "None"
11
20
  }
12
- export declare type BaseEntitlement = {
13
- isValid: boolean;
14
- isGranted: boolean;
15
- featureType?: FeatureType;
16
- featureDisplayName?: string;
17
- featureDescription?: string | null;
18
- accessDeniedReason?: AccessDeniedReason | null;
19
- featureId?: string | null;
20
- };
21
- export interface FallbackEntitlement extends BaseEntitlement {
22
- isValid: false;
23
- }
24
- export interface InvalidEntitlement extends BaseEntitlement {
25
- isValid: false;
26
- isGranted: false;
27
- accessDeniedReason: AccessDeniedReason.FeatureNotFound | AccessDeniedReason.CustomerNotFound | AccessDeniedReason.Unknown;
21
+ export declare enum EntitlementResetPeriod {
22
+ Daily = "Daily",
23
+ Hourly = "Hourly",
24
+ Monthly = "Monthly",
25
+ Weekly = "Weekly"
28
26
  }
29
- export interface ValidEntitlement extends BaseEntitlement {
30
- isValid: true;
31
- }
32
- export interface BooleanEntitlement extends ValidEntitlement {
33
- featureType: FeatureType.Boolean;
27
+ export declare type EntitlementFeature = {
28
+ id: string;
29
+ featureType: FeatureType;
30
+ displayName: string;
31
+ description?: string;
32
+ units?: string;
33
+ unitsPlural?: string;
34
+ meterType?: MeterType.Fluctuating | MeterType.Incremental | MeterType.None;
35
+ isMetered?: boolean;
36
+ };
37
+ export declare type BaseEntitlement = {
38
+ hasAccess: boolean;
39
+ isFallback: boolean;
40
+ accessDeniedReason?: AccessDeniedReason;
41
+ feature?: EntitlementFeature;
42
+ };
43
+ export interface BooleanEntitlement extends BaseEntitlement {
34
44
  }
35
- export interface NumberEntitlement extends ValidEntitlement {
36
- featureType: FeatureType.Number;
37
- usageLimit: number;
38
- featureUnits?: string;
39
- featureUnitsPlural?: string;
40
- hasUnlimitedUsage: boolean;
45
+ export interface NumericEntitlement extends BaseEntitlement {
46
+ value?: number;
47
+ isUnlimited: boolean;
41
48
  }
42
- export interface MeteredEntitlement extends NumberEntitlement {
43
- featureType: FeatureType.Number;
44
- meterType: MeterType.Fluctuating | MeterType.Incremental | MeterType.None;
49
+ export declare type ResetSettings = {
50
+ nextResetDate: Date;
51
+ resetPeriod: EntitlementResetPeriod;
52
+ };
53
+ export interface MeteredEntitlement extends BaseEntitlement {
54
+ usageLimit?: number;
55
+ isUnlimited: boolean;
45
56
  currentUsage: number;
46
- requestedUsage: number | null;
47
- resetPeriod?: EntitlementResetPeriod | null;
48
- nextResetDate?: any | null;
49
- resetPeriodConfiguration?: {
50
- __typename: 'MonthlyResetPeriodConfig';
51
- monthlyAccordingTo?: MonthlyAccordingTo | null | undefined;
52
- } | {
53
- __typename: 'WeeklyResetPeriodConfig';
54
- weeklyAccordingTo?: WeeklyAccordingTo | null | undefined;
55
- } | null;
57
+ requestedUsage: number;
58
+ resetSettings?: ResetSettings;
56
59
  }
57
- export declare type Entitlement = FallbackEntitlement | InvalidEntitlement | BooleanEntitlement | NumberEntitlement | MeteredEntitlement;
58
- export declare const INVALID_ENTITLEMENT: InvalidEntitlement;
60
+ export declare type Entitlement = BooleanEntitlement | NumericEntitlement | MeteredEntitlement;
61
+ /** @internal */
62
+ export declare const BOOLEAN_DEFAULT_FALLBACK_ENTITLEMENT: BooleanEntitlement;
63
+ /** @internal */
64
+ export declare const NUMERIC_DEFAULT_FALLBACK_ENTITLEMENT: NumericEntitlement;
65
+ /** @internal */
66
+ export declare const METERED_DEFAULT_FALLBACK_ENTITLEMENT: MeteredEntitlement;
59
67
  export declare type PackageEntitlement = {
60
68
  usageLimit: number;
61
- featureType: FeatureType;
62
- featureMeterType?: MeterType | null;
63
- featureUnits?: string | null;
64
- featureUnitsPlural?: string | null;
65
- featureDisplayName: string;
66
- featureDescription?: string | null;
67
- featureId: string;
69
+ feature: EntitlementFeature;
68
70
  hasUnlimitedUsage?: boolean | null;
69
71
  resetPeriod?: EntitlementResetPeriod | null;
70
72
  };
71
73
  export declare type PromotionalEntitlement = {
72
74
  usageLimit: number;
73
- featureType: FeatureType;
74
- featureMeterType?: MeterType | null;
75
- featureUnits?: string | null;
76
- featureUnitsPlural?: string | null;
77
- featureDisplayName: string;
78
- featureDescription?: string | null;
79
- featureId: string;
75
+ feature: EntitlementFeature;
80
76
  hasUnlimitedUsage?: boolean | null;
81
- resetPeriod?: EntitlementResetPeriod | null;
82
77
  status: PromotionalEntitlementStatus;
83
- endDate?: Date;
78
+ expiresAt?: Date;
79
+ hasExpirationDate: boolean;
84
80
  isVisible: boolean;
85
81
  };
86
82
  export declare type Price = {
87
- billingModel: BillingModel;
83
+ pricingModel: BillingModel;
88
84
  billingPeriod: BillingPeriod;
89
85
  amount: number;
90
- currency: string;
86
+ currency: Currency;
91
87
  feature?: {
92
- featureUnits?: string | null | undefined;
93
- featureUnitsPlural?: string | null | undefined;
88
+ units?: string | null | undefined;
89
+ unitsPlural?: string | null | undefined;
94
90
  displayName: string;
95
91
  } | null;
96
92
  };
@@ -106,7 +102,7 @@ export declare type Plan = {
106
102
  basePlan?: BasePlan;
107
103
  entitlements: PackageEntitlement[];
108
104
  inheritedEntitlements: PackageEntitlement[];
109
- prices: Price[];
105
+ pricePoints: Price[];
110
106
  defaultTrialConfig?: DefaultTrialConfig | null;
111
107
  compatibleAddons: Addon[];
112
108
  product: Product;
@@ -119,15 +115,46 @@ export declare type DefaultTrialConfig = {
119
115
  duration: number;
120
116
  units: TrialPeriodUnits;
121
117
  };
122
- export declare type EntitlementOptions = {
123
- requestedUsage?: number;
124
- shouldTrack?: boolean;
125
- fallbackGrantedValue?: boolean;
118
+ export declare type GetBooleanEntitlement = {
119
+ featureId: string;
120
+ options?: BooleanEntitlementOptions;
126
121
  };
127
- export declare type FetchEntitlement = {
128
- customerId: string;
122
+ export declare type GetNumericEntitlement = {
129
123
  featureId: string;
130
- options?: EntitlementOptions;
124
+ options?: NumericEntitlementOptions;
125
+ };
126
+ export declare type GetMeteredEntitlement = {
127
+ featureId: string;
128
+ options?: MeteredEntitlementOptions;
129
+ };
130
+ export declare type GetPaywall = {
131
+ productId?: string;
132
+ };
133
+ export declare type BooleanEntitlementFallback = {
134
+ hasAccess: boolean;
135
+ };
136
+ export declare type BooleanEntitlementOptions = {
137
+ shouldTrack?: boolean;
138
+ fallback?: BooleanEntitlementFallback;
139
+ };
140
+ export declare type NumericEntitlementFallback = {
141
+ hasAccess: boolean;
142
+ value?: number;
143
+ isUnlimited?: boolean;
144
+ };
145
+ export declare type NumericEntitlementOptions = {
146
+ shouldTrack?: boolean;
147
+ fallback?: NumericEntitlementFallback;
148
+ };
149
+ export declare type MeteredEntitlementFallback = {
150
+ hasAccess: boolean;
151
+ usageLimit?: number;
152
+ isUnlimited?: boolean;
153
+ };
154
+ export declare type MeteredEntitlementOptions = {
155
+ requestedUsage?: number;
156
+ shouldTrack?: boolean;
157
+ fallback?: MeteredEntitlementFallback;
131
158
  };
132
159
  export declare type Addon = {
133
160
  id: string;
@@ -162,7 +189,8 @@ export declare type Customer = {
162
189
  getActivePromotionalEntitlements(): PromotionalEntitlement[];
163
190
  getActiveTrials(): Subscription[];
164
191
  };
165
- declare type CustomerState = Omit<Customer, 'getActiveSubscriptions' | 'getActivePromotionalEntitlements' | 'getActiveTrials'>;
192
+ export declare type CustomerState = Omit<Customer, 'getActiveSubscriptions' | 'getActivePromotionalEntitlements' | 'getActiveTrials'>;
193
+ /** @hidden */
166
194
  export declare class CustomerModel implements Customer {
167
195
  id: string;
168
196
  createdAt: Date;
@@ -1,15 +1,9 @@
1
- import { EntitlementResetPeriod, FeatureType, MeterType } from '../models';
1
+ import { EntitlementFeature, EntitlementResetPeriod } from '../models';
2
2
  import { ResetPeriodConfigurationFragment } from '../api/generated/types';
3
3
  export interface CalculatedEntitlement {
4
- featureId: string;
5
- featureType: FeatureType;
6
4
  usageLimit?: number | null;
7
- featureUnits?: string;
8
- featureUnitsPlural?: string;
9
- featureDisplayName?: string;
10
- featureDescription?: string | null;
11
5
  hasUnlimitedUsage: boolean;
12
- meterType: MeterType.Fluctuating | MeterType.Incremental | MeterType.None;
6
+ feature?: EntitlementFeature;
13
7
  }
14
8
  export interface EntitlementUsage {
15
9
  currentUsage: number;
@@ -1,9 +1,9 @@
1
1
  import CachedEntitlement from './cachedEntitlement';
2
- import { AccessDeniedReason } from '../api/generated/types';
2
+ import { AccessDeniedReason } from '../models';
3
3
  export declare class EntitlementDecisionService {
4
4
  static decideEntitlementPolicy(entitlement?: CachedEntitlement | null, requestUsage?: number): Decision;
5
5
  }
6
6
  export interface Decision {
7
- readonly isGranted: boolean;
7
+ readonly hasAccess: boolean;
8
8
  readonly accessDeniedReason?: AccessDeniedReason;
9
9
  }
@@ -1,9 +1,9 @@
1
- import { CacheService } from './cacheService';
2
1
  import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core';
3
- import { Entitlement, InvalidEntitlement } from '../models';
4
- import { Decision } from './entitlementDecisionService';
5
- import CachedEntitlement from './cachedEntitlement';
6
2
  import { EntitlementFragment } from '../api/generated/types';
3
+ import { BooleanEntitlement, MeteredEntitlement, MeteredEntitlementOptions, NumericEntitlement } from '../models';
4
+ import CachedEntitlement from './cachedEntitlement';
5
+ import { CacheService } from './cacheService';
6
+ import { Decision } from './entitlementDecisionService';
7
7
  export declare class EntitlementsService {
8
8
  private readonly customerId;
9
9
  private readonly cacheService;
@@ -14,11 +14,13 @@ export declare class EntitlementsService {
14
14
  constructor(customerId: string, cacheService: CacheService, client: ApolloClient<NormalizedCacheObject>);
15
15
  startPolling(interval: number): void;
16
16
  refresh(): Promise<void>;
17
- getEntitlement<T extends Entitlement>(featureRefId: string, requestedUsage?: number): T | InvalidEntitlement;
17
+ getBooleanEntitlement(featureId: string): BooleanEntitlement;
18
+ getNumericEntitlement(featureId: string): NumericEntitlement;
19
+ getMeteredEntitlement(featureId: string, options?: MeteredEntitlementOptions): MeteredEntitlement;
18
20
  loadEntitlements(): Promise<void>;
19
- private doLoadEntitlements;
20
- protected handleFetchedEntitlements(entitlements: Array<EntitlementFragment>): void;
21
- getEntitlements(): Promise<Entitlement[]>;
21
+ private loadEntitlementsFromRemote;
22
+ protected storeFetchedEntitlementsInCache(entitlements: EntitlementFragment[]): void;
23
+ getEntitlements(): Promise<BooleanEntitlement[]>;
22
24
  stopPolling(): void;
23
25
  }
24
26
  export declare type GetEntitlementResult = {
@@ -0,0 +1,21 @@
1
+ export interface Logger {
2
+ log: (message: string, object?: Record<string, string>) => void;
3
+ error: (message: string, error?: Record<string, string>) => void;
4
+ }
5
+ export interface LogConfiguration {
6
+ logger: Logger;
7
+ logLevel: LogLevel;
8
+ }
9
+ export declare enum LogLevel {
10
+ ALL = "ALL",
11
+ NONE = "NONE",
12
+ LOG = "LOG",
13
+ ERROR = "ERROR"
14
+ }
15
+ export declare class LoggerService implements Logger {
16
+ private readonly logger;
17
+ private readonly logLevel;
18
+ constructor(logger: Logger, logLevel: LogLevel);
19
+ error(message: string, error?: Record<string, string>): void;
20
+ log(message: string, object?: Record<string, string>): void;
21
+ }
@@ -1,18 +1,20 @@
1
- import { CustomerFragment, EntitlementFragment, GetPlansQuery, SlimEntitlementFragment } from '../api/generated/types';
2
- import { Customer, Entitlement, Plan } from '../models';
1
+ import { CustomerFragment, EntitlementFragment, GetPlansQuery, FeatureType as ApiFeatureType, EntitlementResetPeriod as ApiEntitlementResetPeriod } from '../api/generated/types';
2
+ import { BooleanEntitlement, Customer, FeatureType, MeteredEntitlement, NumericEntitlement, Plan, EntitlementResetPeriod } from '../models';
3
3
  import CachedEntitlement from '../services/cachedEntitlement';
4
4
  import { Decision } from '../services/entitlementDecisionService';
5
5
  export declare class ModelMapper {
6
- mapEntitlementByDecision: (decision: Decision, featureId: string, entitlement: CachedEntitlement, requestedUsage?: number | undefined) => Entitlement;
7
- mapSlimEntitlement(entitlement: SlimEntitlementFragment): Entitlement;
8
- mapFullEntitlementByDecision(entitlement: CachedEntitlement, decision: Decision, customerId: string, requestedUsage?: number): Entitlement;
9
- mapFullEntitlement(fullEntitlement: EntitlementFragment): Entitlement;
6
+ mapBooleanEntitlement(entitlement: CachedEntitlement, decision: Decision): BooleanEntitlement;
7
+ mapNumericEntitlement(entitlement: CachedEntitlement, decision: Decision): NumericEntitlement;
8
+ mapMeteredEntitlement(entitlement: CachedEntitlement, decision: Decision, requestedUsage?: number): MeteredEntitlement;
9
+ mapEntitlement(entitlement: CachedEntitlement, decision: Decision, requestedUsage?: number): BooleanEntitlement;
10
+ mapFeatureType(featureType: ApiFeatureType): FeatureType;
11
+ mapEntitlementResetPeriod(resetPeriod: ApiEntitlementResetPeriod): EntitlementResetPeriod;
10
12
  mapCachedEntitlement(entitlement: EntitlementFragment, currentUsage?: number, nextResetDate?: number | null): CachedEntitlement;
11
13
  mapCachedEntitlements(updatedEntitlements: EntitlementFragment[]): Map<string, CachedEntitlement>;
12
14
  mapPlans(resultData: GetPlansQuery): Plan[];
15
+ mapCustomer(customer: CustomerFragment): Customer;
13
16
  private mapPrice;
14
17
  private mapPlan;
15
- mapCustomer(customer: CustomerFragment): Customer;
16
18
  private mapPackageEntitlement;
17
19
  private mapPromotionalEntitlement;
18
20
  private mapSubscription;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stigg/js-client-sdk",
3
- "version": "0.22.2",
3
+ "version": "0.25.0",
4
4
  "description": "Stigg client-side SDK for Browser",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -19,16 +19,17 @@
19
19
  "test": "jest",
20
20
  "test:watch": "jest --watch",
21
21
  "test:cov": "jest --coverage",
22
- "prepare": "husky install"
22
+ "prepare": "husky install",
23
+ "docs": "typedoc"
23
24
  },
24
25
  "files": [
25
26
  "dist/**/*"
26
27
  ],
27
28
  "dependencies": {
28
29
  "@apollo/client": "^3.4.17",
30
+ "cross-fetch": "^3.1.4",
29
31
  "graphql": "^16.0.1",
30
32
  "husky": "^7.0.4",
31
- "cross-fetch": "^3.1.4",
32
33
  "lint-staged": "^12.0.2",
33
34
  "lodash": "^4.17.21"
34
35
  },
@@ -49,12 +50,14 @@
49
50
  "eslint-plugin-prettier": "^4.0.0",
50
51
  "jest": "^27.3.1",
51
52
  "jest-fetch-mock": "^3.0.3",
53
+ "msw": "^0.35.0",
52
54
  "npm-run-all": "^4.1.5",
53
55
  "prettier": "^2.4.1",
54
56
  "ts-jest": "^27.0.7",
55
57
  "ts-loader": "^9.2.6",
58
+ "typedoc": "^0.22.13",
59
+ "typedoc-plugin-rename-defaults": "^0.4.0",
56
60
  "typescript": "^4.5.3",
57
- "msw": "^0.35.0",
58
61
  "webpack": "^5.64.1",
59
62
  "webpack-cli": "^4.9.1",
60
63
  "webpack-dev-server": "^4.5.0"