Skip to content

Commit 1539fd1

Browse files
fix(sdk): replace uuid with crypto.randomUUID to fix Jest ESM incompatibility (#1000)
Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Miguel_LZPF <miguel.carpena@io.builders> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Miguel_LZPF <miguel.carpena@io.builders>
1 parent 0d4f003 commit 1539fd1

7 files changed

Lines changed: 26 additions & 11 deletions

File tree

apps/ats/web/jest.polyfills.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ class _LRU {
4747
// For ESM, use jest.mock or manual global override if needed
4848
// Example for Jest:
4949
// jest.mock('lru-cache', () => LRU);
50+
51+
// crypto.randomUUID is not available in JSDOM — polyfill from Node.js crypto
52+
if (typeof globalThis.crypto === "undefined") {
53+
globalThis.crypto = {};
54+
}
55+
if (typeof globalThis.crypto.randomUUID !== "function") {
56+
globalThis.crypto.randomUUID = require("node:crypto").randomUUID;
57+
}

package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ats/sdk/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"@hashgraph/eslint-config": "*",
4949
"@types/jest": "^29.2.6",
5050
"@types/node": "^18.11.18",
51-
"@types/uuid": "^9.0.0",
5251
"babel-jest": "^30.1.2",
5352
"jest": "^29.6.4",
5453
"npm-run-all": "^4.1.5",
@@ -86,7 +85,6 @@
8685
"long": "^4.0.0",
8786
"reflect-metadata": "^0.2.2",
8887
"tsyringe": "^4.8.0",
89-
"uuid": "^9.0.0",
9088
"winston": "^3.8.2",
9189
"winston-daily-rotate-file": "^4.7.1"
9290
},

packages/ats/sdk/src/core/decorator/CommandHandlerDecorator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import { COMMAND_HANDLER_METADATA, COMMAND_METADATA } from "@core/Constants";
4-
import { v4 } from "uuid";
54
import { BaseCommand } from "@core/command/Command";
65
import { injectable } from "tsyringe";
76
import { Constructor } from "@core/Type";
@@ -17,7 +16,7 @@ export const CommandHandler = (command: BaseCommand): ClassDecorator => {
1716
return (target: object) => {
1817
const tgt = target as Constructor<typeof target>;
1918
injectable()(tgt);
20-
const id = v4();
19+
const id = crypto.randomUUID();
2120
if (!Reflect.hasMetadata(COMMAND_METADATA, command)) {
2221
Reflect.defineMetadata(COMMAND_METADATA, { id }, command);
2322
}

packages/ats/sdk/src/core/decorator/QueryHandlerDecorator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

33
import { QUERY_HANDLER_METADATA, QUERY_METADATA } from "@core/Constants";
4-
import { v4 } from "uuid";
54
import { BaseQuery } from "@core/query/Query";
65
import { Constructor } from "@core/Type";
76
import { injectable } from "tsyringe";
@@ -17,7 +16,7 @@ export const QueryHandler = (query: BaseQuery): ClassDecorator => {
1716
return (target: object) => {
1817
injectable()(target as Constructor<typeof target>);
1918
if (!Reflect.hasMetadata(QUERY_METADATA, query)) {
20-
Reflect.defineMetadata(QUERY_METADATA, { id: v4() }, query);
19+
Reflect.defineMetadata(QUERY_METADATA, { id: crypto.randomUUID() }, query);
2120
}
2221
Reflect.defineMetadata(QUERY_HANDLER_METADATA, query, target);
2322
};

packages/mass-payout/sdk/src/core/decorator/CommandHandlerDecorator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { Injectable } from "@nestjs/common";
44
import { COMMAND_HANDLER_METADATA, COMMAND_METADATA } from "../Constants";
5-
import { v4 } from "uuid";
65
import { BaseCommand } from "../command/Command.js";
76
import { Constructor } from "../Type.js";
87

@@ -17,7 +16,7 @@ export const CommandHandler = (command: BaseCommand): ClassDecorator => {
1716
return (target: object) => {
1817
const tgt = target as Constructor<typeof target>;
1918
Injectable()(tgt);
20-
const id = v4();
19+
const id = crypto.randomUUID();
2120
if (!Reflect.hasMetadata(COMMAND_METADATA, command)) {
2221
Reflect.defineMetadata(COMMAND_METADATA, { id }, command);
2322
}

packages/mass-payout/sdk/src/core/decorator/QueryHandlerDecorator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { Injectable } from "@nestjs/common";
44
import { QUERY_HANDLER_METADATA, QUERY_METADATA } from "../Constants";
5-
import { v4 } from "uuid";
65
import { BaseQuery } from "../query/Query";
76
import { Constructor } from "../Type";
87

@@ -17,7 +16,7 @@ export const QueryHandler = (query: BaseQuery): ClassDecorator => {
1716
return (target: object) => {
1817
Injectable()(target as Constructor<typeof target>);
1918
if (!Reflect.hasMetadata(QUERY_METADATA, query)) {
20-
Reflect.defineMetadata(QUERY_METADATA, { id: v4() }, query);
19+
Reflect.defineMetadata(QUERY_METADATA, { id: crypto.randomUUID() }, query);
2120
}
2221
Reflect.defineMetadata(QUERY_HANDLER_METADATA, query, target);
2322
};

0 commit comments

Comments
 (0)