@theia/scanoss 1.57.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.
- package/README.md +33 -0
- package/lib/browser/scanoss-frontend-module.d.ts +4 -0
- package/lib/browser/scanoss-frontend-module.d.ts.map +1 -0
- package/lib/browser/scanoss-frontend-module.js +29 -0
- package/lib/browser/scanoss-frontend-module.js.map +1 -0
- package/lib/browser/scanoss-preferences.d.ts +4 -0
- package/lib/browser/scanoss-preferences.d.ts.map +1 -0
- package/lib/browser/scanoss-preferences.js +31 -0
- package/lib/browser/scanoss-preferences.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +20 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/scanoss-service.d.ts +20 -0
- package/lib/common/scanoss-service.d.ts.map +1 -0
- package/lib/common/scanoss-service.js +21 -0
- package/lib/common/scanoss-service.js.map +1 -0
- package/lib/node/scanoss-backend-module.d.ts +4 -0
- package/lib/node/scanoss-backend-module.d.ts.map +1 -0
- package/lib/node/scanoss-backend-module.js +27 -0
- package/lib/node/scanoss-backend-module.js.map +1 -0
- package/lib/node/scanoss-service-impl.d.ts +7 -0
- package/lib/node/scanoss-service-impl.d.ts.map +1 -0
- package/lib/node/scanoss-service-impl.js +107 -0
- package/lib/node/scanoss-service-impl.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +26 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +50 -0
- package/src/browser/scanoss-frontend-module.ts +28 -0
- package/src/browser/scanoss-preferences.ts +31 -0
- package/src/common/index.ts +16 -0
- package/src/common/scanoss-service.ts +34 -0
- package/src/node/scanoss-backend-module.ts +28 -0
- package/src/node/scanoss-service-impl.ts +110 -0
- package/src/package.spec.ts +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<div align='center'>
|
|
2
|
+
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
|
|
6
|
+
|
|
7
|
+
<h2>ECLIPSE THEIA - SCAN OSS EXTENSION</h2>
|
|
8
|
+
|
|
9
|
+
<hr />
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
Offers a `ScanOSSService` on the backend and frontend for scanning code snippets.
|
|
16
|
+
|
|
17
|
+
If needed, an API key can be handed over via preference or environment variable (`SCANOSS_API_KEY`).
|
|
18
|
+
|
|
19
|
+
## Additional Information
|
|
20
|
+
|
|
21
|
+
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
|
|
22
|
+
- [Theia - Website](https://theia-ide.org/)
|
|
23
|
+
- [SCAN OSS Website](https://www.scanoss.com/)
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
|
|
28
|
+
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
29
|
+
|
|
30
|
+
## Trademark
|
|
31
|
+
|
|
32
|
+
"Theia" is a trademark of the Eclipse Foundation
|
|
33
|
+
<https://www.eclipse.org/theia>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/scanoss-frontend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAK/D,wBAMG"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
19
|
+
const scanoss_preferences_1 = require("./scanoss-preferences");
|
|
20
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
21
|
+
const common_1 = require("../common");
|
|
22
|
+
exports.default = new inversify_1.ContainerModule(bind => {
|
|
23
|
+
bind(browser_1.PreferenceContribution).toConstantValue({ schema: scanoss_preferences_1.ScanOSSPreferencesSchema });
|
|
24
|
+
bind(common_1.ScanOSSService).toDynamicValue(ctx => {
|
|
25
|
+
const provider = ctx.container.get(browser_1.RemoteConnectionProvider);
|
|
26
|
+
return provider.createProxy(common_1.SCANOSS_SERVICE_PATH);
|
|
27
|
+
}).inSingletonScope();
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=scanoss-frontend-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-frontend-module.js","sourceRoot":"","sources":["../../src/browser/scanoss-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,4DAA+D;AAC/D,+DAAiE;AACjE,qDAAsH;AACtH,sCAAiE;AAEjE,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,8CAAwB,EAAE,CAAC,CAAC;IACnF,IAAI,CAAC,uBAAc,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QACtC,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAA4B,kCAAwB,CAAC,CAAC;QACxF,OAAO,QAAQ,CAAC,WAAW,CAAiB,6BAAoB,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC1B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-preferences.d.ts","sourceRoot":"","sources":["../../src/browser/scanoss-preferences.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AAEtD,eAAO,MAAM,wBAAwB,EAAE,gBAUtC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ScanOSSPreferencesSchema = exports.SCAN_OSS_API_KEY_PREF = void 0;
|
|
19
|
+
exports.SCAN_OSS_API_KEY_PREF = 'SCANOSS.apiKey';
|
|
20
|
+
exports.ScanOSSPreferencesSchema = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
[exports.SCAN_OSS_API_KEY_PREF]: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
markdownDescription: 'Enter an API Key of your SCANOSS Account. **Please note:** By using this preference the key will be stored in clear text\
|
|
26
|
+
on the machine running Theia. Use the environment variable `SCANOSS_API_KEY` to set the key securely.',
|
|
27
|
+
title: 'SCANOSS API Key'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=scanoss-preferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-preferences.js","sourceRoot":"","sources":["../../src/browser/scanoss-preferences.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAInE,QAAA,qBAAqB,GAAG,gBAAgB,CAAC;AAEzC,QAAA,wBAAwB,GAAqB;IACtD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,6BAAqB,CAAC,EAAE;YACrB,IAAI,EAAE,QAAQ;YACd,mBAAmB,EAAE;kHACiF;YACtG,KAAK,EAAE,iBAAiB;SAC3B;KACJ;CACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAeA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// *****************************************************************************
|
|
5
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
6
|
+
//
|
|
7
|
+
// This program and the accompanying materials are made available under the
|
|
8
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
9
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
10
|
+
//
|
|
11
|
+
// This Source Code may also be made available under the following Secondary
|
|
12
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
13
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
14
|
+
// with the GNU Classpath Exception which is available at
|
|
15
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
16
|
+
//
|
|
17
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
18
|
+
// *****************************************************************************
|
|
19
|
+
tslib_1.__exportStar(require("./scanoss-service"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,4DAAkC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const SCANOSS_SERVICE_PATH = "/services/scanoss/service";
|
|
2
|
+
export declare const ScanOSSService: unique symbol;
|
|
3
|
+
export interface ScanOSSResultClean {
|
|
4
|
+
type: 'clean';
|
|
5
|
+
}
|
|
6
|
+
export interface ScanOSSResultMatch {
|
|
7
|
+
type: 'match';
|
|
8
|
+
matched: string;
|
|
9
|
+
url: string;
|
|
10
|
+
raw: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface ScanOSSResultError {
|
|
13
|
+
type: 'error';
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
export type ScanOSSResult = ScanOSSResultClean | ScanOSSResultMatch | ScanOSSResultError;
|
|
17
|
+
export interface ScanOSSService {
|
|
18
|
+
scanContent(content: string, apiKey?: string): Promise<ScanOSSResult>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=scanoss-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-service.d.ts","sourceRoot":"","sources":["../../src/common/scanoss-service.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,oBAAoB,8BAA8B,CAAC;AAChE,eAAO,MAAM,cAAc,eAA2B,CAAC;AACvD,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,OAAO,CAAC;CACjB;AACD,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,OAAO,CAAC;CAChB;AACD,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB;AACD,MAAM,MAAM,aAAa,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AACzF,MAAM,WAAW,cAAc;IAC3B,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CACzE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScanOSSService = exports.SCANOSS_SERVICE_PATH = void 0;
|
|
4
|
+
// *****************************************************************************
|
|
5
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
6
|
+
//
|
|
7
|
+
// This program and the accompanying materials are made available under the
|
|
8
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
9
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
10
|
+
//
|
|
11
|
+
// This Source Code may also be made available under the following Secondary
|
|
12
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
13
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
14
|
+
// with the GNU Classpath Exception which is available at
|
|
15
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
16
|
+
//
|
|
17
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
18
|
+
// *****************************************************************************
|
|
19
|
+
exports.SCANOSS_SERVICE_PATH = '/services/scanoss/service';
|
|
20
|
+
exports.ScanOSSService = Symbol('ScanOSSService');
|
|
21
|
+
//# sourceMappingURL=scanoss-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-service.js","sourceRoot":"","sources":["../../src/common/scanoss-service.ts"],"names":[],"mappings":";;;AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AACnE,QAAA,oBAAoB,GAAG,2BAA2B,CAAC;AACnD,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/scanoss-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAK/D,wBAMG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
19
|
+
const core_1 = require("@theia/core");
|
|
20
|
+
const common_1 = require("../common");
|
|
21
|
+
const scanoss_service_impl_1 = require("./scanoss-service-impl");
|
|
22
|
+
exports.default = new inversify_1.ContainerModule(bind => {
|
|
23
|
+
bind(scanoss_service_impl_1.ScanOSSServiceImpl).toSelf().inSingletonScope();
|
|
24
|
+
bind(common_1.ScanOSSService).toService(scanoss_service_impl_1.ScanOSSServiceImpl);
|
|
25
|
+
bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(common_1.SCANOSS_SERVICE_PATH, () => ctx.container.get(common_1.ScanOSSService))).inSingletonScope();
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=scanoss-backend-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-backend-module.js","sourceRoot":"","sources":["../../src/node/scanoss-backend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,4DAA+D;AAC/D,sCAAsE;AACtE,sCAAiE;AACjE,iEAA4D;AAE5D,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,yCAAkB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACrD,IAAI,CAAC,uBAAc,CAAC,CAAC,SAAS,CAAC,yCAAkB,CAAC,CAAC;IACnD,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CAAC,6BAAoB,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,uBAAc,CAAC,CAAC,CAC1F,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ScanOSSResult, ScanOSSService } from '../common';
|
|
2
|
+
export declare class ScanOSSServiceImpl implements ScanOSSService {
|
|
3
|
+
private readonly processor;
|
|
4
|
+
scanContent(content: string, apiKey?: string): Promise<ScanOSSResult>;
|
|
5
|
+
doScanContent(content: string, apiKey?: string): Promise<ScanOSSResult>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=scanoss-service-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-service-impl.d.ts","sourceRoot":"","sources":["../../src/node/scanoss-service-impl.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAkB1D,qBACa,kBAAmB,YAAW,cAAc;IAErD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4C;IAEhE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAIrE,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAiEhF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ScanOSSServiceImpl = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const scanoss_1 = require("scanoss");
|
|
22
|
+
// Helper class to perform scans sequentially
|
|
23
|
+
class SequentialProcessor {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.queue = Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
async processTask(task) {
|
|
28
|
+
this.queue = this.queue.then(() => task());
|
|
29
|
+
return this.queue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
let ScanOSSServiceImpl = class ScanOSSServiceImpl {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.processor = new SequentialProcessor();
|
|
35
|
+
}
|
|
36
|
+
async scanContent(content, apiKey) {
|
|
37
|
+
return this.processor.processTask(async () => this.doScanContent(content, apiKey));
|
|
38
|
+
}
|
|
39
|
+
async doScanContent(content, apiKey) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const config = new scanoss_1.ScannerCfg();
|
|
42
|
+
const apiKeyToUse = apiKey || process.env.SCANOSS_API_KEY || undefined;
|
|
43
|
+
if (apiKeyToUse) {
|
|
44
|
+
config.API_KEY = apiKeyToUse;
|
|
45
|
+
}
|
|
46
|
+
const scanner = new scanoss_1.Scanner(config);
|
|
47
|
+
let results = undefined;
|
|
48
|
+
try {
|
|
49
|
+
results = await scanner.scanContents({
|
|
50
|
+
content,
|
|
51
|
+
key: 'content_scanning',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error('SCANOSS error', e);
|
|
56
|
+
// map known errors to a more user-friendly message
|
|
57
|
+
// Invalid API key message
|
|
58
|
+
if ((_a = e.message) === null || _a === void 0 ? void 0 : _a.includes('Forbidden')) {
|
|
59
|
+
return {
|
|
60
|
+
type: 'error',
|
|
61
|
+
message: 'Forbidden: Please check your API key'
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Rate limit message
|
|
65
|
+
// HTTP:
|
|
66
|
+
// HTTP Status code: 503
|
|
67
|
+
// Server Response:
|
|
68
|
+
// 503 Unavailable. Check https://osskb.org/limit
|
|
69
|
+
if ((_b = e.message) === null || _b === void 0 ? void 0 : _b.includes('https://osskb.org/limit')) {
|
|
70
|
+
return {
|
|
71
|
+
type: 'error',
|
|
72
|
+
message: 'You have reached the limit of the free data subscription, for a commercial subscription please contact support@scanoss.com'
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
type: 'error',
|
|
77
|
+
message: e.message
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (!results) {
|
|
81
|
+
return {
|
|
82
|
+
type: 'error',
|
|
83
|
+
message: 'Scan request unsuccessful'
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line no-null/no-null
|
|
87
|
+
console.log('SCANOSS results', JSON.stringify(results, null, 2));
|
|
88
|
+
// first result is the best result
|
|
89
|
+
const firstEntry = results['/content_scanning'][0];
|
|
90
|
+
if (firstEntry.id === 'none') {
|
|
91
|
+
return {
|
|
92
|
+
type: 'clean'
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
type: 'match',
|
|
97
|
+
matched: firstEntry.matched,
|
|
98
|
+
url: firstEntry.url,
|
|
99
|
+
raw: firstEntry
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.ScanOSSServiceImpl = ScanOSSServiceImpl;
|
|
104
|
+
exports.ScanOSSServiceImpl = ScanOSSServiceImpl = tslib_1.__decorate([
|
|
105
|
+
(0, inversify_1.injectable)()
|
|
106
|
+
], ScanOSSServiceImpl);
|
|
107
|
+
//# sourceMappingURL=scanoss-service-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanoss-service-impl.js","sourceRoot":"","sources":["../../src/node/scanoss-service-impl.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
/* note: this bogus test file is required so that
|
|
17
|
+
we are able to run mocha unit tests on this
|
|
18
|
+
package, without having any actual unit tests in it.
|
|
19
|
+
This way a coverage report will be generated,
|
|
20
|
+
showing 0% coverage, instead of no report.
|
|
21
|
+
This file can be removed once we have real unit
|
|
22
|
+
tests in place. */
|
|
23
|
+
describe('ai-scanoss package', () => {
|
|
24
|
+
it('support code coverage statistics', () => true);
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=package.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAEhF;;;;;;qBAMqB;AAErB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAEhC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theia/scanoss",
|
|
3
|
+
"version": "1.57.0",
|
|
4
|
+
"description": "Theia - SCANOSS Integration",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@theia/core": "1.57.0",
|
|
7
|
+
"scanoss": "^0.15.2"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"theiaExtensions": [
|
|
13
|
+
{
|
|
14
|
+
"frontend": "lib/browser/scanoss-frontend-module",
|
|
15
|
+
"backend": "lib/node/scanoss-backend-module"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"theia-extension"
|
|
20
|
+
],
|
|
21
|
+
"license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/eclipse-theia/theia.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/eclipse-theia/theia/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/eclipse-theia/theia",
|
|
30
|
+
"files": [
|
|
31
|
+
"lib",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"main": "lib/common",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "theiaext build",
|
|
37
|
+
"clean": "theiaext clean",
|
|
38
|
+
"compile": "theiaext compile",
|
|
39
|
+
"lint": "theiaext lint",
|
|
40
|
+
"test": "theiaext test",
|
|
41
|
+
"watch": "theiaext watch"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@theia/ext-scripts": "1.57.0"
|
|
45
|
+
},
|
|
46
|
+
"nyc": {
|
|
47
|
+
"extends": "../../configs/nyc.json"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "ca1d948d897b9a774f8cd68bb76bd2f335609cd4"
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ScanOSSPreferencesSchema } from './scanoss-preferences';
|
|
19
|
+
import { PreferenceContribution, RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser';
|
|
20
|
+
import { SCANOSS_SERVICE_PATH, ScanOSSService } from '../common';
|
|
21
|
+
|
|
22
|
+
export default new ContainerModule(bind => {
|
|
23
|
+
bind(PreferenceContribution).toConstantValue({ schema: ScanOSSPreferencesSchema });
|
|
24
|
+
bind(ScanOSSService).toDynamicValue(ctx => {
|
|
25
|
+
const provider = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider);
|
|
26
|
+
return provider.createProxy<ScanOSSService>(SCANOSS_SERVICE_PATH);
|
|
27
|
+
}).inSingletonScope();
|
|
28
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { PreferenceSchema } from '@theia/core/lib/browser/preferences';
|
|
18
|
+
|
|
19
|
+
export const SCAN_OSS_API_KEY_PREF = 'SCANOSS.apiKey';
|
|
20
|
+
|
|
21
|
+
export const ScanOSSPreferencesSchema: PreferenceSchema = {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
[SCAN_OSS_API_KEY_PREF]: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
markdownDescription: 'Enter an API Key of your SCANOSS Account. **Please note:** By using this preference the key will be stored in clear text\
|
|
27
|
+
on the machine running Theia. Use the environment variable `SCANOSS_API_KEY` to set the key securely.',
|
|
28
|
+
title: 'SCANOSS API Key'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
export * from './scanoss-service';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
export const SCANOSS_SERVICE_PATH = '/services/scanoss/service';
|
|
17
|
+
export const ScanOSSService = Symbol('ScanOSSService');
|
|
18
|
+
export interface ScanOSSResultClean {
|
|
19
|
+
type: 'clean';
|
|
20
|
+
}
|
|
21
|
+
export interface ScanOSSResultMatch {
|
|
22
|
+
type: 'match';
|
|
23
|
+
matched: string; // e.g. "75%"
|
|
24
|
+
url: string;
|
|
25
|
+
raw: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface ScanOSSResultError {
|
|
28
|
+
type: 'error';
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
export type ScanOSSResult = ScanOSSResultClean | ScanOSSResultMatch | ScanOSSResultError;
|
|
32
|
+
export interface ScanOSSService {
|
|
33
|
+
scanContent(content: string, apiKey?: string): Promise<ScanOSSResult>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ConnectionHandler, RpcConnectionHandler } from '@theia/core';
|
|
19
|
+
import { ScanOSSService, SCANOSS_SERVICE_PATH } from '../common';
|
|
20
|
+
import { ScanOSSServiceImpl } from './scanoss-service-impl';
|
|
21
|
+
|
|
22
|
+
export default new ContainerModule(bind => {
|
|
23
|
+
bind(ScanOSSServiceImpl).toSelf().inSingletonScope();
|
|
24
|
+
bind(ScanOSSService).toService(ScanOSSServiceImpl);
|
|
25
|
+
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
26
|
+
new RpcConnectionHandler(SCANOSS_SERVICE_PATH, () => ctx.container.get(ScanOSSService))
|
|
27
|
+
).inSingletonScope();
|
|
28
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ScanOSSResult, ScanOSSService } from '../common';
|
|
19
|
+
|
|
20
|
+
import { Scanner, ScannerCfg, ScannerComponent } from 'scanoss';
|
|
21
|
+
|
|
22
|
+
// Define our own type of what is actually returned by the scanner
|
|
23
|
+
interface ScanOSSScanner {
|
|
24
|
+
scanContents: <T extends string>(options: { content: string; key: T }) => Promise<{ [K in `/${T}`]: ScannerComponent[] } | null>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Helper class to perform scans sequentially
|
|
28
|
+
class SequentialProcessor<T> {
|
|
29
|
+
private queue: Promise<T> = Promise.resolve() as Promise<T>;
|
|
30
|
+
public async processTask(task: () => Promise<T>): Promise<T> {
|
|
31
|
+
this.queue = this.queue.then(() => task());
|
|
32
|
+
return this.queue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@injectable()
|
|
37
|
+
export class ScanOSSServiceImpl implements ScanOSSService {
|
|
38
|
+
|
|
39
|
+
private readonly processor = new SequentialProcessor<ScanOSSResult>();
|
|
40
|
+
|
|
41
|
+
async scanContent(content: string, apiKey?: string): Promise<ScanOSSResult> {
|
|
42
|
+
return this.processor.processTask(async () => this.doScanContent(content, apiKey));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async doScanContent(content: string, apiKey?: string): Promise<ScanOSSResult> {
|
|
46
|
+
const config = new ScannerCfg();
|
|
47
|
+
const apiKeyToUse = apiKey || process.env.SCANOSS_API_KEY || undefined;
|
|
48
|
+
if (apiKeyToUse) {
|
|
49
|
+
config.API_KEY = apiKeyToUse;
|
|
50
|
+
}
|
|
51
|
+
const scanner = new Scanner(config);
|
|
52
|
+
let results = undefined;
|
|
53
|
+
try {
|
|
54
|
+
results = await (scanner as unknown as ScanOSSScanner).scanContents({
|
|
55
|
+
content,
|
|
56
|
+
key: 'content_scanning',
|
|
57
|
+
});
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error('SCANOSS error', e);
|
|
60
|
+
|
|
61
|
+
// map known errors to a more user-friendly message
|
|
62
|
+
|
|
63
|
+
// Invalid API key message
|
|
64
|
+
if (e.message?.includes('Forbidden')) {
|
|
65
|
+
return {
|
|
66
|
+
type: 'error',
|
|
67
|
+
message: 'Forbidden: Please check your API key'
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Rate limit message
|
|
71
|
+
// HTTP:
|
|
72
|
+
// HTTP Status code: 503
|
|
73
|
+
// Server Response:
|
|
74
|
+
// 503 Unavailable. Check https://osskb.org/limit
|
|
75
|
+
if (e.message?.includes('https://osskb.org/limit')) {
|
|
76
|
+
return {
|
|
77
|
+
type: 'error',
|
|
78
|
+
message: 'You have reached the limit of the free data subscription, for a commercial subscription please contact support@scanoss.com'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
type: 'error',
|
|
83
|
+
message: e.message
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (!results) {
|
|
87
|
+
return {
|
|
88
|
+
type: 'error',
|
|
89
|
+
message: 'Scan request unsuccessful'
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// eslint-disable-next-line no-null/no-null
|
|
94
|
+
console.log('SCANOSS results', JSON.stringify(results, null, 2));
|
|
95
|
+
|
|
96
|
+
// first result is the best result
|
|
97
|
+
const firstEntry = results['/content_scanning'][0];
|
|
98
|
+
if (firstEntry.id === 'none') {
|
|
99
|
+
return {
|
|
100
|
+
type: 'clean'
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
type: 'match',
|
|
105
|
+
matched: firstEntry.matched,
|
|
106
|
+
url: firstEntry.url,
|
|
107
|
+
raw: firstEntry
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
/* note: this bogus test file is required so that
|
|
18
|
+
we are able to run mocha unit tests on this
|
|
19
|
+
package, without having any actual unit tests in it.
|
|
20
|
+
This way a coverage report will be generated,
|
|
21
|
+
showing 0% coverage, instead of no report.
|
|
22
|
+
This file can be removed once we have real unit
|
|
23
|
+
tests in place. */
|
|
24
|
+
|
|
25
|
+
describe('ai-scanoss package', () => {
|
|
26
|
+
|
|
27
|
+
it('support code coverage statistics', () => true);
|
|
28
|
+
});
|