@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.
@@ -0,0 +1,6 @@
1
+ export declare enum CardanoNetwork {
2
+ MAINNET = "MAINNET",
3
+ PREPROD = "PREPROD",
4
+ PREVIEW = "PREVIEW",
5
+ UNSET = "UNSET"
6
+ }
@@ -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 = {}));
@@ -1,4 +1,4 @@
1
- import { CardanoNetwork } from "../logger";
1
+ import { CardanoNetwork } from "../constants";
2
2
  export declare enum ComputeEnvironment {
3
3
  AWS_LAMBDA = "aws_lambda",
4
4
  AWS_FARGATE = "aws_fargate",
@@ -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 logger_1 = require("../logger");
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 logger_1.CardanoNetwork[process.env.NETWORK.toUpperCase()];
32
+ return constants_1.CardanoNetwork[process.env.NETWORK.toUpperCase()];
33
33
  }
34
34
  else {
35
- return logger_1.CardanoNetwork.UNSET;
35
+ return constants_1.CardanoNetwork.UNSET;
36
36
  }
37
37
  }
38
38
  catch (_a) {
39
- return logger_1.CardanoNetwork.UNSET;
39
+ return constants_1.CardanoNetwork.UNSET;
40
40
  }
41
41
  }
42
42
  static async getIpAddress() {
package/http/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare class Request {
10
10
  body?: string;
11
11
  });
12
12
  getCookie: (key: string) => string | undefined;
13
+ _searchCookie: (cookies: string | undefined, key: string) => string | undefined;
13
14
  }
14
15
  export interface Headers {
15
16
  [key: string]: string;
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
- var _a, _b, _c;
8
- return (_c = (_b = (_a = this.headers["Cookie"]) === null || _a === void 0 ? void 0 : _a.split(/;\s?/gi).find(cookie => cookie.toLowerCase().startsWith(key.toLowerCase()))) === null || _b === void 0 ? void 0 : _b.split('=')) === null || _c === void 0 ? void 0 : _c[1];
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
@@ -9,3 +9,4 @@ export { buildMetadata } from './handles/buildMetadata';
9
9
  export * from './handles/utils';
10
10
  export * from './handles/api';
11
11
  export * from './http';
12
+ export * from './constants';
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.CardanoNetwork = exports.LogCategory = void 0;
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') {
@@ -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 = _1.CardanoNetwork.UNSET;
11
+ _1.Logger.network = constants_1.CardanoNetwork.UNSET;
11
12
  _1.Logger.log({
12
13
  message: 'burritos',
13
14
  category: _1.LogCategory.ERROR,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koralabs/kora-labs-common",
3
- "version": "2.6.9",
3
+ "version": "2.7.0",
4
4
  "description": "Kora Labs Common Utilities",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",