@slicemachine/manager 0.2.1 → 0.2.2
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/_node_modules/node-fetch/src/index.js +2 -2
- package/dist/_node_modules/node-fetch/src/index.js.map +1 -1
- package/dist/auth/PrismicAuthManager.cjs +9 -8
- package/dist/auth/PrismicAuthManager.cjs.map +1 -1
- package/dist/auth/PrismicAuthManager.js +6 -5
- package/dist/auth/PrismicAuthManager.js.map +1 -1
- package/dist/lib/checkIsURLAccessible.cjs +2 -2
- package/dist/lib/checkIsURLAccessible.cjs.map +1 -1
- package/dist/lib/checkIsURLAccessible.js +1 -1
- package/dist/lib/checkIsURLAccessible.js.map +1 -1
- package/dist/lib/fetch.cjs +36 -0
- package/dist/lib/fetch.cjs.map +1 -0
- package/dist/lib/fetch.d.ts +15 -0
- package/dist/lib/fetch.js +18 -0
- package/dist/lib/fetch.js.map +1 -0
- package/dist/lib/fetchGitHubReleaseBodyForRelease.cjs +3 -3
- package/dist/lib/fetchGitHubReleaseBodyForRelease.cjs.map +1 -1
- package/dist/lib/fetchGitHubReleaseBodyForRelease.js +1 -1
- package/dist/lib/fetchGitHubReleaseBodyForRelease.js.map +1 -1
- package/dist/lib/fetchNPMPackageVersions.cjs +2 -2
- package/dist/lib/fetchNPMPackageVersions.cjs.map +1 -1
- package/dist/lib/fetchNPMPackageVersions.js +1 -1
- package/dist/lib/fetchNPMPackageVersions.js.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.cjs +7 -4
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.js +5 -2
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +3 -2
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js +2 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.cjs +8 -7
- package/dist/managers/screenshots/ScreenshotsManager.cjs.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.js +6 -5
- package/dist/managers/screenshots/ScreenshotsManager.js.map +1 -1
- package/dist/managers/simulator/SimulatorManager.cjs +2 -2
- package/dist/managers/simulator/SimulatorManager.cjs.map +1 -1
- package/dist/managers/simulator/SimulatorManager.js +1 -1
- package/dist/managers/simulator/SimulatorManager.js.map +1 -1
- package/dist/managers/slices/SlicesManager.cjs +10 -7
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.d.ts +1 -1
- package/dist/managers/slices/SlicesManager.js +8 -5
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/package.json +3 -3
- package/src/auth/PrismicAuthManager.ts +6 -10
- package/src/lib/checkIsURLAccessible.ts +1 -1
- package/src/lib/fetch.ts +46 -0
- package/src/lib/fetchGitHubReleaseBodyForRelease.ts +1 -1
- package/src/lib/fetchNPMPackageVersions.ts +1 -1
- package/src/managers/customTypes/CustomTypesManager.ts +6 -3
- package/src/managers/prismicRepository/PrismicRepositoryManager.ts +4 -1
- package/src/managers/screenshots/ScreenshotsManager.ts +5 -4
- package/src/managers/simulator/SimulatorManager.ts +1 -1
- package/src/managers/slices/SlicesManager.ts +8 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import http__default from "node:http";
|
|
2
|
-
import
|
|
2
|
+
import https__default from "node:https";
|
|
3
3
|
import zlib from "node:zlib";
|
|
4
4
|
import Stream, { pipeline, PassThrough } from "node:stream";
|
|
5
5
|
import { Buffer } from "node:buffer";
|
|
@@ -31,7 +31,7 @@ async function fetch(url, options_) {
|
|
|
31
31
|
resolve(response2);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
const send = (parsedURL.protocol === "https:" ?
|
|
34
|
+
const send = (parsedURL.protocol === "https:" ? https__default : http__default).request;
|
|
35
35
|
const { signal } = request;
|
|
36
36
|
let response = null;
|
|
37
37
|
const abort = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../node_modules/node-fetch/src/index.js"],"sourcesContent":["/**\n * Index.js\n *\n * a request API compatible with window.fetch\n *\n * All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.\n */\n\nimport http from 'node:http';\nimport https from 'node:https';\nimport zlib from 'node:zlib';\nimport Stream, {PassThrough, pipeline as pump} from 'node:stream';\nimport {Buffer} from 'node:buffer';\n\nimport dataUriToBuffer from 'data-uri-to-buffer';\n\nimport {writeToStream, clone} from './body.js';\nimport Response from './response.js';\nimport Headers, {fromRawHeaders} from './headers.js';\nimport Request, {getNodeRequestOptions} from './request.js';\nimport {FetchError} from './errors/fetch-error.js';\nimport {AbortError} from './errors/abort-error.js';\nimport {isRedirect} from './utils/is-redirect.js';\nimport {FormData} from 'formdata-polyfill/esm.min.js';\nimport {isDomainOrSubdomain, isSameProtocol} from './utils/is.js';\nimport {parseReferrerPolicyFromHeader} from './utils/referrer.js';\nimport {\n\tBlob,\n\tFile,\n\tfileFromSync,\n\tfileFrom,\n\tblobFromSync,\n\tblobFrom\n} from 'fetch-blob/from.js';\n\nexport {FormData, Headers, Request, Response, FetchError, AbortError, isRedirect};\nexport {Blob, File, fileFromSync, fileFrom, blobFromSync, blobFrom};\n\nconst supportedSchemas = new Set(['data:', 'http:', 'https:']);\n\n/**\n * Fetch function\n *\n * @param {string | URL | import('./request').default} url - Absolute url or Request instance\n * @param {*} [options_] - Fetch options\n * @return {Promise<import('./response').default>}\n */\nexport default async function fetch(url, options_) {\n\treturn new Promise((resolve, reject) => {\n\t\t// Build request object\n\t\tconst request = new Request(url, options_);\n\t\tconst {parsedURL, options} = getNodeRequestOptions(request);\n\t\tif (!supportedSchemas.has(parsedURL.protocol)) {\n\t\t\tthrow new TypeError(`node-fetch cannot load ${url}. URL scheme \"${parsedURL.protocol.replace(/:$/, '')}\" is not supported.`);\n\t\t}\n\n\t\tif (parsedURL.protocol === 'data:') {\n\t\t\tconst data = dataUriToBuffer(request.url);\n\t\t\tconst response = new Response(data, {headers: {'Content-Type': data.typeFull}});\n\t\t\tresolve(response);\n\t\t\treturn;\n\t\t}\n\n\t\t// Wrap http.request into fetch\n\t\tconst send = (parsedURL.protocol === 'https:' ? https : http).request;\n\t\tconst {signal} = request;\n\t\tlet response = null;\n\n\t\tconst abort = () => {\n\t\t\tconst error = new AbortError('The operation was aborted.');\n\t\t\treject(error);\n\t\t\tif (request.body && request.body instanceof Stream.Readable) {\n\t\t\t\trequest.body.destroy(error);\n\t\t\t}\n\n\t\t\tif (!response || !response.body) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tresponse.body.emit('error', error);\n\t\t};\n\n\t\tif (signal && signal.aborted) {\n\t\t\tabort();\n\t\t\treturn;\n\t\t}\n\n\t\tconst abortAndFinalize = () => {\n\t\t\tabort();\n\t\t\tfinalize();\n\t\t};\n\n\t\t// Send request\n\t\tconst request_ = send(parsedURL.toString(), options);\n\n\t\tif (signal) {\n\t\t\tsignal.addEventListener('abort', abortAndFinalize);\n\t\t}\n\n\t\tconst finalize = () => {\n\t\t\trequest_.abort();\n\t\t\tif (signal) {\n\t\t\t\tsignal.removeEventListener('abort', abortAndFinalize);\n\t\t\t}\n\t\t};\n\n\t\trequest_.on('error', error => {\n\t\t\treject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));\n\t\t\tfinalize();\n\t\t});\n\n\t\tfixResponseChunkedTransferBadEnding(request_, error => {\n\t\t\tif (response && response.body) {\n\t\t\t\tresponse.body.destroy(error);\n\t\t\t}\n\t\t});\n\n\t\t/* c8 ignore next 18 */\n\t\tif (process.version < 'v14') {\n\t\t\t// Before Node.js 14, pipeline() does not fully support async iterators and does not always\n\t\t\t// properly handle when the socket close/end events are out of order.\n\t\t\trequest_.on('socket', s => {\n\t\t\t\tlet endedWithEventsCount;\n\t\t\t\ts.prependListener('end', () => {\n\t\t\t\t\tendedWithEventsCount = s._eventsCount;\n\t\t\t\t});\n\t\t\t\ts.prependListener('close', hadError => {\n\t\t\t\t\t// if end happened before close but the socket didn't emit an error, do it now\n\t\t\t\t\tif (response && endedWithEventsCount < s._eventsCount && !hadError) {\n\t\t\t\t\t\tconst error = new Error('Premature close');\n\t\t\t\t\t\terror.code = 'ERR_STREAM_PREMATURE_CLOSE';\n\t\t\t\t\t\tresponse.body.emit('error', error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\trequest_.on('response', response_ => {\n\t\t\trequest_.setTimeout(0);\n\t\t\tconst headers = fromRawHeaders(response_.rawHeaders);\n\n\t\t\t// HTTP fetch step 5\n\t\t\tif (isRedirect(response_.statusCode)) {\n\t\t\t\t// HTTP fetch step 5.2\n\t\t\t\tconst location = headers.get('Location');\n\n\t\t\t\t// HTTP fetch step 5.3\n\t\t\t\tlet locationURL = null;\n\t\t\t\ttry {\n\t\t\t\t\tlocationURL = location === null ? null : new URL(location, request.url);\n\t\t\t\t} catch {\n\t\t\t\t\t// error here can only be invalid URL in Location: header\n\t\t\t\t\t// do not throw when options.redirect == manual\n\t\t\t\t\t// let the user extract the errorneous redirect URL\n\t\t\t\t\tif (request.redirect !== 'manual') {\n\t\t\t\t\t\treject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));\n\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// HTTP fetch step 5.5\n\t\t\t\tswitch (request.redirect) {\n\t\t\t\t\tcase 'error':\n\t\t\t\t\t\treject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect'));\n\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\treturn;\n\t\t\t\t\tcase 'manual':\n\t\t\t\t\t\t// Nothing to do\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'follow': {\n\t\t\t\t\t\t// HTTP-redirect fetch step 2\n\t\t\t\t\t\tif (locationURL === null) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 5\n\t\t\t\t\t\tif (request.counter >= request.follow) {\n\t\t\t\t\t\t\treject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'));\n\t\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 6 (counter increment)\n\t\t\t\t\t\t// Create a new Request object.\n\t\t\t\t\t\tconst requestOptions = {\n\t\t\t\t\t\t\theaders: new Headers(request.headers),\n\t\t\t\t\t\t\tfollow: request.follow,\n\t\t\t\t\t\t\tcounter: request.counter + 1,\n\t\t\t\t\t\t\tagent: request.agent,\n\t\t\t\t\t\t\tcompress: request.compress,\n\t\t\t\t\t\t\tmethod: request.method,\n\t\t\t\t\t\t\tbody: clone(request),\n\t\t\t\t\t\t\tsignal: request.signal,\n\t\t\t\t\t\t\tsize: request.size,\n\t\t\t\t\t\t\treferrer: request.referrer,\n\t\t\t\t\t\t\treferrerPolicy: request.referrerPolicy\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// when forwarding sensitive headers like \"Authorization\",\n\t\t\t\t\t\t// \"WWW-Authenticate\", and \"Cookie\" to untrusted targets,\n\t\t\t\t\t\t// headers will be ignored when following a redirect to a domain\n\t\t\t\t\t\t// that is not a subdomain match or exact match of the initial domain.\n\t\t\t\t\t\t// For example, a redirect from \"foo.com\" to either \"foo.com\" or \"sub.foo.com\"\n\t\t\t\t\t\t// will forward the sensitive headers, but a redirect to \"bar.com\" will not.\n\t\t\t\t\t\t// headers will also be ignored when following a redirect to a domain using\n\t\t\t\t\t\t// a different protocol. For example, a redirect from \"https://foo.com\" to \"http://foo.com\"\n\t\t\t\t\t\t// will not forward the sensitive headers\n\t\t\t\t\t\tif (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {\n\t\t\t\t\t\t\tfor (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {\n\t\t\t\t\t\t\t\trequestOptions.headers.delete(name);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 9\n\t\t\t\t\t\tif (response_.statusCode !== 303 && request.body && options_.body instanceof Stream.Readable) {\n\t\t\t\t\t\t\treject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));\n\t\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 11\n\t\t\t\t\t\tif (response_.statusCode === 303 || ((response_.statusCode === 301 || response_.statusCode === 302) && request.method === 'POST')) {\n\t\t\t\t\t\t\trequestOptions.method = 'GET';\n\t\t\t\t\t\t\trequestOptions.body = undefined;\n\t\t\t\t\t\t\trequestOptions.headers.delete('content-length');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 14\n\t\t\t\t\t\tconst responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);\n\t\t\t\t\t\tif (responseReferrerPolicy) {\n\t\t\t\t\t\t\trequestOptions.referrerPolicy = responseReferrerPolicy;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 15\n\t\t\t\t\t\tresolve(fetch(new Request(locationURL, requestOptions)));\n\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Prepare response\n\t\t\tif (signal) {\n\t\t\t\tresponse_.once('end', () => {\n\t\t\t\t\tsignal.removeEventListener('abort', abortAndFinalize);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet body = pump(response_, new PassThrough(), error => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\t// see https://github.com/nodejs/node/pull/29376\n\t\t\t/* c8 ignore next 3 */\n\t\t\tif (process.version < 'v12.10') {\n\t\t\t\tresponse_.on('aborted', abortAndFinalize);\n\t\t\t}\n\n\t\t\tconst responseOptions = {\n\t\t\t\turl: request.url,\n\t\t\t\tstatus: response_.statusCode,\n\t\t\t\tstatusText: response_.statusMessage,\n\t\t\t\theaders,\n\t\t\t\tsize: request.size,\n\t\t\t\tcounter: request.counter,\n\t\t\t\thighWaterMark: request.highWaterMark\n\t\t\t};\n\n\t\t\t// HTTP-network fetch step 12.1.1.3\n\t\t\tconst codings = headers.get('Content-Encoding');\n\n\t\t\t// HTTP-network fetch step 12.1.1.4: handle content codings\n\n\t\t\t// in following scenarios we ignore compression support\n\t\t\t// 1. compression support is disabled\n\t\t\t// 2. HEAD request\n\t\t\t// 3. no Content-Encoding header\n\t\t\t// 4. no content response (204)\n\t\t\t// 5. content not modified response (304)\n\t\t\tif (!request.compress || request.method === 'HEAD' || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {\n\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\tresolve(response);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For Node v6+\n\t\t\t// Be less strict when decoding compressed responses, since sometimes\n\t\t\t// servers send slightly invalid responses that are still accepted\n\t\t\t// by common browsers.\n\t\t\t// Always using Z_SYNC_FLUSH is what cURL does.\n\t\t\tconst zlibOptions = {\n\t\t\t\tflush: zlib.Z_SYNC_FLUSH,\n\t\t\t\tfinishFlush: zlib.Z_SYNC_FLUSH\n\t\t\t};\n\n\t\t\t// For gzip\n\t\t\tif (codings === 'gzip' || codings === 'x-gzip') {\n\t\t\t\tbody = pump(body, zlib.createGunzip(zlibOptions), error => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\tresolve(response);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For deflate\n\t\t\tif (codings === 'deflate' || codings === 'x-deflate') {\n\t\t\t\t// Handle the infamous raw deflate response from old servers\n\t\t\t\t// a hack for old IIS and Apache servers\n\t\t\t\tconst raw = pump(response_, new PassThrough(), error => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\traw.once('data', chunk => {\n\t\t\t\t\t// See http://stackoverflow.com/questions/37519828\n\t\t\t\t\tif ((chunk[0] & 0x0F) === 0x08) {\n\t\t\t\t\t\tbody = pump(body, zlib.createInflate(), error => {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbody = pump(body, zlib.createInflateRaw(), error => {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\t\tresolve(response);\n\t\t\t\t});\n\t\t\t\traw.once('end', () => {\n\t\t\t\t\t// Some old IIS servers return zero-length OK deflate responses, so\n\t\t\t\t\t// 'data' is never emitted. See https://github.com/node-fetch/node-fetch/pull/903\n\t\t\t\t\tif (!response) {\n\t\t\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\t\t\tresolve(response);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For br\n\t\t\tif (codings === 'br') {\n\t\t\t\tbody = pump(body, zlib.createBrotliDecompress(), error => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\tresolve(response);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise, use response as-is\n\t\t\tresponse = new Response(body, responseOptions);\n\t\t\tresolve(response);\n\t\t});\n\n\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\twriteToStream(request_, request).catch(reject);\n\t});\n}\n\nfunction fixResponseChunkedTransferBadEnding(request, errorCallback) {\n\tconst LAST_CHUNK = Buffer.from('0\\r\\n\\r\\n');\n\n\tlet isChunkedTransfer = false;\n\tlet properLastChunkReceived = false;\n\tlet previousChunk;\n\n\trequest.on('response', response => {\n\t\tconst {headers} = response;\n\t\tisChunkedTransfer = headers['transfer-encoding'] === 'chunked' && !headers['content-length'];\n\t});\n\n\trequest.on('socket', socket => {\n\t\tconst onSocketClose = () => {\n\t\t\tif (isChunkedTransfer && !properLastChunkReceived) {\n\t\t\t\tconst error = new Error('Premature close');\n\t\t\t\terror.code = 'ERR_STREAM_PREMATURE_CLOSE';\n\t\t\t\terrorCallback(error);\n\t\t\t}\n\t\t};\n\n\t\tconst onData = buf => {\n\t\t\tproperLastChunkReceived = Buffer.compare(buf.slice(-5), LAST_CHUNK) === 0;\n\n\t\t\t// Sometimes final 0-length chunk and end of message code are in separate packets\n\t\t\tif (!properLastChunkReceived && previousChunk) {\n\t\t\t\tproperLastChunkReceived = (\n\t\t\t\t\tBuffer.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 &&\n\t\t\t\t\tBuffer.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpreviousChunk = buf;\n\t\t};\n\n\t\tsocket.prependListener('close', onSocketClose);\n\t\tsocket.on('data', onData);\n\n\t\trequest.on('close', () => {\n\t\t\tsocket.removeListener('close', onSocketClose);\n\t\t\tsocket.removeListener('data', onData);\n\t\t});\n\t});\n}\n"],"names":["response","http","pump"],"mappings":";;;;;;;;;;;;;;;;;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,gBAAgB;AAAA,EAC7F,CAAE;AAED,UAAQ,GAAG,UAAU,YAAU;AAC9B,UAAM,gBAAgB,MAAM;AAC3B,UAAI,qBAAqB,CAAC,yBAAyB;AAClD,cAAM,QAAQ,IAAI,MAAM,iBAAiB;AACzC,cAAM,OAAO;AACb,sBAAc,KAAK;AAAA,MACnB;AAAA,IACJ;AAEE,UAAM,SAAS,SAAO;AACrB,gCAA0B,OAAO,QAAQ,IAAI,MAAM,EAAE,GAAG,UAAU,MAAM;AAGxE,UAAI,CAAC,2BAA2B,eAAe;AAC9C,kCACC,OAAO,QAAQ,cAAc,MAAM,EAAE,GAAG,WAAW,MAAM,GAAG,CAAC,CAAC,MAAM,KACpE,OAAO,QAAQ,IAAI,MAAM,EAAE,GAAG,WAAW,MAAM,CAAC,CAAC,MAAM;AAAA,MAExD;AAED,sBAAgB;AAAA,IACnB;AAEE,WAAO,gBAAgB,SAAS,aAAa;AAC7C,WAAO,GAAG,QAAQ,MAAM;AAExB,YAAQ,GAAG,SAAS,MAAM;AACzB,aAAO,eAAe,SAAS,aAAa;AAC5C,aAAO,eAAe,QAAQ,MAAM;AAAA,IACvC,CAAG;AAAA,EACH,CAAE;AACF;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../node_modules/node-fetch/src/index.js"],"sourcesContent":["/**\n * Index.js\n *\n * a request API compatible with window.fetch\n *\n * All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.\n */\n\nimport http from 'node:http';\nimport https from 'node:https';\nimport zlib from 'node:zlib';\nimport Stream, {PassThrough, pipeline as pump} from 'node:stream';\nimport {Buffer} from 'node:buffer';\n\nimport dataUriToBuffer from 'data-uri-to-buffer';\n\nimport {writeToStream, clone} from './body.js';\nimport Response from './response.js';\nimport Headers, {fromRawHeaders} from './headers.js';\nimport Request, {getNodeRequestOptions} from './request.js';\nimport {FetchError} from './errors/fetch-error.js';\nimport {AbortError} from './errors/abort-error.js';\nimport {isRedirect} from './utils/is-redirect.js';\nimport {FormData} from 'formdata-polyfill/esm.min.js';\nimport {isDomainOrSubdomain, isSameProtocol} from './utils/is.js';\nimport {parseReferrerPolicyFromHeader} from './utils/referrer.js';\nimport {\n\tBlob,\n\tFile,\n\tfileFromSync,\n\tfileFrom,\n\tblobFromSync,\n\tblobFrom\n} from 'fetch-blob/from.js';\n\nexport {FormData, Headers, Request, Response, FetchError, AbortError, isRedirect};\nexport {Blob, File, fileFromSync, fileFrom, blobFromSync, blobFrom};\n\nconst supportedSchemas = new Set(['data:', 'http:', 'https:']);\n\n/**\n * Fetch function\n *\n * @param {string | URL | import('./request').default} url - Absolute url or Request instance\n * @param {*} [options_] - Fetch options\n * @return {Promise<import('./response').default>}\n */\nexport default async function fetch(url, options_) {\n\treturn new Promise((resolve, reject) => {\n\t\t// Build request object\n\t\tconst request = new Request(url, options_);\n\t\tconst {parsedURL, options} = getNodeRequestOptions(request);\n\t\tif (!supportedSchemas.has(parsedURL.protocol)) {\n\t\t\tthrow new TypeError(`node-fetch cannot load ${url}. URL scheme \"${parsedURL.protocol.replace(/:$/, '')}\" is not supported.`);\n\t\t}\n\n\t\tif (parsedURL.protocol === 'data:') {\n\t\t\tconst data = dataUriToBuffer(request.url);\n\t\t\tconst response = new Response(data, {headers: {'Content-Type': data.typeFull}});\n\t\t\tresolve(response);\n\t\t\treturn;\n\t\t}\n\n\t\t// Wrap http.request into fetch\n\t\tconst send = (parsedURL.protocol === 'https:' ? https : http).request;\n\t\tconst {signal} = request;\n\t\tlet response = null;\n\n\t\tconst abort = () => {\n\t\t\tconst error = new AbortError('The operation was aborted.');\n\t\t\treject(error);\n\t\t\tif (request.body && request.body instanceof Stream.Readable) {\n\t\t\t\trequest.body.destroy(error);\n\t\t\t}\n\n\t\t\tif (!response || !response.body) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tresponse.body.emit('error', error);\n\t\t};\n\n\t\tif (signal && signal.aborted) {\n\t\t\tabort();\n\t\t\treturn;\n\t\t}\n\n\t\tconst abortAndFinalize = () => {\n\t\t\tabort();\n\t\t\tfinalize();\n\t\t};\n\n\t\t// Send request\n\t\tconst request_ = send(parsedURL.toString(), options);\n\n\t\tif (signal) {\n\t\t\tsignal.addEventListener('abort', abortAndFinalize);\n\t\t}\n\n\t\tconst finalize = () => {\n\t\t\trequest_.abort();\n\t\t\tif (signal) {\n\t\t\t\tsignal.removeEventListener('abort', abortAndFinalize);\n\t\t\t}\n\t\t};\n\n\t\trequest_.on('error', error => {\n\t\t\treject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));\n\t\t\tfinalize();\n\t\t});\n\n\t\tfixResponseChunkedTransferBadEnding(request_, error => {\n\t\t\tif (response && response.body) {\n\t\t\t\tresponse.body.destroy(error);\n\t\t\t}\n\t\t});\n\n\t\t/* c8 ignore next 18 */\n\t\tif (process.version < 'v14') {\n\t\t\t// Before Node.js 14, pipeline() does not fully support async iterators and does not always\n\t\t\t// properly handle when the socket close/end events are out of order.\n\t\t\trequest_.on('socket', s => {\n\t\t\t\tlet endedWithEventsCount;\n\t\t\t\ts.prependListener('end', () => {\n\t\t\t\t\tendedWithEventsCount = s._eventsCount;\n\t\t\t\t});\n\t\t\t\ts.prependListener('close', hadError => {\n\t\t\t\t\t// if end happened before close but the socket didn't emit an error, do it now\n\t\t\t\t\tif (response && endedWithEventsCount < s._eventsCount && !hadError) {\n\t\t\t\t\t\tconst error = new Error('Premature close');\n\t\t\t\t\t\terror.code = 'ERR_STREAM_PREMATURE_CLOSE';\n\t\t\t\t\t\tresponse.body.emit('error', error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\trequest_.on('response', response_ => {\n\t\t\trequest_.setTimeout(0);\n\t\t\tconst headers = fromRawHeaders(response_.rawHeaders);\n\n\t\t\t// HTTP fetch step 5\n\t\t\tif (isRedirect(response_.statusCode)) {\n\t\t\t\t// HTTP fetch step 5.2\n\t\t\t\tconst location = headers.get('Location');\n\n\t\t\t\t// HTTP fetch step 5.3\n\t\t\t\tlet locationURL = null;\n\t\t\t\ttry {\n\t\t\t\t\tlocationURL = location === null ? null : new URL(location, request.url);\n\t\t\t\t} catch {\n\t\t\t\t\t// error here can only be invalid URL in Location: header\n\t\t\t\t\t// do not throw when options.redirect == manual\n\t\t\t\t\t// let the user extract the errorneous redirect URL\n\t\t\t\t\tif (request.redirect !== 'manual') {\n\t\t\t\t\t\treject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));\n\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// HTTP fetch step 5.5\n\t\t\t\tswitch (request.redirect) {\n\t\t\t\t\tcase 'error':\n\t\t\t\t\t\treject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect'));\n\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\treturn;\n\t\t\t\t\tcase 'manual':\n\t\t\t\t\t\t// Nothing to do\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'follow': {\n\t\t\t\t\t\t// HTTP-redirect fetch step 2\n\t\t\t\t\t\tif (locationURL === null) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 5\n\t\t\t\t\t\tif (request.counter >= request.follow) {\n\t\t\t\t\t\t\treject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'));\n\t\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 6 (counter increment)\n\t\t\t\t\t\t// Create a new Request object.\n\t\t\t\t\t\tconst requestOptions = {\n\t\t\t\t\t\t\theaders: new Headers(request.headers),\n\t\t\t\t\t\t\tfollow: request.follow,\n\t\t\t\t\t\t\tcounter: request.counter + 1,\n\t\t\t\t\t\t\tagent: request.agent,\n\t\t\t\t\t\t\tcompress: request.compress,\n\t\t\t\t\t\t\tmethod: request.method,\n\t\t\t\t\t\t\tbody: clone(request),\n\t\t\t\t\t\t\tsignal: request.signal,\n\t\t\t\t\t\t\tsize: request.size,\n\t\t\t\t\t\t\treferrer: request.referrer,\n\t\t\t\t\t\t\treferrerPolicy: request.referrerPolicy\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// when forwarding sensitive headers like \"Authorization\",\n\t\t\t\t\t\t// \"WWW-Authenticate\", and \"Cookie\" to untrusted targets,\n\t\t\t\t\t\t// headers will be ignored when following a redirect to a domain\n\t\t\t\t\t\t// that is not a subdomain match or exact match of the initial domain.\n\t\t\t\t\t\t// For example, a redirect from \"foo.com\" to either \"foo.com\" or \"sub.foo.com\"\n\t\t\t\t\t\t// will forward the sensitive headers, but a redirect to \"bar.com\" will not.\n\t\t\t\t\t\t// headers will also be ignored when following a redirect to a domain using\n\t\t\t\t\t\t// a different protocol. For example, a redirect from \"https://foo.com\" to \"http://foo.com\"\n\t\t\t\t\t\t// will not forward the sensitive headers\n\t\t\t\t\t\tif (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {\n\t\t\t\t\t\t\tfor (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {\n\t\t\t\t\t\t\t\trequestOptions.headers.delete(name);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 9\n\t\t\t\t\t\tif (response_.statusCode !== 303 && request.body && options_.body instanceof Stream.Readable) {\n\t\t\t\t\t\t\treject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));\n\t\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 11\n\t\t\t\t\t\tif (response_.statusCode === 303 || ((response_.statusCode === 301 || response_.statusCode === 302) && request.method === 'POST')) {\n\t\t\t\t\t\t\trequestOptions.method = 'GET';\n\t\t\t\t\t\t\trequestOptions.body = undefined;\n\t\t\t\t\t\t\trequestOptions.headers.delete('content-length');\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 14\n\t\t\t\t\t\tconst responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);\n\t\t\t\t\t\tif (responseReferrerPolicy) {\n\t\t\t\t\t\t\trequestOptions.referrerPolicy = responseReferrerPolicy;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// HTTP-redirect fetch step 15\n\t\t\t\t\t\tresolve(fetch(new Request(locationURL, requestOptions)));\n\t\t\t\t\t\tfinalize();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Prepare response\n\t\t\tif (signal) {\n\t\t\t\tresponse_.once('end', () => {\n\t\t\t\t\tsignal.removeEventListener('abort', abortAndFinalize);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet body = pump(response_, new PassThrough(), error => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\t// see https://github.com/nodejs/node/pull/29376\n\t\t\t/* c8 ignore next 3 */\n\t\t\tif (process.version < 'v12.10') {\n\t\t\t\tresponse_.on('aborted', abortAndFinalize);\n\t\t\t}\n\n\t\t\tconst responseOptions = {\n\t\t\t\turl: request.url,\n\t\t\t\tstatus: response_.statusCode,\n\t\t\t\tstatusText: response_.statusMessage,\n\t\t\t\theaders,\n\t\t\t\tsize: request.size,\n\t\t\t\tcounter: request.counter,\n\t\t\t\thighWaterMark: request.highWaterMark\n\t\t\t};\n\n\t\t\t// HTTP-network fetch step 12.1.1.3\n\t\t\tconst codings = headers.get('Content-Encoding');\n\n\t\t\t// HTTP-network fetch step 12.1.1.4: handle content codings\n\n\t\t\t// in following scenarios we ignore compression support\n\t\t\t// 1. compression support is disabled\n\t\t\t// 2. HEAD request\n\t\t\t// 3. no Content-Encoding header\n\t\t\t// 4. no content response (204)\n\t\t\t// 5. content not modified response (304)\n\t\t\tif (!request.compress || request.method === 'HEAD' || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {\n\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\tresolve(response);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For Node v6+\n\t\t\t// Be less strict when decoding compressed responses, since sometimes\n\t\t\t// servers send slightly invalid responses that are still accepted\n\t\t\t// by common browsers.\n\t\t\t// Always using Z_SYNC_FLUSH is what cURL does.\n\t\t\tconst zlibOptions = {\n\t\t\t\tflush: zlib.Z_SYNC_FLUSH,\n\t\t\t\tfinishFlush: zlib.Z_SYNC_FLUSH\n\t\t\t};\n\n\t\t\t// For gzip\n\t\t\tif (codings === 'gzip' || codings === 'x-gzip') {\n\t\t\t\tbody = pump(body, zlib.createGunzip(zlibOptions), error => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\tresolve(response);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For deflate\n\t\t\tif (codings === 'deflate' || codings === 'x-deflate') {\n\t\t\t\t// Handle the infamous raw deflate response from old servers\n\t\t\t\t// a hack for old IIS and Apache servers\n\t\t\t\tconst raw = pump(response_, new PassThrough(), error => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\traw.once('data', chunk => {\n\t\t\t\t\t// See http://stackoverflow.com/questions/37519828\n\t\t\t\t\tif ((chunk[0] & 0x0F) === 0x08) {\n\t\t\t\t\t\tbody = pump(body, zlib.createInflate(), error => {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbody = pump(body, zlib.createInflateRaw(), error => {\n\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\t\tresolve(response);\n\t\t\t\t});\n\t\t\t\traw.once('end', () => {\n\t\t\t\t\t// Some old IIS servers return zero-length OK deflate responses, so\n\t\t\t\t\t// 'data' is never emitted. See https://github.com/node-fetch/node-fetch/pull/903\n\t\t\t\t\tif (!response) {\n\t\t\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\t\t\tresolve(response);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For br\n\t\t\tif (codings === 'br') {\n\t\t\t\tbody = pump(body, zlib.createBrotliDecompress(), error => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tresponse = new Response(body, responseOptions);\n\t\t\t\tresolve(response);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise, use response as-is\n\t\t\tresponse = new Response(body, responseOptions);\n\t\t\tresolve(response);\n\t\t});\n\n\t\t// eslint-disable-next-line promise/prefer-await-to-then\n\t\twriteToStream(request_, request).catch(reject);\n\t});\n}\n\nfunction fixResponseChunkedTransferBadEnding(request, errorCallback) {\n\tconst LAST_CHUNK = Buffer.from('0\\r\\n\\r\\n');\n\n\tlet isChunkedTransfer = false;\n\tlet properLastChunkReceived = false;\n\tlet previousChunk;\n\n\trequest.on('response', response => {\n\t\tconst {headers} = response;\n\t\tisChunkedTransfer = headers['transfer-encoding'] === 'chunked' && !headers['content-length'];\n\t});\n\n\trequest.on('socket', socket => {\n\t\tconst onSocketClose = () => {\n\t\t\tif (isChunkedTransfer && !properLastChunkReceived) {\n\t\t\t\tconst error = new Error('Premature close');\n\t\t\t\terror.code = 'ERR_STREAM_PREMATURE_CLOSE';\n\t\t\t\terrorCallback(error);\n\t\t\t}\n\t\t};\n\n\t\tconst onData = buf => {\n\t\t\tproperLastChunkReceived = Buffer.compare(buf.slice(-5), LAST_CHUNK) === 0;\n\n\t\t\t// Sometimes final 0-length chunk and end of message code are in separate packets\n\t\t\tif (!properLastChunkReceived && previousChunk) {\n\t\t\t\tproperLastChunkReceived = (\n\t\t\t\t\tBuffer.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 &&\n\t\t\t\t\tBuffer.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tpreviousChunk = buf;\n\t\t};\n\n\t\tsocket.prependListener('close', onSocketClose);\n\t\tsocket.on('data', onData);\n\n\t\trequest.on('close', () => {\n\t\t\tsocket.removeListener('close', onSocketClose);\n\t\t\tsocket.removeListener('data', onData);\n\t\t});\n\t});\n}\n"],"names":["response","https","http","pump"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,MAAM,mBAAmB,oBAAI,IAAI,CAAC,SAAS,SAAS,QAAQ,CAAC;AAS9C,eAAe,MAAM,KAAK,UAAU;AAClD,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AAEvC,UAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,UAAM,EAAC,WAAW,QAAO,IAAI,sBAAsB,OAAO;AAC1D,QAAI,CAAC,iBAAiB,IAAI,UAAU,QAAQ,GAAG;AAC9C,YAAM,IAAI,UAAU,0BAA0B,oBAAoB,UAAU,SAAS,QAAQ,MAAM,EAAE,sBAAsB;AAAA,IAC3H;AAED,QAAI,UAAU,aAAa,SAAS;AACnC,YAAM,OAAO,gBAAgB,QAAQ,GAAG;AACxC,YAAMA,YAAW,IAAI,SAAS,MAAM,EAAC,SAAS,EAAC,gBAAgB,KAAK,SAAQ,EAAC,CAAC;A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EE,WAAO,gBAAgB,SAAS,aAAa;AAC7C,WAAO,GAAG,QAAQ,MAAM;AAExB,YAAQ,GAAG,SAAS,MAAM;AACzB,aAAO,eAAe,SAAS,aAAa;AAC5C,aAAO,eAAe,QAAQ,MAAM;AAAA,IACvC,CAAG;AAAA,EACH,CAAE;AACF;","x_google_ignoreList":[0]}
|
|
@@ -12,7 +12,7 @@ const path = require("node:path");
|
|
|
12
12
|
const os = require("node:os");
|
|
13
13
|
const http = require("node:http");
|
|
14
14
|
const h3 = require("h3");
|
|
15
|
-
const
|
|
15
|
+
const fetch = require("../lib/fetch.cjs");
|
|
16
16
|
const cookie = require("cookie");
|
|
17
17
|
const cors = require("cors");
|
|
18
18
|
const index = require('./../_node_modules/get-port/index.cjs');
|
|
@@ -163,7 +163,7 @@ class PrismicAuthManager {
|
|
|
163
163
|
url.searchParams.set("token", authState.cookies[AUTH_COOKIE_KEY]);
|
|
164
164
|
let res;
|
|
165
165
|
try {
|
|
166
|
-
res = await
|
|
166
|
+
res = await fetch.default(url.toString(), {
|
|
167
167
|
headers: {
|
|
168
168
|
"User-Agent": SLICE_MACHINE_USER_AGENT.SLICE_MACHINE_USER_AGENT
|
|
169
169
|
}
|
|
@@ -198,7 +198,7 @@ class PrismicAuthManager {
|
|
|
198
198
|
if (checkHasAuthenticationToken(authState)) {
|
|
199
199
|
const url = new URL("./refreshtoken", API_ENDPOINTS.API_ENDPOINTS.PrismicAuthentication);
|
|
200
200
|
url.searchParams.set("token", authState.cookies[AUTH_COOKIE_KEY]);
|
|
201
|
-
const res = await
|
|
201
|
+
const res = await fetch.default(url.toString(), {
|
|
202
202
|
headers: {
|
|
203
203
|
"User-Agent": SLICE_MACHINE_USER_AGENT.SLICE_MACHINE_USER_AGENT
|
|
204
204
|
}
|
|
@@ -222,7 +222,7 @@ class PrismicAuthManager {
|
|
|
222
222
|
}
|
|
223
223
|
async _getProfileForAuthenticationToken(args) {
|
|
224
224
|
const url = new URL("./profile", API_ENDPOINTS.API_ENDPOINTS.PrismicUser);
|
|
225
|
-
const res = await
|
|
225
|
+
const res = await fetch.default(url.toString(), {
|
|
226
226
|
headers: {
|
|
227
227
|
Authorization: `Bearer ${args.authenticationToken}`,
|
|
228
228
|
"User-Agent": SLICE_MACHINE_USER_AGENT.SLICE_MACHINE_USER_AGENT
|
|
@@ -242,19 +242,20 @@ class PrismicAuthManager {
|
|
|
242
242
|
async _readPersistedAuthState() {
|
|
243
243
|
const authStateFilePath = this._getPersistedAuthStateFilePath();
|
|
244
244
|
let authStateFileContents = JSON.stringify({});
|
|
245
|
+
let rawAuthState = {};
|
|
245
246
|
try {
|
|
246
247
|
authStateFileContents = await fs__namespace.readFile(authStateFilePath, "utf8");
|
|
248
|
+
rawAuthState = JSON.parse(authStateFileContents);
|
|
247
249
|
} catch {
|
|
248
|
-
|
|
250
|
+
rawAuthState = {
|
|
249
251
|
...DEFAULT_PERSISTED_AUTH_STATE,
|
|
250
252
|
cookies: serializeCookies.serializeCookies(DEFAULT_PERSISTED_AUTH_STATE.cookies)
|
|
251
253
|
};
|
|
252
|
-
authStateFileContents = JSON.stringify(
|
|
254
|
+
authStateFileContents = JSON.stringify(rawAuthState, null, " ");
|
|
253
255
|
await fs__namespace.mkdir(path__namespace.dirname(authStateFilePath), { recursive: true });
|
|
254
256
|
await fs__namespace.writeFile(authStateFilePath, authStateFileContents);
|
|
255
257
|
}
|
|
256
|
-
|
|
257
|
-
if ("cookies" in rawAuthState) {
|
|
258
|
+
if (typeof rawAuthState.cookies === "string") {
|
|
258
259
|
rawAuthState.cookies = parseCookies(rawAuthState.cookies);
|
|
259
260
|
}
|
|
260
261
|
const { value: authState, error } = decode.decode(PrismicAuthState, rawAuthState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicAuthManager.cjs","sources":["../../../src/auth/PrismicAuthManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\nimport * as http from \"node:http\";\n\nimport * as h3 from \"h3\";\nimport fetch from \"node-fetch\";\nimport cookie from \"cookie\";\nimport cors from \"cors\";\nimport getPort from \"get-port\";\n\nimport { decode } from \"../lib/decode\";\nimport { serializeCookies } from \"../lib/serializeCookies\";\n\nimport { API_ENDPOINTS } from \"../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../constants/SLICE_MACHINE_USER_AGENT\";\nimport { createPrismicAuthManagerMiddleware } from \"./createPrismicAuthManagerMiddleware\";\nimport {\n\tInternalError,\n\tUnauthenticatedError,\n\tUnexpectedDataError,\n} from \"../errors\";\n\nconst COOKIE_SEPARATOR = \"; \";\nconst AUTH_COOKIE_KEY = \"prismic-auth\";\nconst SESSION_COOKIE_KEY = \"SESSION\";\n\nconst PERSISTED_AUTH_STATE_FILE_NAME = \".prismic\";\nconst DEFAULT_PERSISTED_AUTH_STATE: PrismicAuthState = {\n\tbase: \"https://prismic.io\",\n\tcookies: {},\n};\n\nconst PrismicAuthState = t.intersection([\n\tt.type({\n\t\tbase: t.string,\n\t\tcookies: t.intersection([\n\t\t\tt.partial({\n\t\t\t\t[AUTH_COOKIE_KEY]: t.string,\n\t\t\t\tSESSION: t.string,\n\t\t\t}),\n\t\t\tt.record(t.string, t.string),\n\t\t]),\n\t}),\n\tt.partial({\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\toauthAccessToken: t.string,\n\t\tauthUrl: t.string,\n\t}),\n]);\nexport type PrismicAuthState = t.TypeOf<typeof PrismicAuthState>;\n\nconst PrismicUserProfile = t.exact(\n\tt.type({\n\t\tuserId: t.string,\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\temail: t.string,\n\t\tfirstName: t.string,\n\t\tlastName: t.string,\n\t}),\n);\nexport type PrismicUserProfile = t.TypeOf<typeof PrismicUserProfile>;\n\ntype PrismicAuthManagerConstructorArgs = {\n\tscopedDirectory?: string;\n};\n\ntype PrismicAuthManagerLoginArgs = {\n\temail: string;\n\tcookies: string[];\n};\n\ntype PrismicAuthManagerGetLoginSessionInfoReturnType = {\n\tport: number;\n\turl: string;\n};\n\ntype PrismicAuthManagerNodeLoginSessionArgs = {\n\tport: number;\n\tonListenCallback?: () => void;\n};\n\ntype GetProfileForAuthenticationTokenArgs = {\n\tauthenticationToken: string;\n};\n\nconst checkHasAuthenticationToken = (\n\tauthState: PrismicAuthState,\n): authState is PrismicAuthState & {\n\tcookies: Required<\n\t\tPick<\n\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t>\n\t>;\n} => {\n\treturn Boolean(\n\t\tauthState.cookies[AUTH_COOKIE_KEY] && authState.cookies[SESSION_COOKIE_KEY],\n\t);\n};\n\nconst parseCookies = (cookies: string): Record<string, string> => {\n\treturn cookie.parse(cookies, {\n\t\t// Don't escape any values.\n\t\tdecode: (value) => value,\n\t});\n};\n\nexport class PrismicAuthManager {\n\t// TODO: Automatically scope the manager to the current Slice Machine\n\t// project? If not, this internal state can be removed.\n\tscopedDirectory: string;\n\n\tconstructor({\n\t\tscopedDirectory = os.homedir(),\n\t}: PrismicAuthManagerConstructorArgs = {}) {\n\t\tthis.scopedDirectory = scopedDirectory;\n\t}\n\n\t// TODO: Make the `cookies` argument more explicit. What are these\n\t// mysterious cookies?\n\tasync login(args: PrismicAuthManagerLoginArgs): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Set the auth's URL base to the current base at runtime.\n\t\tauthState.base = API_ENDPOINTS.PrismicWroom;\n\t\tauthState.cookies = {\n\t\t\t...authState.cookies,\n\t\t\t...parseCookies(args.cookies.join(COOKIE_SEPARATOR)),\n\t\t};\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst authenticationToken = authState.cookies[AUTH_COOKIE_KEY];\n\t\t\tconst profile = await this._getProfileForAuthenticationToken({\n\t\t\t\tauthenticationToken,\n\t\t\t});\n\n\t\t\tauthState.shortId = profile.shortId;\n\t\t\tauthState.intercomHash = profile.intercomHash;\n\t\t}\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync getLoginSessionInfo(): Promise<PrismicAuthManagerGetLoginSessionInfoReturnType> {\n\t\t// Pick a random port, with a preference for historic `5555`\n\t\tconst port = await getPort({ port: 5555 });\n\n\t\tconst url = new URL(\n\t\t\t`./dashboard/cli/login?source=slice-machine&port=${port}`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t).toString();\n\n\t\treturn {\n\t\t\tport,\n\t\t\turl,\n\t\t};\n\t}\n\n\tasync nodeLoginSession(\n\t\targs: PrismicAuthManagerNodeLoginSessionArgs,\n\t): Promise<void> {\n\t\treturn new Promise<void>(async (resolve) => {\n\t\t\t// Timeout attempt after 3 minutes\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tserver.close();\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Login timeout, server did not receive a response within a 3-minute delay\",\n\t\t\t\t);\n\t\t\t}, 180_000);\n\n\t\t\tconst app = h3.createApp();\n\t\t\tapp.use(h3.fromNodeMiddleware(cors()));\n\t\t\tapp.use(\n\t\t\t\th3.fromNodeMiddleware(\n\t\t\t\t\tcreatePrismicAuthManagerMiddleware({\n\t\t\t\t\t\tprismicAuthManager: this,\n\t\t\t\t\t\tonLoginCallback() {\n\t\t\t\t\t\t\t// Cleanup process and resolve\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tserver.close();\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\t// Start server\n\t\t\tconst server = http.createServer(h3.toNodeListener(app));\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tserver.once(\"listening\", () => {\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t\tserver.listen(args.port);\n\t\t\t});\n\n\t\t\tif (args.onListenCallback) {\n\t\t\t\targs.onListenCallback();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync logout(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Remove all Prismic cookies, short ID, and Intercom hash\n\t\t// associated with the currently logged in user.\n\t\tauthState.cookies = {};\n\t\tauthState.shortId = undefined;\n\t\tauthState.intercomHash = undefined;\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync checkIsLoggedIn(): Promise<boolean> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\"./validate\", API_ENDPOINTS.PrismicAuthentication);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tlet res;\n\t\t\ttry {\n\t\t\t\tres = await fetch(url.toString(), {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined.\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\tawait this.logout();\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync getAuthenticationCookies(): Promise<\n\t\tPrismicAuthState[\"cookies\"] &\n\t\t\tRequired<\n\t\t\t\tPick<\n\t\t\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t\t\t>\n\t\t\t>\n\t> {\n\t\tconst isLoggedIn = await this.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\t\treturn authState.cookies;\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\"Not logged in.\");\n\t}\n\n\tasync getAuthenticationToken(): Promise<string> {\n\t\tconst cookies = await this.getAuthenticationCookies();\n\n\t\treturn cookies[AUTH_COOKIE_KEY];\n\t}\n\n\tasync refreshAuthenticationToken(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\n\t\t\t\t\"./refreshtoken\",\n\t\t\t\tAPI_ENDPOINTS.PrismicAuthentication,\n\t\t\t);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tconst res = await fetch(url.toString(), {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst text = await res.text();\n\n\t\t\tif (res.ok) {\n\t\t\t\tauthState.cookies[AUTH_COOKIE_KEY] = text;\n\n\t\t\t\tawait this._writePersistedAuthState(authState);\n\t\t\t} else {\n\t\t\t\tthrow new InternalError(\"Failed to refresh authentication token.\");\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\t}\n\n\tasync getProfile(): Promise<PrismicUserProfile> {\n\t\tconst authenticationToken = await this.getAuthenticationToken();\n\n\t\treturn await this._getProfileForAuthenticationToken({\n\t\t\tauthenticationToken,\n\t\t});\n\t}\n\n\tprivate async _getProfileForAuthenticationToken(\n\t\targs: GetProfileForAuthenticationTokenArgs,\n\t): Promise<PrismicUserProfile> {\n\t\tconst url = new URL(\"./profile\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await fetch(url.toString(), {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${args.authenticationToken}`,\n\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t},\n\t\t});\n\t\tconst json = await res.json();\n\n\t\tif (res.ok) {\n\t\t\tconst { value: profile, error } = decode(PrismicUserProfile, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\"Received invalid data from the Prismic user service.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn profile;\n\t\t} else {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to retrieve profile from the Prismic user service.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async _readPersistedAuthState(): Promise<PrismicAuthState> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tlet authStateFileContents: string = JSON.stringify({});\n\n\t\ttry {\n\t\t\tauthStateFileContents = await fs.readFile(authStateFilePath, \"utf8\");\n\t\t} catch {\n\t\t\t// Write a default persisted state if it doesn't already exist.\n\n\t\t\tconst defaultStateFileContents = {\n\t\t\t\t...DEFAULT_PERSISTED_AUTH_STATE,\n\t\t\t\tcookies: serializeCookies(DEFAULT_PERSISTED_AUTH_STATE.cookies),\n\t\t\t};\n\t\t\tauthStateFileContents = JSON.stringify(\n\t\t\t\tdefaultStateFileContents,\n\t\t\t\tnull,\n\t\t\t\t\"\\t\",\n\t\t\t);\n\n\t\t\tawait fs.mkdir(path.dirname(authStateFilePath), { recursive: true });\n\t\t\tawait fs.writeFile(authStateFilePath, authStateFileContents);\n\t\t}\n\n\t\tconst rawAuthState = JSON.parse(authStateFileContents);\n\n\t\t// Decode cookies into a record for convenience.\n\t\tif (\"cookies\" in rawAuthState) {\n\t\t\trawAuthState.cookies = parseCookies(rawAuthState.cookies);\n\t\t}\n\n\t\tconst { value: authState, error } = decode(PrismicAuthState, rawAuthState);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\"Prismic authentication state is invalid.\");\n\t\t}\n\n\t\treturn authState;\n\t}\n\n\tprivate async _writePersistedAuthState(\n\t\tauthState: PrismicAuthState,\n\t): Promise<void> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tconst preparedAuthState = {\n\t\t\t...authState,\n\t\t\tcookies: serializeCookies(authState.cookies),\n\t\t};\n\n\t\ttry {\n\t\t\tawait fs.writeFile(\n\t\t\t\tauthStateFilePath,\n\t\t\t\tJSON.stringify(preparedAuthState, null, 2),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to write Prismic authentication state to the file system.\",\n\t\t\t\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate _getPersistedAuthStateFilePath(): string {\n\t\treturn path.resolve(this.scopedDirectory, PERSISTED_AUTH_STATE_FILE_NAME);\n\t}\n}\n"],"names":["t","os","API_ENDPOINTS","getPort","h3","createPrismicAuthManagerMiddleware","http","resolve","fetch","SLICE_MACHINE_USER_AGENT","InternalError","UnauthenticatedError","decode","UnexpectedDataError","fs","serializeCookies","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAE3B,MAAM,iCAAiC;AACvC,MAAM,+BAAiD;AAAA,EACtD,MAAM;AAAA,EACN,SAAS,CAAE;;AAGZ,MAAM,mBAAmBA,aAAE,aAAa;AAAA,EACvCA,aAAE,KAAK;AAAA,IACN,MAAMA,aAAE;AAAA,IACR,SAASA,aAAE,aAAa;AAAA,MACvBA,aAAE,QAAQ;AAAA,QACT,CAAC,eAAe,GAAGA,aAAE;AAAA,QACrB,SAASA,aAAE;AAAA,MAAA,CACX;AAAA,MACDA,aAAE,OAAOA,aAAE,QAAQA,aAAE,MAAM;AAAA,IAAA,CAC3B;AAAA,EAAA,CACD;AAAA,EACDA,aAAE,QAAQ;AAAA,IACT,SAASA,aAAE;AAAA,IACX,cAAcA,aAAE;AAAA,IAChB,kBAAkBA,aAAE;AAAA,IACpB,SAASA,aAAE;AAAA,EAAA,CACX;AACD,CAAA;AAGD,MAAM,qBAAqBA,aAAE,MAC5BA,aAAE,KAAK;AAAA,EACN,QAAQA,aAAE;AAAA,EACV,SAASA,aAAE;AAA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AA;AACG,YAAAD,cAAG,UACR,mBACA,KAAK,UAAU,mBAAmB,MAAM,CAAC,CAAC;AAAA,aAEnC;AACF,YAAA,IAAIJ,qBACT,oEACA;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,iCAA8B;AACrC,WAAOM,gBAAK,QAAQ,KAAK,iBAAiB,8BAA8B;AAAA,EACzE;AACA;;"}
|
|
1
|
+
{"version":3,"file":"PrismicAuthManager.cjs","sources":["../../../src/auth/PrismicAuthManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\nimport * as http from \"node:http\";\n\nimport * as h3 from \"h3\";\nimport fetch from \"../lib/fetch\";\nimport cookie from \"cookie\";\nimport cors from \"cors\";\nimport getPort from \"get-port\";\n\nimport { decode } from \"../lib/decode\";\nimport { serializeCookies } from \"../lib/serializeCookies\";\n\nimport { API_ENDPOINTS } from \"../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../constants/SLICE_MACHINE_USER_AGENT\";\nimport { createPrismicAuthManagerMiddleware } from \"./createPrismicAuthManagerMiddleware\";\nimport {\n\tInternalError,\n\tUnauthenticatedError,\n\tUnexpectedDataError,\n} from \"../errors\";\n\nconst COOKIE_SEPARATOR = \"; \";\nconst AUTH_COOKIE_KEY = \"prismic-auth\";\nconst SESSION_COOKIE_KEY = \"SESSION\";\n\nconst PERSISTED_AUTH_STATE_FILE_NAME = \".prismic\";\nconst DEFAULT_PERSISTED_AUTH_STATE: PrismicAuthState = {\n\tbase: \"https://prismic.io\",\n\tcookies: {},\n};\n\nconst PrismicAuthState = t.intersection([\n\tt.type({\n\t\tbase: t.string,\n\t\tcookies: t.intersection([\n\t\t\tt.partial({\n\t\t\t\t[AUTH_COOKIE_KEY]: t.string,\n\t\t\t\tSESSION: t.string,\n\t\t\t}),\n\t\t\tt.record(t.string, t.string),\n\t\t]),\n\t}),\n\tt.partial({\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\toauthAccessToken: t.string,\n\t\tauthUrl: t.string,\n\t}),\n]);\nexport type PrismicAuthState = t.TypeOf<typeof PrismicAuthState>;\n\nconst PrismicUserProfile = t.exact(\n\tt.type({\n\t\tuserId: t.string,\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\temail: t.string,\n\t\tfirstName: t.string,\n\t\tlastName: t.string,\n\t}),\n);\nexport type PrismicUserProfile = t.TypeOf<typeof PrismicUserProfile>;\n\ntype PrismicAuthManagerConstructorArgs = {\n\tscopedDirectory?: string;\n};\n\ntype PrismicAuthManagerLoginArgs = {\n\temail: string;\n\tcookies: string[];\n};\n\ntype PrismicAuthManagerGetLoginSessionInfoReturnType = {\n\tport: number;\n\turl: string;\n};\n\ntype PrismicAuthManagerNodeLoginSessionArgs = {\n\tport: number;\n\tonListenCallback?: () => void;\n};\n\ntype GetProfileForAuthenticationTokenArgs = {\n\tauthenticationToken: string;\n};\n\nconst checkHasAuthenticationToken = (\n\tauthState: PrismicAuthState,\n): authState is PrismicAuthState & {\n\tcookies: Required<\n\t\tPick<\n\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t>\n\t>;\n} => {\n\treturn Boolean(\n\t\tauthState.cookies[AUTH_COOKIE_KEY] && authState.cookies[SESSION_COOKIE_KEY],\n\t);\n};\n\nconst parseCookies = (cookies: string): Record<string, string> => {\n\treturn cookie.parse(cookies, {\n\t\t// Don't escape any values.\n\t\tdecode: (value) => value,\n\t});\n};\n\nexport class PrismicAuthManager {\n\t// TODO: Automatically scope the manager to the current Slice Machine\n\t// project? If not, this internal state can be removed.\n\tscopedDirectory: string;\n\n\tconstructor({\n\t\tscopedDirectory = os.homedir(),\n\t}: PrismicAuthManagerConstructorArgs = {}) {\n\t\tthis.scopedDirectory = scopedDirectory;\n\t}\n\n\t// TODO: Make the `cookies` argument more explicit. What are these\n\t// mysterious cookies?\n\tasync login(args: PrismicAuthManagerLoginArgs): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Set the auth's URL base to the current base at runtime.\n\t\tauthState.base = API_ENDPOINTS.PrismicWroom;\n\t\tauthState.cookies = {\n\t\t\t...authState.cookies,\n\t\t\t...parseCookies(args.cookies.join(COOKIE_SEPARATOR)),\n\t\t};\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst authenticationToken = authState.cookies[AUTH_COOKIE_KEY];\n\t\t\tconst profile = await this._getProfileForAuthenticationToken({\n\t\t\t\tauthenticationToken,\n\t\t\t});\n\n\t\t\tauthState.shortId = profile.shortId;\n\t\t\tauthState.intercomHash = profile.intercomHash;\n\t\t}\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync getLoginSessionInfo(): Promise<PrismicAuthManagerGetLoginSessionInfoReturnType> {\n\t\t// Pick a random port, with a preference for historic `5555`\n\t\tconst port = await getPort({ port: 5555 });\n\n\t\tconst url = new URL(\n\t\t\t`./dashboard/cli/login?source=slice-machine&port=${port}`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t).toString();\n\n\t\treturn {\n\t\t\tport,\n\t\t\turl,\n\t\t};\n\t}\n\n\tasync nodeLoginSession(\n\t\targs: PrismicAuthManagerNodeLoginSessionArgs,\n\t): Promise<void> {\n\t\treturn new Promise<void>(async (resolve) => {\n\t\t\t// Timeout attempt after 3 minutes\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tserver.close();\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Login timeout, server did not receive a response within a 3-minute delay\",\n\t\t\t\t);\n\t\t\t}, 180_000);\n\n\t\t\tconst app = h3.createApp();\n\t\t\tapp.use(h3.fromNodeMiddleware(cors()));\n\t\t\tapp.use(\n\t\t\t\th3.fromNodeMiddleware(\n\t\t\t\t\tcreatePrismicAuthManagerMiddleware({\n\t\t\t\t\t\tprismicAuthManager: this,\n\t\t\t\t\t\tonLoginCallback() {\n\t\t\t\t\t\t\t// Cleanup process and resolve\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tserver.close();\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\t// Start server\n\t\t\tconst server = http.createServer(h3.toNodeListener(app));\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tserver.once(\"listening\", () => {\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t\tserver.listen(args.port);\n\t\t\t});\n\n\t\t\tif (args.onListenCallback) {\n\t\t\t\targs.onListenCallback();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync logout(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Remove all Prismic cookies, short ID, and Intercom hash\n\t\t// associated with the currently logged in user.\n\t\tauthState.cookies = {};\n\t\tauthState.shortId = undefined;\n\t\tauthState.intercomHash = undefined;\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync checkIsLoggedIn(): Promise<boolean> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\"./validate\", API_ENDPOINTS.PrismicAuthentication);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tlet res;\n\t\t\ttry {\n\t\t\t\tres = await fetch(url.toString(), {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined.\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\tawait this.logout();\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync getAuthenticationCookies(): Promise<\n\t\tPrismicAuthState[\"cookies\"] &\n\t\t\tRequired<\n\t\t\t\tPick<\n\t\t\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t\t\t>\n\t\t\t>\n\t> {\n\t\tconst isLoggedIn = await this.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\t\treturn authState.cookies;\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\"Not logged in.\");\n\t}\n\n\tasync getAuthenticationToken(): Promise<string> {\n\t\tconst cookies = await this.getAuthenticationCookies();\n\n\t\treturn cookies[AUTH_COOKIE_KEY];\n\t}\n\n\tasync refreshAuthenticationToken(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\n\t\t\t\t\"./refreshtoken\",\n\t\t\t\tAPI_ENDPOINTS.PrismicAuthentication,\n\t\t\t);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tconst res = await fetch(url.toString(), {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst text = await res.text();\n\n\t\t\tif (res.ok) {\n\t\t\t\tauthState.cookies[AUTH_COOKIE_KEY] = text;\n\n\t\t\t\tawait this._writePersistedAuthState(authState);\n\t\t\t} else {\n\t\t\t\tthrow new InternalError(\"Failed to refresh authentication token.\");\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\t}\n\n\tasync getProfile(): Promise<PrismicUserProfile> {\n\t\tconst authenticationToken = await this.getAuthenticationToken();\n\n\t\treturn await this._getProfileForAuthenticationToken({\n\t\t\tauthenticationToken,\n\t\t});\n\t}\n\n\tprivate async _getProfileForAuthenticationToken(\n\t\targs: GetProfileForAuthenticationTokenArgs,\n\t): Promise<PrismicUserProfile> {\n\t\tconst url = new URL(\"./profile\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await fetch(url.toString(), {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${args.authenticationToken}`,\n\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t},\n\t\t});\n\t\tconst json = await res.json();\n\n\t\tif (res.ok) {\n\t\t\tconst { value: profile, error } = decode(PrismicUserProfile, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\"Received invalid data from the Prismic user service.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn profile;\n\t\t} else {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to retrieve profile from the Prismic user service.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async _readPersistedAuthState(): Promise<PrismicAuthState> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tlet authStateFileContents: string = JSON.stringify({});\n\t\tlet rawAuthState: Record<string, unknown> = {};\n\n\t\ttry {\n\t\t\tauthStateFileContents = await fs.readFile(authStateFilePath, \"utf8\");\n\t\t\trawAuthState = JSON.parse(authStateFileContents);\n\t\t} catch {\n\t\t\t// Write a default persisted state if it doesn't already exist.\n\n\t\t\trawAuthState = {\n\t\t\t\t...DEFAULT_PERSISTED_AUTH_STATE,\n\t\t\t\tcookies: serializeCookies(DEFAULT_PERSISTED_AUTH_STATE.cookies),\n\t\t\t};\n\t\t\tauthStateFileContents = JSON.stringify(rawAuthState, null, \"\\t\");\n\n\t\t\tawait fs.mkdir(path.dirname(authStateFilePath), { recursive: true });\n\t\t\tawait fs.writeFile(authStateFilePath, authStateFileContents);\n\t\t}\n\n\t\t// Decode cookies into a record for convenience.\n\t\tif (typeof rawAuthState.cookies === \"string\") {\n\t\t\trawAuthState.cookies = parseCookies(rawAuthState.cookies);\n\t\t}\n\n\t\tconst { value: authState, error } = decode(PrismicAuthState, rawAuthState);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\"Prismic authentication state is invalid.\");\n\t\t}\n\n\t\treturn authState;\n\t}\n\n\tprivate async _writePersistedAuthState(\n\t\tauthState: PrismicAuthState,\n\t): Promise<void> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tconst preparedAuthState = {\n\t\t\t...authState,\n\t\t\tcookies: serializeCookies(authState.cookies),\n\t\t};\n\n\t\ttry {\n\t\t\tawait fs.writeFile(\n\t\t\t\tauthStateFilePath,\n\t\t\t\tJSON.stringify(preparedAuthState, null, 2),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to write Prismic authentication state to the file system.\",\n\t\t\t\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate _getPersistedAuthStateFilePath(): string {\n\t\treturn path.resolve(this.scopedDirectory, PERSISTED_AUTH_STATE_FILE_NAME);\n\t}\n}\n"],"names":["t","os","API_ENDPOINTS","getPort","h3","createPrismicAuthManagerMiddleware","http","resolve","fetch","SLICE_MACHINE_USER_AGENT","InternalError","UnauthenticatedError","decode","UnexpectedDataError","fs","serializeCookies","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAE3B,MAAM,iCAAiC;AACvC,MAAM,+BAAiD;AAAA,EACtD,MAAM;AAAA,EACN,SAAS,CAAE;;AAGZ,MAAM,mBAAmBA,aAAE,aAAa;AAAA,EACvCA,aAAE,KAAK;AAAA,IACN,MAAMA,aAAE;AAAA,IACR,SAASA,aAAE,aAAa;AAAA,MACvBA,aAAE,QAAQ;AAAA,QACT,C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;AAAA,IAC3D;AAGG,QAAA,OAAO,aAAa,YAAY,UAAU;AAChC,mBAAA,UAAU,aAAa,aAAa,OAAO;AAAA,IACxD;AAED,UAAM,EAAE,OAAO,WAAW,MAAU,IAAAF,cAAO,kBAAkB,YAAY;AAEzE,QAAI,OAAO;AACJ,YAAA,IAAIC,OAAAA,oBAAoB,0CAA0C;AAAA,IACxE;AAEM,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,yBACb,WAA2B;AAErB,UAAA,oBAAoB,KAAK;AAE/B,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,SAASE,iBAAAA,iBAAiB,UAAU,OAAO;AAAA,IAAA;AAGxC,QAAA;AACG,YAAAD,cAAG,UACR,mBACA,KAAK,UAAU,mBAAmB,MAAM,CAAC,CAAC;AAAA,aAEnC;AACF,YAAA,IAAIJ,qBACT,oEACA;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,iCAA8B;AACrC,WAAOM,gBAAK,QAAQ,KAAK,iBAAiB,8BAA8B;AAAA,EACzE;AACA;;"}
|
|
@@ -10,7 +10,7 @@ import * as path from "node:path";
|
|
|
10
10
|
import * as os from "node:os";
|
|
11
11
|
import * as http from "node:http";
|
|
12
12
|
import * as h3 from "h3";
|
|
13
|
-
import fetch from
|
|
13
|
+
import fetch from "../lib/fetch.js";
|
|
14
14
|
import cookie from "cookie";
|
|
15
15
|
import cors from "cors";
|
|
16
16
|
import getPorts from './../_node_modules/get-port/index.js';
|
|
@@ -218,19 +218,20 @@ class PrismicAuthManager {
|
|
|
218
218
|
async _readPersistedAuthState() {
|
|
219
219
|
const authStateFilePath = this._getPersistedAuthStateFilePath();
|
|
220
220
|
let authStateFileContents = JSON.stringify({});
|
|
221
|
+
let rawAuthState = {};
|
|
221
222
|
try {
|
|
222
223
|
authStateFileContents = await fs.readFile(authStateFilePath, "utf8");
|
|
224
|
+
rawAuthState = JSON.parse(authStateFileContents);
|
|
223
225
|
} catch {
|
|
224
|
-
|
|
226
|
+
rawAuthState = {
|
|
225
227
|
...DEFAULT_PERSISTED_AUTH_STATE,
|
|
226
228
|
cookies: serializeCookies(DEFAULT_PERSISTED_AUTH_STATE.cookies)
|
|
227
229
|
};
|
|
228
|
-
authStateFileContents = JSON.stringify(
|
|
230
|
+
authStateFileContents = JSON.stringify(rawAuthState, null, " ");
|
|
229
231
|
await fs.mkdir(path.dirname(authStateFilePath), { recursive: true });
|
|
230
232
|
await fs.writeFile(authStateFilePath, authStateFileContents);
|
|
231
233
|
}
|
|
232
|
-
|
|
233
|
-
if ("cookies" in rawAuthState) {
|
|
234
|
+
if (typeof rawAuthState.cookies === "string") {
|
|
234
235
|
rawAuthState.cookies = parseCookies(rawAuthState.cookies);
|
|
235
236
|
}
|
|
236
237
|
const { value: authState, error } = decode(PrismicAuthState, rawAuthState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicAuthManager.js","sources":["../../../src/auth/PrismicAuthManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\nimport * as http from \"node:http\";\n\nimport * as h3 from \"h3\";\nimport fetch from \"node-fetch\";\nimport cookie from \"cookie\";\nimport cors from \"cors\";\nimport getPort from \"get-port\";\n\nimport { decode } from \"../lib/decode\";\nimport { serializeCookies } from \"../lib/serializeCookies\";\n\nimport { API_ENDPOINTS } from \"../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../constants/SLICE_MACHINE_USER_AGENT\";\nimport { createPrismicAuthManagerMiddleware } from \"./createPrismicAuthManagerMiddleware\";\nimport {\n\tInternalError,\n\tUnauthenticatedError,\n\tUnexpectedDataError,\n} from \"../errors\";\n\nconst COOKIE_SEPARATOR = \"; \";\nconst AUTH_COOKIE_KEY = \"prismic-auth\";\nconst SESSION_COOKIE_KEY = \"SESSION\";\n\nconst PERSISTED_AUTH_STATE_FILE_NAME = \".prismic\";\nconst DEFAULT_PERSISTED_AUTH_STATE: PrismicAuthState = {\n\tbase: \"https://prismic.io\",\n\tcookies: {},\n};\n\nconst PrismicAuthState = t.intersection([\n\tt.type({\n\t\tbase: t.string,\n\t\tcookies: t.intersection([\n\t\t\tt.partial({\n\t\t\t\t[AUTH_COOKIE_KEY]: t.string,\n\t\t\t\tSESSION: t.string,\n\t\t\t}),\n\t\t\tt.record(t.string, t.string),\n\t\t]),\n\t}),\n\tt.partial({\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\toauthAccessToken: t.string,\n\t\tauthUrl: t.string,\n\t}),\n]);\nexport type PrismicAuthState = t.TypeOf<typeof PrismicAuthState>;\n\nconst PrismicUserProfile = t.exact(\n\tt.type({\n\t\tuserId: t.string,\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\temail: t.string,\n\t\tfirstName: t.string,\n\t\tlastName: t.string,\n\t}),\n);\nexport type PrismicUserProfile = t.TypeOf<typeof PrismicUserProfile>;\n\ntype PrismicAuthManagerConstructorArgs = {\n\tscopedDirectory?: string;\n};\n\ntype PrismicAuthManagerLoginArgs = {\n\temail: string;\n\tcookies: string[];\n};\n\ntype PrismicAuthManagerGetLoginSessionInfoReturnType = {\n\tport: number;\n\turl: string;\n};\n\ntype PrismicAuthManagerNodeLoginSessionArgs = {\n\tport: number;\n\tonListenCallback?: () => void;\n};\n\ntype GetProfileForAuthenticationTokenArgs = {\n\tauthenticationToken: string;\n};\n\nconst checkHasAuthenticationToken = (\n\tauthState: PrismicAuthState,\n): authState is PrismicAuthState & {\n\tcookies: Required<\n\t\tPick<\n\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t>\n\t>;\n} => {\n\treturn Boolean(\n\t\tauthState.cookies[AUTH_COOKIE_KEY] && authState.cookies[SESSION_COOKIE_KEY],\n\t);\n};\n\nconst parseCookies = (cookies: string): Record<string, string> => {\n\treturn cookie.parse(cookies, {\n\t\t// Don't escape any values.\n\t\tdecode: (value) => value,\n\t});\n};\n\nexport class PrismicAuthManager {\n\t// TODO: Automatically scope the manager to the current Slice Machine\n\t// project? If not, this internal state can be removed.\n\tscopedDirectory: string;\n\n\tconstructor({\n\t\tscopedDirectory = os.homedir(),\n\t}: PrismicAuthManagerConstructorArgs = {}) {\n\t\tthis.scopedDirectory = scopedDirectory;\n\t}\n\n\t// TODO: Make the `cookies` argument more explicit. What are these\n\t// mysterious cookies?\n\tasync login(args: PrismicAuthManagerLoginArgs): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Set the auth's URL base to the current base at runtime.\n\t\tauthState.base = API_ENDPOINTS.PrismicWroom;\n\t\tauthState.cookies = {\n\t\t\t...authState.cookies,\n\t\t\t...parseCookies(args.cookies.join(COOKIE_SEPARATOR)),\n\t\t};\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst authenticationToken = authState.cookies[AUTH_COOKIE_KEY];\n\t\t\tconst profile = await this._getProfileForAuthenticationToken({\n\t\t\t\tauthenticationToken,\n\t\t\t});\n\n\t\t\tauthState.shortId = profile.shortId;\n\t\t\tauthState.intercomHash = profile.intercomHash;\n\t\t}\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync getLoginSessionInfo(): Promise<PrismicAuthManagerGetLoginSessionInfoReturnType> {\n\t\t// Pick a random port, with a preference for historic `5555`\n\t\tconst port = await getPort({ port: 5555 });\n\n\t\tconst url = new URL(\n\t\t\t`./dashboard/cli/login?source=slice-machine&port=${port}`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t).toString();\n\n\t\treturn {\n\t\t\tport,\n\t\t\turl,\n\t\t};\n\t}\n\n\tasync nodeLoginSession(\n\t\targs: PrismicAuthManagerNodeLoginSessionArgs,\n\t): Promise<void> {\n\t\treturn new Promise<void>(async (resolve) => {\n\t\t\t// Timeout attempt after 3 minutes\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tserver.close();\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Login timeout, server did not receive a response within a 3-minute delay\",\n\t\t\t\t);\n\t\t\t}, 180_000);\n\n\t\t\tconst app = h3.createApp();\n\t\t\tapp.use(h3.fromNodeMiddleware(cors()));\n\t\t\tapp.use(\n\t\t\t\th3.fromNodeMiddleware(\n\t\t\t\t\tcreatePrismicAuthManagerMiddleware({\n\t\t\t\t\t\tprismicAuthManager: this,\n\t\t\t\t\t\tonLoginCallback() {\n\t\t\t\t\t\t\t// Cleanup process and resolve\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tserver.close();\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\t// Start server\n\t\t\tconst server = http.createServer(h3.toNodeListener(app));\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tserver.once(\"listening\", () => {\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t\tserver.listen(args.port);\n\t\t\t});\n\n\t\t\tif (args.onListenCallback) {\n\t\t\t\targs.onListenCallback();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync logout(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Remove all Prismic cookies, short ID, and Intercom hash\n\t\t// associated with the currently logged in user.\n\t\tauthState.cookies = {};\n\t\tauthState.shortId = undefined;\n\t\tauthState.intercomHash = undefined;\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync checkIsLoggedIn(): Promise<boolean> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\"./validate\", API_ENDPOINTS.PrismicAuthentication);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tlet res;\n\t\t\ttry {\n\t\t\t\tres = await fetch(url.toString(), {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined.\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\tawait this.logout();\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync getAuthenticationCookies(): Promise<\n\t\tPrismicAuthState[\"cookies\"] &\n\t\t\tRequired<\n\t\t\t\tPick<\n\t\t\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t\t\t>\n\t\t\t>\n\t> {\n\t\tconst isLoggedIn = await this.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\t\treturn authState.cookies;\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\"Not logged in.\");\n\t}\n\n\tasync getAuthenticationToken(): Promise<string> {\n\t\tconst cookies = await this.getAuthenticationCookies();\n\n\t\treturn cookies[AUTH_COOKIE_KEY];\n\t}\n\n\tasync refreshAuthenticationToken(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\n\t\t\t\t\"./refreshtoken\",\n\t\t\t\tAPI_ENDPOINTS.PrismicAuthentication,\n\t\t\t);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tconst res = await fetch(url.toString(), {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst text = await res.text();\n\n\t\t\tif (res.ok) {\n\t\t\t\tauthState.cookies[AUTH_COOKIE_KEY] = text;\n\n\t\t\t\tawait this._writePersistedAuthState(authState);\n\t\t\t} else {\n\t\t\t\tthrow new InternalError(\"Failed to refresh authentication token.\");\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\t}\n\n\tasync getProfile(): Promise<PrismicUserProfile> {\n\t\tconst authenticationToken = await this.getAuthenticationToken();\n\n\t\treturn await this._getProfileForAuthenticationToken({\n\t\t\tauthenticationToken,\n\t\t});\n\t}\n\n\tprivate async _getProfileForAuthenticationToken(\n\t\targs: GetProfileForAuthenticationTokenArgs,\n\t): Promise<PrismicUserProfile> {\n\t\tconst url = new URL(\"./profile\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await fetch(url.toString(), {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${args.authenticationToken}`,\n\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t},\n\t\t});\n\t\tconst json = await res.json();\n\n\t\tif (res.ok) {\n\t\t\tconst { value: profile, error } = decode(PrismicUserProfile, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\"Received invalid data from the Prismic user service.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn profile;\n\t\t} else {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to retrieve profile from the Prismic user service.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async _readPersistedAuthState(): Promise<PrismicAuthState> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tlet authStateFileContents: string = JSON.stringify({});\n\n\t\ttry {\n\t\t\tauthStateFileContents = await fs.readFile(authStateFilePath, \"utf8\");\n\t\t} catch {\n\t\t\t// Write a default persisted state if it doesn't already exist.\n\n\t\t\tconst defaultStateFileContents = {\n\t\t\t\t...DEFAULT_PERSISTED_AUTH_STATE,\n\t\t\t\tcookies: serializeCookies(DEFAULT_PERSISTED_AUTH_STATE.cookies),\n\t\t\t};\n\t\t\tauthStateFileContents = JSON.stringify(\n\t\t\t\tdefaultStateFileContents,\n\t\t\t\tnull,\n\t\t\t\t\"\\t\",\n\t\t\t);\n\n\t\t\tawait fs.mkdir(path.dirname(authStateFilePath), { recursive: true });\n\t\t\tawait fs.writeFile(authStateFilePath, authStateFileContents);\n\t\t}\n\n\t\tconst rawAuthState = JSON.parse(authStateFileContents);\n\n\t\t// Decode cookies into a record for convenience.\n\t\tif (\"cookies\" in rawAuthState) {\n\t\t\trawAuthState.cookies = parseCookies(rawAuthState.cookies);\n\t\t}\n\n\t\tconst { value: authState, error } = decode(PrismicAuthState, rawAuthState);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\"Prismic authentication state is invalid.\");\n\t\t}\n\n\t\treturn authState;\n\t}\n\n\tprivate async _writePersistedAuthState(\n\t\tauthState: PrismicAuthState,\n\t): Promise<void> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tconst preparedAuthState = {\n\t\t\t...authState,\n\t\t\tcookies: serializeCookies(authState.cookies),\n\t\t};\n\n\t\ttry {\n\t\t\tawait fs.writeFile(\n\t\t\t\tauthStateFilePath,\n\t\t\t\tJSON.stringify(preparedAuthState, null, 2),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to write Prismic authentication state to the file system.\",\n\t\t\t\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate _getPersistedAuthStateFilePath(): string {\n\t\treturn path.resolve(this.scopedDirectory, PERSISTED_AUTH_STATE_FILE_NAME);\n\t}\n}\n"],"names":["getPort","resolve"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAE3B,MAAM,iCAAiC;AACvC,MAAM,+BAAiD;AAAA,EACtD,MAAM;AAAA,E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KAAK,MAAM,qBAAqB;AAGrD,QAAI,aAAa,cAAc;AACjB,mBAAA,UAAU,aAAa,aAAa,OAAO;AAAA,IACxD;AAED,UAAM,EAAE,OAAO,WAAW,MAAU,IAAA,OAAO,kBAAkB,YAAY;AAEzE,QAAI,OAAO;AACJ,YAAA,IAAI,oBAAoB,0CAA0C;AAAA,IACxE;AAEM,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,yBACb,WAA2B;AAErB,UAAA,oBAAoB,KAAK;AAE/B,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,SAAS,iBAAiB,UAAU,OAAO;AAAA,IAAA;AAGxC,QAAA;AACG,YAAA,GAAG,UACR,mBACA,KAAK,UAAU,mBAAmB,MAAM,CAAC,CAAC;AAAA,aAEnC;AACF,YAAA,IAAI,cACT,oEACA;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,iCAA8B;AACrC,WAAO,KAAK,QAAQ,KAAK,iBAAiB,8BAA8B;AAAA,EACzE;AACA;"}
|
|
1
|
+
{"version":3,"file":"PrismicAuthManager.js","sources":["../../../src/auth/PrismicAuthManager.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\nimport * as http from \"node:http\";\n\nimport * as h3 from \"h3\";\nimport fetch from \"../lib/fetch\";\nimport cookie from \"cookie\";\nimport cors from \"cors\";\nimport getPort from \"get-port\";\n\nimport { decode } from \"../lib/decode\";\nimport { serializeCookies } from \"../lib/serializeCookies\";\n\nimport { API_ENDPOINTS } from \"../constants/API_ENDPOINTS\";\nimport { SLICE_MACHINE_USER_AGENT } from \"../constants/SLICE_MACHINE_USER_AGENT\";\nimport { createPrismicAuthManagerMiddleware } from \"./createPrismicAuthManagerMiddleware\";\nimport {\n\tInternalError,\n\tUnauthenticatedError,\n\tUnexpectedDataError,\n} from \"../errors\";\n\nconst COOKIE_SEPARATOR = \"; \";\nconst AUTH_COOKIE_KEY = \"prismic-auth\";\nconst SESSION_COOKIE_KEY = \"SESSION\";\n\nconst PERSISTED_AUTH_STATE_FILE_NAME = \".prismic\";\nconst DEFAULT_PERSISTED_AUTH_STATE: PrismicAuthState = {\n\tbase: \"https://prismic.io\",\n\tcookies: {},\n};\n\nconst PrismicAuthState = t.intersection([\n\tt.type({\n\t\tbase: t.string,\n\t\tcookies: t.intersection([\n\t\t\tt.partial({\n\t\t\t\t[AUTH_COOKIE_KEY]: t.string,\n\t\t\t\tSESSION: t.string,\n\t\t\t}),\n\t\t\tt.record(t.string, t.string),\n\t\t]),\n\t}),\n\tt.partial({\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\toauthAccessToken: t.string,\n\t\tauthUrl: t.string,\n\t}),\n]);\nexport type PrismicAuthState = t.TypeOf<typeof PrismicAuthState>;\n\nconst PrismicUserProfile = t.exact(\n\tt.type({\n\t\tuserId: t.string,\n\t\tshortId: t.string,\n\t\tintercomHash: t.string,\n\t\temail: t.string,\n\t\tfirstName: t.string,\n\t\tlastName: t.string,\n\t}),\n);\nexport type PrismicUserProfile = t.TypeOf<typeof PrismicUserProfile>;\n\ntype PrismicAuthManagerConstructorArgs = {\n\tscopedDirectory?: string;\n};\n\ntype PrismicAuthManagerLoginArgs = {\n\temail: string;\n\tcookies: string[];\n};\n\ntype PrismicAuthManagerGetLoginSessionInfoReturnType = {\n\tport: number;\n\turl: string;\n};\n\ntype PrismicAuthManagerNodeLoginSessionArgs = {\n\tport: number;\n\tonListenCallback?: () => void;\n};\n\ntype GetProfileForAuthenticationTokenArgs = {\n\tauthenticationToken: string;\n};\n\nconst checkHasAuthenticationToken = (\n\tauthState: PrismicAuthState,\n): authState is PrismicAuthState & {\n\tcookies: Required<\n\t\tPick<\n\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t>\n\t>;\n} => {\n\treturn Boolean(\n\t\tauthState.cookies[AUTH_COOKIE_KEY] && authState.cookies[SESSION_COOKIE_KEY],\n\t);\n};\n\nconst parseCookies = (cookies: string): Record<string, string> => {\n\treturn cookie.parse(cookies, {\n\t\t// Don't escape any values.\n\t\tdecode: (value) => value,\n\t});\n};\n\nexport class PrismicAuthManager {\n\t// TODO: Automatically scope the manager to the current Slice Machine\n\t// project? If not, this internal state can be removed.\n\tscopedDirectory: string;\n\n\tconstructor({\n\t\tscopedDirectory = os.homedir(),\n\t}: PrismicAuthManagerConstructorArgs = {}) {\n\t\tthis.scopedDirectory = scopedDirectory;\n\t}\n\n\t// TODO: Make the `cookies` argument more explicit. What are these\n\t// mysterious cookies?\n\tasync login(args: PrismicAuthManagerLoginArgs): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Set the auth's URL base to the current base at runtime.\n\t\tauthState.base = API_ENDPOINTS.PrismicWroom;\n\t\tauthState.cookies = {\n\t\t\t...authState.cookies,\n\t\t\t...parseCookies(args.cookies.join(COOKIE_SEPARATOR)),\n\t\t};\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst authenticationToken = authState.cookies[AUTH_COOKIE_KEY];\n\t\t\tconst profile = await this._getProfileForAuthenticationToken({\n\t\t\t\tauthenticationToken,\n\t\t\t});\n\n\t\t\tauthState.shortId = profile.shortId;\n\t\t\tauthState.intercomHash = profile.intercomHash;\n\t\t}\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync getLoginSessionInfo(): Promise<PrismicAuthManagerGetLoginSessionInfoReturnType> {\n\t\t// Pick a random port, with a preference for historic `5555`\n\t\tconst port = await getPort({ port: 5555 });\n\n\t\tconst url = new URL(\n\t\t\t`./dashboard/cli/login?source=slice-machine&port=${port}`,\n\t\t\tAPI_ENDPOINTS.PrismicWroom,\n\t\t).toString();\n\n\t\treturn {\n\t\t\tport,\n\t\t\turl,\n\t\t};\n\t}\n\n\tasync nodeLoginSession(\n\t\targs: PrismicAuthManagerNodeLoginSessionArgs,\n\t): Promise<void> {\n\t\treturn new Promise<void>(async (resolve) => {\n\t\t\t// Timeout attempt after 3 minutes\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tserver.close();\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Login timeout, server did not receive a response within a 3-minute delay\",\n\t\t\t\t);\n\t\t\t}, 180_000);\n\n\t\t\tconst app = h3.createApp();\n\t\t\tapp.use(h3.fromNodeMiddleware(cors()));\n\t\t\tapp.use(\n\t\t\t\th3.fromNodeMiddleware(\n\t\t\t\t\tcreatePrismicAuthManagerMiddleware({\n\t\t\t\t\t\tprismicAuthManager: this,\n\t\t\t\t\t\tonLoginCallback() {\n\t\t\t\t\t\t\t// Cleanup process and resolve\n\t\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\t\tserver.close();\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\t// Start server\n\t\t\tconst server = http.createServer(h3.toNodeListener(app));\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tserver.once(\"listening\", () => {\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t\tserver.listen(args.port);\n\t\t\t});\n\n\t\t\tif (args.onListenCallback) {\n\t\t\t\targs.onListenCallback();\n\t\t\t}\n\t\t});\n\t}\n\n\tasync logout(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t// Remove all Prismic cookies, short ID, and Intercom hash\n\t\t// associated with the currently logged in user.\n\t\tauthState.cookies = {};\n\t\tauthState.shortId = undefined;\n\t\tauthState.intercomHash = undefined;\n\n\t\tawait this._writePersistedAuthState(authState);\n\t}\n\n\tasync checkIsLoggedIn(): Promise<boolean> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\"./validate\", API_ENDPOINTS.PrismicAuthentication);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tlet res;\n\t\t\ttry {\n\t\t\t\tres = await fetch(url.toString(), {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined.\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\tawait this.logout();\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync getAuthenticationCookies(): Promise<\n\t\tPrismicAuthState[\"cookies\"] &\n\t\t\tRequired<\n\t\t\t\tPick<\n\t\t\t\t\tPrismicAuthState[\"cookies\"],\n\t\t\t\t\ttypeof AUTH_COOKIE_KEY | typeof SESSION_COOKIE_KEY\n\t\t\t\t>\n\t\t\t>\n\t> {\n\t\tconst isLoggedIn = await this.checkIsLoggedIn();\n\n\t\tif (isLoggedIn) {\n\t\t\tconst authState = await this._readPersistedAuthState();\n\n\t\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\t\treturn authState.cookies;\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\"Not logged in.\");\n\t}\n\n\tasync getAuthenticationToken(): Promise<string> {\n\t\tconst cookies = await this.getAuthenticationCookies();\n\n\t\treturn cookies[AUTH_COOKIE_KEY];\n\t}\n\n\tasync refreshAuthenticationToken(): Promise<void> {\n\t\tconst authState = await this._readPersistedAuthState();\n\n\t\tif (checkHasAuthenticationToken(authState)) {\n\t\t\tconst url = new URL(\n\t\t\t\t\"./refreshtoken\",\n\t\t\t\tAPI_ENDPOINTS.PrismicAuthentication,\n\t\t\t);\n\t\t\turl.searchParams.set(\"token\", authState.cookies[AUTH_COOKIE_KEY]);\n\n\t\t\tconst res = await fetch(url.toString(), {\n\t\t\t\theaders: {\n\t\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst text = await res.text();\n\n\t\t\tif (res.ok) {\n\t\t\t\tauthState.cookies[AUTH_COOKIE_KEY] = text;\n\n\t\t\t\tawait this._writePersistedAuthState(authState);\n\t\t\t} else {\n\t\t\t\tthrow new InternalError(\"Failed to refresh authentication token.\");\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new UnauthenticatedError();\n\t\t}\n\t}\n\n\tasync getProfile(): Promise<PrismicUserProfile> {\n\t\tconst authenticationToken = await this.getAuthenticationToken();\n\n\t\treturn await this._getProfileForAuthenticationToken({\n\t\t\tauthenticationToken,\n\t\t});\n\t}\n\n\tprivate async _getProfileForAuthenticationToken(\n\t\targs: GetProfileForAuthenticationTokenArgs,\n\t): Promise<PrismicUserProfile> {\n\t\tconst url = new URL(\"./profile\", API_ENDPOINTS.PrismicUser);\n\t\tconst res = await fetch(url.toString(), {\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${args.authenticationToken}`,\n\t\t\t\t\"User-Agent\": SLICE_MACHINE_USER_AGENT,\n\t\t\t},\n\t\t});\n\t\tconst json = await res.json();\n\n\t\tif (res.ok) {\n\t\t\tconst { value: profile, error } = decode(PrismicUserProfile, json);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new UnexpectedDataError(\n\t\t\t\t\t\"Received invalid data from the Prismic user service.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn profile;\n\t\t} else {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to retrieve profile from the Prismic user service.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async _readPersistedAuthState(): Promise<PrismicAuthState> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tlet authStateFileContents: string = JSON.stringify({});\n\t\tlet rawAuthState: Record<string, unknown> = {};\n\n\t\ttry {\n\t\t\tauthStateFileContents = await fs.readFile(authStateFilePath, \"utf8\");\n\t\t\trawAuthState = JSON.parse(authStateFileContents);\n\t\t} catch {\n\t\t\t// Write a default persisted state if it doesn't already exist.\n\n\t\t\trawAuthState = {\n\t\t\t\t...DEFAULT_PERSISTED_AUTH_STATE,\n\t\t\t\tcookies: serializeCookies(DEFAULT_PERSISTED_AUTH_STATE.cookies),\n\t\t\t};\n\t\t\tauthStateFileContents = JSON.stringify(rawAuthState, null, \"\\t\");\n\n\t\t\tawait fs.mkdir(path.dirname(authStateFilePath), { recursive: true });\n\t\t\tawait fs.writeFile(authStateFilePath, authStateFileContents);\n\t\t}\n\n\t\t// Decode cookies into a record for convenience.\n\t\tif (typeof rawAuthState.cookies === \"string\") {\n\t\t\trawAuthState.cookies = parseCookies(rawAuthState.cookies);\n\t\t}\n\n\t\tconst { value: authState, error } = decode(PrismicAuthState, rawAuthState);\n\n\t\tif (error) {\n\t\t\tthrow new UnexpectedDataError(\"Prismic authentication state is invalid.\");\n\t\t}\n\n\t\treturn authState;\n\t}\n\n\tprivate async _writePersistedAuthState(\n\t\tauthState: PrismicAuthState,\n\t): Promise<void> {\n\t\tconst authStateFilePath = this._getPersistedAuthStateFilePath();\n\n\t\tconst preparedAuthState = {\n\t\t\t...authState,\n\t\t\tcookies: serializeCookies(authState.cookies),\n\t\t};\n\n\t\ttry {\n\t\t\tawait fs.writeFile(\n\t\t\t\tauthStateFilePath,\n\t\t\t\tJSON.stringify(preparedAuthState, null, 2),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"Failed to write Prismic authentication state to the file system.\",\n\t\t\t\t{\n\t\t\t\t\tcause: error,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate _getPersistedAuthStateFilePath(): string {\n\t\treturn path.resolve(this.scopedDirectory, PERSISTED_AUTH_STATE_FILE_NAME);\n\t}\n}\n"],"names":["getPort","resolve"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,q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,KAAK,QAAQ,iBAAiB,GAAG,EAAE,WAAW,KAAA,CAAM;AAC7D,YAAA,GAAG,UAAU,mBAAmB,qBAAqB;AAAA,IAC3D;AAGG,QAAA,OAAO,aAAa,YAAY,UAAU;AAChC,mBAAA,UAAU,aAAa,aAAa,OAAO;AAAA,IACxD;AAED,UAAM,EAAE,OAAO,WAAW,MAAU,IAAA,OAAO,kBAAkB,YAAY;AAEzE,QAAI,OAAO;AACJ,YAAA,IAAI,oBAAoB,0CAA0C;AAAA,IACxE;AAEM,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,yBACb,WAA2B;AAErB,UAAA,oBAAoB,KAAK;AAE/B,UAAM,oBAAoB;AAAA,MACzB,GAAG;AAAA,MACH,SAAS,iBAAiB,UAAU,OAAO;AAAA,IAAA;AAGxC,QAAA;AACG,YAAA,GAAG,UACR,mBACA,KAAK,UAAU,mBAAmB,MAAM,CAAC,CAAC;AAAA,aAEnC;AACF,YAAA,IAAI,cACT,oEACA;AAAA,QACC,OAAO;AAAA,MAAA,CACP;AAAA,IAEF;AAAA,EACF;AAAA,EAEQ,iCAA8B;AACrC,WAAO,KAAK,QAAQ,KAAK,iBAAiB,8BAA8B;AAAA,EACzE;AACA;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const fetch = require("./fetch.cjs");
|
|
4
4
|
const checkIsURLAccessible = async (url) => {
|
|
5
|
-
const res = await
|
|
5
|
+
const res = await fetch.default(url);
|
|
6
6
|
return res.ok;
|
|
7
7
|
};
|
|
8
8
|
exports.checkIsURLAccessible = checkIsURLAccessible;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkIsURLAccessible.cjs","sources":["../../../src/lib/checkIsURLAccessible.ts"],"sourcesContent":["import fetch from \"
|
|
1
|
+
{"version":3,"file":"checkIsURLAccessible.cjs","sources":["../../../src/lib/checkIsURLAccessible.ts"],"sourcesContent":["import fetch from \"./fetch\";\n\nexport const checkIsURLAccessible = async (url: string): Promise<boolean> => {\n\tconst res = await fetch(url);\n\n\treturn res.ok;\n};\n"],"names":["fetch"],"mappings":";;;AAEa,MAAA,uBAAuB,OAAO,QAAiC;AACrE,QAAA,MAAM,MAAMA,cAAM,GAAG;AAE3B,SAAO,IAAI;AACZ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkIsURLAccessible.js","sources":["../../../src/lib/checkIsURLAccessible.ts"],"sourcesContent":["import fetch from \"
|
|
1
|
+
{"version":3,"file":"checkIsURLAccessible.js","sources":["../../../src/lib/checkIsURLAccessible.ts"],"sourcesContent":["import fetch from \"./fetch\";\n\nexport const checkIsURLAccessible = async (url: string): Promise<boolean> => {\n\tconst res = await fetch(url);\n\n\treturn res.ok;\n};\n"],"names":[],"mappings":";AAEa,MAAA,uBAAuB,OAAO,QAAiC;AACrE,QAAA,MAAM,MAAM,MAAM,GAAG;AAE3B,SAAO,IAAI;AACZ;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const http = require("node:http");
|
|
4
|
+
const https = require("node:https");
|
|
5
|
+
const index$1 = require('./../_node_modules/node-fetch/src/index.cjs');
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
if (k !== "default") {
|
|
11
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: () => e[k]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
const http__namespace = /* @__PURE__ */ _interopNamespaceDefault(http);
|
|
23
|
+
const https__namespace = /* @__PURE__ */ _interopNamespaceDefault(https);
|
|
24
|
+
const DEFAULT_HTTP_AGENT = new http__namespace.Agent({ keepAlive: true });
|
|
25
|
+
const DEFAULT_HTTPS_AGENT = new https__namespace.Agent({ keepAlive: true });
|
|
26
|
+
const fetch = (url, init) => {
|
|
27
|
+
return index$1.default(url, {
|
|
28
|
+
agent: (parsedURL) => {
|
|
29
|
+
return parsedURL.protocol === "http:" ? DEFAULT_HTTP_AGENT : DEFAULT_HTTPS_AGENT;
|
|
30
|
+
},
|
|
31
|
+
...init
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const fetch$1 = fetch;
|
|
35
|
+
exports.default = fetch$1;
|
|
36
|
+
//# sourceMappingURL=fetch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.cjs","sources":["../../../src/lib/fetch.ts"],"sourcesContent":["// This temporary wrapper around `node-fetch` fixes an issue where quick\n// consecutive network requests cause failed requests.\n//\n// See https://github.com/node-fetch/node-fetch/issues/1735 for more details.\n//\n// TODO: Remove this wrapper and replace all imports with `node-fetch` if https://github.com/node-fetch/node-fetch/pull/1736 is merged.\n\nimport * as http from \"node:http\";\nimport * as https from \"node:https\";\nimport baseFetch from \"node-fetch\";\n\nexport * from \"node-fetch\";\n\n/**\n * The default HTTP Agent with `keepAlive: true` used in `fetch()` requests.\n */\nconst DEFAULT_HTTP_AGENT = new http.Agent({ keepAlive: true });\n\n/**\n * The default HTTPS Agent with `keepAlive: true` used in `fetch()` requests.\n */\nconst DEFAULT_HTTPS_AGENT = new https.Agent({ keepAlive: true });\n\n/**\n * Patched `fetch()` from `node-fetch` that fixes a bug where quick consecutive\n * network requests cause failed requests.\n *\n * Use this `fetch()` in place of `node-fetch`'s `fetch()`.\n *\n * @remarks\n * `fetch()` is patched by setting an HTTP/HTTPS Agent with `keepAlive: true`.\n * If you need to assign an Agent, be sure to retain the `keepAlive: true`\n * option.\n */\nconst fetch: typeof baseFetch = (url, init) => {\n\treturn baseFetch(url, {\n\t\tagent: (parsedURL) => {\n\t\t\treturn parsedURL.protocol === \"http:\"\n\t\t\t\t? DEFAULT_HTTP_AGENT\n\t\t\t\t: DEFAULT_HTTPS_AGENT;\n\t\t},\n\t\t...init,\n\t});\n};\n\nexport default fetch;\n"],"names":["http","https","baseFetch"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,qBAAqB,IAAIA,gBAAK,MAAM,EAAE,WAAW,MAAM;AAK7D,MAAM,sBAAsB,IAAIC,iBAAM,MAAM,EAAE,WAAW,MAAM;AAa/D,MAAM,QAA0B,CAAC,KAAK,SAAQ;AAC7C,SAAOC,QAAAA,QAAU,KAAK;AAAA,IACrB,OAAO,CAAC,cAAa;AACb,aAAA,UAAU,aAAa,UAC3B,qBACA;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EAAA,CACH;AACF;AAEA,MAAA,UAAe;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import baseFetch from "node-fetch";
|
|
2
|
+
export * from "node-fetch";
|
|
3
|
+
/**
|
|
4
|
+
* Patched `fetch()` from `node-fetch` that fixes a bug where quick consecutive
|
|
5
|
+
* network requests cause failed requests.
|
|
6
|
+
*
|
|
7
|
+
* Use this `fetch()` in place of `node-fetch`'s `fetch()`.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* `fetch()` is patched by setting an HTTP/HTTPS Agent with `keepAlive: true`.
|
|
11
|
+
* If you need to assign an Agent, be sure to retain the `keepAlive: true`
|
|
12
|
+
* option.
|
|
13
|
+
*/
|
|
14
|
+
declare const fetch: typeof baseFetch;
|
|
15
|
+
export default fetch;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as http from "node:http";
|
|
2
|
+
import * as https from "node:https";
|
|
3
|
+
import fetch$2 from './../_node_modules/node-fetch/src/index.js';
|
|
4
|
+
const DEFAULT_HTTP_AGENT = new http.Agent({ keepAlive: true });
|
|
5
|
+
const DEFAULT_HTTPS_AGENT = new https.Agent({ keepAlive: true });
|
|
6
|
+
const fetch = (url, init) => {
|
|
7
|
+
return fetch$2(url, {
|
|
8
|
+
agent: (parsedURL) => {
|
|
9
|
+
return parsedURL.protocol === "http:" ? DEFAULT_HTTP_AGENT : DEFAULT_HTTPS_AGENT;
|
|
10
|
+
},
|
|
11
|
+
...init
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const fetch$1 = fetch;
|
|
15
|
+
export {
|
|
16
|
+
fetch$1 as default
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sources":["../../../src/lib/fetch.ts"],"sourcesContent":["// This temporary wrapper around `node-fetch` fixes an issue where quick\n// consecutive network requests cause failed requests.\n//\n// See https://github.com/node-fetch/node-fetch/issues/1735 for more details.\n//\n// TODO: Remove this wrapper and replace all imports with `node-fetch` if https://github.com/node-fetch/node-fetch/pull/1736 is merged.\n\nimport * as http from \"node:http\";\nimport * as https from \"node:https\";\nimport baseFetch from \"node-fetch\";\n\nexport * from \"node-fetch\";\n\n/**\n * The default HTTP Agent with `keepAlive: true` used in `fetch()` requests.\n */\nconst DEFAULT_HTTP_AGENT = new http.Agent({ keepAlive: true });\n\n/**\n * The default HTTPS Agent with `keepAlive: true` used in `fetch()` requests.\n */\nconst DEFAULT_HTTPS_AGENT = new https.Agent({ keepAlive: true });\n\n/**\n * Patched `fetch()` from `node-fetch` that fixes a bug where quick consecutive\n * network requests cause failed requests.\n *\n * Use this `fetch()` in place of `node-fetch`'s `fetch()`.\n *\n * @remarks\n * `fetch()` is patched by setting an HTTP/HTTPS Agent with `keepAlive: true`.\n * If you need to assign an Agent, be sure to retain the `keepAlive: true`\n * option.\n */\nconst fetch: typeof baseFetch = (url, init) => {\n\treturn baseFetch(url, {\n\t\tagent: (parsedURL) => {\n\t\t\treturn parsedURL.protocol === \"http:\"\n\t\t\t\t? DEFAULT_HTTP_AGENT\n\t\t\t\t: DEFAULT_HTTPS_AGENT;\n\t\t},\n\t\t...init,\n\t});\n};\n\nexport default fetch;\n"],"names":["baseFetch"],"mappings":";;;AAgBA,MAAM,qBAAqB,IAAI,KAAK,MAAM,EAAE,WAAW,MAAM;AAK7D,MAAM,sBAAsB,IAAI,MAAM,MAAM,EAAE,WAAW,MAAM;AAa/D,MAAM,QAA0B,CAAC,KAAK,SAAQ;AAC7C,SAAOA,QAAU,KAAK;AAAA,IACrB,OAAO,CAAC,cAAa;AACb,aAAA,UAAU,aAAa,UAC3B,qBACA;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EAAA,CACH;AACF;AAEA,MAAA,UAAe;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const t = require("io-ts");
|
|
4
|
-
const
|
|
4
|
+
const fetch = require("./fetch.cjs");
|
|
5
5
|
const index = require('./../_node_modules/p-limit/index.cjs');
|
|
6
6
|
const decode = require("./decode.cjs");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
@@ -27,7 +27,7 @@ const GitHubReleaseMetadata = t__namespace.type({
|
|
|
27
27
|
body: t__namespace.union([t__namespace.null, t__namespace.string])
|
|
28
28
|
});
|
|
29
29
|
const fetchAllGitHubReleases = async (args) => {
|
|
30
|
-
const res = await
|
|
30
|
+
const res = await fetch.default(`https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases`, {
|
|
31
31
|
headers: {
|
|
32
32
|
Accept: GITHUB_JSON_ACCEPT_HEADER
|
|
33
33
|
}
|
|
@@ -50,7 +50,7 @@ const fetchGitHubReleaseByVersion = async (args) => {
|
|
|
50
50
|
} else {
|
|
51
51
|
url = `https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases/tags/${args.version}`;
|
|
52
52
|
}
|
|
53
|
-
const res = await
|
|
53
|
+
const res = await fetch.default(url, {
|
|
54
54
|
headers: {
|
|
55
55
|
Accept: GITHUB_JSON_ACCEPT_HEADER
|
|
56
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchGitHubReleaseBodyForRelease.cjs","sources":["../../../src/lib/fetchGitHubReleaseBodyForRelease.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport fetch from \"
|
|
1
|
+
{"version":3,"file":"fetchGitHubReleaseBodyForRelease.cjs","sources":["../../../src/lib/fetchGitHubReleaseBodyForRelease.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport fetch from \"./fetch\";\nimport pLimit from \"p-limit\";\n\nimport { decode } from \"./decode\";\n\nconst GITHUB_JSON_ACCEPT_HEADER = \"application/vnd.github+json\";\n\n/**\n * A minimally defined codec for GitHub release metadata.\n *\n * @see https://docs.github.com/en/rest/releases/releases#get-a-release-by-tag-name\n */\nconst GitHubReleaseMetadata = t.type({\n\tname: t.string,\n\tbody: t.union([t.null, t.string]),\n});\nexport type GitHubReleaseMetadata = t.TypeOf<typeof GitHubReleaseMetadata>;\n\ntype FetchAllGitHubReleasesArgs = {\n\trepositoryOwner: string;\n\trepositoryName: string;\n};\n\nconst fetchAllGitHubReleases = async (\n\targs: FetchAllGitHubReleasesArgs,\n): Promise<GitHubReleaseMetadata[]> => {\n\tconst res = await fetch(\n\t\t`https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAccept: GITHUB_JSON_ACCEPT_HEADER,\n\t\t\t},\n\t\t},\n\t);\n\n\tif (res.ok) {\n\t\tconst json = await res.json();\n\n\t\tconst { value, error } = decode(t.array(GitHubReleaseMetadata), json);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid GitHub Release response.`, { cause: error });\n\t\t}\n\n\t\treturn value;\n\t} else {\n\t\tthrow new Error(`Invalid GitHub Release response.`);\n\t}\n};\n\ntype FetchGitHubReleaseByVersionArgs = {\n\trepositoryOwner: string;\n\trepositoryName: string;\n\tpackageName?: string;\n\tversion: string;\n};\n\nconst fetchGitHubReleaseByVersion = async (\n\targs: FetchGitHubReleaseByVersionArgs,\n): Promise<GitHubReleaseMetadata | undefined> => {\n\tlet url: string;\n\n\tif (args.packageName) {\n\t\turl = `https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases/tags/${args.packageName}@${args.version}`;\n\t} else {\n\t\turl = `https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases/tags/${args.version}`;\n\t}\n\n\tconst res = await fetch(url, {\n\t\theaders: {\n\t\t\tAccept: GITHUB_JSON_ACCEPT_HEADER,\n\t\t},\n\t});\n\n\tif (res.ok) {\n\t\tconst json = await res.json();\n\n\t\tconst { value, error } = decode(GitHubReleaseMetadata, json);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid GitHub Release response.`, { cause: error });\n\t\t}\n\n\t\treturn value;\n\t}\n};\n\ntype FetchGitHubReleaseBodyForReleaseArgs = {\n\trepositoryOwner: string;\n\trepositoryName: string;\n\tpackageName?: string;\n\tversion: string;\n\tcache?: Record<string, GitHubReleaseMetadata | undefined>;\n};\n\nconst _fetchGitHubReleaseBodyForRelease = async (\n\targs: FetchGitHubReleaseBodyForReleaseArgs,\n): Promise<string | undefined> => {\n\tconst cache = args.cache || {};\n\n\tif (Object.keys(cache).length < 1) {\n\t\tconst releases = await fetchAllGitHubReleases({\n\t\t\trepositoryOwner: args.repositoryOwner,\n\t\t\trepositoryName: args.repositoryName,\n\t\t});\n\n\t\tfor (const release of releases) {\n\t\t\tcache[release.name] = release;\n\t\t}\n\t}\n\n\tif (args.version in cache) {\n\t\tconst release = cache[args.version];\n\n\t\treturn release?.body ?? undefined;\n\t} else {\n\t\ttry {\n\t\t\tconst version = await fetchGitHubReleaseByVersion({\n\t\t\t\trepositoryOwner: args.repositoryOwner,\n\t\t\t\trepositoryName: args.repositoryName,\n\t\t\t\tpackageName: args.packageName,\n\t\t\t\tversion: args.version,\n\t\t\t});\n\n\t\t\tcache[args.version] = version;\n\n\t\t\treturn version?.body ?? undefined;\n\t\t} catch {\n\t\t\tcache[args.version] = undefined;\n\n\t\t\treturn undefined;\n\t\t}\n\t}\n};\n\nconst limit = pLimit(1);\n\nexport const fetchGitHubReleaseBodyForRelease = async (\n\t...args: Parameters<typeof _fetchGitHubReleaseBodyForRelease>\n): ReturnType<typeof _fetchGitHubReleaseBodyForRelease> => {\n\treturn await limit(() => _fetchGitHubReleaseBodyForRelease(...args));\n};\n"],"names":["t","fetch","decode","pLimit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,4BAA4B;AAOlC,MAAM,wBAAwBA,aAAE,KAAK;AAAA,EACpC,MAAMA,aAAE;AAAA,EACR,MAAMA,aAAE,MAAM,CAACA,aAAE,MAAMA,aAAE,MAAM,CAAC;AAChC,CAAA;AAQD,MAAM,yBAAyB,OAC9B,SACqC;AACrC,QAAM,MAAM,MAAMC,cACjB,gCAAgC,KAAK,mBAAmB,KAAK,2BAC7D;AAAA,IACC,SAAS;AAAA,MACR,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAGF,MAAI,IAAI,IAAI;AACL,UAAA,OAAO,MAAM,IAAI;AAEjB,UAAA,EAAE,OAAO,MAAK,IAAKC,cAAOF,aAAE,MAAM,qBAAqB,GAAG,IAAI;AAEpE,QAAI,OAAO;AACV,YAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO;AAAA,IACpE;AAEM,WAAA;AAAA,EAAA,OACD;AACA,UAAA,IAAI,MAAM,kCAAkC;AAAA,EAClD;AACF;AASA,MAAM,8BAA8B,OACnC,SAC+C;AAC3C,MAAA;AAEJ,MAAI,KAAK,aAAa;AACrB,UAAM,gCAAgC,KAAK,mBAAmB,KAAK,gCAAgC,KAAK,eAAe,KAAK;AAAA,EA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AI,CAAC;AACpE;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
import fetch from
|
|
2
|
+
import fetch from "./fetch.js";
|
|
3
3
|
import pLimit from './../_node_modules/p-limit/index.js';
|
|
4
4
|
import { decode } from "./decode.js";
|
|
5
5
|
const GITHUB_JSON_ACCEPT_HEADER = "application/vnd.github+json";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchGitHubReleaseBodyForRelease.js","sources":["../../../src/lib/fetchGitHubReleaseBodyForRelease.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport fetch from \"
|
|
1
|
+
{"version":3,"file":"fetchGitHubReleaseBodyForRelease.js","sources":["../../../src/lib/fetchGitHubReleaseBodyForRelease.ts"],"sourcesContent":["import * as t from \"io-ts\";\nimport fetch from \"./fetch\";\nimport pLimit from \"p-limit\";\n\nimport { decode } from \"./decode\";\n\nconst GITHUB_JSON_ACCEPT_HEADER = \"application/vnd.github+json\";\n\n/**\n * A minimally defined codec for GitHub release metadata.\n *\n * @see https://docs.github.com/en/rest/releases/releases#get-a-release-by-tag-name\n */\nconst GitHubReleaseMetadata = t.type({\n\tname: t.string,\n\tbody: t.union([t.null, t.string]),\n});\nexport type GitHubReleaseMetadata = t.TypeOf<typeof GitHubReleaseMetadata>;\n\ntype FetchAllGitHubReleasesArgs = {\n\trepositoryOwner: string;\n\trepositoryName: string;\n};\n\nconst fetchAllGitHubReleases = async (\n\targs: FetchAllGitHubReleasesArgs,\n): Promise<GitHubReleaseMetadata[]> => {\n\tconst res = await fetch(\n\t\t`https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAccept: GITHUB_JSON_ACCEPT_HEADER,\n\t\t\t},\n\t\t},\n\t);\n\n\tif (res.ok) {\n\t\tconst json = await res.json();\n\n\t\tconst { value, error } = decode(t.array(GitHubReleaseMetadata), json);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid GitHub Release response.`, { cause: error });\n\t\t}\n\n\t\treturn value;\n\t} else {\n\t\tthrow new Error(`Invalid GitHub Release response.`);\n\t}\n};\n\ntype FetchGitHubReleaseByVersionArgs = {\n\trepositoryOwner: string;\n\trepositoryName: string;\n\tpackageName?: string;\n\tversion: string;\n};\n\nconst fetchGitHubReleaseByVersion = async (\n\targs: FetchGitHubReleaseByVersionArgs,\n): Promise<GitHubReleaseMetadata | undefined> => {\n\tlet url: string;\n\n\tif (args.packageName) {\n\t\turl = `https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases/tags/${args.packageName}@${args.version}`;\n\t} else {\n\t\turl = `https://api.github.com/repos/${args.repositoryOwner}/${args.repositoryName}/releases/tags/${args.version}`;\n\t}\n\n\tconst res = await fetch(url, {\n\t\theaders: {\n\t\t\tAccept: GITHUB_JSON_ACCEPT_HEADER,\n\t\t},\n\t});\n\n\tif (res.ok) {\n\t\tconst json = await res.json();\n\n\t\tconst { value, error } = decode(GitHubReleaseMetadata, json);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid GitHub Release response.`, { cause: error });\n\t\t}\n\n\t\treturn value;\n\t}\n};\n\ntype FetchGitHubReleaseBodyForReleaseArgs = {\n\trepositoryOwner: string;\n\trepositoryName: string;\n\tpackageName?: string;\n\tversion: string;\n\tcache?: Record<string, GitHubReleaseMetadata | undefined>;\n};\n\nconst _fetchGitHubReleaseBodyForRelease = async (\n\targs: FetchGitHubReleaseBodyForReleaseArgs,\n): Promise<string | undefined> => {\n\tconst cache = args.cache || {};\n\n\tif (Object.keys(cache).length < 1) {\n\t\tconst releases = await fetchAllGitHubReleases({\n\t\t\trepositoryOwner: args.repositoryOwner,\n\t\t\trepositoryName: args.repositoryName,\n\t\t});\n\n\t\tfor (const release of releases) {\n\t\t\tcache[release.name] = release;\n\t\t}\n\t}\n\n\tif (args.version in cache) {\n\t\tconst release = cache[args.version];\n\n\t\treturn release?.body ?? undefined;\n\t} else {\n\t\ttry {\n\t\t\tconst version = await fetchGitHubReleaseByVersion({\n\t\t\t\trepositoryOwner: args.repositoryOwner,\n\t\t\t\trepositoryName: args.repositoryName,\n\t\t\t\tpackageName: args.packageName,\n\t\t\t\tversion: args.version,\n\t\t\t});\n\n\t\t\tcache[args.version] = version;\n\n\t\t\treturn version?.body ?? undefined;\n\t\t} catch {\n\t\t\tcache[args.version] = undefined;\n\n\t\t\treturn undefined;\n\t\t}\n\t}\n};\n\nconst limit = pLimit(1);\n\nexport const fetchGitHubReleaseBodyForRelease = async (\n\t...args: Parameters<typeof _fetchGitHubReleaseBodyForRelease>\n): ReturnType<typeof _fetchGitHubReleaseBodyForRelease> => {\n\treturn await limit(() => _fetchGitHubReleaseBodyForRelease(...args));\n};\n"],"names":[],"mappings":";;;;AAMA,MAAM,4BAA4B;AAOlC,MAAM,wBAAwB,EAAE,KAAK;AAAA,EACpC,MAAM,EAAE;AAAA,EACR,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC;AAChC,CAAA;AAQD,MAAM,yBAAyB,OAC9B,SACqC;AACrC,QAAM,MAAM,MAAM,MACjB,gCAAgC,KAAK,mBAAmB,KAAK,2BAC7D;AAAA,IACC,SAAS;AAAA,MACR,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAGF,MAAI,IAAI,IAAI;AACL,UAAA,OAAO,MAAM,IAAI;AAEjB,UAAA,EAAE,OAAO,MAAK,IAAK,OAAO,EAAE,MAAM,qBAAqB,GAAG,IAAI;AAEpE,QAAI,OAAO;AACV,YAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO;AAAA,IACpE;AAEM,WAAA;AAAA,EAAA,OACD;AACA,UAAA,IAAI,MAAM,kCAAkC;AAAA,EAClD;AACF;AASA,MAAM,8BAA8B,OACnC,SAC+C;AAC3C,MAAA;AAEJ,MAAI,KAAK,aAAa;AACrB,UAAM,gCAAgC,KAAK,mBAAmB,KAAK,gCAAgC,KAAK,eAAe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