@microlink/mql 0.9.10 → 0.9.14

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/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  /// <reference types="node" />
2
2
 
3
3
  declare module "@microlink/mql" {
4
- export type WaitUntilEvent = "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
4
+ export type WaitUntilEvent =
5
+ | "load"
6
+ | "domcontentloaded"
7
+ | "networkidle0"
8
+ | "networkidle2";
5
9
 
6
10
  export type ScreenshotOptions = Partial<{
7
11
  background: string;
@@ -24,14 +28,24 @@ declare module "@microlink/mql" {
24
28
  }>;
25
29
 
26
30
  export type MqlQueryResponseType =
31
+ | "audio"
27
32
  | "author"
33
+ | "auto"
34
+ | "boolean"
28
35
  | "date"
29
36
  | "description"
30
37
  | "image"
38
+ | "ip"
39
+ | "lang"
40
+ | "logo"
41
+ | "number"
42
+ | "object"
43
+ | "publisher"
44
+ | "regexp"
45
+ | "string"
31
46
  | "title"
32
47
  | "url"
33
- | "lang"
34
- | "publisher";
48
+ | "video";
35
49
 
36
50
  export type MqlQueryOptions = Partial<{
37
51
  attr: string | string[];
@@ -41,7 +55,7 @@ declare module "@microlink/mql" {
41
55
  }>;
42
56
 
43
57
  export interface MqlQuery {
44
- [field: string]: MqlQueryOptions;
58
+ [field: string]: MqlQueryOptions | MqlQueryOptions[];
45
59
  }
46
60
 
47
61
  export type MicrolinkApiOptions = Partial<{
@@ -128,7 +142,10 @@ declare module "@microlink/mql" {
128
142
  response: Response;
129
143
  }
130
144
 
131
- declare function mql(url: string, opts?: MqlOptions & MicrolinkApiOptions): Promise<MqlResponse>;
145
+ declare function mql(
146
+ url: string,
147
+ opts?: MqlOptions & MicrolinkApiOptions
148
+ ): Promise<MqlResponse>;
132
149
 
133
150
  declare namespace mql {
134
151
  export class MicrolinkError extends Error {}
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.9.10",
5
+ "version": "0.9.14",
6
6
  "browser": "src/browser.js",
7
7
  "main": "src/node.js",
8
8
  "author": {
@@ -11,6 +11,10 @@
11
11
  "url": "https://github.com/Kikobeats"
12
12
  },
13
13
  "contributors": [
14
+ {
15
+ "name": "Dani de la Cruz",
16
+ "email": "5173869+delacruz-dev@users.noreply.github.com"
17
+ },
14
18
  {
15
19
  "name": "ndom91",
16
20
  "email": "yo@ndo.dev"
@@ -33,7 +37,7 @@
33
37
  "dependencies": {
34
38
  "flattie": "~1.1.0",
35
39
  "got": "~11.8.2",
36
- "is-url-http": "~2.2.3",
40
+ "is-url-http": "~2.2.4",
37
41
  "qss": "~2.0.3",
38
42
  "whoops": "~4.1.0"
39
43
  },
@@ -56,7 +60,7 @@
56
60
  "ky": "latest",
57
61
  "lint-staged": "latest",
58
62
  "meow": "latest",
59
- "node-fetch": "latest",
63
+ "node-fetch": "2",
60
64
  "npm-check-updates": "latest",
61
65
  "nyc": "latest",
62
66
  "prettier-standard": "latest",
package/src/factory.js CHANGED
@@ -14,8 +14,8 @@ const parseBody = (input, error, url) => {
14
14
  return {
15
15
  status: 'error',
16
16
  data: { url: message },
17
- more: 'https://microlink.io/efatal',
18
- code: 'EFATAL',
17
+ more: 'https://microlink.io/efatalclient',
18
+ code: 'EFATALCLIENT',
19
19
  message,
20
20
  url
21
21
  }
@@ -41,12 +41,12 @@ const factory = ({ VERSION, MicrolinkError, isUrlHttp, stringify, got, flatten }
41
41
  if (!isObject(rules)) return
42
42
  const flatRules = flatten(rules)
43
43
  return Object.keys(flatRules).reduce(
44
- (acc, key) => ({ ...acc, [`data.${key}`]: flatRules[key] }),
44
+ (acc, key) => ({ ...acc, [`data.${key}`]: flatRules[key].toString() }),
45
45
  {}
46
46
  )
47
47
  }
48
48
 
49
- const fetchFromApi = async (apiUrl, opts = {}) => {
49
+ const fetchFromApi = async (apiUrl, opts = {}, retryCount = 0) => {
50
50
  try {
51
51
  const response = await got(apiUrl, opts)
52
52
  return opts.responseType === 'buffer'
@@ -59,6 +59,8 @@ const factory = ({ VERSION, MicrolinkError, isUrlHttp, stringify, got, flatten }
59
59
  const body =
60
60
  isObject(rawBody) && !Buffer.isBuffer(rawBody) ? rawBody : parseBody(rawBody, err, uri)
61
61
 
62
+ if (body.code === 'EFATALCLIENT' && retryCount++ < 2) return fetchFromApi(apiUrl, opts, retryCount)
63
+
62
64
  throw MicrolinkError({
63
65
  ...body,
64
66
  message: body.message,