Skip to content

Commit

Permalink
Add publicFetchStoreThemes function
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Sep 24, 2024
1 parent e03265e commit 77feaa7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/theme/src/cli/utilities/theme-selector/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import {fetchThemes} from '@shopify/cli-kit/node/themes/api'
import {AdminSession} from '@shopify/cli-kit/node/session'
import {AdminSession, ensureAuthenticatedThemes} from '@shopify/cli-kit/node/session'
import {AbortError} from '@shopify/cli-kit/node/error'
import {Theme} from '@shopify/cli-kit/node/themes/types'

export type Role = 'live' | 'development' | 'unpublished'
export const ALLOWED_ROLES: Role[] = ['live', 'unpublished', 'development']

/**
* Fetches the themes from the store.
* @param store - The store to fetch the themes from.
* @param password - The password to authenticate with.
* @returns The themes from the store.
*/
export async function publicFetchStoreThemes(store: string, password: string) {
const adminSession = await ensureAuthenticatedThemes(store, password)
return fetchStoreThemes(adminSession)
}

export async function fetchStoreThemes(session: AdminSession) {
const store = session.storeFqdn
const themes = (await fetchThemes(session)).filter(isRoleAllowed)
Expand Down
2 changes: 2 additions & 0 deletions packages/theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Serve from './cli/commands/theme/serve.js'
import Share from './cli/commands/theme/share.js'
import {pull} from './cli/services/pull.js'
import {push} from './cli/services/push.js'
import {publicFetchStoreThemes} from './cli/utilities/theme-selector/fetch.js'

const COMMANDS = {
'theme:init': Init,
Expand All @@ -39,6 +40,7 @@ const COMMANDS = {
const PUBLIC_COMMANDS = {
pull,
push,
publicFetchStoreThemes,
}

export {PUBLIC_COMMANDS}
Expand Down

0 comments on commit 77feaa7

Please sign in to comment.