itrm-tools 1.3.2 → 1.3.5-beta.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/.github/workflows/node.js.yml +30 -0
- package/README.md +2 -2
- package/dist/api/APIRequest.js +22 -29
- package/dist/api/APIRequest.js.map +1 -1
- package/dist/api/APIRouter.js +3 -1
- package/dist/api/APIRouter.js.map +1 -1
- package/dist/api/APIService.js +11 -17
- package/dist/api/APIService.js.map +1 -1
- package/dist/api/HttpsAPIService.js +5 -13
- package/dist/api/HttpsAPIService.js.map +1 -1
- package/dist/api/alegra/AlegraConnectionManager.js +23 -50
- package/dist/api/alegra/AlegraConnectionManager.js.map +1 -1
- package/dist/api/channel/ServerSentEventsManager.js +2 -1
- package/dist/api/channel/ServerSentEventsManager.js.map +1 -1
- package/dist/api/check/APIChecker.js +11 -25
- package/dist/api/check/APIChecker.js.map +1 -1
- package/dist/api/check/CheckableAPIRequest.js +17 -29
- package/dist/api/check/CheckableAPIRequest.js.map +1 -1
- package/dist/api/check/CheckableAPIRouter.js +17 -29
- package/dist/api/check/CheckableAPIRouter.js.map +1 -1
- package/dist/api/check/request/CheckableFileUploadingPostRequest.js +2 -0
- package/dist/api/check/request/CheckableFileUploadingPostRequest.js.map +1 -1
- package/dist/api/check/route/CorsCheckApiRouter.js +2 -13
- package/dist/api/check/route/CorsCheckApiRouter.js.map +1 -1
- package/dist/api/check/route/SimpleCheckableAPIRouter.js +2 -13
- package/dist/api/check/route/SimpleCheckableAPIRouter.js.map +1 -1
- package/dist/api/external/ExternalApiSigner.js +2 -0
- package/dist/api/external/ExternalApiSigner.js.map +1 -1
- package/dist/api/external/cetus/CetusStrategyApiManager.js +8 -20
- package/dist/api/external/cetus/CetusStrategyApiManager.js.map +1 -1
- package/dist/api/request/RequestAxiosCall.js +20 -37
- package/dist/api/request/RequestAxiosCall.js.map +1 -1
- package/dist/api/request/crud/CrudServiceManager.js +6 -17
- package/dist/api/request/crud/CrudServiceManager.js.map +1 -1
- package/dist/api/request/docs/DocumentationRequest.js +4 -7
- package/dist/api/request/docs/DocumentationRequest.js.map +1 -1
- package/dist/api/route/SimpleAPIRouter.js +2 -13
- package/dist/api/route/SimpleAPIRouter.js.map +1 -1
- package/dist/database/mongoose/MongooseModelManager.d.ts +8 -40
- package/dist/database/mongoose/MongooseModelManager.js +5 -14
- package/dist/database/mongoose/MongooseModelManager.js.map +1 -1
- package/dist/database/redis/RedisConnection.js +1 -0
- package/dist/database/redis/RedisConnection.js.map +1 -1
- package/dist/database/redis/RedisModelManager.js +1 -0
- package/dist/database/redis/RedisModelManager.js.map +1 -1
- package/dist/database/sequelize/SequelizeConnection.js +1 -0
- package/dist/database/sequelize/SequelizeConnection.js.map +1 -1
- package/dist/database/sequelize/SequelizeModelManager.js +6 -15
- package/dist/database/sequelize/SequelizeModelManager.js.map +1 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.js +1 -28
- package/dist/index.js.map +1 -1
- package/dist/log/Logger.js +2 -0
- package/dist/log/Logger.js.map +1 -1
- package/dist/log/LoggerManager.js +11 -21
- package/dist/log/LoggerManager.js.map +1 -1
- package/dist/log/LoggerWebSocket.js +4 -2
- package/dist/log/LoggerWebSocket.js.map +1 -1
- package/dist/web3/coingecko/CoingeckoPriceFinder.js +24 -36
- package/dist/web3/coingecko/CoingeckoPriceFinder.js.map +1 -1
- package/jest.config.js +7 -0
- package/package.json +68 -74
- package/sequelize.sqlite +0 -0
- package/src/algorithm/encryption/EncryptionAlgorithm.ts +4 -0
- package/src/api/APIRequest.ts +176 -0
- package/src/api/APIRequestBuilder.ts +28 -0
- package/src/api/APIRouter.ts +26 -0
- package/src/api/APIService.ts +117 -0
- package/src/api/ExpressConfiguration.ts +5 -0
- package/src/api/HttpsAPIService.ts +35 -0
- package/src/api/alegra/AlegraConnectionManager.ts +54 -0
- package/src/api/alegra/AlegraTypes.ts +150 -0
- package/src/api/builder/StandardGetRequestBuilder.ts +34 -0
- package/src/api/channel/ServerSentEventsManager.ts +28 -0
- package/src/api/check/APIChecker.ts +50 -0
- package/src/api/check/CheckableAPIRequest.ts +33 -0
- package/src/api/check/CheckableAPIRouter.ts +39 -0
- package/src/api/check/request/CheckableDeleteRequest.ts +17 -0
- package/src/api/check/request/CheckableFileUploadingPostRequest.ts +26 -0
- package/src/api/check/request/CheckableGetRequest.ts +17 -0
- package/src/api/check/request/CheckablePostRequest.ts +17 -0
- package/src/api/check/request/CheckablePutRequest.ts +17 -0
- package/src/api/check/route/CorsCheckApiRouter.ts +22 -0
- package/src/api/check/route/SimpleCheckableAPIRouter.ts +14 -0
- package/src/api/express/ExpressFileUploadingConfiguration.ts +22 -0
- package/src/api/express/ExpressLogableConfig.ts +11 -0
- package/src/api/express/ExpressStandardConfiguration.ts +25 -0
- package/src/api/external/ExternalApiSigner.ts +29 -0
- package/src/api/external/cetus/CetusStrategyApiManager.ts +48 -0
- package/src/api/request/DeleteRequest.ts +16 -0
- package/src/api/request/GetRequest.ts +16 -0
- package/src/api/request/PostRequest.ts +16 -0
- package/src/api/request/PutRequest.ts +16 -0
- package/src/api/request/RequestAxiosCall.ts +38 -0
- package/src/api/request/crud/CrudManager.ts +11 -0
- package/src/api/request/crud/CrudServiceManager.ts +117 -0
- package/src/api/request/docs/DocumentationModels.ts +121 -0
- package/src/api/request/docs/DocumentationRequest.ts +132 -0
- package/src/api/route/SimpleAPIRouter.ts +12 -0
- package/src/database/mongoose/MongooseModelManager.ts +65 -0
- package/src/database/redis/RedisConnection.ts +18 -0
- package/src/database/redis/RedisModelManager.ts +23 -0
- package/src/database/sequelize/SequelizeConnection.ts +45 -0
- package/src/database/sequelize/SequelizeModelManager.ts +71 -0
- package/src/index.ts +51 -0
- package/src/log/Logger.ts +27 -0
- package/src/log/LoggerManager.ts +50 -0
- package/src/log/LoggerWebSocket.ts +13 -0
- package/src/math/Utils.ts +4 -0
- package/src/types/payments.ts +811 -0
- package/src/web3/Coin.ts +18 -0
- package/src/web3/coingecko/CoingeckoPriceFinder.ts +75 -0
- package/test/api/APIRouter.test.ts +78 -0
- package/test/api/APIService.test.ts +50 -0
- package/test/api/APITestDefinitions.ts +7 -0
- package/test/api/CORS.test.ts +56 -0
- package/test/api/alegra/AlegraConnectionManager.test.ts +32 -0
- package/test/api/check/CheckDefinitions.ts +47 -0
- package/test/api/check/CheckableAPIRouter.test.ts +67 -0
- package/test/api/check/CheckableDeleteRequest.test.ts +92 -0
- package/test/api/check/CheckableGetRequest.test.ts +99 -0
- package/test/api/check/CheckablePostRequest.test.ts +108 -0
- package/test/api/check/CheckablePutRequest.test.ts +99 -0
- package/test/api/docs/DocumentationRequest.test.ts +192 -0
- package/test/api/request/DeleteRequest.test.ts +117 -0
- package/test/api/request/GetRequest.test.ts +140 -0
- package/test/api/request/PostRequest.test.ts +237 -0
- package/test/api/request/PutRequest.test.ts +166 -0
- package/test/database/mongoose/MongooseModelManager.test.ts +139 -0
- package/test/database/redis/RedisConnection.test.ts +7 -0
- package/test/database/sequelize/SequealizeDefinitions.ts +6 -0
- package/test/database/sequelize/SequelizeConnection.test.ts +30 -0
- package/test/database/sequelize/SequelizeModelManager.test.ts +206 -0
- package/test/log/Logger.test.ts +44 -0
- package/test/web3/coingecko/CoingeckoPriceFinder.test.ts +72 -0
- package/tsconfig.json +23 -0
- package/dist/api/check/RoleServicePermissionsChecker.d.ts +0 -13
- package/dist/api/check/RoleServicePermissionsChecker.js +0 -92
- package/dist/api/check/RoleServicePermissionsChecker.js.map +0 -1
- package/dist/api/check/ServiceSessionChecker.d.ts +0 -28
- package/dist/api/check/ServiceSessionChecker.js +0 -119
- package/dist/api/check/ServiceSessionChecker.js.map +0 -1
- package/dist/api/request/crud/common/ActivityHistoryManager.d.ts +0 -40
- package/dist/api/request/crud/common/ActivityHistoryManager.js +0 -86
- package/dist/api/request/crud/common/ActivityHistoryManager.js.map +0 -1
- package/dist/api/request/crud/common/ApplicationManager.d.ts +0 -39
- package/dist/api/request/crud/common/ApplicationManager.js +0 -72
- package/dist/api/request/crud/common/ApplicationManager.js.map +0 -1
- package/dist/api/request/crud/common/AvailablePlatformManager.d.ts +0 -39
- package/dist/api/request/crud/common/AvailablePlatformManager.js +0 -86
- package/dist/api/request/crud/common/AvailablePlatformManager.js.map +0 -1
- package/dist/api/request/crud/common/ComponentManager.d.ts +0 -56
- package/dist/api/request/crud/common/ComponentManager.js +0 -78
- package/dist/api/request/crud/common/ComponentManager.js.map +0 -1
- package/dist/api/request/crud/common/KeyManager.d.ts +0 -39
- package/dist/api/request/crud/common/KeyManager.js +0 -88
- package/dist/api/request/crud/common/KeyManager.js.map +0 -1
- package/dist/api/request/crud/common/PlatformManager.d.ts +0 -44
- package/dist/api/request/crud/common/PlatformManager.js +0 -75
- package/dist/api/request/crud/common/PlatformManager.js.map +0 -1
- package/dist/api/request/crud/common/RoleManager.d.ts +0 -56
- package/dist/api/request/crud/common/RoleManager.js +0 -75
- package/dist/api/request/crud/common/RoleManager.js.map +0 -1
- package/dist/api/request/crud/common/StatusManager.d.ts +0 -34
- package/dist/api/request/crud/common/StatusManager.js +0 -74
- package/dist/api/request/crud/common/StatusManager.js.map +0 -1
- package/dist/api/request/crud/common/TypeManager.d.ts +0 -33
- package/dist/api/request/crud/common/TypeManager.js +0 -76
- package/dist/api/request/crud/common/TypeManager.js.map +0 -1
- package/dist/api/request/crud/common/UserCredentialsManager.d.ts +0 -39
- package/dist/api/request/crud/common/UserCredentialsManager.js +0 -84
- package/dist/api/request/crud/common/UserCredentialsManager.js.map +0 -1
- package/dist/api/request/crud/common/UserManager.d.ts +0 -35
- package/dist/api/request/crud/common/UserManager.js +0 -80
- package/dist/api/request/crud/common/UserManager.js.map +0 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { DataTypes } from '@sequelize/core';
|
|
2
|
+
import { SequelizeConnection, SequelizeModelManager } from '../../../dist';
|
|
3
|
+
import { config } from './SequealizeDefinitions';
|
|
4
|
+
|
|
5
|
+
interface Test {
|
|
6
|
+
testId: number,
|
|
7
|
+
name: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface TestB {
|
|
11
|
+
testId: number,
|
|
12
|
+
name: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const connection = new SequelizeConnection(config);
|
|
16
|
+
const manager = new SequelizeModelManager<Test>({
|
|
17
|
+
name: 'Test',
|
|
18
|
+
attributes: {
|
|
19
|
+
testId: {
|
|
20
|
+
type: DataTypes.INTEGER,
|
|
21
|
+
allowNull: false,
|
|
22
|
+
unique: true
|
|
23
|
+
},
|
|
24
|
+
name: {
|
|
25
|
+
type: DataTypes.STRING,
|
|
26
|
+
allowNull: false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const managerB = new SequelizeModelManager<TestB>({
|
|
32
|
+
name: 'TestB',
|
|
33
|
+
attributes: {
|
|
34
|
+
name: {
|
|
35
|
+
type: DataTypes.STRING,
|
|
36
|
+
allowNull: false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const managerC = new SequelizeModelManager<TestB>({
|
|
42
|
+
name: 'TestC',
|
|
43
|
+
attributes: {
|
|
44
|
+
name: {
|
|
45
|
+
type: DataTypes.STRING,
|
|
46
|
+
allowNull: false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("Testing Sequelize Model Manager", () => {
|
|
52
|
+
beforeAll(async () => {
|
|
53
|
+
await connection.connect();
|
|
54
|
+
await managerB.define(connection);
|
|
55
|
+
await managerC.define(connection);
|
|
56
|
+
});
|
|
57
|
+
afterAll(async() => {
|
|
58
|
+
await connection.disconnect();
|
|
59
|
+
});
|
|
60
|
+
test("Init Model", async () => {
|
|
61
|
+
await manager.define(connection);
|
|
62
|
+
let result = await manager.sync();
|
|
63
|
+
expect(result.name).toMatch('Test');
|
|
64
|
+
expect(result.tableName).toMatch('Tests');
|
|
65
|
+
});
|
|
66
|
+
test("Insert", async () => {
|
|
67
|
+
expect.assertions(2);
|
|
68
|
+
return manager.create({
|
|
69
|
+
testId: 1,
|
|
70
|
+
name: 'test1'
|
|
71
|
+
}).then((response: any) => {
|
|
72
|
+
expect(response.dataValues.testId).toBe(1);
|
|
73
|
+
expect(response.dataValues.name).toMatch('test1');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
test("Insert Fail", async () => {
|
|
77
|
+
expect.assertions(2);
|
|
78
|
+
return manager.create({
|
|
79
|
+
testId: 1,
|
|
80
|
+
name: 'test1'
|
|
81
|
+
}).catch((err: any) => {
|
|
82
|
+
expect(err.name).toMatch('SequelizeUniqueConstraintError');
|
|
83
|
+
expect(err.errors[0].message).toMatch('testId must be unique');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
test("Insert Many", async () => {
|
|
87
|
+
expect.assertions(4);
|
|
88
|
+
return manager.bulkCreate([{
|
|
89
|
+
testId: 2,
|
|
90
|
+
name: 'test2'
|
|
91
|
+
}, {
|
|
92
|
+
testId: 3,
|
|
93
|
+
name: 'test3'
|
|
94
|
+
}]).then((response: any) => {
|
|
95
|
+
expect(response[0].dataValues.testId).toBe(2);
|
|
96
|
+
expect(response[0].dataValues.name).toMatch('test2');
|
|
97
|
+
expect(response[1].dataValues.testId).toBe(3);
|
|
98
|
+
expect(response[1].dataValues.name).toMatch('test3');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
test("Update", async () => {
|
|
102
|
+
expect.assertions(1);
|
|
103
|
+
return manager.update({
|
|
104
|
+
name: 'test2'
|
|
105
|
+
}, {
|
|
106
|
+
where: {
|
|
107
|
+
testId: 1
|
|
108
|
+
}
|
|
109
|
+
}).then((response: any) => {
|
|
110
|
+
expect(response[0]).toBeGreaterThan(0);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
test("Find All", async () => {
|
|
114
|
+
expect.assertions(2);
|
|
115
|
+
return manager.findAll({
|
|
116
|
+
where: {
|
|
117
|
+
testId: 1
|
|
118
|
+
}
|
|
119
|
+
}).then((response: any) => {
|
|
120
|
+
expect(response[0].dataValues.testId).toBe(1);
|
|
121
|
+
expect(response[0].dataValues.name).toMatch('test2');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
test("Delete", async () => {
|
|
125
|
+
expect.assertions(1);
|
|
126
|
+
return manager.destroy({
|
|
127
|
+
where: {
|
|
128
|
+
testId: [1, 2, 3]
|
|
129
|
+
}
|
|
130
|
+
}).then((response: any) => {
|
|
131
|
+
expect(response).toBeGreaterThan(0);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
test("> testing hasOne:", async () => {
|
|
135
|
+
let response = await manager.hasOne(managerB);
|
|
136
|
+
console.log("> hasOne response:", response);
|
|
137
|
+
expect(response.accessors.create).toMatch("createTestB");
|
|
138
|
+
expect(response.accessors.get).toMatch("getTestB");
|
|
139
|
+
expect(response.accessors.set).toMatch("setTestB");
|
|
140
|
+
expect(response.inverse.accessors.create).toMatch("createTest");
|
|
141
|
+
expect(response.inverse.accessors.get).toMatch("getTest");
|
|
142
|
+
expect(response.inverse.accessors.set).toMatch("setTest");
|
|
143
|
+
expect(response.inverse.foreignKey).toMatch("testId");
|
|
144
|
+
expect(response.inverse.options.as).toMatch("test");
|
|
145
|
+
});
|
|
146
|
+
test("> testing hasMany:", async () => {
|
|
147
|
+
let response = await manager.hasMany(managerB);
|
|
148
|
+
console.log("> hasMany response:", response);
|
|
149
|
+
expect(response.accessors.add).toMatch("addTestB");
|
|
150
|
+
expect(response.accessors.addMultiple).toMatch("addTestBs");
|
|
151
|
+
expect(response.accessors.count).toMatch("countTestBs");
|
|
152
|
+
expect(response.accessors.create).toMatch("createTestB");
|
|
153
|
+
expect(response.accessors.get).toMatch("getTestBs");
|
|
154
|
+
expect(response.accessors.hasAll).toMatch("hasTestBs");
|
|
155
|
+
expect(response.accessors.hasSingle).toMatch("hasTestB");
|
|
156
|
+
expect(response.accessors.remove).toMatch("removeTestB");
|
|
157
|
+
expect(response.accessors.removeMultiple).toMatch("removeTestBs");
|
|
158
|
+
expect(response.accessors.set).toMatch("setTestBs");
|
|
159
|
+
expect(response.inverse.accessors.create).toMatch("createTest");
|
|
160
|
+
expect(response.inverse.accessors.get).toMatch("getTest");
|
|
161
|
+
expect(response.inverse.accessors.set).toMatch("setTest");
|
|
162
|
+
expect(response.inverse.foreignKey).toMatch("testId");
|
|
163
|
+
expect(response.inverse.options.as).toMatch("test");
|
|
164
|
+
});
|
|
165
|
+
test("> testing belongsTo:", async () => {
|
|
166
|
+
let response = await managerB.belongsTo(manager);
|
|
167
|
+
console.log("> belongsTo:", response);
|
|
168
|
+
expect(response.accessors.create).toMatch("createTest");
|
|
169
|
+
expect(response.accessors.get).toMatch("getTest");
|
|
170
|
+
expect(response.accessors.set).toMatch("setTest");
|
|
171
|
+
expect(response.parentAssociation.accessors.create).toMatch("createTestB");
|
|
172
|
+
expect(response.parentAssociation.accessors.get).toMatch("getTestB");
|
|
173
|
+
expect(response.parentAssociation.accessors.set).toMatch("setTestB");
|
|
174
|
+
expect(response.foreignKey).toMatch("testId");
|
|
175
|
+
expect(response.options.as).toMatch("test");
|
|
176
|
+
});
|
|
177
|
+
test("> testing belongsToMany:", async () => {
|
|
178
|
+
let response = await managerC.belongsToMany(managerB, { through: "" });
|
|
179
|
+
console.log("> belongsToMany:", response);
|
|
180
|
+
expect(response.accessors.add).toMatch("addTestB");
|
|
181
|
+
expect(response.accessors.addMultiple).toMatch("addTestBs");
|
|
182
|
+
expect(response.accessors.count).toMatch("countTestBs");
|
|
183
|
+
expect(response.accessors.create).toMatch("createTestB");
|
|
184
|
+
expect(response.accessors.get).toMatch("getTestBs");
|
|
185
|
+
expect(response.accessors.hasAll).toMatch("hasTestBs");
|
|
186
|
+
expect(response.accessors.hasSingle).toMatch("hasTestB");
|
|
187
|
+
expect(response.accessors.remove).toMatch("removeTestB");
|
|
188
|
+
expect(response.accessors.removeMultiple).toMatch("removeTestBs");
|
|
189
|
+
expect(response.accessors.set).toMatch("setTestBs");
|
|
190
|
+
expect(response.fromSourceToThrough.accessors.add).toMatch("addTestBsTestC");
|
|
191
|
+
expect(response.fromSourceToThrough.accessors.addMultiple).toMatch("addTestBsTestCs");
|
|
192
|
+
expect(response.fromSourceToThrough.accessors.count).toMatch("countTestBsTestCs");
|
|
193
|
+
expect(response.fromSourceToThrough.accessors.create).toMatch("createTestBsTestC");
|
|
194
|
+
expect(response.fromSourceToThrough.accessors.get).toMatch("getTestBsTestCs");
|
|
195
|
+
expect(response.fromSourceToThrough.accessors.hasAll).toMatch("hasTestBsTestCs");
|
|
196
|
+
expect(response.fromSourceToThrough.accessors.hasSingle).toMatch("hasTestBsTestC");
|
|
197
|
+
expect(response.fromSourceToThrough.accessors.remove).toMatch("removeTestBsTestC");
|
|
198
|
+
expect(response.fromSourceToThrough.accessors.removeMultiple).toMatch("removeTestBsTestCs");
|
|
199
|
+
expect(response.fromSourceToThrough.accessors.set).toMatch("setTestBsTestCs");
|
|
200
|
+
expect(response.fromSourceToThrough.inverse.accessors.create).toMatch("createTestC");
|
|
201
|
+
expect(response.fromSourceToThrough.inverse.accessors.get).toMatch("getTestC");
|
|
202
|
+
expect(response.fromSourceToThrough.inverse.accessors.set).toMatch("setTestC");
|
|
203
|
+
expect(response.fromSourceToThrough.inverse.foreignKey).toMatch("testCId");
|
|
204
|
+
expect(response.fromSourceToThrough.inverse.options.as).toMatch("testC");
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Logger } from '../../dist';
|
|
2
|
+
import { v4 as uuidv4, validate } from 'uuid';
|
|
3
|
+
import MockAdapter from "axios-mock-adapter";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
|
|
6
|
+
const EXECUTOR = "https://services.itrmachines.com/log-executor/";
|
|
7
|
+
const LOGGER = "https://services.itrmachines.com/log-executor/send";
|
|
8
|
+
|
|
9
|
+
const logger: Logger = new Logger(EXECUTOR, LOGGER);
|
|
10
|
+
|
|
11
|
+
describe("> testing Logger", () => {
|
|
12
|
+
let mock: MockAdapter;
|
|
13
|
+
let executionId: string;
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
mock = new MockAdapter(axios);
|
|
16
|
+
});
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
mock.reset();
|
|
19
|
+
});
|
|
20
|
+
test("> testing request a new extecution Id", async () => {
|
|
21
|
+
mock.onPost(`${EXECUTOR}/generateid`).reply(200, uuidv4() + "87");
|
|
22
|
+
executionId = await logger.requestExecutionId();
|
|
23
|
+
expect(executionId.length).toBeGreaterThan(36);
|
|
24
|
+
expect(validate(executionId.substring(0, 36))).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
test("> testing sending a log", async () => {
|
|
27
|
+
mock.onPost(LOGGER).reply(404, { log: {} });
|
|
28
|
+
return await logger.send({})
|
|
29
|
+
.catch((err: any) => {
|
|
30
|
+
expect(err.message).toMatch('Request failed with status code 404');
|
|
31
|
+
expect(err.response.status).toBe(404);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
test("> testing sending a log", async () => {
|
|
35
|
+
mock.onPost(LOGGER).reply(200, 'Ok');
|
|
36
|
+
return await logger.send({
|
|
37
|
+
timestamp: 10000000,
|
|
38
|
+
executionId: '7752a2cc-676f-4c0f-881f-8bb6086ab7f21',
|
|
39
|
+
data: {}
|
|
40
|
+
}).then((response: any) => {
|
|
41
|
+
expect(response).toMatch('Ok');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Coin, CoingeckoPriceFinder, RequestAxiosCall } from "../../../dist";
|
|
2
|
+
import MockAdapter from "axios-mock-adapter";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
|
|
5
|
+
const finderETH = new CoingeckoPriceFinder();
|
|
6
|
+
const finderUSD = new CoingeckoPriceFinder('usd');
|
|
7
|
+
const dates = [ '01-01-2022', '02-02-2022', '03-03-2022', '04-04-2022', '05-05-2022' ];
|
|
8
|
+
const coins = [ Coin.BTC, Coin.MANA, Coin.DAI, Coin.SAND ];
|
|
9
|
+
const symbolId = [ 'bitcoin', 'decentraland', 'dai', 'the-sandbox' ];
|
|
10
|
+
|
|
11
|
+
const testCoins = [
|
|
12
|
+
Coin.APE, Coin.ARTX, Coin.ATRI, Coin.BTC, Coin.CUBE, Coin.DAI, Coin.MANA,
|
|
13
|
+
Coin.MATIC, Coin.RARI, Coin.SAND, Coin.SCOTT, Coin.USDC, Coin.WBTC
|
|
14
|
+
];
|
|
15
|
+
const testSymbolIds = [
|
|
16
|
+
"apecoin", "artx", "atari", "bitcoin", "somnium-space-cubes",
|
|
17
|
+
"dai", "decentraland", "matic-network", "rarible", "the-sandbox",
|
|
18
|
+
"scotty-beam", "usd-coin", "bitcoin"
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
async function findEthValues(coinIndex: number, dateIndex: number) {
|
|
22
|
+
let info = dates[dateIndex].split('-');
|
|
23
|
+
let year = parseInt(info[2]);
|
|
24
|
+
let month = parseInt(info[1]);
|
|
25
|
+
let day = parseInt(info[0]);
|
|
26
|
+
let price = await finderETH.getPrice(coins[coinIndex], new Date(year, month - 1, day, 0, 0, 0));
|
|
27
|
+
let coinGeckoPrice: any = await RequestAxiosCall.get(`https://api.coingecko.com/api/v3/coins/${symbolId[coinIndex]}/history?date=${dates[dateIndex]}`);
|
|
28
|
+
return {
|
|
29
|
+
original: coinGeckoPrice.market_data.current_price.eth,
|
|
30
|
+
price: price
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function findUsdValues(coinIndex: number, dateIndex: number) {
|
|
35
|
+
let info = dates[dateIndex].split('-');
|
|
36
|
+
let year = parseInt(info[2]);
|
|
37
|
+
let month = parseInt(info[1]);
|
|
38
|
+
let day = parseInt(info[0]);
|
|
39
|
+
let price = await finderUSD.getPrice(coins[coinIndex], new Date(year, month - 1, day, 0, 0, 0));
|
|
40
|
+
let coinGeckoPrice: any = await RequestAxiosCall.get(`https://api.coingecko.com/api/v3/coins/${symbolId[coinIndex]}/history?date=${dates[dateIndex]}`);
|
|
41
|
+
return {
|
|
42
|
+
original: coinGeckoPrice.market_data.current_price.usd,
|
|
43
|
+
price: price
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('testing Checkable Router', () => {
|
|
48
|
+
let mock: MockAdapter;
|
|
49
|
+
beforeAll(() => {
|
|
50
|
+
mock = new MockAdapter(axios);
|
|
51
|
+
for (let symbol of symbolId)
|
|
52
|
+
for (let date of dates)
|
|
53
|
+
mock.onGet(`https://api.coingecko.com/api/v3/coins/${symbol}/history?date=${date}`).reply(200, { market_data: { current_price: { eth: Math.random(), usd: 1200 * Math.random() } } });
|
|
54
|
+
});
|
|
55
|
+
afterAll(() => {
|
|
56
|
+
mock.reset();
|
|
57
|
+
});
|
|
58
|
+
test('ETH Finder Random', async() => {
|
|
59
|
+
let coinIndex: number = Math.floor(Math.random() * coins.length);
|
|
60
|
+
let dateIndex: number = Math.floor(Math.random() * dates.length);
|
|
61
|
+
let values: any;
|
|
62
|
+
if (Math.random() < 0.5)
|
|
63
|
+
values = await findEthValues(coinIndex, dateIndex);
|
|
64
|
+
else
|
|
65
|
+
values = await findUsdValues(coinIndex, dateIndex);
|
|
66
|
+
expect(values.price).toBe(values.price);
|
|
67
|
+
});
|
|
68
|
+
test('Testing symbolId function', () => {
|
|
69
|
+
for (let i = 0; i < testCoins.length; i++)
|
|
70
|
+
expect(finderETH.parseSymbolId(testCoins[i])).toMatch(testSymbolIds[i]);
|
|
71
|
+
})
|
|
72
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "es2022",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"emitDecoratorMetadata": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"rootDir": "./src",
|
|
12
|
+
"allowJs": false,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"src/**/*.ts"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"node_modules",
|
|
21
|
+
"**/*.spec.ts"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Request } from "express";
|
|
2
|
-
import { APICheck, APICheckConfig, APICheckResult } from "./APIChecker";
|
|
3
|
-
export declare class RoleServicePermissionsChecker implements APICheck {
|
|
4
|
-
private service;
|
|
5
|
-
private sessionServiceUrl;
|
|
6
|
-
private roleManager;
|
|
7
|
-
constructor(service: string, sessionServiceUrl: string, sessionServiceCrud: string);
|
|
8
|
-
getConfig(): APICheckConfig;
|
|
9
|
-
apply(config: APICheckConfig, req: Request): Promise<APICheckResult>;
|
|
10
|
-
private checkServicePermissions;
|
|
11
|
-
private isMethodAndPathAllowed;
|
|
12
|
-
private unexpectedErrorRejection;
|
|
13
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
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.RoleServicePermissionsChecker = void 0;
|
|
13
|
-
const RequestAxiosCall_1 = require("../request/RequestAxiosCall");
|
|
14
|
-
const RoleManager_1 = require("../request/crud/common/RoleManager");
|
|
15
|
-
class RoleServicePermissionsChecker {
|
|
16
|
-
constructor(service, sessionServiceUrl, sessionServiceCrud) {
|
|
17
|
-
this.service = service;
|
|
18
|
-
this.sessionServiceUrl = sessionServiceUrl;
|
|
19
|
-
this.roleManager = new RoleManager_1.RoleManager(`${sessionServiceCrud}/v1`);
|
|
20
|
-
}
|
|
21
|
-
getConfig() {
|
|
22
|
-
return {
|
|
23
|
-
check: "rolePermissionService",
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
apply(config, req) {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
var _a, _b, _c;
|
|
29
|
-
try {
|
|
30
|
-
const { platform } = req.headers;
|
|
31
|
-
let headers = {
|
|
32
|
-
headers: {
|
|
33
|
-
"Authorization": req.headers.authorization,
|
|
34
|
-
"platform": platform
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
// Verify the JWT and platform with the session service
|
|
38
|
-
let verification = yield RequestAxiosCall_1.RequestAxiosCall.post(`${this.sessionServiceUrl}/v1/verify`, { jwt: ((_a = req.headers.authorization) !== null && _a !== void 0 ? _a : 'NoToken').replace("Bearer ", ""), platform: platform }, headers);
|
|
39
|
-
// Fetch the service role
|
|
40
|
-
let role = yield this.roleManager.find({ name: verification === null || verification === void 0 ? void 0 : verification.role, config: headers });
|
|
41
|
-
// Check if the service and endpoint are allowed
|
|
42
|
-
return this.checkServicePermissions((_c = (_b = role === null || role === void 0 ? void 0 : role.permissions) === null || _b === void 0 ? void 0 : _b.services) !== null && _c !== void 0 ? _c : {}, req, verification);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
return this.unexpectedErrorRejection(error);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// Checks if the requested service, method, and path are allowed for the user's role.
|
|
50
|
-
checkServicePermissions(permissions, req, verification) {
|
|
51
|
-
if (permissions[this.service]) {
|
|
52
|
-
if (this.isMethodAndPathAllowed(permissions[this.service], req))
|
|
53
|
-
return { approved: true, payload: verification };
|
|
54
|
-
return {
|
|
55
|
-
approved: false,
|
|
56
|
-
rejection: {
|
|
57
|
-
code: 401,
|
|
58
|
-
payload: {
|
|
59
|
-
status: "Error",
|
|
60
|
-
message: `Method or Path are not allowed: ${req.method} ${req.baseUrl + req.path.replace(/\/\d+$/, "")}`
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
approved: false,
|
|
67
|
-
rejection: {
|
|
68
|
-
code: 401,
|
|
69
|
-
payload: {
|
|
70
|
-
status: "Error",
|
|
71
|
-
message: `Service is not allowed: ${this.service}`
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
//Checks if the HTTP method and path are allowed in the permissions object.
|
|
77
|
-
isMethodAndPathAllowed(permissions, req) {
|
|
78
|
-
return permissions[req.method] && permissions[req.method][req.baseUrl + req.path.replace(/\/\d+$/, "")];
|
|
79
|
-
}
|
|
80
|
-
unexpectedErrorRejection(error) {
|
|
81
|
-
var _a, _b, _c, _d;
|
|
82
|
-
return {
|
|
83
|
-
approved: false,
|
|
84
|
-
rejection: {
|
|
85
|
-
code: (_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 500,
|
|
86
|
-
payload: { status: "Error", message: (_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) !== null && _d !== void 0 ? _d : error }
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.RoleServicePermissionsChecker = RoleServicePermissionsChecker;
|
|
92
|
-
//# sourceMappingURL=RoleServicePermissionsChecker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RoleServicePermissionsChecker.js","sourceRoot":"","sources":["../../../src/api/check/RoleServicePermissionsChecker.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,kEAA+D;AAC/D,oEAAiE;AAGjE,MAAa,6BAA6B;IAMxC,YAAY,OAAe,EAAE,iBAAyB,EAAE,kBAA0B;QAChF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,GAAG,kBAAkB,KAAK,CAAC,CAAC;IACjE,CAAC;IAEM,SAAS;QACd,OAAO;YACL,KAAK,EAAE,uBAAuB;SAC/B,CAAC;IACJ,CAAC;IAEY,KAAK,CAAC,MAAsB,EAAE,GAAY;;;YACrD,IAAI,CAAC;gBACH,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;gBACjC,IAAI,OAAO,GAAG;oBACZ,OAAO,EAAE;wBACP,eAAe,EAAE,GAAG,CAAC,OAAO,CAAC,aAAa;wBAC1C,UAAU,EAAE,QAAQ;qBACrB;iBACF,CAAA;gBACD,uDAAuD;gBACvD,IAAI,YAAY,GAAQ,MAAM,mCAAgB,CAAC,IAAI,CACjD,GAAG,IAAI,CAAC,iBAAiB,YAAY,EACrC,EAAE,GAAG,EAAE,CAAC,MAAA,GAAG,CAAC,OAAO,CAAC,aAAa,mCAAI,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAC5F,OAAO,CACR,CAAC;gBACF,yBAAyB;gBACzB,IAAI,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,aAAZ,YAAY,uBAA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OAAO,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1G,CAAC;IAEO,wBAAwB,CAAC,KAAU;;QACzC,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE;gBACT,IAAI,EAAE,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,0CAAE,MAAM,mCAAI,GAAG;gBACpC,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,0CAAE,IAAI,mCAAI,KAAK,EAAE;aACtE;SACF,CAAC;IACJ,CAAC;CACF;AApFD,sEAoFC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Request } from "express";
|
|
2
|
-
import { APICheck, APICheckConfig, APICheckResult } from "./APIChecker";
|
|
3
|
-
export interface IServiceSessionConfig {
|
|
4
|
-
name: string;
|
|
5
|
-
url: string;
|
|
6
|
-
}
|
|
7
|
-
export interface IServiceCredentials {
|
|
8
|
-
apiKey: string;
|
|
9
|
-
apiSecret: string;
|
|
10
|
-
}
|
|
11
|
-
export declare class ServiceSessionChecker implements APICheck {
|
|
12
|
-
private token;
|
|
13
|
-
private readonly sessionServiceUrl;
|
|
14
|
-
private readonly config;
|
|
15
|
-
constructor(sessionServiceUrl: string, config: IServiceSessionConfig);
|
|
16
|
-
getConfig(): APICheckConfig;
|
|
17
|
-
apply(config: APICheckConfig, req: Request): Promise<APICheckResult>;
|
|
18
|
-
private createToken;
|
|
19
|
-
sign(params: {
|
|
20
|
-
method: string;
|
|
21
|
-
path: string;
|
|
22
|
-
}): Promise<{
|
|
23
|
-
headers: {
|
|
24
|
-
Authorization: string;
|
|
25
|
-
};
|
|
26
|
-
} | undefined>;
|
|
27
|
-
private getServiceCredentials;
|
|
28
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
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.ServiceSessionChecker = void 0;
|
|
13
|
-
const crypto_js_1 = require("crypto-js");
|
|
14
|
-
const RequestAxiosCall_1 = require("../request/RequestAxiosCall");
|
|
15
|
-
class ServiceSessionChecker {
|
|
16
|
-
constructor(sessionServiceUrl, config) {
|
|
17
|
-
this.token = "";
|
|
18
|
-
this.sessionServiceUrl = sessionServiceUrl;
|
|
19
|
-
this.config = config;
|
|
20
|
-
}
|
|
21
|
-
getConfig() {
|
|
22
|
-
return {
|
|
23
|
-
check: "serviceSession"
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
apply(config, req) {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
var _a;
|
|
29
|
-
try {
|
|
30
|
-
// Verifies the session token by calling the session service, if it exists approve the request else create new token
|
|
31
|
-
const verification = yield RequestAxiosCall_1.RequestAxiosCall.post(`${this.sessionServiceUrl}/v1/verify`, {
|
|
32
|
-
jwt: ((_a = req.headers.authorization) !== null && _a !== void 0 ? _a : 'NoToken').replace("Bearer ", ""),
|
|
33
|
-
platform: req.headers.platform
|
|
34
|
-
}, {
|
|
35
|
-
headers: { "Authorization": this.token }
|
|
36
|
-
});
|
|
37
|
-
console.log("> verification:", verification);
|
|
38
|
-
return {
|
|
39
|
-
approved: true,
|
|
40
|
-
payload: { headers: { "Authorization": this.token } }
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
// If verification fails, create a new token
|
|
45
|
-
return yield this.createToken();
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// Generate a new session token
|
|
50
|
-
createToken() {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
var _a, _b, _c, _d, _e;
|
|
53
|
-
try {
|
|
54
|
-
const headers = yield this.sign({ method: "POST", path: "/login" });
|
|
55
|
-
if (headers) {
|
|
56
|
-
// Call the session service to create a new session
|
|
57
|
-
const session = yield RequestAxiosCall_1.RequestAxiosCall.post(`${this.sessionServiceUrl}/service/login`, { service: this.config.name }, headers);
|
|
58
|
-
// Store the new token
|
|
59
|
-
this.token = (_c = (_b = (_a = session === null || session === void 0 ? void 0 : session.token) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.jwt) !== null && _c !== void 0 ? _c : "";
|
|
60
|
-
return {
|
|
61
|
-
approved: true,
|
|
62
|
-
payload: { headers: { "Authorization": this.token } }
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
// If headers are not available, return an error
|
|
66
|
-
return {
|
|
67
|
-
approved: false,
|
|
68
|
-
rejection: {
|
|
69
|
-
code: 500,
|
|
70
|
-
payload: { status: 'Error', message: 'Public API is not available' }
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
// Handle any errors that occur during token creation
|
|
76
|
-
return {
|
|
77
|
-
approved: false,
|
|
78
|
-
rejection: {
|
|
79
|
-
code: 401,
|
|
80
|
-
payload: (_e = (_d = err === null || err === void 0 ? void 0 : err.response) === null || _d === void 0 ? void 0 : _d.data) !== null && _e !== void 0 ? _e : err
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
// Sign the request with HMAC, if successful return headers else return undefined
|
|
87
|
-
sign(params) {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
const { method, path } = params;
|
|
90
|
-
let nonce = Date.now();
|
|
91
|
-
let message = `${nonce}${method}${path}${this.config.name ? JSON.stringify(this.config.name) : ""}`;
|
|
92
|
-
const credentials = yield this.getServiceCredentials();
|
|
93
|
-
if (credentials) {
|
|
94
|
-
const hash = (0, crypto_js_1.HmacSHA256)(message, credentials.apiSecret);
|
|
95
|
-
let signature = crypto_js_1.enc.Hex.stringify(hash);
|
|
96
|
-
return {
|
|
97
|
-
headers: {
|
|
98
|
-
Authorization: `${credentials.apiKey}:${nonce}:${signature}`,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return undefined;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
// Get service credentials
|
|
106
|
-
getServiceCredentials() {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
try {
|
|
109
|
-
const credentials = yield RequestAxiosCall_1.RequestAxiosCall.get(`${this.sessionServiceUrl}/service/credentials?service=${this.config.name}`, { headers: { referer: this.config.url } });
|
|
110
|
-
return credentials.payload;
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
exports.ServiceSessionChecker = ServiceSessionChecker;
|
|
119
|
-
//# sourceMappingURL=ServiceSessionChecker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceSessionChecker.js","sourceRoot":"","sources":["../../../src/api/check/ServiceSessionChecker.ts"],"names":[],"mappings":";;;;;;;;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GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YACpG,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;YACvD,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,IAAI,GAAG,IAAA,sBAAU,EAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;gBACxD,IAAI,SAAS,GAAG,eAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACxC,OAAO;oBACL,OAAO,EAAE;wBACP,aAAa,EAAE,GAAG,WAAW,CAAC,MAAM,IAAI,KAAK,IAAI,SAAS,EAAE;qBAC7D;iBACF,CAAC;YACJ,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED,0BAA0B;IACZ,qBAAqB;;YACjC,IAAI,CAAC;gBACH,MAAM,WAAW,GAAQ,MAAM,mCAAgB,CAAC,GAAG,CACjD,GAAG,IAAI,CAAC,iBAAiB,gCAAgC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAC3E,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAC1C,CAAC;gBACF,OAAO,WAAW,CAAC,OAAO,CAAC;YAC7B,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;KAAA;CACF;AAvGD,sDAuGC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { CrudServiceManager, StandardIdRequestDefinition } from "../CrudServiceManager";
|
|
2
|
-
import { AxiosRequestConfig } from "axios";
|
|
3
|
-
export interface IActivityHistory {
|
|
4
|
-
activityHistoryId?: number;
|
|
5
|
-
userId?: number;
|
|
6
|
-
platformId?: number;
|
|
7
|
-
roleId?: number;
|
|
8
|
-
typeId?: number;
|
|
9
|
-
details?: any;
|
|
10
|
-
updatedAt?: string;
|
|
11
|
-
createdAt?: string;
|
|
12
|
-
config?: AxiosRequestConfig;
|
|
13
|
-
}
|
|
14
|
-
export interface IActivityHistoryDetails {
|
|
15
|
-
activityHistoryId?: number;
|
|
16
|
-
userId?: number;
|
|
17
|
-
platformId?: number | string;
|
|
18
|
-
roleId?: number;
|
|
19
|
-
typeId?: number | string;
|
|
20
|
-
details?: any;
|
|
21
|
-
values?: IActivityHistory[];
|
|
22
|
-
limit?: number;
|
|
23
|
-
offset?: number;
|
|
24
|
-
config?: AxiosRequestConfig;
|
|
25
|
-
}
|
|
26
|
-
export declare class ActivityHistoryManager extends CrudServiceManager<IActivityHistoryDetails, IActivityHistory> {
|
|
27
|
-
private url;
|
|
28
|
-
constructor(url: string);
|
|
29
|
-
find(details: IActivityHistoryDetails): Promise<IActivityHistory | undefined>;
|
|
30
|
-
count(details: IActivityHistoryDetails): Promise<{
|
|
31
|
-
result: number;
|
|
32
|
-
}>;
|
|
33
|
-
findAll(details: IActivityHistoryDetails): Promise<IActivityHistory[] | undefined>;
|
|
34
|
-
private buildRequestUrl;
|
|
35
|
-
findById(id: StandardIdRequestDefinition): Promise<IActivityHistory | undefined>;
|
|
36
|
-
create(details: IActivityHistoryDetails): Promise<IActivityHistory | undefined>;
|
|
37
|
-
createMany(details: IActivityHistoryDetails): Promise<IActivityHistory[] | undefined>;
|
|
38
|
-
modify(activityHistory: IActivityHistory): Promise<any>;
|
|
39
|
-
destroy(activityHistory: IActivityHistory): Promise<any>;
|
|
40
|
-
}
|