Skip to content

Commit

Permalink
feat: add remaining events [FTL-8912] (#95)
Browse files Browse the repository at this point in the history
* feat: [FTL-8912] Added more events

* feat: add time taken to generate app

---------

Co-authored-by: diegoscaro <[email protected]>
  • Loading branch information
YoussefAWasfy and diegoscaro authored Feb 2, 2023
1 parent 337eddf commit 7b88fef
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/auth/authentication-provider/auth-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ProgressLocation, window } from 'vscode'
import { authMessage } from '../messages'
import { userManagementClient } from '../../features/user-management/userManagementClient'
import { validateEmail, validateOTP } from './validators'
import { credentialsVault } from '../../config/credentialsVault'
import { telemetryHelpers } from '../../features/telemetry/telemetryHelpers'

type AuthProcessOutput = {
id: string
Expand Down Expand Up @@ -73,7 +75,9 @@ export const executeAuthProcess = async ({
})
},
)

credentialsVault.setTimeStamp()
if (isSignUp) telemetryHelpers.trackCommand('affinidi.signUp.completed')
else telemetryHelpers.trackCommand('affinidi.login.completed')
const { userId } = parseJwt(consoleAuthToken)

return { email, id: userId, accessToken: consoleAuthToken }
Expand Down
2 changes: 0 additions & 2 deletions src/auth/init-authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async function signUpHandler(): Promise<void> {

window.showInformationMessage(authMessage.signedUp)
ext.outputChannel.appendLine(authMessage.signedUp)

await iamHelpers.createDefaultProject()

cliHelper.suggestInstallingCLI()
Expand All @@ -60,7 +59,6 @@ async function loginHandler(): Promise<void> {
await authentication.getSession(AUTH_PROVIDER_ID, ['login'], {
forceNewSession: true,
})

window.showInformationMessage(authMessage.loggedIn)
ext.outputChannel.appendLine(authMessage.loggedIn)
cliHelper.suggestInstallingCLI()
Expand Down
9 changes: 9 additions & 0 deletions src/config/credentialsVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ConfigType = {
env?: Environment
activeProjectSummary?: ProjectSummary
session?: Session
timeStamp?: number
}

export type Session = {
Expand Down Expand Up @@ -68,6 +69,14 @@ class CredentialsVault {
onSessionChange(callback: OnDidChangeCallback<Session | undefined>) {
return this.store.onDidChange('session', callback)
}

getTimeStamp(): number | undefined {
return this.store.get('timeStamp')
}

setTimeStamp() {
this.store.set('timeStamp', Date.now())
}
}

const credentialConf = new Conf<ConfigType>({
Expand Down
13 changes: 6 additions & 7 deletions src/config/validateVaultFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const configInlogin = z.object({
configs: z.record(z.optional(z.object({ activeProjectId: z.string() }))).optional(),
})

function clearVault() {
credentialsVault.clear()
configVault.clear()

window.showErrorMessage(configMessage.invalidConfigFiles)
}
export function validateConfig() {
const isConfigValid = isValidObject(configInlogin, configVault.getObject())

Expand All @@ -57,10 +63,3 @@ export function validateConfigAndCredentials() {
clearVault()
}
}

function clearVault() {
credentialsVault.clear()
configVault.clear()

window.showErrorMessage(configMessage.invalidConfigFiles)
}
16 changes: 12 additions & 4 deletions src/generators/initGenerators.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { commands } from 'vscode'

import { ext } from '../extensionVariables'
import { telemetryHelpers } from '../features/telemetry/telemetryHelpers'
import { generateAffinidiAppWithCLI } from './create-app/generator'
import { labels } from '../tree/messages'
import { DevToolsTreeItem } from '../tree/devToolsTreeItem'
import { credentialsVault } from '../config/credentialsVault'

export const initGenerators = () => {
ext.context.subscriptions.push(
commands.registerCommand('affinidi.codegen.app', async (element: DevToolsTreeItem) => {
telemetryHelpers.trackCommand('affinidi.codegen.app')

await generateAffinidiAppWithCLI(
const reffAppName =
element?.label?.toString() === labels.portableReputation
? 'portable-reputation'
: 'certification-and-verification',
)
: 'certification-and-verification'

const timeStamp = credentialsVault.getTimeStamp()
await generateAffinidiAppWithCLI(reffAppName)

telemetryHelpers.trackCommand('affinidi.codegen.app.completed', {
timeTaken: timeStamp ? Math.floor((Date.now() - timeStamp) / 1000) : 0,
referenceApp: reffAppName,
})
}),
)
}

0 comments on commit 7b88fef

Please sign in to comment.