@clxmedia/xperience-rights-client 1.0.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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/client.d.ts +8 -0
- package/dist/client.js +92 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 John Biundo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<h1 align="center"></h1>
|
|
2
|
+
|
|
3
|
+
<h3 align="center">CLXperience Rights Client</h3>
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Helper class for Xperience apps that use XperienceRightsData.
|
|
8
|
+
|
|
9
|
+
## Change Log
|
|
10
|
+
|
|
11
|
+
See [Changelog](CHANGELOG.md) for more information.
|
|
12
|
+
|
|
13
|
+
## Author
|
|
14
|
+
|
|
15
|
+
**Brandon Thompson**
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { XperienceAbility, XperienceRightsData, XperienceScopes } from '@clxmedia/types/core/auth';
|
|
2
|
+
export declare class XperienceRightsClient {
|
|
3
|
+
static findAbility(data: XperienceRightsData, scope: XperienceScopes, qualifier?: number): XperienceAbility;
|
|
4
|
+
static abilityValue(ability: XperienceAbility): number;
|
|
5
|
+
static compareAbilities(a: XperienceAbility, b: XperienceAbility, comparison?: 'enough' | 'better'): boolean;
|
|
6
|
+
static bestAbility(...abilities: XperienceAbility[]): XperienceAbility;
|
|
7
|
+
static xperienceScopeName(scope: XperienceScopes): string;
|
|
8
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XperienceRightsClient = void 0;
|
|
4
|
+
class XperienceRightsClient {
|
|
5
|
+
static findAbility(data, scope, qualifier) {
|
|
6
|
+
if (!data || !data.rights) {
|
|
7
|
+
return 'none';
|
|
8
|
+
}
|
|
9
|
+
const abilities = data.rights[scope];
|
|
10
|
+
if (!abilities) {
|
|
11
|
+
return 'none';
|
|
12
|
+
}
|
|
13
|
+
if (!qualifier) {
|
|
14
|
+
qualifier = 0;
|
|
15
|
+
}
|
|
16
|
+
const settingsIncludeQualifier = (settings, qualifier) => {
|
|
17
|
+
if (!qualifier) {
|
|
18
|
+
qualifier = 0;
|
|
19
|
+
}
|
|
20
|
+
if ([0, qualifier].some((q) => settings.qualifiers.includes(q))) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return settings.common && data.commonQualifiers.includes(qualifier);
|
|
24
|
+
};
|
|
25
|
+
return Object.entries(abilities).reduce((best, [ability, settings]) => {
|
|
26
|
+
if (settingsIncludeQualifier(settings, qualifier)) {
|
|
27
|
+
return XperienceRightsClient.bestAbility(ability, best);
|
|
28
|
+
}
|
|
29
|
+
return best;
|
|
30
|
+
}, 'none');
|
|
31
|
+
}
|
|
32
|
+
static abilityValue(ability) {
|
|
33
|
+
switch (ability) {
|
|
34
|
+
case 'none':
|
|
35
|
+
return 0;
|
|
36
|
+
case 'view':
|
|
37
|
+
return 1;
|
|
38
|
+
case 'edit':
|
|
39
|
+
return 2;
|
|
40
|
+
case 'admin':
|
|
41
|
+
return 3;
|
|
42
|
+
default:
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
static compareAbilities(a, b, comparison = 'enough') {
|
|
47
|
+
const aValue = XperienceRightsClient.abilityValue(a);
|
|
48
|
+
const bValue = XperienceRightsClient.abilityValue(b);
|
|
49
|
+
if (comparison === 'enough') {
|
|
50
|
+
return aValue >= bValue;
|
|
51
|
+
}
|
|
52
|
+
return aValue > bValue;
|
|
53
|
+
}
|
|
54
|
+
static bestAbility(...abilities) {
|
|
55
|
+
return abilities.reduce((best, current) => {
|
|
56
|
+
return XperienceRightsClient.compareAbilities(current, best, 'better') ? current : best;
|
|
57
|
+
}, 'none');
|
|
58
|
+
}
|
|
59
|
+
static xperienceScopeName(scope) {
|
|
60
|
+
switch (scope) {
|
|
61
|
+
case 'company':
|
|
62
|
+
return 'Company';
|
|
63
|
+
case 'displayreview':
|
|
64
|
+
return 'Display Review';
|
|
65
|
+
case 'platform':
|
|
66
|
+
return 'Xperience Platform';
|
|
67
|
+
case 'users':
|
|
68
|
+
return 'Users';
|
|
69
|
+
case 'forms':
|
|
70
|
+
return 'Forms';
|
|
71
|
+
case 'gbpreview':
|
|
72
|
+
return 'GBP Review';
|
|
73
|
+
case 'gbpa':
|
|
74
|
+
return 'GBPA';
|
|
75
|
+
case 'insights':
|
|
76
|
+
return 'Insights';
|
|
77
|
+
case 'mac':
|
|
78
|
+
return 'MAC';
|
|
79
|
+
case 'macreview':
|
|
80
|
+
return 'MAC Review';
|
|
81
|
+
case 'mediahub':
|
|
82
|
+
return 'Media Hub';
|
|
83
|
+
case 'onboarding':
|
|
84
|
+
return 'Onboarding';
|
|
85
|
+
case 'dashboard':
|
|
86
|
+
return 'Dashboard';
|
|
87
|
+
default:
|
|
88
|
+
return 'Unknown';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.XperienceRightsClient = XperienceRightsClient;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { XperienceRightsClient } from './client';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XperienceRightsClient = void 0;
|
|
4
|
+
var client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "XperienceRightsClient", { enumerable: true, get: function () { return client_1.XperienceRightsClient; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clxmedia/xperience-rights-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLXperience Rights Client",
|
|
5
|
+
"author": "Brandon Thompson <brandont@clxmedia.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"readmeFilename": "README.md",
|
|
8
|
+
"main": "dist/client.js",
|
|
9
|
+
"typings": "dist/client.d.ts",
|
|
10
|
+
"packageManager": "yarn@1.22.18",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*",
|
|
13
|
+
"*.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"start:dev": "tsc -w",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"prepare": "npm run build",
|
|
19
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
20
|
+
"lint": "tslint -p tsconfig.json -c tslint.json",
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"test:watch": "jest --watch",
|
|
23
|
+
"test:cov": "jest --coverage",
|
|
24
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/adsupnow/xperience-library/xperience-rights-client"
|
|
32
|
+
},
|
|
33
|
+
"bugs": "https://github.com/adsupnow/xperience-library/xperience-rights-client",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@clxmedia/types": "1.0.52"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/jest": "29.5.11",
|
|
39
|
+
"@types/js-yaml": "4.0.9",
|
|
40
|
+
"@types/node": "^20.10",
|
|
41
|
+
"@types/supertest": "2.0.16",
|
|
42
|
+
"jest": "29.7.0",
|
|
43
|
+
"prettier": "3.1.0",
|
|
44
|
+
"rxjs": "7.8.1",
|
|
45
|
+
"supertest": "6.3.3",
|
|
46
|
+
"ts-jest": "29.1.1",
|
|
47
|
+
"ts-node": "10.9.2",
|
|
48
|
+
"tsc-watch": "6.0.4",
|
|
49
|
+
"tsconfig-paths": "4.2.0",
|
|
50
|
+
"tslint": "6.1.3",
|
|
51
|
+
"typescript": "5.3.3"
|
|
52
|
+
},
|
|
53
|
+
"jest": {
|
|
54
|
+
"moduleFileExtensions": [
|
|
55
|
+
"js",
|
|
56
|
+
"json",
|
|
57
|
+
"ts"
|
|
58
|
+
],
|
|
59
|
+
"rootDir": "src",
|
|
60
|
+
"testRegex": ".spec.ts$",
|
|
61
|
+
"transform": {
|
|
62
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
63
|
+
},
|
|
64
|
+
"coverageDirectory": "../coverage",
|
|
65
|
+
"testEnvironment": "node"
|
|
66
|
+
}
|
|
67
|
+
}
|