@microlink/mql 0.10.6 → 0.10.7

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.
Files changed (2) hide show
  1. package/package.json +20 -20
  2. package/src/factory.js +18 -4
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@microlink/mql",
3
3
  "description": "Microlink Query Language. The official HTTP client to interact with Microlink API for Node.js, browsers & Deno.",
4
4
  "homepage": "https://nicedoc.io/microlinkhq/mql",
5
- "version": "0.10.6",
5
+ "version": "0.10.7",
6
6
  "browser": "src/browser.js",
7
7
  "main": "src/node.js",
8
8
  "author": {
@@ -91,23 +91,6 @@
91
91
  "lightweight.js",
92
92
  "src"
93
93
  ],
94
- "scripts": {
95
- "build": "rollup -c rollup.config.js",
96
- "build:ky": "[ -f src/ky.js ] || rollup node_modules/ky/index.js --format=umd --name=ky --file=src/ky.js",
97
- "clean": "rm -rf node_modules",
98
- "dev": "npm run build -- -w",
99
- "lint": "standard",
100
- "postrelease": "npm run release:build && npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
101
- "prerelease": "git-dirty && npm run update:check && npm test",
102
- "pretest": "npm run lint && npm run build:ky",
103
- "release": "git-authors-cli && git add package.json && standard-version -a",
104
- "release:build": "npm run build && git add dist/ && git commit -m \"build(no-release): generate bundle\"",
105
- "release:github": "conventional-github-releaser -p angular",
106
- "release:tags": "git push --follow-tags origin master",
107
- "test": "nyc ava --verbose",
108
- "update": "ncu -u",
109
- "update:check": "ncu -- --error-level 2"
110
- },
111
94
  "license": "MIT",
112
95
  "ava": {
113
96
  "files": [
@@ -148,5 +131,22 @@
148
131
  },
149
132
  "types": "index.d.ts",
150
133
  "umd:main": "dist/mql.js",
151
- "unpkg": "dist/mql.js"
152
- }
134
+ "unpkg": "dist/mql.js",
135
+ "scripts": {
136
+ "build": "rollup -c rollup.config.js",
137
+ "build:ky": "[ -f src/ky.js ] || rollup node_modules/ky/index.js --format=umd --name=ky --file=src/ky.js",
138
+ "clean": "rm -rf node_modules",
139
+ "dev": "npm run build -- -w",
140
+ "lint": "standard",
141
+ "postrelease": "npm run release:build && npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
142
+ "prerelease": "git-dirty && npm run update:check && npm test",
143
+ "pretest": "npm run lint && npm run build:ky",
144
+ "release": "git-authors-cli && git add package.json && standard-version -a",
145
+ "release:build": "npm run build && git add dist/ && git commit -m \"build(no-release): generate bundle\"",
146
+ "release:github": "conventional-github-releaser -p angular",
147
+ "release:tags": "git push --follow-tags origin master",
148
+ "test": "nyc ava --verbose",
149
+ "update": "ncu -u",
150
+ "update:check": "ncu -- --error-level 2"
151
+ }
152
+ }
package/src/factory.js CHANGED
@@ -22,7 +22,14 @@ const parseBody = (input, error, url) => {
22
22
  }
23
23
  }
24
24
 
25
- const factory = ({ VERSION, MicrolinkError, isUrlHttp, stringify, got, flatten }) => {
25
+ const factory = ({
26
+ VERSION,
27
+ MicrolinkError,
28
+ isUrlHttp,
29
+ stringify,
30
+ got,
31
+ flatten
32
+ }) => {
26
33
  const assertUrl = (url = '') => {
27
34
  if (!isUrlHttp(url)) {
28
35
  const message = `The \`url\` as \`${url}\` is not valid. Ensure it has protocol (http or https) and hostname.`
@@ -55,11 +62,16 @@ const factory = ({ VERSION, MicrolinkError, isUrlHttp, stringify, got, flatten }
55
62
  } catch (err) {
56
63
  const { response = {} } = err
57
64
  const { statusCode, body: rawBody, headers, url: uri = apiUrl } = response
65
+ const isBuffer = Buffer.isBuffer(rawBody)
58
66
 
59
67
  const body =
60
- isObject(rawBody) && !Buffer.isBuffer(rawBody) ? rawBody : parseBody(rawBody, err, uri)
68
+ isObject(rawBody) && !isBuffer
69
+ ? rawBody
70
+ : parseBody(isBuffer ? rawBody.toString() : rawBody, err, uri)
61
71
 
62
- if (body.code === 'EFATALCLIENT' && retryCount++ < 2) return fetchFromApi(apiUrl, opts, retryCount)
72
+ if (body.code === 'EFATALCLIENT' && retryCount++ < 2) {
73
+ return fetchFromApi(apiUrl, opts, retryCount)
74
+ }
63
75
 
64
76
  throw MicrolinkError({
65
77
  ...body,
@@ -85,7 +97,9 @@ const factory = ({ VERSION, MicrolinkError, isUrlHttp, stringify, got, flatten }
85
97
  ...flatten(opts)
86
98
  })}`
87
99
 
88
- const headers = isPro ? { ...gotHeaders, 'x-api-key': apiKey } : { ...gotHeaders }
100
+ const headers = isPro
101
+ ? { ...gotHeaders, 'x-api-key': apiKey }
102
+ : { ...gotHeaders }
89
103
  return [apiUrl, { ...gotOpts, responseType, cache, retry, headers }]
90
104
  }
91
105