Added isKnownEnv

This commit is contained in:
Aleksandr Kraiz
2023-02-20 15:01:47 +04:00
parent 67fe598635
commit e8934b1698
5 changed files with 16 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.17.14",
"version": "0.17.15",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -28,7 +28,9 @@ export const pureEnvPayloadSchema = z.object({
),
});
export const knownEnvs = ['production', 'staging', 'testing'] as const;
export const pureEnvSchema = z.record(
z.enum(['production', 'staging', 'testing']).or(z.string()),
z.enum(knownEnvs).or(z.string()),
pureEnvPayloadSchema,
);

View File

@@ -2,6 +2,7 @@ import type BigNumber from 'bignumber.js';
import type exchanges from './constants/exchanges';
import type subOrderStatuses from './constants/subOrderStatuses';
import type positionStatuses from './constants/positionStatuses';
import type { knownEnvs } from './config/schemas';
export type DeepPartial<T> = T extends object ? {
[P in keyof T]?: DeepPartial<T[P]>;
@@ -284,4 +285,4 @@ export type VerboseOrionUnitConfig = {
}
}
export type KnownEnv = 'testing' | 'staging' | 'production';
export type KnownEnv = typeof knownEnvs[number];

View File

@@ -4,7 +4,6 @@ export { default as calculateNetworkFeeInFeeAsset } from './calculateNetworkFeeI
export { default as calculateOrionFeeInFeeAsset } from './calculateOrionFeeInFeeAsset';
export { default as checkIsToken } from './checkIsToken';
export { default as generateSecret } from './generateSecret';
export { default as isValidChainId } from './isValidChainId';
export { default as denormalizeNumber } from './denormalizeNumber';
export { default as normalizeNumber } from './normalizeNumber';
export { default as isNetworkCodeInEnvironment } from './isNetworkCodeInEnvironment';
@@ -14,6 +13,8 @@ export { default as toLowerCase } from './toLowerCase';
export { default as isUppercasedNetworkCode } from './isUppercasedNetworkCode';
export { default as getNativeCryptocurrency } from './getNativeCryptocurrency';
export { default as isValidChainId } from './isValidChainId';
export { default as isKnownEnv } from './isKnownEnv';
// export { default as HttpError } from './httpError';
export * from './typeHelpers';

8
src/utils/isKnownEnv.ts Normal file
View File

@@ -0,0 +1,8 @@
import { knownEnvs } from '../config/schemas';
import type { KnownEnv, } from '../types';
const isKnownEnv = (env: string): env is KnownEnv => {
return knownEnvs.some((knownEnv) => knownEnv === env);
}
export default isKnownEnv;