t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/GCP/ChromeManagement/common.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

59 lines
2.1 KiB
TypeScript

import * as chromemanagement from "@distilled.cloud/gcp/chromemanagement_v1";
import * as Effect from "effect/Effect";
import { MinimumLogLevel } from "effect/References";
import * as Schedule from "effect/Schedule";
export const logLevel = Effect.provideService(
MinimumLogLevel,
process.env.DEBUG ? "Debug" : "Info",
);
const lastSegment = (value: string) => {
const trimmed = value.replace(/\/+$/, "");
const parts = trimmed.split("/");
return parts[parts.length - 1] || trimmed;
};
export const toCustomerName = (value: string) => {
const trimmed = value.replace(/\/+$/, "").trim();
if (trimmed.length === 0) return "";
const idx = trimmed.lastIndexOf("/customers/");
if (idx >= 0) {
const id = trimmed.slice(idx + "/customers/".length).split("/")[0] ?? "";
return id.length > 0 ? `customers/${id}` : "";
}
if (trimmed.startsWith("customers/")) {
const id = trimmed.slice("customers/".length).split("/")[0] ?? "";
return id.length > 0 ? `customers/${id}` : trimmed;
}
return `customers/${lastSegment(trimmed)}`;
};
export const customerName = (() => {
const raw =
process.env.GCP_CHROMEMANAGEMENT_CUSTOMER?.trim() ||
process.env.GCP_CHROMEMANAGEMENT_CUSTOMER_ID?.trim();
return raw ? toCustomerName(raw) : "customers/my_customer";
})();
// Needs a Chrome Enterprise customer the credentials administer
// (GCP_CHROMEMANAGEMENT_CUSTOMER); the service-account token fails with
// `InsufficientScopes` ("Request had insufficient authentication scopes.")
export const runLifecycle = !!(
process.env.GCP_CHROMEMANAGEMENT_CUSTOMER?.trim() ||
process.env.GCP_CHROMEMANAGEMENT_CUSTOMER_ID?.trim()
);
export const probeParent = "customers/0";
export const probeName = `${probeParent}/connectorConfigs/alchemy-missing`;
export const waitUntilGone = (name: string) =>
chromemanagement.getCustomersConnectorConfigs({ name }).pipe(
Effect.as("found" as const),
Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
Effect.repeat({
schedule: Schedule.spaced("1 second"),
until: (status) => status === "gone",
times: 10,
}),
);