Skip to content
Sarj Workspace Sync

Configuration

Configure one immutable policy per process or Worker isolate. Supply credentials through the host environment.

Read-only audit

import { readFile } from "node:fs/promises";
import { z } from "zod";
import {
configureWorkspaceSyncPolicy,
getWorkspaceSyncPolicy,
} from "@sarj-ai/workspace-sync";
import { GoogleDirectoryClient } from "@sarj-ai/workspace-sync/org-sync/google-directory-client";
const policyPath = process.argv[2];
if (!policyPath)
throw new Error("Usage: node audit-directory.ts /path/to/host-policy.json");
const input: unknown = JSON.parse(await readFile(policyPath, "utf8"));
configureWorkspaceSyncPolicy(input);
const policy = getWorkspaceSyncPolicy();
const credentials = z
.object({
GOOGLE_SERVICE_ACCOUNT_EMAIL: z.email(),
GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY: z.string().trim().min(1),
})
.parse(process.env);
const directory = new GoogleDirectoryClient({
adminSubject: policy.org.googleAdminSubject,
privateKey: credentials.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY,
serviceAccountEmail: credentials.GOOGLE_SERVICE_ACCOUNT_EMAIL,
userProject: policy.org.googleUserProject,
});
const users = await directory.listAllUsers(
crypto.randomUUID(),
Date.now() + 60_000,
);
process.stdout.write(`Read ${String(users.length)} Directory users.\n`);

Policy

WorkspaceSyncPolicySchema.parse validates shape and cross-field invariants.

JSON Schema ยท Synthetic example

Example policy
{
"contractorAuthorityGroup": {
"acceptedEmails": [
"team-contractors@example.com",
"team-eng-contract@example.com"
],
"email": "team-contractors@example.com",
"id": "contractor-group-test"
},
"employeeEntitlementExcludedEmails": [],
"ignoredDeletedGoogleUserIds": [],
"org": {
"allowedEmptyDepartmentGoogleUserIds": ["100000000000000000001"],
"allTeamDriveId": "test-shared-drive",
"excludedGoogleUserIds": [],
"expectedRootGoogleUserIds": [
"100000000000000000001",
"100000000000000000002"
],
"expectedSlackTeamId": "TTEST000001",
"protectedDepartedGoogleUserIds": [],
"fieldIds": {
"manages": "XTESTMANAGES",
"reportsTo": "XTESTREPORTS",
"team": "XTESTTEAM"
},
"googleAdminSubject": "admin@example.com",
"googleUserProject": "workspace-sync-test",
"managedDomain": "example.com",
"maxAutomaticChanges": 10,
"minimumGoogleParticipants": 40,
"orgChartFileId": "test-org-chart-file"
},
"reviewedGitHubDirectGrantRetentions": [],
"reviewedGitHubTeamMemberships": [],
"sentryTeamSlug": "platform",
"trycomp": {
"contractorGroupEmail": "team-contractors@example.com",
"contractorGroupId": "contractor-group-test",
"maxAutomaticActivations": 1,
"maxAutomaticContractorDeactivations": 1,
"maxAutomaticInactiveGoogleDeactivations": 1,
"maxAutomaticDeactivations": 1,
"offboardingOnly": true,
"minimumGoogleUsers": 40
}
}