@heyputer/puter.js 2.1.15 → 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.
- package/dist/puter.cjs +2 -2
- package/index.d.ts +0 -2
- package/package.json +2 -3
- package/src/index.js +100 -82
- package/src/lib/utils.js +42 -55
- package/src/modules/AI.js +8 -204
- package/src/modules/Apps.js +42 -11
- package/src/modules/Auth.js +6 -5
- package/src/modules/Debug.js +4 -4
- package/src/modules/Drivers.js +12 -17
- package/src/modules/FileSystem/index.js +9 -24
- package/src/modules/Hosting.js +5 -4
- package/src/modules/KV.js +67 -11
- package/src/modules/OS.js +6 -5
- package/src/modules/Perms.js +4 -3
- package/src/modules/PuterDialog.js +2 -2
- package/src/modules/UI.js +44 -28
- package/src/modules/UsageLimitDialog.js +208 -0
- package/types/modules/ai.d.ts +0 -10
- package/types/modules/apps.d.ts +24 -15
- package/types/modules/auth.d.ts +3 -1
- package/types/modules/filesystem.d.ts +0 -2
- package/types/modules/kv.d.ts +10 -0
- package/types/modules/networking.d.ts +1 -1
- package/types/modules/os.d.ts +2 -7
- package/types/modules/ui.d.ts +10 -7
- package/types/modules/util.d.ts +0 -1
- package/types/modules/workers.d.ts +9 -10
- package/types/puter.d.ts +1 -7
- package/src/lib/filesystem/APIFS.js +0 -65
- package/src/lib/filesystem/CacheFS.js +0 -243
- package/src/lib/filesystem/PostMessageFS.js +0 -40
- package/src/lib/filesystem/definitions.js +0 -40
- package/src/modules/Threads.js +0 -72
- package/src/services/APIAccess.js +0 -46
- package/src/services/FSRelay.js +0 -20
- package/src/services/Filesystem.js +0 -137
- package/src/services/NoPuterYet.js +0 -20
- package/src/services/XDIncoming.js +0 -44
- package/types/modules/threads.d.ts +0 -27
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import putility from '@heyputer/putility';
|
|
2
|
-
import { PuterAPIFilesystem } from '../lib/filesystem/APIFS.js';
|
|
3
|
-
import { CachedFilesystem } from '../lib/filesystem/CacheFS.js';
|
|
4
|
-
import { ProxyFilesystem, TFilesystem } from '../lib/filesystem/definitions.js';
|
|
5
|
-
import { PostMessageFilesystem } from '../lib/filesystem/PostMessageFS.js';
|
|
6
|
-
import io from '../lib/socket.io/socket.io.esm.min.js';
|
|
7
|
-
|
|
8
|
-
export class FilesystemService extends putility.concepts.Service {
|
|
9
|
-
static PROPERTIES = {
|
|
10
|
-
// filesystem:
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
static DEPENDS = ['api-access'];
|
|
14
|
-
static HOOKS = [
|
|
15
|
-
{
|
|
16
|
-
service: 'api-access',
|
|
17
|
-
event: 'update',
|
|
18
|
-
description: `
|
|
19
|
-
re-initialize the socket connection whenever the
|
|
20
|
-
authentication token or API origin is changed.
|
|
21
|
-
`,
|
|
22
|
-
async do () {
|
|
23
|
-
this.initializeSocket();
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
_init () {
|
|
29
|
-
const env = this._.context.env;
|
|
30
|
-
|
|
31
|
-
if ( env === 'app' ) {
|
|
32
|
-
// TODO: uncomment when relay is ready
|
|
33
|
-
// this.init_app_fs_();
|
|
34
|
-
|
|
35
|
-
this.init_top_fs_();
|
|
36
|
-
} else {
|
|
37
|
-
this.init_top_fs_();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.initializeSocket();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
init_app_fs_ () {
|
|
44
|
-
this.fs_nocache_ = new PostMessageFilesystem({
|
|
45
|
-
messageTarget: globalThis.parent,
|
|
46
|
-
rpc: this._.context.util.rpc,
|
|
47
|
-
}).as(TFilesystem);
|
|
48
|
-
this.filesystem = this.fs_nocache_;
|
|
49
|
-
}
|
|
50
|
-
init_top_fs_ () {
|
|
51
|
-
const api_info = this._.context.services.get('api-access').get_api_info();
|
|
52
|
-
this.fs_nocache_ = new PuterAPIFilesystem({ api_info }).as(TFilesystem);
|
|
53
|
-
this.fs_cache_ = new CachedFilesystem({ delegate: this.fs_nocache_ }).as(TFilesystem);
|
|
54
|
-
// this.filesystem = this.fs_nocache;
|
|
55
|
-
this.fs_proxy_ = new ProxyFilesystem({ delegate: this.fs_nocache_ });
|
|
56
|
-
this.filesystem = this.fs_proxy_.as(TFilesystem);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
cache_on () {
|
|
60
|
-
this.fs_proxy_.delegate = this.fs_cache_;
|
|
61
|
-
}
|
|
62
|
-
cache_off () {
|
|
63
|
-
this.fs_proxy_.delegate = this.fs_nocache_;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async initializeSocket () {
|
|
67
|
-
if ( this.socket ) {
|
|
68
|
-
this.socket.disconnect();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const svc_apiAccess = this._.context.services.get('api-access');
|
|
72
|
-
const api_info = svc_apiAccess.get_api_info();
|
|
73
|
-
|
|
74
|
-
if ( api_info.api_origin === undefined ) {
|
|
75
|
-
// This will get called again later with updated information
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this.socket = io(api_info.api_origin, {
|
|
80
|
-
auth: { auth_token: api_info.auth_token },
|
|
81
|
-
autoUnref: this._.context.env === 'nodejs',
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
this.bindSocketEvents();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
bindSocketEvents () {
|
|
88
|
-
this.socket.on('connect', () => {
|
|
89
|
-
if ( puter.debugMode )
|
|
90
|
-
{
|
|
91
|
-
console.log('FileSystem Socket: Connected', this.socket.id);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
this.socket.on('disconnect', () => {
|
|
96
|
-
if ( puter.debugMode )
|
|
97
|
-
{
|
|
98
|
-
console.log('FileSystem Socket: Disconnected');
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this.socket.on('reconnect', (attempt) => {
|
|
103
|
-
if ( puter.debugMode )
|
|
104
|
-
{
|
|
105
|
-
console.log('FileSystem Socket: Reconnected', this.socket.id);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
this.socket.on('reconnect_attempt', (attempt) => {
|
|
110
|
-
if ( puter.debugMode )
|
|
111
|
-
{
|
|
112
|
-
console.log('FileSystem Socket: Reconnection Attemps', attempt);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
this.socket.on('reconnect_error', (error) => {
|
|
117
|
-
if ( puter.debugMode )
|
|
118
|
-
{
|
|
119
|
-
console.log('FileSystem Socket: Reconnection Error', error);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
this.socket.on('reconnect_failed', () => {
|
|
124
|
-
if ( puter.debugMode )
|
|
125
|
-
{
|
|
126
|
-
console.log('FileSystem Socket: Reconnection Failed');
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
this.socket.on('error', (error) => {
|
|
131
|
-
if ( puter.debugMode )
|
|
132
|
-
{
|
|
133
|
-
console.error('FileSystem Socket Error:', error);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import putility from '@heyputer/putility';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Runs commands on the special `globalThis.when_puter_happens` global, for
|
|
5
|
-
* situations where the `puter` global doesn't exist soon enough.
|
|
6
|
-
*/
|
|
7
|
-
export class NoPuterYetService extends putility.concepts.Service {
|
|
8
|
-
_init () {
|
|
9
|
-
if ( ! globalThis.when_puter_happens ) return;
|
|
10
|
-
if ( puter && puter.env !== 'gui' ) return;
|
|
11
|
-
|
|
12
|
-
if ( ! Array.isArray(globalThis.when_puter_happens) ) {
|
|
13
|
-
globalThis.when_puter_happens = [globalThis.when_puter_happens];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
for ( const fn of globalThis.when_puter_happens ) {
|
|
17
|
-
fn({ context: this._.context });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import putility from '@heyputer/putility';
|
|
2
|
-
|
|
3
|
-
const TeePromise = putility.libs.promise.TeePromise;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Manages message events from the window object.
|
|
7
|
-
*/
|
|
8
|
-
export class XDIncomingService extends putility.concepts.Service {
|
|
9
|
-
_construct () {
|
|
10
|
-
this.filter_listeners_ = [];
|
|
11
|
-
this.tagged_listeners_ = {};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
_init () {
|
|
15
|
-
globalThis.addEventListener('message', async event => {
|
|
16
|
-
for ( const fn of this.filter_listeners_ ) {
|
|
17
|
-
const tp = new TeePromise();
|
|
18
|
-
fn(event, tp);
|
|
19
|
-
if ( await tp ) return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const data = event.data;
|
|
23
|
-
if ( ! data ) return;
|
|
24
|
-
const tag = data.$;
|
|
25
|
-
if ( ! tag ) return;
|
|
26
|
-
if ( ! this.tagged_listeners_[tag] ) return;
|
|
27
|
-
|
|
28
|
-
for ( const fn of this.tagged_listeners_[tag] ) {
|
|
29
|
-
fn({ data, source: event.source });
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
register_filter_listener (fn) {
|
|
35
|
-
this.filter_listeners_.push(fn);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
register_tagged_listener (tag, fn) {
|
|
39
|
-
if ( ! this.tagged_listeners_[tag] ) {
|
|
40
|
-
this.tagged_listeners_[tag] = [];
|
|
41
|
-
}
|
|
42
|
-
this.tagged_listeners_[tag].push(fn);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -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
|
-
}
|