@phpsandbox/sdk 0.1.10 → 0.1.11

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/http.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Cloudflare Workers does not support `redirect: "error"`, while `follow` can
3
+ * forward authorization headers across redirects. Handle redirects manually so
4
+ * authenticated requests never follow them.
5
+ */
6
+ export declare function authenticatedRequest(input: URL | string, init: RequestInit): Request;
package/dist/http.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Cloudflare Workers does not support `redirect: "error"`, while `follow` can
3
+ * forward authorization headers across redirects. Handle redirects manually so
4
+ * authenticated requests never follow them.
5
+ */
6
+ export function authenticatedRequest(input, init) {
7
+ return new Request(input, {
8
+ ...init,
9
+ redirect: 'manual',
10
+ });
11
+ }
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ import { RestRuntimeInvoker } from './runtime/rest.js';
30
30
  import { Feedback } from './feedback.js';
31
31
  import { IntegrationApi } from './integrations.js';
32
32
  import { SandboxIntegrationApi } from './sandbox-integrations.js';
33
+ import { authenticatedRequest } from './http.js';
33
34
  export { LspConnection } from './lsp.js';
34
35
  export { FileChangeFilter, FileChangeType, FileType, } from './filesystem.js';
35
36
  export { notebookBuiltinServices, notebookKnownServices } from './services.js';
@@ -105,10 +106,9 @@ class ClientImplementation {
105
106
  return this.makeRequest('PATCH', path, { body: body === undefined ? undefined : JSON.stringify(body) });
106
107
  }
107
108
  async stream(path) {
108
- const response = await this.fetchResponse(new Request(new URL(path.replace(/^\//, ''), this.baseUrl), {
109
+ const response = await this.fetchResponse(authenticatedRequest(new URL(path.replace(/^\//, ''), this.baseUrl), {
109
110
  method: 'GET',
110
111
  headers: this.headers,
111
- redirect: 'error',
112
112
  }));
113
113
  if (!response.ok) {
114
114
  throw remoteError('core', errorPayload(await responsePayload(response)), response);
@@ -119,9 +119,8 @@ class ClientImplementation {
119
119
  return response.body;
120
120
  }
121
121
  async sse(url) {
122
- const response = await this.fetchResponse(new Request(url, {
122
+ const response = await this.fetchResponse(authenticatedRequest(url, {
123
123
  method: 'GET',
124
- redirect: 'error',
125
124
  headers: {
126
125
  ...this.headers,
127
126
  'Accept': 'text/event-stream',
@@ -136,11 +135,10 @@ class ClientImplementation {
136
135
  return response.body;
137
136
  }
138
137
  async makeRequest(method, path, init) {
139
- const response = await this.fetchResponse(new Request(new URL(path.replace(/^\//, ''), this.baseUrl), {
138
+ const response = await this.fetchResponse(authenticatedRequest(new URL(path.replace(/^\//, ''), this.baseUrl), {
140
139
  method,
141
140
  ...init,
142
141
  headers: this.headers,
143
- redirect: 'error',
144
142
  }));
145
143
  if (!response.ok) {
146
144
  throw remoteError('core', errorPayload(await responsePayload(response)), response);
@@ -1,4 +1,5 @@
1
1
  import { PHPSandboxError, RemoteError, TransportError, remoteError } from '../errors/index.js';
2
+ import { authenticatedRequest } from '../http.js';
2
3
  const restActionRoutes = {
3
4
  'runtime.ready': { method: 'GET', path: '/runtime' },
4
5
  'config.get': { method: 'GET', path: '/runtime/config' },
@@ -119,12 +120,11 @@ export class RestRuntimeInvoker {
119
120
  Authorization: `Bearer ${this.ticket}`,
120
121
  };
121
122
  const body = runtimeActionRequestBody(action, data, url, headers);
122
- return new Request(url, {
123
+ return authenticatedRequest(url, {
123
124
  method: route.method,
124
125
  headers,
125
126
  body: route.method === 'GET' ? undefined : body,
126
127
  signal,
127
- redirect: 'error',
128
128
  });
129
129
  }
130
130
  async refreshAuthorization() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phpsandbox/sdk",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "A comprehensive TypeScript SDK for interacting with cloud-based PHP development environments",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",