@taqueria/toolkit 0.42.5 → 0.42.7
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/index.js +15 -2
- package/index.js.map +1 -1
- package/index.ts +16 -2
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -102,6 +102,19 @@ function getContractAddress(contractName, env) {
|
|
|
102
102
|
// index.ts
|
|
103
103
|
var transform = __toESM(require("@taqueria/protocol/types-config-files"));
|
|
104
104
|
var DEFAULT_ENV_VAR_PREFIX = "";
|
|
105
|
+
function withFixedEnv(env) {
|
|
106
|
+
return Object.entries(env).reduce(
|
|
107
|
+
(acc, [key, value]) => {
|
|
108
|
+
if (key.startsWith("VITE_")) {
|
|
109
|
+
const newKey = key.replace("VITE_", "");
|
|
110
|
+
acc[newKey] = value;
|
|
111
|
+
}
|
|
112
|
+
acc[key] = value;
|
|
113
|
+
return acc;
|
|
114
|
+
},
|
|
115
|
+
{}
|
|
116
|
+
);
|
|
117
|
+
}
|
|
105
118
|
function withEnv(env, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
106
119
|
const getConfigEnvKey = () => `${prefix}TAQ_CONFIG`;
|
|
107
120
|
const decode = (value) => {
|
|
@@ -152,7 +165,7 @@ function withEnv(env, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
|
152
165
|
}
|
|
153
166
|
var getConfigAsV1 = (env, prefix = DEFAULT_ENV_VAR_PREFIX) => {
|
|
154
167
|
var _a;
|
|
155
|
-
const { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);
|
|
168
|
+
const { getRawConfig, getEnvironmentConfig } = withEnv(withFixedEnv(env), prefix);
|
|
156
169
|
const rawConfig = getRawConfig();
|
|
157
170
|
try {
|
|
158
171
|
if (!rawConfig.version || rawConfig.version.toLowerCase() === "v1")
|
|
@@ -180,7 +193,7 @@ var getConfigAsV1 = (env, prefix = DEFAULT_ENV_VAR_PREFIX) => {
|
|
|
180
193
|
};
|
|
181
194
|
function getConfigV2(env, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
182
195
|
var _a;
|
|
183
|
-
const { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);
|
|
196
|
+
const { getRawConfig, getEnvironmentConfig } = withEnv(withFixedEnv(env), prefix);
|
|
184
197
|
const rawConfig = getRawConfig();
|
|
185
198
|
try {
|
|
186
199
|
if (!rawConfig.version || rawConfig.version.toLowerCase() === "v1") {
|
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 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;A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AQ;AAAA,QACR;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAGA,UAAM,IAAI,SAAS,yDAAyD;AAAA,EAC7E,SAAS,KAAK;AACb,UAAM,WAAW,GAAG,IACjB,MACA,IAAI;AAAA,MACL,2GAA2G,GAAG;AAAA,IAC/G;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 withFixedEnv(env: Record<string, string | undefined>) {\n\treturn Object.entries(env).reduce(\n\t\t(acc, [key, value]) => {\n\t\t\tif (key.startsWith('VITE_')) {\n\t\t\t\tconst newKey = key.replace('VITE_', '');\n\t\t\t\tacc[newKey] = value;\n\t\t\t}\n\t\t\tacc[key] = value;\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, string | undefined>,\n\t);\n}\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(withFixedEnv(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(withFixedEnv(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,UAAU,IACvD,OAAO,YAAY,UAAU,IAC7B;AACJ;AAEO,IAAM,kBAAkB,CAAC,QAAa,UAA0B;AAVvE;AAWC,QAAM,aAAa,cAAc,MAAM;AACvC,OAAI,oDAAY,YAAZ,mBAAsB,WAAtB,mBAA8B;AAAS,WAAO,WAAW,QAAQ,KAAK,EAAE;AAC5E,QAAM,sBAAsB,KAAK,wDAAwD;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,OAAO;AAAA,IACjC;AAAA,EACD;AACA,QAAM,IAAI,S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AG;AAAA,IAC/G;AAAA,EACF;AACD;AAEO,SAAS,YACf,KACA,SAAS,wBACmB;AAvH7B;AAwHC,QAAM,EAAE,cAAc,qBAAqB,IAAI,QAAQ,aAAa,GAAG,GAAG,MAAM;AAEhF,QAAM,YAAY,aAAa;AAE/B,MAAI;AAEH,QAAI,CAAC,UAAU,WAAW,UAAU,QAAQ,YAAY,MAAM,MAAM;AACnE,YAAM,WAAkB,YAAK,SAAS;AACtC,aAAiB,wCAA8B,QAAQ;AAAA,IACxD,WAAW,UAAU,QAAQ,YAAY,MAAM,MAAM;AACpD,YAAM,WAAwB,kBAAK,SAAS;AAC5C,YAAM,eAAe,OAAO,MAAK,cAAS,iBAAT,YAAyB,CAAC,CAAC,EAAE;AAAA,QAC7D,CAACC,SAAQ,aAAa,EAAE,GAAGA,SAAQ,CAAC,OAAO,GAAG,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,KAAK;AACb,UAAM,WAAW,GAAG,IACjB,MACA,IAAI;AAAA,MACL,2GAA2G,GAAG;AAAA,IAC/G;AAAA,EACF;AACD;AAIA,IAAMC,mBAAqB;AAC3B,IAAMC,iBAAmB;","names":["getAliasAddress","getCurrentEnv","getCurrentEnv","getCurrentEnv","retval","getAliasAddress","getCurrentEnv"]}
|
package/index.ts
CHANGED
|
@@ -9,6 +9,20 @@ import * as transform from '@taqueria/protocol/types-config-files';
|
|
|
9
9
|
|
|
10
10
|
const DEFAULT_ENV_VAR_PREFIX = '';
|
|
11
11
|
|
|
12
|
+
function withFixedEnv(env: Record<string, string | undefined>) {
|
|
13
|
+
return Object.entries(env).reduce(
|
|
14
|
+
(acc, [key, value]) => {
|
|
15
|
+
if (key.startsWith('VITE_')) {
|
|
16
|
+
const newKey = key.replace('VITE_', '');
|
|
17
|
+
acc[newKey] = value;
|
|
18
|
+
}
|
|
19
|
+
acc[key] = value;
|
|
20
|
+
return acc;
|
|
21
|
+
},
|
|
22
|
+
{} as Record<string, string | undefined>,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
function withEnv(env: Record<string, string | undefined>, prefix = DEFAULT_ENV_VAR_PREFIX) {
|
|
13
27
|
const getConfigEnvKey = () => `${prefix}TAQ_CONFIG`;
|
|
14
28
|
|
|
@@ -65,7 +79,7 @@ function withEnv(env: Record<string, string | undefined>, prefix = DEFAULT_ENV_V
|
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
export const getConfigAsV1 = (env: Record<string, string | undefined>, prefix = DEFAULT_ENV_VAR_PREFIX): Config.t => {
|
|
68
|
-
const { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);
|
|
82
|
+
const { getRawConfig, getEnvironmentConfig } = withEnv(withFixedEnv(env), prefix);
|
|
69
83
|
|
|
70
84
|
const rawConfig = getRawConfig();
|
|
71
85
|
|
|
@@ -104,7 +118,7 @@ export function getConfigV2(
|
|
|
104
118
|
env: Record<string, string | undefined>,
|
|
105
119
|
prefix = DEFAULT_ENV_VAR_PREFIX,
|
|
106
120
|
): transform.ConfigFileSetV2 {
|
|
107
|
-
const { getRawConfig, getEnvironmentConfig } = withEnv(env, prefix);
|
|
121
|
+
const { getRawConfig, getEnvironmentConfig } = withEnv(withFixedEnv(env), prefix);
|
|
108
122
|
|
|
109
123
|
const rawConfig = getRawConfig();
|
|
110
124
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taqueria/toolkit",
|
|
3
|
-
"version": "0.42.
|
|
3
|
+
"version": "0.42.7",
|
|
4
4
|
"description": "A TypeScript library for NodeJS to work with Taqueria projects",
|
|
5
5
|
"source": "./index.ts",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typescript": "^5.2.2"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@taqueria/protocol": "^0.42.
|
|
40
|
+
"@taqueria/protocol": "^0.42.7",
|
|
41
41
|
"cross-spawn": "^7.0.3",
|
|
42
42
|
"yargs": "^17.7.2"
|
|
43
43
|
},
|