Skip to content

Commit

Permalink
feat: cleanup old code and start sentry plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Oct 5, 2022
1 parent e6c9af9 commit dd4a518
Show file tree
Hide file tree
Showing 34 changed files with 11,976 additions and 28,552 deletions.
6 changes: 3 additions & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"npmClient": "npm",
"packages": [
"packages/medusa/*",
"packages/medusa-extender/*"
"packages/*"
],
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
"publish": {
"conventionalCommits": true,
Expand Down
7,431 changes: 0 additions & 7,431 deletions package-lock.json

This file was deleted.

28 changes: 19 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
{
"name": "medusa-plugins",
"name": "@medusa-plugins/medusa-plugins",
"private": true,
"version": "0.0.0",
"description": "A collection of awesome plugins for medusa and medusa-extender :rocket:",
"engines": {
"node": "14.17.3"
"node": ">14.17.3"
},
"workspaces": {
"packages": [
"packages/*"
]
},
"scripts": {
"clean": "./node_modules/.bin/lerna run clean",
"build": "./node_modules/.bin/lerna run build",
"build": "run-p clean run-s build:api /node_modules/.bin/lerna/tsc -b ./packages/tsconfig.api-base.json",
"bootstrap": "./node_modules/.bin/lerna/lerna bootstrap",
"clean": "./node_modules/.bin/lerna/lerna run --parallel clean",
"release": "./node_modules/.bin/lerna/lerna publish",
"watch": "./node_modules/.bin/lerna run watch",
"test": "./node_modules/.bin/lerna run test",
"test:local": "./node_modules/.bin/lerna run test:local",
"bootstrap": "./node_modules/.bin/lerna bootstrap --no-hoist",
"lint": "./node_modules/.bin/eslint 'packages/**/*.ts' --fix",
"format": "./node_modules/.bin/prettier 'packages/**/*.ts' --write",
"release": "npx lerna verion"
"format": "./node_modules/.bin/prettier 'packages/**/*.ts' --write"
},
"repository": {
"type": "git",
Expand All @@ -26,6 +32,9 @@
"url": "https://github.com/adrien2p/medusa-plugins/issues"
},
"homepage": "https://github.com/adrien2p/medusa-plugins#readme",
"dependencies": {
"rimraf": "^3.0.1"
},
"devDependencies": {
"lerna": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
Expand All @@ -34,8 +43,9 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.0",
"rimraf": "^3.0.2",
"tslint": "~6.1.0"
"tslint": "~6.1.0",
"typescript": "^3.7.5"
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
.idea
/lib
/dist
api/
node_modules
.DS_store
**/.DS_Store

dist
coverage

/api/
/services/
/subscribers/
utils.js
types.js
index.js

/tsconfig.tsbuildinfo
/package-lock.json
/yarn.json
Expand Down
25 changes: 25 additions & 0 deletions packages/medusa-plugin-sentry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@medusa-plugins/medusa-plugin-sentry",
"version": "1.0.0",
"main": "index.js",
"author": "Adrien de Peretti",
"license": "MIT",
"scripts": {
"build": "run-s clean build:tsc",
"build:tsc": "tsc -b",
"clean": "rimraf lib coverage tsconfig.tsbuildinfo"
},
"peerDependencies": {
"@medusajs/medusa": "^1.4.1"
},
"devDependencies": {
"ts-node": "^8.6.2",
"@medusajs/medusa": "^1.4.1"
},
"dependencies": {
"@sentry/node": "^7.14.1",
"@sentry/tracing": "^7.14.1",
"@types/express": "types/express",
"express": "^4.18.1"
}
}
64 changes: 64 additions & 0 deletions packages/medusa-plugin-sentry/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Router } from 'express';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import { NodeOptions } from '@sentry/node/types/types';
import { Integration } from '@sentry/types/types/integration';
import { RequestHandlerOptions } from '@sentry/node/types/handlers';

export type SentryOptions = Omit<NodeOptions, 'integrations'> & {
integrations: Integration[] | ((router: Router, sentry: typeof Sentry, tracing: typeof Tracing) => Integration[]);
shouldHandleError: (code: number) => boolean;
requestHandlerOptions?: RequestHandlerOptions;
enableRequestHandler?: boolean;
enableTracing?: boolean;
};

export default function (rootDirectory, pluginOptions: SentryOptions) {
const router = Router();

const {
integrations,
shouldHandleError = (code) => code >= 400,
requestHandlerOptions = {},
enableTracing = true,
enableRequestHandler = true,
...options
} = pluginOptions;

Sentry.init({
...options,
integrations: Array.isArray(integrations) ? integrations : integrations(router, Sentry, Tracing),
});

if (enableRequestHandler) {
// RequestHandler creates a separate execution context using domains, so that every
// transaction/span/breadcrumb is attached to its own Hub instance
router.use(Sentry.Handlers.requestHandler(requestHandlerOptions));
}

if (enableTracing) {
// TracingHandler creates a trace for every incoming request
router.use(Sentry.Handlers.tracingHandler());
}

const medusaErrorHandler = require('@medusajs/medusa/dist/api/middlewares/error-handler');
const originalMedusaErrorHandler = medusaErrorHandler.default;
medusaErrorHandler.default = () => {
return (err, req, res, next) => {
let statusCode;
const res_ = {
...res,
status: (status) => {
statusCode = status;
return res;
},
};
originalMedusaErrorHandler()(err, req, res_, next);
Sentry.Handlers.errorHandler({
shouldHandleError: () => shouldHandleError(statusCode),
})(err, req, res, () => void 0);
};
};

return router;
}
12 changes: 12 additions & 0 deletions packages/medusa-plugin-sentry/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": ".",
"rootDir": "src",
"baseUrl": "./",
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/__tests__/*", "**/__e2e__/*"],
}
8 changes: 0 additions & 8 deletions packages/medusa/payment-paytr/.npmignore

This file was deleted.

21 changes: 0 additions & 21 deletions packages/medusa/payment-paytr/LICENSE

This file was deleted.

119 changes: 0 additions & 119 deletions packages/medusa/payment-paytr/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions packages/medusa/payment-paytr/jest.config.js

This file was deleted.

Loading

0 comments on commit dd4a518

Please sign in to comment.