Files
pikasTech-HWLAB/internal/dev-report-lifecycle.mjs
T
2026-05-22 14:33:10 +08:00

64 lines
2.0 KiB
JavaScript

export const ACTIVE_DEV_PUBLIC_ENDPOINT = "http://74.48.78.17:16667";
export const ACTIVE_DEV_BROWSER_ENDPOINT = "http://74.48.78.17:16666";
export const DEPRECATED_DEV_PUBLIC_ENDPOINT = "http://74.48.78.17:6667";
export const DEPRECATED_RESERVED_PROD_ENDPOINT = "http://74.48.78.17:6666";
export const REPORT_LIFECYCLE_VERSION = "v1";
export const deprecatedPublicEndpoints = Object.freeze([
DEPRECATED_DEV_PUBLIC_ENDPOINT,
DEPRECATED_RESERVED_PROD_ENDPOINT
]);
const deprecatedPublicEndpointPattern = /http:\/\/74\.48\.78\.17:666[67]\b/gu;
export function findDeprecatedPublicEndpoints(text) {
return [...new Set(String(text).match(deprecatedPublicEndpointPattern) ?? [])].sort();
}
export function isDeprecatedEndpointAllowedInActiveReport(report, endpoint) {
const legacyEndpoint = report?.runtimeSmoke?.legacyPublicEndpoint;
return Boolean(
legacyEndpoint &&
legacyEndpoint.endpoint === endpoint &&
legacyEndpoint.status === "deprecated" &&
legacyEndpoint.activeGreenEligible === false
);
}
export function findForbiddenActiveDeprecatedEndpoints(report, raw) {
if (reportIsHistorical(report)) return [];
return findDeprecatedPublicEndpoints(raw).filter(
(endpoint) => !isDeprecatedEndpointAllowedInActiveReport(report, endpoint)
);
}
export function reportLifecycleState(report) {
return report?.reportLifecycle?.state ?? "active";
}
export function reportIsHistorical(report) {
return reportLifecycleState(report) === "historical";
}
export function activeReportLifecycle(summary) {
return {
version: REPORT_LIFECYCLE_VERSION,
state: "active",
activeEndpoint: ACTIVE_DEV_PUBLIC_ENDPOINT,
activeBrowserEndpoint: ACTIVE_DEV_BROWSER_ENDPOINT,
deprecatedEndpoint: null,
summary
};
}
export function historicalReportLifecycle({ activeEndpoint = ACTIVE_DEV_PUBLIC_ENDPOINT, deprecatedEndpoint, summary }) {
return {
version: REPORT_LIFECYCLE_VERSION,
state: "historical",
activeEndpoint,
activeBrowserEndpoint: ACTIVE_DEV_BROWSER_ENDPOINT,
deprecatedEndpoint,
summary
};
}