@kaspernj/api-maker 1.0.194 → 1.0.197

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.194",
19
+ "version": "1.0.197",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -5,11 +5,15 @@ class BaseError extends Error {
5
5
  constructor (message, args = {}) {
6
6
  let messageToUse = message
7
7
 
8
- if (typeof args.response == "object" && dig(args, "response", "errors")) {
9
- if (message) {
10
- messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
11
- } else {
12
- messageToUse = errorMessages(args).join(". ")
8
+ if ("addResponseErrorsToErrorMessage" in args && !args.addResponseErrorsToErrorMessage) {
9
+ messageToUse = message
10
+ } else {
11
+ if (typeof args.response == "object" && dig(args, "response", "errors")) {
12
+ if (message) {
13
+ messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
14
+ } else {
15
+ messageToUse = errorMessages(args).join(". ")
16
+ }
13
17
  }
14
18
  }
15
19
 
@@ -17,8 +21,7 @@ class BaseError extends Error {
17
21
  this.args = args
18
22
 
19
23
  // Maintains proper stack trace for where our error was thrown (only available on V8)
20
- if (Error.captureStackTrace)
21
- Error.captureStackTrace(this, BaseError)
24
+ if (Error.captureStackTrace) Error.captureStackTrace(this, BaseError)
22
25
  }
23
26
 
24
27
  errorMessages () {
@@ -311,7 +311,7 @@ class BaseModel {
311
311
  }
312
312
 
313
313
  static parseValidationErrors ({error, model, options}) {
314
- if (!(error instanceof CustomError)) return
314
+ if (!(error instanceof ValidationError)) return
315
315
  if (!error.args.response.validation_errors) return
316
316
 
317
317
  const validationErrors = new ValidationErrors({
package/src/config.js CHANGED
@@ -1,50 +1,48 @@
1
+ import inflection from "inflection"
2
+
3
+ const accessors = {
4
+ breakPoints: {
5
+ default: [
6
+ ["xxl", 1400],
7
+ ["xl", 1200],
8
+ ["lg", 992],
9
+ ["md", 768],
10
+ ["sm", 576],
11
+ ["xs", 0]
12
+ ],
13
+ required: true
14
+ },
15
+ currenciesCollection: {required: true},
16
+ history: {required: false},
17
+ host: {required: false},
18
+ routes: {required: false},
19
+ routeDefinitions: {required: false}
20
+ }
21
+
1
22
  class ApiMakerConfig {
2
23
  constructor() {
3
24
  if (!global.apiMakerConfigGlobal) global.apiMakerConfigGlobal = {}
4
25
 
5
26
  this.global = global.apiMakerConfigGlobal
6
27
  }
28
+ }
7
29
 
8
- getCurrenciesCollection() {
9
- if (!this.global.currenciesCollection) throw new Error("Currencies collection hasn't been set")
10
-
11
- return this.global.currenciesCollection
12
- }
13
-
14
- getHost() {
15
- const host = this.global.host
16
-
17
- if (typeof host == "function") return host()
18
-
19
- return host
20
- }
21
-
22
- getRouteDefinitions() {
23
- return this.global.routeDefinitions
24
- }
30
+ for (const accessorName in accessors) {
31
+ const accessorData = accessors[accessorName]
32
+ const camelizedAccessor = inflection.camelize(accessorName)
25
33
 
26
- getRoutes() {
27
- return this.global.routes
28
- }
34
+ ApiMakerConfig.prototype[`set${camelizedAccessor}`] = function (newValue) { this.global[accessorName] = newValue }
35
+ ApiMakerConfig.prototype[`get${camelizedAccessor}`] = function (...args) {
36
+ if (!this.global[accessorName]) {
37
+ if (accessorData.default) return accessorData.default
38
+ if (accessorData.required) throw new Error(`${accessorName} hasn't been set`)
39
+ }
29
40
 
30
- setCurrenciesCollection(newCurrenciesCollection) {
31
- this.global.currenciesCollection = newCurrenciesCollection
32
- }
41
+ const value = this.global[accessorName]
33
42
 
34
- setHistory(history) {
35
- this.global.history = history
36
- }
37
-
38
- setHost(host) {
39
- this.global.host = host
40
- }
41
-
42
- setRouteDefinitions(routeDefinitions) {
43
- this.global.routeDefinitions = routeDefinitions
44
- }
43
+ if (typeof value == "function") return value(...args)
45
44
 
46
- setRoutes(routes) {
47
- this.global.routes = routes
45
+ return value
48
46
  }
49
47
  }
50
48
 
package/src/link.jsx CHANGED
@@ -17,7 +17,7 @@ export default class Link extends React.PureComponent {
17
17
  if (!e.defaultPrevented && !e.ctrlKey && !e.metaKey) {
18
18
  e.preventDefault()
19
19
 
20
- const history = global.apiMakerConfigGlobal?.history
20
+ const history = globalThis.apiMakerConfigGlobal?.history
21
21
 
22
22
  if (!history) throw new Error("History hasn't been set in the API maker configuration")
23
23
 
@@ -99,7 +99,7 @@ module.exports = class SourceMapsLoader {
99
99
  }
100
100
 
101
101
  includeMapURL(src) {
102
- return src.includes("/packs/") || src.includes("/assets/")
102
+ return src.includes("/packs/")
103
103
  }
104
104
 
105
105
  async loadSourceMapForSource ({originalUrl, sourceMapUrl}) {
@@ -1,9 +1,13 @@
1
- const CustomError = require("./custom-error.cjs")
1
+ const BaseError = require("./base-error.cjs")
2
2
  const inflection = require("inflection")
3
3
 
4
- class ValidationError extends CustomError {
4
+ class ValidationError extends BaseError {
5
5
  constructor (validationErrors, args) {
6
- super(validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage(), args)
6
+ const errorMessage = validationErrors.getUnhandledErrorMessage() || validationErrors.getErrorMessage()
7
+ const forwardedArgs = {addResponseErrorsToErrorMessage: false}
8
+ const newArgs = Object.assign({}, args, forwardedArgs)
9
+
10
+ super(errorMessage, newArgs)
7
11
  this.validationErrors = validationErrors
8
12
  }
9
13
 
@@ -96,8 +96,7 @@ class ValidationErrors {
96
96
  return this.validationErrors
97
97
  }
98
98
 
99
- getValidationErrorsForInput (args) {
100
- const {attribute, inputName, onMatchValidationError} = args
99
+ getValidationErrorsForInput ({attribute, inputName, onMatchValidationError}) {
101
100
  const validationErrors = this.validationErrors.filter((validationError) => {
102
101
  if (onMatchValidationError) {
103
102
  return onMatchValidationError(validationError)