Skip to content

Commit e95f2cd

Browse files
authored
Merge pull request #5359 from Shopify/theme-access-domain
Add support to staging theme access app staging
2 parents 7db60d6 + 2b8f36a commit e95f2cd

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

packages/cli-kit/src/private/node/context/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Returns whether an environment variable has been set and is non-empty
33
*/
4-
export function isSet(variable: string | undefined): boolean {
4+
export function isSet(variable: string | undefined): variable is string {
55
if (variable === undefined || variable.trim() === '') {
66
return false
77
}

packages/cli-kit/src/public/node/context/local.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
cloudEnvironment,
99
macAddress,
1010
isAppManagementDisabled,
11+
getThemeKitAccessDomain,
12+
opentelemetryDomain,
1113
} from './local.js'
1214
import {getPartnersToken} from '../environment.js'
1315
import {fileExists} from '../fs.js'
@@ -306,3 +308,51 @@ describe('ciPlatform', () => {
306308
})
307309
})
308310
})
311+
312+
describe('getThemeKitAccessDomain', () => {
313+
test('returns default domain when env var not set', () => {
314+
// Given
315+
const env = {}
316+
317+
// When
318+
const got = getThemeKitAccessDomain(env)
319+
320+
// Then
321+
expect(got).toBe('theme-kit-access.shopifyapps.com')
322+
})
323+
324+
test('returns custom domain when env var set', () => {
325+
// Given
326+
const env = {SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN: 'theme-kit-staging.shopifyapps.com'}
327+
328+
// When
329+
const got = getThemeKitAccessDomain(env)
330+
331+
// Then
332+
expect(got).toBe('theme-kit-staging.shopifyapps.com')
333+
})
334+
})
335+
336+
describe('opentelemetryDomain', () => {
337+
test('returns default domain when env var not set', () => {
338+
// Given
339+
const env = {}
340+
341+
// When
342+
const got = opentelemetryDomain(env)
343+
344+
// Then
345+
expect(got).toBe('https://otlp-http-production-cli.shopifysvc.com')
346+
})
347+
348+
test('returns custom domain when env var set', () => {
349+
// Given
350+
const env = {SHOPIFY_CLI_OTEL_EXPORTER_OTLP_ENDPOINT: 'custom-otel-domain.com'}
351+
352+
// When
353+
const got = opentelemetryDomain(env)
354+
355+
// Then
356+
expect(got).toBe('custom-otel-domain.com')
357+
})
358+
})

packages/cli-kit/src/public/node/context/local.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {isSpin} from './spin.js'
22
import {isTruthy} from './utilities.js'
33
import {getCIMetadata, isSet, Metadata} from '../../../private/node/context/utilities.js'
4-
import {environmentVariables, pathConstants} from '../../../private/node/constants.js'
4+
import {defaultThemeKitAccessDomain, environmentVariables, pathConstants} from '../../../private/node/constants.js'
55
import {fileExists} from '../fs.js'
66
import {exec} from '../system.js'
77
import {getPartnersToken} from '../environment.js'
@@ -287,6 +287,22 @@ export function macAddress(): Promise<string> {
287287
return macaddress.one()
288288
}
289289

290+
/**
291+
* Get the domain for theme kit access.
292+
*
293+
* It can be overridden via the SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN environment
294+
* variable.
295+
*
296+
* @param env - The environment variables from the environment of the process.
297+
*
298+
* @returns The domain for theme kit access.
299+
*/
300+
export function getThemeKitAccessDomain(env = process.env): string {
301+
const domain = env[environmentVariables.themeKitAccessDomain]
302+
303+
return isSet(domain) ? domain : defaultThemeKitAccessDomain
304+
}
305+
290306
/**
291307
* Get the domain to send OTEL metrics to.
292308
*
@@ -295,11 +311,10 @@ export function macAddress(): Promise<string> {
295311
* @param env - The environment variables from the environment of the current process.
296312
* @returns The domain to send OTEL metrics to.
297313
*/
298-
export function opentelemetryDomain(env = process.env): string | undefined {
299-
if (isSet(env[environmentVariables.otelURL])) {
300-
return env[environmentVariables.otelURL]
301-
}
302-
return 'https://otlp-http-production-cli.shopifysvc.com'
314+
export function opentelemetryDomain(env = process.env): string {
315+
const domain = env[environmentVariables.otelURL]
316+
317+
return isSet(domain) ? domain : 'https://otlp-http-production-cli.shopifysvc.com'
303318
}
304319

305320
export type CIMetadata = Metadata

packages/theme/src/cli/utilities/theme-environment/storefront-renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {outputDebug} from '@shopify/cli-kit/node/output'
55
import {AdminSession} from '@shopify/cli-kit/node/session'
66
import {fetch, type Response} from '@shopify/cli-kit/node/http'
77
import {createError} from 'h3'
8+
import {getThemeKitAccessDomain} from '@shopify/cli-kit/node/context/local'
89

910
export async function render(session: DevServerSession, context: DevServerRenderContext): Promise<Response> {
1011
const url = buildStorefrontUrl(session, context)
@@ -131,7 +132,7 @@ function buildStorefrontUrl(session: DevServerSession, {path, sectionId, appBloc
131132

132133
export function buildBaseStorefrontUrl(session: AdminSession) {
133134
if (isThemeAccessSession(session)) {
134-
return 'https://theme-kit-access.shopifyapps.com/cli/sfr'
135+
return `https://${getThemeKitAccessDomain()}/cli/sfr`
135136
} else {
136137
return `https://${session.storeFqdn}`
137138
}

0 commit comments

Comments
 (0)