@kaspernj/api-maker 1.0.174 → 1.0.177

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/.eslintrc.js CHANGED
@@ -113,6 +113,7 @@ module.exports = {
113
113
  "no-caller": "error",
114
114
  "no-confusing-arrow": "error",
115
115
  "no-constant-binary-expression": "error",
116
+ "no-constant-condition": "off",
116
117
  "no-constructor-return": "error",
117
118
  "no-continue": "error",
118
119
  "no-div-regex": "error",
@@ -251,6 +252,7 @@ module.exports = {
251
252
  "react/jsx-sort-props": "error",
252
253
  "react/jsx-tag-spacing": "error",
253
254
  "react/jsx-wrap-multilines": "error",
255
+ "react/jsx-max-props-per-line": "off",
254
256
  "react/no-access-state-in-setstate": "error",
255
257
  "react/no-adjacent-inline-elements": "error",
256
258
  "react/no-array-index-key": "error",
@@ -292,7 +294,7 @@ module.exports = {
292
294
  "sort-imports": "error",
293
295
  "sort-vars": "error",
294
296
  "space-before-blocks": "error",
295
- "space-before-function-paren": "error",
297
+ "space-before-function-paren": ["error", "never"],
296
298
  "space-in-parens": "error",
297
299
  "space-infix-ops": "error",
298
300
  "space-unary-ops": "error",
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.174",
19
+ "version": "1.0.177",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -6,7 +6,11 @@ class BaseError extends Error {
6
6
  let messageToUse = message
7
7
 
8
8
  if (typeof args.response == "object" && dig(args, "response", "errors")) {
9
- messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
9
+ if (message) {
10
+ messageToUse = `${messageToUse}: ${errorMessages(args).join(". ")}`
11
+ } else {
12
+ messageToUse = errorMessages(args).join(". ")
13
+ }
10
14
  }
11
15
 
12
16
  super(messageToUse)
@@ -47,7 +47,7 @@ module.exports = class ApiMakerCommandsPool {
47
47
  this.pool = {}
48
48
  this.poolData = {}
49
49
  this.currentId = 1
50
- this.globalRequestData = null
50
+ this.globalRequestData = {}
51
51
  }
52
52
 
53
53
  addCommand (data) {
@@ -107,7 +107,7 @@ module.exports = class ApiMakerCommandsPool {
107
107
  try {
108
108
  const submitData = {pool: currentPoolData}
109
109
 
110
- if (this.globalRequestData)
110
+ if (Object.keys(this.globalRequestData).length > 0)
111
111
  submitData.global = this.globalRequestData
112
112
 
113
113
  const commandSubmitData = new CommandSubmitData(submitData)
@@ -162,7 +162,11 @@ module.exports = class ApiMakerCommandsPool {
162
162
  })
163
163
  error = new ValidationError(validationErrors, {response: commandResponseData})
164
164
  } else {
165
- error = new CustomError(`Command failed`, {response: commandResponseData})
165
+ let errorMessage
166
+
167
+ if (!commandResponseData.errors) { errorMessage = "Command failed" }
168
+
169
+ error = new CustomError(errorMessage, {response: commandResponseData})
166
170
  }
167
171
 
168
172
  commandData.reject(error)
package/src/config.js CHANGED
@@ -12,7 +12,11 @@ class ApiMakerConfig {
12
12
  }
13
13
 
14
14
  getHost() {
15
- return this.global.host
15
+ const host = this.global.host
16
+
17
+ if (typeof host == "function") return host()
18
+
19
+ return host
16
20
  }
17
21
 
18
22
  getRouteDefinitions() {
@@ -8,8 +8,8 @@ import shouldComponentUpdate from "set-state-compare/src/should-component-update
8
8
  export default (WrapperComponent) => class WithRouter extends React.Component {
9
9
  static propTypes = {
10
10
  path: PropTypes.string,
11
- routes: PropTypes.object,
12
- routeDefinitions: PropTypes.object
11
+ routeDefinitions: PropTypes.object,
12
+ routes: PropTypes.object
13
13
  }
14
14
 
15
15
  parsedRouteDefinitions = this.parseRouteDefinitions()
@@ -18,7 +18,7 @@ export default (WrapperComponent) => class WithRouter extends React.Component {
18
18
  return shouldComponentUpdate(this, nextProps, nextState)
19
19
  }
20
20
 
21
- findRouteParams (routeDefinition) {
21
+ findRouteParams(routeDefinition) {
22
22
  const result = []
23
23
  const parts = routeDefinition.path.split("/")
24
24
 
@@ -33,13 +33,18 @@ export default (WrapperComponent) => class WithRouter extends React.Component {
33
33
  path() {
34
34
  let path = this.props.path || window.location.pathname
35
35
 
36
- path = path.replace(/[\/]+$/, "")
36
+ path = path.replace(/[/]+$/, "")
37
37
 
38
38
  return path
39
39
  }
40
40
 
41
- routeDefinitions() { return this.props.routeDefinitions || config.getRouteDefinitions() }
42
- routes() { return this.props.routes || config.getRoutes() }
41
+ routeDefinitions() {
42
+ return this.props.routeDefinitions || config.getRouteDefinitions()
43
+ }
44
+
45
+ routes() {
46
+ return this.props.routes || config.getRoutes()
47
+ }
43
48
 
44
49
  parseRouteDefinitions() {
45
50
  const Locales = require("shared/locales").default
@@ -58,10 +63,9 @@ export default (WrapperComponent) => class WithRouter extends React.Component {
58
63
  if (!(routePathName in routes))
59
64
  throw new Error(`${routePathName} not found in routes: ${Object.keys(routes, ", ")}`)
60
65
 
61
- const routePath = routes[routePathName](...params).replace(/[\/]+$/, "")
66
+ const routePath = routes[routePathName](...params).replace(/[/]+$/, "")
62
67
  const groups = []
63
-
64
- let pathRegexString = '^'
68
+ let pathRegexString = "^"
65
69
 
66
70
  pathRegexString += escapeStringRegexp(routePath)
67
71
 
@@ -74,10 +78,10 @@ export default (WrapperComponent) => class WithRouter extends React.Component {
74
78
 
75
79
  groups.push(variableName)
76
80
 
77
- pathRegexString = pathRegexString.replace(match[0], `([^\/]+)`)
81
+ pathRegexString = pathRegexString.replace(match[0], "([^/]+)")
78
82
  }
79
83
 
80
- pathRegexString += '$'
84
+ pathRegexString += "$"
81
85
 
82
86
  const pathRegex = new RegExp(pathRegexString)
83
87