@prosopo/cli 2.5.5 → 2.6.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.
- package/CHANGELOG.md +49 -0
- package/dist/bundle/{i18nBackend-0BOdS0ng.js → i18nBackend-DMKzoSvT.js} +89 -86
- package/dist/bundle/provider.cli.bundle.js +76884 -73750
- package/dist/cjs/RateLimiter.cjs +60 -0
- package/dist/cjs/argv.cjs +34 -0
- package/dist/cjs/cli.cjs +65 -0
- package/dist/cjs/commands/index.cjs +12 -0
- package/dist/cjs/commands/providerSetDataset.cjs +51 -0
- package/dist/cjs/commands/siteKeyRegister.cjs +82 -0
- package/dist/cjs/commands/siteKeyRegisterApi.cjs +90 -0
- package/dist/cjs/commands/storeCaptchasExternally.cjs +25 -0
- package/dist/cjs/commands/validators.cjs +41 -0
- package/dist/cjs/commands/version.cjs +14 -0
- package/dist/cjs/files.cjs +39 -0
- package/dist/cjs/index.cjs +21 -0
- package/dist/cjs/process.env.cjs +45 -0
- package/dist/cjs/prosopo.config.cjs +87 -0
- package/dist/cjs/reloader.cjs +68 -0
- package/dist/cjs/start.cjs +125 -0
- package/dist/commands/siteKeyRegister.d.ts +5 -0
- package/dist/commands/siteKeyRegister.d.ts.map +1 -1
- package/dist/commands/siteKeyRegister.js +8 -1
- package/dist/commands/siteKeyRegister.js.map +1 -1
- package/dist/commands/siteKeyRegisterApi.d.ts +2 -0
- package/dist/commands/siteKeyRegisterApi.d.ts.map +1 -1
- package/dist/commands/siteKeyRegisterApi.js +7 -1
- package/dist/commands/siteKeyRegisterApi.js.map +1 -1
- package/dist/start.d.ts.map +1 -1
- package/dist/start.js +12 -6
- package/dist/start.js.map +1 -1
- package/package.json +20 -15
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const types = require("@prosopo/types");
|
|
4
|
+
const getRateLimitConfig = () => {
|
|
5
|
+
return {
|
|
6
|
+
[types.ClientApiPaths.GetImageCaptchaChallenge]: {
|
|
7
|
+
windowMs: process.env.PROSOPO_GET_IMAGE_CAPTCHA_CHALLENGE_WINDOW,
|
|
8
|
+
limit: process.env.PROSOPO_GET_IMAGE_CAPTCHA_CHALLENGE_LIMIT
|
|
9
|
+
},
|
|
10
|
+
[types.ClientApiPaths.GetPowCaptchaChallenge]: {
|
|
11
|
+
windowMs: process.env.PROSOPO_GET_POW_CAPTCHA_CHALLENGE_WINDOW,
|
|
12
|
+
limit: process.env.PROSOPO_GET_POW_CAPTCHA_CHALLENGE_LIMIT
|
|
13
|
+
},
|
|
14
|
+
[types.ClientApiPaths.SubmitImageCaptchaSolution]: {
|
|
15
|
+
windowMs: process.env.PROSOPO_SUBMIT_IMAGE_CAPTCHA_SOLUTION_WINDOW,
|
|
16
|
+
limit: process.env.PROSOPO_SUBMIT_IMAGE_CAPTCHA_SOLUTION_LIMIT
|
|
17
|
+
},
|
|
18
|
+
[types.ClientApiPaths.SubmitPowCaptchaSolution]: {
|
|
19
|
+
windowMs: process.env.PROSOPO_SUBMIT_POW_CAPTCHA_SOLUTION_WINDOW,
|
|
20
|
+
limit: process.env.PROSOPO_SUBMIT_POW_CAPTCHA_SOLUTION_LIMIT
|
|
21
|
+
},
|
|
22
|
+
[types.ClientApiPaths.VerifyPowCaptchaSolution]: {
|
|
23
|
+
windowMs: process.env.PROSOPO_VERIFY_POW_CAPTCHA_SOLUTION_WINDOW,
|
|
24
|
+
limit: process.env.PROSOPO_VERIFY_POW_CAPTCHA_SOLUTION_LIMIT
|
|
25
|
+
},
|
|
26
|
+
[types.ClientApiPaths.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.ClientApiPaths.GetProviderStatus]: {
|
|
31
|
+
windowMs: process.env.PROSOPO_GET_PROVIDER_STATUS_WINDOW,
|
|
32
|
+
limit: process.env.PROSOPO_GET_PROVIDER_STATUS_LIMIT
|
|
33
|
+
},
|
|
34
|
+
[types.PublicApiPaths.GetProviderDetails]: {
|
|
35
|
+
windowMs: process.env.PROSOPO_GET_PROVIDER_DETAILS_WINDOW,
|
|
36
|
+
limit: process.env.PROSOPO_GET_PROVIDER_DETAILS_LIMIT
|
|
37
|
+
},
|
|
38
|
+
[types.ClientApiPaths.SubmitUserEvents]: {
|
|
39
|
+
windowMs: process.env.PROSOPO_SUBMIT_USER_EVENTS_WINDOW,
|
|
40
|
+
limit: process.env.PROSOPO_SUBMIT_USER_EVENTS_LIMIT
|
|
41
|
+
},
|
|
42
|
+
[types.AdminApiPaths.SiteKeyRegister]: {
|
|
43
|
+
windowMs: process.env.PROSOPO_SITE_KEY_REGISTER_WINDOW,
|
|
44
|
+
limit: process.env.PROSOPO_SITE_KEY_REGISTER_LIMIT
|
|
45
|
+
},
|
|
46
|
+
[types.AdminApiPaths.UpdateDetectorKey]: {
|
|
47
|
+
windowMs: process.env.PROSOPO_UPDATE_DETECTOR_KEY_WINDOW,
|
|
48
|
+
limit: process.env.PROSOPO_UPDATE_DETECTOR_KEY_LIMIT
|
|
49
|
+
},
|
|
50
|
+
[types.AdminApiPaths.RemoveDetectorKey]: {
|
|
51
|
+
windowMs: process.env.PROSOPO_REMOVE_DETECTOR_KEY_WINDOW,
|
|
52
|
+
limit: process.env.PROSOPO_REMOVE_DETECTOR_KEY_LIMIT
|
|
53
|
+
},
|
|
54
|
+
[types.ClientApiPaths.GetFrictionlessCaptchaChallenge]: {
|
|
55
|
+
windowMs: process.env.PROSOPO_GET_FR_CAPTCHA_CHALLENGE_WINDOW,
|
|
56
|
+
limit: process.env.PROSOPO_GET_FR_CAPTCHA_CHALLENGE_LIMIT
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.getRateLimitConfig = getRateLimitConfig;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 siteKeyRegister = require("./commands/siteKeyRegister.cjs");
|
|
10
|
+
const siteKeyRegisterApi = require("./commands/siteKeyRegisterApi.cjs");
|
|
11
|
+
const version = require("./commands/version.cjs");
|
|
12
|
+
function getCommands(pair, config, authAccount, logger) {
|
|
13
|
+
return [
|
|
14
|
+
providerSetDataset(pair, config, { logger }),
|
|
15
|
+
storeCaptchasExternally(pair, config, { logger }),
|
|
16
|
+
siteKeyRegister.default(pair, config, { logger }),
|
|
17
|
+
siteKeyRegisterApi(pair, authAccount, config, { logger }),
|
|
18
|
+
version(pair, config, { logger })
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
function processArgs(args, pair, authAccount, config) {
|
|
22
|
+
const logger = common.getLogger(common.LogLevel.enum.info, "CLI");
|
|
23
|
+
const commandManager = yargs(helpers.hideBin(args)).usage("Usage: $0 [global options] <command> [options]").option("api", { demand: false, default: false, type: "boolean" }).option("adminApi", {
|
|
24
|
+
demand: false,
|
|
25
|
+
default: false,
|
|
26
|
+
type: "boolean"
|
|
27
|
+
});
|
|
28
|
+
const commands = getCommands(pair, config, authAccount, logger);
|
|
29
|
+
for (const command of commands) {
|
|
30
|
+
commandManager.command(command);
|
|
31
|
+
}
|
|
32
|
+
return commandManager.parse();
|
|
33
|
+
}
|
|
34
|
+
exports.processArgs = processArgs;
|
package/dist/cjs/cli.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const process = require("node:process");
|
|
3
|
+
const common = require("@prosopo/common");
|
|
4
|
+
const dotenv = require("@prosopo/dotenv");
|
|
5
|
+
const keyring = require("@prosopo/keyring");
|
|
6
|
+
const locale = require("@prosopo/locale");
|
|
7
|
+
const util = require("@prosopo/util");
|
|
8
|
+
const argv = require("./argv.cjs");
|
|
9
|
+
const prosopo_config = require("./prosopo.config.cjs");
|
|
10
|
+
const reloader = require("./reloader.cjs");
|
|
11
|
+
const log = common.getLogger(common.LogLevel.enum.info, "CLI");
|
|
12
|
+
async function main() {
|
|
13
|
+
const envPath = dotenv.loadEnv();
|
|
14
|
+
const config = prosopo_config(void 0, {
|
|
15
|
+
solved: { count: 2 },
|
|
16
|
+
unsolved: { count: 0 }
|
|
17
|
+
});
|
|
18
|
+
if (config.devOnlyWatchEvents) {
|
|
19
|
+
log.warn(
|
|
20
|
+
`
|
|
21
|
+
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
|
|
22
|
+
EVENT TRACKING ON. IF NOT DEVELOPMENT, PLEASE STOP, CHANGE THE ENVIRONMENT, AND RESTART
|
|
23
|
+
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
|
|
24
|
+
`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const pair = await keyring.getPairAsync(
|
|
28
|
+
config.account.secret,
|
|
29
|
+
config.account.address
|
|
30
|
+
);
|
|
31
|
+
const authAccount = await keyring.getPairAsync(
|
|
32
|
+
config.authAccount.secret,
|
|
33
|
+
config.authAccount.address
|
|
34
|
+
);
|
|
35
|
+
log.info(`Pair address: ${pair.address}`);
|
|
36
|
+
const processedArgs = await argv.processArgs(
|
|
37
|
+
process.argv,
|
|
38
|
+
pair,
|
|
39
|
+
authAccount,
|
|
40
|
+
config
|
|
41
|
+
);
|
|
42
|
+
log.info({ cliArgs: processedArgs });
|
|
43
|
+
if (processedArgs.api) {
|
|
44
|
+
if (process.env.NODE_ENV === "development") {
|
|
45
|
+
await new reloader(envPath, config, pair, authAccount, processedArgs).startDev().then(() => {
|
|
46
|
+
log.info("Reloading API started...");
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
await new reloader(envPath, config, pair, authAccount, processedArgs).start().then(() => {
|
|
50
|
+
log.info("Reloading API started...");
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (util.isMain(module, "provider")) {
|
|
58
|
+
locale.loadI18next(true).then(() => {
|
|
59
|
+
main().then(() => {
|
|
60
|
+
log.info("Running main process...");
|
|
61
|
+
}).catch((error) => {
|
|
62
|
+
log.error(error);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
const siteKeyRegister = require("./siteKeyRegister.cjs");
|
|
7
|
+
const siteKeyRegisterApi = require("./siteKeyRegisterApi.cjs");
|
|
8
|
+
exports.commandProviderSetDataset = providerSetDataset;
|
|
9
|
+
exports.commandStoreCaptchasExternally = storeCaptchasExternally;
|
|
10
|
+
exports.commandVersion = version;
|
|
11
|
+
exports.commandSiteKeyRegister = siteKeyRegister.default;
|
|
12
|
+
exports.commandSiteKeyRegisterApi = siteKeyRegisterApi;
|
|
@@ -0,0 +1,51 @@
|
|
|
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;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const common = require("@prosopo/common");
|
|
4
|
+
const env = require("@prosopo/env");
|
|
5
|
+
const provider = require("@prosopo/provider");
|
|
6
|
+
const types = require("@prosopo/types");
|
|
7
|
+
const z = require("zod");
|
|
8
|
+
const validators = require("./validators.cjs");
|
|
9
|
+
const SiteKeyRegisterCommandArgsSpec = z.z.object({
|
|
10
|
+
sitekey: z.z.string(),
|
|
11
|
+
tier: z.z.nativeEnum(types.Tier),
|
|
12
|
+
captcha_type: types.CaptchaTypeSpec,
|
|
13
|
+
frictionless_threshold: z.z.number().max(1).min(0),
|
|
14
|
+
pow_difficulty: z.z.number(),
|
|
15
|
+
domains: z.z.array(z.z.string()),
|
|
16
|
+
image_threshold: z.z.number().max(1).min(0)
|
|
17
|
+
});
|
|
18
|
+
const commandSiteKeyRegister = (pair, config, cmdArgs) => {
|
|
19
|
+
const logger = cmdArgs?.logger || common.getLogger(common.LogLevel.enum.info, "cli.dapp_register");
|
|
20
|
+
return {
|
|
21
|
+
command: "site_key_register <sitekey> <tier>",
|
|
22
|
+
describe: "Register a Site Key",
|
|
23
|
+
builder: (yargs) => yargs.positional("sitekey", {
|
|
24
|
+
type: "string",
|
|
25
|
+
demandOption: true,
|
|
26
|
+
desc: "The AccountId of the application to register the Site Key with"
|
|
27
|
+
}).option("tier", {
|
|
28
|
+
type: "string",
|
|
29
|
+
demandOption: false,
|
|
30
|
+
desc: "The AccountId of the application to register the Site Key with"
|
|
31
|
+
}).option("captcha_type", {
|
|
32
|
+
type: "string",
|
|
33
|
+
demandOption: false,
|
|
34
|
+
desc: "Captcha type for settings"
|
|
35
|
+
}).option("domains", {
|
|
36
|
+
type: "array",
|
|
37
|
+
demandOption: false,
|
|
38
|
+
desc: "Domains for settings"
|
|
39
|
+
}).option("frictionless_threshold", {
|
|
40
|
+
type: "number",
|
|
41
|
+
demandOption: false,
|
|
42
|
+
desc: "Frictionless threshold for settings"
|
|
43
|
+
}).option("pow_difficulty", {
|
|
44
|
+
type: "number",
|
|
45
|
+
demandOption: false,
|
|
46
|
+
desc: "POW difficulty for settings"
|
|
47
|
+
}).option("image_threshold", {
|
|
48
|
+
type: "number",
|
|
49
|
+
demandOption: false,
|
|
50
|
+
desc: "Image threshold for settings"
|
|
51
|
+
}),
|
|
52
|
+
handler: async (argv) => {
|
|
53
|
+
try {
|
|
54
|
+
const env$1 = new env.ProviderEnvironment(config, pair);
|
|
55
|
+
await env$1.isReady();
|
|
56
|
+
const {
|
|
57
|
+
sitekey,
|
|
58
|
+
tier,
|
|
59
|
+
captcha_type,
|
|
60
|
+
frictionless_threshold,
|
|
61
|
+
pow_difficulty,
|
|
62
|
+
domains,
|
|
63
|
+
image_threshold
|
|
64
|
+
} = SiteKeyRegisterCommandArgsSpec.parse(argv);
|
|
65
|
+
const tasks = new provider.Tasks(env$1);
|
|
66
|
+
await tasks.clientTaskManager.registerSiteKey(sitekey, tier, {
|
|
67
|
+
captchaType: types.CaptchaTypeSpec.parse(captcha_type),
|
|
68
|
+
frictionlessThreshold: frictionless_threshold,
|
|
69
|
+
domains: domains || [],
|
|
70
|
+
powDifficulty: pow_difficulty,
|
|
71
|
+
imageThreshold: image_threshold
|
|
72
|
+
});
|
|
73
|
+
logger.info(`Site Key ${argv.sitekey} registered`);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
logger.error(err);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
middlewares: [validators.validateSiteKey]
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
exports.SiteKeyRegisterCommandArgsSpec = SiteKeyRegisterCommandArgsSpec;
|
|
82
|
+
exports.default = commandSiteKeyRegister;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const api = require("@prosopo/api");
|
|
3
|
+
const common = require("@prosopo/common");
|
|
4
|
+
const env = require("@prosopo/env");
|
|
5
|
+
const types = require("@prosopo/types");
|
|
6
|
+
const util = require("@prosopo/util");
|
|
7
|
+
const z = require("zod");
|
|
8
|
+
const siteKeyRegister = require("./siteKeyRegister.cjs");
|
|
9
|
+
const validators = require("./validators.cjs");
|
|
10
|
+
const SiteKeyRegisterApiCommandArgsSpec = siteKeyRegister.SiteKeyRegisterCommandArgsSpec.extend(
|
|
11
|
+
{
|
|
12
|
+
url: z.z.string()
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
const commandSiteKeyRegisterApi = (pair, authAccount, config, cmdArgs) => {
|
|
16
|
+
const logger = cmdArgs?.logger || common.getLogger(common.LogLevel.enum.info, "cli.dapp_register");
|
|
17
|
+
return {
|
|
18
|
+
command: "site_key_register_api <sitekey> <url>",
|
|
19
|
+
describe: "Register a Site Key",
|
|
20
|
+
builder: (yargs) => yargs.positional("sitekey", {
|
|
21
|
+
type: "string",
|
|
22
|
+
demandOption: true,
|
|
23
|
+
desc: "The AccountId of the application to register the Site Key with"
|
|
24
|
+
}).positional("tier", {
|
|
25
|
+
choices: Object.values(types.Tier),
|
|
26
|
+
demandOption: true,
|
|
27
|
+
desc: "The tier of the account"
|
|
28
|
+
}).option("url", {
|
|
29
|
+
type: "string",
|
|
30
|
+
demandOption: true,
|
|
31
|
+
desc: "Provider URL to register the Site Key with"
|
|
32
|
+
}).option("captcha_type", {
|
|
33
|
+
type: "string",
|
|
34
|
+
demandOption: false,
|
|
35
|
+
desc: "Captcha type for settings"
|
|
36
|
+
}).option("frictionless_threshold", {
|
|
37
|
+
type: "number",
|
|
38
|
+
demandOption: false,
|
|
39
|
+
desc: "Frictionless threshold for settings"
|
|
40
|
+
}).option("domains", {
|
|
41
|
+
type: "array",
|
|
42
|
+
demandOption: false,
|
|
43
|
+
desc: "URLs for settings"
|
|
44
|
+
}).option("pow_difficulty", {
|
|
45
|
+
type: "number",
|
|
46
|
+
demandOption: false,
|
|
47
|
+
desc: "POW difficulty for settings"
|
|
48
|
+
}).option("image_threshold", {
|
|
49
|
+
type: "number",
|
|
50
|
+
demandOption: false,
|
|
51
|
+
desc: "Image threshold for settings"
|
|
52
|
+
}),
|
|
53
|
+
handler: async (argv) => {
|
|
54
|
+
try {
|
|
55
|
+
const env$1 = new env.ProviderEnvironment(config, pair, authAccount);
|
|
56
|
+
await env$1.isReady();
|
|
57
|
+
const {
|
|
58
|
+
sitekey,
|
|
59
|
+
captcha_type,
|
|
60
|
+
frictionless_threshold,
|
|
61
|
+
url,
|
|
62
|
+
domains,
|
|
63
|
+
pow_difficulty,
|
|
64
|
+
image_threshold
|
|
65
|
+
} = SiteKeyRegisterApiCommandArgsSpec.parse(argv);
|
|
66
|
+
const api$1 = new api.ProviderApi(url, pair.address);
|
|
67
|
+
const timestamp = (/* @__PURE__ */ new Date()).getTime().toString();
|
|
68
|
+
const signature = util.u8aToHex(authAccount.sign(timestamp));
|
|
69
|
+
await api$1.registerSiteKey(
|
|
70
|
+
sitekey,
|
|
71
|
+
argv.tier,
|
|
72
|
+
{
|
|
73
|
+
captchaType: types.CaptchaTypeSpec.parse(captcha_type),
|
|
74
|
+
frictionlessThreshold: frictionless_threshold,
|
|
75
|
+
domains: domains || [],
|
|
76
|
+
powDifficulty: pow_difficulty,
|
|
77
|
+
imageThreshold: image_threshold
|
|
78
|
+
},
|
|
79
|
+
timestamp,
|
|
80
|
+
signature
|
|
81
|
+
);
|
|
82
|
+
logger.info(`Site Key ${argv.sitekey} registered`);
|
|
83
|
+
} catch (err) {
|
|
84
|
+
logger.error(err);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
middlewares: [validators.validateSiteKey]
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
module.exports = commandSiteKeyRegisterApi;
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const common = require("@prosopo/common");
|
|
4
|
+
const provider = require("@prosopo/provider");
|
|
5
|
+
const parser = require("cron-parser");
|
|
6
|
+
const validateAddress = (argv) => {
|
|
7
|
+
const address = provider.encodeStringAddress(argv.address);
|
|
8
|
+
return { address };
|
|
9
|
+
};
|
|
10
|
+
const validateSiteKey = (argv) => {
|
|
11
|
+
const sitekey = provider.encodeStringAddress(argv.sitekey);
|
|
12
|
+
return { sitekey };
|
|
13
|
+
};
|
|
14
|
+
const validateValue = (argv) => {
|
|
15
|
+
if (typeof argv.value !== "number") {
|
|
16
|
+
throw new common.ProsopoEnvError("CLI.PARAMETER_ERROR", {
|
|
17
|
+
context: { value: [argv.value] }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const value = argv.value;
|
|
21
|
+
return { value };
|
|
22
|
+
};
|
|
23
|
+
const validateScheduleExpression = (argv) => {
|
|
24
|
+
if (typeof argv.schedule === "string") {
|
|
25
|
+
const result = parser.parseString(argv.schedule);
|
|
26
|
+
if (argv.schedule in result.errors) {
|
|
27
|
+
throw new common.ProsopoEnvError("CLI.PARAMETER_ERROR", {
|
|
28
|
+
context: {
|
|
29
|
+
payee: [argv.shedule],
|
|
30
|
+
failedFuncName: validateScheduleExpression.name
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return { schedule: argv.schedule };
|
|
35
|
+
}
|
|
36
|
+
return { schedule: null };
|
|
37
|
+
};
|
|
38
|
+
exports.validateAddress = validateAddress;
|
|
39
|
+
exports.validateScheduleExpression = validateScheduleExpression;
|
|
40
|
+
exports.validateSiteKey = validateSiteKey;
|
|
41
|
+
exports.validateValue = validateValue;
|
|
@@ -0,0 +1,14 @@
|
|
|
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: () => {
|
|
10
|
+
logger.info(`Version: ${JSON.stringify(util.version)}`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
module.exports = commandVersion;
|
|
@@ -0,0 +1,39 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
@@ -0,0 +1,45 @@
|
|
|
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;
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
const getLRules = () => {
|
|
18
|
+
if (!process.env.L_RULES) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(process.env.L_RULES);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function getConfig(captchaSolutionsConfig, captchaServeConfig, who = "PROVIDER", admin = "ADMIN") {
|
|
28
|
+
return types.ProsopoConfigSchema.parse({
|
|
29
|
+
logLevel: common.getLogLevel(),
|
|
30
|
+
defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT ? types.EnvironmentTypesSchema.parse(process.env.PROSOPO_DEFAULT_ENVIRONMENT) : types.EnvironmentTypesSchema.enum.development,
|
|
31
|
+
account: {
|
|
32
|
+
address: process_env.getAddress(who),
|
|
33
|
+
password: process_env.getPassword(who),
|
|
34
|
+
secret: process_env.getSecret(who)
|
|
35
|
+
},
|
|
36
|
+
database: {
|
|
37
|
+
development: {
|
|
38
|
+
type: types.DatabaseTypes.enum.provider,
|
|
39
|
+
endpoint: getMongoURI(),
|
|
40
|
+
dbname: process.env.PROSOPO_DATABASE_NAME,
|
|
41
|
+
authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
|
|
42
|
+
},
|
|
43
|
+
staging: {
|
|
44
|
+
type: types.DatabaseTypes.enum.provider,
|
|
45
|
+
endpoint: getMongoURI(),
|
|
46
|
+
dbname: process.env.PROSOPO_DATABASE_NAME,
|
|
47
|
+
authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
|
|
48
|
+
},
|
|
49
|
+
production: {
|
|
50
|
+
type: types.DatabaseTypes.enum.provider,
|
|
51
|
+
endpoint: getMongoURI(),
|
|
52
|
+
dbname: process.env.PROSOPO_DATABASE_NAME,
|
|
53
|
+
authSource: process.env.PROSOPO_DATABASE_AUTH_SOURCE
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
server: {
|
|
57
|
+
baseURL: process.env.PROSOPO_API_BASE_URL || "http://localhost",
|
|
58
|
+
port: process.env.PROSOPO_API_PORT ? Number.parseInt(process.env.PROSOPO_API_PORT) : 9229
|
|
59
|
+
},
|
|
60
|
+
captchaSolutions: captchaSolutionsConfig,
|
|
61
|
+
captchas: captchaServeConfig,
|
|
62
|
+
penalties: types.FrictionlessPenalties.parse({
|
|
63
|
+
PENALTY_OLD_TIMESTAMP: process.env.PENALTY_OLD_TIMESTAMP,
|
|
64
|
+
PENALTY_ACCESS_RULE: process.env.PENALTY_ACCESS_RULE
|
|
65
|
+
}),
|
|
66
|
+
mongoEventsUri: process.env.PROSOPO_MONGO_EVENTS_URI || "",
|
|
67
|
+
mongoCaptchaUri: process.env.PROSOPO_MONGO_CAPTCHA_URI || "",
|
|
68
|
+
mongoClientUri: process.env.PROSOPO_MONGO_CLIENT_URI || "",
|
|
69
|
+
rateLimits: RateLimiter.getRateLimitConfig(),
|
|
70
|
+
proxyCount: process.env.PROSOPO_PROXY_COUNT ? Number.parseInt(process.env.PROSOPO_PROXY_COUNT) : 0,
|
|
71
|
+
scheduledTasks: {
|
|
72
|
+
captchaScheduler: {
|
|
73
|
+
schedule: process.env.CAPTCHA_STORAGE_SCHEDULE
|
|
74
|
+
},
|
|
75
|
+
clientListScheduler: {
|
|
76
|
+
schedule: process.env.CLIENT_LIST_SCHEDULE
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
lRules: getLRules(),
|
|
80
|
+
authAccount: {
|
|
81
|
+
address: process_env.getAddress(admin),
|
|
82
|
+
password: process_env.getPassword(admin),
|
|
83
|
+
secret: process_env.getSecret(admin)
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
module.exports = getConfig;
|