-
-
Notifications
You must be signed in to change notification settings - Fork 340
Expand file tree
/
Copy pathshared.ts
More file actions
81 lines (71 loc) · 1.96 KB
/
shared.ts
File metadata and controls
81 lines (71 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Shared Deploy Dialog utilities
*
* Common types, constants, and validation for deploy dialogs.
*/
export type DeployProvider = 'cloudflare' | 'netlify' | 'railway'
export type DeployState =
| { step: 'auth-check' }
| { step: 'needs-auth' }
| { step: 'form' }
| { step: 'deploying'; message: string }
| { step: 'success'; repoUrl: string; owner: string; repoName: string }
| { step: 'error'; message: string; code?: string }
export type RepoNameStatus =
| 'idle'
| 'checking'
| 'available'
| 'taken'
| 'invalid'
export interface ProviderInfo {
name: string
color: string
deployUrl: (owner: string, repo: string) => string
}
export const PROVIDER_INFO: Record<DeployProvider, ProviderInfo> = {
cloudflare: {
name: 'Cloudflare',
color: '#F38020',
deployUrl: (owner, repo) =>
`https://deploy.workers.cloudflare.com/?url=https://github.com/${owner}/${repo}`,
},
netlify: {
name: 'Netlify',
color: '#00C7B7',
deployUrl: (owner, repo) =>
`https://app.netlify.com/start/deploy?repository=https://github.com/${owner}/${repo}`,
},
railway: {
name: 'Railway',
color: '#9B4DCA',
deployUrl: () =>
`https://railway.com/new/github?utm_medium=sponsor&utm_source=oss&utm_campaign=tanstack`,
},
}
export async function checkRepoNameAvailability(
name: string,
): Promise<{ available: boolean }> {
const response = await fetch(
`/api/builder/deploy/check-name?name=${encodeURIComponent(name)}`,
)
return response.json()
}
export function validateRepoNameFormat(name: string): {
valid: boolean
error?: string
} {
if (!name.trim()) {
return { valid: false }
}
const validPattern = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/
if (!validPattern.test(name)) {
return {
valid: false,
error: 'Letters, numbers, hyphens, underscores, and periods only',
}
}
if (name.length > 100) {
return { valid: false, error: 'Must be 100 characters or less' }
}
return { valid: true }
}