@bifold/oca 1.0.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/build/__tests__/remote.test.d.ts +1 -0
- package/build/__tests__/remote.test.js +162 -0
- package/build/constants.d.ts +4 -0
- package/build/constants.js +7 -0
- package/build/formatters/credential/CredentialFormatter.d.ts +8 -0
- package/build/formatters/credential/CredentialFormatter.js +32 -0
- package/build/formatters/credential/DisplayAttribute.d.ts +11 -0
- package/build/formatters/credential/DisplayAttribute.js +18 -0
- package/build/formatters/credential/LocalizedCredential.d.ts +13 -0
- package/build/formatters/credential/LocalizedCredential.js +57 -0
- package/build/formatters/credential/index.d.ts +4 -0
- package/build/formatters/credential/index.js +12 -0
- package/build/formatters/index.d.ts +4 -0
- package/build/formatters/index.js +12 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +34 -0
- package/build/interfaces/data/base/BaseOverlayData.interface.d.ts +5 -0
- package/build/interfaces/data/base/BaseOverlayData.interface.js +2 -0
- package/build/interfaces/data/branding/BrandingOverlayData.interface.d.ts +12 -0
- package/build/interfaces/data/branding/BrandingOverlayData.interface.js +2 -0
- package/build/interfaces/data/branding/LegacyBrandingOverlayData.interface.d.ts +15 -0
- package/build/interfaces/data/branding/LegacyBrandingOverlayData.interface.js +2 -0
- package/build/interfaces/data/bundle/OverlayBundleData.interface.d.ts +6 -0
- package/build/interfaces/data/bundle/OverlayBundleData.interface.js +2 -0
- package/build/interfaces/data/capture-base/CaptureBaseData.interface.d.ts +7 -0
- package/build/interfaces/data/capture-base/CaptureBaseData.interface.js +2 -0
- package/build/interfaces/data/index.d.ts +12 -0
- package/build/interfaces/data/index.js +2 -0
- package/build/interfaces/data/semantic/CharacterEncodingOverlayData.interface.d.ts +6 -0
- package/build/interfaces/data/semantic/CharacterEncodingOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/FormatOverlayData.interface.d.ts +4 -0
- package/build/interfaces/data/semantic/FormatOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/InformationOverlayData.interface.d.ts +5 -0
- package/build/interfaces/data/semantic/InformationOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/LabelOverlayData.interface.d.ts +7 -0
- package/build/interfaces/data/semantic/LabelOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/MetaOverlayData.interface.d.ts +12 -0
- package/build/interfaces/data/semantic/MetaOverlayData.interface.js +2 -0
- package/build/interfaces/data/semantic/StandardOverlayData.interface.d.ts +5 -0
- package/build/interfaces/data/semantic/StandardOverlayData.interface.js +2 -0
- package/build/interfaces/index.d.ts +2 -0
- package/build/interfaces/index.js +18 -0
- package/build/interfaces/overlay/OverlayBundleAttribute.interface.d.ts +9 -0
- package/build/interfaces/overlay/OverlayBundleAttribute.interface.js +2 -0
- package/build/interfaces/overlay/OverlayBundleMetadata.interface.d.ts +9 -0
- package/build/interfaces/overlay/OverlayBundleMetadata.interface.js +2 -0
- package/build/interfaces/overlay/index.d.ts +3 -0
- package/build/interfaces/overlay/index.js +2 -0
- package/build/legacy/index.d.ts +3 -0
- package/build/legacy/index.js +19 -0
- package/build/legacy/resolver/oca.d.ts +99 -0
- package/build/legacy/resolver/oca.js +239 -0
- package/build/legacy/resolver/record.d.ts +50 -0
- package/build/legacy/resolver/record.js +37 -0
- package/build/legacy/resolver/remote-oca.d.ts +186 -0
- package/build/legacy/resolver/remote-oca.js +536 -0
- package/build/types/OverlayTypeMap.d.ts +5 -0
- package/build/types/OverlayTypeMap.js +25 -0
- package/build/types/TypeEnums.d.ts +19 -0
- package/build/types/TypeEnums.js +24 -0
- package/build/types/base/BaseOverlay.d.ts +8 -0
- package/build/types/base/BaseOverlay.js +28 -0
- package/build/types/branding/BrandingOverlay.d.ts +15 -0
- package/build/types/branding/BrandingOverlay.js +68 -0
- package/build/types/branding/LegacyBrandingOverlay.d.ts +18 -0
- package/build/types/branding/LegacyBrandingOverlay.js +51 -0
- package/build/types/bundle/OverlayBundle.d.ts +20 -0
- package/build/types/bundle/OverlayBundle.js +167 -0
- package/build/types/capture-base/CaptureBase.d.ts +10 -0
- package/build/types/capture-base/CaptureBase.js +30 -0
- package/build/types/index.d.ts +14 -0
- package/build/types/index.js +33 -0
- package/build/types/semantic/CharacterEncodingOverlay.d.ts +9 -0
- package/build/types/semantic/CharacterEncodingOverlay.js +43 -0
- package/build/types/semantic/FormatOverlay.d.ts +7 -0
- package/build/types/semantic/FormatOverlay.js +30 -0
- package/build/types/semantic/InformationOverlay.d.ts +8 -0
- package/build/types/semantic/InformationOverlay.js +31 -0
- package/build/types/semantic/LabelOverlay.d.ts +10 -0
- package/build/types/semantic/LabelOverlay.js +41 -0
- package/build/types/semantic/MetaOverlay.d.ts +15 -0
- package/build/types/semantic/MetaOverlay.js +54 -0
- package/build/types/semantic/StandardOverlay.d.ts +8 -0
- package/build/types/semantic/StandardOverlay.js +38 -0
- package/build/utils/color/generateColor.d.ts +2 -0
- package/build/utils/color/generateColor.js +11 -0
- package/build/utils/color/hashCode.d.ts +8 -0
- package/build/utils/color/hashCode.js +12 -0
- package/build/utils/color/hashToRGBA.d.ts +8 -0
- package/build/utils/color/hashToRGBA.js +23 -0
- package/build/utils/color/index.d.ts +5 -0
- package/build/utils/color/index.js +15 -0
- package/build/utils/color/luminanceForHexColor.d.ts +7 -0
- package/build/utils/color/luminanceForHexColor.js +18 -0
- package/build/utils/color/mulberry32.d.ts +9 -0
- package/build/utils/color/mulberry32.js +16 -0
- package/build/utils/color/textColorForBackground.d.ts +1 -0
- package/build/utils/color/textColorForBackground.js +24 -0
- package/build/utils/credential-definition.d.ts +1 -0
- package/build/utils/credential-definition.js +21 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +17 -0
- package/build/utils/logger.d.ts +5 -0
- package/build/utils/logger.js +17 -0
- package/build/utils/schema.d.ts +4 -0
- package/build/utils/schema.js +19 -0
- package/package.json +53 -0
- package/src/__tests__/__snapshots__/remote.test.ts.snap +293 -0
- package/src/__tests__/fixtures/bundle.json +131 -0
- package/src/__tests__/fixtures/oca.json +4 -0
- package/src/__tests__/fixtures/ocabundles.json +142 -0
- package/src/__tests__/remote.test.ts +180 -0
- package/src/constants.ts +7 -0
- package/src/formatters/credential/CredentialFormatter.ts +20 -0
- package/src/formatters/credential/DisplayAttribute.ts +29 -0
- package/src/formatters/credential/LocalizedCredential.ts +53 -0
- package/src/formatters/credential/index.ts +5 -0
- package/src/formatters/index.ts +5 -0
- package/src/index.ts +5 -0
- package/src/interfaces/data/base/BaseOverlayData.interface.ts +5 -0
- package/src/interfaces/data/branding/BrandingOverlayData.interface.ts +13 -0
- package/src/interfaces/data/branding/LegacyBrandingOverlayData.interface.ts +16 -0
- package/src/interfaces/data/bundle/OverlayBundleData.interface.ts +7 -0
- package/src/interfaces/data/capture-base/CaptureBaseData.interface.ts +7 -0
- package/src/interfaces/data/index.ts +25 -0
- package/src/interfaces/data/semantic/CharacterEncodingOverlayData.interface.ts +8 -0
- package/src/interfaces/data/semantic/FormatOverlayData.interface.ts +5 -0
- package/src/interfaces/data/semantic/InformationOverlayData.interface.ts +6 -0
- package/src/interfaces/data/semantic/LabelOverlayData.interface.ts +8 -0
- package/src/interfaces/data/semantic/MetaOverlayData.interface.ts +13 -0
- package/src/interfaces/data/semantic/StandardOverlayData.interface.ts +7 -0
- package/src/interfaces/index.ts +2 -0
- package/src/interfaces/overlay/OverlayBundleAttribute.interface.ts +9 -0
- package/src/interfaces/overlay/OverlayBundleMetadata.interface.ts +9 -0
- package/src/interfaces/overlay/index.ts +4 -0
- package/src/legacy/index.ts +3 -0
- package/src/legacy/resolver/oca.ts +377 -0
- package/src/legacy/resolver/record.ts +81 -0
- package/src/legacy/resolver/remote-oca.ts +661 -0
- package/src/types/OverlayTypeMap.ts +25 -0
- package/src/types/TypeEnums.ts +20 -0
- package/src/types/base/BaseOverlay.ts +18 -0
- package/src/types/branding/BrandingOverlay.ts +61 -0
- package/src/types/branding/LegacyBrandingOverlay.ts +47 -0
- package/src/types/bundle/OverlayBundle.ts +203 -0
- package/src/types/capture-base/CaptureBase.ts +22 -0
- package/src/types/index.ts +30 -0
- package/src/types/semantic/CharacterEncodingOverlay.ts +30 -0
- package/src/types/semantic/FormatOverlay.ts +15 -0
- package/src/types/semantic/InformationOverlay.ts +18 -0
- package/src/types/semantic/LabelOverlay.ts +30 -0
- package/src/types/semantic/MetaOverlay.ts +48 -0
- package/src/types/semantic/StandardOverlay.ts +24 -0
- package/src/utils/color/generateColor.ts +8 -0
- package/src/utils/color/hashCode.ts +11 -0
- package/src/utils/color/hashToRGBA.ts +22 -0
- package/src/utils/color/index.ts +7 -0
- package/src/utils/color/luminanceForHexColor.ts +19 -0
- package/src/utils/color/mulberry32.ts +15 -0
- package/src/utils/color/textColorForBackground.ts +18 -0
- package/src/utils/credential-definition.ts +19 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/logger.ts +14 -0
- package/src/utils/schema.ts +16 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IBaseOverlayData } from '../../interfaces/data'
|
|
2
|
+
|
|
3
|
+
export default class BaseOverlay {
|
|
4
|
+
#capture_base: string
|
|
5
|
+
|
|
6
|
+
type: string
|
|
7
|
+
digest: string
|
|
8
|
+
|
|
9
|
+
constructor(overlay: IBaseOverlayData) {
|
|
10
|
+
this.type = overlay.type
|
|
11
|
+
this.#capture_base = overlay.capture_base
|
|
12
|
+
this.digest = overlay.digest ?? ''
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get captureBase(): string {
|
|
16
|
+
return this.#capture_base
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IBrandingOverlayData } from '../../interfaces/data'
|
|
2
|
+
import { generateColor } from '../../utils/color'
|
|
3
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
4
|
+
|
|
5
|
+
export default class BrandingOverlay extends BaseOverlay {
|
|
6
|
+
#background_image?: string
|
|
7
|
+
#background_image_slice?: string
|
|
8
|
+
#primary_background_color: string
|
|
9
|
+
#secondary_background_color?: string
|
|
10
|
+
#primary_attribute?: string
|
|
11
|
+
#secondary_attribute?: string
|
|
12
|
+
#issued_date_attribute?: string
|
|
13
|
+
#expiry_date_attribute?: string
|
|
14
|
+
|
|
15
|
+
logo?: string
|
|
16
|
+
|
|
17
|
+
constructor(credentialDefinitionId: string, overlay: IBrandingOverlayData) {
|
|
18
|
+
super(overlay)
|
|
19
|
+
this.logo = overlay.logo
|
|
20
|
+
this.#background_image = overlay.background_image
|
|
21
|
+
this.#background_image_slice = overlay.background_image_slice
|
|
22
|
+
this.#primary_background_color = overlay.primary_background_color ?? generateColor(credentialDefinitionId)
|
|
23
|
+
this.#secondary_background_color = overlay.secondary_background_color
|
|
24
|
+
this.#primary_attribute = overlay.primary_attribute
|
|
25
|
+
this.#secondary_attribute = overlay.secondary_attribute
|
|
26
|
+
this.#issued_date_attribute = overlay.issued_date_attribute
|
|
27
|
+
this.#expiry_date_attribute = overlay.expiry_date_attribute
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get backgroundImage(): string | undefined {
|
|
31
|
+
return this.#background_image
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get backgroundImageSlice(): string | undefined {
|
|
35
|
+
return this.#background_image_slice
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get primaryBackgroundColor(): string | undefined {
|
|
39
|
+
return this.#primary_background_color
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get secondaryBackgroundColor(): string | undefined {
|
|
43
|
+
return this.#secondary_background_color
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get primaryAttribute(): string | undefined {
|
|
47
|
+
return this.#primary_attribute
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get secondaryAttribute(): string | undefined {
|
|
51
|
+
return this.#secondary_attribute
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get issuedDateAttribute(): string | undefined {
|
|
55
|
+
return this.#issued_date_attribute
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get expiryDateAttribute(): string | undefined {
|
|
59
|
+
return this.#expiry_date_attribute
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ILegacyBrandingOverlayData } from '../../interfaces/data'
|
|
2
|
+
import { generateColor } from '../../utils/color'
|
|
3
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
4
|
+
|
|
5
|
+
export default class LegacyBrandingOverlay extends BaseOverlay {
|
|
6
|
+
#background_color: string
|
|
7
|
+
#image_source?: string
|
|
8
|
+
header?: {
|
|
9
|
+
color?: string
|
|
10
|
+
backgroundColor?: string
|
|
11
|
+
imageSource?: string
|
|
12
|
+
hideIssuer?: boolean
|
|
13
|
+
}
|
|
14
|
+
footer?: {
|
|
15
|
+
color?: string
|
|
16
|
+
backgroundColor?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor(credentialDefinitionId: string, overlay: ILegacyBrandingOverlayData) {
|
|
20
|
+
super(overlay)
|
|
21
|
+
|
|
22
|
+
this.#background_color = overlay.background_color ?? generateColor(credentialDefinitionId)
|
|
23
|
+
this.#image_source = overlay.image_source
|
|
24
|
+
if (overlay.header) {
|
|
25
|
+
this.header = {
|
|
26
|
+
color: overlay.header?.color,
|
|
27
|
+
backgroundColor: overlay.header?.background_color,
|
|
28
|
+
imageSource: overlay.header?.image_source,
|
|
29
|
+
hideIssuer: overlay.header?.hide_issuer,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (overlay.footer) {
|
|
33
|
+
this.footer = {
|
|
34
|
+
color: overlay.footer?.color,
|
|
35
|
+
backgroundColor: overlay.footer?.background_color,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public get backgroundColor(): string {
|
|
41
|
+
return this.#background_color
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public get imageSource(): string | undefined {
|
|
45
|
+
return this.#image_source
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { IBrandingOverlayData, ILegacyBrandingOverlayData, IOverlayBundleData } from '../../interfaces/data'
|
|
2
|
+
import { IOverlayBundleAttribute, IOverlayBundleMetadata } from '../../interfaces/overlay'
|
|
3
|
+
import OverlayTypeMap from '../OverlayTypeMap'
|
|
4
|
+
import { OverlayType } from '../TypeEnums'
|
|
5
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
6
|
+
import BrandingOverlay from '../branding/BrandingOverlay'
|
|
7
|
+
import LegacyBrandingOverlay from '../branding/LegacyBrandingOverlay'
|
|
8
|
+
import CaptureBase from '../capture-base/CaptureBase'
|
|
9
|
+
import CharacterEncodingOverlay from '../semantic/CharacterEncodingOverlay'
|
|
10
|
+
import FormatOverlay from '../semantic/FormatOverlay'
|
|
11
|
+
import InformationOverlay from '../semantic/InformationOverlay'
|
|
12
|
+
import LabelOverlay from '../semantic/LabelOverlay'
|
|
13
|
+
import MetaOverlay from '../semantic/MetaOverlay'
|
|
14
|
+
import StandardOverlay from '../semantic/StandardOverlay'
|
|
15
|
+
|
|
16
|
+
class OverlayBundle {
|
|
17
|
+
credentialDefinitionId!: string
|
|
18
|
+
captureBase!: CaptureBase
|
|
19
|
+
overlays!: BaseOverlay[]
|
|
20
|
+
languages!: string[]
|
|
21
|
+
metadata!: IOverlayBundleMetadata
|
|
22
|
+
attributes!: IOverlayBundleAttribute[]
|
|
23
|
+
flaggedAttributes!: IOverlayBundleAttribute[]
|
|
24
|
+
|
|
25
|
+
constructor(credentialDefinitionId: string, bundle: IOverlayBundleData) {
|
|
26
|
+
this.credentialDefinitionId = credentialDefinitionId
|
|
27
|
+
this.captureBase = new CaptureBase(bundle.capture_base)
|
|
28
|
+
this.overlays = bundle.overlays
|
|
29
|
+
.filter((overlay) => !overlay.type.startsWith('aries/overlays/branding/'))
|
|
30
|
+
.map((overlay) => {
|
|
31
|
+
const OverlayClass = (OverlayTypeMap.get(overlay.type) || BaseOverlay) as typeof BaseOverlay
|
|
32
|
+
return new OverlayClass(overlay)
|
|
33
|
+
})
|
|
34
|
+
this.overlays.push(
|
|
35
|
+
...bundle.overlays
|
|
36
|
+
.filter((overlay) => overlay.type === OverlayType.Branding01)
|
|
37
|
+
.map((overlay) => {
|
|
38
|
+
const OverlayClass = (OverlayTypeMap.get(overlay.type) ||
|
|
39
|
+
LegacyBrandingOverlay) as typeof LegacyBrandingOverlay
|
|
40
|
+
return new OverlayClass(credentialDefinitionId, overlay as ILegacyBrandingOverlayData)
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
this.overlays.push(
|
|
44
|
+
...bundle.overlays
|
|
45
|
+
.filter((overlay) => overlay.type === OverlayType.Branding10 || overlay.type === OverlayType.Branding11)
|
|
46
|
+
.map((overlay) => {
|
|
47
|
+
const OverlayClass = (OverlayTypeMap.get(overlay.type) || BrandingOverlay) as typeof BrandingOverlay
|
|
48
|
+
return new OverlayClass(credentialDefinitionId, overlay as IBrandingOverlayData)
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
this.languages = this.#processLanguages()
|
|
52
|
+
this.metadata = this.#processMetadata()
|
|
53
|
+
this.attributes = this.#processOverlayAttributes()
|
|
54
|
+
this.flaggedAttributes = this.attributes.filter((attribute) =>
|
|
55
|
+
this.captureBase.flaggedAttributes.includes(attribute.name)
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get branding(): BrandingOverlay | undefined {
|
|
60
|
+
return (
|
|
61
|
+
this.#overlaysForType<BrandingOverlay>(OverlayType.Branding10)[0] ||
|
|
62
|
+
this.#overlaysForType<BrandingOverlay>(OverlayType.Branding11)[0]
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getAttribute(name: string): IOverlayBundleAttribute | undefined {
|
|
67
|
+
return this.attributes.find((attribute) => attribute.name === name)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getFlaggedAttribute(name: string): IOverlayBundleAttribute | undefined {
|
|
71
|
+
return this.flaggedAttributes.find((attribute) => attribute.name === name)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#processMetadata(): IOverlayBundleMetadata {
|
|
75
|
+
const metadata: IOverlayBundleMetadata & {
|
|
76
|
+
credentialHelpText: Record<string, string>
|
|
77
|
+
credentialSupportUrl: Record<string, string>
|
|
78
|
+
issuer: Record<string, string>
|
|
79
|
+
issuerDescription: Record<string, string>
|
|
80
|
+
issuerUrl: Record<string, string>
|
|
81
|
+
} = {
|
|
82
|
+
name: {},
|
|
83
|
+
description: {},
|
|
84
|
+
credentialHelpText: {},
|
|
85
|
+
credentialSupportUrl: {},
|
|
86
|
+
issuer: {},
|
|
87
|
+
issuerDescription: {},
|
|
88
|
+
issuerUrl: {},
|
|
89
|
+
}
|
|
90
|
+
for (const overlay of this.#overlaysForType<MetaOverlay>(OverlayType.Meta10)) {
|
|
91
|
+
const language = overlay.language ?? 'en'
|
|
92
|
+
const { name, description, credentialHelpText, credentialSupportUrl, issuer, issuerDescription, issuerUrl } =
|
|
93
|
+
overlay
|
|
94
|
+
|
|
95
|
+
if (name) {
|
|
96
|
+
metadata.name[language] = name
|
|
97
|
+
}
|
|
98
|
+
if (description) {
|
|
99
|
+
metadata.description[language] = description
|
|
100
|
+
}
|
|
101
|
+
if (credentialHelpText) {
|
|
102
|
+
metadata.credentialHelpText[language] = credentialHelpText
|
|
103
|
+
}
|
|
104
|
+
if (credentialSupportUrl) {
|
|
105
|
+
metadata.credentialSupportUrl[language] = credentialSupportUrl
|
|
106
|
+
}
|
|
107
|
+
if (issuer) {
|
|
108
|
+
metadata.issuer[language] = issuer
|
|
109
|
+
}
|
|
110
|
+
if (issuerDescription) {
|
|
111
|
+
metadata.issuerDescription[language] = issuerDescription
|
|
112
|
+
}
|
|
113
|
+
if (issuerUrl) {
|
|
114
|
+
metadata.issuerUrl[language] = issuerUrl
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return metadata
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#processLanguages(): string[] {
|
|
121
|
+
const languages: string[] = []
|
|
122
|
+
for (const overlay of this.#overlaysForType<MetaOverlay>(OverlayType.Meta10)) {
|
|
123
|
+
const language = overlay.language
|
|
124
|
+
if (language && !languages.includes(language)) {
|
|
125
|
+
languages.push(language)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
languages.sort((a, b) => a.localeCompare(b))
|
|
129
|
+
return languages
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#processOverlayAttributes(): IOverlayBundleAttribute[] {
|
|
133
|
+
const attributes: IOverlayBundleAttribute[] = []
|
|
134
|
+
const attributeMap = new Map(Object.entries(this.captureBase.attributes))
|
|
135
|
+
for (const [name, type] of attributeMap) {
|
|
136
|
+
attributes.push({
|
|
137
|
+
name,
|
|
138
|
+
type,
|
|
139
|
+
information: this.#processInformationForAttribute(name),
|
|
140
|
+
label: this.#processLabelForAttribute(name),
|
|
141
|
+
characterEncoding: this.#processCharacterEncodingForAttribute(name),
|
|
142
|
+
standard: this.#processStandardForAttribute(name),
|
|
143
|
+
format: this.#processFormatForAttribute(name),
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
return attributes
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#processInformationForAttribute(key: string): Record<string, string> {
|
|
150
|
+
const information: Record<string, string> = {}
|
|
151
|
+
for (const overlay of this.#overlaysForType<InformationOverlay>(OverlayType.Information10)) {
|
|
152
|
+
if (overlay.attributeInformation?.[key]) {
|
|
153
|
+
const language = overlay.language ?? 'en'
|
|
154
|
+
information[language] = overlay.attributeInformation[key]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return information
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#processLabelForAttribute(key: string): Record<string, string> {
|
|
161
|
+
const label: Record<string, string> = {}
|
|
162
|
+
for (const overlay of this.#overlaysForType<LabelOverlay>(OverlayType.Label10)) {
|
|
163
|
+
if (overlay.attributeLabels?.[key]) {
|
|
164
|
+
const language = overlay.language ?? 'en'
|
|
165
|
+
label[language] = overlay.attributeLabels[key]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return label
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#processCharacterEncodingForAttribute(key: string): string | undefined {
|
|
172
|
+
for (const overlay of this.#overlaysForType<CharacterEncodingOverlay>(OverlayType.CharacterEncoding10)) {
|
|
173
|
+
if (overlay.attributeCharacterEncoding?.[key]) {
|
|
174
|
+
return overlay.attributeCharacterEncoding[key]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#processStandardForAttribute(key: string): string | undefined {
|
|
181
|
+
for (const overlay of this.#overlaysForType<StandardOverlay>(OverlayType.Standard10)) {
|
|
182
|
+
if (overlay.attributeStandards?.[key]) {
|
|
183
|
+
return overlay.attributeStandards[key]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#processFormatForAttribute(key: string): string | undefined {
|
|
190
|
+
for (const overlay of this.#overlaysForType<FormatOverlay>(OverlayType.Format10)) {
|
|
191
|
+
if (overlay.attributeFormats?.[key]) {
|
|
192
|
+
return overlay.attributeFormats[key]
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#overlaysForType<T>(type: string): T[] {
|
|
199
|
+
return this.overlays.filter((overlay) => overlay.type === type) as T[]
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export default OverlayBundle
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ICaptureBaseData } from '../../interfaces/data'
|
|
2
|
+
|
|
3
|
+
export default class CaptureBase {
|
|
4
|
+
#flagged_attributes: string[]
|
|
5
|
+
|
|
6
|
+
type: string
|
|
7
|
+
classification: string
|
|
8
|
+
attributes: Record<string, string>
|
|
9
|
+
digest: string
|
|
10
|
+
|
|
11
|
+
constructor(captureBase: ICaptureBaseData) {
|
|
12
|
+
this.type = captureBase.type
|
|
13
|
+
this.classification = captureBase.classification
|
|
14
|
+
this.attributes = captureBase.attributes
|
|
15
|
+
this.#flagged_attributes = captureBase.flagged_attributes
|
|
16
|
+
this.digest = captureBase.digest ?? ''
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get flaggedAttributes(): string[] {
|
|
20
|
+
return this.#flagged_attributes
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import OverlayTypeMap from './OverlayTypeMap'
|
|
2
|
+
import { OverlayType, CaptureBaseAttributeType } from './TypeEnums'
|
|
3
|
+
import BaseOverlay from './base/BaseOverlay'
|
|
4
|
+
import BrandingOverlay from './branding/BrandingOverlay'
|
|
5
|
+
import LegacyBrandingOverlay from './branding/LegacyBrandingOverlay'
|
|
6
|
+
import OverlayBundle from './bundle/OverlayBundle'
|
|
7
|
+
import CaptureBase from './capture-base/CaptureBase'
|
|
8
|
+
import CharacterEncodingOverlay from './semantic/CharacterEncodingOverlay'
|
|
9
|
+
import FormatOverlay from './semantic/FormatOverlay'
|
|
10
|
+
import InformationOverlay from './semantic/InformationOverlay'
|
|
11
|
+
import LabelOverlay from './semantic/LabelOverlay'
|
|
12
|
+
import MetaOverlay from './semantic/MetaOverlay'
|
|
13
|
+
import StandardOverlay from './semantic/StandardOverlay'
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
OverlayType,
|
|
17
|
+
CaptureBaseAttributeType,
|
|
18
|
+
BaseOverlay,
|
|
19
|
+
CaptureBase,
|
|
20
|
+
OverlayBundle,
|
|
21
|
+
BrandingOverlay,
|
|
22
|
+
LegacyBrandingOverlay,
|
|
23
|
+
CharacterEncodingOverlay,
|
|
24
|
+
FormatOverlay,
|
|
25
|
+
InformationOverlay,
|
|
26
|
+
LabelOverlay,
|
|
27
|
+
MetaOverlay,
|
|
28
|
+
StandardOverlay,
|
|
29
|
+
OverlayTypeMap,
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ICharacterEncodingOverlayData } from '../../interfaces/data'
|
|
2
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
3
|
+
|
|
4
|
+
export default class CharacterEncodingOverlay extends BaseOverlay {
|
|
5
|
+
#default_character_encoding?: string
|
|
6
|
+
// DEPRECATED - Use #attribute_character_encoding instead
|
|
7
|
+
#attr_character_encoding?: Record<string, string>
|
|
8
|
+
#attribute_character_encoding?: Record<string, string>
|
|
9
|
+
|
|
10
|
+
constructor(overlay: ICharacterEncodingOverlayData) {
|
|
11
|
+
super(overlay)
|
|
12
|
+
this.#default_character_encoding = overlay.default_character_encoding
|
|
13
|
+
// DEPRECATED - Use #attribute_character_encoding instead
|
|
14
|
+
this.#attr_character_encoding = overlay.attr_character_encoding
|
|
15
|
+
this.#attribute_character_encoding = overlay.attribute_character_encoding
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get defaultCharacterEncoding(): string | undefined {
|
|
19
|
+
return this.#default_character_encoding
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// DEPRECATED - Use attributeCharacterEncoding instead
|
|
23
|
+
get attrCharacterEncoding(): Record<string, string> | undefined {
|
|
24
|
+
return this.#attr_character_encoding
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get attributeCharacterEncoding(): Record<string, string> | undefined {
|
|
28
|
+
return this.#attribute_character_encoding
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IFormatOverlayData } from '../../interfaces/data'
|
|
2
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
3
|
+
|
|
4
|
+
export default class FormatOverlay extends BaseOverlay {
|
|
5
|
+
#attribute_formats: Record<string, string>
|
|
6
|
+
|
|
7
|
+
constructor(overlay: IFormatOverlayData) {
|
|
8
|
+
super(overlay)
|
|
9
|
+
this.#attribute_formats = overlay.attribute_formats
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get attributeFormats(): Record<string, string> {
|
|
13
|
+
return this.#attribute_formats
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IInformationOverlayData } from '../../interfaces/data'
|
|
2
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
3
|
+
|
|
4
|
+
export default class InformationOverlay extends BaseOverlay {
|
|
5
|
+
#attribute_information: Record<string, string>
|
|
6
|
+
|
|
7
|
+
language: string
|
|
8
|
+
|
|
9
|
+
constructor(overlay: IInformationOverlayData) {
|
|
10
|
+
super(overlay)
|
|
11
|
+
this.language = overlay.language
|
|
12
|
+
this.#attribute_information = overlay.attribute_information
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get attributeInformation(): Record<string, string> {
|
|
16
|
+
return this.#attribute_information
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ILabelOverlayData } from '../../interfaces/data'
|
|
2
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
3
|
+
|
|
4
|
+
export default class LabelOverlay extends BaseOverlay {
|
|
5
|
+
#attribute_labels: Record<string, string>
|
|
6
|
+
#attribute_categories?: string[]
|
|
7
|
+
#category_labels?: Record<string, string>
|
|
8
|
+
|
|
9
|
+
language: string
|
|
10
|
+
|
|
11
|
+
constructor(overlay: ILabelOverlayData) {
|
|
12
|
+
super(overlay)
|
|
13
|
+
this.language = overlay.language
|
|
14
|
+
this.#attribute_labels = overlay.attribute_labels
|
|
15
|
+
this.#attribute_categories = overlay.attribute_categories
|
|
16
|
+
this.#category_labels = overlay.category_labels
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get attributeLabels(): Record<string, string> {
|
|
20
|
+
return this.#attribute_labels
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get attributeCategories(): string[] | undefined {
|
|
24
|
+
return this.#attribute_categories
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get categoryLabels(): Record<string, string> | undefined {
|
|
28
|
+
return this.#category_labels
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IMetaOverlayData } from '../../interfaces/data'
|
|
2
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
3
|
+
|
|
4
|
+
export default class MetaOverlay extends BaseOverlay {
|
|
5
|
+
#credential_help_text?: string
|
|
6
|
+
#credential_support_url?: string
|
|
7
|
+
#issuer_description?: string
|
|
8
|
+
#issuer_url?: string
|
|
9
|
+
#watermark?: string
|
|
10
|
+
|
|
11
|
+
language: string
|
|
12
|
+
name?: string
|
|
13
|
+
description?: string
|
|
14
|
+
issuer?: string
|
|
15
|
+
|
|
16
|
+
constructor(overlay: IMetaOverlayData) {
|
|
17
|
+
super(overlay)
|
|
18
|
+
this.language = overlay.language
|
|
19
|
+
this.name = overlay.name
|
|
20
|
+
this.description = overlay.description
|
|
21
|
+
this.#credential_help_text = overlay.credential_help_text
|
|
22
|
+
this.#credential_support_url = overlay.credential_support_url
|
|
23
|
+
this.issuer = overlay.issuer
|
|
24
|
+
this.#issuer_description = overlay.issuer_description
|
|
25
|
+
this.#issuer_url = overlay.issuer_url
|
|
26
|
+
this.#watermark = overlay.watermark
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get credentialHelpText(): string | undefined {
|
|
30
|
+
return this.#credential_help_text
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get credentialSupportUrl(): string | undefined {
|
|
34
|
+
return this.#credential_support_url
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get issuerDescription(): string | undefined {
|
|
38
|
+
return this.#issuer_description
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get issuerUrl(): string | undefined {
|
|
42
|
+
return this.#issuer_url
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get watermark(): string | undefined {
|
|
46
|
+
return this.#watermark
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IStandardOverlayData } from '../../interfaces/data'
|
|
2
|
+
import BaseOverlay from '../base/BaseOverlay'
|
|
3
|
+
|
|
4
|
+
export default class StandardOverlay extends BaseOverlay {
|
|
5
|
+
// DEPRECATED - Use #attribute_standards instead
|
|
6
|
+
#attr_standards?: Record<string, string>
|
|
7
|
+
#attribute_standards: Record<string, string>
|
|
8
|
+
|
|
9
|
+
constructor(overlay: IStandardOverlayData) {
|
|
10
|
+
super(overlay)
|
|
11
|
+
// DEPRECATED - Use #attribute_standards instead
|
|
12
|
+
this.#attr_standards = overlay.attr_standards
|
|
13
|
+
this.#attribute_standards = overlay.attribute_standards
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// DEPRECATED - Use attributeStandards instead
|
|
17
|
+
get attrStandards(): Record<string, string> | undefined {
|
|
18
|
+
return this.#attr_standards
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get attributeStandards(): Record<string, string> {
|
|
22
|
+
return this.#attribute_standards
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a numerical hash based on a given string
|
|
3
|
+
* @see https://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-javascript
|
|
4
|
+
* @param { string } s given string
|
|
5
|
+
* @returns { number } numerical hash value
|
|
6
|
+
*/
|
|
7
|
+
const hashCode = (s: string): number => {
|
|
8
|
+
return s.split('').reduce((hash, char) => char.charCodeAt(0) + ((hash << 5) - hash), 0)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default hashCode
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import mulberry32 from './mulberry32'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts a numerical hash into a hexidecimal color string
|
|
5
|
+
* @see https://helderesteves.com/generating-random-colors-js/#Generating_random_dark_colors
|
|
6
|
+
* @param { number } hash numerical hash value (generated by hashCode function above)
|
|
7
|
+
* @returns { string } hexidecimal string eg. #32d3cc
|
|
8
|
+
*/
|
|
9
|
+
const hashToRGBA = (hash: number): string => {
|
|
10
|
+
let color = '#'
|
|
11
|
+
const colorRangeUpperBound = 256
|
|
12
|
+
|
|
13
|
+
// once for r, g, b
|
|
14
|
+
for (let i = 0; i < 3; i++) {
|
|
15
|
+
// append a pseudorandom two-char hexidecimal value from the lower half of the color spectrum (to limit to darker colors)
|
|
16
|
+
color += ('0' + Math.floor((mulberry32(hash + i) * colorRangeUpperBound) / 2).toString(16)).slice(-2)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return color
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default hashToRGBA
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import generateColor from './generateColor'
|
|
2
|
+
// Remove hashCode and hashToRGBA when deprecated OCA resolver is removed
|
|
3
|
+
import hashCode from './hashCode'
|
|
4
|
+
import hashToRGBA from './hashToRGBA'
|
|
5
|
+
import { textColorForBackground } from './textColorForBackground'
|
|
6
|
+
|
|
7
|
+
export { generateColor, textColorForBackground, hashCode, hashToRGBA }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a hexidecimal color string into a luminance value
|
|
3
|
+
* @param hex color string in hexidecimal format
|
|
4
|
+
* @returns { number | undefined } between 0 and 255
|
|
5
|
+
*/
|
|
6
|
+
const luminanceForHexColor = (hex: string): number | undefined => {
|
|
7
|
+
if (!/^#([A-Fa-f0-9]{6})$/.test(hex)) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const hexAsNumber = Number(`0x${hex.slice(1)}`)
|
|
12
|
+
const [r, g, b] = [(hexAsNumber >> 16) & 255, (hexAsNumber >> 8) & 255, hexAsNumber & 255]
|
|
13
|
+
// Scalars below defined [here](https://en.wikipedia.org/wiki/Relative_luminance)
|
|
14
|
+
const y = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
15
|
+
|
|
16
|
+
return Math.round(y)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default luminanceForHexColor
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a pseudorandom number between 0 and 1 based on a seed
|
|
3
|
+
* @see https://gist.github.com/tommyettinger/46a874533244883189143505d203312c
|
|
4
|
+
* @see https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
|
|
5
|
+
* @param { number } seed any number
|
|
6
|
+
* @returns { number } pseudorandom number between 0 and 1
|
|
7
|
+
*/
|
|
8
|
+
const mulberry32 = (seed: number): number => {
|
|
9
|
+
let t = (seed += 0x6d2b79f5)
|
|
10
|
+
t = Math.imul(t ^ (t >>> 15), t | 1)
|
|
11
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
|
|
12
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default mulberry32
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import luminanceForHexColor from './luminanceForHexColor'
|
|
2
|
+
|
|
3
|
+
export const textColorForBackground = (background: string): string => {
|
|
4
|
+
const spectrum = {
|
|
5
|
+
black: '#000000',
|
|
6
|
+
darkGrey: '#313132',
|
|
7
|
+
mediumGrey: '#606060',
|
|
8
|
+
lightGrey: '#D3D3D3',
|
|
9
|
+
veryLightGrey: '#F2F2F2',
|
|
10
|
+
white: '#FFFFFF',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const midpoint = 255 / 2
|
|
14
|
+
if ((luminanceForHexColor(background ?? '') ?? 0) >= midpoint) {
|
|
15
|
+
return spectrum.darkGrey
|
|
16
|
+
}
|
|
17
|
+
return spectrum.white
|
|
18
|
+
}
|