Skip to content

add function to set default certificate subject for ESM compatibility#1519

Open
PriyankuBiswas-EH wants to merge 4 commits into
node-opcua:masterfrom
PriyankuBiswas-EH:master
Open

add function to set default certificate subject for ESM compatibility#1519
PriyankuBiswas-EH wants to merge 4 commits into
node-opcua:masterfrom
PriyankuBiswas-EH:master

Conversation

@PriyankuBiswas-EH

Copy link
Copy Markdown

The "export let" in "node-opcua-common/make_subject.ts" is technically mutable from within the module, but ESM module namespace objects are frozen from the outside. The cleanest short-term fix is using require() in a CJS context. The real fix needs to come from the library itself by exposing a setter function.

The library should expose a setter function like "setDefaultCertificateSubject(value: string)" that mutates the internal variable from within the module (which is always allowed). This is the proper fix. The current design is broken for ESM consumers.

Copilot AI review requested due to automatic review settings June 2, 2026 22:12
@CLAassistant

CLAassistant commented Jun 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a supported way to mutate the module-level defaultCertificateSubject for ESM consumers by introducing a setter function.

Changes:

  • Introduced setDefaultCertificateSubject(value) to update defaultCertificateSubject from within the module
  • Documented why direct assignment to an exported let doesn’t work for ESM namespace imports and provided an example

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/node-opcua-common/source/make_subject.ts
Comment thread packages/node-opcua-common/source/make_subject.ts Outdated
// 3. Validate the overall shape: one or more /KEY=VALUE segments.
// Keys are one or more word characters; values may be anything except a raw slash
// (nested values would need quoting, which is out of scope here).
const subjectPattern = /^(?:\/[A-Za-z][A-Za-z0-9]*=[^/]+)+$/;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have a utility to parse a CN string and verify it in node-opcua-pki or node-opcua-crupt. I'd suggest reusing existing material rather than maintaining a hard-to-validate REGEXP.

We need a single source of truth.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @erossignon , I updated the code as per your comment, reusing the existing function.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread packages/node-opcua-common/source/make_subject.ts
Comment thread packages/node-opcua-common/source/make_subject.ts
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.

4 participants