vet-sdk-core-ts 0.4.41 → 0.4.43

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 CHANGED
@@ -7,15 +7,13 @@ An animal is the first member of its own Individual Organization, so
7
7
  human that creates it is `Organization.owner`, the controller by default;
8
8
  `RESPRSN` must never be copied into the animal member.
9
9
 
10
- Usual name, birth date, exact NCBI species and optional breed are animal
11
- demographics. The usual name may be supplied by the controller or generated as
12
- a pronounceable species ordinal such as `Dog 1`; it is not identity evidence.
13
- Breed remains separate descriptive text. Controller-authored
10
+ Name, birth date, exact NCBI species and optional breed are animal
11
+ demographics. Breed remains separate descriptive text. Controller-authored
14
12
  demographics remain editable until a veterinarian attests them; attestation
15
13
  does not rewrite the original author, and later correction creates a new
16
14
  veterinarian-authored version.
17
15
 
18
- Use `buildVetChainAnimalDraftClaims(...)` while the generated/supplied usual name, exact NCBI species or
16
+ Use `buildVetChainAnimalDraftClaims(...)` while the name, exact NCBI species or
19
17
  public Card is missing. Only a draft for which
20
18
  `readVetChainAnimalOnboardingReadiness(...)` returns `ready: true` may be
21
19
  activated and issued a Card. See
@@ -32,8 +30,10 @@ Development and releases follow the mandatory
32
30
  Browser-safe VetChain domain contracts. This repository is independent from
33
31
  UHC SDK packages and must not import them.
34
32
 
35
- The SDK consumes governed browser-safe values from `vet-data-utils-ts` and
36
- owns gateway request construction. GW VET remains the policy authority.
33
+ The SDK consumes governed browser-safe values from `vet-data-utils-ts` and the
34
+ product-neutral Task, subject-card index and emergency record contracts from
35
+ `sos-data-utils-ts`. It owns veterinary orchestration and gateway request
36
+ construction. GW VET remains the policy authority.
37
37
 
38
38
  `vet-sdk-core-ts/health-dcat` provides the neutral manager for tenant-owned
39
39
  HealthDCAT metadata. It publishes and searches claims-first resources, asks an
@@ -1,6 +1,7 @@
1
1
  // Copyright 2026 Connecting Solution & Applications Ltd under the Apache License, Version 2.0.
2
2
  import { sha3_256 } from "@noble/hashes/sha3.js";
3
3
  import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
4
+ import { normalizeSubjectSpeciesId7 } from "sos-data-utils-ts/subject-card-index";
4
5
  export const AnimalIdentityEvidenceSystems = Object.freeze({
5
6
  UsdaAin: "usda-ain",
6
7
  CfiaIso11784: "cfia-iso-11784",
@@ -28,17 +29,11 @@ const DAMM_TABLE = Object.freeze([
28
29
  * projection, never an organization fiscal identifier.
29
30
  */
30
31
  export function buildSpeciesId7(ncbiTaxonomyId) {
31
- const source = String(ncbiTaxonomyId || "").trim();
32
- if (!/^\d{1,7}$/.test(source)) {
33
- throw new TypeError("NCBI Taxonomy identifier must contain at most seven digits.");
34
- }
35
- const normalized = source.replace(/^0+/, "") || "0";
36
- if (normalized === "9606") {
32
+ const speciesId7 = normalizeSubjectSpeciesId7(ncbiTaxonomyId);
33
+ if (speciesId7 === "0009606") {
37
34
  throw new TypeError("Human NCBI Taxonomy identifier 9606 is not valid for a VetChain animal.");
38
35
  }
39
- if (normalized === "0")
40
- throw new TypeError("NCBI Taxonomy identifier must be positive.");
41
- return normalized.padStart(7, "0");
36
+ return speciesId7;
42
37
  }
43
38
  /** Country3 plus immutable birth/initial-registration region2. */
44
39
  export function normalizeJurisdictionCode5(value) {
@@ -1,50 +1,3 @@
1
- /**
2
- * Channel-neutral form contract for animal demographics.
3
- *
4
- * Voice, chat and portal navigation may render this schema differently, but
5
- * they must not redefine required fields or post-activation mutability.
6
- */
7
- export declare const VETCHAIN_ANIMAL_DEMOGRAPHICS_SCHEMA: Readonly<{
8
- readonly $schema: "https://json-schema.org/draft/2020-12/schema";
9
- readonly $id: "https://vetchain.org/schemas/animal-demographics/v1";
10
- readonly type: "object";
11
- readonly additionalProperties: false;
12
- readonly properties: Readonly<{
13
- usualName: Readonly<{
14
- type: "string";
15
- maxLength: 200;
16
- 'x-vetchain-claim': "org.schema.Organization.alternateName";
17
- 'x-vetchain-auto-generated': true;
18
- 'x-vetchain-mutable-until-attested': true;
19
- }>;
20
- birthDate: Readonly<{
21
- type: "string";
22
- pattern: "^\\d{4}(?:-(?:0[1-9]|1[0-2])(?:-(?:0[1-9]|[12]\\d|3[01]))?)?$";
23
- 'x-vetchain-claim': "org.schema.Organization.member.birthDate";
24
- 'x-vetchain-mutable-until-attested': true;
25
- }>;
26
- species: Readonly<{
27
- type: "string";
28
- pattern: "^[1-9]\\d*$";
29
- not: Readonly<{
30
- const: "9606";
31
- }>;
32
- 'x-vetchain-claim': "org.schema.Organization.member.additionalType";
33
- 'x-vetchain-immutable-after-activation': true;
34
- }>;
35
- }>;
36
- readonly required: readonly string[];
37
- }>;
38
- /**
39
- * Returns the controller-supplied usual name or a stable, pronounceable
40
- * English fallback such as `Dog 1`. The ordinal is allocated durably by the
41
- * owning BFF; this pure helper never counts records or exposes a private UUID.
42
- */
43
- export declare function resolveVetChainAnimalUsualName(input: Readonly<{
44
- usualName?: string;
45
- ncbiTaxonomyId: string;
46
- ordinal: number;
47
- }>): string;
48
1
  /** Canonical member relationship for the animal SELF subject. */
49
2
  export declare const VetChainAnimalMemberRoles: Readonly<{
50
3
  readonly Self: "ONESELF";
@@ -1,55 +1,6 @@
1
1
  import { parseVetChainAnimalCardDid } from 'vet-data-utils-ts';
2
2
  import { buildAnimalIdentifier16, buildSpeciesId7 } from './animal-identity.js';
3
3
  import { normalizeVetChainNcbiTaxonomyId } from './card-issuance.js';
4
- import { findVetChainSpeciesByTaxonomyId } from './species.js';
5
- /**
6
- * Channel-neutral form contract for animal demographics.
7
- *
8
- * Voice, chat and portal navigation may render this schema differently, but
9
- * they must not redefine required fields or post-activation mutability.
10
- */
11
- export const VETCHAIN_ANIMAL_DEMOGRAPHICS_SCHEMA = Object.freeze({
12
- $schema: 'https://json-schema.org/draft/2020-12/schema',
13
- $id: 'https://vetchain.org/schemas/animal-demographics/v1',
14
- type: 'object',
15
- additionalProperties: false,
16
- properties: Object.freeze({
17
- usualName: Object.freeze({
18
- type: 'string', maxLength: 200,
19
- 'x-vetchain-claim': 'org.schema.Organization.alternateName',
20
- 'x-vetchain-auto-generated': true,
21
- 'x-vetchain-mutable-until-attested': true,
22
- }),
23
- birthDate: Object.freeze({
24
- type: 'string', pattern: '^\\d{4}(?:-(?:0[1-9]|1[0-2])(?:-(?:0[1-9]|[12]\\d|3[01]))?)?$',
25
- 'x-vetchain-claim': 'org.schema.Organization.member.birthDate',
26
- 'x-vetchain-mutable-until-attested': true,
27
- }),
28
- species: Object.freeze({
29
- type: 'string', pattern: '^[1-9]\\d*$', not: Object.freeze({ const: '9606' }),
30
- 'x-vetchain-claim': 'org.schema.Organization.member.additionalType',
31
- 'x-vetchain-immutable-after-activation': true,
32
- }),
33
- }),
34
- required: Object.freeze(['species']),
35
- });
36
- /**
37
- * Returns the controller-supplied usual name or a stable, pronounceable
38
- * English fallback such as `Dog 1`. The ordinal is allocated durably by the
39
- * owning BFF; this pure helper never counts records or exposes a private UUID.
40
- */
41
- export function resolveVetChainAnimalUsualName(input) {
42
- const supplied = String(input.usualName || '').trim();
43
- if (supplied)
44
- return supplied;
45
- if (!Number.isSafeInteger(input.ordinal) || input.ordinal < 1) {
46
- throw new TypeError('vet_animal_usual_name_ordinal_invalid');
47
- }
48
- const taxonomy = normalizeVetChainNcbiTaxonomyId(input.ncbiTaxonomyId);
49
- const species = findVetChainSpeciesByTaxonomyId(taxonomy);
50
- const label = species ? humanizeSpeciesKey(species.key) : 'Animal';
51
- return `${label} ${input.ordinal}`;
52
- }
53
4
  /** Canonical member relationship for the animal SELF subject. */
54
5
  export const VetChainAnimalMemberRoles = Object.freeze({ Self: 'ONESELF' });
55
6
  /** Canonical schema.org claim names for the VetChain animal registration. */
@@ -185,6 +136,3 @@ function required(value, error) {
185
136
  throw new TypeError(error);
186
137
  return normalized;
187
138
  }
188
- function humanizeSpeciesKey(value) {
189
- return value.replace(/([a-z0-9])([A-Z])/g, '$1 $2').trim();
190
- }
@@ -2,7 +2,8 @@ export type VetChainIssuedAnimalCard = Readonly<{
2
2
  providerCode9: string;
3
3
  jurisdictionCode5: string;
4
4
  ncbiTaxonomyId: string;
5
- speciesCode5: string;
5
+ /** Separate checksum/hash context; never embedded in cardNumber21. */
6
+ speciesId7: string;
6
7
  animalNumericId15: string;
7
8
  animalId16: string;
8
9
  cardNumber21: string;
@@ -8,7 +8,7 @@ export function issueVetChainAnimalCard(input) {
8
8
  const providerCode9 = digits(input.providerCode9, 9, 'vet_card_provider_code_invalid');
9
9
  const jurisdictionCode5 = providerCode9.slice(0, 5);
10
10
  const ncbiTaxonomyId = taxonomy(input.ncbiTaxonomyId);
11
- const speciesCode5 = ncbiTaxonomyId.padStart(5, '0');
11
+ const speciesId7 = buildSpeciesId7(ncbiTaxonomyId);
12
12
  const subjectUuid = String(input.subjectUuid || '').trim().toLowerCase().replace(/[{}]/g, '');
13
13
  if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(subjectUuid)) {
14
14
  throw new TypeError('vet_card_subject_uuid_invalid');
@@ -24,7 +24,7 @@ export function issueVetChainAnimalCard(input) {
24
24
  ].join(':')));
25
25
  const animalNumericId15 = `000${reduceDigestToDecimalDigits(digest, 12)}`;
26
26
  const animalId16 = buildAnimalIdentifier16({
27
- speciesId7: buildSpeciesId7(ncbiTaxonomyId),
27
+ speciesId7,
28
28
  jurisdictionCode5,
29
29
  animalNumericId15,
30
30
  });
@@ -34,14 +34,14 @@ export function issueVetChainAnimalCard(input) {
34
34
  throw new TypeError('vet_card_host_invalid');
35
35
  const cardDidWeb = `did:web:${host.replace(':', '%3A')}:card:vetchain:${jurisdictionCode5}:${animalId16}`;
36
36
  parseVetChainAnimalCardDid(cardDidWeb);
37
- return Object.freeze({ providerCode9, jurisdictionCode5, ncbiTaxonomyId, speciesCode5, animalNumericId15, animalId16, cardNumber21, cardDidWeb });
37
+ return Object.freeze({ providerCode9, jurisdictionCode5, ncbiTaxonomyId, speciesId7, animalNumericId15, animalId16, cardNumber21, cardDidWeb });
38
38
  }
39
39
  export function normalizeVetChainNcbiTaxonomyId(value) {
40
40
  return taxonomy(value);
41
41
  }
42
42
  function taxonomy(value) {
43
43
  const normalized = String(value || '').trim();
44
- if (!/^[1-9]\d{0,4}$/.test(normalized) || normalized === '9606')
44
+ if (!/^[1-9]\d{0,6}$/.test(normalized) || normalized === '9606')
45
45
  throw new TypeError('vet_card_taxonomy_invalid');
46
46
  return normalized;
47
47
  }
@@ -40,8 +40,7 @@ readVetChainAnimalOnboardingReadiness(draft)
40
40
  // { ready: false, missing: ['alternateName', 'species', 'card'] }
41
41
  ```
42
42
 
43
- The BFF later rebuilds the same subject draft with its supplied usual name or a
44
- durably numbered species fallback such as `Dog 1`, plus its exact NCBI
43
+ The BFF later rebuilds the same subject draft with its name and exact NCBI
45
44
  taxonomy, issues the public Card, and resubmits it under the same private
46
45
  `subjectId`. GW VET alone performs the `pending -> active` transition. A draft
47
46
  does not need a clinical `Composition`; the active clinical index is a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vet-sdk-core-ts",
3
- "version": "0.4.41",
3
+ "version": "0.4.43",
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",
@@ -89,6 +89,7 @@
89
89
  "@noble/hashes": "^2.2.0",
90
90
  "@noble/post-quantum": "0.5.4",
91
91
  "gdc-common-utils-ts": "2.9.10",
92
+ "sos-data-utils-ts": "0.3.0",
92
93
  "vet-data-utils-ts": "0.5.28"
93
94
  }
94
95
  }