From dc827f90c4f15d4cedf9df3248e0bef4d5db473e Mon Sep 17 00:00:00 2001 From: Reynaldi Chernando <12949382+reynaldichernando@users.noreply.github.com> Date: Tue, 16 Dec 2025 07:29:04 +0700 Subject: [PATCH] Fix more puter.js typescript types (#2181) * Fix networking types * Fix os types * Fix UI types * Remove constructor in util.d.ts * Fix worker types * Fix puter.d.ts * Fix apps types * Change socket and tlssocket back to psocket and ptlssocket --- src/puter-js/types/modules/apps.d.ts | 21 ++++++++------------- src/puter-js/types/modules/networking.d.ts | 2 +- src/puter-js/types/modules/os.d.ts | 9 ++------- src/puter-js/types/modules/ui.d.ts | 17 ++++++++++------- src/puter-js/types/modules/util.d.ts | 1 - src/puter-js/types/modules/workers.d.ts | 4 ---- src/puter-js/types/puter.d.ts | 6 +----- 7 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/puter-js/types/modules/apps.d.ts b/src/puter-js/types/modules/apps.d.ts index 57acc3813..1df13c9aa 100644 --- a/src/puter-js/types/modules/apps.d.ts +++ b/src/puter-js/types/modules/apps.d.ts @@ -1,6 +1,6 @@ import type { PaginationOptions, RequestCallbacks } from '../shared.d.ts'; -export interface AppRecord { +export interface App { uid: string; name: string; index_url: string; @@ -21,7 +21,7 @@ export interface AppListOptions extends PaginationOptions { icon_size?: null | 16 | 32 | 64 | 128 | 256 | 512; } -export interface CreateAppOptions extends RequestCallbacks { +export interface CreateAppOptions extends RequestCallbacks { name: string; indexURL: string; title?: string; @@ -34,7 +34,7 @@ export interface CreateAppOptions extends RequestCallbacks { dedupeName?: boolean; } -export interface UpdateAppAttributes extends RequestCallbacks { +export interface UpdateAppAttributes extends RequestCallbacks { name?: string; indexURL?: string; title?: string; @@ -47,16 +47,11 @@ export interface UpdateAppAttributes extends RequestCallbacks { } export class Apps { - constructor (context: { authToken?: string; APIOrigin: string; appID?: string }); - - setAuthToken (authToken: string): void; - setAPIOrigin (APIOrigin: string): void; - - list (options?: AppListOptions): Promise; - create (name: string, indexURL: string, title?: string): Promise; - create (options: CreateAppOptions): Promise; - update (name: string, attributes: UpdateAppAttributes): Promise; - get (name: string, options?: AppListOptions): Promise; + list (options?: AppListOptions): Promise; + create (name: string, indexURL: string, title?: string): Promise; + create (options: CreateAppOptions): Promise; + update (name: string, attributes: UpdateAppAttributes): Promise; + get (name: string, options?: AppListOptions): Promise; delete (name: string): Promise<{ success?: boolean }>; getDeveloperProfile (options?: RequestCallbacks>): Promise>; } diff --git a/src/puter-js/types/modules/networking.d.ts b/src/puter-js/types/modules/networking.d.ts index 975c3de9f..a5255dc4b 100644 --- a/src/puter-js/types/modules/networking.d.ts +++ b/src/puter-js/types/modules/networking.d.ts @@ -14,7 +14,7 @@ export class PSocket { close (): void; on (event: 'open', handler: () => void): void; on (event: 'data', handler: (buffer: Uint8Array) => void): void; - on (event: 'error', handler: (reason: unknown) => void): void; + on (event: 'error', handler: (reason: string) => void): void; on (event: 'close', handler: (hadError: boolean) => void): void; addListener (event: SocketEvent, handler: (...args: unknown[]) => void): void; } diff --git a/src/puter-js/types/modules/os.d.ts b/src/puter-js/types/modules/os.d.ts index ebe39b2d3..6dfb69fb1 100644 --- a/src/puter-js/types/modules/os.d.ts +++ b/src/puter-js/types/modules/os.d.ts @@ -1,12 +1,7 @@ import type { RequestCallbacks } from '../shared.d.ts'; -import type { AuthUser } from './auth.d.ts'; +import type { User } from './auth.d.ts'; export class OS { - constructor (context: { authToken?: string; APIOrigin: string; appID?: string }); - - setAuthToken (authToken: string): void; - setAPIOrigin (APIOrigin: string): void; - - user (options?: RequestCallbacks & { query?: Record }): Promise; + user (options?: RequestCallbacks & { query?: Record }): Promise; version (options?: RequestCallbacks>): Promise>; } diff --git a/src/puter-js/types/modules/ui.d.ts b/src/puter-js/types/modules/ui.d.ts index b2c48443d..be9b92a3a 100644 --- a/src/puter-js/types/modules/ui.d.ts +++ b/src/puter-js/types/modules/ui.d.ts @@ -1,4 +1,3 @@ -import type { RequestCallbacks } from '../shared.d.ts'; import type { FSItem } from './fs-item.d.ts'; export interface AlertButton { @@ -36,8 +35,12 @@ export interface WindowOptions { export interface LaunchAppOptions { name?: string; + app_name?: string; args?: Record; - appInstanceID?: string; + file_paths?: string[]; + items?: FSItem[]; + pseudonym?: string; + callback?: (connection: AppConnection) => void; } export interface ThemeData { @@ -90,17 +93,17 @@ export class AppConnection { } export class UI { - constructor (context: Record, parameters: { appInstanceID?: string; parentInstanceID?: string }); - alert (message?: string, buttons?: AlertButton[]): Promise; - prompt (message?: string, defaultValue?: string): Promise; - authenticateWithPuter (): Promise; + prompt (message?: string, placeholder?: string): Promise; + authenticateWithPuter (): Promise; contextMenu (options: ContextMenuOptions): void; createWindow (options?: WindowOptions): void; exit (statusCode?: number): void; getLanguage (): Promise; hideSpinner (): void; + hideWindow (): void; showSpinner (): void; + showWindow (): void; showColorPicker (defaultColor?: string | Record): Promise; showDirectoryPicker (options?: DirectoryPickerOptions): Promise; showFontPicker (defaultFont?: string | Record): Promise<{ fontFamily: string }>; @@ -127,7 +130,7 @@ export class UI { on (eventName: 'localeChanged', handler: (data: { language: string }) => void): void; on (eventName: 'themeChanged', handler: (data: ThemeData) => void): void; parentApp (): AppConnection | null; - launchApp (appName?: string, args?: Record): Promise; + launchApp (appName?: string, args?: Record, callback?: (connection: AppConnection) => void): Promise; launchApp (options: LaunchAppOptions): Promise; getEntriesFromDataTransferItems (dataTransferItems: DataTransferItemList, options?: { raw?: boolean }): Promise>; diff --git a/src/puter-js/types/modules/util.d.ts b/src/puter-js/types/modules/util.d.ts index 40d616cfa..072048fea 100644 --- a/src/puter-js/types/modules/util.d.ts +++ b/src/puter-js/types/modules/util.d.ts @@ -7,6 +7,5 @@ export class UtilRPC { } export default class Util { - constructor (); rpc: UtilRPC; } diff --git a/src/puter-js/types/modules/workers.d.ts b/src/puter-js/types/modules/workers.d.ts index 6616dae63..90ffe9f48 100644 --- a/src/puter-js/types/modules/workers.d.ts +++ b/src/puter-js/types/modules/workers.d.ts @@ -4,19 +4,15 @@ export interface WorkerInfo { file_path?: string; file_uid?: string; created_at?: string; - [key: string]: unknown; } export interface WorkerDeployment { success: boolean; url: string; errors?: unknown[]; - [key: string]: unknown; } export class WorkersHandler { - constructor (authToken?: string); - create (workerName: string, filePath: string, appName?: string): Promise; delete (workerName: string): Promise; exec (request: RequestInfo | URL, init?: RequestInit): Promise; diff --git a/src/puter-js/types/puter.d.ts b/src/puter-js/types/puter.d.ts index 5e0089521..f879e4785 100644 --- a/src/puter-js/types/puter.d.ts +++ b/src/puter-js/types/puter.d.ts @@ -15,8 +15,6 @@ import type Util from './modules/util.d.ts'; import type { WorkersHandler } from './modules/workers.d.ts'; import type { APICallLogger, APILoggingConfig, PuterEnvironment, ToolSchema } from './shared.d.ts'; -export interface NetAPI extends Networking {} - export interface PuterArgs { [key: string]: unknown; } @@ -65,13 +63,11 @@ export class Puter { [key: string]: unknown; }; - net: NetAPI; + net: Networking; workers: WorkersHandler; static FSItem: typeof FSItem; - constructor(); - setAuthToken(authToken: string): void; resetAuthToken(): void; setAPIOrigin(APIOrigin: string): void;