@prosopo/cli 2.1.0 → 2.1.2

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 (78) hide show
  1. package/package.json +12 -9
  2. package/dist/RateLimiter.d.ts +0 -59
  3. package/dist/RateLimiter.d.ts.map +0 -1
  4. package/dist/RateLimiter.js +0 -62
  5. package/dist/RateLimiter.js.map +0 -1
  6. package/dist/argv.d.ts +0 -22
  7. package/dist/argv.d.ts.map +0 -1
  8. package/dist/argv.js +0 -20
  9. package/dist/argv.js.map +0 -1
  10. package/dist/bundle/provider.cli.bundle.js +0 -238350
  11. package/dist/cjs/RateLimiter.cjs +0 -64
  12. package/dist/cjs/argv.cjs +0 -18
  13. package/dist/cjs/cli.cjs +0 -53
  14. package/dist/cjs/commands/index.cjs +0 -8
  15. package/dist/cjs/commands/providerSetDataset.cjs +0 -51
  16. package/dist/cjs/commands/storeCaptchasExternally.cjs +0 -25
  17. package/dist/cjs/commands/version.cjs +0 -14
  18. package/dist/cjs/files.cjs +0 -39
  19. package/dist/cjs/index.cjs +0 -21
  20. package/dist/cjs/process.env.cjs +0 -45
  21. package/dist/cjs/prosopo.config.cjs +0 -68
  22. package/dist/cjs/reloader.cjs +0 -59
  23. package/dist/cjs/start.cjs +0 -68
  24. package/dist/cli.d.ts +0 -2
  25. package/dist/cli.d.ts.map +0 -1
  26. package/dist/cli.js +0 -56
  27. package/dist/cli.js.map +0 -1
  28. package/dist/commands/index.d.ts +0 -4
  29. package/dist/commands/index.d.ts.map +0 -1
  30. package/dist/commands/index.js +0 -4
  31. package/dist/commands/index.js.map +0 -1
  32. package/dist/commands/providerDeregister.d.ts +0 -19
  33. package/dist/commands/providerDeregister.d.ts.map +0 -1
  34. package/dist/commands/providerDeregister.js +0 -30
  35. package/dist/commands/providerDeregister.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 +0 -35
  39. package/dist/commands/providerSetDataset.js.map +0 -1
  40. package/dist/commands/storeCaptchasExternally.d.ts +0 -13
  41. package/dist/commands/storeCaptchasExternally.d.ts.map +0 -1
  42. package/dist/commands/storeCaptchasExternally.js +0 -27
  43. package/dist/commands/storeCaptchasExternally.js.map +0 -1
  44. package/dist/commands/validators.d.ts +0 -15
  45. package/dist/commands/validators.d.ts.map +0 -1
  46. package/dist/commands/validators.js +0 -32
  47. package/dist/commands/validators.js.map +0 -1
  48. package/dist/commands/version.d.ts +0 -12
  49. package/dist/commands/version.d.ts.map +0 -1
  50. package/dist/commands/version.js +0 -13
  51. package/dist/commands/version.js.map +0 -1
  52. package/dist/files.d.ts +0 -4
  53. package/dist/files.d.ts.map +0 -1
  54. package/dist/files.js +0 -37
  55. package/dist/files.js.map +0 -1
  56. package/dist/index.d.ts +0 -7
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/process.env.d.ts +0 -8
  60. package/dist/process.env.d.ts.map +0 -1
  61. package/dist/process.env.js +0 -44
  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 +0 -73
  66. package/dist/prosopo.config.js.map +0 -1
  67. package/dist/reloader.d.ts +0 -21
  68. package/dist/reloader.d.ts.map +0 -1
  69. package/dist/reloader.js +0 -58
  70. package/dist/reloader.js.map +0 -1
  71. package/dist/start.d.ts +0 -5
  72. package/dist/start.d.ts.map +0 -1
  73. package/dist/start.js +0 -63
  74. package/dist/start.js.map +0 -1
  75. package/dist/tests/bundle/bundle.unit.test.d.ts +0 -2
  76. package/dist/tests/bundle/bundle.unit.test.d.ts.map +0 -1
  77. package/dist/tests/bundle/bundle.unit.test.js +0 -14
  78. package/dist/tests/bundle/bundle.unit.test.js.map +0 -1
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const types = require("@prosopo/types");
4
- const getRateLimitConfig = () => {
5
- return {
6
- [types.ApiPaths.GetImageCaptchaChallenge]: {
7
- windowMs: process.env.PROSOPO_GET_IMAGE_CAPTCHA_CHALLENGE_WINDOW,
8
- limit: process.env.PROSOPO_GET_IMAGE_CAPTCHA_CHALLENGE_LIMIT
9
- },
10
- [types.ApiPaths.GetPowCaptchaChallenge]: {
11
- windowMs: process.env.PROSOPO_GET_POW_CAPTCHA_CHALLENGE_WINDOW,
12
- limit: process.env.PROSOPO_GET_POW_CAPTCHA_CHALLENGE_LIMIT
13
- },
14
- [types.ApiPaths.SubmitImageCaptchaSolution]: {
15
- windowMs: process.env.PROSOPO_SUBMIT_IMAGE_CAPTCHA_SOLUTION_WINDOW,
16
- limit: process.env.PROSOPO_SUBMIT_IMAGE_CAPTCHA_SOLUTION_LIMIT
17
- },
18
- [types.ApiPaths.SubmitPowCaptchaSolution]: {
19
- windowMs: process.env.PROSOPO_SUBMIT_POW_CAPTCHA_SOLUTION_WINDOW,
20
- limit: process.env.PROSOPO_SUBMIT_POW_CAPTCHA_SOLUTION_LIMIT
21
- },
22
- [types.ApiPaths.VerifyPowCaptchaSolution]: {
23
- windowMs: process.env.PROSOPO_VERIFY_POW_CAPTCHA_SOLUTION_WINDOW,
24
- limit: process.env.PROSOPO_VERIFY_POW_CAPTCHA_SOLUTION_LIMIT
25
- },
26
- [types.ApiPaths.VerifyImageCaptchaSolutionDapp]: {
27
- windowMs: process.env.PROSOPO_VERIFY_IMAGE_CAPTCHA_SOLUTION_DAPP_WINDOW,
28
- limit: process.env.PROSOPO_VERIFY_IMAGE_CAPTCHA_SOLUTION_DAPP_LIMIT
29
- },
30
- [types.ApiPaths.VerifyImageCaptchaSolutionUser]: {
31
- windowMs: process.env.PROSOPO_VERIFY_IMAGE_CAPTCHA_SOLUTION_USER_WINDOW,
32
- limit: process.env.PROSOPO_VERIFY_IMAGE_CAPTCHA_SOLUTION_USER_LIMIT
33
- },
34
- [types.ApiPaths.GetProviderStatus]: {
35
- windowMs: process.env.PROSOPO_GET_PROVIDER_STATUS_WINDOW,
36
- limit: process.env.PROSOPO_GET_PROVIDER_STATUS_LIMIT
37
- },
38
- [types.ApiPaths.GetProviderDetails]: {
39
- windowMs: process.env.PROSOPO_GET_PROVIDER_DETAILS_WINDOW,
40
- limit: process.env.PROSOPO_GET_PROVIDER_DETAILS_LIMIT
41
- },
42
- [types.ApiPaths.SubmitUserEvents]: {
43
- windowMs: process.env.PROSOPO_SUBMIT_USER_EVENTS_WINDOW,
44
- limit: process.env.PROSOPO_SUBMIT_USER_EVENTS_LIMIT
45
- },
46
- [types.AdminApiPaths.BatchCommit]: {
47
- windowMs: process.env.PROSOPO_BATCH_COMMIT_WINDOW,
48
- limit: process.env.PROSOPO_BATCH_COMMIT_LIMIT
49
- },
50
- [types.AdminApiPaths.UpdateDataset]: {
51
- windowMs: process.env.PROSOPO_UPDATE_DATASET_WINDOW,
52
- limit: process.env.PROSOPO_UPDATE_DATASET_LIMIT
53
- },
54
- [types.AdminApiPaths.ProviderDeregister]: {
55
- windowMs: process.env.PROSOPO_PROVIDER_DEREGISTER_WINDOW,
56
- limit: process.env.PROSOPO_PROVIDER_DEREGISTER_LIMIT
57
- },
58
- [types.AdminApiPaths.ProviderUpdate]: {
59
- windowMs: process.env.PROSOPO_PROVIDER_UPDATE_WINDOW,
60
- limit: process.env.PROSOPO_PROVIDER_UPDATE_LIMIT
61
- }
62
- };
63
- };
64
- exports.getRateLimitConfig = getRateLimitConfig;
package/dist/cjs/argv.cjs DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const common = require("@prosopo/common");
4
- const yargs = require("yargs");
5
- const helpers = require("yargs/helpers");
6
- require("./commands/index.cjs");
7
- const providerSetDataset = require("./commands/providerSetDataset.cjs");
8
- const storeCaptchasExternally = require("./commands/storeCaptchasExternally.cjs");
9
- const version = require("./commands/version.cjs");
10
- function processArgs(args, pair, config) {
11
- const logger = common.getLogger(common.LogLevel.enum.info, "CLI");
12
- return yargs(helpers.hideBin(args)).usage("Usage: $0 [global options] <command> [options]").option("api", { demand: false, default: false, type: "boolean" }).option("adminApi", {
13
- demand: false,
14
- default: false,
15
- type: "boolean"
16
- }).command(providerSetDataset(pair, config, { logger })).command(storeCaptchasExternally(pair, config, { logger })).command(version(pair, config, { logger })).parse();
17
- }
18
- exports.processArgs = processArgs;
package/dist/cjs/cli.cjs DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- const process = require("node:process");
3
- const common = require("@prosopo/common");
4
- const contract = require("@prosopo/contract");
5
- const dotenv = require("@prosopo/dotenv");
6
- const util = require("@prosopo/util");
7
- const argv = require("./argv.cjs");
8
- const prosopo_config = require("./prosopo.config.cjs");
9
- const reloader = require("./reloader.cjs");
10
- const log = common.getLogger(common.LogLevel.enum.info, "CLI");
11
- async function main() {
12
- const envPath = dotenv.loadEnv();
13
- const config = prosopo_config(void 0, {
14
- solved: { count: 2 },
15
- unsolved: { count: 0 }
16
- });
17
- if (config.devOnlyWatchEvents) {
18
- log.warn(
19
- `
20
- ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
21
- EVENT TRACKING ON. IF NOT DEVELOPMENT, PLEASE STOP, CHANGE THE ENVIRONMENT, AND RESTART
22
- ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
23
- `
24
- );
25
- }
26
- const pair = await contract.getPairAsync(
27
- config.account.secret,
28
- config.account.address
29
- );
30
- log.info(`Pair address: ${pair.address}`);
31
- const processedArgs = await argv.processArgs(process.argv, pair, config);
32
- log.info(`Processsed args: ${JSON.stringify(processedArgs, null, 4)}`);
33
- if (processedArgs.api) {
34
- if (process.env.NODE_ENV === "development") {
35
- await new reloader(envPath, config, pair, processedArgs).startDev().then(() => {
36
- log.info("Reloading API started...");
37
- });
38
- } else {
39
- await new reloader(envPath, config, pair, processedArgs).start().then(() => {
40
- log.info("Reloading API started...");
41
- });
42
- }
43
- } else {
44
- process.exit(0);
45
- }
46
- }
47
- if (util.isMain(module, "provider")) {
48
- main().then(() => {
49
- log.info("Running main process...");
50
- }).catch((error) => {
51
- log.error(error);
52
- });
53
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const providerSetDataset = require("./providerSetDataset.cjs");
4
- const storeCaptchasExternally = require("./storeCaptchasExternally.cjs");
5
- const version = require("./version.cjs");
6
- exports.commandProviderSetDataset = providerSetDataset;
7
- exports.commandStoreCaptchasExternally = storeCaptchasExternally;
8
- exports.commandVersion = version;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- const common = require("@prosopo/common");
3
- const env = require("@prosopo/env");
4
- const provider = require("@prosopo/provider");
5
- const z = require("zod");
6
- const files = require("../files.cjs");
7
- function _interopNamespaceDefault(e) {
8
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
9
- if (e) {
10
- for (const k in e) {
11
- if (k !== "default") {
12
- const d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: () => e[k]
16
- });
17
- }
18
- }
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
- const z__namespace = /* @__PURE__ */ _interopNamespaceDefault(z);
24
- const commandProviderSetDataset = (pair, config, cmdArgs) => {
25
- const logger = cmdArgs?.logger || common.getLogger(common.LogLevel.enum.info, "cli.provider_set_data_set");
26
- return {
27
- command: "provider_set_data_set",
28
- describe: "Add a dataset as a Provider",
29
- builder: (yargs) => yargs.option("file", {
30
- type: "string",
31
- demand: true,
32
- desc: "The file path of a JSON dataset file"
33
- }),
34
- handler: async (argv) => {
35
- try {
36
- const env$1 = new env.ProviderEnvironment(config, pair);
37
- await env$1.isReady();
38
- const tasks = new provider.Tasks(env$1);
39
- const file = z__namespace.string().parse(argv.file);
40
- const jsonFile = files.loadJSONFile(file);
41
- logger.info(`Loaded JSON from ${file}`);
42
- const result = await tasks.datasetManager.providerSetDatasetFromFile(jsonFile);
43
- logger.info(JSON.stringify(result, null, 2));
44
- } catch (err) {
45
- logger.error(err);
46
- }
47
- },
48
- middlewares: []
49
- };
50
- };
51
- module.exports = commandProviderSetDataset;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- const common = require("@prosopo/common");
3
- const env = require("@prosopo/env");
4
- const provider = require("@prosopo/provider");
5
- const commandStoreCaptchasExternally = (pair, config, cmdArgs) => {
6
- const logger = cmdArgs?.logger || common.getLogger(common.LogLevel.enum.info, "cli.store_captchas");
7
- return {
8
- command: "store_captchas",
9
- describe: "Store captcha records externally for billing purposes",
10
- handler: async () => {
11
- try {
12
- const env$1 = new env.ProviderEnvironment(config, pair);
13
- await env$1.isReady();
14
- const tasks = new provider.Tasks(env$1);
15
- await tasks.clientTaskManager.storeCommitmentsExternal().catch((err) => {
16
- env$1.logger.error(err);
17
- });
18
- } catch (err) {
19
- logger.error(err);
20
- }
21
- },
22
- middlewares: []
23
- };
24
- };
25
- module.exports = commandStoreCaptchasExternally;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- const common = require("@prosopo/common");
3
- const util = require("@prosopo/util");
4
- const commandVersion = (pair, config, cmdArgs) => {
5
- const logger = cmdArgs?.logger || common.getLogger(common.LogLevel.enum.info, "cli.version");
6
- return {
7
- command: "version",
8
- describe: "Return the version of the software",
9
- handler: async () => {
10
- logger.info(`Version: ${JSON.stringify(util.version)}`);
11
- }
12
- };
13
- };
14
- module.exports = commandVersion;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("node:fs");
4
- const node_stream = require("node:stream");
5
- const common = require("@prosopo/common");
6
- function loadJSONFile(filePath) {
7
- try {
8
- return JSON.parse(fs.readFileSync(filePath, "utf8"));
9
- } catch (error) {
10
- throw new common.ProsopoCliError("GENERAL.JSON_LOAD_FAILED", {
11
- context: { error, filePath }
12
- });
13
- }
14
- }
15
- function writeJSONFile(filePath, jsonData) {
16
- return new Promise((resolve, reject) => {
17
- const writeStream = fs.createWriteStream(filePath);
18
- writeStream.setDefaultEncoding("utf-8");
19
- writeStream.on("finish", () => {
20
- resolve(true);
21
- });
22
- writeStream.on("error", (err) => {
23
- reject(err);
24
- });
25
- const readable = node_stream.Readable.from(JSON.stringify(jsonData));
26
- readable.pipe(writeStream);
27
- });
28
- }
29
- async function readFile(filePath) {
30
- return new Promise((resolve, reject) => {
31
- fs.readFile(filePath, (err, data) => {
32
- if (err) reject(err);
33
- resolve(data);
34
- });
35
- });
36
- }
37
- exports.loadJSONFile = loadJSONFile;
38
- exports.readFile = readFile;
39
- exports.writeJSONFile = writeJSONFile;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const argv = require("./argv.cjs");
4
- require("./cli.cjs");
5
- const start = require("./start.cjs");
6
- const process_env = require("./process.env.cjs");
7
- const files = require("./files.cjs");
8
- const prosopo_config = require("./prosopo.config.cjs");
9
- exports.processArgs = argv.processArgs;
10
- exports.start = start.start;
11
- exports.startDev = start.startDev;
12
- exports.getAddress = process_env.getAddress;
13
- exports.getDB = process_env.getDB;
14
- exports.getPairType = process_env.getPairType;
15
- exports.getPassword = process_env.getPassword;
16
- exports.getSecret = process_env.getSecret;
17
- exports.getSs58Format = process_env.getSs58Format;
18
- exports.loadJSONFile = files.loadJSONFile;
19
- exports.readFile = files.readFile;
20
- exports.writeJSONFile = files.writeJSONFile;
21
- exports.defaultConfig = prosopo_config;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const common = require("@prosopo/common");
4
- function getSs58Format() {
5
- return Number.parseInt(process.env.SS58_FORMAT || "") || 42;
6
- }
7
- function getPairType() {
8
- return process.env.PROSOPO_PAIR_TYPE || "sr25519";
9
- }
10
- function getAddress(who) {
11
- if (!who) {
12
- who = "PROVIDER";
13
- } else {
14
- who = who.toUpperCase();
15
- }
16
- return process.env[`PROSOPO_${who}_ADDRESS`];
17
- }
18
- function getPassword(who) {
19
- if (!who) {
20
- who = "PROVIDER";
21
- } else {
22
- who = who.toUpperCase();
23
- }
24
- return process.env[`PROSOPO_${who}_ACCOUNT_PASSWORD`];
25
- }
26
- function getSecret(who) {
27
- if (!who) {
28
- who = "PROVIDER";
29
- } else {
30
- who = who.toUpperCase();
31
- }
32
- return process.env[`PROSOPO_${who}_MNEMONIC`] || process.env[`PROSOPO_${who}_SEED`] || process.env[`PROSOPO_${who}_URI`] || process.env[`PROSOPO_${who}_JSON`];
33
- }
34
- function getDB() {
35
- if (!process.env.PROSOPO_DATABASE_HOST) {
36
- throw new common.ProsopoEnvError("DATABASE.DATABASE_HOST_UNDEFINED");
37
- }
38
- return process.env.PROSOPO_DATABASE_HOST;
39
- }
40
- exports.getAddress = getAddress;
41
- exports.getDB = getDB;
42
- exports.getPairType = getPairType;
43
- exports.getPassword = getPassword;
44
- exports.getSecret = getSecret;
45
- exports.getSs58Format = getSs58Format;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- const common = require("@prosopo/common");
3
- const types = require("@prosopo/types");
4
- const RateLimiter = require("./RateLimiter.cjs");
5
- const process_env = require("./process.env.cjs");
6
- function getMongoURI() {
7
- const protocol = process.env.PROSOPO_DATABASE_PROTOCOL || "mongodb";
8
- const mongoSrv = protocol === "mongodb+srv";
9
- const password = process.env.PROSOPO_DATABASE_PASSWORD || "root";
10
- const username = process.env.PROSOPO_DATABASE_USERNAME || "root";
11
- const host = process.env.PROSOPO_DATABASE_HOST || "localhost";
12
- const port = mongoSrv ? "" : `:${process.env.PROSOPO_DATABASE_PORT || 27017}`;
13
- const retries = mongoSrv ? "?retryWrites=true&w=majority" : "";
14
- const mongoURI = `${protocol}://${username}:${password}@${host}${port}/${retries}`;
15
- return mongoURI;
16
- }
17
- function getConfig(captchaSolutionsConfig, captchaServeConfig, who = "PROVIDER") {
18
- return types.ProsopoConfigSchema.parse({
19
- logLevel: common.getLogLevel(),
20
- defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT ? types.EnvironmentTypesSchema.parse(process.env.PROSOPO_DEFAULT_ENVIRONMENT) : types.EnvironmentTypesSchema.enum.development,
21
- account: {
22
- address: process_env.getAddress(who),
23
- password: process_env.getPassword(who),
24
- secret: process_env.getSecret(who)
25
- },
26
- database: {
27
- development: {
28
- type: types.DatabaseTypes.enum.provider,
29
- endpoint: getMongoURI(),
30
- dbname: process.env.PROSOPO_DATABASE_NAME,
31
- authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
32
- },
33
- staging: {
34
- type: types.DatabaseTypes.enum.provider,
35
- endpoint: getMongoURI(),
36
- dbname: process.env.PROSOPO_DATABASE_NAME,
37
- authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
38
- },
39
- production: {
40
- type: types.DatabaseTypes.enum.provider,
41
- endpoint: getMongoURI(),
42
- dbname: process.env.PROSOPO_DATABASE_NAME,
43
- authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
44
- }
45
- },
46
- server: {
47
- baseURL: process.env.PROSOPO_API_BASE_URL || "http://localhost",
48
- port: process.env.PROSOPO_API_PORT ? Number.parseInt(process.env.PROSOPO_API_PORT) : 9229
49
- },
50
- captchaSolutions: captchaSolutionsConfig,
51
- captchas: captchaServeConfig,
52
- devOnlyWatchEvents: process.env._DEV_ONLY_WATCH_EVENTS === "true",
53
- mongoEventsUri: process.env.PROSOPO_MONGO_EVENTS_URI || "",
54
- mongoCaptchaUri: process.env.PROSOPO_MONGO_CAPTCHA_URI || "",
55
- mongoClientUri: process.env.PROSOPO_MONGO_CLIENT_URI || "",
56
- rateLimits: RateLimiter.getRateLimitConfig(),
57
- proxyCount: process.env.PROSOPO_PROXY_COUNT ? Number.parseInt(process.env.PROSOPO_PROXY_COUNT) : 0,
58
- scheduledTasks: {
59
- captchaScheduler: {
60
- schedule: process.env.CAPTCHA_STORAGE_SCHEDULE
61
- },
62
- clientListScheduler: {
63
- schedule: process.env.CLIENT_LIST_SCHEDULE
64
- }
65
- }
66
- });
67
- }
68
- module.exports = getConfig;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- const fs = require("node:fs");
3
- const common = require("@prosopo/common");
4
- const dotenv = require("@prosopo/dotenv");
5
- const env = require("@prosopo/env");
6
- const start = require("./start.cjs");
7
- const log = common.getLogger(common.LogLevel.enum.info, "CLI");
8
- class ReloadingAPI {
9
- constructor(envPath, config, pair, processedArgs) {
10
- this._envPath = envPath;
11
- this._config = config;
12
- this._pair = pair;
13
- this._processedArgs = processedArgs;
14
- this._restarting = false;
15
- }
16
- get env() {
17
- return this._env;
18
- }
19
- async start(reloadEnv = false) {
20
- log.info("Starting API");
21
- this._envWatcher = await this._watchEnv();
22
- dotenv.loadEnv();
23
- if (!this._env && reloadEnv) {
24
- const env$1 = new env.ProviderEnvironment(this._config, this._pair);
25
- await env$1.isReady();
26
- this._env = env$1;
27
- }
28
- this.api = await start.start(this.env, !!this._processedArgs.adminApi);
29
- }
30
- async startDev() {
31
- log.info("Starting API");
32
- this._envWatcher = await this._watchEnv();
33
- dotenv.loadEnv();
34
- const env$1 = new env.ProviderEnvironment(this._config, this._pair);
35
- await env$1.isReady();
36
- this.api = await start.startDev(env$1, !!this._processedArgs.adminApi);
37
- }
38
- async stop() {
39
- log.info("Stopping API");
40
- return new Promise((resolve) => {
41
- if (this.api) {
42
- this.api.close(resolve);
43
- }
44
- });
45
- }
46
- async _watchEnv() {
47
- return fs.watchFile(this._envPath, async () => {
48
- log.info(`env file change detected. Restarting: ${this._restarting}`);
49
- if (!this._restarting) {
50
- this._restarting = true;
51
- await this.stop();
52
- dotenv.loadEnv();
53
- await this.start(true);
54
- this._restarting = false;
55
- }
56
- });
57
- }
58
- }
59
- module.exports = ReloadingAPI;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const common = require("@prosopo/common");
4
- const contract = require("@prosopo/contract");
5
- const dotenv = require("@prosopo/dotenv");
6
- const env = require("@prosopo/env");
7
- const provider = require("@prosopo/provider");
8
- const cors = require("cors");
9
- const express = require("express");
10
- const rateLimit = require("express-rate-limit");
11
- const process_env = require("./process.env.cjs");
12
- const prosopo_config = require("./prosopo.config.cjs");
13
- function startApi(env2, admin = false, port) {
14
- env2.logger.info("Starting Prosopo API");
15
- const apiApp = express();
16
- const apiPort = port || env2.config.server.port;
17
- apiApp.set(
18
- "trust proxy",
19
- env2.config.proxyCount
20
- );
21
- apiApp.use(cors());
22
- apiApp.use(express.json({ limit: "50mb" }));
23
- apiApp.use(common.i18nMiddleware({}));
24
- apiApp.use(provider.prosopoRouter(env2));
25
- apiApp.use(provider.prosopoVerifyRouter(env2));
26
- if (admin) {
27
- apiApp.use(provider.prosopoAdminRouter(env2));
28
- }
29
- const rateLimits = env2.config.rateLimits;
30
- for (const [path, limit] of Object.entries(rateLimits)) {
31
- const enumPath = path;
32
- apiApp.use(enumPath, rateLimit(limit));
33
- }
34
- return apiApp.listen(apiPort, () => {
35
- env2.logger.info(`Prosopo app listening at http://localhost:${apiPort}`);
36
- });
37
- }
38
- async function start(env$1, admin, port) {
39
- if (!env$1) {
40
- dotenv.loadEnv();
41
- process_env.getDB();
42
- const secret = process_env.getSecret();
43
- const config = prosopo_config(void 0, {
44
- solved: { count: 2 },
45
- unsolved: { count: 0 }
46
- });
47
- const pair = await contract.getPairAsync(secret);
48
- env$1 = new env.ProviderEnvironment(config, pair);
49
- } else {
50
- env$1.logger.debug("Env already defined");
51
- }
52
- await env$1.isReady();
53
- if (env$1.pair) {
54
- provider.storeCaptchasExternally(env$1.pair, env$1.config).catch((err) => {
55
- console.error("Failed to start scheduler:", err);
56
- });
57
- provider.getClientList(env$1.pair, env$1.config).catch((err) => {
58
- console.error("Failed to get client list:", err);
59
- });
60
- }
61
- return startApi(env$1, admin, port);
62
- }
63
- async function startDev(env2, admin) {
64
- start(env2, admin, 9238);
65
- return await start(env2, admin);
66
- }
67
- exports.start = start;
68
- exports.startDev = startDev;
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js DELETED
@@ -1,56 +0,0 @@
1
- import process from "node:process";
2
- import { LogLevel, getLogger } from "@prosopo/common";
3
- import { getPairAsync } from "@prosopo/contract";
4
- import { loadEnv } from "@prosopo/dotenv";
5
- import { isMain } from "@prosopo/util";
6
- import { processArgs } from "./argv.js";
7
- import getConfig from "./prosopo.config.js";
8
- import ReloadingAPI from "./reloader.js";
9
- const log = getLogger(LogLevel.enum.info, "CLI");
10
- async function main() {
11
- const envPath = loadEnv();
12
- const config = getConfig(undefined, {
13
- solved: { count: 2 },
14
- unsolved: { count: 0 },
15
- });
16
- if (config.devOnlyWatchEvents) {
17
- log.warn(`
18
- ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
19
- EVENT TRACKING ON. IF NOT DEVELOPMENT, PLEASE STOP, CHANGE THE ENVIRONMENT, AND RESTART
20
- ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
21
- `);
22
- }
23
- const pair = await getPairAsync(config.account.secret, config.account.address);
24
- log.info(`Pair address: ${pair.address}`);
25
- const processedArgs = await processArgs(process.argv, pair, config);
26
- log.info(`Processsed args: ${JSON.stringify(processedArgs, null, 4)}`);
27
- if (processedArgs.api) {
28
- if (process.env.NODE_ENV === "development") {
29
- await new ReloadingAPI(envPath, config, pair, processedArgs)
30
- .startDev()
31
- .then(() => {
32
- log.info("Reloading API started...");
33
- });
34
- }
35
- else {
36
- await new ReloadingAPI(envPath, config, pair, processedArgs)
37
- .start()
38
- .then(() => {
39
- log.info("Reloading API started...");
40
- });
41
- }
42
- }
43
- else {
44
- process.exit(0);
45
- }
46
- }
47
- if (isMain(import.meta.url, "provider")) {
48
- main()
49
- .then(() => {
50
- log.info("Running main process...");
51
- })
52
- .catch((error) => {
53
- log.error(error);
54
- });
55
- }
56
- //# sourceMappingURL=cli.js.map
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAaA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAEjD,KAAK,UAAU,IAAI;IAClB,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;IAG1B,MAAM,MAAM,GAAwB,SAAS,CAAC,SAAS,EAAE;QACxD,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;QACpB,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;KACtB,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAC/B,GAAG,CAAC,IAAI,CACP;;;;aAIU,CACV,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,YAAY,CAC9B,MAAM,CAAC,OAAO,CAAC,MAAM,EACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CACtB,CAAC;IAEF,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAE1C,MAAM,aAAa,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAEpE,GAAG,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACvE,IAAI,aAAa,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;YAC5C,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC;iBAC1D,QAAQ,EAAE;iBACV,IAAI,CAAC,GAAG,EAAE;gBACV,GAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC;iBAC1D,KAAK,EAAE;iBACP,IAAI,CAAC,GAAG,EAAE;gBACV,GAAG,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACL,CAAC;IACF,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;AACF,CAAC;AAGD,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC;IACzC,IAAI,EAAE;SACJ,IAAI,CAAC,GAAG,EAAE;QACV,GAAG,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACrC,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QAChB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,4 +0,0 @@
1
- export { default as commandProviderSetDataset } from "./providerSetDataset.js";
2
- export { default as commandStoreCaptchasExternally } from "./storeCaptchasExternally.js";
3
- export { default as commandVersion } from "./version.js";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -1,4 +0,0 @@
1
- export { default as commandProviderSetDataset } from "./providerSetDataset.js";
2
- export { default as commandStoreCaptchasExternally } from "./storeCaptchasExternally.js";
3
- export { default as commandVersion } from "./version.js";
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -1,19 +0,0 @@
1
- import type { KeyringPair } from "@polkadot/keyring/types";
2
- import { type Logger } from "@prosopo/common";
3
- import type { ProsopoConfigOutput } from "@prosopo/types";
4
- import type { ArgumentsCamelCase, Argv } from "yargs";
5
- declare const _default: (pair: KeyringPair, config: ProsopoConfigOutput, cmdArgs?: {
6
- logger?: Logger;
7
- }) => {
8
- command: string;
9
- describe: string;
10
- builder: (yargs: Argv) => Argv<{
11
- address: string;
12
- }>;
13
- handler: (argv: ArgumentsCamelCase) => Promise<void>;
14
- middlewares: ((argv: ArgumentsCamelCase) => {
15
- address: string;
16
- })[];
17
- };
18
- export default _default;
19
- //# sourceMappingURL=providerDeregister.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"providerDeregister.d.ts","sourceRoot":"","sources":["../../src/commands/providerDeregister.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAY,KAAK,MAAM,EAAa,MAAM,iBAAiB,CAAC;AAInE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;+BAI/C,WAAW,UACT,mBAAmB,YACjB;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;qBAQX,IAAI;;;oBAMC,kBAAkB;;;;;AAjB1C,wBAmCE"}