//=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { TeamApiKeysCrud, UserApiKeysCrud, teamApiKeysCreateInputSchema, userApiKeysCreateInputSchema } from "@hexclave/shared/dist/interface/crud/project-api-keys"; import { filterUndefined } from "@hexclave/shared/dist/utils/objects"; import { IfAndOnlyIf, PrettifyType } from "@hexclave/shared/dist/utils/types"; import type * as yup from "yup"; export type ApiKeyType = "user" | "team"; export type ApiKey = & { id: string, description: string, expiresAt?: Date, manuallyRevokedAt?: Date | null, createdAt: Date, value: IfAndOnlyIf, update(options: ApiKeyUpdateOptions): Promise, revoke: () => Promise, isValid: () => boolean, whyInvalid: () => "manually-revoked" | "expired" | null, } & ( | ("user" extends Type ? { type: "user", userId: string } : never) | ("team" extends Type ? { type: "team", teamId: string } : never) ); export type UserApiKeyFirstView = PrettifyType>; export type UserApiKey = PrettifyType>; export type TeamApiKeyFirstView = PrettifyType>; export type TeamApiKey = PrettifyType>; export type ApiKeyCreationOptions = & { description: string, expiresAt: Date | null, /** * Whether the API key should be considered public. A public API key will not be detected by the secret scanner, which * automatically revokes API keys when it detects that they may have been exposed to the public. */ isPublic?: boolean, }; export function apiKeyCreationOptionsToCrud(type: "user", userId: string, options: ApiKeyCreationOptions<"user">): Promise>; export function apiKeyCreationOptionsToCrud(type: "team", teamId: string, options: ApiKeyCreationOptions<"team">): Promise>; export function apiKeyCreationOptionsToCrud(type: ApiKeyType, userIdOrTeamId: string, options: ApiKeyCreationOptions): Promise | yup.InferType>; export async function apiKeyCreationOptionsToCrud(type: ApiKeyType, userIdOrTeamId: string, options: ApiKeyCreationOptions): Promise | yup.InferType> { return { description: options.description, expires_at_millis: options.expiresAt == null ? options.expiresAt : options.expiresAt.getTime(), is_public: options.isPublic, ...(type === "user" ? { user_id: userIdOrTeamId } : { team_id: userIdOrTeamId }), }; } export type ApiKeyUpdateOptions = { description?: string, expiresAt?: Date | null, revoked?: boolean, }; export function apiKeyUpdateOptionsToCrud(type: "user", options: ApiKeyUpdateOptions<"user">): Promise; export function apiKeyUpdateOptionsToCrud(type: "team", options: ApiKeyUpdateOptions<"team">): Promise; export function apiKeyUpdateOptionsToCrud(type: ApiKeyType, options: ApiKeyUpdateOptions): Promise; export async function apiKeyUpdateOptionsToCrud(type: ApiKeyType, options: ApiKeyUpdateOptions): Promise { return filterUndefined({ description: options.description, expires_at_millis: options.expiresAt == null ? options.expiresAt : options.expiresAt.getTime(), revoked: options.revoked, }); }