@prosopo/cli 3.4.6 → 3.5.0
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 +179 -0
- package/dist/RateLimiter.js +4 -0
- package/dist/argv.js +0 -2
- package/dist/bundle/i18nBackend-D6GWR1ra.js +5260 -0
- package/dist/bundle/provider.cli.bundle.js +116378 -0
- package/dist/cjs/RateLimiter.cjs +4 -0
- package/dist/cjs/argv.cjs +0 -2
- package/dist/cjs/cli.cjs +2 -10
- package/dist/cjs/commands/siteKeyRegister.cjs +6 -1
- package/dist/cjs/commands/siteKeyRegisterApi.cjs +6 -1
- package/dist/cjs/start.cjs +20 -10
- package/dist/cli.js +0 -9
- package/dist/commands/siteKeyRegister.js +7 -2
- package/dist/commands/siteKeyRegisterApi.js +7 -2
- package/dist/start.js +20 -10
- package/package.json +23 -25
- package/dist/cjs/commands/migrateIpInCaptchaRecords/getDb.cjs +0 -32
- package/dist/cjs/commands/migrateIpInCaptchaRecords/migrateIpField.cjs +0 -98
- package/dist/cjs/commands/migrateIpInCaptchaRecords/migrateIpInCaptchaRecords.cjs +0 -56
- package/dist/commands/migrateIpInCaptchaRecords/getDb.js +0 -32
- package/dist/commands/migrateIpInCaptchaRecords/migrateIpField.js +0 -98
- package/dist/commands/migrateIpInCaptchaRecords/migrateIpInCaptchaRecords.js +0 -39
package/dist/cjs/RateLimiter.cjs
CHANGED
|
@@ -51,6 +51,10 @@ const getRateLimitConfig = () => {
|
|
|
51
51
|
windowMs: process.env.PROSOPO_REMOVE_DETECTOR_KEY_WINDOW,
|
|
52
52
|
limit: process.env.PROSOPO_REMOVE_DETECTOR_KEY_LIMIT
|
|
53
53
|
},
|
|
54
|
+
[types.AdminApiPaths.ToggleMaintenanceMode]: {
|
|
55
|
+
windowMs: process.env.PROSOPO_TOGGLE_MAINTENANCE_MODE_WINDOW,
|
|
56
|
+
limit: process.env.PROSOPO_TOGGLE_MAINTENANCE_MODE_LIMIT
|
|
57
|
+
},
|
|
54
58
|
[types.ClientApiPaths.GetFrictionlessCaptchaChallenge]: {
|
|
55
59
|
windowMs: process.env.PROSOPO_GET_FR_CAPTCHA_CHALLENGE_WINDOW,
|
|
56
60
|
limit: process.env.PROSOPO_GET_FR_CAPTCHA_CHALLENGE_LIMIT
|
package/dist/cjs/argv.cjs
CHANGED
|
@@ -4,7 +4,6 @@ const common = require("@prosopo/common");
|
|
|
4
4
|
const yargs = require("yargs");
|
|
5
5
|
const helpers = require("yargs/helpers");
|
|
6
6
|
require("./commands/index.cjs");
|
|
7
|
-
const migrateIpInCaptchaRecords = require("./commands/migrateIpInCaptchaRecords/migrateIpInCaptchaRecords.cjs");
|
|
8
7
|
const ensureIndexes = require("./commands/ensureIndexes.cjs");
|
|
9
8
|
const ensureExternalIndexes = require("./commands/ensureExternalIndexes.cjs");
|
|
10
9
|
const providerSetDataset = require("./commands/providerSetDataset.cjs");
|
|
@@ -20,7 +19,6 @@ function getCommands(pair, config, authAccount, logger) {
|
|
|
20
19
|
storeCaptchasExternally(pair, config, { logger }),
|
|
21
20
|
siteKeyRegister.default(pair, config, { logger }),
|
|
22
21
|
siteKeyRegisterApi(pair, authAccount, config, { logger }),
|
|
23
|
-
migrateIpInCaptchaRecords.migrateIpInCaptchaRecordsCommand(pair, config, logger),
|
|
24
22
|
version(pair, config, { logger })
|
|
25
23
|
];
|
|
26
24
|
}
|
package/dist/cjs/cli.cjs
CHANGED
|
@@ -8,19 +8,11 @@ const util = require("@prosopo/util");
|
|
|
8
8
|
const argv = require("./argv.cjs");
|
|
9
9
|
const prosopo_config = require("./prosopo.config.cjs");
|
|
10
10
|
const reloader = require("./reloader.cjs");
|
|
11
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
11
12
|
const log = common.getLogger(common.LogLevel.enum.info, "CLI");
|
|
12
13
|
async function main() {
|
|
13
14
|
const envPath = dotenv.loadEnv();
|
|
14
15
|
const config = prosopo_config();
|
|
15
|
-
if (config.devOnlyWatchEvents) {
|
|
16
|
-
log.warn(() => ({
|
|
17
|
-
msg: `
|
|
18
|
-
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
|
|
19
|
-
EVENT TRACKING ON. IF NOT DEVELOPMENT, PLEASE STOP, CHANGE THE ENVIRONMENT, AND RESTART
|
|
20
|
-
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
|
|
21
|
-
`
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
16
|
const pair = keyring.getPair(config.account.secret, config.account.address);
|
|
25
17
|
const authAccount = keyring.getPair(
|
|
26
18
|
config.authAccount.secret,
|
|
@@ -42,7 +34,7 @@ async function main() {
|
|
|
42
34
|
process.exit(0);
|
|
43
35
|
}
|
|
44
36
|
}
|
|
45
|
-
if (util.isMain(
|
|
37
|
+
if (util.isMain(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("cli.cjs", document.baseURI).href, "provider")) {
|
|
46
38
|
locale.loadI18next(true).then(() => {
|
|
47
39
|
main().then(() => {
|
|
48
40
|
log.info(() => ({ msg: "Running main process..." }));
|
|
@@ -68,7 +68,12 @@ const commandSiteKeyRegister = (pair, config, cmdArgs) => {
|
|
|
68
68
|
frictionlessThreshold: frictionless_threshold,
|
|
69
69
|
domains: domains || [],
|
|
70
70
|
powDifficulty: pow_difficulty,
|
|
71
|
-
imageThreshold: image_threshold
|
|
71
|
+
imageThreshold: image_threshold,
|
|
72
|
+
disallowWebView: false,
|
|
73
|
+
contextAware: {
|
|
74
|
+
enabled: false,
|
|
75
|
+
threshold: types.contextAwareThresholdDefault
|
|
76
|
+
}
|
|
72
77
|
});
|
|
73
78
|
logger.info(() => ({
|
|
74
79
|
data: { sitekey },
|
|
@@ -74,7 +74,12 @@ const commandSiteKeyRegisterApi = (pair, authAccount, config, cmdArgs) => {
|
|
|
74
74
|
frictionlessThreshold: frictionless_threshold,
|
|
75
75
|
domains: domains || [],
|
|
76
76
|
powDifficulty: pow_difficulty,
|
|
77
|
-
imageThreshold: image_threshold
|
|
77
|
+
imageThreshold: image_threshold,
|
|
78
|
+
disallowWebView: false,
|
|
79
|
+
contextAware: {
|
|
80
|
+
enabled: false,
|
|
81
|
+
threshold: types.contextAwareThresholdDefault
|
|
82
|
+
}
|
|
78
83
|
},
|
|
79
84
|
timestamp,
|
|
80
85
|
signature
|
package/dist/cjs/start.cjs
CHANGED
|
@@ -8,7 +8,7 @@ const keyring = require("@prosopo/keyring");
|
|
|
8
8
|
const locale = require("@prosopo/locale");
|
|
9
9
|
const provider = require("@prosopo/provider");
|
|
10
10
|
const types = require("@prosopo/types");
|
|
11
|
-
const
|
|
11
|
+
const api = require("@prosopo/user-access-policy/api");
|
|
12
12
|
const cors = require("cors");
|
|
13
13
|
const express = require("express");
|
|
14
14
|
const rateLimit = require("express-rate-limit");
|
|
@@ -27,8 +27,9 @@ async function startApi(env2, admin = false, port) {
|
|
|
27
27
|
const apiEndpointAdapter = apiExpressRouter.createApiExpressDefaultEndpointAdapter(
|
|
28
28
|
common.parseLogLevel(env2.config.logLevel)
|
|
29
29
|
);
|
|
30
|
-
const apiRuleRoutesProvider =
|
|
31
|
-
env2.getDb().getUserAccessRulesStorage()
|
|
30
|
+
const apiRuleRoutesProvider = new api.AccessRuleApiRoutes(
|
|
31
|
+
env2.getDb().getUserAccessRulesStorage(),
|
|
32
|
+
env2.logger
|
|
32
33
|
);
|
|
33
34
|
const apiAdminRoutesProvider = provider.createApiAdminRoutesProvider(env2);
|
|
34
35
|
const clientPathsExcludingVerify = getClientApiPathsExcludingVerify();
|
|
@@ -46,8 +47,8 @@ async function startApi(env2, admin = false, port) {
|
|
|
46
47
|
apiApp.use(apiExpressRouter.requestLoggerMiddleware(env2));
|
|
47
48
|
apiApp.use(i18Middleware);
|
|
48
49
|
apiApp.use(provider.ja4Middleware(env2));
|
|
49
|
-
apiApp.use(provider.prosopoVerifyRouter(env2));
|
|
50
50
|
apiApp.use(clientPathsExcludingVerify, provider.headerCheckMiddleware(env2));
|
|
51
|
+
apiApp.use(provider.prosopoVerifyRouter(env2));
|
|
51
52
|
env2.logger.info(() => ({ msg: "Enabling admin auth middleware" }));
|
|
52
53
|
apiApp.use(
|
|
53
54
|
"/v1/prosopo/provider/admin",
|
|
@@ -57,11 +58,8 @@ async function startApi(env2, admin = false, port) {
|
|
|
57
58
|
apiApp.use("/v1/prosopo/provider/client/", provider.domainMiddleware(env2));
|
|
58
59
|
apiApp.use(provider.prosopoRouter(env2));
|
|
59
60
|
const userAccessRuleRoutes = apiRuleRoutesProvider.getRoutes();
|
|
60
|
-
for (const userAccessRuleRoute
|
|
61
|
-
apiApp.use(
|
|
62
|
-
userAccessRuleRoute.path,
|
|
63
|
-
apiExpressRouter.authMiddleware(env2.pair, env2.authAccount)
|
|
64
|
-
);
|
|
61
|
+
for (const userAccessRuleRoute in userAccessRuleRoutes) {
|
|
62
|
+
apiApp.use(userAccessRuleRoute, apiExpressRouter.authMiddleware(env2.pair, env2.authAccount));
|
|
65
63
|
}
|
|
66
64
|
apiApp.use(
|
|
67
65
|
apiExpressRouter.apiExpressRouterFactory.createRouter(
|
|
@@ -80,7 +78,7 @@ async function startApi(env2, admin = false, port) {
|
|
|
80
78
|
)
|
|
81
79
|
);
|
|
82
80
|
const configRateLimits = env2.config.rateLimits;
|
|
83
|
-
const rateLimits = { ...configRateLimits, ...
|
|
81
|
+
const rateLimits = { ...configRateLimits, ...api.getExpressApiRuleRateLimits() };
|
|
84
82
|
for (const [path, limit] of Object.entries(rateLimits)) {
|
|
85
83
|
const enumPath = path;
|
|
86
84
|
apiApp.use(enumPath, rateLimit(limit));
|
|
@@ -136,6 +134,18 @@ async function start(env$1, admin, port) {
|
|
|
136
134
|
}));
|
|
137
135
|
});
|
|
138
136
|
}
|
|
137
|
+
const cronClientEntropySetter = env$1.config.scheduledTasks?.clientEntropyScheduler?.schedule;
|
|
138
|
+
if (cronClientEntropySetter) {
|
|
139
|
+
provider.setClientEntropy(env$1.pair, cronClientEntropySetter, env$1.config).catch(
|
|
140
|
+
(err) => {
|
|
141
|
+
env$1.logger.error(() => ({
|
|
142
|
+
msg: "Failed to start client entropy scheduler",
|
|
143
|
+
err,
|
|
144
|
+
context: { failedFuncName: provider.setClientEntropy.name }
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
139
149
|
}
|
|
140
150
|
return startApi(env$1, admin, port);
|
|
141
151
|
}
|
package/dist/cli.js
CHANGED
|
@@ -11,15 +11,6 @@ const log = getLogger(LogLevel.enum.info, "CLI");
|
|
|
11
11
|
async function main() {
|
|
12
12
|
const envPath = loadEnv();
|
|
13
13
|
const config = getConfig();
|
|
14
|
-
if (config.devOnlyWatchEvents) {
|
|
15
|
-
log.warn(() => ({
|
|
16
|
-
msg: `
|
|
17
|
-
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
|
|
18
|
-
EVENT TRACKING ON. IF NOT DEVELOPMENT, PLEASE STOP, CHANGE THE ENVIRONMENT, AND RESTART
|
|
19
|
-
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
|
|
20
|
-
`
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
14
|
const pair = getPair(config.account.secret, config.account.address);
|
|
24
15
|
const authAccount = getPair(
|
|
25
16
|
config.authAccount.secret,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getLogger, LogLevel } from "@prosopo/common";
|
|
2
2
|
import { ProviderEnvironment } from "@prosopo/env";
|
|
3
3
|
import { Tasks } from "@prosopo/provider";
|
|
4
|
-
import { CaptchaTypeSpec, Tier } from "@prosopo/types";
|
|
4
|
+
import { CaptchaTypeSpec, Tier, contextAwareThresholdDefault } from "@prosopo/types";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { validateSiteKey } from "./validators.js";
|
|
7
7
|
const SiteKeyRegisterCommandArgsSpec = z.object({
|
|
@@ -66,7 +66,12 @@ const commandSiteKeyRegister = (pair, config, cmdArgs) => {
|
|
|
66
66
|
frictionlessThreshold: frictionless_threshold,
|
|
67
67
|
domains: domains || [],
|
|
68
68
|
powDifficulty: pow_difficulty,
|
|
69
|
-
imageThreshold: image_threshold
|
|
69
|
+
imageThreshold: image_threshold,
|
|
70
|
+
disallowWebView: false,
|
|
71
|
+
contextAware: {
|
|
72
|
+
enabled: false,
|
|
73
|
+
threshold: contextAwareThresholdDefault
|
|
74
|
+
}
|
|
70
75
|
});
|
|
71
76
|
logger.info(() => ({
|
|
72
77
|
data: { sitekey },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProviderApi } from "@prosopo/api";
|
|
2
2
|
import { getLogger, LogLevel } from "@prosopo/common";
|
|
3
3
|
import { ProviderEnvironment } from "@prosopo/env";
|
|
4
|
-
import { CaptchaTypeSpec, Tier } from "@prosopo/types";
|
|
4
|
+
import { contextAwareThresholdDefault, CaptchaTypeSpec, Tier } from "@prosopo/types";
|
|
5
5
|
import { u8aToHex } from "@prosopo/util";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { SiteKeyRegisterCommandArgsSpec } from "./siteKeyRegister.js";
|
|
@@ -73,7 +73,12 @@ const commandSiteKeyRegisterApi = (pair, authAccount, config, cmdArgs) => {
|
|
|
73
73
|
frictionlessThreshold: frictionless_threshold,
|
|
74
74
|
domains: domains || [],
|
|
75
75
|
powDifficulty: pow_difficulty,
|
|
76
|
-
imageThreshold: image_threshold
|
|
76
|
+
imageThreshold: image_threshold,
|
|
77
|
+
disallowWebView: false,
|
|
78
|
+
contextAware: {
|
|
79
|
+
enabled: false,
|
|
80
|
+
threshold: contextAwareThresholdDefault
|
|
81
|
+
}
|
|
77
82
|
},
|
|
78
83
|
timestamp,
|
|
79
84
|
signature
|
package/dist/start.js
CHANGED
|
@@ -4,9 +4,9 @@ import { loadEnv } from "@prosopo/dotenv";
|
|
|
4
4
|
import { ProviderEnvironment } from "@prosopo/env";
|
|
5
5
|
import { getPair } from "@prosopo/keyring";
|
|
6
6
|
import { i18nMiddleware } from "@prosopo/locale";
|
|
7
|
-
import { createApiAdminRoutesProvider, publicRouter, robotsMiddleware, ignoreMiddleware, ja4Middleware,
|
|
7
|
+
import { createApiAdminRoutesProvider, publicRouter, robotsMiddleware, ignoreMiddleware, ja4Middleware, headerCheckMiddleware, prosopoVerifyRouter, blockMiddleware, domainMiddleware, prosopoRouter, storeCaptchasExternally, getClientList, setClientEntropy } from "@prosopo/provider";
|
|
8
8
|
import { ClientApiPaths } from "@prosopo/types";
|
|
9
|
-
import {
|
|
9
|
+
import { AccessRuleApiRoutes, getExpressApiRuleRateLimits } from "@prosopo/user-access-policy/api";
|
|
10
10
|
import cors from "cors";
|
|
11
11
|
import express from "express";
|
|
12
12
|
import rateLimit from "express-rate-limit";
|
|
@@ -25,8 +25,9 @@ async function startApi(env, admin = false, port) {
|
|
|
25
25
|
const apiEndpointAdapter = createApiExpressDefaultEndpointAdapter(
|
|
26
26
|
parseLogLevel(env.config.logLevel)
|
|
27
27
|
);
|
|
28
|
-
const apiRuleRoutesProvider =
|
|
29
|
-
env.getDb().getUserAccessRulesStorage()
|
|
28
|
+
const apiRuleRoutesProvider = new AccessRuleApiRoutes(
|
|
29
|
+
env.getDb().getUserAccessRulesStorage(),
|
|
30
|
+
env.logger
|
|
30
31
|
);
|
|
31
32
|
const apiAdminRoutesProvider = createApiAdminRoutesProvider(env);
|
|
32
33
|
const clientPathsExcludingVerify = getClientApiPathsExcludingVerify();
|
|
@@ -44,8 +45,8 @@ async function startApi(env, admin = false, port) {
|
|
|
44
45
|
apiApp.use(requestLoggerMiddleware(env));
|
|
45
46
|
apiApp.use(i18Middleware);
|
|
46
47
|
apiApp.use(ja4Middleware(env));
|
|
47
|
-
apiApp.use(prosopoVerifyRouter(env));
|
|
48
48
|
apiApp.use(clientPathsExcludingVerify, headerCheckMiddleware(env));
|
|
49
|
+
apiApp.use(prosopoVerifyRouter(env));
|
|
49
50
|
env.logger.info(() => ({ msg: "Enabling admin auth middleware" }));
|
|
50
51
|
apiApp.use(
|
|
51
52
|
"/v1/prosopo/provider/admin",
|
|
@@ -55,11 +56,8 @@ async function startApi(env, admin = false, port) {
|
|
|
55
56
|
apiApp.use("/v1/prosopo/provider/client/", domainMiddleware(env));
|
|
56
57
|
apiApp.use(prosopoRouter(env));
|
|
57
58
|
const userAccessRuleRoutes = apiRuleRoutesProvider.getRoutes();
|
|
58
|
-
for (const userAccessRuleRoute
|
|
59
|
-
apiApp.use(
|
|
60
|
-
userAccessRuleRoute.path,
|
|
61
|
-
authMiddleware(env.pair, env.authAccount)
|
|
62
|
-
);
|
|
59
|
+
for (const userAccessRuleRoute in userAccessRuleRoutes) {
|
|
60
|
+
apiApp.use(userAccessRuleRoute, authMiddleware(env.pair, env.authAccount));
|
|
63
61
|
}
|
|
64
62
|
apiApp.use(
|
|
65
63
|
apiExpressRouterFactory.createRouter(
|
|
@@ -134,6 +132,18 @@ async function start(env, admin, port) {
|
|
|
134
132
|
}));
|
|
135
133
|
});
|
|
136
134
|
}
|
|
135
|
+
const cronClientEntropySetter = env.config.scheduledTasks?.clientEntropyScheduler?.schedule;
|
|
136
|
+
if (cronClientEntropySetter) {
|
|
137
|
+
setClientEntropy(env.pair, cronClientEntropySetter, env.config).catch(
|
|
138
|
+
(err) => {
|
|
139
|
+
env.logger.error(() => ({
|
|
140
|
+
msg: "Failed to start client entropy scheduler",
|
|
141
|
+
err,
|
|
142
|
+
context: { failedFuncName: setClientEntropy.name }
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
}
|
|
137
147
|
}
|
|
138
148
|
return startApi(env, admin, port);
|
|
139
149
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "CLI for Prosopo Provider",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
|
-
"node": "
|
|
10
|
-
"npm": "10.
|
|
9
|
+
"node": ">=v20.0.0",
|
|
10
|
+
"npm": ">=10.6.0"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
@@ -30,46 +30,44 @@
|
|
|
30
30
|
"start:dev": "node ./dist/cli.js --api --dev"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@polkadot/types-codec": "
|
|
34
|
-
"@prosopo/api": "3.1.
|
|
35
|
-
"@prosopo/api-express-router": "3.0.
|
|
36
|
-
"@prosopo/common": "3.1.
|
|
37
|
-
"@prosopo/config": "3.1.
|
|
38
|
-
"@prosopo/dotenv": "3.0.
|
|
39
|
-
"@prosopo/env": "3.2.
|
|
40
|
-
"@prosopo/keyring": "2.8.
|
|
41
|
-
"@prosopo/locale": "3.1.
|
|
42
|
-
"@prosopo/provider": "3.
|
|
43
|
-
"@prosopo/types": "3.
|
|
44
|
-
"@prosopo/
|
|
45
|
-
"@prosopo/
|
|
46
|
-
"@prosopo/util": "
|
|
47
|
-
"@prosopo/
|
|
48
|
-
"@prosopo/workspace": "3.1.13",
|
|
33
|
+
"@polkadot/types-codec": "16.4.9",
|
|
34
|
+
"@prosopo/api": "3.1.33",
|
|
35
|
+
"@prosopo/api-express-router": "3.0.34",
|
|
36
|
+
"@prosopo/common": "3.1.22",
|
|
37
|
+
"@prosopo/config": "3.1.22",
|
|
38
|
+
"@prosopo/dotenv": "3.0.27",
|
|
39
|
+
"@prosopo/env": "3.2.22",
|
|
40
|
+
"@prosopo/keyring": "2.8.36",
|
|
41
|
+
"@prosopo/locale": "3.1.22",
|
|
42
|
+
"@prosopo/provider": "3.13.0",
|
|
43
|
+
"@prosopo/types": "3.6.0",
|
|
44
|
+
"@prosopo/user-access-policy": "3.5.28",
|
|
45
|
+
"@prosopo/util": "3.2.0",
|
|
46
|
+
"@prosopo/util-crypto": "13.5.24",
|
|
47
|
+
"@prosopo/workspace": "3.1.15",
|
|
49
48
|
"cors": "2.8.5",
|
|
50
49
|
"cron-parser": "4.9.0",
|
|
51
50
|
"dotenv": "16.4.5",
|
|
52
51
|
"express-rate-limit": "7.4.0",
|
|
53
|
-
"ip-address": "10.0.1",
|
|
54
|
-
"mongodb": "6.15.0",
|
|
55
|
-
"mongoose": "8.13.0",
|
|
56
52
|
"yargs": "17.7.2",
|
|
57
53
|
"zod": "3.23.8"
|
|
58
54
|
},
|
|
59
55
|
"devDependencies": {
|
|
56
|
+
"@polkadot-api/substrate-client": "0.1.4",
|
|
60
57
|
"@types/cors": "2.8.17",
|
|
61
58
|
"@types/node": "22.10.2",
|
|
62
59
|
"@types/yargs": "17.0.33",
|
|
63
|
-
"@vitest/coverage-v8": "3.
|
|
60
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
64
61
|
"concurrently": "9.0.1",
|
|
65
62
|
"del-cli": "6.0.0",
|
|
66
63
|
"express": "4.21.2",
|
|
67
64
|
"npm-run-all": "4.1.5",
|
|
65
|
+
"smoldot": "2.0.26",
|
|
68
66
|
"tslib": "2.7.0",
|
|
69
67
|
"tsx": "4.20.3",
|
|
70
68
|
"typescript": "5.6.2",
|
|
71
|
-
"vite": "6.
|
|
72
|
-
"vitest": "3.
|
|
69
|
+
"vite": "6.4.1",
|
|
70
|
+
"vitest": "3.2.4"
|
|
73
71
|
},
|
|
74
72
|
"author": "Prosopo",
|
|
75
73
|
"license": "Apache-2.0",
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const env = require("@prosopo/env");
|
|
4
|
-
const mongoose = require("mongoose");
|
|
5
|
-
const getDb = async (pair, config, uri, logger) => {
|
|
6
|
-
let db;
|
|
7
|
-
if (uri) {
|
|
8
|
-
logger.info(() => ({
|
|
9
|
-
msg: "Using DB connection from the URI"
|
|
10
|
-
}));
|
|
11
|
-
db = await getByUri(uri);
|
|
12
|
-
} else {
|
|
13
|
-
logger.info(() => ({
|
|
14
|
-
msg: "Using DB connection from the config"
|
|
15
|
-
}));
|
|
16
|
-
db = await getByConfig(pair, config);
|
|
17
|
-
}
|
|
18
|
-
if (db) {
|
|
19
|
-
return db;
|
|
20
|
-
}
|
|
21
|
-
throw new Error("Db connection cannot be established");
|
|
22
|
-
};
|
|
23
|
-
const getByUri = async (uri) => {
|
|
24
|
-
await mongoose.connect(uri);
|
|
25
|
-
return mongoose.connection.db;
|
|
26
|
-
};
|
|
27
|
-
const getByConfig = async (pair, config) => {
|
|
28
|
-
const env$1 = new env.ProviderEnvironment(config, pair);
|
|
29
|
-
await env$1.isReady();
|
|
30
|
-
return env$1.db?.getConnection()?.db;
|
|
31
|
-
};
|
|
32
|
-
exports.getDb = getDb;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const provider = require("@prosopo/provider");
|
|
4
|
-
const typesDatabase = require("@prosopo/types-database");
|
|
5
|
-
const ipAddress = require("ip-address");
|
|
6
|
-
const mongodb = require("mongodb");
|
|
7
|
-
const MAX_IPV4_NUMERIC = 4294967295;
|
|
8
|
-
const BATCH_SIZE = 1e5;
|
|
9
|
-
const migrateIpField = async (db, collectionsToUpgrade, logger) => {
|
|
10
|
-
for (const collection of collectionsToUpgrade) {
|
|
11
|
-
await migrateV4Records(db, collection, logger);
|
|
12
|
-
await migrateV6Records(db, collection, logger);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const migrateV4Records = async (db, collection, logger) => {
|
|
16
|
-
const searchArgs = {
|
|
17
|
-
ipAddress: {
|
|
18
|
-
$type: "number",
|
|
19
|
-
$lte: Number(MAX_IPV4_NUMERIC)
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
let totalModified = 0;
|
|
23
|
-
let processed = 0;
|
|
24
|
-
const count = await db.collection(collection).countDocuments(searchArgs);
|
|
25
|
-
while (true) {
|
|
26
|
-
const docs = await db.collection(collection).find(searchArgs, { projection: { ipAddress: 1 } }).limit(BATCH_SIZE).toArray();
|
|
27
|
-
if (docs.length === 0) break;
|
|
28
|
-
const operations = docs.map((doc) => ({
|
|
29
|
-
updateOne: {
|
|
30
|
-
filter: { _id: doc._id },
|
|
31
|
-
update: {
|
|
32
|
-
$set: {
|
|
33
|
-
ipAddress: {
|
|
34
|
-
lower: doc.ipAddress,
|
|
35
|
-
type: typesDatabase.IpAddressType.v4
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}));
|
|
41
|
-
const bulkResult = await db.collection(collection).bulkWrite(operations, { ordered: false });
|
|
42
|
-
totalModified += bulkResult?.modifiedCount || 0;
|
|
43
|
-
processed += docs.length;
|
|
44
|
-
logger.info(() => ({
|
|
45
|
-
msg: `Migrated v4 batch (${docs.length}) [${processed}/${count}] in "${collection}"`
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
logger.info(() => ({
|
|
49
|
-
msg: `Migrated ${count} v4 records (${totalModified} modified) in "${collection}" collection`
|
|
50
|
-
}));
|
|
51
|
-
};
|
|
52
|
-
const migrateV6Records = async (db, collection, logger) => {
|
|
53
|
-
const searchArgs = {
|
|
54
|
-
ipAddress: {
|
|
55
|
-
$type: "number",
|
|
56
|
-
$gt: Number(MAX_IPV4_NUMERIC)
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
let totalModified = 0;
|
|
60
|
-
let processed = 0;
|
|
61
|
-
const count = await db.collection(collection).countDocuments(searchArgs);
|
|
62
|
-
while (true) {
|
|
63
|
-
const docs = await db.collection(collection).find(searchArgs, { projection: { ipAddress: 1 } }).limit(BATCH_SIZE).toArray();
|
|
64
|
-
if (docs.length === 0) break;
|
|
65
|
-
const operations = docs.map((doc) => {
|
|
66
|
-
const ipAddress$1 = ipAddress.Address6.fromBigInt(BigInt(doc.ipAddress));
|
|
67
|
-
const compositeIpAddress = provider.getCompositeIpAddress(ipAddress$1);
|
|
68
|
-
return {
|
|
69
|
-
updateOne: {
|
|
70
|
-
filter: { _id: doc._id },
|
|
71
|
-
update: {
|
|
72
|
-
$set: {
|
|
73
|
-
ipAddress: {
|
|
74
|
-
lower: mongodb.Decimal128.fromString(
|
|
75
|
-
compositeIpAddress.lower.toString()
|
|
76
|
-
),
|
|
77
|
-
upper: mongodb.Decimal128.fromString(
|
|
78
|
-
(compositeIpAddress.upper || 0n).toString()
|
|
79
|
-
),
|
|
80
|
-
type: typesDatabase.IpAddressType.v6
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
});
|
|
87
|
-
const bulkResult = await db.collection(collection).bulkWrite(operations, { ordered: false });
|
|
88
|
-
totalModified += bulkResult?.modifiedCount || 0;
|
|
89
|
-
processed += docs.length;
|
|
90
|
-
logger.info(() => ({
|
|
91
|
-
msg: `Migrated v6 batch (${docs.length}) [${processed}/${count}] in "${collection}"`
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
logger.info(() => ({
|
|
95
|
-
msg: `Migrated ${count} v6 records (${totalModified} modified) in "${collection}"`
|
|
96
|
-
}));
|
|
97
|
-
};
|
|
98
|
-
exports.migrateIpField = migrateIpField;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const common = require("@prosopo/common");
|
|
4
|
-
const z = require("zod");
|
|
5
|
-
const getDb = require("./getDb.cjs");
|
|
6
|
-
const migrateIpField = require("./migrateIpField.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 collectionsToUpgrade = [
|
|
25
|
-
"powcaptchas",
|
|
26
|
-
"usercommitments",
|
|
27
|
-
"frictionlesstokens",
|
|
28
|
-
"pendings"
|
|
29
|
-
];
|
|
30
|
-
const migrateIpInCaptchaRecordsCommand = (pair, config, logger) => {
|
|
31
|
-
logger = logger || common.getLogger(common.LogLevel.enum.info, "cli.migrate_ip_in_captcha_records");
|
|
32
|
-
return {
|
|
33
|
-
command: "migrateIpInCaptchaRecords",
|
|
34
|
-
describe: "Migrate IP addresses in captcha records",
|
|
35
|
-
builder: (yargs) => yargs.option("uri", {
|
|
36
|
-
type: "string",
|
|
37
|
-
desc: "DB Uri. When skipped, used the default connection based on the current environment"
|
|
38
|
-
}),
|
|
39
|
-
handler: async (argv) => {
|
|
40
|
-
const uri = z__namespace.string().parse(argv.uri || "");
|
|
41
|
-
try {
|
|
42
|
-
const db = await getDb.getDb(pair, config, uri, logger);
|
|
43
|
-
await migrateIpField.migrateIpField(db, collectionsToUpgrade, logger);
|
|
44
|
-
logger.info(() => ({
|
|
45
|
-
msg: "migration completed"
|
|
46
|
-
}));
|
|
47
|
-
} catch (err) {
|
|
48
|
-
logger.error(() => ({
|
|
49
|
-
err,
|
|
50
|
-
msg: "Error migrating captcha records"
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.migrateIpInCaptchaRecordsCommand = migrateIpInCaptchaRecordsCommand;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ProviderEnvironment } from "@prosopo/env";
|
|
2
|
-
import mongoose from "mongoose";
|
|
3
|
-
const getDb = async (pair, config, uri, logger) => {
|
|
4
|
-
let db;
|
|
5
|
-
if (uri) {
|
|
6
|
-
logger.info(() => ({
|
|
7
|
-
msg: "Using DB connection from the URI"
|
|
8
|
-
}));
|
|
9
|
-
db = await getByUri(uri);
|
|
10
|
-
} else {
|
|
11
|
-
logger.info(() => ({
|
|
12
|
-
msg: "Using DB connection from the config"
|
|
13
|
-
}));
|
|
14
|
-
db = await getByConfig(pair, config);
|
|
15
|
-
}
|
|
16
|
-
if (db) {
|
|
17
|
-
return db;
|
|
18
|
-
}
|
|
19
|
-
throw new Error("Db connection cannot be established");
|
|
20
|
-
};
|
|
21
|
-
const getByUri = async (uri) => {
|
|
22
|
-
await mongoose.connect(uri);
|
|
23
|
-
return mongoose.connection.db;
|
|
24
|
-
};
|
|
25
|
-
const getByConfig = async (pair, config) => {
|
|
26
|
-
const env = new ProviderEnvironment(config, pair);
|
|
27
|
-
await env.isReady();
|
|
28
|
-
return env.db?.getConnection()?.db;
|
|
29
|
-
};
|
|
30
|
-
export {
|
|
31
|
-
getDb
|
|
32
|
-
};
|