@prosopo/cli 3.1.0 → 3.1.1

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 (75) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/RateLimiter.js +59 -57
  3. package/dist/argv.js +29 -25
  4. package/dist/bundle/{i18nBackend-DDiD0rVZ.js → i18nBackend-B5QB3n19.js} +48 -45
  5. package/dist/bundle/provider.cli.bundle.js +65208 -66203
  6. package/dist/cjs/cli.cjs +1 -4
  7. package/dist/cli.js +35 -36
  8. package/dist/commands/index.js +12 -6
  9. package/dist/commands/providerSetDataset.js +39 -39
  10. package/dist/commands/siteKeyRegister.js +82 -79
  11. package/dist/commands/siteKeyRegisterApi.js +90 -81
  12. package/dist/commands/storeCaptchasExternally.js +23 -24
  13. package/dist/commands/validators.js +32 -27
  14. package/dist/commands/version.js +15 -13
  15. package/dist/files.js +31 -29
  16. package/dist/index.js +20 -7
  17. package/dist/process.env.js +38 -37
  18. package/dist/prosopo.config.js +85 -90
  19. package/dist/reloader.js +53 -47
  20. package/dist/start.js +118 -87
  21. package/package.json +22 -19
  22. package/vite.cjs.config.ts +4 -1
  23. package/vite.esm.config.ts +20 -0
  24. package/dist/RateLimiter.d.ts +0 -55
  25. package/dist/RateLimiter.d.ts.map +0 -1
  26. package/dist/RateLimiter.js.map +0 -1
  27. package/dist/argv.d.ts +0 -22
  28. package/dist/argv.d.ts.map +0 -1
  29. package/dist/argv.js.map +0 -1
  30. package/dist/cli.d.ts +0 -2
  31. package/dist/cli.d.ts.map +0 -1
  32. package/dist/cli.js.map +0 -1
  33. package/dist/commands/index.d.ts +0 -6
  34. package/dist/commands/index.d.ts.map +0 -1
  35. package/dist/commands/index.js.map +0 -1
  36. package/dist/commands/providerSetDataset.d.ts +0 -17
  37. package/dist/commands/providerSetDataset.d.ts.map +0 -1
  38. package/dist/commands/providerSetDataset.js.map +0 -1
  39. package/dist/commands/siteKeyRegister.d.ts +0 -57
  40. package/dist/commands/siteKeyRegister.d.ts.map +0 -1
  41. package/dist/commands/siteKeyRegister.js.map +0 -1
  42. package/dist/commands/siteKeyRegisterApi.d.ts +0 -33
  43. package/dist/commands/siteKeyRegisterApi.d.ts.map +0 -1
  44. package/dist/commands/siteKeyRegisterApi.js.map +0 -1
  45. package/dist/commands/storeCaptchasExternally.d.ts +0 -13
  46. package/dist/commands/storeCaptchasExternally.d.ts.map +0 -1
  47. package/dist/commands/storeCaptchasExternally.js.map +0 -1
  48. package/dist/commands/validators.d.ts +0 -18
  49. package/dist/commands/validators.d.ts.map +0 -1
  50. package/dist/commands/validators.js.map +0 -1
  51. package/dist/commands/version.d.ts +0 -12
  52. package/dist/commands/version.d.ts.map +0 -1
  53. package/dist/commands/version.js.map +0 -1
  54. package/dist/files.d.ts +0 -4
  55. package/dist/files.d.ts.map +0 -1
  56. package/dist/files.js.map +0 -1
  57. package/dist/index.d.ts +0 -7
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/index.js.map +0 -1
  60. package/dist/process.env.d.ts +0 -8
  61. package/dist/process.env.d.ts.map +0 -1
  62. package/dist/process.env.js.map +0 -1
  63. package/dist/prosopo.config.d.ts +0 -3
  64. package/dist/prosopo.config.d.ts.map +0 -1
  65. package/dist/prosopo.config.js.map +0 -1
  66. package/dist/reloader.d.ts +0 -20
  67. package/dist/reloader.d.ts.map +0 -1
  68. package/dist/reloader.js.map +0 -1
  69. package/dist/start.d.ts +0 -4
  70. package/dist/start.d.ts.map +0 -1
  71. package/dist/start.js.map +0 -1
  72. package/dist/tests/bundle/bundle.unit.test.d.ts +0 -2
  73. package/dist/tests/bundle/bundle.unit.test.d.ts.map +0 -1
  74. package/dist/tests/bundle/bundle.unit.test.js +0 -14
  75. package/dist/tests/bundle/bundle.unit.test.js.map +0 -1
@@ -1,36 +1,41 @@
1
1
  import { ProsopoEnvError } from "@prosopo/common";
2
2
  import { encodeStringAddress } from "@prosopo/provider";
3
3
  import parser from "cron-parser";
4
- export const validateAddress = (argv) => {
5
- const address = encodeStringAddress(argv.address);
6
- return { address };
4
+ const validateAddress = (argv) => {
5
+ const address = encodeStringAddress(argv.address);
6
+ return { address };
7
7
  };
8
- export const validateSiteKey = (argv) => {
9
- const sitekey = encodeStringAddress(argv.sitekey);
10
- return { sitekey };
8
+ const validateSiteKey = (argv) => {
9
+ const sitekey = encodeStringAddress(argv.sitekey);
10
+ return { sitekey };
11
11
  };
12
- export const validateValue = (argv) => {
13
- if (typeof argv.value !== "number") {
14
- throw new ProsopoEnvError("CLI.PARAMETER_ERROR", {
15
- context: { value: [argv.value] },
16
- });
17
- }
18
- const value = argv.value;
19
- return { value };
12
+ const validateValue = (argv) => {
13
+ if (typeof argv.value !== "number") {
14
+ throw new ProsopoEnvError("CLI.PARAMETER_ERROR", {
15
+ context: { value: [argv.value] }
16
+ });
17
+ }
18
+ const value = argv.value;
19
+ return { value };
20
20
  };
21
- export const validateScheduleExpression = (argv) => {
22
- if (typeof argv.schedule === "string") {
23
- const result = parser.parseString(argv.schedule);
24
- if (argv.schedule in result.errors) {
25
- throw new ProsopoEnvError("CLI.PARAMETER_ERROR", {
26
- context: {
27
- payee: [argv.shedule],
28
- failedFuncName: validateScheduleExpression.name,
29
- },
30
- });
21
+ const validateScheduleExpression = (argv) => {
22
+ if (typeof argv.schedule === "string") {
23
+ const result = parser.parseString(argv.schedule);
24
+ if (argv.schedule in result.errors) {
25
+ throw new ProsopoEnvError("CLI.PARAMETER_ERROR", {
26
+ context: {
27
+ payee: [argv.shedule],
28
+ failedFuncName: validateScheduleExpression.name
31
29
  }
32
- return { schedule: argv.schedule };
30
+ });
33
31
  }
34
- return { schedule: null };
32
+ return { schedule: argv.schedule };
33
+ }
34
+ return { schedule: null };
35
+ };
36
+ export {
37
+ validateAddress,
38
+ validateScheduleExpression,
39
+ validateSiteKey,
40
+ validateValue
35
41
  };
36
- //# sourceMappingURL=validators.js.map
@@ -1,15 +1,17 @@
1
- import { LogLevel, getLogger } from "@prosopo/common";
1
+ import { getLogger, LogLevel } from "@prosopo/common";
2
2
  import { version } from "@prosopo/util";
3
- export default (pair, config, cmdArgs) => {
4
- const logger = cmdArgs?.logger || getLogger(LogLevel.enum.info, "cli.version");
5
- return {
6
- command: "version",
7
- describe: "Return the version of the software",
8
- handler: () => {
9
- logger.info(() => ({
10
- data: { version },
11
- }));
12
- },
13
- };
3
+ const commandVersion = (pair, config, cmdArgs) => {
4
+ const logger = cmdArgs?.logger || getLogger(LogLevel.enum.info, "cli.version");
5
+ return {
6
+ command: "version",
7
+ describe: "Return the version of the software",
8
+ handler: () => {
9
+ logger.info(() => ({
10
+ data: { version }
11
+ }));
12
+ }
13
+ };
14
+ };
15
+ export {
16
+ commandVersion as default
14
17
  };
15
- //# sourceMappingURL=version.js.map
package/dist/files.js CHANGED
@@ -1,37 +1,39 @@
1
1
  import fs, { createWriteStream } from "node:fs";
2
2
  import { Readable } from "node:stream";
3
3
  import { ProsopoCliError } from "@prosopo/common";
4
- export function loadJSONFile(filePath) {
5
- try {
6
- return JSON.parse(fs.readFileSync(filePath, "utf8"));
7
- }
8
- catch (error) {
9
- throw new ProsopoCliError("GENERAL.JSON_LOAD_FAILED", {
10
- context: { error, filePath },
11
- });
12
- }
4
+ function loadJSONFile(filePath) {
5
+ try {
6
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
7
+ } catch (error) {
8
+ throw new ProsopoCliError("GENERAL.JSON_LOAD_FAILED", {
9
+ context: { error, filePath }
10
+ });
11
+ }
13
12
  }
14
- export function writeJSONFile(filePath, jsonData) {
15
- return new Promise((resolve, reject) => {
16
- const writeStream = createWriteStream(filePath);
17
- writeStream.setDefaultEncoding("utf-8");
18
- writeStream.on("finish", () => {
19
- resolve(true);
20
- });
21
- writeStream.on("error", (err) => {
22
- reject(err);
23
- });
24
- const readable = Readable.from(JSON.stringify(jsonData));
25
- readable.pipe(writeStream);
13
+ function writeJSONFile(filePath, jsonData) {
14
+ return new Promise((resolve, reject) => {
15
+ const writeStream = createWriteStream(filePath);
16
+ writeStream.setDefaultEncoding("utf-8");
17
+ writeStream.on("finish", () => {
18
+ resolve(true);
19
+ });
20
+ writeStream.on("error", (err) => {
21
+ reject(err);
26
22
  });
23
+ const readable = Readable.from(JSON.stringify(jsonData));
24
+ readable.pipe(writeStream);
25
+ });
27
26
  }
28
- export async function readFile(filePath) {
29
- return new Promise((resolve, reject) => {
30
- fs.readFile(filePath, (err, data) => {
31
- if (err)
32
- reject(err);
33
- resolve(data);
34
- });
27
+ async function readFile(filePath) {
28
+ return new Promise((resolve, reject) => {
29
+ fs.readFile(filePath, (err, data) => {
30
+ if (err) reject(err);
31
+ resolve(data);
35
32
  });
33
+ });
36
34
  }
37
- //# sourceMappingURL=files.js.map
35
+ export {
36
+ loadJSONFile,
37
+ readFile,
38
+ writeJSONFile
39
+ };
package/dist/index.js CHANGED
@@ -1,7 +1,20 @@
1
- export * from "./argv.js";
2
- export * from "./cli.js";
3
- export * from "./start.js";
4
- export * from "./process.env.js";
5
- export * from "./files.js";
6
- export { default as defaultConfig } from "./prosopo.config.js";
7
- //# sourceMappingURL=index.js.map
1
+ import { processArgs } from "./argv.js";
2
+ import "./cli.js";
3
+ import { start } from "./start.js";
4
+ import { getAddress, getDB, getPairType, getPassword, getSecret, getSs58Format } from "./process.env.js";
5
+ import { loadJSONFile, readFile, writeJSONFile } from "./files.js";
6
+ import { default as default2 } from "./prosopo.config.js";
7
+ export {
8
+ default2 as defaultConfig,
9
+ getAddress,
10
+ getDB,
11
+ getPairType,
12
+ getPassword,
13
+ getSecret,
14
+ getSs58Format,
15
+ loadJSONFile,
16
+ processArgs,
17
+ readFile,
18
+ start,
19
+ writeJSONFile
20
+ };
@@ -1,44 +1,45 @@
1
1
  import { ProsopoEnvError } from "@prosopo/common";
2
- export function getSs58Format() {
3
- return Number.parseInt(process.env.SS58_FORMAT || "") || 42;
2
+ function getSs58Format() {
3
+ return Number.parseInt(process.env.SS58_FORMAT || "") || 42;
4
4
  }
5
- export function getPairType() {
6
- return (process.env.PROSOPO_PAIR_TYPE || "sr25519");
5
+ function getPairType() {
6
+ return process.env.PROSOPO_PAIR_TYPE || "sr25519";
7
7
  }
8
- export function getAddress(who) {
9
- if (!who) {
10
- who = "PROVIDER";
11
- }
12
- else {
13
- who = who.toUpperCase();
14
- }
15
- return process.env[`PROSOPO_${who}_ADDRESS`];
8
+ function getAddress(who) {
9
+ if (!who) {
10
+ who = "PROVIDER";
11
+ } else {
12
+ who = who.toUpperCase();
13
+ }
14
+ return process.env[`PROSOPO_${who}_ADDRESS`];
16
15
  }
17
- export function getPassword(who) {
18
- if (!who) {
19
- who = "PROVIDER";
20
- }
21
- else {
22
- who = who.toUpperCase();
23
- }
24
- return process.env[`PROSOPO_${who}_ACCOUNT_PASSWORD`];
16
+ function getPassword(who) {
17
+ if (!who) {
18
+ who = "PROVIDER";
19
+ } else {
20
+ who = who.toUpperCase();
21
+ }
22
+ return process.env[`PROSOPO_${who}_ACCOUNT_PASSWORD`];
25
23
  }
26
- export function getSecret(who) {
27
- if (!who) {
28
- who = "PROVIDER";
29
- }
30
- else {
31
- who = who.toUpperCase();
32
- }
33
- return (process.env[`PROSOPO_${who}_MNEMONIC`] ||
34
- process.env[`PROSOPO_${who}_SEED`] ||
35
- process.env[`PROSOPO_${who}_URI`] ||
36
- process.env[`PROSOPO_${who}_JSON`]);
24
+ function getSecret(who) {
25
+ if (!who) {
26
+ who = "PROVIDER";
27
+ } else {
28
+ who = who.toUpperCase();
29
+ }
30
+ return process.env[`PROSOPO_${who}_MNEMONIC`] || process.env[`PROSOPO_${who}_SEED`] || process.env[`PROSOPO_${who}_URI`] || process.env[`PROSOPO_${who}_JSON`];
37
31
  }
38
- export function getDB() {
39
- if (!process.env.PROSOPO_DATABASE_HOST) {
40
- throw new ProsopoEnvError("DATABASE.DATABASE_HOST_UNDEFINED");
41
- }
42
- return process.env.PROSOPO_DATABASE_HOST;
32
+ function getDB() {
33
+ if (!process.env.PROSOPO_DATABASE_HOST) {
34
+ throw new ProsopoEnvError("DATABASE.DATABASE_HOST_UNDEFINED");
35
+ }
36
+ return process.env.PROSOPO_DATABASE_HOST;
43
37
  }
44
- //# sourceMappingURL=process.env.js.map
38
+ export {
39
+ getAddress,
40
+ getDB,
41
+ getPairType,
42
+ getPassword,
43
+ getSecret,
44
+ getSs58Format
45
+ };
@@ -1,97 +1,92 @@
1
1
  import { parseLogLevel } from "@prosopo/common";
2
- import { DatabaseTypes, EnvironmentTypesSchema, FrictionlessPenalties, ProsopoConfigSchema, } from "@prosopo/types";
2
+ import { ProsopoConfigSchema, FrictionlessPenalties, DatabaseTypes, EnvironmentTypesSchema } from "@prosopo/types";
3
3
  import { getRateLimitConfig } from "./RateLimiter.js";
4
- import { getAddress, getPassword, getSecret } from "./process.env.js";
4
+ import { getSecret, getPassword, getAddress } from "./process.env.js";
5
5
  function getMongoURI() {
6
- const protocol = process.env.PROSOPO_DATABASE_PROTOCOL || "mongodb";
7
- const mongoSrv = protocol === "mongodb+srv";
8
- const password = process.env.PROSOPO_DATABASE_PASSWORD || "root";
9
- const username = process.env.PROSOPO_DATABASE_USERNAME || "root";
10
- const host = process.env.PROSOPO_DATABASE_HOST || "localhost";
11
- const port = mongoSrv ? "" : `:${process.env.PROSOPO_DATABASE_PORT || 27017}`;
12
- const retries = mongoSrv ? "?retryWrites=true&w=majority" : "";
13
- const mongoURI = `${protocol}://${username}:${password}@${host}${port}/${retries}`;
14
- return mongoURI;
6
+ const protocol = process.env.PROSOPO_DATABASE_PROTOCOL || "mongodb";
7
+ const mongoSrv = protocol === "mongodb+srv";
8
+ const password = process.env.PROSOPO_DATABASE_PASSWORD || "root";
9
+ const username = process.env.PROSOPO_DATABASE_USERNAME || "root";
10
+ const host = process.env.PROSOPO_DATABASE_HOST || "localhost";
11
+ const port = mongoSrv ? "" : `:${process.env.PROSOPO_DATABASE_PORT || 27017}`;
12
+ const retries = mongoSrv ? "?retryWrites=true&w=majority" : "";
13
+ const mongoURI = `${protocol}://${username}:${password}@${host}${port}/${retries}`;
14
+ return mongoURI;
15
15
  }
16
16
  const getLRules = () => {
17
- if (!process.env.L_RULES) {
18
- return {};
19
- }
20
- try {
21
- return JSON.parse(process.env.L_RULES);
22
- }
23
- catch (e) {
24
- return {};
25
- }
17
+ if (!process.env.L_RULES) {
18
+ return {};
19
+ }
20
+ try {
21
+ return JSON.parse(process.env.L_RULES);
22
+ } catch (e) {
23
+ return {};
24
+ }
26
25
  };
27
- export default function getConfig(captchaSolutionsConfig, captchaServeConfig, who = "PROVIDER", admin = "ADMIN") {
28
- return ProsopoConfigSchema.parse({
29
- logLevel: parseLogLevel(process.env.PROSOPO_LOG_LEVEL, "info"),
30
- defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT
31
- ? EnvironmentTypesSchema.parse(process.env.PROSOPO_DEFAULT_ENVIRONMENT)
32
- : EnvironmentTypesSchema.enum.development,
33
- account: {
34
- address: getAddress(who),
35
- password: getPassword(who),
36
- secret: getSecret(who),
37
- },
38
- database: {
39
- development: {
40
- type: DatabaseTypes.enum.provider,
41
- endpoint: getMongoURI(),
42
- dbname: process.env.PROSOPO_DATABASE_NAME,
43
- authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE,
44
- },
45
- staging: {
46
- type: DatabaseTypes.enum.provider,
47
- endpoint: getMongoURI(),
48
- dbname: process.env.PROSOPO_DATABASE_NAME,
49
- authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE,
50
- },
51
- production: {
52
- type: DatabaseTypes.enum.provider,
53
- endpoint: getMongoURI(),
54
- dbname: process.env.PROSOPO_DATABASE_NAME,
55
- authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE,
56
- },
57
- },
58
- server: {
59
- baseURL: process.env.PROSOPO_API_BASE_URL || "http://localhost",
60
- port: process.env.PROSOPO_API_PORT
61
- ? Number.parseInt(process.env.PROSOPO_API_PORT)
62
- : 9229,
63
- },
64
- captchaSolutions: captchaSolutionsConfig,
65
- captchas: captchaServeConfig,
66
- penalties: FrictionlessPenalties.parse({
67
- PENALTY_OLD_TIMESTAMP: process.env.PENALTY_OLD_TIMESTAMP,
68
- PENALTY_ACCESS_RULE: process.env.PENALTY_ACCESS_RULE,
69
- }),
70
- mongoEventsUri: process.env.PROSOPO_MONGO_EVENTS_URI || "",
71
- mongoCaptchaUri: process.env.PROSOPO_MONGO_CAPTCHA_URI || "",
72
- mongoClientUri: process.env.PROSOPO_MONGO_CLIENT_URI || "",
73
- redisConnection: {
74
- url: process.env.REDIS_CONNECTION_URL || "",
75
- password: process.env.REDIS_CONNECTION_PASSWORD || "",
76
- },
77
- rateLimits: getRateLimitConfig(),
78
- proxyCount: process.env.PROSOPO_PROXY_COUNT
79
- ? Number.parseInt(process.env.PROSOPO_PROXY_COUNT)
80
- : 0,
81
- scheduledTasks: {
82
- captchaScheduler: {
83
- schedule: process.env.CAPTCHA_STORAGE_SCHEDULE,
84
- },
85
- clientListScheduler: {
86
- schedule: process.env.CLIENT_LIST_SCHEDULE,
87
- },
88
- },
89
- lRules: getLRules(),
90
- authAccount: {
91
- address: getAddress(admin),
92
- password: getPassword(admin),
93
- secret: getSecret(admin),
94
- },
95
- });
26
+ function getConfig(captchaSolutionsConfig, captchaServeConfig, who = "PROVIDER", admin = "ADMIN") {
27
+ return ProsopoConfigSchema.parse({
28
+ logLevel: parseLogLevel(process.env.PROSOPO_LOG_LEVEL, "info"),
29
+ defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT ? EnvironmentTypesSchema.parse(process.env.PROSOPO_DEFAULT_ENVIRONMENT) : EnvironmentTypesSchema.enum.development,
30
+ account: {
31
+ address: getAddress(who),
32
+ password: getPassword(who),
33
+ secret: getSecret(who)
34
+ },
35
+ database: {
36
+ development: {
37
+ type: DatabaseTypes.enum.provider,
38
+ endpoint: getMongoURI(),
39
+ dbname: process.env.PROSOPO_DATABASE_NAME,
40
+ authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
41
+ },
42
+ staging: {
43
+ type: DatabaseTypes.enum.provider,
44
+ endpoint: getMongoURI(),
45
+ dbname: process.env.PROSOPO_DATABASE_NAME,
46
+ authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
47
+ },
48
+ production: {
49
+ type: DatabaseTypes.enum.provider,
50
+ endpoint: getMongoURI(),
51
+ dbname: process.env.PROSOPO_DATABASE_NAME,
52
+ authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
53
+ }
54
+ },
55
+ server: {
56
+ baseURL: process.env.PROSOPO_API_BASE_URL || "http://localhost",
57
+ port: process.env.PROSOPO_API_PORT ? Number.parseInt(process.env.PROSOPO_API_PORT) : 9229
58
+ },
59
+ captchaSolutions: captchaSolutionsConfig,
60
+ captchas: captchaServeConfig,
61
+ penalties: FrictionlessPenalties.parse({
62
+ PENALTY_OLD_TIMESTAMP: process.env.PENALTY_OLD_TIMESTAMP,
63
+ PENALTY_ACCESS_RULE: process.env.PENALTY_ACCESS_RULE
64
+ }),
65
+ mongoEventsUri: process.env.PROSOPO_MONGO_EVENTS_URI || "",
66
+ mongoCaptchaUri: process.env.PROSOPO_MONGO_CAPTCHA_URI || "",
67
+ mongoClientUri: process.env.PROSOPO_MONGO_CLIENT_URI || "",
68
+ redisConnection: {
69
+ url: process.env.REDIS_CONNECTION_URL || "",
70
+ password: process.env.REDIS_CONNECTION_PASSWORD || ""
71
+ },
72
+ rateLimits: getRateLimitConfig(),
73
+ proxyCount: process.env.PROSOPO_PROXY_COUNT ? Number.parseInt(process.env.PROSOPO_PROXY_COUNT) : 0,
74
+ scheduledTasks: {
75
+ captchaScheduler: {
76
+ schedule: process.env.CAPTCHA_STORAGE_SCHEDULE
77
+ },
78
+ clientListScheduler: {
79
+ schedule: process.env.CLIENT_LIST_SCHEDULE
80
+ }
81
+ },
82
+ lRules: getLRules(),
83
+ authAccount: {
84
+ address: getAddress(admin),
85
+ password: getPassword(admin),
86
+ secret: getSecret(admin)
87
+ }
88
+ });
96
89
  }
97
- //# sourceMappingURL=prosopo.config.js.map
90
+ export {
91
+ getConfig as default
92
+ };
package/dist/reloader.js CHANGED
@@ -1,56 +1,62 @@
1
1
  import fs from "node:fs";
2
- import { LogLevel, getLogger } from "@prosopo/common";
2
+ import { getLogger, LogLevel } from "@prosopo/common";
3
3
  import { loadEnv } from "@prosopo/dotenv";
4
4
  import { ProviderEnvironment } from "@prosopo/env";
5
5
  import { start } from "./start.js";
6
6
  const log = getLogger(LogLevel.enum.info, "CLI");
7
- export default class ReloadingAPI {
8
- constructor(envPath, config, pair, authAccount, processedArgs) {
9
- this._envPath = envPath;
10
- this._config = config;
11
- this._pair = pair;
12
- this._authAccount = authAccount;
13
- this._processedArgs = processedArgs;
14
- this._restarting = false;
7
+ class ReloadingAPI {
8
+ constructor(envPath, config, pair, authAccount, processedArgs) {
9
+ this._envPath = envPath;
10
+ this._config = config;
11
+ this._pair = pair;
12
+ this._authAccount = authAccount;
13
+ this._processedArgs = processedArgs;
14
+ this._restarting = false;
15
+ }
16
+ get env() {
17
+ if (!this._env) {
18
+ throw new Error("Environment not initialized. Call start() first.");
15
19
  }
16
- get env() {
17
- if (!this._env) {
18
- throw new Error("Environment not initialized. Call start() first.");
19
- }
20
- return this._env;
20
+ return this._env;
21
+ }
22
+ async start(reloadEnv = false) {
23
+ log.info(() => ({ msg: "Starting API" }));
24
+ this._envWatcher = await this._watchEnv();
25
+ loadEnv();
26
+ if (!this._env || reloadEnv) {
27
+ this._env = new ProviderEnvironment(
28
+ this._config,
29
+ this._pair,
30
+ this._authAccount
31
+ );
21
32
  }
22
- async start(reloadEnv = false) {
23
- log.info(() => ({ msg: "Starting API" }));
24
- this._envWatcher = await this._watchEnv();
33
+ await this.env.isReady();
34
+ this.api = await start(this.env, !!this._processedArgs.adminApi);
35
+ }
36
+ async stop() {
37
+ log.info(() => ({ msg: "Stopping API" }));
38
+ return new Promise((resolve) => {
39
+ if (this.api) {
40
+ this.api.close(resolve);
41
+ }
42
+ });
43
+ }
44
+ async _watchEnv() {
45
+ return fs.watchFile(this._envPath, async () => {
46
+ log.info(() => ({
47
+ data: { restarting: this._restarting },
48
+ msg: "env file change detected. Restarting"
49
+ }));
50
+ if (!this._restarting) {
51
+ this._restarting = true;
52
+ await this.stop();
25
53
  loadEnv();
26
- if (!this._env || reloadEnv) {
27
- this._env = new ProviderEnvironment(this._config, this._pair, this._authAccount);
28
- }
29
- await this.env.isReady();
30
- this.api = await start(this.env, !!this._processedArgs.adminApi);
31
- }
32
- async stop() {
33
- log.info(() => ({ msg: "Stopping API" }));
34
- return new Promise((resolve) => {
35
- if (this.api) {
36
- this.api.close(resolve);
37
- }
38
- });
39
- }
40
- async _watchEnv() {
41
- return fs.watchFile(this._envPath, async () => {
42
- log.info(() => ({
43
- data: { restarting: this._restarting },
44
- msg: "env file change detected. Restarting",
45
- }));
46
- if (!this._restarting) {
47
- this._restarting = true;
48
- await this.stop();
49
- loadEnv();
50
- await this.start(true);
51
- this._restarting = false;
52
- }
53
- });
54
- }
54
+ await this.start(true);
55
+ this._restarting = false;
56
+ }
57
+ });
58
+ }
55
59
  }
56
- //# sourceMappingURL=reloader.js.map
60
+ export {
61
+ ReloadingAPI as default
62
+ };