@luxorai/sandbox
Version:
TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud
88 lines • 3.07 kB
JavaScript
import { randomUUID } from "node:crypto";
import { timestampDate } from "@bufbuild/protobuf/wkt";
import { workspaceSecretError } from "./workspace-secrets.js";
function metadata(policy) {
if (!policy)
throw new Error("Missing secret policy metadata");
return {
id: policy.id,
workspaceId: policy.workspaceId,
name: policy.name,
revision: policy.revision,
attachedSessionCount: policy.attachedSessionCount,
rules: policy.rules.map((rule) => ({
origin: rule.origin,
methods: [...rule.methods],
pathPrefix: rule.pathPrefix,
header: rule.header || undefined,
queryParameter: rule.queryParameter || undefined,
jsonPointer: rule.jsonPointer || undefined,
secrets: [...rule.secrets],
})),
createdAt: policy.createdAt && timestampDate(policy.createdAt),
updatedAt: policy.updatedAt && timestampDate(policy.updatedAt),
deletedAt: policy.deletedAt && timestampDate(policy.deletedAt),
};
}
/** Saved policies affect subsequent requests from sessions that select them. */
export class SecretPolicies {
workspaceId;
rpc;
constructor(workspaceId, rpc) {
this.workspaceId = workspaceId;
this.rpc = rpc;
}
async create(name, rules, requestId = randomUUID()) {
try {
return metadata((await this.rpc.createSecretPolicy({ workspaceId: this.workspaceId, name, rules, requestId })).policy);
}
catch (err) {
throw workspaceSecretError(err);
}
}
async update(policyId, rules, options) {
try {
return metadata((await this.rpc.updateSecretPolicy({
...options,
workspaceId: this.workspaceId,
policyId,
rules,
requestId: options.requestId ?? randomUUID(),
})).policy);
}
catch (err) {
throw workspaceSecretError(err);
}
}
async delete(policyId, options) {
try {
return metadata((await this.rpc.deleteSecretPolicy({
...options,
workspaceId: this.workspaceId,
policyId,
requestId: options.requestId ?? randomUUID(),
})).policy);
}
catch (err) {
throw workspaceSecretError(err);
}
}
async get(nameOrId) {
try {
return metadata((await this.rpc.getSecretPolicy({ workspaceId: this.workspaceId, policyId: nameOrId })).policy);
}
catch (err) {
throw workspaceSecretError(err);
}
}
async list(options = {}) {
try {
const page = await this.rpc.listSecretPolicies({ ...options, workspaceId: this.workspaceId });
return { policies: page.policies.map(metadata), nextCursor: page.nextCursor };
}
catch (err) {
throw workspaceSecretError(err);
}
}
}
//# sourceMappingURL=secret-policies.js.map