@clxmedia/credstore-client 1.0.24 → 2.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/README.md +3 -3
- package/dist/client.d.ts +8 -96
- package/dist/client.js +32 -57
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -8
- package/package.json +27 -31
- package/CHANGELOG.md +0 -8
- package/CONTRIBUTING.md +0 -31
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<h1 align="center"></h1>
|
|
2
2
|
|
|
3
|
-
<h3 align="center">CLXperience
|
|
3
|
+
<h3 align="center">CLXperience Credstore Client</h3>
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Reads and writes to the Xperience Credstore
|
|
8
8
|
|
|
9
9
|
## Change Log
|
|
10
10
|
|
|
@@ -16,4 +16,4 @@ See [Changelog](CHANGELOG.md) for more information.
|
|
|
16
16
|
|
|
17
17
|
## License
|
|
18
18
|
|
|
19
|
-
Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
19
|
+
Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,109 +1,21 @@
|
|
|
1
|
+
import { CredStoreBundle, CredStoreConfig, CredentialProvider, CredstoreCredential } from '@clxmedia/types/core/credstore';
|
|
1
2
|
export declare const XperienceEntityKeyValidator: (entityId: string | number, entitySecret: string, availableEntityKeys: string[]) => boolean;
|
|
2
3
|
export declare const XperienceEntityKeyGenerator: (entityId: string | number, xperienceEntityKey: string) => string;
|
|
3
|
-
export
|
|
4
|
-
api_server: string;
|
|
5
|
-
api_key?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare enum CredentialProvider {
|
|
8
|
-
generic = "generic",
|
|
9
|
-
entrata = "entrata",
|
|
10
|
-
realpage = "realpage",
|
|
11
|
-
yardi = "yardi",
|
|
12
|
-
mailjet = "mailjet",
|
|
13
|
-
rentcafe_v2 = "rentcafe_v2",
|
|
14
|
-
welcome_home = "welcome_home"
|
|
15
|
-
}
|
|
16
|
-
export interface EntrataCredStoreBundle extends CredStoreBundle {
|
|
17
|
-
data: EntrataCredential;
|
|
18
|
-
}
|
|
19
|
-
export interface YardiCredStoreBundle extends CredStoreBundle {
|
|
20
|
-
data: YardiCredential;
|
|
21
|
-
}
|
|
22
|
-
export interface RealPageCredStoreBundle extends CredStoreBundle {
|
|
23
|
-
data: RealPageCredential;
|
|
24
|
-
}
|
|
25
|
-
export interface MailJetCredStoreBundle extends CredStoreBundle {
|
|
26
|
-
data: MailJetCredential;
|
|
27
|
-
}
|
|
28
|
-
export interface RentCafeV2CredStoreBundle extends CredStoreBundle {
|
|
29
|
-
data: RentCafeV2Credential;
|
|
30
|
-
}
|
|
31
|
-
export interface WelcomeHomeCredStoreBundle extends CredStoreBundle {
|
|
32
|
-
data: WelcomeHomeCredential;
|
|
33
|
-
}
|
|
34
|
-
export interface CredStoreBundle {
|
|
35
|
-
id: number;
|
|
36
|
-
description?: string;
|
|
37
|
-
guid: string;
|
|
38
|
-
secret?: string;
|
|
39
|
-
provider: CredentialProvider;
|
|
40
|
-
data: GenericCredential | EntrataCredential | RealPageCredential | YardiCredential | RentCafeV2Credential | MailJetCredential | WelcomeHomeCredential;
|
|
41
|
-
updated_at: string;
|
|
42
|
-
created_at: string;
|
|
43
|
-
}
|
|
44
|
-
export interface CredentialAttribute {
|
|
45
|
-
[x: string]: any;
|
|
46
|
-
}
|
|
47
|
-
export interface BaseCredential {
|
|
48
|
-
attributes?: Array<CredentialAttribute>;
|
|
49
|
-
}
|
|
50
|
-
export interface GenericCredential extends BaseCredential {
|
|
51
|
-
[x: string]: any;
|
|
52
|
-
}
|
|
53
|
-
export interface MailJetCredential extends BaseCredential {
|
|
54
|
-
username: string;
|
|
55
|
-
password: string;
|
|
56
|
-
}
|
|
57
|
-
export interface EntrataCredential extends BaseCredential {
|
|
58
|
-
domain: string;
|
|
59
|
-
username: string;
|
|
60
|
-
password: string;
|
|
61
|
-
property_id: string;
|
|
62
|
-
}
|
|
63
|
-
export interface RealPageCredential extends BaseCredential {
|
|
64
|
-
pmcid: string;
|
|
65
|
-
siteid: string;
|
|
66
|
-
username: string;
|
|
67
|
-
password: string;
|
|
68
|
-
licenseKey: string;
|
|
69
|
-
}
|
|
70
|
-
export interface RentCafeV2Credential extends BaseCredential {
|
|
71
|
-
company_api_key: string;
|
|
72
|
-
company_code: string;
|
|
73
|
-
}
|
|
74
|
-
export interface YardiCredential extends BaseCredential {
|
|
75
|
-
endpoint: string;
|
|
76
|
-
userName: string;
|
|
77
|
-
password: string;
|
|
78
|
-
serverName: string;
|
|
79
|
-
database: string;
|
|
80
|
-
platform: string;
|
|
81
|
-
yardiPropertyId: string;
|
|
82
|
-
interfaceEntity: string;
|
|
83
|
-
interfaceLicense: string;
|
|
84
|
-
}
|
|
85
|
-
export interface WelcomeHomeCredential extends BaseCredential {
|
|
86
|
-
api_key: string;
|
|
87
|
-
community_id: string;
|
|
88
|
-
lead_source_id: string;
|
|
89
|
-
}
|
|
90
|
-
export interface FetchOptions extends OptionsBase {
|
|
91
|
-
skipCache?: boolean;
|
|
92
|
-
}
|
|
93
|
-
export interface UpdateOptions extends OptionsBase {
|
|
94
|
-
}
|
|
95
|
-
export interface OptionsBase {
|
|
4
|
+
export type OptionsBase = {
|
|
96
5
|
guidSecret?: string;
|
|
97
|
-
}
|
|
6
|
+
};
|
|
7
|
+
export type FetchOptions = OptionsBase & {
|
|
8
|
+
skipCache?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type UpdateOptions = OptionsBase;
|
|
98
11
|
export declare class CredStoreClient {
|
|
99
12
|
private apiServer;
|
|
100
13
|
private apiKey?;
|
|
101
|
-
private httpService;
|
|
102
14
|
constructor(config: CredStoreConfig);
|
|
103
15
|
buildHeaders(guidSecret?: string, skipCache?: boolean): {
|
|
104
16
|
[x: string]: string;
|
|
105
17
|
};
|
|
106
18
|
fetchCredential(guid: string, fetchOptions?: FetchOptions): Promise<CredStoreBundle>;
|
|
107
|
-
createCredential(provider: CredentialProvider, credData:
|
|
19
|
+
createCredential(provider: CredentialProvider, credData: CredstoreCredential): Promise<any>;
|
|
108
20
|
updateCredential(guid: string, data: any, updateOptions?: UpdateOptions): Promise<any>;
|
|
109
21
|
}
|
package/dist/client.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CredStoreClient = exports.CredentialProvider = exports.XperienceEntityKeyGenerator = exports.XperienceEntityKeyValidator = void 0;
|
|
13
|
-
const axios_1 = require("@nestjs/axios");
|
|
14
|
-
const rxjs_1 = require("rxjs");
|
|
15
|
-
const luxon_1 = require("luxon");
|
|
16
|
-
const crypto_1 = require("crypto");
|
|
17
|
-
const XperienceEntityKeyValidator = (entityId, entitySecret, availableEntityKeys) => {
|
|
18
|
-
const now = luxon_1.DateTime.local().startOf('minute').toSeconds();
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
export const XperienceEntityKeyValidator = (entityId, entitySecret, availableEntityKeys) => {
|
|
5
|
+
const now = DateTime.local().startOf('minute').toSeconds();
|
|
19
6
|
const timeRange = Array.from(Array(9).keys()).map((i) => now + (i - 4) * 60);
|
|
20
7
|
return timeRange.some((timeSalt) => {
|
|
21
8
|
return availableEntityKeys.some((entityKey) => {
|
|
@@ -23,38 +10,24 @@ const XperienceEntityKeyValidator = (entityId, entitySecret, availableEntityKeys
|
|
|
23
10
|
});
|
|
24
11
|
});
|
|
25
12
|
};
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const timeSalt = luxon_1.DateTime.local().startOf('minute').toSeconds();
|
|
13
|
+
export const XperienceEntityKeyGenerator = (entityId, xperienceEntityKey) => {
|
|
14
|
+
const timeSalt = DateTime.local().startOf('minute').toSeconds();
|
|
29
15
|
return sha256Hash(`${entityId}:${xperienceEntityKey}`, timeSalt.toString());
|
|
30
16
|
};
|
|
31
|
-
exports.XperienceEntityKeyGenerator = XperienceEntityKeyGenerator;
|
|
32
17
|
const sha256Hash = (input, salt) => {
|
|
33
|
-
return
|
|
18
|
+
return createHash('sha256')
|
|
34
19
|
.update(input)
|
|
35
|
-
.update(
|
|
36
|
-
.digest(
|
|
20
|
+
.update(createHash('sha256').update(salt, 'utf8').digest('hex'))
|
|
21
|
+
.digest('hex');
|
|
37
22
|
};
|
|
38
|
-
|
|
39
|
-
(function (CredentialProvider) {
|
|
40
|
-
CredentialProvider["generic"] = "generic";
|
|
41
|
-
CredentialProvider["entrata"] = "entrata";
|
|
42
|
-
CredentialProvider["realpage"] = "realpage";
|
|
43
|
-
CredentialProvider["yardi"] = "yardi";
|
|
44
|
-
CredentialProvider["mailjet"] = "mailjet";
|
|
45
|
-
CredentialProvider["rentcafe_v2"] = "rentcafe_v2";
|
|
46
|
-
CredentialProvider["welcome_home"] = "welcome_home";
|
|
47
|
-
})(CredentialProvider = exports.CredentialProvider || (exports.CredentialProvider = {}));
|
|
48
|
-
;
|
|
49
|
-
class CredStoreClient {
|
|
23
|
+
export class CredStoreClient {
|
|
50
24
|
constructor(config) {
|
|
51
|
-
this.httpService = new axios_1.HttpService();
|
|
52
25
|
this.apiServer = config.api_server;
|
|
53
26
|
this.apiKey = config.api_key;
|
|
54
27
|
}
|
|
55
28
|
buildHeaders(guidSecret, skipCache) {
|
|
56
29
|
const headers = {
|
|
57
|
-
'x-credstore-skip-cache': `${skipCache}
|
|
30
|
+
'x-credstore-skip-cache': `${skipCache}`,
|
|
58
31
|
};
|
|
59
32
|
if (this.apiKey) {
|
|
60
33
|
headers['x-credstore-admin-key'] = this.apiKey;
|
|
@@ -64,28 +37,30 @@ class CredStoreClient {
|
|
|
64
37
|
}
|
|
65
38
|
return headers;
|
|
66
39
|
}
|
|
67
|
-
fetchCredential(guid, fetchOptions) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
40
|
+
async fetchCredential(guid, fetchOptions) {
|
|
41
|
+
if (!fetchOptions) {
|
|
42
|
+
throw new Error('fetchOptions is required');
|
|
43
|
+
}
|
|
44
|
+
const { guidSecret, skipCache } = fetchOptions;
|
|
45
|
+
const response = await axios.get(`${this.apiServer}/credstore/credentials/${guid}`, {
|
|
46
|
+
headers: this.buildHeaders(guidSecret, skipCache),
|
|
73
47
|
});
|
|
48
|
+
return response.data;
|
|
74
49
|
}
|
|
75
|
-
createCredential(provider, credData) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return response.data;
|
|
79
|
-
})));
|
|
50
|
+
async createCredential(provider, credData) {
|
|
51
|
+
const response = await axios.post(`${this.apiServer}/credstore/credentials/${provider}`, credData, {
|
|
52
|
+
headers: this.buildHeaders(),
|
|
80
53
|
});
|
|
54
|
+
return response.data;
|
|
81
55
|
}
|
|
82
|
-
updateCredential(guid, data, updateOptions) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
56
|
+
async updateCredential(guid, data, updateOptions) {
|
|
57
|
+
if (!updateOptions) {
|
|
58
|
+
throw new Error('updateOptions is required');
|
|
59
|
+
}
|
|
60
|
+
const { guidSecret } = updateOptions;
|
|
61
|
+
const response = await axios.patch(`${this.apiServer}/credstore/credentials/${guid}`, data, {
|
|
62
|
+
headers: this.buildHeaders(guidSecret),
|
|
88
63
|
});
|
|
64
|
+
return response.data;
|
|
89
65
|
}
|
|
90
66
|
}
|
|
91
|
-
exports.CredStoreClient = CredStoreClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './client';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XperienceEntityKeyGenerator = exports.XperienceEntityKeyValidator = exports.CredentialProvider = exports.CredStoreClient = void 0;
|
|
4
|
-
var client_1 = require("./client");
|
|
5
|
-
Object.defineProperty(exports, "CredStoreClient", { enumerable: true, get: function () { return client_1.CredStoreClient; } });
|
|
6
|
-
Object.defineProperty(exports, "CredentialProvider", { enumerable: true, get: function () { return client_1.CredentialProvider; } });
|
|
7
|
-
Object.defineProperty(exports, "XperienceEntityKeyValidator", { enumerable: true, get: function () { return client_1.XperienceEntityKeyValidator; } });
|
|
8
|
-
Object.defineProperty(exports, "XperienceEntityKeyGenerator", { enumerable: true, get: function () { return client_1.XperienceEntityKeyGenerator; } });
|
|
1
|
+
export * from './client';
|
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clxmedia/credstore-client",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "CLXperience
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "CLXperience Credstore Client",
|
|
5
5
|
"author": "Brandon Thompson <brandont@clxmedia.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"readmeFilename": "README.md",
|
|
8
|
-
"main": "dist/
|
|
9
|
-
"
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist/**/*",
|
|
12
12
|
"*.md"
|
|
13
13
|
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./client": "./dist/client.js"
|
|
20
|
+
},
|
|
14
21
|
"scripts": {
|
|
15
22
|
"start:dev": "tsc -w",
|
|
16
|
-
"build": "tsc",
|
|
23
|
+
"build": "rm -Rf dist && tsc",
|
|
17
24
|
"prepare": "npm run build",
|
|
18
25
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
19
26
|
"lint": "tslint -p tsconfig.json -c tslint.json",
|
|
@@ -30,36 +37,25 @@
|
|
|
30
37
|
},
|
|
31
38
|
"repository": {
|
|
32
39
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/adsupnow/xperience-
|
|
34
|
-
},
|
|
35
|
-
"bugs": "https://github.com/adsupnow/xperience-cred-store/client",
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"@nestjs/common": "^8.1.1"
|
|
40
|
+
"url": "https://github.com/adsupnow/xperience-clients/credstore"
|
|
38
41
|
},
|
|
42
|
+
"bugs": "https://github.com/adsupnow/xperience-clients/credstore",
|
|
43
|
+
"peerDependencies": {},
|
|
39
44
|
"dependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"
|
|
45
|
+
"@clxmedia/types": "1.0.15",
|
|
46
|
+
"axios": "1.6.8",
|
|
47
|
+
"jsonwebtoken": "9.0.2",
|
|
48
|
+
"luxon": "3.4.4"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
|
-
"
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"@types/node": "16.11.7",
|
|
52
|
-
"@types/supertest": "2.0.12",
|
|
53
|
-
"jest": "28.1.3",
|
|
54
|
-
"prettier": "2.7.1",
|
|
55
|
-
"rxjs": "7.5.7",
|
|
56
|
-
"supertest": "6.2.4",
|
|
57
|
-
"ts-jest": "28.0.8",
|
|
58
|
-
"ts-node": "10.9.1",
|
|
59
|
-
"tsc-watch": "5.0.3",
|
|
60
|
-
"tsconfig-paths": "4.1.0",
|
|
51
|
+
"typescript": "^5.2.2",
|
|
52
|
+
"@types/node": "^20",
|
|
53
|
+
"@types/jsonwebtoken": "9.0.6",
|
|
54
|
+
"jest": "29.7.0",
|
|
55
|
+
"ts-jest": "29.1.2",
|
|
56
|
+
"nock": "13.5.4",
|
|
61
57
|
"tslint": "6.1.3",
|
|
62
|
-
"
|
|
58
|
+
"@types/luxon": "3.4.2"
|
|
63
59
|
},
|
|
64
60
|
"jest": {
|
|
65
61
|
"moduleFileExtensions": [
|
|
@@ -75,4 +71,4 @@
|
|
|
75
71
|
"coverageDirectory": "../coverage",
|
|
76
72
|
"testEnvironment": "node"
|
|
77
73
|
}
|
|
78
|
-
}
|
|
74
|
+
}
|
package/CHANGELOG.md
DELETED
package/CONTRIBUTING.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
1. [Fork it](https://help.github.com/articles/fork-a-repo/)
|
|
4
|
-
2. Install dependencies (`npm install`)
|
|
5
|
-
3. Create your feature branch (`git checkout -b my-new-feature`)
|
|
6
|
-
4. Commit your changes (`git commit -am 'Added some feature'`)
|
|
7
|
-
5. Test your changes (`npm test`)
|
|
8
|
-
6. Push to the branch (`git push origin my-new-feature`)
|
|
9
|
-
7. [Create new Pull Request](https://help.github.com/articles/creating-a-pull-request/)
|
|
10
|
-
|
|
11
|
-
## Testing
|
|
12
|
-
|
|
13
|
-
We use [Jest](https://github.com/facebook/jest) to write tests. Run our test suite with this command:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
npm test
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Code Style
|
|
20
|
-
|
|
21
|
-
We use [Prettier](https://prettier.io/) and tslint to maintain code style and best practices.
|
|
22
|
-
Please make sure your PR adheres to the guides by running:
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
npm run format
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
and
|
|
29
|
-
```
|
|
30
|
-
npm run lint
|
|
31
|
-
```
|