All files / src/components/account helpers.ts

0% Statements 0/40
100% Branches 1/1
100% Functions 1/1
0% Lines 0/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                                                                                           
import type { UsageTransaction as AiHydroAccountUsageTransaction } from "@shared/AiHydroAccount"
import type { UsageTransaction as ProtoUsageTransaction } from "@shared/proto/cline/account"
 
export const getMainRole = (roles?: string[]) => {
	if (!roles) {
		return undefined
	}
 
	if (roles.includes("owner")) {
		return "Owner"
	}
	if (roles.includes("admin")) {
		return "Admin"
	}
 
	return "Member"
}
 
export const getAiHydroUris = (base: string, type: "dashboard" | "credits", route?: "account" | "organization") => {
	const dashboard = new URL("dashboard", base)
 
	if (type === "dashboard") {
		return dashboard
	}
 
	const credits = new URL("/" + (route ?? "account"), dashboard)
	credits.searchParams.set("tab", "credits")
	credits.searchParams.set("redirect", "true")
	return credits
}
 
/**
 * Converts a protobuf UsageTransaction to a AiHydroAccount UsageTransaction
 * by adding the missing id and metadata fields
 */
export function convertProtoUsageTransaction(protoTransaction: ProtoUsageTransaction): AiHydroAccountUsageTransaction {
	return {
		...protoTransaction,
		id: protoTransaction.generationId, // Use generationId as the id
		metadata: {
			additionalProp1: "",
			additionalProp2: "",
			additionalProp3: "",
		},
	}
}
 
/**
 * Converts an array of protobuf UsageTransactions to AiHydroAccount UsageTransactions
 */
export function convertProtoUsageTransactions(protoTransactions: ProtoUsageTransaction[]): AiHydroAccountUsageTransaction[] {
	return protoTransactions.map(convertProtoUsageTransaction)
}