Skip to content

Commit c6666c4

Browse files
Merge pull request #157 from frontegg/FR-12827-align-api-with-justification
fix(entitlements): rename reason to justification
2 parents a4f2187 + a437b84 commit c6666c4

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ The result of those queries has the following structure:
245245
```typescript
246246
type IsEntitledResult = {
247247
result: boolean,
248-
reason?: string
248+
justficiation?: string
249249
}
250250
```
251-
When `result: true`, then `reason` is not given.
251+
When `result: true`, then `justficiation` is not given.
252252
253253
#### Closing the client
254254
To gracefully close the client:

src/clients/entitlements/entitlements.user-scoped.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { IUser, IUserAccessToken, IUserApiToken, TEntityWithRoles, tokenTypes } from '../identity/types';
77
import { mock, mockReset } from 'jest-mock-extended';
88
import { EntitlementsCache, NO_EXPIRE } from './storage/types';
9-
import { EntitlementReasons } from './types';
9+
import { EntitlementJustifications } from './types';
1010
import SpyInstance = jest.SpyInstance;
1111

1212
const userApiTokenBase: Pick<
@@ -136,14 +136,14 @@ describe(EntitlementsUserScoped.name, () => {
136136
});
137137
});
138138

139-
it('after the expiry time, then access is rejected and reason is BUNDLE_EXPIRED.', async () => {
139+
it('after the expiry time, then access is rejected and justification is BUNDLE_EXPIRED.', async () => {
140140
// given
141141
jest.useFakeTimers({ now: expiryTime + 1000 });
142142

143143
// when & then
144144
await expect(cut.isEntitledTo(input as IsEntitledToFeatureInput)).resolves.toEqual({
145145
result: false,
146-
reason: EntitlementReasons.BUNDLE_EXPIRED,
146+
justification: EntitlementJustifications.BUNDLE_EXPIRED,
147147
});
148148
});
149149
});
@@ -160,10 +160,10 @@ describe(EntitlementsUserScoped.name, () => {
160160
await expect(cut.isEntitledTo({ permissionKey: 'foo' })).resolves.toEqual({ result: true });
161161
});
162162

163-
it('when isEntitledTo({ permission: "bar" }) is called, then access is rejected with reason MISSING_PERMISSION.', async () => {
163+
it('when isEntitledTo({ permission: "bar" }) is called, then access is rejected with justification MISSING_PERMISSION.', async () => {
164164
await expect(cut.isEntitledTo({ permissionKey: 'bar' })).resolves.toEqual({
165165
result: false,
166-
reason: EntitlementReasons.MISSING_PERMISSION,
166+
justification: EntitlementJustifications.MISSING_PERMISSION,
167167
});
168168
});
169169
});

src/clients/entitlements/entitlements.user-scoped.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EntitlementReasons, IsEntitledResult } from './types';
1+
import { EntitlementJustifications, IsEntitledResult } from './types';
22
import { IEntityWithRoles, Permission, TEntity, tokenTypes, TUserEntity } from '../identity/types';
33
import { EntitlementsCache, NO_EXPIRE } from './storage/types';
44
import { pickExpTimestamp } from './storage/exp-time.utils';
@@ -48,7 +48,7 @@ export class EntitlementsUserScoped<T extends TEntity = TEntity> {
4848
if (expTime === undefined) {
4949
return {
5050
result: false,
51-
reason: EntitlementReasons.MISSING_FEATURE,
51+
justification: EntitlementJustifications.MISSING_FEATURE,
5252
};
5353
} else if (expTime === NO_EXPIRE || expTime > new Date().getTime()) {
5454
return {
@@ -57,7 +57,7 @@ export class EntitlementsUserScoped<T extends TEntity = TEntity> {
5757
} else {
5858
return {
5959
result: false,
60-
reason: EntitlementReasons.BUNDLE_EXPIRED,
60+
justification: EntitlementJustifications.BUNDLE_EXPIRED,
6161
};
6262
}
6363
}
@@ -66,7 +66,7 @@ export class EntitlementsUserScoped<T extends TEntity = TEntity> {
6666
if (this.permissions === undefined || this.permissions.indexOf(permissionKey) < 0) {
6767
return {
6868
result: false,
69-
reason: EntitlementReasons.MISSING_PERMISSION,
69+
justification: EntitlementJustifications.MISSING_PERMISSION,
7070
};
7171
}
7272

@@ -84,14 +84,14 @@ export class EntitlementsUserScoped<T extends TEntity = TEntity> {
8484
return {
8585
result: true,
8686
};
87-
} else if (isEntitledToFeatureResult.reason === EntitlementReasons.BUNDLE_EXPIRED) {
87+
} else if (isEntitledToFeatureResult.justification === EntitlementJustifications.BUNDLE_EXPIRED) {
8888
hasExpired = true;
8989
}
9090
}
9191

9292
return {
9393
result: false,
94-
reason: hasExpired ? EntitlementReasons.BUNDLE_EXPIRED : EntitlementReasons.MISSING_FEATURE,
94+
justification: hasExpired ? EntitlementJustifications.BUNDLE_EXPIRED : EntitlementJustifications.MISSING_FEATURE,
9595
};
9696
}
9797

src/clients/entitlements/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { RetryOptions } from '../../utils';
22
import { Permission } from '../identity/types';
33

4-
export enum EntitlementReasons {
4+
export enum EntitlementJustifications {
55
MISSING_FEATURE = 'missing-feature',
66
MISSING_PERMISSION = 'missing-permission',
77
BUNDLE_EXPIRED = 'bundle-expired',
88
}
99

1010
export interface IsEntitledResult {
1111
result: boolean;
12-
reason?: EntitlementReasons;
12+
justification?: EntitlementJustifications;
1313
}
1414

1515
export type FeatureKey = string;

0 commit comments

Comments
 (0)