@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,187 @@
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 * as Enums from '../../enums'
21
+ import { HashContent } from '../../models'
22
+ import { SpdxId } from '../../spdx'
23
+ import { CPE, Integer, UrnUuid } from '../../types'
24
+
25
+ // eslint-disable-next-line @typescript-eslint/no-namespace
26
+ export namespace JsonSchema {
27
+
28
+ /**
29
+ * @see isIriReference
30
+ */
31
+ export type IriReference = string
32
+ /**
33
+ * Test whether format is JSON::iri-reference - best-effort.
34
+ *
35
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc3987}
36
+ */
37
+ export function isIriReference (value: IriReference | any): value is IriReference {
38
+ return typeof value === 'string' &&
39
+ value.length > 0
40
+ // TODO add more validation according to spec
41
+ }
42
+
43
+ /**
44
+ * @see isIdnEmail
45
+ */
46
+ export type IdnEmail = string
47
+ /**
48
+ * Test whether format is JSON::idn-email - best-effort.
49
+ *
50
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc6531}
51
+ */
52
+ export function isIdnEmail (value: IdnEmail | any): value is IdnEmail {
53
+ return typeof value === 'string' &&
54
+ value.length > 0
55
+ // TODO add more validation according to spec
56
+ }
57
+
58
+ export type DateTime = string
59
+
60
+ }
61
+
62
+ // eslint-disable-next-line @typescript-eslint/no-namespace
63
+ export namespace Normalized {
64
+
65
+ export type RefType = string
66
+
67
+ export interface Bom {
68
+ $schema?: string
69
+ bomFormat: 'CycloneDX'
70
+ specVersion: string
71
+ version: Integer
72
+ serialNumber?: UrnUuid
73
+ metadata?: Metadata
74
+ components?: Component[]
75
+ externalReferences?: ExternalReference[]
76
+ dependencies?: Dependency[]
77
+ }
78
+
79
+ export interface Metadata {
80
+ timestamp?: JsonSchema.DateTime
81
+ tools?: Tool[]
82
+ authors?: OrganizationalContact[]
83
+ component?: Component
84
+ manufacture?: OrganizationalEntity
85
+ supplier?: OrganizationalEntity
86
+ licenses?: License[]
87
+ }
88
+
89
+ export interface Tool {
90
+ vendor?: string
91
+ name?: string
92
+ version?: string
93
+ hashes?: Hash[]
94
+ externalReferences?: ExternalReference[]
95
+ }
96
+
97
+ export interface OrganizationalContact {
98
+ name?: string
99
+ email?: JsonSchema.IdnEmail
100
+ phone?: string
101
+ }
102
+
103
+ export interface OrganizationalEntity {
104
+ name?: string
105
+ url?: JsonSchema.IriReference[]
106
+ contact?: OrganizationalContact[]
107
+ }
108
+
109
+ export interface Hash {
110
+ alg: Enums.HashAlgorithm
111
+ content: HashContent
112
+ }
113
+
114
+ export interface Component {
115
+ type: Enums.ComponentType
116
+ name: string
117
+ 'mime-type'?: string
118
+ 'bom-ref'?: RefType
119
+ supplier?: OrganizationalEntity
120
+ author?: string
121
+ publisher?: string
122
+ group?: string
123
+ version?: string
124
+ description?: string
125
+ scope?: Enums.ComponentScope
126
+ hashes?: Hash[]
127
+ licenses?: License[]
128
+ copyright?: string
129
+ cpe?: CPE
130
+ purl?: string
131
+ swid?: SWID
132
+ modified?: boolean
133
+ externalReferences?: ExternalReference[]
134
+ components?: Component[]
135
+ }
136
+
137
+ export interface NamedLicense {
138
+ license: {
139
+ name: string
140
+ text?: Attachment
141
+ url?: string
142
+ }
143
+ }
144
+
145
+ export interface SpdxLicense {
146
+ license: {
147
+ /** @see {@link http://cyclonedx.org/schema/spdx} */
148
+ id: SpdxId
149
+ text?: Attachment
150
+ url?: string
151
+ }
152
+ }
153
+
154
+ export interface LicenseExpression {
155
+ expression: string
156
+ }
157
+
158
+ export type License = NamedLicense | SpdxLicense | LicenseExpression
159
+
160
+ export interface SWID {
161
+ tagId: string
162
+ name: string
163
+ version?: string
164
+ tagVersion?: Integer
165
+ patch?: boolean
166
+ text?: Attachment
167
+ url?: JsonSchema.IriReference
168
+ }
169
+
170
+ export interface ExternalReference {
171
+ url: string
172
+ type: Enums.ExternalReferenceType
173
+ comment?: string
174
+ }
175
+
176
+ export interface Attachment {
177
+ content?: string
178
+ contentType?: string
179
+ encoding?: Enums.AttachmentEncoding
180
+ }
181
+
182
+ export interface Dependency {
183
+ ref: RefType
184
+ dependsOn?: RefType[]
185
+ }
186
+
187
+ }
@@ -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 { Bom } from '../models'
21
+ import { Format, UnsupportedFormatError } from '../spec'
22
+ import { NormalizerOptions, SerializerOptions } from './types'
23
+ import { BaseSerializer } from './baseSerializer'
24
+ import { Factory as NormalizerFactory } from './json/normalize'
25
+ import { Normalized } from './json/types'
26
+
27
+ /**
28
+ * Multi purpose Json serializer.
29
+ */
30
+ export class JsonSerializer extends BaseSerializer<Normalized.Bom> {
31
+ readonly #normalizerFactory: NormalizerFactory
32
+
33
+ /**
34
+ * @throws {UnsupportedFormatError} if {@see normalizerFactory.spec} does not support {@see Format.JSON}.
35
+ */
36
+ constructor (normalizerFactory: NormalizerFactory) {
37
+ if (!normalizerFactory.spec.supportsFormat(Format.JSON)) {
38
+ throw new UnsupportedFormatError('Spec does not support JSON format.')
39
+ }
40
+
41
+ super()
42
+ this.#normalizerFactory = normalizerFactory
43
+ }
44
+
45
+ protected _normalize (
46
+ bom: Bom,
47
+ options: NormalizerOptions = {}
48
+ ): Normalized.Bom {
49
+ return this.#normalizerFactory.makeForBom()
50
+ .normalize(bom, options)
51
+ }
52
+
53
+ protected _serialize (
54
+ bom: Normalized.Bom,
55
+ { space }: SerializerOptions = {}
56
+ ): string {
57
+ return JSON.stringify(bom, null, space)
58
+ }
59
+ }
@@ -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 { Bom } from '../models'
21
+
22
+ export interface NormalizerOptions {
23
+ /**
24
+ * Whether to sort lists in normalization results. Sorted lists make the output reproducible.
25
+ */
26
+ sortLists?: boolean
27
+ }
28
+
29
+ export interface SerializerOptions {
30
+ /**
31
+ * Add indention in the serialization result. Indention increases readability for humans.
32
+ */
33
+ space?: string | number
34
+ }
35
+
36
+ export interface Serializer {
37
+ serialize: (bom: Bom, options?: SerializerOptions & NormalizerOptions) => string
38
+ }
@@ -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 * as Types from './types'
21
+
22
+ export * as Normalize from './normalize'
23
+ // export * as Denormalize from './denormalize' // TODO