@dtect/security-sdk-react 0.0.14 → 0.0.16
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/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/src/context/securityCheckContext.tsx +58 -0
- package/src/index.ts +17 -6
- package/src/provider/index.tsx +3 -2
- package/src/types/context.ts +23 -7
- package/src/types/error.ts +12 -9
- package/src/types/index.ts +1 -1
- package/src/types/input.ts +15 -0
- package/src/types/response.ts +14 -3
- package/src/useActivityMonitor.ts +70 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
export { LanguageCodes, QualityQuestionsRespondentTypes } from '@dtect/security-sdk-js';
|
|
2
3
|
|
|
3
4
|
interface ISecurityCheckInput {
|
|
4
5
|
projectId: string;
|
|
@@ -8,6 +9,22 @@ interface ISecurityCheckInput {
|
|
|
8
9
|
};
|
|
9
10
|
metaData?: any;
|
|
10
11
|
}
|
|
12
|
+
interface IGetQualityQuestionsInput {
|
|
13
|
+
respondentType: string;
|
|
14
|
+
language: string;
|
|
15
|
+
}
|
|
16
|
+
interface ICheckQualityQuestionsInput {
|
|
17
|
+
projectId: string;
|
|
18
|
+
visitorId?: string;
|
|
19
|
+
questions: {
|
|
20
|
+
questionId: string;
|
|
21
|
+
answers: string[];
|
|
22
|
+
}[];
|
|
23
|
+
}
|
|
24
|
+
interface IIsAIUsageDetectedInput {
|
|
25
|
+
projectId: string;
|
|
26
|
+
visitorId?: string;
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
interface ISecurityResultResponse {
|
|
13
30
|
results: {
|
|
@@ -33,18 +50,25 @@ interface ISecurityResultResponse {
|
|
|
33
50
|
interface ISecurityTokenResponse {
|
|
34
51
|
token: string;
|
|
35
52
|
}
|
|
53
|
+
interface IQualityQuestionsResponse {
|
|
54
|
+
questions: any[];
|
|
55
|
+
}
|
|
36
56
|
|
|
37
57
|
interface SecurityAPIProviderProps {
|
|
38
58
|
clientId: string;
|
|
39
59
|
apiKey: string;
|
|
40
60
|
endpoint?: string;
|
|
61
|
+
includeResults?: boolean;
|
|
41
62
|
children: React.ReactNode;
|
|
42
63
|
}
|
|
43
|
-
declare const SecurityAPIProvider: ({ clientId, apiKey, children, endpoint, }: SecurityAPIProviderProps) => react_jsx_runtime.JSX.Element;
|
|
64
|
+
declare const SecurityAPIProvider: ({ clientId, apiKey, children, endpoint, includeResults }: SecurityAPIProviderProps) => react_jsx_runtime.JSX.Element;
|
|
44
65
|
|
|
45
66
|
declare const useSecurityApi: () => {
|
|
46
67
|
getSecurityResult: (props: ISecurityCheckInput) => Promise<ISecurityResultResponse | Error>;
|
|
47
68
|
getSecurityToken: (props: ISecurityCheckInput) => Promise<ISecurityTokenResponse | Error>;
|
|
69
|
+
getQualityQuestions: (props: IGetQualityQuestionsInput) => Promise<IQualityQuestionsResponse | Error>;
|
|
70
|
+
isAIUsageDetected: (props: IIsAIUsageDetectedInput) => Promise<ISecurityTokenResponse | ISecurityResultResponse | Error>;
|
|
71
|
+
checkQualityQuestions: (props: ICheckQualityQuestionsInput) => Promise<ISecurityTokenResponse | ISecurityResultResponse | Error>;
|
|
48
72
|
};
|
|
49
73
|
|
|
50
74
|
declare const SecurityAPIError: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
export { LanguageCodes, QualityQuestionsRespondentTypes } from '@dtect/security-sdk-js';
|
|
2
3
|
|
|
3
4
|
interface ISecurityCheckInput {
|
|
4
5
|
projectId: string;
|
|
@@ -8,6 +9,22 @@ interface ISecurityCheckInput {
|
|
|
8
9
|
};
|
|
9
10
|
metaData?: any;
|
|
10
11
|
}
|
|
12
|
+
interface IGetQualityQuestionsInput {
|
|
13
|
+
respondentType: string;
|
|
14
|
+
language: string;
|
|
15
|
+
}
|
|
16
|
+
interface ICheckQualityQuestionsInput {
|
|
17
|
+
projectId: string;
|
|
18
|
+
visitorId?: string;
|
|
19
|
+
questions: {
|
|
20
|
+
questionId: string;
|
|
21
|
+
answers: string[];
|
|
22
|
+
}[];
|
|
23
|
+
}
|
|
24
|
+
interface IIsAIUsageDetectedInput {
|
|
25
|
+
projectId: string;
|
|
26
|
+
visitorId?: string;
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
interface ISecurityResultResponse {
|
|
13
30
|
results: {
|
|
@@ -33,18 +50,25 @@ interface ISecurityResultResponse {
|
|
|
33
50
|
interface ISecurityTokenResponse {
|
|
34
51
|
token: string;
|
|
35
52
|
}
|
|
53
|
+
interface IQualityQuestionsResponse {
|
|
54
|
+
questions: any[];
|
|
55
|
+
}
|
|
36
56
|
|
|
37
57
|
interface SecurityAPIProviderProps {
|
|
38
58
|
clientId: string;
|
|
39
59
|
apiKey: string;
|
|
40
60
|
endpoint?: string;
|
|
61
|
+
includeResults?: boolean;
|
|
41
62
|
children: React.ReactNode;
|
|
42
63
|
}
|
|
43
|
-
declare const SecurityAPIProvider: ({ clientId, apiKey, children, endpoint, }: SecurityAPIProviderProps) => react_jsx_runtime.JSX.Element;
|
|
64
|
+
declare const SecurityAPIProvider: ({ clientId, apiKey, children, endpoint, includeResults }: SecurityAPIProviderProps) => react_jsx_runtime.JSX.Element;
|
|
44
65
|
|
|
45
66
|
declare const useSecurityApi: () => {
|
|
46
67
|
getSecurityResult: (props: ISecurityCheckInput) => Promise<ISecurityResultResponse | Error>;
|
|
47
68
|
getSecurityToken: (props: ISecurityCheckInput) => Promise<ISecurityTokenResponse | Error>;
|
|
69
|
+
getQualityQuestions: (props: IGetQualityQuestionsInput) => Promise<IQualityQuestionsResponse | Error>;
|
|
70
|
+
isAIUsageDetected: (props: IIsAIUsageDetectedInput) => Promise<ISecurityTokenResponse | ISecurityResultResponse | Error>;
|
|
71
|
+
checkQualityQuestions: (props: ICheckQualityQuestionsInput) => Promise<ISecurityTokenResponse | ISecurityResultResponse | Error>;
|
|
48
72
|
};
|
|
49
73
|
|
|
50
74
|
declare const SecurityAPIError: {
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var b=Object.create;var m=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var V=(e,t)=>{for(var r in t)m(e,r,{get:t[r],enumerable:!0})},C=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of K(t))!q.call(e,s)&&s!==r&&m(e,s,{get:()=>t[s],enumerable:!(i=G(t,s))||i.enumerable});return e};var _=(e,t,r)=>(r=e!=null?b(H(e)):{},C(t||!e||!e.__esModule?m(r,"default",{value:e,enumerable:!0}):r,e)),Y=e=>C(m({},"__esModule",{value:!0}),e);var J={};V(J,{LanguageCodes:()=>R.LanguageCodes,QualityQuestionsRespondentTypes:()=>R.QualityQuestionsRespondentTypes,SecurityAPIError:()=>W,SecurityAPIProvider:()=>M,useSecurityApi:()=>B});module.exports=Y(J);var f=require("react");var z={UNAUTHORIZED:"Unauthorized"},g={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key",MAINTENANCE_MODE:"API Under Maintenance",RATE_LIMIT_REACHED:"Too many requests. Rate limit exceeded"},h={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},w={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},D={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},P={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},E={...z,...g,...h,...w,...D,...P,FAILED_TO_CHECK_QUESTIONS:"Fail to check questions",FAILED_TO_GET_QUALITY_QUESTIONS:"Fail to get quality questions",FAILED_TO_DETECT_AI:"Fail to detect ai"},x={...g,...h,...w,...D,...P};var S=_(require("@dtect/security-sdk-js"));var I=require("react"),L=()=>{let[e,t]=(0,I.useState)(!1),[r,i]=(0,I.useState)(!1),[s,l]=(0,I.useState)(!1),[y,d]=(0,I.useState)(),n=(0,I.useRef)(0),o=()=>{t(!1),i(!1),d(void 0),l(!1),n.current=0};return(0,I.useEffect)(()=>{let c=()=>{window.getSelection()?.toString()?.length&&(n.current=new Date().getTime(),t(!0))},p=a=>{let A=a.clipboardData?.getData("text"),T=a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement;A&&T&&l(!0)},u=()=>{i(!0),d(a=>{let T=(new Date().getTime()-n.current)/1e3;return n.current?a?T<a?T:a:T:a})};return document?.addEventListener("copy",c),document?.addEventListener("paste",p),window?.addEventListener("blur",u),()=>{document?.removeEventListener("copy",c),document?.removeEventListener("paste",p),window?.removeEventListener("blur",u)}},[]),{qbc:e,mas:r,scb:y,apd:s,reset:o}};var N=require("react/jsx-runtime"),k=(0,f.createContext)({}),Q=({children:e})=>{let{reset:t,...r}=L(),i=async({projectId:n,visitorId:o,securitySettings:c,metaData:p})=>{try{return await S.default.getSecurityResult({projectId:n,visitorId:o,securitySettings:c,metaData:p})}catch(u){throw u instanceof Error?new Error(u.message):new Error(E.FAILED_TO_GET_SECURITY_RESULT)}},s=async({projectId:n,visitorId:o,securitySettings:c,metaData:p})=>{try{return await S.default.getSecurityToken({projectId:n,visitorId:o,securitySettings:c,metaData:p})}catch(u){throw u instanceof Error?new Error(u.message):new Error(E.FAILED_TO_GET_SECURITY_TOKEN)}},l=async({respondentType:n,language:o})=>{try{return await S.default.getQualityQuestions({respondentType:n,language:o})}catch(c){throw c instanceof Error?new Error(c.message):new Error(E.FAILED_TO_GET_QUALITY_QUESTIONS)}},y=async n=>{try{return await S.default.checkQualityQuestions({...n})}catch(o){throw o instanceof Error?new Error(o.message):new Error(E.FAILED_TO_CHECK_QUESTIONS)}},d=async n=>{try{return await S.default.isAIUsageDetected({...n,...r})}catch(o){throw o instanceof Error?new Error(o.message):new Error(E.FAILED_TO_DETECT_AI)}};return(0,N.jsx)(k.Provider,{value:{getSecurityResult:i,getSecurityToken:s,getQualityQuestions:l,isAIUsageDetected:d,checkQualityQuestions:y},children:e})},O=()=>(0,f.useContext)(k);var v=require("react"),U=_(require("@dtect/security-sdk-js"));var F=require("react/jsx-runtime"),Z=({clientId:e,apiKey:t,children:r,endpoint:i,includeResults:s})=>{let l=async()=>{try{await U.default.init({apiKey:t,clientId:e,endpoint:i,includeResults:s})}catch(y){if(y instanceof Error){console.error(y.message);return}console.error(E.SDK_INIT_ERROR)}};if((0,v.useEffect)(()=>{e&&t&&l()},[]),!e||!t)throw new Error(E.MISSING_CREDENTIALS);return(0,F.jsx)(Q,{children:r})},M=Z;var R=require("@dtect/security-sdk-js"),B=()=>{let{getSecurityResult:e,getSecurityToken:t,getQualityQuestions:r,isAIUsageDetected:i,checkQualityQuestions:s}=O();return{getSecurityResult:e,getSecurityToken:t,getQualityQuestions:r,isAIUsageDetected:i,checkQualityQuestions:s}},W=x;0&&(module.exports={LanguageCodes,QualityQuestionsRespondentTypes,SecurityAPIError,SecurityAPIProvider,useSecurityApi});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{createContext as
|
|
2
|
+
import{createContext as Q,useContext as O}from"react";var x={UNAUTHORIZED:"Unauthorized"},f={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key",MAINTENANCE_MODE:"API Under Maintenance",RATE_LIMIT_REACHED:"Too many requests. Rate limit exceeded"},R={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},A={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},C={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},_={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},c={...x,...f,...R,...A,...C,..._,FAILED_TO_CHECK_QUESTIONS:"Fail to check questions",FAILED_TO_GET_QUALITY_QUESTIONS:"Fail to get quality questions",FAILED_TO_DETECT_AI:"Fail to detect ai"},g={...f,...R,...A,...C,..._};import S from"@dtect/security-sdk-js";import{useState as d,useRef as L,useEffect as k}from"react";var h=()=>{let[n,s]=d(!1),[a,u]=d(!1),[E,I]=d(!1),[l,T]=d(),t=L(0),e=()=>{s(!1),u(!1),T(void 0),I(!1),t.current=0};return k(()=>{let r=()=>{window.getSelection()?.toString()?.length&&(t.current=new Date().getTime(),s(!0))},y=i=>{let m=i.clipboardData?.getData("text"),p=i.target instanceof HTMLInputElement||i.target instanceof HTMLTextAreaElement;m&&p&&I(!0)},o=()=>{u(!0),T(i=>{let p=(new Date().getTime()-t.current)/1e3;return t.current?i?p<i?p:i:p:i})};return document?.addEventListener("copy",r),document?.addEventListener("paste",y),window?.addEventListener("blur",o),()=>{document?.removeEventListener("copy",r),document?.removeEventListener("paste",y),window?.removeEventListener("blur",o)}},[]),{qbc:n,mas:a,scb:l,apd:E,reset:e}};import{jsx as N}from"react/jsx-runtime";var w=Q({}),D=({children:n})=>{let{reset:s,...a}=h(),u=async({projectId:t,visitorId:e,securitySettings:r,metaData:y})=>{try{return await S.getSecurityResult({projectId:t,visitorId:e,securitySettings:r,metaData:y})}catch(o){throw o instanceof Error?new Error(o.message):new Error(c.FAILED_TO_GET_SECURITY_RESULT)}},E=async({projectId:t,visitorId:e,securitySettings:r,metaData:y})=>{try{return await S.getSecurityToken({projectId:t,visitorId:e,securitySettings:r,metaData:y})}catch(o){throw o instanceof Error?new Error(o.message):new Error(c.FAILED_TO_GET_SECURITY_TOKEN)}},I=async({respondentType:t,language:e})=>{try{return await S.getQualityQuestions({respondentType:t,language:e})}catch(r){throw r instanceof Error?new Error(r.message):new Error(c.FAILED_TO_GET_QUALITY_QUESTIONS)}},l=async t=>{try{return await S.checkQualityQuestions({...t})}catch(e){throw e instanceof Error?new Error(e.message):new Error(c.FAILED_TO_CHECK_QUESTIONS)}},T=async t=>{try{return await S.isAIUsageDetected({...t,...a})}catch(e){throw e instanceof Error?new Error(e.message):new Error(c.FAILED_TO_DETECT_AI)}};return N(w.Provider,{value:{getSecurityResult:u,getSecurityToken:E,getQualityQuestions:I,isAIUsageDetected:T,checkQualityQuestions:l},children:n})},P=()=>O(w);import{useEffect as v}from"react";import U from"@dtect/security-sdk-js";import{jsx as b}from"react/jsx-runtime";var M=({clientId:n,apiKey:s,children:a,endpoint:u,includeResults:E})=>{let I=async()=>{try{await U.init({apiKey:s,clientId:n,endpoint:u,includeResults:E})}catch(l){if(l instanceof Error){console.error(l.message);return}console.error(c.SDK_INIT_ERROR)}};if(v(()=>{n&&s&&I()},[]),!n||!s)throw new Error(c.MISSING_CREDENTIALS);return b(D,{children:a})},F=M;import{LanguageCodes as ge,QualityQuestionsRespondentTypes as he}from"@dtect/security-sdk-js";var fe=()=>{let{getSecurityResult:n,getSecurityToken:s,getQualityQuestions:a,isAIUsageDetected:u,checkQualityQuestions:E}=P();return{getSecurityResult:n,getSecurityToken:s,getQualityQuestions:a,isAIUsageDetected:u,checkQualityQuestions:E}},Re=g;export{ge as LanguageCodes,he as QualityQuestionsRespondentTypes,Re as SecurityAPIError,F as SecurityAPIProvider,fe as useSecurityApi};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtect/security-sdk-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"ts:check": "tsc --noEmit"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dtect/security-sdk-js": "^0.0.
|
|
13
|
+
"@dtect/security-sdk-js": "^0.0.16",
|
|
14
14
|
"@tanstack/react-query": "^5.64.1",
|
|
15
15
|
"react": "^18.3.1",
|
|
16
16
|
"react-dom": "^18.3.1"
|
|
@@ -5,8 +5,12 @@ import {
|
|
|
5
5
|
ISecurityCheckInput,
|
|
6
6
|
ISecurityResultResponse,
|
|
7
7
|
ISecurityTokenResponse,
|
|
8
|
+
IQualityQuestionsResponse,
|
|
9
|
+
ICheckQualityQuestionsInput,
|
|
10
|
+
IIsAIUsageDetectedInput,
|
|
8
11
|
} from "../types";
|
|
9
12
|
import dtect from "@dtect/security-sdk-js";
|
|
13
|
+
import { useActivityMonitor } from "../useActivityMonitor";
|
|
10
14
|
|
|
11
15
|
const SecurityCheckContext = createContext<ISecurityCheckContext>(
|
|
12
16
|
{} as ISecurityCheckContext
|
|
@@ -15,6 +19,8 @@ const SecurityCheckContext = createContext<ISecurityCheckContext>(
|
|
|
15
19
|
export const SecurityCheckContextProvider = ({
|
|
16
20
|
children,
|
|
17
21
|
}: React.PropsWithChildren) => {
|
|
22
|
+
const { reset: resetMonitor, ...monitorValues } = useActivityMonitor();
|
|
23
|
+
|
|
18
24
|
const getSecurityResult = async ({
|
|
19
25
|
projectId,
|
|
20
26
|
visitorId,
|
|
@@ -61,11 +67,63 @@ export const SecurityCheckContextProvider = ({
|
|
|
61
67
|
}
|
|
62
68
|
};
|
|
63
69
|
|
|
70
|
+
const getQualityQuestions = async ({
|
|
71
|
+
respondentType,
|
|
72
|
+
language,
|
|
73
|
+
}: {
|
|
74
|
+
respondentType: string,
|
|
75
|
+
language: string
|
|
76
|
+
}): Promise<IQualityQuestionsResponse | Error> => {
|
|
77
|
+
try {
|
|
78
|
+
const response = await dtect.getQualityQuestions({
|
|
79
|
+
respondentType,
|
|
80
|
+
language
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return response;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
throw new Error(error.message);
|
|
87
|
+
}
|
|
88
|
+
throw new Error(ErrorMessageEnum.FAILED_TO_GET_QUALITY_QUESTIONS);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const checkQualityQuestions = async (props: ICheckQualityQuestionsInput): Promise<ISecurityResultResponse | ISecurityTokenResponse | Error> => {
|
|
93
|
+
try {
|
|
94
|
+
const response = await dtect.checkQualityQuestions({...props});
|
|
95
|
+
|
|
96
|
+
return response;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error instanceof Error) {
|
|
99
|
+
throw new Error(error.message);
|
|
100
|
+
}
|
|
101
|
+
throw new Error(ErrorMessageEnum.FAILED_TO_CHECK_QUESTIONS);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const isAIUsageDetected = async (props: IIsAIUsageDetectedInput): Promise<ISecurityResultResponse | ISecurityTokenResponse | Error> => {
|
|
106
|
+
try {
|
|
107
|
+
const response = await dtect.isAIUsageDetected({...props, ...monitorValues});
|
|
108
|
+
|
|
109
|
+
return response;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (error instanceof Error) {
|
|
112
|
+
throw new Error(error.message);
|
|
113
|
+
}
|
|
114
|
+
throw new Error(ErrorMessageEnum.FAILED_TO_DETECT_AI);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
|
|
64
119
|
return (
|
|
65
120
|
<SecurityCheckContext.Provider
|
|
66
121
|
value={{
|
|
67
122
|
getSecurityResult,
|
|
68
123
|
getSecurityToken,
|
|
124
|
+
getQualityQuestions,
|
|
125
|
+
isAIUsageDetected,
|
|
126
|
+
checkQualityQuestions
|
|
69
127
|
}}
|
|
70
128
|
>
|
|
71
129
|
{children}
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import { useSecurityCheckContext } from "./context";
|
|
4
|
-
import { SecurityAPIErrorsEnum } from "./types"
|
|
4
|
+
import { SecurityAPIErrorsEnum } from "./types";
|
|
5
5
|
|
|
6
6
|
export const useSecurityApi = () => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
7
|
+
const {
|
|
8
|
+
getSecurityResult,
|
|
9
|
+
getSecurityToken,
|
|
10
|
+
getQualityQuestions,
|
|
11
|
+
isAIUsageDetected,
|
|
12
|
+
checkQualityQuestions,
|
|
13
|
+
} = useSecurityCheckContext();
|
|
9
14
|
|
|
10
15
|
return {
|
|
11
16
|
getSecurityResult,
|
|
12
|
-
|
|
17
|
+
getSecurityToken,
|
|
18
|
+
getQualityQuestions,
|
|
19
|
+
isAIUsageDetected,
|
|
20
|
+
checkQualityQuestions,
|
|
13
21
|
};
|
|
14
22
|
};
|
|
15
23
|
|
|
16
24
|
export { default as SecurityAPIProvider } from "./provider";
|
|
25
|
+
export {
|
|
26
|
+
LanguageCodes,
|
|
27
|
+
QualityQuestionsRespondentTypes,
|
|
28
|
+
} from "@dtect/security-sdk-js";
|
|
17
29
|
|
|
18
|
-
|
|
19
|
-
export const SecurityAPIError = SecurityAPIErrorsEnum
|
|
30
|
+
export const SecurityAPIError = SecurityAPIErrorsEnum;
|
package/src/provider/index.tsx
CHANGED
|
@@ -9,6 +9,7 @@ interface SecurityAPIProviderProps {
|
|
|
9
9
|
clientId: string;
|
|
10
10
|
apiKey: string;
|
|
11
11
|
endpoint?: string;
|
|
12
|
+
includeResults?: boolean
|
|
12
13
|
children: React.ReactNode;
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -17,12 +18,12 @@ const SecurityAPIProvider = ({
|
|
|
17
18
|
apiKey,
|
|
18
19
|
children,
|
|
19
20
|
endpoint,
|
|
21
|
+
includeResults
|
|
20
22
|
}: SecurityAPIProviderProps) => {
|
|
21
23
|
|
|
22
24
|
const getKeysHandler = async () => {
|
|
23
25
|
try {
|
|
24
|
-
await dtect.init({ apiKey, clientId, endpoint });
|
|
25
|
-
|
|
26
|
+
await dtect.init({ apiKey, clientId, endpoint, includeResults });
|
|
26
27
|
} catch (error) {
|
|
27
28
|
if (error instanceof Error) {
|
|
28
29
|
console.error(error.message);
|
package/src/types/context.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
IGetQualityQuestionsInput,
|
|
3
|
+
ICheckQualityQuestionsInput,
|
|
4
|
+
IQualityQuestionsResponse,
|
|
5
|
+
ISecurityCheckInput,
|
|
6
|
+
ISecurityResultResponse,
|
|
7
|
+
ISecurityTokenResponse,
|
|
8
|
+
IIsAIUsageDetectedInput,
|
|
9
|
+
} from ".";
|
|
2
10
|
|
|
3
11
|
export interface ISecurityCheckContext {
|
|
4
12
|
getSecurityResult: (
|
|
@@ -7,13 +15,21 @@ export interface ISecurityCheckContext {
|
|
|
7
15
|
getSecurityToken: (
|
|
8
16
|
props: ISecurityCheckInput
|
|
9
17
|
) => Promise<ISecurityTokenResponse | Error>;
|
|
18
|
+
getQualityQuestions: (
|
|
19
|
+
props: IGetQualityQuestionsInput
|
|
20
|
+
) => Promise<IQualityQuestionsResponse | Error>;
|
|
21
|
+
isAIUsageDetected: (
|
|
22
|
+
props: IIsAIUsageDetectedInput
|
|
23
|
+
) => Promise<ISecurityTokenResponse | ISecurityResultResponse | Error>;
|
|
24
|
+
checkQualityQuestions: (
|
|
25
|
+
props: ICheckQualityQuestionsInput
|
|
26
|
+
) => Promise<ISecurityTokenResponse | ISecurityResultResponse | Error>;
|
|
10
27
|
}
|
|
11
28
|
|
|
12
|
-
|
|
13
29
|
export interface ISecurityAppContext {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
30
|
+
isReady: boolean;
|
|
31
|
+
isHcaptchaReady: boolean;
|
|
32
|
+
isKeysReady: boolean;
|
|
33
|
+
setIsHcaptchaReady: (isHcaptchaReady: boolean) => void;
|
|
34
|
+
setIsKeysReady: (isKeysReady: boolean) => void;
|
|
19
35
|
}
|
package/src/types/error.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
1
|
const InternalError = {
|
|
3
2
|
UNAUTHORIZED: "Unauthorized",
|
|
4
|
-
}
|
|
3
|
+
};
|
|
5
4
|
|
|
6
5
|
const GeneralError = {
|
|
7
6
|
INTERNAL_SERVER_ERROR: "Internal Server Error during API Request",
|
|
8
7
|
MISSING_CREDENTIALS: "Missing Public Client ID or Public API Key",
|
|
9
8
|
MAINTENANCE_MODE: "API Under Maintenance",
|
|
10
|
-
RATE_LIMIT_REACHED: "Too many requests. Rate limit exceeded"
|
|
9
|
+
RATE_LIMIT_REACHED: "Too many requests. Rate limit exceeded",
|
|
11
10
|
} as const;
|
|
12
11
|
|
|
13
12
|
const InitError = {
|
|
14
13
|
SDK_INIT_ERROR: "Internal Server Error during SDK Initialization",
|
|
15
|
-
DUPLICATE_INITIALIZATION:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
14
|
+
DUPLICATE_INITIALIZATION: "Multiple SDK Initializations Detected",
|
|
15
|
+
NOT_INITIALIZED: "SDK Not Initialized",
|
|
16
|
+
};
|
|
19
17
|
|
|
20
18
|
const GetKeysError = {
|
|
21
19
|
INVALID_CREDENTIALS: "Invalid Public Client ID or Public API Key",
|
|
@@ -36,6 +34,11 @@ export const ErrorMessageEnum = {
|
|
|
36
34
|
...GetKeysError,
|
|
37
35
|
...GetSecurityResultError,
|
|
38
36
|
...GetSecurityTokenError,
|
|
37
|
+
...{
|
|
38
|
+
FAILED_TO_CHECK_QUESTIONS: "Fail to check questions",
|
|
39
|
+
FAILED_TO_GET_QUALITY_QUESTIONS: "Fail to get quality questions",
|
|
40
|
+
FAILED_TO_DETECT_AI: "Fail to detect ai",
|
|
41
|
+
},
|
|
39
42
|
} as const;
|
|
40
43
|
|
|
41
44
|
export const SecurityAPIErrorsEnum = {
|
|
@@ -44,10 +47,10 @@ export const SecurityAPIErrorsEnum = {
|
|
|
44
47
|
...GetKeysError,
|
|
45
48
|
...GetSecurityResultError,
|
|
46
49
|
...GetSecurityTokenError,
|
|
47
|
-
}
|
|
50
|
+
};
|
|
48
51
|
|
|
49
52
|
type ValueOf<T> = T[keyof T];
|
|
50
53
|
|
|
51
54
|
export type IErrorMessage = ValueOf<typeof ErrorMessageEnum>;
|
|
52
55
|
|
|
53
|
-
export type SecurityAPIErrors = ValueOf<typeof SecurityAPIErrorsEnum
|
|
56
|
+
export type SecurityAPIErrors = ValueOf<typeof SecurityAPIErrorsEnum>;
|
package/src/types/index.ts
CHANGED
package/src/types/input.ts
CHANGED
|
@@ -17,3 +17,18 @@ export interface ISecurityCheckVisitorDataInput {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export interface IGetQualityQuestionsInput {
|
|
21
|
+
respondentType: string;
|
|
22
|
+
language: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ICheckQualityQuestionsInput {
|
|
26
|
+
projectId: string;
|
|
27
|
+
visitorId?: string;
|
|
28
|
+
questions: { questionId: string; answers: string[] }[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface IIsAIUsageDetectedInput {
|
|
32
|
+
projectId: string;
|
|
33
|
+
visitorId?: string;
|
|
34
|
+
}
|
package/src/types/response.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ISecurityResultResponse {
|
|
|
17
17
|
isTorDetected: boolean;
|
|
18
18
|
isHighActivityDevice: boolean;
|
|
19
19
|
isIncognito: boolean;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface ISecurityTokenResponse {
|
|
@@ -25,7 +25,18 @@ export interface ISecurityTokenResponse {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface IGetKeysResponse {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
behaviorKey: string;
|
|
29
|
+
automationKey: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export interface IQualityQuestionsResponse {
|
|
33
|
+
questions: any[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IIsAiUsageDetectedResponse {
|
|
37
|
+
ok: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ICheckQualityQuestionsResponse {
|
|
41
|
+
pass: boolean;
|
|
42
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
export const useActivityMonitor = () => {
|
|
4
|
+
const [qbc, setQbc] = useState(false);
|
|
5
|
+
const [mas, setMas] = useState(false);
|
|
6
|
+
const [apd, setApd] = useState(false);
|
|
7
|
+
const [scb, setScb] = useState<number>();
|
|
8
|
+
|
|
9
|
+
const copyTimestampRef = useRef<number>(0);
|
|
10
|
+
|
|
11
|
+
const reset = () => {
|
|
12
|
+
setQbc(false);
|
|
13
|
+
setMas(false);
|
|
14
|
+
setScb(undefined);
|
|
15
|
+
setApd(false);
|
|
16
|
+
copyTimestampRef.current = 0;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const handleCopy = () => {
|
|
21
|
+
const selection = window.getSelection();
|
|
22
|
+
const selectedText = selection?.toString();
|
|
23
|
+
if (selectedText?.length || 0 > 0) {
|
|
24
|
+
copyTimestampRef.current = new Date().getTime();
|
|
25
|
+
setQbc(true);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const handlePaste = (e: ClipboardEvent) => {
|
|
30
|
+
const textPasted = e.clipboardData?.getData("text");
|
|
31
|
+
const pastedOnBadField =
|
|
32
|
+
e.target instanceof HTMLInputElement ||
|
|
33
|
+
e.target instanceof HTMLTextAreaElement;
|
|
34
|
+
if (textPasted && pastedOnBadField) {
|
|
35
|
+
setApd(true);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleBlur = () => {
|
|
40
|
+
setMas(true);
|
|
41
|
+
setScb((prev) => {
|
|
42
|
+
const now = new Date().getTime();
|
|
43
|
+
const timeElapsed = (now - copyTimestampRef.current) / 1000;
|
|
44
|
+
|
|
45
|
+
if (!copyTimestampRef.current) return prev;
|
|
46
|
+
if (!prev) return timeElapsed;
|
|
47
|
+
|
|
48
|
+
return timeElapsed < prev ? timeElapsed : prev;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
document?.addEventListener("copy", handleCopy);
|
|
53
|
+
document?.addEventListener("paste", handlePaste);
|
|
54
|
+
window?.addEventListener("blur", handleBlur);
|
|
55
|
+
|
|
56
|
+
return () => {
|
|
57
|
+
document?.removeEventListener("copy", handleCopy);
|
|
58
|
+
document?.removeEventListener("paste", handlePaste);
|
|
59
|
+
window?.removeEventListener("blur", handleBlur);
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
qbc,
|
|
65
|
+
mas,
|
|
66
|
+
scb,
|
|
67
|
+
apd,
|
|
68
|
+
reset,
|
|
69
|
+
};
|
|
70
|
+
};
|