@unkey/api
Version:
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@unkey/api* API.
181 lines (165 loc) • 6.1 kB
text/typescript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
V2Ratelimit,
V2Ratelimit$inboundSchema,
V2Ratelimit$Outbound,
V2Ratelimit$outboundSchema,
} from "./v2ratelimit.js";
/**
* Attach metadata to this identity that you need to have access to when verifying a key.
*
* @remarks
*
* This will be returned as part of the `verifyKey` response.
*/
export type V2IdentitiesCreateIdentityRequestBodyMeta = {};
export type V2IdentitiesCreateIdentityRequestBody = {
/**
* The id of this identity in your system.
*
* @remarks
*
* This usually comes from your authentication provider and could be a userId, organisationId or even an email.
* It does not matter what you use, as long as it uniquely identifies something in your application.
*
* `externalId`s are unique across your workspace and therefore a `CONFLICT` error is returned when you try to create duplicates.
*/
externalId: string;
/**
* Attach metadata to this identity that you need to have access to when verifying a key.
*
* @remarks
*
* This will be returned as part of the `verifyKey` response.
*/
meta?: V2IdentitiesCreateIdentityRequestBodyMeta | undefined;
/**
* Attach ratelimits to this identity.
*
* @remarks
*
* When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits.
*/
ratelimits?: Array<V2Ratelimit> | undefined;
};
/** @internal */
export const V2IdentitiesCreateIdentityRequestBodyMeta$inboundSchema: z.ZodType<
V2IdentitiesCreateIdentityRequestBodyMeta,
z.ZodTypeDef,
unknown
> = z.object({});
/** @internal */
export type V2IdentitiesCreateIdentityRequestBodyMeta$Outbound = {};
/** @internal */
export const V2IdentitiesCreateIdentityRequestBodyMeta$outboundSchema:
z.ZodType<
V2IdentitiesCreateIdentityRequestBodyMeta$Outbound,
z.ZodTypeDef,
V2IdentitiesCreateIdentityRequestBodyMeta
> = z.object({});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace V2IdentitiesCreateIdentityRequestBodyMeta$ {
/** @deprecated use `V2IdentitiesCreateIdentityRequestBodyMeta$inboundSchema` instead. */
export const inboundSchema =
V2IdentitiesCreateIdentityRequestBodyMeta$inboundSchema;
/** @deprecated use `V2IdentitiesCreateIdentityRequestBodyMeta$outboundSchema` instead. */
export const outboundSchema =
V2IdentitiesCreateIdentityRequestBodyMeta$outboundSchema;
/** @deprecated use `V2IdentitiesCreateIdentityRequestBodyMeta$Outbound` instead. */
export type Outbound = V2IdentitiesCreateIdentityRequestBodyMeta$Outbound;
}
export function v2IdentitiesCreateIdentityRequestBodyMetaToJSON(
v2IdentitiesCreateIdentityRequestBodyMeta:
V2IdentitiesCreateIdentityRequestBodyMeta,
): string {
return JSON.stringify(
V2IdentitiesCreateIdentityRequestBodyMeta$outboundSchema.parse(
v2IdentitiesCreateIdentityRequestBodyMeta,
),
);
}
export function v2IdentitiesCreateIdentityRequestBodyMetaFromJSON(
jsonString: string,
): SafeParseResult<
V2IdentitiesCreateIdentityRequestBodyMeta,
SDKValidationError
> {
return safeParse(
jsonString,
(x) =>
V2IdentitiesCreateIdentityRequestBodyMeta$inboundSchema.parse(
JSON.parse(x),
),
`Failed to parse 'V2IdentitiesCreateIdentityRequestBodyMeta' from JSON`,
);
}
/** @internal */
export const V2IdentitiesCreateIdentityRequestBody$inboundSchema: z.ZodType<
V2IdentitiesCreateIdentityRequestBody,
z.ZodTypeDef,
unknown
> = z.object({
externalId: z.string(),
meta: z.lazy(() => V2IdentitiesCreateIdentityRequestBodyMeta$inboundSchema)
.optional(),
ratelimits: z.array(V2Ratelimit$inboundSchema).optional(),
});
/** @internal */
export type V2IdentitiesCreateIdentityRequestBody$Outbound = {
externalId: string;
meta?: V2IdentitiesCreateIdentityRequestBodyMeta$Outbound | undefined;
ratelimits?: Array<V2Ratelimit$Outbound> | undefined;
};
/** @internal */
export const V2IdentitiesCreateIdentityRequestBody$outboundSchema: z.ZodType<
V2IdentitiesCreateIdentityRequestBody$Outbound,
z.ZodTypeDef,
V2IdentitiesCreateIdentityRequestBody
> = z.object({
externalId: z.string(),
meta: z.lazy(() => V2IdentitiesCreateIdentityRequestBodyMeta$outboundSchema)
.optional(),
ratelimits: z.array(V2Ratelimit$outboundSchema).optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace V2IdentitiesCreateIdentityRequestBody$ {
/** @deprecated use `V2IdentitiesCreateIdentityRequestBody$inboundSchema` instead. */
export const inboundSchema =
V2IdentitiesCreateIdentityRequestBody$inboundSchema;
/** @deprecated use `V2IdentitiesCreateIdentityRequestBody$outboundSchema` instead. */
export const outboundSchema =
V2IdentitiesCreateIdentityRequestBody$outboundSchema;
/** @deprecated use `V2IdentitiesCreateIdentityRequestBody$Outbound` instead. */
export type Outbound = V2IdentitiesCreateIdentityRequestBody$Outbound;
}
export function v2IdentitiesCreateIdentityRequestBodyToJSON(
v2IdentitiesCreateIdentityRequestBody: V2IdentitiesCreateIdentityRequestBody,
): string {
return JSON.stringify(
V2IdentitiesCreateIdentityRequestBody$outboundSchema.parse(
v2IdentitiesCreateIdentityRequestBody,
),
);
}
export function v2IdentitiesCreateIdentityRequestBodyFromJSON(
jsonString: string,
): SafeParseResult<V2IdentitiesCreateIdentityRequestBody, SDKValidationError> {
return safeParse(
jsonString,
(x) =>
V2IdentitiesCreateIdentityRequestBody$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'V2IdentitiesCreateIdentityRequestBody' from JSON`,
);
}