-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtypes.ts
More file actions
77 lines (70 loc) · 3.03 KB
/
types.ts
File metadata and controls
77 lines (70 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import type { KeyvStoreAdapter } from "keyv";
import type Keyv from "keyv";
import type { VRChatApplication } from "./application";
import type { createConfig, Options, RequestResult } from "./generated/client";
import type { Lazy } from "./lib/lazy";
import type { GetCurrentUser, GetCurrentUserErrors, GetCurrentUserResponses } from "./types";
import type { VRChatWebsocketOptions } from "./websocket";
export interface VRChatAuthentication {
/**
* The credentials to use for the VRChat API.
*
* If not provided, the user must be logged in using the `login` method.
* If provided, this will be used to authenticate the user automatically.
*/
credentials?: Lazy<LoginCredentials>;
/**
* If set to `true`, the client will attempt to authenticate immediately after being created.
* If set to `false`, the client will only re-authenticate on request failure (e.g. 401 Unauthorized).
* @default true
*/
optimistic?: boolean;
}
export interface VRChatOptions extends Omit<NonNullable<Parameters<typeof createConfig>[0]>, "body" | "bodySerializer" | "credentials" | "global" | "method" | "mode" | "parseAs" | "querySerializer"> {
/**
* When using the VRChat API, you must provide an application name, version, and contact information.
* This is used to identify your application to VRChat, and to provide support if needed.
*/
application: VRChatApplication;
authentication?: VRChatAuthentication;
pipeline?: VRChatWebsocketOptions;
/**
* A [Keyv-compatible adapter](https://npm.im/keyv#official-storage-adapters) for caching & persistent sessions.
*/
keyv?: Keyv<unknown> | KeyvStoreAdapter | Map<unknown, unknown>;
/**
* If set to `true`, this client will log debug information to the console.
* This is useful for debugging, but **will expose sensitive information**.
* @default false
*/
verbose?: boolean;
}
export const TwoFactorMethods = ["totp", "otp", "emailOtp"] as const;
export type TwoFactorMethods = (typeof TwoFactorMethods)[number];
export interface LoginCredentials {
/**
* The username or email of the VRChat account.
*/
username: string;
/**
* The password of the VRChat account.
*/
password: string;
/**
* The secret key for two-factor authentication, useful for service accounts & automated workflows.
* If this is a user-initiated login, don't use this.
*
* Equivalent to ``twoFactorCode: TOTP.generate(totpSecret).otp``.
*/
totpSecret?: string;
/**
* If provided, this function will be called to generate the two-factor authentication code.
* It overrides ``totpSecret`` if both are provided, ``totpSecret`` will be ignored.
*
* @returns The two-factor authentication code.
*/
twoFactorCode?: Lazy<string>;
}
export type LoginOptions<ThrowOnError extends boolean> = { meta?: Record<PropertyKey, unknown> } & LoginCredentials & Omit<Options<GetCurrentUser, ThrowOnError>, "credentials" | "responseTransformer">;
export type LoginResult<ThrowOnError extends boolean = false> = Awaited<RequestResult<GetCurrentUserResponses, GetCurrentUserErrors, ThrowOnError>>;
export * from "./generated/types.gen";