Skip to content

Feat/wna server#35

Merged
azam-ismail merged 5 commits into
feat/authfrom
feat/wna-server
Jan 30, 2026
Merged

Feat/wna server#35
azam-ismail merged 5 commits into
feat/authfrom
feat/wna-server

Conversation

@azam-ismail
Copy link
Copy Markdown
Collaborator

No description provided.

@azam-ismail azam-ismail changed the base branch from master to feat/auth January 15, 2026 07:52
Comment thread src/routes/admin.ts

const adminLogger = createLogger('Admin');

export const createAdminRouter = (): express.Router => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those endpoints can be called by smartflows, can we make separate http server for it? We need to consider additional security layer here so no one can randomly stop instance

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread src/routes/admin.ts Outdated
});

// Perform graceful shutdown after response is sent
setTimeout(() => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike this setTimeout. Can you send SIGTERM and add event handler on it?

Comment thread src/health/health.ts Outdated
};
};

const getOperatorInfo = async (timeoutMs: number = 5000): Promise<OperatorInfo | undefined> => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move it to different place and export as public method

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread docs/env-vars.md Outdated
| `LOCAL_SOLUTIONS_PATH` | Path to locally hosted NodeRed solution flow files to be used when installing solutions using "local" prefix within WorkLogic field. | `string` | |
| `SS58_FORMAT` | SS58 Key Format. | `number` (_>0_) | `42` |
| `PRETTY_PRINT` | Should pretty print logs. If you plan to use Grafana or any other log tooling it's recommended to set it to false. | `'true' \| 'false'` | `'false'` |
| `LOG_FILE_PATH` | Full path to log file (e.g., /var/log/app.log or ./logs/app.log) | `string` | |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If value is not provided it means that log file transport is disabled

Comment thread src/health/health.ts Outdated
};
};

const getOperatorInfo = async (timeoutMs: number = 5000): Promise<OperatorInfo | undefined> => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of undefined please use null, it's more explicit

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread src/health/health.ts Outdated
return {
id: solution.solutionId,
name,
status: 'Active', // Assume active if installed
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use enum

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread src/health/health.ts Outdated
solutionGroups,
};
} catch {
return undefined;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least print error so we know what is going on

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread src/node-red/red.ts Outdated
export const getAllInstalledSolutionsWithGroups = async (): Promise<InstalledSolutionDetails[]> => {
const tabNodes = await getTabNodes();

const solutions: Array<InstalledSolutionDetails | null> = await Promise.all(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you need Promise.all ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread src/util/logger.ts Outdated
return logPath;
};

const ensureLogDir = (logPath: string): void => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensureLogDirExists

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread src/routes/admin.ts
@@ -0,0 +1,46 @@
import express from 'express';
import { createLogger } from '../util/logger';
import { getIsShuttingDown } from '../shutdown';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a middleware that will not accept new requests?

It can be even applied to submit vote endpoint so we don't accept new votes in case

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@azam-ismail azam-ismail requested a review from hejkerooo January 19, 2026 07:18
Comment thread src/health/health.ts
// Gather configuration (non-sensitive)
let rpcUrl: string | undefined;
let workerAddress: string | undefined;
try {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app should not initialize without worker address but it's ok.

I don't see a point to assign rpcUrl in both places, why not just const rpcUrl = MAIN_CONFIG.PALLET_RPC_URL ? We don't even need to reassign it, just use it in return

Copy link
Copy Markdown
Collaborator Author

@azam-ismail azam-ismail Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/health/health.ts
}

// Get operator information with solution groups
const operatorInfo = await getOperatorInfo();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic does not make sense to me, first there is a try-catch that I assume checks if worker address is present and then you fetch operator info based on worker address without any additional checks?

Please clean up this logic as it's confusing

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated check top logic

Comment thread src/util/logger.ts Outdated
: {}),
};

const cacheKey = `file:${JSON.stringify(options)}`;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make maybe hash out of this JSON stringify? It's not cheap operation

https://www.npmjs.com/package/object-hash
Maybe use this but let's ensure that it will work as expected for our use case

Comment thread src/util/logger.ts Outdated
translateTime: 'SYS:HH:MM:ss',
};

const cacheKey = `pretty:${JSON.stringify(options)}`;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment thread src/util/operator-address-cache.ts Outdated
() => null,
);

await api.disconnect().catch(() => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be in some finally block so we are sure it will execute and not lost

Comment thread src/util/operator-address-cache.ts Outdated
const logger = createLogger('OperatorAddressCache');

// In-memory cache: Map<workerAddress, operatorAddress>
const operatorAddressCache = new Map<string, string>();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operator of worker might be changed while WNS is still running so it will return incorrect information.

Please add some cache expiration, ideally you could use https://www.npmjs.com/package/cache-manager

Comment thread src/util/operator-info.ts

// Extracts solution name, removing UUID suffix if present
const extractSolutionName = (solutionId: string): string => {
const lastDot = solutionId.lastIndexOf('.');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case? It looks like it's for some very specific use case, can you describe that one? In some cases it might lead to undefined-behavior.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put in func description

@azam-ismail azam-ismail requested a review from hejkerooo January 30, 2026 04:00
Comment thread src/health/health.ts
};
};

export const getSolutionGroupsDetailsStatus = async (): Promise<SolutionGroupsDetailsStatus> => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check here

@azam-ismail azam-ismail merged commit 3262629 into feat/auth Jan 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants