@phpsandbox/sdk 0.1.12 → 0.1.14

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.
Files changed (38) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +7 -18
  3. package/dist/browser/phpsandbox-sdk.esm.js +7 -3
  4. package/dist/browser/phpsandbox-sdk.esm.min.js +7 -7
  5. package/dist/browser/phpsandbox-sdk.iife.js +7 -3
  6. package/dist/browser/phpsandbox-sdk.iife.min.js +7 -7
  7. package/dist/index.d.ts +21 -5
  8. package/dist/index.js +5 -2
  9. package/dist/{integrations.d.ts → integrations/account.d.ts} +1 -1
  10. package/dist/integrations/index.d.ts +2 -0
  11. package/dist/integrations/index.js +2 -0
  12. package/dist/{sandbox-integrations.d.ts → integrations/sandbox.d.ts} +2 -2
  13. package/dist/{sandbox-integrations.js → integrations/sandbox.js} +1 -1
  14. package/dist/log.d.ts +1 -1
  15. package/dist/log.js +1 -1
  16. package/dist/metrics.d.ts +1 -1
  17. package/dist/metrics.js +1 -1
  18. package/dist/ports.d.ts +1 -1
  19. package/dist/ports.js +1 -1
  20. package/dist/runtime.d.ts +1 -1
  21. package/dist/runtime.js +1 -1
  22. package/package.json +5 -9
  23. package/docs/api-summary.md +0 -181
  24. package/docs/cdn-usage.md +0 -68
  25. package/docs/getting-started.md +0 -169
  26. package/examples/README.md +0 -203
  27. package/examples/basic.ts +0 -15
  28. package/examples/get.ts +0 -22
  29. package/examples/git-merge-smoke.ts +0 -395
  30. package/examples/laravel-load-test.ts +0 -2800
  31. package/examples/notebook-readonly-smoke.ts +0 -806
  32. package/examples/publication-provider-label.ts +0 -11
  33. package/examples/publish-cloudflare-container.ts +0 -65
  34. package/examples/publish-laravel-cloud.ts +0 -123
  35. package/examples/publish-ssh-agent.ts +0 -211
  36. /package/dist/{integrations.js → integrations/account.js} +0 -0
  37. /package/dist/{runtime-telemetry.d.ts → telemetry.d.ts} +0 -0
  38. /package/dist/{runtime-telemetry.js → telemetry.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -15,15 +15,14 @@ import { RemoteError } from './errors/index.js';
15
15
  import { PublicationApi, PublicationInstance, PublicationRun, type PublishInput } from './publications.js';
16
16
  import { ServerApi } from './servers.js';
17
17
  import { Feedback } from './feedback.js';
18
- import { IntegrationApi } from './integrations.js';
19
- import { SandboxIntegrationApi } from './sandbox-integrations.js';
18
+ import { IntegrationApi, SandboxIntegrationApi } from './integrations/index.js';
20
19
  export type { Disposable } from './types.js';
21
20
  export { LspConnection } from './lsp.js';
22
21
  export { FileChangeFilter, FileChangeType, FileType, } from './filesystem.js';
23
22
  export type { FileChange, FileContents, FileDeleteOptions, FileDownloadOptions, FileFollowOptions, FileLineRange, FileLineRangeResult, FileListOptions, FileOverwriteOptions, FileResult, FileSearchOptions, FileTailOptions, FileWriteOptions, Filesystem, Stats, TextSearchMatch, TextSearchOptions, TextSearchQuery, TextSearchResult, WatchOptions, } from './filesystem.js';
24
23
  export type { PortInfo } from './runtime.js';
25
24
  export type { RuntimeLogEntry } from './log.js';
26
- export type { RuntimeWatchOptions } from './runtime-telemetry.js';
25
+ export type { RuntimeWatchOptions } from './telemetry.js';
27
26
  export type { RuntimeResourceUsage, RuntimeStats } from './runtime.js';
28
27
  export type { ProcessOutputChunk, ProcessOutputSource, ProcessResult, ShellProcess } from './shell.js';
29
28
  export type { SandboxProcess, SpawnOptions, Task, TerminalOptions } from './terminal.js';
@@ -36,8 +35,7 @@ export type { RemoteErrorCode, RemoteErrorSource, TransportErrorCode, Validation
36
35
  export type { BuiltInPublicationProviderName, CloudflareContainersProviderOptions, LaravelCloudProviderData, LaravelCloudProviderInput, LaravelCloudRegion, PublicationBuildData, PublicationBuildStatus, PublicationData, PublicationEventData, PublicationInstance, PublicationJurisdiction, PublicationLogChunkData, PublicationLogStream, PublicationPlacement, PublicationProtectionData, PublicationProtectionInput, PublicationProtectionMode, PublicationProtectionSessionData, PublicationProvider, PublicationProviderData, PublicationProviderInput, PublicationProviderInputs, PublicationProviderName, PublicationRegion, PublicationReleaseData, PublicationReleaseStatus, PublicationRun, PublicationSize, PublicationStatus, PublishInput, PublishStreamEvent, PublishStreamLog, PublishStreamPhase, PublishStreamResult, PublishStreamSseEvent, SshServerProviderOptions, UpdatePublicationProtectionInput, } from './publications.js';
37
36
  export type { CreateServerInput, ServerData, ServerInstance, ServerListOptions, ServerSshOptions } from './servers.js';
38
37
  export type { ConfigureFeedbackInput, FeedbackData, FeedbackListOptions, FeedbackSource, FeedbackStatus, FeedbackType, FeedbackWidgetConfig, FeedbackWidgetTarget, SubmitFeedbackInput, UpdateFeedbackInput, } from './feedback.js';
39
- export type { Integration, IntegrationAuthorization, IntegrationAuthorizationType, IntegrationData, IntegrationProvider, IntegrationReference, LinkIntegrationInput, UpdateIntegrationInput, } from './integrations.js';
40
- export type { AttachSandboxIntegrationInput, SandboxIntegration, SandboxIntegrationData, SandboxIntegrationEffect, SandboxIntegrationReference, UpdateSandboxIntegrationInput, } from './sandbox-integrations.js';
38
+ export type { Integration, IntegrationAuthorization, IntegrationAuthorizationType, IntegrationData, IntegrationProvider, IntegrationReference, LinkIntegrationInput, UpdateIntegrationInput, AttachSandboxIntegrationInput, SandboxIntegration, SandboxIntegrationData, SandboxIntegrationEffect, SandboxIntegrationReference, UpdateSandboxIntegrationInput, } from './integrations/index.js';
41
39
  interface Result<TType extends 'success' | 'error' | 'running', TData extends object> {
42
40
  type: TType;
43
41
  message: string;
@@ -108,8 +106,24 @@ export interface CreateNotebookImportInput {
108
106
  provider: 'github';
109
107
  repo: string;
110
108
  branch?: string;
109
+ ref?: string;
111
110
  auth: CreateNotebookImportAuthInput;
112
111
  }
112
+ export type InspectNotebookImportInput = CreateNotebookImportInput;
113
+ export interface NotebookImportRequiredSecret {
114
+ name: string;
115
+ description: string | null;
116
+ }
117
+ export interface NotebookImportInspectionData {
118
+ supported: boolean;
119
+ repository: string;
120
+ branch: string;
121
+ ref: string;
122
+ framework: 'laravel' | 'adonisjs' | 'custom' | null;
123
+ template: string | null;
124
+ reason: string | null;
125
+ requiredSecrets: NotebookImportRequiredSecret[];
126
+ }
113
127
  export interface NotebookLifecycleInput {
114
128
  persistent?: true;
115
129
  }
@@ -118,6 +132,7 @@ export interface CreateNotebookInput extends NotebookLifecycleInput {
118
132
  visibility: 'public' | 'private' | 'unlisted';
119
133
  import?: CreateNotebookImportInput;
120
134
  composerCredentials?: ComposerCredentialInput[];
135
+ secrets?: UpsertNotebookSecretItemInput[];
121
136
  }
122
137
  export type ForkNotebookInput = NotebookLifecycleInput;
123
138
  export interface NotebookPolicyData {
@@ -254,6 +269,7 @@ export interface NotebookMailListOptions {
254
269
  declare class NotebookApi {
255
270
  private readonly client;
256
271
  constructor(client: Client);
272
+ inspectImport(input: InspectNotebookImportInput): Promise<NotebookImportInspectionData>;
257
273
  create(template: string, input?: Partial<CreateNotebookInput>): Promise<NotebookInstance>;
258
274
  get(id: string): Promise<NotebookInstance>;
259
275
  open(data: NotebookData): NotebookInstance;
package/dist/index.js CHANGED
@@ -28,8 +28,7 @@ import { PublicationApi, PublicationInstance, PublicationRun, } from './publicat
28
28
  import { ServerApi } from './servers.js';
29
29
  import { RestRuntimeInvoker } from './runtime/rest.js';
30
30
  import { Feedback } from './feedback.js';
31
- import { IntegrationApi } from './integrations.js';
32
- import { SandboxIntegrationApi } from './sandbox-integrations.js';
31
+ import { IntegrationApi, SandboxIntegrationApi } from './integrations/index.js';
33
32
  import { authenticatedRequest } from './http.js';
34
33
  export { LspConnection } from './lsp.js';
35
34
  export { FileChangeFilter, FileChangeType, FileType, } from './filesystem.js';
@@ -48,6 +47,10 @@ class NotebookApi {
48
47
  constructor(client) {
49
48
  this.client = client;
50
49
  }
50
+ async inspectImport(input) {
51
+ const response = await this.client.post('/notebook/imports/inspect', input);
52
+ return response.data;
53
+ }
51
54
  async create(template, input = {}) {
52
55
  const response = await this.client.post('/notebook', { template, ...input });
53
56
  return new NotebookInstance(response.data, this.client);
@@ -1,4 +1,4 @@
1
- import type { Client } from './index.js';
1
+ import type { Client } from '../index.js';
2
2
  export type IntegrationProvider = 'cloudflare' | 'github' | 'laravel-cloud';
3
3
  export type IntegrationAuthorizationType = 'token';
4
4
  export interface IntegrationAuthorization {
@@ -0,0 +1,2 @@
1
+ export * from './account.js';
2
+ export * from './sandbox.js';
@@ -0,0 +1,2 @@
1
+ export * from './account.js';
2
+ export * from './sandbox.js';
@@ -1,5 +1,5 @@
1
- import type { Client } from './index.js';
2
- import { Integration, type IntegrationData, type IntegrationReference } from './integrations.js';
1
+ import type { Client } from '../index.js';
2
+ import { Integration, type IntegrationData, type IntegrationReference } from './account.js';
3
3
  export type SandboxIntegrationEffect = 'network';
4
4
  export interface AttachSandboxIntegrationInput {
5
5
  integration: IntegrationReference;
@@ -1,4 +1,4 @@
1
- import { Integration, integrationId, } from './integrations.js';
1
+ import { Integration, integrationId, } from './account.js';
2
2
  export class SandboxIntegrationApi {
3
3
  constructor(notebookId, client) {
4
4
  this.notebookId = notebookId;
package/dist/log.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { NotebookInstance } from './index.js';
2
- import { RuntimeTelemetry, type RuntimeWatchOptions } from './runtime-telemetry.js';
2
+ import { RuntimeTelemetry, type RuntimeWatchOptions } from './telemetry.js';
3
3
  export interface LogEvents {
4
4
  'notebook.log': string;
5
5
  }
package/dist/log.js CHANGED
@@ -1,4 +1,4 @@
1
- import { watchRuntimeTelemetry } from './runtime-telemetry.js';
1
+ import { watchRuntimeTelemetry } from './telemetry.js';
2
2
  export default class Logs {
3
3
  constructor(okra, telemetry) {
4
4
  this.okra = okra;
package/dist/metrics.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NotebookInstance } from './index.js';
2
2
  import type { RuntimeStats } from './runtime.js';
3
- import { RuntimeTelemetry, type RuntimeWatchOptions } from './runtime-telemetry.js';
3
+ import { RuntimeTelemetry, type RuntimeWatchOptions } from './telemetry.js';
4
4
  export default class Metrics {
5
5
  private readonly okra;
6
6
  private readonly telemetry;
package/dist/metrics.js CHANGED
@@ -1,4 +1,4 @@
1
- import { watchRuntimeTelemetry } from './runtime-telemetry.js';
1
+ import { watchRuntimeTelemetry } from './telemetry.js';
2
2
  export default class Metrics {
3
3
  constructor(okra, telemetry) {
4
4
  this.okra = okra;
package/dist/ports.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NotebookInstance } from './index.js';
2
2
  import type { PortInfo } from './runtime.js';
3
- import { RuntimeTelemetry, type RuntimeWatchOptions } from './runtime-telemetry.js';
3
+ import { RuntimeTelemetry, type RuntimeWatchOptions } from './telemetry.js';
4
4
  export default class Ports {
5
5
  private readonly okra;
6
6
  private readonly telemetry;
package/dist/ports.js CHANGED
@@ -1,4 +1,4 @@
1
- import { watchRuntimeTelemetry } from './runtime-telemetry.js';
1
+ import { watchRuntimeTelemetry } from './telemetry.js';
2
2
  export default class Ports {
3
3
  constructor(okra, telemetry) {
4
4
  this.okra = okra;
package/dist/runtime.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { Action, NotebookInstance } from './index.js';
2
2
  import Logs, { type RuntimeLogEntry } from './log.js';
3
3
  import Metrics from './metrics.js';
4
4
  import Ports from './ports.js';
5
- import { type RuntimeTelemetryFeature, type RuntimeWatchOptions } from './runtime-telemetry.js';
5
+ import { type RuntimeTelemetryFeature, type RuntimeWatchOptions } from './telemetry.js';
6
6
  export interface PortInfo {
7
7
  subdomain: string;
8
8
  url: string;
package/dist/runtime.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import Logs from './log.js';
2
2
  import Metrics from './metrics.js';
3
3
  import Ports from './ports.js';
4
- import { RuntimeTelemetry, } from './runtime-telemetry.js';
4
+ import { RuntimeTelemetry, } from './telemetry.js';
5
5
  export class RuntimeMetrics {
6
6
  constructor(metrics) {
7
7
  this.metrics = metrics;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@phpsandbox/sdk",
3
- "version": "0.1.12",
4
- "description": "A comprehensive TypeScript SDK for interacting with cloud-based PHP development environments",
3
+ "version": "0.1.14",
4
+ "description": "The TypeScript SDK for PHPSandbox cloud development environments",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -20,8 +20,6 @@
20
20
  },
21
21
  "files": [
22
22
  "dist",
23
- "docs",
24
- "examples",
25
23
  "README.md",
26
24
  "LICENSE"
27
25
  ],
@@ -42,10 +40,8 @@
42
40
  "smoke:feedback-widget": "npm run build:tsc && vitest run --reporter=verbose --config tests/smoke/vitest.config.ts tests/smoke/integrations/feedback-widget.smoke.ts",
43
41
  "smoke:reaper": "npm run build:tsc && vitest run --reporter=verbose --config tests/smoke/vitest.config.ts tests/smoke/maintenance/resources.reaper.smoke.ts",
44
42
  "smoke:typecheck": "npm run build:tsc && tsc --project tests/smoke/tsconfig.json --noEmit",
45
- "check:examples": "tsc --noEmit --module NodeNext --moduleResolution NodeNext --target ES2020 --types node --skipLibCheck --allowSyntheticDefaultImports --esModuleInterop examples/basic.ts examples/publish-cloudflare-container.ts examples/publish-laravel-cloud.ts examples/publish-ssh-agent.ts examples/get.ts examples/git-merge-smoke.ts examples/laravel-load-test.ts examples/notebook-readonly-smoke.ts",
46
- "prepublishOnly": "npm test && npm run check:examples && npm run check:docs && npm run clean && npm run build",
47
- "bumpAndPublish": "npm version patch && npm publish --access public",
48
- "check:docs": "npm run build:tsc && node tools/check-documentation.mjs"
43
+ "prepublishOnly": "npm test && npm run clean && npm run build",
44
+ "bumpAndPublish": "npm version patch && npm publish --access public"
49
45
  },
50
46
  "keywords": [
51
47
  "php",
@@ -86,6 +82,6 @@
86
82
  "esbuild": "^0.27.1",
87
83
  "playwright": "^1.62.1",
88
84
  "typescript": "^5.7.2",
89
- "vitest": "^4.1.8"
85
+ "vitest": "^4.1.11"
90
86
  }
91
87
  }
@@ -1,181 +0,0 @@
1
- # PHPSandbox SDK API Summary
2
-
3
- This is a quick reference for the current SDK surface.
4
-
5
- ## Top-Level Client
6
-
7
- ```ts
8
- import { PHPSandbox } from '@phpsandbox/sdk';
9
-
10
- const client = PHPSandbox.realtime(token, 'https://api.phpsandbox.io/v1', {
11
- debug: false,
12
- });
13
-
14
- const restClient = PHPSandbox.rest(token, 'https://api.phpsandbox.io/v1', {
15
- runtimeUrlProvider: async (notebookId) => getFreshRuntimeUrl(notebookId),
16
- });
17
- ```
18
-
19
- Connection lifecycle methods, streaming actions, and event subscriptions require the realtime transport. The REST transport rejects unsupported operations without falling back to a websocket.
20
-
21
- ### `NotebookApi`
22
-
23
- - `create(template, input?)`
24
- - `get(id)`
25
- - `open(data)`
26
-
27
- ## `NotebookInstance`
28
-
29
- - Lifecycle: `ready()`, `connected()`, `reconnect()`, `dispose()`
30
- - Notebook actions: `fork(input?)`, `destroy()`, `stop()`, `restart()`
31
- - Processes: `exec(command, args?, options?)`, or `run(command, args?, options?)` returning native `stdin`, `stdout`, `stderr`, ordered `output`, `wait()`, and `kill()`
32
- - Events: `listen(event, handler)`, `onDidConnect(handler)`, `onDidDisconnect(handler)`, `onDidInitialize(handler)`
33
- - Raw call: `invoke(action, data?, options?)`
34
-
35
- ## Services
36
-
37
- ### Filesystem (`notebook.files`)
38
-
39
- - File data: `read()`, `readText()`, `readStream()`, `write()`, `tail()`, `stat()`, `exists()`
40
- - File management: `move()`, `copy()`, `remove()`
41
- - Directory: `createDirectory()`, `list()`, `tree()`
42
- - Search: `find()`, `search()`
43
- - Streaming/monitoring: `readStream()`, `watch()`, `download()`
44
- - `tail()` is an eager last-lines snapshot; it does not follow future appends.
45
-
46
- ### Terminal (`notebook.terminals`)
47
-
48
- - `list()` returns terminal metadata
49
- - `create(options?)` returns a terminal handle
50
- - `attach(id, options?)` returns a terminal handle
51
- - Handles expose `input`, `output`, `wait()`, `resize()`, and `kill()`
52
-
53
- ### Notebook lifecycle
54
-
55
- - `notebook.stop()`, `notebook.restart()`
56
-
57
- ### Runtime (`notebook.runtime`)
58
-
59
- - Runtime configuration: `setPhpVersion(version)`
60
-
61
- ### Runtime observability
62
-
63
- - `notebook.runtime.logs.follow({ signal? })` returns `ReadableStream<RuntimeLogEntry>`
64
- - `notebook.runtime.ports.list()` returns the current preview ports
65
- - `notebook.runtime.ports.resolve(port)` returns preview routing information even when the port is not open
66
- - `notebook.runtime.ports.watch({ signal? })` returns `ReadableStream<PortInfo[]>`
67
- - `notebook.runtime.metrics.current()` returns the current CPU, memory, and disk sample
68
- - `notebook.runtime.metrics.watch({ signal? })` returns `ReadableStream<RuntimeStats>`
69
-
70
- ### Processes
71
-
72
- - `notebook.run(command, args?, options?)` returns a streaming process handle
73
- - `notebook.exec(command, args?, options?)` returns a buffered `ProcessResult` for one-shot commands
74
- - Process handles expose `output`, `stdout`, `stderr`, `stdin`, `wait()`, and `kill()`
75
-
76
- ### Services (`notebook.services`)
77
-
78
- - Constants: `notebookBuiltinServices`, `notebookKnownServices`
79
- - `list()`
80
- - `run(name, command?)`
81
- - `stop(name)`
82
- - `logs(name, { tail? })`
83
- - `logs(name, { follow: true, tail?, id? })` returning `ReadableStream<string>`; cancel the stream to stop following
84
-
85
- ### Composer (`notebook.composer`)
86
-
87
- - `run(command, args?, options?)`
88
- - `packages()`
89
- - Command handles expose `output`, `stdout`, `stderr`, `wait()`, and `kill()`
90
-
91
- ### Git (`notebook.git`)
92
-
93
- - `checkpoint(author, message, branch = 'main')`
94
- - `targets.create({ provider, repository, author, branch?, setDefault? })`
95
- - `targets.list()`, `targets.get(target)`, and `target.sync({ direction?, author? })`
96
- - `diff({ notebookId?, url?, token?, ref?, base?, target?, patch? })`
97
- - `merge({ notebookId?, url?, token?, ref?, target?, expectedBaseRef?, author?, message? })`
98
- - `conflicts()`
99
- - `abortMerge()`
100
- - `continueMerge(author, message?)`
101
- - `review()`
102
- - `stage({ path?, paths?, all? })`
103
- - `unstage({ path?, paths?, all? })`
104
- - `revert({ path?, paths?, all?, staged? })`
105
- - `log(ref = 'main')`
106
- - `restore(ref)`
107
-
108
- ### Sandbox integrations (`notebook.integrations`)
109
-
110
- - `attach({ integration, effects? })`
111
- - A sandbox has one attached integration per provider. `binding.update({ integration })` replaces that provider selection.
112
- - Provider-backed operations resolve the attached integration when they run; persistent sandbox behavior remains controlled by explicit effects.
113
- - `list()`
114
- - `get(binding)`
115
- - Binding resources expose `update({ effects })` and `detach()`
116
- - The currently supported sandbox effect is GitHub `network`; effects are explicit and provider-specific.
117
-
118
- ### Mail (`notebook.mail`)
119
-
120
- - `status()` returning non-sensitive mail configuration state
121
- - `enable()` enabling SMTP env injection for the notebook
122
- - `disable()` disabling SMTP env injection and revoking the active SMTP token
123
- - `list({ page? })` returning paginated notebook mail
124
- - `get(hash)`
125
- - `delete(hash)`
126
-
127
- ### Feedback (`sandbox.feedback`)
128
-
129
- - `configure({ widget })`, where `widget` is `null` or contains `targets`, optional `label`, and optional `types`
130
- - `submit({ type, message, author?, context?, metadata? })`
131
- - `list({ type?, status?, source?, page? })`
132
- - `get(id)`
133
- - `update(id, { status })`
134
-
135
- Feedback ingestion is always available through the authenticated API. Configuration controls only the optional widget and can target `preview`, `publication`, or both.
136
-
137
- ### LSP (`notebook.lsp`)
138
-
139
- - Messaging: `start(id)`, `close(id)`, `message(id, payload)`
140
- - Events: `onResponse()`, `onError()`, `onClose()`, `onClientDisconnect()`
141
- - Connection wrapper: `connection(id)`
142
-
143
- ### REPL (`notebook.repl`)
144
-
145
- - `stop()`, `eval(code, args?, replOpts?)`, `write(input)`, `resize(cols, rows)`
146
- - Events: `listen()`, `onOutput()`
147
-
148
- ### Auth (`notebook.auth`)
149
-
150
- - `login(runtimeUrl)` using a fresh ticket-bearing runtime URL
151
-
152
- ## Publications
153
-
154
- - `notebook.publish({ slug, provider, protection?, metadata? })`
155
- - `notebook.publication()` returns the current publication or `null`
156
- - `client.publications.get(id)` returns a publication reference.
157
- - Publication references expose `refresh()`, `destroy()`, `events()`, `logs()`, `buildLogs()`, and protection operations.
158
- - A publish run exposes `events()` as an `AsyncIterable`, `result()` with the final status and URL, and `publication()` when refreshed deployment state is needed.
159
- - Built-in provider names are `cloudflare-containers`, `ssh-server`, and `laravel-cloud`. Provider maps support TypeScript declaration merging.
160
- - Cloudflare Containers input uses `{ name: 'cloudflare-containers', accountId, size?, sleepAfter?, placement?, instances? }` and resolves the sandbox's attached Cloudflare integration when each operation runs.
161
- - Laravel Cloud input uses `{ name: 'laravel-cloud', region }` and resolves the sandbox's attached Laravel Cloud integration when each operation runs.
162
-
163
- ## Account integrations
164
-
165
- - `client.integrations.link({ provider, label?, authorization })`
166
- - `client.integrations.list()` and `get(integration)`
167
- - Resource instances expose `update(input)` and `unlink()`.
168
- - Built-in providers are `cloudflare`, `github`, and `laravel-cloud`; current public authorization uses opaque caller-managed tokens.
169
-
170
- ## Common Errors
171
-
172
- - `RemoteError` when Core or the notebook runtime returns a structured failure
173
- - `RemoteError.is(error, code)` for exact conditions such as `FileNotFound` and `RateLimited`
174
- - `RemoteError.isValidation(error)` for typed validation details
175
- - `TransportError` when no valid remote response is received
176
-
177
- ## Notes for Consumers
178
-
179
- - Runtime actions wait for readiness before their handlers run.
180
- - Call `ready()` explicitly when you need provisioning metadata or initialization errors before another action.
181
- - Always call `notebook.dispose()` when finished.
package/docs/cdn-usage.md DELETED
@@ -1,68 +0,0 @@
1
- # Browser/CDN usage
2
-
3
- The SDK includes ESM and script-tag browser bundles. Browser support is a packaging capability, not permission to expose an account API key.
4
-
5
- ## Choose a trust boundary
6
-
7
- For public applications, keep the SDK on your backend. Authenticate your application users and authorize the sandbox and operation before making SDK calls. Do not expose a generic proxy for arbitrary management or runtime operations.
8
-
9
- There is no public SDK API for minting short-lived account keys. Never embed a `psb_` API key in a page, frontend environment variable, local storage, or CDN example.
10
-
11
- A trusted workspace can receive a notebook-specific runtime URL from its backend. That URL contains a bearer ticket and grants access to the sandbox runtime. Only give it to a user you trust to access that sandbox; it is not a preview link. Use preview sessions or handoffs for application review.
12
-
13
- ## Trusted workspace example (ESM)
14
-
15
- The `/api/sandbox-session` endpoint below belongs to **your application** and must be implemented on your backend. It must authenticate the user, authorize access to the selected notebook, retrieve fresh notebook data using your server-side API key, and return `id`, `gitUrl`, and `runtimeUrl` with `Cache-Control: no-store`. Never return the account API key. Do not accept arbitrary notebook IDs without authorization.
16
-
17
- ```html
18
- <script type="module">
19
- import { PHPSandbox } from 'https://cdn.jsdelivr.net/npm/@phpsandbox/sdk@0.1.9/dist/browser/phpsandbox-sdk.esm.min.js';
20
-
21
- async function getSession() {
22
- const response = await fetch('/api/sandbox-session', {
23
- credentials: 'same-origin',
24
- cache: 'no-store',
25
- });
26
- if (!response.ok) throw new Error(`Sandbox session failed: ${response.status}`);
27
- return response.json();
28
- }
29
-
30
- // No account token in this client. Management calls stay on your backend.
31
- const client = PHPSandbox.realtime('', undefined, {
32
- runtimeUrlProvider: async () => (await getSession()).runtimeUrl,
33
- });
34
- const notebook = client.notebook.open(await getSession());
35
-
36
- const result = await notebook.exec('php', ['-v']);
37
- if (result.exitCode !== 0) throw new Error(result.stderr || result.output);
38
- document.querySelector('#output').textContent = result.stdout;
39
- notebook.dispose();
40
- </script>
41
- <pre id="output"></pre>
42
- ```
43
-
44
- `open()` creates a runtime handle without requesting notebook data from Core. Do not call `client.notebook.create()`, `get()`, or other management methods with this tokenless client. Refresh the same authorized notebook's ticket through your backend when reconnecting. Never log session responses or runtime URLs.
45
-
46
- ## Script tag (IIFE)
47
-
48
- ```html
49
- <script src="https://unpkg.com/@phpsandbox/sdk@0.1.9/dist/browser/phpsandbox-sdk.iife.min.js"></script>
50
- <script>
51
- // The IIFE namespace contains the exported PHPSandbox class.
52
- const client = PHPSandbox.PHPSandbox.realtime('');
53
- // Use the same authorized backend session and open flow shown above.
54
- </script>
55
- ```
56
-
57
- ## Version pinning
58
-
59
- These URLs pin `0.1.9`. Use the version you have tested when upgrading; avoid unversioned or `latest` URLs. Both CDNs serve the same package files:
60
-
61
- - `dist/browser/phpsandbox-sdk.esm.js`
62
- - `dist/browser/phpsandbox-sdk.esm.min.js`
63
- - `dist/browser/phpsandbox-sdk.iife.js`
64
- - `dist/browser/phpsandbox-sdk.iife.min.js`
65
-
66
- ## Browser requirements
67
-
68
- Use a modern browser with `fetch`, `WebSocket`, `ReadableStream`, `WritableStream`, `TextEncoder`, `TextDecoder`, and `AbortController`. ES2020 syntax support alone does not supply these web APIs. Your application's CSP must permit the CDN script and the authorized runtime connection.
@@ -1,169 +0,0 @@
1
- # Getting Started with PHPSandbox SDK
2
-
3
- This guide walks through the fastest path from install to a working notebook.
4
-
5
- ## Prerequisites
6
-
7
- - Node.js 18+
8
- - A PHPSandbox account with an active subscription and available notebook capacity
9
- - SDK access enabled and an API key created in **API keys**
10
-
11
- ## Install
12
-
13
- ```bash
14
- npm install @phpsandbox/sdk
15
- ```
16
-
17
- Copy the API key when shown and store it in `PHPSANDBOX_TOKEN` in your server environment or secret store. Keys are shown once and grant notebook read and write access; never include them in frontend bundles or commit them. If **API keys** is unavailable, request SDK access first.
18
-
19
- For a complete runnable example, save the [root quick start](../README.md#quick-start) as `quickstart.mjs` and run `node quickstart.mjs`. The snippets below explain individual operations.
20
-
21
- ## 1. Create a Client
22
-
23
- ```ts
24
- import { PHPSandbox } from '@phpsandbox/sdk';
25
-
26
- const token = process.env.PHPSANDBOX_TOKEN;
27
- if (!token) throw new Error('Missing PHPSANDBOX_TOKEN');
28
-
29
- const client = PHPSandbox.realtime(token);
30
- ```
31
-
32
- ## 2. Create or Open a Notebook
33
-
34
- ```ts
35
- const notebook = await client.notebook.create('standard');
36
-
37
- const persistent = await client.notebook.create('laravel', {
38
- title: 'Persistent Laravel',
39
- persistent: true,
40
- });
41
-
42
- const existing = await client.notebook.get('notebook-id');
43
-
44
- const fork = await existing.fork();
45
- const persistentFork = await existing.fork({ persistent: true });
46
- ```
47
-
48
- API notebook creates and forks are ephemeral by default. Use `persistent: true` only when your account is allowed to create persistent notebooks.
49
-
50
- ## 3. Write and Read Files
51
-
52
- ```ts
53
- await notebook.files.write('hello.php', '<?php echo "Hello";');
54
-
55
- const data = await notebook.files.read('hello.php');
56
- const text = new TextDecoder().decode(data);
57
-
58
- console.log(text);
59
- ```
60
-
61
- The same `write()` method accepts text, bytes, readable streams, and async iterables:
62
-
63
- ```ts
64
- await notebook.files.write('binary.dat', new Uint8Array([1, 2, 3]), {
65
- create: true,
66
- overwrite: true,
67
- unlock: false,
68
- atomic: false,
69
- });
70
- ```
71
-
72
- ## 4. Run Commands
73
-
74
- ### Terminal (stream output)
75
-
76
- ```ts
77
- const task = await notebook.terminals.create({ command: 'php', args: ['hello.php'] });
78
- const reader = task.output.getReader();
79
-
80
- while (true) {
81
- const { done, value } = await reader.read();
82
- if (done) break;
83
- process.stdout.write(value);
84
- }
85
- reader.releaseLock();
86
-
87
- const exitCode = await task.wait();
88
- console.log(`\nExit code: ${exitCode}`);
89
- ```
90
-
91
- ### Shell (single command result)
92
-
93
- ```ts
94
- const result = await notebook.exec('php -v', { tty: false });
95
- if (result.exitCode !== 0) throw new Error(result.stderr || result.output);
96
- console.log(result.stdout);
97
- ```
98
-
99
- ## 5. Search and Watch Files
100
-
101
- ```ts
102
- const matches = await notebook.files.find('*.php', {
103
- includes: ['app/**'],
104
- excludes: ['vendor/**'],
105
- });
106
-
107
- console.log(matches.map((match) => match.path));
108
-
109
- const watcher = await notebook.files.watch(
110
- '/app',
111
- {
112
- recursive: true,
113
- excludes: ['vendor/**', 'node_modules/**'],
114
- },
115
- (change) => {
116
- console.log(change.type, change.path);
117
- }
118
- );
119
-
120
- // later
121
- watcher.dispose();
122
- ```
123
-
124
- ## 6. Use Composer and Git
125
-
126
- ```ts
127
- const installResult = await notebook.composer.run('install').wait();
128
- if (installResult.exitCode !== 0) throw new Error(installResult.stderr || installResult.output);
129
-
130
- const requireResult = await notebook.composer.run('require', { packages: ['monolog/monolog'] }).wait();
131
- if (requireResult.exitCode !== 0) throw new Error(requireResult.stderr || requireResult.output);
132
-
133
- await notebook.git.checkpoint('Jane Doe <jane@example.com>', 'Initial checkpoint');
134
- ```
135
-
136
- ## 7. Clean Up
137
-
138
- Use a `finally` block to dispose every connection, including forks and notebooks opened with `get()`. `dispose()` only closes local resources. For temporary automation, delete the remote notebook as well:
139
-
140
- ```ts
141
- try {
142
- await notebook.destroy();
143
- } finally {
144
- notebook.dispose();
145
- }
146
- ```
147
-
148
- Omit `destroy()` only when you intend to keep the notebook. Stopping a notebook does not delete it. Ephemeral notebooks are eventually pruned according to `notebook.data.policy`; do not rely on that as immediate cleanup.
149
-
150
- ## Common Pitfalls
151
-
152
- - Runtime actions wait for readiness. Call `ready()` only when you need its provisioning metadata.
153
- - `files.watch()` requires an `excludes` array.
154
- - Command results include `exitCode`; decide explicitly whether a non-zero exit should fail your workflow.
155
-
156
- ## Troubleshooting
157
-
158
- - `401`: check that the API key is set and has not been revoked.
159
- - `403`: check permissions, account subscription, notebook capacity, and persistence entitlement.
160
- - `404`: the notebook is missing or inaccessible to your account.
161
- - `422`: use `RemoteError.isValidation(error)` to inspect field errors; `standard` is the plain PHP template ID.
162
- - `429`: respect `error.response.headers.get('Retry-After')` and reduce concurrency. Avoid blind retries of resource creation or publication.
163
- - A process stays alive after the script finishes: ensure all notebook instances are disposed in `finally`.
164
-
165
- ## Next Reading
166
-
167
- - API overview: [API overview](api-summary.md)
168
- - CDN/browser usage: [Browser usage](cdn-usage.md)
169
- - Root quick start: [Root quick start](../README.md)