@shipstatic/types 0.4.6 → 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 +42 -6
- package/dist/index.js +73 -2
- package/package.json +1 -1
- package/src/index.ts +77 -8
package/dist/index.d.ts
CHANGED
|
@@ -36,8 +36,6 @@ export interface Deployment {
|
|
|
36
36
|
readonly created: number;
|
|
37
37
|
/** Unix timestamp (seconds) when deployment expires */
|
|
38
38
|
expires?: number;
|
|
39
|
-
/** Unix timestamp (seconds) when deployment was reviewed (content moderation) */
|
|
40
|
-
reviewed?: number;
|
|
41
39
|
/** Short-lived JWT token for claiming this deployment (only present for public deployments) */
|
|
42
40
|
claimToken?: string;
|
|
43
41
|
}
|
|
@@ -79,10 +77,6 @@ export interface Domain {
|
|
|
79
77
|
readonly created: number;
|
|
80
78
|
/** Whether this was a create (201) or update (200) operation */
|
|
81
79
|
readonly isCreate?: boolean;
|
|
82
|
-
/** When DNS was verified (Unix timestamp, null if pending) */
|
|
83
|
-
verified?: number;
|
|
84
|
-
/** Total DNS verification attempts */
|
|
85
|
-
verifications?: number;
|
|
86
80
|
/** When deployment was last linked (Unix timestamp, null if never) */
|
|
87
81
|
linked?: number;
|
|
88
82
|
/** Total deployment links */
|
|
@@ -705,6 +699,22 @@ export interface RateLimitData {
|
|
|
705
699
|
count: number;
|
|
706
700
|
timestamp: number;
|
|
707
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;
|
|
708
718
|
/**
|
|
709
719
|
* Generate deployment URL from deployment ID and base domain
|
|
710
720
|
*/
|
|
@@ -713,3 +723,29 @@ export declare function generateDeploymentUrl(deployment: string, baseDomain?: s
|
|
|
713
723
|
* Generate domain URL based on whether it's internal (subdomain) or external (custom domain)
|
|
714
724
|
*/
|
|
715
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
|
-
//
|
|
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
|
|
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
package/src/index.ts
CHANGED
|
@@ -43,8 +43,6 @@ export interface Deployment {
|
|
|
43
43
|
readonly created: number;
|
|
44
44
|
/** Unix timestamp (seconds) when deployment expires */
|
|
45
45
|
expires?: number; // Mutable - can be updated
|
|
46
|
-
/** Unix timestamp (seconds) when deployment was reviewed (content moderation) */
|
|
47
|
-
reviewed?: number; // Mutable - can be updated
|
|
48
46
|
/** Short-lived JWT token for claiming this deployment (only present for public deployments) */
|
|
49
47
|
claimToken?: string; // Mutable - can be updated
|
|
50
48
|
}
|
|
@@ -95,10 +93,6 @@ export interface Domain {
|
|
|
95
93
|
readonly created: number;
|
|
96
94
|
/** Whether this was a create (201) or update (200) operation */
|
|
97
95
|
readonly isCreate?: boolean;
|
|
98
|
-
/** When DNS was verified (Unix timestamp, null if pending) */
|
|
99
|
-
verified?: number;
|
|
100
|
-
/** Total DNS verification attempts */
|
|
101
|
-
verifications?: number;
|
|
102
96
|
/** When deployment was last linked (Unix timestamp, null if never) */
|
|
103
97
|
linked?: number;
|
|
104
98
|
/** Total deployment links */
|
|
@@ -1046,9 +1040,31 @@ export interface RateLimitData {
|
|
|
1046
1040
|
}
|
|
1047
1041
|
|
|
1048
1042
|
// =============================================================================
|
|
1049
|
-
//
|
|
1043
|
+
// DOMAIN UTILITIES
|
|
1050
1044
|
// =============================================================================
|
|
1051
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
|
+
|
|
1052
1068
|
/**
|
|
1053
1069
|
* Generate deployment URL from deployment ID and base domain
|
|
1054
1070
|
*/
|
|
@@ -1062,11 +1078,64 @@ export function generateDeploymentUrl(deployment: string, baseDomain?: string):
|
|
|
1062
1078
|
*/
|
|
1063
1079
|
export function generateDomainUrl(domainName: string, baseDomain?: string): string {
|
|
1064
1080
|
// If domain contains dots, it's an external domain
|
|
1065
|
-
if (domainName
|
|
1081
|
+
if (isExternalDomain(domainName)) {
|
|
1066
1082
|
return `https://${domainName}`;
|
|
1067
1083
|
}
|
|
1068
1084
|
|
|
1069
1085
|
// Otherwise it's an internal subdomain
|
|
1070
1086
|
const domain = baseDomain || 'shipstatic.com';
|
|
1071
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
|
+
}
|
|
1072
1141
|
}
|