vet-sdk-core-ts 0.4.1 → 0.4.2
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/animal-onboarding.d.ts +36 -0
- package/dist/animal-onboarding.js +66 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type VetChainAnimalOnboardingInput = Readonly<{
|
|
2
|
+
subjectId: string;
|
|
3
|
+
cardDidWeb: string;
|
|
4
|
+
alternateName: string;
|
|
5
|
+
legalName?: string;
|
|
6
|
+
birthDate?: string;
|
|
7
|
+
birthYear?: number;
|
|
8
|
+
gender?: 'female' | 'male' | 'other' | 'unknown';
|
|
9
|
+
ncbiTaxonomyId: string;
|
|
10
|
+
controllerEmail?: string;
|
|
11
|
+
controllerTelephone?: string;
|
|
12
|
+
sector?: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** Canonical schema.org claim names for the VetChain animal registration. */
|
|
15
|
+
export declare const VetChainAnimalOnboardingClaimNames: Readonly<{
|
|
16
|
+
readonly identifierValue: "org.schema.Organization.identifier.value";
|
|
17
|
+
readonly additionalType: "org.schema.Organization.additionalType";
|
|
18
|
+
readonly alternateName: "org.schema.Organization.alternateName";
|
|
19
|
+
readonly legalName: "org.schema.Organization.legalName";
|
|
20
|
+
readonly sameAs: "org.schema.Organization.sameAs";
|
|
21
|
+
readonly memberName: "org.schema.Organization.member.name";
|
|
22
|
+
readonly memberAdditionalType: "org.schema.Organization.member.additionalType";
|
|
23
|
+
readonly memberBirthDate: "org.schema.Organization.member.birthDate";
|
|
24
|
+
readonly memberGender: "org.schema.Organization.member.gender";
|
|
25
|
+
readonly memberRole: "org.schema.Organization.member.role";
|
|
26
|
+
readonly ownerEmail: "org.schema.Organization.owner.email";
|
|
27
|
+
readonly ownerTelephone: "org.schema.Organization.owner.telephone";
|
|
28
|
+
readonly serviceCategory: "org.schema.Service.category";
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Projects one controller-authorized animal to the GW Organization envelope.
|
|
32
|
+
*
|
|
33
|
+
* Species remains separate governed metadata. It validates the Damm digit with
|
|
34
|
+
* jurisdiction and animalNumericId15 but is never decoded from cardNumber21.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildVetChainAnimalOnboardingClaims(input: VetChainAnimalOnboardingInput): Readonly<Record<string, string>>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { parseVetChainAnimalCardDid } from 'vet-data-utils-ts';
|
|
2
|
+
import { buildAnimalIdentifier16, buildSpeciesId7 } from './animal-identity.js';
|
|
3
|
+
import { normalizeVetChainNcbiTaxonomyId } from './card-issuance.js';
|
|
4
|
+
/** Canonical schema.org claim names for the VetChain animal registration. */
|
|
5
|
+
export const VetChainAnimalOnboardingClaimNames = Object.freeze({
|
|
6
|
+
identifierValue: 'org.schema.Organization.identifier.value',
|
|
7
|
+
additionalType: 'org.schema.Organization.additionalType',
|
|
8
|
+
alternateName: 'org.schema.Organization.alternateName',
|
|
9
|
+
legalName: 'org.schema.Organization.legalName',
|
|
10
|
+
sameAs: 'org.schema.Organization.sameAs',
|
|
11
|
+
memberName: 'org.schema.Organization.member.name',
|
|
12
|
+
memberAdditionalType: 'org.schema.Organization.member.additionalType',
|
|
13
|
+
memberBirthDate: 'org.schema.Organization.member.birthDate',
|
|
14
|
+
memberGender: 'org.schema.Organization.member.gender',
|
|
15
|
+
memberRole: 'org.schema.Organization.member.role',
|
|
16
|
+
ownerEmail: 'org.schema.Organization.owner.email',
|
|
17
|
+
ownerTelephone: 'org.schema.Organization.owner.telephone',
|
|
18
|
+
serviceCategory: 'org.schema.Service.category',
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Projects one controller-authorized animal to the GW Organization envelope.
|
|
22
|
+
*
|
|
23
|
+
* Species remains separate governed metadata. It validates the Damm digit with
|
|
24
|
+
* jurisdiction and animalNumericId15 but is never decoded from cardNumber21.
|
|
25
|
+
*/
|
|
26
|
+
export function buildVetChainAnimalOnboardingClaims(input) {
|
|
27
|
+
const subjectId = required(input.subjectId, 'vet_animal_subject_id_invalid');
|
|
28
|
+
const alternateName = required(input.alternateName, 'vet_animal_name_invalid');
|
|
29
|
+
const card = parseVetChainAnimalCardDid(input.cardDidWeb);
|
|
30
|
+
const ncbiTaxonomyId = normalizeVetChainNcbiTaxonomyId(input.ncbiTaxonomyId);
|
|
31
|
+
const expectedAnimalId16 = buildAnimalIdentifier16({
|
|
32
|
+
speciesId7: buildSpeciesId7(ncbiTaxonomyId),
|
|
33
|
+
jurisdictionCode5: card.jurisdictionCode5,
|
|
34
|
+
animalNumericId15: card.animalNumericId15,
|
|
35
|
+
});
|
|
36
|
+
if (expectedAnimalId16 !== card.animalId16) {
|
|
37
|
+
throw new TypeError('vet_animal_card_species_checksum_invalid');
|
|
38
|
+
}
|
|
39
|
+
const birthDate = String(input.birthDate || '').trim()
|
|
40
|
+
|| (Number.isInteger(input.birthYear) ? String(input.birthYear) : '');
|
|
41
|
+
const legalName = String(input.legalName || '').trim();
|
|
42
|
+
const gender = input.gender && input.gender !== 'unknown' ? input.gender : '';
|
|
43
|
+
const claim = VetChainAnimalOnboardingClaimNames;
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
'@context': 'org.schema',
|
|
46
|
+
[claim.identifierValue]: subjectId,
|
|
47
|
+
[claim.additionalType]: 'animal',
|
|
48
|
+
[claim.alternateName]: alternateName,
|
|
49
|
+
...(legalName ? { [claim.legalName]: legalName } : {}),
|
|
50
|
+
[claim.sameAs]: card.did,
|
|
51
|
+
[claim.memberName]: alternateName,
|
|
52
|
+
[claim.memberAdditionalType]: `http://purl.obolibrary.org/obo/NCBITaxon_${ncbiTaxonomyId}`,
|
|
53
|
+
[claim.memberRole]: 'RESPRSN',
|
|
54
|
+
...(birthDate ? { [claim.memberBirthDate]: birthDate } : {}),
|
|
55
|
+
...(gender ? { [claim.memberGender]: gender } : {}),
|
|
56
|
+
[claim.ownerEmail]: String(input.controllerEmail || '').trim(),
|
|
57
|
+
[claim.ownerTelephone]: String(input.controllerTelephone || '').trim(),
|
|
58
|
+
[claim.serviceCategory]: String(input.sector || '').trim() || 'animal-care',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function required(value, error) {
|
|
62
|
+
const normalized = String(value || '').trim();
|
|
63
|
+
if (!normalized)
|
|
64
|
+
throw new TypeError(error);
|
|
65
|
+
return normalized;
|
|
66
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vet-sdk-core-ts",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Browser-safe VetChain core contracts and governed animal species identifiers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Connecting Solution & Applications Ltd",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
"./card-issuance": {
|
|
28
28
|
"types": "./dist/card-issuance.d.ts",
|
|
29
29
|
"default": "./dist/card-issuance.js"
|
|
30
|
+
},
|
|
31
|
+
"./animal-onboarding": {
|
|
32
|
+
"types": "./dist/animal-onboarding.d.ts",
|
|
33
|
+
"default": "./dist/animal-onboarding.js"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"files": [
|