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

Add: New package JSON hash added #186

Open
wants to merge 54 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
607bbac
Feat!: added support for more complex filters
Akalanka47000 Mar 25, 2024
acb7572
Merge pull request #168 from sliit-foss/feat/increase-filter-query-fi…
Akalanka47000 Mar 25, 2024
6269a04
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Mar 25, 2024
00260c1
Fix(mongoose-audit): exception when change is null
Akalanka47000 Apr 9, 2024
3f4071e
Merge pull request #171 from sliit-foss/fix/mongoose-audit-exception
Akalanka47000 Apr 9, 2024
dab0359
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Apr 9, 2024
05abfbc
Chore(git): add non-pnpm lock files to gitignore
ThulinaWickramasinghe Apr 12, 2024
d857c8a
Chore(git-hooks): remove husky
ThulinaWickramasinghe Apr 12, 2024
4684693
Chore(git-hooks): setup lefthook
ThulinaWickramasinghe Apr 12, 2024
661eeb0
Merge pull request #1 from ThulinaWickramasinghe/feat/integrate-lefthook
ThulinaWickramasinghe Apr 12, 2024
34dd036
Fix: address PR comments
ThulinaWickramasinghe Apr 12, 2024
3964d52
Fix: add cache flag for eslint
ThulinaWickramasinghe Apr 12, 2024
3b32d86
Merge pull request #2 from ThulinaWickramasinghe/feat/integrate-lefthook
ThulinaWickramasinghe Apr 12, 2024
e2f4d01
Fix(lefthook): change linting command from 'code' to 'lint'
ThulinaWickramasinghe Apr 13, 2024
b5d79d1
Chore(deps): update prettier version
ThulinaWickramasinghe Apr 13, 2024
8e7e60f
Merge pull request #3 from ThulinaWickramasinghe/feat/integrate-lefthook
ThulinaWickramasinghe Apr 13, 2024
1bd33c9
Chore: updated lockfile
Akalanka47000 Apr 14, 2024
f297337
Chore: updated lefthook scripts
Akalanka47000 Apr 14, 2024
222c131
Merge pull request #173 from ThulinaWickramasinghe/main
Akalanka47000 Apr 14, 2024
9d6d920
feat(actions-exec-wrapper): add type support
ThulinaWickramasinghe Apr 14, 2024
61566aa
Docs: update require statements for default exports
ThulinaWickramasinghe Apr 14, 2024
f86e4e5
Fix(actions-exec-wrapper): link types in package.json
ThulinaWickramasinghe Apr 14, 2024
79d2024
Merge pull request #176 from sliit-foss/fix/default-export-require-docs
Akalanka47000 Apr 14, 2024
5aaa0aa
Merge pull request #175 from sliit-foss/feat/actions-exec-type-support
Akalanka47000 Apr 14, 2024
55802c4
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Apr 14, 2024
fad5b35
Fix(filter-query): added automatic parsing of object ids
Akalanka47000 Apr 14, 2024
e948d14
Merge pull request #177 from sliit-foss/fix/filter-query-object-id-pa…
Akalanka47000 Apr 14, 2024
ab55e85
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Apr 14, 2024
44c39f2
Fix(mongoose-filter-query): incorrect parsing of regexp
Akalanka47000 Apr 16, 2024
3ad4a5b
Merge pull request #179 from sliit-foss/fix/filter-query-regexp-parsing
Akalanka47000 Apr 16, 2024
6c456fa
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Apr 16, 2024
f213613
Fix(mongoose-filter-query): default boolean parsing
Akalanka47000 Apr 20, 2024
2e53191
Fix: erroneus test
Akalanka47000 Apr 20, 2024
4371256
Merge pull request #180 from sliit-foss/fix/filter-query-default-bool…
Akalanka47000 Apr 20, 2024
8730510
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Apr 20, 2024
9878cc8
Feat(filter-query): added support for regexp modifiers
Akalanka47000 May 8, 2024
1e1c0bc
Merge pull request #181 from sliit-foss/feat/filter-query-regex-modif…
Akalanka47000 May 8, 2024
1547432
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] May 8, 2024
7338f24
Feat(service-connector): added support for retrying
Akalanka47000 May 10, 2024
c2558e6
Merge pull request #182 from sliit-foss/feat/service-connector-retry
Akalanka47000 May 10, 2024
c8651dd
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] May 10, 2024
d6efc2a
Fix(filter-query): in & nin object id parse
Akalanka47000 May 19, 2024
e067694
Merge pull request #183 from sliit-foss/fix/filter-query-object-id-pa…
Akalanka47000 May 19, 2024
5cd0edd
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] May 19, 2024
9b3d674
Feat!(filter-query): added prepaginate flag to query
Akalanka47000 Jun 22, 2024
a8f7548
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Jun 22, 2024
bdaf418
Feat!: added aggregate paginate plugin
Akalanka47000 Jun 22, 2024
af60063
CI: @sliit-foss/automatic-versioning - sync release
github-actions[bot] Jun 22, 2024
042633e
Style: remove unwanted .gitkeep file
ThulinaWickramasinghe Jun 23, 2024
955db95
Fix: remove fixed pnpm version
ThulinaWickramasinghe Jun 23, 2024
e57fc53
Feat(json-hash): add new package json-hash
ThulinaWickramasinghe Jun 23, 2024
130c06f
Style(json-hash): remove commented code
ThulinaWickramasinghe Jun 23, 2024
1e35f75
Refactor(json-hash): remove redundant code
ThulinaWickramasinghe Jun 23, 2024
f0e5f8c
Test(json-hash): remove browser tests, fix async issue and add test f…
ThulinaWickramasinghe Jun 24, 2024
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
Empty file removed .github/actions/.gitkeep
Empty file.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ yarn-error.log*

.vscode

.eslintcache

packages/automatic-versioning/tmp

p*/**/dist/
Expand All @@ -51,4 +53,8 @@ p*/**/jest.config.js
p*/**/LICENSE

p*/**/node_modules/
p*/**/logs/.turbo
p*/**/logs/.turbo

#non-pnpm lock files
yarn.lock
package-lock.json
4 changes: 0 additions & 4 deletions .husky/commit-msg

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"printWidth": 120,
"trailingComma": "none"
"trailingComma": "none",
"semi": true,
"quoteProps": "consistent"
}
14 changes: 14 additions & 0 deletions lefthook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pre-commit:
parallel: true
commands:
format:
glob: "*.{css,html,json,less,md,scss,yaml,yml,js,jsx,ts,tsx}"
run: npx prettier --write --cache {staged_files} && git add {staged_files}
lint:
glob: "*.{js,jsx,ts,tsx}"
run: npm run lint && git add {staged_files}

commit-msg:
commands:
commitlint:
run: npx commitlint --edit --color
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dev": "turbo run dev",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{js,ts,tsx,md}\" --cache",
"prepare": "husky install",
"prepare": "lefthook install",
"release": "turbo run release",
"submodules:load": "git submodule update --init",
"submodules:sync": "git submodule update --recursive --remote",
Expand All @@ -31,17 +31,17 @@
"turbo": "1.7.3"
},
"devDependencies": {
"@commitlint/cli": "17.4.2",
"@commitlint/config-conventional": "17.4.2",
"@commitlint/cli": "19.2.1",
"@commitlint/config-conventional": "19.1.0",
"@sliit-foss/eslint-config-internal": "workspace:*",
"eslint": "8.33.0",
"eslint-config-turbo": "0.0.7",
"husky": "8.0.3",
"lefthook": "1.6.10",
"nodemon": "2.0.21",
"prettier": "2.8.3"
"prettier": "3.2.5"
},
"engines": {
"node": ">=14.0.0"
},
"packageManager": "[email protected]"
"node": ">=14.0.0",
"pnpm": ">=7.5.0"
}
}
65 changes: 33 additions & 32 deletions packages/actions-exec-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
{
"name": "@sliit-foss/actions-exec-wrapper",
"version": "1.1.1",
"description": "A wrapper around the @actions/exec module which promisifies the console output of a command",
"main": "dist/index.js",
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/actions-exec-wrapper",
"lint": "bash ../../scripts/lint.sh",
"release": "bash ../../scripts/release.sh",
"test": "bash ../../scripts/test/test.sh"
},
"dependencies": {
"@actions/exec": "1.1.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sliit-foss/npm-catalogue.git"
},
"keywords": [
"@actions/exec",
"actions-exec-wrapper",
"console-output"
],
"author": "SLIIT FOSS",
"license": "MIT",
"bugs": {
"url": "https://github.com/sliit-foss/npm-catalogue/issues"
},
"homepage": "https://github.com/sliit-foss/npm-catalogue/blob/main/packages/actions-exec-wrapper/readme.md"
}
{
"name": "@sliit-foss/actions-exec-wrapper",
"version": "1.1.2",
"description": "A wrapper around the @actions/exec module which promisifies the console output of a command",
"main": "dist/index.js",
"types": "types/index.d.ts",
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/actions-exec-wrapper",
"lint": "bash ../../scripts/lint.sh",
"release": "bash ../../scripts/release.sh",
"test": "bash ../../scripts/test/test.sh"
},
"dependencies": {
"@actions/exec": "1.1.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sliit-foss/npm-catalogue.git"
},
"keywords": [
"@actions/exec",
"actions-exec-wrapper",
"console-output"
],
"author": "SLIIT FOSS",
"license": "MIT",
"bugs": {
"url": "https://github.com/sliit-foss/npm-catalogue/issues"
},
"homepage": "https://github.com/sliit-foss/npm-catalogue/blob/main/packages/actions-exec-wrapper/readme.md"
}
14 changes: 14 additions & 0 deletions packages/actions-exec-wrapper/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @description Runs a given CLI command and return's it's standard output(stdout)
* @param command The command to be run
* @returns Command output wrapped around a promise
* @example
* exec("npm --version")
* .then((result) => {
* console.log(result);
* })
* .catch((error) => {
* console.log(error);
* });
*/
export default function execute(command: string): Promise<string>;
2 changes: 1 addition & 1 deletion packages/http-logger/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ yarn add @sliit-foss/http-logger

```js
# using require
const httpLogger = require("@sliit-foss/http-logger");
const httpLogger = require("@sliit-foss/http-logger").default;

# using import
import httpLogger from "@sliit-foss/http-logger";
Expand Down
32 changes: 32 additions & 0 deletions packages/json-hash/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "json-hash",
"version": "1.0.0",
"description": "Hash JS objects reliablly on both Node.js and browser",
"main": "dist/index.js",
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/json-hash",
"lint": "bash ../../scripts/lint.sh",
"release": "bash ../../scripts/release.sh",
"test": "bash ../../scripts/test/test.sh"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sliit-foss/npm-catalogue.git"
},
"dependencies": {
"json-stable-stringify": "1.1.1"
},
"keywords": [
"json",
"hash",
"hashing",
"object-hash"
],
"author": "SLIIT FOSS",
"license": "MIT",
"bugs": {
"url": "https://github.com/sliit-foss/npm-catalogue/issues"
}
}
46 changes: 46 additions & 0 deletions packages/json-hash/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const getNodeJSAlgoName = (algorithm) => {
const algos = {
"SHA-1": "sha1",
"SHA-256": "sha256",
"SHA-384": "sha384",
"SHA-512": "sha512"
};

return algos[algorithm];
};

export const computeHash = async (obj, { algorithm = "SHA-1", sort = false }) => {
const nodeJSAlgoName = getNodeJSAlgoName(algorithm);

if (nodeJSAlgoName === undefined) {
throw new Error("Provided algorithm is not available");
}

if (typeof obj !== "string") {
if (sort) {
const { default: stringify } = await import("json-stable-stringify");
obj = stringify(obj);
} else {
obj = JSON.stringify(obj);
}
}

// For browser
// eslint-disable-next-line no-undef
if (typeof window !== "undefined" && window.crypto && window.crypto.subtle) {
const msgUint8 = new TextEncoder().encode(obj); // encode as (utf-8) Uint8Array

// eslint-disable-next-line no-undef
const hashBuffer = await window.crypto.subtle.digest(algorithm, msgUint8); // hash data
const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); // convert bytes to hex string
return hashHex;
}

// For Node.js
if (typeof global !== "undefined" && global.crypto) {
const { createHash } = await import("crypto");
const hash = createHash(nodeJSAlgoName).update(obj).digest("hex");
return hash;
}
};
96 changes: 96 additions & 0 deletions packages/json-hash/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { computeHash, getNodeJSAlgoName } from "../src";

describe("json-hash-node-js", () => {
beforeAll(() => {
console.log("Running tests for json-hash on Node.js");
});

afterAll(() => {
console.log("Ending tests for json-hash on Node.js");
});

const objectToHash = { name: "Siri", age: 30, country: "Sri Lanka" };

//tests for getNodeJSAlgoName
it("should-get-node-js-algo-name", () => {
expect(getNodeJSAlgoName("SHA-1")).toBe("sha1");
expect(getNodeJSAlgoName("SHA-256")).toBe("sha256");
expect(getNodeJSAlgoName("SHA-384")).toBe("sha384");
expect(getNodeJSAlgoName("SHA-512")).toBe("sha512");
});

it("should-not-throw-error-for-invalid-algo-name", () => {
expect(getNodeJSAlgoName("NIKE")).toBe(undefined);
expect(getNodeJSAlgoName("")).toBe(undefined);
});

// tests for computeHash begins

it("should-throw-error-for-invalid-algo-name", async () => {
expect.assertions(1);

try {
await computeHash(objectToHash, { algorithm: "Sock" });
} catch (error) {
expect(error).toMatchObject(new Error("Provided algorithm is not available"));
}
});

// without sorting
it("should-compute-hash-with-SHA-1", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-1" });
expect(hash).toBe("9edcbfaaba0af491b8f73961416a250655bf483c");
});

it("should-compute-hash-with-SHA-256", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-256" });
expect(hash).toBe("f17f5b4a7b8d4f7258cfedff4b78982f6d472d856d1fc1a9da3562d633ffff72");
});

it("should-compute-hash-with-SHA-384", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-384" });
expect(hash).toBe(
"8096ba11adb69941ad3ff5cbfc8c4b00d9b8d092de640e8abf8b54e1fcb7ddfdeaa3f5df0f03af50ca2648e76ed704b5"
);
});

it("should-compute-hash-with-SHA-512", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-512" });
expect(hash).toBe(
"e6dc6e4edb2de44db04a6611ce3bb7127d9c5e93d8cc8c2092fca748db04d676ebf12dd06f6819eb6b7b20f957025e2da490918511adf34775e869e17619180e"
);
});

// with sorting
it("should-sort-and-compute-hash-with-SHA-1", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-1", sort: true });
expect(hash).toBe("10e3e5df394451377f778d7402b62b5134dca39a");
});

it("should-sort-and-compute-hash-with-SHA-256", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-256", sort: true });
expect(hash).toBe("37d0042f1f11c95c8563b530cc8769d4229ef48b5a31f763e2f841783216d6f2");
});

it("should-sort-and-compute-hash-with-SHA-384", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-384", sort: true });
expect(hash).toBe(
"f43ccfc81ea4e92fc11bed100e7cd82a665ad359faf91ff666e51a947cba8a7c5e3931ed6e7cebaef1a66b4b3c0c5d41"
);
});

it("should-sort-and-compute-hash-with-SHA-512", async () => {
expect.assertions(1);
const hash = await computeHash(objectToHash, { algorithm: "SHA-512", sort: true });
expect(hash).toBe(
"f6a03a2a8cf61713c4c2fc3bae86736f6f8322d5271d1c2b3046268871f3d6ca434b1414b910990c9ba2f13cbe629f54646b7430880f1e60a4a899c94f45b6b1"
);
});
});
Loading