@@ -12,20 +12,14 @@ import {
1212import { IdentityToken , Session } from './session/schema.js'
1313import * as secureStore from './session/store.js'
1414import { pollForDeviceAuthorization , requestDeviceAuthorization } from './session/device-authorization.js'
15- import { RequestClientError } from './api/headers.js'
16- import { getCachedPartnerAccountStatus , setCachedPartnerAccountStatus } from './conf-store.js'
1715import { isThemeAccessSession } from './api/rest.js'
1816import { outputContent , outputToken , outputDebug } from '../../public/node/output.js'
19- import { firstPartyDev , isAppManagementEnabled , themeToken } from '../../public/node/context/local.js'
17+ import { firstPartyDev , themeToken } from '../../public/node/context/local.js'
2018import { AbortError , BugError } from '../../public/node/error.js'
21- import { partnersRequest } from '../../public/node/api/partners.js'
22- import { normalizeStoreFqdn , partnersFqdn , identityFqdn } from '../../public/node/context/fqdn.js'
23- import { openURL } from '../../public/node/system.js'
24- import { keypress } from '../../public/node/ui.js'
19+ import { normalizeStoreFqdn , identityFqdn } from '../../public/node/context/fqdn.js'
2520import { getIdentityTokenInformation , getPartnersToken } from '../../public/node/environment.js'
26- import { gql } from 'graphql-request'
2721import { AdminSession } from '@shopify/cli-kit/node/session'
28- import { outputCompleted , outputInfo , outputWarn } from '@shopify/cli-kit/node/output'
22+ import { outputCompleted } from '@shopify/cli-kit/node/output'
2923import { isSpin } from '@shopify/cli-kit/node/context/spin'
3024import { nonRandomUUID } from '@shopify/cli-kit/node/crypto'
3125
@@ -247,9 +241,6 @@ The CLI is currently unable to prompt for reauthentication.`,
247241 if ( envToken && applications . partnersApi ) {
248242 tokens . partners = ( await exchangeCustomPartnerToken ( envToken ) ) . accessToken
249243 }
250- if ( ! envToken && tokens . partners ) {
251- await ensureUserHasPartnerAccount ( tokens . partners , tokens . userId )
252- }
253244
254245 setLastSeenAuthMethod ( envToken ? 'partners_token' : 'device_auth' )
255246 setLastSeenUserIdAfterAuth ( tokens . userId )
@@ -301,74 +292,6 @@ async function executeCompleteFlow(applications: OAuthApplications, identityFqdn
301292 return session
302293}
303294
304- /**
305- * If the user creates an account from the Identity website, the created
306- * account won't get a Partner organization created. We need to detect that
307- * and take the user to create a partner organization.
308- *
309- * @param partnersToken - Partners token.
310- */
311- async function ensureUserHasPartnerAccount ( partnersToken : string , userId : string | undefined ) {
312- if ( isAppManagementEnabled ( ) ) return
313-
314- outputDebug ( outputContent `Verifying that the user has a Partner organization` )
315- if ( ! ( await hasPartnerAccount ( partnersToken , userId ) ) ) {
316- outputInfo ( `\nA Shopify Partners organization is needed to proceed.` )
317- outputInfo ( `👉 Press any key to create one` )
318- await keypress ( )
319- await openURL ( `https://${ await partnersFqdn ( ) } /signup` )
320- outputInfo ( outputContent `👉 Press any key when you have ${ outputToken . cyan ( 'created the organization' ) } ` )
321- outputWarn ( outputContent `Make sure you've confirmed your Shopify and the Partner organization from the email` )
322- await keypress ( )
323- if ( ! ( await hasPartnerAccount ( partnersToken , userId ) ) ) {
324- throw new AbortError (
325- `Couldn't find your Shopify Partners organization` ,
326- `Have you confirmed your accounts from the emails you received?` ,
327- )
328- }
329- }
330- }
331-
332- // eslint-disable-next-line @shopify/cli/no-inline-graphql
333- const getFirstOrganization = gql `
334- {
335- organizations(first: 1) {
336- nodes {
337- id
338- }
339- }
340- }
341- `
342-
343- /**
344- * Validate if the current token is valid for partners API.
345- *
346- * @param partnersToken - Partners token.
347- * @returns A promise that resolves to true if the token is valid for partners API.
348- */
349- async function hasPartnerAccount ( partnersToken : string , userId ?: string ) : Promise < boolean > {
350- const cacheKey = userId ?? partnersToken
351- const cachedStatus = getCachedPartnerAccountStatus ( cacheKey )
352-
353- if ( cachedStatus ) {
354- outputDebug ( `Confirmed partner account exists from cache` )
355- return true
356- }
357-
358- try {
359- await partnersRequest ( getFirstOrganization , partnersToken )
360- setCachedPartnerAccountStatus ( cacheKey )
361- return true
362- // eslint-disable-next-line no-catch-all/no-catch-all
363- } catch ( error ) {
364- if ( error instanceof RequestClientError && error . statusCode === 404 ) {
365- return false
366- } else {
367- return true
368- }
369- }
370- }
371-
372295/**
373296 * Refresh the tokens for a given session.
374297 *
0 commit comments