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: add cryptoJS message id and itemChat hook typing #137

Merged
merged 5 commits into from
Mar 8, 2022
Merged
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@graasp/translations": "github:graasp/graasp-translations.git",
"axios": "0.24.0",
"crypto-js": "4.1.1",
"http-status-codes": "2.2.0",
"immutable": "4.0.0",
"js-cookie": "3.0.1",
Expand All @@ -30,6 +31,7 @@
"@testing-library/react": "12.1.2",
"@testing-library/react-hooks": "7.0.2",
"@testing-library/user-event": "13.5.0",
"@types/crypto-js": "4.1.1",
"@types/jest": "27.4.0",
"@types/js-cookie": "3.0.1",
"@types/node": "17.0.8",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export type PartialChatMessage = {
};

export type ChatMessage = {
id: string,
chatId: string;
creator: string;
createdAt: string;
Expand Down
11 changes: 2 additions & 9 deletions src/utils/item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Utils functions
* todo: use utils from a dedicated repo */

import crypto from 'crypto';
import CryptoJS from 'crypto-js';
import type { UUID, GraaspError } from '../types';

// eslint-disable-next-line no-useless-escape
Expand Down Expand Up @@ -46,14 +46,7 @@ export const getDirectParentId = (path: string) => {
return ids[parentIdx];
};

export const hashItemsIds = (ids?: UUID[]) =>
ids
? crypto
.createHash('sha1')
.update([...ids].sort().join(''))
.digest('hex')
.toString()
: undefined;
export const hashItemsIds = (ids?: UUID[]) => ids ? CryptoJS.SHA1([...ids].sort().join()).toString() : undefined;

export const isError = (error: unknown) => {
const errorObject = error as GraaspError;
Expand Down
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,7 @@ __metadata:
"@testing-library/react": 12.1.2
"@testing-library/react-hooks": 7.0.2
"@testing-library/user-event": 13.5.0
"@types/crypto-js": 4.1.1
"@types/jest": 27.4.0
"@types/js-cookie": 3.0.1
"@types/node": 17.0.8
Expand All @@ -1961,6 +1962,7 @@ __metadata:
"@typescript-eslint/parser": 5.9.0
axios: 0.24.0
babel-jest: 27.4.6
crypto-js: 4.1.1
env-cmd: 10.1.0
eslint: 8.6.0
eslint-config-airbnb: 19.0.4
Expand Down Expand Up @@ -3212,6 +3214,13 @@ __metadata:
languageName: node
linkType: hard

"@types/crypto-js@npm:4.1.1":
version: 4.1.1
resolution: "@types/crypto-js@npm:4.1.1"
checksum: ea3d6a67b69f88baeb6af96004395903d2367a41bd5cd86306da23a44dd96589749495da50974a9b01bb5163c500764c8a33706831eade036bddae016417e3ea
languageName: node
linkType: hard

"@types/eslint@npm:^7.28.2":
version: 7.29.0
resolution: "@types/eslint@npm:7.29.0"
Expand Down Expand Up @@ -6570,6 +6579,13 @@ __metadata:
languageName: node
linkType: hard

"crypto-js@npm:4.1.1":
version: 4.1.1
resolution: "crypto-js@npm:4.1.1"
checksum: b3747c12ee3a7632fab3b3e171ea50f78b182545f0714f6d3e7e2858385f0f4101a15f2517e033802ce9d12ba50a391575ff4638c9de3dd9b2c4bc47768d5425
languageName: node
linkType: hard

"crypto-random-string@npm:^1.0.0":
version: 1.0.0
resolution: "crypto-random-string@npm:1.0.0"
Expand Down