@shipstatic/types 0.4.12 → 0.4.13
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 +13 -2
- package/dist/index.js +21 -6
- package/package.json +1 -1
- package/src/index.ts +24 -7
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
|
|
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
|
*/
|
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
|
|
142
|
-
return new ShipError(ErrorType.Api, message, status
|
|
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
|
|
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;
|
package/package.json
CHANGED
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
|
|
399
|
-
return new ShipError(ErrorType.Api, message, status
|
|
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
|
|
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
|
// =============================================================================
|