@shipstatic/types 0.4.12 → 0.4.14

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/dist/index.d.ts CHANGED
@@ -292,11 +292,10 @@ export declare class ShipError extends Error {
292
292
  static cancelled(message: string): ShipError;
293
293
  static file(message: string, filePath?: string): ShipError;
294
294
  static config(message: string, details?: any): ShipError;
295
- static api(message: string, status?: number, code?: string, data?: any): ShipError;
295
+ static api(message: string, status?: number): ShipError;
296
296
  static database(message: string, status?: number): ShipError;
297
297
  static storage(message: string, status?: number): ShipError;
298
298
  get filePath(): string | undefined;
299
- get code(): string | undefined;
300
299
  isClientError(): boolean;
301
300
  isNetworkError(): boolean;
302
301
  isAuthError(): boolean;
@@ -305,6 +304,18 @@ export declare class ShipError extends Error {
305
304
  isConfigError(): boolean;
306
305
  isType(errorType: ErrorType): boolean;
307
306
  }
307
+ /**
308
+ * Type guard to check if an unknown value is a ShipError.
309
+ *
310
+ * Uses structural checking instead of instanceof to handle module duplication
311
+ * in bundled applications where multiple copies of the ShipError class may exist.
312
+ *
313
+ * @example
314
+ * if (isShipError(error)) {
315
+ * console.log(error.status, error.message);
316
+ * }
317
+ */
318
+ export declare function isShipError(error: unknown): error is ShipError;
308
319
  /**
309
320
  * Platform configuration response from API
310
321
  */
@@ -501,6 +512,11 @@ export interface DomainResource {
501
512
  verify: (name: string) => Promise<{
502
513
  message: string;
503
514
  }>;
515
+ validate: (name: string) => Promise<{
516
+ valid: boolean;
517
+ normalized?: string;
518
+ error?: string;
519
+ }>;
504
520
  dns: (name: string) => Promise<DomainDnsResponse>;
505
521
  records: (name: string) => Promise<DomainRecordsResponse>;
506
522
  share: (name: string) => Promise<{
package/dist/index.js CHANGED
@@ -138,8 +138,8 @@ export class ShipError extends Error {
138
138
  static config(message, details) {
139
139
  return new ShipError(ErrorType.Config, message, undefined, details);
140
140
  }
141
- static api(message, status = 500, code, data) {
142
- return new ShipError(ErrorType.Api, message, status, { code, data });
141
+ static api(message, status = 500) {
142
+ return new ShipError(ErrorType.Api, message, status);
143
143
  }
144
144
  static database(message, status = 500) {
145
145
  return new ShipError(ErrorType.Api, message, status);
@@ -147,13 +147,10 @@ export class ShipError extends Error {
147
147
  static storage(message, status = 500) {
148
148
  return new ShipError(ErrorType.Api, message, status);
149
149
  }
150
- // Helper getters for accessing common detail properties
150
+ // Helper getter for accessing file path from details
151
151
  get filePath() {
152
152
  return this.details?.filePath;
153
153
  }
154
- get code() {
155
- return this.details?.code;
156
- }
157
154
  // Helper methods for error type checking using categorization
158
155
  isClientError() {
159
156
  return ERROR_CATEGORIES.client.has(this.type);
@@ -178,6 +175,24 @@ export class ShipError extends Error {
178
175
  return this.type === errorType;
179
176
  }
180
177
  }
178
+ /**
179
+ * Type guard to check if an unknown value is a ShipError.
180
+ *
181
+ * Uses structural checking instead of instanceof to handle module duplication
182
+ * in bundled applications where multiple copies of the ShipError class may exist.
183
+ *
184
+ * @example
185
+ * if (isShipError(error)) {
186
+ * console.log(error.status, error.message);
187
+ * }
188
+ */
189
+ export function isShipError(error) {
190
+ return (error !== null &&
191
+ typeof error === 'object' &&
192
+ 'name' in error &&
193
+ error.name === 'ShipError' &&
194
+ 'status' in error);
195
+ }
181
196
  // API Key Configuration
182
197
  export const API_KEY_PREFIX = 'ship-';
183
198
  export const API_KEY_HEX_LENGTH = 64;
@@ -246,7 +261,7 @@ export function validateApiUrl(apiUrl) {
246
261
  }
247
262
  }
248
263
  catch (error) {
249
- if (error instanceof ShipError) {
264
+ if (isShipError(error)) {
250
265
  throw error;
251
266
  }
252
267
  throw ShipError.validation('API URL must be a valid URL');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "Shared types for Shipstatic platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -395,8 +395,8 @@ export class ShipError extends Error {
395
395
  return new ShipError(ErrorType.Config, message, undefined, details);
396
396
  }
397
397
 
398
- static api(message: string, status: number = 500, code?: string, data?: any): ShipError {
399
- return new ShipError(ErrorType.Api, message, status, { code, data });
398
+ static api(message: string, status: number = 500): ShipError {
399
+ return new ShipError(ErrorType.Api, message, status);
400
400
  }
401
401
 
402
402
  static database(message: string, status: number = 500): ShipError {
@@ -407,15 +407,11 @@ export class ShipError extends Error {
407
407
  return new ShipError(ErrorType.Api, message, status);
408
408
  }
409
409
 
410
- // Helper getters for accessing common detail properties
410
+ // Helper getter for accessing file path from details
411
411
  get filePath(): string | undefined {
412
412
  return this.details?.filePath;
413
413
  }
414
414
 
415
- get code(): string | undefined {
416
- return this.details?.code;
417
- }
418
-
419
415
  // Helper methods for error type checking using categorization
420
416
  isClientError(): boolean {
421
417
  return ERROR_CATEGORIES.client.has(this.type);
@@ -447,6 +443,27 @@ export class ShipError extends Error {
447
443
  }
448
444
  }
449
445
 
446
+ /**
447
+ * Type guard to check if an unknown value is a ShipError.
448
+ *
449
+ * Uses structural checking instead of instanceof to handle module duplication
450
+ * in bundled applications where multiple copies of the ShipError class may exist.
451
+ *
452
+ * @example
453
+ * if (isShipError(error)) {
454
+ * console.log(error.status, error.message);
455
+ * }
456
+ */
457
+ export function isShipError(error: unknown): error is ShipError {
458
+ return (
459
+ error !== null &&
460
+ typeof error === 'object' &&
461
+ 'name' in error &&
462
+ error.name === 'ShipError' &&
463
+ 'status' in error
464
+ );
465
+ }
466
+
450
467
  // =============================================================================
451
468
  // CONFIG TYPES
452
469
  // =============================================================================
@@ -572,7 +589,7 @@ export function validateApiUrl(apiUrl: string): void {
572
589
  throw ShipError.validation('API URL must not contain query parameters or fragments');
573
590
  }
574
591
  } catch (error) {
575
- if (error instanceof ShipError) {
592
+ if (isShipError(error)) {
576
593
  throw error;
577
594
  }
578
595
  throw ShipError.validation('API URL must be a valid URL');
@@ -747,6 +764,7 @@ export interface DomainResource {
747
764
  get: (name: string) => Promise<Domain>;
748
765
  remove: (name: string) => Promise<void>;
749
766
  verify: (name: string) => Promise<{ message: string }>;
767
+ validate: (name: string) => Promise<{ valid: boolean; normalized?: string; error?: string }>;
750
768
  dns: (name: string) => Promise<DomainDnsResponse>;
751
769
  records: (name: string) => Promise<DomainRecordsResponse>;
752
770
  share: (name: string) => Promise<{ domain: string; hash: string }>;