Skip to content

Commit

Permalink
Remove logs
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacroldan committed Feb 3, 2025
1 parent 344fd10 commit ddad615
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ import {
SchemaDefinitionByApiTypeQueryVariables,
} from '../../api/graphql/functions/generated/schema-definition-by-api-type.js'
import {WebhooksSpecIdentifier} from '../../models/extensions/specifications/app_config_webhook.js'
import {ensureAuthenticatedAppManagement, ensureAuthenticatedBusinessPlatform} from '@shopify/cli-kit/node/session'
import {
ensureAuthenticatedAppManagementAndBusinessPlatform,
ensureAuthenticatedBusinessPlatform,
} from '@shopify/cli-kit/node/session'
import {isUnitTest} from '@shopify/cli-kit/node/context/local'
import {AbortError, BugError} from '@shopify/cli-kit/node/error'
import {fetch} from '@shopify/cli-kit/node/http'
Expand Down Expand Up @@ -171,20 +174,23 @@ export class AppManagementClient implements DeveloperPlatformClient {
if (isUnitTest()) {
throw new Error('AppManagementClient.session() should not be invoked dynamically in a unit test')
}
const userInfoResult = await businessPlatformRequestDoc(UserInfo, await this.businessPlatformToken())
const {token, userId} = await ensureAuthenticatedAppManagement()
if (userInfoResult.currentUserAccount) {

const {appToken, userId, businessPlatformToken} = await ensureAuthenticatedAppManagementAndBusinessPlatform()
this._businessPlatformToken = businessPlatformToken
const userAccount = await businessPlatformRequestDoc(UserInfo, businessPlatformToken)

if (userAccount.currentUserAccount) {
this._session = {
token,
token: appToken,
accountInfo: {
type: 'UserAccount',
email: userInfoResult.currentUserAccount.email,
email: userAccount.currentUserAccount.email,
},
userId,
}
} else {
this._session = {
token,
token: appToken,
accountInfo: {
type: 'UnknownAccount',
},
Expand All @@ -200,10 +206,18 @@ export class AppManagementClient implements DeveloperPlatformClient {
}

async refreshToken(): Promise<string> {
const {token} = await ensureAuthenticatedAppManagement([], process.env, {noPrompt: true})
const {appToken, businessPlatformToken} = await ensureAuthenticatedAppManagementAndBusinessPlatform(
[],
[],
process.env,
{noPrompt: true},
)
const session = await this.session()
if (token) {
session.token = token
if (appToken) {
session.token = appToken
}
if (businessPlatformToken) {
this._businessPlatformToken = businessPlatformToken
}
return session.token
}
Expand Down
3 changes: 0 additions & 3 deletions packages/cli-kit/src/private/node/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {sanitizedHeadersOutput} from './api/headers.js'
import {sanitizeURL} from './api/urls.js'
import {startHRTime} from '@shopify/cli-kit/node/hrtime'
import {outputDebug} from '@shopify/cli-kit/node/output'
import {Headers} from 'form-data'
import {ClientError} from 'graphql-request'
Expand Down Expand Up @@ -54,9 +53,7 @@ async function makeVerboseRequest<T extends {headers: Headers; status: number}>(
const sanitizedUrl = sanitizeURL(url)
let response: T = {} as T
try {
const start = startHRTime()
response = await request()
// console.log(`${endHRTimeInMs(start)}ms - Network: ${outputContent`${outputToken.magenta(url)}`.value}`)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response.headers.forEach((value: any, key: any) => {
if (responseHeaderIsInteresting(key)) responseHeaders[key] = value
Expand Down
3 changes: 0 additions & 3 deletions packages/cli-kit/src/private/node/session/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {sessionConstants} from '../constants.js'
import {outputDebug} from '../../../public/node/output.js'
import {firstPartyDev} from '../../../public/node/context/local.js'
import {OAuthApplications} from '../session.js'
import {endHRTimeInMs, startHRTime} from '@shopify/cli-kit/node/hrtime'

type ValidationResult = 'needs_refresh' | 'needs_full_auth' | 'ok'

Expand Down Expand Up @@ -36,9 +35,7 @@ export async function validateSession(
): Promise<ValidationResult> {
if (!session) return 'needs_full_auth'
const scopesAreValid = validateScopes(scopes, session.identity)
const start = startHRTime()
const identityIsValid = await validateIdentityToken(session.identity.accessToken)
console.log(`${endHRTimeInMs(start)}ms - Auth: Identity token introspection (${identityIsValid ? 'OK' : 'FAILED'})`)
if (!scopesAreValid) return 'needs_full_auth'
let tokensAreExpired = isTokenExpired(session.identity)

Expand Down
1 change: 0 additions & 1 deletion packages/cli-kit/src/public/node/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export async function reportAnalyticsEvent(options: ReportAnalyticsEventOptions)
withinRateLimit = true
},
})
console.log('All network time:', payload.public.cmd_all_timing_network_ms)
if (!withinRateLimit) {
outputDebug(outputContent`Skipping command analytics due to rate limiting, payload: ${outputToken.json(payload)}`)
return
Expand Down
7 changes: 0 additions & 7 deletions packages/cli-kit/src/public/node/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {debugLogRequestInfo, errorHandler} from '../../../private/node/api/graph
import {addPublicMetadata, runWithTimer} from '../metadata.js'
import {retryAwareRequest} from '../../../private/node/api.js'
import {requestIdsCollection} from '../../../private/node/request-ids.js'
import {endHRTimeInMs, startHRTime} from '../hrtime.js'
import {outputContent, outputToken} from '../output.js'
import {
GraphQLClient,
rawRequest,
Expand Down Expand Up @@ -77,13 +75,8 @@ async function performGraphQLRequest<TResult>(options: PerformGraphQLRequestOpti
// there is a errorPolicy option which returns rather than throwing on errors, but we _do_ ultimately want to
// throw.
try {
const time = startHRTime()
fullResponse = await client.rawRequest<TResult>(queryAsString, variables)
await logLastRequestIdFromResponse(fullResponse)
const firstLine = queryAsString.split('\n')[0] ?? ''
const secondLine = queryAsString.split('\n')[1] ?? ''
const validLine = firstLine.includes('query') ? firstLine : secondLine
console.log(`${endHRTimeInMs(time)}ms - Network: ${outputContent`${outputToken.yellow(validLine)}`.value}`)
return fullResponse
} catch (error) {
if (error instanceof ClientError) {
Expand Down
28 changes: 20 additions & 8 deletions packages/cli-kit/src/public/node/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,37 @@ ${outputToken.json(scopes)}
/**
* Ensure that we have a valid session to access the App Management API.
*
* @param scopes - Optional array of extra scopes to authenticate with.
* @param appManagementScopes - Optional array of extra scopes to authenticate with.
* @param businessPlatformScopes - Optional array of extra scopes to authenticate with.
* @param env - Optional environment variables to use.
* @param options - Optional extra options to use.
* @returns The access token for the App Management API.
*/
export async function ensureAuthenticatedAppManagement(
scopes: AppManagementAPIScope[] = [],
export async function ensureAuthenticatedAppManagementAndBusinessPlatform(
appManagementScopes: AppManagementAPIScope[] = [],
businessPlatformScopes: BusinessPlatformScope[] = [],
env = process.env,
options: EnsureAuthenticatedAdditionalOptions = {},
): Promise<{token: string; userId: string}> {
): Promise<{appToken: string; userId: string; businessPlatformToken: string}> {
outputDebug(outputContent`Ensuring that the user is authenticated with the App Management API with the following scopes:
${outputToken.json(scopes)}
${outputToken.json(appManagementScopes)}
`)
const tokens = await ensureAuthenticated({appManagementApi: {scopes}}, env, options)
const tokens = await ensureAuthenticated(
{appManagementApi: {scopes: appManagementScopes}, businessPlatformApi: {scopes: businessPlatformScopes}},
env,
options,
)
if (!tokens) {
throw new BugError('No App Management token found after ensuring authenticated')
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return {token: tokens.appManagement!, userId: tokens.userId}

return {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
appToken: tokens.appManagement!,
userId: tokens.userId,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
businessPlatformToken: tokens.businessPlatform!,
}
}

/**
Expand Down

0 comments on commit ddad615

Please sign in to comment.