@heyputer/puter.js 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import type { RequestCallbacks } from '../shared.d.ts';
2
1
  import type { FSItem } from './fs-item.d.ts';
3
2
 
4
3
  export interface AlertButton {
@@ -36,8 +35,12 @@ export interface WindowOptions {
36
35
 
37
36
  export interface LaunchAppOptions {
38
37
  name?: string;
38
+ app_name?: string;
39
39
  args?: Record<string, unknown>;
40
- appInstanceID?: string;
40
+ file_paths?: string[];
41
+ items?: FSItem[];
42
+ pseudonym?: string;
43
+ callback?: (connection: AppConnection) => void;
41
44
  }
42
45
 
43
46
  export interface ThemeData {
@@ -90,17 +93,17 @@ export class AppConnection {
90
93
  }
91
94
 
92
95
  export class UI {
93
- constructor (context: Record<string, unknown>, parameters: { appInstanceID?: string; parentInstanceID?: string });
94
-
95
96
  alert (message?: string, buttons?: AlertButton[]): Promise<string>;
96
- prompt (message?: string, defaultValue?: string): Promise<string | null>;
97
- authenticateWithPuter (): Promise<unknown>;
97
+ prompt (message?: string, placeholder?: string): Promise<string | null>;
98
+ authenticateWithPuter (): Promise<void>;
98
99
  contextMenu (options: ContextMenuOptions): void;
99
100
  createWindow (options?: WindowOptions): void;
100
101
  exit (statusCode?: number): void;
101
102
  getLanguage (): Promise<string>;
102
103
  hideSpinner (): void;
104
+ hideWindow (): void;
103
105
  showSpinner (): void;
106
+ showWindow (): void;
104
107
  showColorPicker (defaultColor?: string | Record<string, unknown>): Promise<string>;
105
108
  showDirectoryPicker (options?: DirectoryPickerOptions): Promise<FSItem | FSItem[]>;
106
109
  showFontPicker (defaultFont?: string | Record<string, unknown>): Promise<{ fontFamily: string }>;
@@ -127,7 +130,7 @@ export class UI {
127
130
  on (eventName: 'localeChanged', handler: (data: { language: string }) => void): void;
128
131
  on (eventName: 'themeChanged', handler: (data: ThemeData) => void): void;
129
132
  parentApp (): AppConnection | null;
130
- launchApp (appName?: string, args?: Record<string, unknown>): Promise<AppConnection>;
133
+ launchApp (appName?: string, args?: Record<string, unknown>, callback?: (connection: AppConnection) => void): Promise<AppConnection>;
131
134
  launchApp (options: LaunchAppOptions): Promise<AppConnection>;
132
135
 
133
136
  getEntriesFromDataTransferItems (dataTransferItems: DataTransferItemList, options?: { raw?: boolean }): Promise<Array<File | FileSystemEntry>>;
@@ -7,6 +7,5 @@ export class UtilRPC {
7
7
  }
8
8
 
9
9
  export default class Util {
10
- constructor ();
11
10
  rpc: UtilRPC;
12
11
  }
@@ -1,26 +1,25 @@
1
1
  export interface WorkerInfo {
2
2
  name: string;
3
3
  url: string;
4
- file_path?: string;
5
- file_uid?: string;
6
- created_at?: string;
7
- [key: string]: unknown;
4
+ file_path: string;
5
+ file_uid: string;
6
+ created_at: string;
8
7
  }
9
8
 
10
9
  export interface WorkerDeployment {
11
10
  success: boolean;
12
11
  url: string;
13
- errors?: unknown[];
14
- [key: string]: unknown;
12
+ errors?: string[];
15
13
  }
16
14
 
17
15
  export class WorkersHandler {
18
- constructor (authToken?: string);
19
-
20
16
  create (workerName: string, filePath: string, appName?: string): Promise<WorkerDeployment>;
21
17
  delete (workerName: string): Promise<boolean>;
22
18
  exec (request: RequestInfo | URL, init?: RequestInit): Promise<Response>;
23
- get (workerName: string): Promise<WorkerInfo>;
19
+ get (workerName: string): Promise<WorkerInfo | undefined>;
24
20
  list (): Promise<WorkerInfo[]>;
25
- getLoggingHandle (workerName: string): Promise<EventTarget & { close: () => void }>;
21
+ getLoggingHandle (workerName: string): Promise<EventTarget & {
22
+ close: () => void;
23
+ onLog: (event: MessageEvent) => void;
24
+ }>;
26
25
  }
package/types/puter.d.ts CHANGED
@@ -10,14 +10,11 @@ import type { KV } from './modules/kv.d.ts';
10
10
  import type { Networking } from './modules/networking.d.ts';
11
11
  import type { OS } from './modules/os.d.ts';
12
12
  import type { Perms } from './modules/perms.d.ts';
13
- import type Threads from './modules/threads.d.ts';
14
13
  import type { UI } from './modules/ui.d.ts';
15
14
  import type Util from './modules/util.d.ts';
16
15
  import type { WorkersHandler } from './modules/workers.d.ts';
17
16
  import type { APICallLogger, APILoggingConfig, PuterEnvironment, ToolSchema } from './shared.d.ts';
18
17
 
19
- export interface NetAPI extends Networking {}
20
-
21
18
  export interface PuterArgs {
22
19
  [key: string]: unknown;
23
20
  }
@@ -55,7 +52,6 @@ export class Puter {
55
52
  ui: UI;
56
53
  hosting: Hosting;
57
54
  kv: KV;
58
- threads: Threads;
59
55
  perms: Perms;
60
56
  drivers: Drivers;
61
57
  debug: Debug;
@@ -67,13 +63,11 @@ export class Puter {
67
63
  [key: string]: unknown;
68
64
  };
69
65
 
70
- net: NetAPI;
66
+ net: Networking;
71
67
  workers: WorkersHandler;
72
68
 
73
69
  static FSItem: typeof FSItem;
74
70
 
75
- constructor();
76
-
77
71
  setAuthToken(authToken: string): void;
78
72
  resetAuthToken(): void;
79
73
  setAPIOrigin(APIOrigin: string): void;
@@ -1,73 +0,0 @@
1
- import { RequestError } from '../lib/RequestError.js';
2
-
3
- export default class Threads {
4
- constructor (puter) {
5
- this.puter = puter;
6
- this.authToken = puter.authToken;
7
- this.APIOrigin = puter.APIOrigin;
8
- }
9
- setAuthToken (authToken) {
10
- this.authToken = authToken;
11
- }
12
- setAPIOrigin (APIOrigin) {
13
- this.APIOrigin = APIOrigin;
14
- }
15
- async req_ (method, route, body) {
16
- const resp = await fetch(this.APIOrigin + route, {
17
- method,
18
- headers: {
19
- Authorization: `Bearer ${this.authToken}`,
20
- ...(body ? { 'Content-Type': 'application/json' } : {}),
21
- },
22
- ...(body ? { body: JSON.stringify(body) } : {}),
23
- });
24
- if ( ! resp.ok ) {
25
- const resp_data = await resp.json();
26
- const err = new RequestError(resp_data.message);
27
- err.response = resp_data;
28
- throw err;
29
- }
30
- return await resp.json();
31
- }
32
-
33
- async create (spec, parent) {
34
- if ( typeof spec === 'string' ) spec = { text: spec };
35
- return await this.req_('POST', '/threads/create', {
36
- ...spec,
37
- ...(parent ? { parent } : {}),
38
- });
39
- }
40
-
41
- async edit (uid, spec = {}) {
42
- if ( typeof spec === 'string' ) spec = { text: spec };
43
- await this.req_('PUT', `/threads/edit/${ encodeURIComponent(uid)}`, {
44
- ...spec,
45
- });
46
- }
47
-
48
- async delete (uid) {
49
- await this.req_('DELETE', `/threads/${ encodeURIComponent(uid)}`);
50
- }
51
-
52
- async list (uid, page, options) {
53
- return await this.req_('POST',
54
- `/threads/list/${ encodeURIComponent(uid) }/${ page}`,
55
- options ?? {});
56
- }
57
-
58
- async subscribe (uid, callback) {
59
- puter.fs.socket.emit('thread.sub-request', { uid });
60
-
61
- // socket.io, which we use unfortunatelly, doesn't handle
62
- // wildcard events, so we have to just put them all here.
63
- const events = [
64
- 'post', 'edit', 'delete', 'child-edit', 'child-delete',
65
- ];
66
-
67
- for ( const event of events ) {
68
- puter.fs.socket.on(`thread.${event}`, (data) => {
69
- if ( data.subscription === uid ) callback(event, data);
70
- });
71
- }
72
- }
73
- }
@@ -1,27 +0,0 @@
1
- export interface ThreadPost {
2
- uid?: string;
3
- parent?: string;
4
- text?: string;
5
- [key: string]: unknown;
6
- }
7
-
8
- export interface ThreadListResult {
9
- posts: ThreadPost[];
10
- total?: number;
11
- page?: number;
12
- }
13
-
14
- export type ThreadSubscriptionHandler = (event: string, data: Record<string, unknown>) => void;
15
-
16
- export default class Threads {
17
- constructor (context: { authToken?: string; APIOrigin: string });
18
-
19
- setAuthToken (authToken: string): void;
20
- setAPIOrigin (APIOrigin: string): void;
21
-
22
- create (spec: string | ThreadPost, parent?: string): Promise<ThreadPost>;
23
- edit (uid: string, spec?: string | ThreadPost): Promise<void>;
24
- delete (uid: string): Promise<void>;
25
- list (uid: string, page?: number, options?: Record<string, unknown>): Promise<ThreadListResult>;
26
- subscribe (uid: string, callback: ThreadSubscriptionHandler): Promise<void>;
27
- }