@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.
Files changed (165) hide show
  1. package/README.md +33 -0
  2. package/build/__tests__/remote.test.d.ts +1 -0
  3. package/build/__tests__/remote.test.js +162 -0
  4. package/build/constants.d.ts +4 -0
  5. package/build/constants.js +7 -0
  6. package/build/formatters/credential/CredentialFormatter.d.ts +8 -0
  7. package/build/formatters/credential/CredentialFormatter.js +32 -0
  8. package/build/formatters/credential/DisplayAttribute.d.ts +11 -0
  9. package/build/formatters/credential/DisplayAttribute.js +18 -0
  10. package/build/formatters/credential/LocalizedCredential.d.ts +13 -0
  11. package/build/formatters/credential/LocalizedCredential.js +57 -0
  12. package/build/formatters/credential/index.d.ts +4 -0
  13. package/build/formatters/credential/index.js +12 -0
  14. package/build/formatters/index.d.ts +4 -0
  15. package/build/formatters/index.js +12 -0
  16. package/build/index.d.ts +5 -0
  17. package/build/index.js +34 -0
  18. package/build/interfaces/data/base/BaseOverlayData.interface.d.ts +5 -0
  19. package/build/interfaces/data/base/BaseOverlayData.interface.js +2 -0
  20. package/build/interfaces/data/branding/BrandingOverlayData.interface.d.ts +12 -0
  21. package/build/interfaces/data/branding/BrandingOverlayData.interface.js +2 -0
  22. package/build/interfaces/data/branding/LegacyBrandingOverlayData.interface.d.ts +15 -0
  23. package/build/interfaces/data/branding/LegacyBrandingOverlayData.interface.js +2 -0
  24. package/build/interfaces/data/bundle/OverlayBundleData.interface.d.ts +6 -0
  25. package/build/interfaces/data/bundle/OverlayBundleData.interface.js +2 -0
  26. package/build/interfaces/data/capture-base/CaptureBaseData.interface.d.ts +7 -0
  27. package/build/interfaces/data/capture-base/CaptureBaseData.interface.js +2 -0
  28. package/build/interfaces/data/index.d.ts +12 -0
  29. package/build/interfaces/data/index.js +2 -0
  30. package/build/interfaces/data/semantic/CharacterEncodingOverlayData.interface.d.ts +6 -0
  31. package/build/interfaces/data/semantic/CharacterEncodingOverlayData.interface.js +2 -0
  32. package/build/interfaces/data/semantic/FormatOverlayData.interface.d.ts +4 -0
  33. package/build/interfaces/data/semantic/FormatOverlayData.interface.js +2 -0
  34. package/build/interfaces/data/semantic/InformationOverlayData.interface.d.ts +5 -0
  35. package/build/interfaces/data/semantic/InformationOverlayData.interface.js +2 -0
  36. package/build/interfaces/data/semantic/LabelOverlayData.interface.d.ts +7 -0
  37. package/build/interfaces/data/semantic/LabelOverlayData.interface.js +2 -0
  38. package/build/interfaces/data/semantic/MetaOverlayData.interface.d.ts +12 -0
  39. package/build/interfaces/data/semantic/MetaOverlayData.interface.js +2 -0
  40. package/build/interfaces/data/semantic/StandardOverlayData.interface.d.ts +5 -0
  41. package/build/interfaces/data/semantic/StandardOverlayData.interface.js +2 -0
  42. package/build/interfaces/index.d.ts +2 -0
  43. package/build/interfaces/index.js +18 -0
  44. package/build/interfaces/overlay/OverlayBundleAttribute.interface.d.ts +9 -0
  45. package/build/interfaces/overlay/OverlayBundleAttribute.interface.js +2 -0
  46. package/build/interfaces/overlay/OverlayBundleMetadata.interface.d.ts +9 -0
  47. package/build/interfaces/overlay/OverlayBundleMetadata.interface.js +2 -0
  48. package/build/interfaces/overlay/index.d.ts +3 -0
  49. package/build/interfaces/overlay/index.js +2 -0
  50. package/build/legacy/index.d.ts +3 -0
  51. package/build/legacy/index.js +19 -0
  52. package/build/legacy/resolver/oca.d.ts +99 -0
  53. package/build/legacy/resolver/oca.js +239 -0
  54. package/build/legacy/resolver/record.d.ts +50 -0
  55. package/build/legacy/resolver/record.js +37 -0
  56. package/build/legacy/resolver/remote-oca.d.ts +186 -0
  57. package/build/legacy/resolver/remote-oca.js +536 -0
  58. package/build/types/OverlayTypeMap.d.ts +5 -0
  59. package/build/types/OverlayTypeMap.js +25 -0
  60. package/build/types/TypeEnums.d.ts +19 -0
  61. package/build/types/TypeEnums.js +24 -0
  62. package/build/types/base/BaseOverlay.d.ts +8 -0
  63. package/build/types/base/BaseOverlay.js +28 -0
  64. package/build/types/branding/BrandingOverlay.d.ts +15 -0
  65. package/build/types/branding/BrandingOverlay.js +68 -0
  66. package/build/types/branding/LegacyBrandingOverlay.d.ts +18 -0
  67. package/build/types/branding/LegacyBrandingOverlay.js +51 -0
  68. package/build/types/bundle/OverlayBundle.d.ts +20 -0
  69. package/build/types/bundle/OverlayBundle.js +167 -0
  70. package/build/types/capture-base/CaptureBase.d.ts +10 -0
  71. package/build/types/capture-base/CaptureBase.js +30 -0
  72. package/build/types/index.d.ts +14 -0
  73. package/build/types/index.js +33 -0
  74. package/build/types/semantic/CharacterEncodingOverlay.d.ts +9 -0
  75. package/build/types/semantic/CharacterEncodingOverlay.js +43 -0
  76. package/build/types/semantic/FormatOverlay.d.ts +7 -0
  77. package/build/types/semantic/FormatOverlay.js +30 -0
  78. package/build/types/semantic/InformationOverlay.d.ts +8 -0
  79. package/build/types/semantic/InformationOverlay.js +31 -0
  80. package/build/types/semantic/LabelOverlay.d.ts +10 -0
  81. package/build/types/semantic/LabelOverlay.js +41 -0
  82. package/build/types/semantic/MetaOverlay.d.ts +15 -0
  83. package/build/types/semantic/MetaOverlay.js +54 -0
  84. package/build/types/semantic/StandardOverlay.d.ts +8 -0
  85. package/build/types/semantic/StandardOverlay.js +38 -0
  86. package/build/utils/color/generateColor.d.ts +2 -0
  87. package/build/utils/color/generateColor.js +11 -0
  88. package/build/utils/color/hashCode.d.ts +8 -0
  89. package/build/utils/color/hashCode.js +12 -0
  90. package/build/utils/color/hashToRGBA.d.ts +8 -0
  91. package/build/utils/color/hashToRGBA.js +23 -0
  92. package/build/utils/color/index.d.ts +5 -0
  93. package/build/utils/color/index.js +15 -0
  94. package/build/utils/color/luminanceForHexColor.d.ts +7 -0
  95. package/build/utils/color/luminanceForHexColor.js +18 -0
  96. package/build/utils/color/mulberry32.d.ts +9 -0
  97. package/build/utils/color/mulberry32.js +16 -0
  98. package/build/utils/color/textColorForBackground.d.ts +1 -0
  99. package/build/utils/color/textColorForBackground.js +24 -0
  100. package/build/utils/credential-definition.d.ts +1 -0
  101. package/build/utils/credential-definition.js +21 -0
  102. package/build/utils/index.d.ts +1 -0
  103. package/build/utils/index.js +17 -0
  104. package/build/utils/logger.d.ts +5 -0
  105. package/build/utils/logger.js +17 -0
  106. package/build/utils/schema.d.ts +4 -0
  107. package/build/utils/schema.js +19 -0
  108. package/package.json +53 -0
  109. package/src/__tests__/__snapshots__/remote.test.ts.snap +293 -0
  110. package/src/__tests__/fixtures/bundle.json +131 -0
  111. package/src/__tests__/fixtures/oca.json +4 -0
  112. package/src/__tests__/fixtures/ocabundles.json +142 -0
  113. package/src/__tests__/remote.test.ts +180 -0
  114. package/src/constants.ts +7 -0
  115. package/src/formatters/credential/CredentialFormatter.ts +20 -0
  116. package/src/formatters/credential/DisplayAttribute.ts +29 -0
  117. package/src/formatters/credential/LocalizedCredential.ts +53 -0
  118. package/src/formatters/credential/index.ts +5 -0
  119. package/src/formatters/index.ts +5 -0
  120. package/src/index.ts +5 -0
  121. package/src/interfaces/data/base/BaseOverlayData.interface.ts +5 -0
  122. package/src/interfaces/data/branding/BrandingOverlayData.interface.ts +13 -0
  123. package/src/interfaces/data/branding/LegacyBrandingOverlayData.interface.ts +16 -0
  124. package/src/interfaces/data/bundle/OverlayBundleData.interface.ts +7 -0
  125. package/src/interfaces/data/capture-base/CaptureBaseData.interface.ts +7 -0
  126. package/src/interfaces/data/index.ts +25 -0
  127. package/src/interfaces/data/semantic/CharacterEncodingOverlayData.interface.ts +8 -0
  128. package/src/interfaces/data/semantic/FormatOverlayData.interface.ts +5 -0
  129. package/src/interfaces/data/semantic/InformationOverlayData.interface.ts +6 -0
  130. package/src/interfaces/data/semantic/LabelOverlayData.interface.ts +8 -0
  131. package/src/interfaces/data/semantic/MetaOverlayData.interface.ts +13 -0
  132. package/src/interfaces/data/semantic/StandardOverlayData.interface.ts +7 -0
  133. package/src/interfaces/index.ts +2 -0
  134. package/src/interfaces/overlay/OverlayBundleAttribute.interface.ts +9 -0
  135. package/src/interfaces/overlay/OverlayBundleMetadata.interface.ts +9 -0
  136. package/src/interfaces/overlay/index.ts +4 -0
  137. package/src/legacy/index.ts +3 -0
  138. package/src/legacy/resolver/oca.ts +377 -0
  139. package/src/legacy/resolver/record.ts +81 -0
  140. package/src/legacy/resolver/remote-oca.ts +661 -0
  141. package/src/types/OverlayTypeMap.ts +25 -0
  142. package/src/types/TypeEnums.ts +20 -0
  143. package/src/types/base/BaseOverlay.ts +18 -0
  144. package/src/types/branding/BrandingOverlay.ts +61 -0
  145. package/src/types/branding/LegacyBrandingOverlay.ts +47 -0
  146. package/src/types/bundle/OverlayBundle.ts +203 -0
  147. package/src/types/capture-base/CaptureBase.ts +22 -0
  148. package/src/types/index.ts +30 -0
  149. package/src/types/semantic/CharacterEncodingOverlay.ts +30 -0
  150. package/src/types/semantic/FormatOverlay.ts +15 -0
  151. package/src/types/semantic/InformationOverlay.ts +18 -0
  152. package/src/types/semantic/LabelOverlay.ts +30 -0
  153. package/src/types/semantic/MetaOverlay.ts +48 -0
  154. package/src/types/semantic/StandardOverlay.ts +24 -0
  155. package/src/utils/color/generateColor.ts +8 -0
  156. package/src/utils/color/hashCode.ts +11 -0
  157. package/src/utils/color/hashToRGBA.ts +22 -0
  158. package/src/utils/color/index.ts +7 -0
  159. package/src/utils/color/luminanceForHexColor.ts +19 -0
  160. package/src/utils/color/mulberry32.ts +15 -0
  161. package/src/utils/color/textColorForBackground.ts +18 -0
  162. package/src/utils/credential-definition.ts +19 -0
  163. package/src/utils/index.ts +1 -0
  164. package/src/utils/logger.ts +14 -0
  165. package/src/utils/schema.ts +16 -0
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./data"), exports);
18
+ __exportStar(require("./overlay"), exports);
@@ -0,0 +1,9 @@
1
+ export default interface IOverlayBundleAttribute {
2
+ name: string;
3
+ type: string;
4
+ information?: Record<string, string>;
5
+ label?: Record<string, string>;
6
+ format?: string;
7
+ characterEncoding?: string;
8
+ standard?: string;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export default interface IOverlayBundleMetadata {
2
+ name: Record<string, string>;
3
+ description: Record<string, string>;
4
+ credentialHelpText?: Record<string, string>;
5
+ credentialSupportUrl?: Record<string, string>;
6
+ issuer: Record<string, string>;
7
+ issuerDescription?: Record<string, string>;
8
+ issuerUrl?: Record<string, string>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import IOverlayBundleAttribute from './OverlayBundleAttribute.interface';
2
+ import IOverlayBundleMetadata from './OverlayBundleMetadata.interface';
3
+ export { IOverlayBundleAttribute, IOverlayBundleMetadata };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from './resolver/oca';
2
+ export * from './resolver/record';
3
+ export * from './resolver/remote-oca';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./resolver/oca"), exports);
18
+ __exportStar(require("./resolver/record"), exports);
19
+ __exportStar(require("./resolver/remote-oca"), exports);
@@ -0,0 +1,99 @@
1
+ import { IOverlayBundleData } from '../../interfaces';
2
+ import { BaseOverlay, BrandingOverlay, CaptureBase, CharacterEncodingOverlay, FormatOverlay, LabelOverlay, LegacyBrandingOverlay, MetaOverlay, OverlayBundle, OverlayType } from '../../types';
3
+ import { Field } from './record';
4
+ export declare const BrandingOverlayType: {
5
+ readonly Branding01: OverlayType.Branding01;
6
+ readonly Branding10: OverlayType.Branding10;
7
+ readonly Branding11: OverlayType.Branding11;
8
+ };
9
+ export type BrandingOverlayType = (typeof BrandingOverlayType)[keyof typeof BrandingOverlayType];
10
+ export interface CredentialOverlay<T> {
11
+ bundle?: OCABundle;
12
+ presentationFields?: Field[];
13
+ metaOverlay?: MetaOverlay;
14
+ brandingOverlay?: T;
15
+ }
16
+ export interface OCABundleType {
17
+ get captureBase(): CaptureBase;
18
+ get metaOverlay(): MetaOverlay | undefined;
19
+ get labelOverlay(): LabelOverlay | undefined;
20
+ get formatOverlay(): FormatOverlay | undefined;
21
+ get characterEncodingOverlay(): CharacterEncodingOverlay | undefined;
22
+ get brandingOverlay(): BrandingOverlay | LegacyBrandingOverlay | undefined;
23
+ }
24
+ export type OCABundleResolveParams = {
25
+ identifiers: Identifiers;
26
+ language?: string;
27
+ };
28
+ export type OCABundleResolveDefaultParams = {
29
+ identifiers: Identifiers;
30
+ meta?: Meta;
31
+ language?: string;
32
+ };
33
+ export type OCABundleResolveAllParams = {
34
+ identifiers: Identifiers;
35
+ attributes?: Array<Field>;
36
+ meta?: Meta;
37
+ language?: string;
38
+ };
39
+ export type OCABundleResolvePresentationFieldsParams = {
40
+ identifiers: Identifiers;
41
+ attributes: Array<Field>;
42
+ language?: string;
43
+ };
44
+ export interface OCABundleResolverType {
45
+ resolve(params: OCABundleResolveParams): Promise<OCABundle | undefined>;
46
+ resolveDefaultBundle(params: OCABundleResolveDefaultParams): Promise<OCABundle | undefined>;
47
+ presentationFields(params: OCABundleResolvePresentationFieldsParams): Promise<Field[]>;
48
+ resolveAllBundles(params: OCABundleResolveAllParams): Promise<CredentialOverlay<BaseOverlay | BrandingOverlay | LegacyBrandingOverlay>>;
49
+ getBrandingOverlayType(): BrandingOverlayType;
50
+ }
51
+ export interface OCABundleResolverOptions {
52
+ language?: string;
53
+ brandingOverlayType?: BrandingOverlayType;
54
+ }
55
+ export interface Identifiers {
56
+ schemaId?: string;
57
+ credentialDefinitionId?: string;
58
+ templateId?: string;
59
+ }
60
+ export interface Meta {
61
+ alias?: string;
62
+ credName?: string;
63
+ credConnectionId?: string;
64
+ logo?: string;
65
+ }
66
+ export declare class OCABundle implements OCABundleType {
67
+ private bundle;
68
+ private options;
69
+ constructor(bundle: OverlayBundle, options?: OCABundleResolverOptions);
70
+ get captureBase(): CaptureBase;
71
+ get characterEncodingOverlay(): CharacterEncodingOverlay | undefined;
72
+ get formatOverlay(): FormatOverlay | undefined;
73
+ get labelOverlay(): LabelOverlay | undefined;
74
+ get metaOverlay(): MetaOverlay | undefined;
75
+ get brandingOverlay(): BrandingOverlay | LegacyBrandingOverlay | undefined;
76
+ buildOverlay(name: string, language: string): MetaOverlay;
77
+ private getOverlay;
78
+ }
79
+ export declare class DefaultOCABundleResolver implements OCABundleResolverType {
80
+ protected bundles: Record<string, OverlayBundle | string>;
81
+ protected options: OCABundleResolverOptions;
82
+ private _log?;
83
+ constructor(bundlesData?: Record<string, IOverlayBundleData | string>, options?: OCABundleResolverOptions);
84
+ /**
85
+ * Sets the log value.
86
+ * @param value - The new value for the log.
87
+ */
88
+ set log(value: any);
89
+ /**
90
+ * Get the log value.
91
+ */
92
+ get log(): any;
93
+ getBrandingOverlayType(): BrandingOverlayType;
94
+ private getDefaultBundle;
95
+ resolveDefaultBundle(params: OCABundleResolveDefaultParams): Promise<OCABundle | undefined>;
96
+ resolve(params: OCABundleResolveParams): Promise<OCABundle | undefined>;
97
+ presentationFields(params: OCABundleResolvePresentationFieldsParams): Promise<Field[]>;
98
+ resolveAllBundles(params: OCABundleResolveAllParams): Promise<CredentialOverlay<BaseOverlay | BrandingOverlay | LegacyBrandingOverlay>>;
99
+ }
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DefaultOCABundleResolver = exports.OCABundle = exports.BrandingOverlayType = void 0;
7
+ const lodash_startcase_1 = __importDefault(require("lodash.startcase"));
8
+ const constants_1 = require("../../constants");
9
+ const types_1 = require("../../types");
10
+ const color_1 = require("../../utils/color");
11
+ const credential_definition_1 = require("../../utils/credential-definition");
12
+ exports.BrandingOverlayType = {
13
+ Branding01: types_1.OverlayType.Branding01,
14
+ Branding10: types_1.OverlayType.Branding10,
15
+ Branding11: types_1.OverlayType.Branding11,
16
+ };
17
+ class OCABundle {
18
+ constructor(bundle, options) {
19
+ var _a, _b;
20
+ this.bundle = bundle;
21
+ this.options = {
22
+ brandingOverlayType: (_a = options === null || options === void 0 ? void 0 : options.brandingOverlayType) !== null && _a !== void 0 ? _a : exports.BrandingOverlayType.Branding10,
23
+ language: (_b = options === null || options === void 0 ? void 0 : options.language) !== null && _b !== void 0 ? _b : constants_1.defaultBundleLanguage,
24
+ };
25
+ // Make bundle overlay type come from options.brandingOverlayType
26
+ this.bundle.overlays.forEach((o) => {
27
+ if (o.type === exports.BrandingOverlayType.Branding10 || o.type === exports.BrandingOverlayType.Branding11) {
28
+ o.type = this.options.brandingOverlayType;
29
+ }
30
+ });
31
+ }
32
+ get captureBase() {
33
+ const overlay = this.bundle.captureBase;
34
+ if (!overlay) {
35
+ throw new Error('Capture Base must be defined');
36
+ }
37
+ return overlay;
38
+ }
39
+ get characterEncodingOverlay() {
40
+ return this.getOverlay(types_1.OverlayType.CharacterEncoding10);
41
+ }
42
+ get formatOverlay() {
43
+ return this.getOverlay(types_1.OverlayType.Format10);
44
+ }
45
+ get labelOverlay() {
46
+ return this.getOverlay(types_1.OverlayType.Label10, this.options.language);
47
+ }
48
+ get metaOverlay() {
49
+ return this.getOverlay(types_1.OverlayType.Meta10, this.options.language);
50
+ }
51
+ get brandingOverlay() {
52
+ var _a;
53
+ return this.getOverlay(((_a = this.options) === null || _a === void 0 ? void 0 : _a.brandingOverlayType) || exports.BrandingOverlayType.Branding10);
54
+ }
55
+ buildOverlay(name, language) {
56
+ return new types_1.MetaOverlay({
57
+ capture_base: '',
58
+ type: types_1.OverlayType.Meta10,
59
+ name,
60
+ language,
61
+ description: '',
62
+ credential_help_text: '',
63
+ credential_support_url: '',
64
+ issuer: '',
65
+ issuer_description: '',
66
+ issuer_url: '',
67
+ });
68
+ }
69
+ getOverlay(type, language) {
70
+ if (type === types_1.OverlayType.CaptureBase10) {
71
+ return this.bundle.captureBase;
72
+ }
73
+ if (language !== undefined) {
74
+ // we want to return branding even if there isn't a bundle for a given language
75
+ const overlay = this.bundle.overlays.find((item) => (item.language === undefined && item.type === type.toString()) ||
76
+ (item.type === type.toString() && item.language === language));
77
+ if (overlay) {
78
+ return overlay;
79
+ }
80
+ }
81
+ return this.bundle.overlays.find((item) => item.type === type.toString());
82
+ }
83
+ }
84
+ exports.OCABundle = OCABundle;
85
+ class DefaultOCABundleResolver {
86
+ constructor(bundlesData = {}, options) {
87
+ var _a, _b, _c;
88
+ this.bundles = {};
89
+ for (const cid in bundlesData) {
90
+ try {
91
+ if (typeof bundlesData[cid] !== 'string') {
92
+ this.bundles[cid] = new types_1.OverlayBundle(cid, bundlesData[cid]);
93
+ }
94
+ else {
95
+ this.bundles[cid] = bundlesData[cid];
96
+ }
97
+ }
98
+ catch (error) {
99
+ // might get an error trying to parse javascript's default value
100
+ (_a = this.log) === null || _a === void 0 ? void 0 : _a.error(`Error parsing bundle for ${cid}`, error);
101
+ }
102
+ }
103
+ this.options = {
104
+ brandingOverlayType: (_b = options === null || options === void 0 ? void 0 : options.brandingOverlayType) !== null && _b !== void 0 ? _b : exports.BrandingOverlayType.Branding10,
105
+ language: (_c = options === null || options === void 0 ? void 0 : options.language) !== null && _c !== void 0 ? _c : constants_1.defaultBundleLanguage,
106
+ };
107
+ }
108
+ /**
109
+ * Sets the log value.
110
+ * @param value - The new value for the log.
111
+ */
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ set log(value) {
114
+ this._log = value;
115
+ }
116
+ /**
117
+ * Get the log value.
118
+ */
119
+ get log() {
120
+ return this._log;
121
+ }
122
+ getBrandingOverlayType() {
123
+ var _a;
124
+ return (_a = this.options.brandingOverlayType) !== null && _a !== void 0 ? _a : exports.BrandingOverlayType.Branding10;
125
+ }
126
+ getDefaultBundle(params) {
127
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
128
+ if (!params.language) {
129
+ params.language = constants_1.defaultBundleLanguage;
130
+ }
131
+ const metaOverlay = {
132
+ capture_base: '',
133
+ type: types_1.OverlayType.Meta10,
134
+ name: (0, lodash_startcase_1.default)((_b = (_a = params.meta) === null || _a === void 0 ? void 0 : _a.credName) !== null && _b !== void 0 ? _b : (0, credential_definition_1.parseCredDefFromId)((_c = params.identifiers) === null || _c === void 0 ? void 0 : _c.credentialDefinitionId, (_d = params.identifiers) === null || _d === void 0 ? void 0 : _d.schemaId)),
135
+ issuer: ((_e = params.meta) === null || _e === void 0 ? void 0 : _e.alias) || ((_f = params.meta) === null || _f === void 0 ? void 0 : _f.credConnectionId) || 'Unknown Contact',
136
+ language: (_g = params.language) !== null && _g !== void 0 ? _g : (_h = this.options) === null || _h === void 0 ? void 0 : _h.language,
137
+ description: '',
138
+ credential_help_text: '',
139
+ credential_support_url: '',
140
+ issuer_description: '',
141
+ issuer_url: '',
142
+ };
143
+ let colorHash = 'default';
144
+ if (metaOverlay === null || metaOverlay === void 0 ? void 0 : metaOverlay.name) {
145
+ colorHash = metaOverlay.name;
146
+ }
147
+ else if (metaOverlay === null || metaOverlay === void 0 ? void 0 : metaOverlay.issuer) {
148
+ colorHash = metaOverlay.issuer;
149
+ }
150
+ const brandingOverlay01 = {
151
+ capture_base: '',
152
+ type: types_1.OverlayType.Branding01,
153
+ background_color: (0, color_1.generateColor)(colorHash),
154
+ };
155
+ const brandingOverlay10 = {
156
+ capture_base: '',
157
+ type: types_1.OverlayType.Branding10,
158
+ primary_background_color: (0, color_1.generateColor)(colorHash),
159
+ };
160
+ const brandingOverlay11 = {
161
+ capture_base: '',
162
+ type: types_1.OverlayType.Branding11,
163
+ primary_background_color: '#FFFFFF',
164
+ secondary_background_color: (0, color_1.generateColor)(colorHash),
165
+ };
166
+ let brandingOverlay = this.getBrandingOverlayType() === exports.BrandingOverlayType.Branding01 ? brandingOverlay01 : brandingOverlay10;
167
+ if (this.getBrandingOverlayType() === exports.BrandingOverlayType.Branding11) {
168
+ brandingOverlay = brandingOverlay11;
169
+ }
170
+ const bundle = new types_1.OverlayBundle((_j = params.identifiers) === null || _j === void 0 ? void 0 : _j.credentialDefinitionId, {
171
+ capture_base: {
172
+ attributes: {},
173
+ classification: '',
174
+ type: types_1.OverlayType.CaptureBase10,
175
+ flagged_attributes: [],
176
+ },
177
+ overlays: [metaOverlay, brandingOverlay],
178
+ });
179
+ return Promise.resolve(new OCABundle(bundle, Object.assign(Object.assign({}, this.options), { language: (_k = params.language) !== null && _k !== void 0 ? _k : this.options.language })));
180
+ }
181
+ resolveDefaultBundle(params) {
182
+ return this.getDefaultBundle(params);
183
+ }
184
+ resolve(params) {
185
+ var _a, _b, _c;
186
+ const language = params.language || constants_1.defaultBundleLanguage;
187
+ for (const item of [
188
+ (_a = params.identifiers) === null || _a === void 0 ? void 0 : _a.credentialDefinitionId,
189
+ (_b = params.identifiers) === null || _b === void 0 ? void 0 : _b.schemaId,
190
+ (_c = params.identifiers) === null || _c === void 0 ? void 0 : _c.templateId,
191
+ ]) {
192
+ if (item && this.bundles[item] !== undefined) {
193
+ let bundle = this.bundles[item];
194
+ // if it is a string, it is a reference/alias to another one bundle
195
+ if (typeof bundle === 'string') {
196
+ bundle = this.bundles[bundle];
197
+ }
198
+ return Promise.resolve(new OCABundle(bundle, Object.assign(Object.assign({}, this.options), { language: language !== null && language !== void 0 ? language : this.options.language })));
199
+ }
200
+ }
201
+ return Promise.resolve(undefined);
202
+ }
203
+ async presentationFields(params) {
204
+ var _a, _b, _c, _d, _e, _f, _g;
205
+ const bundle = await this.resolve(params);
206
+ let presentationFields = [...params.attributes];
207
+ if ((_a = bundle === null || bundle === void 0 ? void 0 : bundle.captureBase) === null || _a === void 0 ? void 0 : _a.attributes) {
208
+ // if the oca branding has the attributes set, only display those attributes
209
+ const bundleFields = Object.keys(bundle.captureBase.attributes);
210
+ presentationFields = presentationFields.filter((item) => item.name && bundleFields.includes(item.name));
211
+ for (let i = 0; i < presentationFields.length; i++) {
212
+ const presentationField = presentationFields[i];
213
+ const key = presentationField.name || '';
214
+ if (bundle.captureBase.attributes[key]) {
215
+ presentationField.label = (_b = bundle === null || bundle === void 0 ? void 0 : bundle.labelOverlay) === null || _b === void 0 ? void 0 : _b.attributeLabels[key];
216
+ presentationField.format = (_c = bundle === null || bundle === void 0 ? void 0 : bundle.formatOverlay) === null || _c === void 0 ? void 0 : _c.attributeFormats[key];
217
+ presentationField.type = (_e = (_d = bundle === null || bundle === void 0 ? void 0 : bundle.captureBase) === null || _d === void 0 ? void 0 : _d.attributes) === null || _e === void 0 ? void 0 : _e[key];
218
+ presentationField.encoding = (_g = (_f = bundle === null || bundle === void 0 ? void 0 : bundle.characterEncodingOverlay) === null || _f === void 0 ? void 0 : _f.attributeCharacterEncoding) === null || _g === void 0 ? void 0 : _g[key];
219
+ }
220
+ }
221
+ }
222
+ return presentationFields;
223
+ }
224
+ async resolveAllBundles(params) {
225
+ var _a;
226
+ const [bundle, defaultBundle] = await Promise.all([this.resolve(params), this.resolveDefaultBundle(params)]);
227
+ const fields = params.attributes
228
+ ? await this.presentationFields(Object.assign(Object.assign({}, params), { attributes: params.attributes }))
229
+ : [];
230
+ const overlayBundle = bundle !== null && bundle !== void 0 ? bundle : defaultBundle;
231
+ const metaOverlay = overlayBundle === null || overlayBundle === void 0 ? void 0 : overlayBundle.metaOverlay;
232
+ const brandingOverlay = overlayBundle === null || overlayBundle === void 0 ? void 0 : overlayBundle.brandingOverlay;
233
+ if (brandingOverlay && 'logo' in brandingOverlay && ((_a = params.meta) === null || _a === void 0 ? void 0 : _a.logo)) {
234
+ brandingOverlay.logo = params.meta.logo;
235
+ }
236
+ return { bundle: overlayBundle, presentationFields: fields, metaOverlay, brandingOverlay };
237
+ }
238
+ }
239
+ exports.DefaultOCABundleResolver = DefaultOCABundleResolver;
@@ -0,0 +1,50 @@
1
+ import { AnonCredsNonRevokedInterval, AnonCredsProofRequestRestriction } from '@credo-ts/anoncreds';
2
+ export interface FieldParams {
3
+ name: string;
4
+ format?: string;
5
+ type?: string;
6
+ encoding?: string;
7
+ mimeType?: string;
8
+ revoked?: boolean;
9
+ credentialId?: string;
10
+ label?: string;
11
+ restrictions?: AnonCredsProofRequestRestriction[];
12
+ nonRevoked?: AnonCredsNonRevokedInterval;
13
+ }
14
+ export interface AttributeParams extends FieldParams {
15
+ value: string | number | null;
16
+ revealed?: boolean;
17
+ hasError?: boolean;
18
+ }
19
+ export interface PredicateParams extends FieldParams {
20
+ pValue: string | number | null;
21
+ pType: string;
22
+ parameterizable?: boolean;
23
+ satisfied?: boolean;
24
+ }
25
+ export declare class Field {
26
+ name: string;
27
+ format?: string;
28
+ type?: string;
29
+ encoding?: string;
30
+ mimeType?: string;
31
+ revoked?: boolean;
32
+ credentialId?: string;
33
+ label?: string;
34
+ restrictions?: AnonCredsProofRequestRestriction[];
35
+ nonRevoked?: AnonCredsNonRevokedInterval;
36
+ protected constructor(params: FieldParams);
37
+ }
38
+ export declare class Attribute extends Field {
39
+ value: string | number | null;
40
+ revealed?: boolean;
41
+ hasError?: boolean;
42
+ constructor(params: AttributeParams);
43
+ }
44
+ export declare class Predicate extends Field {
45
+ pValue: string | number | null;
46
+ pType: string;
47
+ parameterizable?: boolean;
48
+ satisfied?: boolean;
49
+ constructor(params: PredicateParams);
50
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Predicate = exports.Attribute = exports.Field = void 0;
4
+ class Field {
5
+ constructor(params) {
6
+ this.name = params.name;
7
+ this.format = params.format;
8
+ this.type = params.type;
9
+ this.encoding = params.encoding;
10
+ this.mimeType = params.mimeType;
11
+ this.revoked = params.revoked;
12
+ this.credentialId = params.credentialId;
13
+ this.label = params.label;
14
+ this.restrictions = params.restrictions;
15
+ this.nonRevoked = params.nonRevoked;
16
+ }
17
+ }
18
+ exports.Field = Field;
19
+ class Attribute extends Field {
20
+ constructor(params) {
21
+ super(params);
22
+ this.value = params.value;
23
+ this.revealed = params.revealed;
24
+ this.hasError = params.hasError;
25
+ }
26
+ }
27
+ exports.Attribute = Attribute;
28
+ class Predicate extends Field {
29
+ constructor(params) {
30
+ super(params);
31
+ this.pValue = params.pValue;
32
+ this.pType = params.pType;
33
+ this.parameterizable = params.parameterizable;
34
+ this.satisfied = params.satisfied;
35
+ }
36
+ }
37
+ exports.Predicate = Predicate;