-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Fetch and add the utility property (#375)
* feat: Fetch and add the utility property * fix: Remove double quotes
- Loading branch information
1 parent
764cc45
commit 2ae497e
Showing
16 changed files
with
513 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 @@ | ||
import { URL } from 'url' | ||
import { | ||
IFetchComponent, | ||
ILoggerComponent, | ||
} from '@well-known-components/interfaces' | ||
import { IBuilderComponent } from './types' | ||
|
||
export function createBuilderComponent(options: { | ||
url: string | ||
logs: ILoggerComponent | ||
fetcher: IFetchComponent | ||
}): IBuilderComponent { | ||
const { fetcher, url, logs } = options | ||
const logger = logs.getLogger('builder-component') | ||
|
||
return { | ||
async getItemUtility( | ||
collectionAddress: string, | ||
itemId: string | ||
): Promise<string | undefined> { | ||
try { | ||
const baseUrl = new URL(url) | ||
baseUrl.pathname = `/v1/published-collections/${collectionAddress}/items/${itemId}/utility` | ||
const response = await fetcher.fetch(baseUrl.toString()) | ||
if (!response.ok) { | ||
throw new Error( | ||
`Failed to fetch utility for item: ${response.status}` | ||
) | ||
} | ||
const utility = (await response.json()) as { | ||
data: { utility: string | null } | ||
} | ||
return utility.data.utility ?? undefined | ||
} catch (_e) { | ||
logger.info( | ||
`Failed looking for the utility of the item: ${collectionAddress} - ${itemId}.` | ||
) | ||
return undefined | ||
} | ||
}, | ||
} | ||
} |
This file contains 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,2 @@ | ||
export * from './component' | ||
export * from './types' |
This file contains 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,6 @@ | ||
export interface IBuilderComponent { | ||
getItemUtility( | ||
collectionAddress: string, | ||
itemId: string | ||
): Promise<string | undefined> | ||
} |
This file contains 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 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,2 @@ | ||
export * from './component' | ||
export * from './types' |
This file contains 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 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
Oops, something went wrong.