@koralabs/kora-labs-common 6.4.16 → 6.4.18
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/logger/index.d.ts +4 -1
- package/logger/index.js +6 -4
- package/package.json +4 -1
- package/utils/cbor/index.js +6 -0
- package/utils/index.d.ts +8 -0
- package/utils/index.js +33 -1
package/logger/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export declare enum LogCategory {
|
|
|
6
6
|
WARN = "WARN",
|
|
7
7
|
ERROR = "ERROR",
|
|
8
8
|
FATAL = "FATAL",
|
|
9
|
-
NOTIFY = "NOTIFY"
|
|
9
|
+
NOTIFY = "NOTIFY",
|
|
10
|
+
USER_ISSUE = "USER_ISSUE"
|
|
10
11
|
}
|
|
11
12
|
export declare class Logger {
|
|
12
13
|
static application: string;
|
|
@@ -23,6 +24,7 @@ export declare class Logger {
|
|
|
23
24
|
milliseconds?: number;
|
|
24
25
|
count?: number;
|
|
25
26
|
dimensions?: string[];
|
|
27
|
+
context?: Record<string, unknown>;
|
|
26
28
|
} | string): void;
|
|
27
29
|
static log(args: {
|
|
28
30
|
message: string;
|
|
@@ -31,6 +33,7 @@ export declare class Logger {
|
|
|
31
33
|
milliseconds?: number;
|
|
32
34
|
count?: number;
|
|
33
35
|
dimensions?: string[];
|
|
36
|
+
context?: Record<string, unknown>;
|
|
34
37
|
} | string): void;
|
|
35
38
|
private static log_entry;
|
|
36
39
|
private static colorize;
|
package/logger/index.js
CHANGED
|
@@ -25,6 +25,7 @@ var LogCategory;
|
|
|
25
25
|
LogCategory["ERROR"] = "ERROR";
|
|
26
26
|
LogCategory["FATAL"] = "FATAL";
|
|
27
27
|
LogCategory["NOTIFY"] = "NOTIFY";
|
|
28
|
+
LogCategory["USER_ISSUE"] = "USER_ISSUE";
|
|
28
29
|
})(LogCategory = exports.LogCategory || (exports.LogCategory = {}));
|
|
29
30
|
const ANSI_RESET = '\x1b[0m';
|
|
30
31
|
const ANSI_BLUE = '\x1b[34m';
|
|
@@ -96,10 +97,10 @@ class Logger {
|
|
|
96
97
|
this.log_entry(LogCategory.INFO, args);
|
|
97
98
|
return;
|
|
98
99
|
}
|
|
99
|
-
const { message, category, event, milliseconds, count, dimensions } = args;
|
|
100
|
-
this.log_entry(category !== null && category !== void 0 ? category : LogCategory.INFO, message, event, milliseconds, count, dimensions);
|
|
100
|
+
const { message, category, event, milliseconds, count, dimensions, context } = args;
|
|
101
|
+
this.log_entry(category !== null && category !== void 0 ? category : LogCategory.INFO, message, event, milliseconds, count, dimensions, context);
|
|
101
102
|
}
|
|
102
|
-
static log_entry(category, message, event, milliseconds, count, dimensions) {
|
|
103
|
+
static log_entry(category, message, event, milliseconds, count, dimensions, context) {
|
|
103
104
|
const now = new Date().toISOString();
|
|
104
105
|
message = message.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); // escape double quotes and already escaped escapes
|
|
105
106
|
const logCategory = category !== null && category !== void 0 ? category : LogCategory.INFO;
|
|
@@ -109,6 +110,7 @@ class Logger {
|
|
|
109
110
|
const log_milliseconds = milliseconds != undefined && milliseconds != null ? `, "milliseconds": ${milliseconds}` : '';
|
|
110
111
|
const log_count = count != undefined && count != null ? `, "count": ${count}` : '';
|
|
111
112
|
const log_dimensions = dimensions && Object.keys(dimensions).length ? `, "dimensions": ${JSON.stringify(dimensions)}` : '';
|
|
113
|
+
const log_context = context ? `, "context": ${JSON.stringify(context)}` : '';
|
|
112
114
|
let logFunc = console.log;
|
|
113
115
|
switch (category) {
|
|
114
116
|
case LogCategory.DEBUG:
|
|
@@ -124,7 +126,7 @@ class Logger {
|
|
|
124
126
|
break;
|
|
125
127
|
}
|
|
126
128
|
// PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
|
|
127
|
-
logFunc(`{"network": "${Logger.network}", "application": "${Logger.application}", "category": "${displayCategory}", "message": "${message}"${log_event}, "timestamp": "${now}"${log_milliseconds}${log_count}${log_dimensions} }`);
|
|
129
|
+
logFunc(`{"network": "${Logger.network}", "application": "${Logger.application}", "category": "${displayCategory}", "message": "${message}"${log_event}, "timestamp": "${now}"${log_milliseconds}${log_count}${log_dimensions}${log_context} }`);
|
|
128
130
|
// PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
|
|
129
131
|
}
|
|
130
132
|
static colorize(value, ansiColor) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koralabs/kora-labs-common",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.18",
|
|
4
4
|
"description": "Kora Labs Common Utilities",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -46,5 +46,8 @@
|
|
|
46
46
|
"cbor": "^9.0.2",
|
|
47
47
|
"crc": "^4.3.2",
|
|
48
48
|
"pluralize-esm": "^9.0.5"
|
|
49
|
+
},
|
|
50
|
+
"overrides": {
|
|
51
|
+
"minimatch": "10.2.2"
|
|
49
52
|
}
|
|
50
53
|
}
|
package/utils/cbor/index.js
CHANGED
|
@@ -248,6 +248,12 @@ const getAddressHexFromObject = (obj) => {
|
|
|
248
248
|
return `0x${addressType}${network}${paymentHash}${stakeHash}`;
|
|
249
249
|
};
|
|
250
250
|
const decodeObject = ({ val, constr = null, schema = {}, defaultKeyType = DefaultTextFormat.UTF8, forJson = true }) => {
|
|
251
|
+
if (val === null || val === undefined) {
|
|
252
|
+
if (schema === 'bool' && (0, boolean_1.isBooleanable)(val)) {
|
|
253
|
+
return (0, boolean_1.boolean)(val);
|
|
254
|
+
}
|
|
255
|
+
return val;
|
|
256
|
+
}
|
|
251
257
|
const isMap = val instanceof Map;
|
|
252
258
|
if (isMap) {
|
|
253
259
|
const obj = new Map();
|
package/utils/index.d.ts
CHANGED
|
@@ -21,5 +21,13 @@ export declare const ExcludesFalse: <T>(n?: T | null | undefined) => n is T;
|
|
|
21
21
|
export declare const diff: (lhs: any, rhs: any) => any;
|
|
22
22
|
export declare const mapStringifyReplacer: (_key: any, value: any) => any;
|
|
23
23
|
export declare const mapNoKeysStringifyReplacer: (_key: any, value: any) => any;
|
|
24
|
+
export declare const USER_ISSUE_TRACKING_ID_REGEX: RegExp;
|
|
25
|
+
export declare const createUserIssueTrackingId: ({ timestamp, random }?: {
|
|
26
|
+
timestamp?: number | undefined;
|
|
27
|
+
random?: (() => number) | undefined;
|
|
28
|
+
}) => string;
|
|
29
|
+
export declare const isUserIssueTrackingId: (value: unknown) => value is string;
|
|
30
|
+
export declare const normalizeUserIssueEventSegment: (value: string) => string;
|
|
31
|
+
export declare const buildUserIssueEventKey: (repo: string, flow: string, pathOrFunction: string, step: string) => string;
|
|
24
32
|
export { decodeCborToJson, encodeJsonToDatum, DefaultTextFormat as KeyType } from './cbor';
|
|
25
33
|
export * from './crypto';
|
package/utils/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.KeyType = exports.encodeJsonToDatum = exports.decodeCborToJson = exports.mapNoKeysStringifyReplacer = exports.mapStringifyReplacer = exports.diff = exports.ExcludesFalse = exports.makeObjectWithoutPrototype = exports.isEmptyObject = exports.isDate = exports.hasOwnProperty = exports.isObject = exports.isEmpty = exports.objectHasKeys = exports.getElapsedTime = exports.getSlotNumberFromDate = exports.getDateFromSlot = exports.isAlphaNumeric = exports.isNullEmptyOrUndefined = exports.isNumeric = exports.asyncForEach = exports.awaitForEach = exports.chunk = exports.toADA = exports.toLovelace = exports.delay = void 0;
|
|
17
|
+
exports.KeyType = exports.encodeJsonToDatum = exports.decodeCborToJson = exports.buildUserIssueEventKey = exports.normalizeUserIssueEventSegment = exports.isUserIssueTrackingId = exports.createUserIssueTrackingId = exports.USER_ISSUE_TRACKING_ID_REGEX = exports.mapNoKeysStringifyReplacer = exports.mapStringifyReplacer = exports.diff = exports.ExcludesFalse = exports.makeObjectWithoutPrototype = exports.isEmptyObject = exports.isDate = exports.hasOwnProperty = exports.isObject = exports.isEmpty = exports.objectHasKeys = exports.getElapsedTime = exports.getSlotNumberFromDate = exports.getDateFromSlot = exports.isAlphaNumeric = exports.isNullEmptyOrUndefined = exports.isNumeric = exports.asyncForEach = exports.awaitForEach = exports.chunk = exports.toADA = exports.toLovelace = exports.delay = void 0;
|
|
18
18
|
const delay = (ms) => {
|
|
19
19
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
20
|
};
|
|
@@ -163,6 +163,38 @@ const mapNoKeysStringifyReplacer = (_key, value) => {
|
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
exports.mapNoKeysStringifyReplacer = mapNoKeysStringifyReplacer;
|
|
166
|
+
const BASE36_CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
167
|
+
const USER_ISSUE_RANDOM_SEGMENT_LENGTH = 6;
|
|
168
|
+
exports.USER_ISSUE_TRACKING_ID_REGEX = /^UI-[0-9a-z]+-[0-9a-z]{6}$/;
|
|
169
|
+
const createUserIssueTrackingId = ({ timestamp = Date.now(), random = Math.random } = {}) => {
|
|
170
|
+
const timestampBase36 = Math.max(0, Math.floor(timestamp)).toString(36);
|
|
171
|
+
let randomSegment = '';
|
|
172
|
+
for (let i = 0; i < USER_ISSUE_RANDOM_SEGMENT_LENGTH; i++) {
|
|
173
|
+
const sample = random();
|
|
174
|
+
const clamped = Number.isFinite(sample) ? Math.min(0.999999999, Math.max(0, sample)) : 0;
|
|
175
|
+
const idx = Math.floor(clamped * BASE36_CHARS.length);
|
|
176
|
+
randomSegment += BASE36_CHARS[idx];
|
|
177
|
+
}
|
|
178
|
+
return `UI-${timestampBase36}-${randomSegment}`;
|
|
179
|
+
};
|
|
180
|
+
exports.createUserIssueTrackingId = createUserIssueTrackingId;
|
|
181
|
+
const isUserIssueTrackingId = (value) => {
|
|
182
|
+
return typeof value === 'string' && exports.USER_ISSUE_TRACKING_ID_REGEX.test(value);
|
|
183
|
+
};
|
|
184
|
+
exports.isUserIssueTrackingId = isUserIssueTrackingId;
|
|
185
|
+
const normalizeUserIssueEventSegment = (value) => {
|
|
186
|
+
return value
|
|
187
|
+
.toLowerCase()
|
|
188
|
+
.replace(/[^a-z0-9]+/g, '_')
|
|
189
|
+
.replace(/^_+|_+$/g, '')
|
|
190
|
+
.replace(/_+/g, '_');
|
|
191
|
+
};
|
|
192
|
+
exports.normalizeUserIssueEventSegment = normalizeUserIssueEventSegment;
|
|
193
|
+
const buildUserIssueEventKey = (repo, flow, pathOrFunction, step) => {
|
|
194
|
+
const segment = (value) => (0, exports.normalizeUserIssueEventSegment)(value) || 'unknown';
|
|
195
|
+
return `user_issue.${segment(repo)}.${segment(flow)}.${segment(pathOrFunction)}.${segment(step)}`;
|
|
196
|
+
};
|
|
197
|
+
exports.buildUserIssueEventKey = buildUserIssueEventKey;
|
|
166
198
|
var cbor_1 = require("./cbor");
|
|
167
199
|
Object.defineProperty(exports, "decodeCborToJson", { enumerable: true, get: function () { return cbor_1.decodeCborToJson; } });
|
|
168
200
|
Object.defineProperty(exports, "encodeJsonToDatum", { enumerable: true, get: function () { return cbor_1.encodeJsonToDatum; } });
|