@taqueria/toolkit 0.28.0 → 0.28.1
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/bin/run.js +49 -26
- package/bin/run.js.map +1 -1
- package/bin/run.ts +11 -53
- package/index.d.ts +3 -20
- package/index.js +6 -2
- package/index.js.map +1 -1
- package/index.ts +7 -2
- package/lib/README.md +1 -0
- package/lib/env.d.ts +19 -0
- package/lib/env.ts +73 -0
- package/package.json +14 -4
- package/v1.d.ts +6 -3
- package/v1.js +40 -0
- package/v1.js.map +1 -0
- package/v2-e3846710.d.ts +22 -0
- package/v2.d.ts +3 -9
- package/v2.js +61 -0
- package/v2.js.map +1 -0
package/bin/run.js
CHANGED
|
@@ -21,10 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
|
|
22
22
|
// bin/run.ts
|
|
23
23
|
var import_cross_spawn = require("cross-spawn");
|
|
24
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
25
|
-
var import_promises2 = require("fs/promises");
|
|
26
|
-
var import_path = __toESM(require("path"));
|
|
27
24
|
var import_yargs = __toESM(require("yargs"));
|
|
25
|
+
|
|
26
|
+
// lib/env.ts
|
|
27
|
+
var import_promises = require("fs/promises");
|
|
28
|
+
var import_path = __toESM(require("path"));
|
|
28
29
|
var CustomErr = class extends Error {
|
|
29
30
|
};
|
|
30
31
|
var TaqNotFoundError = class extends CustomErr {
|
|
@@ -39,30 +40,12 @@ function isCustomError(err) {
|
|
|
39
40
|
async function checkTaqProject(dir) {
|
|
40
41
|
try {
|
|
41
42
|
const searchPath = import_path.default.join(dir, ".taq");
|
|
42
|
-
await (0,
|
|
43
|
+
await (0, import_promises.stat)(searchPath);
|
|
43
44
|
return searchPath;
|
|
44
45
|
} catch {
|
|
45
46
|
throw new TaqNotFoundError(`${dir} is not a valid Taqueria project.`);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
function withArguments(cliArgs, fn) {
|
|
49
|
-
if (cliArgs[0].endsWith("node"))
|
|
50
|
-
cliArgs.shift();
|
|
51
|
-
const script = cliArgs.shift();
|
|
52
|
-
const parsedArgs = (0, import_yargs.default)(cliArgs).option("projectDir", {
|
|
53
|
-
alias: "p",
|
|
54
|
-
type: "string",
|
|
55
|
-
requiresArg: true
|
|
56
|
-
}).option("prefix", {
|
|
57
|
-
type: "string",
|
|
58
|
-
requiresArg: true,
|
|
59
|
-
default: ""
|
|
60
|
-
}).global(["projectDir"]).parseSync();
|
|
61
|
-
if (parsedArgs._.length > 0 && parsedArgs.projectDir) {
|
|
62
|
-
fn(parsedArgs.projectDir, parsedArgs.prefix, parsedArgs._.join(" "));
|
|
63
|
-
} else
|
|
64
|
-
console.log(`Usage: ${script} --projectDir <projectDir> [--prefix <prefix>] <command>`);
|
|
65
|
-
}
|
|
66
49
|
function getEnvName(filename, prefix = "") {
|
|
67
50
|
return `${prefix}TAQ_${filename}`.replace(".json", "").replace(/\./mg, "_").replace(/\-/mg, "_").toUpperCase();
|
|
68
51
|
}
|
|
@@ -70,14 +53,14 @@ var TaqConfigError = class extends CustomErr {
|
|
|
70
53
|
};
|
|
71
54
|
async function getConfig(taqDir, prefix) {
|
|
72
55
|
try {
|
|
73
|
-
const files = await import_promises.
|
|
56
|
+
const files = await (0, import_promises.readdir)(taqDir);
|
|
74
57
|
return files.reduce(
|
|
75
58
|
async (retval, file) => {
|
|
76
59
|
if (!file.endsWith(".json"))
|
|
77
60
|
return await retval;
|
|
78
61
|
return {
|
|
79
62
|
...await retval,
|
|
80
|
-
[getEnvName(file, prefix)]: await (0,
|
|
63
|
+
[getEnvName(file, prefix)]: await (0, import_promises.readFile)(import_path.default.join(taqDir, file), "utf-8")
|
|
81
64
|
};
|
|
82
65
|
},
|
|
83
66
|
Promise.resolve({})
|
|
@@ -88,16 +71,56 @@ async function getConfig(taqDir, prefix) {
|
|
|
88
71
|
);
|
|
89
72
|
}
|
|
90
73
|
}
|
|
74
|
+
function encode(value) {
|
|
75
|
+
const buffer = Buffer.from(value, "utf8");
|
|
76
|
+
return buffer.toString("base64");
|
|
77
|
+
}
|
|
78
|
+
async function getEncodedConfig(taqDir, prefix) {
|
|
79
|
+
const config = await getConfig(taqDir, prefix);
|
|
80
|
+
return Object.fromEntries(
|
|
81
|
+
Object.entries(config).map(
|
|
82
|
+
([k, v]) => [k, encode(v)]
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// bin/run.ts
|
|
88
|
+
function withArguments(cliArgs, fn) {
|
|
89
|
+
if (cliArgs[0].endsWith("node"))
|
|
90
|
+
cliArgs.shift();
|
|
91
|
+
const script = cliArgs.shift();
|
|
92
|
+
const parsedArgs = (0, import_yargs.default)(cliArgs).option("projectDir", {
|
|
93
|
+
alias: "p",
|
|
94
|
+
type: "string",
|
|
95
|
+
requiresArg: true
|
|
96
|
+
}).option("prefix", {
|
|
97
|
+
type: "string",
|
|
98
|
+
requiresArg: true,
|
|
99
|
+
default: ""
|
|
100
|
+
}).global(["projectDir"]).parseSync();
|
|
101
|
+
if (parsedArgs._.length > 0 && parsedArgs.projectDir) {
|
|
102
|
+
fn(parsedArgs.projectDir, parsedArgs.prefix, parsedArgs._.join(" "));
|
|
103
|
+
} else
|
|
104
|
+
console.log(`Usage: ${script} --projectDir <projectDir> [--prefix <prefix>] <command>`);
|
|
105
|
+
}
|
|
91
106
|
function toCommandWithEnvVars(cmd, config) {
|
|
92
107
|
return Object.entries(config).reduce(
|
|
93
|
-
(retval, [key, value]) =>
|
|
108
|
+
(retval, [key, value]) => {
|
|
109
|
+
try {
|
|
110
|
+
return `${key}=${value} ${retval}`;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.warn(`Could not set ${key}`);
|
|
113
|
+
console.warn("Check the contents of the associated file and ensure that it can be Base64 encoded.");
|
|
114
|
+
return retval;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
94
117
|
cmd
|
|
95
118
|
);
|
|
96
119
|
}
|
|
97
120
|
async function run(projectDir, prefix, cmd) {
|
|
98
121
|
try {
|
|
99
122
|
const taqDir = await checkTaqProject(projectDir);
|
|
100
|
-
const config = await
|
|
123
|
+
const config = await getEncodedConfig(taqDir, prefix);
|
|
101
124
|
const cmdWithEnvVars = toCommandWithEnvVars(cmd, config);
|
|
102
125
|
(0, import_cross_spawn.spawn)(cmdWithEnvVars, {
|
|
103
126
|
shell: true,
|
package/bin/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["run.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { spawn } from 'cross-spawn';\nimport
|
|
1
|
+
{"version":3,"sources":["run.ts","../lib/env.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { spawn } from 'cross-spawn';\nimport path from 'path';\nimport yargs from 'yargs';\nimport { checkTaqProject, getEncodedConfig, isCustomError } from '../lib/env';\n\nfunction withArguments(cliArgs: string[], fn: (projectDir: string, prefix: string, cmd: string) => Promise<void>) {\n\tif (cliArgs[0].endsWith('node')) cliArgs.shift();\n\n\tconst script = cliArgs.shift();\n\n\tconst parsedArgs = yargs(cliArgs)\n\t\t.option('projectDir', {\n\t\t\talias: 'p',\n\t\t\ttype: 'string',\n\t\t\trequiresArg: true,\n\t\t})\n\t\t.option('prefix', {\n\t\t\ttype: 'string',\n\t\t\trequiresArg: true,\n\t\t\tdefault: '',\n\t\t})\n\t\t.global(['projectDir'])\n\t\t.parseSync();\n\n\tif (parsedArgs._.length > 0 && parsedArgs.projectDir) {\n\t\tfn(parsedArgs.projectDir, parsedArgs.prefix, parsedArgs._.join(' '));\n\t} else console.log(`Usage: ${script} --projectDir <projectDir> [--prefix <prefix>] <command>`);\n}\n\nfunction toCommandWithEnvVars(cmd: string, config: Record<string, string>) {\n\treturn Object.entries(config).reduce(\n\t\t(retval, [key, value]) => {\n\t\t\ttry {\n\t\t\t\treturn `${key}=${value} ${retval}`;\n\t\t\t} catch (err) {\n\t\t\t\tconsole.warn(`Could not set ${key}`);\n\t\t\t\tconsole.warn('Check the contents of the associated file and ensure that it can be Base64 encoded.');\n\t\t\t\treturn retval;\n\t\t\t}\n\t\t},\n\t\tcmd,\n\t);\n}\n\nasync function run(projectDir: string, prefix: string, cmd: string) {\n\ttry {\n\t\tconst taqDir = await checkTaqProject(projectDir);\n\t\tconst config = await getEncodedConfig(taqDir, prefix);\n\t\tconst cmdWithEnvVars = toCommandWithEnvVars(cmd, config);\n\n\t\tspawn(cmdWithEnvVars, {\n\t\t\tshell: true,\n\t\t\tstdio: 'inherit',\n\t\t});\n\t} catch (err) {\n\t\tif (isCustomError(err)) {\n\t\t\tconsole.error(err.message);\n\t\t\treturn;\n\t\t}\n\t\tthrow err;\n\t}\n}\n\nwithArguments(process.argv, run);\n","import { readdir, readFile, stat } from 'fs/promises';\nimport path from 'path';\n\nclass CustomErr extends Error {}\n\nexport class TaqNotFoundError extends CustomErr {\n\tpublic isCustomErr = true;\n}\n\nexport function isCustomError(err: unknown): err is Error {\n\treturn typeof err === 'object' && (err as object).hasOwnProperty('isCustomErr');\n}\n\nexport async function checkTaqProject(dir: string) {\n\ttry {\n\t\tconst searchPath = path.join(dir, '.taq');\n\t\tawait stat(searchPath);\n\t\treturn searchPath;\n\t} catch {\n\t\tthrow new TaqNotFoundError(`${dir} is not a valid Taqueria project.`);\n\t}\n}\n\nfunction getEnvName(filename: string, prefix = '') {\n\treturn `${prefix}TAQ_${filename}`\n\t\t.replace('.json', '')\n\t\t.replace(/\\./mg, '_')\n\t\t.replace(/\\-/mg, '_')\n\t\t.toUpperCase();\n}\n\nexport class TaqConfigError extends CustomErr {}\nexport async function getConfig(taqDir: string, prefix: string) {\n\ttry {\n\t\tconst files = await readdir(taqDir);\n\t\treturn files.reduce(\n\t\t\tasync (retval, file) => {\n\t\t\t\tif (!file.endsWith('.json')) return (await retval);\n\t\t\t\treturn {\n\t\t\t\t\t...(await retval),\n\t\t\t\t\t[getEnvName(file, prefix)]: await readFile(path.join(taqDir, file), 'utf-8'),\n\t\t\t\t};\n\t\t\t},\n\t\t\tPromise.resolve({}),\n\t\t);\n\t} catch {\n\t\tthrow new TaqConfigError(\n\t\t\t`There was a problem reading the config files in ${taqDir}. Please check file permissions are try again.`,\n\t\t);\n\t}\n}\n\nexport function encode(value: string) {\n\tconst buffer = Buffer.from(value, 'utf8');\n\treturn buffer.toString('base64');\n}\n\nexport async function getEncodedConfig(taqDir: string, prefix: string) {\n\tconst config = await getConfig(taqDir, prefix);\n\treturn Object.fromEntries(\n\t\tObject.entries(config).map(\n\t\t\t([k, v]) => [k, encode(v as string)],\n\t\t),\n\t);\n}\n\nexport async function getEnv(env: typeof process.env, taqDir: string, prefix: string = '') {\n\tconst realTaqDir = await checkTaqProject(taqDir);\n\treturn {\n\t\t...env,\n\t\t...await getEncodedConfig(realTaqDir, prefix),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,yBAAsB;AAEtB,mBAAkB;;;ACHlB,sBAAwC;AACxC,kBAAiB;AAEjB,IAAM,YAAN,cAAwB,MAAM;AAAC;AAExB,IAAM,mBAAN,cAA+B,UAAU;AAAA,EAAzC;AAAA;AACN,SAAO,cAAc;AAAA;AACtB;AAEO,SAAS,cAAc,KAA4B;AACzD,SAAO,OAAO,QAAQ,YAAa,IAAe,eAAe,aAAa;AAC/E;AAEA,eAAsB,gBAAgB,KAAa;AAClD,MAAI;AACH,UAAM,aAAa,YAAAA,QAAK,KAAK,KAAK,MAAM;AACxC,cAAM,sBAAK,UAAU;AACrB,WAAO;AAAA,EACR,QAAE;AACD,UAAM,IAAI,iBAAiB,GAAG,sCAAsC;AAAA,EACrE;AACD;AAEA,SAAS,WAAW,UAAkB,SAAS,IAAI;AAClD,SAAO,GAAG,aAAa,WACrB,QAAQ,SAAS,EAAE,EACnB,QAAQ,QAAQ,GAAG,EACnB,QAAQ,QAAQ,GAAG,EACnB,YAAY;AACf;AAEO,IAAM,iBAAN,cAA6B,UAAU;AAAC;AAC/C,eA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YAAY;AACrD,OAAG,WAAW,YAAY,WAAW,QAAQ,WAAW,EAAE,KAAK,GAAG,CAAC;AAAA,EACpE;AAAO,YAAQ,IAAI,UAAU,gEAAgE;AAC9F;AAEA,SAAS,qBAAqB,KAAa,QAAgC;AAC1E,SAAO,OAAO,QAAQ,MAAM,EAAE;AAAA,IAC7B,CAAC,QAAQ,CAAC,KAAK,KAAK,MAAM;AACzB,UAAI;AACH,eAAO,GAAG,OAAO,SAAS;AAAA,MAC3B,SAAS,KAAP;AACD,gBAAQ,KAAK,iBAAiB,KAAK;AACnC,gBAAQ,KAAK,qFAAqF;AAClG,eAAO;AAAA,MACR;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;AAEA,eAAe,IAAI,YAAoB,QAAgB,KAAa;AACnE,MAAI;AACH,UAAM,SAAS,MAAM,gBAAgB,UAAU;AAC/C,UAAM,SAAS,MAAM,iBAAiB,QAAQ,MAAM;AACpD,UAAM,iBAAiB,qBAAqB,KAAK,MAAM;AAEvD,kCAAM,gBAAgB;AAAA,MACrB,OAAO;AAAA,MACP,OAAO;AAAA,IACR,CAAC;AAAA,EACF,SAAS,KAAP;AACD,QAAI,cAAc,GAAG,GAAG;AACvB,cAAQ,MAAM,IAAI,OAAO;AACzB;AAAA,IACD;AACA,UAAM;AAAA,EACP;AACD;AAEA,cAAc,QAAQ,MAAM,GAAG;","names":["path","yargs"]}
|
package/bin/run.ts
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn } from 'cross-spawn';
|
|
3
|
-
import fs from 'fs/promises';
|
|
4
|
-
import { readFile, stat } from 'fs/promises';
|
|
5
3
|
import path from 'path';
|
|
6
4
|
import yargs from 'yargs';
|
|
7
|
-
|
|
8
|
-
class CustomErr extends Error {}
|
|
9
|
-
|
|
10
|
-
class TaqNotFoundError extends CustomErr {
|
|
11
|
-
public isCustomErr = true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function isCustomError(err: unknown): err is Error {
|
|
15
|
-
return typeof err === 'object' && (err as object).hasOwnProperty('isCustomErr');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function checkTaqProject(dir: string) {
|
|
19
|
-
try {
|
|
20
|
-
const searchPath = path.join(dir, '.taq');
|
|
21
|
-
await stat(searchPath);
|
|
22
|
-
return searchPath;
|
|
23
|
-
} catch {
|
|
24
|
-
throw new TaqNotFoundError(`${dir} is not a valid Taqueria project.`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
5
|
+
import { checkTaqProject, getEncodedConfig, isCustomError } from '../lib/env';
|
|
27
6
|
|
|
28
7
|
function withArguments(cliArgs: string[], fn: (projectDir: string, prefix: string, cmd: string) => Promise<void>) {
|
|
29
8
|
if (cliArgs[0].endsWith('node')) cliArgs.shift();
|
|
@@ -49,38 +28,17 @@ function withArguments(cliArgs: string[], fn: (projectDir: string, prefix: strin
|
|
|
49
28
|
} else console.log(`Usage: ${script} --projectDir <projectDir> [--prefix <prefix>] <command>`);
|
|
50
29
|
}
|
|
51
30
|
|
|
52
|
-
function getEnvName(filename: string, prefix = '') {
|
|
53
|
-
return `${prefix}TAQ_${filename}`
|
|
54
|
-
.replace('.json', '')
|
|
55
|
-
.replace(/\./mg, '_')
|
|
56
|
-
.replace(/\-/mg, '_')
|
|
57
|
-
.toUpperCase();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
class TaqConfigError extends CustomErr {}
|
|
61
|
-
async function getConfig(taqDir: string, prefix: string) {
|
|
62
|
-
try {
|
|
63
|
-
const files = await fs.readdir(taqDir);
|
|
64
|
-
return files.reduce(
|
|
65
|
-
async (retval, file) => {
|
|
66
|
-
if (!file.endsWith('.json')) return (await retval);
|
|
67
|
-
return {
|
|
68
|
-
...(await retval),
|
|
69
|
-
[getEnvName(file, prefix)]: await readFile(path.join(taqDir, file), 'utf-8'),
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
Promise.resolve({}),
|
|
73
|
-
);
|
|
74
|
-
} catch {
|
|
75
|
-
throw new TaqConfigError(
|
|
76
|
-
`There was a problem reading the config files in ${taqDir}. Please check file permissions are try again.`,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
31
|
function toCommandWithEnvVars(cmd: string, config: Record<string, string>) {
|
|
82
32
|
return Object.entries(config).reduce(
|
|
83
|
-
(retval, [key, value]) =>
|
|
33
|
+
(retval, [key, value]) => {
|
|
34
|
+
try {
|
|
35
|
+
return `${key}=${value} ${retval}`;
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.warn(`Could not set ${key}`);
|
|
38
|
+
console.warn('Check the contents of the associated file and ensure that it can be Base64 encoded.');
|
|
39
|
+
return retval;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
84
42
|
cmd,
|
|
85
43
|
);
|
|
86
44
|
}
|
|
@@ -88,7 +46,7 @@ function toCommandWithEnvVars(cmd: string, config: Record<string, string>) {
|
|
|
88
46
|
async function run(projectDir: string, prefix: string, cmd: string) {
|
|
89
47
|
try {
|
|
90
48
|
const taqDir = await checkTaqProject(projectDir);
|
|
91
|
-
const config = await
|
|
49
|
+
const config = await getEncodedConfig(taqDir, prefix);
|
|
92
50
|
const cmdWithEnvVars = toCommandWithEnvVars(cmd, config);
|
|
93
51
|
|
|
94
52
|
spawn(cmdWithEnvVars, {
|
package/index.d.ts
CHANGED
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
import * as _taqueria_protocol_Environment from '@taqueria/protocol/Environment';
|
|
2
2
|
import * as Config from '@taqueria/protocol/Config';
|
|
3
3
|
export { Config };
|
|
4
|
-
|
|
4
|
+
export { v as V2 } from './v2-e3846710.js';
|
|
5
5
|
import * as transform from '@taqueria/protocol/types-config-files';
|
|
6
|
-
import
|
|
6
|
+
import '@taqueria/protocol/ConfigEnvironmentFileV2';
|
|
7
7
|
|
|
8
8
|
declare class TaqError extends Error {
|
|
9
9
|
isTaqError: boolean;
|
|
10
10
|
}
|
|
11
11
|
declare const isTaqError: (err: unknown) => err is TaqError;
|
|
12
12
|
|
|
13
|
-
type ExpandedEnv = Record<string, unknown> & ConfigEnvironmentFileV2.t & {
|
|
14
|
-
__type: 'expandedEnv';
|
|
15
|
-
};
|
|
16
|
-
declare function getEnv(envName: string, settings: ConfigFileSetV2$1): ExpandedEnv;
|
|
17
|
-
declare const getCurrentEnv$1: (settings: ConfigFileSetV2$1) => ExpandedEnv;
|
|
18
|
-
declare function getContractAddress(contractName: string, env: ExpandedEnv): string | undefined;
|
|
19
|
-
|
|
20
|
-
declare const v2_getContractAddress: typeof getContractAddress;
|
|
21
|
-
declare const v2_getEnv: typeof getEnv;
|
|
22
|
-
declare namespace v2 {
|
|
23
|
-
export {
|
|
24
|
-
v2_getContractAddress as getContractAddress,
|
|
25
|
-
getCurrentEnv$1 as getCurrentEnv,
|
|
26
|
-
v2_getEnv as getEnv,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
13
|
declare const getConfigAsV1: (env: Record<string, string | undefined>, prefix?: string) => Config.t;
|
|
31
14
|
declare function getConfigV2(env: Record<string, string | undefined>, prefix?: string): transform.ConfigFileSetV2;
|
|
32
15
|
declare const getAliasAddress: (config: any, alias: string) => string;
|
|
@@ -34,4 +17,4 @@ declare const getCurrentEnv: (config: Config.Config) => _taqueria_protocol_Envir
|
|
|
34
17
|
|
|
35
18
|
type ConfigFileSetV2 = transform.ConfigFileSetV2;
|
|
36
19
|
|
|
37
|
-
export { ConfigFileSetV2, TaqError,
|
|
20
|
+
export { ConfigFileSetV2, TaqError, getAliasAddress, getConfigAsV1, getConfigV2, getCurrentEnv, isTaqError };
|
package/index.js
CHANGED
|
@@ -100,6 +100,10 @@ var transform = __toESM(require("@taqueria/protocol/types-config-files"));
|
|
|
100
100
|
var DEFAULT_ENV_VAR_PREFIX = "";
|
|
101
101
|
function withEnv(env, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
102
102
|
const getConfigEnvKey = () => `${prefix}TAQ_CONFIG`;
|
|
103
|
+
const decode = (value) => {
|
|
104
|
+
const buffer = Buffer.from(value, "base64");
|
|
105
|
+
return buffer.toString("utf8");
|
|
106
|
+
};
|
|
103
107
|
const getRawConfig = () => {
|
|
104
108
|
const key = getConfigEnvKey();
|
|
105
109
|
const data = env[key];
|
|
@@ -109,7 +113,7 @@ function withEnv(env, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
|
109
113
|
);
|
|
110
114
|
}
|
|
111
115
|
try {
|
|
112
|
-
const decoded =
|
|
116
|
+
const decoded = decode(data);
|
|
113
117
|
const rawConfig = JSON.parse(decoded);
|
|
114
118
|
return rawConfig;
|
|
115
119
|
} catch (e) {
|
|
@@ -126,7 +130,7 @@ function withEnv(env, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
|
126
130
|
return ConfigEnvironmentFileV2.from({});
|
|
127
131
|
}
|
|
128
132
|
try {
|
|
129
|
-
const decoded =
|
|
133
|
+
const decoded = decode(data);
|
|
130
134
|
const rawConfig = JSON.parse(decoded);
|
|
131
135
|
return ConfigEnvironmentFileV2.from(rawConfig);
|
|
132
136
|
} catch (e) {
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts","TaqError.ts","v1.ts","v2.ts"],"sourcesContent":["import * as Config from '@taqueria/protocol/Config';\nimport * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';\nimport * as ConfigFileV2 from '@taqueria/protocol/ConfigFileV2';\nimport { isTaqError, TaqError } from './TaqError';\nexport { isTaqError, TaqError } from './TaqError';\nimport * as V1 from './v1';\nexport * as V2 from './v2';\nimport * as transform from '@taqueria/protocol/types-config-files';\n\nconst DEFAULT_ENV_VAR_PREFIX = '';\n\nfunction withEnv(env: Record<string, string | undefined>, prefix = DEFAULT_ENV_VAR_PREFIX) {\n\tconst getConfigEnvKey = () => `${prefix}TAQ_CONFIG`;\n\n\tconst getRawConfig = () => {\n\t\tconst key = getConfigEnvKey();\n\t\tconst data = env[key];\n\t\tif (!data) {\n\t\t\tthrow new TaqError(\n\t\t\t\t`Could not find config. Please ensure that the environment variable called ${key} is defined and set to the value of your config.json file using Base64 encoding.`,\n\t\t\t);\n\t\t}\n\t\ttry {\n\t\t\tconst decoded = atob(data);\n\t\t\tconst rawConfig = JSON.parse(decoded);\n\t\t\treturn rawConfig;\n\t\t} catch {\n\t\t\tthrow new TaqError(\n\t\t\t\t`Could not parse the config. Please ensure that the environment variable called ${key} is defined and set to the value of your config.json file using Base64 encoding.`,\n\t\t\t);\n\t\t}\n\t};\n\n\tconst getEnvironmentConfigKey = (environmentName: string) =>\n\t\t`${prefix}TAQ_CONFIG_LOCAL_${environmentName.toUpperCase()}`;\n\n\tconst getEnvironmentConfig = (environmentName: string) => {\n\t\tconst key = getEnvironmentConfigKey(environmentName);\n\t\tconst data = env[key];\n\t\tif (!data) {\n\t\t\treturn ConfigEnvironmentFileV2.from({});\n\t\t}\n\t\ttry {\n\t\t\tconst decoded = atob(data);\n\t\t\tconst rawConfig = JSON.parse(decoded);\n\t\t\treturn ConfigEnvironmentFileV2.from(rawConfig);\n\t\t} catch {\n\t\t\tthrow new TaqError(\n\t\t\t\t`Could not parse environment config for an environment called ${environmentName}. Please ensure that the environment variable called ${key} is defined and set to the value of your config.json file using Base64 encoding.`,\n\t\t\t);\n\t\t}\n\t};\n\n\treturn {\n\t\tgetConfigEnvKey,\n\t\tgetRawConfig,\n\t\tgetEnvironmentConfigKey,\n\t\tgetEnvironmentConfig,\n\t};\n}\n\nexport const getConfigAsV1 = (env: Record<string, string | undefined>, prefix = DEFAULT_ENV_VAR_PREFIX): Config.t => {\n\tconst { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);\n\n\tconst rawConfig = getRawConfig();\n\n\ttry {\n\t\t// If version v1, return the config object\n\t\tif (!rawConfig.version || rawConfig.version.toLowerCase() === 'v1') return Config.from(rawConfig);\n\t\t// If version v2, transform to V1 and return that\n\t\telse if (rawConfig.version.toLowerCase() === 'v2') {\n\t\t\tconst config = ConfigFileV2.from(rawConfig);\n\t\t\tconst environments = Object.keys(config.environments ?? {}).reduce(\n\t\t\t\t(retval, envName) => ({\n\t\t\t\t\t...retval,\n\t\t\t\t\t[envName]: getEnvironmentConfig(envName),\n\t\t\t\t}),\n\t\t\t\t{},\n\t\t\t);\n\n\t\t\treturn Config.create(transform.transformConfigFileV2ToConfig({\n\t\t\t\tconfig,\n\t\t\t\tenvironments,\n\t\t\t}));\n\t\t}\n\n\t\t// Other version handlers go here\n\t\tthrow new TaqError(`The version of your configuration is not yet supported.`);\n\t} catch (err) {\n\t\tthrow isTaqError(err)\n\t\t\t? err\n\t\t\t: new TaqError(\n\t\t\t\t`Something went wrong trying to parse your configuration. Please report this to the Taqueria Developers: ${err}`,\n\t\t\t);\n\t}\n};\n\nexport function getConfigV2(\n\tenv: Record<string, string | undefined>,\n\tprefix = DEFAULT_ENV_VAR_PREFIX,\n): transform.ConfigFileSetV2 {\n\tconst { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);\n\n\tconst rawConfig = getRawConfig();\n\n\ttry {\n\t\t// If version v1, return the config object\n\t\tif (!rawConfig.version || rawConfig.version.toLowerCase() === 'v1') {\n\t\t\tconst configV1 = Config.from(rawConfig);\n\t\t\treturn transform.transformConfigToConfigFileV2(configV1);\n\t\t} else if (rawConfig.version.toLowerCase() === 'v2') {\n\t\t\tconst configV2 = ConfigFileV2.from(rawConfig);\n\t\t\tconst environments = Object.keys(configV2.environments ?? {}).reduce(\n\t\t\t\t(retval, envName) => ({ ...retval, [envName]: getEnvironmentConfig(envName) }),\n\t\t\t\t{},\n\t\t\t);\n\t\t\tconst retval: transform.ConfigFileSetV2 = {\n\t\t\t\tconfig: configV2,\n\t\t\t\tenvironments,\n\t\t\t};\n\n\t\t\treturn retval;\n\t\t}\n\t\t// Other version handlers go here\n\t\t// No other versions we're aware of.\n\t\tthrow new TaqError(`The version of your configuration is not yet supported.`);\n\t} catch (err) {\n\t\tthrow isTaqError(err)\n\t\t\t? err\n\t\t\t: new TaqError(\n\t\t\t\t`Something went wrong trying to parse your configuration. Please report this to the Taqueria Developers: ${err}`,\n\t\t\t);\n\t}\n}\n\n// Backwards compatibility\n// Before introducing V1, the toolkit just exported these two functions\nconst getAliasAddress = V1.getAliasAddress;\nconst getCurrentEnv = V1.getCurrentEnv;\nexport { Config, getAliasAddress, getCurrentEnv };\n\n// New exports as of V2\nexport type ConfigFileSetV2 = transform.ConfigFileSetV2;\n","export class TaqError extends Error {\n\tpublic isTaqError = true;\n}\nexport const isTaqError = (err: unknown): err is TaqError =>\n\ttypeof err === 'object' && (err as object).hasOwnProperty('isTaqError');\n","import * as Config from '@taqueria/protocol/Config';\nimport * as Environment from '@taqueria/protocol/Environment';\n\nexport const getCurrentEnv = (config: Config.t): Environment.t | undefined => {\n\tconst currentEnv = config?.environment?.default ? config.environment.default as string : 'development';\n\treturn config.environment && config.environment[currentEnv]\n\t\t? config.environment[currentEnv] as Environment.t | undefined\n\t\t: undefined;\n};\n\nexport const getAliasAddress = (config: any, alias: string): string => {\n\tconst currentEnv = getCurrentEnv(config);\n\tif (currentEnv?.aliases?.[alias]?.address) return currentEnv.aliases[alias].address;\n\talert(`Address for alias, ${alias}, is missing. Please deploy a contract with such alias`);\n\treturn '';\n};\n","// TODO: Write a comprehensive API for V2\nimport * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';\nimport * as Config from '@taqueria/protocol/ConfigFileV2';\nimport { ConfigFileSetV2 } from '@taqueria/protocol/types-config-files';\nimport { isTaqError, TaqError } from './TaqError';\n\ntype ExpandedEnv = Record<string, unknown> & ConfigEnvironmentFileV2.t & { __type: 'expandedEnv' };\nexport function getEnv(envName: string, settings: ConfigFileSetV2): ExpandedEnv {\n\tconst mainEnv = settings.config.environments?.[envName];\n\tif (mainEnv) {\n\t\treturn {\n\t\t\t...mainEnv,\n\t\t\t...settings.environments[envName],\n\t\t} as ExpandedEnv;\n\t}\n\tthrow new TaqError(`There is no environment configured called ${envName}`);\n}\n\nexport const getCurrentEnv = (settings: ConfigFileSetV2) => {\n\tif (settings.config.environmentDefault) {\n\t\treturn getEnv(settings.config.environmentDefault, settings);\n\t}\n\tthrow new TaqError(\n\t\t`No default environment has been configured. Please set the \"environmentDefault\" property in your .taq/config.json.`,\n\t);\n};\n\nexport function getContractAddress(contractName: string, env: ExpandedEnv) {\n\treturn env.contracts?.[contractName]?.address;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAAA;AAAA,EAAA;AAAA;AAAA,uBAAAC;AAAA,EAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,8BAAyC;AACzC,mBAA8B;;;ACFvB,IAAM,WAAN,cAAuB,MAAM;AAAA,EAA7B;AAAA;AACN,SAAO,aAAa;AAAA;AACrB;AACO,IAAM,aAAa,CAAC,QAC1B,OAAO,QAAQ,YAAa,IAAe,eAAe,YAAY;;;ACDhE,IAAM,gBAAgB,CAAC,WAAgD;AAH9E;AAIC,QAAM,eAAa,sCAAQ,gBAAR,mBAAqB,WAAU,OAAO,YAAY,UAAoB;AACzF,SAAO,OAAO,eAAe,OAAO,YAAY,cAC7C,OAAO,YAAY,cACnB;AACJ;AAEO,IAAM,kBAAkB,CAAC,QAAa,UAA0B;AAVvE;AAWC,QAAM,aAAa,cAAc,MAAM;AACvC,OAAI,oDAAY,YAAZ,mBAAsB,WAAtB,mBAA8B;AAAS,WAAO,WAAW,QAAQ,OAAO;AAC5E,QAAM,sBAAsB,6DAA6D;AACzF,SAAO;AACR;;;ACfA;AAAA;AAAA;AAAA,uBAAAC;AAAA,EAAA;AAAA;AAOO,SAAS,OAAO,SAAiB,UAAwC;AAPhF;AAQC,QAAM,WAAU,cAAS,OAAO,iBAAhB,mBAA+B;AAC/C,MAAI,SAAS;AACZ,WAAO;AAAA,MACN,GAAG;AAAA,MACH,GAAG,SAAS,aAAa;AAAA,IAC1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,aAAa,EAAE,GAAGA,SAAQ,CAAC,UAAU,qBAAqB,OAAO,EAAE;AAAA,QAC5E,CAAC;AAAA,MACF;AACA,YAAM,SAAoC;AAAA,QACzC,QAAQ;AAAA,QACR;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAGA,UAAM,IAAI,SAAS,yDAAyD;AAAA,EAC7E,SAAS,KAAP;AACD,UAAM,WAAW,GAAG,IACjB,MACA,IAAI;AAAA,MACL,2GAA2G;AAAA,IAC5G;AAAA,EACF;AACD;AAIA,IAAMC,mBAAqB;AAC3B,IAAMC,iBAAmB;","names":["getAliasAddress","getCurrentEnv","getCurrentEnv","getCurrentEnv","retval","getAliasAddress","getCurrentEnv"]}
|
|
1
|
+
{"version":3,"sources":["index.ts","TaqError.ts","v1.ts","v2.ts"],"sourcesContent":["import * as Config from '@taqueria/protocol/Config';\nimport * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';\nimport * as ConfigFileV2 from '@taqueria/protocol/ConfigFileV2';\nimport { isTaqError, TaqError } from './TaqError';\nexport { isTaqError, TaqError } from './TaqError';\nimport * as V1 from './v1';\nexport * as V2 from './v2';\nimport * as transform from '@taqueria/protocol/types-config-files';\n\nconst DEFAULT_ENV_VAR_PREFIX = '';\n\nfunction withEnv(env: Record<string, string | undefined>, prefix = DEFAULT_ENV_VAR_PREFIX) {\n\tconst getConfigEnvKey = () => `${prefix}TAQ_CONFIG`;\n\n\tconst decode = (value: string) => {\n\t\tconst buffer = Buffer.from(value, 'base64');\n\t\treturn buffer.toString('utf8');\n\t};\n\n\tconst getRawConfig = () => {\n\t\tconst key = getConfigEnvKey();\n\t\tconst data = env[key];\n\t\tif (!data) {\n\t\t\tthrow new TaqError(\n\t\t\t\t`Could not find config. Please ensure that the environment variable called ${key} is defined and set to the value of your config.json file using Base64 encoding.`,\n\t\t\t);\n\t\t}\n\t\ttry {\n\t\t\tconst decoded = decode(data);\n\t\t\tconst rawConfig = JSON.parse(decoded);\n\t\t\treturn rawConfig;\n\t\t} catch {\n\t\t\tthrow new TaqError(\n\t\t\t\t`Could not parse the config. Please ensure that the environment variable called ${key} is defined and set to the value of your config.json file using Base64 encoding.`,\n\t\t\t);\n\t\t}\n\t};\n\n\tconst getEnvironmentConfigKey = (environmentName: string) =>\n\t\t`${prefix}TAQ_CONFIG_LOCAL_${environmentName.toUpperCase()}`;\n\n\tconst getEnvironmentConfig = (environmentName: string) => {\n\t\tconst key = getEnvironmentConfigKey(environmentName);\n\t\tconst data = env[key];\n\t\tif (!data) {\n\t\t\treturn ConfigEnvironmentFileV2.from({});\n\t\t}\n\t\ttry {\n\t\t\tconst decoded = decode(data);\n\t\t\tconst rawConfig = JSON.parse(decoded);\n\t\t\treturn ConfigEnvironmentFileV2.from(rawConfig);\n\t\t} catch {\n\t\t\tthrow new TaqError(\n\t\t\t\t`Could not parse environment config for an environment called ${environmentName}. Please ensure that the environment variable called ${key} is defined and set to the value of your config.json file using Base64 encoding.`,\n\t\t\t);\n\t\t}\n\t};\n\n\treturn {\n\t\tgetConfigEnvKey,\n\t\tgetRawConfig,\n\t\tgetEnvironmentConfigKey,\n\t\tgetEnvironmentConfig,\n\t};\n}\n\nexport const getConfigAsV1 = (env: Record<string, string | undefined>, prefix = DEFAULT_ENV_VAR_PREFIX): Config.t => {\n\tconst { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);\n\n\tconst rawConfig = getRawConfig();\n\n\ttry {\n\t\t// If version v1, return the config object\n\t\tif (!rawConfig.version || rawConfig.version.toLowerCase() === 'v1') return Config.from(rawConfig);\n\t\t// If version v2, transform to V1 and return that\n\t\telse if (rawConfig.version.toLowerCase() === 'v2') {\n\t\t\tconst config = ConfigFileV2.from(rawConfig);\n\t\t\tconst environments = Object.keys(config.environments ?? {}).reduce(\n\t\t\t\t(retval, envName) => ({\n\t\t\t\t\t...retval,\n\t\t\t\t\t[envName]: getEnvironmentConfig(envName),\n\t\t\t\t}),\n\t\t\t\t{},\n\t\t\t);\n\n\t\t\treturn Config.create(transform.transformConfigFileV2ToConfig({\n\t\t\t\tconfig,\n\t\t\t\tenvironments,\n\t\t\t}));\n\t\t}\n\n\t\t// Other version handlers go here\n\t\tthrow new TaqError(`The version of your configuration is not yet supported.`);\n\t} catch (err) {\n\t\tthrow isTaqError(err)\n\t\t\t? err\n\t\t\t: new TaqError(\n\t\t\t\t`Something went wrong trying to parse your configuration. Please report this to the Taqueria Developers: ${err}`,\n\t\t\t);\n\t}\n};\n\nexport function getConfigV2(\n\tenv: Record<string, string | undefined>,\n\tprefix = DEFAULT_ENV_VAR_PREFIX,\n): transform.ConfigFileSetV2 {\n\tconst { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);\n\n\tconst rawConfig = getRawConfig();\n\n\ttry {\n\t\t// If version v1, return the config object\n\t\tif (!rawConfig.version || rawConfig.version.toLowerCase() === 'v1') {\n\t\t\tconst configV1 = Config.from(rawConfig);\n\t\t\treturn transform.transformConfigToConfigFileV2(configV1);\n\t\t} else if (rawConfig.version.toLowerCase() === 'v2') {\n\t\t\tconst configV2 = ConfigFileV2.from(rawConfig);\n\t\t\tconst environments = Object.keys(configV2.environments ?? {}).reduce(\n\t\t\t\t(retval, envName) => ({ ...retval, [envName]: getEnvironmentConfig(envName) }),\n\t\t\t\t{},\n\t\t\t);\n\t\t\tconst retval: transform.ConfigFileSetV2 = {\n\t\t\t\tconfig: configV2,\n\t\t\t\tenvironments,\n\t\t\t};\n\n\t\t\treturn retval;\n\t\t}\n\t\t// Other version handlers go here\n\t\t// No other versions we're aware of.\n\t\tthrow new TaqError(`The version of your configuration is not yet supported.`);\n\t} catch (err) {\n\t\tthrow isTaqError(err)\n\t\t\t? err\n\t\t\t: new TaqError(\n\t\t\t\t`Something went wrong trying to parse your configuration. Please report this to the Taqueria Developers: ${err}`,\n\t\t\t);\n\t}\n}\n\n// Backwards compatibility\n// Before introducing V1, the toolkit just exported these two functions\nconst getAliasAddress = V1.getAliasAddress;\nconst getCurrentEnv = V1.getCurrentEnv;\nexport { Config, getAliasAddress, getCurrentEnv };\n\n// New exports as of V2\nexport type ConfigFileSetV2 = transform.ConfigFileSetV2;\n","export class TaqError extends Error {\n\tpublic isTaqError = true;\n}\nexport const isTaqError = (err: unknown): err is TaqError =>\n\ttypeof err === 'object' && (err as object).hasOwnProperty('isTaqError');\n","import * as Config from '@taqueria/protocol/Config';\nimport * as Environment from '@taqueria/protocol/Environment';\n\nexport const getCurrentEnv = (config: Config.t): Environment.t | undefined => {\n\tconst currentEnv = config?.environment?.default ? config.environment.default as string : 'development';\n\treturn config.environment && config.environment[currentEnv]\n\t\t? config.environment[currentEnv] as Environment.t | undefined\n\t\t: undefined;\n};\n\nexport const getAliasAddress = (config: any, alias: string): string => {\n\tconst currentEnv = getCurrentEnv(config);\n\tif (currentEnv?.aliases?.[alias]?.address) return currentEnv.aliases[alias].address;\n\talert(`Address for alias, ${alias}, is missing. Please deploy a contract with such alias`);\n\treturn '';\n};\n","// TODO: Write a comprehensive API for V2\nimport * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';\nimport * as Config from '@taqueria/protocol/ConfigFileV2';\nimport { ConfigFileSetV2 } from '@taqueria/protocol/types-config-files';\nimport { isTaqError, TaqError } from './TaqError';\n\ntype ExpandedEnv = Record<string, unknown> & ConfigEnvironmentFileV2.t & { __type: 'expandedEnv' };\nexport function getEnv(envName: string, settings: ConfigFileSetV2): ExpandedEnv {\n\tconst mainEnv = settings.config.environments?.[envName];\n\tif (mainEnv) {\n\t\treturn {\n\t\t\t...mainEnv,\n\t\t\t...settings.environments[envName],\n\t\t} as ExpandedEnv;\n\t}\n\tthrow new TaqError(`There is no environment configured called ${envName}`);\n}\n\nexport const getCurrentEnv = (settings: ConfigFileSetV2) => {\n\tif (settings.config.environmentDefault) {\n\t\treturn getEnv(settings.config.environmentDefault, settings);\n\t}\n\tthrow new TaqError(\n\t\t`No default environment has been configured. Please set the \"environmentDefault\" property in your .taq/config.json.`,\n\t);\n};\n\nexport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SAAoC;AAAA,QACzC,QAAQ;AAAA,QACR;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAGA,UAAM,IAAI,SAAS,yDAAyD;AAAA,EAC7E,SAAS,KAAP;AACD,UAAM,WAAW,GAAG,IACjB,MACA,IAAI;AAAA,MACL,2GAA2G;AAAA,IAC5G;AAAA,EACF;AACD;AAIA,IAAMC,mBAAqB;AAC3B,IAAMC,iBAAmB;","names":["getAliasAddress","getCurrentEnv","getCurrentEnv","getCurrentEnv","retval","getAliasAddress","getCurrentEnv"]}
|
package/index.ts
CHANGED
|
@@ -12,6 +12,11 @@ const DEFAULT_ENV_VAR_PREFIX = '';
|
|
|
12
12
|
function withEnv(env: Record<string, string | undefined>, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
13
13
|
const getConfigEnvKey = () => `${prefix}TAQ_CONFIG`;
|
|
14
14
|
|
|
15
|
+
const decode = (value: string) => {
|
|
16
|
+
const buffer = Buffer.from(value, 'base64');
|
|
17
|
+
return buffer.toString('utf8');
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
const getRawConfig = () => {
|
|
16
21
|
const key = getConfigEnvKey();
|
|
17
22
|
const data = env[key];
|
|
@@ -21,7 +26,7 @@ function withEnv(env: Record<string, string | undefined>, prefix = DEFAULT_ENV_V
|
|
|
21
26
|
);
|
|
22
27
|
}
|
|
23
28
|
try {
|
|
24
|
-
const decoded =
|
|
29
|
+
const decoded = decode(data);
|
|
25
30
|
const rawConfig = JSON.parse(decoded);
|
|
26
31
|
return rawConfig;
|
|
27
32
|
} catch {
|
|
@@ -41,7 +46,7 @@ function withEnv(env: Record<string, string | undefined>, prefix = DEFAULT_ENV_V
|
|
|
41
46
|
return ConfigEnvironmentFileV2.from({});
|
|
42
47
|
}
|
|
43
48
|
try {
|
|
44
|
-
const decoded =
|
|
49
|
+
const decoded = decode(data);
|
|
45
50
|
const rawConfig = JSON.parse(decoded);
|
|
46
51
|
return ConfigEnvironmentFileV2.from(rawConfig);
|
|
47
52
|
} catch {
|
package/lib/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This directory contains packages that are NodeJS specific
|
package/lib/env.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare class CustomErr extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class TaqNotFoundError extends CustomErr {
|
|
4
|
+
isCustomErr: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function isCustomError(err: unknown): err is Error;
|
|
7
|
+
export declare function checkTaqProject(dir: string): Promise<string>;
|
|
8
|
+
export declare class TaqConfigError extends CustomErr {
|
|
9
|
+
}
|
|
10
|
+
export declare function getConfig(taqDir: string, prefix: string): Promise<{}>;
|
|
11
|
+
export declare function encode(value: string): string;
|
|
12
|
+
export declare function getEncodedConfig(taqDir: string, prefix: string): Promise<{
|
|
13
|
+
[k: string]: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function getEnv(env: typeof process.env, taqDir: string, prefix?: string): Promise<{
|
|
16
|
+
[x: string]: string | undefined;
|
|
17
|
+
TZ?: string | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
export {};
|
package/lib/env.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
class CustomErr extends Error {}
|
|
5
|
+
|
|
6
|
+
export class TaqNotFoundError extends CustomErr {
|
|
7
|
+
public isCustomErr = true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function isCustomError(err: unknown): err is Error {
|
|
11
|
+
return typeof err === 'object' && (err as object).hasOwnProperty('isCustomErr');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function checkTaqProject(dir: string) {
|
|
15
|
+
try {
|
|
16
|
+
const searchPath = path.join(dir, '.taq');
|
|
17
|
+
await stat(searchPath);
|
|
18
|
+
return searchPath;
|
|
19
|
+
} catch {
|
|
20
|
+
throw new TaqNotFoundError(`${dir} is not a valid Taqueria project.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getEnvName(filename: string, prefix = '') {
|
|
25
|
+
return `${prefix}TAQ_${filename}`
|
|
26
|
+
.replace('.json', '')
|
|
27
|
+
.replace(/\./mg, '_')
|
|
28
|
+
.replace(/\-/mg, '_')
|
|
29
|
+
.toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class TaqConfigError extends CustomErr {}
|
|
33
|
+
export async function getConfig(taqDir: string, prefix: string) {
|
|
34
|
+
try {
|
|
35
|
+
const files = await readdir(taqDir);
|
|
36
|
+
return files.reduce(
|
|
37
|
+
async (retval, file) => {
|
|
38
|
+
if (!file.endsWith('.json')) return (await retval);
|
|
39
|
+
return {
|
|
40
|
+
...(await retval),
|
|
41
|
+
[getEnvName(file, prefix)]: await readFile(path.join(taqDir, file), 'utf-8'),
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
Promise.resolve({}),
|
|
45
|
+
);
|
|
46
|
+
} catch {
|
|
47
|
+
throw new TaqConfigError(
|
|
48
|
+
`There was a problem reading the config files in ${taqDir}. Please check file permissions are try again.`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function encode(value: string) {
|
|
54
|
+
const buffer = Buffer.from(value, 'utf8');
|
|
55
|
+
return buffer.toString('base64');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function getEncodedConfig(taqDir: string, prefix: string) {
|
|
59
|
+
const config = await getConfig(taqDir, prefix);
|
|
60
|
+
return Object.fromEntries(
|
|
61
|
+
Object.entries(config).map(
|
|
62
|
+
([k, v]) => [k, encode(v as string)],
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function getEnv(env: typeof process.env, taqDir: string, prefix: string = '') {
|
|
68
|
+
const realTaqDir = await checkTaqProject(taqDir);
|
|
69
|
+
return {
|
|
70
|
+
...env,
|
|
71
|
+
...await getEncodedConfig(realTaqDir, prefix),
|
|
72
|
+
};
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taqueria/toolkit",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "A TypeScript library for NodeJS to work with Taqueria projects",
|
|
5
5
|
"source": "./index.ts",
|
|
6
|
+
"main": "./index.js",
|
|
6
7
|
"bin": {
|
|
7
8
|
"withTaq": "./bin/run.js"
|
|
8
9
|
},
|
|
@@ -36,14 +37,16 @@
|
|
|
36
37
|
"typescript": "^4.7.2"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@taqueria/protocol": "^0.28.
|
|
40
|
+
"@taqueria/protocol": "^0.28.1",
|
|
40
41
|
"cross-spawn": "^7.0.3",
|
|
41
42
|
"yargs": "^17.6.2"
|
|
42
43
|
},
|
|
43
44
|
"tsup": [
|
|
44
45
|
{
|
|
45
46
|
"entry": [
|
|
46
|
-
"index.ts"
|
|
47
|
+
"index.ts",
|
|
48
|
+
"v1.ts",
|
|
49
|
+
"v2.ts"
|
|
47
50
|
],
|
|
48
51
|
"sourcemap": true,
|
|
49
52
|
"target": "es2018",
|
|
@@ -66,5 +69,12 @@
|
|
|
66
69
|
"skipNodeModulesBundle": true,
|
|
67
70
|
"platform": "node"
|
|
68
71
|
}
|
|
69
|
-
]
|
|
72
|
+
],
|
|
73
|
+
"exports": {
|
|
74
|
+
"./lib/*": "./lib/*",
|
|
75
|
+
".*": "./*",
|
|
76
|
+
".": "./index.js",
|
|
77
|
+
"./v1": "./v1.js",
|
|
78
|
+
"./v2": "./v2.js"
|
|
79
|
+
}
|
|
70
80
|
}
|
package/v1.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import * as Config from '@taqueria/protocol/Config';
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import * as _taqueria_protocol_Environment from '@taqueria/protocol/Environment';
|
|
3
|
+
|
|
4
|
+
declare const getCurrentEnv: (config: Config.t) => _taqueria_protocol_Environment.t | undefined;
|
|
5
|
+
declare const getAliasAddress: (config: any, alias: string) => string;
|
|
6
|
+
|
|
7
|
+
export { getAliasAddress, getCurrentEnv };
|
package/v1.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// v1.ts
|
|
21
|
+
var v1_exports = {};
|
|
22
|
+
__export(v1_exports, {
|
|
23
|
+
getAliasAddress: () => getAliasAddress,
|
|
24
|
+
getCurrentEnv: () => getCurrentEnv
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(v1_exports);
|
|
27
|
+
var getCurrentEnv = (config) => {
|
|
28
|
+
var _a;
|
|
29
|
+
const currentEnv = ((_a = config == null ? void 0 : config.environment) == null ? void 0 : _a.default) ? config.environment.default : "development";
|
|
30
|
+
return config.environment && config.environment[currentEnv] ? config.environment[currentEnv] : void 0;
|
|
31
|
+
};
|
|
32
|
+
var getAliasAddress = (config, alias) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const currentEnv = getCurrentEnv(config);
|
|
35
|
+
if ((_b = (_a = currentEnv == null ? void 0 : currentEnv.aliases) == null ? void 0 : _a[alias]) == null ? void 0 : _b.address)
|
|
36
|
+
return currentEnv.aliases[alias].address;
|
|
37
|
+
alert(`Address for alias, ${alias}, is missing. Please deploy a contract with such alias`);
|
|
38
|
+
return "";
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=v1.js.map
|
package/v1.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["v1.ts"],"sourcesContent":["import * as Config from '@taqueria/protocol/Config';\nimport * as Environment from '@taqueria/protocol/Environment';\n\nexport const getCurrentEnv = (config: Config.t): Environment.t | undefined => {\n\tconst currentEnv = config?.environment?.default ? config.environment.default as string : 'development';\n\treturn config.environment && config.environment[currentEnv]\n\t\t? config.environment[currentEnv] as Environment.t | undefined\n\t\t: undefined;\n};\n\nexport const getAliasAddress = (config: any, alias: string): string => {\n\tconst currentEnv = getCurrentEnv(config);\n\tif (currentEnv?.aliases?.[alias]?.address) return currentEnv.aliases[alias].address;\n\talert(`Address for alias, ${alias}, is missing. Please deploy a contract with such alias`);\n\treturn '';\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAM,gBAAgB,CAAC,WAAgD;AAH9E;AAIC,QAAM,eAAa,sCAAQ,gBAAR,mBAAqB,WAAU,OAAO,YAAY,UAAoB;AACzF,SAAO,OAAO,eAAe,OAAO,YAAY,cAC7C,OAAO,YAAY,cACnB;AACJ;AAEO,IAAM,kBAAkB,CAAC,QAAa,UAA0B;AAVvE;AAWC,QAAM,aAAa,cAAc,MAAM;AACvC,OAAI,oDAAY,YAAZ,mBAAsB,WAAtB,mBAA8B;AAAS,WAAO,WAAW,QAAQ,OAAO;AAC5E,QAAM,sBAAsB,6DAA6D;AACzF,SAAO;AACR;","names":[]}
|
package/v2-e3846710.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';
|
|
2
|
+
import { ConfigFileSetV2 } from '@taqueria/protocol/types-config-files';
|
|
3
|
+
|
|
4
|
+
type ExpandedEnv = Record<string, unknown> & ConfigEnvironmentFileV2.t & {
|
|
5
|
+
__type: 'expandedEnv';
|
|
6
|
+
};
|
|
7
|
+
declare function getEnv(envName: string, settings: ConfigFileSetV2): ExpandedEnv;
|
|
8
|
+
declare const getCurrentEnv: (settings: ConfigFileSetV2) => ExpandedEnv;
|
|
9
|
+
declare function getContractAddress(contractName: string, env: ExpandedEnv): string | undefined;
|
|
10
|
+
|
|
11
|
+
declare const v2_getContractAddress: typeof getContractAddress;
|
|
12
|
+
declare const v2_getCurrentEnv: typeof getCurrentEnv;
|
|
13
|
+
declare const v2_getEnv: typeof getEnv;
|
|
14
|
+
declare namespace v2 {
|
|
15
|
+
export {
|
|
16
|
+
v2_getContractAddress as getContractAddress,
|
|
17
|
+
v2_getCurrentEnv as getCurrentEnv,
|
|
18
|
+
v2_getEnv as getEnv,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { getCurrentEnv as a, getContractAddress as b, getEnv as g, v2 as v };
|
package/v2.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
__type: 'expandedEnv';
|
|
5
|
-
};
|
|
6
|
-
export declare function getEnv(envName: string, settings: ConfigFileSetV2): ExpandedEnv;
|
|
7
|
-
export declare const getCurrentEnv: (settings: ConfigFileSetV2) => ExpandedEnv;
|
|
8
|
-
export declare function getContractAddress(contractName: string, env: ExpandedEnv): string | undefined;
|
|
9
|
-
export {};
|
|
1
|
+
import '@taqueria/protocol/ConfigEnvironmentFileV2';
|
|
2
|
+
import '@taqueria/protocol/types-config-files';
|
|
3
|
+
export { b as getContractAddress, a as getCurrentEnv, g as getEnv } from './v2-e3846710.js';
|
package/v2.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// v2.ts
|
|
21
|
+
var v2_exports = {};
|
|
22
|
+
__export(v2_exports, {
|
|
23
|
+
getContractAddress: () => getContractAddress,
|
|
24
|
+
getCurrentEnv: () => getCurrentEnv,
|
|
25
|
+
getEnv: () => getEnv
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(v2_exports);
|
|
28
|
+
|
|
29
|
+
// TaqError.ts
|
|
30
|
+
var TaqError = class extends Error {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
this.isTaqError = true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// v2.ts
|
|
38
|
+
function getEnv(envName, settings) {
|
|
39
|
+
var _a;
|
|
40
|
+
const mainEnv = (_a = settings.config.environments) == null ? void 0 : _a[envName];
|
|
41
|
+
if (mainEnv) {
|
|
42
|
+
return {
|
|
43
|
+
...mainEnv,
|
|
44
|
+
...settings.environments[envName]
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
throw new TaqError(`There is no environment configured called ${envName}`);
|
|
48
|
+
}
|
|
49
|
+
var getCurrentEnv = (settings) => {
|
|
50
|
+
if (settings.config.environmentDefault) {
|
|
51
|
+
return getEnv(settings.config.environmentDefault, settings);
|
|
52
|
+
}
|
|
53
|
+
throw new TaqError(
|
|
54
|
+
`No default environment has been configured. Please set the "environmentDefault" property in your .taq/config.json.`
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
function getContractAddress(contractName, env) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
return (_b = (_a = env.contracts) == null ? void 0 : _a[contractName]) == null ? void 0 : _b.address;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=v2.js.map
|
package/v2.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["v2.ts","TaqError.ts"],"sourcesContent":["// TODO: Write a comprehensive API for V2\nimport * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';\nimport * as Config from '@taqueria/protocol/ConfigFileV2';\nimport { ConfigFileSetV2 } from '@taqueria/protocol/types-config-files';\nimport { isTaqError, TaqError } from './TaqError';\n\ntype ExpandedEnv = Record<string, unknown> & ConfigEnvironmentFileV2.t & { __type: 'expandedEnv' };\nexport function getEnv(envName: string, settings: ConfigFileSetV2): ExpandedEnv {\n\tconst mainEnv = settings.config.environments?.[envName];\n\tif (mainEnv) {\n\t\treturn {\n\t\t\t...mainEnv,\n\t\t\t...settings.environments[envName],\n\t\t} as ExpandedEnv;\n\t}\n\tthrow new TaqError(`There is no environment configured called ${envName}`);\n}\n\nexport const getCurrentEnv = (settings: ConfigFileSetV2) => {\n\tif (settings.config.environmentDefault) {\n\t\treturn getEnv(settings.config.environmentDefault, settings);\n\t}\n\tthrow new TaqError(\n\t\t`No default environment has been configured. Please set the \"environmentDefault\" property in your .taq/config.json.`,\n\t);\n};\n\nexport function getContractAddress(contractName: string, env: ExpandedEnv) {\n\treturn env.contracts?.[contractName]?.address;\n}\n","export class TaqError extends Error {\n\tpublic isTaqError = true;\n}\nexport const isTaqError = (err: unknown): err is TaqError =>\n\ttypeof err === 'object' && (err as object).hasOwnProperty('isTaqError');\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAA7B;AAAA;AACN,SAAO,aAAa;AAAA;AACrB;;;ADKO,SAAS,OAAO,SAAiB,UAAwC;AAPhF;AAQC,QAAM,WAAU,cAAS,OAAO,iBAAhB,mBAA+B;AAC/C,MAAI,SAAS;AACZ,WAAO;AAAA,MACN,GAAG;AAAA,MACH,GAAG,SAAS,aAAa;AAAA,IAC1B;AAAA,EACD;AACA,QAAM,IAAI,SAAS,6CAA6C,SAAS;AAC1E;AAEO,IAAM,gBAAgB,CAAC,aAA8B;AAC3D,MAAI,SAAS,OAAO,oBAAoB;AACvC,WAAO,OAAO,SAAS,OAAO,oBAAoB,QAAQ;AAAA,EAC3D;AACA,QAAM,IAAI;AAAA,IACT;AAAA,EACD;AACD;AAEO,SAAS,mBAAmB,cAAsB,KAAkB;AA3B3E;AA4BC,UAAO,eAAI,cAAJ,mBAAgB,kBAAhB,mBAA+B;AACvC;","names":[]}
|