Skip to content

Commit

Permalink
feat: redirects (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats authored Dec 8, 2024
1 parent e9329d4 commit 5b90fd7
Show file tree
Hide file tree
Showing 3 changed files with 315 additions and 304 deletions.
302 changes: 167 additions & 135 deletions lightweight/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,194 +1,226 @@
type ColorScheme = | "dark" | "light";
type ColorScheme = 'dark' | 'light'

type WaitUntilEvent = "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
type WaitUntilEvent =
| 'load'
| 'domcontentloaded'
| 'networkidle0'
| 'networkidle2'

type PixelUnit = string | number;
type PixelUnit = string | number

type ScreenshotOverlay = {
background?: string,
background?: string
browser?: 'dark' | 'light'
}

type PdfMargin = {
bottom?: string | number;
left?: string | number;
right?: string | number;
top?: string | number;
bottom?: string | number
left?: string | number
right?: string | number
top?: string | number
}

type PdfOptions = {
format?: string;
height?: PixelUnit;
landscape?: string;
margin?: string | PdfMargin;
pageRanges?: string;
scale?: number;
width?: PixelUnit;
format?: string
height?: PixelUnit
landscape?: string
margin?: string | PdfMargin
pageRanges?: string
scale?: number
width?: PixelUnit
}

type ScreenshotOptions = {
codeScheme?: string;
element?: string;
fullPage?: boolean;
omitBackground?: boolean;
optimizeForSpeed?: boolean;
overlay?: ScreenshotOverlay,
type?: "jpeg" | "png";
codeScheme?: string
element?: string
fullPage?: boolean
omitBackground?: boolean
optimizeForSpeed?: boolean
overlay?: ScreenshotOverlay
type?: 'jpeg' | 'png'
}

type MqlClientOptions = {
apiKey?: string;
cache?: Map<string, any>;
endpoint?: string;
retry?: number;
apiKey?: string
cache?: Map<string, any>
endpoint?: string
retry?: number
}

type MqlQuery = {
[field: string]: MqlQueryOptions;
[field: string]: MqlQueryOptions
}

type MqlQueryOptions = {
attr?: string | string[] | MqlQuery;
evaluate?: string;
selector?: string | string[];
selectorAll?: string | string[];
type?: "audio" | "author" | "auto" | "boolean" | "date" | "description" | "email" | "image" | "ip" | "lang" | "logo" | "number" | "object" | "publisher" | "regexp" | "string" | "title" | "url" | "video";
attr?: string | string[] | MqlQuery
evaluate?: string
selector?: string | string[]
selectorAll?: string | string[]
type?:
| 'audio'
| 'author'
| 'auto'
| 'boolean'
| 'date'
| 'description'
| 'email'
| 'image'
| 'ip'
| 'lang'
| 'logo'
| 'number'
| 'object'
| 'publisher'
| 'regexp'
| 'string'
| 'title'
| 'url'
| 'video'
}

type MicrolinkApiOptions = {
adblock?: boolean;
animations?: boolean;
audio?: boolean;
click?: string | string[];
colorScheme?: ColorScheme;
data?: MqlQuery;
device?: string;
embed?: string;
filename?: string;
filter?: string;
force?: boolean;
function?: string;
headers?: Record<string, string>;
iframe?: boolean | { maxWidth?: number, maxHeight?: number };
insights?: boolean | { lighthouse?: boolean | object, technologies?: boolean };
javascript?: boolean;
mediaType?: string;
meta?: boolean | { logo: { square: boolean } };
modules?: string | string[];
palette?: boolean;
pdf?: boolean | PdfOptions;
ping?: boolean | object;
prerender?: boolean | "auto";
proxy?: string | { countryCode?: string };
retry?: number;
screenshot?: boolean | ScreenshotOptions;
scripts?: string | string[];
scroll?: string;
staleTtl?: string | number;
stream?: string;
styles?: string | string[];
timeout?: number;
ttl?: string | number;
video?: boolean;
viewport?: object;
waitForSelector?: string;
waitForTimeout?: number;
waitUntil?: WaitUntilEvent | WaitUntilEvent[];
adblock?: boolean
animations?: boolean
audio?: boolean
click?: string | string[]
colorScheme?: ColorScheme
data?: MqlQuery
device?: string
embed?: string
filename?: string
filter?: string
force?: boolean
function?: string
headers?: Record<string, string>
iframe?: boolean | { maxWidth?: number; maxHeight?: number }
insights?: boolean | { lighthouse?: boolean | object; technologies?: boolean }
javascript?: boolean
mediaType?: string
meta?: boolean | { logo: { square: boolean } }
modules?: string | string[]
palette?: boolean
pdf?: boolean | PdfOptions
ping?: boolean | object
prerender?: boolean | 'auto'
proxy?: string | { countryCode?: string }
retry?: number
screenshot?: boolean | ScreenshotOptions
scripts?: string | string[]
scroll?: string
staleTtl?: string | number
stream?: string
styles?: string | string[]
timeout?: number
ttl?: string | number
video?: boolean
viewport?: object
waitForSelector?: string
waitForTimeout?: number
waitUntil?: WaitUntilEvent | WaitUntilEvent[]
}

type IframeInfo = {
html: string;
scripts: Record<string, unknown>;
html: string
scripts: Record<string, unknown>
}

type MediaInfo = {
alternative_color?: string;
background_color?: string;
color?: string;
duration_pretty?: string;
duration?: number;
height?: number;
palette?: string[];
size_pretty?: string;
size?: number;
type?: string;
url: string;
width?: number;
alternative_color?: string
background_color?: string
color?: string
duration_pretty?: string
duration?: number
height?: number
palette?: string[]
size_pretty?: string
size?: number
type?: string
url: string
width?: number
}

export type MqlResponseData = {
audio?: MediaInfo | null;
author?: string | null;
date?: string | null;
description?: string | null;
function?: MqlFunctionResult;
iframe?: IframeInfo | null;
image?: MediaInfo | null;
lang?: string | null;
logo?: MediaInfo | null;
publisher?: string | null;
screenshot?: MediaInfo | null;
title?: string | null;
url?: string;
video?: MediaInfo | null;
audio?: MediaInfo | null
author?: string | null
date?: string | null
description?: string | null
function?: MqlFunctionResult
iframe?: IframeInfo | null
image?: MediaInfo | null
lang?: string | null
logo?: MediaInfo | null
publisher?: string | null
screenshot?: MediaInfo | null
title?: string | null
url?: string
video?: MediaInfo | null
}

type MqlFunctionResult = {
isFulfilled: boolean;
isRejected: boolean;
value: any;
};
isFulfilled: boolean
isRejected: boolean
value: any
}

type MqlStatus = "success" | "fail" | "error";
type MqlStatus = 'success' | 'fail' | 'error'

export type MqlPayload = {
status: MqlStatus;
data: MqlResponseData;
statusCode?: number;
headers: { [key: string]: string };
status: MqlStatus
data: MqlResponseData
statusCode?: number
redirects: { statusCode: number; url: string }[]
headers: { [key: string]: string }
}

type HTTPResponse = {
url: string;
statusCode: number;
headers: Headers;
url: string
statusCode: number
headers: Headers
}

type HTTPResponseWithBody = HTTPResponse & { body: MqlPayload };
type HTTPResponseWithBody = HTTPResponse & { body: MqlPayload }

export type HTTPResponseRaw = HTTPResponse & { body: ArrayBuffer };
export type HTTPResponseRaw = HTTPResponse & { body: ArrayBuffer }

export type MqlResponse = MqlPayload & { response: HTTPResponseWithBody };
export type MqlResponse = MqlPayload & { response: HTTPResponseWithBody }

export type MqlError = {
code: string;
data?: MqlResponseData;
description: string;
headers: { [key: string]: string };
message: string;
more: string;
name: string;
status: MqlStatus;
statusCode?: number;
url: string;
code: string
data?: MqlResponseData
description: string
headers: { [key: string]: string }
message: string
more: string
name: string
status: MqlStatus
statusCode?: number
url: string
}

export type MqlOptions = MqlClientOptions & MicrolinkApiOptions;
export type MqlOptions = MqlClientOptions & MicrolinkApiOptions

export const MicrolinkError: new (props: object) => MqlError;
export const MicrolinkError: new (props: object) => MqlError

export const version: string;
export const version: string

interface mql {
(url: string, opts?: MqlOptions & { stream: string }, gotOpts?: object): Promise<HTTPResponseRaw>;
(url: string, opts?: MqlOptions, gotOpts?: object): Promise<MqlResponse>;
arrayBuffer: (url: string, opts?: MqlOptions, gotOpts?: object) => Promise<HTTPResponseRaw>;
extend: (gotOpts?: object) => mql;
stream: (input: RequestInfo, init?: RequestInit) => ReadableStream;
MicrolinkError: new (props: object) => MqlError;
version: string;
(
url: string,
opts?: MqlOptions & { stream: string },
gotOpts?: object
): Promise<HTTPResponseRaw>
(url: string, opts?: MqlOptions, gotOpts?: object): Promise<MqlResponse>
arrayBuffer: (
url: string,
opts?: MqlOptions,
gotOpts?: object
) => Promise<HTTPResponseRaw>
extend: (gotOpts?: object) => mql
stream: (input: RequestInfo, init?: RequestInit) => ReadableStream
MicrolinkError: new (props: object) => MqlError
version: string
}

declare const mql: mql;
declare const mql: mql

export default mql;
export default mql
Loading

0 comments on commit 5b90fd7

Please sign in to comment.