Files
pterodactyl-panel/resources/scripts/api/definitions/index.d.ts
T
Dane Everitt a81c3b4d52 Add support for stripe-style identifiers on existing models with UUIDs (#5548)
This is a partial implementation to begin moving towards stripe-style
identifiers for resources in the system. Any models with an existing
`uuid` column can easily be updated to return an identifier in the
format of `prfx_xyz` where `prfx` is a four character prefix, and `xyz`
is the UUID, encoded using base-32.

These are quite easy to use within the API layer because we just need to
do one quick transformation to extract the UUID for those models. This
PR implements that logic for servers in the `SubstituteClientBindings`
logic.

A future PR will need to come through and handle identifiers for models
that _don't_ currently use UUIDs for reference that we want to expose to
clients. In those cases it is easier to just generate base-32 encoded
UUID7s that get stored in the database and indexed. They follow the same
base approach, but you don't need to do any transformations in the code
(other than stripping the prefix, unless we decide to store the prefix).

There is also now a `PTERODACTYL_USE_SERVER_IDENTIFIERS` environment
variable, that when set to true, updates the front-end and API response
to use this new identifier in place of the `uuidShort` value.
2026-02-14 11:21:57 -08:00

35 lines
1.3 KiB
TypeScript

import { MarkRequired } from 'ts-essentials';
import { FractalResponseData, FractalResponseList } from '../http';
export type UUID = string;
export type Identifier<P extends string = string> = `${P}_${string}`;
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Model {}
interface ModelWithRelationships extends Model {
relationships: Record<string, FractalResponseData | FractalResponseList | undefined>;
}
/**
* Allows a model to have optional relationships that are marked as being
* present in a given pathway. This allows different API calls to specify the
* "completeness" of a response object without having to make every API return
* the same information, or every piece of logic do explicit null checking.
*
* Example:
* >> const user: WithLoaded<User, 'servers'> = {};
* >> // "user.servers" is no longer potentially undefined.
*/
type WithLoaded<M extends ModelWithRelationships, R extends keyof M['relationships']> = M & {
relationships: MarkRequired<M['relationships'], R>;
};
/**
* Helper type that allows you to infer the type of an object by giving
* it the specific API request function with a return type. For example:
*
* type Egg = InferModel<typeof getEgg>;
*/
export type InferModel<T extends (...args: any) => any> = ReturnType<T> extends Promise<infer U> ? U : T;