@taqueria/toolkit 0.28.1-beta → 0.28.2

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 CHANGED
@@ -71,11 +71,15 @@ async function getConfig(taqDir, prefix) {
71
71
  );
72
72
  }
73
73
  }
74
+ function encode(value) {
75
+ const buffer = Buffer.from(value, "utf8");
76
+ return buffer.toString("base64");
77
+ }
74
78
  async function getEncodedConfig(taqDir, prefix) {
75
79
  const config = await getConfig(taqDir, prefix);
76
80
  return Object.fromEntries(
77
81
  Object.entries(config).map(
78
- ([k, v]) => [k, btoa(v)]
82
+ ([k, v]) => [k, encode(v)]
79
83
  )
80
84
  );
81
85
  }
package/bin/run.js.map CHANGED
@@ -1 +1 @@
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 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, btoa(v as string)],\n\t\t),\n\t);\n}\n\nexport async function getEnv(env: typeof process.env, taqDir: string, prefix: string = '') {\n\treturn Object.entries(getEncodedConfig(taqDir, prefix)).reduce(\n\t\t(retval, [k, v]) => ({ ...retval, [k]: v }),\n\t\tenv,\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;A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Q,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"]}
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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HANGED
@@ -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
- import * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';
4
+ export { v as V2 } from './v2-e3846710.js';
5
5
  import * as transform from '@taqueria/protocol/types-config-files';
6
- import { ConfigFileSetV2 as ConfigFileSetV2$1 } from '@taqueria/protocol/types-config-files';
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, v2 as V2, getAliasAddress, getConfigAsV1, getConfigV2, getCurrentEnv, isTaqError };
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 = atob(data);
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 = atob(data);
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;AAA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T,YAAyB,CAAC,CAAC,EAAE;AAAA,QAC7D,CAACC,SAAQ,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 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,IAC1B;AAAA,EACD;AACA,QAAM,IAAI,SAAS,6CAA6C,SAAS;AAC1E;AAEO,IAAMC,iBAAgB,CAAC,aAA8B;AAC3D,MAAI,SAAS,OAAO,oBAAoB;AACvC,WAAO,OAAO,SAAS,OAAO,oBAAoB,QAAQ;AAAA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AAE;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"]}
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 = atob(data);
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 = atob(data);
49
+ const decoded = decode(data);
45
50
  const rawConfig = JSON.parse(decoded);
46
51
  return ConfigEnvironmentFileV2.from(rawConfig);
47
52
  } catch {
package/lib/env.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  declare class CustomErr extends Error {
3
2
  }
4
3
  export declare class TaqNotFoundError extends CustomErr {
@@ -9,8 +8,12 @@ export declare function checkTaqProject(dir: string): Promise<string>;
9
8
  export declare class TaqConfigError extends CustomErr {
10
9
  }
11
10
  export declare function getConfig(taqDir: string, prefix: string): Promise<{}>;
11
+ export declare function encode(value: string): string;
12
12
  export declare function getEncodedConfig(taqDir: string, prefix: string): Promise<{
13
13
  [k: string]: string;
14
14
  }>;
15
- export declare function getEnv(env: typeof process.env, taqDir: string, prefix?: string): Promise<NodeJS.ProcessEnv>;
15
+ export declare function getEnv(env: typeof process.env, taqDir: string, prefix?: string): Promise<{
16
+ [x: string]: string | undefined;
17
+ TZ?: string | undefined;
18
+ }>;
16
19
  export {};
package/lib/env.ts CHANGED
@@ -50,18 +50,24 @@ export async function getConfig(taqDir: string, prefix: string) {
50
50
  }
51
51
  }
52
52
 
53
+ export function encode(value: string) {
54
+ const buffer = Buffer.from(value, 'utf8');
55
+ return buffer.toString('base64');
56
+ }
57
+
53
58
  export async function getEncodedConfig(taqDir: string, prefix: string) {
54
59
  const config = await getConfig(taqDir, prefix);
55
60
  return Object.fromEntries(
56
61
  Object.entries(config).map(
57
- ([k, v]) => [k, btoa(v as string)],
62
+ ([k, v]) => [k, encode(v as string)],
58
63
  ),
59
64
  );
60
65
  }
61
66
 
62
67
  export async function getEnv(env: typeof process.env, taqDir: string, prefix: string = '') {
63
- return Object.entries(getEncodedConfig(taqDir, prefix)).reduce(
64
- (retval, [k, v]) => ({ ...retval, [k]: v }),
65
- env,
66
- );
68
+ const realTaqDir = await checkTaqProject(taqDir);
69
+ return {
70
+ ...env,
71
+ ...await getEncodedConfig(realTaqDir, prefix),
72
+ };
67
73
  }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@taqueria/toolkit",
3
- "version": "0.28.1-beta",
3
+ "version": "0.28.2",
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.0",
40
+ "@taqueria/protocol": "^0.28.2",
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",
@@ -68,6 +71,10 @@
68
71
  }
69
72
  ],
70
73
  "exports": {
71
- "./lib/*": "./lib/*"
74
+ "./lib/*": "./lib/*",
75
+ ".*": "./*",
76
+ ".": "./index.js",
77
+ "./v1": "./v1.js",
78
+ "./v2": "./v2.js"
72
79
  }
73
80
  }
package/v1.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import * as Config from '@taqueria/protocol/Config';
2
- import * as Environment from '@taqueria/protocol/Environment';
3
- export declare const getCurrentEnv: (config: Config.t) => Environment.t | undefined;
4
- export declare const getAliasAddress: (config: any, alias: string) => string;
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":[]}
@@ -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 * as ConfigEnvironmentFileV2 from '@taqueria/protocol/ConfigEnvironmentFileV2';
2
- import { ConfigFileSetV2 } from '@taqueria/protocol/types-config-files';
3
- type ExpandedEnv = Record<string, unknown> & ConfigEnvironmentFileV2.t & {
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":[]}
package/env.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /// <reference types="node" />
2
- declare class CustomErr extends Error {
3
- }
4
- export declare class TaqNotFoundError extends CustomErr {
5
- isCustomErr: boolean;
6
- }
7
- export declare function isCustomError(err: unknown): err is Error;
8
- export declare function checkTaqProject(dir: string): Promise<string>;
9
- export declare class TaqConfigError extends CustomErr {
10
- }
11
- export declare function getConfig(taqDir: string, prefix: string): Promise<{}>;
12
- export declare function getEncodedConfig(taqDir: string, prefix: string): Promise<{
13
- [k: string]: string;
14
- }>;
15
- export declare function getEnv(taqDir: string, prefix: string, env: typeof process.env): Promise<NodeJS.ProcessEnv>;
16
- export {};