@heyputer/puter.js 2.1.4 → 2.1.7
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 +41 -15
- package/package.json +1 -1
- package/src/index.js +116 -79
- package/src/lib/APICallLogger.js +20 -21
- package/src/lib/EventListener.js +10 -10
- package/src/lib/filesystem/APIFS.js +11 -19
- package/src/lib/filesystem/CacheFS.js +25 -25
- package/src/lib/filesystem/PostMessageFS.js +11 -11
- package/src/lib/filesystem/definitions.js +11 -10
- package/src/lib/path.js +505 -446
- package/src/lib/polyfills/fileReaderPoly.js +40 -0
- package/src/lib/polyfills/localStorage.js +30 -33
- package/src/lib/polyfills/xhrshim.js +206 -207
- package/src/lib/utils.js +160 -151
- package/src/lib/xdrpc.js +9 -9
- package/src/modules/AI.js +473 -292
- package/src/modules/Apps.js +56 -56
- package/src/modules/Auth.js +17 -17
- package/src/modules/Debug.js +1 -1
- package/src/modules/Drivers.js +41 -41
- package/src/modules/FSItem.js +64 -62
- package/src/modules/FileSystem/index.js +22 -23
- package/src/modules/FileSystem/operations/copy.js +7 -7
- package/src/modules/FileSystem/operations/deleteFSEntry.js +14 -12
- package/src/modules/FileSystem/operations/getReadUrl.js +16 -14
- package/src/modules/FileSystem/operations/mkdir.js +11 -11
- package/src/modules/FileSystem/operations/move.js +12 -12
- package/src/modules/FileSystem/operations/read.js +10 -10
- package/src/modules/FileSystem/operations/readdir.js +28 -28
- package/src/modules/FileSystem/operations/rename.js +11 -11
- package/src/modules/FileSystem/operations/sign.js +33 -30
- package/src/modules/FileSystem/operations/space.js +7 -7
- package/src/modules/FileSystem/operations/stat.js +25 -25
- package/src/modules/FileSystem/operations/symlink.js +15 -17
- package/src/modules/FileSystem/operations/upload.js +151 -122
- package/src/modules/FileSystem/operations/write.js +16 -12
- package/src/modules/FileSystem/utils/getAbsolutePathForApp.js +10 -6
- package/src/modules/Hosting.js +29 -29
- package/src/modules/KV.js +23 -23
- package/src/modules/OS.js +15 -15
- package/src/modules/Perms.js +19 -21
- package/src/modules/PuterDialog.js +46 -48
- package/src/modules/Threads.js +17 -20
- package/src/modules/UI.js +156 -156
- package/src/modules/Util.js +3 -3
- package/src/modules/Workers.js +52 -49
- package/src/modules/networking/PSocket.js +38 -38
- package/src/modules/networking/PTLS.js +54 -47
- package/src/modules/networking/PWispHandler.js +49 -47
- package/src/modules/networking/parsers.js +110 -108
- package/src/modules/networking/requests.js +67 -78
- package/src/services/APIAccess.js +9 -9
- package/src/services/FSRelay.js +6 -6
- package/src/services/Filesystem.js +8 -8
- package/src/services/NoPuterYet.js +2 -2
- package/src/services/XDIncoming.js +1 -1
|
@@ -3,12 +3,11 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
3
3
|
* Detects if the current page is loaded using the file:// protocol.
|
|
4
4
|
* @returns {boolean} True if using file:// protocol, false otherwise.
|
|
5
5
|
*/
|
|
6
|
-
isUsingFileProtocol = ()=>{
|
|
6
|
+
isUsingFileProtocol = () => {
|
|
7
7
|
return window.location.protocol === 'file:';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(resolve, reject) {
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
constructor (resolve, reject) {
|
|
12
11
|
super();
|
|
13
12
|
this.reject = reject;
|
|
14
13
|
this.resolve = resolve;
|
|
@@ -20,15 +19,15 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
20
19
|
*/
|
|
21
20
|
this.hasUserActivation = () => {
|
|
22
21
|
// Modern browsers support navigator.userActivation
|
|
23
|
-
if (navigator.userActivation) {
|
|
22
|
+
if ( navigator.userActivation ) {
|
|
24
23
|
return navigator.userActivation.hasBeenActive && navigator.userActivation.isActive;
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
|
|
27
26
|
// Fallback: try to detect user activation by attempting to open a popup
|
|
28
27
|
// This is a bit hacky but works as a fallback
|
|
29
28
|
try {
|
|
30
29
|
const testPopup = window.open('', '_blank', 'width=1,height=1,left=-1000,top=-1000');
|
|
31
|
-
if (testPopup) {
|
|
30
|
+
if ( testPopup ) {
|
|
32
31
|
testPopup.close();
|
|
33
32
|
return true;
|
|
34
33
|
}
|
|
@@ -36,7 +35,7 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
36
35
|
} catch (e) {
|
|
37
36
|
return false;
|
|
38
37
|
}
|
|
39
|
-
}
|
|
38
|
+
};
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* Launches the authentication popup window
|
|
@@ -47,19 +46,17 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
47
46
|
let w = 600;
|
|
48
47
|
let h = 400;
|
|
49
48
|
let title = 'Puter';
|
|
50
|
-
var left = (screen.width/2)-(w/2);
|
|
51
|
-
var top = (screen.height/2)-(h/2);
|
|
52
|
-
const popup = window.open(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left
|
|
56
|
-
);
|
|
49
|
+
var left = (screen.width / 2) - (w / 2);
|
|
50
|
+
var top = (screen.height / 2) - (h / 2);
|
|
51
|
+
const popup = window.open(`${puter.defaultGUIOrigin }/?embedded_in_popup=true&request_auth=true${ window.crossOriginIsolated ? '&cross_origin_isolated=true' : ''}`,
|
|
52
|
+
title,
|
|
53
|
+
`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${ w }, height=${ h }, top=${ top }, left=${ left}`);
|
|
57
54
|
return popup;
|
|
58
55
|
} catch (e) {
|
|
59
56
|
console.error('Failed to open popup:', e);
|
|
60
57
|
return null;
|
|
61
58
|
}
|
|
62
|
-
}
|
|
59
|
+
};
|
|
63
60
|
|
|
64
61
|
this.attachShadow({ mode: 'open' });
|
|
65
62
|
|
|
@@ -338,7 +335,7 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
338
335
|
}
|
|
339
336
|
</style>`;
|
|
340
337
|
// Error message for unsupported protocol
|
|
341
|
-
if(window.location.protocol === 'file:'){
|
|
338
|
+
if ( window.location.protocol === 'file:' ) {
|
|
342
339
|
h += `<dialog>
|
|
343
340
|
<div class="puter-dialog-content" style="padding: 20px 40px; background:white !important; font-size: 15px;">
|
|
344
341
|
<span class="close-btn">✕</span>
|
|
@@ -360,7 +357,7 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
360
357
|
</p>
|
|
361
358
|
</div>
|
|
362
359
|
</dialog>`;
|
|
363
|
-
}else{
|
|
360
|
+
} else {
|
|
364
361
|
h += `<dialog>
|
|
365
362
|
<div class="puter-dialog-content">
|
|
366
363
|
<span class="close-btn">✕</span>
|
|
@@ -376,12 +373,11 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
376
373
|
</dialog>`;
|
|
377
374
|
}
|
|
378
375
|
|
|
379
|
-
|
|
380
376
|
this.shadowRoot.innerHTML = h;
|
|
381
377
|
|
|
382
378
|
// Event listener for the 'message' event
|
|
383
379
|
this.messageListener = async (event) => {
|
|
384
|
-
if (event.data.msg === 'puter.token') {
|
|
380
|
+
if ( event.data.msg === 'puter.token' ) {
|
|
385
381
|
this.close();
|
|
386
382
|
// Set the authToken property
|
|
387
383
|
puter.setAuthToken(event.data.token);
|
|
@@ -395,16 +391,16 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
395
391
|
this.resolve();
|
|
396
392
|
|
|
397
393
|
// Call onAuth callback
|
|
398
|
-
if(puter.onAuth && typeof puter.onAuth === 'function'){
|
|
394
|
+
if ( puter.onAuth && typeof puter.onAuth === 'function' ) {
|
|
399
395
|
puter.getUser().then((user) => {
|
|
400
|
-
puter.onAuth(user)
|
|
396
|
+
puter.onAuth(user);
|
|
401
397
|
});
|
|
402
398
|
}
|
|
403
399
|
|
|
404
400
|
puter.puterAuthState.isPromptOpen = false;
|
|
405
401
|
// Resolve or reject any waiting promises.
|
|
406
|
-
if (puter.puterAuthState.resolver) {
|
|
407
|
-
if (puter.puterAuthState.authGranted) {
|
|
402
|
+
if ( puter.puterAuthState.resolver ) {
|
|
403
|
+
if ( puter.puterAuthState.authGranted ) {
|
|
408
404
|
puter.puterAuthState.resolver.resolve();
|
|
409
405
|
} else {
|
|
410
406
|
puter.puterAuthState.resolver.reject();
|
|
@@ -422,60 +418,62 @@ class PuterDialog extends (globalThis.HTMLElement || Object) { // It will fall b
|
|
|
422
418
|
window.removeEventListener('message', this.messageListener);
|
|
423
419
|
puter.puterAuthState.authGranted = false;
|
|
424
420
|
puter.puterAuthState.isPromptOpen = false;
|
|
425
|
-
|
|
421
|
+
|
|
426
422
|
// Reject the promise with an error message indicating user cancellation.
|
|
427
423
|
// This ensures that the calling code's catch block will be triggered.
|
|
428
424
|
this.reject(new Error('User cancelled the authentication'));
|
|
429
|
-
|
|
425
|
+
|
|
430
426
|
// If there's a resolver set, use it to reject the waiting promise as well.
|
|
431
|
-
if (puter.puterAuthState.resolver) {
|
|
427
|
+
if ( puter.puterAuthState.resolver ) {
|
|
432
428
|
puter.puterAuthState.resolver.reject(new Error('User cancelled the authentication'));
|
|
433
429
|
puter.puterAuthState.resolver = null;
|
|
434
430
|
}
|
|
435
431
|
};
|
|
436
432
|
|
|
437
|
-
connectedCallback() {
|
|
433
|
+
connectedCallback () {
|
|
438
434
|
// Add event listener to the button
|
|
439
|
-
this.shadowRoot.querySelector('#launch-auth-popup')?.addEventListener('click', ()=>{
|
|
435
|
+
this.shadowRoot.querySelector('#launch-auth-popup')?.addEventListener('click', () => {
|
|
440
436
|
let w = 600;
|
|
441
437
|
let h = 400;
|
|
442
438
|
let title = 'Puter';
|
|
443
|
-
var left = (screen.width/2)-(w/2);
|
|
444
|
-
var top = (screen.height/2)-(h/2);
|
|
445
|
-
window.open(puter.defaultGUIOrigin
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
})
|
|
439
|
+
var left = (screen.width / 2) - (w / 2);
|
|
440
|
+
var top = (screen.height / 2) - (h / 2);
|
|
441
|
+
window.open(`${puter.defaultGUIOrigin }/?embedded_in_popup=true&request_auth=true${ window.crossOriginIsolated ? '&cross_origin_isolated=true' : ''}`,
|
|
442
|
+
title,
|
|
443
|
+
`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${ w }, height=${ h }, top=${ top }, left=${ left}`);
|
|
444
|
+
});
|
|
449
445
|
|
|
450
446
|
// Add the event listener to the window object
|
|
451
|
-
window.addEventListener('message', this.messageListener);
|
|
447
|
+
window.addEventListener('message', this.messageListener);
|
|
452
448
|
|
|
453
449
|
// Add event listeners for cancel and close buttons
|
|
454
450
|
this.shadowRoot.querySelector('#launch-auth-popup-cancel')?.addEventListener('click', this.cancelListener);
|
|
455
|
-
this.shadowRoot.querySelector('.close-btn')?.addEventListener('click',this.cancelListener);
|
|
451
|
+
this.shadowRoot.querySelector('.close-btn')?.addEventListener('click', this.cancelListener);
|
|
456
452
|
}
|
|
457
453
|
|
|
458
|
-
open() {
|
|
459
|
-
if(this.hasUserActivation()){
|
|
454
|
+
open () {
|
|
455
|
+
if ( this.hasUserActivation() ) {
|
|
460
456
|
let w = 600;
|
|
461
457
|
let h = 400;
|
|
462
458
|
let title = 'Puter';
|
|
463
|
-
var left = (screen.width/2)-(w/2);
|
|
464
|
-
var top = (screen.height/2)-(h/2);
|
|
465
|
-
window.open(puter.defaultGUIOrigin
|
|
466
|
-
|
|
467
|
-
|
|
459
|
+
var left = (screen.width / 2) - (w / 2);
|
|
460
|
+
var top = (screen.height / 2) - (h / 2);
|
|
461
|
+
window.open(`${puter.defaultGUIOrigin }/?embedded_in_popup=true&request_auth=true${ window.crossOriginIsolated ? '&cross_origin_isolated=true' : ''}`,
|
|
462
|
+
title,
|
|
463
|
+
`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${ w }, height=${ h }, top=${ top }, left=${ left}`);
|
|
468
464
|
}
|
|
469
|
-
else{
|
|
465
|
+
else {
|
|
470
466
|
this.shadowRoot.querySelector('dialog').showModal();
|
|
471
467
|
}
|
|
472
468
|
}
|
|
473
469
|
|
|
474
|
-
close() {
|
|
470
|
+
close () {
|
|
475
471
|
this.shadowRoot.querySelector('dialog').close();
|
|
476
472
|
}
|
|
477
473
|
}
|
|
478
|
-
if (PuterDialog.__proto__
|
|
474
|
+
if ( PuterDialog.__proto__ === globalThis.HTMLElement )
|
|
475
|
+
{
|
|
479
476
|
customElements.define('puter-dialog', PuterDialog);
|
|
477
|
+
}
|
|
480
478
|
|
|
481
479
|
export default PuterDialog;
|
package/src/modules/Threads.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestError } from
|
|
1
|
+
import { RequestError } from '../lib/RequestError.js';
|
|
2
2
|
|
|
3
3
|
export default class Threads {
|
|
4
4
|
constructor (context) {
|
|
@@ -12,16 +12,14 @@ export default class Threads {
|
|
|
12
12
|
this.APIOrigin = APIOrigin;
|
|
13
13
|
}
|
|
14
14
|
async req_ (method, route, body) {
|
|
15
|
-
const resp = await fetch(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
);
|
|
15
|
+
const resp = await fetch(this.APIOrigin + route, {
|
|
16
|
+
method,
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
19
|
+
...(body ? { 'Content-Type': 'application/json' } : {}),
|
|
20
|
+
},
|
|
21
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
22
|
+
});
|
|
25
23
|
if ( ! resp.ok ) {
|
|
26
24
|
const resp_data = await resp.json();
|
|
27
25
|
const err = new RequestError(resp_data.message);
|
|
@@ -30,7 +28,7 @@ export default class Threads {
|
|
|
30
28
|
}
|
|
31
29
|
return await resp.json();
|
|
32
30
|
}
|
|
33
|
-
|
|
31
|
+
|
|
34
32
|
async create (spec, parent) {
|
|
35
33
|
if ( typeof spec === 'string' ) spec = { text: spec };
|
|
36
34
|
return await this.req_('POST', '/threads/create', {
|
|
@@ -38,23 +36,22 @@ export default class Threads {
|
|
|
38
36
|
...(parent ? { parent } : {}),
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
|
-
|
|
39
|
+
|
|
42
40
|
async edit (uid, spec = {}) {
|
|
43
41
|
if ( typeof spec === 'string' ) spec = { text: spec };
|
|
44
|
-
await this.req_('PUT',
|
|
42
|
+
await this.req_('PUT', `/threads/edit/${ encodeURIComponent(uid)}`, {
|
|
45
43
|
...spec,
|
|
46
44
|
});
|
|
47
45
|
}
|
|
48
|
-
|
|
46
|
+
|
|
49
47
|
async delete (uid) {
|
|
50
|
-
await this.req_('DELETE',
|
|
48
|
+
await this.req_('DELETE', `/threads/${ encodeURIComponent(uid)}`);
|
|
51
49
|
}
|
|
52
|
-
|
|
50
|
+
|
|
53
51
|
async list (uid, page, options) {
|
|
54
52
|
return await this.req_('POST',
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
53
|
+
`/threads/list/${ encodeURIComponent(uid) }/${ page}`,
|
|
54
|
+
options ?? {});
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
async subscribe (uid, callback) {
|