@shipstatic/types 0.3.21 → 0.4.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.
package/README.md CHANGED
@@ -1,371 +1,87 @@
1
1
  # @shipstatic/types
2
2
 
3
- Shared TypeScript types, constants, and utilities for the Shipstatic platform. This package is the single source of truth for all shared data structures used across the API, SDK, and CLI.
3
+ Shared TypeScript types for the Shipstatic platform.
4
4
 
5
- ## Overview
5
+ Single source of truth for types used across API, SDK, CLI, and web applications.
6
6
 
7
- This package contains all shared types used between:
8
- - **Shipstatic API** (`/cloudflare/api`) - Backend API on Cloudflare Workers
9
- - **Shipstatic SDK** (`/ship`) - Universal SDK for Node.js and Browser
10
- - **Shipstatic CLI** - Command-line interface
11
-
12
- ## Core Entities
13
-
14
- ### Deployment
15
-
16
- ```typescript
17
- interface Deployment {
18
- deployment: string; // Deployment ID (e.g., "happy-cat-abc1234")
19
- files: number; // Number of files in deployment
20
- size: number; // Total size in bytes
21
- status: 'pending' | 'success' | 'failed' | 'deleting';
22
- config?: boolean; // Whether deployment has ship.json
23
- url: string; // Deployment URL
24
- created: number; // Unix timestamp (seconds)
25
- expires?: number; // Unix timestamp (seconds)
26
- verified?: number; // Unix timestamp (seconds) when verified
27
- }
28
- ```
29
-
30
- ### Alias
31
-
32
- ```typescript
33
- interface Alias {
34
- alias: string; // Alias name (subdomain or custom domain)
35
- deployment: string; // Target deployment ID
36
- status: 'pending' | 'success' | 'failed';
37
- url: string; // Alias URL
38
- created: number; // Unix timestamp (seconds)
39
- confirmed?: number; // Unix timestamp (seconds) when confirmed
40
- isCreate?: boolean; // Present in set operations only
41
- }
42
- ```
43
-
44
- ### Account
45
-
46
- ```typescript
47
- interface Account {
48
- email: string; // User email address
49
- name: string; // User display name
50
- picture?: string; // Profile picture URL
51
- plan: 'free' | 'standard' | 'sponsored' | 'enterprise' | 'suspended' | 'terminating' | 'terminated'; // Account plan status
52
- created: number; // Unix timestamp (seconds)
53
- }
54
- ```
55
-
56
- ### Static File
57
-
58
- ```typescript
59
- interface StaticFile {
60
- content: File | Buffer | Blob; // File content
61
- path: string; // Server path (e.g., "assets/style.css")
62
- filePath?: string; // Original filesystem path (Node.js)
63
- md5?: string; // MD5 hash of content
64
- size: number; // File size in bytes
65
- }
66
- ```
67
-
68
- ## API Response Types
69
-
70
- ### Success Responses
71
-
72
- ```typescript
73
- interface DeploymentListResponse {
74
- deployments: Deployment[];
75
- cursor?: string; // Pagination cursor
76
- total?: number; // Total count if available
77
- }
78
-
79
- interface AliasListResponse {
80
- aliases: Alias[];
81
- cursor?: string;
82
- total?: number;
83
- }
84
-
85
- interface SuccessResponse<T = any> {
86
- success: true;
87
- data: T;
88
- }
89
- ```
90
-
91
- ### Configuration
92
-
93
- ```typescript
94
- interface ConfigResponse {
95
- maxFileSize: number; // Maximum file size in bytes
96
- maxFilesCount: number; // Maximum files per deployment
97
- maxTotalSize: number; // Maximum total deployment size
98
- }
99
-
100
- interface PlatformConfig {
101
- apiUrl?: string;
102
- deployToken?: string;
103
- apiKey?: string;
104
- }
105
- ```
106
-
107
- ### SPA Detection
7
+ ## Installation
108
8
 
109
- ```typescript
110
- interface SPACheckRequest {
111
- files: string[]; // Array of file paths
112
- index: string; // Index file path
113
- }
9
+ ```bash
10
+ # Included with Ship SDK
11
+ npm install @shipstatic/ship
114
12
 
115
- interface SPACheckResponse {
116
- isSPA: boolean; // Whether it's detected as SPA
117
- debug: {
118
- tier: 'exclusions' | 'inclusions' | 'scoring' | 'ai' | 'fallback';
119
- reason: string;
120
- };
121
- }
13
+ # Direct installation
14
+ npm install @shipstatic/types
122
15
  ```
123
16
 
124
- ## Resource Interface Contracts
17
+ ## What's Included
125
18
 
126
- These interfaces define the contracts that all SDK implementations must follow:
19
+ ### Core Entities
127
20
 
128
21
  ```typescript
129
- interface DeploymentResource {
130
- create: (input: DeployInput, options?: any) => Promise<Deployment>;
131
- list: () => Promise<DeploymentListResponse>;
132
- remove: (id: string) => Promise<void>;
133
- get: (id: string) => Promise<Deployment>;
134
- }
135
-
136
- interface AliasResource {
137
- set: (aliasName: string, deployment: string) => Promise<Alias>;
138
- get: (aliasName: string) => Promise<Alias>;
139
- list: () => Promise<AliasListResponse>;
140
- remove: (aliasName: string) => Promise<void>;
141
- check: (aliasName: string) => Promise<{ message: string }>;
142
- }
143
-
144
- interface AccountResource {
145
- get: () => Promise<Account>;
146
- }
147
-
148
- interface KeysResource {
149
- create: () => Promise<{ apiKey: string }>;
150
- }
22
+ import type { Deployment, Domain, Account, Token, StaticFile } from '@shipstatic/types';
151
23
  ```
152
24
 
153
- ## Error System
154
-
155
- ### Unified Error Handling
25
+ ### Error System
156
26
 
157
27
  ```typescript
158
- enum ErrorType {
159
- Validation = "validation_failed",
160
- NotFound = "not_found",
161
- RateLimit = "rate_limit_exceeded",
162
- Authentication = "authentication_failed",
163
- Business = "business_logic_error",
164
- Api = "internal_server_error",
165
- Network = "network_error",
166
- Cancelled = "operation_cancelled",
167
- File = "file_error",
168
- Config = "config_error"
169
- }
28
+ import { ShipError, ErrorType } from '@shipstatic/types';
170
29
 
171
- interface ErrorResponse {
172
- error: ErrorType;
173
- message: string;
174
- status?: number;
175
- details?: any;
176
- }
30
+ throw ShipError.validation('File too large');
31
+ throw ShipError.notFound('Deployment', id);
177
32
 
178
- class ShipError extends Error {
179
- constructor(
180
- public readonly type: ErrorType,
181
- message: string,
182
- public readonly status?: number,
183
- public readonly details?: any
184
- );
185
-
186
- // Factory methods
187
- static validation(message: string, details?: any): ShipError;
188
- static notFound(resource: string, id?: string): ShipError;
189
- static authentication(message?: string): ShipError;
190
- static business(message: string, status?: number): ShipError;
191
- static network(message: string, cause?: Error): ShipError;
192
- static api(message?: string, status?: number): ShipError;
193
-
194
- // Helper methods
195
- isClientError(): boolean;
196
- isNetworkError(): boolean;
197
- isAuthError(): boolean;
198
- toResponse(): ErrorResponse;
199
- }
33
+ if (error.isClientError()) { /* handle */ }
200
34
  ```
201
35
 
202
- ## Platform Constants
36
+ ### API Response Types
203
37
 
204
38
  ```typescript
205
- // API configuration
206
- const DEFAULT_API = 'https://api.shipstatic.com';
207
-
208
- // Server configuration limits
209
- const serverConfig = {
210
- maxFileSize: 10 * 1024 * 1024, // 10MB
211
- maxFilesCount: 1000, // Files per deployment
212
- maxTotalSize: 100 * 1024 * 1024, // 100MB total
213
- deploymentExpiryHours: 120, // 5 days
214
- defaultLimit: 50, // Pagination default
215
- maxLimit: 100, // Pagination maximum
216
- } as const;
217
-
218
- // API key format validation
219
- const API_KEY_PREFIX = 'ship-';
220
- const API_KEY_HEX_LENGTH = 64;
221
- const API_KEY_TOTAL_LENGTH = 69; // 'ship-' + 64 hex chars
39
+ import type {
40
+ DeploymentListResponse,
41
+ DomainListResponse,
42
+ ConfigResponse,
43
+ BillingStatus
44
+ } from '@shipstatic/types';
222
45
  ```
223
46
 
224
- ## Upload Types
47
+ ### Resource Contracts
225
48
 
226
- ```typescript
227
- enum UploadStatus {
228
- PENDING = 'pending',
229
- SUCCESS = 'success',
230
- FAILED = 'failed',
231
- DELETING = 'deleting'
232
- }
233
-
234
- interface UploadedFile {
235
- key: string; // Storage key
236
- etag: string; // ETag from storage
237
- size: number; // File size in bytes
238
- validated?: boolean; // Whether file was validated
239
- }
240
-
241
- interface RateLimitData {
242
- count: number; // Current request count
243
- timestamp: number; // Window start timestamp
244
- }
245
- ```
246
-
247
- ## Validation Utilities
49
+ SDK interface definitions:
248
50
 
249
51
  ```typescript
250
- // Validate API key format
251
- function validateApiKey(apiKey: string): void;
252
-
253
- // Validate deploy token format
254
- function validateDeployToken(deployToken: string): void;
255
-
256
- // Validate API URL format
257
- function validateApiUrl(apiUrl: string): void;
258
-
259
- // Validate deployment subdomain format
260
- function validateSubdomain(input: string): boolean;
52
+ import type { DeploymentResource, DomainResource, AccountResource } from '@shipstatic/types';
261
53
  ```
262
54
 
263
- ## URL Generation
55
+ ### Validation Utilities
264
56
 
265
57
  ```typescript
266
- // Generate deployment URL
267
- function generateDeploymentUrl(deployment: string, sitesDomain?: string): string;
268
-
269
- // Generate alias URL (handles both subdomains and custom domains)
270
- function generateAliasUrl(alias: string, sitesDomain?: string): string;
58
+ import { validateApiKey, validateDeployToken, validateSubdomain } from '@shipstatic/types';
271
59
  ```
272
60
 
273
- ## Usage Examples
274
-
275
- ### In the API
61
+ ### Constants
276
62
 
277
63
  ```typescript
278
- import {
279
- serverConfig,
280
- ShipError,
281
- type ConfigResponse,
282
- type Deployment
64
+ import {
65
+ DEFAULT_API,
66
+ API_KEY_PREFIX,
67
+ DeploymentStatus,
68
+ DomainStatus,
69
+ AccountPlan
283
70
  } from '@shipstatic/types';
284
-
285
- // Use shared configuration
286
- const config: ConfigResponse = {
287
- maxFileSize: serverConfig.maxFileSize,
288
- maxFilesCount: serverConfig.maxFilesCount,
289
- maxTotalSize: serverConfig.maxTotalSize,
290
- };
291
-
292
- // Use unified error handling
293
- throw ShipError.validation('File too large', {
294
- maxSize: serverConfig.maxFileSize
295
- });
296
71
  ```
297
72
 
298
- ### In the SDK
73
+ ## Usage
299
74
 
300
75
  ```typescript
301
- import {
302
- ShipError,
303
- type ConfigResponse,
304
- type DeploymentListResponse,
305
- generateDeploymentUrl
306
- } from '@shipstatic/types';
307
-
308
- // Handle API responses
309
- const deployments: DeploymentListResponse = await api.listDeployments();
76
+ import { ShipError, type Deployment, DeploymentStatus } from '@shipstatic/types';
310
77
 
311
- // Generate URLs consistently
312
- const url = generateDeploymentUrl('happy-cat-abc1234');
313
-
314
- // Handle errors consistently
315
- try {
316
- const result = await deploy(files);
317
- } catch (error) {
318
- if (error instanceof ShipError && error.isClientError()) {
319
- // Handle client errors
78
+ function processDeployment(deployment: Deployment) {
79
+ if (deployment.status === DeploymentStatus.FAILED) {
80
+ throw ShipError.business('Deployment failed');
320
81
  }
321
82
  }
322
83
  ```
323
84
 
324
- ## Installation
325
-
326
- This package is automatically installed as a dependency:
327
-
328
- ```bash
329
- # Included with Ship SDK
330
- npm install @shipstatic/ship
331
-
332
- # Direct installation (if needed)
333
- npm install @shipstatic/types
334
- ```
335
-
336
- ## Architecture
337
-
338
- ### Design Principles
339
-
340
- - **Single source of truth** - All types defined once, used everywhere
341
- - **Type safety** - Strict TypeScript with comprehensive validation
342
- - **Wire format compatibility** - Types match actual API contracts
343
- - **Error consistency** - Unified error handling across all components
344
- - **Platform contracts** - Resource interfaces define SDK behavior
345
-
346
- ### Type Organization
347
-
348
- All types are organized in a single `src/index.ts` file by category:
349
-
350
- 1. **Core entities** - Deployment, Alias, Account objects
351
- 2. **API responses** - Response wrappers and pagination
352
- 3. **Resource contracts** - SDK interface definitions
353
- 4. **Error system** - Unified ShipError class and error types
354
- 5. **Platform configuration** - Shared constants and validation
355
- 6. **Upload types** - File handling and status enums
356
- 7. **Utility functions** - URL generation and validation
357
-
358
- ## Philosophy
359
-
360
- This package follows the **"Impossible Simplicity"** principle:
361
-
362
- - **Clear contracts** - Types define platform behavior
363
- - **Zero duplication** - Single source prevents drift
364
- - **Developer experience** - Predictable, well-documented interfaces
365
- - **Maintainability** - Easy to update types across entire platform
366
-
367
- The result is type-safe development across the entire Shipstatic platform with guaranteed consistency between API, SDK, and CLI components.
368
-
369
- ---
85
+ ## License
370
86
 
371
- **@shipstatic/types** - The foundation of type safety for Shipstatic 🚢
87
+ MIT
package/dist/index.d.ts CHANGED
@@ -464,30 +464,47 @@ export declare const DEFAULT_API = "https://api.shipstatic.com";
464
464
  * Node.js: string | string[] - file/directory paths
465
465
  */
466
466
  export type DeployInput = File[] | string | string[];
467
+ /**
468
+ * Options for deployment creation at the API contract level.
469
+ * SDK implementations may extend with additional options (timeout, signal, callbacks, etc.).
470
+ */
471
+ export interface DeploymentCreateOptions {
472
+ /** Optional tags for categorization and filtering */
473
+ tags?: string[];
474
+ /** Optional subdomain suggestion for the deployment */
475
+ subdomain?: string;
476
+ /** Client identifier (e.g., 'cli', 'sdk', 'web') */
477
+ via?: string;
478
+ }
467
479
  /**
468
480
  * Deployment resource interface - the contract all implementations must follow
469
481
  */
470
482
  export interface DeploymentResource {
471
- create: (input: DeployInput, options?: any) => Promise<Deployment>;
483
+ create: (input: DeployInput, options?: DeploymentCreateOptions) => Promise<Deployment>;
472
484
  list: () => Promise<DeploymentListResponse>;
473
- remove: (id: string) => Promise<void>;
474
485
  get: (id: string) => Promise<Deployment>;
486
+ set: (id: string, options: {
487
+ tags: string[];
488
+ }) => Promise<Deployment>;
489
+ remove: (id: string) => Promise<void>;
475
490
  }
476
491
  /**
477
492
  * Domain resource interface - the contract all implementations must follow
478
493
  */
479
494
  export interface DomainResource {
480
- set: (domainName: string, deployment?: string, tags?: string[]) => Promise<Domain>;
481
- update: (domainName: string, tags: string[]) => Promise<Domain>;
482
- get: (domainName: string) => Promise<Domain>;
495
+ set: (name: string, options?: {
496
+ deployment?: string;
497
+ tags?: string[];
498
+ }) => Promise<Domain>;
483
499
  list: () => Promise<DomainListResponse>;
484
- remove: (domainName: string) => Promise<void>;
485
- verify: (domainName: string) => Promise<{
500
+ get: (name: string) => Promise<Domain>;
501
+ remove: (name: string) => Promise<void>;
502
+ verify: (name: string) => Promise<{
486
503
  message: string;
487
504
  }>;
488
- dns: (domainName: string) => Promise<DomainDnsResponse>;
489
- records: (domainName: string) => Promise<DomainRecordsResponse>;
490
- share: (domainName: string) => Promise<{
505
+ dns: (name: string) => Promise<DomainDnsResponse>;
506
+ records: (name: string) => Promise<DomainRecordsResponse>;
507
+ share: (name: string) => Promise<{
491
508
  domain: string;
492
509
  hash: string;
493
510
  }>;
@@ -502,7 +519,10 @@ export interface AccountResource {
502
519
  * Token resource interface - the contract all implementations must follow
503
520
  */
504
521
  export interface TokenResource {
505
- create: (ttl?: number, tags?: string[]) => Promise<TokenCreateResponse>;
522
+ create: (options?: {
523
+ ttl?: number;
524
+ tags?: string[];
525
+ }) => Promise<TokenCreateResponse>;
506
526
  list: () => Promise<TokenListResponse>;
507
527
  remove: (token: string) => Promise<void>;
508
528
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "0.3.21",
3
+ "version": "0.4.1",
4
4
  "description": "Shared types for Shipstatic platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "node": ">=20.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/node": "^24.10.4",
36
+ "@types/node": "^24.10.9",
37
37
  "typescript": "^5.9.3"
38
38
  },
39
39
  "scripts": {
package/src/index.ts CHANGED
@@ -716,29 +716,42 @@ export const DEFAULT_API = 'https://api.shipstatic.com';
716
716
  */
717
717
  export type DeployInput = File[] | string | string[];
718
718
 
719
+ /**
720
+ * Options for deployment creation at the API contract level.
721
+ * SDK implementations may extend with additional options (timeout, signal, callbacks, etc.).
722
+ */
723
+ export interface DeploymentCreateOptions {
724
+ /** Optional tags for categorization and filtering */
725
+ tags?: string[];
726
+ /** Optional subdomain suggestion for the deployment */
727
+ subdomain?: string;
728
+ /** Client identifier (e.g., 'cli', 'sdk', 'web') */
729
+ via?: string;
730
+ }
731
+
719
732
  /**
720
733
  * Deployment resource interface - the contract all implementations must follow
721
734
  */
722
735
  export interface DeploymentResource {
723
- create: (input: DeployInput, options?: any) => Promise<Deployment>;
736
+ create: (input: DeployInput, options?: DeploymentCreateOptions) => Promise<Deployment>;
724
737
  list: () => Promise<DeploymentListResponse>;
725
- remove: (id: string) => Promise<void>;
726
738
  get: (id: string) => Promise<Deployment>;
739
+ set: (id: string, options: { tags: string[] }) => Promise<Deployment>;
740
+ remove: (id: string) => Promise<void>;
727
741
  }
728
742
 
729
743
  /**
730
744
  * Domain resource interface - the contract all implementations must follow
731
745
  */
732
746
  export interface DomainResource {
733
- set: (domainName: string, deployment?: string, tags?: string[]) => Promise<Domain>;
734
- update: (domainName: string, tags: string[]) => Promise<Domain>;
735
- get: (domainName: string) => Promise<Domain>;
747
+ set: (name: string, options?: { deployment?: string; tags?: string[] }) => Promise<Domain>;
736
748
  list: () => Promise<DomainListResponse>;
737
- remove: (domainName: string) => Promise<void>;
738
- verify: (domainName: string) => Promise<{ message: string }>;
739
- dns: (domainName: string) => Promise<DomainDnsResponse>;
740
- records: (domainName: string) => Promise<DomainRecordsResponse>;
741
- share: (domainName: string) => Promise<{ domain: string; hash: string }>;
749
+ get: (name: string) => Promise<Domain>;
750
+ remove: (name: string) => Promise<void>;
751
+ verify: (name: string) => Promise<{ message: string }>;
752
+ dns: (name: string) => Promise<DomainDnsResponse>;
753
+ records: (name: string) => Promise<DomainRecordsResponse>;
754
+ share: (name: string) => Promise<{ domain: string; hash: string }>;
742
755
  }
743
756
 
744
757
  /**
@@ -752,7 +765,7 @@ export interface AccountResource {
752
765
  * Token resource interface - the contract all implementations must follow
753
766
  */
754
767
  export interface TokenResource {
755
- create: (ttl?: number, tags?: string[]) => Promise<TokenCreateResponse>;
768
+ create: (options?: { ttl?: number; tags?: string[] }) => Promise<TokenCreateResponse>;
756
769
  list: () => Promise<TokenListResponse>;
757
770
  remove: (token: string) => Promise<void>;
758
771
  }