@prosopo/scripts 3.0.11 → 3.0.12
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 +33 -0
- package/dist/cjs/cli/index.cjs +105 -0
- package/dist/cjs/contract/import.cjs +183 -0
- package/dist/cjs/contract/index.cjs +4 -0
- package/dist/cjs/index.cjs +25 -0
- package/dist/cjs/scripts/setVersion.cjs +132 -0
- package/dist/cjs/setup/index.cjs +7 -0
- package/dist/cjs/setup/provider.cjs +11 -0
- package/dist/cjs/setup/setup.cjs +138 -0
- package/dist/cjs/setup/site.cjs +25 -0
- package/dist/cjs/util/exec.cjs +46 -0
- package/dist/cjs/util/fluxLogDappDetails.cjs +18 -0
- package/dist/cjs/util/index.cjs +13 -0
- package/dist/cjs/util/loadContractFiles.cjs +44 -0
- package/dist/cjs/util/updateEnv.cjs +71 -0
- package/dist/cli/index.js +96 -99
- package/dist/contract/import.js +169 -149
- package/dist/contract/index.js +4 -2
- package/dist/index.js +25 -5
- package/dist/scripts/setVersion.js +115 -121
- package/dist/setup/index.js +7 -3
- package/dist/setup/provider.js +8 -6
- package/dist/setup/setup.js +113 -113
- package/dist/setup/site.js +23 -19
- package/dist/util/exec.js +42 -41
- package/dist/util/fluxLogDappDetails.js +17 -15
- package/dist/util/index.js +13 -5
- package/dist/util/loadContractFiles.js +34 -30
- package/dist/util/updateEnv.js +59 -54
- package/package.json +29 -21
- package/vite.cjs.config.ts +19 -0
- package/vite.esm.config.ts +20 -0
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/contract/import.d.ts +0 -3
- package/dist/contract/import.d.ts.map +0 -1
- package/dist/contract/import.js.map +0 -1
- package/dist/contract/index.d.ts +0 -2
- package/dist/contract/index.d.ts.map +0 -1
- package/dist/contract/index.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scripts/bytesToHex.d.ts +0 -2
- package/dist/scripts/bytesToHex.d.ts.map +0 -1
- package/dist/scripts/bytesToHex.js +0 -7
- package/dist/scripts/bytesToHex.js.map +0 -1
- package/dist/scripts/convertAccount.d.ts +0 -2
- package/dist/scripts/convertAccount.d.ts.map +0 -1
- package/dist/scripts/convertAccount.js +0 -24
- package/dist/scripts/convertAccount.js.map +0 -1
- package/dist/scripts/encodeDecode.d.ts +0 -2
- package/dist/scripts/encodeDecode.d.ts.map +0 -1
- package/dist/scripts/encodeDecode.js +0 -108
- package/dist/scripts/encodeDecode.js.map +0 -1
- package/dist/scripts/findUnused.d.ts +0 -2
- package/dist/scripts/findUnused.d.ts.map +0 -1
- package/dist/scripts/findUnused.js +0 -80
- package/dist/scripts/findUnused.js.map +0 -1
- package/dist/scripts/generateMnemonic.d.ts +0 -2
- package/dist/scripts/generateMnemonic.d.ts.map +0 -1
- package/dist/scripts/generateMnemonic.js +0 -26
- package/dist/scripts/generateMnemonic.js.map +0 -1
- package/dist/scripts/getBlock.d.ts +0 -2
- package/dist/scripts/getBlock.d.ts.map +0 -1
- package/dist/scripts/getBlock.js +0 -17
- package/dist/scripts/getBlock.js.map +0 -1
- package/dist/scripts/getContractInfoOf.d.ts +0 -2
- package/dist/scripts/getContractInfoOf.d.ts.map +0 -1
- package/dist/scripts/getContractInfoOf.js +0 -40
- package/dist/scripts/getContractInfoOf.js.map +0 -1
- package/dist/scripts/hash.d.ts +0 -2
- package/dist/scripts/hash.d.ts.map +0 -1
- package/dist/scripts/hash.js +0 -41
- package/dist/scripts/hash.js.map +0 -1
- package/dist/scripts/hexToBytes.d.ts +0 -2
- package/dist/scripts/hexToBytes.d.ts.map +0 -1
- package/dist/scripts/hexToBytes.js +0 -6
- package/dist/scripts/hexToBytes.js.map +0 -1
- package/dist/scripts/setVersion.d.ts +0 -2
- package/dist/scripts/setVersion.d.ts.map +0 -1
- package/dist/scripts/setVersion.js.map +0 -1
- package/dist/scripts/sign.d.ts +0 -2
- package/dist/scripts/sign.d.ts.map +0 -1
- package/dist/scripts/sign.js +0 -41
- package/dist/scripts/sign.js.map +0 -1
- package/dist/scripts/testImport.d.ts +0 -2
- package/dist/scripts/testImport.d.ts.map +0 -1
- package/dist/scripts/testImport.js +0 -13
- package/dist/scripts/testImport.js.map +0 -1
- package/dist/setup/index.d.ts +0 -3
- package/dist/setup/index.d.ts.map +0 -1
- package/dist/setup/index.js.map +0 -1
- package/dist/setup/provider.d.ts +0 -3
- package/dist/setup/provider.d.ts.map +0 -1
- package/dist/setup/provider.js.map +0 -1
- package/dist/setup/setup.d.ts +0 -3
- package/dist/setup/setup.d.ts.map +0 -1
- package/dist/setup/setup.js.map +0 -1
- package/dist/setup/site.d.ts +0 -4
- package/dist/setup/site.d.ts.map +0 -1
- package/dist/setup/site.js.map +0 -1
- package/dist/util/exec.d.ts +0 -10
- package/dist/util/exec.d.ts.map +0 -1
- package/dist/util/exec.js.map +0 -1
- package/dist/util/fluxLogDappDetails.d.ts +0 -2
- package/dist/util/fluxLogDappDetails.d.ts.map +0 -1
- package/dist/util/fluxLogDappDetails.js.map +0 -1
- package/dist/util/index.d.ts +0 -5
- package/dist/util/index.d.ts.map +0 -1
- package/dist/util/index.js.map +0 -1
- package/dist/util/loadContractFiles.d.ts +0 -4
- package/dist/util/loadContractFiles.d.ts.map +0 -1
- package/dist/util/loadContractFiles.js.map +0 -1
- package/dist/util/updateEnv.d.ts +0 -5
- package/dist/util/updateEnv.d.ts.map +0 -1
- package/dist/util/updateEnv.js.map +0 -1
package/dist/setup/setup.js
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import {
|
|
3
|
-
import { LogLevel, ProsopoEnvError
|
|
2
|
+
import { getSecret, defaultConfig } from "@prosopo/cli";
|
|
3
|
+
import { getLogger, LogLevel, ProsopoEnvError } from "@prosopo/common";
|
|
4
4
|
import { getEnvFile } from "@prosopo/dotenv";
|
|
5
5
|
import { ProviderEnvironment } from "@prosopo/env";
|
|
6
|
-
import { generateMnemonic, getDefaultSiteKeys
|
|
6
|
+
import { getPair, generateMnemonic, getDefaultSiteKeys } from "@prosopo/keyring";
|
|
7
7
|
import { get } from "@prosopo/util";
|
|
8
8
|
import fse from "fs-extra";
|
|
9
|
-
import
|
|
9
|
+
import "../util/index.js";
|
|
10
10
|
import { setupProvider } from "./provider.js";
|
|
11
11
|
import { registerSiteKey } from "./site.js";
|
|
12
|
+
import { updateDemoHTMLFiles, updateEnvFiles } from "../util/updateEnv.js";
|
|
12
13
|
const logger = getLogger(LogLevel.enum.info, "setup");
|
|
13
14
|
const __dirname = path.resolve();
|
|
14
15
|
function getRootDir() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const rootDir = process.env.PROSOPO_ROOT_DIR || path.resolve(__dirname, "../..");
|
|
17
|
+
logger.info(() => ({ msg: "Root dir:", data: { rootDir } }));
|
|
18
|
+
return rootDir;
|
|
18
19
|
}
|
|
19
20
|
function getDatasetFilePath() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return datasetFile;
|
|
21
|
+
const datasetFile = process.env.PROSOPO_PROVIDER_DATASET_FILE || path.resolve("../data/captchas.json");
|
|
22
|
+
logger.info(() => ({ msg: "Dataset file:", data: { datasetFile } }));
|
|
23
|
+
return datasetFile;
|
|
24
24
|
}
|
|
25
25
|
function getDefaultProvider() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
pair: getPair(getSecret()),
|
|
36
|
-
};
|
|
26
|
+
const host = process.env.PROSOPO_PROVIDER_HOST || "localhost";
|
|
27
|
+
return {
|
|
28
|
+
url: process.env.PROSOPO_API_PORT ? `http://${host}:${process.env.PROSOPO_API_PORT}` : `http://${host}:9229`,
|
|
29
|
+
datasetFile: getDatasetFilePath(),
|
|
30
|
+
address: process.env.PROSOPO_PROVIDER_ADDRESS || "",
|
|
31
|
+
secret: getSecret(),
|
|
32
|
+
captchaDatasetId: "",
|
|
33
|
+
pair: getPair(getSecret())
|
|
34
|
+
};
|
|
37
35
|
}
|
|
38
36
|
async function copyEnvFile() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
37
|
+
try {
|
|
38
|
+
const rootDir = getRootDir();
|
|
39
|
+
const tplLocation = path.resolve(rootDir, "./dev/scripts");
|
|
40
|
+
const tplEnvFile = getEnvFile(tplLocation, "env");
|
|
41
|
+
const envFile = getEnvFile(tplLocation, ".env");
|
|
42
|
+
await fse.copy(tplEnvFile, envFile, { overwrite: false });
|
|
43
|
+
} catch (err) {
|
|
44
|
+
logger.debug(() => ({ msg: "Error copying env file", err }));
|
|
45
|
+
}
|
|
49
46
|
}
|
|
50
47
|
function updateEnvFileVar(source, name, value) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const envVar = new RegExp(`.*(${name}=)(.*)`, "g");
|
|
49
|
+
if (envVar.test(source)) {
|
|
50
|
+
return source.replace(envVar, `$1${value}`);
|
|
51
|
+
}
|
|
52
|
+
return `${source}
|
|
53
|
+
${name}=${value}`;
|
|
56
54
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
async function updateEnvFile(vars) {
|
|
56
|
+
const rootDir = getRootDir();
|
|
57
|
+
const envFile = getEnvFile(rootDir, ".env");
|
|
58
|
+
let readEnvFile = await fse.readFile(envFile, "utf8");
|
|
59
|
+
for (const key in vars) {
|
|
60
|
+
readEnvFile = updateEnvFileVar(readEnvFile, key, get(vars, key));
|
|
61
|
+
}
|
|
62
|
+
logger.info(() => ({ msg: `Updating ${envFile}` }));
|
|
63
|
+
await fse.writeFile(envFile, readEnvFile);
|
|
66
64
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
async function setup(provider, sites) {
|
|
66
|
+
if (!provider && !sites) {
|
|
67
|
+
logger.info(() => ({ msg: "No setup required, exiting." }));
|
|
68
|
+
process.exit(0);
|
|
69
|
+
}
|
|
70
|
+
const defaultProvider = getDefaultProvider();
|
|
71
|
+
if (defaultProvider.secret) {
|
|
72
|
+
const hasProviderAccount = defaultProvider.address && defaultProvider.secret;
|
|
73
|
+
logger.debug(() => ({
|
|
74
|
+
msg: "ENVIRONMENT",
|
|
75
|
+
data: { nodeEnv: process.env.NODE_ENV }
|
|
76
|
+
}));
|
|
77
|
+
const [mnemonic, address] = !hasProviderAccount ? await generateMnemonic() : [defaultProvider.secret, defaultProvider.address];
|
|
78
|
+
logger.debug(() => ({ msg: `Address: ${address}` }));
|
|
79
|
+
logger.debug(() => ({ msg: `Mnemonic: ${mnemonic}` }));
|
|
80
|
+
logger.debug(() => ({ msg: "Writing .env file..." }));
|
|
81
|
+
await copyEnvFile();
|
|
82
|
+
if (!process.env.PROSOPO_SITE_KEY) {
|
|
83
|
+
throw new ProsopoEnvError("DEVELOPER.PROSOPO_SITE_KEY_MISSING");
|
|
71
84
|
}
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
defaultProvider.secret = mnemonic;
|
|
85
|
+
const config = defaultConfig();
|
|
86
|
+
const providerSecret = config.account.secret;
|
|
87
|
+
const pair = getPair(providerSecret);
|
|
88
|
+
const authAccount = getPair(config.authAccount.secret);
|
|
89
|
+
const env = new ProviderEnvironment(config, pair, authAccount);
|
|
90
|
+
await env.isReady();
|
|
91
|
+
defaultProvider.secret = mnemonic;
|
|
92
|
+
env.logger.info(() => ({
|
|
93
|
+
msg: `Registering provider... ${defaultProvider.address}`
|
|
94
|
+
}));
|
|
95
|
+
defaultProvider.pair = getPair(providerSecret);
|
|
96
|
+
if (provider) {
|
|
97
|
+
await setupProvider(env);
|
|
98
|
+
if (!hasProviderAccount) {
|
|
99
|
+
await updateEnvFile({
|
|
100
|
+
PROVIDER_MNEMONIC: `"${mnemonic}"`,
|
|
101
|
+
PROVIDER_ADDRESS: address
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (sites) {
|
|
106
|
+
for (const siteKey of getDefaultSiteKeys()) {
|
|
107
|
+
siteKey.pair = getPair(siteKey.secret);
|
|
96
108
|
env.logger.info(() => ({
|
|
97
|
-
|
|
109
|
+
msg: `Registering ${siteKey.secret} siteKey ... ${siteKey.pair?.address}`
|
|
98
110
|
}));
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
env.logger.debug(() => ({
|
|
117
|
-
msg: "Updating env files with PROSOPO_SITE_KEY",
|
|
118
|
-
}));
|
|
119
|
-
await updateDemoHTMLFiles([/data-sitekey="(\w{48})"/, /siteKey:\s*'(\w{48})'/], siteKey.pair.address, env.logger);
|
|
120
|
-
const envVarNames = siteKey.settings.captchaType === "image"
|
|
121
|
-
? [
|
|
122
|
-
"PROSOPO_SITE_KEY",
|
|
123
|
-
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`,
|
|
124
|
-
]
|
|
125
|
-
: [
|
|
126
|
-
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`,
|
|
127
|
-
];
|
|
128
|
-
await updateEnvFiles(envVarNames, siteKey.pair.address, env.logger);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
process.exit();
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
console.error("no secret found in .env file");
|
|
135
|
-
throw new ProsopoEnvError("GENERAL.NO_MNEMONIC_OR_SEED");
|
|
111
|
+
await registerSiteKey(env, siteKey.pair.address, siteKey.settings);
|
|
112
|
+
env.logger.debug(() => ({
|
|
113
|
+
msg: "Updating env files with PROSOPO_SITE_KEY"
|
|
114
|
+
}));
|
|
115
|
+
await updateDemoHTMLFiles(
|
|
116
|
+
[/data-sitekey="(\w{48})"/, /siteKey:\s*'(\w{48})'/],
|
|
117
|
+
siteKey.pair.address,
|
|
118
|
+
env.logger
|
|
119
|
+
);
|
|
120
|
+
const envVarNames = siteKey.settings.captchaType === "image" ? [
|
|
121
|
+
"PROSOPO_SITE_KEY",
|
|
122
|
+
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`
|
|
123
|
+
] : [
|
|
124
|
+
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`
|
|
125
|
+
];
|
|
126
|
+
await updateEnvFiles(envVarNames, siteKey.pair.address, env.logger);
|
|
127
|
+
}
|
|
136
128
|
}
|
|
129
|
+
process.exit();
|
|
130
|
+
} else {
|
|
131
|
+
console.error("no secret found in .env file");
|
|
132
|
+
throw new ProsopoEnvError("GENERAL.NO_MNEMONIC_OR_SEED");
|
|
133
|
+
}
|
|
137
134
|
}
|
|
138
|
-
|
|
135
|
+
export {
|
|
136
|
+
setup,
|
|
137
|
+
updateEnvFile
|
|
138
|
+
};
|
package/dist/setup/site.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { Tasks } from "@prosopo/provider";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
import { Tier, ClientSettingsSchema, CaptchaType } from "@prosopo/types";
|
|
3
|
+
async function registerSiteKey(env, siteKey, settings = {}) {
|
|
4
|
+
const logger = env.logger;
|
|
5
|
+
const tasks = new Tasks(env);
|
|
6
|
+
logger.info(() => ({
|
|
7
|
+
msg: "registerSiteKey",
|
|
8
|
+
data: { siteKey, captchaType: settings.captchaType }
|
|
9
|
+
}));
|
|
10
|
+
await tasks.clientTaskManager.registerSiteKey(
|
|
11
|
+
siteKey,
|
|
12
|
+
Tier.Professional,
|
|
13
|
+
ClientSettingsSchema.parse({
|
|
14
|
+
captchaType: CaptchaType.frictionless,
|
|
15
|
+
frictionlessThreshold: 0.8,
|
|
16
|
+
powDifficulty: 4,
|
|
17
|
+
imageThreshold: 0.8,
|
|
18
|
+
...settings,
|
|
19
|
+
domains: settings.domains && settings.domains.length > 0 ? settings.domains : ["localhost", "0.0.0.0"]
|
|
20
|
+
})
|
|
21
|
+
);
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
export {
|
|
24
|
+
registerSiteKey
|
|
25
|
+
};
|
package/dist/util/exec.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
});
|
|
3
|
+
const exec = (command, options) => {
|
|
4
|
+
let { pipe, printCmd } = options || {};
|
|
5
|
+
pipe = pipe === void 0 || pipe;
|
|
6
|
+
printCmd = printCmd === void 0 || printCmd;
|
|
7
|
+
if (printCmd) {
|
|
8
|
+
console.log(`[exec] ${command}`);
|
|
9
|
+
}
|
|
10
|
+
const prc = spawn(command, {
|
|
11
|
+
shell: true
|
|
12
|
+
});
|
|
13
|
+
if (pipe || pipe === void 0) {
|
|
14
|
+
prc.stdout.pipe(process.stdout);
|
|
15
|
+
prc.stderr.pipe(process.stderr);
|
|
16
|
+
}
|
|
17
|
+
stdin.pipe(prc.stdin);
|
|
18
|
+
const stdoutData = [];
|
|
19
|
+
const stderrData = [];
|
|
20
|
+
prc.stdout.on("data", (data) => {
|
|
21
|
+
stdoutData.push(data.toString());
|
|
22
|
+
});
|
|
23
|
+
prc.stderr.on("data", (data) => {
|
|
24
|
+
stderrData.push(data.toString());
|
|
25
|
+
});
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
prc.on("close", (code) => {
|
|
28
|
+
if (pipe || pipe === void 0) {
|
|
29
|
+
console.log("");
|
|
30
|
+
}
|
|
31
|
+
const output = {
|
|
32
|
+
stdout: stdoutData.join(""),
|
|
33
|
+
stderr: stderrData.join(""),
|
|
34
|
+
code
|
|
35
|
+
};
|
|
36
|
+
if (code === 0) {
|
|
37
|
+
resolve(output);
|
|
38
|
+
} else {
|
|
39
|
+
reject(output);
|
|
40
|
+
}
|
|
43
41
|
});
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
exec
|
|
44
46
|
};
|
|
45
|
-
//# sourceMappingURL=exec.js.map
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
function extractReferrersFromLogs(logsText) {
|
|
2
|
+
const urls = [
|
|
3
|
+
...logsText.split("\n").reduce((accumulator, line) => {
|
|
4
|
+
const matches = line.match(/"(https?:\/\/[^"]+)"/g);
|
|
5
|
+
if (matches) {
|
|
6
|
+
for (const match of matches) {
|
|
7
|
+
const url = match.substring(1, match.length - 1);
|
|
8
|
+
accumulator.add(url);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return accumulator;
|
|
12
|
+
}, /* @__PURE__ */ new Set())
|
|
13
|
+
];
|
|
14
|
+
return urls.join(" ");
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
export {
|
|
17
|
+
extractReferrersFromLogs
|
|
18
|
+
};
|
package/dist/util/index.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { AbiJSON, Wasm } from "./loadContractFiles.js";
|
|
2
|
+
import { findEnvFiles, updateDemoHTMLFiles, updateEnvFiles } from "./updateEnv.js";
|
|
3
|
+
import { exec } from "./exec.js";
|
|
4
|
+
import { extractReferrersFromLogs } from "./fluxLogDappDetails.js";
|
|
5
|
+
export {
|
|
6
|
+
AbiJSON,
|
|
7
|
+
Wasm,
|
|
8
|
+
exec,
|
|
9
|
+
extractReferrersFromLogs,
|
|
10
|
+
findEnvFiles,
|
|
11
|
+
updateDemoHTMLFiles,
|
|
12
|
+
updateEnvFiles
|
|
13
|
+
};
|
|
@@ -4,37 +4,41 @@ import { hexToU8a, isWasm } from "@polkadot/util";
|
|
|
4
4
|
import { ProsopoError } from "@prosopo/common";
|
|
5
5
|
import fse from "fs-extra";
|
|
6
6
|
const __dirname = path.resolve();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
async function AbiJSON(filePath) {
|
|
8
|
+
const resolvedFilePath = path.resolve(__dirname, filePath);
|
|
9
|
+
await fse.ensureFile(resolvedFilePath);
|
|
10
|
+
const fileExists = await fse.pathExists(resolvedFilePath);
|
|
11
|
+
if (fileExists) {
|
|
12
|
+
const json = JSON.parse(
|
|
13
|
+
await fse.readFile(resolvedFilePath, {
|
|
14
|
+
encoding: "utf8"
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
return new Abi(json);
|
|
18
|
+
}
|
|
19
|
+
throw new ProsopoError("FS.FILE_NOT_FOUND", {
|
|
20
|
+
context: { error: `File ${filePath} does not exist` }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async function Wasm(filePath) {
|
|
24
|
+
const resolvedFilePath = path.resolve(__dirname, filePath);
|
|
25
|
+
await fse.ensureFile(resolvedFilePath);
|
|
26
|
+
const fileExists = await fse.pathExists(resolvedFilePath);
|
|
27
|
+
if (fileExists) {
|
|
28
|
+
const wasm = `0x${fse.readFileSync(resolvedFilePath).toString("hex")}`;
|
|
29
|
+
const wasmBytes = hexToU8a(wasm);
|
|
30
|
+
if (isWasm(wasmBytes)) {
|
|
31
|
+
return wasmBytes;
|
|
16
32
|
}
|
|
33
|
+
console.error(`Error loading contract wasm: ${wasm.slice(0, 10)}...`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
} else {
|
|
17
36
|
throw new ProsopoError("FS.FILE_NOT_FOUND", {
|
|
18
|
-
|
|
37
|
+
context: { error: `File ${filePath} does not exist` }
|
|
19
38
|
});
|
|
39
|
+
}
|
|
20
40
|
}
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (fileExists) {
|
|
26
|
-
const wasm = `0x${fse.readFileSync(resolvedFilePath).toString("hex")}`;
|
|
27
|
-
const wasmBytes = hexToU8a(wasm);
|
|
28
|
-
if (isWasm(wasmBytes)) {
|
|
29
|
-
return wasmBytes;
|
|
30
|
-
}
|
|
31
|
-
console.error(`Error loading contract wasm: ${wasm.slice(0, 10)}...`);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
throw new ProsopoError("FS.FILE_NOT_FOUND", {
|
|
36
|
-
context: { error: `File ${filePath} does not exist` },
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=loadContractFiles.js.map
|
|
41
|
+
export {
|
|
42
|
+
AbiJSON,
|
|
43
|
+
Wasm
|
|
44
|
+
};
|
package/dist/util/updateEnv.js
CHANGED
|
@@ -5,62 +5,67 @@ import { at } from "@prosopo/util";
|
|
|
5
5
|
import dotenv from "dotenv";
|
|
6
6
|
import fg from "fast-glob";
|
|
7
7
|
const ignore = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
"**/node_modules/**",
|
|
9
|
+
"node_modules/**",
|
|
10
|
+
"../../**/node_modules/**",
|
|
11
|
+
"../node_modules/**",
|
|
12
|
+
"../../node_modules/**"
|
|
13
13
|
];
|
|
14
14
|
const __dirname = path.resolve();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
async function findEnvFiles(logger, cwd) {
|
|
16
|
+
const env = getEnv();
|
|
17
|
+
const fileName = `.env.${env}`;
|
|
18
|
+
logger.info(() => ({ msg: "Searching for files" }));
|
|
19
|
+
return await fg(`${cwd || "../.."}/**/${fileName}`, {
|
|
20
|
+
ignore
|
|
21
|
+
});
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
async function updateDemoHTMLFiles(varMatchers, varValue, logger) {
|
|
24
|
+
const files = await fg("../../demos/**/*.html", {
|
|
25
|
+
ignore
|
|
26
|
+
});
|
|
27
|
+
logger.info(() => ({ data: { files }, msg: "HTML files found" }));
|
|
28
|
+
files.forEach((file) => {
|
|
29
|
+
const filePath = path.resolve(process.cwd(), file);
|
|
30
|
+
const contents = fs.readFileSync(filePath).toString();
|
|
31
|
+
let newContents = contents;
|
|
32
|
+
for (const varMatcher of varMatchers) {
|
|
33
|
+
const matches = contents.match(varMatcher);
|
|
34
|
+
if (matches) {
|
|
35
|
+
const matchedVar = at(matches, 1);
|
|
36
|
+
logger.info(() => ({ data: { matchedVar }, msg: "matchedVar" }));
|
|
37
|
+
newContents = contents.replaceAll(matchedVar, varValue);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (newContents !== contents) {
|
|
42
|
+
fs.writeFileSync(path.resolve(__dirname, filePath), newContents);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
46
|
+
async function updateEnvFiles(varNames, varValue, logger, cwd) {
|
|
47
|
+
const files = await findEnvFiles(logger, cwd);
|
|
48
|
+
logger.info(() => ({ data: { files }, msg: "Env files found" }));
|
|
49
|
+
files.forEach((file) => {
|
|
50
|
+
let write = false;
|
|
51
|
+
const filePath = path.resolve(cwd || process.cwd(), file);
|
|
52
|
+
const envConfig = dotenv.parse(fs.readFileSync(filePath));
|
|
53
|
+
for (const varName of varNames) {
|
|
54
|
+
if (varName in envConfig) {
|
|
55
|
+
envConfig[varName] = varValue;
|
|
56
|
+
write = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (write) {
|
|
60
|
+
fs.writeFileSync(
|
|
61
|
+
path.resolve(__dirname, filePath),
|
|
62
|
+
Object.keys(envConfig).map((k) => `${k}=${envConfig[k]}`).join("\n")
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
export {
|
|
68
|
+
findEnvFiles,
|
|
69
|
+
updateDemoHTMLFiles,
|
|
70
|
+
updateEnvFiles
|
|
71
|
+
};
|