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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 wpkyoto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -122,11 +122,14 @@ The main class for processing sitemaps.
|
|
|
122
122
|
#### Constructor
|
|
123
123
|
|
|
124
124
|
```typescript
|
|
125
|
-
constructor(options:
|
|
125
|
+
constructor(options: SitemapProcessorOptions = {})
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
- `options.debug`: Enable debug mode (default: false)
|
|
129
|
-
- `options.logger`: Custom logger implementation (default: ConsoleLogger)
|
|
129
|
+
- `options.logger`: Custom logger implementation (default: ConsoleLogger, which prints `log` / `warn` only in debug mode)
|
|
130
|
+
- `options.rateLimit`: Rate limiting and retry settings (see below)
|
|
131
|
+
- `options.fetch`: Custom fetch implementation (default: global `fetch`)
|
|
132
|
+
- `options.sleep`: Custom sleep implementation, mainly for tests
|
|
130
133
|
|
|
131
134
|
#### Methods
|
|
132
135
|
|
|
@@ -150,6 +153,49 @@ constructor(options: { debug?: boolean; logger?: Logger } = {})
|
|
|
150
153
|
- `fetchAndProcessSitemapIndex(indexUrl: string, baseUrl?: string): Promise<string[]>`
|
|
151
154
|
- Fetch a sitemap index and process all referenced sitemaps
|
|
152
155
|
|
|
156
|
+
### Rate limiting and retries
|
|
157
|
+
|
|
158
|
+
Sitemap requests (and the loaders in `langchain-stripe-loader`) are sent one at a time.
|
|
159
|
+
`fetchAndProcessSitemapIndex` waits between partitions, and every request retries HTTP 429 / 5xx
|
|
160
|
+
responses and network errors with exponential backoff, honouring `Retry-After`.
|
|
161
|
+
|
|
162
|
+
| Option | Default | Meaning |
|
|
163
|
+
| ----------------- | ------- | ------------------------------------------------------- |
|
|
164
|
+
| `requestDelayMs` | 1000 | Delay between requests |
|
|
165
|
+
| `requestJitterMs` | 500 | Random variation (±half of this value) |
|
|
166
|
+
| `maxRetries` | 3 | Retries after the first attempt |
|
|
167
|
+
| `backoffBaseMs` | 1000 | Exponential backoff base |
|
|
168
|
+
| `backoffMaxMs` | 30000 | Upper bound for a single wait (also caps `Retry-After`) |
|
|
169
|
+
|
|
170
|
+
The helpers are exported for reuse:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { fetchWithRetry, RequestPacer, resolveRateLimit } from 'stripe-loaders-core';
|
|
174
|
+
|
|
175
|
+
const pacer = new RequestPacer(resolveRateLimit({ requestDelayMs: 2000 }));
|
|
176
|
+
for (const url of urls) {
|
|
177
|
+
await pacer.wait(); // no wait before the first request
|
|
178
|
+
const response = await fetchWithRetry(url); // returns the final response, including 4xx
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Stripe API changelog
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { fetchStripeChangelog, parseStripeChangelog } from 'stripe-loaders-core';
|
|
186
|
+
|
|
187
|
+
// Fetch https://docs.stripe.com/changelog.md (retried on 429 / 5xx) and parse it
|
|
188
|
+
const versions = await fetchStripeChangelog({ locale: 'ja-JP' });
|
|
189
|
+
for (const version of versions) {
|
|
190
|
+
console.log(version.release, version.version, version.entries.length);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Or parse Markdown you already have
|
|
194
|
+
const parsed = parseStripeChangelog(markdown);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Each version has `release` (e.g. `Endive`, or a year such as `2024` for older entries), `version` (e.g. `2026-11-18.endive`), `date` (`YYYY-MM-DD`), and `entries`. Each entry has `title`, `link` (absolute URL of the Markdown detail page, or an empty string), `category`, `affectedProducts`, `isBreakingChange`, and `changeType` (`api` / `stripejs`). Versions without entries are omitted.
|
|
198
|
+
|
|
153
199
|
### Logger Interface
|
|
154
200
|
|
|
155
201
|
Interface for custom loggers.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ConsoleLogger: () => ConsoleLogger,
|
|
24
|
+
DEFAULT_RATE_LIMIT: () => DEFAULT_RATE_LIMIT,
|
|
25
|
+
RequestPacer: () => RequestPacer,
|
|
26
|
+
STRIPE_CHANGELOG_URL: () => STRIPE_CHANGELOG_URL,
|
|
27
|
+
SitemapProcessor: () => SitemapProcessor,
|
|
28
|
+
calculateExponentialBackoff: () => calculateExponentialBackoff,
|
|
29
|
+
delay: () => delay,
|
|
30
|
+
delayWithJitter: () => delayWithJitter,
|
|
31
|
+
escapeRegExp: () => escapeRegExp,
|
|
32
|
+
fetchStripeChangelog: () => fetchStripeChangelog,
|
|
33
|
+
fetchWithRetry: () => fetchWithRetry,
|
|
34
|
+
parseRetryAfter: () => parseRetryAfter,
|
|
35
|
+
parseStripeChangelog: () => parseStripeChangelog,
|
|
36
|
+
resolveRateLimit: () => resolveRateLimit,
|
|
37
|
+
stripeChangelogUrl: () => stripeChangelogUrl,
|
|
38
|
+
withJitter: () => withJitter
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
|
|
42
|
+
// src/http.ts
|
|
43
|
+
var DEFAULT_RATE_LIMIT = Object.freeze({
|
|
44
|
+
requestDelayMs: 1e3,
|
|
45
|
+
requestJitterMs: 500,
|
|
46
|
+
maxRetries: 3,
|
|
47
|
+
backoffBaseMs: 1e3,
|
|
48
|
+
backoffMaxMs: 3e4
|
|
49
|
+
});
|
|
50
|
+
function resolveRateLimit(options) {
|
|
51
|
+
return { ...DEFAULT_RATE_LIMIT, ...options };
|
|
52
|
+
}
|
|
53
|
+
function delay(ms) {
|
|
54
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
55
|
+
}
|
|
56
|
+
function withJitter(baseMs, jitterMs, random = Math.random) {
|
|
57
|
+
const jitter = random() * jitterMs - jitterMs / 2;
|
|
58
|
+
return Math.max(0, Math.floor(baseMs + jitter));
|
|
59
|
+
}
|
|
60
|
+
async function delayWithJitter(baseMs, jitterMs, sleep = delay) {
|
|
61
|
+
const ms = withJitter(baseMs, jitterMs);
|
|
62
|
+
if (ms > 0) {
|
|
63
|
+
await sleep(ms);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function calculateExponentialBackoff(attempt, baseMs, maxMs) {
|
|
67
|
+
return Math.min(baseMs * Math.pow(2, attempt), maxMs);
|
|
68
|
+
}
|
|
69
|
+
function parseRetryAfter(value, now = Date.now()) {
|
|
70
|
+
if (!value) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
const trimmed = value.trim();
|
|
74
|
+
if (/^\d+$/.test(trimmed)) {
|
|
75
|
+
const ms2 = Number(trimmed) * 1e3;
|
|
76
|
+
return ms2 > 0 ? ms2 : void 0;
|
|
77
|
+
}
|
|
78
|
+
const date = Date.parse(trimmed);
|
|
79
|
+
if (Number.isNaN(date)) {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
const ms = date - now;
|
|
83
|
+
return ms > 0 ? ms : void 0;
|
|
84
|
+
}
|
|
85
|
+
function isRetryableStatus(status) {
|
|
86
|
+
return status === 429 || status >= 500;
|
|
87
|
+
}
|
|
88
|
+
async function fetchWithRetry(url, init, options = {}) {
|
|
89
|
+
const limits = resolveRateLimit(options.rateLimit);
|
|
90
|
+
const doFetch = options.fetch ?? ((input, reqInit) => fetch(input, reqInit));
|
|
91
|
+
const sleep = options.sleep ?? delay;
|
|
92
|
+
for (let attempt = 0; ; attempt++) {
|
|
93
|
+
let response;
|
|
94
|
+
try {
|
|
95
|
+
response = await doFetch(url, init);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (attempt >= limits.maxRetries) {
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
const waitMs2 = calculateExponentialBackoff(
|
|
101
|
+
attempt,
|
|
102
|
+
limits.backoffBaseMs,
|
|
103
|
+
limits.backoffMaxMs
|
|
104
|
+
);
|
|
105
|
+
options.onRetry?.({ url, attempt: attempt + 1, waitMs: waitMs2, reason: String(error) });
|
|
106
|
+
await delayWithJitter(waitMs2, limits.requestJitterMs, sleep);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!isRetryableStatus(response.status) || attempt >= limits.maxRetries) {
|
|
110
|
+
return response;
|
|
111
|
+
}
|
|
112
|
+
const retryAfter = parseRetryAfter(response.headers?.get?.("Retry-After"));
|
|
113
|
+
const waitMs = Math.min(
|
|
114
|
+
retryAfter ?? calculateExponentialBackoff(attempt, limits.backoffBaseMs, limits.backoffMaxMs),
|
|
115
|
+
limits.backoffMaxMs
|
|
116
|
+
);
|
|
117
|
+
options.onRetry?.({ url, attempt: attempt + 1, waitMs, reason: `HTTP ${response.status}` });
|
|
118
|
+
await delayWithJitter(waitMs, limits.requestJitterMs, sleep);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
var RequestPacer = class {
|
|
122
|
+
constructor(limits, sleep = delay) {
|
|
123
|
+
this.limits = limits;
|
|
124
|
+
this.sleep = sleep;
|
|
125
|
+
this.started = false;
|
|
126
|
+
}
|
|
127
|
+
async wait() {
|
|
128
|
+
if (this.started) {
|
|
129
|
+
await delayWithJitter(this.limits.requestDelayMs, this.limits.requestJitterMs, this.sleep);
|
|
130
|
+
}
|
|
131
|
+
this.started = true;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/changelog.ts
|
|
136
|
+
var STRIPE_CHANGELOG_URL = "https://docs.stripe.com/changelog.md";
|
|
137
|
+
var HEADING = /^(#{1,3})\s+(.+)$/;
|
|
138
|
+
function absoluteLink(link, baseUrl) {
|
|
139
|
+
try {
|
|
140
|
+
return new URL(link, baseUrl).toString();
|
|
141
|
+
} catch {
|
|
142
|
+
return link;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function parseStripeChangelog(markdown, baseUrl = "https://docs.stripe.com/") {
|
|
146
|
+
const lines = markdown.split(/\r\n?|\n/);
|
|
147
|
+
const titleIndex = lines.findIndex((line) => line.match(HEADING)?.[1] === "#");
|
|
148
|
+
const versions = [];
|
|
149
|
+
let release;
|
|
150
|
+
let current;
|
|
151
|
+
let category;
|
|
152
|
+
for (const [index, line] of lines.entries()) {
|
|
153
|
+
const heading = line.match(HEADING);
|
|
154
|
+
if (heading) {
|
|
155
|
+
const [, level, text] = heading;
|
|
156
|
+
const name = text.trim();
|
|
157
|
+
if (level === "###") {
|
|
158
|
+
category = name;
|
|
159
|
+
} else if (level === "##") {
|
|
160
|
+
const date = name.match(/^\d{4}-\d{2}-\d{2}/)?.[0] ?? "";
|
|
161
|
+
current = { release, version: name, date, entries: [] };
|
|
162
|
+
versions.push(current);
|
|
163
|
+
category = void 0;
|
|
164
|
+
} else if (index !== titleIndex) {
|
|
165
|
+
release = name;
|
|
166
|
+
current = void 0;
|
|
167
|
+
}
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const row = line.trim();
|
|
171
|
+
if (!current || !row.startsWith("|") || !row.endsWith("|")) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const cells = row.slice(1, -1).split(/(?<!\\)\|/).map((cell) => cell.trim());
|
|
175
|
+
const isHeader = cells[0].toLowerCase() === "title";
|
|
176
|
+
const isSeparator = cells.every((cell) => /^:?-+:?$/.test(cell));
|
|
177
|
+
if (cells.length < 3 || isHeader || isSeparator) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const [titleCell, productsCell, breakingCell, typeCell] = cells;
|
|
181
|
+
const linkMatch = titleCell.match(/\[([^\]]+)\]\(([^)]+)\)/);
|
|
182
|
+
const title = (linkMatch ? linkMatch[1] : titleCell).trim().replace(/\\\|/g, "|");
|
|
183
|
+
if (!title) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const link = linkMatch ? linkMatch[2].trim() : "";
|
|
187
|
+
current.entries.push({
|
|
188
|
+
release: current.release,
|
|
189
|
+
version: current.version,
|
|
190
|
+
date: current.date,
|
|
191
|
+
category,
|
|
192
|
+
title,
|
|
193
|
+
link: link ? absoluteLink(link, baseUrl) : "",
|
|
194
|
+
affectedProducts: productsCell.split(",").map((product) => product.trim()).filter((product) => product.length > 0),
|
|
195
|
+
isBreakingChange: breakingCell.toLowerCase().replace(/\s+/g, "") === "breaking",
|
|
196
|
+
changeType: typeCell || void 0
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return versions.filter((version) => version.entries.length > 0);
|
|
200
|
+
}
|
|
201
|
+
function stripeChangelogUrl(options = {}) {
|
|
202
|
+
const url = new URL(options.url ?? STRIPE_CHANGELOG_URL);
|
|
203
|
+
if (options.locale) {
|
|
204
|
+
url.searchParams.set("locale", options.locale);
|
|
205
|
+
}
|
|
206
|
+
return url.toString();
|
|
207
|
+
}
|
|
208
|
+
async function fetchStripeChangelog(options = {}) {
|
|
209
|
+
const url = stripeChangelogUrl(options);
|
|
210
|
+
const response = await fetchWithRetry(url, void 0, {
|
|
211
|
+
rateLimit: options.rateLimit,
|
|
212
|
+
fetch: options.fetch,
|
|
213
|
+
sleep: options.sleep
|
|
214
|
+
});
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
throw new Error(`Failed to fetch Stripe changelog: ${response.status} ${response.statusText}`);
|
|
217
|
+
}
|
|
218
|
+
return parseStripeChangelog(await response.text(), url);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/index.ts
|
|
222
|
+
function escapeRegExp(value) {
|
|
223
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
224
|
+
}
|
|
225
|
+
var ConsoleLogger = class {
|
|
226
|
+
constructor(debug = false) {
|
|
227
|
+
this.debug = debug;
|
|
228
|
+
}
|
|
229
|
+
log(message) {
|
|
230
|
+
if (this.debug) {
|
|
231
|
+
console.log(message);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
error(message) {
|
|
235
|
+
console.error(message);
|
|
236
|
+
}
|
|
237
|
+
warn(message) {
|
|
238
|
+
if (this.debug) {
|
|
239
|
+
console.warn(message);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var SitemapProcessor = class {
|
|
244
|
+
/**
|
|
245
|
+
* Constructor for SitemapProcessor
|
|
246
|
+
* @param options Configuration options
|
|
247
|
+
*/
|
|
248
|
+
constructor(options = {}) {
|
|
249
|
+
this.debug = options.debug ?? false;
|
|
250
|
+
this.logger = options.logger ?? new ConsoleLogger(this.debug);
|
|
251
|
+
this.rateLimit = resolveRateLimit(options.rateLimit);
|
|
252
|
+
this.fetchImpl = options.fetch;
|
|
253
|
+
this.sleep = options.sleep;
|
|
254
|
+
}
|
|
255
|
+
fetchUrl(url) {
|
|
256
|
+
return fetchWithRetry(url, void 0, {
|
|
257
|
+
rateLimit: this.rateLimit,
|
|
258
|
+
fetch: this.fetchImpl,
|
|
259
|
+
sleep: this.sleep,
|
|
260
|
+
onRetry: ({ attempt, waitMs, reason }) => this.logWarning(`Retrying ${url} (attempt ${attempt}, ${reason}) in ${waitMs}ms`)
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Log a message if debug mode is enabled
|
|
265
|
+
* @param message Message to log
|
|
266
|
+
*/
|
|
267
|
+
log(message) {
|
|
268
|
+
this.logger.log(message);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Log an error message
|
|
272
|
+
* @param message Error message to log
|
|
273
|
+
*/
|
|
274
|
+
logError(message) {
|
|
275
|
+
this.logger.error(message);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Log a warning message
|
|
279
|
+
* @param message Warning message to log
|
|
280
|
+
*/
|
|
281
|
+
logWarning(message) {
|
|
282
|
+
this.logger.warn(message);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Extract URLs from a sitemap
|
|
286
|
+
* @param content Sitemap XML content
|
|
287
|
+
* @param baseUrl Base URL part to extract (e.g., https://docs.stripe.com/)
|
|
288
|
+
* @returns Array of extracted URLs
|
|
289
|
+
*/
|
|
290
|
+
extractUrlsFromSitemap(content, baseUrl = "https://docs.stripe.com/") {
|
|
291
|
+
const urlRegex = new RegExp(`<loc>(${escapeRegExp(baseUrl)}[^<]+)</loc>`, "g");
|
|
292
|
+
const urls = [];
|
|
293
|
+
let match;
|
|
294
|
+
while ((match = urlRegex.exec(content)) !== null) {
|
|
295
|
+
urls.push(match[1]);
|
|
296
|
+
}
|
|
297
|
+
return urls;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Extract sitemap URLs from a sitemap index
|
|
301
|
+
* @param content Sitemap index XML content
|
|
302
|
+
* @returns Array of extracted sitemap URLs
|
|
303
|
+
*/
|
|
304
|
+
extractSitemapUrlsFromIndex(content) {
|
|
305
|
+
if (!content || typeof content !== "string") {
|
|
306
|
+
this.logError("Invalid input: content must be a string");
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
if (!content.includes("<?xml") || !content.includes("<sitemapindex")) {
|
|
310
|
+
this.logError("Invalid sitemap index XML: Missing <?xml or <sitemapindex> elements.");
|
|
311
|
+
return [];
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
const sitemapRegex = /<loc>([^<]+)<\/loc>/g;
|
|
315
|
+
const sitemapUrls = [];
|
|
316
|
+
let match;
|
|
317
|
+
while ((match = sitemapRegex.exec(content)) !== null) {
|
|
318
|
+
const url = match[1];
|
|
319
|
+
try {
|
|
320
|
+
new URL(url);
|
|
321
|
+
sitemapUrls.push(url);
|
|
322
|
+
} catch (urlError) {
|
|
323
|
+
this.logWarning(`Skipped invalid URL format: ${url}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (sitemapUrls.length === 0) {
|
|
327
|
+
this.logWarning("No valid URLs found in sitemap index");
|
|
328
|
+
}
|
|
329
|
+
return sitemapUrls;
|
|
330
|
+
} catch (error) {
|
|
331
|
+
this.logError(`Error extracting URLs from sitemap index: ${error}`);
|
|
332
|
+
return [];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Find newly added URLs
|
|
337
|
+
* @param currentUrls Current URL list
|
|
338
|
+
* @param previousUrls Previous URL list
|
|
339
|
+
* @returns Array of newly added URLs
|
|
340
|
+
*/
|
|
341
|
+
findNewUrls(currentUrls, previousUrls) {
|
|
342
|
+
const previousUrlSet = new Set(previousUrls);
|
|
343
|
+
return currentUrls.filter((url) => !previousUrlSet.has(url));
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Fetch and process a sitemap
|
|
347
|
+
* @param url Sitemap URL
|
|
348
|
+
* @param baseUrl Base URL part to extract
|
|
349
|
+
* @returns List of retrieved URLs
|
|
350
|
+
*/
|
|
351
|
+
async fetchAndProcessSitemap(url, baseUrl) {
|
|
352
|
+
const response = await this.fetchUrl(url);
|
|
353
|
+
if (!response.ok) {
|
|
354
|
+
throw new Error(`Failed to fetch sitemap: ${response.status} ${response.statusText}`);
|
|
355
|
+
}
|
|
356
|
+
const sitemapContent = await response.text();
|
|
357
|
+
return this.extractUrlsFromSitemap(sitemapContent, baseUrl);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Fetch and process a sitemap index
|
|
361
|
+
* @param indexUrl Sitemap index URL
|
|
362
|
+
* @param baseUrl Base URL part to extract
|
|
363
|
+
* @returns List of retrieved URLs
|
|
364
|
+
*/
|
|
365
|
+
async fetchAndProcessSitemapIndex(indexUrl, baseUrl) {
|
|
366
|
+
this.log(`Fetching sitemap index: ${indexUrl}`);
|
|
367
|
+
const pacer = new RequestPacer(this.rateLimit, this.sleep);
|
|
368
|
+
await pacer.wait();
|
|
369
|
+
const response = await this.fetchUrl(indexUrl);
|
|
370
|
+
if (!response.ok) {
|
|
371
|
+
throw new Error(`Failed to fetch sitemap index: ${response.status} ${response.statusText}`);
|
|
372
|
+
}
|
|
373
|
+
const indexContent = await response.text();
|
|
374
|
+
const sitemapUrls = this.extractSitemapUrlsFromIndex(indexContent);
|
|
375
|
+
this.log(`Number of sitemap partitions: ${sitemapUrls.length}`);
|
|
376
|
+
const allUrls = [];
|
|
377
|
+
for (let i = 0; i < sitemapUrls.length; i++) {
|
|
378
|
+
const sitemapUrl = sitemapUrls[i];
|
|
379
|
+
this.log(`Processing partition ${i + 1}/${sitemapUrls.length}: ${sitemapUrl}`);
|
|
380
|
+
await pacer.wait();
|
|
381
|
+
const urls = await this.fetchAndProcessSitemap(sitemapUrl, baseUrl);
|
|
382
|
+
this.log(`Retrieved ${urls.length} URLs from partition ${i + 1}`);
|
|
383
|
+
allUrls.push(...urls);
|
|
384
|
+
}
|
|
385
|
+
return allUrls;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
389
|
+
0 && (module.exports = {
|
|
390
|
+
ConsoleLogger,
|
|
391
|
+
DEFAULT_RATE_LIMIT,
|
|
392
|
+
RequestPacer,
|
|
393
|
+
STRIPE_CHANGELOG_URL,
|
|
394
|
+
SitemapProcessor,
|
|
395
|
+
calculateExponentialBackoff,
|
|
396
|
+
delay,
|
|
397
|
+
delayWithJitter,
|
|
398
|
+
escapeRegExp,
|
|
399
|
+
fetchStripeChangelog,
|
|
400
|
+
fetchWithRetry,
|
|
401
|
+
parseRetryAfter,
|
|
402
|
+
parseStripeChangelog,
|
|
403
|
+
resolveRateLimit,
|
|
404
|
+
stripeChangelogUrl,
|
|
405
|
+
withJitter
|
|
406
|
+
});
|
|
407
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/http.ts","../src/changelog.ts"],"sourcesContent":["/**\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","/**\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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