@0xsequence/marketplace 2.0.23

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/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@0xsequence/marketplace",
3
+ "version": "2.0.23",
4
+ "description": "marketplace sub-package for Sequence",
5
+ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/marketplace",
6
+ "source": "src/index.ts",
7
+ "main": "dist/0xsequence-marketplace.cjs.js",
8
+ "module": "dist/0xsequence-marketplace.esm.js",
9
+ "author": "Horizon Blockchain Games",
10
+ "license": "Apache-2.0",
11
+ "dependencies": {},
12
+ "peerDependencies": {},
13
+ "devDependencies": {},
14
+ "files": [
15
+ "src",
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "test": "echo",
20
+ "typecheck": "tsc --noEmit"
21
+ }
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1,38 @@
1
+ export * from './marketplace.gen'
2
+
3
+ import { Marketplace as MarketplaceRpc } from './marketplace.gen'
4
+
5
+ const fetch = globalThis.fetch
6
+
7
+ export class MarketplaceIndexer extends MarketplaceRpc {
8
+ constructor(
9
+ hostname: string,
10
+ public projectAccessKey?: string,
11
+ public jwtAuth?: string
12
+ ) {
13
+ super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch)
14
+ this.fetch = this._fetch
15
+ }
16
+
17
+ _fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => {
18
+ // automatically include jwt and access key auth header to requests
19
+ // if its been set on the api client
20
+ const headers: { [key: string]: any } = {}
21
+
22
+ const jwtAuth = this.jwtAuth
23
+ const projectAccessKey = this.projectAccessKey
24
+
25
+ if (jwtAuth && jwtAuth.length > 0) {
26
+ headers['Authorization'] = `BEARER ${jwtAuth}`
27
+ }
28
+
29
+ if (projectAccessKey && projectAccessKey.length > 0) {
30
+ headers['X-Access-Key'] = projectAccessKey
31
+ }
32
+
33
+ // before the request is made
34
+ init!.headers = { ...init!.headers, ...headers }
35
+
36
+ return fetch(input, init)
37
+ }
38
+ }