@koralabs/kora-labs-common 3.0.0 → 3.1.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.
Files changed (59) hide show
  1. package/constants/index.d.ts +6 -0
  2. package/constants/index.js +10 -0
  3. package/{lib/environment → environment}/index.d.ts +1 -1
  4. package/environment/index.js +122 -0
  5. package/handles/api.d.ts +10 -0
  6. package/handles/api.js +39 -0
  7. package/{lib/handles → handles}/buildMetadata.js +7 -1
  8. package/{lib/handles → handles}/constants.d.ts +3 -0
  9. package/{lib/handles → handles}/constants.js +9 -1
  10. package/{lib/handles → handles}/interfaces.d.ts +71 -0
  11. package/http/index.d.ts +34 -0
  12. package/http/index.js +45 -0
  13. package/http/index.test.js +15 -0
  14. package/{lib/index.d.ts → index.d.ts} +3 -0
  15. package/{lib/index.js → index.js} +3 -0
  16. package/{lib/logger → logger}/index.d.ts +1 -6
  17. package/{lib/logger → logger}/index.js +14 -32
  18. package/{lib/logger → logger}/index.test.js +6 -2
  19. package/package.json +15 -7
  20. package/protectedWords/index.js +352 -0
  21. package/{lib/protectedWords → protectedWords}/index.test.js +3 -12
  22. package/{lib/utils → utils}/cbor/index.js +10 -19
  23. package/utils/cbor/index.test.d.ts +1 -0
  24. package/{lib/utils → utils}/cbor/index.test.js +81 -90
  25. package/{lib/utils → utils}/cbor/schema/subHandleSettings.js +4 -1
  26. package/utils/crypto/index.d.ts +159 -0
  27. package/utils/crypto/index.js +74 -0
  28. package/{lib/utils → utils}/index.d.ts +1 -0
  29. package/{lib/utils → utils}/index.js +8 -16
  30. package/LICENSE +0 -674
  31. package/README.md +0 -1
  32. package/lib/environment/index.js +0 -137
  33. package/lib/protectedWords/index.js +0 -363
  34. /package/{lib/handles → handles}/buildMetadata.d.ts +0 -0
  35. /package/{lib/handles → handles}/buildMetadata.test.d.ts +0 -0
  36. /package/{lib/handles → handles}/buildMetadata.test.js +0 -0
  37. /package/{lib/handles → handles}/interfaces.js +0 -0
  38. /package/{lib/handles → handles}/utils.d.ts +0 -0
  39. /package/{lib/handles → handles}/utils.js +0 -0
  40. /package/{lib/handles → handles}/validation.d.ts +0 -0
  41. /package/{lib/handles → handles}/validation.js +0 -0
  42. /package/{lib/handles → handles}/validation.test.d.ts +0 -0
  43. /package/{lib/handles → handles}/validation.test.js +0 -0
  44. /package/{lib/logger → http}/index.test.d.ts +0 -0
  45. /package/{lib/protectedWords → logger}/index.test.d.ts +0 -0
  46. /package/{lib/protectedWords → protectedWords}/index.d.ts +0 -0
  47. /package/{lib/utils/cbor → protectedWords}/index.test.d.ts +0 -0
  48. /package/{lib/protectedWords → protectedWords}/protectedWords.d.ts +0 -0
  49. /package/{lib/protectedWords → protectedWords}/protectedWords.js +0 -0
  50. /package/{lib/utils → utils}/cbor/index.d.ts +0 -0
  51. /package/{lib/utils → utils}/cbor/schema/designer.d.ts +0 -0
  52. /package/{lib/utils → utils}/cbor/schema/designer.js +0 -0
  53. /package/{lib/utils → utils}/cbor/schema/handleData.d.ts +0 -0
  54. /package/{lib/utils → utils}/cbor/schema/handleData.js +0 -0
  55. /package/{lib/utils → utils}/cbor/schema/portal.d.ts +0 -0
  56. /package/{lib/utils → utils}/cbor/schema/portal.js +0 -0
  57. /package/{lib/utils → utils}/cbor/schema/socials.d.ts +0 -0
  58. /package/{lib/utils → utils}/cbor/schema/socials.js +0 -0
  59. /package/{lib/utils → utils}/cbor/schema/subHandleSettings.d.ts +0 -0
@@ -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",
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Environment = exports.ComputeEnvironment = void 0;
4
+ const constants_1 = require("../constants");
5
+ var ComputeEnvironment;
6
+ (function (ComputeEnvironment) {
7
+ ComputeEnvironment["AWS_LAMBDA"] = "aws_lambda";
8
+ ComputeEnvironment["AWS_FARGATE"] = "aws_fargate";
9
+ ComputeEnvironment["AWS_EC2"] = "aws_ec2";
10
+ ComputeEnvironment["AWS_OTHER"] = "aws_other";
11
+ ComputeEnvironment["OTHER"] = "other";
12
+ })(ComputeEnvironment = exports.ComputeEnvironment || (exports.ComputeEnvironment = {}));
13
+ class Environment {
14
+ static async getComputeEnvironment() {
15
+ if (process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.AWS_EXECUTION_ENV) {
16
+ return ComputeEnvironment.AWS_LAMBDA;
17
+ }
18
+ if (process.env.ECS_CLUSTER) {
19
+ return ComputeEnvironment.AWS_FARGATE;
20
+ }
21
+ if (await Environment.getEc2InstanceName()) {
22
+ return ComputeEnvironment.AWS_EC2;
23
+ }
24
+ if (process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION) {
25
+ return ComputeEnvironment.AWS_OTHER;
26
+ }
27
+ return ComputeEnvironment.OTHER;
28
+ }
29
+ static getCardanoNetwork() {
30
+ try {
31
+ if (process.env.NETWORK) {
32
+ return constants_1.CardanoNetwork[process.env.NETWORK.toUpperCase()];
33
+ }
34
+ else {
35
+ return constants_1.CardanoNetwork.UNSET;
36
+ }
37
+ }
38
+ catch (_a) {
39
+ return constants_1.CardanoNetwork.UNSET;
40
+ }
41
+ }
42
+ static async getIpAddress() {
43
+ var _a, _b;
44
+ let prv;
45
+ let pub;
46
+ if (await Environment.getComputeEnvironment() == ComputeEnvironment.AWS_EC2) {
47
+ try {
48
+ const response = await fetch('http://169.254.169.254/latest/meta-data/local-ipv4');
49
+ prv = await response.text();
50
+ }
51
+ catch (_c) {
52
+ // swallow
53
+ }
54
+ try {
55
+ const response = await fetch('http://169.254.169.254/latest/meta-data/public-ipv4');
56
+ pub = await response.text();
57
+ }
58
+ catch (_d) {
59
+ // swallow
60
+ }
61
+ if (prv || pub) {
62
+ return { private: prv !== null && prv !== void 0 ? prv : null, public: pub !== null && pub !== void 0 ? pub : null };
63
+ }
64
+ }
65
+ if (await Environment.getComputeEnvironment() == ComputeEnvironment.AWS_EC2) {
66
+ const metadata = await Environment.getEcsTaskMetaData();
67
+ return { private: (_b = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.Networks[0]) === null || _a === void 0 ? void 0 : _a.IPv4Addresses[0]) !== null && _b !== void 0 ? _b : null, public: null };
68
+ }
69
+ return null;
70
+ }
71
+ static async getEc2InstanceName() {
72
+ try {
73
+ const response = await fetch('http://169.254.169.254/latest/meta-data/tags/instance/Name');
74
+ return response.text();
75
+ }
76
+ catch (err) {
77
+ // swallow
78
+ }
79
+ try {
80
+ const response = await fetch('http://169.254.169.254/latest/meta-data/instance-id');
81
+ return response.text();
82
+ }
83
+ catch (err) {
84
+ // swallow
85
+ }
86
+ return null;
87
+ }
88
+ static async getEcsTaskMetaData() {
89
+ try {
90
+ const response = await fetch('http://169.254.170.2/v2/metadata');
91
+ return await response.json();
92
+ }
93
+ catch (err) {
94
+ return null;
95
+ }
96
+ }
97
+ static async getPotentialApplicationName() {
98
+ var _a, _b;
99
+ if (process.env.APPLICATION_NAME) {
100
+ return process.env.APPLICATION_NAME;
101
+ }
102
+ if (await Environment.getComputeEnvironment() == ComputeEnvironment.AWS_LAMBDA) {
103
+ return (_a = process.env.AWS_LAMBDA_FUNCTION_NAME) !== null && _a !== void 0 ? _a : null;
104
+ }
105
+ if (await Environment.getComputeEnvironment() == ComputeEnvironment.AWS_FARGATE) {
106
+ return (_b = process.env.ECS_CLUSTER) !== null && _b !== void 0 ? _b : null;
107
+ }
108
+ if (await Environment.getComputeEnvironment() == ComputeEnvironment.AWS_EC2) {
109
+ const ec2_name = await Environment.getEc2InstanceName();
110
+ if (ec2_name) {
111
+ return ec2_name;
112
+ }
113
+ }
114
+ try {
115
+ return process.cwd();
116
+ }
117
+ catch (_c) {
118
+ return null;
119
+ }
120
+ }
121
+ }
122
+ exports.Environment = Environment;
@@ -0,0 +1,10 @@
1
+ export declare class HandlesApi {
2
+ private static _network?;
3
+ private static _host?;
4
+ static init(options?: {
5
+ network?: string;
6
+ host?: string;
7
+ }): void;
8
+ static getHandle(handle: string): Promise<any>;
9
+ static apiRequest(url: string, headers?: Record<string, string>, body?: any): Promise<any>;
10
+ }
package/handles/api.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HandlesApi = void 0;
4
+ const constants_1 = require("./constants");
5
+ // WHEN WE REVAMP THE SDK, THIS CAN ALL MOVE THERE
6
+ class HandlesApi {
7
+ static init(options = { network: 'mainnet' }) {
8
+ if (options.host) {
9
+ HandlesApi._host = options.host;
10
+ }
11
+ else {
12
+ HandlesApi._host = `https://${options.network == 'mainnet' ? '' : `${options.network}.`}api.handle.me`;
13
+ }
14
+ HandlesApi._network = options.network;
15
+ }
16
+ static async getHandle(handle) {
17
+ if (!handle) {
18
+ throw new Error("handle is required");
19
+ }
20
+ return await this.apiRequest(`/handles/${handle}`);
21
+ }
22
+ static async apiRequest(url, headers, body) {
23
+ body;
24
+ if (!HandlesApi._host) {
25
+ throw new Error('HandlesApi has not been initialized. Please call HandlesApi.init(<network>)');
26
+ }
27
+ if (!headers) {
28
+ headers = {
29
+ "Accepts": "application/json",
30
+ "User-Agent": constants_1.KORA_USER_AGENT,
31
+ "api-key": constants_1.HANDLES_API_KEY
32
+ };
33
+ }
34
+ // We should probably use cross-fetch since this might get called on the front-end as well
35
+ const response = (await fetch(`${HandlesApi._host}${url}`, { headers })).json();
36
+ return response;
37
+ }
38
+ }
39
+ exports.HandlesApi = HandlesApi;
@@ -45,7 +45,13 @@ const buildMetadata = ({ handleName, cid, ogNumber }) => {
45
45
  version: 1
46
46
  };
47
47
  if (isSubHandle) {
48
- metadata = Object.assign(Object.assign({}, metadata), { sub_rarity: (0, utils_1.getRarity)(subHandleName), sub_length: subHandleName.length, sub_characters: buildCharacters(subHandleName), sub_numeric_modifiers: buildNumericModifiers(subHandleName) });
48
+ metadata = {
49
+ ...metadata,
50
+ sub_rarity: (0, utils_1.getRarity)(subHandleName),
51
+ sub_length: subHandleName.length,
52
+ sub_characters: buildCharacters(subHandleName),
53
+ sub_numeric_modifiers: buildNumericModifiers(subHandleName)
54
+ };
49
55
  }
50
56
  return metadata;
51
57
  };
@@ -9,3 +9,6 @@ export declare const REGEX_SPLIT_ON_CHARS: RegExp;
9
9
  export declare const REGEX_SPLIT_ON_NUMS: RegExp;
10
10
  export declare const REGEX_HANDLE: RegExp;
11
11
  export declare const REGEX_SUB_HANDLE: RegExp;
12
+ export declare const isProduction: () => boolean;
13
+ export declare const HANDLES_API_KEY: string;
14
+ export declare const KORA_USER_AGENT: string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
+ var _a, _b;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REGEX_SUB_HANDLE = exports.REGEX_HANDLE = exports.REGEX_SPLIT_ON_NUMS = exports.REGEX_SPLIT_ON_CHARS = exports.RESPONSE_NOT_ALLOWED = exports.RESPONSE_INVALID_HANDLE_FORMAT = exports.RESPONSE_UNAVAILABLE_LEGENDARY = exports.RESPONSE_UNAVAILABLE_RESERVED = exports.RESPONSE_UNAVAILABLE_ACTIVE_SESSION = exports.RESPONSE_UNAVAILABLE_PAID = exports.RESPONSE_AVAILABLE = void 0;
4
+ exports.KORA_USER_AGENT = exports.HANDLES_API_KEY = exports.isProduction = exports.REGEX_SUB_HANDLE = exports.REGEX_HANDLE = exports.REGEX_SPLIT_ON_NUMS = exports.REGEX_SPLIT_ON_CHARS = exports.RESPONSE_NOT_ALLOWED = exports.RESPONSE_INVALID_HANDLE_FORMAT = exports.RESPONSE_UNAVAILABLE_LEGENDARY = exports.RESPONSE_UNAVAILABLE_RESERVED = exports.RESPONSE_UNAVAILABLE_ACTIVE_SESSION = exports.RESPONSE_UNAVAILABLE_PAID = exports.RESPONSE_AVAILABLE = void 0;
4
5
  exports.RESPONSE_AVAILABLE = 'Yay! This handle is available.';
5
6
  exports.RESPONSE_UNAVAILABLE_PAID = 'Sorry! This Handle is pending mint or already minted.';
6
7
  exports.RESPONSE_UNAVAILABLE_ACTIVE_SESSION = 'Pending purchase. Try a different variation.';
@@ -12,3 +13,10 @@ exports.REGEX_SPLIT_ON_CHARS = /([0-9a-z]+)[@_.-]*/g;
12
13
  exports.REGEX_SPLIT_ON_NUMS = /([a-z]+)[0-9]*/g;
13
14
  exports.REGEX_HANDLE = new RegExp(/^[a-zA-Z0-9_.-]{1,15}$/);
14
15
  exports.REGEX_SUB_HANDLE = new RegExp(/(?:^[a-z0-9_.-]{1,15}$)|(?:^(?!.{29})[a-z0-9_.-]+@[a-z0-9_.-]{1,15}$)/g);
16
+ const isProduction = () => {
17
+ var _a;
18
+ return ((_a = process.env.NODE_ENV) === null || _a === void 0 ? void 0 : _a.trim()) === 'production' && process.env.NETWORK == 'MAINNET';
19
+ };
20
+ exports.isProduction = isProduction;
21
+ exports.HANDLES_API_KEY = (0, exports.isProduction)() ? (_a = process.env.HANDLES_API_KEY) !== null && _a !== void 0 ? _a : '' : '';
22
+ exports.KORA_USER_AGENT = (_b = process.env.KORA_USER_AGENT) !== null && _b !== void 0 ? _b : '';
@@ -305,4 +305,75 @@ export interface ReservedOrProtected {
305
305
  reserved?: string[];
306
306
  protected: ProtectedWord[];
307
307
  }
308
+ /**
309
+ * Example: If you have 10 handles in your wallet, the new price is X
310
+ *
311
+ * {
312
+ * "0x{policyId}${assetName(optional)}": {
313
+ * 10: 10,
314
+ * 20: 20,
315
+ * 30: 30
316
+ * }
317
+ * }
318
+ *
319
+ */
320
+ export interface MintHandleDiscount {
321
+ [policyAndAssetName: string]: {
322
+ [ownedAmount: number]: number;
323
+ };
324
+ }
325
+ /**
326
+ * Example: If you have 10 handles in your wallet, the new price is X
327
+ *
328
+ * [
329
+ * ['0x000000000000000000000000000000000000000000000000000000027465737433', [[1, 35000000],[1, 35000000]]],
330
+ * ['0x000000000000000000000000000000000000000000000000000000027465737431', [[2, 30000000]]],
331
+ * ['0x0000000000000000000000000000000000000000000000000000000274657374', [[4, 0]]]
332
+ * ]
333
+ *
334
+ */
335
+ export type MintHandleDiscountArray = [string, [number, number]][];
336
+ export interface CollectionInfo {
337
+ paymentAddress: string;
338
+ referenceTokenAddress?: string;
339
+ collectionName: string;
340
+ collectionImage: string;
341
+ royaltyAddress: string;
342
+ royaltyPercentage: number;
343
+ relatedPolicyIds: string[];
344
+ nsfw: boolean;
345
+ }
346
+ export type MintConfig = [
347
+ string,
348
+ [
349
+ number,
350
+ number
351
+ ][]
352
+ ];
353
+ export type MintHandleSettingsAsset = [
354
+ string,
355
+ [
356
+ string,
357
+ number
358
+ ],
359
+ number,
360
+ number,
361
+ // valid until timestamp
362
+ MintHandleDiscount | MintHandleDiscountArray
363
+ ];
364
+ export interface MintHandleSettingsDetails {
365
+ collectionName: string;
366
+ collectionImage: string;
367
+ lastEditingContractHash: string;
368
+ mintingPolicyId: string;
369
+ relatedPolicyIds?: string[];
370
+ contractVersion?: number;
371
+ nsfw: boolean;
372
+ }
373
+ export type MintHandleSettings = [
374
+ string,
375
+ string,
376
+ MintHandleSettingsAsset[],
377
+ MintHandleSettingsDetails
378
+ ];
308
379
  export {};
@@ -0,0 +1,34 @@
1
+ export declare class Request {
2
+ method: string;
3
+ headers: Headers;
4
+ url: URL;
5
+ body?: string;
6
+ constructor(req: {
7
+ method: string;
8
+ headers: Headers;
9
+ url: URL;
10
+ body?: string;
11
+ });
12
+ getCookie: (key: string) => string | undefined;
13
+ _searchCookie: (cookies: string | undefined, key: string) => string | undefined;
14
+ }
15
+ export interface Headers {
16
+ [key: string]: string;
17
+ }
18
+ export declare class Response {
19
+ body: any;
20
+ headers: Headers;
21
+ cookies: string[];
22
+ status: number;
23
+ constructor(res: {
24
+ body?: string;
25
+ headers?: Headers;
26
+ status?: number;
27
+ cookies?: string[];
28
+ });
29
+ setCookie: (key: string, value: string, options?: {
30
+ domain: string;
31
+ maxAge: number;
32
+ path: string;
33
+ }) => void;
34
+ }
package/http/index.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Response = exports.Request = void 0;
4
+ class Request {
5
+ constructor(req) {
6
+ this.getCookie = (key) => {
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];
24
+ };
25
+ this.method = req.method;
26
+ this.headers = req.headers;
27
+ this.url = req.url;
28
+ this.body = req.body;
29
+ }
30
+ }
31
+ exports.Request = Request;
32
+ class Response {
33
+ constructor(res) {
34
+ var _a, _b, _c;
35
+ this.cookies = [];
36
+ this.setCookie = (key, value, options) => {
37
+ this.cookies.push(`${key}=${value}; ${(options === null || options === void 0 ? void 0 : options.domain) ? `Domain=${options.domain}; ` : ''}${(options === null || options === void 0 ? void 0 : options.maxAge) ? `Max-Age=${options.maxAge}; ` : ''}${(options === null || options === void 0 ? void 0 : options.path) ? `Path=${options.path}; ` : ''}Secure; HttpOnly`);
38
+ };
39
+ this.body = res === null || res === void 0 ? void 0 : res.body;
40
+ this.headers = (_a = res === null || res === void 0 ? void 0 : res.headers) !== null && _a !== void 0 ? _a : {};
41
+ this.status = (_b = res === null || res === void 0 ? void 0 : res.status) !== null && _b !== void 0 ? _b : 200;
42
+ this.cookies = (_c = res === null || res === void 0 ? void 0 : res.cookies) !== null && _c !== void 0 ? _c : [];
43
+ }
44
+ }
45
+ exports.Response = Response;
@@ -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
+ });
@@ -7,3 +7,6 @@ export * from './utils';
7
7
  export { ProtectedWords } from './protectedWords';
8
8
  export { buildMetadata } from './handles/buildMetadata';
9
9
  export * from './handles/utils';
10
+ export * from './handles/api';
11
+ export * from './http';
12
+ export * from './constants';
@@ -31,3 +31,6 @@ Object.defineProperty(exports, "ProtectedWords", { enumerable: true, get: functi
31
31
  var buildMetadata_1 = require("./handles/buildMetadata");
32
32
  Object.defineProperty(exports, "buildMetadata", { enumerable: true, get: function () { return buildMetadata_1.buildMetadata; } });
33
33
  __exportStar(require("./handles/utils"), exports);
34
+ __exportStar(require("./handles/api"), exports);
35
+ __exportStar(require("./http"), exports);
36
+ __exportStar(require("./constants"), exports);
@@ -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;
@@ -1,15 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Logger = exports.CardanoNetwork = exports.LogCategory = void 0;
3
+ exports.Logger = exports.LogCategory = void 0;
13
4
  const environment_1 = require("../environment");
14
5
  // Fix from https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify
15
6
  if (!('toJSON' in Error.prototype))
@@ -34,31 +25,22 @@ var LogCategory;
34
25
  LogCategory["FATAL"] = "FATAL";
35
26
  LogCategory["NOTIFY"] = "NOTIFY";
36
27
  })(LogCategory = exports.LogCategory || (exports.LogCategory = {}));
37
- var CardanoNetwork;
38
- (function (CardanoNetwork) {
39
- CardanoNetwork["MAINNET"] = "MAINNET";
40
- CardanoNetwork["PREPROD"] = "PREPROD";
41
- CardanoNetwork["PREVIEW"] = "PREVIEW";
42
- CardanoNetwork["UNSET"] = "UNSET";
43
- })(CardanoNetwork = exports.CardanoNetwork || (exports.CardanoNetwork = {}));
44
28
  class Logger {
45
- static initialize() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- if (process.env.NODE_ENV !== 'test') {
48
- if (!Logger.application) {
49
- const potentialName = yield environment_1.Environment.getPotentialApplicationName();
50
- if (!potentialName) {
51
- throw new Error('Logger.application must be set!');
52
- }
53
- Logger.application = potentialName;
29
+ static async initialize() {
30
+ if (process.env.NODE_ENV !== 'test') {
31
+ if (!Logger.application) {
32
+ const potentialName = await environment_1.Environment.getPotentialApplicationName();
33
+ if (!potentialName) {
34
+ throw new Error('Logger.application must be set!');
54
35
  }
36
+ Logger.application = potentialName;
55
37
  }
56
- else {
57
- Logger.application = 'TEST';
58
- }
59
- this.network = environment_1.Environment.getCardanoNetwork();
60
- Logger.isInitialized = true;
61
- });
38
+ }
39
+ else {
40
+ Logger.application = 'TEST';
41
+ }
42
+ this.network = environment_1.Environment.getCardanoNetwork();
43
+ Logger.isInitialized = true;
62
44
  }
63
45
  static log(args) {
64
46
  if (!Logger.isInitialized)
@@ -1,10 +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', () => {
7
+ var _a, _b;
6
8
  const now = Date.now();
7
9
  const logSpy = jest.spyOn(console, 'log');
10
+ _1.Logger.application = 'TEST';
11
+ _1.Logger.network = constants_1.CardanoNetwork.UNSET;
8
12
  _1.Logger.log({
9
13
  message: 'burritos',
10
14
  category: _1.LogCategory.ERROR,
@@ -22,9 +26,9 @@ describe('Logger Tests', () => {
22
26
  dimensions: ['taco'],
23
27
  event: 'test.log',
24
28
  message: 'burritos',
25
- network: "UNSET",
29
+ network: (_b = (_a = process.env.NETWORK) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : "UNSET",
26
30
  milliseconds: now,
27
- timestamp: expect.stringMatching(/[0-9\-]+T[0-9\:\.]+Z/)
31
+ timestamp: expect.stringMatching(/[0-9-]+T[0-9:.]+Z/)
28
32
  });
29
33
  });
30
34
  });
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@koralabs/kora-labs-common",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Kora Labs Common Utilities",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
7
  "homepage": "https://github.com/koralabs/kora-labs-common",
8
8
  "repository": {
9
9
  "type": "git",
@@ -12,19 +12,28 @@
12
12
  "contributors": [
13
13
  {
14
14
  "name": "BigIrishLion"
15
+ },
16
+ {
17
+ "name": "papag00se"
15
18
  }
16
19
  ],
17
20
  "scripts": {
21
+ "lint": "eslint . --ext .ts",
18
22
  "test": "node --experimental-vm-modules node_modules/.bin/jest",
19
23
  "build": "tsc",
20
- "npm:publish": "yarn build && yarn publish"
24
+ "npm:publish": "yarn build && cp package.json ./lib/package.json && (cd ./lib && npm publish)"
21
25
  },
22
26
  "author": "",
23
27
  "license": "ISC",
24
28
  "devDependencies": {
29
+ "@aws-sdk/client-dynamodb": "^3.549.0",
30
+ "@aws-sdk/lib-dynamodb": "^3.549.0",
25
31
  "@types/jest": "^28.1.1",
26
32
  "@types/node": "^18.11.17",
27
33
  "@types/pluralize": "^0.0.29",
34
+ "@typescript-eslint/eslint-plugin": "^7.6.0",
35
+ "@typescript-eslint/parser": "^7.6.0",
36
+ "eslint": "^8.57.0",
28
37
  "jest": "^28.1.1",
29
38
  "ts-jest": "^28.0.4",
30
39
  "typescript": "^4.7.3"
@@ -35,7 +44,6 @@
35
44
  "pluralize": "^8.0.0"
36
45
  },
37
46
  "files": [
38
- "bin",
39
- "lib"
47
+ "*"
40
48
  ]
41
- }
49
+ }