@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.
package/README.md CHANGED
@@ -55,6 +55,25 @@ PHPSandbox.rest('token', 'https://api.phpsandbox.io/v1', {
55
55
  });
56
56
  ```
57
57
 
58
+ ## Server invitations
59
+
60
+ Server administrators can invite someone by email and inspect the shared invitation state:
61
+
62
+ ```typescript
63
+ const server = await client.servers.get('SERVER_ID');
64
+ const invitation = await server.share({ email: 'person@example.com', requestId: crypto.randomUUID() });
65
+ const invitations = await server.invitations();
66
+
67
+ // The recipient uses their own workspace credential and the proof from their invitation link.
68
+ await recipientClient.servers.acceptInvitation(invitation.id, invitationProof);
69
+ ```
70
+
71
+ Keep the same `requestId` when retrying creation. Use `client.servers.inspectInvitation()`, `acceptInvitation()` and `declineInvitation()` to respond, and `server.resendInvitation()` or `cancelInvitation()` to manage pending invitations. An `accepting` status means access confirmation is still in progress; retry acceptance with the same recipient workspace.
72
+
73
+ For an immediate grant to an existing workspace, use `server.share({ organizationId: 'WORKSPACE_ID', requestId })`.
74
+
75
+ Invitation operations use the same API base URL and credential as all other operations. No additional endpoint configuration is required.
76
+
58
77
  ## Notebook Lifecycle
59
78
 
60
79
  ```ts
@@ -19676,6 +19676,15 @@ var ServerApi = class {
19676
19676
  constructor(client) {
19677
19677
  this.client = client;
19678
19678
  }
19679
+ async inspectInvitation(id, token) {
19680
+ return (await this.client.post(`/platform/server-invitations/${encodeURIComponent(id)}/inspect`, { token })).data;
19681
+ }
19682
+ async acceptInvitation(id, token) {
19683
+ return (await this.client.post(`/platform/server-invitations/${encodeURIComponent(id)}/accept`, { token })).data;
19684
+ }
19685
+ async declineInvitation(id, token) {
19686
+ return (await this.client.post(`/platform/server-invitations/${encodeURIComponent(id)}/decline`, { token })).data;
19687
+ }
19679
19688
  async list(options = {}) {
19680
19689
  const query = options.page === void 0 ? "" : `?${new URLSearchParams({ page: String(options.page) }).toString()}`;
19681
19690
  return this.client.get(`/servers${query}`);
@@ -19701,17 +19710,40 @@ var ServerInstance = class {
19701
19710
  const query = options.page === void 0 ? "" : `?${new URLSearchParams({ page: String(options.page) }).toString()}`;
19702
19711
  return this.client.get(`/servers/${encodeURIComponent(this.data.id)}/members${query}`);
19703
19712
  }
19704
- async share(email3) {
19705
- return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { email: email3 })).data;
19706
- }
19707
- async shareWithOrganization(organizationId) {
19708
- return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { organizationId })).data;
19713
+ async share(target) {
19714
+ if (target.email !== void 0) {
19715
+ return (await this.client.post(`/platform/servers/${encodeURIComponent(this.data.id)}/invitations`, {
19716
+ email: target.email,
19717
+ requestId: target.requestId ?? crypto.randomUUID()
19718
+ })).data;
19719
+ }
19720
+ const body = { organizationId: target.organizationId, requestId: target.requestId };
19721
+ return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, body)).data;
19709
19722
  }
19710
19723
  async revokeAccess(memberId) {
19711
19724
  await this.client.delete(
19712
19725
  `/servers/${encodeURIComponent(this.data.id)}/members/${encodeURIComponent(String(memberId))}`
19713
19726
  );
19714
19727
  }
19728
+ async invitations(options = {}) {
19729
+ const query = options.page === void 0 ? "" : `?${new URLSearchParams({ page: String(options.page) }).toString()}`;
19730
+ return this.client.get(`/platform/servers/${encodeURIComponent(this.data.id)}/invitations${query}`);
19731
+ }
19732
+ async cancelInvitation(id) {
19733
+ const response = await this.client.delete(
19734
+ `/platform/servers/${encodeURIComponent(this.data.id)}/invitations/${encodeURIComponent(id)}`
19735
+ );
19736
+ if (response.data === void 0) {
19737
+ throw new PHPSandboxError("Missing invitation cancellation response.");
19738
+ }
19739
+ return response.data;
19740
+ }
19741
+ async resendInvitation(id) {
19742
+ return (await this.client.post(
19743
+ `/platform/servers/${encodeURIComponent(this.data.id)}/invitations/${encodeURIComponent(id)}/resend`,
19744
+ {}
19745
+ )).data;
19746
+ }
19715
19747
  refresh() {
19716
19748
  return this.client.servers.get(this.data.id);
19717
19749
  }
@@ -20250,7 +20282,7 @@ var ClientImplementation = class {
20250
20282
  })
20251
20283
  );
20252
20284
  if (!response.ok) {
20253
- throw await responseError(response);
20285
+ throw await responseError(response, path.startsWith("/platform/") ? "platform" : "core");
20254
20286
  }
20255
20287
  if (response.status === 204) {
20256
20288
  return { data: void 0 };
@@ -20283,10 +20315,10 @@ var ClientImplementation = class {
20283
20315
  }
20284
20316
  }
20285
20317
  };
20286
- async function responseError(response) {
20318
+ async function responseError(response, source = "core") {
20287
20319
  const body = await response.text();
20288
20320
  try {
20289
- return remoteError("core", errorPayload(body === "" ? void 0 : JSON.parse(body)), response);
20321
+ return remoteError(source, errorPayload(body === "" ? void 0 : JSON.parse(body)), response);
20290
20322
  } catch {
20291
20323
  return new TransportError(
20292
20324
  `PHPSandbox API returned an invalid error response (HTTP ${response.status}).`,