@cuemath/leap 4.1.3 → 4.1.4-as2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/features/fraud-detection/api/report-fraudulent-login.js +9 -0
- package/dist/features/fraud-detection/api/report-fraudulent-login.js.map +1 -0
- package/dist/features/fraud-detection/hooks/use-report-fraud.js +58 -52
- package/dist/features/fraud-detection/hooks/use-report-fraud.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createPostAPI as t } from "@cuemath/rest-api";
|
|
2
|
+
import { BASE_URL_V1 as r } from "../../../constants/api.js";
|
|
3
|
+
const { usePost: u } = t({
|
|
4
|
+
getURL: ({ student_classroom_id: o }) => `${r}/student-classrooms/${o}/report-fraudulent-login`
|
|
5
|
+
});
|
|
6
|
+
export {
|
|
7
|
+
u as useReportFraudulentLogin
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=report-fraudulent-login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-fraudulent-login.js","sources":["../../../../src/features/fraud-detection/api/report-fraudulent-login.ts"],"sourcesContent":["import { createPostAPI } from '@cuemath/rest-api';\n\nimport { BASE_URL_V1 } from '../../../constants/api';\nimport { type IReportFraudulentLoginPayload } from '../hooks/report-fraud-types';\n\nexport const { usePost: useReportFraudulentLogin } = createPostAPI<\n null,\n IReportFraudulentLoginPayload\n>({\n getURL: ({ student_classroom_id }: { student_classroom_id: string }) =>\n `${BASE_URL_V1}/student-classrooms/${student_classroom_id}/report-fraudulent-login`,\n});\n"],"names":["useReportFraudulentLogin","createPostAPI","student_classroom_id","BASE_URL_V1"],"mappings":";;AAKO,MAAM,EAAE,SAASA,EAAyB,IAAIC,EAGnD;AAAA,EACA,QAAQ,CAAC,EAAE,sBAAAC,QACT,GAAGC,CAAW,uBAAuBD,CAAoB;AAC7D,CAAC;"}
|
|
@@ -1,83 +1,89 @@
|
|
|
1
|
-
import { useState as S, useCallback as
|
|
2
|
-
import { useLocalPeer as
|
|
1
|
+
import { useState as S, useCallback as m, useEffect as T } from "react";
|
|
2
|
+
import { useLocalPeer as $, useRemotePeers as U, useCaptureMediaStreamImage as L } from "@cuemath/av";
|
|
3
3
|
import { useUIContext as N } from "../../ui/context/context.js";
|
|
4
|
-
import { base64ToFile as
|
|
5
|
-
import { FRAUD_DETECTION_ANALYTICS_EVENTS as
|
|
4
|
+
import { base64ToFile as D } from "../fraud-alert-modal/fraud-alert-modal-helpers.js";
|
|
5
|
+
import { FRAUD_DETECTION_ANALYTICS_EVENTS as y } from "./report-fraud-analytics.js";
|
|
6
6
|
import k from "../../hooks/use-s3-helper/use-s3-helper.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
import { useReportFraudulentLogin as v } from "../api/report-fraudulent-login.js";
|
|
8
|
+
const w = { type: "class_fraud_login" }, b = ({
|
|
9
|
+
teacherId: a,
|
|
10
|
+
studentId: n,
|
|
11
|
+
studentClassroomId: r,
|
|
12
|
+
teacherClassroomId: u,
|
|
13
|
+
classStartTs: i,
|
|
14
|
+
studentName: f
|
|
14
15
|
}) => {
|
|
15
|
-
const { onEvent:
|
|
16
|
-
studentId:
|
|
17
|
-
query:
|
|
18
|
-
}),
|
|
19
|
-
(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
16
|
+
const { onEvent: s } = N(), [p, g] = S(!1), e = $(), t = U().find((o) => o.userId === a), c = L(), E = k({
|
|
17
|
+
studentId: n,
|
|
18
|
+
query: w
|
|
19
|
+
}), { post: d } = v(), F = m(
|
|
20
|
+
(o) => {
|
|
21
|
+
const _ = {
|
|
22
|
+
class_start_ts: i,
|
|
23
|
+
student_classroom_id: r,
|
|
24
|
+
student_id: n,
|
|
25
|
+
student_name: f,
|
|
26
|
+
teacher_classroom_id: u,
|
|
27
|
+
teacher_id: a,
|
|
28
|
+
teacher_url: o[0] || "",
|
|
29
|
+
student_url: o[1] || ""
|
|
30
|
+
};
|
|
31
|
+
s(y.FRAUD_LOGIN_TEACHER_ENTERED_CLASS_AS_STUDENT, {
|
|
32
|
+
..._,
|
|
33
|
+
class_start_ts: new Date(i * 1e3)
|
|
34
|
+
}), d(_);
|
|
30
35
|
},
|
|
31
36
|
[
|
|
32
|
-
|
|
37
|
+
i,
|
|
38
|
+
s,
|
|
39
|
+
d,
|
|
33
40
|
r,
|
|
41
|
+
n,
|
|
42
|
+
f,
|
|
34
43
|
u,
|
|
35
|
-
|
|
36
|
-
m,
|
|
37
|
-
_,
|
|
38
|
-
n
|
|
44
|
+
a
|
|
39
45
|
]
|
|
40
|
-
), R =
|
|
41
|
-
|
|
42
|
-
}, [
|
|
46
|
+
), R = m(() => {
|
|
47
|
+
s("fraud_detection_images_failed", { classStartTs: i, teacherId: a, studentId: n });
|
|
48
|
+
}, [i, s, n, a]);
|
|
43
49
|
return T(() => {
|
|
44
|
-
if (!
|
|
50
|
+
if (!p || !(t != null && t.id) || !(e != null && e.id))
|
|
45
51
|
return;
|
|
46
|
-
const { image:
|
|
47
|
-
!
|
|
52
|
+
const { image: o } = c(t == null ? void 0 : t.id, "camera"), { image: _ } = c(e == null ? void 0 : e.id, "camera"), l = D(o, `teacher-${Date.now()}.png`), A = D(_, `student-${Date.now()}.png`);
|
|
53
|
+
!l || !A || (E({
|
|
48
54
|
fileKey: "media/class_fraud_login/",
|
|
49
|
-
onSuccess:
|
|
55
|
+
onSuccess: F,
|
|
50
56
|
onError: R,
|
|
51
57
|
images: [
|
|
52
58
|
{
|
|
53
|
-
file:
|
|
54
|
-
name: `teacher_${
|
|
59
|
+
file: l,
|
|
60
|
+
name: `teacher_${u}_${a}`,
|
|
55
61
|
url: ""
|
|
56
62
|
},
|
|
57
63
|
{
|
|
58
64
|
file: A,
|
|
59
|
-
name: `student_${
|
|
65
|
+
name: `student_${r}_${n}`,
|
|
60
66
|
url: ""
|
|
61
67
|
}
|
|
62
68
|
]
|
|
63
69
|
}), g(!1));
|
|
64
70
|
}, [
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
p,
|
|
72
|
+
c,
|
|
67
73
|
e == null ? void 0 : e.id,
|
|
68
74
|
R,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
t,
|
|
73
|
-
_,
|
|
75
|
+
F,
|
|
76
|
+
t == null ? void 0 : t.id,
|
|
77
|
+
r,
|
|
74
78
|
n,
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
u,
|
|
80
|
+
a,
|
|
81
|
+
E
|
|
82
|
+
]), m(() => {
|
|
77
83
|
g(!0);
|
|
78
84
|
}, []);
|
|
79
|
-
},
|
|
85
|
+
}, K = b;
|
|
80
86
|
export {
|
|
81
|
-
|
|
87
|
+
K as default
|
|
82
88
|
};
|
|
83
89
|
//# sourceMappingURL=use-report-fraud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-report-fraud.js","sources":["../../../../src/features/fraud-detection/hooks/use-report-fraud.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport { useCaptureMediaStreamImage, useLocalPeer, useRemotePeers } from '@cuemath/av';\n\nimport { useUIContext } from '../../ui/context/context';\nimport { base64ToFile } from '../fraud-alert-modal/fraud-alert-modal-helpers';\nimport { type IUseFraudAlertProps } from './report-fraud-types';\nimport { FRAUD_DETECTION_ANALYTICS_EVENTS } from './report-fraud-analytics';\nimport useS3ImageUploadHelper from '../../hooks/use-s3-helper/use-s3-helper';\n\nconst QUERY = { type: 'class_fraud_login' };\n\nconst useReportFraud = ({\n teacherId,\n studentId,\n studentClassroomId,\n teacherClassroomId,\n classStartTs,\n studentName,\n}: IUseFraudAlertProps) => {\n const { onEvent } = useUIContext();\n\n const [canTrackEvent, setCanTrackEvent] = useState(false);\n const localpeer = useLocalPeer();\n const remotePeer = useRemotePeers().find(peer => peer.userId === teacherId);\n const captureMediaStreamImage = useCaptureMediaStreamImage();\n const uploadImages = useS3ImageUploadHelper({\n studentId,\n query: QUERY,\n });\n const onSuccess = useCallback(\n (urls: string[]) => {\n
|
|
1
|
+
{"version":3,"file":"use-report-fraud.js","sources":["../../../../src/features/fraud-detection/hooks/use-report-fraud.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nimport { useCaptureMediaStreamImage, useLocalPeer, useRemotePeers } from '@cuemath/av';\n\nimport { useUIContext } from '../../ui/context/context';\nimport { base64ToFile } from '../fraud-alert-modal/fraud-alert-modal-helpers';\nimport { type IUseFraudAlertProps } from './report-fraud-types';\nimport { FRAUD_DETECTION_ANALYTICS_EVENTS } from './report-fraud-analytics';\nimport useS3ImageUploadHelper from '../../hooks/use-s3-helper/use-s3-helper';\nimport { useReportFraudulentLogin } from '../api/report-fraudulent-login';\n\nconst QUERY = { type: 'class_fraud_login' };\n\nconst useReportFraud = ({\n teacherId,\n studentId,\n studentClassroomId,\n teacherClassroomId,\n classStartTs,\n studentName,\n}: IUseFraudAlertProps) => {\n const { onEvent } = useUIContext();\n\n const [canTrackEvent, setCanTrackEvent] = useState(false);\n const localpeer = useLocalPeer();\n const remotePeer = useRemotePeers().find(peer => peer.userId === teacherId);\n const captureMediaStreamImage = useCaptureMediaStreamImage();\n const uploadImages = useS3ImageUploadHelper({\n studentId,\n query: QUERY,\n });\n const { post: reportFraud } = useReportFraudulentLogin();\n const onSuccess = useCallback(\n (urls: string[]) => {\n const fraudPayload = {\n class_start_ts: classStartTs,\n student_classroom_id: studentClassroomId,\n student_id: studentId,\n student_name: studentName,\n teacher_classroom_id: teacherClassroomId,\n teacher_id: teacherId,\n teacher_url: urls[0] || '',\n student_url: urls[1] || '',\n };\n\n onEvent(FRAUD_DETECTION_ANALYTICS_EVENTS.FRAUD_LOGIN_TEACHER_ENTERED_CLASS_AS_STUDENT, {\n ...fraudPayload,\n class_start_ts: new Date(classStartTs * 1000),\n });\n\n reportFraud(fraudPayload);\n },\n [\n classStartTs,\n onEvent,\n reportFraud,\n studentClassroomId,\n studentId,\n studentName,\n teacherClassroomId,\n teacherId,\n ],\n );\n\n const onError = useCallback(() => {\n onEvent('fraud_detection_images_failed', { classStartTs, teacherId, studentId });\n }, [classStartTs, onEvent, studentId, teacherId]);\n\n useEffect(() => {\n if (!canTrackEvent || !remotePeer?.id || !localpeer?.id) {\n return;\n }\n\n const { image: teacherImage } = captureMediaStreamImage(remotePeer?.id, 'camera');\n const { image: studentImage } = captureMediaStreamImage(localpeer?.id, 'camera');\n const teacherFile = base64ToFile(teacherImage, `teacher-${Date.now()}.png`);\n const studentFile = base64ToFile(studentImage, `student-${Date.now()}.png`);\n\n if (!teacherFile || !studentFile) {\n return;\n }\n\n uploadImages({\n fileKey: `media/class_fraud_login/`,\n onSuccess,\n onError,\n images: [\n {\n file: teacherFile,\n name: `teacher_${teacherClassroomId}_${teacherId}`,\n url: '',\n },\n {\n file: studentFile,\n name: `student_${studentClassroomId}_${studentId}`,\n url: '',\n },\n ],\n });\n\n setCanTrackEvent(false);\n }, [\n canTrackEvent,\n captureMediaStreamImage,\n localpeer?.id,\n onError,\n onSuccess,\n remotePeer?.id,\n studentClassroomId,\n studentId,\n teacherClassroomId,\n teacherId,\n uploadImages,\n ]);\n\n const captureAndReportFraudImages = useCallback(() => {\n setCanTrackEvent(true);\n }, []);\n\n return captureAndReportFraudImages;\n};\n\nexport default useReportFraud;\n"],"names":["QUERY","useReportFraud","teacherId","studentId","studentClassroomId","teacherClassroomId","classStartTs","studentName","onEvent","useUIContext","canTrackEvent","setCanTrackEvent","useState","localpeer","useLocalPeer","remotePeer","useRemotePeers","peer","captureMediaStreamImage","useCaptureMediaStreamImage","uploadImages","useS3ImageUploadHelper","reportFraud","useReportFraudulentLogin","onSuccess","useCallback","urls","fraudPayload","FRAUD_DETECTION_ANALYTICS_EVENTS","onError","useEffect","teac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