feat: Typescript for API layer (#817)

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com>
Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Sebastian Rindom <seb@medusa-commerce.com>
This commit is contained in:
413 files changed
+20957 -10349

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"plugins": ["@babel/plugin-proposal-class-properties"],
"presets": ["@babel/preset-env"],
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
"env": {
"test": {
"plugins": ["@babel/plugin-transform-runtime"]
+7 -3
View File
@@ -10,7 +10,7 @@
},
"scripts": {
"test": "jest",
"build": "babel src --out-dir dist/ --ignore **/__tests__",
"build": "tsc --build",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir dist/ --ignore **/__tests__"
},
@@ -23,15 +23,19 @@
"@babel/plugin-transform-classes": "^7.9.5",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.13.9",
"@babel/preset-typescript": "^7.16.0",
"@babel/runtime": "^7.13.9",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"cross-env": "^5.2.1",
"eslint": "^6.8.0",
"jest": "^25.5.2",
"prettier": "^1.19.1"
"prettier": "^1.19.1",
"typescript": "^4.4.4"
},
"dependencies": {
"joi": "^17.3.0",
"joi-objectid": "^3.0.1"
},
"gitHead": "41a5425405aea5045a26def95c0dc00cf4a5a44d"
}
}
@@ -22,12 +22,21 @@ export const MedusaErrorCodes = {
* @extends Error
*/
class MedusaError extends Error {
public type: string
public message: string
public code?: string
public date: Date
public static Types = MedusaErrorTypes
public static Codes = MedusaErrorCodes
/**
* Creates a standardized error to be used across Medusa project.
* @param type {MedusaErrorType} - the type of error.
* @param params {Array} - Error params.
* @param {string} type - type of error
* @param {string} message - message to go along with error
* @param {string} code - code of error
* @param {Array} params - params
*/
constructor(type, message, code, ...params) {
constructor(type: string, message: string, code?: string, ...params: any) {
super(...params)
if (Error.captureStackTrace) {
@@ -35,14 +44,10 @@ class MedusaError extends Error {
}
this.type = type
this.name = type
this.code = code
this.message = message
this.date = new Date()
}
}
MedusaError.Types = MedusaErrorTypes
MedusaError.Codes = MedusaErrorCodes
export default MedusaError
+8 -8
View File
@@ -1,11 +1,11 @@
export { countries } from "./countries"
export { isoCountryLookup } from "./countries"
export { transformIdableFields } from "./transform-idable-fields"
export { indexTypes } from "./index-types"
export { default as Validator } from "./validator"
export { default as compareObjectsByProp } from "./compare-objects"
export { countries, isoCountryLookup } from "./countries"
export { default as createRequireFromPath } from "./create-require-from-path"
export { default as MedusaError } from "./errors"
export { default as getConfigFile } from "./get-config-file"
export { default as createRequireFromPath } from "./create-require-from-path"
export { default as compareObjectsByProp } from "./compare-objects"
export { default as zeroDecimalCurrencies } from "./zero-decimal-currencies"
export { default as humanizeAmount } from "./humanize-amount"
export { indexTypes } from "./index-types"
export { transformIdableFields } from "./transform-idable-fields"
export { default as Validator } from "./validator"
export { default as zeroDecimalCurrencies } from "./zero-decimal-currencies"
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"lib": ["es5", "es6"],
"target": "es5",
"outDir": "./dist",
"esModuleInterop": true,
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"allowJs": true,
"skipLibCheck": true
},
"include": ["./src/**/*"],
"exclude": ["./dist/**/*", "./src/__tests__", "node_modules"]
}
File diff suppressed because it is too large. Load diff