Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ CLOUDPAYMENTS_SECRET=
# INN of legal entity for CloudKassir
LEGAL_ENTITY_INN=

# Token for Amplitude analytics
AMPLITUDE_TOKEN=

# AWS S3 Bucket Configuration
AWS_S3_ACCESS_KEY_ID=
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.4.3",
"version": "1.4.5",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down Expand Up @@ -38,7 +38,6 @@
},
"dependencies": {
"@ai-sdk/openai": "^2.0.64",
"@amplitude/node": "^1.10.0",
"@graphql-tools/merge": "^8.3.1",
"@graphql-tools/schema": "^8.5.1",
"@graphql-tools/utils": "^8.9.0",
Expand Down
8 changes: 4 additions & 4 deletions src/integrations/github/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ export function createGitHubRouter(factories: ContextFactories): express.Router
* just log query parameters and respond with 200 without signature validation.
*/
if (req.method !== 'POST') {
// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
const { code, installation_id, setup_action, state, ...restQuery } = req.query as Record<string, unknown>;

// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
if (code || installation_id || state || setup_action) {
// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
log('info', `${WEBHOOK_LOG_PREFIX}Received non-POST request on /webhook with OAuth-like params`, {
// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
code,
installation_id,
setup_action,
installation_id, // eslint-disable-line @typescript-eslint/camelcase, camelcase
setup_action, // eslint-disable-line @typescript-eslint/camelcase, camelcase
state,
query: restQuery,
});
Expand Down
10 changes: 1 addition & 9 deletions src/models/usersFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UserModel from './user';
import { Collection, Db, OptionalId } from 'mongodb';
import DataLoaders from '../dataLoaders';
import { UserDBScheme } from '@hawk.so/types';
import { Analytics, AnalyticsEventTypes } from '../utils/analytics';


/**
* Users factory to work with User Model
Expand Down Expand Up @@ -91,14 +91,6 @@ export default class UsersFactory extends AbstractModelFactory<Omit<UserDBScheme

user.generatedPassword = generatedPassword;

await Analytics.logEvent({
/* eslint-disable-next-line camelcase */
event_type: AnalyticsEventTypes.NEW_USER_REGISTERED,
/* eslint-disable-next-line camelcase */
user_id: userId.toString(),
time: Date.now(),
});

return user;
}

Expand Down
9 changes: 0 additions & 9 deletions src/models/workspacesFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import UserModel from './user';
import PlansFactory from './plansFactory';
import PlanModel from './plan';
import { WorkspaceDBScheme } from '@hawk.so/types';
import { Analytics, AnalyticsEventTypes } from '../utils/analytics';

/**
* Workspaces factory to work with WorkspaceModel
Expand Down Expand Up @@ -70,14 +69,6 @@ export default class WorkspacesFactory extends AbstractModelFactory<WorkspaceDBS
await ownerModel.addWorkspace(workspaceModel._id.toString());
await workspaceModel.changePlan((await this.getDefaultPlan())._id.toString());

await Analytics.logEvent({
/* eslint-disable-next-line camelcase */
event_type: AnalyticsEventTypes.WORKSPACE_CREATED,
/* eslint-disable-next-line camelcase */
user_id: ownerModel._id.toString(),
time: Date.now(),
});

return workspaceModel;
}

Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ module.exports = {
*/
const taskManager = project.taskManager;

if (taskManager && taskManager.type === 'github' && taskManager.config?.installationId) {
if (taskManager && taskManager.type === 'github' && taskManager.config && taskManager.config.installationId) {
const githubService = new GitHubService();

await githubService.deleteInstallation(taskManager.config.installationId);
Expand Down
35 changes: 8 additions & 27 deletions src/typeDefs/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,6 @@ type EventUser {
photo: String
}

"""
Breadcrumb severity level
"""
enum BreadcrumbLevel {
fatal
error
warning
info
debug
}

"""
Breadcrumb type - controls categorization and UI appearance
"""
enum BreadcrumbType {
default
request
ui
navigation
logic
error
}

"""
Single breadcrumb entry - represents an event that occurred before the error
"""
Expand All @@ -149,9 +126,11 @@ type Breadcrumb {
timestamp: Float!

"""
Type of breadcrumb - controls UI categorization
Type of breadcrumb - controls UI categorization.
Common values: default, request, ui, navigation, logic, error.
Accepts any string since SDK users may send custom types.
"""
type: BreadcrumbType
type: String

"""
Category of the event - more specific than type
Expand All @@ -164,9 +143,11 @@ type Breadcrumb {
message: String

"""
Severity level of the breadcrumb
Severity level of the breadcrumb.
Common values: fatal, error, warning, info, debug.
Accepts any string since SDK users may send custom levels.
"""
level: BreadcrumbLevel
level: String

"""
Arbitrary key-value data associated with the breadcrumb
Expand Down
27 changes: 0 additions & 27 deletions src/utils/analytics/amplitude.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/utils/analytics/events.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/utils/analytics/index.ts

This file was deleted.

5 changes: 5 additions & 0 deletions test/__mocks__/github-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const deleteInstallationMock = jest.fn().mockResolvedValue(undefined);

export const GitHubService = jest.fn().mockImplementation(() => ({
deleteInstallation: deleteInstallationMock,
}));
6 changes: 3 additions & 3 deletions test/integrations/github-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ describe('GitHub Routes - /integration/github/connect', () => {

expect(response.status).toBe(302);
expect(response.body).toContain('http://localhost:8080/');
expect(response.body).toContain('error=Missing+or+invalid+OAuth+code');
expect(response.body).toContain('apiError=Missing+or+invalid+OAuth+code');
});

it('should redirect with error when state is missing', async () => {
Expand All @@ -501,7 +501,7 @@ describe('GitHub Routes - /integration/github/connect', () => {

expect(response.status).toBe(302);
expect(response.body).toContain('http://localhost:8080/');
expect(response.body).toContain('error=Missing+or+invalid+state');
expect(response.body).toContain('apiError=Missing+or+invalid+state');
});

it('should redirect with error when state is invalid or expired', async () => {
Expand All @@ -525,7 +525,7 @@ describe('GitHub Routes - /integration/github/connect', () => {

expect(response.status).toBe(302);
expect(response.body).toContain('http://localhost:8080/');
expect(response.body).toContain('error=Invalid+or+expired+state');
expect(response.body).toContain('apiError=Invalid+or+expired+state');
expect(mockGetState).toHaveBeenCalledWith(state);
});

Expand Down
9 changes: 9 additions & 0 deletions test/resolvers/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { ObjectId } from 'mongodb';
import { ProjectDBScheme, ProjectTaskManagerConfig } from '@hawk.so/types';
import { ResolverContextWithUser } from '../../src/types/graphql';
import { ApolloError, UserInputError } from 'apollo-server-express';

jest.mock('../../src/integrations/github/service', () => require('../__mocks__/github-service'));
// eslint-disable-next-line @typescript-eslint/no-var-requires
import { deleteInstallationMock, GitHubService } from '../__mocks__/github-service';

// @ts-expect-error - CommonJS module, TypeScript can't infer types properly
import projectResolverModule from '../../src/resolvers/project';

Expand Down Expand Up @@ -141,6 +146,8 @@ describe('Project Resolver - Task Manager Mutations', () => {
)) as { taskManager: ProjectTaskManagerConfig | null };

expect(context.factories.projectsFactory.findById).toHaveBeenCalledWith(mockProject._id.toString());
expect(GitHubService).toHaveBeenCalledTimes(1);
expect(deleteInstallationMock).toHaveBeenCalledWith('123456');
expect(mockProject.updateProject).toHaveBeenCalledWith({
taskManager: null,
});
Expand Down Expand Up @@ -217,6 +224,8 @@ describe('Project Resolver - Task Manager Mutations', () => {
context
)) as { taskManager: ProjectTaskManagerConfig | null };

expect(GitHubService).not.toHaveBeenCalled();
expect(deleteInstallationMock).not.toHaveBeenCalled();
expect(mockProject.updateProject).toHaveBeenCalledWith({
taskManager: null,
});
Expand Down
34 changes: 1 addition & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,6 @@
dependencies:
json-schema "^0.4.0"

"@amplitude/identify@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@amplitude/identify/-/identify-1.10.0.tgz#d62b8b6785c29350c368810475a6fc7b04985210"
integrity sha512-BshMDcZX9qO4mgGBR45HmiHxfcPCDY/eBOE/MTUZBW+y9+N61aKmNY3YJsAUfRPzieDiyfqs8rNm7quVkaNzJQ==
dependencies:
"@amplitude/types" "^1.10.0"
"@amplitude/utils" "^1.10.0"
tslib "^1.9.3"

"@amplitude/node@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@amplitude/node/-/node-1.10.0.tgz#33f84ddf82b31471fce53e6fa60b688d4bc62ee4"
integrity sha512-Jh8w1UpxhonWe0kCALVvqiBE3vo5NYmbNZbZrrI9Lfa/1HbGboZlGdg0I7/WtihbZvEjpfcfTOf8OkmtZh6vsQ==
dependencies:
"@amplitude/identify" "^1.10.0"
"@amplitude/types" "^1.10.0"
"@amplitude/utils" "^1.10.0"
tslib "^1.9.3"

"@amplitude/types@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@amplitude/types/-/types-1.10.0.tgz#dfaf7cc25f533a1e2b0ef0ad675371b396733c0f"
integrity sha512-xN0gnhutztv6kqHaZ2bre18anQV5GDmMXOeipTvI670g2VjNbPfOzMwu1LN4p1NadYq+GqYI223UcZrXR+R4Pw==

"@amplitude/utils@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@amplitude/utils/-/utils-1.10.0.tgz#138b0ba4e5755540a9e4abf426b7a25d045418a9"
integrity sha512-/R8j8IzFH0GYfA6ehQDm5IEzt71gIeMdiYYFIzZp6grERQlgJcwNJMAiza0o2JwwTDIruzqdB3c/vLVjuakp+w==
dependencies:
"@amplitude/types" "^1.10.0"
tslib "^1.9.3"

"@apollo/protobufjs@1.2.4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@apollo/protobufjs/-/protobufjs-1.2.4.tgz#d913e7627210ec5efd758ceeb751c776c68ba133"
Expand Down Expand Up @@ -6662,7 +6630,7 @@ tsconfig@^7.0.0:
strip-bom "^3.0.0"
strip-json-comments "^2.0.0"

tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
tslib@^1.8.1, tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
Expand Down