@intuned/runtime-dev 0.1.0-test.13 → 0.1.0-test.15

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 (97) hide show
  1. package/bin/intuned-api-run +1 -1
  2. package/bin/intuned-auth-session-check +1 -1
  3. package/bin/intuned-auth-session-create +1 -1
  4. package/bin/intuned-auth-session-load +1 -1
  5. package/bin/intuned-auth-session-refresh +1 -1
  6. package/bin/intuned-browser-save-state +1 -1
  7. package/bin/intuned-browser-start +1 -1
  8. package/bin/intuned-build +1 -1
  9. package/bin/intuned-ts-check +1 -1
  10. package/dist/commands/api/run.js +83 -156
  11. package/dist/commands/auth-sessions/load.js +20 -20
  12. package/dist/commands/auth-sessions/run-check.js +39 -45
  13. package/dist/commands/auth-sessions/run-create.js +74 -84
  14. package/dist/commands/browser/save-state.js +7 -12
  15. package/dist/commands/browser/start-browser.js +4 -7
  16. package/dist/commands/build.js +62 -96
  17. package/dist/commands/common/browserUtils.js +30 -41
  18. package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
  19. package/dist/commands/common/getDefaultExportFromFile.js +0 -12
  20. package/dist/commands/common/getFirstLineNumber.js +83 -90
  21. package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +2 -1
  22. package/dist/commands/common/sendMessageToClient.js +2 -4
  23. package/dist/commands/common/utils/fileUtils.js +16 -16
  24. package/dist/commands/common/utils/settings.js +18 -16
  25. package/dist/commands/common/utils/unixSocket.js +36 -43
  26. package/dist/commands/common/utils/webTemplate.js +19 -25
  27. package/dist/commands/interface/run.js +133 -139
  28. package/dist/commands/ts-check.js +41 -44
  29. package/dist/common/Logger/Logger/index.js +46 -40
  30. package/dist/common/Logger/Logger/types.js +1 -1
  31. package/dist/common/Logger/index.js +46 -40
  32. package/dist/common/Logger/types.js +1 -1
  33. package/dist/common/asyncLocalStorage/index.js +4 -4
  34. package/dist/common/cleanEnvironmentVariables.js +9 -11
  35. package/dist/common/constants.js +1 -1
  36. package/dist/common/contextStorageStateHelpers.js +38 -36
  37. package/dist/common/getPlaywrightConstructs.js +158 -187
  38. package/dist/common/jwtTokenManager.js +61 -74
  39. package/dist/common/runApi/errors.js +121 -130
  40. package/dist/common/runApi/index.js +231 -217
  41. package/dist/common/runApi/types.js +41 -55
  42. package/dist/common/settingsSchema.js +6 -9
  43. package/dist/common/telemetry.js +16 -27
  44. package/dist/index.js +3 -3
  45. package/dist/runtime/RunError.js +10 -10
  46. package/dist/runtime/downloadDirectory.js +10 -10
  47. package/dist/runtime/enums.d.ts +11 -1
  48. package/dist/runtime/enums.js +12 -12
  49. package/dist/runtime/export.d.ts +202 -1
  50. package/dist/runtime/extendPayload.js +12 -12
  51. package/dist/runtime/extendTimeout.js +20 -19
  52. package/dist/runtime/index.js +1 -1
  53. package/dist/runtime/requestMoreInfo.js +14 -14
  54. package/dist/runtime/runInfo.js +12 -11
  55. package/package.json +2 -3
  56. package/dist/commands/api/run.ts +0 -105
  57. package/dist/commands/auth-sessions/load.ts +0 -30
  58. package/dist/commands/auth-sessions/run-check.ts +0 -51
  59. package/dist/commands/auth-sessions/run-create.ts +0 -91
  60. package/dist/commands/browser/save-state.ts +0 -14
  61. package/dist/commands/browser/start-browser.ts +0 -11
  62. package/dist/commands/build.ts +0 -78
  63. package/dist/commands/common/browserUtils.ts +0 -45
  64. package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
  65. package/dist/commands/common/getFirstLineNumber.ts +0 -96
  66. package/dist/commands/common/sendMessageToClient.ts +0 -3
  67. package/dist/commands/common/utils/fileUtils.ts +0 -23
  68. package/dist/commands/common/utils/settings.ts +0 -22
  69. package/dist/commands/common/utils/unixSocket.ts +0 -38
  70. package/dist/commands/common/utils/webTemplate.ts +0 -22
  71. package/dist/commands/interface/run.ts +0 -156
  72. package/dist/commands/ts-check.ts +0 -50
  73. package/dist/common/Logger/Logger/index.ts +0 -53
  74. package/dist/common/Logger/index.ts +0 -53
  75. package/dist/common/asyncLocalStorage/index.ts +0 -9
  76. package/dist/common/cleanEnvironmentVariables.ts +0 -10
  77. package/dist/common/constants.ts +0 -1
  78. package/dist/common/contextStorageStateHelpers.ts +0 -43
  79. package/dist/common/getPlaywrightConstructs.ts +0 -181
  80. package/dist/common/jwtTokenManager.ts +0 -71
  81. package/dist/common/runApi/errors.ts +0 -154
  82. package/dist/common/runApi/index.ts +0 -253
  83. package/dist/common/runApi/types.ts +0 -43
  84. package/dist/common/settingsSchema.ts +0 -9
  85. package/dist/common/telemetry.ts +0 -23
  86. package/dist/index.ts +0 -4
  87. package/dist/runtime/RunError.ts +0 -12
  88. package/dist/runtime/downloadDirectory.ts +0 -13
  89. package/dist/runtime/enums.ts +0 -12
  90. package/dist/runtime/extendPayload.ts +0 -15
  91. package/dist/runtime/extendTimeout.ts +0 -24
  92. package/dist/runtime/index.ts +0 -6
  93. package/dist/runtime/requestMoreInfo.ts +0 -18
  94. package/dist/runtime/runInfo.ts +0 -15
  95. /package/dist/{common/Logger/Logger/types.ts → runtime/enums.d.js} +0 -0
  96. /package/dist/runtime/{executionHelpers.test.ts → executionHelpers.test.js} +0 -0
  97. /package/dist/{common/Logger/types.ts → runtime/export.d.js} +0 -0
@@ -1,29 +1,23 @@
1
1
  import * as fs from "fs-extra";
2
2
  import * as path from "path";
3
- import { getFullPathInProject, listProjectFilesAndFolders, } from "./fileUtils.js";
3
+ import { getFullPathInProject, listProjectFilesAndFolders } from "./fileUtils.js";
4
+ import { fileURLToPath } from "url";
4
5
  export const moveWebTemplateFiles = async () => {
5
- await fs.remove("./intuned");
6
- await fs.ensureDir("./intuned");
7
- const currentFileLocation = path.resolve(path.dirname(import.meta.url), "..", "..", "..", "..", "WebTemplate");
8
- // copy WebTemplate to ./intuned
9
- await fs.copy(`${currentFileLocation}`, "./intuned/WebTemplate", {
10
- filter: (src, dest) => {
11
- if (src.includes(".d.ts")) {
12
- return false;
13
- }
14
- return true;
15
- },
16
- });
17
- const filesAndFolders = await listProjectFilesAndFolders();
18
- const pathsIgnoreList = [
19
- getFullPathInProject("intuned"),
20
- getFullPathInProject("node_modules"),
21
- getFullPathInProject("package.json"),
22
- getFullPathInProject("yarn.lock"),
23
- getFullPathInProject(".env"),
24
- ];
25
- const filesToCopy = filesAndFolders.filter((file) => !pathsIgnoreList.includes(file.fullPath));
26
- for (const file of filesToCopy) {
27
- await fs.copy(file.fullPath, `./intuned/WebTemplate/${file.name}`);
6
+ await fs.remove("./intuned");
7
+ await fs.ensureDir("./intuned");
8
+ const currentFileLocation = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "..", "WebTemplate");
9
+ await fs.copy(`${currentFileLocation}`, "./intuned/WebTemplate", {
10
+ filter: (src, dest) => {
11
+ if (src.includes(".d.ts")) {
12
+ return false;
13
+ }
14
+ return true;
28
15
  }
29
- };
16
+ });
17
+ const filesAndFolders = await listProjectFilesAndFolders();
18
+ const pathsIgnoreList = [getFullPathInProject("intuned"), getFullPathInProject("node_modules"), getFullPathInProject("package.json"), getFullPathInProject("yarn.lock"), getFullPathInProject(".env")];
19
+ const filesToCopy = filesAndFolders.filter(file => !pathsIgnoreList.includes(file.fullPath));
20
+ for (const file of filesToCopy) {
21
+ await fs.copy(file.fullPath, `./intuned/WebTemplate/${file.name}`);
22
+ }
23
+ };
@@ -1,162 +1,156 @@
1
1
  #!/usr/bin/env node
2
2
  import { program } from "commander";
3
3
  import dotenv from "dotenv";
4
- import { runWithContext, } from "../../common/asyncLocalStorage";
4
+ import { runWithContext } from "../../common/asyncLocalStorage";
5
5
  import * as net from "net";
6
6
  import z from "zod";
7
- import { runApiGenerator, runApiParametersSchema, } from "../../common/runApi";
7
+ import { runApiGenerator, runApiParametersSchema } from "../../common/runApi";
8
8
  import { RunEnvironment } from "src/runtime/enums";
9
9
  import { JSONUnixSocket } from "../common/utils/unixSocket";
10
10
  import { setTimeout } from "timers/promises";
11
11
  const startRunApiSchema = z.object({
12
- type: z.literal("start"),
13
- parameters: runApiParametersSchema.extend({
14
- retrieveSession: z.boolean(),
15
- context: z
16
- .object({
17
- jobId: z.string().optional(),
18
- jobRunId: z.string().optional(),
19
- runId: z.string().optional(),
20
- queueId: z.string().optional(),
21
- })
22
- .optional(),
23
- }),
12
+ type: z.literal("start"),
13
+ parameters: runApiParametersSchema.extend({
14
+ retrieveSession: z.boolean(),
15
+ context: z.object({
16
+ jobId: z.string().optional(),
17
+ jobRunId: z.string().optional(),
18
+ runId: z.string().optional(),
19
+ queueId: z.string().optional()
20
+ }).optional()
21
+ })
24
22
  });
25
23
  const nextRunApiSchema = z.object({
26
- type: z.literal("next"),
27
- parameters: z.object({ value: z.string() }),
24
+ type: z.literal("next"),
25
+ parameters: z.object({
26
+ value: z.string()
27
+ })
28
28
  });
29
29
  const abortRunApiSchema = z.object({
30
- type: z.literal("abort"),
31
- parameters: z.object({}).optional(),
30
+ type: z.literal("abort"),
31
+ parameters: z.object({}).optional()
32
32
  });
33
- const inputSchema = z.union([
34
- startRunApiSchema,
35
- nextRunApiSchema,
36
- abortRunApiSchema,
37
- ]);
33
+ const inputSchema = z.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema]);
38
34
  dotenv.config({
39
- path: `.env`,
35
+ path: `.env`
40
36
  });
41
- program
42
- .description("run user automation and communicate using unix socket")
43
- .argument("<socket-path>", "path to unix socket")
44
- .action(async (socketPath) => {
45
- let context;
46
- const throttleTime = 1_000;
47
- let timeoutTimestamp = Date.now();
48
- const client = net.createConnection(socketPath, () => {
49
- console.log("connected to server!");
50
- });
51
- let generator = null;
52
- const abortController = new AbortController();
53
- client.on("end", () => {
54
- console.log("Disconnected from socket");
55
- });
56
- client.on("error", (err) => {
57
- console.error("Child connection error:", err);
58
- void generator?.throw(err).catch(() => undefined);
59
- });
60
- process.on("SIGINT", () => {
61
- console.log("Received SIGINT");
62
- void generator?.throw(new Error("Interrupted")).catch(() => undefined);
63
- client.end();
64
- process.exit(1);
65
- });
66
- const jsonUnixSocket = new JSONUnixSocket(client);
67
- async function runGeneratorAndSendResult(next) {
68
- if (!generator)
69
- return;
70
- const result = await runWithContext(context, () => generator.next(next));
71
- if (result.done) {
72
- const resultToSend = result.value.isOk()
73
- ? result.value.value
74
- : result.value.error.json;
75
- const success = result.value.isOk();
76
- jsonUnixSocket.sendJSON({
77
- type: "done",
78
- result: resultToSend,
79
- success,
80
- });
81
- return true;
82
- }
83
- else {
84
- jsonUnixSocket.sendJSON({ type: "yield", result: result.value });
85
- return false;
86
- }
37
+ program.description("run user automation and communicate using unix socket").argument("<socket-path>", "path to unix socket").action(async socketPath => {
38
+ let context;
39
+ const throttleTime = 1_000;
40
+ let timeoutTimestamp = Date.now();
41
+ const client = net.createConnection(socketPath, () => {
42
+ console.log("connected to server!");
43
+ });
44
+ let generator = null;
45
+ const abortController = new AbortController();
46
+ client.on("end", () => {
47
+ console.log("Disconnected from socket");
48
+ });
49
+ client.on("error", err => {
50
+ var _generator;
51
+ console.error("Child connection error:", err);
52
+ void ((_generator = generator) === null || _generator === void 0 ? void 0 : _generator.throw(err).catch(() => undefined));
53
+ });
54
+ process.on("SIGINT", () => {
55
+ var _generator2;
56
+ console.log("Received SIGINT");
57
+ void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(new Error("Interrupted")).catch(() => undefined));
58
+ client.end();
59
+ process.exit(1);
60
+ });
61
+ const jsonUnixSocket = new JSONUnixSocket(client);
62
+ async function runGeneratorAndSendResult(next) {
63
+ if (!generator) return;
64
+ const result = await runWithContext(context, () => generator.next(next));
65
+ if (result.done) {
66
+ const resultToSend = result.value.isOk() ? result.value.value : result.value.error.json;
67
+ const success = result.value.isOk();
68
+ jsonUnixSocket.sendJSON({
69
+ type: "done",
70
+ result: resultToSend,
71
+ success
72
+ });
73
+ return true;
74
+ } else {
75
+ jsonUnixSocket.sendJSON({
76
+ type: "yield",
77
+ result: result.value
78
+ });
79
+ return false;
80
+ }
81
+ }
82
+ for await (const data of jsonUnixSocket.receiveJSON()) {
83
+ const inputParseResult = inputSchema.safeParse(data);
84
+ if (!inputParseResult.success) {
85
+ console.error(inputParseResult.error.errors);
86
+ jsonUnixSocket.sendJSON({
87
+ type: "done",
88
+ result: {
89
+ error: "InvalidJSON",
90
+ message: "Invalid input",
91
+ details: {
92
+ errors: inputParseResult.error.errors
93
+ }
94
+ },
95
+ success: false
96
+ });
97
+ break;
87
98
  }
88
- for await (const data of jsonUnixSocket.receiveJSON()) {
89
- const inputParseResult = inputSchema.safeParse(data);
90
- if (!inputParseResult.success) {
91
- console.error(inputParseResult.error.errors);
99
+ const input = inputParseResult.data;
100
+ if (input.type === "abort") {
101
+ abortController.abort();
102
+ await setTimeout(10);
103
+ jsonUnixSocket.sendJSON({
104
+ type: "done",
105
+ result: null
106
+ });
107
+ break;
108
+ }
109
+ if (input.type === "start") {
110
+ const gen = runApiGenerator({
111
+ ...input.parameters,
112
+ abortSignal: abortController.signal
113
+ });
114
+ generator = gen;
115
+ context = {
116
+ extendedPayloads: [],
117
+ runEnvironment: input.parameters.runOptions.environment === "deployed" ? RunEnvironment.DEPLOYED : RunEnvironment.IDE,
118
+ timeoutInfo: {
119
+ extendTimeoutCallback: async () => {
120
+ if (Date.now() - timeoutTimestamp < throttleTime) return;
121
+ timeoutTimestamp = Date.now();
92
122
  jsonUnixSocket.sendJSON({
93
- type: "done",
94
- result: {
95
- error: "InvalidJSON",
96
- message: "Invalid input",
97
- details: {
98
- errors: inputParseResult.error.errors,
99
- },
100
- },
101
- success: false,
102
- });
103
- break;
104
- }
105
- const input = inputParseResult.data;
106
- if (input.type === "abort") {
107
- abortController.abort();
108
- await setTimeout(10);
109
- jsonUnixSocket.sendJSON({ type: "done", result: null });
110
- break;
111
- }
112
- if (input.type === "start") {
113
- const gen = runApiGenerator({
114
- ...input.parameters,
115
- abortSignal: abortController.signal,
123
+ type: "extend"
116
124
  });
117
- generator = gen;
118
- context = {
119
- extendedPayloads: [],
120
- runEnvironment: input.parameters.runOptions.environment === "deployed"
121
- ? RunEnvironment.DEPLOYED
122
- : RunEnvironment.IDE,
123
- timeoutInfo: {
124
- extendTimeoutCallback: async () => {
125
- if (Date.now() - timeoutTimestamp < throttleTime)
126
- return;
127
- timeoutTimestamp = Date.now();
128
- jsonUnixSocket.sendJSON({ type: "extend" });
129
- },
130
- },
131
- ...(input.parameters.context ?? {}),
132
- proxy: getProxyUrlFromRunOptions(input.parameters.runOptions),
133
- };
134
- if (await runGeneratorAndSendResult()) {
135
- break;
136
- }
137
- continue;
138
- }
139
- if (input.type === "next") {
140
- if (!generator) {
141
- throw new Error("generator not started");
142
- }
143
- if (await runGeneratorAndSendResult(input.parameters.value)) {
144
- break;
145
- }
146
- continue;
147
- }
125
+ }
126
+ },
127
+ ...(input.parameters.context ?? {}),
128
+ proxy: getProxyUrlFromRunOptions(input.parameters.runOptions)
129
+ };
130
+ if (await runGeneratorAndSendResult()) {
131
+ break;
132
+ }
133
+ continue;
134
+ }
135
+ if (input.type === "next") {
136
+ if (!generator) {
137
+ throw new Error("generator not started");
138
+ }
139
+ if (await runGeneratorAndSendResult(input.parameters.value)) {
140
+ break;
141
+ }
142
+ continue;
148
143
  }
149
- process.exit(0);
144
+ }
145
+ process.exit(0);
150
146
  });
151
147
  program.parse(process.argv);
152
148
  function getProxyUrlFromRunOptions(runOptions) {
153
- if (runOptions?.environment !== "deployed")
154
- return undefined;
155
- const proxy = runOptions.proxy;
156
- if (!proxy)
157
- return undefined;
158
- const url = new URL(proxy.server);
159
- url.username = proxy.username;
160
- url.password = proxy.password;
161
- return url.toString();
162
- }
149
+ if ((runOptions === null || runOptions === void 0 ? void 0 : runOptions.environment) !== "deployed") return undefined;
150
+ const proxy = runOptions.proxy;
151
+ if (!proxy) return undefined;
152
+ const url = new URL(proxy.server);
153
+ url.username = proxy.username;
154
+ url.password = proxy.password;
155
+ return url.toString();
156
+ }
@@ -4,51 +4,48 @@ import { program } from "commander";
4
4
  import * as fs from "fs-extra";
5
5
  import * as path from "path";
6
6
  import { moveWebTemplateFiles } from "./common/utils/webTemplate.js";
7
- program
8
- .description("Check TypeScript types in the project")
9
- .allowUnknownOption()
10
- .action(async () => {
11
- await moveWebTemplateFiles();
12
- const templateTsConfig = path.resolve(path.dirname(import.meta.url), "..", "..", "template.tsconfig.json");
13
- await fs.copy(templateTsConfig, "./intuned/WebTemplate/tsconfig.json");
14
- checkTypes();
7
+ import { fileURLToPath } from "url";
8
+ program.description("Check TypeScript types in the project").allowUnknownOption().action(async () => {
9
+ await moveWebTemplateFiles();
10
+ const templateTsConfig = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "template.tsconfig.json");
11
+ await fs.copy(templateTsConfig, "./intuned/WebTemplate/tsconfig.json");
12
+ checkTypes();
15
13
  });
16
14
  function checkTypes() {
17
- const configPath = ts.findConfigFile("./intuned/WebTemplate", ts.sys.fileExists, "tsconfig.json");
18
- if (!configPath) {
19
- console.error("Could not find a valid 'tsconfig.json'.");
20
- process.exit(1);
21
- }
22
- const readConfigResult = ts.readConfigFile(configPath, ts.sys.readFile);
23
- const config = readConfigResult.config;
24
- const parseConfigHost = {
25
- useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
26
- readDirectory: ts.sys.readDirectory,
27
- fileExists: ts.sys.fileExists,
28
- readFile: ts.sys.readFile,
29
- };
30
- const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, "./intuned");
31
- const program = ts.createProgram(parsed.fileNames, parsed.options);
32
- const emitResult = program.emit();
33
- const allDiagnostics = ts
34
- .getPreEmitDiagnostics(program)
35
- .concat(emitResult.diagnostics);
36
- allDiagnostics.forEach((diagnostic) => {
37
- if (diagnostic.file) {
38
- const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
39
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
40
- console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
41
- }
42
- else {
43
- console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
44
- }
45
- });
46
- if (allDiagnostics.length === 0) {
47
- console.log("✨ TypeScript type checking passed without errors.");
48
- }
49
- else {
50
- console.error("Errors found during TypeScript type checking.");
51
- process.exit(1);
15
+ const configPath = ts.findConfigFile("./intuned/WebTemplate", ts.sys.fileExists, "tsconfig.json");
16
+ if (!configPath) {
17
+ console.error("Could not find a valid 'tsconfig.json'.");
18
+ process.exit(1);
19
+ }
20
+ const readConfigResult = ts.readConfigFile(configPath, ts.sys.readFile);
21
+ const config = readConfigResult.config;
22
+ const parseConfigHost = {
23
+ useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
24
+ readDirectory: ts.sys.readDirectory,
25
+ fileExists: ts.sys.fileExists,
26
+ readFile: ts.sys.readFile
27
+ };
28
+ const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, "./intuned");
29
+ const program = ts.createProgram(parsed.fileNames, parsed.options);
30
+ const emitResult = program.emit();
31
+ const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
32
+ allDiagnostics.forEach(diagnostic => {
33
+ if (diagnostic.file) {
34
+ const {
35
+ line,
36
+ character
37
+ } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
38
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
39
+ console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
40
+ } else {
41
+ console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
52
42
  }
43
+ });
44
+ if (allDiagnostics.length === 0) {
45
+ console.log("✨ TypeScript type checking passed without errors.");
46
+ } else {
47
+ console.error("Errors found during TypeScript type checking.");
48
+ process.exit(1);
49
+ }
53
50
  }
54
- program.parse(process.argv);
51
+ program.parse(process.argv);
@@ -1,47 +1,53 @@
1
1
  import { formatWithOptions } from "node:util";
2
2
  import chalk from "chalk";
3
- const format = formatWithOptions.bind(undefined, { colors: true });
3
+ const format = formatWithOptions.bind(undefined, {
4
+ colors: true
5
+ });
4
6
  const LOG_LEVEL_COLORS = {
5
- TRACE: chalk.gray,
6
- DEBUG: chalk.blue,
7
- INFO: chalk.green,
8
- WARN: chalk.yellow,
9
- ERROR: chalk.red,
7
+ TRACE: chalk.gray,
8
+ DEBUG: chalk.blue,
9
+ INFO: chalk.green,
10
+ WARN: chalk.yellow,
11
+ ERROR: chalk.red
10
12
  };
11
13
  class Logger {
12
- logFunction(entry) {
13
- const { level, timestamp, message, meta } = entry;
14
- const date = new Date(timestamp);
15
- const levelColor = LOG_LEVEL_COLORS[level];
16
- if (meta === undefined) {
17
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
18
- }
19
- else {
20
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
21
- }
22
- }
23
- log(level, message, meta) {
24
- this.logFunction({
25
- level,
26
- message,
27
- meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
28
- timestamp: Date.now(),
29
- });
30
- }
31
- trace(message, meta) {
32
- this.log("TRACE", message, meta);
33
- }
34
- debug(message, meta) {
35
- this.log("DEBUG", message, meta);
36
- }
37
- info(message, meta) {
38
- this.log("INFO", message, meta);
39
- }
40
- warn(message, meta) {
41
- this.log("WARN", message, meta);
42
- }
43
- error(message, meta) {
44
- this.log("ERROR", message, meta);
14
+ logFunction(entry) {
15
+ const {
16
+ level,
17
+ timestamp,
18
+ message,
19
+ meta
20
+ } = entry;
21
+ const date = new Date(timestamp);
22
+ const levelColor = LOG_LEVEL_COLORS[level];
23
+ if (meta === undefined) {
24
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
25
+ } else {
26
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
45
27
  }
28
+ }
29
+ log(level, message, meta) {
30
+ this.logFunction({
31
+ level,
32
+ message,
33
+ meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
34
+ timestamp: Date.now()
35
+ });
36
+ }
37
+ trace(message, meta) {
38
+ this.log("TRACE", message, meta);
39
+ }
40
+ debug(message, meta) {
41
+ this.log("DEBUG", message, meta);
42
+ }
43
+ info(message, meta) {
44
+ this.log("INFO", message, meta);
45
+ }
46
+ warn(message, meta) {
47
+ this.log("WARN", message, meta);
48
+ }
49
+ error(message, meta) {
50
+ this.log("ERROR", message, meta);
51
+ }
46
52
  }
47
- export const logger = new Logger();
53
+ export const logger = new Logger();
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,47 +1,53 @@
1
1
  import { formatWithOptions } from "node:util";
2
2
  import chalk from "chalk";
3
- const format = formatWithOptions.bind(undefined, { colors: true });
3
+ const format = formatWithOptions.bind(undefined, {
4
+ colors: true
5
+ });
4
6
  const LOG_LEVEL_COLORS = {
5
- TRACE: chalk.gray,
6
- DEBUG: chalk.blue,
7
- INFO: chalk.green,
8
- WARN: chalk.yellow,
9
- ERROR: chalk.red,
7
+ TRACE: chalk.gray,
8
+ DEBUG: chalk.blue,
9
+ INFO: chalk.green,
10
+ WARN: chalk.yellow,
11
+ ERROR: chalk.red
10
12
  };
11
13
  class Logger {
12
- logFunction(entry) {
13
- const { level, timestamp, message, meta } = entry;
14
- const date = new Date(timestamp);
15
- const levelColor = LOG_LEVEL_COLORS[level];
16
- if (meta === undefined) {
17
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
18
- }
19
- else {
20
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
21
- }
22
- }
23
- log(level, message, meta) {
24
- this.logFunction({
25
- level,
26
- message,
27
- meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
28
- timestamp: Date.now(),
29
- });
30
- }
31
- trace(message, meta) {
32
- this.log("TRACE", message, meta);
33
- }
34
- debug(message, meta) {
35
- this.log("DEBUG", message, meta);
36
- }
37
- info(message, meta) {
38
- this.log("INFO", message, meta);
39
- }
40
- warn(message, meta) {
41
- this.log("WARN", message, meta);
42
- }
43
- error(message, meta) {
44
- this.log("ERROR", message, meta);
14
+ logFunction(entry) {
15
+ const {
16
+ level,
17
+ timestamp,
18
+ message,
19
+ meta
20
+ } = entry;
21
+ const date = new Date(timestamp);
22
+ const levelColor = LOG_LEVEL_COLORS[level];
23
+ if (meta === undefined) {
24
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
25
+ } else {
26
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
45
27
  }
28
+ }
29
+ log(level, message, meta) {
30
+ this.logFunction({
31
+ level,
32
+ message,
33
+ meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
34
+ timestamp: Date.now()
35
+ });
36
+ }
37
+ trace(message, meta) {
38
+ this.log("TRACE", message, meta);
39
+ }
40
+ debug(message, meta) {
41
+ this.log("DEBUG", message, meta);
42
+ }
43
+ info(message, meta) {
44
+ this.log("INFO", message, meta);
45
+ }
46
+ warn(message, meta) {
47
+ this.log("WARN", message, meta);
48
+ }
49
+ error(message, meta) {
50
+ this.log("ERROR", message, meta);
51
+ }
46
52
  }
47
- export const logger = new Logger();
53
+ export const logger = new Logger();
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,9 +1,9 @@
1
1
  import { AsyncLocalStorage } from "async_hooks";
2
2
  export const asyncLocalStorage = new AsyncLocalStorage();
3
3
  export function runWithContext(contextData, callback, ...args) {
4
- return asyncLocalStorage.run(contextData, callback, ...args);
4
+ return asyncLocalStorage.run(contextData, callback, ...args);
5
5
  }
6
6
  export function getExecutionContext() {
7
- const contextData = asyncLocalStorage.getStore();
8
- return contextData;
9
- }
7
+ const contextData = asyncLocalStorage.getStore();
8
+ return contextData;
9
+ }