@clxmedia/credstore-client 2.0.1 → 2.0.2
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/index.js +22 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CredStoreClient = exports.XperienceEntityKeyGenerator = exports.XperienceEntityKeyValidator = void 0;
|
|
7
|
+
const luxon_1 = require("luxon");
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
const XperienceEntityKeyValidator = (entityId, entitySecret, availableEntityKeys) => {
|
|
11
|
+
const now = luxon_1.DateTime.local().startOf('minute').toSeconds();
|
|
6
12
|
const timeRange = Array.from(Array(9).keys()).map((i) => now + (i - 4) * 60);
|
|
7
13
|
return timeRange.some((timeSalt) => {
|
|
8
14
|
return availableEntityKeys.some((entityKey) => {
|
|
@@ -10,17 +16,19 @@ export const XperienceEntityKeyValidator = (entityId, entitySecret, availableEnt
|
|
|
10
16
|
});
|
|
11
17
|
});
|
|
12
18
|
};
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
exports.XperienceEntityKeyValidator = XperienceEntityKeyValidator;
|
|
20
|
+
const XperienceEntityKeyGenerator = (entityId, xperienceEntityKey) => {
|
|
21
|
+
const timeSalt = luxon_1.DateTime.local().startOf('minute').toSeconds();
|
|
15
22
|
return sha256Hash(`${entityId}:${xperienceEntityKey}`, timeSalt.toString());
|
|
16
23
|
};
|
|
24
|
+
exports.XperienceEntityKeyGenerator = XperienceEntityKeyGenerator;
|
|
17
25
|
const sha256Hash = (input, salt) => {
|
|
18
|
-
return createHash('sha256')
|
|
26
|
+
return (0, crypto_1.createHash)('sha256')
|
|
19
27
|
.update(input)
|
|
20
|
-
.update(createHash('sha256').update(salt, 'utf8').digest('hex'))
|
|
28
|
+
.update((0, crypto_1.createHash)('sha256').update(salt, 'utf8').digest('hex'))
|
|
21
29
|
.digest('hex');
|
|
22
30
|
};
|
|
23
|
-
|
|
31
|
+
class CredStoreClient {
|
|
24
32
|
constructor(config) {
|
|
25
33
|
this.apiServer = config.api_server;
|
|
26
34
|
this.apiKey = config.api_key;
|
|
@@ -42,13 +50,13 @@ export class CredStoreClient {
|
|
|
42
50
|
throw new Error('fetchOptions is required');
|
|
43
51
|
}
|
|
44
52
|
const { guidSecret, skipCache } = fetchOptions;
|
|
45
|
-
const response = await
|
|
53
|
+
const response = await axios_1.default.get(`${this.apiServer}/credstore/credentials/${guid}`, {
|
|
46
54
|
headers: this.buildHeaders(guidSecret, skipCache),
|
|
47
55
|
});
|
|
48
56
|
return response.data;
|
|
49
57
|
}
|
|
50
58
|
async createCredential(provider, credData) {
|
|
51
|
-
const response = await
|
|
59
|
+
const response = await axios_1.default.post(`${this.apiServer}/credstore/credentials/${provider}`, credData, {
|
|
52
60
|
headers: this.buildHeaders(),
|
|
53
61
|
});
|
|
54
62
|
return response.data;
|
|
@@ -58,9 +66,10 @@ export class CredStoreClient {
|
|
|
58
66
|
throw new Error('updateOptions is required');
|
|
59
67
|
}
|
|
60
68
|
const { guidSecret } = updateOptions;
|
|
61
|
-
const response = await
|
|
69
|
+
const response = await axios_1.default.patch(`${this.apiServer}/credstore/credentials/${guid}`, data, {
|
|
62
70
|
headers: this.buildHeaders(guidSecret),
|
|
63
71
|
});
|
|
64
72
|
return response.data;
|
|
65
73
|
}
|
|
66
74
|
}
|
|
75
|
+
exports.CredStoreClient = CredStoreClient;
|