@cyclonedx/cyclonedx-library 1.0.0-beta.1

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 (169) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +152 -0
  4. package/dist.node/_index.node.js +53 -0
  5. package/dist.node/_index.node.js.map +1 -0
  6. package/dist.node/enums/attachmentEncoding.js +26 -0
  7. package/dist.node/enums/attachmentEncoding.js.map +1 -0
  8. package/dist.node/enums/componentScope.js +28 -0
  9. package/dist.node/enums/componentScope.js.map +1 -0
  10. package/dist.node/enums/componentType.js +33 -0
  11. package/dist.node/enums/componentType.js.map +1 -0
  12. package/dist.node/enums/externalReferenceType.js +41 -0
  13. package/dist.node/enums/externalReferenceType.js.map +1 -0
  14. package/dist.node/enums/hashAlogorithm.js +37 -0
  15. package/dist.node/enums/hashAlogorithm.js.map +1 -0
  16. package/dist.node/enums/index.js +40 -0
  17. package/dist.node/enums/index.js.map +1 -0
  18. package/dist.node/factories/index.js +36 -0
  19. package/dist.node/factories/index.js.map +1 -0
  20. package/dist.node/factories/licenseFactory.js +56 -0
  21. package/dist.node/factories/licenseFactory.js.map +1 -0
  22. package/dist.node/helpers/types.js +26 -0
  23. package/dist.node/helpers/types.js.map +1 -0
  24. package/dist.node/models/attachment.js +30 -0
  25. package/dist.node/models/attachment.js.map +1 -0
  26. package/dist.node/models/bom.js +67 -0
  27. package/dist.node/models/bom.js.map +1 -0
  28. package/dist.node/models/bomRef.js +37 -0
  29. package/dist.node/models/bomRef.js.map +1 -0
  30. package/dist.node/models/component.js +96 -0
  31. package/dist.node/models/component.js.map +1 -0
  32. package/dist.node/models/externalReference.js +40 -0
  33. package/dist.node/models/externalReference.js.map +1 -0
  34. package/dist.node/models/hash.js +29 -0
  35. package/dist.node/models/hash.js.map +1 -0
  36. package/dist.node/models/index.js +47 -0
  37. package/dist.node/models/index.js.map +1 -0
  38. package/dist.node/models/license.js +103 -0
  39. package/dist.node/models/license.js.map +1 -0
  40. package/dist.node/models/metadata.js +35 -0
  41. package/dist.node/models/metadata.js.map +1 -0
  42. package/dist.node/models/organizationalContact.js +41 -0
  43. package/dist.node/models/organizationalContact.js.map +1 -0
  44. package/dist.node/models/organizationalEntity.js +31 -0
  45. package/dist.node/models/organizationalEntity.js.map +1 -0
  46. package/dist.node/models/swid.js +58 -0
  47. package/dist.node/models/swid.js.map +1 -0
  48. package/dist.node/models/tool.js +45 -0
  49. package/dist.node/models/tool.js.map +1 -0
  50. package/dist.node/resources.node.js +55 -0
  51. package/dist.node/resources.node.js.map +1 -0
  52. package/dist.node/serialize/_index.node.js +37 -0
  53. package/dist.node/serialize/_index.node.js.map +1 -0
  54. package/dist.node/serialize/baseSerializer.js +56 -0
  55. package/dist.node/serialize/baseSerializer.js.map +1 -0
  56. package/dist.node/serialize/bomRefDiscriminator.js +66 -0
  57. package/dist.node/serialize/bomRefDiscriminator.js.map +1 -0
  58. package/dist.node/serialize/index.js +55 -0
  59. package/dist.node/serialize/index.js.map +1 -0
  60. package/dist.node/serialize/json/index.js +47 -0
  61. package/dist.node/serialize/json/index.js.map +1 -0
  62. package/dist.node/serialize/json/normalize.js +431 -0
  63. package/dist.node/serialize/json/normalize.js.map +1 -0
  64. package/dist.node/serialize/json/types.js +35 -0
  65. package/dist.node/serialize/json/types.js.map +1 -0
  66. package/dist.node/serialize/jsonSerializer.js +55 -0
  67. package/dist.node/serialize/jsonSerializer.js.map +1 -0
  68. package/dist.node/serialize/types.js +21 -0
  69. package/dist.node/serialize/types.js.map +1 -0
  70. package/dist.node/serialize/xml/index.js +47 -0
  71. package/dist.node/serialize/xml/index.js.map +1 -0
  72. package/dist.node/serialize/xml/normalize.js +560 -0
  73. package/dist.node/serialize/xml/normalize.js.map +1 -0
  74. package/dist.node/serialize/xml/types.js +31 -0
  75. package/dist.node/serialize/xml/types.js.map +1 -0
  76. package/dist.node/serialize/xmlBaseSerializer.js +52 -0
  77. package/dist.node/serialize/xmlBaseSerializer.js.map +1 -0
  78. package/dist.node/serialize/xmlSerializer.node.js +30 -0
  79. package/dist.node/serialize/xmlSerializer.node.js.map +1 -0
  80. package/dist.node/spdx.js +35 -0
  81. package/dist.node/spdx.js.map +1 -0
  82. package/dist.node/spec.js +229 -0
  83. package/dist.node/spec.js.map +1 -0
  84. package/dist.node/types/cpe.js +28 -0
  85. package/dist.node/types/cpe.js.map +1 -0
  86. package/dist.node/types/index.js +39 -0
  87. package/dist.node/types/index.js.map +1 -0
  88. package/dist.node/types/integer.js +36 -0
  89. package/dist.node/types/integer.js.map +1 -0
  90. package/dist.node/types/mimeType.js +28 -0
  91. package/dist.node/types/mimeType.js.map +1 -0
  92. package/dist.node/types/urn.js +28 -0
  93. package/dist.node/types/urn.js.map +1 -0
  94. package/dist.web/lib.dev.js +3487 -0
  95. package/dist.web/lib.dev.js.map +1 -0
  96. package/dist.web/lib.js +2 -0
  97. package/dist.web/lib.js.LICENSE.txt +18 -0
  98. package/libs/universal-node-xml/index.d.ts +33 -0
  99. package/libs/universal-node-xml/index.js +42 -0
  100. package/libs/universal-node-xml/stringifiers/helpers.js +17 -0
  101. package/libs/universal-node-xml/stringifiers/xmlbuilder2.js +51 -0
  102. package/package.json +86 -0
  103. package/res/README.md +27 -0
  104. package/res/bom-1.0.SNAPSHOT.xsd +247 -0
  105. package/res/bom-1.1.SNAPSHOT.xsd +731 -0
  106. package/res/bom-1.2-strict.SNAPSHOT.schema.json +1026 -0
  107. package/res/bom-1.2.SNAPSHOT.schema.json +997 -0
  108. package/res/bom-1.2.SNAPSHOT.xsd +1418 -0
  109. package/res/bom-1.3-strict.SNAPSHOT.schema.json +1085 -0
  110. package/res/bom-1.3.SNAPSHOT.schema.json +1054 -0
  111. package/res/bom-1.3.SNAPSHOT.xsd +1631 -0
  112. package/res/bom-1.4.SNAPSHOT.schema.json +1697 -0
  113. package/res/bom-1.4.SNAPSHOT.xsd +2407 -0
  114. package/res/jsf-0.82.SNAPSHOT.schema.json +244 -0
  115. package/res/spdx.SNAPSHOT.schema.json +533 -0
  116. package/res/spdx.SNAPSHOT.xsd +2639 -0
  117. package/src/_index.node.ts +31 -0
  118. package/src/_index.web.ts +27 -0
  119. package/src/enums/attachmentEncoding.ts +22 -0
  120. package/src/enums/componentScope.ts +24 -0
  121. package/src/enums/componentType.ts +29 -0
  122. package/src/enums/externalReferenceType.ts +37 -0
  123. package/src/enums/hashAlogorithm.ts +33 -0
  124. package/src/enums/index.ts +24 -0
  125. package/src/factories/index.ts +20 -0
  126. package/src/factories/licenseFactory.ts +62 -0
  127. package/src/helpers/README.md +3 -0
  128. package/src/helpers/types.ts +28 -0
  129. package/src/models/attachment.ts +37 -0
  130. package/src/models/bom.ts +85 -0
  131. package/src/models/bomRef.ts +41 -0
  132. package/src/models/component.ts +136 -0
  133. package/src/models/externalReference.ts +48 -0
  134. package/src/models/hash.ts +38 -0
  135. package/src/models/index.ts +31 -0
  136. package/src/models/license.ts +133 -0
  137. package/src/models/metadata.ts +50 -0
  138. package/src/models/organizationalContact.ts +49 -0
  139. package/src/models/organizationalEntity.ts +38 -0
  140. package/src/models/swid.ts +71 -0
  141. package/src/models/tool.ts +58 -0
  142. package/src/resources.node.ts +59 -0
  143. package/src/serialize/_index.node.ts +23 -0
  144. package/src/serialize/_index.web.ts +23 -0
  145. package/src/serialize/baseSerializer.ts +52 -0
  146. package/src/serialize/bomRefDiscriminator.ts +69 -0
  147. package/src/serialize/index.ts +35 -0
  148. package/src/serialize/json/index.ts +23 -0
  149. package/src/serialize/json/normalize.ts +450 -0
  150. package/src/serialize/json/types.ts +187 -0
  151. package/src/serialize/jsonSerializer.ts +59 -0
  152. package/src/serialize/types.ts +38 -0
  153. package/src/serialize/xml/index.ts +23 -0
  154. package/src/serialize/xml/normalize.ts +590 -0
  155. package/src/serialize/xml/types.ts +112 -0
  156. package/src/serialize/xmlBaseSerializer.ts +52 -0
  157. package/src/serialize/xmlSerializer.node.ts +35 -0
  158. package/src/serialize/xmlSerializer.web.ts +89 -0
  159. package/src/spdx.ts +48 -0
  160. package/src/spec.ts +289 -0
  161. package/src/types/cpe.ts +33 -0
  162. package/src/types/index.ts +23 -0
  163. package/src/types/integer.ts +50 -0
  164. package/src/types/mimeType.ts +31 -0
  165. package/src/types/urn.ts +33 -0
  166. package/tsconfig.json +108 -0
  167. package/tsconfig.node.json +8 -0
  168. package/tsconfig.web.json +5 -0
  169. package/webpack.config.js +74 -0
@@ -0,0 +1,31 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export * as Enums from './enums'
21
+ export * as Factories from './factories'
22
+ export * as Models from './models'
23
+ export * as Serialize from './serialize/_index.node'
24
+ export * as SPDX from './spdx'
25
+ export * as Spec from './spec'
26
+ export * as Types from './types'
27
+
28
+ /** @internal until the resources-module was finalized and showed value */
29
+ export * as Resources from './resources.node'
30
+
31
+ // do not export the helpers, they are for internal use only
@@ -0,0 +1,27 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export * as Types from './types'
21
+ export * as Enums from './enums'
22
+ export * as SPDX from './spdx'
23
+ export * as Models from './models'
24
+ export * as Factories from './factories'
25
+ export * as Spec from './spec'
26
+ export * as Serialize from './serialize/_index.web'
27
+ // do not export the helpers, they are for internal use only
@@ -0,0 +1,22 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export enum AttachmentEncoding {
21
+ Base64 = 'base64',
22
+ }
@@ -0,0 +1,24 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export enum ComponentScope {
21
+ Required = 'required',
22
+ Optional = 'optional',
23
+ Excluded = 'excluded',
24
+ }
@@ -0,0 +1,29 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export enum ComponentType {
21
+ Application = 'application',
22
+ Framework = 'framework',
23
+ Library = 'library',
24
+ Container = 'container',
25
+ OperatingSystem = 'operating-system',
26
+ Device = 'device',
27
+ Firmware = 'firmware',
28
+ File = 'file',
29
+ }
@@ -0,0 +1,37 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export enum ExternalReferenceType {
21
+ VCS = 'vcs',
22
+ IssueTracker = 'issue-tracker',
23
+ Website = 'website',
24
+ Advisories = 'advisories',
25
+ BOM = 'bom',
26
+ MailingList = 'mailing-list',
27
+ Social = 'social',
28
+ Chat = 'chat',
29
+ Documentation = 'documentation',
30
+ Support = 'support',
31
+ Distribution = 'distribution',
32
+ License = 'license',
33
+ BuildMeta = 'build-meta',
34
+ BuildSystem = 'build-system',
35
+ ReleaseNotes = 'release-notes',
36
+ Other = 'other',
37
+ }
@@ -0,0 +1,33 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export enum HashAlgorithm {
21
+ MD5 = 'MD5',
22
+ 'SHA-1' = 'SHA-1',
23
+ 'SHA-256' = 'SHA-256',
24
+ 'SHA-384' = 'SHA-384',
25
+ 'SHA-512' = 'SHA-512',
26
+ 'SHA3-256' = 'SHA3-256',
27
+ 'SHA3-384' = 'SHA3-384',
28
+ 'SHA3-512' = 'SHA3-512',
29
+ 'BLAKE2b-256' = 'BLAKE2b-256',
30
+ 'BLAKE2b-384' = 'BLAKE2b-384',
31
+ 'BLAKE2b-512' = 'BLAKE2b-512',
32
+ BLAKE3 = 'BLAKE3',
33
+ }
@@ -0,0 +1,24 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export * from './attachmentEncoding'
21
+ export * from './componentScope'
22
+ export * from './componentType'
23
+ export * from './externalReferenceType'
24
+ export * from './hashAlogorithm'
@@ -0,0 +1,20 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export * from './licenseFactory'
@@ -0,0 +1,62 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { DisjunctiveLicense, License, LicenseExpression, NamedLicense, SpdxLicense } from '../models'
21
+ import { fixupSpdxId } from '../spdx'
22
+
23
+ export class LicenseFactory {
24
+ makeFromString (value: string): License {
25
+ try {
26
+ return this.makeExpression(value)
27
+ } catch (Error) {
28
+ return this.makeDisjunctive(value)
29
+ }
30
+ }
31
+
32
+ /**
33
+ * @throws {RangeError} if expression is not eligible
34
+ */
35
+ makeExpression (value: string): LicenseExpression {
36
+ return new LicenseExpression(value)
37
+ }
38
+
39
+ makeDisjunctive (value: string): DisjunctiveLicense {
40
+ try {
41
+ return this.makeDisjunctiveWithId(value)
42
+ } catch (error) {
43
+ return this.makeDisjunctiveWithName(value)
44
+ }
45
+ }
46
+
47
+ /**
48
+ * @throws {RangeError} if value is not supported SPDX id
49
+ */
50
+ makeDisjunctiveWithId (value: string | any): SpdxLicense {
51
+ const spdxId = fixupSpdxId(String(value))
52
+ if (undefined === spdxId) {
53
+ throw new RangeError('Unsupported SPDX id')
54
+ }
55
+
56
+ return new SpdxLicense(spdxId)
57
+ }
58
+
59
+ makeDisjunctiveWithName (value: string | any): NamedLicense {
60
+ return new NamedLicense(String(value))
61
+ }
62
+ }
@@ -0,0 +1,3 @@
1
+ # Helpers
2
+
3
+ these are internal helpers, that are not intended to be exported/published
@@ -0,0 +1,28 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ export type NotUndefined<T> = T extends undefined ? never : T
21
+
22
+ export function isNotUndefined<T> (value: T | undefined): value is NotUndefined<T> {
23
+ return value !== undefined
24
+ }
25
+
26
+ export interface Stringable {
27
+ toString: () => string
28
+ }
@@ -0,0 +1,37 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { AttachmentEncoding } from '../enums'
21
+
22
+ interface OptionalProperties {
23
+ contentType?: Attachment['contentType']
24
+ encoding?: Attachment['encoding']
25
+ }
26
+
27
+ export class Attachment {
28
+ contentType?: string
29
+ content: string
30
+ encoding?: AttachmentEncoding
31
+
32
+ constructor (content: string, op: OptionalProperties = {}) {
33
+ this.contentType = op.contentType
34
+ this.content = content
35
+ this.encoding = op.encoding
36
+ }
37
+ }
@@ -0,0 +1,85 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { isPositiveInteger, isUrnUuid, PositiveInteger, UrnUuid } from '../types'
21
+ import { Metadata } from './metadata'
22
+ import { ComponentRepository } from './component'
23
+
24
+ interface OptionalProperties {
25
+ metadata?: Bom['metadata']
26
+ components?: Bom['components']
27
+ version?: Bom['version']
28
+ serialNumber?: Bom['serialNumber']
29
+ }
30
+
31
+ export class Bom {
32
+ metadata: Metadata
33
+ components: ComponentRepository
34
+
35
+ /** @see version */
36
+ #version: PositiveInteger = 1
37
+
38
+ /** @see serialNumber */
39
+ #serialNumber?: UrnUuid
40
+
41
+ // Property `bomFormat` is not part of model, it is runtime information.
42
+ // Property `specVersion` is not part of model, it is runtime information.
43
+
44
+ // Property `dependencies` is not part of this model, but part of `Component` and other models.
45
+ // The dependency graph can be normalized on render-time, no need to store it in the bom model.
46
+
47
+ /**
48
+ * @throws {TypeError} if {@see op.version} is not {@see PositiveInteger} nor {@see undefined}
49
+ * @throws {TypeError} if {@see op.serialNumber} is neither {@see UrnUuid} nor {@see undefined}
50
+ */
51
+ constructor (op: OptionalProperties = {}) {
52
+ this.metadata = op.metadata ?? new Metadata()
53
+ this.components = op.components ?? new ComponentRepository()
54
+ this.version = op.version ?? this.version
55
+ this.serialNumber = op.serialNumber
56
+ }
57
+
58
+ get version (): PositiveInteger {
59
+ return this.#version
60
+ }
61
+
62
+ /**
63
+ * @throws {TypeError} if value is not {@see PositiveInteger}
64
+ */
65
+ set version (value: PositiveInteger) {
66
+ if (!isPositiveInteger(value)) {
67
+ throw new TypeError('Not PositiveInteger')
68
+ }
69
+ this.#version = value
70
+ }
71
+
72
+ get serialNumber (): UrnUuid | undefined {
73
+ return this.#serialNumber
74
+ }
75
+
76
+ /**
77
+ * @throws {TypeError} if value is neither {@see UrnUuid} nor {@see undefined}
78
+ */
79
+ set serialNumber (value: UrnUuid | undefined) {
80
+ if (value !== undefined && !isUrnUuid(value)) {
81
+ throw new TypeError('Not UrnUuid nor undefined')
82
+ }
83
+ this.#serialNumber = value
84
+ }
85
+ }
@@ -0,0 +1,41 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ /**
21
+ * Proxy for the BomRef.
22
+ * This way a `BomRef` gets unique by the in-memory-address of the object.
23
+ */
24
+ export class BomRef {
25
+ value?: string
26
+
27
+ constructor (value?: string) {
28
+ this.value = value
29
+ }
30
+
31
+ compare (other: BomRef): number {
32
+ return (this.toString()).localeCompare(other.toString())
33
+ }
34
+
35
+ toString (): string {
36
+ return this.value ?? ''
37
+ }
38
+ }
39
+
40
+ export class BomRefRepository extends Set<BomRef> {
41
+ }
@@ -0,0 +1,136 @@
1
+ /*!
2
+ This file is part of CycloneDX JavaScript Library.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache-2.0
17
+ Copyright (c) OWASP Foundation. All Rights Reserved.
18
+ */
19
+
20
+ import { PackageURL } from 'packageurl-js'
21
+
22
+ import { CPE, isCPE } from '../types'
23
+ import { ComponentScope, ComponentType } from '../enums'
24
+ import { BomRef, BomRefRepository } from './bomRef'
25
+ import { HashRepository } from './hash'
26
+ import { OrganizationalEntity } from './organizationalEntity'
27
+ import { ExternalReferenceRepository } from './externalReference'
28
+ import { LicenseRepository } from './license'
29
+ import { SWID } from './swid'
30
+
31
+ interface OptionalProperties {
32
+ bomRef?: BomRef['value']
33
+ author?: Component['author']
34
+ copyright?: Component['copyright']
35
+ description?: Component['description']
36
+ externalReferences?: Component['externalReferences']
37
+ group?: Component['group']
38
+ hashes?: Component['hashes']
39
+ licenses?: Component['licenses']
40
+ publisher?: Component['publisher']
41
+ purl?: Component['purl']
42
+ scope?: Component['scope']
43
+ supplier?: Component['supplier']
44
+ swid?: Component['swid']
45
+ version?: Component['version']
46
+ dependencies?: Component['dependencies']
47
+ cpe?: Component['cpe']
48
+ }
49
+
50
+ export class Component {
51
+ type: ComponentType
52
+ name: string
53
+ author?: string
54
+ copyright?: string
55
+ description?: string
56
+ externalReferences: ExternalReferenceRepository
57
+ group?: string
58
+ hashes: HashRepository
59
+ licenses: LicenseRepository
60
+ publisher?: string
61
+ purl?: PackageURL
62
+ scope?: ComponentScope
63
+ supplier?: OrganizationalEntity
64
+ swid?: SWID
65
+ version?: string
66
+ dependencies: BomRefRepository
67
+
68
+ /** @see bomRef */
69
+ readonly #bomRef: BomRef
70
+
71
+ /** @see cpe */
72
+ #cpe?: CPE
73
+
74
+ /**
75
+ * @throws {TypeError} if {@see op.cpe} is neither {@see CPE} nor {@see undefined}
76
+ */
77
+ constructor (type: ComponentType, name: string, op: OptionalProperties = {}) {
78
+ this.#bomRef = new BomRef(op.bomRef)
79
+ this.type = type
80
+ this.name = name
81
+ this.author = op.author
82
+ this.copyright = op.copyright
83
+ this.externalReferences = op.externalReferences ?? new ExternalReferenceRepository()
84
+ this.group = op.group
85
+ this.hashes = op.hashes ?? new HashRepository()
86
+ this.licenses = op.licenses ?? new LicenseRepository()
87
+ this.publisher = op.publisher
88
+ this.purl = op.purl
89
+ this.scope = op.scope
90
+ this.swid = op.swid
91
+ this.version = op.version
92
+ this.dependencies = op.dependencies ?? new BomRefRepository()
93
+ this.cpe = op.cpe
94
+ }
95
+
96
+ get bomRef (): BomRef {
97
+ return this.#bomRef
98
+ }
99
+
100
+ get cpe (): CPE | undefined {
101
+ return this.#cpe
102
+ }
103
+
104
+ /**
105
+ * @throws {TypeError} if value is neither {@see CPE} nor {@see undefined}
106
+ */
107
+ set cpe (value: CPE | undefined) {
108
+ if (value !== undefined && !isCPE(value)) {
109
+ throw new TypeError('Not CPE nor undefined')
110
+ }
111
+ this.#cpe = value
112
+ }
113
+
114
+ compare (other: Component): number {
115
+ const bomRefCompare = this.bomRef.compare(other.bomRef)
116
+ if (bomRefCompare !== 0) {
117
+ return bomRefCompare
118
+ }
119
+ if (this.purl !== undefined && other.purl !== undefined) {
120
+ return this.purl.toString().localeCompare(other.purl.toString())
121
+ }
122
+ if (this.#cpe !== undefined && other.#cpe !== undefined) {
123
+ return this.#cpe.toString().localeCompare(other.#cpe.toString())
124
+ }
125
+ /* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
126
+ return (this.group ?? '').localeCompare(other.group ?? '') ||
127
+ this.name.localeCompare(other.name) ||
128
+ (this.version ?? '').localeCompare(other.version ?? '')
129
+ }
130
+ }
131
+
132
+ export class ComponentRepository extends Set<Component> {
133
+ static compareItems (a: Component, b: Component): number {
134
+ return a.compare(b)
135
+ }
136
+ }