Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace crypto module with crypto object associated with the global object. #593

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,449 changes: 1,898 additions & 3,551 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,35 @@
"dependencies": {
"@grpc/grpc-js": "^1.9.3",
"@js-temporal/polyfill": "^0.3.0",
"@microsoft/durabletask-js": "^0.1.0-alpha.1",
"@types/google-protobuf": "^3.15.5",
"@types/node-fetch": "^2.6.2",
"body-parser": "^1.19.0",
"express": "^4.18.2",
"google-protobuf": "^3.18.0",
"http-terminator": "^3.2.0",
"@microsoft/durabletask-js": "^0.1.0-alpha.1",
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@types/body-parser": "^1.19.1",
"@types/express": "^4.17.15",
"@types/jest": "^27.0.1",
"@types/node": "^16.9.1",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.31",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.5.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.1.3",
"grpc_tools_node_protoc_ts": "^5.3.2",
"husky": "^8.0.1",
"jest": "^27.2.0",
"jest": "^29.7.0",
"nodemon": "^2.0.20",
"prettier": "^2.4.0",
"prettier": "^3.2.5",
"pretty-quick": "^3.1.3",
"ts-jest": "^27.0.5",
"typescript": "^4.5.5"
"ts-jest": "^29.1.2",
"typescript": "^5.4.5"
},
"repository": {
"type": "git",
Expand Down
4 changes: 1 addition & 3 deletions src/actors/ActorId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { randomUUID } from "crypto";

export default class ActorId {
private readonly id: string;

Expand All @@ -24,7 +22,7 @@ export default class ActorId {
}

static createRandomId(): ActorId {
return new ActorId(randomUUID());
return new ActorId(crypto.randomUUID());
}

getId() {
Expand Down
3 changes: 1 addition & 2 deletions src/implementation/Client/HTTPClient/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { WorkflowGetResponseType } from "../../../types/workflow/WorkflowGetResp
import { Logger } from "../../../logger/Logger";
import { KeyValueType } from "../../../types/KeyValue.type";
import { WorkflowStartOptions } from "../../../types/workflow/WorkflowStartOptions.type";
import { randomUUID } from "crypto";
import { createHTTPQueryParam } from "../../../utils/Client.util";
import { WorkflowRaiseOptions } from "../../../types/workflow/WorkflowRaiseOptions.type";
import { PropertyRequiredError } from "../../../errors/PropertyRequiredError";
Expand Down Expand Up @@ -81,7 +80,7 @@ export default class HTTPClientWorkflow implements IClientWorkflow {
}

if (!instanceId) {
instanceId = randomUUID();
instanceId = crypto.randomUUID();
}

workflowComponent = workflowComponent ?? HTTPClientWorkflow.DEFAULT_WORKFLOW_COMPONENT;
Expand Down
5 changes: 2 additions & 3 deletions src/utils/Client.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { randomUUID } from "crypto";
import { Map } from "google-protobuf";

import { ConfigurationItem as ConfigurationItemProto } from "../proto/dapr/proto/common/v1/common_pb";
Expand Down Expand Up @@ -179,15 +178,15 @@ export function getBulkPublishEntries(messages: PubSubBulkPublishMessage[]): Pub
// If message is a PubSubBulkPublishEntry, use it directly
if (typeof message !== "string" && "event" in message) {
return {
entryID: message.entryID ? message.entryID : randomUUID(),
entryID: message.entryID ? message.entryID : crypto.randomUUID(),
event: message.event,
contentType: message.contentType ? message.contentType : getContentType(message.event),
metadata: message.metadata ? message.metadata : {},
};
}
// Otherwise, create a PubSubBulkPublishEntry from the message
return {
entryID: randomUUID(),
entryID: crypto.randomUUID(),
event: message,
contentType: getContentType(message),
metadata: {},
Expand Down
17 changes: 8 additions & 9 deletions test/e2e/common/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { randomUUID } from "crypto";
import {
CommunicationProtocolEnum,
DaprClient,
Expand Down Expand Up @@ -153,21 +152,21 @@ describe("common/client", () => {

describe("distributed lock", () => {
runIt("should be able to acquire a new lock and unlock", async (client: DaprClient) => {
const resourceId = randomUUID();
const resourceId = crypto.randomUUID();
const lock = await client.lock.lock("redislock", resourceId, "owner1", 1000);
expect(lock.success).toEqual(true);
const unlock = await client.lock.unlock("redislock", resourceId, "owner1");
expect(unlock.status).toEqual(LockStatus.Success);
});

runIt("should be not be able to unlock when the lock is not acquired", async (client: DaprClient) => {
const resourceId = randomUUID();
const resourceId = crypto.randomUUID();
const unlock = await client.lock.unlock("redislock", resourceId, "owner1");
expect(unlock.status).toEqual(LockStatus.LockDoesNotExist);
});

runIt("should be able to acquire a lock after the previous lock is expired", async (client: DaprClient) => {
const resourceId = randomUUID();
const resourceId = crypto.randomUUID();
let lock = await client.lock.lock("redislock", resourceId, "owner1", 5);
expect(lock.success).toEqual(true);
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand All @@ -178,7 +177,7 @@ describe("common/client", () => {
runIt(
"should not be able to acquire a lock when the same lock is acquired by another owner",
async (client: DaprClient) => {
const resourceId = randomUUID();
const resourceId = crypto.randomUUID();
const lockOne = await client.lock.lock("redislock", resourceId, "owner1", 5);
expect(lockOne.success).toEqual(true);
const lockTwo = await client.lock.lock("redislock", resourceId, "owner2", 5);
Expand All @@ -189,17 +188,17 @@ describe("common/client", () => {
runIt(
"should be able to acquire a lock when a different lock is acquired by another owner",
async (client: DaprClient) => {
const lockOne = await client.lock.lock("redislock", randomUUID(), "owner1", 5);
const lockOne = await client.lock.lock("redislock", crypto.randomUUID(), "owner1", 5);
expect(lockOne.success).toEqual(true);
const lockTwo = await client.lock.lock("redislock", randomUUID(), "owner2", 5);
const lockTwo = await client.lock.lock("redislock", crypto.randomUUID(), "owner2", 5);
expect(lockTwo.success).toEqual(true);
},
);

runIt(
"should not be able to acquire a lock when that lock is acquired by another owner/process",
async (client: DaprClient) => {
const resourceId = randomUUID();
const resourceId = crypto.randomUUID();
const lockOne = await client.lock.lock("redislock", resourceId, "owner3", 5);
expect(lockOne.success).toEqual(true);
const lockTwo = await client.lock.lock("redislock", resourceId, "owner4", 5);
Expand All @@ -210,7 +209,7 @@ describe("common/client", () => {
runIt(
"should not be able to unlock a lock when that lock is acquired by another owner/process",
async (client: DaprClient) => {
const resourceId = randomUUID();
const resourceId = crypto.randomUUID();
const lockOne = await client.lock.lock("redislock", resourceId, "owner5", 5);
expect(lockOne.success).toEqual(true);
const unlock = await client.lock.unlock("redislock", resourceId, "owner6");
Expand Down
9 changes: 4 additions & 5 deletions test/unit/actor/actorRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ActorId from "../../../src/actors/ActorId";
import DemoActorCounterImpl from "../../actor/DemoActorCounterImpl";
import DemoActorSayImpl from "../../actor/DemoActorSayImpl";
import { ActorRuntimeOptions } from "../../../src/types/actors/ActorRuntimeOptions";
import { randomUUID } from "crypto";

describe("ActorRuntime", () => {
let client: DaprClient;
Expand Down Expand Up @@ -102,7 +101,7 @@ describe("ActorRuntime", () => {
});

it("should be able to invoke an actor", async () => {
const actorId = randomUUID();
const actorId = crypto.randomUUID();

await runtime.registerActor(DemoActorSayImpl);

Expand All @@ -111,7 +110,7 @@ describe("ActorRuntime", () => {
});

it("should receive an error if the actor method does not exist", async () => {
const actorId = randomUUID();
const actorId = crypto.randomUUID();

await runtime.registerActor(DemoActorCounterImpl);

Expand All @@ -127,11 +126,11 @@ describe("ActorRuntime", () => {

it("should be able to fire a reminder", async () => {
// TODO: add this test
new ActorId(randomUUID());
new ActorId(crypto.randomUUID());
});

it("should be able to fire a timer", async () => {
// TODO: add this test
new ActorId(randomUUID());
new ActorId(crypto.randomUUID());
});
});
5 changes: 2 additions & 3 deletions test/unit/protocols/http/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ limitations under the License.
import HTTPClient from "../../../../src/implementation/Client/HTTPClient/HTTPClient";
import { PropertyRequiredError } from "../../../../src/errors/PropertyRequiredError";
import HTTPClientWorkflow from "../../../../src/implementation/Client/HTTPClient/workflow";
import { randomUUID } from "crypto";

describe("workflow", () => {
const client = new HTTPClient({
Expand All @@ -34,12 +33,12 @@ describe("workflow", () => {
await expect(workflow._invokeMethod("", "raise")).rejects.toThrow(PropertyRequiredError);
});
it("should throw PropertyRequiredError when method variable is not provided in _invokeMethod method", async () => {
await expect(workflow._invokeMethod(randomUUID(), "")).rejects.toThrow(PropertyRequiredError);
await expect(workflow._invokeMethod(crypto.randomUUID(), "")).rejects.toThrow(PropertyRequiredError);
});
it("should throw PropertyRequiredError when instanceID variable is not provided in raise method", async () => {
await expect(workflow.raise("", "Event")).rejects.toThrow(PropertyRequiredError);
});
it("should throw PropertyRequiredError when eventName variable is not provided in raise method", async () => {
await expect(workflow.raise(randomUUID(), "")).rejects.toThrow(PropertyRequiredError);
await expect(workflow.raise(crypto.randomUUID(), "")).rejects.toThrow(PropertyRequiredError);
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"resolveJsonModule": true,
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": [] /* Specify library files to be included in the compilation. */,
// "lib": [] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
Expand Down