@sphereon/ui-components.credential-branding 0.2.1-unstable.8 → 0.2.1-unstable.86

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.
@@ -1,256 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- exports.__esModule = true;
48
- exports.selectAppLocaleBranding = exports.toCredentialSummary = exports.toNonPersistedCredentialSummary = void 0;
49
- var uuid_1 = require("uuid");
50
- var utils_1 = require("@veramo/utils");
51
- var ui_components_core_1 = require("@sphereon/ui-components.core");
52
- var ssi_sdk_core_1 = require("@sphereon/ssi-sdk.core");
53
- var ImageUtils_1 = require("../utils/ImageUtils");
54
- var WebImagePreloader_1 = require("../services/WebImagePreloader");
55
- var MappingUtils_1 = require("../utils/MappingUtils");
56
- function findCorrelationIdName(correlationId, contacts) {
57
- var contact = contacts.find(function (contact) {
58
- return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; });
59
- });
60
- if (contact) {
61
- return contact.contact.displayName;
62
- }
63
- return correlationId;
64
- }
65
- var toCredentialDetailsRow = function (object, subject, issuer) { return __awaiter(void 0, void 0, void 0, function () {
66
- var rows, _i, _a, _b, key, value, image, _c, _d, _e, _f, _g, _h, label, contacts, _j, _k, _l, _m;
67
- var _o, _p;
68
- return __generator(this, function (_q) {
69
- switch (_q.label) {
70
- case 0:
71
- rows = [];
72
- _i = 0, _a = Object.entries(object);
73
- _q.label = 1;
74
- case 1:
75
- if (!(_i < _a.length)) return [3, 17];
76
- _b = _a[_i], key = _b[0], value = _b[1];
77
- if (!key.toLowerCase().includes('image')) return [3, 7];
78
- image = typeof value === 'string' ? value : value.id;
79
- _d = (_c = rows).push;
80
- _o = {
81
- id: (0, uuid_1.v4)(),
82
- label: 'image',
83
- value: image
84
- };
85
- return [4, (0, ImageUtils_1.isImageAddress)(image)];
86
- case 2:
87
- if (!(_q.sent())) return [3, 5];
88
- _f = ssi_sdk_core_1.getImageDimensions;
89
- return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
90
- case 3: return [4, _f.apply(void 0, [(_q.sent()).base64Content])];
91
- case 4:
92
- _e = _q.sent();
93
- return [3, 6];
94
- case 5:
95
- _e = undefined;
96
- _q.label = 6;
97
- case 6:
98
- _d.apply(_c, [(_o.imageSize = _e,
99
- _o)]);
100
- return [3, 16];
101
- case 7:
102
- if (key === 'type') {
103
- rows.push({
104
- id: (0, uuid_1.v4)(),
105
- label: key,
106
- value: value
107
- });
108
- return [3, 16];
109
- }
110
- _q.label = 8;
111
- case 8:
112
- if (!(typeof value !== 'string')) return [3, 10];
113
- _h = (_g = rows).concat;
114
- return [4, toCredentialDetailsRow(value, subject, issuer)];
115
- case 9:
116
- rows = _h.apply(_g, [_q.sent()]);
117
- return [3, 16];
118
- case 10:
119
- console.log("==>".concat(key, ":").concat(value));
120
- if (key === '0' || value === undefined) {
121
- return [3, 16];
122
- }
123
- label = key;
124
- if (key === 'id' && value.startsWith('did:')) {
125
- label = 'subject';
126
- }
127
- if (value.startsWith('did:')) {
128
- console.log("did: ".concat(value));
129
- contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
130
- value = findCorrelationIdName(value, contacts);
131
- }
132
- _k = (_j = rows).push;
133
- _p = {
134
- id: (0, uuid_1.v4)(),
135
- label: label,
136
- value: value
137
- };
138
- return [4, (0, ImageUtils_1.isImageAddress)(value)];
139
- case 11:
140
- if (!(_q.sent())) return [3, 14];
141
- _m = ssi_sdk_core_1.getImageDimensions;
142
- return [4, (0, ssi_sdk_core_1.downloadImage)(value)];
143
- case 12: return [4, _m.apply(void 0, [(_q.sent()).base64Content])];
144
- case 13:
145
- _l = _q.sent();
146
- return [3, 15];
147
- case 14:
148
- _l = undefined;
149
- _q.label = 15;
150
- case 15:
151
- _k.apply(_j, [(_p.imageSize = _l,
152
- _p)]);
153
- _q.label = 16;
154
- case 16:
155
- _i++;
156
- return [3, 1];
157
- case 17: return [2, rows];
158
- }
159
- });
160
- }); };
161
- var toNonPersistedCredentialSummary = function (verifiableCredential, branding, issuer, subject) {
162
- var _a;
163
- return (0, exports.toCredentialSummary)({
164
- verifiableCredential: verifiableCredential,
165
- hash: (_a = verifiableCredential.id) !== null && _a !== void 0 ? _a : (0, utils_1.computeEntryHash)(verifiableCredential)
166
- }, branding, issuer, subject);
167
- };
168
- exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
169
- var toCredentialSummary = function (_a, branding, issuer, subject) {
170
- var hash = _a.hash, verifiableCredential = _a.verifiableCredential;
171
- return __awaiter(void 0, void 0, void 0, function () {
172
- var expirationDate, issueDate, credentialStatus, title, properties, localeBranding, logo, url, name, issuerAlias;
173
- var _b, _c, _d, _e;
174
- return __generator(this, function (_f) {
175
- switch (_f.label) {
176
- case 0:
177
- expirationDate = verifiableCredential.expirationDate
178
- ? new Date(verifiableCredential.expirationDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS
179
- : 0;
180
- issueDate = new Date(verifiableCredential.issuanceDate).valueOf() / ui_components_core_1.EPOCH_MILLISECONDS;
181
- credentialStatus = (0, MappingUtils_1.getCredentialStatus)(verifiableCredential);
182
- title = verifiableCredential.name
183
- ? verifiableCredential.name
184
- : !verifiableCredential.type
185
- ? 'unknown'
186
- : typeof verifiableCredential.type === 'string'
187
- ? verifiableCredential.type
188
- : verifiableCredential.type.filter(function (value) { return value !== 'VerifiableCredential'; })[0];
189
- return [4, toCredentialDetailsRow(verifiableCredential.credentialSubject, subject, issuer)];
190
- case 1:
191
- properties = _f.sent();
192
- return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
193
- case 2:
194
- localeBranding = _f.sent();
195
- logo = (0, ImageUtils_1.getIssuerLogo)(verifiableCredential, localeBranding);
196
- url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
197
- name = typeof verifiableCredential.issuer === 'string'
198
- ? verifiableCredential.issuer
199
- : (_c = (_b = verifiableCredential.issuer) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : (_d = verifiableCredential.issuer) === null || _d === void 0 ? void 0 : _d.id;
200
- issuerAlias = undefined;
201
- if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object' && ((_e = verifiableCredential.issuer) === null || _e === void 0 ? void 0 : _e.name)) {
202
- issuerAlias = verifiableCredential.issuer.name;
203
- }
204
- if (!issuerAlias && issuer) {
205
- issuerAlias = issuer.contact.displayName;
206
- }
207
- if (!issuerAlias) {
208
- throw Error("Could not deduce issuer alias");
209
- }
210
- return [2, {
211
- hash: hash,
212
- id: verifiableCredential.id,
213
- title: (localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.alias) || title,
214
- credentialStatus: credentialStatus,
215
- issueDate: issueDate,
216
- expirationDate: expirationDate,
217
- properties: properties,
218
- branding: localeBranding,
219
- issuer: {
220
- name: name,
221
- alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
222
- image: logo,
223
- url: url
224
- }
225
- }];
226
- }
227
- });
228
- });
229
- };
230
- exports.toCredentialSummary = toCredentialSummary;
231
- var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
232
- var appLocale, localeBranding, logo, imagePreloader, backgroundImage;
233
- var _a, _b, _c, _d, _e, _f, _g;
234
- return __generator(this, function (_h) {
235
- appLocale = ui_components_core_1.Localization.getLocale();
236
- localeBranding = (_a = args.localeBranding) === null || _a === void 0 ? void 0 : _a.find(function (branding) { var _a; return ((_a = branding.locale) === null || _a === void 0 ? void 0 : _a.startsWith(appLocale)) || branding.locale === undefined; });
237
- logo = ((_b = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.logo) === null || _b === void 0 ? void 0 : _b.dataUri) || ((_c = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.logo) === null || _c === void 0 ? void 0 : _c.uri);
238
- if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
239
- throw new Error('Not implemented');
240
- }
241
- else {
242
- imagePreloader = new WebImagePreloader_1.WebImagePreloader();
243
- }
244
- if (logo) {
245
- imagePreloader.preload([{ uri: logo }])["catch"](function () {
246
- });
247
- }
248
- backgroundImage = ((_e = (_d = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.background) === null || _d === void 0 ? void 0 : _d.image) === null || _e === void 0 ? void 0 : _e.dataUri) || ((_g = (_f = localeBranding === null || localeBranding === void 0 ? void 0 : localeBranding.background) === null || _f === void 0 ? void 0 : _f.image) === null || _g === void 0 ? void 0 : _g.uri);
249
- if (backgroundImage) {
250
- imagePreloader.preload([{ uri: backgroundImage }])["catch"](function () {
251
- });
252
- }
253
- return [2, localeBranding];
254
- });
255
- }); };
256
- exports.selectAppLocaleBranding = selectAppLocaleBranding;
@@ -1 +0,0 @@
1
- export * from './CredentialMapper';