@koralabs/kora-labs-common 2.6.9 → 2.7.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/constants/index.d.ts +6 -0
- package/constants/index.js +10 -0
- package/environment/index.d.ts +1 -1
- package/environment/index.js +4 -4
- package/http/index.d.ts +1 -0
- package/http/index.js +17 -2
- package/http/index.test.d.ts +1 -0
- package/http/index.test.js +15 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/logger/index.d.ts +1 -6
- package/logger/index.js +1 -8
- package/logger/index.test.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CardanoNetwork = void 0;
|
|
4
|
+
var CardanoNetwork;
|
|
5
|
+
(function (CardanoNetwork) {
|
|
6
|
+
CardanoNetwork["MAINNET"] = "MAINNET";
|
|
7
|
+
CardanoNetwork["PREPROD"] = "PREPROD";
|
|
8
|
+
CardanoNetwork["PREVIEW"] = "PREVIEW";
|
|
9
|
+
CardanoNetwork["UNSET"] = "UNSET";
|
|
10
|
+
})(CardanoNetwork = exports.CardanoNetwork || (exports.CardanoNetwork = {}));
|
package/environment/index.d.ts
CHANGED
package/environment/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Environment = exports.ComputeEnvironment = void 0;
|
|
4
|
-
const
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
5
|
var ComputeEnvironment;
|
|
6
6
|
(function (ComputeEnvironment) {
|
|
7
7
|
ComputeEnvironment["AWS_LAMBDA"] = "aws_lambda";
|
|
@@ -29,14 +29,14 @@ class Environment {
|
|
|
29
29
|
static getCardanoNetwork() {
|
|
30
30
|
try {
|
|
31
31
|
if (process.env.NETWORK) {
|
|
32
|
-
return
|
|
32
|
+
return constants_1.CardanoNetwork[process.env.NETWORK.toUpperCase()];
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
return
|
|
35
|
+
return constants_1.CardanoNetwork.UNSET;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
catch (_a) {
|
|
39
|
-
return
|
|
39
|
+
return constants_1.CardanoNetwork.UNSET;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
static async getIpAddress() {
|
package/http/index.d.ts
CHANGED
package/http/index.js
CHANGED
|
@@ -4,8 +4,23 @@ exports.Response = exports.Request = void 0;
|
|
|
4
4
|
class Request {
|
|
5
5
|
constructor(req) {
|
|
6
6
|
this.getCookie = (key) => {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let cookies = this.headers["Cookie"];
|
|
8
|
+
if (!cookies) {
|
|
9
|
+
cookies = this.headers["cookie"];
|
|
10
|
+
}
|
|
11
|
+
let cookie = this._searchCookie(cookies, key);
|
|
12
|
+
if (!cookie) {
|
|
13
|
+
// koracookiejar is how we get around Lambda's MultiValueHeader lameness
|
|
14
|
+
const koracookiejar = this._searchCookie(cookies, 'koracookiejar');
|
|
15
|
+
console.log(koracookiejar);
|
|
16
|
+
cookie = this._searchCookie(koracookiejar ? decodeURIComponent(koracookiejar).replace(/\|/g, '; ') : undefined, key);
|
|
17
|
+
}
|
|
18
|
+
return cookie;
|
|
19
|
+
};
|
|
20
|
+
this._searchCookie = (cookies, key) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
console.log('COOKIES', cookies);
|
|
23
|
+
return (_b = (_a = cookies === null || cookies === void 0 ? void 0 : cookies.split(/;\s?/gi).find(cookie => cookie.toLowerCase().startsWith(key.toLowerCase()))) === null || _a === void 0 ? void 0 : _a.split('=')) === null || _b === void 0 ? void 0 : _b[1];
|
|
9
24
|
};
|
|
10
25
|
this.method = req.method;
|
|
11
26
|
this.headers = req.headers;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require("./");
|
|
4
|
+
describe('Request Tests', () => {
|
|
5
|
+
it('should find cookie', () => {
|
|
6
|
+
const request = new _1.Request({
|
|
7
|
+
headers: { 'Content-Type': 'application/json' },
|
|
8
|
+
method: 'GET',
|
|
9
|
+
url: new URL('https://preview.handle.me')
|
|
10
|
+
});
|
|
11
|
+
request.headers['Cookie'] = 'abc=123; koracookiejar=abc%3D987|def%3D456|ghi%3D789';
|
|
12
|
+
expect(request.getCookie('abc')).toEqual('123');
|
|
13
|
+
expect(request.getCookie('def')).toEqual('456');
|
|
14
|
+
});
|
|
15
|
+
});
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -33,3 +33,4 @@ Object.defineProperty(exports, "buildMetadata", { enumerable: true, get: functio
|
|
|
33
33
|
__exportStar(require("./handles/utils"), exports);
|
|
34
34
|
__exportStar(require("./handles/api"), exports);
|
|
35
35
|
__exportStar(require("./http"), exports);
|
|
36
|
+
__exportStar(require("./constants"), exports);
|
package/logger/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CardanoNetwork } from '../constants';
|
|
1
2
|
export declare enum LogCategory {
|
|
2
3
|
DEBUG = "DEBUG",
|
|
3
4
|
INFO = "INFO",
|
|
@@ -7,12 +8,6 @@ export declare enum LogCategory {
|
|
|
7
8
|
FATAL = "FATAL",
|
|
8
9
|
NOTIFY = "NOTIFY"
|
|
9
10
|
}
|
|
10
|
-
export declare enum CardanoNetwork {
|
|
11
|
-
MAINNET = "MAINNET",
|
|
12
|
-
PREPROD = "PREPROD",
|
|
13
|
-
PREVIEW = "PREVIEW",
|
|
14
|
-
UNSET = "UNSET"
|
|
15
|
-
}
|
|
16
11
|
export declare class Logger {
|
|
17
12
|
static application: string;
|
|
18
13
|
static network: CardanoNetwork;
|
package/logger/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = exports.
|
|
3
|
+
exports.Logger = exports.LogCategory = void 0;
|
|
4
4
|
const environment_1 = require("../environment");
|
|
5
5
|
// Fix from https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify
|
|
6
6
|
if (!('toJSON' in Error.prototype))
|
|
@@ -25,13 +25,6 @@ var LogCategory;
|
|
|
25
25
|
LogCategory["FATAL"] = "FATAL";
|
|
26
26
|
LogCategory["NOTIFY"] = "NOTIFY";
|
|
27
27
|
})(LogCategory = exports.LogCategory || (exports.LogCategory = {}));
|
|
28
|
-
var CardanoNetwork;
|
|
29
|
-
(function (CardanoNetwork) {
|
|
30
|
-
CardanoNetwork["MAINNET"] = "MAINNET";
|
|
31
|
-
CardanoNetwork["PREPROD"] = "PREPROD";
|
|
32
|
-
CardanoNetwork["PREVIEW"] = "PREVIEW";
|
|
33
|
-
CardanoNetwork["UNSET"] = "UNSET";
|
|
34
|
-
})(CardanoNetwork = exports.CardanoNetwork || (exports.CardanoNetwork = {}));
|
|
35
28
|
class Logger {
|
|
36
29
|
static async initialize() {
|
|
37
30
|
if (process.env.NODE_ENV !== 'test') {
|
package/logger/index.test.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const _1 = require(".");
|
|
4
|
+
const constants_1 = require("../constants");
|
|
4
5
|
describe('Logger Tests', () => {
|
|
5
6
|
it('should log', () => {
|
|
6
7
|
var _a, _b;
|
|
7
8
|
const now = Date.now();
|
|
8
9
|
const logSpy = jest.spyOn(console, 'log');
|
|
9
10
|
_1.Logger.application = 'TEST';
|
|
10
|
-
_1.Logger.network =
|
|
11
|
+
_1.Logger.network = constants_1.CardanoNetwork.UNSET;
|
|
11
12
|
_1.Logger.log({
|
|
12
13
|
message: 'burritos',
|
|
13
14
|
category: _1.LogCategory.ERROR,
|