@microlink/mql 0.17.1 → 0.18.1

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/LICENSE.md CHANGED
File without changes
package/dist/index.d.ts CHANGED
@@ -194,6 +194,7 @@ export type MqlErrorProps = {
194
194
  code: string
195
195
  status: MqlStatus
196
196
  message: string
197
+ cause?: Error
197
198
  data?: MqlResponseData
198
199
  headers?: { [key: string]: string }
199
200
  more?: string
package/dist/index.js CHANGED
@@ -1869,7 +1869,7 @@ var distribution = /*#__PURE__*/Object.freeze({
1869
1869
 
1870
1870
  var require$$1 = /*@__PURE__*/getAugmentedNamespace(distribution);
1871
1871
 
1872
- const VERSION = '0.17.1';
1872
+ const VERSION = '0.18.1';
1873
1873
 
1874
1874
  var constants = {
1875
1875
  VERSION,
@@ -1919,11 +1919,17 @@ var constants = {
1919
1919
  typeof input?.constructor?.isBuffer === 'function' &&
1920
1920
  input.constructor.isBuffer(input);
1921
1921
 
1922
+ const rootCause = error => {
1923
+ let cause = error;
1924
+ while (cause?.cause instanceof Error) cause = cause.cause;
1925
+ return cause
1926
+ };
1927
+
1922
1928
  const parseBody = (input, error, url) => {
1923
1929
  try {
1924
1930
  return JSON.parse(input)
1925
1931
  } catch (_) {
1926
- const message = input || error.message;
1932
+ const message = input || rootCause(error).message;
1927
1933
 
1928
1934
  return {
1929
1935
  status: 'error',
@@ -1946,8 +1952,8 @@ var constants = {
1946
1952
  };
1947
1953
 
1948
1954
  class MicrolinkError extends Error {
1949
- constructor (props) {
1950
- super();
1955
+ constructor ({ cause, ...props }) {
1956
+ super(undefined, cause ? { cause } : undefined);
1951
1957
  this.name = 'MicrolinkError';
1952
1958
  Object.assign(this, props);
1953
1959
  this.description = this.message;
@@ -2034,7 +2040,8 @@ var constants = {
2034
2040
  ...body,
2035
2041
  url: uri,
2036
2042
  statusCode,
2037
- headers
2043
+ headers,
2044
+ cause: error
2038
2045
  })
2039
2046
  }
2040
2047
  };
package/dist/index.umd.js CHANGED
@@ -1875,7 +1875,7 @@
1875
1875
 
1876
1876
  var require$$1 = /*@__PURE__*/getAugmentedNamespace(distribution);
1877
1877
 
1878
- const VERSION = '0.17.1';
1878
+ const VERSION = '0.18.1';
1879
1879
 
1880
1880
  var constants = {
1881
1881
  VERSION,
@@ -1925,11 +1925,17 @@
1925
1925
  typeof input?.constructor?.isBuffer === 'function' &&
1926
1926
  input.constructor.isBuffer(input);
1927
1927
 
1928
+ const rootCause = error => {
1929
+ let cause = error;
1930
+ while (cause?.cause instanceof Error) cause = cause.cause;
1931
+ return cause
1932
+ };
1933
+
1928
1934
  const parseBody = (input, error, url) => {
1929
1935
  try {
1930
1936
  return JSON.parse(input)
1931
1937
  } catch (_) {
1932
- const message = input || error.message;
1938
+ const message = input || rootCause(error).message;
1933
1939
 
1934
1940
  return {
1935
1941
  status: 'error',
@@ -1952,8 +1958,8 @@
1952
1958
  };
1953
1959
 
1954
1960
  class MicrolinkError extends Error {
1955
- constructor (props) {
1956
- super();
1961
+ constructor ({ cause, ...props }) {
1962
+ super(undefined, cause ? { cause } : undefined);
1957
1963
  this.name = 'MicrolinkError';
1958
1964
  Object.assign(this, props);
1959
1965
  this.description = this.message;
@@ -2040,7 +2046,8 @@
2040
2046
  ...body,
2041
2047
  url: uri,
2042
2048
  statusCode,
2043
- headers
2049
+ headers,
2050
+ cause: error
2044
2051
  })
2045
2052
  }
2046
2053
  };
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://microlink.io/mql",
5
- "version": "0.17.1",
5
+ "version": "0.18.1",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  "types": "./dist/index.d.ts",
@@ -65,7 +65,7 @@
65
65
  "tsd": "latest"
66
66
  },
67
67
  "engines": {
68
- "node": ">= 22"
68
+ "node": ">= 24"
69
69
  },
70
70
  "files": [
71
71
  "dist",
@@ -73,15 +73,6 @@
73
73
  "src/index.js",
74
74
  "src/main.mjs"
75
75
  ],
76
- "scripts": {
77
- "build": "rollup -c rollup.config.js --bundleConfigAsCjs",
78
- "clean:build": "rm -rf dist/index.js",
79
- "dev": "pnpm run build -- -w",
80
- "prebuild": "pnpm run clean:build",
81
- "prepublishOnly": "pnpm run build",
82
- "pretest": "pnpm run build",
83
- "test": "ava --verbose && tsd"
84
- },
85
76
  "license": "MIT",
86
77
  "ava": {
87
78
  "files": [
@@ -101,5 +92,12 @@
101
92
  },
102
93
  "directory": "test"
103
94
  },
104
- "gitHead": "28020344ffd40e3253e8cfa345e2a0bfe15deda9"
105
- }
95
+ "scripts": {
96
+ "build": "rollup -c rollup.config.js --bundleConfigAsCjs",
97
+ "clean:build": "rm -rf dist/index.js",
98
+ "dev": "pnpm run build -- -w",
99
+ "prebuild": "pnpm run clean:build",
100
+ "pretest": "pnpm run build",
101
+ "test": "ava --verbose && tsd"
102
+ }
103
+ }
package/src/index.js CHANGED
@@ -31,11 +31,17 @@ const isBuffer = input =>
31
31
  typeof input?.constructor?.isBuffer === 'function' &&
32
32
  input.constructor.isBuffer(input)
33
33
 
34
+ const rootCause = error => {
35
+ let cause = error
36
+ while (cause?.cause instanceof Error) cause = cause.cause
37
+ return cause
38
+ }
39
+
34
40
  const parseBody = (input, error, url) => {
35
41
  try {
36
42
  return JSON.parse(input)
37
43
  } catch (_) {
38
- const message = input || error.message
44
+ const message = input || rootCause(error).message
39
45
 
40
46
  return {
41
47
  status: 'error',
@@ -58,8 +64,8 @@ const isURL = url => {
58
64
  }
59
65
 
60
66
  class MicrolinkError extends Error {
61
- constructor (props) {
62
- super()
67
+ constructor ({ cause, ...props }) {
68
+ super(undefined, cause ? { cause } : undefined)
63
69
  this.name = 'MicrolinkError'
64
70
  Object.assign(this, props)
65
71
  this.description = this.message
@@ -146,7 +152,8 @@ const fetchFromApi = async (apiUrl, opts = {}) => {
146
152
  ...body,
147
153
  url: uri,
148
154
  statusCode,
149
- headers
155
+ headers,
156
+ cause: error
150
157
  })
151
158
  }
152
159
  }