@shipstatic/types 0.4.18 → 0.4.19
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 +27 -2
- package/dist/index.js +51 -0
- package/package.json +1 -1
- package/src/index.ts +60 -2
package/dist/index.d.ts
CHANGED
|
@@ -339,6 +339,9 @@ export declare class ShipError extends Error {
|
|
|
339
339
|
export declare function isShipError(error: unknown): error is ShipError;
|
|
340
340
|
/**
|
|
341
341
|
* Platform configuration response from API
|
|
342
|
+
*
|
|
343
|
+
* Contains ONLY dynamic, runtime-specific values (plan-based limits).
|
|
344
|
+
* Static constants (MIME types, validation rules) live as exported constants.
|
|
342
345
|
*/
|
|
343
346
|
export interface ConfigResponse {
|
|
344
347
|
/** Maximum individual file size in bytes */
|
|
@@ -347,9 +350,31 @@ export interface ConfigResponse {
|
|
|
347
350
|
maxFilesCount: number;
|
|
348
351
|
/** Maximum total deployment size in bytes */
|
|
349
352
|
maxTotalSize: number;
|
|
350
|
-
/** Allowed MIME type categories for file validation */
|
|
351
|
-
allowedMimeTypes: string[];
|
|
352
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Allowed MIME types and prefixes for file uploads.
|
|
356
|
+
*
|
|
357
|
+
* This is a static platform constant, not per-user configuration.
|
|
358
|
+
* Safe to share across frontend/backend due to atomic deploys.
|
|
359
|
+
*
|
|
360
|
+
* Validation rules:
|
|
361
|
+
* - Exact match: 'application/json' allows only 'application/json'
|
|
362
|
+
* - Prefix match: 'text/' allows 'text/plain', 'text/html', etc.
|
|
363
|
+
*/
|
|
364
|
+
export declare const ALLOWED_MIME_TYPES: readonly ["text/", "image/", "audio/", "video/", "font/", "model/", "application/json", "application/javascript", "application/pdf", "application/xml", "application/manifest+json", "application/toml", "application/font-woff", "application/font-woff2", "application/x-font-woff", "application/x-woff", "application/vnd.ms-fontobject", "application/x-font-ttf", "application/x-font-truetype", "application/x-font-otf", "application/x-font-opentype"];
|
|
365
|
+
/**
|
|
366
|
+
* Check if a MIME type is allowed for upload.
|
|
367
|
+
*
|
|
368
|
+
* Supports both exact matches and prefix matches:
|
|
369
|
+
* - 'application/json' matches 'application/json' exactly
|
|
370
|
+
* - 'text/' matches 'text/plain', 'text/html', etc.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* isAllowedMimeType('text/plain') // true (prefix match)
|
|
374
|
+
* isAllowedMimeType('application/json') // true (exact match)
|
|
375
|
+
* isAllowedMimeType('application/wasm') // false (not allowed)
|
|
376
|
+
*/
|
|
377
|
+
export declare function isAllowedMimeType(mimeType: string): boolean;
|
|
353
378
|
/**
|
|
354
379
|
* Generic success response wrapper
|
|
355
380
|
*/
|
package/dist/index.js
CHANGED
|
@@ -199,6 +199,57 @@ export function isShipError(error) {
|
|
|
199
199
|
error.name === 'ShipError' &&
|
|
200
200
|
'status' in error);
|
|
201
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Allowed MIME types and prefixes for file uploads.
|
|
204
|
+
*
|
|
205
|
+
* This is a static platform constant, not per-user configuration.
|
|
206
|
+
* Safe to share across frontend/backend due to atomic deploys.
|
|
207
|
+
*
|
|
208
|
+
* Validation rules:
|
|
209
|
+
* - Exact match: 'application/json' allows only 'application/json'
|
|
210
|
+
* - Prefix match: 'text/' allows 'text/plain', 'text/html', etc.
|
|
211
|
+
*/
|
|
212
|
+
export const ALLOWED_MIME_TYPES = [
|
|
213
|
+
// Common web content (prefix matches)
|
|
214
|
+
'text/', // All text types
|
|
215
|
+
'image/', // All image types
|
|
216
|
+
'audio/', // All audio types
|
|
217
|
+
'video/', // All video types
|
|
218
|
+
'font/', // Modern font types (font/woff, font/woff2, font/ttf, font/otf)
|
|
219
|
+
'model/', // 3D models
|
|
220
|
+
// Specific application types (exact matches)
|
|
221
|
+
'application/json',
|
|
222
|
+
'application/javascript',
|
|
223
|
+
'application/pdf',
|
|
224
|
+
'application/xml',
|
|
225
|
+
'application/manifest+json',
|
|
226
|
+
'application/toml',
|
|
227
|
+
// Legacy font MIME types (for Bootstrap, Font Awesome, etc.)
|
|
228
|
+
'application/font-woff',
|
|
229
|
+
'application/font-woff2',
|
|
230
|
+
'application/x-font-woff',
|
|
231
|
+
'application/x-woff',
|
|
232
|
+
'application/vnd.ms-fontobject', // .eot files (IE compatibility)
|
|
233
|
+
'application/x-font-ttf',
|
|
234
|
+
'application/x-font-truetype',
|
|
235
|
+
'application/x-font-otf',
|
|
236
|
+
'application/x-font-opentype',
|
|
237
|
+
];
|
|
238
|
+
/**
|
|
239
|
+
* Check if a MIME type is allowed for upload.
|
|
240
|
+
*
|
|
241
|
+
* Supports both exact matches and prefix matches:
|
|
242
|
+
* - 'application/json' matches 'application/json' exactly
|
|
243
|
+
* - 'text/' matches 'text/plain', 'text/html', etc.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* isAllowedMimeType('text/plain') // true (prefix match)
|
|
247
|
+
* isAllowedMimeType('application/json') // true (exact match)
|
|
248
|
+
* isAllowedMimeType('application/wasm') // false (not allowed)
|
|
249
|
+
*/
|
|
250
|
+
export function isAllowedMimeType(mimeType) {
|
|
251
|
+
return ALLOWED_MIME_TYPES.some(allowed => mimeType === allowed || mimeType.startsWith(allowed));
|
|
252
|
+
}
|
|
202
253
|
// API Key Configuration
|
|
203
254
|
export const API_KEY_PREFIX = 'ship-';
|
|
204
255
|
export const API_KEY_HEX_LENGTH = 64;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -492,6 +492,9 @@ export function isShipError(error: unknown): error is ShipError {
|
|
|
492
492
|
|
|
493
493
|
/**
|
|
494
494
|
* Platform configuration response from API
|
|
495
|
+
*
|
|
496
|
+
* Contains ONLY dynamic, runtime-specific values (plan-based limits).
|
|
497
|
+
* Static constants (MIME types, validation rules) live as exported constants.
|
|
495
498
|
*/
|
|
496
499
|
export interface ConfigResponse {
|
|
497
500
|
/** Maximum individual file size in bytes */
|
|
@@ -500,8 +503,63 @@ export interface ConfigResponse {
|
|
|
500
503
|
maxFilesCount: number;
|
|
501
504
|
/** Maximum total deployment size in bytes */
|
|
502
505
|
maxTotalSize: number;
|
|
503
|
-
|
|
504
|
-
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Allowed MIME types and prefixes for file uploads.
|
|
510
|
+
*
|
|
511
|
+
* This is a static platform constant, not per-user configuration.
|
|
512
|
+
* Safe to share across frontend/backend due to atomic deploys.
|
|
513
|
+
*
|
|
514
|
+
* Validation rules:
|
|
515
|
+
* - Exact match: 'application/json' allows only 'application/json'
|
|
516
|
+
* - Prefix match: 'text/' allows 'text/plain', 'text/html', etc.
|
|
517
|
+
*/
|
|
518
|
+
export const ALLOWED_MIME_TYPES = [
|
|
519
|
+
// Common web content (prefix matches)
|
|
520
|
+
'text/', // All text types
|
|
521
|
+
'image/', // All image types
|
|
522
|
+
'audio/', // All audio types
|
|
523
|
+
'video/', // All video types
|
|
524
|
+
'font/', // Modern font types (font/woff, font/woff2, font/ttf, font/otf)
|
|
525
|
+
'model/', // 3D models
|
|
526
|
+
|
|
527
|
+
// Specific application types (exact matches)
|
|
528
|
+
'application/json',
|
|
529
|
+
'application/javascript',
|
|
530
|
+
'application/pdf',
|
|
531
|
+
'application/xml',
|
|
532
|
+
'application/manifest+json',
|
|
533
|
+
'application/toml',
|
|
534
|
+
|
|
535
|
+
// Legacy font MIME types (for Bootstrap, Font Awesome, etc.)
|
|
536
|
+
'application/font-woff',
|
|
537
|
+
'application/font-woff2',
|
|
538
|
+
'application/x-font-woff',
|
|
539
|
+
'application/x-woff',
|
|
540
|
+
'application/vnd.ms-fontobject', // .eot files (IE compatibility)
|
|
541
|
+
'application/x-font-ttf',
|
|
542
|
+
'application/x-font-truetype',
|
|
543
|
+
'application/x-font-otf',
|
|
544
|
+
'application/x-font-opentype',
|
|
545
|
+
] as const;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Check if a MIME type is allowed for upload.
|
|
549
|
+
*
|
|
550
|
+
* Supports both exact matches and prefix matches:
|
|
551
|
+
* - 'application/json' matches 'application/json' exactly
|
|
552
|
+
* - 'text/' matches 'text/plain', 'text/html', etc.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* isAllowedMimeType('text/plain') // true (prefix match)
|
|
556
|
+
* isAllowedMimeType('application/json') // true (exact match)
|
|
557
|
+
* isAllowedMimeType('application/wasm') // false (not allowed)
|
|
558
|
+
*/
|
|
559
|
+
export function isAllowedMimeType(mimeType: string): boolean {
|
|
560
|
+
return ALLOWED_MIME_TYPES.some(allowed =>
|
|
561
|
+
mimeType === allowed || mimeType.startsWith(allowed)
|
|
562
|
+
);
|
|
505
563
|
}
|
|
506
564
|
|
|
507
565
|
// =============================================================================
|