-
Notifications
You must be signed in to change notification settings - Fork 94
QVAC-18418 fix: route bare-crypto and bare-fetch through imports map #1932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yuranich
merged 3 commits into
tetherto:main
from
opaninakuffo:fix/rag-bundler-imports-map
May 8, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 'use strict' | ||
|
|
||
| const { QvacErrorRAG, ERR_CODES } = require('../errors') | ||
|
|
||
| function ensureCrypto () { | ||
| if (typeof globalThis !== 'undefined' && globalThis.crypto && typeof globalThis.crypto.createHash === 'function') { | ||
| return globalThis.crypto | ||
| } | ||
| throw new QvacErrorRAG({ | ||
| code: ERR_CODES.DEPENDENCY_REQUIRED, | ||
| adds: 'No crypto implementation found. Please ensure a crypto module is available in your environment (Bare: bare-crypto; Node: node:crypto; other: provide a Web Crypto-compatible globalThis.crypto).' | ||
| }) | ||
| } | ||
|
|
||
| module.exports = new Proxy({}, { | ||
| get (_target, prop) { | ||
| return ensureCrypto()[prop] | ||
| }, | ||
| has (_target, prop) { | ||
| try { return prop in ensureCrypto() } catch { return false } | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 'use strict' | ||
|
|
||
| const { QvacErrorRAG, ERR_CODES } = require('../errors') | ||
|
|
||
| function ensureFetch () { | ||
| if (typeof globalThis !== 'undefined' && typeof globalThis.fetch === 'function') { | ||
| return globalThis.fetch.bind(globalThis) | ||
| } | ||
| throw new QvacErrorRAG({ | ||
| code: ERR_CODES.DEPENDENCY_REQUIRED, | ||
| adds: 'No fetch implementation found. Please ensure a Fetch-compatible globalThis.fetch is available (Bare: bare-fetch; Node 18+: built-in; other: provide a polyfill).' | ||
| }) | ||
| } | ||
|
|
||
| function fetchProxy (...args) { | ||
| return ensureFetch()(...args) | ||
| } | ||
|
|
||
| module.exports = fetchProxy | ||
| module.exports.default = fetchProxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict' | ||
|
|
||
| const test = require('brittle') | ||
| const cryptoShim = require('../../src/shims/crypto') | ||
| const { QvacErrorRAG, ERR_CODES } = require('../../src/errors') | ||
|
|
||
| test('crypto shim: throws QvacErrorRAG when no crypto implementation is available', t => { | ||
| const original = globalThis.crypto | ||
| // Force the shim's resolver to find no implementation. | ||
| delete globalThis.crypto | ||
|
|
||
| try { | ||
| const probe = cryptoShim.createHash | ||
| t.fail(`Expected accessing a property on the shim to throw, got ${typeof probe}`) | ||
| } catch (err) { | ||
| t.ok(err instanceof QvacErrorRAG, 'Error should be instance of QvacErrorRAG') | ||
| t.is(err.code, ERR_CODES.DEPENDENCY_REQUIRED, 'Error code should be DEPENDENCY_REQUIRED') | ||
| } finally { | ||
| if (original !== undefined) globalThis.crypto = original | ||
| } | ||
| }) | ||
|
|
||
| test('crypto shim: delegates property access to globalThis.crypto when available', t => { | ||
| const original = globalThis.crypto | ||
| const stub = { | ||
| createHash: () => 'stub', | ||
| anything: 'value' | ||
| } | ||
| globalThis.crypto = stub | ||
|
|
||
| try { | ||
| t.is(typeof cryptoShim.createHash, 'function', 'createHash should be delegated as a function') | ||
| t.is(cryptoShim.createHash(), 'stub', 'createHash invocation should return stubbed value') | ||
| t.is(cryptoShim.anything, 'value', 'arbitrary properties should be delegated to the stub') | ||
| } finally { | ||
| if (original === undefined) { | ||
| delete globalThis.crypto | ||
| } else { | ||
| globalThis.crypto = original | ||
| } | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 'use strict' | ||
|
|
||
| const test = require('brittle') | ||
| const fetchShim = require('../../src/shims/fetch') | ||
| const { QvacErrorRAG, ERR_CODES } = require('../../src/errors') | ||
|
|
||
| test('fetch shim: throws QvacErrorRAG when no fetch implementation is available', async t => { | ||
| const original = globalThis.fetch | ||
| // Force the shim's resolver to find no implementation. | ||
| delete globalThis.fetch | ||
|
|
||
| try { | ||
| await fetchShim('https://example.test') | ||
| t.fail('Expected calling the shim to throw') | ||
| } catch (err) { | ||
| t.ok(err instanceof QvacErrorRAG, 'Error should be instance of QvacErrorRAG') | ||
| t.is(err.code, ERR_CODES.DEPENDENCY_REQUIRED, 'Error code should be DEPENDENCY_REQUIRED') | ||
| } finally { | ||
| if (original !== undefined) globalThis.fetch = original | ||
| } | ||
| }) | ||
|
|
||
| test('fetch shim: delegates calls to globalThis.fetch when available', async t => { | ||
| const original = globalThis.fetch | ||
| let receivedArgs | ||
| globalThis.fetch = async function stub (...args) { | ||
| receivedArgs = args | ||
| return { ok: true, url: args[0] } | ||
| } | ||
|
|
||
| try { | ||
| const result = await fetchShim('https://example.test', { method: 'GET' }) | ||
| t.ok(result.ok, 'Proxy should return the stub response') | ||
| t.is(result.url, 'https://example.test', 'Proxy should pass through positional args') | ||
| t.is(receivedArgs[0], 'https://example.test', 'First arg forwarded to stub') | ||
| t.alike(receivedArgs[1], { method: 'GET' }, 'Second arg forwarded to stub') | ||
| } finally { | ||
| if (original === undefined) { | ||
| delete globalThis.fetch | ||
| } else { | ||
| globalThis.fetch = original | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| test('fetch shim: exposes a default export that aliases the same function', t => { | ||
| t.is(typeof fetchShim, 'function', 'Module export should be a function') | ||
| t.is(fetchShim.default, fetchShim, 'default property should reference the same function') | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.