@oxyhq/core 3.11.0 → 3.13.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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/crypto/signatureService.js +88 -2
- package/dist/cjs/index.js +19 -4
- package/dist/cjs/mixins/OxyServices.civic.js +611 -0
- package/dist/cjs/mixins/index.js +3 -0
- package/dist/cjs/utils/profileLinks.js +63 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/crypto/signatureService.js +87 -2
- package/dist/esm/index.js +11 -1
- package/dist/esm/mixins/OxyServices.civic.js +605 -0
- package/dist/esm/mixins/index.js +3 -0
- package/dist/esm/utils/profileLinks.js +60 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/crypto/signatureService.d.ts +54 -3
- package/dist/types/index.d.ts +5 -1
- package/dist/types/mixins/OxyServices.civic.d.ts +512 -0
- package/dist/types/mixins/index.d.ts +2 -1
- package/dist/types/utils/profileLinks.d.ts +44 -0
- package/package.json +2 -2
- package/src/crypto/__tests__/signedRecord.test.ts +221 -1
- package/src/crypto/signatureService.ts +102 -3
- package/src/index.ts +29 -1
- package/src/mixins/OxyServices.civic.ts +956 -0
- package/src/mixins/__tests__/OxyServices.civic.test.ts +1097 -0
- package/src/mixins/index.ts +4 -0
- package/src/utils/__tests__/profileLinks.test.ts +180 -0
- package/src/utils/profileLinks.ts +91 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeProfileLinks = normalizeProfileLinks;
|
|
4
|
+
function cleanUrl(value) {
|
|
5
|
+
if (typeof value !== 'string')
|
|
6
|
+
return null;
|
|
7
|
+
const trimmed = value.trim();
|
|
8
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Normalizes a user's profile links into a clean display shape.
|
|
12
|
+
*
|
|
13
|
+
* Pure, no side effects, no I/O.
|
|
14
|
+
*
|
|
15
|
+
* - Prefers `linksMetadata` when it is a non-empty array: maps each entry to
|
|
16
|
+
* `{ id, title, url, description, image }`, using `entry.id` when present and
|
|
17
|
+
* falling back to the entry index. `title`, `description`, and `image` are
|
|
18
|
+
* carried through only when they are present strings. Entries without a
|
|
19
|
+
* non-empty string `url` are dropped.
|
|
20
|
+
* - Otherwise falls back to the legacy `links` string array: maps each string to
|
|
21
|
+
* `{ id: <index>, url }` (no title/description/image). Empty/non-string values
|
|
22
|
+
* are dropped.
|
|
23
|
+
* - Returns `[]` when both are absent or empty (including when `linksMetadata`
|
|
24
|
+
* is present but every entry is dropped — it does NOT fall back to `links`).
|
|
25
|
+
*
|
|
26
|
+
* URLs are trimmed and blanks are filtered out. This does NOT add a scheme such
|
|
27
|
+
* as `https://`; prefixing is a display concern left to the caller.
|
|
28
|
+
*/
|
|
29
|
+
function normalizeProfileLinks(linksMetadata, links) {
|
|
30
|
+
if (Array.isArray(linksMetadata) && linksMetadata.length > 0) {
|
|
31
|
+
const result = [];
|
|
32
|
+
linksMetadata.forEach((entry, index) => {
|
|
33
|
+
const url = cleanUrl(entry?.url);
|
|
34
|
+
if (!url)
|
|
35
|
+
return;
|
|
36
|
+
const id = typeof entry?.id === 'string' && entry.id.trim().length > 0
|
|
37
|
+
? entry.id
|
|
38
|
+
: String(index);
|
|
39
|
+
const title = typeof entry?.title === 'string' ? entry.title : undefined;
|
|
40
|
+
const description = typeof entry?.description === 'string' ? entry.description : undefined;
|
|
41
|
+
const image = typeof entry?.image === 'string' ? entry.image : undefined;
|
|
42
|
+
result.push({
|
|
43
|
+
id,
|
|
44
|
+
url,
|
|
45
|
+
...(title !== undefined ? { title } : {}),
|
|
46
|
+
...(description !== undefined ? { description } : {}),
|
|
47
|
+
...(image !== undefined ? { image } : {}),
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(links) && links.length > 0) {
|
|
53
|
+
const result = [];
|
|
54
|
+
links.forEach((value, index) => {
|
|
55
|
+
const url = cleanUrl(value);
|
|
56
|
+
if (!url)
|
|
57
|
+
return;
|
|
58
|
+
result.push({ id: String(index), url });
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
return [];
|
|
63
|
+
}
|