-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathindex.d.ts
More file actions
193 lines (178 loc) · 5.21 KB
/
Copy pathindex.d.ts
File metadata and controls
193 lines (178 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Type definitions for oembed-extractor
// Project: https://github.com/extractus/oembed-extractor
// Definitions by: BendingBender <https://github.com/BendingBender>
// CodeBast4rd <https://github.com/CodeBast4rd>
// Marc McIntosh <https://github.com/MarcMcIntosh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* An oEmbed provider endpoint definition as used in the provider registry.
*/
export interface Endpoint {
/** URL scheme patterns that match resources for this provider */
schemes?: string[]
/** The oEmbed API endpoint URL */
url: string
/** Supported response formats, e.g. "json", "xml" */
formats?: string[]
/** Whether auto-discovery is supported */
discovery?: boolean
}
/**
* A provider entry from the oEmbed registry.
*/
export interface Provider {
/** Human-readable provider name */
provider_name: string
/** Provider's homepage URL */
provider_url: string
/** List of API endpoints for this provider */
endpoints: Endpoint[]
}
/**
* Result returned by findProvider().
*/
export interface FindProviderResult {
/** Matched oEmbed API endpoint URL */
endpoint: string
/** Regex patterns used to match this URL */
schemes: RegExp[]
/** The original queried URL */
url: string
}
/**
* Basic fields present in every oEmbed response.
* See https://oembed.com/
*/
export interface OembedData {
/** Resource type: rich, video, photo, or link */
type: 'rich' | 'video' | 'photo' | 'link'
/** oEmbed version number */
version: string
/** A text title describing the resource */
title?: string
/** Name of the author/owner of the resource */
author_name?: string
/** URL for the author/owner of the resource */
author_url?: string
/** Name of the resource provider */
provider_name?: string
/** URL of the resource provider */
provider_url?: string
/** Suggested cache lifetime in seconds */
cache_age?: string | number
/** URL to a thumbnail image representing the resource */
thumbnail_url?: string
/** Width of the optional thumbnail in pixels */
thumbnail_width?: number
/** Height of the optional thumbnail in pixels */
thumbnail_height?: number
/** How the oEmbed data was retrieved: "provider-api" or "auto-discovery" */
method?: string
}
/**
* oEmbed response for type "link".
*/
export interface LinkTypeData extends OembedData {
readonly type: 'link'
}
/**
* oEmbed response for type "photo".
*/
export interface PhotoTypeData extends OembedData {
readonly type: 'photo'
/** Source URL of the image */
url: string
/** Width of the image in pixels */
width: number
/** Height of the image in pixels */
height: number
}
/**
* oEmbed response for type "video".
*/
export interface VideoTypeData extends OembedData {
readonly type: 'video'
/** HTML required to embed a video player */
html: string
/** Width required to display the HTML in pixels */
width: number
/** Height required to display the HTML in pixels */
height: number
}
/**
* oEmbed response for type "rich".
*/
export interface RichTypeData extends OembedData {
readonly type: 'rich'
/** HTML required to display the resource */
html: string
/** Width required to display the HTML in pixels */
width: number
/** Height required to display the HTML in pixels */
height: number
}
/**
* Optional parameters passed to extract().
*/
export interface Params {
/** Max width of embed size */
maxwidth?: number
/** Max height of embed size */
maxheight?: number
/** Theme for the embed, e.g. "dark" or "light" */
theme?: string
/** Language for the embed, e.g. "en", "fr", "vi" */
lang?: string
}
/**
* Configuration for proxy-based requests.
*/
export interface ProxyConfig {
/** Base URL of the proxy server */
target?: string
/** Headers to send to the proxy (e.g. Proxy-Authorization) */
headers?: Record<string, string>
}
/**
* Advanced fetch options for extract().
*/
export interface FetchOptions {
/** Custom request headers */
headers?: Record<string, string>
/** Proxy configuration */
proxy?: ProxyConfig
/** HTTP proxy agent (e.g. HttpsProxyAgent) */
agent?: object
/** AbortSignal to cancel the request */
signal?: AbortSignal
}
/**
* Extract oEmbed data from a given URL.
*
* @param url - URL of a valid oEmbed resource
* @param params - Optional parameters (maxwidth, maxheight, etc.)
* @param fetchOptions - Advanced fetch options (headers, proxy, agent, signal)
* @returns Promise resolving to oEmbed data
*/
export function extract(url: string, params?: Params, fetchOptions?: FetchOptions): Promise<OembedData>
/**
* Check if a URL is supported by any registered provider.
*
* @param url - URL to check
* @returns True if a matching provider exists
*/
export function hasProvider(url: string): boolean
/**
* Find the provider that matches a given URL.
*
* @param url - URL to look up
* @returns Provider info or undefined if not found
*/
export function findProvider(url: string): FindProviderResult | null
/**
* Replace the provider list with a custom set of providers.
*
* @param providers - List of providers in oEmbed registry format
* @returns Number of providers in the new list
*/
export function setProviderList(providers: Provider[]): number