@shipstatic/ship 0.3.3 → 0.3.5

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
@@ -231,14 +231,21 @@ await ship.deployments.get(id)
231
231
 
232
232
  #### Deploy Input Types
233
233
 
234
- **Node.js Environment:**
235
234
  ```typescript
236
- type NodeDeployInput = string[]; // File paths
235
+ type DeployInput = File[] | string | string[];
237
236
  ```
238
237
 
238
+ **Node.js Environment:**
239
+ - `string` - Single file or directory path
240
+ - `string[]` - Multiple file/directory paths
241
+
239
242
  **Browser Environment:**
243
+ - `File[]` - Array of File objects
244
+
245
+ **Note:** For `<input type="file">` elements, convert FileList to File[]:
240
246
  ```typescript
241
- type BrowserDeployInput = FileList | File[] | HTMLInputElement;
247
+ const files = Array.from(fileInput.files);
248
+ await ship.deploy(files);
242
249
  ```
243
250
 
244
251
  #### Deploy Options
@@ -335,17 +342,14 @@ const ship = new Ship({
335
342
  apiKey: 'ship-your-64-char-hex-string' // 69 chars total
336
343
  });
337
344
 
338
- // From file input
345
+ // From file input - convert FileList to File[]
339
346
  const fileInput = document.getElementById('fileInput') as HTMLInputElement;
340
- const result = await ship.deployments.create(fileInput, {
347
+ const files: File[] = Array.from(fileInput.files || []);
348
+ const result = await ship.deployments.create(files, {
341
349
  onProgress: (progress) => {
342
350
  document.getElementById('progress').textContent = `${progress}%`;
343
351
  }
344
352
  });
345
-
346
- // From File objects
347
- const files: File[] = Array.from(fileInput.files || []);
348
- const result2 = await ship.deployments.create(files);
349
353
  ```
350
354
 
351
355
  ## Event System
package/dist/browser.d.ts CHANGED
@@ -159,9 +159,10 @@ declare class SimpleEvents {
159
159
  */
160
160
  declare class ApiHttp extends SimpleEvents {
161
161
  private readonly apiUrl;
162
- private readonly apiKey;
163
- private readonly deployToken;
164
- constructor(options: ShipClientOptions);
162
+ private readonly getAuthHeadersCallback;
163
+ constructor(options: ShipClientOptions & {
164
+ getAuthHeaders: () => Record<string, string>;
165
+ });
165
166
  /**
166
167
  * Transfer events to another client (clean intentional API)
167
168
  */
@@ -171,13 +172,9 @@ declare class ApiHttp extends SimpleEvents {
171
172
  */
172
173
  private request;
173
174
  /**
174
- * Generate auth headers
175
+ * Generate auth headers from Ship instance callback
175
176
  */
176
177
  private getAuthHeaders;
177
- /**
178
- * Check if credentials are needed
179
- */
180
- private needsCredentials;
181
178
  /**
182
179
  * Safely clone response for events
183
180
  */
@@ -236,7 +233,7 @@ declare class ApiHttp extends SimpleEvents {
236
233
  * @file Ship SDK resource implementations for deployments, domains, and accounts.
237
234
  */
238
235
 
239
- declare function createDeploymentResource(getApi: () => ApiHttp, clientDefaults?: ShipClientOptions, ensureInit?: () => Promise<void>, processInput?: (input: DeployInput, options: DeploymentOptions) => Promise<StaticFile[]>): DeploymentResource;
236
+ declare function createDeploymentResource(getApi: () => ApiHttp, clientDefaults?: ShipClientOptions, ensureInit?: () => Promise<void>, processInput?: (input: DeployInput, options: DeploymentOptions) => Promise<StaticFile[]>, hasAuth?: () => boolean): DeploymentResource;
240
237
  declare function createDomainResource(getApi: () => ApiHttp, ensureInit?: () => Promise<void>): DomainResource;
241
238
  declare function createAccountResource(getApi: () => ApiHttp, ensureInit?: () => Promise<void>): AccountResource;
242
239
  declare function createTokenResource(getApi: () => ApiHttp, ensureInit?: () => Promise<void>): TokenResource;
@@ -252,6 +249,8 @@ declare abstract class Ship$1 {
252
249
  protected readonly clientOptions: ShipClientOptions;
253
250
  protected initPromise: Promise<void> | null;
254
251
  protected _config: ConfigResponse | null;
252
+ private auth;
253
+ private readonly authHeadersCallback;
255
254
  protected _deployments: DeploymentResource;
256
255
  protected _domains: DomainResource;
257
256
  protected _account: AccountResource;
@@ -315,6 +314,30 @@ declare abstract class Ship$1 {
315
314
  * @protected
316
315
  */
317
316
  protected replaceHttpClient(newClient: ApiHttp): void;
317
+ /**
318
+ * Sets the deploy token for authentication.
319
+ * This will override any previously set API key or deploy token.
320
+ * @param token The deploy token (format: token-<64-char-hex>)
321
+ */
322
+ setDeployToken(token: string): void;
323
+ /**
324
+ * Sets the API key for authentication.
325
+ * This will override any previously set API key or deploy token.
326
+ * @param key The API key (format: ship-<64-char-hex>)
327
+ */
328
+ setApiKey(key: string): void;
329
+ /**
330
+ * Generate authorization headers based on current auth state
331
+ * Called dynamically on each request to ensure latest credentials are used
332
+ * @private
333
+ */
334
+ private getAuthHeaders;
335
+ /**
336
+ * Check if authentication credentials are configured
337
+ * Used by resources to fail fast if auth is required
338
+ * @private
339
+ */
340
+ private hasAuth;
318
341
  }
319
342
 
320
343
  /**
@@ -561,15 +584,15 @@ declare function getCurrentConfig(): ConfigResponse;
561
584
  */
562
585
 
563
586
  /**
564
- * Processes browser files (FileList or File[]) into an array of StaticFile objects ready for deploy.
587
+ * Processes browser files into an array of StaticFile objects ready for deploy.
565
588
  * Calculates MD5, filters junk files, and applies automatic path optimization.
566
589
  *
567
- * @param browserFiles - FileList or File[] to process for deploy.
590
+ * @param browserFiles - File[] to process for deploy.
568
591
  * @param options - Processing options including pathDetect for automatic path optimization.
569
592
  * @returns Promise resolving to an array of StaticFile objects.
570
593
  * @throws {ShipClientError} If called outside a browser or with invalid input.
571
594
  */
572
- declare function processFilesForBrowser(browserFiles: FileList | File[], options?: DeploymentOptions): Promise<StaticFile[]>;
595
+ declare function processFilesForBrowser(browserFiles: File[], options?: DeploymentOptions): Promise<StaticFile[]>;
573
596
 
574
597
  /**
575
598
  * @file Ship SDK for browser environments with streamlined configuration.
@@ -590,7 +613,7 @@ declare function processFilesForBrowser(browserFiles: FileList | File[], options
590
613
  * });
591
614
  *
592
615
  * // Deploy files from input element
593
- * const files = fileInput.files;
616
+ * const files = Array.from(fileInput.files);
594
617
  * await ship.deploy(files);
595
618
  * ```
596
619
  */