@sphereon/ui-components.credential-branding 0.2.1-unstable.97 → 0.3.1-next.14

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.
@@ -2,7 +2,13 @@ import { VerifiableCredential } from '@veramo/core';
2
2
  import { CredentialRole, IBasicCredentialLocaleBranding, IBasicIssuerLocaleBranding, Party } from '@sphereon/ssi-sdk.data-store';
3
3
  import { CredentialSummary, ISelectAppLocaleBrandingArgs } from '../types';
4
4
  import { ICredential } from '@sphereon/ssi-types';
5
- export declare const toNonPersistedCredentialSummary: (verifiableCredential: ICredential | VerifiableCredential, credentialRole: CredentialRole, branding?: Array<IBasicCredentialLocaleBranding>, issuer?: Party, subject?: Party) => Promise<CredentialSummary>;
5
+ export declare const toNonPersistedCredentialSummary: ({ verifiableCredential, credentialRole, branding, issuer, subject, }: {
6
+ verifiableCredential: ICredential | VerifiableCredential;
7
+ credentialRole: CredentialRole;
8
+ branding?: IBasicCredentialLocaleBranding[] | undefined;
9
+ issuer?: Party | undefined;
10
+ subject?: Party | undefined;
11
+ }) => Promise<CredentialSummary>;
6
12
  export declare const getDate: (...dates: (number | string | undefined)[]) => number | undefined;
7
13
  export declare const getCredentialDisplayName: ({ verifiableCredential, localeBranding, }: {
8
14
  verifiableCredential: VerifiableCredential;
@@ -15,5 +21,12 @@ export declare const getCredentialIssuerNameAndAlias: ({ verifiableCredential, i
15
21
  issuerAlias: string;
16
22
  issuerName: string;
17
23
  };
18
- export declare const toCredentialSummary: (verifiableCredential: VerifiableCredential, hash: string, credentialRole: CredentialRole, branding?: Array<IBasicCredentialLocaleBranding>, issuer?: Party, subject?: Party) => Promise<CredentialSummary>;
24
+ export declare const toCredentialSummary: ({ verifiableCredential, hash, credentialRole, branding, issuer, subject, }: {
25
+ verifiableCredential: VerifiableCredential;
26
+ hash: string;
27
+ credentialRole: CredentialRole;
28
+ branding?: IBasicCredentialLocaleBranding[] | undefined;
29
+ issuer?: Party | undefined;
30
+ subject?: Party | undefined;
31
+ }) => Promise<CredentialSummary>;
19
32
  export declare const selectAppLocaleBranding: (args: ISelectAppLocaleBrandingArgs) => Promise<IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding | undefined>;
@@ -102,101 +102,118 @@ function findCorrelationIdName(correlationId, parties, activeUser) {
102
102
  if (activeUser) {
103
103
  parties.push(activeUser);
104
104
  }
105
- return ((_b = (_a = allParties === null || allParties === void 0 ? void 0 : allParties.find(function (contact) { return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; }); })) === null || _a === void 0 ? void 0 : _a.contact.displayName) !== null && _b !== void 0 ? _b : correlationId);
105
+ return ((_b = (_a = allParties === null || allParties === void 0 ? void 0 : allParties.find(function (contact) {
106
+ return contact.identities.some(function (identity) { return identity.identifier.correlationId === correlationId; });
107
+ })) === null || _a === void 0 ? void 0 : _a.contact.displayName) !== null && _b !== void 0 ? _b : correlationId);
106
108
  }
107
109
  var getImageSize = function (image) { return __awaiter(void 0, void 0, void 0, function () {
108
- var downloadedImage, imageSize;
110
+ var downloadedImage;
109
111
  return __generator(this, function (_a) {
110
112
  switch (_a.label) {
111
- case 0: return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
113
+ case 0: return [4, (0, utils_2.isImageAddress)(image)];
112
114
  case 1:
113
- downloadedImage = _a.sent();
114
- imageSize = undefined;
115
- return [4, (0, utils_2.isImageAddress)(image)];
115
+ if (!(_a.sent())) {
116
+ return [2];
117
+ }
118
+ if (!(image.startsWith('http://') && !image.startsWith('https://'))) return [3, 3];
119
+ return [4, (0, ssi_sdk_core_1.downloadImage)(image)];
116
120
  case 2:
117
- if (!((_a.sent()) && downloadedImage)) return [3, 4];
118
- return [4, (0, ssi_sdk_core_1.getImageDimensions)(downloadedImage.base64Content)];
121
+ downloadedImage = _a.sent();
122
+ if (downloadedImage) {
123
+ return [2, (0, ssi_sdk_core_1.getImageDimensions)(downloadedImage.base64Content)];
124
+ }
125
+ return [3, 4];
119
126
  case 3:
120
- imageSize = _a.sent();
127
+ if (ui_components_core_1.IS_IMAGE_URI_REGEX.test(image)) {
128
+ return [2, (0, ssi_sdk_core_1.getImageDimensions)(image.split('base64,')[1])];
129
+ }
121
130
  _a.label = 4;
122
- case 4: return [2, imageSize];
131
+ case 4: return [2];
123
132
  }
124
133
  });
125
134
  }); };
126
- var toCredentialDetailsRow = function (object, subject, issuer) { return __awaiter(void 0, void 0, void 0, function () {
127
- var rows, _i, _a, _b, key, value, image, _c, _d, _e, _f, label, contacts, _g, _h;
128
- var _j, _k;
129
- return __generator(this, function (_l) {
130
- switch (_l.label) {
131
- case 0:
132
- rows = [];
133
- _i = 0, _a = Object.entries(object);
134
- _l.label = 1;
135
- case 1:
136
- if (!(_i < _a.length)) return [3, 9];
137
- _b = _a[_i], key = _b[0], value = _b[1];
138
- if (!key.toLowerCase().includes('image')) return [3, 3];
139
- image = typeof value === 'string' ? value : value.id;
140
- _d = (_c = rows).push;
141
- _j = {
142
- id: (0, uuid_1.v4)(),
143
- label: 'image',
144
- value: image
145
- };
146
- return [4, getImageSize(image)];
147
- case 2:
148
- _d.apply(_c, [(_j.imageSize = _l.sent(),
149
- _j)]);
150
- return [3, 8];
151
- case 3:
152
- if (key === 'type') {
135
+ var toCredentialDetailsRow = function (_a) {
136
+ var object = _a.object, subject = _a.subject, issuer = _a.issuer;
137
+ return __awaiter(void 0, void 0, void 0, function () {
138
+ var rows, _i, _b, _c, key, value, _d, _e, label, contacts, imageSize, _f;
139
+ return __generator(this, function (_g) {
140
+ switch (_g.label) {
141
+ case 0:
142
+ rows = [];
143
+ if (!object) {
144
+ return [2, rows];
145
+ }
146
+ _i = 0, _b = Object.entries(object);
147
+ _g.label = 1;
148
+ case 1:
149
+ if (!(_i < _b.length)) return [3, 9];
150
+ _c = _b[_i], key = _c[0], value = _c[1];
151
+ if (!key) {
152
+ return [3, 8];
153
+ }
154
+ if (key === 'type') {
155
+ rows.push({
156
+ id: (0, uuid_1.v4)(),
157
+ label: key,
158
+ value: value
159
+ });
160
+ return [3, 8];
161
+ }
162
+ if (!(typeof value === 'object' && value !== null && value !== undefined)) return [3, 3];
163
+ _e = (_d = rows).concat;
164
+ return [4, toCredentialDetailsRow({ object: value, subject: subject, issuer: issuer })];
165
+ case 2:
166
+ rows = _e.apply(_d, [_g.sent()]);
167
+ return [3, 8];
168
+ case 3:
169
+ if (key === '0' || value === undefined || value === null) {
170
+ return [3, 8];
171
+ }
172
+ label = key;
173
+ if (key === 'id' && typeof value === 'string' && value.startsWith('did:')) {
174
+ label = 'subject';
175
+ }
176
+ if (typeof value === 'string' && value.startsWith('did:')) {
177
+ contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
178
+ value = findCorrelationIdName(value, contacts);
179
+ }
180
+ return [4, (0, utils_2.isImageAddress)(value)];
181
+ case 4:
182
+ if (!(_g.sent())) return [3, 6];
183
+ return [4, getImageSize(value)];
184
+ case 5:
185
+ _f = _g.sent();
186
+ return [3, 7];
187
+ case 6:
188
+ _f = undefined;
189
+ _g.label = 7;
190
+ case 7:
191
+ imageSize = _f;
153
192
  rows.push({
154
193
  id: (0, uuid_1.v4)(),
155
- label: key,
156
- value: value
194
+ label: label,
195
+ value: value,
196
+ imageSize: imageSize
157
197
  });
158
- return [3, 8];
159
- }
160
- _l.label = 4;
161
- case 4:
162
- if (!(typeof value !== 'string')) return [3, 6];
163
- _f = (_e = rows).concat;
164
- return [4, toCredentialDetailsRow(value, subject, issuer)];
165
- case 5:
166
- rows = _f.apply(_e, [_l.sent()]);
167
- return [3, 8];
168
- case 6:
169
- if (key === '0' || value === undefined) {
170
- return [3, 8];
171
- }
172
- label = key;
173
- if (key === 'id' && value.startsWith('did:')) {
174
- label = 'subject';
175
- }
176
- if (value.startsWith('did:')) {
177
- contacts = __spreadArray(__spreadArray([], (issuer ? [issuer] : []), true), (subject ? [subject] : []), true);
178
- value = findCorrelationIdName(value, contacts);
179
- }
180
- _h = (_g = rows).push;
181
- _k = {
182
- id: (0, uuid_1.v4)(),
183
- label: label,
184
- value: value
185
- };
186
- return [4, getImageSize(value)];
187
- case 7:
188
- _h.apply(_g, [(_k.imageSize = _l.sent(),
189
- _k)]);
190
- _l.label = 8;
191
- case 8:
192
- _i++;
193
- return [3, 1];
194
- case 9: return [2, rows];
195
- }
198
+ _g.label = 8;
199
+ case 8:
200
+ _i++;
201
+ return [3, 1];
202
+ case 9: return [2, rows];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ var toNonPersistedCredentialSummary = function (_a) {
208
+ var verifiableCredential = _a.verifiableCredential, credentialRole = _a.credentialRole, branding = _a.branding, issuer = _a.issuer, subject = _a.subject;
209
+ return (0, exports.toCredentialSummary)({
210
+ verifiableCredential: verifiableCredential,
211
+ hash: (0, utils_1.computeEntryHash)(verifiableCredential),
212
+ credentialRole: credentialRole,
213
+ branding: branding,
214
+ issuer: issuer,
215
+ subject: subject
196
216
  });
197
- }); };
198
- var toNonPersistedCredentialSummary = function (verifiableCredential, credentialRole, branding, issuer, subject) {
199
- return (0, exports.toCredentialSummary)(verifiableCredential, (0, utils_1.computeEntryHash)(verifiableCredential), credentialRole, branding, issuer, subject);
200
217
  };
201
218
  exports.toNonPersistedCredentialSummary = toNonPersistedCredentialSummary;
202
219
  var getDate = function () {
@@ -236,9 +253,7 @@ exports.getCredentialDisplayName = getCredentialDisplayName;
236
253
  var getCredentialIssuerNameAndAlias = function (_a) {
237
254
  var _b;
238
255
  var verifiableCredential = _a.verifiableCredential, issuer = _a.issuer;
239
- var issuerName = typeof verifiableCredential.issuer === 'string'
240
- ? verifiableCredential.issuer
241
- : (_b = verifiableCredential.issuer) === null || _b === void 0 ? void 0 : _b.id;
256
+ var issuerName = typeof verifiableCredential.issuer === 'string' ? verifiableCredential.issuer : (_b = verifiableCredential.issuer) === null || _b === void 0 ? void 0 : _b.id;
242
257
  var issuerAlias = undefined;
243
258
  if (typeof (verifiableCredential === null || verifiableCredential === void 0 ? void 0 : verifiableCredential.issuer) === 'object') {
244
259
  issuerAlias = verifiableCredential.issuer.name;
@@ -264,47 +279,54 @@ var getTermsOfUse = function (_a) {
264
279
  return __assign((_a = {}, _a[type] = id, _a), rest);
265
280
  });
266
281
  };
267
- var toCredentialSummary = function (verifiableCredential, hash, credentialRole, branding, issuer, subject) { return __awaiter(void 0, void 0, void 0, function () {
268
- var expirationDate, issueDate, localeBranding, credentialStatus, title, properties, logo, url, _a, issuerName, issuerAlias, termsOfUse;
269
- var _b, _c;
270
- return __generator(this, function (_d) {
271
- switch (_d.label) {
272
- case 0:
273
- expirationDate = (_b = (0, exports.getDate)(verifiableCredential.expirationDate, verifiableCredential.validTo, verifiableCredential.exp)) !== null && _b !== void 0 ? _b : 0;
274
- issueDate = (0, exports.getDate)(verifiableCredential.issuanceDate, verifiableCredential.validFrom, verifiableCredential.nbf, verifiableCredential.iat);
275
- return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
276
- case 1:
277
- localeBranding = _d.sent();
278
- credentialStatus = (0, utils_2.getCredentialStatus)(verifiableCredential);
279
- title = (0, exports.getCredentialDisplayName)({ verifiableCredential: verifiableCredential, localeBranding: localeBranding });
280
- return [4, toCredentialDetailsRow(__assign(__assign({}, (_c = verifiableCredential.vc) === null || _c === void 0 ? void 0 : _c.credentialSubject), verifiableCredential.credentialSubject), subject, issuer)];
281
- case 2:
282
- properties = _d.sent();
283
- logo = (0, utils_2.getIssuerLogo)(verifiableCredential, localeBranding);
284
- url = typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
285
- _a = (0, exports.getCredentialIssuerNameAndAlias)({ verifiableCredential: verifiableCredential, issuer: issuer }), issuerName = _a.issuerName, issuerAlias = _a.issuerAlias;
286
- termsOfUse = getTermsOfUse({ verifiableCredential: verifiableCredential });
287
- return [2, {
288
- hash: hash,
289
- id: verifiableCredential.id,
290
- title: title,
291
- credentialStatus: credentialStatus,
292
- credentialRole: credentialRole,
293
- issueDate: issueDate,
294
- expirationDate: expirationDate,
295
- properties: properties,
296
- branding: localeBranding,
297
- termsOfUse: termsOfUse,
298
- issuer: {
299
- name: issuerName,
300
- alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
301
- image: logo,
302
- url: url
303
- }
304
- }];
305
- }
282
+ var toCredentialSummary = function (_a) {
283
+ var verifiableCredential = _a.verifiableCredential, hash = _a.hash, credentialRole = _a.credentialRole, branding = _a.branding, issuer = _a.issuer, subject = _a.subject;
284
+ return __awaiter(void 0, void 0, void 0, function () {
285
+ var expirationDate, issueDate, localeBranding, credentialStatus, title, properties, logo, url, _b, issuerName, issuerAlias, termsOfUse;
286
+ var _c, _d;
287
+ return __generator(this, function (_e) {
288
+ switch (_e.label) {
289
+ case 0:
290
+ expirationDate = (_c = (0, exports.getDate)(verifiableCredential.expirationDate, verifiableCredential.validTo, verifiableCredential.exp)) !== null && _c !== void 0 ? _c : 0;
291
+ issueDate = (0, exports.getDate)(verifiableCredential.issuanceDate, verifiableCredential.validFrom, verifiableCredential.nbf, verifiableCredential.iat);
292
+ return [4, (0, exports.selectAppLocaleBranding)({ localeBranding: branding })];
293
+ case 1:
294
+ localeBranding = _e.sent();
295
+ credentialStatus = (0, utils_2.getCredentialStatus)(verifiableCredential);
296
+ title = (0, exports.getCredentialDisplayName)({ verifiableCredential: verifiableCredential, localeBranding: localeBranding });
297
+ return [4, toCredentialDetailsRow({
298
+ object: __assign(__assign({}, (_d = verifiableCredential.vc) === null || _d === void 0 ? void 0 : _d.credentialSubject), verifiableCredential.credentialSubject),
299
+ subject: subject,
300
+ issuer: issuer
301
+ })];
302
+ case 2:
303
+ properties = _e.sent();
304
+ logo = (0, utils_2.getIssuerLogo)(verifiableCredential, localeBranding);
305
+ url = verifiableCredential.issuer && typeof verifiableCredential.issuer !== 'string' ? verifiableCredential.issuer.url : undefined;
306
+ _b = (0, exports.getCredentialIssuerNameAndAlias)({ verifiableCredential: verifiableCredential, issuer: issuer }), issuerName = _b.issuerName, issuerAlias = _b.issuerAlias;
307
+ termsOfUse = getTermsOfUse({ verifiableCredential: verifiableCredential });
308
+ return [2, {
309
+ hash: hash,
310
+ id: verifiableCredential.id,
311
+ title: title,
312
+ credentialStatus: credentialStatus,
313
+ credentialRole: credentialRole,
314
+ issueDate: issueDate,
315
+ expirationDate: expirationDate,
316
+ properties: properties,
317
+ branding: localeBranding,
318
+ termsOfUse: termsOfUse,
319
+ issuer: {
320
+ name: issuerName,
321
+ alias: issuerAlias ? (issuerAlias.length > 50 ? "".concat(issuerAlias.substring(0, 50), "...") : issuerAlias) : '',
322
+ image: logo,
323
+ url: url
324
+ }
325
+ }];
326
+ }
327
+ });
306
328
  });
307
- }); };
329
+ };
308
330
  exports.toCredentialSummary = toCredentialSummary;
309
331
  var selectAppLocaleBranding = function (args) { return __awaiter(void 0, void 0, void 0, function () {
310
332
  var appLocale, localeBranding, logo, imagePreloader, ReactNativeImagePreloader, WebImagePreloader, backgroundImage;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sphereon/ui-components.credential-branding",
3
3
  "private": false,
4
- "version": "0.2.1-unstable.97+d6159f8",
4
+ "version": "0.3.1-next.14+a2c5adf",
5
5
  "description": "SSI UI components credential branding",
6
6
  "repository": "git@github.com:Sphereon-Opensource/UI-Components.git",
7
7
  "author": "Sphereon <dev@sphereon.com>",
@@ -28,10 +28,10 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@sphereon/ssi-sdk.core": "0.28.1-next.39",
32
- "@sphereon/ssi-sdk.data-store": "0.28.1-next.39",
33
- "@sphereon/ssi-types": "0.28.1-next.39",
34
- "@sphereon/ui-components.core": "0.2.1-unstable.97+d6159f8",
31
+ "@sphereon/ssi-sdk.core": "0.29.0",
32
+ "@sphereon/ssi-sdk.data-store": "0.29.0",
33
+ "@sphereon/ssi-types": "0.29.0",
34
+ "@sphereon/ui-components.core": "0.3.1-next.14+a2c5adf",
35
35
  "@veramo/core": "4.2.0",
36
36
  "@veramo/utils": "4.2.0",
37
37
  "i18n-js": "^3.8.0",
@@ -39,14 +39,17 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/i18n-js": "^3.8.4",
42
+ "@types/jest": "^29.5.12",
42
43
  "@types/node": "^20.4.0",
43
- "@types/react": "~18.2.67",
44
+ "@types/react": "~18.2.79",
44
45
  "@types/uuid": "^9.0.8",
46
+ "jest": "^29.7.0",
45
47
  "react": "18.2.0",
48
+ "ts-jest": "^29.2.5",
46
49
  "typescript": "4.9.5"
47
50
  },
48
51
  "peerDependencies": {
49
52
  "react": ">= 18"
50
53
  },
51
- "gitHead": "d6159f8321e6f081a83d11c895e607100e6e08bd"
54
+ "gitHead": "a2c5adfd01626310b0585f531315024ef5b7e1b1"
52
55
  }