@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
102 lines (97 loc) • 2.86 kB
text/typescript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { Identity, Identity$inboundSchema } from "./identity.js";
import {
KeyCreditsData,
KeyCreditsData$inboundSchema,
} from "./keycreditsdata.js";
import {
RatelimitResponse,
RatelimitResponse$inboundSchema,
} from "./ratelimitresponse.js";
export type KeyResponseData = {
/**
* Unique identifier for this key.
*/
keyId: string;
/**
* First few characters of the key for identification.
*/
start: string;
/**
* Whether the key is enabled or disabled.
*/
enabled: boolean;
/**
* Human-readable name for this key.
*/
name?: string | undefined;
/**
* Custom metadata associated with this key.
*/
meta?: { [k: string]: any } | undefined;
/**
* Unix timestamp in milliseconds when key was created.
*/
createdAt: number;
/**
* Unix timestamp in milliseconds when key was last updated.
*/
updatedAt?: number | undefined;
/**
* Unix timestamp in milliseconds when key was last used for verification. This is an approximated value, accurate to within 5 minutes.
*/
lastUsedAt?: number | undefined;
/**
* Unix timestamp in milliseconds when key expires (if set).
*/
expires?: number | undefined;
permissions?: Array<string> | undefined;
roles?: Array<string> | undefined;
/**
* Credit configuration and remaining balance for this key.
*/
credits?: KeyCreditsData | undefined;
identity?: Identity | undefined;
/**
* Decrypted key value (only when decrypt=true).
*/
plaintext?: string | undefined;
ratelimits?: Array<RatelimitResponse> | undefined;
};
/** @internal */
export const KeyResponseData$inboundSchema: z.ZodType<
KeyResponseData,
z.ZodTypeDef,
unknown
> = z.object({
keyId: z.string(),
start: z.string(),
enabled: z.boolean(),
name: z.string().optional(),
meta: z.record(z.any()).optional(),
createdAt: z.number().int(),
updatedAt: z.number().int().optional(),
lastUsedAt: z.number().int().optional(),
expires: z.number().int().optional(),
permissions: z.array(z.string()).optional(),
roles: z.array(z.string()).optional(),
credits: KeyCreditsData$inboundSchema.optional(),
identity: Identity$inboundSchema.optional(),
plaintext: z.string().optional(),
ratelimits: z.array(RatelimitResponse$inboundSchema).optional(),
});
export function keyResponseDataFromJSON(
jsonString: string,
): SafeParseResult<KeyResponseData, SDKValidationError> {
return safeParse(
jsonString,
(x) => KeyResponseData$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'KeyResponseData' from JSON`,
);
}