@0xsequence/metadata 1.3.0 → 1.4.0

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.
@@ -262,8 +262,28 @@ const buildResponse = res => {
262
262
 
263
263
  const fetch = typeof global === 'object' ? global.fetch : window.fetch;
264
264
  class SequenceMetadataClient extends Metadata {
265
- constructor(hostname = 'https://metadata.sequence.app') {
265
+ constructor(hostname = 'https://metadata.sequence.app', _projectAccessKey, _jwtAuth) {
266
266
  super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch);
267
+ this._fetch = (input, init) => {
268
+ // automatically include jwt and access key auth header to requests
269
+ // if its been set on the api client
270
+ const headers = {};
271
+ const jwtAuth = this.jwtAuth;
272
+ const projectAccessKey = this.projectAccessKey;
273
+ if (jwtAuth && jwtAuth.length > 0) {
274
+ headers['Authorization'] = `BEARER ${jwtAuth}`;
275
+ }
276
+ if (projectAccessKey && projectAccessKey.length > 0) {
277
+ headers['X-Access-Key'] = projectAccessKey;
278
+ }
279
+
280
+ // before the request is made
281
+ init.headers = _extends({}, init.headers, headers);
282
+ return fetch(input, init);
283
+ };
284
+ this.projectAccessKey = _projectAccessKey;
285
+ this.jwtAuth = _jwtAuth;
286
+ this.fetch = this._fetch;
267
287
  }
268
288
  }
269
289
 
@@ -262,8 +262,28 @@ const buildResponse = res => {
262
262
 
263
263
  const fetch = typeof global === 'object' ? global.fetch : window.fetch;
264
264
  class SequenceMetadataClient extends Metadata {
265
- constructor(hostname = 'https://metadata.sequence.app') {
265
+ constructor(hostname = 'https://metadata.sequence.app', _projectAccessKey, _jwtAuth) {
266
266
  super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch);
267
+ this._fetch = (input, init) => {
268
+ // automatically include jwt and access key auth header to requests
269
+ // if its been set on the api client
270
+ const headers = {};
271
+ const jwtAuth = this.jwtAuth;
272
+ const projectAccessKey = this.projectAccessKey;
273
+ if (jwtAuth && jwtAuth.length > 0) {
274
+ headers['Authorization'] = `BEARER ${jwtAuth}`;
275
+ }
276
+ if (projectAccessKey && projectAccessKey.length > 0) {
277
+ headers['X-Access-Key'] = projectAccessKey;
278
+ }
279
+
280
+ // before the request is made
281
+ init.headers = _extends({}, init.headers, headers);
282
+ return fetch(input, init);
283
+ };
284
+ this.projectAccessKey = _projectAccessKey;
285
+ this.jwtAuth = _jwtAuth;
286
+ this.fetch = this._fetch;
267
287
  }
268
288
  }
269
289
 
@@ -258,8 +258,28 @@ const buildResponse = res => {
258
258
 
259
259
  const fetch = typeof global === 'object' ? global.fetch : window.fetch;
260
260
  class SequenceMetadataClient extends Metadata {
261
- constructor(hostname = 'https://metadata.sequence.app') {
261
+ constructor(hostname = 'https://metadata.sequence.app', _projectAccessKey, _jwtAuth) {
262
262
  super(hostname.endsWith('/') ? hostname.slice(0, -1) : hostname, fetch);
263
+ this._fetch = (input, init) => {
264
+ // automatically include jwt and access key auth header to requests
265
+ // if its been set on the api client
266
+ const headers = {};
267
+ const jwtAuth = this.jwtAuth;
268
+ const projectAccessKey = this.projectAccessKey;
269
+ if (jwtAuth && jwtAuth.length > 0) {
270
+ headers['Authorization'] = `BEARER ${jwtAuth}`;
271
+ }
272
+ if (projectAccessKey && projectAccessKey.length > 0) {
273
+ headers['X-Access-Key'] = projectAccessKey;
274
+ }
275
+
276
+ // before the request is made
277
+ init.headers = _extends({}, init.headers, headers);
278
+ return fetch(input, init);
279
+ };
280
+ this.projectAccessKey = _projectAccessKey;
281
+ this.jwtAuth = _jwtAuth;
282
+ this.fetch = this._fetch;
263
283
  }
264
284
  }
265
285
 
@@ -1,5 +1,8 @@
1
1
  export * from "./metadata.gen.js";
2
2
  import { Metadata as MetadataRpc } from "./metadata.gen.js";
3
3
  export declare class SequenceMetadataClient extends MetadataRpc {
4
- constructor(hostname?: string);
4
+ projectAccessKey?: string | undefined;
5
+ jwtAuth?: string | undefined;
6
+ constructor(hostname?: string, projectAccessKey?: string | undefined, jwtAuth?: string | undefined);
7
+ _fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
5
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/metadata",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "metadata sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/metadata",
6
6
  "source": "src/index.ts",
package/src/index.ts CHANGED
@@ -5,7 +5,34 @@ import { Metadata as MetadataRpc } from './metadata.gen'
5
5
  const fetch = typeof global === 'object' ? global.fetch : window.fetch
6
6
 
7
7
  export class SequenceMetadataClient extends MetadataRpc {
8
- constructor(hostname: string = 'https://metadata.sequence.app') {
8
+ constructor(
9
+ hostname: string = 'https://metadata.sequence.app',
10
+ public projectAccessKey?: string,
11
+ public jwtAuth?: string
12
+ ) {
9
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)
10
37
  }
11
38
  }