@quikturn/logos 0.2.0 → 0.2.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/README.md +11 -87
- package/dist/client/index.cjs +7 -59
- package/dist/client/index.d.cts +2 -187
- package/dist/client/index.d.ts +2 -187
- package/dist/client/index.mjs +8 -57
- package/dist/index.cjs +1 -91
- package/dist/index.d.cts +1 -167
- package/dist/index.d.ts +1 -167
- package/dist/index.mjs +2 -83
- package/dist/server/index.cjs +15 -24
- package/dist/server/index.d.cts +2 -94
- package/dist/server/index.d.ts +2 -94
- package/dist/server/index.mjs +16 -23
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @quikturn/logos SDK — Public Type Definitions
|
|
3
|
-
*
|
|
4
|
-
* All types mirror the Cloudflare Worker's type system exactly.
|
|
5
|
-
* This file contains only type-level constructs (no runtime code).
|
|
6
|
-
*
|
|
7
|
-
* Source of truth: cf-worker-logos/src/types.ts, options.ts, rateLimit.ts, monthlyQuota.ts
|
|
8
|
-
*/
|
|
9
|
-
/** Distinguishes between publishable (browser-safe) and secret (server-only) keys. */
|
|
10
|
-
type KeyType = "publishable" | "secret";
|
|
11
|
-
/** Valid key prefixes used to identify key type from the token string. */
|
|
12
|
-
type KeyPrefix = "qt_" | "pk_" | "sk_";
|
|
13
|
-
/** Subscription tier determining rate limits, monthly quotas, and max image width. */
|
|
14
|
-
type Tier = "free" | "launch" | "growth" | "enterprise";
|
|
15
|
-
/** Current lifecycle status of an API token. */
|
|
16
|
-
type TokenStatus = "active" | "suspended" | "revoked";
|
|
17
1
|
/** Theme adjusts the gamma curve applied during image transformation. */
|
|
18
2
|
type ThemeOption = "light" | "dark";
|
|
19
3
|
/** Full MIME-type output formats supported by the worker's image pipeline. */
|
|
@@ -29,7 +13,6 @@ type FormatShorthand = "png" | "jpeg" | "webp" | "avif";
|
|
|
29
13
|
* - `greyscale` — When true, applies saturation: 0 transformation. Default: false.
|
|
30
14
|
* - `theme` — "light" (gamma 0.9) or "dark" (gamma 1.12).
|
|
31
15
|
* - `format` — Output image format. Accepts full MIME type or shorthand. Default: "image/png".
|
|
32
|
-
* - `autoScrape` — When true, triggers a background scrape if the logo is not found. Default: false.
|
|
33
16
|
* - `baseUrl` — Override the default API base URL. Useful for testing or proxied environments.
|
|
34
17
|
*/
|
|
35
18
|
interface LogoRequestOptions {
|
|
@@ -39,7 +22,6 @@ interface LogoRequestOptions {
|
|
|
39
22
|
greyscale?: boolean;
|
|
40
23
|
theme?: ThemeOption;
|
|
41
24
|
format?: SupportedOutputFormat | FormatShorthand;
|
|
42
|
-
autoScrape?: boolean;
|
|
43
25
|
baseUrl?: string;
|
|
44
26
|
}
|
|
45
27
|
/**
|
|
@@ -96,34 +78,6 @@ interface ServerLogoResponse {
|
|
|
96
78
|
contentType: string;
|
|
97
79
|
metadata: LogoMetadata;
|
|
98
80
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Describes a background scrape job returned in a 202 response.
|
|
101
|
-
*
|
|
102
|
-
* - `jobId` — Unique identifier for the scrape job.
|
|
103
|
-
* - `pollUrl` — URL to poll for scrape progress.
|
|
104
|
-
* - `estimatedWaitMs` — Estimated time in milliseconds before the scrape completes.
|
|
105
|
-
*/
|
|
106
|
-
interface ScrapeJob {
|
|
107
|
-
jobId: string;
|
|
108
|
-
pollUrl: string;
|
|
109
|
-
estimatedWaitMs: number;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* The JSON body returned by the worker when a 202 (scrape pending) response is issued.
|
|
113
|
-
*
|
|
114
|
-
* - `status` — Always "scrape_pending".
|
|
115
|
-
* - `message` — Human-readable status message.
|
|
116
|
-
* - `companyId` — Optional identifier of the matched company.
|
|
117
|
-
* - `companyName` — Optional name of the matched company.
|
|
118
|
-
* - `scrapeJob` — Details for polling the scrape job.
|
|
119
|
-
*/
|
|
120
|
-
interface ScrapePendingResponse {
|
|
121
|
-
status: "scrape_pending";
|
|
122
|
-
message: string;
|
|
123
|
-
companyId?: number;
|
|
124
|
-
companyName?: string;
|
|
125
|
-
scrapeJob: ScrapeJob;
|
|
126
|
-
}
|
|
127
81
|
/** Lifecycle status of a background scrape job. */
|
|
128
82
|
type ScrapeJobStatus = "pending" | "complete" | "failed";
|
|
129
83
|
/**
|
|
@@ -145,32 +99,6 @@ interface ScrapeProgressEvent {
|
|
|
145
99
|
};
|
|
146
100
|
error?: string;
|
|
147
101
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Possible attribution verification states for free-tier consumers.
|
|
150
|
-
*
|
|
151
|
-
* - "verified" — Attribution confirmed and valid.
|
|
152
|
-
* - "pending" — Verification in progress; treated as valid.
|
|
153
|
-
* - "unverified" — Attribution not yet set up.
|
|
154
|
-
* - "failed" — Verification attempted but failed.
|
|
155
|
-
* - "grace-period" — Temporary grace; validity depends on graceDeadline.
|
|
156
|
-
* - "error" — An error occurred during verification.
|
|
157
|
-
*/
|
|
158
|
-
type AttributionStatus = "verified" | "pending" | "unverified" | "failed" | "grace-period" | "error";
|
|
159
|
-
/**
|
|
160
|
-
* Structured attribution information parsed from response headers.
|
|
161
|
-
*
|
|
162
|
-
* - `status` — Current attribution verification state.
|
|
163
|
-
* - `graceDeadline` — If in grace period, the deadline by which attribution must be verified.
|
|
164
|
-
* - `verifiedAt` — Timestamp of when attribution was last verified.
|
|
165
|
-
* - `isValid` — Derived boolean: true when status is "verified", "pending",
|
|
166
|
-
* or "grace-period" with a future graceDeadline.
|
|
167
|
-
*/
|
|
168
|
-
interface AttributionInfo {
|
|
169
|
-
status: AttributionStatus;
|
|
170
|
-
graceDeadline?: Date;
|
|
171
|
-
verifiedAt?: Date;
|
|
172
|
-
isValid: boolean;
|
|
173
|
-
}
|
|
174
102
|
/**
|
|
175
103
|
* Discriminated union of all machine-readable error codes used by the SDK.
|
|
176
104
|
*
|
|
@@ -196,38 +124,12 @@ type LogoErrorCode = "DOMAIN_VALIDATION_ERROR" | "RATE_LIMIT_ERROR" | "QUOTA_EXC
|
|
|
196
124
|
declare const BASE_URL: "https://logos.getquikturn.io";
|
|
197
125
|
/** Default logo width in pixels when no size/width is provided. */
|
|
198
126
|
declare const DEFAULT_WIDTH: 128;
|
|
199
|
-
/** Maximum width (px) for requests using publishable keys (qt_/pk_). */
|
|
200
|
-
declare const MAX_WIDTH: 800;
|
|
201
|
-
/** Maximum width (px) for requests using secret keys (sk_). */
|
|
202
|
-
declare const MAX_WIDTH_SERVER: 1200;
|
|
203
127
|
/** Default MIME type returned when no format is specified. */
|
|
204
128
|
declare const DEFAULT_FORMAT: SupportedOutputFormat;
|
|
205
129
|
/** All MIME types the Logos API can produce. */
|
|
206
130
|
declare const SUPPORTED_FORMATS: ReadonlySet<SupportedOutputFormat>;
|
|
207
131
|
/** Maps shorthand format strings to their full MIME types. */
|
|
208
132
|
declare const FORMAT_ALIASES: Readonly<Record<FormatShorthand, SupportedOutputFormat>>;
|
|
209
|
-
/**
|
|
210
|
-
* Per-tier rate limits for publishable-key (browser) requests.
|
|
211
|
-
* All tiers share a 60-second sliding window.
|
|
212
|
-
*/
|
|
213
|
-
declare const RATE_LIMITS: Readonly<Record<Tier, {
|
|
214
|
-
requests: number;
|
|
215
|
-
windowSeconds: number;
|
|
216
|
-
}>>;
|
|
217
|
-
/**
|
|
218
|
-
* Per-tier rate limits for secret-key (server) requests.
|
|
219
|
-
* The free tier does not have server-side access.
|
|
220
|
-
*/
|
|
221
|
-
declare const SERVER_RATE_LIMITS: Readonly<Record<Exclude<Tier, "free">, {
|
|
222
|
-
requests: number;
|
|
223
|
-
windowSeconds: number;
|
|
224
|
-
}>>;
|
|
225
|
-
/** All subscription tiers as a runtime-iterable tuple. */
|
|
226
|
-
declare const TIERS: readonly Tier[];
|
|
227
|
-
/** All key types as a runtime-iterable tuple. */
|
|
228
|
-
declare const KEY_TYPES: readonly KeyType[];
|
|
229
|
-
/** Maximum logo requests per calendar month for each tier. */
|
|
230
|
-
declare const MONTHLY_LIMITS: Readonly<Record<Tier, number>>;
|
|
231
133
|
|
|
232
134
|
/**
|
|
233
135
|
* @quikturn/logos SDK — URL Builder
|
|
@@ -264,74 +166,6 @@ declare const MONTHLY_LIMITS: Readonly<Record<Tier, number>>;
|
|
|
264
166
|
*/
|
|
265
167
|
declare function logoUrl(domain: string, options?: LogoRequestOptions): string;
|
|
266
168
|
|
|
267
|
-
/**
|
|
268
|
-
* @quikturn/logos SDK — Response Header Parser
|
|
269
|
-
*
|
|
270
|
-
* Parses structured metadata from Cloudflare Worker response headers into
|
|
271
|
-
* strongly-typed SDK objects. The worker attaches cache status, rate-limit
|
|
272
|
-
* counters, monthly quota info, and image transformation details as custom
|
|
273
|
-
* `X-` headers on every successful response.
|
|
274
|
-
*
|
|
275
|
-
* Two public functions are exported:
|
|
276
|
-
* - `parseLogoHeaders` — extracts a full `LogoMetadata` object.
|
|
277
|
-
* - `parseRetryAfter` — extracts the `Retry-After` value for 429 handling.
|
|
278
|
-
*/
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Parses Cloudflare Worker response headers into a `LogoMetadata` object.
|
|
282
|
-
*
|
|
283
|
-
* Extracts and normalizes the following header families:
|
|
284
|
-
*
|
|
285
|
-
* | Header | Field |
|
|
286
|
-
* |-----------------------------|---------------------------------|
|
|
287
|
-
* | `X-Cache-Status` | `cache.status` |
|
|
288
|
-
* | `X-RateLimit-Remaining` | `rateLimit.remaining` |
|
|
289
|
-
* | `X-RateLimit-Reset` | `rateLimit.reset` (as `Date`) |
|
|
290
|
-
* | `X-Quota-Remaining` | `quota.remaining` |
|
|
291
|
-
* | `X-Quota-Limit` | `quota.limit` |
|
|
292
|
-
* | `X-Quikturn-Token` | `tokenPrefix` |
|
|
293
|
-
* | `X-Transformation-Applied` | `transformation.applied` |
|
|
294
|
-
* | `X-Transformation-Status` | `transformation.status` |
|
|
295
|
-
* | `X-Transformation-Method` | `transformation.method` |
|
|
296
|
-
* | `X-Transformation-Width` | `transformation.width` |
|
|
297
|
-
* | `X-Transformation-Greyscale`| `transformation.greyscale` |
|
|
298
|
-
* | `X-Transformation-Gamma` | `transformation.gamma` |
|
|
299
|
-
*
|
|
300
|
-
* Missing or unparseable numeric headers fall back to `0` for required fields
|
|
301
|
-
* and `undefined` for optional fields. The cache status defaults to `"MISS"`
|
|
302
|
-
* unless the header value is exactly `"HIT"`.
|
|
303
|
-
*
|
|
304
|
-
* @param headers - The `Headers` object from a fetch `Response`.
|
|
305
|
-
* @returns A fully-populated `LogoMetadata` object.
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* ```ts
|
|
309
|
-
* const response = await fetch(logoUrl("github.com"));
|
|
310
|
-
* const metadata = parseLogoHeaders(response.headers);
|
|
311
|
-
* console.log(metadata.cache.status); // "HIT" or "MISS"
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
declare function parseLogoHeaders(headers: Headers): LogoMetadata;
|
|
315
|
-
/**
|
|
316
|
-
* Parses the `Retry-After` response header into a numeric value (seconds).
|
|
317
|
-
*
|
|
318
|
-
* The Logos API always sends `Retry-After` as an integer number of seconds
|
|
319
|
-
* (not an HTTP-date). Returns `null` when the header is absent or its value
|
|
320
|
-
* cannot be parsed as a finite number.
|
|
321
|
-
*
|
|
322
|
-
* @param headers - The `Headers` object from a fetch `Response`.
|
|
323
|
-
* @returns The retry delay in seconds, or `null` if not present.
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* ```ts
|
|
327
|
-
* const retryAfter = parseRetryAfter(response.headers);
|
|
328
|
-
* if (retryAfter !== null) {
|
|
329
|
-
* await new Promise((r) => setTimeout(r, retryAfter * 1000));
|
|
330
|
-
* }
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
declare function parseRetryAfter(headers: Headers): number | null;
|
|
334
|
-
|
|
335
169
|
/**
|
|
336
170
|
* @quikturn/logos SDK — Error Classes
|
|
337
171
|
*
|
|
@@ -434,4 +268,4 @@ declare class BadRequestError extends LogoError {
|
|
|
434
268
|
constructor(message: string);
|
|
435
269
|
}
|
|
436
270
|
|
|
437
|
-
export {
|
|
271
|
+
export { AuthenticationError, BASE_URL, BadRequestError, type BrowserLogoResponse, DEFAULT_FORMAT, DEFAULT_WIDTH, DomainValidationError, FORMAT_ALIASES, ForbiddenError, type FormatShorthand, LogoError, type LogoErrorCode, type LogoMetadata, type LogoRequestOptions, NotFoundError, QuotaExceededError, RateLimitError, SUPPORTED_FORMATS, type ScrapeProgressEvent, ScrapeTimeoutError, type ServerLogoResponse, type SupportedOutputFormat, type ThemeOption, logoUrl };
|
package/dist/index.mjs
CHANGED
|
@@ -16,25 +16,6 @@ var FORMAT_ALIASES = {
|
|
|
16
16
|
webp: "image/webp",
|
|
17
17
|
avif: "image/avif"
|
|
18
18
|
};
|
|
19
|
-
var RATE_LIMITS = {
|
|
20
|
-
free: { requests: 100, windowSeconds: 60 },
|
|
21
|
-
launch: { requests: 500, windowSeconds: 60 },
|
|
22
|
-
growth: { requests: 5e3, windowSeconds: 60 },
|
|
23
|
-
enterprise: { requests: 5e4, windowSeconds: 60 }
|
|
24
|
-
};
|
|
25
|
-
var SERVER_RATE_LIMITS = {
|
|
26
|
-
launch: { requests: 1e3, windowSeconds: 60 },
|
|
27
|
-
growth: { requests: 1e4, windowSeconds: 60 },
|
|
28
|
-
enterprise: { requests: 1e5, windowSeconds: 60 }
|
|
29
|
-
};
|
|
30
|
-
var TIERS = ["free", "launch", "growth", "enterprise"];
|
|
31
|
-
var KEY_TYPES = ["publishable", "secret"];
|
|
32
|
-
var MONTHLY_LIMITS = {
|
|
33
|
-
free: 5e5,
|
|
34
|
-
launch: 1e6,
|
|
35
|
-
growth: 5e6,
|
|
36
|
-
enterprise: 1e7
|
|
37
|
-
};
|
|
38
19
|
|
|
39
20
|
// src/errors.ts
|
|
40
21
|
var LogoError = class extends Error {
|
|
@@ -199,7 +180,6 @@ function logoUrl(domain, options) {
|
|
|
199
180
|
greyscale,
|
|
200
181
|
theme,
|
|
201
182
|
format,
|
|
202
|
-
autoScrape,
|
|
203
183
|
baseUrl
|
|
204
184
|
} = options ?? {};
|
|
205
185
|
const maxWidth = token?.startsWith("sk_") ? MAX_WIDTH_SERVER : MAX_WIDTH;
|
|
@@ -226,69 +206,8 @@ function logoUrl(domain, options) {
|
|
|
226
206
|
if (resolvedFormat !== void 0) {
|
|
227
207
|
url.searchParams.set("format", resolvedFormat);
|
|
228
208
|
}
|
|
229
|
-
|
|
230
|
-
url.searchParams.set("autoScrape", "true");
|
|
231
|
-
}
|
|
209
|
+
url.searchParams.set("autoScrape", "true");
|
|
232
210
|
return url.toString();
|
|
233
211
|
}
|
|
234
212
|
|
|
235
|
-
|
|
236
|
-
function safeParseInt(value, fallback) {
|
|
237
|
-
if (value === null) return fallback;
|
|
238
|
-
const parsed = parseInt(value, 10);
|
|
239
|
-
return Number.isNaN(parsed) ? fallback : parsed;
|
|
240
|
-
}
|
|
241
|
-
function safeParseFloat(value, fallback) {
|
|
242
|
-
if (value === null) return fallback;
|
|
243
|
-
const parsed = parseFloat(value);
|
|
244
|
-
return Number.isNaN(parsed) ? fallback : parsed;
|
|
245
|
-
}
|
|
246
|
-
function parseLogoHeaders(headers) {
|
|
247
|
-
const cacheStatus = headers.get("X-Cache-Status");
|
|
248
|
-
const rateLimitRemaining = safeParseInt(headers.get("X-RateLimit-Remaining"), 0);
|
|
249
|
-
const rateLimitReset = safeParseInt(headers.get("X-RateLimit-Reset"), 0);
|
|
250
|
-
const quotaRemaining = safeParseInt(headers.get("X-Quota-Remaining"), 0);
|
|
251
|
-
const quotaLimit = safeParseInt(headers.get("X-Quota-Limit"), 0);
|
|
252
|
-
const tokenPrefix = headers.get("X-Quikturn-Token") ?? void 0;
|
|
253
|
-
const transformApplied = headers.get("X-Transformation-Applied") === "true";
|
|
254
|
-
const VALID_TRANSFORM_STATUSES = /* @__PURE__ */ new Set([
|
|
255
|
-
"not-requested",
|
|
256
|
-
"unsupported-format",
|
|
257
|
-
"transformation-error"
|
|
258
|
-
]);
|
|
259
|
-
const rawTransformStatus = headers.get("X-Transformation-Status");
|
|
260
|
-
const transformStatus = rawTransformStatus && VALID_TRANSFORM_STATUSES.has(rawTransformStatus) ? rawTransformStatus : void 0;
|
|
261
|
-
const rawTransformMethod = headers.get("X-Transformation-Method");
|
|
262
|
-
const transformMethod = rawTransformMethod === "images-binding" ? "images-binding" : void 0;
|
|
263
|
-
const transformWidth = safeParseInt(headers.get("X-Transformation-Width"), void 0);
|
|
264
|
-
const transformGreyscale = headers.get("X-Transformation-Greyscale") === "true" ? true : void 0;
|
|
265
|
-
const transformGamma = safeParseFloat(headers.get("X-Transformation-Gamma"), void 0);
|
|
266
|
-
return {
|
|
267
|
-
cache: { status: cacheStatus === "HIT" ? "HIT" : "MISS" },
|
|
268
|
-
rateLimit: {
|
|
269
|
-
remaining: rateLimitRemaining,
|
|
270
|
-
reset: new Date(rateLimitReset * 1e3)
|
|
271
|
-
},
|
|
272
|
-
quota: {
|
|
273
|
-
remaining: quotaRemaining,
|
|
274
|
-
limit: quotaLimit
|
|
275
|
-
},
|
|
276
|
-
transformation: {
|
|
277
|
-
applied: transformApplied,
|
|
278
|
-
...transformStatus ? { status: transformStatus } : {},
|
|
279
|
-
...transformMethod ? { method: transformMethod } : {},
|
|
280
|
-
...transformWidth !== void 0 ? { width: transformWidth } : {},
|
|
281
|
-
...transformGreyscale !== void 0 ? { greyscale: transformGreyscale } : {},
|
|
282
|
-
...transformGamma !== void 0 ? { gamma: transformGamma } : {}
|
|
283
|
-
},
|
|
284
|
-
...tokenPrefix !== void 0 ? { tokenPrefix } : {}
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
function parseRetryAfter(headers) {
|
|
288
|
-
const value = headers.get("Retry-After");
|
|
289
|
-
if (value === null) return null;
|
|
290
|
-
const parsed = Number(value);
|
|
291
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export { AuthenticationError, BASE_URL, BadRequestError, DEFAULT_FORMAT, DEFAULT_WIDTH, DomainValidationError, FORMAT_ALIASES, ForbiddenError, KEY_TYPES, LogoError, MAX_WIDTH, MAX_WIDTH_SERVER, MONTHLY_LIMITS, NotFoundError, QuotaExceededError, RATE_LIMITS, RateLimitError, SERVER_RATE_LIMITS, SUPPORTED_FORMATS, ScrapeTimeoutError, TIERS, logoUrl, parseLogoHeaders, parseRetryAfter };
|
|
213
|
+
export { AuthenticationError, BASE_URL, BadRequestError, DEFAULT_FORMAT, DEFAULT_WIDTH, DomainValidationError, FORMAT_ALIASES, ForbiddenError, LogoError, NotFoundError, QuotaExceededError, RateLimitError, SUPPORTED_FORMATS, ScrapeTimeoutError, logoUrl };
|
package/dist/server/index.cjs
CHANGED
|
@@ -183,7 +183,6 @@ function logoUrl(domain, options) {
|
|
|
183
183
|
greyscale,
|
|
184
184
|
theme,
|
|
185
185
|
format,
|
|
186
|
-
autoScrape,
|
|
187
186
|
baseUrl
|
|
188
187
|
} = options ?? {};
|
|
189
188
|
const maxWidth = token?.startsWith("sk_") ? MAX_WIDTH_SERVER : MAX_WIDTH;
|
|
@@ -210,9 +209,7 @@ function logoUrl(domain, options) {
|
|
|
210
209
|
if (resolvedFormat !== void 0) {
|
|
211
210
|
url.searchParams.set("format", resolvedFormat);
|
|
212
211
|
}
|
|
213
|
-
|
|
214
|
-
url.searchParams.set("autoScrape", "true");
|
|
215
|
-
}
|
|
212
|
+
url.searchParams.set("autoScrape", "true");
|
|
216
213
|
return url.toString();
|
|
217
214
|
}
|
|
218
215
|
|
|
@@ -672,7 +669,6 @@ var QuikturnLogos = class {
|
|
|
672
669
|
greyscale: options?.greyscale,
|
|
673
670
|
theme: options?.theme,
|
|
674
671
|
format: options?.format,
|
|
675
|
-
autoScrape: options?.autoScrape,
|
|
676
672
|
baseUrl: this.baseUrl
|
|
677
673
|
});
|
|
678
674
|
const format = options?.format;
|
|
@@ -685,23 +681,21 @@ var QuikturnLogos = class {
|
|
|
685
681
|
onRateLimitWarning: (remaining, limit) => this.emit("rateLimitWarning", remaining, limit),
|
|
686
682
|
onQuotaWarning: (remaining, limit) => this.emit("quotaWarning", remaining, limit)
|
|
687
683
|
});
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
684
|
+
const fetchForPoller = (fetchUrl) => serverFetch(fetchUrl, {
|
|
685
|
+
token: this.secretKey,
|
|
686
|
+
maxRetries: this.maxRetries,
|
|
687
|
+
signal: options?.signal
|
|
688
|
+
});
|
|
689
|
+
response = await handleScrapeResponse(
|
|
690
|
+
response,
|
|
691
|
+
url,
|
|
692
|
+
fetchForPoller,
|
|
693
|
+
{
|
|
694
|
+
scrapeTimeout: options?.scrapeTimeout,
|
|
695
|
+
onScrapeProgress: options?.onScrapeProgress,
|
|
692
696
|
signal: options?.signal
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
response,
|
|
696
|
-
url,
|
|
697
|
-
fetchForPoller,
|
|
698
|
-
{
|
|
699
|
-
scrapeTimeout: options?.scrapeTimeout,
|
|
700
|
-
onScrapeProgress: options?.onScrapeProgress,
|
|
701
|
-
signal: options?.signal
|
|
702
|
-
}
|
|
703
|
-
);
|
|
704
|
-
}
|
|
697
|
+
}
|
|
698
|
+
);
|
|
705
699
|
const contentLength = response.headers.get("Content-Length");
|
|
706
700
|
if (contentLength) {
|
|
707
701
|
const size = parseInt(contentLength, 10);
|
|
@@ -782,7 +776,6 @@ var QuikturnLogos = class {
|
|
|
782
776
|
greyscale: options?.greyscale,
|
|
783
777
|
theme: options?.theme,
|
|
784
778
|
format: options?.format,
|
|
785
|
-
autoScrape: options?.autoScrape,
|
|
786
779
|
baseUrl: this.baseUrl
|
|
787
780
|
});
|
|
788
781
|
const format = options?.format;
|
|
@@ -854,5 +847,3 @@ var QuikturnLogos = class {
|
|
|
854
847
|
};
|
|
855
848
|
|
|
856
849
|
exports.QuikturnLogos = QuikturnLogos;
|
|
857
|
-
exports.getMany = getMany;
|
|
858
|
-
exports.serverFetch = serverFetch;
|
package/dist/server/index.d.cts
CHANGED
|
@@ -157,96 +157,6 @@ interface BatchResult {
|
|
|
157
157
|
metadata?: LogoMetadata;
|
|
158
158
|
error?: LogoError;
|
|
159
159
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Fetches logos for multiple domains with concurrency control.
|
|
162
|
-
* Yields results in the same order as the input domains array.
|
|
163
|
-
*
|
|
164
|
-
* The `fetchFn` parameter is a function that takes a domain and returns
|
|
165
|
-
* a result object with buffer, contentType, metadata. This decouples
|
|
166
|
-
* the batch module from the server fetcher implementation.
|
|
167
|
-
*
|
|
168
|
-
* Rate limit handling: when fetchFn throws a {@link RateLimitError},
|
|
169
|
-
* the batch pauses ALL pending work for `retryAfter` seconds before
|
|
170
|
-
* retrying the failed domain.
|
|
171
|
-
*
|
|
172
|
-
* @param domains - Array of domain strings to fetch logos for.
|
|
173
|
-
* @param fetchFn - Async function that fetches a single logo by domain.
|
|
174
|
-
* @param options - Optional batch configuration.
|
|
175
|
-
* @yields {BatchResult} Results in the same order as the input domains.
|
|
176
|
-
*/
|
|
177
|
-
declare function getMany(domains: string[], fetchFn: (domain: string) => Promise<{
|
|
178
|
-
buffer: Buffer;
|
|
179
|
-
contentType: string;
|
|
180
|
-
metadata: LogoMetadata;
|
|
181
|
-
}>, options?: BatchOptions): AsyncGenerator<BatchResult>;
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @quikturn/logos SDK — Server Fetch Wrapper
|
|
185
|
-
*
|
|
186
|
-
* Low-level fetch wrapper for the server entry point. Handles HTTP error
|
|
187
|
-
* mapping, retry logic for rate-limited and server-error responses,
|
|
188
|
-
* AbortSignal propagation, and proactive warning callbacks when rate-limit
|
|
189
|
-
* or quota headroom drops below 10%.
|
|
190
|
-
*
|
|
191
|
-
* Unlike the browser fetcher, this module sends the secret key as an
|
|
192
|
-
* `Authorization: Bearer` header — tokens are NEVER appended as query
|
|
193
|
-
* parameters.
|
|
194
|
-
*/
|
|
195
|
-
/**
|
|
196
|
-
* Options accepted by {@link serverFetch}.
|
|
197
|
-
*
|
|
198
|
-
* - `token` — Required: secret key (`sk_` prefix) sent as Bearer token.
|
|
199
|
-
* - `maxRetries` — Maximum number of retry attempts for 429/500 responses. Default: 2.
|
|
200
|
-
* - `signal` — An `AbortSignal` to cancel the in-flight request.
|
|
201
|
-
* - `format` — MIME type string used as the `Accept` request header.
|
|
202
|
-
* - `onRateLimitWarning` — Called when `X-RateLimit-Remaining` drops below 10% of the limit.
|
|
203
|
-
* - `onQuotaWarning` — Called when `X-Quota-Remaining` drops below 10% of the limit.
|
|
204
|
-
*/
|
|
205
|
-
interface ServerFetcherOptions {
|
|
206
|
-
token: string;
|
|
207
|
-
maxRetries?: number;
|
|
208
|
-
signal?: AbortSignal;
|
|
209
|
-
format?: string;
|
|
210
|
-
onRateLimitWarning?: (remaining: number, limit: number) => void;
|
|
211
|
-
onQuotaWarning?: (remaining: number, limit: number) => void;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Performs a fetch request to the Logos API with Bearer token authentication,
|
|
215
|
-
* error mapping, and retry logic.
|
|
216
|
-
*
|
|
217
|
-
* **Key difference from browser fetcher:**
|
|
218
|
-
* The secret key is sent as an `Authorization: Bearer {token}` header and is
|
|
219
|
-
* NEVER included in the URL query string.
|
|
220
|
-
*
|
|
221
|
-
* **Error mapping:**
|
|
222
|
-
* | Status | Error Class | Notes |
|
|
223
|
-
* |--------|-----------------------|--------------------------------------------|
|
|
224
|
-
* | 401 | AuthenticationError | Invalid or missing API token |
|
|
225
|
-
* | 403 | ForbiddenError | Body text used as `reason` |
|
|
226
|
-
* | 404 | NotFoundError | Domain extracted from URL path |
|
|
227
|
-
* | 429 | QuotaExceededError | When `X-Quota-Limit` header is present |
|
|
228
|
-
* | 429 | RateLimitError | After retries are exhausted |
|
|
229
|
-
* | 500 | LogoError | After a single retry attempt |
|
|
230
|
-
*
|
|
231
|
-
* **Retry behavior:**
|
|
232
|
-
* - 429: Waits `Retry-After` seconds (default 60s), retries up to `maxRetries`.
|
|
233
|
-
* If `X-Quota-Limit` is present, throws `QuotaExceededError` immediately.
|
|
234
|
-
* - 500: Retries once after a 1-second delay, then throws.
|
|
235
|
-
* - AbortError: Never retried; throws immediately.
|
|
236
|
-
* - Network errors: Never retried; throws immediately.
|
|
237
|
-
*
|
|
238
|
-
* @param url - Fully-qualified Logos API URL (built by `logoUrl`).
|
|
239
|
-
* @param options - Fetch configuration including the required `token`.
|
|
240
|
-
* @returns The raw `Response` object on success (2xx).
|
|
241
|
-
*
|
|
242
|
-
* @throws {AuthenticationError} On 401.
|
|
243
|
-
* @throws {ForbiddenError} On 403.
|
|
244
|
-
* @throws {NotFoundError} On 404.
|
|
245
|
-
* @throws {RateLimitError} On 429 after retries exhausted (no quota header).
|
|
246
|
-
* @throws {QuotaExceededError} On 429 with `X-Quota-Limit` header.
|
|
247
|
-
* @throws {LogoError} On 500, network error, or abort.
|
|
248
|
-
*/
|
|
249
|
-
declare function serverFetch(url: string, options: ServerFetcherOptions): Promise<Response>;
|
|
250
160
|
|
|
251
161
|
/**
|
|
252
162
|
* @quikturn/logos SDK — Server Client Class
|
|
@@ -291,7 +201,6 @@ interface ServerClientOptions {
|
|
|
291
201
|
* - `greyscale` — When true, returns a greyscale image.
|
|
292
202
|
* - `theme` — "light" or "dark" gamma adjustment.
|
|
293
203
|
* - `format` — Output image format (MIME type or shorthand).
|
|
294
|
-
* - `autoScrape` — When true, triggers background scrape if logo is not found.
|
|
295
204
|
* - `scrapeTimeout` — Maximum time (ms) to wait for a scrape to complete.
|
|
296
205
|
* - `onScrapeProgress`— Callback fired on each scrape poll.
|
|
297
206
|
* - `signal` — AbortSignal to cancel the request.
|
|
@@ -302,7 +211,6 @@ interface ServerGetOptions {
|
|
|
302
211
|
greyscale?: boolean;
|
|
303
212
|
theme?: ThemeOption;
|
|
304
213
|
format?: SupportedOutputFormat | FormatShorthand;
|
|
305
|
-
autoScrape?: boolean;
|
|
306
214
|
scrapeTimeout?: number;
|
|
307
215
|
onScrapeProgress?: (event: ScrapeProgressEvent) => void;
|
|
308
216
|
signal?: AbortSignal;
|
|
@@ -395,7 +303,7 @@ declare class QuikturnLogos {
|
|
|
395
303
|
* @param options - Optional request parameters (size, format, etc.).
|
|
396
304
|
* @returns A fully-qualified Logos API URL string (without token).
|
|
397
305
|
*/
|
|
398
|
-
getUrl(domain: string, options?: Omit<ServerGetOptions, "
|
|
306
|
+
getUrl(domain: string, options?: Omit<ServerGetOptions, "scrapeTimeout" | "onScrapeProgress" | "signal">): string;
|
|
399
307
|
/**
|
|
400
308
|
* Registers an event listener for a client event.
|
|
401
309
|
*
|
|
@@ -420,4 +328,4 @@ declare class QuikturnLogos {
|
|
|
420
328
|
private emit;
|
|
421
329
|
}
|
|
422
330
|
|
|
423
|
-
export { type BatchOptions, type BatchResult, type ClientEvent, type EventHandler, QuikturnLogos, type ServerClientOptions, type
|
|
331
|
+
export { type BatchOptions, type BatchResult, type ClientEvent, type EventHandler, QuikturnLogos, type ServerClientOptions, type ServerGetOptions };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -157,96 +157,6 @@ interface BatchResult {
|
|
|
157
157
|
metadata?: LogoMetadata;
|
|
158
158
|
error?: LogoError;
|
|
159
159
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Fetches logos for multiple domains with concurrency control.
|
|
162
|
-
* Yields results in the same order as the input domains array.
|
|
163
|
-
*
|
|
164
|
-
* The `fetchFn` parameter is a function that takes a domain and returns
|
|
165
|
-
* a result object with buffer, contentType, metadata. This decouples
|
|
166
|
-
* the batch module from the server fetcher implementation.
|
|
167
|
-
*
|
|
168
|
-
* Rate limit handling: when fetchFn throws a {@link RateLimitError},
|
|
169
|
-
* the batch pauses ALL pending work for `retryAfter` seconds before
|
|
170
|
-
* retrying the failed domain.
|
|
171
|
-
*
|
|
172
|
-
* @param domains - Array of domain strings to fetch logos for.
|
|
173
|
-
* @param fetchFn - Async function that fetches a single logo by domain.
|
|
174
|
-
* @param options - Optional batch configuration.
|
|
175
|
-
* @yields {BatchResult} Results in the same order as the input domains.
|
|
176
|
-
*/
|
|
177
|
-
declare function getMany(domains: string[], fetchFn: (domain: string) => Promise<{
|
|
178
|
-
buffer: Buffer;
|
|
179
|
-
contentType: string;
|
|
180
|
-
metadata: LogoMetadata;
|
|
181
|
-
}>, options?: BatchOptions): AsyncGenerator<BatchResult>;
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @quikturn/logos SDK — Server Fetch Wrapper
|
|
185
|
-
*
|
|
186
|
-
* Low-level fetch wrapper for the server entry point. Handles HTTP error
|
|
187
|
-
* mapping, retry logic for rate-limited and server-error responses,
|
|
188
|
-
* AbortSignal propagation, and proactive warning callbacks when rate-limit
|
|
189
|
-
* or quota headroom drops below 10%.
|
|
190
|
-
*
|
|
191
|
-
* Unlike the browser fetcher, this module sends the secret key as an
|
|
192
|
-
* `Authorization: Bearer` header — tokens are NEVER appended as query
|
|
193
|
-
* parameters.
|
|
194
|
-
*/
|
|
195
|
-
/**
|
|
196
|
-
* Options accepted by {@link serverFetch}.
|
|
197
|
-
*
|
|
198
|
-
* - `token` — Required: secret key (`sk_` prefix) sent as Bearer token.
|
|
199
|
-
* - `maxRetries` — Maximum number of retry attempts for 429/500 responses. Default: 2.
|
|
200
|
-
* - `signal` — An `AbortSignal` to cancel the in-flight request.
|
|
201
|
-
* - `format` — MIME type string used as the `Accept` request header.
|
|
202
|
-
* - `onRateLimitWarning` — Called when `X-RateLimit-Remaining` drops below 10% of the limit.
|
|
203
|
-
* - `onQuotaWarning` — Called when `X-Quota-Remaining` drops below 10% of the limit.
|
|
204
|
-
*/
|
|
205
|
-
interface ServerFetcherOptions {
|
|
206
|
-
token: string;
|
|
207
|
-
maxRetries?: number;
|
|
208
|
-
signal?: AbortSignal;
|
|
209
|
-
format?: string;
|
|
210
|
-
onRateLimitWarning?: (remaining: number, limit: number) => void;
|
|
211
|
-
onQuotaWarning?: (remaining: number, limit: number) => void;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Performs a fetch request to the Logos API with Bearer token authentication,
|
|
215
|
-
* error mapping, and retry logic.
|
|
216
|
-
*
|
|
217
|
-
* **Key difference from browser fetcher:**
|
|
218
|
-
* The secret key is sent as an `Authorization: Bearer {token}` header and is
|
|
219
|
-
* NEVER included in the URL query string.
|
|
220
|
-
*
|
|
221
|
-
* **Error mapping:**
|
|
222
|
-
* | Status | Error Class | Notes |
|
|
223
|
-
* |--------|-----------------------|--------------------------------------------|
|
|
224
|
-
* | 401 | AuthenticationError | Invalid or missing API token |
|
|
225
|
-
* | 403 | ForbiddenError | Body text used as `reason` |
|
|
226
|
-
* | 404 | NotFoundError | Domain extracted from URL path |
|
|
227
|
-
* | 429 | QuotaExceededError | When `X-Quota-Limit` header is present |
|
|
228
|
-
* | 429 | RateLimitError | After retries are exhausted |
|
|
229
|
-
* | 500 | LogoError | After a single retry attempt |
|
|
230
|
-
*
|
|
231
|
-
* **Retry behavior:**
|
|
232
|
-
* - 429: Waits `Retry-After` seconds (default 60s), retries up to `maxRetries`.
|
|
233
|
-
* If `X-Quota-Limit` is present, throws `QuotaExceededError` immediately.
|
|
234
|
-
* - 500: Retries once after a 1-second delay, then throws.
|
|
235
|
-
* - AbortError: Never retried; throws immediately.
|
|
236
|
-
* - Network errors: Never retried; throws immediately.
|
|
237
|
-
*
|
|
238
|
-
* @param url - Fully-qualified Logos API URL (built by `logoUrl`).
|
|
239
|
-
* @param options - Fetch configuration including the required `token`.
|
|
240
|
-
* @returns The raw `Response` object on success (2xx).
|
|
241
|
-
*
|
|
242
|
-
* @throws {AuthenticationError} On 401.
|
|
243
|
-
* @throws {ForbiddenError} On 403.
|
|
244
|
-
* @throws {NotFoundError} On 404.
|
|
245
|
-
* @throws {RateLimitError} On 429 after retries exhausted (no quota header).
|
|
246
|
-
* @throws {QuotaExceededError} On 429 with `X-Quota-Limit` header.
|
|
247
|
-
* @throws {LogoError} On 500, network error, or abort.
|
|
248
|
-
*/
|
|
249
|
-
declare function serverFetch(url: string, options: ServerFetcherOptions): Promise<Response>;
|
|
250
160
|
|
|
251
161
|
/**
|
|
252
162
|
* @quikturn/logos SDK — Server Client Class
|
|
@@ -291,7 +201,6 @@ interface ServerClientOptions {
|
|
|
291
201
|
* - `greyscale` — When true, returns a greyscale image.
|
|
292
202
|
* - `theme` — "light" or "dark" gamma adjustment.
|
|
293
203
|
* - `format` — Output image format (MIME type or shorthand).
|
|
294
|
-
* - `autoScrape` — When true, triggers background scrape if logo is not found.
|
|
295
204
|
* - `scrapeTimeout` — Maximum time (ms) to wait for a scrape to complete.
|
|
296
205
|
* - `onScrapeProgress`— Callback fired on each scrape poll.
|
|
297
206
|
* - `signal` — AbortSignal to cancel the request.
|
|
@@ -302,7 +211,6 @@ interface ServerGetOptions {
|
|
|
302
211
|
greyscale?: boolean;
|
|
303
212
|
theme?: ThemeOption;
|
|
304
213
|
format?: SupportedOutputFormat | FormatShorthand;
|
|
305
|
-
autoScrape?: boolean;
|
|
306
214
|
scrapeTimeout?: number;
|
|
307
215
|
onScrapeProgress?: (event: ScrapeProgressEvent) => void;
|
|
308
216
|
signal?: AbortSignal;
|
|
@@ -395,7 +303,7 @@ declare class QuikturnLogos {
|
|
|
395
303
|
* @param options - Optional request parameters (size, format, etc.).
|
|
396
304
|
* @returns A fully-qualified Logos API URL string (without token).
|
|
397
305
|
*/
|
|
398
|
-
getUrl(domain: string, options?: Omit<ServerGetOptions, "
|
|
306
|
+
getUrl(domain: string, options?: Omit<ServerGetOptions, "scrapeTimeout" | "onScrapeProgress" | "signal">): string;
|
|
399
307
|
/**
|
|
400
308
|
* Registers an event listener for a client event.
|
|
401
309
|
*
|
|
@@ -420,4 +328,4 @@ declare class QuikturnLogos {
|
|
|
420
328
|
private emit;
|
|
421
329
|
}
|
|
422
330
|
|
|
423
|
-
export { type BatchOptions, type BatchResult, type ClientEvent, type EventHandler, QuikturnLogos, type ServerClientOptions, type
|
|
331
|
+
export { type BatchOptions, type BatchResult, type ClientEvent, type EventHandler, QuikturnLogos, type ServerClientOptions, type ServerGetOptions };
|