@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 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 g=Object.create;var u=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var v=(r,e)=>{for(var t in e)u(r,t,{get:e[t],enumerable:!0})},a=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!L.call(r,o)&&o!==t&&u(r,o,{get:()=>e[o],enumerable:!(n=k(e,o))||n.enumerable});return r};var y=(r,e,t)=>(t=r!=null?g(O(r)):{},a(e||!r||!r.__esModule?u(t,"default",{value:r,enumerable:!0}):t,r)),w=r=>a(u({},"__esModule",{value:!0}),r);var F={};v(F,{SecurityAPIError:()=>K,SecurityAPIProvider:()=>x,useSecurityApi:()=>U});module.exports=w(F);var E=require("react");var M={UNAUTHORIZED:"Unauthorized"},p={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"},T={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},C={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},l={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},s={...M,...p,...R,...T,...C,...l},m={...p,...R,...T,...C,...l};var S=y(require("@dtect/security-sdk-js")),_=require("react/jsx-runtime"),f=(0,E.createContext)({}),P=({children:r})=>{let e=async({projectId:n,visitorId:o,securitySettings:c,metaData:I})=>{try{return await S.default.getSecurityResult({projectId:n,visitorId:o,securitySettings:c,metaData:I})}catch(i){throw i instanceof Error?new Error(i.message):new Error(s.FAILED_TO_GET_SECURITY_RESULT)}},t=async({projectId:n,visitorId:o,securitySettings:c,metaData:I})=>{try{return await S.default.getSecurityToken({projectId:n,visitorId:o,securitySettings:c,metaData:I})}catch(i){throw i instanceof Error?new Error(i.message):new Error(s.FAILED_TO_GET_SECURITY_TOKEN)}};return(0,_.jsx)(f.Provider,{value:{getSecurityResult:e,getSecurityToken:t},children:r})},A=()=>(0,E.useContext)(f);var d=require("react"),h=y(require("@dtect/security-sdk-js"));var N=require("react/jsx-runtime"),G=({clientId:r,apiKey:e,children:t,endpoint:n})=>{let o=async()=>{try{await h.default.init({apiKey:e,clientId:r,endpoint:n})}catch(c){if(c instanceof Error){console.error(c.message);return}console.error(s.SDK_INIT_ERROR)}};if((0,d.useEffect)(()=>{r&&e&&o()},[]),!r||!e)throw new Error(s.MISSING_CREDENTIALS);return(0,N.jsx)(P,{children:t})},x=G;var U=()=>{let{getSecurityResult:r,getSecurityToken:e}=A();return{getSecurityResult:r,getSecurityToken:e}},K=m;0&&(module.exports={SecurityAPIError,SecurityAPIProvider,useSecurityApi});
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 f,useContext as P}from"react";var m={UNAUTHORIZED:"Unauthorized"},E={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"},I={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},S={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},a={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},y={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},n={...m,...E,...I,...S,...a,...y},p={...E,...I,...S,...a,...y};import R from"@dtect/security-sdk-js";import{jsx as A}from"react/jsx-runtime";var T=f({}),C=({children:r})=>{let e=async({projectId:i,visitorId:c,securitySettings:o,metaData:u})=>{try{return await R.getSecurityResult({projectId:i,visitorId:c,securitySettings:o,metaData:u})}catch(t){throw t instanceof Error?new Error(t.message):new Error(n.FAILED_TO_GET_SECURITY_RESULT)}},s=async({projectId:i,visitorId:c,securitySettings:o,metaData:u})=>{try{return await R.getSecurityToken({projectId:i,visitorId:c,securitySettings:o,metaData:u})}catch(t){throw t instanceof Error?new Error(t.message):new Error(n.FAILED_TO_GET_SECURITY_TOKEN)}};return A(T.Provider,{value:{getSecurityResult:e,getSecurityToken:s},children:r})},l=()=>P(T);import{useEffect as _}from"react";import d from"@dtect/security-sdk-js";import{jsx as N}from"react/jsx-runtime";var h=({clientId:r,apiKey:e,children:s,endpoint:i})=>{let c=async()=>{try{await d.init({apiKey:e,clientId:r,endpoint:i})}catch(o){if(o instanceof Error){console.error(o.message);return}console.error(n.SDK_INIT_ERROR)}};if(_(()=>{r&&e&&c()},[]),!r||!e)throw new Error(n.MISSING_CREDENTIALS);return N(C,{children:s})},x=h;var er=()=>{let{getSecurityResult:r,getSecurityToken:e}=l();return{getSecurityResult:r,getSecurityToken:e}},tr=p;export{tr as SecurityAPIError,x as SecurityAPIProvider,er as useSecurityApi};
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.14",
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.14",
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 { getSecurityResult, getSecurityToken } = useSecurityCheckContext();
8
-
7
+ const {
8
+ getSecurityResult,
9
+ getSecurityToken,
10
+ getQualityQuestions,
11
+ isAIUsageDetected,
12
+ checkQualityQuestions,
13
+ } = useSecurityCheckContext();
9
14
 
10
15
  return {
11
16
  getSecurityResult,
12
- getSecurityToken
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;
@@ -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);
@@ -1,4 +1,12 @@
1
- import { ISecurityCheckInput, ISecurityResultResponse, ISecurityTokenResponse } from ".";
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
- isReady: boolean;
15
- isHcaptchaReady: boolean;
16
- isKeysReady: boolean;
17
- setIsHcaptchaReady: (isHcaptchaReady: boolean) => void;
18
- setIsKeysReady:(isKeysReady: boolean) => void;
30
+ isReady: boolean;
31
+ isHcaptchaReady: boolean;
32
+ isKeysReady: boolean;
33
+ setIsHcaptchaReady: (isHcaptchaReady: boolean) => void;
34
+ setIsKeysReady: (isKeysReady: boolean) => void;
19
35
  }
@@ -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
- "Multiple SDK Initializations Detected",
17
- NOT_INITIALIZED: "SDK Not Initialized"
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>;
@@ -1,4 +1,4 @@
1
1
  export * from "./context";
2
2
  export * from "./error";
3
3
  export * from "./input";
4
- export * from "./response"
4
+ export * from "./response";
@@ -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
+ }
@@ -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
- behaviorKey: string;
29
- automationKey: string;
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
+ };