@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.
Files changed (118) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/cjs/cli/index.cjs +105 -0
  3. package/dist/cjs/contract/import.cjs +183 -0
  4. package/dist/cjs/contract/index.cjs +4 -0
  5. package/dist/cjs/index.cjs +25 -0
  6. package/dist/cjs/scripts/setVersion.cjs +132 -0
  7. package/dist/cjs/setup/index.cjs +7 -0
  8. package/dist/cjs/setup/provider.cjs +11 -0
  9. package/dist/cjs/setup/setup.cjs +138 -0
  10. package/dist/cjs/setup/site.cjs +25 -0
  11. package/dist/cjs/util/exec.cjs +46 -0
  12. package/dist/cjs/util/fluxLogDappDetails.cjs +18 -0
  13. package/dist/cjs/util/index.cjs +13 -0
  14. package/dist/cjs/util/loadContractFiles.cjs +44 -0
  15. package/dist/cjs/util/updateEnv.cjs +71 -0
  16. package/dist/cli/index.js +96 -99
  17. package/dist/contract/import.js +169 -149
  18. package/dist/contract/index.js +4 -2
  19. package/dist/index.js +25 -5
  20. package/dist/scripts/setVersion.js +115 -121
  21. package/dist/setup/index.js +7 -3
  22. package/dist/setup/provider.js +8 -6
  23. package/dist/setup/setup.js +113 -113
  24. package/dist/setup/site.js +23 -19
  25. package/dist/util/exec.js +42 -41
  26. package/dist/util/fluxLogDappDetails.js +17 -15
  27. package/dist/util/index.js +13 -5
  28. package/dist/util/loadContractFiles.js +34 -30
  29. package/dist/util/updateEnv.js +59 -54
  30. package/package.json +29 -21
  31. package/vite.cjs.config.ts +19 -0
  32. package/vite.esm.config.ts +20 -0
  33. package/dist/cli/index.d.ts +0 -2
  34. package/dist/cli/index.d.ts.map +0 -1
  35. package/dist/cli/index.js.map +0 -1
  36. package/dist/contract/import.d.ts +0 -3
  37. package/dist/contract/import.d.ts.map +0 -1
  38. package/dist/contract/import.js.map +0 -1
  39. package/dist/contract/index.d.ts +0 -2
  40. package/dist/contract/index.d.ts.map +0 -1
  41. package/dist/contract/index.js.map +0 -1
  42. package/dist/index.d.ts +0 -5
  43. package/dist/index.d.ts.map +0 -1
  44. package/dist/index.js.map +0 -1
  45. package/dist/scripts/bytesToHex.d.ts +0 -2
  46. package/dist/scripts/bytesToHex.d.ts.map +0 -1
  47. package/dist/scripts/bytesToHex.js +0 -7
  48. package/dist/scripts/bytesToHex.js.map +0 -1
  49. package/dist/scripts/convertAccount.d.ts +0 -2
  50. package/dist/scripts/convertAccount.d.ts.map +0 -1
  51. package/dist/scripts/convertAccount.js +0 -24
  52. package/dist/scripts/convertAccount.js.map +0 -1
  53. package/dist/scripts/encodeDecode.d.ts +0 -2
  54. package/dist/scripts/encodeDecode.d.ts.map +0 -1
  55. package/dist/scripts/encodeDecode.js +0 -108
  56. package/dist/scripts/encodeDecode.js.map +0 -1
  57. package/dist/scripts/findUnused.d.ts +0 -2
  58. package/dist/scripts/findUnused.d.ts.map +0 -1
  59. package/dist/scripts/findUnused.js +0 -80
  60. package/dist/scripts/findUnused.js.map +0 -1
  61. package/dist/scripts/generateMnemonic.d.ts +0 -2
  62. package/dist/scripts/generateMnemonic.d.ts.map +0 -1
  63. package/dist/scripts/generateMnemonic.js +0 -26
  64. package/dist/scripts/generateMnemonic.js.map +0 -1
  65. package/dist/scripts/getBlock.d.ts +0 -2
  66. package/dist/scripts/getBlock.d.ts.map +0 -1
  67. package/dist/scripts/getBlock.js +0 -17
  68. package/dist/scripts/getBlock.js.map +0 -1
  69. package/dist/scripts/getContractInfoOf.d.ts +0 -2
  70. package/dist/scripts/getContractInfoOf.d.ts.map +0 -1
  71. package/dist/scripts/getContractInfoOf.js +0 -40
  72. package/dist/scripts/getContractInfoOf.js.map +0 -1
  73. package/dist/scripts/hash.d.ts +0 -2
  74. package/dist/scripts/hash.d.ts.map +0 -1
  75. package/dist/scripts/hash.js +0 -41
  76. package/dist/scripts/hash.js.map +0 -1
  77. package/dist/scripts/hexToBytes.d.ts +0 -2
  78. package/dist/scripts/hexToBytes.d.ts.map +0 -1
  79. package/dist/scripts/hexToBytes.js +0 -6
  80. package/dist/scripts/hexToBytes.js.map +0 -1
  81. package/dist/scripts/setVersion.d.ts +0 -2
  82. package/dist/scripts/setVersion.d.ts.map +0 -1
  83. package/dist/scripts/setVersion.js.map +0 -1
  84. package/dist/scripts/sign.d.ts +0 -2
  85. package/dist/scripts/sign.d.ts.map +0 -1
  86. package/dist/scripts/sign.js +0 -41
  87. package/dist/scripts/sign.js.map +0 -1
  88. package/dist/scripts/testImport.d.ts +0 -2
  89. package/dist/scripts/testImport.d.ts.map +0 -1
  90. package/dist/scripts/testImport.js +0 -13
  91. package/dist/scripts/testImport.js.map +0 -1
  92. package/dist/setup/index.d.ts +0 -3
  93. package/dist/setup/index.d.ts.map +0 -1
  94. package/dist/setup/index.js.map +0 -1
  95. package/dist/setup/provider.d.ts +0 -3
  96. package/dist/setup/provider.d.ts.map +0 -1
  97. package/dist/setup/provider.js.map +0 -1
  98. package/dist/setup/setup.d.ts +0 -3
  99. package/dist/setup/setup.d.ts.map +0 -1
  100. package/dist/setup/setup.js.map +0 -1
  101. package/dist/setup/site.d.ts +0 -4
  102. package/dist/setup/site.d.ts.map +0 -1
  103. package/dist/setup/site.js.map +0 -1
  104. package/dist/util/exec.d.ts +0 -10
  105. package/dist/util/exec.d.ts.map +0 -1
  106. package/dist/util/exec.js.map +0 -1
  107. package/dist/util/fluxLogDappDetails.d.ts +0 -2
  108. package/dist/util/fluxLogDappDetails.d.ts.map +0 -1
  109. package/dist/util/fluxLogDappDetails.js.map +0 -1
  110. package/dist/util/index.d.ts +0 -5
  111. package/dist/util/index.d.ts.map +0 -1
  112. package/dist/util/index.js.map +0 -1
  113. package/dist/util/loadContractFiles.d.ts +0 -4
  114. package/dist/util/loadContractFiles.d.ts.map +0 -1
  115. package/dist/util/loadContractFiles.js.map +0 -1
  116. package/dist/util/updateEnv.d.ts +0 -5
  117. package/dist/util/updateEnv.d.ts.map +0 -1
  118. package/dist/util/updateEnv.js.map +0 -1
@@ -1,138 +1,138 @@
1
1
  import path from "node:path";
2
- import { defaultConfig, getSecret } from "@prosopo/cli";
3
- import { LogLevel, ProsopoEnvError, getLogger } from "@prosopo/common";
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, getPair, } from "@prosopo/keyring";
6
+ import { getPair, generateMnemonic, getDefaultSiteKeys } from "@prosopo/keyring";
7
7
  import { get } from "@prosopo/util";
8
8
  import fse from "fs-extra";
9
- import { updateDemoHTMLFiles, updateEnvFiles } from "../util/index.js";
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
- const rootDir = process.env.PROSOPO_ROOT_DIR || path.resolve(__dirname, "../..");
16
- logger.info(() => ({ msg: "Root dir:", data: { rootDir } }));
17
- return rootDir;
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
- const datasetFile = process.env.PROSOPO_PROVIDER_DATASET_FILE ||
21
- path.resolve("../data/captchas.json");
22
- logger.info(() => ({ msg: "Dataset file:", data: { datasetFile } }));
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
- const host = process.env.PROSOPO_PROVIDER_HOST || "localhost";
27
- return {
28
- url: process.env.PROSOPO_API_PORT
29
- ? `http://${host}:${process.env.PROSOPO_API_PORT}`
30
- : `http://${host}:9229`,
31
- datasetFile: getDatasetFilePath(),
32
- address: process.env.PROSOPO_PROVIDER_ADDRESS || "",
33
- secret: getSecret(),
34
- captchaDatasetId: "",
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
- try {
40
- const rootDir = getRootDir();
41
- const tplLocation = path.resolve(rootDir, "./dev/scripts");
42
- const tplEnvFile = getEnvFile(tplLocation, "env");
43
- const envFile = getEnvFile(tplLocation, ".env");
44
- await fse.copy(tplEnvFile, envFile, { overwrite: false });
45
- }
46
- catch (err) {
47
- logger.debug(() => ({ msg: "Error copying env file", err }));
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
- const envVar = new RegExp(`.*(${name}=)(.*)`, "g");
52
- if (envVar.test(source)) {
53
- return source.replace(envVar, `$1${value}`);
54
- }
55
- return `${source}\n${name}=${value}`;
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
- export async function updateEnvFile(vars) {
58
- const rootDir = getRootDir();
59
- const envFile = getEnvFile(rootDir, ".env");
60
- let readEnvFile = await fse.readFile(envFile, "utf8");
61
- for (const key in vars) {
62
- readEnvFile = updateEnvFileVar(readEnvFile, key, get(vars, key));
63
- }
64
- logger.info(() => ({ msg: `Updating ${envFile}` }));
65
- await fse.writeFile(envFile, readEnvFile);
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
- export async function setup(provider, sites) {
68
- if (!provider && !sites) {
69
- logger.info(() => ({ msg: "No setup required, exiting." }));
70
- process.exit(0);
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 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
80
- ? await generateMnemonic()
81
- : [defaultProvider.secret, defaultProvider.address];
82
- logger.debug(() => ({ msg: `Address: ${address}` }));
83
- logger.debug(() => ({ msg: `Mnemonic: ${mnemonic}` }));
84
- logger.debug(() => ({ msg: "Writing .env file..." }));
85
- await copyEnvFile();
86
- if (!process.env.PROSOPO_SITE_KEY) {
87
- throw new ProsopoEnvError("DEVELOPER.PROSOPO_SITE_KEY_MISSING");
88
- }
89
- const config = defaultConfig();
90
- const providerSecret = config.account.secret;
91
- const pair = getPair(providerSecret);
92
- const authAccount = getPair(config.authAccount.secret);
93
- const env = new ProviderEnvironment(defaultConfig(), pair, authAccount);
94
- await env.isReady();
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
- msg: `Registering provider... ${defaultProvider.address}`,
109
+ msg: `Registering ${siteKey.secret} siteKey ... ${siteKey.pair?.address}`
98
110
  }));
99
- defaultProvider.pair = getPair(providerSecret);
100
- if (provider) {
101
- await setupProvider(env);
102
- if (!hasProviderAccount) {
103
- await updateEnvFile({
104
- PROVIDER_MNEMONIC: `"${mnemonic}"`,
105
- PROVIDER_ADDRESS: address,
106
- });
107
- }
108
- }
109
- if (sites) {
110
- for (const siteKey of getDefaultSiteKeys()) {
111
- siteKey.pair = getPair(siteKey.secret);
112
- env.logger.info(() => ({
113
- msg: `Registering ${siteKey.secret} siteKey ... ${siteKey.pair?.address}`,
114
- }));
115
- await registerSiteKey(env, siteKey.pair.address, siteKey.settings);
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
- //# sourceMappingURL=setup.js.map
135
+ export {
136
+ setup,
137
+ updateEnvFile
138
+ };
@@ -1,21 +1,25 @@
1
1
  import { Tasks } from "@prosopo/provider";
2
- import { CaptchaType, ClientSettingsSchema, Tier, } from "@prosopo/types";
3
- export 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(siteKey, Tier.Professional, ClientSettingsSchema.parse({
11
- captchaType: CaptchaType.frictionless,
12
- frictionlessThreshold: 0.8,
13
- powDifficulty: 4,
14
- imageThreshold: 0.8,
15
- ...settings,
16
- domains: settings.domains && settings.domains.length > 0
17
- ? settings.domains
18
- : ["localhost", "0.0.0.0"],
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
- //# sourceMappingURL=site.js.map
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
- export const exec = (command, options) => {
4
- let { pipe, printCmd } = options || {};
5
- pipe = pipe === undefined || pipe;
6
- printCmd = printCmd === undefined || printCmd;
7
- if (printCmd) {
8
- console.log(`[exec] ${command}`);
9
- }
10
- const prc = spawn(command, {
11
- shell: true,
12
- });
13
- if (pipe || pipe === undefined) {
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 === undefined) {
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
- }
39
- else {
40
- reject(output);
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
- export 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
- }, new Set()),
13
- ];
14
- return urls.join(" ");
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
- //# sourceMappingURL=fluxLogDappDetails.js.map
16
+ export {
17
+ extractReferrersFromLogs
18
+ };
@@ -1,5 +1,13 @@
1
- export * from "./loadContractFiles.js";
2
- export * from "./updateEnv.js";
3
- export * from "./exec.js";
4
- export * from "./fluxLogDappDetails.js";
5
- //# sourceMappingURL=index.js.map
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
- export 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(await fse.readFile(resolvedFilePath, {
13
- encoding: "utf8",
14
- }));
15
- return new Abi(json);
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
- context: { error: `File ${filePath} does not exist` },
37
+ context: { error: `File ${filePath} does not exist` }
19
38
  });
39
+ }
20
40
  }
21
- export async function Wasm(filePath) {
22
- const resolvedFilePath = path.resolve(__dirname, filePath);
23
- await fse.ensureFile(resolvedFilePath);
24
- const fileExists = await fse.pathExists(resolvedFilePath);
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
+ };
@@ -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
- "**/node_modules/**",
9
- "node_modules/**",
10
- "../../**/node_modules/**",
11
- "../node_modules/**",
12
- "../../node_modules/**",
8
+ "**/node_modules/**",
9
+ "node_modules/**",
10
+ "../../**/node_modules/**",
11
+ "../node_modules/**",
12
+ "../../node_modules/**"
13
13
  ];
14
14
  const __dirname = path.resolve();
15
- export 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
- });
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
- export async function updateDemoHTMLFiles(varMatchers, varValue, logger) {
24
- const files = await fg("../../demos/**/*.html", {
25
- ignore: 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
- });
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
- export 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(path.resolve(__dirname, filePath), Object.keys(envConfig)
61
- .map((k) => `${k}=${envConfig[k]}`)
62
- .join("\n"));
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
- //# sourceMappingURL=updateEnv.js.map
67
+ export {
68
+ findEnvFiles,
69
+ updateDemoHTMLFiles,
70
+ updateEnvFiles
71
+ };