@prosopo/scripts 3.0.11 → 3.0.13
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 +40 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @prosopo/scripts
|
|
2
2
|
|
|
3
|
+
## 3.0.13
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies [9e4e7ca]
|
|
7
|
+
- @prosopo/provider@3.2.2
|
|
8
|
+
- @prosopo/cli@3.1.2
|
|
9
|
+
|
|
10
|
+
## 3.0.12
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3573f0b: fix npm scripts bundle command
|
|
14
|
+
- 3573f0b: build using vite, typecheck using tsc
|
|
15
|
+
- efd8102: Add tests for unwrap error helper
|
|
16
|
+
- f29fc7e: Refining API error handling. Adding more language strings
|
|
17
|
+
- 3573f0b: standardise all vite based npm scripts for bundling
|
|
18
|
+
- Updated dependencies [2f0c830]
|
|
19
|
+
- Updated dependencies [52dbf21]
|
|
20
|
+
- Updated dependencies [93d5e50]
|
|
21
|
+
- Updated dependencies [3573f0b]
|
|
22
|
+
- Updated dependencies [3573f0b]
|
|
23
|
+
- Updated dependencies [efd8102]
|
|
24
|
+
- Updated dependencies [93d5e50]
|
|
25
|
+
- Updated dependencies [63519d7]
|
|
26
|
+
- Updated dependencies [f29fc7e]
|
|
27
|
+
- Updated dependencies [3573f0b]
|
|
28
|
+
- Updated dependencies [2d0dd8a]
|
|
29
|
+
- @prosopo/provider@3.2.1
|
|
30
|
+
- @prosopo/util@3.0.3
|
|
31
|
+
- @prosopo/types-env@2.7.14
|
|
32
|
+
- @prosopo/keyring@2.8.7
|
|
33
|
+
- @prosopo/types@3.0.4
|
|
34
|
+
- @prosopo/types-database@3.0.10
|
|
35
|
+
- @prosopo/datasets@3.0.10
|
|
36
|
+
- @prosopo/account@2.7.10
|
|
37
|
+
- @prosopo/common@3.1.0
|
|
38
|
+
- @prosopo/dotenv@3.0.5
|
|
39
|
+
- @prosopo/cli@3.1.1
|
|
40
|
+
- @prosopo/env@3.1.1
|
|
41
|
+
- @prosopo/config@3.1.1
|
|
42
|
+
|
|
3
43
|
## 3.0.11
|
|
4
44
|
### Patch Changes
|
|
5
45
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const util = require("@polkadot/util");
|
|
5
|
+
const common = require("@prosopo/common");
|
|
6
|
+
const dotenv = require("@prosopo/dotenv");
|
|
7
|
+
const types = require("@prosopo/types");
|
|
8
|
+
const workspace = require("@prosopo/workspace");
|
|
9
|
+
const yargs = require("yargs");
|
|
10
|
+
const helpers = require("yargs/helpers");
|
|
11
|
+
require("../contract/index.cjs");
|
|
12
|
+
const setVersion = require("../scripts/setVersion.cjs");
|
|
13
|
+
require("../setup/index.cjs");
|
|
14
|
+
require("../util/index.cjs");
|
|
15
|
+
const exec = require("../util/exec.cjs");
|
|
16
|
+
const setup = require("../setup/setup.cjs");
|
|
17
|
+
const _import = require("../contract/import.cjs");
|
|
18
|
+
const rootDir = path.resolve(".");
|
|
19
|
+
dotenv.loadEnv(rootDir);
|
|
20
|
+
async function processArgs(args) {
|
|
21
|
+
const parsed = await yargs(helpers.hideBin(args)).option("logLevel", {
|
|
22
|
+
describe: "set log level",
|
|
23
|
+
choices: Object.keys(common.LogLevel.enum)
|
|
24
|
+
}).argv;
|
|
25
|
+
const log = common.getLogger(common.parseLogLevel(parsed.logLevel), "CLI");
|
|
26
|
+
await yargs(helpers.hideBin(args)).usage("Usage: $0 [global options] <command> [options]").command(
|
|
27
|
+
"create_env_files",
|
|
28
|
+
"Copies the env.xyz files to .env.xyz",
|
|
29
|
+
(yargs2) => yargs2,
|
|
30
|
+
async () => {
|
|
31
|
+
const env = dotenv.getEnv();
|
|
32
|
+
const scripts = workspace.getScriptsPkgDir();
|
|
33
|
+
await exec.exec(`cp -v ${scripts}/env.${env} ${scripts}/.env.${env}`);
|
|
34
|
+
},
|
|
35
|
+
[]
|
|
36
|
+
).command({
|
|
37
|
+
command: "setup",
|
|
38
|
+
describe: "Setup the development environment by registering a provider, staking, loading a data set and then registering a dapp and staking.",
|
|
39
|
+
builder: (yargs2) => yargs2.option("sites", {
|
|
40
|
+
type: "boolean",
|
|
41
|
+
demandOption: false,
|
|
42
|
+
default: true,
|
|
43
|
+
desc: "Set up sites"
|
|
44
|
+
}).option("provider", {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
demandOption: false,
|
|
47
|
+
default: true,
|
|
48
|
+
desc: "Set up the provider"
|
|
49
|
+
}),
|
|
50
|
+
handler: async (argv) => {
|
|
51
|
+
log.info(() => ({ msg: "Running setup scripts" }));
|
|
52
|
+
await setup.setup(argv.provider, argv.sites);
|
|
53
|
+
}
|
|
54
|
+
}).command({
|
|
55
|
+
command: "import_contract",
|
|
56
|
+
describe: "Import a contract into the contract package.",
|
|
57
|
+
builder: (yargs2) => yargs2.option("in", {
|
|
58
|
+
type: "string",
|
|
59
|
+
demandOption: true,
|
|
60
|
+
desc: "The path to the contract's abi"
|
|
61
|
+
}).option("out", {
|
|
62
|
+
type: "string",
|
|
63
|
+
demandOption: true,
|
|
64
|
+
desc: "The path to the output directory"
|
|
65
|
+
}),
|
|
66
|
+
handler: async (argv) => {
|
|
67
|
+
await _import(argv.in, argv.out);
|
|
68
|
+
}
|
|
69
|
+
}).command({
|
|
70
|
+
command: "version",
|
|
71
|
+
describe: "Set the version of packages",
|
|
72
|
+
builder: (yargs2) => yargs2.option("v", { type: "string", demandOption: true }),
|
|
73
|
+
handler: async (argv) => {
|
|
74
|
+
await setVersion(String(argv.v));
|
|
75
|
+
}
|
|
76
|
+
}).command({
|
|
77
|
+
command: "token <token>",
|
|
78
|
+
describe: "Encode or Decode a Procaptcha token to the JSON output format",
|
|
79
|
+
builder: (yargs2) => yargs2.positional("token", {
|
|
80
|
+
describe: "a Procaptcha token to decode",
|
|
81
|
+
type: "string",
|
|
82
|
+
demandOption: true
|
|
83
|
+
}),
|
|
84
|
+
handler: async (argv) => {
|
|
85
|
+
if (!util.isHex(argv.token)) {
|
|
86
|
+
log.debug(() => ({ msg: "Encoding token to hex" }));
|
|
87
|
+
log.info(() => ({
|
|
88
|
+
data: { result: types.encodeProcaptchaOutput(JSON.parse(argv.token)) }
|
|
89
|
+
}));
|
|
90
|
+
} else {
|
|
91
|
+
log.debug(() => ({ msg: "Decoding token from hex" }));
|
|
92
|
+
log.info(() => ({
|
|
93
|
+
data: { result: types.decodeProcaptchaOutput(argv.token) }
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}).argv;
|
|
98
|
+
}
|
|
99
|
+
processArgs(process.argv).then(() => {
|
|
100
|
+
process.exit(0);
|
|
101
|
+
}).catch((error) => {
|
|
102
|
+
console.error(error);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
});
|
|
105
|
+
exports.processArgs = processArgs;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const common = require("@prosopo/common");
|
|
5
|
+
const lodash = require("@prosopo/util/lodash");
|
|
6
|
+
require("../util/index.cjs");
|
|
7
|
+
const exec = require("../util/exec.cjs");
|
|
8
|
+
const replaceExtension = (file, ext) => {
|
|
9
|
+
const parts = file.split(".");
|
|
10
|
+
parts.pop();
|
|
11
|
+
parts.push(ext);
|
|
12
|
+
return parts.join(".");
|
|
13
|
+
};
|
|
14
|
+
async function importContract(pathToAbis, pathToOutput) {
|
|
15
|
+
const verbose = false;
|
|
16
|
+
pathToAbis = path.relative(process.cwd(), pathToAbis);
|
|
17
|
+
pathToOutput = path.relative(process.cwd(), pathToOutput);
|
|
18
|
+
if (!fs.existsSync(pathToAbis))
|
|
19
|
+
throw new common.ProsopoEnvError("FS.FILE_NOT_FOUND", {
|
|
20
|
+
context: { error: `Path to ABIs does not exist: ${pathToAbis}` }
|
|
21
|
+
});
|
|
22
|
+
await exec.exec(`mkdir -p ${pathToOutput}`);
|
|
23
|
+
const cmd = `npx @prosopo/typechain-polkadot --in ${pathToAbis} --out ${pathToOutput}`;
|
|
24
|
+
await exec.exec(cmd);
|
|
25
|
+
const name = path.basename(pathToAbis);
|
|
26
|
+
await exec.exec(`cp ${pathToAbis}/${name}.json ${pathToOutput}/${name}.json`);
|
|
27
|
+
const _ = lodash.lodash();
|
|
28
|
+
const writeIndexJsFiles = (src) => {
|
|
29
|
+
const typeChainDirs = fs.readdirSync(src).filter((file2) => {
|
|
30
|
+
return fs.lstatSync(`${src}/${file2}`).isDirectory();
|
|
31
|
+
});
|
|
32
|
+
const rootExports = [];
|
|
33
|
+
const typeChainExports = [
|
|
34
|
+
{
|
|
35
|
+
dir: "build-extrinsic",
|
|
36
|
+
defaultExportName: "extrinsics"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
dir: "constructors"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
dir: "contract-info",
|
|
43
|
+
exports: [
|
|
44
|
+
{
|
|
45
|
+
name: "ContractAbi"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "ContractFile"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
dir: "contracts",
|
|
54
|
+
defaultExportName: "contract"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
dir: "data"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
dir: "event-data"
|
|
61
|
+
},
|
|
62
|
+
// { // no events used so this is empty - not sure about structure so left out
|
|
63
|
+
// dir: 'event-types'
|
|
64
|
+
// },
|
|
65
|
+
{
|
|
66
|
+
dir: "events"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
dir: "mixed-methods",
|
|
70
|
+
defaultExportName: "methods"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
dir: "query",
|
|
74
|
+
defaultExportName: "query"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
dir: "tx-sign-and-send",
|
|
78
|
+
defaultExportName: "tx"
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
let file = "";
|
|
82
|
+
for (const typeChainExport of typeChainExports) {
|
|
83
|
+
const dirPath = `${src}/${typeChainExport.dir}`;
|
|
84
|
+
const files = fs.readdirSync(dirPath);
|
|
85
|
+
if (files.length !== 1) {
|
|
86
|
+
throw new common.ProsopoEnvError("FS.INVALID_DIR_FORMAT", {
|
|
87
|
+
context: {
|
|
88
|
+
error: `Expected 1 file in ${dirPath}, found ${files.length}`
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
file = files[0] || "";
|
|
93
|
+
if (file === "") {
|
|
94
|
+
throw new common.ProsopoEnvError("FS.FILE_NOT_FOUND", {
|
|
95
|
+
context: { error: `No file found in ${dirPath}` }
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (file.endsWith(".ts")) {
|
|
99
|
+
file = replaceExtension(file, "js");
|
|
100
|
+
}
|
|
101
|
+
if (typeChainExport.defaultExportName !== void 0) {
|
|
102
|
+
const name2 = _.upperFirst(
|
|
103
|
+
_.camelCase(typeChainExport.defaultExportName || typeChainExport.dir)
|
|
104
|
+
);
|
|
105
|
+
rootExports.push(
|
|
106
|
+
`export { default as ${name2} } from './${typeChainExport.dir}/${file}'`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (typeChainExport.exports !== void 0) {
|
|
110
|
+
for (const namedExport of typeChainExport.exports) {
|
|
111
|
+
const alias = namedExport.alias ? ` as ${namedExport.alias}` : "";
|
|
112
|
+
rootExports.push(
|
|
113
|
+
`export { ${namedExport.name}${alias} } from './${typeChainExport.dir}/${file}'`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
rootExports.push(`export * from './shared/utils.js'`);
|
|
119
|
+
const regex = /export\s+([a-z]+)\s+(\w+)/g;
|
|
120
|
+
const fileTs = replaceExtension(file, "ts");
|
|
121
|
+
const typesArgumentsFileContent = fs.readFileSync(
|
|
122
|
+
`${src}/types-arguments/${fileTs}`,
|
|
123
|
+
"utf8"
|
|
124
|
+
);
|
|
125
|
+
const typesReturnsFileContent = fs.readFileSync(
|
|
126
|
+
`${src}/types-returns/${fileTs}`,
|
|
127
|
+
"utf8"
|
|
128
|
+
);
|
|
129
|
+
const argumentTypes = Array.from(
|
|
130
|
+
typesArgumentsFileContent.matchAll(regex)
|
|
131
|
+
).map((match) => {
|
|
132
|
+
return {
|
|
133
|
+
name: match[2] || "",
|
|
134
|
+
category: match[1] || ""
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
const returnTypes = Array.from(
|
|
138
|
+
typesReturnsFileContent.matchAll(regex)
|
|
139
|
+
).map((match) => {
|
|
140
|
+
return {
|
|
141
|
+
name: match[2] || "",
|
|
142
|
+
category: match[1] || ""
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
const argumentTypeNames = argumentTypes.map((entry) => entry.name);
|
|
146
|
+
const uniqueTypes = [...argumentTypes];
|
|
147
|
+
const locations = [...argumentTypes.map(() => "types-arguments")];
|
|
148
|
+
for (const entry of returnTypes) {
|
|
149
|
+
if (!argumentTypeNames.includes(entry.name)) {
|
|
150
|
+
uniqueTypes.push(entry);
|
|
151
|
+
locations.push("types-arguments");
|
|
152
|
+
} else {
|
|
153
|
+
locations.push("types-returns");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
uniqueTypes.forEach((entry, i) => {
|
|
157
|
+
const location = locations[i];
|
|
158
|
+
const prefix = entry.category === "type" || entry.category === "interface" ? " type" : "";
|
|
159
|
+
rootExports.push(
|
|
160
|
+
`export${prefix} { ${entry.name} } from './${location}/${file}'`
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
fs.writeFileSync(`${src}/index.ts`, rootExports.join("\n"));
|
|
164
|
+
};
|
|
165
|
+
writeIndexJsFiles(pathToOutput);
|
|
166
|
+
}
|
|
167
|
+
const getExtension = (str) => {
|
|
168
|
+
const i = str.indexOf("assert");
|
|
169
|
+
if (i >= 0) {
|
|
170
|
+
str = str.slice(0, i);
|
|
171
|
+
}
|
|
172
|
+
const arr = str.split(".");
|
|
173
|
+
if (arr.length <= 1) {
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
return arr.pop();
|
|
177
|
+
};
|
|
178
|
+
const getPath = (str) => {
|
|
179
|
+
const j = Math.max(str.lastIndexOf('"'), str.lastIndexOf("'"));
|
|
180
|
+
const i = Math.max(str.indexOf('"'), str.indexOf("'"));
|
|
181
|
+
return str.slice(i + 1, j);
|
|
182
|
+
};
|
|
183
|
+
module.exports = importContract;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
require("./setup/index.cjs");
|
|
4
|
+
require("./util/index.cjs");
|
|
5
|
+
const index = require("./cli/index.cjs");
|
|
6
|
+
require("./contract/index.cjs");
|
|
7
|
+
const setup = require("./setup/setup.cjs");
|
|
8
|
+
const provider = require("./setup/provider.cjs");
|
|
9
|
+
const loadContractFiles = require("./util/loadContractFiles.cjs");
|
|
10
|
+
const updateEnv = require("./util/updateEnv.cjs");
|
|
11
|
+
const exec = require("./util/exec.cjs");
|
|
12
|
+
const fluxLogDappDetails = require("./util/fluxLogDappDetails.cjs");
|
|
13
|
+
const _import = require("./contract/import.cjs");
|
|
14
|
+
exports.processArgs = index.processArgs;
|
|
15
|
+
exports.setup = setup.setup;
|
|
16
|
+
exports.updateEnvFile = setup.updateEnvFile;
|
|
17
|
+
exports.setupProvider = provider.setupProvider;
|
|
18
|
+
exports.AbiJSON = loadContractFiles.AbiJSON;
|
|
19
|
+
exports.Wasm = loadContractFiles.Wasm;
|
|
20
|
+
exports.findEnvFiles = updateEnv.findEnvFiles;
|
|
21
|
+
exports.updateDemoHTMLFiles = updateEnv.updateDemoHTMLFiles;
|
|
22
|
+
exports.updateEnvFiles = updateEnv.updateEnvFiles;
|
|
23
|
+
exports.exec = exec.exec;
|
|
24
|
+
exports.extractReferrersFromLogs = fluxLogDappDetails.extractReferrersFromLogs;
|
|
25
|
+
exports.importContract = _import;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const toml = require("@iarna/toml");
|
|
5
|
+
const common = require("@prosopo/common");
|
|
6
|
+
const dotenv = require("@prosopo/dotenv");
|
|
7
|
+
const workspace = require("@prosopo/workspace");
|
|
8
|
+
dotenv.loadEnv();
|
|
9
|
+
const logLevel = common.parseLogLevel(process.env.PROSOPO_LOG_LEVEL);
|
|
10
|
+
const log = common.getLogger(logLevel, "setVersion");
|
|
11
|
+
log.info(() => ({ data: { logLevel } }));
|
|
12
|
+
const parseVersion = (version) => {
|
|
13
|
+
try {
|
|
14
|
+
const parts = version.split(".");
|
|
15
|
+
if (parts.length !== 3) {
|
|
16
|
+
throw new Error();
|
|
17
|
+
}
|
|
18
|
+
let [major, minor, patch] = parts;
|
|
19
|
+
major = Number.parseInt(major ?? "").toString();
|
|
20
|
+
minor = Number.parseInt(minor ?? "").toString();
|
|
21
|
+
patch = Number.parseInt(patch ?? "").toString();
|
|
22
|
+
if (major === "NaN" || minor === "NaN" || patch === "NaN") {
|
|
23
|
+
throw new Error();
|
|
24
|
+
}
|
|
25
|
+
return `${major}.${minor}.${patch}`;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
throw new Error("Version must be in the format of x.y.z");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const find = (pth, filter) => {
|
|
31
|
+
const files = fs.readdirSync(pth);
|
|
32
|
+
const results = [];
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
const fullPath = path.join(pth, file);
|
|
35
|
+
if (filter(fullPath)) {
|
|
36
|
+
results.push(fullPath);
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
40
|
+
results.push(...find(fullPath, filter));
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
log.debug(() => ({ data: { fullPath }, msg: "Not a directory" }));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return results;
|
|
47
|
+
};
|
|
48
|
+
async function setVersion(versionIn, ignore) {
|
|
49
|
+
log.info(() => ({ data: { versionIn }, msg: "Setting version to" }));
|
|
50
|
+
const version = parseVersion(versionIn);
|
|
51
|
+
const root = workspace.getRootDir();
|
|
52
|
+
const ignorePaths = ["node_modules", "cargo-cache", ...ignore ?? []];
|
|
53
|
+
log.debug(() => ({ data: { ignorePaths }, msg: "Ignoring paths" }));
|
|
54
|
+
const files = find(root, (pth) => {
|
|
55
|
+
if (ignorePaths.some((ignorePath) => pth.includes(ignorePath))) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const basename = path.basename(pth);
|
|
59
|
+
return basename === "package.json" || basename === "Cargo.toml";
|
|
60
|
+
});
|
|
61
|
+
files.filter((pth) => path.extname(pth) === ".json").forEach((pth) => {
|
|
62
|
+
log.debug(() => ({ data: { pth }, msg: "setting version in" }));
|
|
63
|
+
const content = fs.readFileSync(pth, "utf8");
|
|
64
|
+
const jsonContent = JSON.parse(content);
|
|
65
|
+
if (jsonContent.version) {
|
|
66
|
+
jsonContent.version = version;
|
|
67
|
+
}
|
|
68
|
+
for (const obj of [
|
|
69
|
+
jsonContent.dependencies ?? {},
|
|
70
|
+
jsonContent.devDependencies ?? {},
|
|
71
|
+
jsonContent.peerDependencies ?? {}
|
|
72
|
+
]) {
|
|
73
|
+
for (const key of Object.keys(obj)) {
|
|
74
|
+
if (key.startsWith("@prosopo") && !key.includes("typechain")) {
|
|
75
|
+
log.debug(() => ({
|
|
76
|
+
data: { key, version, pth },
|
|
77
|
+
msg: "setting dependency version"
|
|
78
|
+
}));
|
|
79
|
+
obj[key] = version;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
fs.writeFileSync(pth, `${JSON.stringify(jsonContent, null, 4)}
|
|
84
|
+
`);
|
|
85
|
+
});
|
|
86
|
+
files.filter((pth) => path.extname(pth) === ".toml").filter((pth) => {
|
|
87
|
+
return !ignorePaths.some((ignorePath) => pth.includes(ignorePath));
|
|
88
|
+
}).forEach((pth) => {
|
|
89
|
+
log.debug(() => ({ data: { pth }, msg: "setting version in" }));
|
|
90
|
+
const content = fs.readFileSync(pth, "utf8");
|
|
91
|
+
const tomlContent = toml.parse(content);
|
|
92
|
+
if (tomlContent.workspace) {
|
|
93
|
+
if (tomlContent.workspace.version) {
|
|
94
|
+
tomlContent.workspace.version = version;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
tomlContent.package.version = version;
|
|
98
|
+
}
|
|
99
|
+
fs.writeFileSync(pth, `${toml.stringify(tomlContent)}
|
|
100
|
+
`);
|
|
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 content = fs.readFileSync(pth, "utf8");
|
|
108
|
+
const tomlContent = toml.parse(content);
|
|
109
|
+
if (tomlContent.workspace) {
|
|
110
|
+
if (tomlContent.workspace.version) {
|
|
111
|
+
tomlContent.workspace.version = version;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
for (const obj of [
|
|
115
|
+
tomlContent.dependencies ?? {},
|
|
116
|
+
tomlContent["dev-dependencies"] ?? {}
|
|
117
|
+
]) {
|
|
118
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
119
|
+
if (value.path) {
|
|
120
|
+
path.join(value.path, "Cargo.toml");
|
|
121
|
+
const depContent = fs.readFileSync(pth, "utf8");
|
|
122
|
+
const depTomlContent = toml.parse(depContent);
|
|
123
|
+
value.version = depTomlContent.version;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
fs.writeFileSync(pth, `${toml.stringify(tomlContent)}
|
|
129
|
+
`);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
module.exports = setVersion;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const setup = require("./setup.cjs");
|
|
4
|
+
const provider = require("./provider.cjs");
|
|
5
|
+
exports.setup = setup.setup;
|
|
6
|
+
exports.updateEnvFile = setup.updateEnvFile;
|
|
7
|
+
exports.setupProvider = provider.setupProvider;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const datasets = require("@prosopo/datasets");
|
|
4
|
+
const provider = require("@prosopo/provider");
|
|
5
|
+
async function setupProvider(env) {
|
|
6
|
+
const logger = env.logger;
|
|
7
|
+
const tasks = new provider.Tasks(env);
|
|
8
|
+
logger.info(() => ({ msg: " - providerSetDataset" }));
|
|
9
|
+
await tasks.datasetManager.providerSetDataset(datasets.datasetWithSolutionHashes);
|
|
10
|
+
}
|
|
11
|
+
exports.setupProvider = setupProvider;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const cli = require("@prosopo/cli");
|
|
5
|
+
const common = require("@prosopo/common");
|
|
6
|
+
const dotenv = require("@prosopo/dotenv");
|
|
7
|
+
const env = require("@prosopo/env");
|
|
8
|
+
const keyring = require("@prosopo/keyring");
|
|
9
|
+
const util = require("@prosopo/util");
|
|
10
|
+
const fse = require("fs-extra");
|
|
11
|
+
require("../util/index.cjs");
|
|
12
|
+
const provider = require("./provider.cjs");
|
|
13
|
+
const site = require("./site.cjs");
|
|
14
|
+
const updateEnv = require("../util/updateEnv.cjs");
|
|
15
|
+
const logger = common.getLogger(common.LogLevel.enum.info, "setup");
|
|
16
|
+
const __dirname$1 = path.resolve();
|
|
17
|
+
function getRootDir() {
|
|
18
|
+
const rootDir = process.env.PROSOPO_ROOT_DIR || path.resolve(__dirname$1, "../..");
|
|
19
|
+
logger.info(() => ({ msg: "Root dir:", data: { rootDir } }));
|
|
20
|
+
return rootDir;
|
|
21
|
+
}
|
|
22
|
+
function getDatasetFilePath() {
|
|
23
|
+
const datasetFile = process.env.PROSOPO_PROVIDER_DATASET_FILE || path.resolve("../data/captchas.json");
|
|
24
|
+
logger.info(() => ({ msg: "Dataset file:", data: { datasetFile } }));
|
|
25
|
+
return datasetFile;
|
|
26
|
+
}
|
|
27
|
+
function getDefaultProvider() {
|
|
28
|
+
const host = process.env.PROSOPO_PROVIDER_HOST || "localhost";
|
|
29
|
+
return {
|
|
30
|
+
url: process.env.PROSOPO_API_PORT ? `http://${host}:${process.env.PROSOPO_API_PORT}` : `http://${host}:9229`,
|
|
31
|
+
datasetFile: getDatasetFilePath(),
|
|
32
|
+
address: process.env.PROSOPO_PROVIDER_ADDRESS || "",
|
|
33
|
+
secret: cli.getSecret(),
|
|
34
|
+
captchaDatasetId: "",
|
|
35
|
+
pair: keyring.getPair(cli.getSecret())
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async function copyEnvFile() {
|
|
39
|
+
try {
|
|
40
|
+
const rootDir = getRootDir();
|
|
41
|
+
const tplLocation = path.resolve(rootDir, "./dev/scripts");
|
|
42
|
+
const tplEnvFile = dotenv.getEnvFile(tplLocation, "env");
|
|
43
|
+
const envFile = dotenv.getEnvFile(tplLocation, ".env");
|
|
44
|
+
await fse.copy(tplEnvFile, envFile, { overwrite: false });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
logger.debug(() => ({ msg: "Error copying env file", err }));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function updateEnvFileVar(source, name, value) {
|
|
50
|
+
const envVar = new RegExp(`.*(${name}=)(.*)`, "g");
|
|
51
|
+
if (envVar.test(source)) {
|
|
52
|
+
return source.replace(envVar, `$1${value}`);
|
|
53
|
+
}
|
|
54
|
+
return `${source}
|
|
55
|
+
${name}=${value}`;
|
|
56
|
+
}
|
|
57
|
+
async function updateEnvFile(vars) {
|
|
58
|
+
const rootDir = getRootDir();
|
|
59
|
+
const envFile = dotenv.getEnvFile(rootDir, ".env");
|
|
60
|
+
let readEnvFile = await fse.readFile(envFile, "utf8");
|
|
61
|
+
for (const key in vars) {
|
|
62
|
+
readEnvFile = updateEnvFileVar(readEnvFile, key, util.get(vars, key));
|
|
63
|
+
}
|
|
64
|
+
logger.info(() => ({ msg: `Updating ${envFile}` }));
|
|
65
|
+
await fse.writeFile(envFile, readEnvFile);
|
|
66
|
+
}
|
|
67
|
+
async function setup(provider$1, sites) {
|
|
68
|
+
if (!provider$1 && !sites) {
|
|
69
|
+
logger.info(() => ({ msg: "No setup required, exiting." }));
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
72
|
+
const defaultProvider = getDefaultProvider();
|
|
73
|
+
if (defaultProvider.secret) {
|
|
74
|
+
const hasProviderAccount = defaultProvider.address && defaultProvider.secret;
|
|
75
|
+
logger.debug(() => ({
|
|
76
|
+
msg: "ENVIRONMENT",
|
|
77
|
+
data: { nodeEnv: process.env.NODE_ENV }
|
|
78
|
+
}));
|
|
79
|
+
const [mnemonic, address] = !hasProviderAccount ? await keyring.generateMnemonic() : [defaultProvider.secret, defaultProvider.address];
|
|
80
|
+
logger.debug(() => ({ msg: `Address: ${address}` }));
|
|
81
|
+
logger.debug(() => ({ msg: `Mnemonic: ${mnemonic}` }));
|
|
82
|
+
logger.debug(() => ({ msg: "Writing .env file..." }));
|
|
83
|
+
await copyEnvFile();
|
|
84
|
+
if (!process.env.PROSOPO_SITE_KEY) {
|
|
85
|
+
throw new common.ProsopoEnvError("DEVELOPER.PROSOPO_SITE_KEY_MISSING");
|
|
86
|
+
}
|
|
87
|
+
const config = cli.defaultConfig();
|
|
88
|
+
const providerSecret = config.account.secret;
|
|
89
|
+
const pair = keyring.getPair(providerSecret);
|
|
90
|
+
const authAccount = keyring.getPair(config.authAccount.secret);
|
|
91
|
+
const env$1 = new env.ProviderEnvironment(config, pair, authAccount);
|
|
92
|
+
await env$1.isReady();
|
|
93
|
+
defaultProvider.secret = mnemonic;
|
|
94
|
+
env$1.logger.info(() => ({
|
|
95
|
+
msg: `Registering provider... ${defaultProvider.address}`
|
|
96
|
+
}));
|
|
97
|
+
defaultProvider.pair = keyring.getPair(providerSecret);
|
|
98
|
+
if (provider$1) {
|
|
99
|
+
await provider.setupProvider(env$1);
|
|
100
|
+
if (!hasProviderAccount) {
|
|
101
|
+
await updateEnvFile({
|
|
102
|
+
PROVIDER_MNEMONIC: `"${mnemonic}"`,
|
|
103
|
+
PROVIDER_ADDRESS: address
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (sites) {
|
|
108
|
+
for (const siteKey of keyring.getDefaultSiteKeys()) {
|
|
109
|
+
siteKey.pair = keyring.getPair(siteKey.secret);
|
|
110
|
+
env$1.logger.info(() => ({
|
|
111
|
+
msg: `Registering ${siteKey.secret} siteKey ... ${siteKey.pair?.address}`
|
|
112
|
+
}));
|
|
113
|
+
await site.registerSiteKey(env$1, siteKey.pair.address, siteKey.settings);
|
|
114
|
+
env$1.logger.debug(() => ({
|
|
115
|
+
msg: "Updating env files with PROSOPO_SITE_KEY"
|
|
116
|
+
}));
|
|
117
|
+
await updateEnv.updateDemoHTMLFiles(
|
|
118
|
+
[/data-sitekey="(\w{48})"/, /siteKey:\s*'(\w{48})'/],
|
|
119
|
+
siteKey.pair.address,
|
|
120
|
+
env$1.logger
|
|
121
|
+
);
|
|
122
|
+
const envVarNames = siteKey.settings.captchaType === "image" ? [
|
|
123
|
+
"PROSOPO_SITE_KEY",
|
|
124
|
+
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`
|
|
125
|
+
] : [
|
|
126
|
+
`PROSOPO_SITE_KEY_${siteKey.settings.captchaType.toUpperCase()}`
|
|
127
|
+
];
|
|
128
|
+
await updateEnv.updateEnvFiles(envVarNames, siteKey.pair.address, env$1.logger);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
process.exit();
|
|
132
|
+
} else {
|
|
133
|
+
console.error("no secret found in .env file");
|
|
134
|
+
throw new common.ProsopoEnvError("GENERAL.NO_MNEMONIC_OR_SEED");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.setup = setup;
|
|
138
|
+
exports.updateEnvFile = updateEnvFile;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const provider = require("@prosopo/provider");
|
|
4
|
+
const types = require("@prosopo/types");
|
|
5
|
+
async function registerSiteKey(env, siteKey, settings = {}) {
|
|
6
|
+
const logger = env.logger;
|
|
7
|
+
const tasks = new provider.Tasks(env);
|
|
8
|
+
logger.info(() => ({
|
|
9
|
+
msg: "registerSiteKey",
|
|
10
|
+
data: { siteKey, captchaType: settings.captchaType }
|
|
11
|
+
}));
|
|
12
|
+
await tasks.clientTaskManager.registerSiteKey(
|
|
13
|
+
siteKey,
|
|
14
|
+
types.Tier.Professional,
|
|
15
|
+
types.ClientSettingsSchema.parse({
|
|
16
|
+
captchaType: types.CaptchaType.frictionless,
|
|
17
|
+
frictionlessThreshold: 0.8,
|
|
18
|
+
powDifficulty: 4,
|
|
19
|
+
imageThreshold: 0.8,
|
|
20
|
+
...settings,
|
|
21
|
+
domains: settings.domains && settings.domains.length > 0 ? settings.domains : ["localhost", "0.0.0.0"]
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
exports.registerSiteKey = registerSiteKey;
|