@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
105 lines (97 loc) • 2.74 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 * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
/**
* How often credits are automatically refilled.
*/
export const KeyCreditsRefillInterval = {
Daily: "daily",
Monthly: "monthly",
} as const;
/**
* How often credits are automatically refilled.
*/
export type KeyCreditsRefillInterval = OpenEnum<
typeof KeyCreditsRefillInterval
>;
/**
* Configuration for automatic credit refill behavior.
*/
export type KeyCreditsRefill = {
/**
* How often credits are automatically refilled.
*/
interval: KeyCreditsRefillInterval;
/**
* Number of credits to add during each refill cycle.
*/
amount: number;
/**
* Day of the month for monthly refills (1-31).
*
* @remarks
* Only required when interval is 'monthly'.
* For days beyond the month's length, refill occurs on the last day of the month.
*/
refillDay?: number | undefined;
};
/** @internal */
export const KeyCreditsRefillInterval$inboundSchema: z.ZodType<
KeyCreditsRefillInterval,
z.ZodTypeDef,
unknown
> = openEnums.inboundSchema(KeyCreditsRefillInterval);
/** @internal */
export const KeyCreditsRefillInterval$outboundSchema: z.ZodType<
string,
z.ZodTypeDef,
KeyCreditsRefillInterval
> = openEnums.outboundSchema(KeyCreditsRefillInterval);
/** @internal */
export const KeyCreditsRefill$inboundSchema: z.ZodType<
KeyCreditsRefill,
z.ZodTypeDef,
unknown
> = z.object({
interval: KeyCreditsRefillInterval$inboundSchema,
amount: z.number().int(),
refillDay: z.number().int().optional(),
});
/** @internal */
export type KeyCreditsRefill$Outbound = {
interval: string;
amount: number;
refillDay?: number | undefined;
};
/** @internal */
export const KeyCreditsRefill$outboundSchema: z.ZodType<
KeyCreditsRefill$Outbound,
z.ZodTypeDef,
KeyCreditsRefill
> = z.object({
interval: KeyCreditsRefillInterval$outboundSchema,
amount: z.number().int(),
refillDay: z.number().int().optional(),
});
export function keyCreditsRefillToJSON(
keyCreditsRefill: KeyCreditsRefill,
): string {
return JSON.stringify(
KeyCreditsRefill$outboundSchema.parse(keyCreditsRefill),
);
}
export function keyCreditsRefillFromJSON(
jsonString: string,
): SafeParseResult<KeyCreditsRefill, SDKValidationError> {
return safeParse(
jsonString,
(x) => KeyCreditsRefill$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'KeyCreditsRefill' from JSON`,
);
}