@clxmedia/xperience-rights-client 1.0.11 → 1.1.1
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 +2 -0
- package/dist/client.js +93 -26
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CLiQUserLocator, XperienceAbility, XperienceRightsData, XperienceScopes } from '@clxmedia/types/core/auth';
|
|
2
|
+
import { FeatureFlagStrategyDefinition } from '@clxmedia/types/core/features';
|
|
2
3
|
export type OdooRole = {
|
|
3
4
|
id: number;
|
|
4
5
|
slug: string;
|
|
@@ -19,6 +20,7 @@ export declare const FRIENDLY_SCOPE_NAMES: {
|
|
|
19
20
|
export declare class XperienceRightsClient {
|
|
20
21
|
static findAbility(data: XperienceRightsData, scope: XperienceScopes, qualifier?: number): XperienceAbility;
|
|
21
22
|
static cliqLocatorDescription(locator: CLiQUserLocator | null, long?: boolean): string | null;
|
|
23
|
+
static featureFlagEnabled(data: XperienceRightsData, strategies: FeatureFlagStrategyDefinition[], qualifier?: number): boolean;
|
|
22
24
|
static isGroupMember(data: XperienceRightsData, group: string, qualifier?: number): boolean;
|
|
23
25
|
static abilityValue(ability: XperienceAbility): number;
|
|
24
26
|
static compareAbilities(a: XperienceAbility, b: XperienceAbility, comparison?: 'enough' | 'better'): boolean;
|
package/dist/client.js
CHANGED
|
@@ -2,30 +2,62 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.XperienceRightsClient = exports.FRIENDLY_SCOPE_NAMES = exports.CLIQ_ROLES = exports.CLIQ_GROUPS = exports.ODOO_ROLES = void 0;
|
|
4
4
|
exports.ODOO_ROLES = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'
|
|
5
|
+
proofing_contact: {
|
|
6
|
+
id: 2,
|
|
7
|
+
name: 'Proofing Contact',
|
|
8
|
+
slug: 'proofing_contact',
|
|
9
|
+
},
|
|
10
|
+
reporting_contact: {
|
|
11
|
+
id: 3,
|
|
12
|
+
name: 'Reporting Contact',
|
|
13
|
+
slug: 'reporting_contact',
|
|
14
|
+
},
|
|
15
|
+
billing_contact: { id: 4, name: 'Billing Contact', slug: 'billing_contact' },
|
|
16
|
+
marketing_contact: {
|
|
17
|
+
id: 5,
|
|
18
|
+
name: 'Marketing Contact',
|
|
19
|
+
slug: 'marketing_contact',
|
|
20
|
+
},
|
|
21
|
+
video_producer: { id: 8, name: 'Video Producer', slug: 'video_producer' },
|
|
22
|
+
regional_contact: {
|
|
23
|
+
id: 9,
|
|
24
|
+
name: 'Regional Contact',
|
|
25
|
+
slug: 'regional_contact',
|
|
26
|
+
},
|
|
27
|
+
accounts_payable: {
|
|
28
|
+
id: 16,
|
|
29
|
+
name: 'Accounts Payable',
|
|
30
|
+
slug: 'accounts_payable',
|
|
31
|
+
},
|
|
32
|
+
main: { id: 17, name: 'Main', slug: 'main' },
|
|
33
|
+
website_contact: { id: 18, name: 'Website Contact', slug: 'website_contact' },
|
|
34
|
+
gtm_contact: { id: 19, name: 'GTM Contact', slug: 'gtm_contact' },
|
|
35
|
+
ga_contact: { id: 20, name: 'GA Contact', slug: 'ga_contact' },
|
|
36
|
+
gbp_contact: { id: 21, name: 'GBP Contact', slug: 'gbp_contact' },
|
|
37
|
+
fb_contact: { id: 22, name: 'FB Contact', slug: 'fb_contact' },
|
|
38
|
+
crm_contact: { id: 23, name: 'CRM Contact', slug: 'crm_contact' },
|
|
39
|
+
tcc_chat_contact: {
|
|
40
|
+
id: 24,
|
|
41
|
+
name: 'TCC/Chat Contact',
|
|
42
|
+
slug: 'tcc_chat_contact',
|
|
43
|
+
},
|
|
44
|
+
leasing_community_manager: {
|
|
45
|
+
id: 25,
|
|
46
|
+
name: 'Leasing/Community Manager',
|
|
47
|
+
slug: 'leasing_community_manager',
|
|
48
|
+
},
|
|
49
|
+
pausing_notifications_contact: {
|
|
22
50
|
id: 27,
|
|
23
51
|
name: 'Pausing Notifications Contact',
|
|
24
|
-
slug: '
|
|
52
|
+
slug: 'pausing_notifications_contact',
|
|
53
|
+
},
|
|
54
|
+
bov_contact: { id: 28, name: 'BOV Contact', slug: 'bov_contact' },
|
|
55
|
+
contract_signee: { id: 29, name: 'Contract Signee', slug: 'contract_signee' },
|
|
56
|
+
onboarding_contact: {
|
|
57
|
+
id: 30,
|
|
58
|
+
name: 'Onboarding Contact',
|
|
59
|
+
slug: 'onboarding_contact',
|
|
25
60
|
},
|
|
26
|
-
'28-BOV Contact': { id: 28, name: 'BOV Contact', slug: '28-BOV Contact' },
|
|
27
|
-
'29-Contract Signee': { id: 29, name: 'Contract Signee', slug: '29-Contract Signee' },
|
|
28
|
-
'30-Onboarding Contact': { id: 30, name: 'Onboarding Contact', slug: '30-Onboarding Contact' },
|
|
29
61
|
};
|
|
30
62
|
exports.CLIQ_GROUPS = {
|
|
31
63
|
ad_reviewer: 'Property Ad Reviewers',
|
|
@@ -107,13 +139,42 @@ class XperienceRightsClient {
|
|
|
107
139
|
}
|
|
108
140
|
if (locator.type === 'right') {
|
|
109
141
|
const [scope, ability] = locator.value.split('@');
|
|
110
|
-
return long
|
|
142
|
+
return long
|
|
143
|
+
? `any ${locator.constraint ? `${locator.constraint} ` : ''}user with the ${exports.FRIENDLY_SCOPE_NAMES[scope]} ${ability} rights`
|
|
144
|
+
: `${exports.FRIENDLY_SCOPE_NAMES[scope]} ${ability}${locator.constraint ? ` (${locator.constraint})` : ''}`;
|
|
111
145
|
}
|
|
112
146
|
if (locator.type === 'odoo_role') {
|
|
113
|
-
return `${long ? 'any user with the Odoo role: ' : ''}${exports.ODOO_ROLES[locator.value]
|
|
147
|
+
return `${long ? 'any user with the Odoo role: ' : ''}${exports.ODOO_ROLES[locator.value]
|
|
148
|
+
? exports.ODOO_ROLES[locator.value].name
|
|
149
|
+
: locator.value}`;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
static featureFlagEnabled(data, strategies, qualifier) {
|
|
153
|
+
if (!data || !strategies || !strategies.length) {
|
|
154
|
+
return false;
|
|
114
155
|
}
|
|
156
|
+
if (!qualifier) {
|
|
157
|
+
qualifier = 0;
|
|
158
|
+
}
|
|
159
|
+
return strategies.some((strategy) => {
|
|
160
|
+
if (strategy.type === 'group') {
|
|
161
|
+
return strategy.groups.some((group) => XperienceRightsClient.isGroupMember(data, group, qualifier));
|
|
162
|
+
}
|
|
163
|
+
if (strategy.type === 'user') {
|
|
164
|
+
return strategy.users.includes(data.email);
|
|
165
|
+
}
|
|
166
|
+
if (strategy.type === 'company') {
|
|
167
|
+
return strategy.master_ids.includes(qualifier);
|
|
168
|
+
}
|
|
169
|
+
if (strategy.type === 'company_user') {
|
|
170
|
+
return strategy.master_ids.includes(qualifier) && strategy.users.includes(data.email);
|
|
171
|
+
}
|
|
172
|
+
if (strategy.type === 'company_group') {
|
|
173
|
+
return strategy.master_ids.includes(qualifier) && strategy.groups.some((group) => XperienceRightsClient.isGroupMember(data, group, qualifier));
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
});
|
|
115
177
|
}
|
|
116
|
-
;
|
|
117
178
|
static isGroupMember(data, group, qualifier) {
|
|
118
179
|
if (!data || !data.groups || !data.groups[group]) {
|
|
119
180
|
return false;
|
|
@@ -121,7 +182,11 @@ class XperienceRightsClient {
|
|
|
121
182
|
if (!qualifier) {
|
|
122
183
|
qualifier = 0;
|
|
123
184
|
}
|
|
124
|
-
return data.groups[group].qualifiers.includes(0) ||
|
|
185
|
+
return (data.groups[group].qualifiers.includes(0) ||
|
|
186
|
+
data.groups[group].qualifiers.includes(qualifier) ||
|
|
187
|
+
(data.groups[group].common &&
|
|
188
|
+
(data.commonQualifiers.includes(qualifier) ||
|
|
189
|
+
data.commonQualifiers.includes(0))));
|
|
125
190
|
}
|
|
126
191
|
static abilityValue(ability) {
|
|
127
192
|
switch (ability) {
|
|
@@ -147,7 +212,9 @@ class XperienceRightsClient {
|
|
|
147
212
|
}
|
|
148
213
|
static bestAbility(...abilities) {
|
|
149
214
|
return abilities.reduce((best, current) => {
|
|
150
|
-
return XperienceRightsClient.compareAbilities(current, best, 'better')
|
|
215
|
+
return XperienceRightsClient.compareAbilities(current, best, 'better')
|
|
216
|
+
? current
|
|
217
|
+
: best;
|
|
151
218
|
}, 'none');
|
|
152
219
|
}
|
|
153
220
|
static xperienceScopeName(scope) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clxmedia/xperience-rights-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "CLXperience Rights Client",
|
|
5
5
|
"author": "Brandon Thompson <brandont@clxmedia.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"bugs": "https://github.com/adsupnow/xperience-library/xperience-rights-client",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@clxmedia/types": "1.0.
|
|
35
|
+
"@clxmedia/types": "1.0.160"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "29.5.11",
|