Skip to content

Commit

Permalink
parseAuthorization now supports Pinax API token
Browse files Browse the repository at this point in the history
  • Loading branch information
chamorin committed Jan 22, 2024
1 parent 6eb3766 commit 8b97c47
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 55 deletions.
98 changes: 49 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "substreams-sink",
"version": "0.13.5",
"version": "0.13.6",
"description": "Substreams Sink",
"type": "module",
"exports": "./dist/index.js",
Expand Down Expand Up @@ -44,9 +44,9 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@substreams/core": "^0.10.0",
"@substreams/manifest": "^0.9.0",
"@substreams/node": "^0.5.0",
"@substreams/core": "^0.12.0",
"@substreams/manifest": "^0.11.0",
"@substreams/node": "^0.5.2",
"commander": "latest",
"dotenv": "latest",
"prom-client": "latest",
Expand Down
13 changes: 13 additions & 0 deletions src/parseAuthorization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { authIssue } from "@substreams/core";

// Supports 48 characters long Pinax API key
export async function parseAuthorization(authorization: string, url?: string) {
// issue token if includes server_ prefix or is 48 characters long
if (authorization.includes("server_") || authorization.length === 48) {
const { token } = await authIssue(authorization, url);
return token;
}

// no action if Substreams API token is provided
return authorization;
}
5 changes: 3 additions & 2 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRegistry, createRequest, createModuleHashHex, parseAuthorization } from "@substreams/core";
import { createRegistry, createRequest, createModuleHashHex } from "@substreams/core";
import { BlockEmitter, createDefaultTransport } from "@substreams/node";
import { readPackage } from "@substreams/manifest";
import { setTimeout } from "timers/promises";
Expand All @@ -10,6 +10,7 @@ import { logger } from "./logger.js";
import { onInactivitySeconds } from "./inactivitySeconds.js";
import { applyParams } from "./applyParams.js";
import { health } from "./health.js";
import { parseAuthorization } from "./parseAuthorization.js";

export async function setup(options: RunOptions) {
// Configure logging with TSLog
Expand All @@ -26,7 +27,7 @@ export async function setup(options: RunOptions) {
let baseUrl = options.substreamsEndpoint;

// append https if not present
if ( baseUrl.match(/http/) === null ) {
if (baseUrl.match(/http/) === null) {
baseUrl = `https://${baseUrl}`;
}

Expand Down

0 comments on commit 8b97c47

Please sign in to comment.