@payfit/audit-log 1.0.3 → 1.0.5
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/CHANGELOG.md +9 -0
- package/README.md +10 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/transport/generated/api/default-api.d.ts +3 -3
- package/dist/transport/generated/api/default-api.js +24 -12
- package/dist/transport/generated/api/default-api.js.map +1 -1
- package/dist/transport/generated/configuration.d.ts +2 -2
- package/dist/transport/generated/model/inline-object.d.ts +7 -1
- package/dist/transport/implementation.js +13 -2
- package/dist/transport/implementation.js.map +1 -1
- package/package.json +6 -4
- package/playground/index.ts +1 -1
- package/src/index.ts +4 -1
- package/src/transport/generated/.openapi-generator/VERSION +1 -1
- package/src/transport/generated/api/default-api.ts +8 -7
- package/src/transport/generated/configuration.ts +2 -2
- package/src/transport/generated/model/inline-object.ts +7 -1
- package/src/transport/implementation.ts +10 -1
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -26,8 +26,9 @@ You can finally write an audit log:
|
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
28
|
logger.log({
|
|
29
|
-
event: 'bonusAdded',
|
|
30
29
|
namespace: 'payroll',
|
|
30
|
+
target: 'employee.bonus',
|
|
31
|
+
event: 'create',
|
|
31
32
|
payload: {
|
|
32
33
|
amount: 200,
|
|
33
34
|
},
|
|
@@ -52,10 +53,10 @@ In order to keep synced with the actual API, the API calls from the SDK are auto
|
|
|
52
53
|
To build it, simply run
|
|
53
54
|
|
|
54
55
|
```sh
|
|
55
|
-
|
|
56
|
+
npm run build
|
|
56
57
|
```
|
|
57
58
|
|
|
58
|
-
from the
|
|
59
|
+
from the sdk folder (where the `package.json` is located).
|
|
59
60
|
|
|
60
61
|
### Testing
|
|
61
62
|
|
|
@@ -63,28 +64,29 @@ For now, no unit tests have been written, but it should arrive soon !
|
|
|
63
64
|
|
|
64
65
|
### Playing around with he SDK
|
|
65
66
|
|
|
66
|
-
Could it be for testing some changes you made, or just to discover how to use the SDK, there is a [playground](./playground) at your disposal.
|
|
67
|
+
Could it be for testing some changes you made, or just to discover how to use the SDK, there is a [playground](./playground) at your disposal.
|
|
67
68
|
|
|
68
69
|
It uses the current code in the repository, not the published one, so you don't have to `npm publish` or `npm link` to make it work 🙂
|
|
69
70
|
|
|
70
71
|
To run it, simply run from the `sdk` folder:
|
|
72
|
+
|
|
71
73
|
```sh
|
|
72
74
|
npm run start:playground
|
|
73
75
|
```
|
|
74
76
|
|
|
75
77
|
### Publishing
|
|
76
78
|
|
|
77
|
-
For now, there is no automated publishing from CI, so you have to publish it manually.
|
|
79
|
+
For now, there is no automated publishing from CI, so you have to publish it manually.
|
|
80
|
+
|
|
81
|
+
To do so, simply bump the `version` field in the `package.json` file, and run
|
|
78
82
|
|
|
79
|
-
To do so, simply bump the `version` field in the `package.json` file, and run
|
|
80
83
|
```
|
|
81
84
|
npm publish
|
|
82
85
|
```
|
|
83
86
|
|
|
84
|
-
|
|
85
87
|
## Code organisation
|
|
86
88
|
|
|
87
89
|
The code is mainly split into 2 parts:
|
|
90
|
+
|
|
88
91
|
- The transport part, whose only goal is to tell how to communicate with the API, i.e it abstracts the communication layer.
|
|
89
92
|
- The logic part, which tells how to build an audit log.
|
|
90
|
-
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
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); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
5
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
6
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
@@ -31,9 +32,9 @@ class AuditLogger {
|
|
|
31
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
33
|
const uuid = uuid_1.v4();
|
|
33
34
|
const { environment, service } = this.params;
|
|
34
|
-
const timestamp =
|
|
35
|
-
const log = Object.assign({}, data, account, { service, id: uuid, environment,
|
|
36
|
-
timestamp }, (scope && { scope }));
|
|
35
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
36
|
+
const log = Object.assign(Object.assign(Object.assign(Object.assign({}, data), account), { service, id: uuid, environment,
|
|
37
|
+
timestamp }), (scope && { scope }));
|
|
37
38
|
yield this.transport.create(log);
|
|
38
39
|
});
|
|
39
40
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAmC;AAEnC,+DAAsD;AAwGtD,MAAa,WAAW;IAGtB,YAAsB,MAAkC;QAAlC,WAAM,GAAN,MAAM,CAA4B;QACtD,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IAEK,GAAG,CAAC,EAA0C;YAA1C,EAAE,KAAK,EAAE,OAAO,OAA0B,EAAxB,uCAAO;;YACjC,MAAM,IAAI,GAAG,SAAM,EAAE,CAAA;YACrB,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;YAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;YAE/C,MAAM,GAAG,+DACJ,IAAI,GACJ,OAAO,KACV,OAAO,EACP,EAAE,EAAE,IAAI,EACR,WAAW;gBACX,SAAS,KACN,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC,CACxB,CAAA;YAED,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;;KACjC;CACF;AAxBD,kCAwBC"}
|
|
@@ -25,7 +25,7 @@ export declare const DefaultApiAxiosParamCreator: (configuration?: Configuration
|
|
|
25
25
|
* @param {*} [options] Override http request option.
|
|
26
26
|
* @throws {RequiredError}
|
|
27
27
|
*/
|
|
28
|
-
v1LogPost(inlineObject: InlineObject, options?: any)
|
|
28
|
+
v1LogPost: (inlineObject: InlineObject, options?: any) => Promise<RequestArgs>;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* DefaultApi - functional programming interface
|
|
@@ -39,7 +39,7 @@ export declare const DefaultApiFp: (configuration?: Configuration | undefined) =
|
|
|
39
39
|
* @param {*} [options] Override http request option.
|
|
40
40
|
* @throws {RequiredError}
|
|
41
41
|
*/
|
|
42
|
-
v1LogPost(inlineObject: InlineObject, options?: any): (axios?: AxiosInstance | undefined, basePath?: string | undefined) => AxiosPromise<void
|
|
42
|
+
v1LogPost(inlineObject: InlineObject, options?: any): Promise<(axios?: AxiosInstance | undefined, basePath?: string | undefined) => AxiosPromise<void>>;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* DefaultApi - factory interface
|
|
@@ -70,5 +70,5 @@ export declare class DefaultApi extends BaseAPI {
|
|
|
70
70
|
* @throws {RequiredError}
|
|
71
71
|
* @memberof DefaultApi
|
|
72
72
|
*/
|
|
73
|
-
v1LogPost(inlineObject: InlineObject, options?: any):
|
|
73
|
+
v1LogPost(inlineObject: InlineObject, options?: any): Promise<import("axios").AxiosResponse<void>>;
|
|
74
74
|
}
|
|
@@ -11,6 +11,15 @@
|
|
|
11
11
|
* https://openapi-generator.tech
|
|
12
12
|
* Do not edit the class manually.
|
|
13
13
|
*/
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
14
23
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
24
|
if (mod && mod.__esModule) return mod;
|
|
16
25
|
var result = {};
|
|
@@ -40,7 +49,7 @@ exports.DefaultApiAxiosParamCreator = function (configuration) {
|
|
|
40
49
|
* @param {*} [options] Override http request option.
|
|
41
50
|
* @throws {RequiredError}
|
|
42
51
|
*/
|
|
43
|
-
v1LogPost(inlineObject, options = {}) {
|
|
52
|
+
v1LogPost: (inlineObject, options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
44
53
|
// verify required parameter 'inlineObject' is not null or undefined
|
|
45
54
|
if (inlineObject === null || inlineObject === undefined) {
|
|
46
55
|
throw new base_1.RequiredError('inlineObject', 'Required parameter inlineObject was null or undefined when calling v1LogPost.');
|
|
@@ -51,21 +60,22 @@ exports.DefaultApiAxiosParamCreator = function (configuration) {
|
|
|
51
60
|
if (configuration) {
|
|
52
61
|
baseOptions = configuration.baseOptions;
|
|
53
62
|
}
|
|
54
|
-
const localVarRequestOptions = Object.assign({ method: 'POST' }, baseOptions, options);
|
|
63
|
+
const localVarRequestOptions = Object.assign(Object.assign({ method: 'POST' }, baseOptions), options);
|
|
55
64
|
const localVarHeaderParameter = {};
|
|
56
65
|
const localVarQueryParameter = {};
|
|
57
66
|
localVarHeaderParameter['Content-Type'] = 'application/json';
|
|
58
|
-
localVarUrlObj.query = Object.assign({}, localVarUrlObj.query, localVarQueryParameter, options.query);
|
|
67
|
+
localVarUrlObj.query = Object.assign(Object.assign(Object.assign({}, localVarUrlObj.query), localVarQueryParameter), options.query);
|
|
59
68
|
// fix override query string Detail: https://stackoverflow.com/a/7517673/1077943
|
|
60
69
|
delete localVarUrlObj.search;
|
|
61
|
-
|
|
70
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
71
|
+
localVarRequestOptions.headers = Object.assign(Object.assign(Object.assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
|
|
62
72
|
const needsSerialization = (typeof inlineObject !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
|
|
63
73
|
localVarRequestOptions.data = needsSerialization ? JSON.stringify(inlineObject !== undefined ? inlineObject : {}) : (inlineObject || "");
|
|
64
74
|
return {
|
|
65
75
|
url: globalImportUrl.format(localVarUrlObj),
|
|
66
76
|
options: localVarRequestOptions,
|
|
67
77
|
};
|
|
68
|
-
},
|
|
78
|
+
}),
|
|
69
79
|
};
|
|
70
80
|
};
|
|
71
81
|
/**
|
|
@@ -82,11 +92,13 @@ exports.DefaultApiFp = function (configuration) {
|
|
|
82
92
|
* @throws {RequiredError}
|
|
83
93
|
*/
|
|
84
94
|
v1LogPost(inlineObject, options) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const localVarAxiosArgs = yield exports.DefaultApiAxiosParamCreator(configuration).v1LogPost(inlineObject, options);
|
|
97
|
+
return (axios = axios_1.default, basePath = base_1.BASE_PATH) => {
|
|
98
|
+
const axiosRequestArgs = Object.assign(Object.assign({}, localVarAxiosArgs.options), { url: basePath + localVarAxiosArgs.url });
|
|
99
|
+
return axios.request(axiosRequestArgs);
|
|
100
|
+
};
|
|
101
|
+
});
|
|
90
102
|
},
|
|
91
103
|
};
|
|
92
104
|
};
|
|
@@ -104,7 +116,7 @@ exports.DefaultApiFactory = function (configuration, basePath, axios) {
|
|
|
104
116
|
* @throws {RequiredError}
|
|
105
117
|
*/
|
|
106
118
|
v1LogPost(inlineObject, options) {
|
|
107
|
-
return exports.DefaultApiFp(configuration).v1LogPost(inlineObject, options)(axios, basePath);
|
|
119
|
+
return exports.DefaultApiFp(configuration).v1LogPost(inlineObject, options).then((request) => request(axios, basePath));
|
|
108
120
|
},
|
|
109
121
|
};
|
|
110
122
|
};
|
|
@@ -124,7 +136,7 @@ class DefaultApi extends base_1.BaseAPI {
|
|
|
124
136
|
* @memberof DefaultApi
|
|
125
137
|
*/
|
|
126
138
|
v1LogPost(inlineObject, options) {
|
|
127
|
-
return exports.DefaultApiFp(this.configuration).v1LogPost(inlineObject, options)(this.axios, this.basePath);
|
|
139
|
+
return exports.DefaultApiFp(this.configuration).v1LogPost(inlineObject, options).then((request) => request(this.axios, this.basePath));
|
|
128
140
|
}
|
|
129
141
|
}
|
|
130
142
|
exports.DefaultApi = DefaultApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-api.js","sourceRoot":"","sources":["../../../../src/transport/generated/api/default-api.ts"],"names":[],"mappings":";AAAA,iBAAiB;AACjB;;;;;;;;;;GAUG
|
|
1
|
+
{"version":3,"file":"default-api.js","sourceRoot":"","sources":["../../../../src/transport/generated/api/default-api.ts"],"names":[],"mappings":";AAAA,iBAAiB;AACjB;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;;;;;AAGH,qDAAuC;AACvC,kDAAiE;AAEjE,yDAAyD;AACzD,aAAa;AACb,kCAA6F;AAG7F;;;GAGG;AACU,QAAA,2BAA2B,GAAG,UAAU,aAA6B;IAC9E,OAAO;QACH;;;;;;WAMG;QACH,SAAS,EAAE,CAAO,YAA0B,EAAE,UAAe,EAAE,EAAwB,EAAE;YACrF,oEAAoE;YACpE,IA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C,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnI,CAAC;CAEJ;AAbD,gCAaC"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
export interface ConfigurationParameters {
|
|
13
|
-
apiKey?: string | ((name: string) => string);
|
|
13
|
+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
14
14
|
username?: string;
|
|
15
15
|
password?: string;
|
|
16
16
|
accessToken?: string | ((name?: string, scopes?: string[]) => string);
|
|
@@ -23,7 +23,7 @@ export declare class Configuration {
|
|
|
23
23
|
* @param name security name
|
|
24
24
|
* @memberof Configuration
|
|
25
25
|
*/
|
|
26
|
-
apiKey?: string | ((name: string) => string);
|
|
26
|
+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
27
27
|
/**
|
|
28
28
|
* parameter for basic security
|
|
29
29
|
*
|
|
@@ -70,7 +70,7 @@ export interface InlineObject {
|
|
|
70
70
|
*/
|
|
71
71
|
target: string;
|
|
72
72
|
/**
|
|
73
|
-
* Audit log event environment
|
|
73
|
+
* Audit log event environment, only required when in todd context
|
|
74
74
|
* @type {string}
|
|
75
75
|
* @memberof InlineObject
|
|
76
76
|
*/
|
|
@@ -129,4 +129,10 @@ export interface InlineObject {
|
|
|
129
129
|
* @memberof InlineObject
|
|
130
130
|
*/
|
|
131
131
|
scope?: object;
|
|
132
|
+
/**
|
|
133
|
+
* Audit log event timestamp unix format
|
|
134
|
+
* @type {number}
|
|
135
|
+
* @memberof InlineObject
|
|
136
|
+
*/
|
|
137
|
+
timestamp: number;
|
|
132
138
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
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); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
5
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
6
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
@@ -17,8 +18,18 @@ class Transport {
|
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
create(auditLogData) {
|
|
21
|
+
var _a;
|
|
20
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
|
|
23
|
+
try {
|
|
24
|
+
yield this.api.v1LogPost(auditLogData);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (!err.isAxiosError) {
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
const message = ((_a = err.response) === null || _a === void 0 ? void 0 : _a.data) || err.message;
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
}
|
|
22
33
|
});
|
|
23
34
|
}
|
|
24
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/transport/implementation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/transport/implementation.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAAwC;AAKxC,MAAa,SAAS;IAGpB,YAAsB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAClC,IAAI,CAAC,GAAG,GAAG,IAAI,sBAAU,CAAC;YACxB,QAAQ,EAAE,IAAI,CAAC,MAAM;SACtB,CAAC,CAAA;IACJ,CAAC;IAEK,MAAM,CAAC,YAA0B;;;YACrC,IAAI;gBACF,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;aACvC;YAAC,OAAM,GAAG,EAAE;gBACX,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE;oBACrB,MAAM,GAAG,CAAA;iBACV;gBAED,MAAM,OAAO,GAAG,OAAA,GAAG,CAAC,QAAQ,0CAAE,IAAI,KAAI,GAAG,CAAC,OAAO,CAAA;gBACjD,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;aACzB;;KACF;CACF;AArBD,8BAqBC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payfit/audit-log",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Library to handle audit logs at Payfit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
8
|
"type:check": "tsc --noEmit",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"codegen:sdk": "openapi-generator generate -i ../pkg/broker/v1/swagger/openapi.json -g typescript-axios -o src/transport/generated -c openapi-codegen-config.yml",
|
|
10
|
+
"build": "npm run codegen:sdk && rimraf dist && tsc",
|
|
11
|
+
"prepublishOnly": "npm run build",
|
|
11
12
|
"start:playground": "ts-node playground/index.ts"
|
|
12
13
|
},
|
|
13
14
|
"author": "",
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"@types/lodash": "4.14.149",
|
|
23
|
+
"@types/node": "^14.0.9",
|
|
22
24
|
"@types/uuid": "3.4.7",
|
|
23
25
|
"prettier": "1.18.2",
|
|
24
26
|
"rimraf": "2.6.3",
|
|
@@ -26,6 +28,6 @@
|
|
|
26
28
|
"ts-node-dev": "1.0.0-pre.40",
|
|
27
29
|
"tslint": "5.18.0",
|
|
28
30
|
"tslint-config-prettier": "1.18.0",
|
|
29
|
-
"typescript": "3.
|
|
31
|
+
"typescript": "3.8.3"
|
|
30
32
|
}
|
|
31
33
|
}
|
package/playground/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -88,6 +88,9 @@ export type IAuditLogScope =
|
|
|
88
88
|
companyId: string
|
|
89
89
|
employeeId?: string
|
|
90
90
|
}
|
|
91
|
+
| {
|
|
92
|
+
individualId: string
|
|
93
|
+
}
|
|
91
94
|
| null
|
|
92
95
|
|
|
93
96
|
// warning: modifying this interface means probably make a breaking change to the SDK
|
|
@@ -111,7 +114,7 @@ export class AuditLogger implements IAuditLogger {
|
|
|
111
114
|
async log({ scope, account, ...data }: IAuditLogData) {
|
|
112
115
|
const uuid = uuidV4()
|
|
113
116
|
const { environment, service } = this.params
|
|
114
|
-
const timestamp =
|
|
117
|
+
const timestamp = Math.floor(Date.now() / 1000)
|
|
115
118
|
|
|
116
119
|
const log = {
|
|
117
120
|
...data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
4.
|
|
1
|
+
4.3.1
|
|
@@ -18,7 +18,7 @@ import { Configuration } from '../configuration';
|
|
|
18
18
|
// Some imports not used depending on template conditions
|
|
19
19
|
// @ts-ignore
|
|
20
20
|
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
|
|
21
|
-
|
|
21
|
+
// @ts-ignore
|
|
22
22
|
import { InlineObject } from '../model';
|
|
23
23
|
/**
|
|
24
24
|
* DefaultApi - axios parameter creator
|
|
@@ -33,7 +33,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
|
|
|
33
33
|
* @param {*} [options] Override http request option.
|
|
34
34
|
* @throws {RequiredError}
|
|
35
35
|
*/
|
|
36
|
-
v1LogPost(inlineObject: InlineObject, options: any = {}): RequestArgs {
|
|
36
|
+
v1LogPost: async (inlineObject: InlineObject, options: any = {}): Promise<RequestArgs> => {
|
|
37
37
|
// verify required parameter 'inlineObject' is not null or undefined
|
|
38
38
|
if (inlineObject === null || inlineObject === undefined) {
|
|
39
39
|
throw new RequiredError('inlineObject','Required parameter inlineObject was null or undefined when calling v1LogPost.');
|
|
@@ -55,7 +55,8 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
|
|
|
55
55
|
localVarUrlObj.query = {...localVarUrlObj.query, ...localVarQueryParameter, ...options.query};
|
|
56
56
|
// fix override query string Detail: https://stackoverflow.com/a/7517673/1077943
|
|
57
57
|
delete localVarUrlObj.search;
|
|
58
|
-
|
|
58
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
59
|
+
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
|
59
60
|
const needsSerialization = (typeof inlineObject !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
|
|
60
61
|
localVarRequestOptions.data = needsSerialization ? JSON.stringify(inlineObject !== undefined ? inlineObject : {}) : (inlineObject || "");
|
|
61
62
|
|
|
@@ -80,8 +81,8 @@ export const DefaultApiFp = function(configuration?: Configuration) {
|
|
|
80
81
|
* @param {*} [options] Override http request option.
|
|
81
82
|
* @throws {RequiredError}
|
|
82
83
|
*/
|
|
83
|
-
v1LogPost(inlineObject: InlineObject, options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise<void
|
|
84
|
-
const localVarAxiosArgs = DefaultApiAxiosParamCreator(configuration).v1LogPost(inlineObject, options);
|
|
84
|
+
async v1LogPost(inlineObject: InlineObject, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
|
85
|
+
const localVarAxiosArgs = await DefaultApiAxiosParamCreator(configuration).v1LogPost(inlineObject, options);
|
|
85
86
|
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
|
|
86
87
|
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
|
|
87
88
|
return axios.request(axiosRequestArgs);
|
|
@@ -104,7 +105,7 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa
|
|
|
104
105
|
* @throws {RequiredError}
|
|
105
106
|
*/
|
|
106
107
|
v1LogPost(inlineObject: InlineObject, options?: any): AxiosPromise<void> {
|
|
107
|
-
return DefaultApiFp(configuration).v1LogPost(inlineObject, options)(axios, basePath);
|
|
108
|
+
return DefaultApiFp(configuration).v1LogPost(inlineObject, options).then((request) => request(axios, basePath));
|
|
108
109
|
},
|
|
109
110
|
};
|
|
110
111
|
};
|
|
@@ -125,7 +126,7 @@ export class DefaultApi extends BaseAPI {
|
|
|
125
126
|
* @memberof DefaultApi
|
|
126
127
|
*/
|
|
127
128
|
public v1LogPost(inlineObject: InlineObject, options?: any) {
|
|
128
|
-
return DefaultApiFp(this.configuration).v1LogPost(inlineObject, options)(this.axios, this.basePath);
|
|
129
|
+
return DefaultApiFp(this.configuration).v1LogPost(inlineObject, options).then((request) => request(this.axios, this.basePath));
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
export interface ConfigurationParameters {
|
|
16
|
-
apiKey?: string | ((name: string) => string);
|
|
16
|
+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
17
17
|
username?: string;
|
|
18
18
|
password?: string;
|
|
19
19
|
accessToken?: string | ((name?: string, scopes?: string[]) => string);
|
|
@@ -27,7 +27,7 @@ export class Configuration {
|
|
|
27
27
|
* @param name security name
|
|
28
28
|
* @memberof Configuration
|
|
29
29
|
*/
|
|
30
|
-
apiKey?: string | ((name: string) => string);
|
|
30
|
+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
31
31
|
/**
|
|
32
32
|
* parameter for basic security
|
|
33
33
|
*
|
|
@@ -74,7 +74,7 @@ export interface InlineObject {
|
|
|
74
74
|
*/
|
|
75
75
|
target: string;
|
|
76
76
|
/**
|
|
77
|
-
* Audit log event environment
|
|
77
|
+
* Audit log event environment, only required when in todd context
|
|
78
78
|
* @type {string}
|
|
79
79
|
* @memberof InlineObject
|
|
80
80
|
*/
|
|
@@ -133,6 +133,12 @@ export interface InlineObject {
|
|
|
133
133
|
* @memberof InlineObject
|
|
134
134
|
*/
|
|
135
135
|
scope?: object;
|
|
136
|
+
/**
|
|
137
|
+
* Audit log event timestamp unix format
|
|
138
|
+
* @type {number}
|
|
139
|
+
* @memberof InlineObject
|
|
140
|
+
*/
|
|
141
|
+
timestamp: number;
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
|
|
@@ -13,6 +13,15 @@ export class Transport implements IAuditLogTransport {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async create(auditLogData: InlineObject) {
|
|
16
|
-
|
|
16
|
+
try {
|
|
17
|
+
await this.api.v1LogPost(auditLogData)
|
|
18
|
+
} catch(err) {
|
|
19
|
+
if (!err.isAxiosError) {
|
|
20
|
+
throw err
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const message = err.response?.data || err.message
|
|
24
|
+
throw new Error(message)
|
|
25
|
+
}
|
|
17
26
|
}
|
|
18
27
|
}
|