@snyk/code-client
Advanced tools
Comparing version 4.17.1 to 4.18.0
@@ -38,3 +38,3 @@ import { FileInfo, SupportedFiles } from './interfaces/files.interface'; | ||
} | ||
interface CreateBundleFromFoldersOptions extends ConnectionOptions, AnalyzeFoldersOptions { | ||
export interface CreateBundleFromFoldersOptions extends ConnectionOptions, AnalyzeFoldersOptions { | ||
} | ||
@@ -41,0 +41,0 @@ /** |
@@ -20,3 +20,3 @@ "use strict"; | ||
emitter_1.emitter.createBundleProgress(cumulativeProgress, options.files.length); | ||
for (const chunkedFiles of (0, files_1.composeFilePayloads)(options.files, constants_1.MAX_PAYLOAD)) { | ||
for (const chunkedFiles of (0, files_1.composeFilePayloads)(options.files)) { | ||
const apiParams = { | ||
@@ -82,3 +82,3 @@ ...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'extraHeaders', 'removedFiles', 'requestId', 'org']), | ||
const files = []; | ||
for (const bucketFiles of (0, files_1.composeFilePayloads)(options.files, constants_1.MAX_PAYLOAD)) { | ||
for (const bucketFiles of (0, files_1.composeFilePayloads)(options.files)) { | ||
files.push(bucketFiles); | ||
@@ -85,0 +85,0 @@ } |
@@ -386,6 +386,13 @@ "use strict"; | ||
exports.resolveBundleFilePath = resolveBundleFilePath; | ||
function* composeFilePayloads(files, bucketSize = constants_1.MAX_PAYLOAD) { | ||
// MAX_PAYLOAD / 2 is because every char takes 2 bytes in the payload | ||
function* composeFilePayloads(files, bucketSize = constants_1.MAX_PAYLOAD / 2) { | ||
const buckets = [{ size: bucketSize, files: [] }]; | ||
let bucketIndex = -1; | ||
const getFileDataPayloadSize = (fileData) => { var _a; return (((_a = fileData.content) === null || _a === void 0 ? void 0 : _a.length) || 0) + fileData.bundlePath.length + fileData.hash.length; }; | ||
const getFileDataPayloadSize = (fileData) => { | ||
var _a; | ||
return (((_a = fileData.content) === null || _a === void 0 ? void 0 : _a.length) ? fileData.content.length + 16 : 0) + | ||
fileData.bundlePath.length + | ||
fileData.hash.length + | ||
6; | ||
}; // constants is for the separators | ||
const isLowerSize = (size, fileData) => size >= getFileDataPayloadSize(fileData); | ||
@@ -392,0 +399,0 @@ for (const fileData of files) { |
@@ -20,3 +20,4 @@ { | ||
"watch": "tsc -watch -p ./", | ||
"test": "jest --coverage --runInBand" | ||
"test": "jest --coverage --runInBand", | ||
"cli": "ts-node-cwd src/cli.ts" | ||
}, | ||
@@ -70,3 +71,5 @@ "repository": { | ||
"typescript": "^4.0.2", | ||
"write": "^2.0.0" | ||
"write": "^2.0.0", | ||
"commander": "^10.0.0", | ||
"ts-node": "^10.9.1" | ||
}, | ||
@@ -92,3 +95,3 @@ "dependencies": { | ||
}, | ||
"version": "4.17.1" | ||
"version": "4.18.0" | ||
} |
@@ -59,3 +59,3 @@ # code-client | ||
/** Building bundle process started with provided data */ | ||
codeClient.emitter.on('scanFilesProgress', (processed: number) = { | ||
codeClient.emitter.on('scanFilesProgress', (processed: number) => { | ||
console.log(`Indexed ${processed} files`); | ||
@@ -75,6 +75,5 @@ }); | ||
/** Logs HTTP requests sent to the API **/ | ||
codeClient.emitter.on('apiRequestLog', (message) => { | ||
codeClient.emitter.on('apiRequestLog', message => { | ||
console.log(message); | ||
}); | ||
``` | ||
@@ -142,1 +141,33 @@ | ||
``` | ||
## CLI | ||
There is a way to run separate calls using a CLI | ||
### Create bundle | ||
Help manifest: `time npm run cli -- help bundle:create` | ||
``` | ||
Usage: CLI bundle:create [options] | ||
create a new bundle and return its ID with meta info | ||
Options: | ||
--patterns [string...] supported file patterns | ||
--ignore [path...] ignored path glob | ||
--path [path...] source code dir | ||
--url <url> service URL | ||
--token <hash> user token | ||
--org <string> organization | ||
--source <string> source identifier (default: "code-client") | ||
-H, --headers [string...] custom headers e.g. "X-Custom-Header: some value". Can have multiple values diveded by space | ||
--debug enable debug mode | ||
-h, --help display help for command | ||
``` | ||
Example call: | ||
```bash | ||
npm run cli -- bundle:create --url="<service url>" --token="<snyk token>" --headers="<extra>" --patterns=".*" --path="<absolute path>" | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158621
45
2229
171
20