@heyputer/puter.js 2.1.8 → 2.1.10
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.
- package/README.md +10 -1
- package/dist/puter.cjs +2 -2
- package/index.d.ts +2 -1
- package/package.json +4 -3
- package/src/modules/Perms.js +16 -9
- package/types/modules/ai.d.ts +124 -0
- package/types/modules/apps.d.ts +62 -0
- package/types/modules/auth.d.ts +48 -0
- package/types/modules/debug.d.ts +3 -0
- package/types/modules/drivers.d.ts +21 -0
- package/types/modules/filesystem.d.ts +104 -0
- package/types/modules/fs-item.d.ts +57 -0
- package/types/modules/hosting.d.ts +23 -0
- package/types/modules/kv.d.ts +34 -0
- package/types/modules/networking.d.ts +33 -0
- package/types/modules/os.d.ts +12 -0
- package/types/modules/perms.d.ts +23 -0
- package/types/modules/threads.d.ts +27 -0
- package/types/modules/ui.d.ts +146 -0
- package/types/modules/util.d.ts +12 -0
- package/types/modules/workers.d.ts +26 -0
- package/types/puter.d.ts +101 -0
- package/types/shared.d.ts +39 -0
package/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare global {
|
|
|
26
26
|
declare const puter: Puter;
|
|
27
27
|
|
|
28
28
|
export default puter;
|
|
29
|
-
export { puter
|
|
29
|
+
export { puter };
|
|
30
30
|
|
|
31
31
|
export type {
|
|
32
32
|
AI,
|
|
@@ -109,6 +109,7 @@ export type {
|
|
|
109
109
|
WorkerInfo,
|
|
110
110
|
WorkersHandler,
|
|
111
111
|
WriteOptions,
|
|
112
|
+
Puter
|
|
112
113
|
};
|
|
113
114
|
|
|
114
115
|
// NOTE: Provider-specific response bodies (AI, drivers, workers logging stream) intentionally
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyputer/puter.js",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "Puter.js - A JavaScript library for interacting with Puter services.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"typings": "index.d.ts",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"typings": "./index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/puter.cjs",
|
|
11
11
|
"src/",
|
|
12
|
+
"types/",
|
|
12
13
|
"index.d.ts"
|
|
13
14
|
],
|
|
14
15
|
"publishConfig": {
|
package/src/modules/Perms.js
CHANGED
|
@@ -10,15 +10,22 @@ export default class Perms {
|
|
|
10
10
|
this.APIOrigin = APIOrigin;
|
|
11
11
|
}
|
|
12
12
|
async req_ (route, body) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
try {
|
|
14
|
+
const resp = await fetch(this.APIOrigin + route, {
|
|
15
|
+
method: body ? 'POST' : 'GET',
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
21
|
+
});
|
|
22
|
+
if ( resp.headers.get('content-type')?.includes('application/json') ) {
|
|
23
|
+
return await resp.json();
|
|
24
|
+
}
|
|
25
|
+
return { message: await resp.text(), code: 'unknown_error' };
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return { message: e.message, code: 'internal_error' };
|
|
28
|
+
}
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
// Grant Permissions
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export type AIMessageContent = string | { image_url?: { url: string } } | Record<string, unknown>;
|
|
2
|
+
|
|
3
|
+
export interface ChatMessage {
|
|
4
|
+
role?: string;
|
|
5
|
+
content: AIMessageContent | AIMessageContent[];
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ChatOptions {
|
|
10
|
+
model?: string;
|
|
11
|
+
temperature?: number;
|
|
12
|
+
max_tokens?: number;
|
|
13
|
+
stream?: boolean;
|
|
14
|
+
vision?: boolean;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ChatResponse {
|
|
19
|
+
message?: ChatMessage;
|
|
20
|
+
choices?: unknown;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ChatResponseChunk {
|
|
25
|
+
text?: string;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Img2TxtOptions {
|
|
30
|
+
source?: string | File | Blob;
|
|
31
|
+
provider?: string;
|
|
32
|
+
testMode?: boolean;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Txt2ImgOptions {
|
|
37
|
+
prompt?: string;
|
|
38
|
+
model?: string;
|
|
39
|
+
quality?: string;
|
|
40
|
+
input_image?: string;
|
|
41
|
+
input_image_mime_type?: string;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Txt2VidOptions {
|
|
46
|
+
prompt?: string;
|
|
47
|
+
model?: string;
|
|
48
|
+
duration?: number;
|
|
49
|
+
width?: number;
|
|
50
|
+
height?: number;
|
|
51
|
+
fps?: number;
|
|
52
|
+
steps?: number;
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface Txt2SpeechOptions {
|
|
57
|
+
text?: string;
|
|
58
|
+
language?: string;
|
|
59
|
+
voice?: string;
|
|
60
|
+
engine?: string;
|
|
61
|
+
provider?: string;
|
|
62
|
+
model?: string;
|
|
63
|
+
response_format?: string;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Txt2SpeechCallable {
|
|
68
|
+
(text: string, options?: Txt2SpeechOptions): Promise<HTMLAudioElement>;
|
|
69
|
+
(text: string, language?: string, voice?: string, engine?: string): Promise<HTMLAudioElement>;
|
|
70
|
+
listEngines: (options?: string | Record<string, unknown>) => Promise<unknown>;
|
|
71
|
+
listVoices: (options?: string | Record<string, unknown>) => Promise<unknown>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Speech2TxtOptions {
|
|
75
|
+
file?: string | File | Blob;
|
|
76
|
+
audio?: string | File | Blob;
|
|
77
|
+
model?: string;
|
|
78
|
+
response_format?: string;
|
|
79
|
+
language?: string;
|
|
80
|
+
prompt?: string;
|
|
81
|
+
stream?: boolean;
|
|
82
|
+
translate?: boolean;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface Speech2SpeechOptions {
|
|
87
|
+
audio?: string | File | Blob;
|
|
88
|
+
file?: string | File | Blob;
|
|
89
|
+
provider?: string;
|
|
90
|
+
model?: string;
|
|
91
|
+
voice?: string;
|
|
92
|
+
[key: string]: unknown;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class AI {
|
|
96
|
+
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
97
|
+
|
|
98
|
+
setAuthToken (authToken: string): void;
|
|
99
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
100
|
+
|
|
101
|
+
listModels (provider?: string): Promise<Record<string, unknown>[]>;
|
|
102
|
+
listModelProviders (): Promise<string[]>;
|
|
103
|
+
|
|
104
|
+
chat (prompt: string, options?: ChatOptions): Promise<ChatResponse>;
|
|
105
|
+
chat (prompt: string, imageURL: string | File, options?: ChatOptions): Promise<ChatResponse>;
|
|
106
|
+
chat (messages: ChatMessage[], options?: ChatOptions): Promise<ChatResponse>;
|
|
107
|
+
chat (prompt: string, options: ChatOptions & { stream: true }): AsyncIterable<ChatResponseChunk>;
|
|
108
|
+
chat (prompt: string, imageURL: string | File, options: ChatOptions & { stream: true }): AsyncIterable<ChatResponseChunk>;
|
|
109
|
+
chat (messages: ChatMessage[], options: ChatOptions & { stream: true }): AsyncIterable<ChatResponseChunk>;
|
|
110
|
+
chat (...args: unknown[]): Promise<ChatResponse> | AsyncIterable<ChatResponseChunk>;
|
|
111
|
+
|
|
112
|
+
img2txt (source: string | File | Blob | Img2TxtOptions, testMode?: boolean): Promise<string>;
|
|
113
|
+
txt2img (prompt: string, testMode?: boolean): Promise<HTMLImageElement>;
|
|
114
|
+
txt2img (prompt: string, options: Txt2ImgOptions): Promise<HTMLImageElement>;
|
|
115
|
+
txt2vid (prompt: string, testMode?: boolean): Promise<HTMLVideoElement>;
|
|
116
|
+
txt2vid (prompt: string, options: Txt2VidOptions): Promise<HTMLVideoElement>;
|
|
117
|
+
speech2txt (source: string | File | Blob | Speech2TxtOptions, options?: Speech2TxtOptions): Promise<string | Record<string, unknown>>;
|
|
118
|
+
speech2speech (source: string | File | Blob | Speech2SpeechOptions, options?: Speech2SpeechOptions): Promise<Record<string, unknown>>;
|
|
119
|
+
|
|
120
|
+
txt2speech: Txt2SpeechCallable;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// NOTE: AI responses contain provider-specific payloads that are not fully typed here because
|
|
124
|
+
// the SDK does not yet publish stable shapes for those fields.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PaginationOptions, RequestCallbacks } from '../shared.d.ts';
|
|
2
|
+
|
|
3
|
+
export interface AppRecord {
|
|
4
|
+
uid: string;
|
|
5
|
+
name: string;
|
|
6
|
+
index_url: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
maximize_on_start?: boolean;
|
|
11
|
+
background?: boolean;
|
|
12
|
+
filetype_associations?: string[];
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
created_at?: string;
|
|
15
|
+
open_count?: number;
|
|
16
|
+
user_count?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AppListOptions extends PaginationOptions {
|
|
20
|
+
stats_period?: string;
|
|
21
|
+
icon_size?: null | 16 | 32 | 64 | 128 | 256 | 512;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CreateAppOptions extends RequestCallbacks<AppRecord> {
|
|
25
|
+
name: string;
|
|
26
|
+
indexURL: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
icon?: string;
|
|
30
|
+
maximizeOnStart?: boolean;
|
|
31
|
+
background?: boolean;
|
|
32
|
+
filetypeAssociations?: string[];
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
dedupeName?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface UpdateAppAttributes extends RequestCallbacks<AppRecord> {
|
|
38
|
+
name?: string;
|
|
39
|
+
indexURL?: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
icon?: string;
|
|
43
|
+
maximizeOnStart?: boolean;
|
|
44
|
+
background?: boolean;
|
|
45
|
+
filetypeAssociations?: string[];
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class Apps {
|
|
50
|
+
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
51
|
+
|
|
52
|
+
setAuthToken (authToken: string): void;
|
|
53
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
54
|
+
|
|
55
|
+
list (options?: AppListOptions): Promise<AppRecord[]>;
|
|
56
|
+
create (name: string, indexURL: string, title?: string): Promise<AppRecord>;
|
|
57
|
+
create (options: CreateAppOptions): Promise<AppRecord>;
|
|
58
|
+
update (name: string, attributes: UpdateAppAttributes): Promise<AppRecord>;
|
|
59
|
+
get (name: string, options?: AppListOptions): Promise<AppRecord>;
|
|
60
|
+
delete (name: string): Promise<{ success?: boolean }>;
|
|
61
|
+
getDeveloperProfile (options?: RequestCallbacks<Record<string, unknown>>): Promise<Record<string, unknown>>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface AuthUser {
|
|
2
|
+
uuid: string;
|
|
3
|
+
username: string;
|
|
4
|
+
email_confirmed?: boolean;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface AllowanceInfo {
|
|
9
|
+
monthUsageAllowance: number;
|
|
10
|
+
remaining: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AppUsage {
|
|
14
|
+
count: number;
|
|
15
|
+
total: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface APIUsage {
|
|
19
|
+
cost: number;
|
|
20
|
+
count: number;
|
|
21
|
+
units: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface MonthlyUsage {
|
|
25
|
+
allowanceInfo: AllowanceInfo;
|
|
26
|
+
appTotals: Record<string, AppUsage>;
|
|
27
|
+
usage: Record<string, APIUsage>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DetailedAppUsage {
|
|
31
|
+
total: number;
|
|
32
|
+
[key: string]: APIUsage;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class Auth {
|
|
36
|
+
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
37
|
+
|
|
38
|
+
setAuthToken (authToken: string): void;
|
|
39
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
40
|
+
|
|
41
|
+
signIn (options?: { attempt_temp_user_creation?: boolean }): Promise<AuthUser | { token?: string }>;
|
|
42
|
+
signOut (): void;
|
|
43
|
+
isSignedIn (): boolean;
|
|
44
|
+
getUser (): Promise<AuthUser>;
|
|
45
|
+
whoami (): Promise<AuthUser>;
|
|
46
|
+
getMonthlyUsage (): Promise<MonthlyUsage>;
|
|
47
|
+
getDetailedAppUsage (appId: string): Promise<DetailedAppUsage>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface DriverDescriptor {
|
|
2
|
+
iface_name: string;
|
|
3
|
+
service_name?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export class Driver {
|
|
7
|
+
constructor (config: DriverDescriptor & { call_backend: unknown });
|
|
8
|
+
call (methodName: string, parameters?: Record<string, unknown>): Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Drivers {
|
|
12
|
+
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
13
|
+
|
|
14
|
+
setAuthToken (authToken: string): void;
|
|
15
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
16
|
+
|
|
17
|
+
list (): Promise<Record<string, unknown>>;
|
|
18
|
+
get (iface_name: string, service_name?: string): Promise<Driver>;
|
|
19
|
+
call (iface_name: string, method_name: string, parameters?: Record<string, unknown>): Promise<unknown>;
|
|
20
|
+
call (iface_name: string, service_name: string, method_name: string, parameters?: Record<string, unknown>): Promise<unknown>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { RequestCallbacks } from '../shared.d.ts';
|
|
2
|
+
import type { FSItem } from './fs-item.d.ts';
|
|
3
|
+
|
|
4
|
+
export interface SpaceInfo {
|
|
5
|
+
capacity: number;
|
|
6
|
+
used: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CopyOptions extends RequestCallbacks<FSItem> {
|
|
10
|
+
source: string;
|
|
11
|
+
destination: string;
|
|
12
|
+
overwrite?: boolean;
|
|
13
|
+
newName?: string;
|
|
14
|
+
createMissingParents?: boolean;
|
|
15
|
+
dedupeName?: boolean;
|
|
16
|
+
newMetadata?: Record<string, unknown>;
|
|
17
|
+
excludeSocketID?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MoveOptions extends RequestCallbacks<FSItem> {
|
|
21
|
+
source: string;
|
|
22
|
+
destination: string;
|
|
23
|
+
overwrite?: boolean;
|
|
24
|
+
newName?: string;
|
|
25
|
+
createMissingParents?: boolean;
|
|
26
|
+
newMetadata?: Record<string, unknown>;
|
|
27
|
+
excludeSocketID?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MkdirOptions extends RequestCallbacks<FSItem> {
|
|
31
|
+
path?: string;
|
|
32
|
+
overwrite?: boolean;
|
|
33
|
+
dedupeName?: boolean;
|
|
34
|
+
createMissingParents?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface DeleteOptions extends RequestCallbacks<void> {
|
|
38
|
+
path?: string;
|
|
39
|
+
recursive?: boolean;
|
|
40
|
+
descendantsOnly?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ReadOptions extends RequestCallbacks<Blob> {
|
|
44
|
+
path?: string;
|
|
45
|
+
offset?: number;
|
|
46
|
+
byte_count?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ReaddirOptions extends RequestCallbacks<FSItem[]> {
|
|
50
|
+
path?: string;
|
|
51
|
+
uid?: string;
|
|
52
|
+
no_thumbs?: boolean;
|
|
53
|
+
no_assocs?: boolean;
|
|
54
|
+
consistency?: 'strong' | 'eventual';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface RenameOptions extends RequestCallbacks<FSItem> {
|
|
58
|
+
uid?: string;
|
|
59
|
+
path?: string;
|
|
60
|
+
newName: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface UploadOptions extends RequestCallbacks<FSItem[]> {
|
|
64
|
+
overwrite?: boolean;
|
|
65
|
+
dedupeName?: boolean;
|
|
66
|
+
name?: string;
|
|
67
|
+
parsedDataTransferItems?: boolean;
|
|
68
|
+
createFileParent?: boolean;
|
|
69
|
+
init?: (operationId: string, xhr: XMLHttpRequest) => void;
|
|
70
|
+
error?: (e: unknown) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface WriteOptions extends RequestCallbacks<FSItem> {
|
|
74
|
+
overwrite?: boolean;
|
|
75
|
+
dedupeName?: boolean;
|
|
76
|
+
createMissingParents?: boolean;
|
|
77
|
+
name?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface SignResult<T = Record<string, unknown>> {
|
|
81
|
+
token: string;
|
|
82
|
+
items: T | T[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class PuterJSFileSystemModule {
|
|
86
|
+
constructor (context: Record<string, unknown>);
|
|
87
|
+
|
|
88
|
+
space (options?: RequestCallbacks<SpaceInfo>): Promise<SpaceInfo>;
|
|
89
|
+
mkdir (pathOrOptions: string | MkdirOptions, options?: MkdirOptions): Promise<FSItem>;
|
|
90
|
+
copy (sourceOrOptions: string | CopyOptions, destination?: string, options?: CopyOptions): Promise<FSItem>;
|
|
91
|
+
rename (pathOrUid: string, newName: string, options?: RenameOptions): Promise<FSItem>;
|
|
92
|
+
upload (items: FileList | File[] | Blob[] | Blob | string | unknown[], dirPath?: string, options?: UploadOptions): Promise<FSItem[]>;
|
|
93
|
+
read (pathOrOptions: string | ReadOptions, options?: ReadOptions): Promise<Blob>;
|
|
94
|
+
delete (pathOrOptions: string | DeleteOptions, options?: DeleteOptions): Promise<void>;
|
|
95
|
+
move (sourceOrOptions: string | MoveOptions, destination?: string, options?: MoveOptions): Promise<FSItem>;
|
|
96
|
+
write (path: string, data?: string | File | Blob | ArrayBuffer | ArrayBufferView, options?: WriteOptions): Promise<FSItem>;
|
|
97
|
+
sign (appUid: string, items: unknown | unknown[], success?: (result: SignResult) => void, error?: (reason: unknown) => void): Promise<SignResult>;
|
|
98
|
+
symlink (targetPath: string, linkPath: string, options?: Record<string, unknown>): Promise<FSItem>;
|
|
99
|
+
getReadURL (path: string, expiresIn?: number): Promise<string>;
|
|
100
|
+
readdir (pathOrOptions?: string | ReaddirOptions, options?: ReaddirOptions): Promise<FSItem[]>;
|
|
101
|
+
stat (pathOrUid: string, options?: Record<string, unknown>): Promise<FSItem>;
|
|
102
|
+
|
|
103
|
+
FSItem: typeof FSItem;
|
|
104
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ReaddirOptions, WriteOptions } from './filesystem.d.ts';
|
|
2
|
+
|
|
3
|
+
export interface FileSignatureInfo {
|
|
4
|
+
read_url?: string;
|
|
5
|
+
write_url?: string;
|
|
6
|
+
metadata_url?: string;
|
|
7
|
+
fsentry_accessed?: number;
|
|
8
|
+
fsentry_modified?: number;
|
|
9
|
+
fsentry_created?: number;
|
|
10
|
+
fsentry_is_dir?: boolean;
|
|
11
|
+
fsentry_size?: number | null;
|
|
12
|
+
fsentry_name?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
uid?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface InternalFSProperties {
|
|
18
|
+
signature?: string | null;
|
|
19
|
+
expires?: string | null;
|
|
20
|
+
file_signature: FileSignatureInfo;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class FSItem {
|
|
24
|
+
constructor (options: Record<string, unknown>);
|
|
25
|
+
|
|
26
|
+
readURL?: string;
|
|
27
|
+
writeURL?: string;
|
|
28
|
+
metadataURL?: string;
|
|
29
|
+
name: string;
|
|
30
|
+
uid: string;
|
|
31
|
+
id: string;
|
|
32
|
+
uuid: string;
|
|
33
|
+
path: string;
|
|
34
|
+
size: number | null;
|
|
35
|
+
accessed?: number;
|
|
36
|
+
modified?: number;
|
|
37
|
+
created?: number;
|
|
38
|
+
isDirectory: boolean;
|
|
39
|
+
_internalProperties?: InternalFSProperties;
|
|
40
|
+
|
|
41
|
+
write (data: Blob | File | ArrayBuffer | ArrayBufferView | string): Promise<FSItem>;
|
|
42
|
+
rename (newName: string): Promise<FSItem>;
|
|
43
|
+
move (destination: string, overwrite?: boolean, newName?: string): Promise<FSItem>;
|
|
44
|
+
copy (destinationDirectory: string, autoRename?: boolean, overwrite?: boolean): Promise<FSItem>;
|
|
45
|
+
delete (): Promise<void>;
|
|
46
|
+
mkdir (name: string, autoRename?: boolean): Promise<FSItem>;
|
|
47
|
+
readdir (options?: ReaddirOptions): Promise<FSItem[]>;
|
|
48
|
+
read (): Promise<Blob>;
|
|
49
|
+
|
|
50
|
+
// Placeholders that are not implemented in the runtime SDK yet.
|
|
51
|
+
watch (callback: (item: FSItem) => void): void;
|
|
52
|
+
open (callback: (item: FSItem) => void): void;
|
|
53
|
+
setAsWallpaper (options?: Record<string, unknown>, callback?: () => void): void;
|
|
54
|
+
versions (): Promise<unknown>;
|
|
55
|
+
trash (): Promise<unknown>;
|
|
56
|
+
metadata (): Promise<unknown>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RequestCallbacks } from '../shared.d.ts';
|
|
2
|
+
import type { FSItem } from './fs-item.d.ts';
|
|
3
|
+
|
|
4
|
+
export interface Subdomain extends RequestCallbacks<Subdomain> {
|
|
5
|
+
uid: string;
|
|
6
|
+
subdomain: string;
|
|
7
|
+
root_dir?: FSItem | string | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class Hosting {
|
|
11
|
+
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
12
|
+
|
|
13
|
+
setAuthToken (authToken: string): void;
|
|
14
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
15
|
+
|
|
16
|
+
list (): Promise<Subdomain[]>;
|
|
17
|
+
create (subdomain: string): Promise<Subdomain>;
|
|
18
|
+
create (subdomain: string, dirPath: string): Promise<Subdomain>;
|
|
19
|
+
create (options: { subdomain: string; root_dir?: string | FSItem }): Promise<Subdomain>;
|
|
20
|
+
update (subdomain: string, dirPath?: string | null): Promise<Subdomain>;
|
|
21
|
+
get (subdomain: string): Promise<Subdomain>;
|
|
22
|
+
delete (subdomain: string): Promise<boolean>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type KVValue = string | number | boolean | object | unknown;
|
|
2
|
+
export type KVScalar = KVValue | KVValue[];
|
|
3
|
+
|
|
4
|
+
export interface KVPair<T = unknown> {
|
|
5
|
+
key: string;
|
|
6
|
+
value: T;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface KVIncrementPath {
|
|
10
|
+
[path: string]: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class KV {
|
|
14
|
+
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
15
|
+
|
|
16
|
+
readonly MAX_KEY_SIZE: number;
|
|
17
|
+
readonly MAX_VALUE_SIZE: number;
|
|
18
|
+
|
|
19
|
+
setAuthToken (authToken: string): void;
|
|
20
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
21
|
+
|
|
22
|
+
set<T = KVScalar>(key: string, value: T, expireAt?: number): Promise<boolean>;
|
|
23
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
24
|
+
del (key: string): Promise<boolean>;
|
|
25
|
+
incr (key: string, amount?: number | KVIncrementPath): Promise<number>;
|
|
26
|
+
decr (key: string, amount?: number | KVIncrementPath): Promise<number>;
|
|
27
|
+
expire (key: string, ttlSeconds: number): Promise<boolean>;
|
|
28
|
+
expireAt (key: string, timestampSeconds: number): Promise<boolean>;
|
|
29
|
+
list (pattern?: string, returnValues?: false): Promise<string[]>;
|
|
30
|
+
list<T = unknown>(pattern: string, returnValues: true): Promise<KVPair<T>[]>;
|
|
31
|
+
list<T = unknown>(returnValues: true): Promise<KVPair<T>[]>;
|
|
32
|
+
flush (): Promise<boolean>;
|
|
33
|
+
clear (): Promise<boolean>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type SocketEvent =
|
|
2
|
+
| 'open'
|
|
3
|
+
| 'data'
|
|
4
|
+
| 'error'
|
|
5
|
+
| 'close'
|
|
6
|
+
| 'drain'
|
|
7
|
+
| 'tlsdata'
|
|
8
|
+
| 'tlsopen'
|
|
9
|
+
| 'tlsclose';
|
|
10
|
+
|
|
11
|
+
export class PSocket {
|
|
12
|
+
constructor (host: string, port: number);
|
|
13
|
+
write (data: ArrayBuffer | ArrayBufferView | string, callback?: () => void): void;
|
|
14
|
+
close (): void;
|
|
15
|
+
on (event: 'open', handler: () => void): void;
|
|
16
|
+
on (event: 'data', handler: (buffer: Uint8Array) => void): void;
|
|
17
|
+
on (event: 'error', handler: (reason: unknown) => void): void;
|
|
18
|
+
on (event: 'close', handler: (hadError: boolean) => void): void;
|
|
19
|
+
addListener (event: SocketEvent, handler: (...args: unknown[]) => void): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class PTLSSocket extends PSocket {
|
|
23
|
+
constructor (host: string, port: number);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface Networking {
|
|
27
|
+
generateWispV1URL(): Promise<string>;
|
|
28
|
+
Socket: typeof PSocket;
|
|
29
|
+
tls: {
|
|
30
|
+
TLSSocket: typeof PTLSSocket;
|
|
31
|
+
};
|
|
32
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RequestCallbacks } from '../shared.d.ts';
|
|
2
|
+
import type { AuthUser } from './auth.d.ts';
|
|
3
|
+
|
|
4
|
+
export class OS {
|
|
5
|
+
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
6
|
+
|
|
7
|
+
setAuthToken (authToken: string): void;
|
|
8
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
9
|
+
|
|
10
|
+
user (options?: RequestCallbacks<AuthUser> & { query?: Record<string, string> }): Promise<AuthUser>;
|
|
11
|
+
version (options?: RequestCallbacks<Record<string, unknown>>): Promise<Record<string, unknown>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class Perms {
|
|
2
|
+
constructor (context: { authToken?: string; APIOrigin: string });
|
|
3
|
+
|
|
4
|
+
setAuthToken (authToken: string): void;
|
|
5
|
+
setAPIOrigin (APIOrigin: string): void;
|
|
6
|
+
|
|
7
|
+
grantUser (username: string, permission: string): Promise<Record<string, unknown>>;
|
|
8
|
+
grantGroup (groupUid: string, permission: string): Promise<Record<string, unknown>>;
|
|
9
|
+
grantApp (appUid: string, permission: string): Promise<Record<string, unknown>>;
|
|
10
|
+
grantAppAnyUser (appUid: string, permission: string): Promise<Record<string, unknown>>;
|
|
11
|
+
grantOrigin (origin: string, permission: string): Promise<Record<string, unknown>>;
|
|
12
|
+
|
|
13
|
+
revokeUser (username: string, permission: string): Promise<Record<string, unknown>>;
|
|
14
|
+
revokeGroup (groupUid: string, permission: string): Promise<Record<string, unknown>>;
|
|
15
|
+
revokeApp (appUid: string, permission: string): Promise<Record<string, unknown>>;
|
|
16
|
+
revokeAppAnyUser (appUid: string, permission: string): Promise<Record<string, unknown>>;
|
|
17
|
+
revokeOrigin (origin: string, permission: string): Promise<Record<string, unknown>>;
|
|
18
|
+
|
|
19
|
+
createGroup (metadata?: Record<string, unknown>, extra?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
20
|
+
addUsersToGroup (uid: string, usernames: string[]): Promise<Record<string, unknown>>;
|
|
21
|
+
removeUsersFromGroup (uid: string, usernames: string[]): Promise<Record<string, unknown>>;
|
|
22
|
+
listGroups (): Promise<Record<string, unknown>>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|