codequiry 1.0.3 → 2.0.0

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -100
  3. package/index.js +251 -126
  4. package/package.json +36 -35
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Codequiry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,100 +1,123 @@
1
- # NodeJS SDK for Codequiry API
2
-
3
- Codequiry is a commercial grade plagiarism and similarity detection software for source code files. Submissions are checked with billions of sources on the web as well as checked locally against provided submissions. This is a NodeJS example application for the API to check code plagiarism and similarity.
4
-
5
- The API allows us to run multiple different tests on source code files:
6
- 1. Peer Check - Given a group of submissions as individual zip files, all lines of code are compared to each other and relative similarity scores are computed, as well as matched snippets.
7
- 2. Database Check - Checks submissions against popular repositories and public sources of code.
8
- 3. Web Check - Does a full check of code with over 2 billion public sources on the web.
9
-
10
- Checks return us tons of data such as similarity scores, individual file scores, cluster graphs, similarity histograms, highlights results, matched snippets, percentage plagiarised and similar, and a ton more...
11
-
12
- Main Website:
13
- https://codequiry.com
14
-
15
- Full API Docs:
16
- https://codequiry.com/usage/api
17
-
18
- ## Installation
19
-
20
- ```
21
- npm install codequiry
22
- ```
23
- #### Initializing
24
- ```
25
- var Codequiry = require('codequiry')
26
- ```
27
-
28
- #### Setting your API Key
29
- ```
30
- Codequiry.setAPIKey('YOUR_API_KEY')
31
- ```
32
- ## Usage
33
- #### Getting account information
34
- ```javascript
35
- Codequiry.account(function(data, err)) {
36
- if (!err) console.log(data);
37
- else console.log(err)
38
- });
39
- ```
40
- #### Getting checks
41
- ```javascript
42
- Codequiry.checks(function(data, err)) {
43
- if (!err) console.log(data);
44
- else console.log(err)
45
- });
46
- ```
47
- #### Creating checks (specify name and programming language)
48
- Examples: java, c-cpp, python, csharp, txt
49
- ```javascript
50
- Codequiry.createCheck('CheckNameHere', 'java', function(data, err) {
51
- if (!err) console.log(data);
52
- else console.log(err)
53
- });
54
- ```
55
- #### Uploading to a check (specify check_id and file (must be a zip file))
56
- ```javascript
57
- Codequiry.uploadFile(CHECK_ID, './test.zip', function(data, err) {
58
- if (!err) console.log(data);
59
- else console.log(err)
60
- });
61
- ```
62
- #### Starting a check (specify check_id and if running database check or web check)
63
- ```javascript
64
- Codequiry.startCheck(CHECK_ID, false, false, function(data, err) {
65
- if (!err) console.log(data);
66
- else console.log(err)
67
- });
68
- ```
69
- #### Getting a check information/status
70
- ```javascript
71
- Codequiry.getCheck(CHECK_ID, function(data, err) {
72
- if (!err) console.log(data);
73
- else console.log(err)
74
- });
75
- ```
76
- #### Getting results overview
77
- ```javascript
78
- Codequiry.getOverview(CHECK_ID, function(data, err) {
79
- if (!err) console.log(data);
80
- else console.log(err)
81
- });
82
- ```
83
- #### Getting specific results of a submission
84
- ```javascript
85
- Codequiry.getResults(CHECK_ID, SUBMISSION_ID function(data, err) {
86
- if (!err) console.log(data);
87
- else console.log(err)
88
- });
89
- ```
90
- ## Realtime checking progress - SocketIO
91
- This is an example of the listener, you can call this after getting a check status or after starting a check (both will reutrn a job ID, which you can listen to). Here we will listen to specific CHECK_ID.
92
- ```javascript
93
- Codequiry.getCheck(CHECK_ID, function(data) {
94
- console.log(data.check.job_id);
95
- Codequiry.checkListen(data.check.job_id);
96
- Codequiry.emitter.on('update', function(data) {
97
- console.log(data);
98
- });
99
- });
100
- ```
1
+ # Codequiry - Node.js SDK
2
+
3
+ Official Node.js SDK for [Codequiry's](https://codequiry.com) Code Plagiarism & Similarity Detection API.
4
+
5
+ Check source code files against billions of web sources, public repositories, and peer submissions. Supports 65+ programming languages.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install codequiry
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```javascript
16
+ const Codequiry = require('codequiry');
17
+
18
+ const cq = new Codequiry('YOUR_API_KEY');
19
+
20
+ // Create a check, upload files, start, and get results
21
+ async function run() {
22
+ // Create a check (language 14 = Python)
23
+ const check = await cq.createCheck('Assignment 1', 14);
24
+ console.log('Created:', check);
25
+
26
+ // Upload a zip file
27
+ await cq.uploadFile(check.check.id, './submissions.zip');
28
+
29
+ // Start the check
30
+ await cq.startCheck(check.check.id, { dbcheck: true });
31
+
32
+ // Poll until complete
33
+ const status = await cq.pollUntilComplete(check.check.id, {
34
+ onProgress: (s) => console.log('Progress:', s),
35
+ });
36
+
37
+ // Get results
38
+ const overview = await cq.getOverview(check.check.id);
39
+ console.log('Results:', overview);
40
+ }
41
+
42
+ run().catch(console.error);
43
+ ```
44
+
45
+ ## API Reference
46
+
47
+ ### Constructor
48
+
49
+ ```javascript
50
+ const cq = new Codequiry('YOUR_API_KEY');
51
+ ```
52
+
53
+ ### Account
54
+
55
+ | Method | Description |
56
+ |--------|-------------|
57
+ | `cq.account()` | Get account info and usage quota |
58
+
59
+ ### Checks
60
+
61
+ | Method | Description |
62
+ |--------|-------------|
63
+ | `cq.checks()` | List all checks |
64
+ | `cq.createCheck(name, languageId, testType?)` | Create a new check |
65
+ | `cq.getCheck(checkId)` | Get check info and status |
66
+ | `cq.deleteCheck(checkId)` | Delete a check |
67
+
68
+ ### Upload
69
+
70
+ | Method | Description |
71
+ |--------|-------------|
72
+ | `cq.uploadFile(checkId, filePath)` | Upload a ZIP file |
73
+ | `cq.uploadBatch(checkId, filePaths)` | Upload multiple ZIP files |
74
+
75
+ ### Start & Status
76
+
77
+ | Method | Description |
78
+ |--------|-------------|
79
+ | `cq.startCheck(checkId, options?)` | Start a check. Options: `{ dbcheck, webcheck, testType }` |
80
+ | `cq.getStatus(checkId)` | Get current check status |
81
+ | `cq.pollUntilComplete(checkId, options?)` | Poll until done. Options: `{ interval, timeout, onProgress }` |
82
+
83
+ ### Results
84
+
85
+ | Method | Description |
86
+ |--------|-------------|
87
+ | `cq.getOverview(checkId)` | Results overview with similarity scores |
88
+ | `cq.getResults(checkId, submissionId)` | Detailed results for a submission |
89
+ | `cq.getSummary(checkId)` | Summary statistics |
90
+
91
+ ### Reference Data
92
+
93
+ | Method | Description |
94
+ |--------|-------------|
95
+ | `cq.getLanguages()` | List supported programming languages |
96
+ | `cq.getTestTypes()` | List available check engine types |
97
+
98
+ ## Supported Languages
99
+
100
+ Java, Python, C, C++, C#, Perl, PHP, SQL, VB, XML, Haskell, Pascal, Go, Matlab, Lisp, Ruby, Assembly, HTML, JavaScript/TypeScript, Swift, Kotlin, Dart, Elixir, Jupyter Notebooks, and many more.
101
+
102
+ ## Migration from v1
103
+
104
+ v2 uses modern async/await instead of callbacks:
105
+
106
+ ```javascript
107
+ // v1 (old)
108
+ Codequiry.setAPIKey('key');
109
+ Codequiry.checks(function(data, err) {
110
+ console.log(data);
111
+ });
112
+
113
+ // v2 (new)
114
+ const cq = new Codequiry('key');
115
+ const checks = await cq.checks();
116
+ console.log(checks);
117
+ ```
118
+
119
+ ## Links
120
+
121
+ - [Codequiry](https://codequiry.com)
122
+ - [API Documentation](https://codequiry.com/usage/docs)
123
+ - [CLI Tool](https://www.npmjs.com/package/codequiry-cli)
package/index.js CHANGED
@@ -1,126 +1,251 @@
1
- const axios = require('axios');
2
- var api_key;
3
- var request = require('request');
4
- var fs = require('fs');
5
- var events = require('events');
6
- var io = require('socket.io-client');
7
- var em = new events.EventEmitter();
8
- exports.checkListen = function(job_id) {
9
- var socket = io('https://api.codequiry.com/');
10
- if (job_id != 0) {
11
- socket.emit('job-check', {
12
- jobid: job_id
13
- });
14
- socket.on('job-status', function(data) {
15
- em.emit('update', data);
16
- if (data.error == 1 || data.percent == 100) {
17
- socket.disconnect();
18
- }
19
- });
20
- }
21
- };
22
- exports.emitter = em;
23
- exports.setAPIKey = function(api) {
24
- api_key = api;
25
- };
26
- // Other stuff...
27
- exports.account = function(callback) {
28
- runner('account', {}, function(data, err) {
29
- callback(data, err)
30
- });
31
- };
32
- exports.checks = function(callback) {
33
- runner('checks', {}, function(data, err) {
34
- callback(data, err)
35
- });
36
- };
37
- exports.createCheck = function(checkname, lang, callback) {
38
- runner('check/create', {
39
- name: checkname,
40
- language: lang
41
- }, function(data, err) {
42
- callback(data, err)
43
- });
44
- };
45
- exports.startCheck = function(checkid, db, web, callback) {
46
- if (db) db = 1
47
- if (web) web = 1
48
- runner('check/start', {
49
- check_id: checkid,
50
- webcheck: web,
51
- dbcheck: db
52
- }, function(data, err) {
53
- callback(data, err)
54
- });
55
- };
56
- exports.uploadFile = function(checkid, filein, callback) {
57
- var params = {
58
- check_id: checkid,
59
- file: fs.createReadStream(filein)
60
- };
61
- var headersWebex = {
62
- "Access-Control-Allow-Origin": "*",
63
- 'apikey': api_key,
64
- 'Content-Type': 'multipart/form-data'
65
- }
66
- request.post({
67
- headers: headersWebex,
68
- url: 'https://codequiry.com/api/v1/check/upload',
69
- method: 'POST',
70
- formData: params
71
- }, function(error, response, body) {
72
- if (error) callback(null, error)
73
- if (JSON.parse(body).error) {
74
- callback(null, JSON.parse(body).error)
75
- } else {
76
- callback(JSON.parse(body));
77
- }
78
- });
79
- };
80
- exports.getCheck = function(checkid, callback) {
81
- runner('check/get', {
82
- check_id: checkid
83
- }, function(data, err) {
84
- callback(data, err)
85
- });
86
- };
87
- exports.getOverview = function(checkid, callback) {
88
- runner('check/overview', {
89
- check_id: checkid
90
- }, function(data, err) {
91
- callback(data, err)
92
- });
93
- };
94
- exports.getResults = function(checkid, sid, callback) {
95
- runner('check/results', {
96
- check_id: checkid,
97
- submission_id: sid
98
- }, function(data, err) {
99
- callback(data, err)
100
- });
101
- };
102
-
103
- function runner(route, postdata, callback) {
104
- if (api_key != null) {
105
- var postData = postdata;
106
- var contentType;
107
- let axiosConfig = {
108
- headers: {
109
- 'Content-Type': 'application/json',
110
- "Access-Control-Allow-Origin": "*",
111
- 'apikey': api_key,
112
- }
113
- };
114
- axios.post('https://codequiry.com/api/v1/' + route, postData, axiosConfig).then((res) => {
115
- if (res.data.error) {
116
- callback(null, res.data.error)
117
- } else {
118
- callback(res.data)
119
- }
120
- }).catch((err) => {
121
- callback(null, err.response.data.error);
122
- })
123
- } else {
124
- callback(null, 'No API Key was set');
125
- }
126
- };
1
+ 'use strict';
2
+
3
+ const axios = require('axios');
4
+ const FormData = require('form-data');
5
+ const fs = require('fs');
6
+
7
+ const BASE_URL = 'https://codequiry.com/api/v1';
8
+
9
+ class Codequiry {
10
+ /**
11
+ * Create a Codequiry SDK instance.
12
+ * @param {string} apiKey - Your Codequiry API key
13
+ */
14
+ constructor(apiKey) {
15
+ if (!apiKey) {
16
+ throw new Error('API key is required. Get one at https://codequiry.com/dashboard');
17
+ }
18
+ this.apiKey = apiKey;
19
+ this.client = axios.create({
20
+ baseURL: BASE_URL,
21
+ headers: {
22
+ apikey: apiKey,
23
+ Accept: 'application/json',
24
+ },
25
+ timeout: 120000,
26
+ });
27
+ }
28
+
29
+ // ─── Account ──────────────────────────────────────────
30
+
31
+ /**
32
+ * Get account information and usage quota.
33
+ * @returns {Promise<Object>}
34
+ */
35
+ async account() {
36
+ const res = await this.client.get('/account');
37
+ return res.data;
38
+ }
39
+
40
+ // ─── Checks ───────────────────────────────────────────
41
+
42
+ /**
43
+ * List all checks.
44
+ * @returns {Promise<Object>}
45
+ */
46
+ async checks() {
47
+ const res = await this.client.get('/checks');
48
+ return res.data;
49
+ }
50
+
51
+ /**
52
+ * Create a new check.
53
+ * @param {string} name - Check name
54
+ * @param {number} language - Language ID (get from getLanguages())
55
+ * @param {number} [testType] - Test type ID (get from getTestTypes())
56
+ * @returns {Promise<Object>}
57
+ */
58
+ async createCheck(name, language, testType) {
59
+ const body = { name, language };
60
+ if (testType) body.test_type = testType;
61
+ const res = await this.client.post('/check/create', body);
62
+ return res.data;
63
+ }
64
+
65
+ /**
66
+ * Get check information and status.
67
+ * @param {number} checkId
68
+ * @returns {Promise<Object>}
69
+ */
70
+ async getCheck(checkId) {
71
+ const res = await this.client.post('/check/get', { check_id: checkId });
72
+ return res.data;
73
+ }
74
+
75
+ /**
76
+ * Delete a check.
77
+ * @param {number} checkId
78
+ * @returns {Promise<Object>}
79
+ */
80
+ async deleteCheck(checkId) {
81
+ const res = await this.client.delete(`/checks/${checkId}`);
82
+ return res.data;
83
+ }
84
+
85
+ // ─── Upload ───────────────────────────────────────────
86
+
87
+ /**
88
+ * Upload a ZIP file to a check.
89
+ * @param {number} checkId
90
+ * @param {string} filePath - Path to a .zip file
91
+ * @returns {Promise<Object>}
92
+ */
93
+ async uploadFile(checkId, filePath) {
94
+ const form = new FormData();
95
+ form.append('check_id', String(checkId));
96
+ form.append('file', fs.createReadStream(filePath));
97
+ const res = await this.client.post('/check/upload', form, {
98
+ headers: form.getHeaders(),
99
+ maxContentLength: Infinity,
100
+ maxBodyLength: Infinity,
101
+ });
102
+ return res.data;
103
+ }
104
+
105
+ /**
106
+ * Upload multiple ZIP files to a check (batch).
107
+ * @param {number} checkId
108
+ * @param {string[]} filePaths - Array of paths to .zip files
109
+ * @returns {Promise<Object>}
110
+ */
111
+ async uploadBatch(checkId, filePaths) {
112
+ const form = new FormData();
113
+ form.append('check_id', String(checkId));
114
+ filePaths.forEach((fp) => {
115
+ form.append('files[]', fs.createReadStream(fp));
116
+ });
117
+ const res = await this.client.post('/check/upload-batch', form, {
118
+ headers: form.getHeaders(),
119
+ maxContentLength: Infinity,
120
+ maxBodyLength: Infinity,
121
+ });
122
+ return res.data;
123
+ }
124
+
125
+ // ─── Start & Status ───────────────────────────────────
126
+
127
+ /**
128
+ * Start a check.
129
+ * @param {number} checkId
130
+ * @param {Object} [options]
131
+ * @param {boolean} [options.dbcheck=false] - Enable database check
132
+ * @param {boolean} [options.webcheck=false] - Enable web check
133
+ * @param {number} [options.testType] - Test type override
134
+ * @returns {Promise<Object>}
135
+ */
136
+ async startCheck(checkId, options = {}) {
137
+ const body = {
138
+ check_id: checkId,
139
+ dbcheck: options.dbcheck ? 1 : 0,
140
+ webcheck: options.webcheck ? 1 : 0,
141
+ };
142
+ if (options.testType) body.test_type = options.testType;
143
+ const res = await this.client.post('/check/start', body);
144
+ return res.data;
145
+ }
146
+
147
+ /**
148
+ * Get check status (for polling).
149
+ * @param {number} checkId
150
+ * @returns {Promise<Object>}
151
+ */
152
+ async getStatus(checkId) {
153
+ const res = await this.client.get(`/checks/${checkId}/status`);
154
+ return res.data;
155
+ }
156
+
157
+ // ─── Results ──────────────────────────────────────────
158
+
159
+ /**
160
+ * Get results overview for a check.
161
+ * @param {number} checkId
162
+ * @returns {Promise<Object>}
163
+ */
164
+ async getOverview(checkId) {
165
+ const res = await this.client.post('/check/overview', { check_id: checkId });
166
+ return res.data;
167
+ }
168
+
169
+ /**
170
+ * Get detailed results for a specific submission.
171
+ * @param {number} checkId
172
+ * @param {number} submissionId
173
+ * @returns {Promise<Object>}
174
+ */
175
+ async getResults(checkId, submissionId) {
176
+ const res = await this.client.post('/check/results', {
177
+ check_id: checkId,
178
+ submission_id: submissionId,
179
+ });
180
+ return res.data;
181
+ }
182
+
183
+ /**
184
+ * Get summary stats for a check.
185
+ * @param {number} checkId
186
+ * @returns {Promise<Object>}
187
+ */
188
+ async getSummary(checkId) {
189
+ const res = await this.client.get(`/checks/${checkId}/summary`);
190
+ return res.data;
191
+ }
192
+
193
+ // ─── Reference Data ───────────────────────────────────
194
+
195
+ /**
196
+ * Get supported programming languages.
197
+ * @returns {Promise<Object>}
198
+ */
199
+ async getLanguages() {
200
+ const res = await this.client.get('/languages');
201
+ return res.data;
202
+ }
203
+
204
+ /**
205
+ * Get available test/check types.
206
+ * @returns {Promise<Object>}
207
+ */
208
+ async getTestTypes() {
209
+ const res = await this.client.get('/test-types');
210
+ return res.data;
211
+ }
212
+
213
+ // ─── Helpers ──────────────────────────────────────────
214
+
215
+ /**
216
+ * Poll a check until completion.
217
+ * @param {number} checkId
218
+ * @param {Object} [options]
219
+ * @param {number} [options.interval=3000] - Poll interval in ms
220
+ * @param {number} [options.timeout=600000] - Max wait time in ms
221
+ * @param {function} [options.onProgress] - Callback with status updates
222
+ * @returns {Promise<Object>} Final status
223
+ */
224
+ async pollUntilComplete(checkId, options = {}) {
225
+ const interval = options.interval || 3000;
226
+ const timeout = options.timeout || 600000;
227
+ const startTime = Date.now();
228
+
229
+ while (Date.now() - startTime < timeout) {
230
+ const status = await this.getStatus(checkId);
231
+
232
+ if (options.onProgress) {
233
+ options.onProgress(status);
234
+ }
235
+
236
+ const statusVal = status?.status ?? status?.check_status;
237
+ if (statusVal === 5 || statusVal === 'completed' || statusVal === 'done') {
238
+ return status;
239
+ }
240
+ if (statusVal === 'failed' || statusVal === 'error' || statusVal === -1) {
241
+ throw new Error('Check failed: ' + JSON.stringify(status));
242
+ }
243
+
244
+ await new Promise((resolve) => setTimeout(resolve, interval));
245
+ }
246
+
247
+ throw new Error('Polling timed out after ' + timeout + 'ms');
248
+ }
249
+ }
250
+
251
+ module.exports = Codequiry;
package/package.json CHANGED
@@ -1,35 +1,36 @@
1
- {
2
- "name": "codequiry",
3
- "version": "1.0.3",
4
- "description": "Node JS SDK for Codequiry's Plagiarism Checking API ",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/cqchecker/codequiry-sdk.git"
12
- },
13
- "keywords": [
14
- "codequiry",
15
- "codequiry nodejs",
16
- "code plagiarism checker",
17
- "code similarity api",
18
- "moss api",
19
- "code plagiarism api",
20
- "detect code plagiarism",
21
- "code check api"
22
- ],
23
- "author": "Codequiry",
24
- "license": "ISC",
25
- "bugs": {
26
- "url": "https://github.com/cqchecker/codequiry-sdk/issues"
27
- },
28
- "homepage": "https://github.com/cqchecker/codequiry-sdk#readme",
29
- "dependencies": {
30
- "axios": "^0.19.0",
31
- "events": "^3.0.0",
32
- "request": "^2.88.0",
33
- "socket.io-client": "^2.2.0"
34
- }
35
- }
1
+ {
2
+ "name": "codequiry",
3
+ "version": "2.0.0",
4
+ "description": "Node.js SDK for Codequiry's Code Plagiarism & Similarity Detection API",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"No tests yet\""
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/cqchecker/codequiry-sdk.git"
12
+ },
13
+ "keywords": [
14
+ "codequiry",
15
+ "plagiarism",
16
+ "code-similarity",
17
+ "code-plagiarism",
18
+ "similarity-detection",
19
+ "moss",
20
+ "api",
21
+ "sdk"
22
+ ],
23
+ "author": "Codequiry",
24
+ "license": "MIT",
25
+ "bugs": {
26
+ "url": "https://github.com/cqchecker/codequiry-sdk/issues"
27
+ },
28
+ "homepage": "https://codequiry.com",
29
+ "dependencies": {
30
+ "axios": "^1.6.0",
31
+ "form-data": "^4.0.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=14.0.0"
35
+ }
36
+ }