stripe-loaders-core 0.1.0 → 0.3.0
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 +21 -0
- package/README.md +48 -2
- package/dist/index.cjs +407 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +227 -0
- package/dist/index.d.ts +149 -8
- package/dist/index.js +365 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -17
- package/dist/index.d.ts.map +0 -1
- package/dist/index.spec.d.ts +0 -2
- package/dist/index.spec.d.ts.map +0 -1
- package/dist/stripe-loaders-core.cjs +0 -2
- package/dist/stripe-loaders-core.cjs.map +0 -1
- package/dist/stripe-loaders-core.js +0 -133
- package/dist/stripe-loaders-core.js.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
// src/http.ts
|
|
2
|
+
var DEFAULT_RATE_LIMIT = Object.freeze({
|
|
3
|
+
requestDelayMs: 1e3,
|
|
4
|
+
requestJitterMs: 500,
|
|
5
|
+
maxRetries: 3,
|
|
6
|
+
backoffBaseMs: 1e3,
|
|
7
|
+
backoffMaxMs: 3e4
|
|
8
|
+
});
|
|
9
|
+
function resolveRateLimit(options) {
|
|
10
|
+
return { ...DEFAULT_RATE_LIMIT, ...options };
|
|
11
|
+
}
|
|
12
|
+
function delay(ms) {
|
|
13
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
14
|
+
}
|
|
15
|
+
function withJitter(baseMs, jitterMs, random = Math.random) {
|
|
16
|
+
const jitter = random() * jitterMs - jitterMs / 2;
|
|
17
|
+
return Math.max(0, Math.floor(baseMs + jitter));
|
|
18
|
+
}
|
|
19
|
+
async function delayWithJitter(baseMs, jitterMs, sleep = delay) {
|
|
20
|
+
const ms = withJitter(baseMs, jitterMs);
|
|
21
|
+
if (ms > 0) {
|
|
22
|
+
await sleep(ms);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function calculateExponentialBackoff(attempt, baseMs, maxMs) {
|
|
26
|
+
return Math.min(baseMs * Math.pow(2, attempt), maxMs);
|
|
27
|
+
}
|
|
28
|
+
function parseRetryAfter(value, now = Date.now()) {
|
|
29
|
+
if (!value) {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
const trimmed = value.trim();
|
|
33
|
+
if (/^\d+$/.test(trimmed)) {
|
|
34
|
+
const ms2 = Number(trimmed) * 1e3;
|
|
35
|
+
return ms2 > 0 ? ms2 : void 0;
|
|
36
|
+
}
|
|
37
|
+
const date = Date.parse(trimmed);
|
|
38
|
+
if (Number.isNaN(date)) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
const ms = date - now;
|
|
42
|
+
return ms > 0 ? ms : void 0;
|
|
43
|
+
}
|
|
44
|
+
function isRetryableStatus(status) {
|
|
45
|
+
return status === 429 || status >= 500;
|
|
46
|
+
}
|
|
47
|
+
async function fetchWithRetry(url, init, options = {}) {
|
|
48
|
+
const limits = resolveRateLimit(options.rateLimit);
|
|
49
|
+
const doFetch = options.fetch ?? ((input, reqInit) => fetch(input, reqInit));
|
|
50
|
+
const sleep = options.sleep ?? delay;
|
|
51
|
+
for (let attempt = 0; ; attempt++) {
|
|
52
|
+
let response;
|
|
53
|
+
try {
|
|
54
|
+
response = await doFetch(url, init);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (attempt >= limits.maxRetries) {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
const waitMs2 = calculateExponentialBackoff(
|
|
60
|
+
attempt,
|
|
61
|
+
limits.backoffBaseMs,
|
|
62
|
+
limits.backoffMaxMs
|
|
63
|
+
);
|
|
64
|
+
options.onRetry?.({ url, attempt: attempt + 1, waitMs: waitMs2, reason: String(error) });
|
|
65
|
+
await delayWithJitter(waitMs2, limits.requestJitterMs, sleep);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!isRetryableStatus(response.status) || attempt >= limits.maxRetries) {
|
|
69
|
+
return response;
|
|
70
|
+
}
|
|
71
|
+
const retryAfter = parseRetryAfter(response.headers?.get?.("Retry-After"));
|
|
72
|
+
const waitMs = Math.min(
|
|
73
|
+
retryAfter ?? calculateExponentialBackoff(attempt, limits.backoffBaseMs, limits.backoffMaxMs),
|
|
74
|
+
limits.backoffMaxMs
|
|
75
|
+
);
|
|
76
|
+
options.onRetry?.({ url, attempt: attempt + 1, waitMs, reason: `HTTP ${response.status}` });
|
|
77
|
+
await delayWithJitter(waitMs, limits.requestJitterMs, sleep);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
var RequestPacer = class {
|
|
81
|
+
constructor(limits, sleep = delay) {
|
|
82
|
+
this.limits = limits;
|
|
83
|
+
this.sleep = sleep;
|
|
84
|
+
this.started = false;
|
|
85
|
+
}
|
|
86
|
+
async wait() {
|
|
87
|
+
if (this.started) {
|
|
88
|
+
await delayWithJitter(this.limits.requestDelayMs, this.limits.requestJitterMs, this.sleep);
|
|
89
|
+
}
|
|
90
|
+
this.started = true;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/changelog.ts
|
|
95
|
+
var STRIPE_CHANGELOG_URL = "https://docs.stripe.com/changelog.md";
|
|
96
|
+
var HEADING = /^(#{1,3})\s+(.+)$/;
|
|
97
|
+
function absoluteLink(link, baseUrl) {
|
|
98
|
+
try {
|
|
99
|
+
return new URL(link, baseUrl).toString();
|
|
100
|
+
} catch {
|
|
101
|
+
return link;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function parseStripeChangelog(markdown, baseUrl = "https://docs.stripe.com/") {
|
|
105
|
+
const lines = markdown.split(/\r\n?|\n/);
|
|
106
|
+
const titleIndex = lines.findIndex((line) => line.match(HEADING)?.[1] === "#");
|
|
107
|
+
const versions = [];
|
|
108
|
+
let release;
|
|
109
|
+
let current;
|
|
110
|
+
let category;
|
|
111
|
+
for (const [index, line] of lines.entries()) {
|
|
112
|
+
const heading = line.match(HEADING);
|
|
113
|
+
if (heading) {
|
|
114
|
+
const [, level, text] = heading;
|
|
115
|
+
const name = text.trim();
|
|
116
|
+
if (level === "###") {
|
|
117
|
+
category = name;
|
|
118
|
+
} else if (level === "##") {
|
|
119
|
+
const date = name.match(/^\d{4}-\d{2}-\d{2}/)?.[0] ?? "";
|
|
120
|
+
current = { release, version: name, date, entries: [] };
|
|
121
|
+
versions.push(current);
|
|
122
|
+
category = void 0;
|
|
123
|
+
} else if (index !== titleIndex) {
|
|
124
|
+
release = name;
|
|
125
|
+
current = void 0;
|
|
126
|
+
}
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const row = line.trim();
|
|
130
|
+
if (!current || !row.startsWith("|") || !row.endsWith("|")) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const cells = row.slice(1, -1).split(/(?<!\\)\|/).map((cell) => cell.trim());
|
|
134
|
+
const isHeader = cells[0].toLowerCase() === "title";
|
|
135
|
+
const isSeparator = cells.every((cell) => /^:?-+:?$/.test(cell));
|
|
136
|
+
if (cells.length < 3 || isHeader || isSeparator) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const [titleCell, productsCell, breakingCell, typeCell] = cells;
|
|
140
|
+
const linkMatch = titleCell.match(/\[([^\]]+)\]\(([^)]+)\)/);
|
|
141
|
+
const title = (linkMatch ? linkMatch[1] : titleCell).trim().replace(/\\\|/g, "|");
|
|
142
|
+
if (!title) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const link = linkMatch ? linkMatch[2].trim() : "";
|
|
146
|
+
current.entries.push({
|
|
147
|
+
release: current.release,
|
|
148
|
+
version: current.version,
|
|
149
|
+
date: current.date,
|
|
150
|
+
category,
|
|
151
|
+
title,
|
|
152
|
+
link: link ? absoluteLink(link, baseUrl) : "",
|
|
153
|
+
affectedProducts: productsCell.split(",").map((product) => product.trim()).filter((product) => product.length > 0),
|
|
154
|
+
isBreakingChange: breakingCell.toLowerCase().replace(/\s+/g, "") === "breaking",
|
|
155
|
+
changeType: typeCell || void 0
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return versions.filter((version) => version.entries.length > 0);
|
|
159
|
+
}
|
|
160
|
+
function stripeChangelogUrl(options = {}) {
|
|
161
|
+
const url = new URL(options.url ?? STRIPE_CHANGELOG_URL);
|
|
162
|
+
if (options.locale) {
|
|
163
|
+
url.searchParams.set("locale", options.locale);
|
|
164
|
+
}
|
|
165
|
+
return url.toString();
|
|
166
|
+
}
|
|
167
|
+
async function fetchStripeChangelog(options = {}) {
|
|
168
|
+
const url = stripeChangelogUrl(options);
|
|
169
|
+
const response = await fetchWithRetry(url, void 0, {
|
|
170
|
+
rateLimit: options.rateLimit,
|
|
171
|
+
fetch: options.fetch,
|
|
172
|
+
sleep: options.sleep
|
|
173
|
+
});
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
throw new Error(`Failed to fetch Stripe changelog: ${response.status} ${response.statusText}`);
|
|
176
|
+
}
|
|
177
|
+
return parseStripeChangelog(await response.text(), url);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/index.ts
|
|
181
|
+
function escapeRegExp(value) {
|
|
182
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
183
|
+
}
|
|
184
|
+
var ConsoleLogger = class {
|
|
185
|
+
constructor(debug = false) {
|
|
186
|
+
this.debug = debug;
|
|
187
|
+
}
|
|
188
|
+
log(message) {
|
|
189
|
+
if (this.debug) {
|
|
190
|
+
console.log(message);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
error(message) {
|
|
194
|
+
console.error(message);
|
|
195
|
+
}
|
|
196
|
+
warn(message) {
|
|
197
|
+
if (this.debug) {
|
|
198
|
+
console.warn(message);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var SitemapProcessor = class {
|
|
203
|
+
/**
|
|
204
|
+
* Constructor for SitemapProcessor
|
|
205
|
+
* @param options Configuration options
|
|
206
|
+
*/
|
|
207
|
+
constructor(options = {}) {
|
|
208
|
+
this.debug = options.debug ?? false;
|
|
209
|
+
this.logger = options.logger ?? new ConsoleLogger(this.debug);
|
|
210
|
+
this.rateLimit = resolveRateLimit(options.rateLimit);
|
|
211
|
+
this.fetchImpl = options.fetch;
|
|
212
|
+
this.sleep = options.sleep;
|
|
213
|
+
}
|
|
214
|
+
fetchUrl(url) {
|
|
215
|
+
return fetchWithRetry(url, void 0, {
|
|
216
|
+
rateLimit: this.rateLimit,
|
|
217
|
+
fetch: this.fetchImpl,
|
|
218
|
+
sleep: this.sleep,
|
|
219
|
+
onRetry: ({ attempt, waitMs, reason }) => this.logWarning(`Retrying ${url} (attempt ${attempt}, ${reason}) in ${waitMs}ms`)
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Log a message if debug mode is enabled
|
|
224
|
+
* @param message Message to log
|
|
225
|
+
*/
|
|
226
|
+
log(message) {
|
|
227
|
+
this.logger.log(message);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Log an error message
|
|
231
|
+
* @param message Error message to log
|
|
232
|
+
*/
|
|
233
|
+
logError(message) {
|
|
234
|
+
this.logger.error(message);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Log a warning message
|
|
238
|
+
* @param message Warning message to log
|
|
239
|
+
*/
|
|
240
|
+
logWarning(message) {
|
|
241
|
+
this.logger.warn(message);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Extract URLs from a sitemap
|
|
245
|
+
* @param content Sitemap XML content
|
|
246
|
+
* @param baseUrl Base URL part to extract (e.g., https://docs.stripe.com/)
|
|
247
|
+
* @returns Array of extracted URLs
|
|
248
|
+
*/
|
|
249
|
+
extractUrlsFromSitemap(content, baseUrl = "https://docs.stripe.com/") {
|
|
250
|
+
const urlRegex = new RegExp(`<loc>(${escapeRegExp(baseUrl)}[^<]+)</loc>`, "g");
|
|
251
|
+
const urls = [];
|
|
252
|
+
let match;
|
|
253
|
+
while ((match = urlRegex.exec(content)) !== null) {
|
|
254
|
+
urls.push(match[1]);
|
|
255
|
+
}
|
|
256
|
+
return urls;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Extract sitemap URLs from a sitemap index
|
|
260
|
+
* @param content Sitemap index XML content
|
|
261
|
+
* @returns Array of extracted sitemap URLs
|
|
262
|
+
*/
|
|
263
|
+
extractSitemapUrlsFromIndex(content) {
|
|
264
|
+
if (!content || typeof content !== "string") {
|
|
265
|
+
this.logError("Invalid input: content must be a string");
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
if (!content.includes("<?xml") || !content.includes("<sitemapindex")) {
|
|
269
|
+
this.logError("Invalid sitemap index XML: Missing <?xml or <sitemapindex> elements.");
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const sitemapRegex = /<loc>([^<]+)<\/loc>/g;
|
|
274
|
+
const sitemapUrls = [];
|
|
275
|
+
let match;
|
|
276
|
+
while ((match = sitemapRegex.exec(content)) !== null) {
|
|
277
|
+
const url = match[1];
|
|
278
|
+
try {
|
|
279
|
+
new URL(url);
|
|
280
|
+
sitemapUrls.push(url);
|
|
281
|
+
} catch (urlError) {
|
|
282
|
+
this.logWarning(`Skipped invalid URL format: ${url}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (sitemapUrls.length === 0) {
|
|
286
|
+
this.logWarning("No valid URLs found in sitemap index");
|
|
287
|
+
}
|
|
288
|
+
return sitemapUrls;
|
|
289
|
+
} catch (error) {
|
|
290
|
+
this.logError(`Error extracting URLs from sitemap index: ${error}`);
|
|
291
|
+
return [];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Find newly added URLs
|
|
296
|
+
* @param currentUrls Current URL list
|
|
297
|
+
* @param previousUrls Previous URL list
|
|
298
|
+
* @returns Array of newly added URLs
|
|
299
|
+
*/
|
|
300
|
+
findNewUrls(currentUrls, previousUrls) {
|
|
301
|
+
const previousUrlSet = new Set(previousUrls);
|
|
302
|
+
return currentUrls.filter((url) => !previousUrlSet.has(url));
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Fetch and process a sitemap
|
|
306
|
+
* @param url Sitemap URL
|
|
307
|
+
* @param baseUrl Base URL part to extract
|
|
308
|
+
* @returns List of retrieved URLs
|
|
309
|
+
*/
|
|
310
|
+
async fetchAndProcessSitemap(url, baseUrl) {
|
|
311
|
+
const response = await this.fetchUrl(url);
|
|
312
|
+
if (!response.ok) {
|
|
313
|
+
throw new Error(`Failed to fetch sitemap: ${response.status} ${response.statusText}`);
|
|
314
|
+
}
|
|
315
|
+
const sitemapContent = await response.text();
|
|
316
|
+
return this.extractUrlsFromSitemap(sitemapContent, baseUrl);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Fetch and process a sitemap index
|
|
320
|
+
* @param indexUrl Sitemap index URL
|
|
321
|
+
* @param baseUrl Base URL part to extract
|
|
322
|
+
* @returns List of retrieved URLs
|
|
323
|
+
*/
|
|
324
|
+
async fetchAndProcessSitemapIndex(indexUrl, baseUrl) {
|
|
325
|
+
this.log(`Fetching sitemap index: ${indexUrl}`);
|
|
326
|
+
const pacer = new RequestPacer(this.rateLimit, this.sleep);
|
|
327
|
+
await pacer.wait();
|
|
328
|
+
const response = await this.fetchUrl(indexUrl);
|
|
329
|
+
if (!response.ok) {
|
|
330
|
+
throw new Error(`Failed to fetch sitemap index: ${response.status} ${response.statusText}`);
|
|
331
|
+
}
|
|
332
|
+
const indexContent = await response.text();
|
|
333
|
+
const sitemapUrls = this.extractSitemapUrlsFromIndex(indexContent);
|
|
334
|
+
this.log(`Number of sitemap partitions: ${sitemapUrls.length}`);
|
|
335
|
+
const allUrls = [];
|
|
336
|
+
for (let i = 0; i < sitemapUrls.length; i++) {
|
|
337
|
+
const sitemapUrl = sitemapUrls[i];
|
|
338
|
+
this.log(`Processing partition ${i + 1}/${sitemapUrls.length}: ${sitemapUrl}`);
|
|
339
|
+
await pacer.wait();
|
|
340
|
+
const urls = await this.fetchAndProcessSitemap(sitemapUrl, baseUrl);
|
|
341
|
+
this.log(`Retrieved ${urls.length} URLs from partition ${i + 1}`);
|
|
342
|
+
allUrls.push(...urls);
|
|
343
|
+
}
|
|
344
|
+
return allUrls;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
export {
|
|
348
|
+
ConsoleLogger,
|
|
349
|
+
DEFAULT_RATE_LIMIT,
|
|
350
|
+
RequestPacer,
|
|
351
|
+
STRIPE_CHANGELOG_URL,
|
|
352
|
+
SitemapProcessor,
|
|
353
|
+
calculateExponentialBackoff,
|
|
354
|
+
delay,
|
|
355
|
+
delayWithJitter,
|
|
356
|
+
escapeRegExp,
|
|
357
|
+
fetchStripeChangelog,
|
|
358
|
+
fetchWithRetry,
|
|
359
|
+
parseRetryAfter,
|
|
360
|
+
parseStripeChangelog,
|
|
361
|
+
resolveRateLimit,
|
|
362
|
+
stripeChangelogUrl,
|
|
363
|
+
withJitter
|
|
364
|
+
};
|
|
365
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/http.ts","../src/changelog.ts","../src/index.ts"],"sourcesContent":["/**\n * Rate limiting and retry helpers for fetching Stripe sites.\n *\n * Requests are sent one at a time with a delay between them, and HTTP 429 / 5xx\n * responses are retried with exponential backoff (honouring `Retry-After`).\n * The defaults follow the conservative access policy used by\n * hideokamoto/stripe-docs-updates for docs.stripe.com and stripe.com.\n */\n\nexport interface RateLimitOptions {\n /** Delay between consecutive requests in milliseconds. */\n requestDelayMs: number;\n /** Random variation (±half of this value) added to each delay in milliseconds. */\n requestJitterMs: number;\n /** Number of retries after the first attempt for 429 / 5xx responses and network errors. */\n maxRetries: number;\n /** Base delay for exponential backoff in milliseconds. */\n backoffBaseMs: number;\n /** Upper bound for a single backoff delay in milliseconds. */\n backoffMaxMs: number;\n}\n\nexport const DEFAULT_RATE_LIMIT: Readonly<RateLimitOptions> = Object.freeze({\n requestDelayMs: 1000,\n requestJitterMs: 500,\n maxRetries: 3,\n backoffBaseMs: 1000,\n backoffMaxMs: 30000,\n});\n\nexport type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;\nexport type SleepFn = (ms: number) => Promise<void>;\n\nexport function resolveRateLimit(options?: Partial<RateLimitOptions>): RateLimitOptions {\n return { ...DEFAULT_RATE_LIMIT, ...options };\n}\n\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nexport function withJitter(baseMs: number, jitterMs: number, random: () => number = Math.random) {\n const jitter = random() * jitterMs - jitterMs / 2;\n return Math.max(0, Math.floor(baseMs + jitter));\n}\n\nexport async function delayWithJitter(\n baseMs: number,\n jitterMs: number,\n sleep: SleepFn = delay\n): Promise<void> {\n const ms = withJitter(baseMs, jitterMs);\n if (ms > 0) {\n await sleep(ms);\n }\n}\n\nexport function calculateExponentialBackoff(attempt: number, baseMs: number, maxMs: number) {\n return Math.min(baseMs * Math.pow(2, attempt), maxMs);\n}\n\n/**\n * Parse a `Retry-After` header (seconds or HTTP date) into milliseconds.\n * Returns undefined when the header is missing, invalid, or not in the future.\n */\nexport function parseRetryAfter(value: string | null | undefined, now: number = Date.now()) {\n if (!value) {\n return undefined;\n }\n const trimmed = value.trim();\n if (/^\\d+$/.test(trimmed)) {\n const ms = Number(trimmed) * 1000;\n return ms > 0 ? ms : undefined;\n }\n const date = Date.parse(trimmed);\n if (Number.isNaN(date)) {\n return undefined;\n }\n const ms = date - now;\n return ms > 0 ? ms : undefined;\n}\n\nfunction isRetryableStatus(status: number): boolean {\n return status === 429 || status >= 500;\n}\n\nexport interface FetchWithRetryOptions {\n rateLimit?: Partial<RateLimitOptions>;\n fetch?: FetchLike;\n sleep?: SleepFn;\n /** Called before each retry; useful for logging. */\n onRetry?: (info: { url: string; attempt: number; waitMs: number; reason: string }) => void;\n}\n\n/**\n * Fetch a URL, retrying 429 / 5xx responses and network errors.\n *\n * The final response is returned as-is, including non-2xx responses, so the\n * caller decides how to treat 404 and similar statuses. A network error is\n * rethrown after the last retry.\n */\nexport async function fetchWithRetry(\n url: string,\n init?: RequestInit,\n options: FetchWithRetryOptions = {}\n): Promise<Response> {\n const limits = resolveRateLimit(options.rateLimit);\n const doFetch: FetchLike = options.fetch ?? ((input, reqInit) => fetch(input, reqInit));\n const sleep = options.sleep ?? delay;\n\n for (let attempt = 0; ; attempt++) {\n let response: Response;\n try {\n response = await doFetch(url, init);\n } catch (error) {\n if (attempt >= limits.maxRetries) {\n throw error;\n }\n const waitMs = calculateExponentialBackoff(\n attempt,\n limits.backoffBaseMs,\n limits.backoffMaxMs\n );\n options.onRetry?.({ url, attempt: attempt + 1, waitMs, reason: String(error) });\n await delayWithJitter(waitMs, limits.requestJitterMs, sleep);\n continue;\n }\n\n if (!isRetryableStatus(response.status) || attempt >= limits.maxRetries) {\n return response;\n }\n\n const retryAfter = parseRetryAfter(response.headers?.get?.('Retry-After'));\n const waitMs = Math.min(\n retryAfter ?? calculateExponentialBackoff(attempt, limits.backoffBaseMs, limits.backoffMaxMs),\n limits.backoffMaxMs\n );\n options.onRetry?.({ url, attempt: attempt + 1, waitMs, reason: `HTTP ${response.status}` });\n await delayWithJitter(waitMs, limits.requestJitterMs, sleep);\n }\n}\n\n/**\n * Sequential request pacer: waits `requestDelayMs` (± jitter) before every\n * request except the first one.\n */\nexport class RequestPacer {\n private started = false;\n\n constructor(\n private readonly limits: RateLimitOptions,\n private readonly sleep: SleepFn = delay\n ) {}\n\n async wait(): Promise<void> {\n if (this.started) {\n await delayWithJitter(this.limits.requestDelayMs, this.limits.requestJitterMs, this.sleep);\n }\n this.started = true;\n }\n}\n","/**\n * Parser and fetcher for the Stripe API changelog (https://docs.stripe.com/changelog.md).\n *\n * The Markdown is organised as:\n * # <release> (e.g. `# Endive`, or a year such as `# 2024` for older entries)\n * ## <version> (e.g. `## 2026-11-18.endive`, `## 2026-11-18.preview`, `## 2011-06-21`)\n * ### <category> (e.g. `### Payments`; localised when `?locale=` is set)\n * | Title | Affected Products | Breaking change? | Category |\n * | [title](url) | Connect, Payments | Breaking / Non-breaking | api |\n */\n\nimport { fetchWithRetry, type FetchLike, type RateLimitOptions, type SleepFn } from './http';\n\nexport const STRIPE_CHANGELOG_URL = 'https://docs.stripe.com/changelog.md';\n\nexport interface StripeChangelogEntry {\n /** Release the version belongs to (e.g. `Endive`, or `2024` for year-grouped entries). */\n release?: string;\n /** Version heading as written (e.g. `2026-11-18.endive`). */\n version: string;\n /** `YYYY-MM-DD` taken from the version, or an empty string when the version has no date. */\n date: string;\n /** Section heading inside the version (e.g. `Payments`). */\n category?: string;\n title: string;\n /** Absolute URL of the entry's detail page (Markdown), or an empty string when the row has no link. */\n link: string;\n affectedProducts: string[];\n isBreakingChange: boolean;\n /** Value of the `Category` column (e.g. `api`, `stripejs`). */\n changeType?: string;\n}\n\nexport interface StripeChangelogVersion {\n release?: string;\n version: string;\n date: string;\n entries: StripeChangelogEntry[];\n}\n\nconst HEADING = /^(#{1,3})\\s+(.+)$/;\n\nfunction absoluteLink(link: string, baseUrl: string): string {\n try {\n return new URL(link, baseUrl).toString();\n } catch {\n return link;\n }\n}\n\n/**\n * Parse the changelog Markdown into versions, newest first (the order of the document).\n * Versions without any entries are omitted.\n *\n * @param markdown Changelog Markdown\n * @param baseUrl Base used to resolve relative links (defaults to https://docs.stripe.com/)\n */\nexport function parseStripeChangelog(\n markdown: string,\n baseUrl: string = 'https://docs.stripe.com/'\n): StripeChangelogVersion[] {\n const lines = markdown.split(/\\r\\n?|\\n/);\n // The first level-1 heading is the document title (\"Changelog\" / \"変更ログ\").\n const titleIndex = lines.findIndex(line => line.match(HEADING)?.[1] === '#');\n const versions: StripeChangelogVersion[] = [];\n let release: string | undefined;\n let current: StripeChangelogVersion | undefined;\n let category: string | undefined;\n\n for (const [index, line] of lines.entries()) {\n const heading = line.match(HEADING);\n if (heading) {\n const [, level, text] = heading;\n const name = text.trim();\n if (level === '###') {\n category = name;\n } else if (level === '##') {\n const date = name.match(/^\\d{4}-\\d{2}-\\d{2}/)?.[0] ?? '';\n current = { release, version: name, date, entries: [] };\n versions.push(current);\n category = undefined;\n } else if (index !== titleIndex) {\n release = name;\n current = undefined;\n }\n continue;\n }\n\n const row = line.trim();\n if (!current || !row.startsWith('|') || !row.endsWith('|')) {\n continue;\n }\n const cells = row\n .slice(1, -1)\n .split(/(?<!\\\\)\\|/)\n .map(cell => cell.trim());\n const isHeader = cells[0].toLowerCase() === 'title';\n const isSeparator = cells.every(cell => /^:?-+:?$/.test(cell));\n if (cells.length < 3 || isHeader || isSeparator) {\n continue;\n }\n\n const [titleCell, productsCell, breakingCell, typeCell] = cells;\n const linkMatch = titleCell.match(/\\[([^\\]]+)\\]\\(([^)]+)\\)/);\n const title = (linkMatch ? linkMatch[1] : titleCell).trim().replace(/\\\\\\|/g, '|');\n if (!title) {\n continue;\n }\n const link = linkMatch ? linkMatch[2].trim() : '';\n current.entries.push({\n release: current.release,\n version: current.version,\n date: current.date,\n category,\n title,\n link: link ? absoluteLink(link, baseUrl) : '',\n affectedProducts: productsCell\n .split(',')\n .map(product => product.trim())\n .filter(product => product.length > 0),\n isBreakingChange: breakingCell.toLowerCase().replace(/\\s+/g, '') === 'breaking',\n changeType: typeCell || undefined,\n });\n }\n\n return versions.filter(version => version.entries.length > 0);\n}\n\nexport interface FetchStripeChangelogOptions {\n /** Locale for the changelog (e.g. `ja-JP`). Omitted: the default (English) changelog. */\n locale?: string;\n /** Changelog URL. Defaults to https://docs.stripe.com/changelog.md */\n url?: string;\n rateLimit?: Partial<RateLimitOptions>;\n fetch?: FetchLike;\n sleep?: SleepFn;\n}\n\nexport function stripeChangelogUrl(\n options: Pick<FetchStripeChangelogOptions, 'locale' | 'url'> = {}\n): string {\n const url = new URL(options.url ?? STRIPE_CHANGELOG_URL);\n if (options.locale) {\n url.searchParams.set('locale', options.locale);\n }\n return url.toString();\n}\n\n/**\n * Fetch and parse the Stripe API changelog (one request, retried on 429 / 5xx).\n * Throws when the final response is not 2xx.\n */\nexport async function fetchStripeChangelog(\n options: FetchStripeChangelogOptions = {}\n): Promise<StripeChangelogVersion[]> {\n const url = stripeChangelogUrl(options);\n const response = await fetchWithRetry(url, undefined, {\n rateLimit: options.rateLimit,\n fetch: options.fetch,\n sleep: options.sleep,\n });\n if (!response.ok) {\n throw new Error(`Failed to fetch Stripe changelog: ${response.status} ${response.statusText}`);\n }\n return parseStripeChangelog(await response.text(), url);\n}\n","/**\n * Utility functions for processing Stripe docs sitemaps\n */\n\nimport {\n fetchWithRetry,\n resolveRateLimit,\n RequestPacer,\n type FetchLike,\n type RateLimitOptions,\n type SleepFn,\n} from './http';\n\nexport * from './http';\nexport * from './changelog';\n\n/**\n * Escape a string so it can be embedded in a regular expression literally.\n */\nexport function escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport interface SitemapProcessorOptions {\n debug?: boolean;\n logger?: Logger;\n /** Rate limiting and retry settings for sitemap requests. */\n rateLimit?: Partial<RateLimitOptions>;\n /** Custom fetch implementation (defaults to the global fetch). */\n fetch?: FetchLike;\n /** Custom sleep implementation, mainly for tests. */\n sleep?: SleepFn;\n}\n\n/**\n * Logger interface for SitemapProcessor\n */\nexport interface Logger {\n log(message: string): void;\n error(message: string): void;\n warn(message: string): void;\n}\n\n/**\n * Default console logger implementation\n */\nexport class ConsoleLogger implements Logger {\n constructor(private debug: boolean = false) {}\n\n log(message: string): void {\n if (this.debug) {\n console.log(message);\n }\n }\n\n error(message: string): void {\n console.error(message);\n }\n\n warn(message: string): void {\n if (this.debug) {\n console.warn(message);\n }\n }\n}\n\n/**\n * Utility class for processing Stripe docs sitemaps\n */\nexport class SitemapProcessor {\n private debug: boolean;\n private logger: Logger;\n private rateLimit: RateLimitOptions;\n private fetchImpl?: FetchLike;\n private sleep?: SleepFn;\n\n /**\n * Constructor for SitemapProcessor\n * @param options Configuration options\n */\n constructor(options: SitemapProcessorOptions = {}) {\n this.debug = options.debug ?? false;\n this.logger = options.logger ?? new ConsoleLogger(this.debug);\n this.rateLimit = resolveRateLimit(options.rateLimit);\n this.fetchImpl = options.fetch;\n this.sleep = options.sleep;\n }\n\n private fetchUrl(url: string): Promise<Response> {\n return fetchWithRetry(url, undefined, {\n rateLimit: this.rateLimit,\n fetch: this.fetchImpl,\n sleep: this.sleep,\n onRetry: ({ attempt, waitMs, reason }) =>\n this.logWarning(`Retrying ${url} (attempt ${attempt}, ${reason}) in ${waitMs}ms`),\n });\n }\n\n /**\n * Log a message if debug mode is enabled\n * @param message Message to log\n */\n private log(message: string): void {\n this.logger.log(message);\n }\n\n /**\n * Log an error message\n * @param message Error message to log\n */\n private logError(message: string): void {\n this.logger.error(message);\n }\n\n /**\n * Log a warning message\n * @param message Warning message to log\n */\n private logWarning(message: string): void {\n this.logger.warn(message);\n }\n\n /**\n * Extract URLs from a sitemap\n * @param content Sitemap XML content\n * @param baseUrl Base URL part to extract (e.g., https://docs.stripe.com/)\n * @returns Array of extracted URLs\n */\n public extractUrlsFromSitemap(\n content: string,\n baseUrl: string = 'https://docs.stripe.com/'\n ): string[] {\n const urlRegex = new RegExp(`<loc>(${escapeRegExp(baseUrl)}[^<]+)<\\/loc>`, 'g');\n const urls: string[] = [];\n let match;\n\n while ((match = urlRegex.exec(content)) !== null) {\n urls.push(match[1]);\n }\n\n return urls;\n }\n\n /**\n * Extract sitemap URLs from a sitemap index\n * @param content Sitemap index XML content\n * @returns Array of extracted sitemap URLs\n */\n public extractSitemapUrlsFromIndex(content: string): string[] {\n // Input validation\n if (!content || typeof content !== 'string') {\n this.logError('Invalid input: content must be a string');\n return [];\n }\n\n // Basic XML structure validation\n if (!content.includes('<?xml') || !content.includes('<sitemapindex')) {\n this.logError('Invalid sitemap index XML: Missing <?xml or <sitemapindex> elements.');\n return [];\n }\n\n try {\n const sitemapRegex = /<loc>([^<]+)<\\/loc>/g;\n const sitemapUrls: string[] = [];\n let match;\n\n while ((match = sitemapRegex.exec(content)) !== null) {\n // URL validation (optional)\n const url = match[1];\n try {\n new URL(url); // Check if URL is valid\n sitemapUrls.push(url);\n } catch (urlError) {\n this.logWarning(`Skipped invalid URL format: ${url}`);\n // Skip invalid URLs\n }\n }\n\n if (sitemapUrls.length === 0) {\n this.logWarning('No valid URLs found in sitemap index');\n }\n\n return sitemapUrls;\n } catch (error) {\n this.logError(`Error extracting URLs from sitemap index: ${error}`);\n return []; // Return empty array on error\n }\n }\n\n /**\n * Find newly added URLs\n * @param currentUrls Current URL list\n * @param previousUrls Previous URL list\n * @returns Array of newly added URLs\n */\n public findNewUrls(currentUrls: string[], previousUrls: string[]): string[] {\n const previousUrlSet = new Set(previousUrls);\n return currentUrls.filter(url => !previousUrlSet.has(url));\n }\n\n /**\n * Fetch and process a sitemap\n * @param url Sitemap URL\n * @param baseUrl Base URL part to extract\n * @returns List of retrieved URLs\n */\n public async fetchAndProcessSitemap(url: string, baseUrl?: string): Promise<string[]> {\n const response = await this.fetchUrl(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch sitemap: ${response.status} ${response.statusText}`);\n }\n\n const sitemapContent = await response.text();\n return this.extractUrlsFromSitemap(sitemapContent, baseUrl);\n }\n\n /**\n * Fetch and process a sitemap index\n * @param indexUrl Sitemap index URL\n * @param baseUrl Base URL part to extract\n * @returns List of retrieved URLs\n */\n public async fetchAndProcessSitemapIndex(indexUrl: string, baseUrl?: string): Promise<string[]> {\n this.log(`Fetching sitemap index: ${indexUrl}`);\n const pacer = new RequestPacer(this.rateLimit, this.sleep);\n await pacer.wait();\n const response = await this.fetchUrl(indexUrl);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch sitemap index: ${response.status} ${response.statusText}`);\n }\n\n const indexContent = await response.text();\n const sitemapUrls = this.extractSitemapUrlsFromIndex(indexContent);\n this.log(`Number of sitemap partitions: ${sitemapUrls.length}`);\n\n // Combine URLs from each sitemap file\n const allUrls: string[] = [];\n\n for (let i = 0; i < sitemapUrls.length; i++) {\n const sitemapUrl = sitemapUrls[i];\n this.log(`Processing partition ${i + 1}/${sitemapUrls.length}: ${sitemapUrl}`);\n await pacer.wait();\n const urls = await this.fetchAndProcessSitemap(sitemapUrl, baseUrl);\n this.log(`Retrieved ${urls.length} URLs from partition ${i + 1}`);\n allUrls.push(...urls);\n }\n\n return allUrls;\n }\n}\n"],"mappings":";AAsBO,IAAM,qBAAiD,OAAO,OAAO;AAAA,EAC1E,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,cAAc;AAChB,CAAC;AAKM,SAAS,iBAAiB,SAAuD;AACtF,SAAO,EAAE,GAAG,oBAAoB,GAAG,QAAQ;AAC7C;AAEO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW,WAAW,SAAS,EAAE,CAAC;AACvD;AAEO,SAAS,WAAW,QAAgB,UAAkB,SAAuB,KAAK,QAAQ;AAC/F,QAAM,SAAS,OAAO,IAAI,WAAW,WAAW;AAChD,SAAO,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,MAAM,CAAC;AAChD;AAEA,eAAsB,gBACpB,QACA,UACA,QAAiB,OACF;AACf,QAAM,KAAK,WAAW,QAAQ,QAAQ;AACtC,MAAI,KAAK,GAAG;AACV,UAAM,MAAM,EAAE;AAAA,EAChB;AACF;AAEO,SAAS,4BAA4B,SAAiB,QAAgB,OAAe;AAC1F,SAAO,KAAK,IAAI,SAAS,KAAK,IAAI,GAAG,OAAO,GAAG,KAAK;AACtD;AAMO,SAAS,gBAAgB,OAAkC,MAAc,KAAK,IAAI,GAAG;AAC1F,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,QAAQ,KAAK,OAAO,GAAG;AACzB,UAAMA,MAAK,OAAO,OAAO,IAAI;AAC7B,WAAOA,MAAK,IAA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,IAAI,iCAAiC,YAAY,MAAM,EAAE;AAG9D,UAAM,UAAoB,CAAC;AAE3B,aAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;AAC3C,YAAM,aAAa,YAAY,CAAC;AAChC,WAAK,IAAI,wBAAwB,IAAI,CAAC,IAAI,YAAY,MAAM,KAAK,UAAU,EAAE;AAC7E,YAAM,MAAM,KAAK;AACjB,YAAM,OAAO,MAAM,KAAK,uBAAuB,YAAY,OAAO;AAClE,WAAK,IAAI,aAAa,KAAK,MAAM,wBAAwB,IAAI,CAAC,EAAE;AAChE,cAAQ,KAAK,GAAG,IAAI;AAAA,IACtB;AAEA,WAAO;AAAA,EACT;AACF;","names":["ms","waitMs"]}
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stripe-loaders-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./dist/
|
|
6
|
-
"module": "./dist/
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
14
20
|
},
|
|
15
21
|
"files": [
|
|
16
22
|
"dist"
|
|
17
23
|
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"dev": "vite build --watch",
|
|
20
|
-
"build": "vite build && tsc --emitDeclarationOnly",
|
|
21
|
-
"test": "vitest run",
|
|
22
|
-
"prepublishOnly": "npm run build"
|
|
23
|
-
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"stripe",
|
|
26
26
|
"documentation",
|
|
@@ -33,14 +33,23 @@
|
|
|
33
33
|
"description": "Core library for Stripe loaders",
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
|
-
"url": "https://github.com/
|
|
36
|
+
"url": "https://github.com/hideokamoto/stripe-docs-loader",
|
|
37
37
|
"directory": "packages/core"
|
|
38
38
|
},
|
|
39
39
|
"bugs": {
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/hideokamoto/stripe-docs-loader/issues"
|
|
41
41
|
},
|
|
42
|
-
"homepage": "https://github.com/
|
|
42
|
+
"homepage": "https://github.com/hideokamoto/stripe-docs-loader/tree/main/packages/core#readme",
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"sideEffects": false,
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=20"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"dev": "tsup --watch",
|
|
52
|
+
"build": "tsup",
|
|
53
|
+
"test": "vitest run"
|
|
45
54
|
}
|
|
46
|
-
}
|
|
55
|
+
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;IAC9B,OAAO,CAAC,KAAK;gBAAL,KAAK,GAAE,OAAe;IAE1C,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAM1B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAK5B;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,MAAM,CAAS;IAEvB;;;OAGG;gBACS,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAK9D;;;OAGG;IACH,OAAO,CAAC,GAAG;IAIX;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAIhB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;OAKG;IACI,sBAAsB,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAAmC,GAC3C,MAAM,EAAE;IAYX;;;;OAIG;IACI,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAyC7D;;;;;OAKG;IACI,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAK3E;;;;;OAKG;IACU,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAWrF;;;;;OAKG;IACU,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAyBhG"}
|
package/dist/index.spec.d.ts
DELETED
package/dist/index.spec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class c{constructor(t=!1){this.debug=t}log(t){this.debug&&console.log(t)}error(t){console.error(t)}warn(t){this.debug&&console.warn(t)}}class h{constructor(t={}){this.debug=t.debug??!1,this.logger=t.logger??new c(this.debug)}log(t){this.logger.log(t)}logError(t){this.logger.error(t)}logWarning(t){this.logger.warn(t)}extractUrlsFromSitemap(t,r="https://docs.stripe.com/"){const e=new RegExp(`<loc>(${r}[^<]+)</loc>`,"g"),s=[];let o;for(;(o=e.exec(t))!==null;)s.push(o[1]);return s}extractSitemapUrlsFromIndex(t){if(!t||typeof t!="string")return this.logError("Invalid input: content must be a string"),[];if(!t.includes("<?xml")||!t.includes("<sitemapindex"))return this.logError("Invalid sitemap index XML: Missing <?xml or <sitemapindex> elements."),[];try{const r=/<loc>([^<]+)<\/loc>/g,e=[];let s;for(;(s=r.exec(t))!==null;){const o=s[1];try{new URL(o),e.push(o)}catch{this.logWarning(`Skipped invalid URL format: ${o}`)}}return e.length===0&&this.logWarning("No valid URLs found in sitemap index"),e}catch(r){return this.logError(`Error extracting URLs from sitemap index: ${r}`),[]}}findNewUrls(t,r){const e=new Set(r);return t.filter(s=>!e.has(s))}async fetchAndProcessSitemap(t,r){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch sitemap: ${e.status} ${e.statusText}`);const s=await e.text();return this.extractUrlsFromSitemap(s,r)}async fetchAndProcessSitemapIndex(t,r){this.log(`Fetching sitemap index: ${t}`);const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch sitemap index: ${e.status} ${e.statusText}`);const s=await e.text(),o=this.extractSitemapUrlsFromIndex(s);this.log(`Number of sitemap partitions: ${o.length}`);const n=[];for(let i=0;i<o.length;i++){const l=o[i];this.log(`Processing partition ${i+1}/${o.length}: ${l}`);const a=await this.fetchAndProcessSitemap(l,r);this.log(`Retrieved ${a.length} URLs from partition ${i+1}`),n.push(...a)}return n}}exports.ConsoleLogger=c;exports.SitemapProcessor=h;
|
|
2
|
-
//# sourceMappingURL=stripe-loaders-core.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-loaders-core.cjs","sources":["../src/index.ts"],"sourcesContent":["/**\n * Utility functions for processing Stripe docs sitemaps\n */\n\n/**\n * Logger interface for SitemapProcessor\n */\nexport interface Logger {\n log(message: string): void;\n error(message: string): void;\n warn(message: string): void;\n}\n\n/**\n * Default console logger implementation\n */\nexport class ConsoleLogger implements Logger {\n constructor(private debug: boolean = false) {}\n\n log(message: string): void {\n if (this.debug) {\n console.log(message);\n }\n }\n\n error(message: string): void {\n console.error(message);\n }\n\n warn(message: string): void {\n if (this.debug) {\n console.warn(message);\n }\n }\n}\n\n/**\n * Utility class for processing Stripe docs sitemaps\n */\nexport class SitemapProcessor {\n private debug: boolean;\n private logger: Logger;\n\n /**\n * Constructor for SitemapProcessor\n * @param options Configuration options\n */\n constructor(options: { debug?: boolean; logger?: Logger } = {}) {\n this.debug = options.debug ?? false;\n this.logger = options.logger ?? new ConsoleLogger(this.debug);\n }\n\n /**\n * Log a message if debug mode is enabled\n * @param message Message to log\n */\n private log(message: string): void {\n this.logger.log(message);\n }\n\n /**\n * Log an error message\n * @param message Error message to log\n */\n private logError(message: string): void {\n this.logger.error(message);\n }\n\n /**\n * Log a warning message\n * @param message Warning message to log\n */\n private logWarning(message: string): void {\n this.logger.warn(message);\n }\n\n /**\n * Extract URLs from a sitemap\n * @param content Sitemap XML content\n * @param baseUrl Base URL part to extract (e.g., https://docs.stripe.com/)\n * @returns Array of extracted URLs\n */\n public extractUrlsFromSitemap(\n content: string,\n baseUrl: string = 'https://docs.stripe.com/'\n ): string[] {\n const urlRegex = new RegExp(`<loc>(${baseUrl}[^<]+)<\\/loc>`, 'g');\n const urls: string[] = [];\n let match;\n\n while ((match = urlRegex.exec(content)) !== null) {\n urls.push(match[1]);\n }\n\n return urls;\n }\n\n /**\n * Extract sitemap URLs from a sitemap index\n * @param content Sitemap index XML content\n * @returns Array of extracted sitemap URLs\n */\n public extractSitemapUrlsFromIndex(content: string): string[] {\n // Input validation\n if (!content || typeof content !== 'string') {\n this.logError('Invalid input: content must be a string');\n return [];\n }\n\n // Basic XML structure validation\n if (!content.includes('<?xml') || !content.includes('<sitemapindex')) {\n this.logError('Invalid sitemap index XML: Missing <?xml or <sitemapindex> elements.');\n return [];\n }\n\n try {\n const sitemapRegex = /<loc>([^<]+)<\\/loc>/g;\n const sitemapUrls: string[] = [];\n let match;\n\n while ((match = sitemapRegex.exec(content)) !== null) {\n // URL validation (optional)\n const url = match[1];\n try {\n new URL(url); // Check if URL is valid\n sitemapUrls.push(url);\n } catch (urlError) {\n this.logWarning(`Skipped invalid URL format: ${url}`);\n // Skip invalid URLs\n }\n }\n\n if (sitemapUrls.length === 0) {\n this.logWarning('No valid URLs found in sitemap index');\n }\n\n return sitemapUrls;\n } catch (error) {\n this.logError(`Error extracting URLs from sitemap index: ${error}`);\n return []; // Return empty array on error\n }\n }\n\n /**\n * Find newly added URLs\n * @param currentUrls Current URL list\n * @param previousUrls Previous URL list\n * @returns Array of newly added URLs\n */\n public findNewUrls(currentUrls: string[], previousUrls: string[]): string[] {\n const previousUrlSet = new Set(previousUrls);\n return currentUrls.filter(url => !previousUrlSet.has(url));\n }\n\n /**\n * Fetch and process a sitemap\n * @param url Sitemap URL\n * @param baseUrl Base URL part to extract\n * @returns List of retrieved URLs\n */\n public async fetchAndProcessSitemap(url: string, baseUrl?: string): Promise<string[]> {\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch sitemap: ${response.status} ${response.statusText}`);\n }\n\n const sitemapContent = await response.text();\n return this.extractUrlsFromSitemap(sitemapContent, baseUrl);\n }\n\n /**\n * Fetch and process a sitemap index\n * @param indexUrl Sitemap index URL\n * @param baseUrl Base URL part to extract\n * @returns List of retrieved URLs\n */\n public async fetchAndProcessSitemapIndex(indexUrl: string, baseUrl?: string): Promise<string[]> {\n this.log(`Fetching sitemap index: ${indexUrl}`);\n const response = await fetch(indexUrl);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch sitemap index: ${response.status} ${response.statusText}`);\n }\n\n const indexContent = await response.text();\n const sitemapUrls = this.extractSitemapUrlsFromIndex(indexContent);\n this.log(`Number of sitemap partitions: ${sitemapUrls.length}`);\n\n // Combine URLs from each sitemap file\n const allUrls: string[] = [];\n\n for (let i = 0; i < sitemapUrls.length; i++) {\n const sitemapUrl = sitemapUrls[i];\n this.log(`Processing partition ${i + 1}/${sitemapUrls.length}: ${sitemapUrl}`);\n const urls = await this.fetchAndProcessSitemap(sitemapUrl, baseUrl);\n this.log(`Retrieved ${urls.length} URLs from partition ${i + 1}`);\n allUrls.push(...urls);\n }\n\n return allUrls;\n }\n}\n"],"names":["ConsoleLogger","debug","message","SitemapProcessor","options","content","baseUrl","urlRegex","urls","match","sitemapRegex","sitemapUrls","url","error","currentUrls","previousUrls","previousUrlSet","response","sitemapContent","indexUrl","indexContent","allUrls","sitemapUrl"],"mappings":"gFAgBO,MAAMA,CAAgC,CAC3C,YAAoBC,EAAiB,GAAO,CAAxB,KAAA,MAAAA,CAAA,CAEpB,IAAIC,EAAuB,CACrB,KAAK,OACP,QAAQ,IAAIA,CAAO,CACrB,CAGF,MAAMA,EAAuB,CAC3B,QAAQ,MAAMA,CAAO,CAAA,CAGvB,KAAKA,EAAuB,CACtB,KAAK,OACP,QAAQ,KAAKA,CAAO,CACtB,CAEJ,CAKO,MAAMC,CAAiB,CAQ5B,YAAYC,EAAgD,GAAI,CACzD,KAAA,MAAQA,EAAQ,OAAS,GAC9B,KAAK,OAASA,EAAQ,QAAU,IAAIJ,EAAc,KAAK,KAAK,CAAA,CAOtD,IAAIE,EAAuB,CAC5B,KAAA,OAAO,IAAIA,CAAO,CAAA,CAOjB,SAASA,EAAuB,CACjC,KAAA,OAAO,MAAMA,CAAO,CAAA,CAOnB,WAAWA,EAAuB,CACnC,KAAA,OAAO,KAAKA,CAAO,CAAA,CASnB,uBACLG,EACAC,EAAkB,2BACR,CACV,MAAMC,EAAW,IAAI,OAAO,SAASD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AA2Ba,CAAQ,EAAE,EACxC,MAAAF,EAAW,MAAM,MAAME,CAAQ,EAEjC,GAAA,CAACF,EAAS,GACN,MAAA,IAAI,MAAM,kCAAkCA,EAAS,MAAM,IAAIA,EAAS,UAAU,EAAE,EAGtF,MAAAG,EAAe,MAAMH,EAAS,KAAK,EACnCN,EAAc,KAAK,4BAA4BS,CAAY,EACjE,KAAK,IAAI,iCAAiCT,EAAY,MAAM,EAAE,EAG9D,MAAMU,EAAoB,CAAC,EAE3B,QAAS,EAAI,EAAG,EAAIV,EAAY,OAAQ,IAAK,CACrC,MAAAW,EAAaX,EAAY,CAAC,EAC3B,KAAA,IAAI,wBAAwB,EAAI,CAAC,IAAIA,EAAY,MAAM,KAAKW,CAAU,EAAE,EAC7E,MAAMd,EAAO,MAAM,KAAK,uBAAuBc,EAAYhB,CAAO,EAClE,KAAK,IAAI,aAAaE,EAAK,MAAM,wBAAwB,EAAI,CAAC,EAAE,EACxDa,EAAA,KAAK,GAAGb,CAAI,CAAA,CAGf,OAAAa,CAAA,CAEX"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
class g {
|
|
2
|
-
constructor(t = !1) {
|
|
3
|
-
this.debug = t;
|
|
4
|
-
}
|
|
5
|
-
log(t) {
|
|
6
|
-
this.debug && console.log(t);
|
|
7
|
-
}
|
|
8
|
-
error(t) {
|
|
9
|
-
console.error(t);
|
|
10
|
-
}
|
|
11
|
-
warn(t) {
|
|
12
|
-
this.debug && console.warn(t);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
class h {
|
|
16
|
-
/**
|
|
17
|
-
* Constructor for SitemapProcessor
|
|
18
|
-
* @param options Configuration options
|
|
19
|
-
*/
|
|
20
|
-
constructor(t = {}) {
|
|
21
|
-
this.debug = t.debug ?? !1, this.logger = t.logger ?? new g(this.debug);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Log a message if debug mode is enabled
|
|
25
|
-
* @param message Message to log
|
|
26
|
-
*/
|
|
27
|
-
log(t) {
|
|
28
|
-
this.logger.log(t);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Log an error message
|
|
32
|
-
* @param message Error message to log
|
|
33
|
-
*/
|
|
34
|
-
logError(t) {
|
|
35
|
-
this.logger.error(t);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Log a warning message
|
|
39
|
-
* @param message Warning message to log
|
|
40
|
-
*/
|
|
41
|
-
logWarning(t) {
|
|
42
|
-
this.logger.warn(t);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Extract URLs from a sitemap
|
|
46
|
-
* @param content Sitemap XML content
|
|
47
|
-
* @param baseUrl Base URL part to extract (e.g., https://docs.stripe.com/)
|
|
48
|
-
* @returns Array of extracted URLs
|
|
49
|
-
*/
|
|
50
|
-
extractUrlsFromSitemap(t, r = "https://docs.stripe.com/") {
|
|
51
|
-
const e = new RegExp(`<loc>(${r}[^<]+)</loc>`, "g"), s = [];
|
|
52
|
-
let i;
|
|
53
|
-
for (; (i = e.exec(t)) !== null; )
|
|
54
|
-
s.push(i[1]);
|
|
55
|
-
return s;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Extract sitemap URLs from a sitemap index
|
|
59
|
-
* @param content Sitemap index XML content
|
|
60
|
-
* @returns Array of extracted sitemap URLs
|
|
61
|
-
*/
|
|
62
|
-
extractSitemapUrlsFromIndex(t) {
|
|
63
|
-
if (!t || typeof t != "string")
|
|
64
|
-
return this.logError("Invalid input: content must be a string"), [];
|
|
65
|
-
if (!t.includes("<?xml") || !t.includes("<sitemapindex"))
|
|
66
|
-
return this.logError("Invalid sitemap index XML: Missing <?xml or <sitemapindex> elements."), [];
|
|
67
|
-
try {
|
|
68
|
-
const r = /<loc>([^<]+)<\/loc>/g, e = [];
|
|
69
|
-
let s;
|
|
70
|
-
for (; (s = r.exec(t)) !== null; ) {
|
|
71
|
-
const i = s[1];
|
|
72
|
-
try {
|
|
73
|
-
new URL(i), e.push(i);
|
|
74
|
-
} catch {
|
|
75
|
-
this.logWarning(`Skipped invalid URL format: ${i}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return e.length === 0 && this.logWarning("No valid URLs found in sitemap index"), e;
|
|
79
|
-
} catch (r) {
|
|
80
|
-
return this.logError(`Error extracting URLs from sitemap index: ${r}`), [];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Find newly added URLs
|
|
85
|
-
* @param currentUrls Current URL list
|
|
86
|
-
* @param previousUrls Previous URL list
|
|
87
|
-
* @returns Array of newly added URLs
|
|
88
|
-
*/
|
|
89
|
-
findNewUrls(t, r) {
|
|
90
|
-
const e = new Set(r);
|
|
91
|
-
return t.filter((s) => !e.has(s));
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Fetch and process a sitemap
|
|
95
|
-
* @param url Sitemap URL
|
|
96
|
-
* @param baseUrl Base URL part to extract
|
|
97
|
-
* @returns List of retrieved URLs
|
|
98
|
-
*/
|
|
99
|
-
async fetchAndProcessSitemap(t, r) {
|
|
100
|
-
const e = await fetch(t);
|
|
101
|
-
if (!e.ok)
|
|
102
|
-
throw new Error(`Failed to fetch sitemap: ${e.status} ${e.statusText}`);
|
|
103
|
-
const s = await e.text();
|
|
104
|
-
return this.extractUrlsFromSitemap(s, r);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Fetch and process a sitemap index
|
|
108
|
-
* @param indexUrl Sitemap index URL
|
|
109
|
-
* @param baseUrl Base URL part to extract
|
|
110
|
-
* @returns List of retrieved URLs
|
|
111
|
-
*/
|
|
112
|
-
async fetchAndProcessSitemapIndex(t, r) {
|
|
113
|
-
this.log(`Fetching sitemap index: ${t}`);
|
|
114
|
-
const e = await fetch(t);
|
|
115
|
-
if (!e.ok)
|
|
116
|
-
throw new Error(`Failed to fetch sitemap index: ${e.status} ${e.statusText}`);
|
|
117
|
-
const s = await e.text(), i = this.extractSitemapUrlsFromIndex(s);
|
|
118
|
-
this.log(`Number of sitemap partitions: ${i.length}`);
|
|
119
|
-
const n = [];
|
|
120
|
-
for (let o = 0; o < i.length; o++) {
|
|
121
|
-
const l = i[o];
|
|
122
|
-
this.log(`Processing partition ${o + 1}/${i.length}: ${l}`);
|
|
123
|
-
const a = await this.fetchAndProcessSitemap(l, r);
|
|
124
|
-
this.log(`Retrieved ${a.length} URLs from partition ${o + 1}`), n.push(...a);
|
|
125
|
-
}
|
|
126
|
-
return n;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
export {
|
|
130
|
-
g as ConsoleLogger,
|
|
131
|
-
h as SitemapProcessor
|
|
132
|
-
};
|
|
133
|
-
//# sourceMappingURL=stripe-loaders-core.js.map
|