@phpsandbox/sdk 0.2.0 → 0.2.1

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.
@@ -2,7 +2,7 @@ import type { Client } from '../index.js';
2
2
  import { PublicationInstance } from './instance.js';
3
3
  import { PublicationRun } from './run.js';
4
4
  import { PublicationResources } from './resources.js';
5
- import type { PlannedPublishInput, PublicationPlan, PublicationPlanInput, PublicationProviderName, PublicationReadiness, PublicationResourceCatalog } from './types.js';
5
+ import type { PlannedPublishInput, PublicationApplicationPlan, PublicationApplicationPlanInput, PublicationApplicationData, PublicationPlan, PublicationPlanInput, PublicationProviderName, PublicationReadiness, PublicationResourceCatalog } from './types.js';
6
6
  export declare class NotebookPublication {
7
7
  private readonly notebookId;
8
8
  private readonly client;
@@ -13,6 +13,17 @@ export declare class NotebookPublication {
13
13
  readiness(): Promise<PublicationReadiness>;
14
14
  /** Review a publishing plan without committing changes or creating resources. */
15
15
  prepare<TName extends PublicationProviderName>(input: PublicationPlanInput<TName>): Promise<PublicationPlan<TName>>;
16
+ /** Review a multi-component publishing plan without creating resources or starting releases. */
17
+ prepareApplication(input: PublicationApplicationPlanInput): Promise<PublicationApplicationPlan>;
18
+ /** Publish every component in a reviewed application plan. */
19
+ publishApplication(input: PublicationApplicationPlanInput): Promise<PublicationApplicationData>;
20
+ application(applicationId: string): Promise<PublicationApplicationData>;
21
+ /** Retry only failed components while leaving healthy components untouched. */
22
+ retryApplication(applicationId: string): Promise<PublicationApplicationData>;
23
+ destroyApplication(applicationId: string, options?: {
24
+ deleteResources?: boolean;
25
+ }): Promise<void>;
26
+ private startApplicationRuns;
16
27
  catalog(provider: 'laravel-cloud' | 'cloudflare-containers'): Promise<PublicationResourceCatalog>;
17
28
  catalog(provider: 'ssh-server', serverId: string): Promise<PublicationResourceCatalog>;
18
29
  /** Core validates the plan, prepares source and executes publishing. */
@@ -30,6 +30,36 @@ export class NotebookPublication {
30
30
  async prepare(input) {
31
31
  return (await this.client.post(`${this.path}/publication/plan`, input)).data;
32
32
  }
33
+ /** Review a multi-component publishing plan without creating resources or starting releases. */
34
+ async prepareApplication(input) {
35
+ return (await this.client.post(`${this.path}/publication/application-plan`, input)).data;
36
+ }
37
+ /** Publish every component in a reviewed application plan. */
38
+ async publishApplication(input) {
39
+ const application = (await this.client.post(`${this.path}/publication/application`, input)).data;
40
+ this.startApplicationRuns(application);
41
+ return application;
42
+ }
43
+ async application(applicationId) {
44
+ return (await this.client.get(`${this.path}/publication/application/${encodeURIComponent(applicationId)}`)).data;
45
+ }
46
+ /** Retry only failed components while leaving healthy components untouched. */
47
+ async retryApplication(applicationId) {
48
+ const application = (await this.client.post(`${this.path}/publication/application/${encodeURIComponent(applicationId)}/retry`, {})).data;
49
+ this.startApplicationRuns(application);
50
+ return application;
51
+ }
52
+ async destroyApplication(applicationId, options = {}) {
53
+ const query = options.deleteResources ? '?deleteResources=1' : '';
54
+ await this.client.delete(`${this.path}/publication/application/${encodeURIComponent(applicationId)}${query}`);
55
+ }
56
+ startApplicationRuns(application) {
57
+ for (const component of application.components) {
58
+ if (!['pending', 'queued', 'building', 'deploying'].includes(component.publication.status))
59
+ continue;
60
+ new PublicationRun(new PublicationInstance(component.publication, this.client, this.notebookId), this.client).start();
61
+ }
62
+ }
33
63
  async catalog(provider, serverId) {
34
64
  const query = new URLSearchParams({ provider });
35
65
  if (serverId !== undefined) {
@@ -46,6 +46,7 @@ export interface PublicationRequirement {
46
46
  export interface PublicationReadiness {
47
47
  repository: string | null;
48
48
  branch: string | null;
49
+ revision?: string | null;
49
50
  sourceProvider: string | null;
50
51
  requirements: PublicationRequirement[];
51
52
  productionVariables: string[];
@@ -81,6 +82,8 @@ export interface PublicationAccessCapabilities {
81
82
  export interface PublicationCapabilities {
82
83
  source: 'git' | 'workspace';
83
84
  sourceProviders?: string[];
85
+ buildModes?: Array<PublicationComponentBuild['mode']>;
86
+ componentKinds?: PublicationComponentKind[];
84
87
  resourceCleanup?: boolean;
85
88
  resources: Record<PublicationResourceKind, PublicationResourceMode[]>;
86
89
  access: {
@@ -164,6 +167,125 @@ export interface PublicationPlan<TName extends PublicationProviderName = Publica
164
167
  message: string;
165
168
  };
166
169
  }
170
+ export type PublicationComponentKind = 'frontend' | 'http-service' | 'static-site' | 'worker' | 'scheduler';
171
+ export type PublicationDockerfile = {
172
+ source: 'generated';
173
+ content: string;
174
+ digest?: string;
175
+ } | {
176
+ source: 'project';
177
+ path: string;
178
+ digest?: string;
179
+ };
180
+ export type PublicationComponentBuild = {
181
+ mode: 'provider-native';
182
+ workingDirectory?: string;
183
+ context?: string;
184
+ installCommand?: string;
185
+ buildCommand?: string;
186
+ deployCommand?: string;
187
+ outputDirectory?: string;
188
+ } | {
189
+ mode: 'dockerfile';
190
+ workingDirectory?: string;
191
+ context?: string;
192
+ dockerfile: PublicationDockerfile;
193
+ target?: string;
194
+ arguments?: Record<string, string>;
195
+ secrets?: string[];
196
+ } | {
197
+ mode: 'image';
198
+ reference: string;
199
+ };
200
+ export interface PublicationComponentRuntime {
201
+ kind?: 'http' | 'static' | 'process';
202
+ command?: string[];
203
+ port?: number;
204
+ healthCheck?: {
205
+ path: string;
206
+ };
207
+ }
208
+ export type PublicationComponentPlacement<TName extends PublicationProviderName = PublicationProviderName> = {
209
+ [Name in TName]: {
210
+ provider: Name;
211
+ } & Partial<PublicationProviderInputs[Name]>;
212
+ }[TName];
213
+ export interface PublicationApplicationComponentInput<TName extends PublicationProviderName = PublicationProviderName> {
214
+ id: string;
215
+ kind: PublicationComponentKind;
216
+ root: string;
217
+ build: PublicationComponentBuild;
218
+ sourceDependencies?: string[];
219
+ runtime?: PublicationComponentRuntime;
220
+ resources?: string[];
221
+ placement: PublicationComponentPlacement<TName>;
222
+ }
223
+ export interface PublicationApplicationResourceInput {
224
+ id: string;
225
+ kind: PublicationResourceKind;
226
+ mode: PublicationResourceMode;
227
+ engine?: string;
228
+ provider?: PublicationProviderName;
229
+ selection?: Omit<PublicationResourceSelection, 'mode'>;
230
+ }
231
+ export interface PublicationApplicationRouteInput {
232
+ hostname: string;
233
+ component: string;
234
+ }
235
+ export interface PublicationPlanAssumption {
236
+ id: string;
237
+ statement: string;
238
+ basis?: string;
239
+ confidence?: 'low' | 'medium' | 'high';
240
+ requiresConfirmation?: boolean;
241
+ }
242
+ export interface PublicationApplicationPlanInput {
243
+ schemaVersion: 1;
244
+ slug?: string;
245
+ source?: {
246
+ repository?: string;
247
+ revision?: string;
248
+ root?: string;
249
+ };
250
+ components: PublicationApplicationComponentInput[];
251
+ resources?: PublicationApplicationResourceInput[];
252
+ routes?: PublicationApplicationRouteInput[];
253
+ assumptions?: PublicationPlanAssumption[];
254
+ }
255
+ export interface PublicationApplicationComponentPlan extends PublicationApplicationComponentInput {
256
+ sourceDependencies: string[];
257
+ resources: string[];
258
+ providerPlan: PublicationPlan;
259
+ }
260
+ export interface PublicationApplicationPlan {
261
+ schemaVersion: 1;
262
+ source: {
263
+ repository: string | null;
264
+ revision: string | null;
265
+ root: string;
266
+ };
267
+ components: PublicationApplicationComponentPlan[];
268
+ resources: PublicationApplicationResourceInput[];
269
+ routes: PublicationApplicationRouteInput[];
270
+ assumptions: PublicationPlanAssumption[];
271
+ blockers: Array<{
272
+ code: string;
273
+ message: string;
274
+ component?: string;
275
+ resource?: string;
276
+ }>;
277
+ ready: boolean;
278
+ input: PublicationApplicationPlanInput;
279
+ }
280
+ export interface PublicationApplicationComponentData {
281
+ componentId: string;
282
+ publication: PublicationData;
283
+ }
284
+ export interface PublicationApplicationData {
285
+ id: string;
286
+ status: 'publishing' | 'healthy' | 'failed' | 'deleted';
287
+ components: PublicationApplicationComponentData[];
288
+ }
167
289
  export interface PublicationDnsInstructions {
168
290
  stage: 'ownership' | 'traffic' | 'connected';
169
291
  records: PublicationDnsRecord[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phpsandbox/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "The TypeScript SDK for PHPSandbox cloud development environments",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",