@prismicio/client 7.21.3-pr.433.c149018 → 7.21.3-pr.437.4958ca1
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/dist/getRepositoryName.cjs +1 -1
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.js +1 -1
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/lib/request.cjs +29 -2
- package/dist/lib/request.cjs.map +1 -1
- package/dist/lib/request.js +29 -2
- package/dist/lib/request.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +1 -1
- package/src/getRepositoryName.ts +0 -3
- package/src/lib/request.ts +49 -7
|
@@ -15,7 +15,7 @@ const require_errors = require('./errors.cjs');
|
|
|
15
15
|
const getRepositoryName = (repositoryEndpoint) => {
|
|
16
16
|
try {
|
|
17
17
|
const hostname = new URL(repositoryEndpoint).hostname;
|
|
18
|
-
if (hostname.endsWith("prismic.io") || hostname.endsWith("wroom.io") || hostname.endsWith("
|
|
18
|
+
if (hostname.endsWith("prismic.io") || hostname.endsWith("wroom.io") || hostname.endsWith("wroom.test")) return hostname.split(".")[0];
|
|
19
19
|
} catch {}
|
|
20
20
|
throw new require_errors.PrismicError(`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`, void 0, void 0);
|
|
21
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryName.cjs","names":["PrismicError"],"sources":["../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"
|
|
1
|
+
{"version":3,"file":"getRepositoryName.cjs","names":["PrismicError"],"sources":["../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,qBAAqB,uBAAuC;AACxE,KAAI;EACH,MAAM,WAAW,IAAI,IAAI,mBAAmB,CAAC;AAE7C,MACC,SAAS,SAAS,aAAa,IAC/B,SAAS,SAAS,WAAW,IAC7B,SAAS,SAAS,aAAa,CAE/B,QAAO,SAAS,MAAM,IAAI,CAAC;SAErB;AAER,OAAM,IAAIA,4BACT,0DAA0D,sBAC1D,QACA,OACA"}
|
|
@@ -15,7 +15,7 @@ import { PrismicError } from "./errors.js";
|
|
|
15
15
|
const getRepositoryName = (repositoryEndpoint) => {
|
|
16
16
|
try {
|
|
17
17
|
const hostname = new URL(repositoryEndpoint).hostname;
|
|
18
|
-
if (hostname.endsWith("prismic.io") || hostname.endsWith("wroom.io") || hostname.endsWith("
|
|
18
|
+
if (hostname.endsWith("prismic.io") || hostname.endsWith("wroom.io") || hostname.endsWith("wroom.test")) return hostname.split(".")[0];
|
|
19
19
|
} catch {}
|
|
20
20
|
throw new PrismicError(`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`, void 0, void 0);
|
|
21
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepositoryName.js","names":[],"sources":["../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"
|
|
1
|
+
{"version":3,"file":"getRepositoryName.js","names":[],"sources":["../src/getRepositoryName.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\n\n/**\n * Get a Prismic repository's name from its standard Prismic Document API or\n * GraphQL endpoint.\n *\n * @param repositoryEndpoint - Prismic Document API endpoint for the repository.\n *\n * @returns The Prismic repository's name.\n *\n * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is\n * provided.\n */\nexport const getRepositoryName = (repositoryEndpoint: string): string => {\n\ttry {\n\t\tconst hostname = new URL(repositoryEndpoint).hostname\n\n\t\tif (\n\t\t\thostname.endsWith(\"prismic.io\") || // Production\n\t\t\thostname.endsWith(\"wroom.io\") || // Staging\n\t\t\thostname.endsWith(\"wroom.test\") // Dev\n\t\t) {\n\t\t\treturn hostname.split(\".\")[0]\n\t\t}\n\t} catch {}\n\n\tthrow new PrismicError(\n\t\t`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`,\n\t\tundefined,\n\t\tundefined,\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,qBAAqB,uBAAuC;AACxE,KAAI;EACH,MAAM,WAAW,IAAI,IAAI,mBAAmB,CAAC;AAE7C,MACC,SAAS,SAAS,aAAa,IAC/B,SAAS,SAAS,WAAW,IAC7B,SAAS,SAAS,aAAa,CAE/B,QAAO,SAAS,MAAM,IAAI,CAAC;SAErB;AAER,OAAM,IAAI,aACT,0DAA0D,sBAC1D,QACA,OACA"}
|
package/dist/lib/request.cjs
CHANGED
|
@@ -16,6 +16,33 @@ const THROTTLED_RUNNERS = {};
|
|
|
16
16
|
* optional signal.
|
|
17
17
|
*/
|
|
18
18
|
const DEDUPLICATED_JOBS = {};
|
|
19
|
+
function memoizeResponse(response) {
|
|
20
|
+
const cache = {};
|
|
21
|
+
function createWrapper(res) {
|
|
22
|
+
return {
|
|
23
|
+
ok: res.ok,
|
|
24
|
+
status: res.status,
|
|
25
|
+
headers: res.headers,
|
|
26
|
+
url: res.url,
|
|
27
|
+
async text() {
|
|
28
|
+
if (!cache.text) cache.text = res.text();
|
|
29
|
+
return cache.text;
|
|
30
|
+
},
|
|
31
|
+
async json() {
|
|
32
|
+
if (!cache.json) cache.json = this.text().then((text) => ({ value: JSON.parse(text) }));
|
|
33
|
+
return cache.json.then((cached) => cached.value);
|
|
34
|
+
},
|
|
35
|
+
async blob() {
|
|
36
|
+
if (!cache.blob) cache.blob = res.blob();
|
|
37
|
+
return cache.blob;
|
|
38
|
+
},
|
|
39
|
+
clone() {
|
|
40
|
+
return createWrapper(res.clone());
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return createWrapper(response);
|
|
45
|
+
}
|
|
19
46
|
/**
|
|
20
47
|
* Makes an HTTP request with automatic retry for rate limits and request
|
|
21
48
|
* deduplication.
|
|
@@ -37,7 +64,7 @@ async function request(url, init, fetchFn) {
|
|
|
37
64
|
const existingJob = (_DEDUPLICATED_JOBS$st = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st === void 0 ? void 0 : _DEDUPLICATED_JOBS$st.get(init === null || init === void 0 ? void 0 : init.signal);
|
|
38
65
|
if (existingJob) job = existingJob;
|
|
39
66
|
else {
|
|
40
|
-
job = fetchFn(stringURL, init).finally(() => {
|
|
67
|
+
job = fetchFn(stringURL, init).then(memoizeResponse).finally(() => {
|
|
41
68
|
var _DEDUPLICATED_JOBS$st2, _DEDUPLICATED_JOBS$st3;
|
|
42
69
|
(_DEDUPLICATED_JOBS$st2 = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st2 === void 0 || _DEDUPLICATED_JOBS$st2.delete(init === null || init === void 0 ? void 0 : init.signal);
|
|
43
70
|
if (((_DEDUPLICATED_JOBS$st3 = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st3 === void 0 ? void 0 : _DEDUPLICATED_JOBS$st3.size) === 0) delete DEDUPLICATED_JOBS[stringURL];
|
|
@@ -52,7 +79,7 @@ async function request(url, init, fetchFn) {
|
|
|
52
79
|
await new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter));
|
|
53
80
|
return request(url, init, fetchFn);
|
|
54
81
|
}
|
|
55
|
-
return response
|
|
82
|
+
return response;
|
|
56
83
|
}
|
|
57
84
|
|
|
58
85
|
//#endregion
|
package/dist/lib/request.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.cjs","names":["THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>>","DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n>","job: Promise<ResponseLike>","pLimit"],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited\n * `fetch()` request (429 response code). The default value is only used if the\n * response does not include a `retry-after` header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/**\n * A record of URLs mapped to throttled task runners.\n */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/**\n * A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their\n * optional signal.\n */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request\n * deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n *\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init).finally(() => {\n\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t}\n\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter)\n\t\t\t? DEFAULT_RETRY_AFTER\n\t\t\t: retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response
|
|
1
|
+
{"version":3,"file":"request.cjs","names":["THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>>","DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n>","cache: {\n\t\ttext?: Promise<string>\n\t\tjson?: Promise<{ value: unknown }>\n\t\tblob?: Promise<Blob>\n\t}","job: Promise<ResponseLike>","pLimit"],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited\n * `fetch()` request (429 response code). The default value is only used if the\n * response does not include a `retry-after` header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/**\n * A record of URLs mapped to throttled task runners.\n */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/**\n * A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their\n * optional signal.\n */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\nfunction memoizeResponse(response: ResponseLike): ResponseLike {\n\tconst cache: {\n\t\ttext?: Promise<string>\n\t\tjson?: Promise<{ value: unknown }>\n\t\tblob?: Promise<Blob>\n\t} = {}\n\n\tfunction createWrapper(res: ResponseLike): ResponseLike {\n\t\treturn {\n\t\t\tok: res.ok,\n\t\t\tstatus: res.status,\n\t\t\theaders: res.headers,\n\t\t\turl: res.url,\n\t\t\tasync text() {\n\t\t\t\tif (!cache.text) {\n\t\t\t\t\tcache.text = res.text()\n\t\t\t\t}\n\t\t\t\treturn cache.text\n\t\t\t},\n\t\t\tasync json() {\n\t\t\t\tif (!cache.json) {\n\t\t\t\t\tcache.json = this.text().then((text) => ({ value: JSON.parse(text) }))\n\t\t\t\t}\n\t\t\t\treturn cache.json.then((cached) => cached.value)\n\t\t\t},\n\t\t\tasync blob() {\n\t\t\t\tif (!cache.blob) {\n\t\t\t\t\tcache.blob = res.blob()\n\t\t\t\t}\n\t\t\t\treturn cache.blob\n\t\t\t},\n\t\t\tclone() {\n\t\t\t\treturn createWrapper(res.clone())\n\t\t\t},\n\t\t}\n\t}\n\n\treturn createWrapper(response)\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request\n * deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n *\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init)\n\t\t\t\t.then(memoizeResponse)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter)\n\t\t\t? DEFAULT_RETRY_AFTER\n\t\t\t: retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,sBAAsB;;;;AAKnC,MAAMA,oBAA4D,EAAE;;;;;AAMpE,MAAMC,oBAEF,EAAE;AAsFN,SAAS,gBAAgB,UAAsC;CAC9D,MAAMC,QAIF,EAAE;CAEN,SAAS,cAAc,KAAiC;AACvD,SAAO;GACN,IAAI,IAAI;GACR,QAAQ,IAAI;GACZ,SAAS,IAAI;GACb,KAAK,IAAI;GACT,MAAM,OAAO;AACZ,QAAI,CAAC,MAAM,KACV,OAAM,OAAO,IAAI,MAAM;AAExB,WAAO,MAAM;;GAEd,MAAM,OAAO;AACZ,QAAI,CAAC,MAAM,KACV,OAAM,OAAO,KAAK,MAAM,CAAC,MAAM,UAAU,EAAE,OAAO,KAAK,MAAM,KAAK,EAAE,EAAE;AAEvE,WAAO,MAAM,KAAK,MAAM,WAAW,OAAO,MAAM;;GAEjD,MAAM,OAAO;AACZ,QAAI,CAAC,MAAM,KACV,OAAM,OAAO,IAAI,MAAM;AAExB,WAAO,MAAM;;GAEd,QAAQ;AACP,WAAO,cAAc,IAAI,OAAO,CAAC;;GAElC;;AAGF,QAAO,cAAc,SAAS;;;;;;;;;;;;AAa/B,eAAsB,QACrB,KACA,MACA,SACwB;CACxB,MAAM,YAAY,IAAI,UAAU;CAEhC,IAAIC;AAGJ,iDAAI,KAAM,MAAM;;AAMf,SAJgB,kCAAkB,IAAI,cAAtB,mCAAoCC,sBAAO,EAC1D,UAAU,qBACV,CAAC,SAEiB,QAAQ,WAAW,KAAK,CAAC;QACtC;;EAEN,MAAM,uCAAc,kBAAkB,0FAAY,gDAAI,KAAM,OAAO;AACnE,MAAI,YACH,OAAM;OACA;AACN,SAAM,QAAQ,WAAW,KAAK,CAC5B,KAAK,gBAAgB,CACrB,cAAc;;AACd,gDAAkB,oFAAY,mDAAO,KAAM,OAAO;AAClD,mCAAI,kBAAkB,4FAAY,UAAS,EAC1C,QAAO,kBAAkB;KAEzB;AAEH,IADa,kBAAkB,eAAlB,kBAAkB,6BAAe,IAAI,KAAK,GACnD,gDAAI,KAAM,QAAQ,IAAI;;;CAI5B,MAAM,WAAW,MAAM;AAGvB,KAAI,SAAS,WAAW,KAAK;EAC5B,MAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,cAAc,CAAC;EAC9D,MAAM,qBAAqB,OAAO,MAAM,WAAW,GAChD,sBACA,aAAa;AAEhB,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,mBAAmB,CAAC;AAEvE,SAAO,QAAQ,KAAK,MAAM,QAAQ;;AAGnC,QAAO"}
|
package/dist/lib/request.js
CHANGED
|
@@ -16,6 +16,33 @@ const THROTTLED_RUNNERS = {};
|
|
|
16
16
|
* optional signal.
|
|
17
17
|
*/
|
|
18
18
|
const DEDUPLICATED_JOBS = {};
|
|
19
|
+
function memoizeResponse(response) {
|
|
20
|
+
const cache = {};
|
|
21
|
+
function createWrapper(res) {
|
|
22
|
+
return {
|
|
23
|
+
ok: res.ok,
|
|
24
|
+
status: res.status,
|
|
25
|
+
headers: res.headers,
|
|
26
|
+
url: res.url,
|
|
27
|
+
async text() {
|
|
28
|
+
if (!cache.text) cache.text = res.text();
|
|
29
|
+
return cache.text;
|
|
30
|
+
},
|
|
31
|
+
async json() {
|
|
32
|
+
if (!cache.json) cache.json = this.text().then((text) => ({ value: JSON.parse(text) }));
|
|
33
|
+
return cache.json.then((cached) => cached.value);
|
|
34
|
+
},
|
|
35
|
+
async blob() {
|
|
36
|
+
if (!cache.blob) cache.blob = res.blob();
|
|
37
|
+
return cache.blob;
|
|
38
|
+
},
|
|
39
|
+
clone() {
|
|
40
|
+
return createWrapper(res.clone());
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return createWrapper(response);
|
|
45
|
+
}
|
|
19
46
|
/**
|
|
20
47
|
* Makes an HTTP request with automatic retry for rate limits and request
|
|
21
48
|
* deduplication.
|
|
@@ -37,7 +64,7 @@ async function request(url, init, fetchFn) {
|
|
|
37
64
|
const existingJob = (_DEDUPLICATED_JOBS$st = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st === void 0 ? void 0 : _DEDUPLICATED_JOBS$st.get(init === null || init === void 0 ? void 0 : init.signal);
|
|
38
65
|
if (existingJob) job = existingJob;
|
|
39
66
|
else {
|
|
40
|
-
job = fetchFn(stringURL, init).finally(() => {
|
|
67
|
+
job = fetchFn(stringURL, init).then(memoizeResponse).finally(() => {
|
|
41
68
|
var _DEDUPLICATED_JOBS$st2, _DEDUPLICATED_JOBS$st3;
|
|
42
69
|
(_DEDUPLICATED_JOBS$st2 = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st2 === void 0 || _DEDUPLICATED_JOBS$st2.delete(init === null || init === void 0 ? void 0 : init.signal);
|
|
43
70
|
if (((_DEDUPLICATED_JOBS$st3 = DEDUPLICATED_JOBS[stringURL]) === null || _DEDUPLICATED_JOBS$st3 === void 0 ? void 0 : _DEDUPLICATED_JOBS$st3.size) === 0) delete DEDUPLICATED_JOBS[stringURL];
|
|
@@ -52,7 +79,7 @@ async function request(url, init, fetchFn) {
|
|
|
52
79
|
await new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter));
|
|
53
80
|
return request(url, init, fetchFn);
|
|
54
81
|
}
|
|
55
|
-
return response
|
|
82
|
+
return response;
|
|
56
83
|
}
|
|
57
84
|
|
|
58
85
|
//#endregion
|
package/dist/lib/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","names":["THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>>","DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n>","job: Promise<ResponseLike>"],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited\n * `fetch()` request (429 response code). The default value is only used if the\n * response does not include a `retry-after` header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/**\n * A record of URLs mapped to throttled task runners.\n */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/**\n * A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their\n * optional signal.\n */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request\n * deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n *\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init).finally(() => {\n\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t}\n\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter)\n\t\t\t? DEFAULT_RETRY_AFTER\n\t\t\t: retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response
|
|
1
|
+
{"version":3,"file":"request.js","names":["THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>>","DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n>","cache: {\n\t\ttext?: Promise<string>\n\t\tjson?: Promise<{ value: unknown }>\n\t\tblob?: Promise<Blob>\n\t}","job: Promise<ResponseLike>"],"sources":["../../src/lib/request.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./pLimit\"\n\n/**\n * The default number of milliseconds to wait before retrying a rate-limited\n * `fetch()` request (429 response code). The default value is only used if the\n * response does not include a `retry-after` header.\n */\nexport const DEFAULT_RETRY_AFTER = 1500 // ms\n\n/**\n * A record of URLs mapped to throttled task runners.\n */\nconst THROTTLED_RUNNERS: Partial<Record<string, LimitFunction>> = {}\n\n/**\n * A record of URLs mapped to active deduplicated jobs. Jobs are keyed by their\n * optional signal.\n */\nconst DEDUPLICATED_JOBS: Partial<\n\tRecord<string, Map<AbortSignalLike | undefined, Promise<ResponseLike>>>\n> = {}\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// oxlint-disable-next-line no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// oxlint-disable-next-line no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\turl: string\n\t// oxlint-disable-next-line no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tblob(): Promise<Blob>\n\tclone(): ResponseLike\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\nfunction memoizeResponse(response: ResponseLike): ResponseLike {\n\tconst cache: {\n\t\ttext?: Promise<string>\n\t\tjson?: Promise<{ value: unknown }>\n\t\tblob?: Promise<Blob>\n\t} = {}\n\n\tfunction createWrapper(res: ResponseLike): ResponseLike {\n\t\treturn {\n\t\t\tok: res.ok,\n\t\t\tstatus: res.status,\n\t\t\theaders: res.headers,\n\t\t\turl: res.url,\n\t\t\tasync text() {\n\t\t\t\tif (!cache.text) {\n\t\t\t\t\tcache.text = res.text()\n\t\t\t\t}\n\t\t\t\treturn cache.text\n\t\t\t},\n\t\t\tasync json() {\n\t\t\t\tif (!cache.json) {\n\t\t\t\t\tcache.json = this.text().then((text) => ({ value: JSON.parse(text) }))\n\t\t\t\t}\n\t\t\t\treturn cache.json.then((cached) => cached.value)\n\t\t\t},\n\t\t\tasync blob() {\n\t\t\t\tif (!cache.blob) {\n\t\t\t\t\tcache.blob = res.blob()\n\t\t\t\t}\n\t\t\t\treturn cache.blob\n\t\t\t},\n\t\t\tclone() {\n\t\t\t\treturn createWrapper(res.clone())\n\t\t\t},\n\t\t}\n\t}\n\n\treturn createWrapper(response)\n}\n\n/**\n * Makes an HTTP request with automatic retry for rate limits and request\n * deduplication.\n *\n * @param url - The URL to request.\n * @param init - Fetch options.\n * @param fetchFn - The fetch function to use.\n *\n * @returns The response from the fetch request.\n */\nexport async function request(\n\turl: URL,\n\tinit: RequestInitLike | undefined,\n\tfetchFn: FetchLike,\n): Promise<ResponseLike> {\n\tconst stringURL = url.toString()\n\n\tlet job: Promise<ResponseLike>\n\n\t// Throttle requests with a body.\n\tif (init?.body) {\n\t\t// Rate limiting is done per hostname.\n\t\tconst runner = (THROTTLED_RUNNERS[url.hostname] ||= pLimit({\n\t\t\tinterval: DEFAULT_RETRY_AFTER,\n\t\t}))\n\n\t\tjob = runner(() => fetchFn(stringURL, init))\n\t} else {\n\t\t// Deduplicate all other requests.\n\t\tconst existingJob = DEDUPLICATED_JOBS[stringURL]?.get(init?.signal)\n\t\tif (existingJob) {\n\t\t\tjob = existingJob\n\t\t} else {\n\t\t\tjob = fetchFn(stringURL, init)\n\t\t\t\t.then(memoizeResponse)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tDEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)\n\t\t\t\t\tif (DEDUPLICATED_JOBS[stringURL]?.size === 0) {\n\t\t\t\t\t\tdelete DEDUPLICATED_JOBS[stringURL]\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\tconst map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())\n\t\t\tmap.set(init?.signal, job)\n\t\t}\n\t}\n\n\tconst response = await job\n\n\t// Retry rate limited requests.\n\tif (response.status === 429) {\n\t\tconst retryAfter = Number(response.headers.get(\"retry-after\"))\n\t\tconst resolvedRetryAfter = Number.isNaN(retryAfter)\n\t\t\t? DEFAULT_RETRY_AFTER\n\t\t\t: retryAfter * 1000\n\n\t\tawait new Promise((resolve) => setTimeout(resolve, resolvedRetryAfter))\n\n\t\treturn request(url, init, fetchFn)\n\t}\n\n\treturn response\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,sBAAsB;;;;AAKnC,MAAMA,oBAA4D,EAAE;;;;;AAMpE,MAAMC,oBAEF,EAAE;AAsFN,SAAS,gBAAgB,UAAsC;CAC9D,MAAMC,QAIF,EAAE;CAEN,SAAS,cAAc,KAAiC;AACvD,SAAO;GACN,IAAI,IAAI;GACR,QAAQ,IAAI;GACZ,SAAS,IAAI;GACb,KAAK,IAAI;GACT,MAAM,OAAO;AACZ,QAAI,CAAC,MAAM,KACV,OAAM,OAAO,IAAI,MAAM;AAExB,WAAO,MAAM;;GAEd,MAAM,OAAO;AACZ,QAAI,CAAC,MAAM,KACV,OAAM,OAAO,KAAK,MAAM,CAAC,MAAM,UAAU,EAAE,OAAO,KAAK,MAAM,KAAK,EAAE,EAAE;AAEvE,WAAO,MAAM,KAAK,MAAM,WAAW,OAAO,MAAM;;GAEjD,MAAM,OAAO;AACZ,QAAI,CAAC,MAAM,KACV,OAAM,OAAO,IAAI,MAAM;AAExB,WAAO,MAAM;;GAEd,QAAQ;AACP,WAAO,cAAc,IAAI,OAAO,CAAC;;GAElC;;AAGF,QAAO,cAAc,SAAS;;;;;;;;;;;;AAa/B,eAAsB,QACrB,KACA,MACA,SACwB;CACxB,MAAM,YAAY,IAAI,UAAU;CAEhC,IAAIC;AAGJ,iDAAI,KAAM,MAAM;;AAMf,SAJgB,kCAAkB,IAAI,cAAtB,mCAAoC,OAAO,EAC1D,UAAU,qBACV,CAAC,SAEiB,QAAQ,WAAW,KAAK,CAAC;QACtC;;EAEN,MAAM,uCAAc,kBAAkB,0FAAY,gDAAI,KAAM,OAAO;AACnE,MAAI,YACH,OAAM;OACA;AACN,SAAM,QAAQ,WAAW,KAAK,CAC5B,KAAK,gBAAgB,CACrB,cAAc;;AACd,gDAAkB,oFAAY,mDAAO,KAAM,OAAO;AAClD,mCAAI,kBAAkB,4FAAY,UAAS,EAC1C,QAAO,kBAAkB;KAEzB;AAEH,IADa,kBAAkB,eAAlB,kBAAkB,6BAAe,IAAI,KAAK,GACnD,gDAAI,KAAM,QAAQ,IAAI;;;CAI5B,MAAM,WAAW,MAAM;AAGvB,KAAI,SAAS,WAAW,KAAK;EAC5B,MAAM,aAAa,OAAO,SAAS,QAAQ,IAAI,cAAc,CAAC;EAC9D,MAAM,qBAAqB,OAAO,MAAM,WAAW,GAChD,sBACA,aAAa;AAEhB,QAAM,IAAI,SAAS,YAAY,WAAW,SAAS,mBAAmB,CAAC;AAEvE,SAAO,QAAQ,KAAK,MAAM,QAAQ;;AAGnC,QAAO"}
|
package/dist/package.cjs
CHANGED
package/dist/package.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.cjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@prismicio/client\",\n\t\"version\": \"7.21.3-pr.
|
|
1
|
+
{"version":3,"file":"package.cjs","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@prismicio/client\",\n\t\"version\": \"7.21.3-pr.437.4958ca1\",\n\t\"description\": \"The official JavaScript + TypeScript client library for Prismic\",\n\t\"keywords\": [\n\t\t\"typescript\",\n\t\t\"client\",\n\t\t\"helpers\",\n\t\t\"types\",\n\t\t\"utils\",\n\t\t\"toolbox\",\n\t\t\"cms\",\n\t\t\"prismic\",\n\t\t\"prismic.io\"\n\t],\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"ssh://git@github.com/prismicio/prismic-client.git\"\n\t},\n\t\"license\": \"Apache-2.0\",\n\t\"author\": \"Prismic <contact@prismic.io> (https://prismic.io)\",\n\t\"sideEffects\": false,\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"import\": \"./dist/index.js\",\n\t\t\t\"require\": \"./dist/index.cjs\"\n\t\t},\n\t\t\"./richtext\": {\n\t\t\t\"import\": \"./dist/richtext.js\",\n\t\t\t\"require\": \"./dist/richtext.cjs\"\n\t\t},\n\t\t\"./package.json\": \"./package.json\"\n\t},\n\t\"main\": \"./dist/index.cjs\",\n\t\"module\": \"./dist/index.js\",\n\t\"react-native\": \"./dist/index.js\",\n\t\"types\": \"./dist/index.d.cts\",\n\t\"typesVersions\": {\n\t\t\"*\": {\n\t\t\t\"*\": [\n\t\t\t\t\"dist/index.d.ts\"\n\t\t\t],\n\t\t\t\"richtext\": [\n\t\t\t\t\"dist/richtext.d.ts\"\n\t\t\t]\n\t\t}\n\t},\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"src\"\n\t],\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\n\t\t\"dev\": \"tsdown --watch\",\n\t\t\"format\": \"prettier --write .\",\n\t\t\"prepare\": \"npm run build\",\n\t\t\"lint\": \"oxlint --deny-warnings\",\n\t\t\"types\": \"tsc --noEmit\",\n\t\t\"unit\": \"vitest run --coverage\",\n\t\t\"unit:watch\": \"vitest watch\",\n\t\t\"test\": \"npm run lint && npm run types && npm run unit && npm run build\"\n\t},\n\t\"dependencies\": {\n\t\t\"imgix-url-builder\": \"^0.0.6\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@prismicio/e2e-tests-utils\": \"^1.14.0\",\n\t\t\"@prismicio/types-internal\": \"^3.16.1\",\n\t\t\"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\n\t\t\"@types/node\": \"^24.10.0\",\n\t\t\"@vitest/coverage-v8\": \"^4.0.6\",\n\t\t\"oxlint\": \"^1.26.0\",\n\t\t\"prettier\": \"^3.6.2\",\n\t\t\"prettier-plugin-jsdoc\": \"1.3.3\",\n\t\t\"tsdown\": \"^0.16.1\",\n\t\t\"typescript\": \"^5.9.3\",\n\t\t\"vitest\": \"^4.0.6\"\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=14.15.0\"\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t}\n}\n"],"mappings":";;WACS;cACG"}
|
package/dist/package.js
CHANGED
package/dist/package.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@prismicio/client\",\n\t\"version\": \"7.21.3-pr.
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@prismicio/client\",\n\t\"version\": \"7.21.3-pr.437.4958ca1\",\n\t\"description\": \"The official JavaScript + TypeScript client library for Prismic\",\n\t\"keywords\": [\n\t\t\"typescript\",\n\t\t\"client\",\n\t\t\"helpers\",\n\t\t\"types\",\n\t\t\"utils\",\n\t\t\"toolbox\",\n\t\t\"cms\",\n\t\t\"prismic\",\n\t\t\"prismic.io\"\n\t],\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"ssh://git@github.com/prismicio/prismic-client.git\"\n\t},\n\t\"license\": \"Apache-2.0\",\n\t\"author\": \"Prismic <contact@prismic.io> (https://prismic.io)\",\n\t\"sideEffects\": false,\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"import\": \"./dist/index.js\",\n\t\t\t\"require\": \"./dist/index.cjs\"\n\t\t},\n\t\t\"./richtext\": {\n\t\t\t\"import\": \"./dist/richtext.js\",\n\t\t\t\"require\": \"./dist/richtext.cjs\"\n\t\t},\n\t\t\"./package.json\": \"./package.json\"\n\t},\n\t\"main\": \"./dist/index.cjs\",\n\t\"module\": \"./dist/index.js\",\n\t\"react-native\": \"./dist/index.js\",\n\t\"types\": \"./dist/index.d.cts\",\n\t\"typesVersions\": {\n\t\t\"*\": {\n\t\t\t\"*\": [\n\t\t\t\t\"dist/index.d.ts\"\n\t\t\t],\n\t\t\t\"richtext\": [\n\t\t\t\t\"dist/richtext.d.ts\"\n\t\t\t]\n\t\t}\n\t},\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"src\"\n\t],\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\n\t\t\"dev\": \"tsdown --watch\",\n\t\t\"format\": \"prettier --write .\",\n\t\t\"prepare\": \"npm run build\",\n\t\t\"lint\": \"oxlint --deny-warnings\",\n\t\t\"types\": \"tsc --noEmit\",\n\t\t\"unit\": \"vitest run --coverage\",\n\t\t\"unit:watch\": \"vitest watch\",\n\t\t\"test\": \"npm run lint && npm run types && npm run unit && npm run build\"\n\t},\n\t\"dependencies\": {\n\t\t\"imgix-url-builder\": \"^0.0.6\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@prismicio/e2e-tests-utils\": \"^1.14.0\",\n\t\t\"@prismicio/types-internal\": \"^3.16.1\",\n\t\t\"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\n\t\t\"@types/node\": \"^24.10.0\",\n\t\t\"@vitest/coverage-v8\": \"^4.0.6\",\n\t\t\"oxlint\": \"^1.26.0\",\n\t\t\"prettier\": \"^3.6.2\",\n\t\t\"prettier-plugin-jsdoc\": \"1.3.3\",\n\t\t\"tsdown\": \"^0.16.1\",\n\t\t\"typescript\": \"^5.9.3\",\n\t\t\"vitest\": \"^4.0.6\"\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=14.15.0\"\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t}\n}\n"],"mappings":";WACS;cACG"}
|
package/package.json
CHANGED
package/src/getRepositoryName.ts
CHANGED
|
@@ -18,9 +18,6 @@ export const getRepositoryName = (repositoryEndpoint: string): string => {
|
|
|
18
18
|
if (
|
|
19
19
|
hostname.endsWith("prismic.io") || // Production
|
|
20
20
|
hostname.endsWith("wroom.io") || // Staging
|
|
21
|
-
hostname.endsWith("dev-tools-wroom.com") || // Dev-Tools
|
|
22
|
-
hostname.endsWith("marketing-tools-wroom.com") || // Marketing-Tools
|
|
23
|
-
hostname.endsWith("platform-wroom.com") || // Platform
|
|
24
21
|
hostname.endsWith("wroom.test") // Dev
|
|
25
22
|
) {
|
|
26
23
|
return hostname.split(".")[0]
|
package/src/lib/request.ts
CHANGED
|
@@ -104,6 +104,46 @@ export interface HeadersLike {
|
|
|
104
104
|
get(name: string): string | null
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
function memoizeResponse(response: ResponseLike): ResponseLike {
|
|
108
|
+
const cache: {
|
|
109
|
+
text?: Promise<string>
|
|
110
|
+
json?: Promise<{ value: unknown }>
|
|
111
|
+
blob?: Promise<Blob>
|
|
112
|
+
} = {}
|
|
113
|
+
|
|
114
|
+
function createWrapper(res: ResponseLike): ResponseLike {
|
|
115
|
+
return {
|
|
116
|
+
ok: res.ok,
|
|
117
|
+
status: res.status,
|
|
118
|
+
headers: res.headers,
|
|
119
|
+
url: res.url,
|
|
120
|
+
async text() {
|
|
121
|
+
if (!cache.text) {
|
|
122
|
+
cache.text = res.text()
|
|
123
|
+
}
|
|
124
|
+
return cache.text
|
|
125
|
+
},
|
|
126
|
+
async json() {
|
|
127
|
+
if (!cache.json) {
|
|
128
|
+
cache.json = this.text().then((text) => ({ value: JSON.parse(text) }))
|
|
129
|
+
}
|
|
130
|
+
return cache.json.then((cached) => cached.value)
|
|
131
|
+
},
|
|
132
|
+
async blob() {
|
|
133
|
+
if (!cache.blob) {
|
|
134
|
+
cache.blob = res.blob()
|
|
135
|
+
}
|
|
136
|
+
return cache.blob
|
|
137
|
+
},
|
|
138
|
+
clone() {
|
|
139
|
+
return createWrapper(res.clone())
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return createWrapper(response)
|
|
145
|
+
}
|
|
146
|
+
|
|
107
147
|
/**
|
|
108
148
|
* Makes an HTTP request with automatic retry for rate limits and request
|
|
109
149
|
* deduplication.
|
|
@@ -137,12 +177,14 @@ export async function request(
|
|
|
137
177
|
if (existingJob) {
|
|
138
178
|
job = existingJob
|
|
139
179
|
} else {
|
|
140
|
-
job = fetchFn(stringURL, init)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
180
|
+
job = fetchFn(stringURL, init)
|
|
181
|
+
.then(memoizeResponse)
|
|
182
|
+
.finally(() => {
|
|
183
|
+
DEDUPLICATED_JOBS[stringURL]?.delete(init?.signal)
|
|
184
|
+
if (DEDUPLICATED_JOBS[stringURL]?.size === 0) {
|
|
185
|
+
delete DEDUPLICATED_JOBS[stringURL]
|
|
186
|
+
}
|
|
187
|
+
})
|
|
146
188
|
const map = (DEDUPLICATED_JOBS[stringURL] ||= new Map())
|
|
147
189
|
map.set(init?.signal, job)
|
|
148
190
|
}
|
|
@@ -162,5 +204,5 @@ export async function request(
|
|
|
162
204
|
return request(url, init, fetchFn)
|
|
163
205
|
}
|
|
164
206
|
|
|
165
|
-
return response
|
|
207
|
+
return response
|
|
166
208
|
}
|