Skip to content

Commit 5f0260a

Browse files
authored
Merge pull request #225 from blockful/feat/anticapture-api-auth-token
feat: add Bearer token auth for Anticapture API Gateway
2 parents 3758a30 + 391e3e5 commit 5f0260a

11 files changed

Lines changed: 35 additions & 4 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# === REQUIRED CONFIGURATION ===
55
ANTICAPTURE_GRAPHQL_ENDPOINT=https://api-gateway-production-0879.up.railway.app/graphql
6+
BLOCKFUL_API_TOKEN=
67

78
# === NOTIFICATION PLATFORMS ===
89
TELEGRAM_BOT_TOKEN=

apps/consumers/example.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
22
ANTICAPTURE_GRAPHQL_ENDPOINT=https://api-gateway/graphql
3+
BLOCKFUL_API_TOKEN=
34
SUBSCRIPTION_SERVER_URL=http://localhost:3001
45
API_PORT=3000

apps/consumers/src/config/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const envSchema = z.object({
1010
SLACK_SIGNING_SECRET: z.string(),
1111
TOKEN_ENCRYPTION_KEY: z.string(),
1212
ANTICAPTURE_GRAPHQL_ENDPOINT: z.string().url("ANTICAPTURE_GRAPHQL_ENDPOINT must be a valid URL"),
13+
BLOCKFUL_API_TOKEN: z.string().optional(),
1314
SUBSCRIPTION_SERVER_URL: z.string(),
1415
RABBITMQ_URL: z.string().url(),
1516
PORT: z.coerce.number().positive().optional().default(3002),
@@ -24,6 +25,7 @@ export function loadConfig() {
2425
slackSigningSecret: env.SLACK_SIGNING_SECRET,
2526
tokenEncryptionKey: env.TOKEN_ENCRYPTION_KEY,
2627
anticaptureGraphqlEndpoint: env.ANTICAPTURE_GRAPHQL_ENDPOINT,
28+
blockfulApiToken: env.BLOCKFUL_API_TOKEN,
2729
subscriptionServerUrl: env.SUBSCRIPTION_SERVER_URL,
2830
rabbitmqUrl: env.RABBITMQ_URL,
2931
port: env.PORT,

apps/consumers/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ const slackClient = new SlackClient(
3535
// Create and start the application
3636
const app = new App(
3737
config.subscriptionServerUrl,
38-
axios.create({ baseURL: config.anticaptureGraphqlEndpoint }),
38+
axios.create({
39+
baseURL: config.anticaptureGraphqlEndpoint,
40+
headers: {
41+
...(config.blockfulApiToken && {
42+
Authorization: `Bearer ${config.blockfulApiToken}`,
43+
}),
44+
},
45+
}),
3946
config.rabbitmqUrl,
4047
ensResolver,
4148
telegramClient,

apps/dispatcher/src/app.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class App {
2323
private subscriptionServerUrl: string,
2424
private rabbitmqUrl: string,
2525
private anticaptureGraphqlEndpoint: string,
26-
private anticaptureHttpClient?: any
26+
private anticaptureHttpClient?: any,
27+
private blockfulApiToken?: string
2728
) {}
2829

2930
private async setupServices(): Promise<void> {
@@ -42,6 +43,9 @@ export class App {
4243
baseURL: this.anticaptureGraphqlEndpoint,
4344
headers: {
4445
'Content-Type': 'application/json',
46+
...(this.blockfulApiToken && {
47+
Authorization: `Bearer ${this.blockfulApiToken}`,
48+
}),
4549
},
4650
});
4751
const anticaptureClient = new AnticaptureClient(anticaptureAxiosClient);

apps/dispatcher/src/envConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const envSchema = z.object({
1111
SUBSCRIPTION_SERVER_URL: z.string().url(),
1212
RABBITMQ_URL: z.string().url(),
1313
ANTICAPTURE_GRAPHQL_ENDPOINT: z.string().url(),
14+
BLOCKFUL_API_TOKEN: z.string().optional(),
1415
});
1516

1617
export function loadConfig() {
@@ -21,5 +22,6 @@ export function loadConfig() {
2122
subscriptionServerUrl: env.SUBSCRIPTION_SERVER_URL,
2223
rabbitmqUrl: env.RABBITMQ_URL,
2324
anticaptureGraphqlEndpoint: env.ANTICAPTURE_GRAPHQL_ENDPOINT,
25+
blockfulApiToken: env.BLOCKFUL_API_TOKEN,
2426
} as const;
2527
}

apps/dispatcher/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const config = loadConfig();
55
const app = new App(
66
config.subscriptionServerUrl,
77
config.rabbitmqUrl,
8-
config.anticaptureGraphqlEndpoint
8+
config.anticaptureGraphqlEndpoint,
9+
undefined,
10+
config.blockfulApiToken
911
);
1012

1113
(async () => {

apps/logic-system/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Anticapture GraphQL API
22
ANTICAPTURE_GRAPHQL_ENDPOINT="https://api-gateway/graphql"
3+
BLOCKFUL_API_TOKEN=
34

45
# Dispatcher service configuration
56
DISPATCHER_ENDPOINT="http://localhost:3000/api/dispatch"

apps/logic-system/src/config/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const validProposalStatuses = [
1313
// Define environment variables schema with validation
1414
const envSchema = z.object({
1515
ANTICAPTURE_GRAPHQL_ENDPOINT: z.string().url('ANTICAPTURE_GRAPHQL_ENDPOINT must be a valid URL'),
16+
BLOCKFUL_API_TOKEN: z.string().optional(),
1617
RABBITMQ_URL: z.string().url(),
1718
TRIGGER_INTERVAL: z.coerce.number().optional().default(60000),
1819
PROPOSAL_STATUS: z.enum(validProposalStatuses),

apps/logic-system/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import { env } from './config/env';
55
const app = new App(
66
env.TRIGGER_INTERVAL,
77
env.PROPOSAL_STATUS,
8-
axios.create({ baseURL: env.ANTICAPTURE_GRAPHQL_ENDPOINT }),
8+
axios.create({
9+
baseURL: env.ANTICAPTURE_GRAPHQL_ENDPOINT,
10+
headers: {
11+
...(env.BLOCKFUL_API_TOKEN && {
12+
Authorization: `Bearer ${env.BLOCKFUL_API_TOKEN}`,
13+
}),
14+
},
15+
}),
916
env.RABBITMQ_URL,
1017
);
1118

0 commit comments

Comments
 (0)