@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,48 @@
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 { ExternalReferenceType } from '../enums'
21
+
22
+ interface OptionalProperties {
23
+ comment?: ExternalReference['comment']
24
+ }
25
+
26
+ export class ExternalReference {
27
+ url: URL | string
28
+ type: ExternalReferenceType
29
+ comment?: string
30
+
31
+ constructor (url: URL | string, type: ExternalReferenceType, op: OptionalProperties = {}) {
32
+ this.url = url
33
+ this.type = type
34
+ this.comment = op.comment
35
+ }
36
+
37
+ compare (other: ExternalReference): number {
38
+ /* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
39
+ return this.type.localeCompare(other.type) ||
40
+ this.url.toString().localeCompare(other.url.toString())
41
+ }
42
+ }
43
+
44
+ export class ExternalReferenceRepository extends Set<ExternalReference> {
45
+ static compareItems (a: ExternalReference, b: ExternalReference): number {
46
+ return a.compare(b)
47
+ }
48
+ }
@@ -0,0 +1,38 @@
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 { HashAlgorithm } from '../enums'
21
+
22
+ // no regex for the HashContent in here. It applies at runtime of a normalization/serialization process.
23
+ export type HashContent = string
24
+
25
+ export type Hash = readonly [
26
+ // order matters: it must reflect [key, value] of HashRepository -
27
+ // this way a HashRepository can be constructed from multiple Hash objects.
28
+ algorithm: HashAlgorithm,
29
+ content: HashContent
30
+ ]
31
+
32
+ export class HashRepository extends Map<Hash[0], Hash[1]> {
33
+ static compareItems (a: Hash, b: Hash): number {
34
+ /* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
35
+ return a[0].localeCompare(b[0]) ||
36
+ a[1].localeCompare(b[1])
37
+ }
38
+ }
@@ -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 * from './attachment'
21
+ export * from './bom'
22
+ export * from './bomRef'
23
+ export * from './component'
24
+ export * from './externalReference'
25
+ export * from './hash'
26
+ export * from './license'
27
+ export * from './metadata'
28
+ export * from './organizationalContact'
29
+ export * from './organizationalEntity'
30
+ export * from './swid'
31
+ export * from './tool'
@@ -0,0 +1,133 @@
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 { isSupportedSpdxId, SpdxId } from '../spdx'
21
+ import { Attachment } from './attachment'
22
+
23
+ export class LicenseExpression {
24
+ static isEligibleExpression (expression: string | any): boolean {
25
+ // smallest known: (A or B)
26
+ return typeof expression === 'string' &&
27
+ expression.length >= 8 &&
28
+ expression[0] === '(' &&
29
+ expression[expression.length - 1] === ')'
30
+ }
31
+
32
+ /** @see expression */
33
+ #expression!: string
34
+
35
+ /**
36
+ * @throws {RangeError} if {@see expression} is not eligible({@see LicenseExpression.isEligibleExpression})
37
+ */
38
+ constructor (expression: string) {
39
+ this.expression = expression
40
+ }
41
+
42
+ get expression (): string {
43
+ return this.#expression
44
+ }
45
+
46
+ /**
47
+ * @throws {RangeError} if expression is not eligible({@see LicenseExpression.isEligibleExpression})
48
+ */
49
+ set expression (value: string) {
50
+ if (!LicenseExpression.isEligibleExpression(value)) {
51
+ throw new RangeError('Not eligible expression')
52
+ }
53
+ this.#expression = value
54
+ }
55
+
56
+ compare (other: LicenseExpression): number {
57
+ return this.#expression.localeCompare(other.#expression)
58
+ }
59
+ }
60
+
61
+ interface NamedLicenseOptionalProperties {
62
+ text?: NamedLicense['text']
63
+ url?: NamedLicense['url']
64
+ }
65
+
66
+ export class NamedLicense {
67
+ name: string
68
+ text?: Attachment
69
+ url?: URL | string
70
+
71
+ constructor (name: string, op: NamedLicenseOptionalProperties = {}) {
72
+ this.name = name
73
+ this.text = op.text
74
+ this.url = op.url
75
+ }
76
+
77
+ compare (other: NamedLicense): number {
78
+ return this.name.localeCompare(other.name)
79
+ }
80
+ }
81
+
82
+ interface SpdxLicenseOptionalProperties {
83
+ text?: SpdxLicense['text']
84
+ url?: SpdxLicense['url']
85
+ }
86
+
87
+ export class SpdxLicense {
88
+ text?: Attachment
89
+ url?: URL | string
90
+
91
+ /** @see id */
92
+ #id!: SpdxId
93
+
94
+ /**
95
+ * @throws {RangeError} if {@see id} is not supported SPDX id({@see isSupportedSpdxId})
96
+ */
97
+ constructor (id: SpdxId, op: SpdxLicenseOptionalProperties = {}) {
98
+ this.id = id
99
+ this.text = op.text
100
+ this.url = op.url
101
+ }
102
+
103
+ get id (): SpdxId {
104
+ return this.#id
105
+ }
106
+
107
+ /**
108
+ * @throws {RangeError} if value is not supported SPDX id({@see isSupportedSpdxId})
109
+ */
110
+ set id (value: SpdxId) {
111
+ if (!isSupportedSpdxId(value)) {
112
+ throw new RangeError('Unknown SPDX id')
113
+ }
114
+ this.#id = value
115
+ }
116
+
117
+ compare (other: SpdxLicense): number {
118
+ return this.#id.localeCompare(other.#id)
119
+ }
120
+ }
121
+
122
+ export type DisjunctiveLicense = NamedLicense | SpdxLicense
123
+ export type License = DisjunctiveLicense | LicenseExpression
124
+
125
+ export class LicenseRepository extends Set<License> {
126
+ static compareItems (a: License, b: License): number {
127
+ if (a.constructor === b.constructor) {
128
+ // @ts-expect-error -- classes are from same type -> they are comparable
129
+ return a.compare(b)
130
+ }
131
+ return a.constructor.name.localeCompare(b.constructor.name)
132
+ }
133
+ }
@@ -0,0 +1,50 @@
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 { Component } from './component'
21
+ import { ToolRepository } from './tool'
22
+ import { OrganizationalEntity } from './organizationalEntity'
23
+ import { OrganizationalContactRepository } from './organizationalContact'
24
+
25
+ interface OptionalProperties {
26
+ timestamp?: Metadata['timestamp']
27
+ tools?: Metadata['tools']
28
+ authors?: Metadata['authors']
29
+ component?: Metadata['component']
30
+ manufacture?: Metadata['manufacture']
31
+ supplier?: Metadata['supplier']
32
+ }
33
+
34
+ export class Metadata {
35
+ timestamp?: Date
36
+ tools: ToolRepository
37
+ authors: OrganizationalContactRepository
38
+ component?: Component
39
+ manufacture?: OrganizationalEntity
40
+ supplier?: OrganizationalEntity
41
+
42
+ constructor (op: OptionalProperties = {}) {
43
+ this.timestamp = op.timestamp
44
+ this.tools = op.tools ?? new ToolRepository()
45
+ this.authors = op.authors ?? new OrganizationalContactRepository()
46
+ this.component = op.component
47
+ this.manufacture = op.manufacture
48
+ this.supplier = op.supplier
49
+ }
50
+ }
@@ -0,0 +1,49 @@
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
+ interface OptionalProperties {
21
+ name?: OrganizationalContact['name']
22
+ email?: OrganizationalContact['email']
23
+ phone?: OrganizationalContact['phone']
24
+ }
25
+
26
+ export class OrganizationalContact {
27
+ name?: string
28
+ email?: string
29
+ phone?: string
30
+
31
+ constructor (op: OptionalProperties = {}) {
32
+ this.name = op.name
33
+ this.email = op.email
34
+ this.phone = op.phone
35
+ }
36
+
37
+ compare (other: OrganizationalContact): number {
38
+ /* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
39
+ return (this.name ?? '').localeCompare(other.name ?? '') ||
40
+ (this.email ?? '').localeCompare(other.email ?? '') ||
41
+ (this.phone ?? '').localeCompare(other.phone ?? '')
42
+ }
43
+ }
44
+
45
+ export class OrganizationalContactRepository extends Set<OrganizationalContact> {
46
+ static compareItems (a: OrganizationalContact, b: OrganizationalContact): number {
47
+ return a.compare(b)
48
+ }
49
+ }
@@ -0,0 +1,38 @@
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 { OrganizationalContactRepository } from './organizationalContact'
21
+
22
+ interface OptionalProperties {
23
+ name?: OrganizationalEntity['name']
24
+ url?: OrganizationalEntity['url']
25
+ contact?: OrganizationalEntity['contact']
26
+ }
27
+
28
+ export class OrganizationalEntity {
29
+ name?: string
30
+ url: Set<URL | string>
31
+ contact: OrganizationalContactRepository
32
+
33
+ constructor (op: OptionalProperties = {}) {
34
+ this.name = op.name
35
+ this.url = op.url ?? new Set()
36
+ this.contact = op.contact ?? new OrganizationalContactRepository()
37
+ }
38
+ }
@@ -0,0 +1,71 @@
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 { isNonNegativeInteger, NonNegativeInteger } from '../types'
21
+ import { Attachment } from './attachment'
22
+
23
+ interface OptionalProperties {
24
+ version?: SWID['version']
25
+ patch?: SWID['patch']
26
+ text?: SWID['text']
27
+ url?: SWID['url']
28
+ tagVersion?: SWID['tagVersion']
29
+ }
30
+
31
+ /**
32
+ * @see {@link https://csrc.nist.gov/projects/Software-Identification-SWID}
33
+ */
34
+ export class SWID {
35
+ tagId: string
36
+ name: string
37
+ version?: string
38
+ patch?: boolean
39
+ text?: Attachment
40
+ url?: URL | string
41
+
42
+ /** @see tagVersion */
43
+ #tagVersion?: NonNegativeInteger
44
+
45
+ /**
46
+ * @throws {TypeError} if {@see op.tagVersion} is neither {@see NonNegativeInteger} nor {@see undefined}
47
+ */
48
+ constructor (tagId: string, name: string, op: OptionalProperties = {}) {
49
+ this.tagId = tagId
50
+ this.name = name
51
+ this.version = op.version
52
+ this.patch = op.patch
53
+ this.text = op.text
54
+ this.url = op.url
55
+ this.tagVersion = op.tagVersion
56
+ }
57
+
58
+ get tagVersion (): NonNegativeInteger | undefined {
59
+ return this.#tagVersion
60
+ }
61
+
62
+ /**
63
+ * @throws {TypeError} if value is neither {@see NonNegativeInteger} nor {@see undefined}
64
+ */
65
+ set tagVersion (value: NonNegativeInteger | undefined) {
66
+ if (value !== undefined && !isNonNegativeInteger(value)) {
67
+ throw new TypeError('Not NonNegativeInteger nor undefined')
68
+ }
69
+ this.#tagVersion = value
70
+ }
71
+ }
@@ -0,0 +1,58 @@
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 { HashRepository } from './hash'
21
+ import { ExternalReferenceRepository } from './externalReference'
22
+
23
+ interface OptionalProperties {
24
+ vendor?: Tool['vendor']
25
+ name?: Tool['name']
26
+ version?: Tool['version']
27
+ hashes?: Tool['hashes']
28
+ externalReferences?: Tool['externalReferences']
29
+ }
30
+
31
+ export class Tool {
32
+ vendor?: string
33
+ name?: string
34
+ version?: string
35
+ hashes: HashRepository
36
+ externalReferences: ExternalReferenceRepository
37
+
38
+ constructor (op: OptionalProperties = {}) {
39
+ this.vendor = op.vendor
40
+ this.name = op.name
41
+ this.version = op.version
42
+ this.hashes = op.hashes ?? new HashRepository()
43
+ this.externalReferences = op.externalReferences ?? new ExternalReferenceRepository()
44
+ }
45
+
46
+ compare (other: Tool): number {
47
+ /* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
48
+ return (this.vendor ?? '').localeCompare(other.vendor ?? '') ||
49
+ (this.name ?? '').localeCompare(other.name ?? '') ||
50
+ (this.version ?? '').localeCompare(other.version ?? '')
51
+ }
52
+ }
53
+
54
+ export class ToolRepository extends Set<Tool> {
55
+ static compareItems (a: Tool, b: Tool): number {
56
+ return a.compare(b)
57
+ }
58
+ }
@@ -0,0 +1,59 @@
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 path from 'path'
21
+
22
+ import { Version } from './spec'
23
+
24
+ /** @internal */
25
+ export const ROOT = path.resolve(__dirname, '..', 'res')
26
+
27
+ /** @internal */
28
+ export const FILES = Object.freeze({
29
+ CDX: Object.freeze({
30
+ XML_SCHEMA: Object.freeze(Object.fromEntries([
31
+ [Version.v1dot0, path.resolve(ROOT, 'bom-1.0.SNAPSHOT.xsd')],
32
+ [Version.v1dot1, path.resolve(ROOT, 'bom-1.1.SNAPSHOT.xsd')],
33
+ [Version.v1dot2, path.resolve(ROOT, 'bom-1.2.SNAPSHOT.xsd')],
34
+ [Version.v1dot3, path.resolve(ROOT, 'bom-1.3.SNAPSHOT.xsd')],
35
+ [Version.v1dot4, path.resolve(ROOT, 'bom-1.4.SNAPSHOT.xsd')]
36
+ ]) as { [key in Version]?: string }),
37
+ JSON_SCHEMA: Object.freeze(Object.fromEntries([
38
+ // v1.0 is not defined in JSON
39
+ // v1.1 is not defined in JSON
40
+ [Version.v1dot2, path.resolve(ROOT, 'bom-1.2.SNAPSHOT.schema.json')],
41
+ [Version.v1dot3, path.resolve(ROOT, 'bom-1.3.SNAPSHOT.schema.json')],
42
+ [Version.v1dot4, path.resolve(ROOT, 'bom-1.4.SNAPSHOT.schema.json')]
43
+ ]) as { [key in Version]?: string }),
44
+ JSON_STRICT_SCHEMA: Object.freeze(Object.fromEntries([
45
+ // v1.0 is not defined in JSON
46
+ // v1.1 is not defined in JSON
47
+ [Version.v1dot2, path.resolve(ROOT, 'bom-1.2-strict.SNAPSHOT.schema.json')],
48
+ [Version.v1dot3, path.resolve(ROOT, 'bom-1.3-strict.SNAPSHOT.schema.json')]
49
+ // v1.4 is already strict - no special file here
50
+ ]) as { [key in Version]?: string })
51
+ }),
52
+ SPDX: Object.freeze({
53
+ XML_SCHEMA: path.resolve(ROOT, 'spdx.SNAPSHOT.xsd'),
54
+ JSON_SCHEMA: path.resolve(ROOT, 'spdx.SNAPSHOT.schema.json')
55
+ }),
56
+ JSF: Object.freeze({
57
+ JSON_SCHEMA: path.resolve(ROOT, 'jsf-0.82.SNAPSHOT.schema.json')
58
+ })
59
+ })
@@ -0,0 +1,23 @@
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 './index'
21
+
22
+ export * from './xmlSerializer.node'
23
+ // export * from './xmlDeserializer.node' // TODO
@@ -0,0 +1,23 @@
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 './index'
21
+
22
+ export * from './xmlSerializer.web'
23
+ // export * from './xmlDeserializer.web' // TODO
@@ -0,0 +1,52 @@
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 { Bom, BomRef } from '../models'
21
+ import { BomRefDiscriminator } from './bomRefDiscriminator'
22
+ import { NormalizerOptions, Serializer, SerializerOptions } from './types'
23
+
24
+ export abstract class BaseSerializer<NormalizedBom> implements Serializer {
25
+ serialize (bom: Bom, options?: SerializerOptions & NormalizerOptions): string {
26
+ const bomRefDiscriminator = new BomRefDiscriminator(this.#getAllBomRefs(bom))
27
+ try {
28
+ // This IS NOT the place to put meaning to the BomRef values. This would be out of scope.
29
+ // This IS the place to make BomRef values (temporary) unique in their own document scope.
30
+ bomRefDiscriminator.discriminate()
31
+
32
+ const normalized = this._normalize(bom, options)
33
+ return this._serialize(normalized, options)
34
+ } finally {
35
+ bomRefDiscriminator.reset()
36
+ }
37
+ }
38
+
39
+ #getAllBomRefs (bom: Bom): Iterable<BomRef> {
40
+ const bomRefs = new Set<BomRef>()
41
+ if (bom.metadata.component !== undefined) {
42
+ bomRefs.add(bom.metadata.component.bomRef)
43
+ }
44
+ for (const { bomRef } of bom.components) {
45
+ bomRefs.add(bomRef)
46
+ }
47
+ return bomRefs.values()
48
+ }
49
+
50
+ protected abstract _normalize (bom: Bom, options?: NormalizerOptions): NormalizedBom
51
+ protected abstract _serialize (normalizedBom: NormalizedBom, options?: SerializerOptions): string
52
+ }