@phpsandbox/sdk 0.3.4 → 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.
@@ -1,4 +1,4 @@
1
- export type RemoteErrorSource = 'core' | 'runtime';
1
+ export type RemoteErrorSource = 'core' | 'platform' | 'runtime';
2
2
  declare const remoteErrorCodes: readonly ["ActionNotFound", "AuthenticationRequired", "BadGateway", "BadRequest", "Conflict", "FileAlreadyExists", "FileIsDirectory", "FileNotDirectory", "FileNotFound", "FilesystemUnavailable", "InternalError", "InvalidArgument", "InvalidConfiguration", "InvalidRequest", "InvalidResponse", "InvalidServiceCommand", "MethodNotAllowed", "NotebookInitializationFailed", "NotebookUnavailable", "NotFound", "PayloadTooLarge", "PermissionDenied", "RateLimited", "RequestFailed", "RuntimeOperationFailed", "ServiceNotFound", "ServiceUnavailable", "UnprocessableEntity", "ValidationFailed", "WorkspaceUnavailable"];
3
3
  export type RemoteErrorCode = (typeof remoteErrorCodes)[number];
4
4
  export type TransportErrorCode = 'ConnectionFailed' | 'ConnectionTimeout' | 'InvalidResponse' | 'SendTimeout';
package/dist/index.d.ts CHANGED
@@ -35,7 +35,7 @@ export type { ConfigPortMapping, ProjectConfig } from './config.js';
35
35
  export { PHPSandboxError, RemoteError, TransportError } from './errors/index.js';
36
36
  export type { HttpResponseDiagnostics, RemoteErrorCode, RemoteErrorSource, TransportErrorCode, ValidationErrorDetails, } from './errors/index.js';
37
37
  export * from './publication/index.js';
38
- export type { CreateServerInput, ServerData, ServerInstance, ServerListOptions, ServerMemberData, ServerSshOptions, } from './servers.js';
38
+ export type { CreateServerInput, ServerData, ServerInstance, ServerListOptions, ServerMemberData, ServerInvitationData, ServerInvitationTarget, ServerOrganizationTarget, ShareServerInput, ServerSshOptions, } from './servers.js';
39
39
  export type { ConfigureFeedbackInput, FeedbackData, FeedbackListOptions, FeedbackSource, FeedbackStatus, FeedbackType, FeedbackWidgetConfig, FeedbackWidgetTarget, SubmitFeedbackInput, UpdateFeedbackInput, } from './feedback.js';
40
40
  export type { Integration, IntegrationAuthorization, IntegrationAuthorizationType, IntegrationData, IntegrationProvider, IntegrationReference, LinkIntegrationInput, UpdateIntegrationInput, AttachSandboxIntegrationInput, SandboxIntegration, SandboxIntegrationData, SandboxIntegrationEffect, SandboxIntegrationReference, UpdateSandboxIntegrationInput, } from './integrations/index.js';
41
41
  interface Result<TType extends 'success' | 'error' | 'running', TData extends object> {
package/dist/index.js CHANGED
@@ -157,7 +157,7 @@ class ClientImplementation {
157
157
  headers: this.headers,
158
158
  }));
159
159
  if (!response.ok) {
160
- throw await responseError(response);
160
+ throw await responseError(response, path.startsWith('/platform/') ? 'platform' : 'core');
161
161
  }
162
162
  if (response.status === 204) {
163
163
  return { data: undefined };
@@ -195,10 +195,10 @@ class ClientImplementation {
195
195
  }
196
196
  }
197
197
  }
198
- async function responseError(response) {
198
+ async function responseError(response, source = 'core') {
199
199
  const body = await response.text();
200
200
  try {
201
- return remoteError('core', errorPayload(body === '' ? undefined : JSON.parse(body)), response);
201
+ return remoteError(source, errorPayload(body === '' ? undefined : JSON.parse(body)), response);
202
202
  }
203
203
  catch {
204
204
  return new TransportError(`PHPSandbox API returned an invalid error response (HTTP ${response.status}).`, 'InvalidResponse', response, {
package/dist/servers.d.ts CHANGED
@@ -20,6 +20,16 @@ export interface ServerMemberData {
20
20
  email: string;
21
21
  access: 'deployer';
22
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
+ }
23
33
  export interface ServerSshOptions {
24
34
  user?: string;
25
35
  port?: number;
@@ -32,9 +42,23 @@ export interface CreateServerInput {
32
42
  export interface ServerListOptions {
33
43
  page?: number;
34
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;
35
56
  export declare class ServerApi {
36
57
  private readonly client;
37
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>;
38
62
  list(options?: ServerListOptions): Promise<PaginatedApiResponse<ServerData>>;
39
63
  create(input: CreateServerInput): Promise<ServerInstance>;
40
64
  get(id: string): Promise<ServerInstance>;
@@ -47,9 +71,13 @@ export declare class ServerInstance {
47
71
  installCommand: string;
48
72
  }>;
49
73
  members(options?: ServerListOptions): Promise<PaginatedApiResponse<ServerMemberData>>;
50
- share(email: string): Promise<ServerMemberData>;
51
- shareWithOrganization(organizationId: string): Promise<ServerMemberData>;
74
+ share(target: ServerInvitationTarget): Promise<ServerInvitationData>;
75
+ share(target: ServerOrganizationTarget): Promise<ServerMemberData>;
76
+ share(target: ShareServerInput): Promise<ServerInvitationData | ServerMemberData>;
52
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>;
53
81
  refresh(): Promise<ServerInstance>;
54
82
  delete(): Promise<void>;
55
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,16 +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(email) {
31
- return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { email })).data;
32
- }
33
- async shareWithOrganization(organizationId) {
34
- return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { organizationId }))
35
- .data;
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;
36
49
  }
37
50
  async revokeAccess(memberId) {
38
51
  await this.client.delete(`/servers/${encodeURIComponent(this.data.id)}/members/${encodeURIComponent(String(memberId))}`);
39
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
+ }
40
67
  refresh() {
41
68
  return this.client.servers.get(this.data.id);
42
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phpsandbox/sdk",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "The TypeScript SDK for PHPSandbox cloud development environments",
5
5
  "keywords": [
6
6
  "cloud",