@shipstatic/types 0.4.7 → 0.4.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/dist/index.d.ts CHANGED
@@ -699,6 +699,22 @@ export interface RateLimitData {
699
699
  count: number;
700
700
  timestamp: number;
701
701
  }
702
+ /**
703
+ * Check if a domain is internal (a subdomain of our platform).
704
+ * Internal domains have no dots (e.g., "www", "my-app").
705
+ *
706
+ * @example isInternalDomain("www") → true
707
+ * @example isInternalDomain("example.com") → false
708
+ */
709
+ export declare function isInternalDomain(domain: string): boolean;
710
+ /**
711
+ * Check if a domain is external (a custom domain).
712
+ * External domains contain at least one dot (e.g., "example.com").
713
+ *
714
+ * @example isExternalDomain("example.com") → true
715
+ * @example isExternalDomain("www") → false
716
+ */
717
+ export declare function isExternalDomain(domain: string): boolean;
702
718
  /**
703
719
  * Generate deployment URL from deployment ID and base domain
704
720
  */
@@ -707,3 +723,29 @@ export declare function generateDeploymentUrl(deployment: string, baseDomain?: s
707
723
  * Generate domain URL based on whether it's internal (subdomain) or external (custom domain)
708
724
  */
709
725
  export declare function generateDomainUrl(domainName: string, baseDomain?: string): string;
726
+ /**
727
+ * Format domain name for display (hostname only, no protocol).
728
+ * Expands internal domains to full hostname.
729
+ *
730
+ * @example formatDomainName("www", "shipstatic.dev") → "www.shipstatic.dev"
731
+ * @example formatDomainName("example.com") → "example.com"
732
+ */
733
+ export declare function formatDomainName(domainName: string, baseDomain?: string): string;
734
+ /**
735
+ * Serialize tags array to JSON string for database storage.
736
+ * Returns null for empty or undefined arrays.
737
+ *
738
+ * @example serializeTags(['web', 'production']) → '["web","production"]'
739
+ * @example serializeTags([]) → null
740
+ * @example serializeTags(undefined) → null
741
+ */
742
+ export declare function serializeTags(tags: string[] | undefined): string | null;
743
+ /**
744
+ * Deserialize tags from JSON string to array.
745
+ * Returns undefined for null/empty strings.
746
+ *
747
+ * @example deserializeTags('["web","production"]') → ['web', 'production']
748
+ * @example deserializeTags(null) → undefined
749
+ * @example deserializeTags('') → undefined
750
+ */
751
+ export declare function deserializeTags(tagsJson: string | null): string[] | undefined;
package/dist/index.js CHANGED
@@ -278,8 +278,28 @@ export const FileValidationStatus = {
278
278
  READY: 'ready',
279
279
  };
280
280
  // =============================================================================
281
- // URL GENERATION UTILITIES
281
+ // DOMAIN UTILITIES
282
282
  // =============================================================================
283
+ /**
284
+ * Check if a domain is internal (a subdomain of our platform).
285
+ * Internal domains have no dots (e.g., "www", "my-app").
286
+ *
287
+ * @example isInternalDomain("www") → true
288
+ * @example isInternalDomain("example.com") → false
289
+ */
290
+ export function isInternalDomain(domain) {
291
+ return !domain.includes('.');
292
+ }
293
+ /**
294
+ * Check if a domain is external (a custom domain).
295
+ * External domains contain at least one dot (e.g., "example.com").
296
+ *
297
+ * @example isExternalDomain("example.com") → true
298
+ * @example isExternalDomain("www") → false
299
+ */
300
+ export function isExternalDomain(domain) {
301
+ return domain.includes('.');
302
+ }
283
303
  /**
284
304
  * Generate deployment URL from deployment ID and base domain
285
305
  */
@@ -292,10 +312,61 @@ export function generateDeploymentUrl(deployment, baseDomain) {
292
312
  */
293
313
  export function generateDomainUrl(domainName, baseDomain) {
294
314
  // If domain contains dots, it's an external domain
295
- if (domainName.includes('.')) {
315
+ if (isExternalDomain(domainName)) {
296
316
  return `https://${domainName}`;
297
317
  }
298
318
  // Otherwise it's an internal subdomain
299
319
  const domain = baseDomain || 'shipstatic.com';
300
320
  return `https://${domainName}.${domain}`;
301
321
  }
322
+ /**
323
+ * Format domain name for display (hostname only, no protocol).
324
+ * Expands internal domains to full hostname.
325
+ *
326
+ * @example formatDomainName("www", "shipstatic.dev") → "www.shipstatic.dev"
327
+ * @example formatDomainName("example.com") → "example.com"
328
+ */
329
+ export function formatDomainName(domainName, baseDomain) {
330
+ // If domain contains dots, it's an external domain - return as-is
331
+ if (isExternalDomain(domainName)) {
332
+ return domainName;
333
+ }
334
+ // Otherwise it's an internal subdomain - expand it
335
+ const domain = baseDomain || 'shipstatic.com';
336
+ return `${domainName}.${domain}`;
337
+ }
338
+ // =============================================================================
339
+ // TAG UTILITIES
340
+ // =============================================================================
341
+ /**
342
+ * Serialize tags array to JSON string for database storage.
343
+ * Returns null for empty or undefined arrays.
344
+ *
345
+ * @example serializeTags(['web', 'production']) → '["web","production"]'
346
+ * @example serializeTags([]) → null
347
+ * @example serializeTags(undefined) → null
348
+ */
349
+ export function serializeTags(tags) {
350
+ if (!tags || tags.length === 0)
351
+ return null;
352
+ return JSON.stringify(tags);
353
+ }
354
+ /**
355
+ * Deserialize tags from JSON string to array.
356
+ * Returns undefined for null/empty strings.
357
+ *
358
+ * @example deserializeTags('["web","production"]') → ['web', 'production']
359
+ * @example deserializeTags(null) → undefined
360
+ * @example deserializeTags('') → undefined
361
+ */
362
+ export function deserializeTags(tagsJson) {
363
+ if (!tagsJson)
364
+ return undefined;
365
+ try {
366
+ const parsed = JSON.parse(tagsJson);
367
+ return Array.isArray(parsed) && parsed.length > 0 ? parsed : undefined;
368
+ }
369
+ catch {
370
+ return undefined;
371
+ }
372
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Shared types for Shipstatic platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1040,9 +1040,31 @@ export interface RateLimitData {
1040
1040
  }
1041
1041
 
1042
1042
  // =============================================================================
1043
- // URL GENERATION UTILITIES
1043
+ // DOMAIN UTILITIES
1044
1044
  // =============================================================================
1045
1045
 
1046
+ /**
1047
+ * Check if a domain is internal (a subdomain of our platform).
1048
+ * Internal domains have no dots (e.g., "www", "my-app").
1049
+ *
1050
+ * @example isInternalDomain("www") → true
1051
+ * @example isInternalDomain("example.com") → false
1052
+ */
1053
+ export function isInternalDomain(domain: string): boolean {
1054
+ return !domain.includes('.');
1055
+ }
1056
+
1057
+ /**
1058
+ * Check if a domain is external (a custom domain).
1059
+ * External domains contain at least one dot (e.g., "example.com").
1060
+ *
1061
+ * @example isExternalDomain("example.com") → true
1062
+ * @example isExternalDomain("www") → false
1063
+ */
1064
+ export function isExternalDomain(domain: string): boolean {
1065
+ return domain.includes('.');
1066
+ }
1067
+
1046
1068
  /**
1047
1069
  * Generate deployment URL from deployment ID and base domain
1048
1070
  */
@@ -1056,11 +1078,64 @@ export function generateDeploymentUrl(deployment: string, baseDomain?: string):
1056
1078
  */
1057
1079
  export function generateDomainUrl(domainName: string, baseDomain?: string): string {
1058
1080
  // If domain contains dots, it's an external domain
1059
- if (domainName.includes('.')) {
1081
+ if (isExternalDomain(domainName)) {
1060
1082
  return `https://${domainName}`;
1061
1083
  }
1062
1084
 
1063
1085
  // Otherwise it's an internal subdomain
1064
1086
  const domain = baseDomain || 'shipstatic.com';
1065
1087
  return `https://${domainName}.${domain}`;
1088
+ }
1089
+
1090
+ /**
1091
+ * Format domain name for display (hostname only, no protocol).
1092
+ * Expands internal domains to full hostname.
1093
+ *
1094
+ * @example formatDomainName("www", "shipstatic.dev") → "www.shipstatic.dev"
1095
+ * @example formatDomainName("example.com") → "example.com"
1096
+ */
1097
+ export function formatDomainName(domainName: string, baseDomain?: string): string {
1098
+ // If domain contains dots, it's an external domain - return as-is
1099
+ if (isExternalDomain(domainName)) {
1100
+ return domainName;
1101
+ }
1102
+
1103
+ // Otherwise it's an internal subdomain - expand it
1104
+ const domain = baseDomain || 'shipstatic.com';
1105
+ return `${domainName}.${domain}`;
1106
+ }
1107
+
1108
+ // =============================================================================
1109
+ // TAG UTILITIES
1110
+ // =============================================================================
1111
+
1112
+ /**
1113
+ * Serialize tags array to JSON string for database storage.
1114
+ * Returns null for empty or undefined arrays.
1115
+ *
1116
+ * @example serializeTags(['web', 'production']) → '["web","production"]'
1117
+ * @example serializeTags([]) → null
1118
+ * @example serializeTags(undefined) → null
1119
+ */
1120
+ export function serializeTags(tags: string[] | undefined): string | null {
1121
+ if (!tags || tags.length === 0) return null;
1122
+ return JSON.stringify(tags);
1123
+ }
1124
+
1125
+ /**
1126
+ * Deserialize tags from JSON string to array.
1127
+ * Returns undefined for null/empty strings.
1128
+ *
1129
+ * @example deserializeTags('["web","production"]') → ['web', 'production']
1130
+ * @example deserializeTags(null) → undefined
1131
+ * @example deserializeTags('') → undefined
1132
+ */
1133
+ export function deserializeTags(tagsJson: string | null): string[] | undefined {
1134
+ if (!tagsJson) return undefined;
1135
+ try {
1136
+ const parsed = JSON.parse(tagsJson);
1137
+ return Array.isArray(parsed) && parsed.length > 0 ? parsed : undefined;
1138
+ } catch {
1139
+ return undefined;
1140
+ }
1066
1141
  }