@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
128 lines (122 loc) • 5.04 kB
text/typescript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import {
RatelimitRequest,
RatelimitRequest$Outbound,
RatelimitRequest$outboundSchema,
} from "./ratelimitrequest.js";
import {
UpdateKeyCreditsData,
UpdateKeyCreditsData$Outbound,
UpdateKeyCreditsData$outboundSchema,
} from "./updatekeycreditsdata.js";
export type V2KeysUpdateKeyRequestBody = {
/**
* Specifies which key to update using the database identifier returned from `createKey`.
*
* @remarks
* Do not confuse this with the actual API key string that users include in requests.
*/
keyId: string;
/**
* Sets a human-readable name for internal organization and identification.
*
* @remarks
* Omitting this field leaves the current name unchanged, while setting null removes it entirely.
* Avoid generic names like "API Key" when managing multiple keys per user or service.
*/
name?: string | null | undefined;
/**
* Links this key to a user or entity in your system for ownership tracking during verification.
*
* @remarks
* Omitting this field preserves the current association, while setting null disconnects the key from any identity.
* Essential for user-specific analytics, billing, and key management across multiple users.
* Supports letters, numbers, underscores, dots, and hyphens for flexible identifier formats.
*/
externalId?: string | null | undefined;
/**
* Stores arbitrary JSON metadata returned during key verification.
*
* @remarks
* Omitting this field preserves existing metadata, while setting null removes all metadata entirely.
* Avoid storing sensitive data here as it's returned in verification responses.
* Large metadata objects increase verification latency and should stay under 10KB total size.
*/
meta?: { [k: string]: any } | null | undefined;
/**
* Sets when this key automatically expires as a Unix timestamp in milliseconds.
*
* @remarks
* Verification fails with code=EXPIRED immediately after this time passes.
* Omitting this field preserves the current expiration, while setting null makes the key permanent.
*
* Avoid setting timestamps in the past as they immediately invalidate the key.
* Keys expire based on server time, not client time, which prevents timezone-related issues.
* Active sessions continue until their next verification attempt after expiry.
*/
expires?: number | null | undefined;
/**
* Credit configuration and remaining balance for this key.
*/
credits?: UpdateKeyCreditsData | null | undefined;
/**
* Defines time-based rate limits that protect against abuse by controlling request frequency.
*
* @remarks
* Omitting this field preserves existing rate limits, while setting null removes all rate limits.
* Unlike credits which track total usage, rate limits reset automatically after each window expires.
* Multiple rate limits can control different operation types with separate thresholds and windows.
*/
ratelimits?: Array<RatelimitRequest> | undefined;
/**
* Controls whether the key is currently active for verification requests.
*
* @remarks
* When set to `false`, all verification attempts fail with `code=DISABLED` regardless of other settings.
* Omitting this field preserves the current enabled status.
* Useful for temporarily suspending access during billing issues, security incidents, or maintenance windows without losing key configuration.
*/
enabled?: boolean | undefined;
roles?: Array<string> | undefined;
permissions?: Array<string> | undefined;
};
/** @internal */
export type V2KeysUpdateKeyRequestBody$Outbound = {
keyId: string;
name?: string | null | undefined;
externalId?: string | null | undefined;
meta?: { [k: string]: any } | null | undefined;
expires?: number | null | undefined;
credits?: UpdateKeyCreditsData$Outbound | null | undefined;
ratelimits?: Array<RatelimitRequest$Outbound> | undefined;
enabled?: boolean | undefined;
roles?: Array<string> | undefined;
permissions?: Array<string> | undefined;
};
/** @internal */
export const V2KeysUpdateKeyRequestBody$outboundSchema: z.ZodType<
V2KeysUpdateKeyRequestBody$Outbound,
z.ZodTypeDef,
V2KeysUpdateKeyRequestBody
> = z.object({
keyId: z.string(),
name: z.nullable(z.string()).optional(),
externalId: z.nullable(z.string()).optional(),
meta: z.nullable(z.record(z.any())).optional(),
expires: z.nullable(z.number().int()).optional(),
credits: z.nullable(UpdateKeyCreditsData$outboundSchema).optional(),
ratelimits: z.array(RatelimitRequest$outboundSchema).optional(),
enabled: z.boolean().optional(),
roles: z.array(z.string()).optional(),
permissions: z.array(z.string()).optional(),
});
export function v2KeysUpdateKeyRequestBodyToJSON(
v2KeysUpdateKeyRequestBody: V2KeysUpdateKeyRequestBody,
): string {
return JSON.stringify(
V2KeysUpdateKeyRequestBody$outboundSchema.parse(v2KeysUpdateKeyRequestBody),
);
}