@superblocksteam/sabs-client 0.418.0 → 0.422.0

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/src/sabs.ts DELETED
@@ -1,487 +0,0 @@
1
- import {
2
- ApplicationMetadata,
3
- BuildRequest,
4
- BuildResponse,
5
- BuildStatus,
6
- BuildStepTimings,
7
- BuildSizeMetrics,
8
- ListRequest,
9
- ListResponse,
10
- StatusResponse,
11
- TerminateRequest,
12
- TerminateResponse,
13
- BulkStatusRequest,
14
- BulkStatusResponse,
15
- CreateLiveEditRequest,
16
- CreateLiveEditResponse,
17
- TerminateLiveEditResponse,
18
- TerminateLiveEditRequest
19
- } from '@superblocksteam/sabs-types';
20
- import axios, { AxiosRequestConfig, RawAxiosRequestHeaders } from 'axios';
21
-
22
- import { createErrorFromStatusCode, createClientError, createNetworkError } from './errors';
23
-
24
- /**
25
- * SABS (Superblocks Application Build System) TypeScript Client
26
- *
27
- * Provides methods to interact with the SABS API for building and managing applications.
28
- *
29
- * All error types inherit from the standard `HttpError` class that extends the standard `Error` class,
30
- * ensuring backward compatibility with existing error handling code that catches generic `Error` instances
31
- * used in earlier versions of the client library.
32
- */
33
- export class SabsClient {
34
- private readonly baseUrl: string;
35
-
36
- public constructor(baseUrl: string) {
37
- this.baseUrl = baseUrl;
38
- }
39
-
40
- /**
41
- * Start a new build for an application
42
- *
43
- * @param params - Build parameters
44
- * @param params.directoryHash - Hash of the application directory to build
45
- * @param params.meta - Application metadata (ID and organization ID)
46
- * @param params.buildKey - Secret build key for authentication
47
- * @param params.accessToken - JWT access token for authorization
48
- * @returns Promise resolving to build information including build ID
49
- * @throws BadRequestError if the directory hash, application metadata, application ID, organization ID, build key, or access token are empty or invalid
50
- * @throws ForbiddenError if the access token is invalid or missing the required scopes
51
- * @throws InternalServerError if the service has an unexpected error while performing this request
52
- * @throws HttpError if the request fails for an unknown reason
53
- */
54
- public async build({
55
- directoryHash,
56
- meta,
57
- buildKey,
58
- accessToken
59
- }: {
60
- directoryHash: string;
61
- meta: ApplicationMetadata;
62
- buildKey: string;
63
- accessToken?: string;
64
- }): Promise<BuildResponse> {
65
- if (!directoryHash || directoryHash.length === 0) {
66
- throw createClientError('Directory hash is required');
67
- }
68
- if (!meta) {
69
- throw createClientError('Application metadata is required');
70
- }
71
- if (!meta.id || meta.id.length === 0) {
72
- throw createClientError('Application ID is required');
73
- }
74
- if (!meta.organizationId || meta.organizationId.length === 0) {
75
- throw createClientError('Organization ID is required');
76
- }
77
- if (!buildKey || buildKey.length === 0) {
78
- throw createClientError('Build key is required');
79
- }
80
- if (!accessToken || accessToken.length === 0) {
81
- throw createClientError('Access token is required');
82
- }
83
-
84
- const data = new BuildRequest({
85
- directoryHash: directoryHash,
86
- applicationMetadata: meta,
87
- buildKey
88
- });
89
-
90
- return this.executeRequest<BuildResponse>(
91
- {
92
- method: 'POST',
93
- url: `${this.baseUrl}/v1/builds`,
94
- data
95
- },
96
- accessToken
97
- );
98
- }
99
-
100
- /**
101
- * Get the status of a build
102
- *
103
- * @param params - Status query parameters
104
- * @param params.buildId - ID of the build to check
105
- * @param params.accessToken - JWT access token for authorization
106
- * @returns Promise resolving to build status information
107
- * @throws BadRequestError if the build ID or access token is empty or invalid
108
- * @throws UnauthorizedError if the access token is invalid or missing the required scopes
109
- * @throws NotFoundError if the build ID is invalid
110
- * @throws InternalServerError if the service has an unexpected error while performing this request
111
- * @throws HttpError if the request fails for an unknown reason
112
- */
113
- public async status({ buildId, accessToken }: { buildId: string; accessToken?: string }): Promise<StatusResponse> {
114
- if (!buildId || buildId.length === 0) {
115
- throw createClientError('Build ID is required');
116
- }
117
- if (!accessToken || accessToken.length === 0) {
118
- throw createClientError('Access token is required');
119
- }
120
-
121
- return this.executeRequest<StatusResponse>(
122
- {
123
- method: 'GET',
124
- url: `${this.baseUrl}/v1/builds/${buildId}`
125
- },
126
- accessToken
127
- );
128
- }
129
-
130
- /**
131
- * Get the status of multiple builds at once
132
- *
133
- * @param params - Bulk status query parameters
134
- * @param params.organizationId - Organization ID
135
- * @param params.applicationId - Application ID
136
- * @param params.directoryHashes - Array of directory hashes to check
137
- * @param params.accessToken - JWT access token for authorization
138
- * @returns Promise resolving to multiple build status information
139
- * @throws BadRequestError if the organization ID, application ID, directory hashes, or access token are empty or invalid
140
- * @throws UnauthorizedError if the access token is invalid or missing the required scopes
141
- * @throws NotFoundError if the organization ID or application ID is invalid
142
- * @throws InternalServerError if the service has an unexpected error while performing this request
143
- * @throws HttpError if the request fails for an unknown reason
144
- */
145
- public async bulkStatus({
146
- organizationId,
147
- applicationId,
148
- directoryHashes,
149
- accessToken
150
- }: {
151
- organizationId: string;
152
- applicationId: string;
153
- directoryHashes: string[];
154
- accessToken?: string;
155
- }): Promise<BulkStatusResponse> {
156
- if (!organizationId || organizationId.length === 0) {
157
- throw createClientError('Organization ID is required');
158
- }
159
- if (!applicationId || applicationId.length === 0) {
160
- throw createClientError('Application ID is required');
161
- }
162
- if (!directoryHashes || directoryHashes.length === 0) {
163
- throw createClientError('Directory hashes are required');
164
- }
165
- if (!accessToken || accessToken.length === 0) {
166
- throw createClientError('Access token is required');
167
- }
168
-
169
- const data = new BulkStatusRequest({
170
- organizationId,
171
- applicationId,
172
- directoryHashes
173
- });
174
-
175
- return this.executeRequest<BulkStatusResponse>(
176
- {
177
- method: 'POST',
178
- url: `${this.baseUrl}/v1/builds/${organizationId}/${applicationId}/bulk-status`,
179
- data
180
- },
181
- accessToken
182
- );
183
- }
184
-
185
- /**
186
- * List all builds for a specific application and directory
187
- *
188
- * @param params - List query parameters
189
- * @param params.organizationId - Organization ID
190
- * @param params.applicationId - Application ID
191
- * @param params.directoryHash - Hash of the application directory
192
- * @param params.accessToken - JWT access token for authorization
193
- * @returns Promise resolving to list of builds
194
- * @throws BadRequestError if the organization ID, application ID, directory hash, or access token are empty or invalid
195
- * @throws UnauthorizedError if the access token is invalid or missing the required scopes
196
- * @throws NotFoundError if the organization ID or application ID is invalid
197
- * @throws InternalServerError if the service has an unexpected error while performing this request
198
- * @throws HttpError if the request fails for an unknown reason
199
- */
200
- public async list({
201
- organizationId,
202
- applicationId,
203
- directoryHash,
204
- accessToken
205
- }: {
206
- organizationId: string;
207
- applicationId: string;
208
- directoryHash: string;
209
- accessToken?: string;
210
- }): Promise<ListResponse> {
211
- if (!organizationId || organizationId.length === 0) {
212
- throw createClientError('Organization ID is required');
213
- }
214
- if (!applicationId || applicationId.length === 0) {
215
- throw createClientError('Application ID is required');
216
- }
217
- if (!directoryHash || directoryHash.length === 0) {
218
- throw createClientError('Directory hash is required');
219
- }
220
- if (!accessToken || accessToken.length === 0) {
221
- throw createClientError('Access token is required');
222
- }
223
-
224
- const data = new ListRequest({
225
- organizationId,
226
- applicationId,
227
- directoryHash
228
- });
229
-
230
- return this.executeRequest<ListResponse>(
231
- {
232
- method: 'GET',
233
- url: `${this.baseUrl}/v1/build`,
234
- params: data
235
- },
236
- accessToken
237
- );
238
- }
239
-
240
- /**
241
- * Terminate a running build with a final status
242
- *
243
- * @param params - Termination parameters
244
- * @param params.buildId - ID of the build to terminate
245
- * @param params.status - Final status of the build
246
- * @param params.buildKey - Secret build key for authentication
247
- * @param params.error - Optional error message if build failed
248
- * @param params.stepTimings - Optional step timing metrics in milliseconds
249
- * @param params.sizeMetrics - Optional size metrics in bytes
250
- * @param params.accessToken - JWT access token for authorization
251
- * @returns Promise resolving to termination confirmation
252
- * @throws BadRequestError if the build ID, build status, build key, or access token are empty or invalid
253
- * @throws UnauthorizedError if the access token is invalid or missing the required scopes
254
- * @throws NotFoundError if the build ID is invalid
255
- * @throws InternalServerError if the service has an unexpected error while performing this request
256
- * @throws HttpError if the request fails for an unknown reason
257
- */
258
- public async terminate({
259
- buildId,
260
- status,
261
- buildKey,
262
- error,
263
- stepTimings,
264
- sizeMetrics,
265
- accessToken
266
- }: {
267
- buildId: string;
268
- status: BuildStatus;
269
- buildKey?: string;
270
- error?: string;
271
- stepTimings?: {
272
- createTempDirMs?: number;
273
- fetchAppBundleMs?: number;
274
- npmInstallMs?: number;
275
- buildMs?: number;
276
- uploadMs?: number;
277
- };
278
- sizeMetrics?: {
279
- sourceBundleSizeBytes?: number;
280
- nodeModulesSizeBytes?: number;
281
- buildOutputSizeBytes?: number;
282
- dependencyCount?: number;
283
- };
284
- accessToken?: string;
285
- }): Promise<TerminateResponse> {
286
- if (!buildId || buildId.length === 0) {
287
- throw createClientError('Build ID is required');
288
- }
289
- if (!status) {
290
- throw createClientError('Build status is required');
291
- }
292
- if (!buildKey || buildKey.length === 0) {
293
- throw createClientError('Build key is required');
294
- }
295
- if (!accessToken || accessToken.length === 0) {
296
- throw createClientError('Access token is required');
297
- }
298
-
299
- const requestData = new TerminateRequest({
300
- buildId,
301
- status,
302
- error,
303
- buildKey
304
- });
305
-
306
- if (stepTimings) {
307
- requestData.stepTimings = new BuildStepTimings({
308
- createTempDirMs: stepTimings.createTempDirMs ? BigInt(stepTimings.createTempDirMs) : undefined,
309
- fetchAppBundleMs: stepTimings.fetchAppBundleMs ? BigInt(stepTimings.fetchAppBundleMs) : undefined,
310
- npmInstallMs: stepTimings.npmInstallMs ? BigInt(stepTimings.npmInstallMs) : undefined,
311
- buildMs: stepTimings.buildMs ? BigInt(stepTimings.buildMs) : undefined,
312
- uploadMs: stepTimings.uploadMs ? BigInt(stepTimings.uploadMs) : undefined
313
- });
314
- } else {
315
- console.warn('No step timings provided for build termination');
316
- }
317
-
318
- if (sizeMetrics) {
319
- requestData.sizeMetrics = new BuildSizeMetrics({
320
- sourceBundleSizeBytes: sizeMetrics.sourceBundleSizeBytes ? BigInt(sizeMetrics.sourceBundleSizeBytes) : undefined,
321
- nodeModulesSizeBytes: sizeMetrics.nodeModulesSizeBytes ? BigInt(sizeMetrics.nodeModulesSizeBytes) : undefined,
322
- buildOutputSizeBytes: sizeMetrics.buildOutputSizeBytes ? BigInt(sizeMetrics.buildOutputSizeBytes) : undefined,
323
- dependencyCount: sizeMetrics.dependencyCount ? BigInt(sizeMetrics.dependencyCount) : undefined
324
- });
325
- } else {
326
- console.warn('No size metrics provided for build termination');
327
- }
328
-
329
- return this.executeRequest<TerminateResponse>(
330
- {
331
- method: 'POST',
332
- url: `${this.baseUrl}/v1/builds/${buildId}/terminate`,
333
- data: requestData
334
- },
335
- accessToken
336
- );
337
- }
338
-
339
- /**
340
- * Create a new live edit session for real-time development
341
- *
342
- * @param params - Live edit creation parameters
343
- * @param params.applicationId - Application ID
344
- * @param params.organizationId - Organization ID
345
- * @param params.branch - Git branch name
346
- * @param params.expiresIn - Session duration in seconds
347
- * @param params.accessToken - JWT access token for authorization
348
- * @param params.clientKey - Optional client-supplied key to detect conflicts when existing live edit was created with a different client key
349
- * @returns Promise resolving to live edit session information
350
- * @throws BadRequestError if the application ID, organization ID, branch, or access token are empty or invalid, or expiresIn is not greater than 0
351
- * @throws UnauthorizedError if the access token is invalid or missing the required scopes
352
- * @throws ConflictError if a live edit exists with a different client key
353
- * @throws InternalServerError if the service has an unexpected error while performing this request
354
- * @throws HttpError if the request fails for an unknown reason
355
- */
356
- public async createLiveEdit({
357
- applicationId,
358
- organizationId,
359
- branch,
360
- expiresIn,
361
- accessToken,
362
- clientKey
363
- }: {
364
- applicationId: string;
365
- organizationId: string;
366
- branch: string;
367
- expiresIn: number;
368
- accessToken: string;
369
- clientKey?: string;
370
- }): Promise<CreateLiveEditResponse> {
371
- if (!applicationId || applicationId.length === 0) {
372
- throw createClientError('Application ID is required');
373
- }
374
- if (!organizationId || organizationId.length === 0) {
375
- throw createClientError('Organization ID is required');
376
- }
377
- if (!branch || branch.length === 0) {
378
- throw createClientError('Branch is required');
379
- }
380
- if (!accessToken || accessToken.length === 0) {
381
- throw createClientError('Access token is required');
382
- }
383
- if (!expiresIn || expiresIn <= 0) {
384
- throw createClientError('Expires in is required and must be greater than 0');
385
- }
386
-
387
- const data = new CreateLiveEditRequest({
388
- application: {
389
- applicationId,
390
- organizationId: organizationId,
391
- branch: branch
392
- },
393
- sessionJwt: accessToken,
394
- expiresIn: BigInt(expiresIn),
395
- clientKey: clientKey ?? ''
396
- });
397
-
398
- return this.executeRequest<CreateLiveEditResponse>(
399
- {
400
- method: 'POST',
401
- url: `${this.baseUrl}/v1/live-edit`,
402
- data
403
- },
404
- accessToken
405
- );
406
- }
407
-
408
- /**
409
- * Terminate an active live edit session
410
- *
411
- * @param params - Live edit termination parameters
412
- * @param params.liveEditId - ID of the live edit session to terminate
413
- * @param params.accessToken - JWT access token for authorization
414
- * @returns Promise resolving to termination confirmation
415
- * @throws BadRequestError if the live edit ID or access token are empty or invalid
416
- * @throws UnauthorizedError if the access token is invalid or missing the required scopes
417
- * @throws NotFoundError if the live edit ID is invalid
418
- * @throws InternalServerError if the service has an unexpected error while performing this request
419
- * @throws HttpError if the request fails for an unknown reason
420
- */
421
- public async terminateLiveEdit({
422
- liveEditId,
423
- accessToken
424
- }: {
425
- liveEditId: string;
426
- accessToken: string;
427
- }): Promise<TerminateLiveEditResponse> {
428
- if (!liveEditId || liveEditId.length === 0) {
429
- throw createClientError('Live edit ID is required');
430
- }
431
- if (!accessToken || accessToken.length === 0) {
432
- throw createClientError('Access token is required');
433
- }
434
-
435
- const data = new TerminateLiveEditRequest({
436
- liveEditId
437
- });
438
-
439
- return this.executeRequest<TerminateLiveEditResponse>(
440
- {
441
- method: 'POST',
442
- url: `${this.baseUrl}/v1/live-edit/${liveEditId}/terminate`,
443
- data
444
- },
445
- accessToken
446
- );
447
- }
448
-
449
- private async executeRequest<T>(config: AxiosRequestConfig, accessToken?: string): Promise<T> {
450
- let headers: RawAxiosRequestHeaders | undefined;
451
- if (accessToken || config.headers) {
452
- headers = {
453
- ...config.headers,
454
- Authorization: accessToken ? `Bearer ${accessToken}` : undefined
455
- };
456
- }
457
-
458
- try {
459
- const response = await axios.request<T>({
460
- ...config,
461
- headers
462
- });
463
- return response.data;
464
- } catch (error) {
465
- if (axios.isAxiosError(error)) {
466
- const statusCode = error.response?.status ?? 500;
467
- const statusText = error.response?.statusText ?? 'Unknown Error';
468
- const responseData = error.response?.data;
469
-
470
- let message: string;
471
- if (responseData && typeof responseData === 'object' && responseData.message) {
472
- message = responseData.message;
473
- } else if (responseData && typeof responseData === 'string') {
474
- message = responseData;
475
- } else {
476
- message = `${statusText} (${statusCode})`;
477
- }
478
-
479
- throw createErrorFromStatusCode(statusCode, message);
480
- } else {
481
- // Network error or other non-HTTP error
482
- const message = error instanceof Error ? error.message : 'Unknown error occurred';
483
- throw createNetworkError(message, error instanceof Error ? error : undefined);
484
- }
485
- }
486
- }
487
- }
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "commonjs",
5
- "composite": true,
6
- "incremental": true,
7
- "declaration": true,
8
- "declarationMap": true,
9
- "sourceMap": true,
10
- "moduleResolution": "node",
11
- "esModuleInterop": true,
12
- "resolveJsonModule": true,
13
- "rootDir": "./src",
14
- "outDir": "./dist",
15
- "allowSyntheticDefaultImports": true,
16
- "forceConsistentCasingInFileNames": true,
17
- "strictNullChecks": true,
18
- "allowJs": false,
19
- "skipLibCheck": true
20
- },
21
- "exclude": ["./dist", "./node_modules"],
22
- "include": ["./**/*.ts"]
23
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": ".",
5
- "noEmit": true
6
- },
7
- "include": ["./test/**/*.ts", "./src/**/*.ts", "./*.config.js", "./src/**/*.json"],
8
- "exclude": ["node_modules"]
9
- }