fix: allow v02 gateway protocol environment
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
export const ENVIRONMENT_DEV = "dev";
|
||||
export const ENVIRONMENT_V02 = "v02";
|
||||
export const PROTOCOL_ENVIRONMENTS = Object.freeze([ENVIRONMENT_DEV, ENVIRONMENT_V02]);
|
||||
export const DEV_ENDPOINT = "http://74.48.78.17:16667";
|
||||
export const DEV_FRONTEND_ENDPOINT = "http://74.48.78.17:16666";
|
||||
export const JSON_RPC_VERSION = "2.0";
|
||||
@@ -307,6 +309,10 @@ export function isFrozenServiceId(serviceId) {
|
||||
return SERVICE_IDS.includes(serviceId);
|
||||
}
|
||||
|
||||
export function isProtocolEnvironment(environment) {
|
||||
return PROTOCOL_ENVIRONMENTS.includes(environment);
|
||||
}
|
||||
|
||||
export function isProtocolId(value) {
|
||||
return typeof value === "string" && protocolIdPattern.test(value);
|
||||
}
|
||||
@@ -321,7 +327,7 @@ export function validateMeta(meta) {
|
||||
if (!isFrozenServiceId(meta.serviceId)) {
|
||||
throw new Error(`unknown serviceId ${JSON.stringify(meta.serviceId)}`);
|
||||
}
|
||||
if (meta.environment !== ENVIRONMENT_DEV) {
|
||||
if (!isProtocolEnvironment(meta.environment)) {
|
||||
throw new Error(`unsupported environment ${JSON.stringify(meta.environment)}`);
|
||||
}
|
||||
}
|
||||
@@ -445,8 +451,8 @@ function assertProtocolField(kind, field, value) {
|
||||
if (timestampFieldNames.has(field) && Number.isNaN(Date.parse(value))) {
|
||||
throw new Error(`${kind}.${field} must be an RFC 3339 timestamp`);
|
||||
}
|
||||
if (field === "environment" && value !== ENVIRONMENT_DEV) {
|
||||
throw new Error(`${kind}.environment must be ${ENVIRONMENT_DEV}`);
|
||||
if (field === "environment" && !isProtocolEnvironment(value)) {
|
||||
throw new Error(`${kind}.environment must be one of ${PROTOCOL_ENVIRONMENTS.join(", ")}`);
|
||||
}
|
||||
if (field === "serviceId" && !isFrozenServiceId(value)) {
|
||||
throw new Error(`${kind}.serviceId is not a frozen service id`);
|
||||
|
||||
Reference in New Issue
Block a user