Skip to content

Commit

Permalink
fix env.process lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Jul 28, 2024
1 parent f3bfb68 commit 8bc00ce
Show file tree
Hide file tree
Showing 8 changed files with 1,874 additions and 21 deletions.
1,861 changes: 1,859 additions & 2 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"tar": "^7.4.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
"typescript": "^5.5.3",
"verdaccio": "^5.31.1"
},
"overrides": {
"web3-eth-contract": "1.10.0"
Expand Down
10 changes: 4 additions & 6 deletions packages/node-sdk/paima-broker/src/event-broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Aedes from 'aedes';
import type { Server } from 'aedes-server-factory';
import { createServer } from 'aedes-server-factory';
import ip from 'ip';
import { ENV } from '@paima/utils';

function isLocalhost(ipAddress: string): boolean {
// note: this only detects simple cases (ex: you're not mapping different hostnames to localhost)
Expand Down Expand Up @@ -70,10 +71,7 @@ export class PaimaEventBroker {
}

private checkEnabled(): void {
// TODO: keep in sync with paima-engine config.ts
if (process.env.MQTT_BROKER == null) return;
// TODO: keep in sync with paima-engine config.ts
if (!['true', '1', 'yes'].includes(String(process.env.MQTT_BROKER).toLocaleLowerCase())) {
if (!ENV.MQTT_BROKER) {
throw new Error('Local MQTT Broker is disabled.');
}
}
Expand All @@ -82,10 +80,10 @@ export class PaimaEventBroker {
switch (this.broker) {
// TODO: use env vars without duplicating default here
case 'Paima-Engine': {
return parseInt(process.env.MQTT_ENGINE_BROKER_PORT ?? '8883', 10);
return ENV.MQTT_ENGINE_BROKER_PORT;
}
case 'Batcher': {
return parseInt(process.env.MQTT_BATCHER_BROKER_PORT ?? '8884', 10);
return ENV.MQTT_BATCHER_BROKER_PORT;
}
}
throw new Error('Unknown engine');
Expand Down
1 change: 1 addition & 0 deletions packages/node-sdk/paima-broker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"src/**/*",
],
"references": [
{ "path": "../../paima-sdk/paima-utils/tsconfig.build.json" },
]
}
13 changes: 3 additions & 10 deletions packages/paima-sdk/paima-events/src/event-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PaimaEventManager } from './event-manager.js';
import { toPattern } from './utils.js';
import { extract, matches } from 'mqtt-pattern';
import { PaimaEventBrokerNames } from './types.js';
import { ENV } from '@paima/utils';

/*
* Paima Event Connector
Expand Down Expand Up @@ -65,11 +66,7 @@ export class PaimaEventConnect {
private async connectPaimaEngine(): Promise<mqtt.MqttClient> {
if (!PaimaEventConnect.clients.engine) {
const broker = PaimaEventBrokerNames.PaimaEngine;
// keep in sync with paima-engine config.ts
const port = process.env.MQTT_ENGINE_BROKER_PORT ?? '8883';
PaimaEventConnect.clients.engine = await this.setupClient(
process.env.MQTT_ENGINE_BROKER_URL ?? 'ws://127.0.0.1:' + port
);
PaimaEventConnect.clients.engine = await this.setupClient(ENV.MQTT_ENGINE_BROKER_URL);
await setupInitialListeners(broker);
}
return PaimaEventConnect.clients.engine;
Expand All @@ -78,11 +75,7 @@ export class PaimaEventConnect {
private async connectBatcher(): Promise<mqtt.MqttClient> {
if (!PaimaEventConnect.clients.batcher) {
const broker = PaimaEventBrokerNames.Batcher;
// keep in sync with batcher config.ts
const port = process.env.MQTT_BATCHER_BROKER_PORT ?? '8883';
PaimaEventConnect.clients.batcher = await this.setupClient(
process.env.MQTT_BATCHER_BROKER_URL ?? 'ws://127.0.0.1:' + port
);
PaimaEventConnect.clients.batcher = await this.setupClient(ENV.MQTT_BATCHER_BROKER_URL);
await setupInitialListeners(broker);
}
return PaimaEventConnect.clients.batcher;
Expand Down
4 changes: 3 additions & 1 deletion packages/paima-sdk/paima-events/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"noEmit": true
},
"include": ["test/**/*", "src/**/*"],
"references": []
"references": [
{ "path": "../paima-utils/tsconfig.build.json" },
]
}
1 change: 0 additions & 1 deletion packages/paima-sdk/paima-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@metamask/eth-json-rpc-middleware": "^12.0.0",
"@metamask/json-rpc-engine": "^7.2.0",
"@sinclair/typebox": "^0.31.28",
"algosdk": "^2.3.0",
"flatted": "^3.2.7",
"web3": "1.10.0",
"yaml": "^2.3.1",
Expand Down
2 changes: 2 additions & 0 deletions tools/scripts/publish-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const program = new Command();
/**
* Step 1: Start Verdaccio
*/
console.log('Starting Verdaccio...');
stopLocalRegistry = await startLocalRegistry({
localRegistryTarget,
storage,
Expand All @@ -62,6 +63,7 @@ const program = new Command();
/**
* Step 2: Publish Library on Verdaccio
*/
console.log('Publishing local packages...');
const nxConfig = JSON.parse(readFileSync(resolve(process.cwd(), `nx.json`)).toString());
const publishStatus = await releasePublish({
groups: Object.keys(nxConfig['release']['groups']),
Expand Down

0 comments on commit 8bc00ce

Please sign in to comment.