@shipstatic/types 0.4.7 → 0.4.9

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
@@ -700,10 +700,53 @@ export interface RateLimitData {
700
700
  timestamp: number;
701
701
  }
702
702
  /**
703
- * Generate deployment URL from deployment ID and base domain
703
+ * Check if a domain is a platform domain (subdomain of our platform).
704
+ * Platform domains are free and don't require DNS verification.
705
+ *
706
+ * @example isPlatformDomain("www.shipstatic.dev", "shipstatic.dev") → true
707
+ * @example isPlatformDomain("example.com", "shipstatic.dev") → false
708
+ */
709
+ export declare function isPlatformDomain(domain: string, platformDomain: string): boolean;
710
+ /**
711
+ * Check if a domain is a custom domain (not a platform subdomain).
712
+ * Custom domains are billable and require DNS verification.
713
+ *
714
+ * @example isCustomDomain("example.com", "shipstatic.dev") → true
715
+ * @example isCustomDomain("www.shipstatic.dev", "shipstatic.dev") → false
704
716
  */
705
- export declare function generateDeploymentUrl(deployment: string, baseDomain?: string): string;
717
+ export declare function isCustomDomain(domain: string, platformDomain: string): boolean;
706
718
  /**
707
- * Generate domain URL based on whether it's internal (subdomain) or external (custom domain)
719
+ * Extract subdomain from a platform domain.
720
+ * Returns null if not a platform domain.
721
+ *
722
+ * @example extractSubdomain("www.shipstatic.dev", "shipstatic.dev") → "www"
723
+ * @example extractSubdomain("example.com", "shipstatic.dev") → null
724
+ */
725
+ export declare function extractSubdomain(domain: string, platformDomain: string): string | null;
726
+ /**
727
+ * Generate deployment URL from deployment ID and platform domain
728
+ */
729
+ export declare function generateDeploymentUrl(deployment: string, platformDomain?: string): string;
730
+ /**
731
+ * Generate URL for a domain.
732
+ * Domains are stored as FQDNs, so this just prepends https://
733
+ */
734
+ export declare function generateDomainUrl(domain: string): string;
735
+ /**
736
+ * Serialize tags array to JSON string for database storage.
737
+ * Returns null for empty or undefined arrays.
738
+ *
739
+ * @example serializeTags(['web', 'production']) → '["web","production"]'
740
+ * @example serializeTags([]) → null
741
+ * @example serializeTags(undefined) → null
742
+ */
743
+ export declare function serializeTags(tags: string[] | undefined): string | null;
744
+ /**
745
+ * Deserialize tags from JSON string to array.
746
+ * Returns undefined for null/empty strings.
747
+ *
748
+ * @example deserializeTags('["web","production"]') → ['web', 'production']
749
+ * @example deserializeTags(null) → undefined
750
+ * @example deserializeTags('') → undefined
708
751
  */
709
- export declare function generateDomainUrl(domainName: string, baseDomain?: string): string;
752
+ export declare function deserializeTags(tagsJson: string | null): string[] | undefined;
package/dist/index.js CHANGED
@@ -278,24 +278,87 @@ export const FileValidationStatus = {
278
278
  READY: 'ready',
279
279
  };
280
280
  // =============================================================================
281
- // URL GENERATION UTILITIES
281
+ // DOMAIN UTILITIES
282
282
  // =============================================================================
283
283
  /**
284
- * Generate deployment URL from deployment ID and base domain
284
+ * Check if a domain is a platform domain (subdomain of our platform).
285
+ * Platform domains are free and don't require DNS verification.
286
+ *
287
+ * @example isPlatformDomain("www.shipstatic.dev", "shipstatic.dev") → true
288
+ * @example isPlatformDomain("example.com", "shipstatic.dev") → false
285
289
  */
286
- export function generateDeploymentUrl(deployment, baseDomain) {
287
- const domain = baseDomain || 'shipstatic.com';
290
+ export function isPlatformDomain(domain, platformDomain) {
291
+ return domain.endsWith(`.${platformDomain}`);
292
+ }
293
+ /**
294
+ * Check if a domain is a custom domain (not a platform subdomain).
295
+ * Custom domains are billable and require DNS verification.
296
+ *
297
+ * @example isCustomDomain("example.com", "shipstatic.dev") → true
298
+ * @example isCustomDomain("www.shipstatic.dev", "shipstatic.dev") → false
299
+ */
300
+ export function isCustomDomain(domain, platformDomain) {
301
+ return !isPlatformDomain(domain, platformDomain);
302
+ }
303
+ /**
304
+ * Extract subdomain from a platform domain.
305
+ * Returns null if not a platform domain.
306
+ *
307
+ * @example extractSubdomain("www.shipstatic.dev", "shipstatic.dev") → "www"
308
+ * @example extractSubdomain("example.com", "shipstatic.dev") → null
309
+ */
310
+ export function extractSubdomain(domain, platformDomain) {
311
+ if (!isPlatformDomain(domain, platformDomain)) {
312
+ return null;
313
+ }
314
+ return domain.slice(0, -(platformDomain.length + 1)); // +1 for the dot
315
+ }
316
+ /**
317
+ * Generate deployment URL from deployment ID and platform domain
318
+ */
319
+ export function generateDeploymentUrl(deployment, platformDomain) {
320
+ const domain = platformDomain || 'shipstatic.com';
288
321
  return `https://${deployment}.${domain}`;
289
322
  }
290
323
  /**
291
- * Generate domain URL based on whether it's internal (subdomain) or external (custom domain)
324
+ * Generate URL for a domain.
325
+ * Domains are stored as FQDNs, so this just prepends https://
292
326
  */
293
- export function generateDomainUrl(domainName, baseDomain) {
294
- // If domain contains dots, it's an external domain
295
- if (domainName.includes('.')) {
296
- return `https://${domainName}`;
297
- }
298
- // Otherwise it's an internal subdomain
299
- const domain = baseDomain || 'shipstatic.com';
300
- return `https://${domainName}.${domain}`;
327
+ export function generateDomainUrl(domain) {
328
+ return `https://${domain}`;
329
+ }
330
+ // =============================================================================
331
+ // TAG UTILITIES
332
+ // =============================================================================
333
+ /**
334
+ * Serialize tags array to JSON string for database storage.
335
+ * Returns null for empty or undefined arrays.
336
+ *
337
+ * @example serializeTags(['web', 'production']) → '["web","production"]'
338
+ * @example serializeTags([]) → null
339
+ * @example serializeTags(undefined) → null
340
+ */
341
+ export function serializeTags(tags) {
342
+ if (!tags || tags.length === 0)
343
+ return null;
344
+ return JSON.stringify(tags);
345
+ }
346
+ /**
347
+ * Deserialize tags from JSON string to array.
348
+ * Returns undefined for null/empty strings.
349
+ *
350
+ * @example deserializeTags('["web","production"]') → ['web', 'production']
351
+ * @example deserializeTags(null) → undefined
352
+ * @example deserializeTags('') → undefined
353
+ */
354
+ export function deserializeTags(tagsJson) {
355
+ if (!tagsJson)
356
+ return undefined;
357
+ try {
358
+ const parsed = JSON.parse(tagsJson);
359
+ return Array.isArray(parsed) && parsed.length > 0 ? parsed : undefined;
360
+ }
361
+ catch {
362
+ return undefined;
363
+ }
301
364
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipstatic/types",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "Shared types for Shipstatic platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1040,27 +1040,92 @@ export interface RateLimitData {
1040
1040
  }
1041
1041
 
1042
1042
  // =============================================================================
1043
- // URL GENERATION UTILITIES
1043
+ // DOMAIN UTILITIES
1044
1044
  // =============================================================================
1045
1045
 
1046
1046
  /**
1047
- * Generate deployment URL from deployment ID and base domain
1047
+ * Check if a domain is a platform domain (subdomain of our platform).
1048
+ * Platform domains are free and don't require DNS verification.
1049
+ *
1050
+ * @example isPlatformDomain("www.shipstatic.dev", "shipstatic.dev") → true
1051
+ * @example isPlatformDomain("example.com", "shipstatic.dev") → false
1048
1052
  */
1049
- export function generateDeploymentUrl(deployment: string, baseDomain?: string): string {
1050
- const domain = baseDomain || 'shipstatic.com';
1051
- return `https://${deployment}.${domain}`;
1053
+ export function isPlatformDomain(domain: string, platformDomain: string): boolean {
1054
+ return domain.endsWith(`.${platformDomain}`);
1055
+ }
1056
+
1057
+ /**
1058
+ * Check if a domain is a custom domain (not a platform subdomain).
1059
+ * Custom domains are billable and require DNS verification.
1060
+ *
1061
+ * @example isCustomDomain("example.com", "shipstatic.dev") → true
1062
+ * @example isCustomDomain("www.shipstatic.dev", "shipstatic.dev") → false
1063
+ */
1064
+ export function isCustomDomain(domain: string, platformDomain: string): boolean {
1065
+ return !isPlatformDomain(domain, platformDomain);
1052
1066
  }
1053
1067
 
1054
1068
  /**
1055
- * Generate domain URL based on whether it's internal (subdomain) or external (custom domain)
1069
+ * Extract subdomain from a platform domain.
1070
+ * Returns null if not a platform domain.
1071
+ *
1072
+ * @example extractSubdomain("www.shipstatic.dev", "shipstatic.dev") → "www"
1073
+ * @example extractSubdomain("example.com", "shipstatic.dev") → null
1056
1074
  */
1057
- export function generateDomainUrl(domainName: string, baseDomain?: string): string {
1058
- // If domain contains dots, it's an external domain
1059
- if (domainName.includes('.')) {
1060
- return `https://${domainName}`;
1075
+ export function extractSubdomain(domain: string, platformDomain: string): string | null {
1076
+ if (!isPlatformDomain(domain, platformDomain)) {
1077
+ return null;
1061
1078
  }
1079
+ return domain.slice(0, -(platformDomain.length + 1)); // +1 for the dot
1080
+ }
1081
+
1082
+ /**
1083
+ * Generate deployment URL from deployment ID and platform domain
1084
+ */
1085
+ export function generateDeploymentUrl(deployment: string, platformDomain?: string): string {
1086
+ const domain = platformDomain || 'shipstatic.com';
1087
+ return `https://${deployment}.${domain}`;
1088
+ }
1062
1089
 
1063
- // Otherwise it's an internal subdomain
1064
- const domain = baseDomain || 'shipstatic.com';
1065
- return `https://${domainName}.${domain}`;
1090
+ /**
1091
+ * Generate URL for a domain.
1092
+ * Domains are stored as FQDNs, so this just prepends https://
1093
+ */
1094
+ export function generateDomainUrl(domain: string): string {
1095
+ return `https://${domain}`;
1096
+ }
1097
+
1098
+ // =============================================================================
1099
+ // TAG UTILITIES
1100
+ // =============================================================================
1101
+
1102
+ /**
1103
+ * Serialize tags array to JSON string for database storage.
1104
+ * Returns null for empty or undefined arrays.
1105
+ *
1106
+ * @example serializeTags(['web', 'production']) → '["web","production"]'
1107
+ * @example serializeTags([]) → null
1108
+ * @example serializeTags(undefined) → null
1109
+ */
1110
+ export function serializeTags(tags: string[] | undefined): string | null {
1111
+ if (!tags || tags.length === 0) return null;
1112
+ return JSON.stringify(tags);
1113
+ }
1114
+
1115
+ /**
1116
+ * Deserialize tags from JSON string to array.
1117
+ * Returns undefined for null/empty strings.
1118
+ *
1119
+ * @example deserializeTags('["web","production"]') → ['web', 'production']
1120
+ * @example deserializeTags(null) → undefined
1121
+ * @example deserializeTags('') → undefined
1122
+ */
1123
+ export function deserializeTags(tagsJson: string | null): string[] | undefined {
1124
+ if (!tagsJson) return undefined;
1125
+ try {
1126
+ const parsed = JSON.parse(tagsJson);
1127
+ return Array.isArray(parsed) && parsed.length > 0 ? parsed : undefined;
1128
+ } catch {
1129
+ return undefined;
1130
+ }
1066
1131
  }