@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,186 @@
|
|
|
1
|
+
import { DefaultOCABundleResolver, Identifiers, OCABundle, OCABundleResolverOptions } from './oca';
|
|
2
|
+
export interface RemoteOCABundleResolverOptions extends OCABundleResolverOptions {
|
|
3
|
+
indexFileName?: string;
|
|
4
|
+
verifyCacheIntegrity?: boolean;
|
|
5
|
+
}
|
|
6
|
+
type BundleIndexEntry = {
|
|
7
|
+
path: string;
|
|
8
|
+
sha256: string;
|
|
9
|
+
};
|
|
10
|
+
type BundleIndex = {
|
|
11
|
+
[key: string]: BundleIndexEntry;
|
|
12
|
+
};
|
|
13
|
+
export declare class RemoteOCABundleResolver extends DefaultOCABundleResolver {
|
|
14
|
+
protected indexFile: BundleIndex;
|
|
15
|
+
private axiosInstance;
|
|
16
|
+
private cacheDataFileName;
|
|
17
|
+
private indexFileName;
|
|
18
|
+
private _indexFileEtag?;
|
|
19
|
+
constructor(indexFileBaseUrl: string, options?: RemoteOCABundleResolverOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Sets the value of the index file ETag.
|
|
22
|
+
*
|
|
23
|
+
* @param value - The new value for the index file ETag.
|
|
24
|
+
*/
|
|
25
|
+
set indexFileEtag(value: string);
|
|
26
|
+
/**
|
|
27
|
+
* Gets the ETag of the index file.
|
|
28
|
+
*
|
|
29
|
+
* @returns The ETag of the index file, or an empty string if not available.
|
|
30
|
+
*/
|
|
31
|
+
get indexFileEtag(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Checks for updates in the OCA (Overlay Capture Architecture) index.
|
|
34
|
+
* If the index file ETag is not available, it loads the cache data and retrieves the ETag from it.
|
|
35
|
+
* Then, it loads the OCA index.
|
|
36
|
+
* @returns A promise that resolves when the update check is complete.
|
|
37
|
+
*/
|
|
38
|
+
checkForUpdates(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Loads the cache data from the local storage.
|
|
41
|
+
* @returns A promise that resolves to the cache data file, or undefined if the cache file does not exist or cannot be loaded.
|
|
42
|
+
*/
|
|
43
|
+
private loadCacheData;
|
|
44
|
+
/**
|
|
45
|
+
* Saves the cache data to local storage.
|
|
46
|
+
*
|
|
47
|
+
* @param cacheData - The cache data to be saved.
|
|
48
|
+
* @returns A promise that resolves to a boolean indicating whether the save operation was successful.
|
|
49
|
+
*/
|
|
50
|
+
private saveCacheData;
|
|
51
|
+
/**
|
|
52
|
+
* Processes the queue of OCABundleQueueEntry items.
|
|
53
|
+
*
|
|
54
|
+
* @param items - An array of OCABundleQueueEntry items to process.
|
|
55
|
+
* @returns A promise that resolves to an array of processed OCABundleQueueEntry items.
|
|
56
|
+
*/
|
|
57
|
+
private processQueue;
|
|
58
|
+
/**
|
|
59
|
+
* Prepares the bundle queue based on the new and old index files.
|
|
60
|
+
* It compares the SHA256 hashes of the files in the new and old index files
|
|
61
|
+
* and determines which files should be removed and which files should be added
|
|
62
|
+
* to the bundle queue.
|
|
63
|
+
*
|
|
64
|
+
* @param newIndexFile - The new bundle index file.
|
|
65
|
+
* @param oldIndexFile - The old bundle index file.
|
|
66
|
+
* @returns An array of `OCABundleQueueEntry` objects representing the files to be removed and added.
|
|
67
|
+
*/
|
|
68
|
+
private prepareBundleQueue;
|
|
69
|
+
/**
|
|
70
|
+
* Finds the SHA-256 hash associated with a given path in the index file.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} path - The path to search for in the index file.
|
|
73
|
+
* @returns {string | null} The SHA-256 hash associated with the path if found, or null if not found.
|
|
74
|
+
*/
|
|
75
|
+
private findSha256ByPath;
|
|
76
|
+
/**
|
|
77
|
+
* Finds the path associated with the given SHA256 hash in the index file.
|
|
78
|
+
*
|
|
79
|
+
* @param sha256 - The SHA256 hash to search for.
|
|
80
|
+
* @returns The path associated with the SHA256 hash, or null if not found.
|
|
81
|
+
*/
|
|
82
|
+
private findPathBySha256;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the file name for the bundle at the specified path.
|
|
85
|
+
*
|
|
86
|
+
* @param path - The path of the bundle.
|
|
87
|
+
* @returns The file name for the bundle, or null if not found.
|
|
88
|
+
*/
|
|
89
|
+
private fileNameForBundleAtPath;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the file storage path for the remote OCA resolver.
|
|
92
|
+
* The file storage path is the concatenation of the `CachesDirectoryPath` and `ocaBundleStorageDirectory`.
|
|
93
|
+
*
|
|
94
|
+
* @returns The file storage path.
|
|
95
|
+
*/
|
|
96
|
+
private fileStoragePath;
|
|
97
|
+
/**
|
|
98
|
+
* Checks if a file exists at a specific path in the document directory.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} fileName - The name of the file to check.
|
|
101
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the file exists, or false otherwise.
|
|
102
|
+
* @throws Will throw an error if the existence check fails.
|
|
103
|
+
*/
|
|
104
|
+
private checkFileExists;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a working directory if it does not already exist.
|
|
107
|
+
*
|
|
108
|
+
* @returns A promise that resolves to a boolean indicating whether the directory was created successfully.
|
|
109
|
+
*/
|
|
110
|
+
private createWorkingDirectoryIfNotExists;
|
|
111
|
+
/**
|
|
112
|
+
* Saves a string of data to a file in the local storage.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} fileName - The name of the file to save.
|
|
115
|
+
* @param {string} data - The data to write to the file.
|
|
116
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the file was saved successfully, or false otherwise.
|
|
117
|
+
* @throws Will throw an error if the write operation fails.
|
|
118
|
+
*/
|
|
119
|
+
private saveFileToLocalStorage;
|
|
120
|
+
/**
|
|
121
|
+
* Loads a file from local storage.
|
|
122
|
+
*
|
|
123
|
+
* @param fileName - The name of the file to load.
|
|
124
|
+
* @returns A promise that resolves to the contents of the file, or undefined if the file does not exist.
|
|
125
|
+
*/
|
|
126
|
+
private loadFileFromLocalStorage;
|
|
127
|
+
/**
|
|
128
|
+
* Removes a file from the local storage.
|
|
129
|
+
*
|
|
130
|
+
* @param fileName - The name of the file to be removed.
|
|
131
|
+
* @returns A promise that resolves to a boolean indicating whether the file was successfully removed.
|
|
132
|
+
*/
|
|
133
|
+
private removeFileFromLocalStorage;
|
|
134
|
+
/**
|
|
135
|
+
* Fetches an OCA bundle from a remote resource and saves it to local storage.
|
|
136
|
+
* @param path - The path of the remote resource.
|
|
137
|
+
* @returns A promise that resolves to a boolean indicating whether the fetch and save operation was successful.
|
|
138
|
+
*/
|
|
139
|
+
private fetchOCABundle;
|
|
140
|
+
/**
|
|
141
|
+
* Loads the OCA index from a remote location and processes it.
|
|
142
|
+
* If the remote resource is not available, it falls back to the cached index file.
|
|
143
|
+
* If the index file has not changed, it uses the existing data.
|
|
144
|
+
* If the index file has changed, it refreshes the index file and the bundles.
|
|
145
|
+
*
|
|
146
|
+
* @param filePath - The path to the remote OCA index file.
|
|
147
|
+
* @returns A Promise that resolves when the index file and bundles have been processed.
|
|
148
|
+
* @throws If there is an error fetching or processing the OCA index.
|
|
149
|
+
*/
|
|
150
|
+
private loadOCAIndex;
|
|
151
|
+
/**
|
|
152
|
+
* Loads the OCABundle from the specified path.
|
|
153
|
+
*
|
|
154
|
+
* @param path - The path of the OCABundle.
|
|
155
|
+
* @returns A promise that resolves to an array of IOverlayBundleData.
|
|
156
|
+
*/
|
|
157
|
+
private loadOCABundle;
|
|
158
|
+
/**
|
|
159
|
+
* Finds a matching identifier in the index file based on the provided identifiers.
|
|
160
|
+
* The order of the identifiers matters if more than one candidate exists in the index file.
|
|
161
|
+
*
|
|
162
|
+
* @param identifiers - The identifiers to match against the index file.
|
|
163
|
+
* @returns The matching identifier, or undefined if no match is found.
|
|
164
|
+
*/
|
|
165
|
+
private matchBundleIndexEntry;
|
|
166
|
+
/**
|
|
167
|
+
* Resolves the OCABundle based on the given parameters.
|
|
168
|
+
* @param params - The parameters for resolving the OCABundle.
|
|
169
|
+
* @param params.identifiers - The identifiers used to match the OCABundle.
|
|
170
|
+
* @param params.language - The language of the OCABundle (optional).
|
|
171
|
+
* @returns A Promise that resolves to the OCABundle or undefined.
|
|
172
|
+
*/
|
|
173
|
+
resolve(params: {
|
|
174
|
+
identifiers: Identifiers;
|
|
175
|
+
language?: string | undefined;
|
|
176
|
+
}): Promise<OCABundle | undefined>;
|
|
177
|
+
/**
|
|
178
|
+
* Retrieves the fallback branding overlays for a given credential definition ID and capture base.
|
|
179
|
+
* @param credentialDefinitionId - The ID of the credential definition.
|
|
180
|
+
* @param captureBase - The capture base for the overlays.
|
|
181
|
+
* @returns An array of fallback branding overlays.
|
|
182
|
+
*/
|
|
183
|
+
private getFallbackBrandingOverlays;
|
|
184
|
+
private verifyCacheIntegrity;
|
|
185
|
+
}
|
|
186
|
+
export {};
|