@prosopo/scripts 3.1.138 → 3.1.140
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/.turbo/turbo-build$colon$cjs.log +20 -35
- package/.turbo/turbo-build$colon$tsc.log +28 -28
- package/.turbo/turbo-build.log +24 -38
- package/CHANGELOG.md +35 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/cli/index.cjs +77 -81
- package/dist/cjs/index.cjs +16 -17
- package/dist/cjs/scripts/setVersion.cjs +119 -127
- package/dist/cjs/setup/index.cjs +5 -7
- package/dist/cjs/setup/provider.cjs +8 -8
- package/dist/cjs/setup/setup.cjs +109 -123
- package/dist/cjs/setup/site.cjs +21 -22
- package/dist/cjs/util/exec.cjs +35 -44
- package/dist/cjs/util/fluxLogDappDetails.cjs +10 -15
- package/dist/cjs/util/index.cjs +8 -10
- package/dist/cjs/util/updateEnv.cjs +61 -61
- package/dist/cli/index.js +69 -80
- package/dist/index.js +7 -16
- package/dist/scripts/setVersion.js +110 -126
- package/dist/setup/index.js +2 -6
- package/dist/setup/provider.js +7 -7
- package/dist/setup/setup.js +97 -119
- package/dist/setup/site.js +21 -22
- package/dist/util/exec.js +34 -43
- package/dist/util/fluxLogDappDetails.js +11 -16
- package/dist/util/index.js +1 -7
- package/dist/util/updateEnv.js +52 -59
- package/dist/workspace/dist/_virtual/_rolldown/runtime.js +2 -0
- package/dist/workspace/dist/index.js +2 -41
- package/dist/workspace/dist/projectInfo.js +80 -114
- package/package.json +18 -18
|
@@ -1,134 +1,118 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getRootDir } from "../workspace/dist/projectInfo.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { parse, stringify } from "@iarna/toml";
|
|
4
3
|
import { loadEnv } from "@prosopo/dotenv";
|
|
5
|
-
import {
|
|
6
|
-
import "
|
|
7
|
-
import {
|
|
4
|
+
import { getLogger, parseLogLevel } from "@prosopo/logger";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { parse, stringify } from "@iarna/toml";
|
|
7
|
+
//#region src/scripts/setVersion.ts
|
|
8
8
|
loadEnv();
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
var logLevel = parseLogLevel(process.env.PROSOPO_LOG_LEVEL);
|
|
10
|
+
var log = getLogger(logLevel, "setVersion");
|
|
11
11
|
log.info(() => ({ data: { logLevel } }));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return `${major}.${minor}.${patch}`;
|
|
26
|
-
} catch (e) {
|
|
27
|
-
throw new Error("Version must be in the format of x.y.z");
|
|
28
|
-
}
|
|
12
|
+
var parseVersion = (version) => {
|
|
13
|
+
try {
|
|
14
|
+
const parts = version.split(".");
|
|
15
|
+
if (parts.length !== 3) throw new Error();
|
|
16
|
+
let [major, minor, patch] = parts;
|
|
17
|
+
major = Number.parseInt(major ?? "").toString();
|
|
18
|
+
minor = Number.parseInt(minor ?? "").toString();
|
|
19
|
+
patch = Number.parseInt(patch ?? "").toString();
|
|
20
|
+
if (major === "NaN" || minor === "NaN" || patch === "NaN") throw new Error();
|
|
21
|
+
return `${major}.${minor}.${patch}`;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw new Error("Version must be in the format of x.y.z");
|
|
24
|
+
}
|
|
29
25
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return results;
|
|
26
|
+
var find = (pth, filter) => {
|
|
27
|
+
const files = fs.readdirSync(pth);
|
|
28
|
+
const results = [];
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
const fullPath = path.join(pth, file);
|
|
31
|
+
if (filter(fullPath)) results.push(fullPath);
|
|
32
|
+
try {
|
|
33
|
+
if (fs.statSync(fullPath).isDirectory()) results.push(...find(fullPath, filter));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
log.debug(() => ({
|
|
36
|
+
data: { fullPath },
|
|
37
|
+
msg: "Not a directory"
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
47
42
|
};
|
|
48
43
|
async function setVersion(versionIn, ignore) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const depContent = fs.readFileSync(pth, "utf8");
|
|
122
|
-
const depTomlContent = parse(depContent);
|
|
123
|
-
value.version = depTomlContent.version;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
fs.writeFileSync(pth, `${stringify(tomlContent)}
|
|
129
|
-
`);
|
|
130
|
-
});
|
|
44
|
+
log.info(() => ({
|
|
45
|
+
data: { versionIn },
|
|
46
|
+
msg: "Setting version to"
|
|
47
|
+
}));
|
|
48
|
+
const version = parseVersion(versionIn);
|
|
49
|
+
const root = getRootDir();
|
|
50
|
+
const ignorePaths = [
|
|
51
|
+
"node_modules",
|
|
52
|
+
"cargo-cache",
|
|
53
|
+
...ignore ?? []
|
|
54
|
+
];
|
|
55
|
+
log.debug(() => ({
|
|
56
|
+
data: { ignorePaths },
|
|
57
|
+
msg: "Ignoring paths"
|
|
58
|
+
}));
|
|
59
|
+
const files = find(root, (pth) => {
|
|
60
|
+
if (ignorePaths.some((ignorePath) => pth.includes(ignorePath))) return false;
|
|
61
|
+
const basename = path.basename(pth);
|
|
62
|
+
return basename === "package.json" || basename === "Cargo.toml";
|
|
63
|
+
});
|
|
64
|
+
files.filter((pth) => path.extname(pth) === ".json").forEach((pth) => {
|
|
65
|
+
log.debug(() => ({
|
|
66
|
+
data: { pth },
|
|
67
|
+
msg: "setting version in"
|
|
68
|
+
}));
|
|
69
|
+
const content = fs.readFileSync(pth, "utf8");
|
|
70
|
+
const jsonContent = JSON.parse(content);
|
|
71
|
+
if (jsonContent.version) jsonContent.version = version;
|
|
72
|
+
for (const obj of [
|
|
73
|
+
jsonContent.dependencies ?? {},
|
|
74
|
+
jsonContent.devDependencies ?? {},
|
|
75
|
+
jsonContent.peerDependencies ?? {}
|
|
76
|
+
]) for (const key of Object.keys(obj)) if (key.startsWith("@prosopo") && !key.includes("typechain")) {
|
|
77
|
+
log.debug(() => ({
|
|
78
|
+
data: {
|
|
79
|
+
key,
|
|
80
|
+
version,
|
|
81
|
+
pth
|
|
82
|
+
},
|
|
83
|
+
msg: "setting dependency version"
|
|
84
|
+
}));
|
|
85
|
+
obj[key] = version;
|
|
86
|
+
}
|
|
87
|
+
fs.writeFileSync(pth, `${JSON.stringify(jsonContent, null, 4)}\n`);
|
|
88
|
+
});
|
|
89
|
+
files.filter((pth) => path.extname(pth) === ".toml").filter((pth) => {
|
|
90
|
+
return !ignorePaths.some((ignorePath) => pth.includes(ignorePath));
|
|
91
|
+
}).forEach((pth) => {
|
|
92
|
+
log.debug(() => ({
|
|
93
|
+
data: { pth },
|
|
94
|
+
msg: "setting version in"
|
|
95
|
+
}));
|
|
96
|
+
const tomlContent = parse(fs.readFileSync(pth, "utf8"));
|
|
97
|
+
if (tomlContent.workspace) {
|
|
98
|
+
if (tomlContent.workspace.version) tomlContent.workspace.version = version;
|
|
99
|
+
} else tomlContent.package.version = version;
|
|
100
|
+
fs.writeFileSync(pth, `${stringify(tomlContent)}\n`);
|
|
101
|
+
});
|
|
102
|
+
files.filter((pth) => path.extname(pth) === ".toml").forEach((pth) => {
|
|
103
|
+
log.debug(() => ({
|
|
104
|
+
data: { pth },
|
|
105
|
+
msg: "setting dependency versions in"
|
|
106
|
+
}));
|
|
107
|
+
const tomlContent = parse(fs.readFileSync(pth, "utf8"));
|
|
108
|
+
if (tomlContent.workspace) {
|
|
109
|
+
if (tomlContent.workspace.version) tomlContent.workspace.version = version;
|
|
110
|
+
} else for (const obj of [tomlContent.dependencies ?? {}, tomlContent["dev-dependencies"] ?? {}]) for (const [key, value] of Object.entries(obj)) if (value.path) {
|
|
111
|
+
path.join(value.path, "Cargo.toml");
|
|
112
|
+
value.version = parse(fs.readFileSync(pth, "utf8")).version;
|
|
113
|
+
}
|
|
114
|
+
fs.writeFileSync(pth, `${stringify(tomlContent)}\n`);
|
|
115
|
+
});
|
|
131
116
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
};
|
|
117
|
+
//#endregion
|
|
118
|
+
export { setVersion as default };
|
package/dist/setup/index.js
CHANGED
package/dist/setup/provider.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { datasetWithSolutionHashes } from "@prosopo/datasets";
|
|
2
2
|
import { Tasks } from "@prosopo/provider";
|
|
3
|
+
//#region src/setup/provider.ts
|
|
3
4
|
async function setupProvider(env) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const logger = env.logger;
|
|
6
|
+
const tasks = new Tasks(env);
|
|
7
|
+
logger.info(() => ({ msg: " - providerSetDataset" }));
|
|
8
|
+
await tasks.datasetManager.providerSetDataset(datasetWithSolutionHashes);
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { setupProvider };
|
package/dist/setup/setup.js
CHANGED
|
@@ -1,139 +1,117 @@
|
|
|
1
|
+
import { updateDemoHTMLFiles, updateEnvFiles } from "../util/updateEnv.js";
|
|
2
|
+
import "../util/index.js";
|
|
3
|
+
import { setupProvider } from "./provider.js";
|
|
4
|
+
import { registerSiteKey } from "./site.js";
|
|
1
5
|
import path from "node:path";
|
|
2
|
-
import {
|
|
6
|
+
import { defaultConfig, getSecret } from "@prosopo/cli";
|
|
3
7
|
import { ProsopoEnvError } from "@prosopo/common";
|
|
4
8
|
import { getEnvFile } from "@prosopo/dotenv";
|
|
5
9
|
import { ProviderEnvironment } from "@prosopo/env";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
10
|
+
import { generateMnemonic, getDefaultSiteKeys, getPair } from "@prosopo/keyring";
|
|
11
|
+
import { LogLevel, getLogger } from "@prosopo/logger";
|
|
8
12
|
import { get } from "@prosopo/util";
|
|
9
13
|
import fse from "fs-extra";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { updateDemoHTMLFiles, updateEnvFiles } from "../util/updateEnv.js";
|
|
14
|
-
const logger = getLogger(LogLevel.enum.info, "setup");
|
|
15
|
-
const __dirname = path.resolve();
|
|
14
|
+
//#region src/setup/setup.ts
|
|
15
|
+
var logger = getLogger(LogLevel.enum.info, "setup");
|
|
16
|
+
var __dirname = path.resolve();
|
|
16
17
|
function getRootDir() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const rootDir = process.env.PROSOPO_ROOT_DIR || path.resolve(__dirname, "../..");
|
|
19
|
+
logger.info(() => ({
|
|
20
|
+
msg: "Root dir:",
|
|
21
|
+
data: { rootDir }
|
|
22
|
+
}));
|
|
23
|
+
return rootDir;
|
|
20
24
|
}
|
|
21
25
|
function getDatasetFilePath() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
const datasetFile = process.env.PROSOPO_PROVIDER_DATASET_FILE || path.resolve("../data/captchas.json");
|
|
27
|
+
logger.info(() => ({
|
|
28
|
+
msg: "Dataset file:",
|
|
29
|
+
data: { datasetFile }
|
|
30
|
+
}));
|
|
31
|
+
return datasetFile;
|
|
25
32
|
}
|
|
26
33
|
function getDefaultProvider() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const host = process.env.PROSOPO_PROVIDER_HOST || "localhost";
|
|
35
|
+
return {
|
|
36
|
+
url: process.env.PROSOPO_API_PORT ? `https://${host}:${process.env.PROSOPO_API_PORT}` : `https://${host}:9229`,
|
|
37
|
+
datasetFile: getDatasetFilePath(),
|
|
38
|
+
address: process.env.PROSOPO_PROVIDER_ADDRESS || "",
|
|
39
|
+
secret: getSecret(),
|
|
40
|
+
captchaDatasetId: "",
|
|
41
|
+
pair: getPair(getSecret())
|
|
42
|
+
};
|
|
36
43
|
}
|
|
37
44
|
async function copyEnvFile() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
try {
|
|
46
|
+
const rootDir = getRootDir();
|
|
47
|
+
const tplLocation = path.resolve(rootDir, "./dev/scripts");
|
|
48
|
+
const tplEnvFile = getEnvFile(tplLocation, "env");
|
|
49
|
+
const envFile = getEnvFile(tplLocation, ".env");
|
|
50
|
+
await fse.copy(tplEnvFile, envFile, { overwrite: false });
|
|
51
|
+
} catch (err) {
|
|
52
|
+
logger.debug(() => ({
|
|
53
|
+
msg: "Error copying env file",
|
|
54
|
+
err
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
47
57
|
}
|
|
48
58
|
function updateEnvFileVar(source, name, value) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return `${source}
|
|
54
|
-
${name}=${value}`;
|
|
59
|
+
const envVar = new RegExp(`.*(${name}=)(.*)`, "g");
|
|
60
|
+
if (envVar.test(source)) return source.replace(envVar, `$1${value}`);
|
|
61
|
+
return `${source}\n${name}=${value}`;
|
|
55
62
|
}
|
|
56
63
|
async function updateEnvFile(vars) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
logger.info(() => ({ msg: `Updating ${envFile}` }));
|
|
64
|
-
await fse.writeFile(envFile, readEnvFile);
|
|
64
|
+
const envFile = getEnvFile(getRootDir(), ".env");
|
|
65
|
+
let readEnvFile = await fse.readFile(envFile, "utf8");
|
|
66
|
+
for (const key in vars) readEnvFile = updateEnvFileVar(readEnvFile, key, get(vars, key));
|
|
67
|
+
logger.info(() => ({ msg: `Updating ${envFile}` }));
|
|
68
|
+
await fse.writeFile(envFile, readEnvFile);
|
|
65
69
|
}
|
|
66
70
|
async function setup(provider, sites) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}));
|
|
112
|
-
await registerSiteKey(env, siteKey.pair.address, siteKey.settings);
|
|
113
|
-
env.logger.debug(() => ({
|
|
114
|
-
msg: "Updating env files with PROSOPO_SITE_KEY"
|
|
115
|
-
}));
|
|
116
|
-
await updateDemoHTMLFiles(
|
|
117
|
-
[/data-sitekey="(\w{48})"/, /siteKey:\s*'(\w{48})'/],
|
|
118
|
-
siteKey.pair.address,
|
|
119
|
-
env.logger
|
|
120
|
-
);
|
|
121
|
-
const envVarNames = siteKey.settings.captchaType === "image" ? [
|
|
122
|
-
"PROSOPO_SITE_KEY",
|
|
123
|
-
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`
|
|
124
|
-
] : [
|
|
125
|
-
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`
|
|
126
|
-
];
|
|
127
|
-
await updateEnvFiles(envVarNames, siteKey.pair.address, env.logger);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
process.exit();
|
|
131
|
-
} else {
|
|
132
|
-
console.error("no secret found in .env file");
|
|
133
|
-
throw new ProsopoEnvError("GENERAL.NO_MNEMONIC_OR_SEED");
|
|
134
|
-
}
|
|
71
|
+
if (!provider && !sites) {
|
|
72
|
+
logger.info(() => ({ msg: "No setup required, exiting." }));
|
|
73
|
+
process.exit(0);
|
|
74
|
+
}
|
|
75
|
+
const defaultProvider = getDefaultProvider();
|
|
76
|
+
if (defaultProvider.secret) {
|
|
77
|
+
const hasProviderAccount = defaultProvider.address && defaultProvider.secret;
|
|
78
|
+
logger.debug(() => ({
|
|
79
|
+
msg: "ENVIRONMENT",
|
|
80
|
+
data: { nodeEnv: process.env.NODE_ENV }
|
|
81
|
+
}));
|
|
82
|
+
const [mnemonic, address] = !hasProviderAccount ? await generateMnemonic() : [defaultProvider.secret, defaultProvider.address];
|
|
83
|
+
logger.debug(() => ({ msg: `Address: ${address}` }));
|
|
84
|
+
logger.debug(() => ({ msg: `Mnemonic: ${mnemonic}` }));
|
|
85
|
+
logger.debug(() => ({ msg: "Writing .env file..." }));
|
|
86
|
+
await copyEnvFile();
|
|
87
|
+
if (!process.env.PROSOPO_SITE_KEY) throw new ProsopoEnvError("DEVELOPER.PROSOPO_SITE_KEY_MISSING");
|
|
88
|
+
const config = defaultConfig();
|
|
89
|
+
const providerSecret = config.account.secret;
|
|
90
|
+
const env = new ProviderEnvironment(config, getPair(providerSecret), getPair(config.authAccount.secret));
|
|
91
|
+
await env.isReady();
|
|
92
|
+
defaultProvider.secret = mnemonic;
|
|
93
|
+
env.logger.info(() => ({ msg: `Registering provider... ${defaultProvider.address}` }));
|
|
94
|
+
defaultProvider.pair = getPair(providerSecret);
|
|
95
|
+
if (provider) {
|
|
96
|
+
await setupProvider(env);
|
|
97
|
+
if (!hasProviderAccount) await updateEnvFile({
|
|
98
|
+
PROVIDER_MNEMONIC: `"${mnemonic}"`,
|
|
99
|
+
PROVIDER_ADDRESS: address
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (sites) for (const siteKey of getDefaultSiteKeys()) {
|
|
103
|
+
siteKey.pair = getPair(siteKey.secret);
|
|
104
|
+
env.logger.info(() => ({ msg: `Registering ${siteKey.secret} siteKey ... ${siteKey.pair?.address}` }));
|
|
105
|
+
await registerSiteKey(env, siteKey.pair.address, siteKey.settings);
|
|
106
|
+
env.logger.debug(() => ({ msg: "Updating env files with PROSOPO_SITE_KEY" }));
|
|
107
|
+
await updateDemoHTMLFiles([/data-sitekey="(\w{48})"/, /siteKey:\s*'(\w{48})'/], siteKey.pair.address, env.logger);
|
|
108
|
+
await updateEnvFiles(siteKey.settings.captchaType === "image" ? ["PROSOPO_SITE_KEY", `PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`] : [`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`], siteKey.pair.address, env.logger);
|
|
109
|
+
}
|
|
110
|
+
process.exit();
|
|
111
|
+
} else {
|
|
112
|
+
console.error("no secret found in .env file");
|
|
113
|
+
throw new ProsopoEnvError("GENERAL.NO_MNEMONIC_OR_SEED");
|
|
114
|
+
}
|
|
135
115
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
updateEnvFile
|
|
139
|
-
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { setup, updateEnvFile };
|
package/dist/setup/site.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { Tasks } from "@prosopo/provider";
|
|
2
|
-
import {
|
|
2
|
+
import { CaptchaType, ClientSettingsSchema, Tier } from "@prosopo/types";
|
|
3
|
+
//#region src/setup/site.ts
|
|
3
4
|
async function registerSiteKey(env, siteKey, settings = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
5
|
+
const logger = env.logger;
|
|
6
|
+
const tasks = new Tasks(env);
|
|
7
|
+
logger.info(() => ({
|
|
8
|
+
msg: "registerSiteKey",
|
|
9
|
+
data: {
|
|
10
|
+
siteKey,
|
|
11
|
+
captchaType: settings.captchaType
|
|
12
|
+
}
|
|
13
|
+
}));
|
|
14
|
+
await tasks.clientTaskManager.registerSiteKey(siteKey, Tier.Professional, ClientSettingsSchema.parse({
|
|
15
|
+
captchaType: CaptchaType.frictionless,
|
|
16
|
+
frictionlessThreshold: .8,
|
|
17
|
+
powDifficulty: 4,
|
|
18
|
+
imageThreshold: .8,
|
|
19
|
+
...settings,
|
|
20
|
+
domains: settings.domains && settings.domains.length > 0 ? settings.domains : ["localhost", "0.0.0.0"]
|
|
21
|
+
}));
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { registerSiteKey };
|
package/dist/util/exec.js
CHANGED
|
@@ -1,46 +1,37 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { stdin } from "node:process";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
if (code === 0) {
|
|
37
|
-
resolve(output);
|
|
38
|
-
} else {
|
|
39
|
-
reject(output);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
export {
|
|
45
|
-
exec
|
|
3
|
+
//#region src/util/exec.ts
|
|
4
|
+
var exec = (command, options) => {
|
|
5
|
+
let { pipe, printCmd } = options || {};
|
|
6
|
+
pipe = pipe === void 0 || pipe;
|
|
7
|
+
printCmd = printCmd === void 0 || printCmd;
|
|
8
|
+
if (printCmd) console.log(`[exec] ${command}`);
|
|
9
|
+
const prc = spawn(command, { shell: true });
|
|
10
|
+
if (pipe || pipe === void 0) {
|
|
11
|
+
prc.stdout.pipe(process.stdout);
|
|
12
|
+
prc.stderr.pipe(process.stderr);
|
|
13
|
+
}
|
|
14
|
+
stdin.pipe(prc.stdin);
|
|
15
|
+
const stdoutData = [];
|
|
16
|
+
const stderrData = [];
|
|
17
|
+
prc.stdout.on("data", (data) => {
|
|
18
|
+
stdoutData.push(data.toString());
|
|
19
|
+
});
|
|
20
|
+
prc.stderr.on("data", (data) => {
|
|
21
|
+
stderrData.push(data.toString());
|
|
22
|
+
});
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
prc.on("close", (code) => {
|
|
25
|
+
if (pipe || pipe === void 0) console.log("");
|
|
26
|
+
const output = {
|
|
27
|
+
stdout: stdoutData.join(""),
|
|
28
|
+
stderr: stderrData.join(""),
|
|
29
|
+
code
|
|
30
|
+
};
|
|
31
|
+
if (code === 0) resolve(output);
|
|
32
|
+
else reject(output);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
46
35
|
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { exec };
|