@shipstatic/ship 0.3.5 → 0.3.8

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
@@ -76,7 +76,7 @@ const ship = new Ship({
76
76
 
77
77
  // Deploy project - SDK automatically fetches platform configuration
78
78
  const result = await ship.deployments.create(['./dist'], {
79
- onProgress: (progress) => console.log(`${progress}%`)
79
+ onProgress: ({ percent }) => console.log(`${percent}%`)
80
80
  });
81
81
 
82
82
  console.log(`Deployed: ${result.deployment}`);
@@ -201,6 +201,7 @@ interface ShipOptions {
201
201
  apiKey?: string; // API key: ship- prefix + 64-char hex (69 chars total)
202
202
  deployToken?: string; // Deploy token: token- prefix + 64-char hex (70 chars total)
203
203
  timeout?: number; // Request timeout (ms)
204
+ useCredentials?: boolean; // Use HTTP-only cookies for auth (skips token check)
204
205
  }
205
206
  ```
206
207
 
@@ -259,8 +260,7 @@ interface DeployOptions {
259
260
  signal?: AbortSignal; // Cancellation
260
261
  subdomain?: string; // Custom subdomain
261
262
  onCancel?: () => void;
262
- onProgress?: (progress: number) => void;
263
- progress?: (stats: ProgressStats) => void;
263
+ onProgress?: (info: ProgressInfo) => void; // Progress with percent (0-100), loaded, total bytes
264
264
  maxConcurrency?: number;
265
265
  timeout?: number;
266
266
  stripCommonPrefix?: boolean; // Remove common path prefix
@@ -321,8 +321,8 @@ const result = await ship.deployments.create([
321
321
  './public'
322
322
  ], {
323
323
  stripCommonPrefix: true,
324
- onProgress: (progress) => {
325
- console.log(`Deployment: ${progress}% complete`);
324
+ onProgress: ({ percent }) => {
325
+ console.log(`Deployment: ${percent}% complete`);
326
326
  }
327
327
  });
328
328
 
@@ -346,8 +346,8 @@ const ship = new Ship({
346
346
  const fileInput = document.getElementById('fileInput') as HTMLInputElement;
347
347
  const files: File[] = Array.from(fileInput.files || []);
348
348
  const result = await ship.deployments.create(files, {
349
- onProgress: (progress) => {
350
- document.getElementById('progress').textContent = `${progress}%`;
349
+ onProgress: ({ percent }) => {
350
+ document.getElementById('progress').textContent = `${percent}%`;
351
351
  }
352
352
  });
353
353
  ```
@@ -691,7 +691,7 @@ import type {
691
691
  BrowserDeployInput,
692
692
  DeployOptions,
693
693
  DeploySuccessResponse,
694
- ProgressStats,
694
+ ProgressInfo,
695
695
  StaticFile,
696
696
  ShipError,
697
697
  ErrorType
package/dist/browser.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _shipstatic_types from '@shipstatic/types';
2
- import { PingResponse, ConfigResponse, StaticFile, Deployment, DeploymentListResponse, Domain, DomainListResponse, Account, TokenCreateResponse, TokenListResponse, DeployInput, DeploymentResource, DomainResource, AccountResource, TokenResource, PlatformConfig } from '@shipstatic/types';
2
+ import { PingResponse, ConfigResponse, StaticFile, Deployment, DeploymentListResponse, Domain, DomainListResponse, Account, TokenCreateResponse, TokenListResponse, CheckoutSession, SubscriptionStatus, SubscriptionSyncResponse, DeployInput, DeploymentResource, DomainResource, AccountResource, TokenResource, SubscriptionResource, PlatformConfig, ValidatableFile, FileValidationResult } from '@shipstatic/types';
3
3
  export * from '@shipstatic/types';
4
- export { Account, DEFAULT_API, DeployInput, Deployment, Domain, PingResponse, ShipError, ShipErrorType } from '@shipstatic/types';
4
+ export { Account, DEFAULT_API, DeployInput, Deployment, Domain, FileValidationStatus as FILE_VALIDATION_STATUS, PingResponse, ShipError, ShipErrorType } from '@shipstatic/types';
5
5
 
6
6
  /**
7
7
  * @file SDK-specific type definitions
@@ -35,10 +35,8 @@ interface DeploymentOptions {
35
35
  spaDetect?: boolean;
36
36
  /** Optional array of tags for categorization and filtering (lowercase, alphanumeric with separators). */
37
37
  tags?: string[];
38
- /** Callback for overall deploy progress (0-100). */
39
- onProgress?: (progress: number) => void;
40
- /** Callback for detailed progress statistics. */
41
- onProgressStats?: (progressStats: ProgressStats) => void;
38
+ /** Callback for deploy progress with detailed statistics. */
39
+ onProgress?: (info: ProgressInfo) => void;
42
40
  }
43
41
  /**
44
42
  * Options for configuring an deploy operation via `apiClient.deployFiles`.
@@ -46,16 +44,17 @@ interface DeploymentOptions {
46
44
  */
47
45
  type ApiDeployOptions = Omit<DeploymentOptions, 'pathDetect'>;
48
46
  /**
49
- * Detailed statistics about the progress of an deploy operation.
47
+ * Progress information for deploy operations.
48
+ * Provides consistent percentage-based progress with byte-level details.
50
49
  */
51
- interface ProgressStats {
52
- /** The number of bytes loaded so far. */
50
+ interface ProgressInfo {
51
+ /** Progress percentage (0-100). */
52
+ percent: number;
53
+ /** Number of bytes loaded so far. */
53
54
  loaded: number;
54
- /** The total number of bytes to be loaded. May be 0 if unknown initially. */
55
+ /** Total number of bytes to be loaded. May be 0 if unknown initially. */
55
56
  total: number;
56
- /** The progress as a fraction (loaded/total). Value is between 0 and 1. */
57
- progress: number;
58
- /** Optional identifier for the file this progress pertains to, if applicable. */
57
+ /** Current file being processed (optional). */
59
58
  file?: string;
60
59
  }
61
60
  /**
@@ -72,15 +71,10 @@ interface ShipClientOptions {
72
71
  /** Path to custom config file. */
73
72
  configFile?: string | undefined;
74
73
  /**
75
- * Default callback for overall deploy progress for deploys made with this client.
76
- * @param progress - A number between 0 and 100.
74
+ * Default callback for deploy progress for deploys made with this client.
75
+ * @param info - Progress information including percentage and byte counts.
77
76
  */
78
- onProgress?: ((progress: number) => void) | undefined;
79
- /**
80
- * Default callback for detailed progress statistics for deploys made with this client.
81
- * @param progressStats - Progress statistics object.
82
- */
83
- onProgressStats?: ((progressStats: ProgressStats) => void) | undefined;
77
+ onProgress?: ((info: ProgressInfo) => void) | undefined;
84
78
  /**
85
79
  * Default for maximum concurrent deploys.
86
80
  * Used if an deploy operation doesn't specify its own `maxConcurrency`.
@@ -92,6 +86,15 @@ interface ShipClientOptions {
92
86
  * Used if an deploy operation doesn't specify its own timeout.
93
87
  */
94
88
  timeout?: number | undefined;
89
+ /**
90
+ * When true, indicates the client should use HTTP-only cookies for authentication
91
+ * instead of explicit tokens. This is useful for internal browser applications
92
+ * where authentication is handled via secure cookies set by the API.
93
+ *
94
+ * When set, the pre-request authentication check is skipped, allowing requests
95
+ * to proceed with cookie-based credentials.
96
+ */
97
+ useCredentials?: boolean | undefined;
95
98
  }
96
99
  /**
97
100
  * Event map for Ship SDK events
@@ -221,6 +224,23 @@ declare class ApiHttp extends SimpleEvents {
221
224
  createToken(ttl?: number, tags?: string[]): Promise<TokenCreateResponse>;
222
225
  listTokens(): Promise<TokenListResponse>;
223
226
  removeToken(token: string): Promise<void>;
227
+ /**
228
+ * Create a Creem checkout session for subscription
229
+ * POST /subscriptions/checkout
230
+ */
231
+ createCheckout(): Promise<CheckoutSession>;
232
+ /**
233
+ * Get current subscription status and usage
234
+ * GET /subscriptions/status
235
+ */
236
+ getSubscriptionStatus(): Promise<SubscriptionStatus>;
237
+ /**
238
+ * Sync subscription ID after checkout redirect
239
+ * POST /subscriptions/sync
240
+ *
241
+ * @param subscriptionId - Subscription ID from Creem redirect URL
242
+ */
243
+ syncSubscription(subscriptionId: string): Promise<SubscriptionSyncResponse>;
224
244
  checkSPA(files: StaticFile[]): Promise<boolean>;
225
245
  private validateFiles;
226
246
  private prepareRequestPayload;
@@ -237,6 +257,7 @@ declare function createDeploymentResource(getApi: () => ApiHttp, clientDefaults?
237
257
  declare function createDomainResource(getApi: () => ApiHttp, ensureInit?: () => Promise<void>): DomainResource;
238
258
  declare function createAccountResource(getApi: () => ApiHttp, ensureInit?: () => Promise<void>): AccountResource;
239
259
  declare function createTokenResource(getApi: () => ApiHttp, ensureInit?: () => Promise<void>): TokenResource;
260
+ declare function createSubscriptionResource(getApi: () => ApiHttp, ensureInit?: () => Promise<void>): SubscriptionResource;
240
261
 
241
262
  /**
242
263
  * Abstract base class for Ship SDK implementations.
@@ -255,6 +276,7 @@ declare abstract class Ship$1 {
255
276
  protected _domains: DomainResource;
256
277
  protected _account: AccountResource;
257
278
  protected _tokens: TokenResource;
279
+ protected _subscriptions: SubscriptionResource;
258
280
  constructor(options?: ShipClientOptions);
259
281
  protected abstract resolveInitialConfig(options: ShipClientOptions): any;
260
282
  protected abstract loadFullConfig(): Promise<void>;
@@ -291,6 +313,10 @@ declare abstract class Ship$1 {
291
313
  * Get tokens resource
292
314
  */
293
315
  get tokens(): TokenResource;
316
+ /**
317
+ * Get subscriptions resource
318
+ */
319
+ get subscriptions(): SubscriptionResource;
294
320
  /**
295
321
  * Get API configuration (file upload limits, etc.)
296
322
  * Reuses platform config fetched during initialization, then caches the result
@@ -401,6 +427,35 @@ declare const JUNK_DIRECTORIES: readonly ["__MACOSX", ".Trashes", ".fseventsd",
401
427
  *
402
428
  * @param filePaths - An array of file path strings to filter
403
429
  * @returns A new array containing only non-junk file paths
430
+ *
431
+ * @example
432
+ * ```typescript
433
+ * import { filterJunk } from '@shipstatic/ship';
434
+ *
435
+ * // Filter an array of file paths
436
+ * const paths = ['index.html', '.DS_Store', '__MACOSX/file.txt', 'app.js'];
437
+ * const clean = filterJunk(paths);
438
+ * // Result: ['index.html', 'app.js']
439
+ * ```
440
+ *
441
+ * @example
442
+ * ```typescript
443
+ * // Use with browser File objects
444
+ * import { filterJunk } from '@shipstatic/ship';
445
+ *
446
+ * const files: File[] = [...]; // From input or drag-drop
447
+ *
448
+ * // Extract paths from File objects
449
+ * const filePaths = files.map(f => f.webkitRelativePath || f.name);
450
+ *
451
+ * // Filter out junk paths
452
+ * const validPaths = new Set(filterJunk(filePaths));
453
+ *
454
+ * // Filter the original File array
455
+ * const validFiles = files.filter(f =>
456
+ * validPaths.has(f.webkitRelativePath || f.name)
457
+ * );
458
+ * ```
404
459
  */
405
460
  declare function filterJunk(filePaths: string[]): string[];
406
461
 
@@ -467,50 +522,6 @@ declare function getENV(): ExecutionEnvironment;
467
522
  * Provides client-side validation for file uploads before deployment
468
523
  */
469
524
 
470
- /**
471
- * File status constants for validation state tracking
472
- */
473
- declare const FILE_VALIDATION_STATUS: {
474
- readonly PENDING: "pending";
475
- readonly PROCESSING_ERROR: "processing_error";
476
- readonly EMPTY_FILE: "empty_file";
477
- readonly VALIDATION_FAILED: "validation_failed";
478
- readonly READY: "ready";
479
- };
480
- type FileValidationStatus = (typeof FILE_VALIDATION_STATUS)[keyof typeof FILE_VALIDATION_STATUS];
481
- /**
482
- * Client-side validation error structure
483
- */
484
- interface ValidationError {
485
- error: string;
486
- details: string;
487
- errors: string[];
488
- isClientError: true;
489
- }
490
- /**
491
- * Minimal file interface required for validation
492
- */
493
- interface ValidatableFile {
494
- name: string;
495
- size: number;
496
- type: string;
497
- status?: string;
498
- statusMessage?: string;
499
- }
500
- /**
501
- * File validation result
502
- *
503
- * NOTE: Validation is ATOMIC - if any file fails validation, ALL files are rejected.
504
- * This ensures deployments are all-or-nothing for data integrity.
505
- */
506
- interface FileValidationResult<T extends ValidatableFile> {
507
- /** All files with updated status */
508
- files: T[];
509
- /** Files that passed validation (empty if ANY file failed - atomic validation) */
510
- validFiles: T[];
511
- /** Validation error if any files failed */
512
- error: ValidationError | null;
513
- }
514
525
  /**
515
526
  * Format file size to human-readable string
516
527
  */
@@ -625,4 +636,4 @@ declare class Ship extends Ship$1 {
625
636
  protected processInput(input: DeployInput, options: DeploymentOptions): Promise<StaticFile[]>;
626
637
  }
627
638
 
628
- export { type ApiDeployOptions, ApiHttp, type Config, type DeployFile, type DeploymentOptions, type ExecutionEnvironment, FILE_VALIDATION_STATUS, type FileValidationResult, type FileValidationStatus, JUNK_DIRECTORIES, type MD5Result, type ProgressStats, Ship, type ShipClientOptions, type ShipEvents, type ValidatableFile, type ValidationError, __setTestEnvironment, allValidFilesReady, calculateMD5, createAccountResource, createDeploymentResource, createDomainResource, createTokenResource, Ship as default, filterJunk, formatFileSize, getCurrentConfig, getENV, getValidFiles, loadConfig, mergeDeployOptions, optimizeDeployPaths, pluralize, processFilesForBrowser, resolveConfig, setConfig as setPlatformConfig, validateFiles };
639
+ export { type ApiDeployOptions, ApiHttp, type Config, type DeployFile, type DeploymentOptions, type ExecutionEnvironment, JUNK_DIRECTORIES, type MD5Result, type ProgressInfo, Ship, type ShipClientOptions, type ShipEvents, __setTestEnvironment, allValidFilesReady, calculateMD5, createAccountResource, createDeploymentResource, createDomainResource, createSubscriptionResource, createTokenResource, Ship as default, filterJunk, formatFileSize, getCurrentConfig, getENV, getValidFiles, loadConfig, mergeDeployOptions, optimizeDeployPaths, pluralize, processFilesForBrowser, resolveConfig, setConfig as setPlatformConfig, validateFiles };