-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathfqdn.ts
More file actions
143 lines (135 loc) · 4.17 KB
/
fqdn.ts
File metadata and controls
143 lines (135 loc) · 4.17 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import {AbortError} from '../error.js'
import {serviceEnvironment} from '../../../private/node/context/service.js'
import {DevServer, DevServerCore} from '../vendor/dev_server/index.js'
export const NotProvidedStoreFQDNError = new AbortError(
"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.",
)
/**
* It returns the Partners' API service we should interact with.
*
* @returns Fully-qualified domain of the partners service we should interact with.
*/
export async function partnersFqdn(): Promise<string> {
const environment = serviceEnvironment()
const productionFqdn = 'partners.shopify.com'
switch (environment) {
case 'local':
return new DevServer('partners').host()
default:
return productionFqdn
}
}
/**
* It returns the Admin service we should interact with.
*
* @returns Fully-qualified domain of the Admin service we should interact with.
*/
export async function adminFqdn(): Promise<string> {
const environment = serviceEnvironment()
const productionFqdn = 'admin.shopify.com'
switch (environment) {
case 'local':
return new DevServerCore().host('admin')
default:
return productionFqdn
}
}
/**
* It returns the App Management API service we should interact with.
*
* @returns Fully-qualified domain of the App Management service we should interact with.
*/
export async function appManagementFqdn(): Promise<string> {
const environment = serviceEnvironment()
const productionFqdn = 'app.shopify.com'
switch (environment) {
case 'local':
return new DevServerCore().host('app')
default:
return productionFqdn
}
}
/**
* It returns the App Dev API service we should interact with.
*
* @param storeFqdn - The store FQDN.
* @returns Fully-qualified domain of the App Dev service we should interact with.
*/
export async function appDevFqdn(storeFqdn: string): Promise<string> {
const environment = serviceEnvironment()
switch (environment) {
case 'local':
return new DevServerCore().host('app')
default:
return storeFqdn
}
}
/**
* It returns the Developer Dashboard domain we should interact with.
*
* @returns Fully-qualified domain of the Developer Dashboard we should interact with.
*/
export async function developerDashboardFqdn(): Promise<string> {
const environment = serviceEnvironment()
const productionFqdn = 'dev.shopify.com'
switch (environment) {
case 'local':
return new DevServerCore().host('dev')
default:
return productionFqdn
}
}
/**
* It returns the BusinessPlatform' API service we should interact with.
*
* @returns Fully-qualified domain of the partners service we should interact with.
*/
export async function businessPlatformFqdn(): Promise<string> {
const environment = serviceEnvironment()
const productionFqdn = 'destinations.shopifysvc.com'
switch (environment) {
case 'local':
return new DevServer('business-platform').host()
default:
return productionFqdn
}
}
/**
* It returns the Identity service we should interact with.
*
* @returns Fully-qualified domain of the Identity service we should interact with.
*/
export async function identityFqdn(): Promise<string> {
const environment = serviceEnvironment()
const productionFqdn = 'accounts.shopify.com'
switch (environment) {
case 'local':
return new DevServer('identity').host()
default:
return productionFqdn
}
}
/**
* Normalize the store name to be used in the CLI.
* It will add the .myshopify.com domain if it's not present.
*
* @param store - Store name.
* @returns Normalized store name.
*/
export function normalizeStoreFqdn(store: string): string {
const storeFqdn = store
.replace(/^https?:\/\//, '')
.replace(/\/$/, '')
.replace(/\/admin$/, '')
const addDomain = (storeFqdn: string) => {
switch (serviceEnvironment()) {
case 'local':
return new DevServerCore().host(storeFqdn)
default:
return `${storeFqdn}.myshopify.com`
}
}
const containDomain = (storeFqdn: string) =>
storeFqdn.endsWith('.myshopify.com') || storeFqdn.endsWith('shopify.io') || storeFqdn.endsWith('.shop.dev')
return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)
}