-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migration to new analytics #321
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7798b5f
added analytics
7dd29a5
new analytics
c27da11
connection established
75ea036
reimagined API Check w/ Lou
4ce6aa7
factor check results into analytics
9626bfd
add cwd to analytics
4c08e24
Merge branch 'develop' into migration-to-new-analytics
acunniffe 83bda94
Merge branch 'develop' into migration-to-new-analytics
acunniffe 04728f5
add target URL
77b4643
my changes
7f2e315
Merge branch 'migration-to-new-analytics' of https://github.com/optic…
a651c3d
fixed regression
58b606c
started sending proper clientId
acb0264
updated links. fixed failing empty check
814203c
added awaits
a8f9b2e
Updated Demo for new Analytics (#324)
trulyronak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
node_modules | ||
.idea | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { defaults: tsjPreset } = require('ts-jest/presets'); | ||
// const { jsWithTs: tsjPreset } = require('ts-jest/presets'); | ||
// const { jsWithBabel: tsjPreset } = require('ts-jest/presets'); | ||
|
||
module.exports = { | ||
// [...] | ||
transform: { | ||
...tsjPreset.transform, | ||
// [...] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@useoptic/analytics", | ||
"version": "8.3.0", | ||
"scripts": { | ||
"ws:build": "tsc -b --verbose", | ||
"ws:clean": "rm -rf build/*", | ||
"ws:test": "jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "ssh://git@github.com/useoptic/optic-package.git", | ||
"directory": "workspaces/cli-client" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"dependencies": { | ||
"@hapi/joi": "^17.1.1", | ||
"joi-extract-type": "^15.0.8", | ||
"keymirror": "^0.1.1", | ||
"uuid": "^8.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.9", | ||
"@types/node": "^14.0.27", | ||
"jest": "^26.4.0", | ||
"ts-jest": "^26.2.0" | ||
}, | ||
"files": [ | ||
"/lib" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
export const consistentAnonymousId = `anonymous_user_${uuidv4()}`; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { EventEmitter } from 'events'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import { | ||
ClientContext, | ||
TrackingEventBase, | ||
} from './interfaces/TrackingEventBase'; | ||
import exp from 'constants'; | ||
|
||
export function newAnalyticsEventBus( | ||
getContext: (batchId: string) => Promise<ClientContext> | ||
): AnalyticsEventBus { | ||
const eventEmitter = new EventEmitter(); | ||
return { | ||
emit: async (...events: TrackingEventBase<any>[]) => { | ||
const batchId = uuidv4(); | ||
const context = await getContext(batchId); | ||
events.forEach((event) => { | ||
eventEmitter.emit('event', { ...event, context }); | ||
}); | ||
}, | ||
eventEmitter, | ||
listen: (callback: (e: TrackingEventBase<any>) => void): void => { | ||
eventEmitter.on('event', callback); | ||
}, | ||
}; | ||
} | ||
|
||
export interface AnalyticsEventBus { | ||
eventEmitter: EventEmitter; | ||
emit: (...events: TrackingEventBase<any>[]) => void; | ||
listen: (callback: (e: TrackingEventBase<any>) => void) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
import { DescribeEvent, RegisteredEvent } from '../interfaces/RegisterEvent'; | ||
import { Events } from '../interfaces/Events'; | ||
// @ts-ignore | ||
import * as Joi from '@hapi/joi'; | ||
import 'joi-extract-type'; | ||
|
||
// Sent whenever an API is created | ||
const UserChangedCaptureOverviewTabSchema = Joi.object({ | ||
currentTab: Joi.string().required(), | ||
diffCount: Joi.number().required(), | ||
undocumentedUrlCount: Joi.number().required(), | ||
}); | ||
type UserChangedCaptureOverviewTabProperties = Joi.extractType< | ||
typeof UserChangedCaptureOverviewTabSchema | ||
>; | ||
export const UserChangedCaptureOverviewTab = DescribeEvent< | ||
UserChangedCaptureOverviewTabProperties | ||
>( | ||
Events.UserChangedCaptureOverviewTab, | ||
UserChangedCaptureOverviewTabSchema, | ||
(props) => | ||
`User changed to ${props.currentTab} and there are ${props.diffCount} diffs + ${props.undocumentedUrlCount} undocumented urls` | ||
); | ||
|
||
const NewBodyDiffRenderedSchema = Joi.object({ | ||
requestCount: Joi.number().required(), | ||
responseCount: Joi.number().required(), | ||
regions: Joi.array().required().items(Joi.string()), | ||
}); | ||
type NewBodyDiffRenderedProperties = Joi.extractType< | ||
typeof NewBodyDiffRenderedSchema | ||
>; | ||
export const NewBodyDiffRendered = DescribeEvent<NewBodyDiffRenderedProperties>( | ||
Events.NewBodyDiffRendered, | ||
NewBodyDiffRenderedSchema, | ||
(props) => `Diff was rendered in regions ${props.regions.join(', \n')}` | ||
); | ||
|
||
const InferPolymorphismEnabledSchema = Joi.object({ | ||
captureId: Joi.string().required(), | ||
endpointId: Joi.string().required(), | ||
}); | ||
type InferPolymorphismEnabledProperties = Joi.extractType< | ||
typeof InferPolymorphismEnabledSchema | ||
>; | ||
export const UserEnabledInferPolymorphism = DescribeEvent< | ||
InferPolymorphismEnabledProperties | ||
>( | ||
Events.UserEnabledInferPolymorphism, | ||
InferPolymorphismEnabledSchema, | ||
(props) => | ||
`Infer Polymorphism was turned on for ${props.captureId}, endpoint ${props.endpointId}` | ||
); | ||
|
||
const UserBeganAddingNewUrlSchema = Joi.object({ | ||
captureId: Joi.string().required(), | ||
method: Joi.string().required(), | ||
path: Joi.string().required(), | ||
knownPathId: Joi.string().optional(), | ||
}); | ||
type UserBeganAddingNewUrlProperties = Joi.extractType< | ||
typeof UserBeganAddingNewUrlSchema | ||
>; | ||
export const UserBeganAddingNewUrl = DescribeEvent< | ||
UserBeganAddingNewUrlProperties | ||
>( | ||
Events.UserBeganAddingNewUrl, | ||
UserBeganAddingNewUrlSchema, | ||
(props) => | ||
`User Began Adding New Url ${props.method} ${props.path} in ${props.captureId}` | ||
); | ||
|
||
const UserFinishedAddingNewUrlSchema = Joi.object({ | ||
purpose: Joi.string().required(), | ||
captureId: Joi.string().required(), | ||
method: Joi.string().required(), | ||
pathExpression: Joi.string().optional(), | ||
}); | ||
type UserFinishedAddingNewUrlProperties = Joi.extractType< | ||
typeof UserFinishedAddingNewUrlSchema | ||
>; | ||
export const UserFinishedAddingNewUrl = DescribeEvent< | ||
UserFinishedAddingNewUrlProperties | ||
>( | ||
Events.UserFinishedAddingNewUrl, | ||
UserFinishedAddingNewUrlSchema, | ||
(props) => | ||
`User Added New Url ${props.method} ${props.pathExpression} in ${props.captureId} with purpose '${props.pathExpression}'` | ||
); | ||
|
||
const SuggestionDisplayedSchema = Joi.object({ | ||
suggestion: Joi.string().required(), | ||
}); | ||
type SuggestionDisplayedProperties = Joi.extractType< | ||
typeof SuggestionDisplayedSchema | ||
>; | ||
export const SuggestionDisplayed = DescribeEvent<SuggestionDisplayedProperties>( | ||
Events.SuggestionDisplayed, | ||
SuggestionDisplayedSchema, | ||
(props) => | ||
`Summary: '${props.suggestion}' ` | ||
); | ||
|
||
|
||
|
||
const SuggestionAcceptedSchema = Joi.object({ | ||
captureId: Joi.string().required(), | ||
suggestion: Joi.string().required(), | ||
}); | ||
type SuggestionAcceptedProperties = Joi.extractType< | ||
typeof SuggestionAcceptedSchema | ||
>; | ||
export const UserAcceptedSuggestion = DescribeEvent< | ||
SuggestionAcceptedProperties | ||
>( | ||
Events.UserAcceptedSuggestion, | ||
SuggestionAcceptedSchema, | ||
(props) => `Suggestion to '${props.suggestion}' was accepted` | ||
); | ||
|
||
const UserPreviewedSuggestionSchema = Joi.object({ | ||
captureId: Joi.string().required(), | ||
diff: Joi.string().required(), | ||
diffAssertion: Joi.string().required(), | ||
suggestion: Joi.string().required(), | ||
}); | ||
type UserPreviewedSuggestionProperties = Joi.extractType< | ||
typeof UserPreviewedSuggestionSchema | ||
>; | ||
export const UserPreviewedSuggestion = DescribeEvent< | ||
UserPreviewedSuggestionProperties | ||
>( | ||
Events.UserPreviewedSuggestion, | ||
UserPreviewedSuggestionSchema, | ||
(props) => | ||
`Suggestion to '${props.suggestion}' was previewed in response to diff: ${props.diff}` | ||
); | ||
|
||
const UserResetDiffSchema = Joi.object({}); | ||
type UserResetDiffProperties = Joi.extractType<typeof UserResetDiffSchema>; | ||
export const UserResetDiff = DescribeEvent<UserResetDiffProperties>( | ||
Events.UserResetDiff, | ||
UserResetDiffSchema, | ||
(props) => `The Diff Was Reset` | ||
); | ||
|
||
const ShowCommitCardSchema = Joi.object({ | ||
message: Joi.string().required(), | ||
captureId: Joi.string().required(), | ||
suggestions: Joi.number().required(), | ||
}); | ||
type ShowCommitCardProperties = Joi.extractType< | ||
typeof ShowCommitCardSchema | ||
>; | ||
export const ShowCommitCard = DescribeEvent<ShowCommitCardProperties>( | ||
Events.ShowCommitCard, | ||
ShowCommitCardSchema, | ||
(props) => `Commit Card Rendered` | ||
); | ||
|
||
const UserCommittedChangesSchema = Joi.object({ | ||
message: Joi.string().required(), | ||
captureId: Joi.string().required(), | ||
suggestions: Joi.number().required(), | ||
}); | ||
type UserCommittedChangesProperties = Joi.extractType< | ||
typeof UserCommittedChangesSchema | ||
>; | ||
export const UserCommittedChanges = DescribeEvent< | ||
UserCommittedChangesProperties | ||
>( | ||
Events.UserCommittedChanges, | ||
UserCommittedChangesSchema, | ||
(props) => `The Diff Was Reset` | ||
); | ||
|
||
const AddUrlModalNamingSchema = Joi.object({ | ||
method: Joi.string().required(), | ||
path: Joi.string().required(), | ||
}); | ||
type AddUrlModalNamingProperties = Joi.extractType< | ||
typeof AddUrlModalNamingSchema | ||
>; | ||
export const AddUrlModalNaming = DescribeEvent<AddUrlModalNamingProperties>( | ||
Events.AddUrlModalNaming, | ||
AddUrlModalNamingSchema, | ||
(props) => `Currently naming ${props.method} ${props.path}` | ||
); | ||
|
||
const AddUrlModalIdentifyingPathComponentsSchema = Joi.object({ | ||
method: Joi.string().required(), | ||
path: Joi.string().required(), | ||
}); | ||
type AddUrlModalIdentifyingPathComponentsProperties = Joi.extractType< | ||
typeof AddUrlModalIdentifyingPathComponentsSchema | ||
>; | ||
export const AddUrlModalIdentifyingPathComponents = DescribeEvent<AddUrlModalIdentifyingPathComponentsProperties>( | ||
Events.AddUrlModalIdentifyingPathComponents, | ||
AddUrlModalIdentifyingPathComponentsSchema, | ||
(props) => `Currently identifying path components for ${props.method} ${props.path}` | ||
); | ||
|
||
const ShowInitialDocumentingViewSchema = Joi.object({ | ||
}); | ||
type ShowInitialDocumentingViewProperties = Joi.extractType< | ||
typeof ShowInitialDocumentingViewSchema | ||
>; | ||
export const ShowInitialDocumentingView = DescribeEvent<ShowInitialDocumentingViewProperties>( | ||
Events.ShowInitialDocumentingView, | ||
ShowInitialDocumentingViewSchema, | ||
() => `Showing initial documenting view` | ||
); | ||
|
||
const UpdateContributionSchema = Joi.object({ | ||
id: Joi.string().required(), | ||
purpose: Joi.string().required(), | ||
value: Joi.string().required(), | ||
}); | ||
type UpdateContributionProperties = Joi.extractType< | ||
typeof UpdateContributionSchema | ||
>; | ||
export const UpdateContribution = DescribeEvent<UpdateContributionProperties>( | ||
Events.UpdateContribution, | ||
UpdateContributionSchema, | ||
({id, purpose, value}) => `Updated ${id} - ${purpose} to be ${value}` | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { DescribeEvent, RegisteredEvent } from '../interfaces/RegisterEvent'; | ||
import { Events } from '../interfaces/Events'; | ||
// @ts-ignore | ||
import * as Joi from '@hapi/joi'; | ||
import 'joi-extract-type'; | ||
|
||
const RequirementForDiffsToHaveASuggestionFailedSchema = Joi.object({ | ||
diff: Joi.string().required(), | ||
}); | ||
type RequirementForDiffsToHaveASuggestionFailedProperties = Joi.extractType< | ||
typeof RequirementForDiffsToHaveASuggestionFailedSchema | ||
>; | ||
export const RequirementForDiffsToHaveASuggestionFailed = DescribeEvent< | ||
RequirementForDiffsToHaveASuggestionFailedProperties | ||
>( | ||
Events.RequirementForDiffsToHaveASuggestionFailed, | ||
RequirementForDiffsToHaveASuggestionFailedSchema, | ||
(props) => `Suggestions should never be empty for diff: ${props.diff}` | ||
); | ||
|
||
const JavascriptErrorDetectedInFrontendSchema = Joi.object({ | ||
message: Joi.string().required(), | ||
stack: Joi.string().required(), | ||
}); | ||
type JavascriptErrorDetectedInFrontendProperties = Joi.extractType< | ||
typeof JavascriptErrorDetectedInFrontendSchema | ||
>; | ||
export const JavascriptErrorDetectedInFrontend = DescribeEvent< | ||
JavascriptErrorDetectedInFrontendProperties | ||
>( | ||
Events.JavascriptErrorDetectedInFrontend, | ||
JavascriptErrorDetectedInFrontendSchema, | ||
(props) => `Error on Frontend: ${props.message}` | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to document here that it must start with anonymous_, or capture that in some test