@phpsandbox/sdk 0.3.3 → 0.3.5
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 +19 -0
- package/dist/beacon/index.js +4 -2
- package/dist/beacon/navigator.js +0 -1
- package/dist/beacon/types.d.ts +1 -1
- package/dist/browser/phpsandbox-sdk.esm.js +345 -287
- package/dist/browser/phpsandbox-sdk.esm.min.js +9 -9
- package/dist/browser/phpsandbox-sdk.iife.js +345 -287
- package/dist/browser/phpsandbox-sdk.iife.min.js +9 -9
- package/dist/composer.js +8 -4
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +1 -3
- package/dist/feedback.js +2 -1
- package/dist/filesystem.js +32 -15
- package/dist/identity.d.ts +13 -0
- package/dist/identity.js +6 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +17 -8
- package/dist/integrations/sandbox.js +1 -1
- package/dist/lsp.d.ts +2 -2
- package/dist/lsp.js +2 -2
- package/dist/publication/instance.js +1 -0
- package/dist/publication/notebook.js +7 -5
- package/dist/publication/resources.js +2 -1
- package/dist/publication/stream.js +36 -19
- package/dist/runtime/rest.js +2 -1
- package/dist/runtime.js +1 -1
- package/dist/schemas/publications.js +53 -59
- package/dist/servers.d.ts +31 -1
- package/dist/servers.js +34 -3
- package/dist/shell.js +5 -2
- package/dist/socket/index.js +25 -13
- package/dist/telemetry.js +8 -3
- package/dist/terminal.js +3 -4
- package/dist/utils/promise.js +1 -1
- package/dist/utils/websocket.js +2 -2
- package/package.json +44 -33
- package/dist/auth.d.ts +0 -11
- package/dist/auth.js +0 -12
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const PublicationProviderNameSchema = z.enum([
|
|
3
|
-
'cloudflare-containers',
|
|
4
|
-
'ssh-server',
|
|
5
|
-
'laravel-cloud',
|
|
6
|
-
]);
|
|
2
|
+
export const PublicationProviderNameSchema = z.enum(['cloudflare-containers', 'ssh-server', 'laravel-cloud']);
|
|
7
3
|
export const PublicationStatusSchema = z.enum([
|
|
8
4
|
'pending',
|
|
9
5
|
'queued',
|
|
@@ -16,71 +12,55 @@ export const PublicationStatusSchema = z.enum([
|
|
|
16
12
|
'deleted',
|
|
17
13
|
'delete_failed',
|
|
18
14
|
]);
|
|
19
|
-
export const PublicationBuildStatusSchema = z.enum([
|
|
20
|
-
'pending',
|
|
21
|
-
'queued',
|
|
22
|
-
'running',
|
|
23
|
-
'succeeded',
|
|
24
|
-
'failed',
|
|
25
|
-
'cancelled',
|
|
26
|
-
]);
|
|
15
|
+
export const PublicationBuildStatusSchema = z.enum(['pending', 'queued', 'running', 'succeeded', 'failed', 'cancelled']);
|
|
27
16
|
export const PublicationReleaseStatusSchema = z.enum(['created', 'ready', 'deleted']);
|
|
28
|
-
export const PublicationSizeSchema = z.enum([
|
|
29
|
-
|
|
30
|
-
'small',
|
|
31
|
-
'medium',
|
|
32
|
-
'large',
|
|
33
|
-
'lite',
|
|
34
|
-
'basic',
|
|
35
|
-
'standard-1',
|
|
36
|
-
'standard-2',
|
|
37
|
-
]);
|
|
38
|
-
export const PublicationRegionSchema = z.enum([
|
|
39
|
-
'ENAM',
|
|
40
|
-
'WNAM',
|
|
41
|
-
'EEUR',
|
|
42
|
-
'WEUR',
|
|
43
|
-
'APAC',
|
|
44
|
-
'SAM',
|
|
45
|
-
'ME',
|
|
46
|
-
'OC',
|
|
47
|
-
'AFR',
|
|
48
|
-
]);
|
|
17
|
+
export const PublicationSizeSchema = z.enum(['nano', 'small', 'medium', 'large', 'lite', 'basic', 'standard-1', 'standard-2']);
|
|
18
|
+
export const PublicationRegionSchema = z.enum(['ENAM', 'WNAM', 'EEUR', 'WEUR', 'APAC', 'SAM', 'ME', 'OC', 'AFR']);
|
|
49
19
|
export const PublicationJurisdictionSchema = z.enum(['eu', 'fedramp']);
|
|
50
20
|
export const PublicationProtectionModeSchema = z.enum(['none', 'password']);
|
|
51
21
|
export const PublicationLogStreamSchema = z.enum(['build', 'runtime']);
|
|
52
22
|
export const PublishStreamLogStreamSchema = z.enum(['build', 'publish', 'runtime']);
|
|
53
|
-
const PublicationEventPayloadSchema = z.preprocess((payload) => Array.isArray(payload) && payload.length === 0 ? {} : payload, z.record(z.string(), z.unknown()));
|
|
54
|
-
export const PublicationEventDataSchema = z
|
|
23
|
+
const PublicationEventPayloadSchema = z.preprocess((payload) => (Array.isArray(payload) && payload.length === 0 ? {} : payload), z.record(z.string(), z.unknown()));
|
|
24
|
+
export const PublicationEventDataSchema = z
|
|
25
|
+
.object({
|
|
55
26
|
id: z.union([z.number(), z.string()]).optional(),
|
|
56
27
|
sequence: z.number(),
|
|
57
28
|
type: z.string(),
|
|
58
29
|
payload: PublicationEventPayloadSchema,
|
|
59
30
|
createdAt: z.string().nullable(),
|
|
60
|
-
})
|
|
61
|
-
|
|
31
|
+
})
|
|
32
|
+
.passthrough();
|
|
33
|
+
export const PublicationLogChunkDataSchema = z
|
|
34
|
+
.object({
|
|
62
35
|
sequence: z.number(),
|
|
63
36
|
stream: PublicationLogStreamSchema,
|
|
64
37
|
content: z.string(),
|
|
65
38
|
createdAt: z.string().nullable(),
|
|
66
|
-
})
|
|
67
|
-
|
|
39
|
+
})
|
|
40
|
+
.passthrough();
|
|
41
|
+
export const PublishStreamPhaseSchema = z
|
|
42
|
+
.object({
|
|
68
43
|
name: z.string(),
|
|
69
44
|
status: z.enum(['running', 'completed', 'failed']).optional(),
|
|
70
45
|
data: z.record(z.string(), z.unknown()).optional(),
|
|
71
|
-
})
|
|
72
|
-
|
|
46
|
+
})
|
|
47
|
+
.strict();
|
|
48
|
+
export const PublishStreamLogSchema = z
|
|
49
|
+
.object({
|
|
73
50
|
stream: PublishStreamLogStreamSchema,
|
|
74
51
|
content: z.string(),
|
|
75
|
-
})
|
|
76
|
-
|
|
52
|
+
})
|
|
53
|
+
.strict();
|
|
54
|
+
export const PublishStreamResultSchema = z
|
|
55
|
+
.object({
|
|
77
56
|
success: z.boolean(),
|
|
78
57
|
publicationId: z.string(),
|
|
79
58
|
url: z.string().url(),
|
|
80
59
|
buildId: z.string(),
|
|
81
60
|
releaseId: z.string(),
|
|
82
61
|
status: PublicationStatusSchema,
|
|
83
|
-
})
|
|
62
|
+
})
|
|
63
|
+
.strict();
|
|
84
64
|
export const PublishStreamPhaseEventSchema = PublishStreamPhaseSchema.extend({
|
|
85
65
|
type: z.literal('phase'),
|
|
86
66
|
}).strict();
|
|
@@ -95,37 +75,51 @@ export const PublishStreamEventSchema = z.discriminatedUnion('type', [
|
|
|
95
75
|
PublishStreamLogEventSchema,
|
|
96
76
|
PublishStreamResultEventSchema,
|
|
97
77
|
]);
|
|
98
|
-
export const PublishStreamErrorSchema = z
|
|
78
|
+
export const PublishStreamErrorSchema = z
|
|
79
|
+
.object({
|
|
99
80
|
message: z.string().optional(),
|
|
100
|
-
})
|
|
81
|
+
})
|
|
82
|
+
.passthrough();
|
|
101
83
|
export const PublishStreamSseEventNameSchema = z.enum(['phase', 'log', 'done', 'result', 'error']);
|
|
102
|
-
export const PublishStreamSsePhaseEventSchema = z
|
|
84
|
+
export const PublishStreamSsePhaseEventSchema = z
|
|
85
|
+
.object({
|
|
103
86
|
event: z.literal('phase'),
|
|
104
87
|
data: PublishStreamPhaseSchema,
|
|
105
|
-
})
|
|
106
|
-
|
|
88
|
+
})
|
|
89
|
+
.strict();
|
|
90
|
+
export const PublishStreamSseLogEventSchema = z
|
|
91
|
+
.object({
|
|
107
92
|
event: z.literal('log'),
|
|
108
93
|
data: PublishStreamLogSchema,
|
|
109
|
-
})
|
|
110
|
-
|
|
94
|
+
})
|
|
95
|
+
.strict();
|
|
96
|
+
export const PublishStreamSseDoneEventSchema = z
|
|
97
|
+
.object({
|
|
111
98
|
event: z.literal('done'),
|
|
112
99
|
data: PublishStreamResultSchema,
|
|
113
|
-
})
|
|
114
|
-
|
|
100
|
+
})
|
|
101
|
+
.strict();
|
|
102
|
+
export const PublishStreamSseResultEventSchema = z
|
|
103
|
+
.object({
|
|
115
104
|
event: z.literal('result'),
|
|
116
105
|
data: PublishStreamResultSchema,
|
|
117
|
-
})
|
|
118
|
-
|
|
106
|
+
})
|
|
107
|
+
.strict();
|
|
108
|
+
export const PublishStreamSseErrorEventSchema = z
|
|
109
|
+
.object({
|
|
119
110
|
event: z.literal('error'),
|
|
120
111
|
data: PublishStreamErrorSchema,
|
|
121
|
-
})
|
|
122
|
-
|
|
112
|
+
})
|
|
113
|
+
.strict();
|
|
114
|
+
export const PublishStreamSseEventSchema = z
|
|
115
|
+
.discriminatedUnion('event', [
|
|
123
116
|
PublishStreamSsePhaseEventSchema,
|
|
124
117
|
PublishStreamSseLogEventSchema,
|
|
125
118
|
PublishStreamSseDoneEventSchema,
|
|
126
119
|
PublishStreamSseResultEventSchema,
|
|
127
120
|
PublishStreamSseErrorEventSchema,
|
|
128
|
-
])
|
|
121
|
+
])
|
|
122
|
+
.transform((event) => {
|
|
129
123
|
if (event.event === 'error') {
|
|
130
124
|
throw new Error(event.data.message ?? 'Publish failed');
|
|
131
125
|
}
|
package/dist/servers.d.ts
CHANGED
|
@@ -14,11 +14,22 @@ export interface ServerData {
|
|
|
14
14
|
updatedAt: string | null;
|
|
15
15
|
}
|
|
16
16
|
export interface ServerMemberData {
|
|
17
|
+
organizationId?: string | null;
|
|
17
18
|
id: number;
|
|
18
19
|
name: string;
|
|
19
20
|
email: string;
|
|
20
21
|
access: 'deployer';
|
|
21
22
|
}
|
|
23
|
+
export interface ServerInvitationData {
|
|
24
|
+
recipientOrganizationId: string | null;
|
|
25
|
+
id: string;
|
|
26
|
+
serverId: string;
|
|
27
|
+
serverName: string;
|
|
28
|
+
email: string;
|
|
29
|
+
status: 'pending' | 'accepting' | 'accepted' | 'declined' | 'cancelled' | 'expired';
|
|
30
|
+
expiresAt: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
}
|
|
22
33
|
export interface ServerSshOptions {
|
|
23
34
|
user?: string;
|
|
24
35
|
port?: number;
|
|
@@ -31,9 +42,23 @@ export interface CreateServerInput {
|
|
|
31
42
|
export interface ServerListOptions {
|
|
32
43
|
page?: number;
|
|
33
44
|
}
|
|
45
|
+
export interface ServerInvitationTarget {
|
|
46
|
+
email: string;
|
|
47
|
+
organizationId?: never;
|
|
48
|
+
requestId?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ServerOrganizationTarget {
|
|
51
|
+
organizationId: string;
|
|
52
|
+
email?: never;
|
|
53
|
+
requestId?: string;
|
|
54
|
+
}
|
|
55
|
+
export type ShareServerInput = ServerInvitationTarget | ServerOrganizationTarget;
|
|
34
56
|
export declare class ServerApi {
|
|
35
57
|
private readonly client;
|
|
36
58
|
constructor(client: Client);
|
|
59
|
+
inspectInvitation(id: string, token: string): Promise<ServerInvitationData>;
|
|
60
|
+
acceptInvitation(id: string, token: string): Promise<ServerInvitationData>;
|
|
61
|
+
declineInvitation(id: string, token: string): Promise<ServerInvitationData>;
|
|
37
62
|
list(options?: ServerListOptions): Promise<PaginatedApiResponse<ServerData>>;
|
|
38
63
|
create(input: CreateServerInput): Promise<ServerInstance>;
|
|
39
64
|
get(id: string): Promise<ServerInstance>;
|
|
@@ -46,8 +71,13 @@ export declare class ServerInstance {
|
|
|
46
71
|
installCommand: string;
|
|
47
72
|
}>;
|
|
48
73
|
members(options?: ServerListOptions): Promise<PaginatedApiResponse<ServerMemberData>>;
|
|
49
|
-
share(
|
|
74
|
+
share(target: ServerInvitationTarget): Promise<ServerInvitationData>;
|
|
75
|
+
share(target: ServerOrganizationTarget): Promise<ServerMemberData>;
|
|
76
|
+
share(target: ShareServerInput): Promise<ServerInvitationData | ServerMemberData>;
|
|
50
77
|
revokeAccess(memberId: number): Promise<void>;
|
|
78
|
+
invitations(options?: ServerListOptions): Promise<PaginatedApiResponse<ServerInvitationData>>;
|
|
79
|
+
cancelInvitation(id: string): Promise<ServerInvitationData>;
|
|
80
|
+
resendInvitation(id: string): Promise<ServerInvitationData>;
|
|
51
81
|
refresh(): Promise<ServerInstance>;
|
|
52
82
|
delete(): Promise<void>;
|
|
53
83
|
waitReady(options?: {
|
package/dist/servers.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { PHPSandboxError } from './errors/index.js';
|
|
1
2
|
export class ServerApi {
|
|
2
3
|
constructor(client) {
|
|
3
4
|
this.client = client;
|
|
4
5
|
}
|
|
6
|
+
async inspectInvitation(id, token) {
|
|
7
|
+
return (await this.client.post(`/platform/server-invitations/${encodeURIComponent(id)}/inspect`, { token })).data;
|
|
8
|
+
}
|
|
9
|
+
async acceptInvitation(id, token) {
|
|
10
|
+
return (await this.client.post(`/platform/server-invitations/${encodeURIComponent(id)}/accept`, { token })).data;
|
|
11
|
+
}
|
|
12
|
+
async declineInvitation(id, token) {
|
|
13
|
+
return (await this.client.post(`/platform/server-invitations/${encodeURIComponent(id)}/decline`, { token })).data;
|
|
14
|
+
}
|
|
5
15
|
async list(options = {}) {
|
|
6
16
|
const query = options.page === undefined ? '' : `?${new URLSearchParams({ page: String(options.page) }).toString()}`;
|
|
7
17
|
return this.client.get(`/servers${query}`);
|
|
@@ -27,12 +37,33 @@ export class ServerInstance {
|
|
|
27
37
|
const query = options.page === undefined ? '' : `?${new URLSearchParams({ page: String(options.page) }).toString()}`;
|
|
28
38
|
return this.client.get(`/servers/${encodeURIComponent(this.data.id)}/members${query}`);
|
|
29
39
|
}
|
|
30
|
-
async share(
|
|
31
|
-
|
|
40
|
+
async share(target) {
|
|
41
|
+
if (target.email !== undefined) {
|
|
42
|
+
return (await this.client.post(`/platform/servers/${encodeURIComponent(this.data.id)}/invitations`, {
|
|
43
|
+
email: target.email,
|
|
44
|
+
requestId: target.requestId ?? crypto.randomUUID(),
|
|
45
|
+
})).data;
|
|
46
|
+
}
|
|
47
|
+
const body = { organizationId: target.organizationId, requestId: target.requestId };
|
|
48
|
+
return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, body)).data;
|
|
32
49
|
}
|
|
33
50
|
async revokeAccess(memberId) {
|
|
34
51
|
await this.client.delete(`/servers/${encodeURIComponent(this.data.id)}/members/${encodeURIComponent(String(memberId))}`);
|
|
35
52
|
}
|
|
53
|
+
async invitations(options = {}) {
|
|
54
|
+
const query = options.page === undefined ? '' : `?${new URLSearchParams({ page: String(options.page) }).toString()}`;
|
|
55
|
+
return this.client.get(`/platform/servers/${encodeURIComponent(this.data.id)}/invitations${query}`);
|
|
56
|
+
}
|
|
57
|
+
async cancelInvitation(id) {
|
|
58
|
+
const response = await this.client.delete(`/platform/servers/${encodeURIComponent(this.data.id)}/invitations/${encodeURIComponent(id)}`);
|
|
59
|
+
if (response.data === undefined) {
|
|
60
|
+
throw new PHPSandboxError('Missing invitation cancellation response.');
|
|
61
|
+
}
|
|
62
|
+
return response.data;
|
|
63
|
+
}
|
|
64
|
+
async resendInvitation(id) {
|
|
65
|
+
return (await this.client.post(`/platform/servers/${encodeURIComponent(this.data.id)}/invitations/${encodeURIComponent(id)}/resend`, {})).data;
|
|
66
|
+
}
|
|
36
67
|
refresh() {
|
|
37
68
|
return this.client.servers.get(this.data.id);
|
|
38
69
|
}
|
|
@@ -51,7 +82,7 @@ export class ServerInstance {
|
|
|
51
82
|
if (server.data.status === 'failed') {
|
|
52
83
|
throw new Error(`Server provisioning failed: ${server.data.id}`);
|
|
53
84
|
}
|
|
54
|
-
await new Promise(resolve => setTimeout(resolve, interval));
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
55
86
|
}
|
|
56
87
|
throw new Error(`Server did not become ready within ${timeout}ms`);
|
|
57
88
|
}
|
package/dist/shell.js
CHANGED
|
@@ -89,10 +89,13 @@ export class ShellProcess {
|
|
|
89
89
|
stderr.fail(error);
|
|
90
90
|
};
|
|
91
91
|
const { abortSignal, ...payloadOpts } = opts;
|
|
92
|
-
this.completion = this.okra
|
|
92
|
+
this.completion = this.okra
|
|
93
|
+
.invoke('shell.exec', { command, opts: { ...payloadOpts, id: this.id } }, { abortSignal })
|
|
94
|
+
.then((result) => {
|
|
93
95
|
finish();
|
|
94
96
|
return result;
|
|
95
|
-
})
|
|
97
|
+
})
|
|
98
|
+
.catch((error) => {
|
|
96
99
|
fail(error);
|
|
97
100
|
throw error;
|
|
98
101
|
});
|
package/dist/socket/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
6
6
|
var _Transport_instances, _Transport_connect, _Transport_startPeriodicPing;
|
|
7
7
|
import { nanoid } from 'nanoid';
|
|
8
8
|
import { encode, decode } from '@msgpack/msgpack';
|
|
9
|
-
import { PromiseTimeoutError, RemoteError, SendTimeoutError, TransportError, remoteError
|
|
9
|
+
import { PromiseTimeoutError, RemoteError, SendTimeoutError, TransportError, remoteError } from '../errors/index.js';
|
|
10
10
|
import { retry } from '../utils/retry.js';
|
|
11
11
|
import * as ReconnectingWebSocketModule from 'reconnecting-websocket';
|
|
12
12
|
import { timeout } from '../utils/promise.js';
|
|
@@ -14,11 +14,21 @@ import { describeWebSocketEvent } from '../utils/websocket.js';
|
|
|
14
14
|
import WebSocket from 'isomorphic-ws';
|
|
15
15
|
import { NamedDisposable } from '../utils/disposable.js';
|
|
16
16
|
const SAFE_DEBUG_METADATA_KEYS = new Set([
|
|
17
|
-
'url',
|
|
18
|
-
'
|
|
17
|
+
'url',
|
|
18
|
+
'action',
|
|
19
|
+
'event',
|
|
20
|
+
'responseEvent',
|
|
21
|
+
'errorEvent',
|
|
22
|
+
'hasData',
|
|
23
|
+
'code',
|
|
24
|
+
'attempt',
|
|
25
|
+
'maxRetries',
|
|
26
|
+
'timeout',
|
|
27
|
+
'errorCount',
|
|
28
|
+
'byteLength',
|
|
19
29
|
]);
|
|
20
|
-
const ReconnectingWebSocket = (ReconnectingWebSocketModule
|
|
21
|
-
?? ReconnectingWebSocketModule);
|
|
30
|
+
const ReconnectingWebSocket = (ReconnectingWebSocketModule
|
|
31
|
+
.default ?? ReconnectingWebSocketModule);
|
|
22
32
|
export var SocketEvent;
|
|
23
33
|
(function (SocketEvent) {
|
|
24
34
|
SocketEvent["BootError"] = "Events.BootError";
|
|
@@ -66,9 +76,7 @@ export class Transport {
|
|
|
66
76
|
// Validate configuration
|
|
67
77
|
this.validateConfiguration(options);
|
|
68
78
|
this.url = typeof url === 'string' ? new URL(url) : null;
|
|
69
|
-
const urlProvider = typeof url === 'string'
|
|
70
|
-
? new URL(url).toString()
|
|
71
|
-
: async () => new URL(await url()).toString();
|
|
79
|
+
const urlProvider = typeof url === 'string' ? new URL(url).toString() : async () => new URL(await url()).toString();
|
|
72
80
|
// Use configurable ping interval
|
|
73
81
|
this.PING_INTERVAL = options.pingInterval ?? 30000;
|
|
74
82
|
this.CONNECT_WAIT_TIMEOUT = options.connectWaitTimeout ?? 30000;
|
|
@@ -127,7 +135,7 @@ export class Transport {
|
|
|
127
135
|
id() {
|
|
128
136
|
return this.clientId;
|
|
129
137
|
}
|
|
130
|
-
|
|
138
|
+
registerWatchers() {
|
|
131
139
|
const onMessage = (ev) => {
|
|
132
140
|
this.incomingMessageChain = this.incomingMessageChain
|
|
133
141
|
.catch(() => undefined)
|
|
@@ -306,7 +314,9 @@ export class Transport {
|
|
|
306
314
|
this.eventEmitter.emit(event, this.clientId);
|
|
307
315
|
return;
|
|
308
316
|
}
|
|
309
|
-
|
|
317
|
+
if (event) {
|
|
318
|
+
this.eventEmitter.emit(as || event, data);
|
|
319
|
+
}
|
|
310
320
|
}
|
|
311
321
|
listen(event, listener, _context) {
|
|
312
322
|
return this.eventEmitter.listen(event, listener);
|
|
@@ -437,14 +447,16 @@ export class Transport {
|
|
|
437
447
|
if (!options.timeout) {
|
|
438
448
|
return promise;
|
|
439
449
|
}
|
|
440
|
-
return timeout(promise, options.timeout)
|
|
450
|
+
return timeout(promise, options.timeout)
|
|
451
|
+
.catch((error) => {
|
|
441
452
|
if (error instanceof PromiseTimeoutError) {
|
|
442
453
|
throw SendTimeoutError.fromPromiseTimeoutError(error);
|
|
443
454
|
}
|
|
444
455
|
throw error;
|
|
445
|
-
})
|
|
456
|
+
})
|
|
457
|
+
.finally(removeListeners);
|
|
446
458
|
};
|
|
447
|
-
const retries = options.retries === false ? 0 : options.retries ?? 0;
|
|
459
|
+
const retries = options.retries === false ? 0 : (options.retries ?? 0);
|
|
448
460
|
return this.sendWithRetry(async () => await send(), retries);
|
|
449
461
|
}
|
|
450
462
|
send(action, data = {}) {
|
package/dist/telemetry.js
CHANGED
|
@@ -40,7 +40,9 @@ export class RuntimeTelemetry {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
synchronize() {
|
|
43
|
-
this.synchronization = this.synchronization
|
|
43
|
+
this.synchronization = this.synchronization
|
|
44
|
+
.catch(() => { })
|
|
45
|
+
.then(async () => {
|
|
44
46
|
const features = Array.from(this.references.keys());
|
|
45
47
|
if (features.length === 0) {
|
|
46
48
|
await this.okra.invoke('container.stop-telemetry');
|
|
@@ -88,13 +90,16 @@ export function watchRuntimeTelemetry(okra, telemetry, feature, event, transform
|
|
|
88
90
|
}
|
|
89
91
|
options.signal.addEventListener('abort', abort, { once: true });
|
|
90
92
|
}
|
|
91
|
-
void telemetry
|
|
93
|
+
void telemetry
|
|
94
|
+
.acquire(feature)
|
|
95
|
+
.then(async (releaseTelemetry) => {
|
|
92
96
|
if (closed) {
|
|
93
97
|
await releaseTelemetry();
|
|
94
98
|
return;
|
|
95
99
|
}
|
|
96
100
|
release = releaseTelemetry;
|
|
97
|
-
})
|
|
101
|
+
})
|
|
102
|
+
.catch((error) => {
|
|
98
103
|
if (!closed) {
|
|
99
104
|
closed = true;
|
|
100
105
|
subscription?.dispose();
|
package/dist/terminal.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { nanoid } from 'nanoid';
|
|
2
2
|
import { once } from './utils/promise.js';
|
|
3
3
|
const TERMINAL_INPUT_FLUSH_DELAY_MS = 8;
|
|
4
|
+
// eslint-disable-next-line no-control-regex -- Terminal control bytes intentionally trigger an immediate flush.
|
|
4
5
|
const terminalInputFlushPattern = /[\x00-\x1f\x7f]/;
|
|
5
6
|
export default class Terminals {
|
|
6
7
|
constructor(okra) {
|
|
@@ -12,9 +13,7 @@ export default class Terminals {
|
|
|
12
13
|
async create(options = {}) {
|
|
13
14
|
const id = options.id ?? nanoid();
|
|
14
15
|
const handle = this.processHandle(id, options.abortSignal);
|
|
15
|
-
const command = typeof options.command === 'string' && options.args?.length
|
|
16
|
-
? [options.command, ...options.args]
|
|
17
|
-
: options.command;
|
|
16
|
+
const command = typeof options.command === 'string' && options.args?.length ? [options.command, ...options.args] : options.command;
|
|
18
17
|
const { abortSignal, args: _args, ...input } = options;
|
|
19
18
|
try {
|
|
20
19
|
const task = await this.okra.invoke('terminal.create', {
|
|
@@ -135,7 +134,7 @@ export default class Terminals {
|
|
|
135
134
|
return this.okra.invoke('terminal.close', { id });
|
|
136
135
|
});
|
|
137
136
|
const resize = (dimensions) => {
|
|
138
|
-
this.okra.invoke('terminal.resize', { id, width: dimensions.cols, height: dimensions.rows });
|
|
137
|
+
return this.okra.invoke('terminal.resize', { id, width: dimensions.cols, height: dimensions.rows });
|
|
139
138
|
};
|
|
140
139
|
if (abortSignal && !abortSignal.aborted) {
|
|
141
140
|
abortHandler = () => {
|
package/dist/utils/promise.js
CHANGED
package/dist/utils/websocket.js
CHANGED
|
@@ -2,12 +2,12 @@ const getReadyStateLabel = (state) => {
|
|
|
2
2
|
if (typeof state !== 'number') {
|
|
3
3
|
return undefined;
|
|
4
4
|
}
|
|
5
|
-
return {
|
|
5
|
+
return ({
|
|
6
6
|
0: 'CONNECTING',
|
|
7
7
|
1: 'OPEN',
|
|
8
8
|
2: 'CLOSING',
|
|
9
9
|
3: 'CLOSED',
|
|
10
|
-
}[state] ?? `STATE_${state}
|
|
10
|
+
}[state] ?? `STATE_${state}`);
|
|
11
11
|
};
|
|
12
12
|
const sanitizeWebSocketUrl = (value) => {
|
|
13
13
|
try {
|
package/package.json
CHANGED
|
@@ -1,11 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phpsandbox/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "The TypeScript SDK for PHPSandbox cloud development environments",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cloud",
|
|
7
|
+
"composer",
|
|
8
|
+
"development",
|
|
9
|
+
"laravel",
|
|
10
|
+
"php",
|
|
11
|
+
"sandbox",
|
|
12
|
+
"sdk",
|
|
13
|
+
"typescript"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/phpsandbox/sdk#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/phpsandbox/sdk/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "PHPSandbox",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/phpsandbox/sdk.git"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
5
31
|
"main": "./dist/index.js",
|
|
6
32
|
"module": "./dist/index.js",
|
|
7
33
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"
|
|
34
|
+
"unpkg": "./dist/browser/phpsandbox-sdk.iife.min.js",
|
|
35
|
+
"jsdelivr": "./dist/browser/phpsandbox-sdk.esm.min.js",
|
|
9
36
|
"exports": {
|
|
10
37
|
".": {
|
|
11
38
|
"types": "./dist/index.d.ts",
|
|
@@ -23,13 +50,6 @@
|
|
|
23
50
|
"default": "./dist/beacon/index.js"
|
|
24
51
|
}
|
|
25
52
|
},
|
|
26
|
-
"files": [
|
|
27
|
-
"dist",
|
|
28
|
-
"README.md",
|
|
29
|
-
"LICENSE"
|
|
30
|
-
],
|
|
31
|
-
"unpkg": "./dist/browser/phpsandbox-sdk.iife.min.js",
|
|
32
|
-
"jsdelivr": "./dist/browser/phpsandbox-sdk.esm.min.js",
|
|
33
53
|
"scripts": {
|
|
34
54
|
"build": "npm run build:tsc && npm run build:browser",
|
|
35
55
|
"build:tsc": "tsc",
|
|
@@ -46,30 +66,15 @@
|
|
|
46
66
|
"smoke:reaper": "npm run build:tsc && vitest run --reporter=verbose --config tests/smoke/vitest.config.ts tests/smoke/maintenance/resources.reaper.smoke.ts",
|
|
47
67
|
"smoke:typecheck": "npm run build:tsc && tsc --project tests/smoke/tsconfig.json --noEmit",
|
|
48
68
|
"prepublishOnly": "npm test && npm run clean && npm run build",
|
|
49
|
-
"bumpAndPublish": "npm version patch && npm publish --access public"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"laravel",
|
|
59
|
-
"composer"
|
|
60
|
-
],
|
|
61
|
-
"author": "PHPSandbox",
|
|
62
|
-
"license": "MIT",
|
|
63
|
-
"repository": {
|
|
64
|
-
"type": "git",
|
|
65
|
-
"url": "git+https://github.com/phpsandbox/sdk.git"
|
|
66
|
-
},
|
|
67
|
-
"bugs": {
|
|
68
|
-
"url": "https://github.com/phpsandbox/sdk/issues"
|
|
69
|
-
},
|
|
70
|
-
"homepage": "https://github.com/phpsandbox/sdk#readme",
|
|
71
|
-
"engines": {
|
|
72
|
-
"node": ">=18.0.0"
|
|
69
|
+
"bumpAndPublish": "npm version patch && npm publish --access public",
|
|
70
|
+
"lint": "oxlint --type-aware .",
|
|
71
|
+
"lint:fix": "oxlint --type-aware --fix .",
|
|
72
|
+
"format": "oxfmt --write src tests package.json tsconfig.json vitest.config.ts build.mjs .oxfmtrc.json .oxlintrc.json",
|
|
73
|
+
"format:check": "oxfmt --check src tests package.json tsconfig.json vitest.config.ts build.mjs .oxfmtrc.json .oxlintrc.json",
|
|
74
|
+
"typecheck": "tsc --noEmit",
|
|
75
|
+
"check": "npm run lint && npm run format:check && npm run typecheck && npm run smoke:typecheck && npm test && npm run build && npm pack --dry-run",
|
|
76
|
+
"prelint": "npm run build:tsc",
|
|
77
|
+
"prelint:fix": "npm run build:tsc"
|
|
73
78
|
},
|
|
74
79
|
"dependencies": {
|
|
75
80
|
"@msgpack/msgpack": "^3.1.1",
|
|
@@ -85,8 +90,14 @@
|
|
|
85
90
|
"@types/ws": "^8.18.1",
|
|
86
91
|
"axios": "^1.17.0",
|
|
87
92
|
"esbuild": "^0.27.1",
|
|
93
|
+
"oxfmt": "0.71.0",
|
|
94
|
+
"oxlint": "1.86.0",
|
|
95
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
88
96
|
"playwright": "^1.62.1",
|
|
89
97
|
"typescript": "^5.7.2",
|
|
90
98
|
"vitest": "^4.1.11"
|
|
99
|
+
},
|
|
100
|
+
"engines": {
|
|
101
|
+
"node": ">=18.0.0"
|
|
91
102
|
}
|
|
92
103
|
}
|
package/dist/auth.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Action, NotebookInstance } from './index.js';
|
|
2
|
-
export interface AuthActions {
|
|
3
|
-
'auth.login': Action<{
|
|
4
|
-
runtimeTicket: string;
|
|
5
|
-
}, boolean>;
|
|
6
|
-
}
|
|
7
|
-
export default class Auth {
|
|
8
|
-
protected okra: NotebookInstance;
|
|
9
|
-
constructor(okra: NotebookInstance);
|
|
10
|
-
login(runtimeUrl: string): Promise<boolean>;
|
|
11
|
-
}
|
package/dist/auth.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export default class Auth {
|
|
2
|
-
constructor(okra) {
|
|
3
|
-
this.okra = okra;
|
|
4
|
-
}
|
|
5
|
-
login(runtimeUrl) {
|
|
6
|
-
const runtimeTicket = new URL(runtimeUrl).searchParams.get('ticket');
|
|
7
|
-
if (runtimeTicket === null || runtimeTicket === '') {
|
|
8
|
-
throw new TypeError('The notebook connection does not contain a runtime ticket.');
|
|
9
|
-
}
|
|
10
|
-
return this.okra.invoke('auth.login', { runtimeTicket });
|
|
11
|
-
}
|
|
12
|
-
}
|