import { z } from 'zod';
// Profile schemas
export const UserProfileSchema = z.object({
username: z.string(),
email: z.string().email(),
timezone: z.string(),
email_notifications: z.boolean(),
restricted: z.boolean(),
two_factor_auth: z.boolean(),
referrals: z.object({
total: z.number(),
completed: z.number(),
pending: z.number(),
credit: z.number(),
code: z.string(),
url: z.string()
}),
authorized_keys: z.array(z.string())
});
// Get profile schema
export const getProfileSchema = z.object({});
// Update profile schema
export const updateProfileSchema = z.object({
email: z.string().email().optional().describe('Your email address'),
timezone: z.string().optional().describe('Your timezone in IANA format (e.g. America/New_York)'),
email_notifications: z.boolean().optional().describe('Whether you want to receive email notifications'),
restricted: z.boolean().optional().describe('Whether your account has restricted access')
});
// SSH Key schemas
export const SSHKeySchema = z.object({
id: z.number(),
label: z.string(),
ssh_key: z.string(),
created: z.string()
});
// List SSH Keys schema
export const listSSHKeysSchema = z.object({
page: z.number().optional().describe('Page number of results to return'),
page_size: z.number().optional().describe('Number of results to return per page')
});
// Get SSH Key schema
export const getSSHKeySchema = z.object({
id: z.number().describe('ID of the SSH key')
});
// Create SSH Key schema
export const createSSHKeySchema = z.object({
label: z.string().describe('A label for the SSH key'),
ssh_key: z.string().describe('The public SSH key')
});
// Update SSH Key schema
export const updateSSHKeySchema = z.object({
id: z.number().describe('ID of the SSH key to update'),
label: z.string().describe('A new label for the SSH key')
});
// Delete SSH Key schema
export const deleteSSHKeySchema = z.object({
id: z.number().describe('ID of the SSH key to delete')
});
// API Token schemas
export const APITokenSchema = z.object({
id: z.number(),
label: z.string(),
created: z.string(),
expiry: z.string().nullable(),
token: z.string().optional(),
scopes: z.array(z.string()),
website: z.string().optional(),
thumbnail_url: z.string().optional()
});
// List API Tokens schema
export const listAPITokensSchema = z.object({
page: z.number().optional().describe('Page number of results to return'),
page_size: z.number().optional().describe('Number of results to return per page')
});
// Get API Token schema
export const getAPITokenSchema = z.object({
id: z.number().describe('ID of the API token')
});
// Create Personal Access Token schema
export const createPersonalAccessTokenSchema = z.object({
label: z.string().describe('A label for the API token'),
expiry: z.string().optional().describe('The expiry date for the token in ISO 8601 format (e.g. 2022-12-31T23:59:59)'),
scopes: z.array(z.string()).describe('The permissions this token has')
});
// Update Token schema
export const updateTokenSchema = z.object({
id: z.number().describe('ID of the API token to update'),
label: z.string().optional().describe('A new label for the API token'),
expiry: z.string().optional().describe('A new expiry date for the token in ISO 8601 format'),
scopes: z.array(z.string()).optional().describe('The new permissions for this token')
});
// Delete Token schema
export const deleteTokenSchema = z.object({
id: z.number().describe('ID of the API token to delete')
});
// Two-Factor Authentication schemas
export const TwoFactorResponseSchema = z.object({
secret: z.string(),
service_name: z.string(),
qr_code: z.string()
});
// Get Two-Factor Secret schema
export const getTwoFactorSecretSchema = z.object({});
// Enable Two-Factor schema
export const enableTwoFactorSchema = z.object({
tfa_code: z.string().describe('The code generated by your authentication app'),
scratch_code: z.string().optional().describe('A scratch code for emergency access')
});
// Disable Two-Factor schema
export const disableTwoFactorSchema = z.object({
tfa_code: z.string().describe('The code generated by your authentication app')
});
// Scope definition
export interface ScopeDefinition {
name: string;
description: string;
category: string;
}
// List of all available API scopes
export const API_SCOPES: ScopeDefinition[] = [
{
name: 'account:read_only',
description: 'Allows access to GET information about your account.',
category: 'Account'
},
{
name: 'account:read_write',
description: 'Allows access to all operations related to your account.',
category: 'Account'
},
{
name: 'databases:read_only',
description: 'Allows access to GET managed databases on your account.',
category: 'Databases'
},
{
name: 'databases:read_write',
description: 'Allows access to all operations related to your managed databases.',
category: 'Databases'
},
{
name: 'domains:read_only',
description: 'Allows access to GET domains on your account.',
category: 'Domains'
},
{
name: 'domains:read_write',
description: 'Allows access to all domain operations.',
category: 'Domains'
},
{
name: 'events:read_only',
description: 'Allows access to GET your events.',
category: 'Events'
},
{
name: 'events:read_write',
description: 'Allows access to all operations related to your events.',
category: 'Events'
},
{
name: 'firewall:read_only',
description: 'Allows access to GET information about your firewalls.',
category: 'Firewall'
},
{
name: 'firewall:read_write',
description: 'Allows access to all firewall operations.',
category: 'Firewall'
},
{
name: 'images:read_only',
description: 'Allows access to GET your images.',
category: 'Images'
},
{
name: 'images:read_write',
description: 'Allows access to all operations related to your images.',
category: 'Images'
},
{
name: 'ips:read_only',
description: 'Allows access to GET your IPs.',
category: 'IPs'
},
{
name: 'ips:read_write',
description: 'Allows access to all operations related to your IPs.',
category: 'IPs'
},
{
name: 'linodes:read_only',
description: 'Allows access to GET Linodes on your account.',
category: 'Linodes'
},
{
name: 'linodes:read_write',
description: 'Allow access to all operations related to your Linodes.',
category: 'Linodes'
},
{
name: 'lke:read_only',
description: 'Allows access to GET LKE clusters on your account.',
category: 'LKE'
},
{
name: 'lke:read_write',
description: 'Allows access to all operations related to LKE clusters on your account.',
category: 'LKE'
},
{
name: 'longview:read_only',
description: 'Allows access to GET your Longview clients.',
category: 'Longview'
},
{
name: 'longview:read_write',
description: 'Allows access to all operations related to your Longview clients.',
category: 'Longview'
},
{
name: 'nodebalancers:read_only',
description: 'Allows access to GET NodeBalancers on your account.',
category: 'NodeBalancers'
},
{
name: 'nodebalancers:read_write',
description: 'Allows access to all NodeBalancer operations.',
category: 'NodeBalancers'
},
{
name: 'object_storage:read_only',
description: 'Allows access to GET information related to your Object Storage.',
category: 'Object Storage'
},
{
name: 'object_storage:read_write',
description: 'Allows access to all Object Storage operations.',
category: 'Object Storage'
},
{
name: 'stackscripts:read_only',
description: 'Allows access to GET your StackScripts.',
category: 'StackScripts'
},
{
name: 'stackscripts:read_write',
description: 'Allows access to all operations related to your StackScripts.',
category: 'StackScripts'
},
{
name: 'volumes:read_only',
description: 'Allows access to GET your volumes.',
category: 'Volumes'
},
{
name: 'volumes:read_write',
description: 'Allows access to all operations related to your volumes.',
category: 'Volumes'
},
{
name: 'vpc:read_only',
description: 'Allows access to GET VPC and subnet information.',
category: 'VPC'
},
{
name: 'vpc:read_write',
description: 'Allows access to all operations related to VPC and subnet creation, updating, and deletion',
category: 'VPC'
}
];
// API Scope schema
export const ScopeSchema = z.object({
name: z.string(),
description: z.string(),
category: z.string()
});
// List API Scopes schema
export const listAPIScopesSchema = z.object({
category: z.string().optional().describe('Filter scopes by category (e.g., "Linodes", "Volumes", "NodeBalancers")')
});
// Scope Response schema
export const ScopeListResponseSchema = z.object({
scopes: z.array(ScopeSchema)
});
// Authorized App schemas
export const AuthorizedAppSchema = z.object({
id: z.number(),
label: z.string(),
thumbnail_url: z.string(),
access: z.string(),
scopes: z.array(z.string()),
website: z.string(),
created: z.string(),
expiry: z.string()
});
// List Authorized Apps schema
export const listAuthorizedAppsSchema = z.object({
page: z.number().optional().describe('Page number of results to return'),
page_size: z.number().optional().describe('Number of results to return per page')
});
// Get Authorized App schema
export const getAuthorizedAppSchema = z.object({
appId: z.number().describe('ID of the authorized app')
});
// Revoke Authorized App schema
export const revokeAuthorizedAppSchema = z.object({
appId: z.number().describe('ID of the authorized app to revoke')
});
// Trusted Device schemas
export const TrustedDeviceSchema = z.object({
id: z.number(),
user_agent: z.string(),
last_remote_addr: z.string(),
last_authenticated: z.string(),
created: z.string(),
expiry: z.string()
});
// List Trusted Devices schema
export const listTrustedDevicesSchema = z.object({
page: z.number().optional().describe('Page number of results to return'),
page_size: z.number().optional().describe('Number of results to return per page')
});
// Get Trusted Device schema
export const getTrustedDeviceSchema = z.object({
deviceId: z.number().describe('ID of the trusted device')
});
// Revoke Trusted Device schema
export const revokeTrustedDeviceSchema = z.object({
deviceId: z.number().describe('ID of the trusted device to revoke')
});
// Grant schemas
export const GrantSchema = z.object({
id: z.number(),
permissions: z.string(),
label: z.string(),
entity: z.object({
id: z.number(),
type: z.string(),
label: z.string()
})
});
// List Grants schema
export const listGrantsSchema = z.object({
page: z.number().optional().describe('Page number of results to return'),
page_size: z.number().optional().describe('Number of results to return per page')
});
// Login schemas
export const LoginSchema = z.object({
id: z.number(),
ip: z.string(),
datetime: z.string(),
username: z.string(),
status: z.string()
});
// List Logins schema
export const listLoginsSchema = z.object({
page: z.number().optional().describe('Page number of results to return'),
page_size: z.number().optional().describe('Number of results to return per page')
});
// Get Login schema
export const getLoginSchema = z.object({
loginId: z.number().describe('ID of the login')
});
// Phone Number schemas
export const deletePhoneNumberSchema = z.object({});
export const sendPhoneVerificationSchema = z.object({
phone_number: z.string().describe('The phone number to verify in E.164 format (e.g. +14155551234)')
});
export const verifyPhoneNumberSchema = z.object({
otp_code: z.string().describe('The one-time password sent to the phone number')
});
// User Preferences schemas
export const UserPreferencesSchema = z.object({
sortKeys: z.record(z.string()).optional(),
timezone: z.string().optional(),
email_notifications: z.boolean().optional(),
default_from_email: z.string().optional(),
authorized_keys: z.array(z.string()).optional(),
theme: z.string().optional(),
editorMode: z.string().optional()
});
// Get User Preferences schema
export const getUserPreferencesSchema = z.object({});
// Update User Preferences schema
export const updateUserPreferencesSchema = z.object({
sortKeys: z.record(z.string()).optional().describe('Sort keys for different views'),
timezone: z.string().optional().describe('Your timezone in IANA format (e.g. America/New_York)'),
email_notifications: z.boolean().optional().describe('Whether you want to receive email notifications'),
default_from_email: z.string().optional().describe('Default email to use as from address'),
authorized_keys: z.array(z.string()).optional().describe('Authorized SSH keys'),
theme: z.string().optional().describe('UI theme preference'),
editorMode: z.string().optional().describe('Editor mode preference')
});
// Security Question schemas
export const SecurityQuestionSchema = z.object({
id: z.number(),
question: z.string()
});
// Get Security Questions schema
export const getSecurityQuestionsSchema = z.object({});
// Answer Security Questions schema
export const answerSecurityQuestionsSchema = z.object({
answers: z.array(
z.object({
question_id: z.number().describe('ID of the security question'),
answer: z.string().describe('Answer to the security question')
})
).describe('Answers to security questions')
});