Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 94f810d

Browse files
authored
Merge pull request #1267 from baumstern/esm
fix(pkg): fix esm export
2 parents 1de418d + 64f26b2 commit 94f810d

File tree

11 files changed

+72
-40
lines changed

11 files changed

+72
-40
lines changed

contracts/RELEASE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 1.1.1
2+
3+
- Improve ESM support by exporting `index.mjs` instead of `index.js`. @baumstern
4+
5+
## New contributors
6+
7+
Welcoming @baumstern as a new contributor to the hypercerts codebase!
8+
19
# 1.1.0
210

311
- Added Sepolia marketplace deployment

contracts/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hypercerts-org/contracts",
33
"description": "EVM compatible protocol for managing impact claims",
4-
"version": "1.1.0",
4+
"version": "1.1.1-alpha.0",
55
"author": {
66
"name": "Hypercerts Foundation",
77
"url": "https://github.com/hypercerts-org/hypercerts"
@@ -14,13 +14,13 @@
1414
"type": "git"
1515
},
1616
"main": "./dist/cjs/index.js",
17-
"module": "./dist/esm/index.js",
17+
"module": "./dist/esm/index.mjs",
1818
"types": "./dist/index.d.ts",
1919
"exports": {
2020
".": {
21+
"types": "./dist/index.d.ts",
2122
"require": "./dist/cjs/index.js",
22-
"import": "./dist/esm/index.js",
23-
"types": "./dist/index.d.ts"
23+
"import": "./dist/esm/index.mjs"
2424
}
2525
},
2626
"files": [

contracts/rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default [
2323
dir: "dist/esm",
2424
sourcemap: true,
2525
exports: "named",
26+
entryFileNames: "index.mjs",
2627
},
2728
{
2829
format: "cjs",

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"@emotion/react": "^11.10.5",
2424
"@emotion/styled": "^11.10.5",
2525
"@graphprotocol/client-cli": "^2.2.16",
26-
"@hypercerts-org/contracts": "1.1.0",
26+
"@hypercerts-org/contracts": "1.1.1-alpha.0",
2727
"@hypercerts-org/observabletreemap": "workspace: *",
28-
"@hypercerts-org/sdk": "1.4.1",
28+
"@hypercerts-org/sdk": "1.4.2-alpha.0",
2929
"@mui/icons-material": "^5.11.9",
3030
"@mui/material": "^5.11.2",
3131
"@mui/x-date-pickers": "^5.0.12",

pnpm-lock.yaml

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/RELEASE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Release notes
22

3+
## 1.4.2
4+
5+
- Improve ESM support by exporting `index.mjs` instead of `index.js`. @baumstern
6+
- Added dweb IPFS gateway links and use `Promise.any` call to try and fetch data from multiple gateways.
7+
8+
## New contributors
9+
10+
Welcoming @baumstern as a new contributor to the hypercerts codebase!
11+
312
## 1.4.0
413

514
- Added all deployments from `@hypercerts-org/contracts` to the SDK under deploments.

sdk/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"name": "@hypercerts-org/sdk",
3-
"version": "1.4.1",
3+
"version": "1.4.2-alpha.0",
44
"description": "SDK for hypercerts protocol",
55
"repository": "[email protected]:hypercerts-org/hypercerts.git",
66
"author": "Hypercerts team",
77
"license": "Apache-2.0",
88
"source": "src/index.ts",
99
"typedocMain": "src/index.ts",
1010
"main": "./dist/cjs/index.js",
11-
"module": "./dist/esm/index.js",
11+
"module": "./dist/esm/index.mjs",
1212
"types": "./dist/index.d.ts",
1313
"exports": {
14+
"types": "./dist/index.d.ts",
1415
"require": "./dist/cjs/index.js",
15-
"import": "./dist/esm/index.js",
16-
"types": "./dist/index.d.ts"
16+
"import": "./dist/esm/index.mjs"
1717
},
1818
"files": [
1919
"dist",
@@ -24,7 +24,7 @@
2424
"@ethereum-attestation-service/eas-sdk": "1.3.7",
2525
"@ethersproject/abstract-signer": "^5.7.0",
2626
"@graphql-typed-document-node/core": "^3.2.0",
27-
"@hypercerts-org/contracts": "1.1.0",
27+
"@hypercerts-org/contracts": "1.1.1-alpha.0",
2828
"@openzeppelin/merkle-tree": "^1.0.5",
2929
"@urql/core": "^4.2.0",
3030
"@whatwg-node/fetch": "^0.9.13",

sdk/rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default [
2121
{
2222
format: "esm",
2323
dir: "dist/esm",
24+
entryFileNames: "index.mjs",
2425
},
2526
{
2627
format: "cjs",

sdk/src/utils/fetchers.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { logger } from "./logger";
33
import axios from "axios";
44

55
/**
6-
* Fetches data from IPFS using either the NFT Storage gateway or the Web3Up gateway.
6+
* Fetches data from IPFS using either the DWeb IPFS, NFT Storage, or the Web3Up gateway.
77
*
8-
* This function attempts to fetch data from the NFT Storage gateway first. If the request times out, it then tries to fetch the data from the Web3Up gateway.
9-
* If the data cannot be fetched from either gateway, it throws a `StorageError`.
8+
* This function attempts to fetch data from all gateways at the same time and returns on the first on to resolve.
9+
* If the data cannot be fetched from any gateway, it throws a `StorageError`.
1010
*
1111
* @param {string} cidOrIpfsUri - The CID or IPFS URI of the data to fetch.
1212
* @param {number} [timeout=10000] - The timeout for the fetch request in milliseconds. Defaults to 10000ms.
@@ -15,15 +15,20 @@ import axios from "axios";
1515
* @async
1616
*/
1717
const getFromIPFS = async (cidOrIpfsUri: string, timeout: number = 10000): Promise<unknown> => {
18-
const nftStorageGatewayLink = getNftStorageGatewayUri(cidOrIpfsUri);
19-
const web3upGatewayLink = getWeb3UpGatewayUri(cidOrIpfsUri);
20-
logger.debug(`Getting metadata ${cidOrIpfsUri} at ${nftStorageGatewayLink}`);
18+
const requests = [
19+
axios.get(getDwebLinkGatewayUri(cidOrIpfsUri), { timeout }),
20+
axios.get(getNftStorageGatewayUri(cidOrIpfsUri), { timeout }),
21+
axios.get(getWeb3UpGatewayUri(cidOrIpfsUri), { timeout }),
22+
];
2123

22-
const res = await axios.get(nftStorageGatewayLink, { timeout }).catch(() => {
23-
logger.debug(`${nftStorageGatewayLink} timed out.`);
24-
logger.debug(`Getting metadata ${cidOrIpfsUri} at ${web3upGatewayLink}`);
25-
return axios.get(web3upGatewayLink, { timeout });
26-
});
24+
logger.debug(`Getting metadata for ${cidOrIpfsUri}`);
25+
26+
const res = await Promise.any(requests)
27+
.then()
28+
.catch((err) => {
29+
logger.error(err);
30+
throw new StorageError(`Failed to get ${cidOrIpfsUri}`, { error: err });
31+
});
2732

2833
if (!res || !res.data) {
2934
throw new StorageError(`Failed to get ${cidOrIpfsUri}`);
@@ -34,6 +39,11 @@ const getFromIPFS = async (cidOrIpfsUri: string, timeout: number = 10000): Promi
3439

3540
const getCid = (cidOrIpfsUri: string) => cidOrIpfsUri.replace("ipfs://", "");
3641

42+
const getDwebLinkGatewayUri = (cidOrIpfsUri: string) => {
43+
const DWEB_LINK_IPFS_GATEWAY = "https://{cid}.ipfs.dweb.link/";
44+
return DWEB_LINK_IPFS_GATEWAY.replace("{cid}", getCid(cidOrIpfsUri));
45+
};
46+
3747
const getNftStorageGatewayUri = (cidOrIpfsUri: string) => {
3848
const NFT_STORAGE_IPFS_GATEWAY = "https://nftstorage.link/ipfs/{cid}";
3949
return NFT_STORAGE_IPFS_GATEWAY.replace("{cid}", getCid(cidOrIpfsUri));

sdk/test/utils/allowlist.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ describe("Fetchers", () => {
4747

4848
expect(res?.proof).to.deep.equal(tree.getProof(0));
4949
expect(res?.root).to.deep.equal(tree.root);
50-
expect(stub.calledOnce).to.be.true;
50+
expect(stub.calledThrice).to.be.true;
5151
});
5252
});

0 commit comments

Comments
 (0)