@bsv/vsc 0.2.0-beta.1
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/LICENSE +58 -0
- package/README.md +107 -0
- package/artifacts/context-0.1.0.jsonld +127 -0
- package/artifacts/disclosure-0.1.0.schema.json +526 -0
- package/artifacts/epcis/NOTICE.md +11 -0
- package/artifacts/epcis/epcis-context-2.0.1.jsonld +593 -0
- package/artifacts/epcis/epcis-json-schema-2.0.1.json +2352 -0
- package/artifacts/epcis/query-schema-2.0.1.json +968 -0
- package/artifacts/external/NOTICE.md +3 -0
- package/artifacts/external/dpp-external-passport-1.context.jsonld +8 -0
- package/artifacts/external/dpp-external-passport-1.schema.json +158 -0
- package/artifacts/profile-0.1.0.json +100 -0
- package/artifacts/seal-0.1.0.schema.json +535 -0
- package/artifacts/w3c/NOTICE.md +3 -0
- package/artifacts/w3c/credentials-v2.jsonld +340 -0
- package/dist/context.d.ts +9 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +50 -0
- package/dist/context.js.map +1 -0
- package/dist/crypto.d.ts +50 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +141 -0
- package/dist/crypto.js.map +1 -0
- package/dist/did-web.d.ts +9 -0
- package/dist/did-web.d.ts.map +1 -0
- package/dist/did-web.js +66 -0
- package/dist/did-web.js.map +1 -0
- package/dist/epcis-source.d.ts +251 -0
- package/dist/epcis-source.d.ts.map +1 -0
- package/dist/epcis-source.js +573 -0
- package/dist/epcis-source.js.map +1 -0
- package/dist/epcis.d.ts +51 -0
- package/dist/epcis.d.ts.map +1 -0
- package/dist/epcis.js +171 -0
- package/dist/epcis.js.map +1 -0
- package/dist/exchange.d.ts +175 -0
- package/dist/exchange.d.ts.map +1 -0
- package/dist/exchange.js +491 -0
- package/dist/exchange.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/jcs.d.ts +25 -0
- package/dist/jcs.d.ts.map +1 -0
- package/dist/jcs.js +67 -0
- package/dist/jcs.js.map +1 -0
- package/dist/schema.d.ts +414 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +537 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validation.d.ts +22 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +147 -0
- package/dist/validation.js.map +1 -0
- package/dist/verification.d.ts +10 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +350 -0
- package/dist/verification.js.map +1 -0
- package/package.json +68 -0
package/dist/did-web.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { parseStrictJsonBytes } from './validation.js';
|
|
2
|
+
/** Resolve did:web using explicit operator-approved origins, with bounded reads and no redirects. */
|
|
3
|
+
export function createDidWebResolver({ allowedOrigins, fetcher = globalThis.fetch, timeoutMs = 5000, maxBytes = 262144 }) {
|
|
4
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || !Number.isSafeInteger(maxBytes) || maxBytes <= 0 || maxBytes > 1_048_576)
|
|
5
|
+
throw new Error('Invalid DID resolution limits');
|
|
6
|
+
return async (requested) => {
|
|
7
|
+
const [did, fragment, ...extra] = requested.split('#');
|
|
8
|
+
if (!did.startsWith('did:web:') || extra.length)
|
|
9
|
+
throw new Error('Unsupported DID method or DID URL');
|
|
10
|
+
const segments = did.slice('did:web:'.length).split(':').map(s => decodeURIComponent(s));
|
|
11
|
+
const domain = segments.shift();
|
|
12
|
+
if (!domain || /[/?#@\s]/.test(domain) || segments.some(s => !s || s === '.' || s === '..' || /[\\/]/.test(s)))
|
|
13
|
+
throw new Error('Invalid did:web identifier');
|
|
14
|
+
const url = new URL(`https://${domain}/${segments.length ? segments.map(encodeURIComponent).join('/') + '/did.json' : '.well-known/did.json'}`);
|
|
15
|
+
if (!allowedOrigins.includes(url.origin))
|
|
16
|
+
throw new Error('DID origin is not permitted by resolver policy');
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
19
|
+
try {
|
|
20
|
+
const response = await fetcher(url, { signal: controller.signal, redirect: 'error', headers: { accept: 'application/did+ld+json, application/json' } });
|
|
21
|
+
if (!response.ok || !response.body)
|
|
22
|
+
throw new Error('DID document is unavailable');
|
|
23
|
+
const declared = response.headers.get('content-length');
|
|
24
|
+
if (declared && (!/^\d+$/.test(declared) || Number(declared) > maxBytes))
|
|
25
|
+
throw new Error('DID document exceeds the size limit');
|
|
26
|
+
const reader = response.body.getReader(), chunks = [];
|
|
27
|
+
let total = 0;
|
|
28
|
+
try {
|
|
29
|
+
for (;;) {
|
|
30
|
+
const { done, value } = await reader.read();
|
|
31
|
+
if (done)
|
|
32
|
+
break;
|
|
33
|
+
total += value.length;
|
|
34
|
+
if (total > maxBytes)
|
|
35
|
+
throw new Error('DID document exceeds the size limit');
|
|
36
|
+
chunks.push(value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
await reader.cancel();
|
|
41
|
+
}
|
|
42
|
+
const bytes = new Uint8Array(total);
|
|
43
|
+
let position = 0;
|
|
44
|
+
for (const chunk of chunks) {
|
|
45
|
+
bytes.set(chunk, position);
|
|
46
|
+
position += chunk.length;
|
|
47
|
+
}
|
|
48
|
+
const parsed = parseStrictJsonBytes(bytes);
|
|
49
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed) || parsed.id !== did)
|
|
50
|
+
throw new Error('Resolved DID document does not match the requested identifier');
|
|
51
|
+
const document = parsed;
|
|
52
|
+
if (!fragment)
|
|
53
|
+
return { document, documentUrl: requested, contextUrl: null };
|
|
54
|
+
const embedded = ['verificationMethod', 'assertionMethod', 'authentication', 'capabilityInvocation', 'capabilityDelegation', 'keyAgreement']
|
|
55
|
+
.flatMap(term => Array.isArray(document[term]) ? document[term] : [])
|
|
56
|
+
.find(value => value && typeof value === 'object' && value.id === requested);
|
|
57
|
+
if (!embedded)
|
|
58
|
+
throw new Error('Verification method is absent from the DID document');
|
|
59
|
+
return { document: { '@context': document['@context'], ...embedded }, documentUrl: requested, contextUrl: null };
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=did-web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-web.js","sourceRoot":"","sources":["../src/did-web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,qGAAqG;AACrG,MAAM,UAAU,oBAAoB,CAAC,EAAE,cAAc,EAAE,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,QAAQ,GAAG,MAAM,EAErH;IACC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,IAAI,QAAQ,GAAG,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACrL,OAAO,KAAK,EAAC,SAAS,EAAC,EAAE;QACvB,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACtG,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAA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AO,CAAC,MAAM,CAAC,IAAK,MAAqB,CAAC,EAAE,KAAK,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;YAC1L,MAAM,QAAQ,GAAG,MAAoB,CAAC;YACtC,IAAI,CAAC,QAAQ;gBAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;YAC7E,MAAM,QAAQ,GAAG,CAAC,oBAAoB,EAAC,iBAAiB,EAAC,gBAAgB,EAAC,sBAAsB,EAAC,sBAAsB,EAAC,cAAc,CAAC;iBACpI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAc,CAAC,CAAC,CAAC,EAAE,CAAC;iBACjF,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAK,KAAoB,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;YAC/F,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;YACtF,OAAO,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,GAAI,QAAuB,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACnI,CAAC;gBAAS,CAAC;YAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import type { JsonObject, Seal } from './types.js';
|
|
2
|
+
/** The pinned GS1 artefacts this module validates against (artifacts/epcis/NOTICE.md). */
|
|
3
|
+
export declare const EPCIS_ARTEFACTS: readonly [{
|
|
4
|
+
readonly id: "epcis-json-schema";
|
|
5
|
+
readonly kind: "json-schema";
|
|
6
|
+
readonly version: "2.0.1";
|
|
7
|
+
readonly path: "artifacts/epcis/epcis-json-schema-2.0.1.json";
|
|
8
|
+
readonly uri: "https://ref.gs1.org/standards/epcis/2.0.1/epcis-json-schema.json";
|
|
9
|
+
readonly sha256: "0f46ff694efffd8d8ce840a33dfde84228add11b516b8b258f3200740ae210af";
|
|
10
|
+
readonly byteLength: 55680;
|
|
11
|
+
readonly carried: true;
|
|
12
|
+
}, {
|
|
13
|
+
readonly id: "epcis-context";
|
|
14
|
+
readonly kind: "jsonld-context";
|
|
15
|
+
readonly version: "2.0.1";
|
|
16
|
+
readonly path: "artifacts/epcis/epcis-context-2.0.1.jsonld";
|
|
17
|
+
readonly uri: "https://ref.gs1.org/standards/epcis/2.0.1/epcis-context.jsonld";
|
|
18
|
+
readonly sha256: "5056c65f991425b1d3a35e35edf4f7d0c7ff56cf688c2912b930f93494713737";
|
|
19
|
+
readonly byteLength: 20690;
|
|
20
|
+
readonly carried: true;
|
|
21
|
+
}, {
|
|
22
|
+
readonly id: "epcis-query-schema";
|
|
23
|
+
readonly kind: "json-schema";
|
|
24
|
+
readonly version: "2.0.1";
|
|
25
|
+
readonly path: "artifacts/epcis/query-schema-2.0.1.json";
|
|
26
|
+
readonly uri: "https://ref.gs1.org/standards/epcis/2.0.1/query-schema.json";
|
|
27
|
+
readonly sha256: "4b5583c9a0a715324594617f3cf6744f4f930568484f7df8fb7aa81819355341";
|
|
28
|
+
readonly byteLength: 27229;
|
|
29
|
+
readonly carried: true;
|
|
30
|
+
}, {
|
|
31
|
+
readonly id: "epcis-openapi";
|
|
32
|
+
readonly kind: "openapi";
|
|
33
|
+
readonly version: "2.0.1";
|
|
34
|
+
readonly path: null;
|
|
35
|
+
readonly uri: "https://ref.gs1.org/standards/epcis/2.0.1/openapi.json";
|
|
36
|
+
readonly sha256: "3d33792c520d7a7a1d080382d956730bb07021c7dd1cc17229fce27b784d66fc";
|
|
37
|
+
readonly byteLength: 351201;
|
|
38
|
+
readonly carried: false;
|
|
39
|
+
}];
|
|
40
|
+
export declare const EPCIS_VERSION = "2.0.1";
|
|
41
|
+
export declare const CBV_VERSION = "2.0.0";
|
|
42
|
+
export declare const EPCIS_CONTEXT_IRI = "https://ref.gs1.org/standards/epcis/2.0.1/epcis-context.jsonld";
|
|
43
|
+
export declare const EPCIS_CONTEXT_DIGEST: "5056c65f991425b1d3a35e35edf4f7d0c7ff56cf688c2912b930f93494713737";
|
|
44
|
+
/** The five event types the profile recognises; anything else is an extension event this profile does not interpret. */
|
|
45
|
+
export declare const EPCIS_EVENT_TYPES: readonly ["ObjectEvent", "AggregationEvent", "TransformationEvent", "TransactionEvent", "AssociationEvent"];
|
|
46
|
+
export type EpcisEventType = (typeof EPCIS_EVENT_TYPES)[number];
|
|
47
|
+
/** The signed source-reference vocabulary a mapped credential carries beside the round-trip event. */
|
|
48
|
+
export declare const EPCIS_SOURCE_VOCABULARY = "urn:bsv:dpp:epcis-source:1";
|
|
49
|
+
export declare const EPCIS_MAPPING_PROFILE = "epcis-vsc@1";
|
|
50
|
+
export declare const EPCIS_SOURCE_PROFILE = "epcis-json@1";
|
|
51
|
+
export declare const EPCIS_MEDIA_TYPES: readonly ["application/json", "application/ld+json"];
|
|
52
|
+
export interface EpcisLimits {
|
|
53
|
+
maxDocumentBytes: number;
|
|
54
|
+
maxEventsPerPage: number;
|
|
55
|
+
maxJsonDepth: number;
|
|
56
|
+
maxContextDocuments: number;
|
|
57
|
+
maxContextBytes: number;
|
|
58
|
+
fetchTimeoutMs: number;
|
|
59
|
+
maxPullPages: number;
|
|
60
|
+
maxPullBytes: number;
|
|
61
|
+
maxPullSeconds: number;
|
|
62
|
+
}
|
|
63
|
+
/** The disclosed defaults of epcis-json@1; an operator lowers them or explicitly configures bounded higher values. */
|
|
64
|
+
export declare const EPCIS_DEFAULT_LIMITS: EpcisLimits;
|
|
65
|
+
export declare function resolveEpcisLimits(overrides?: Partial<EpcisLimits>): EpcisLimits;
|
|
66
|
+
export type EpcisRefusal = 'unsupported-media-type' | 'oversized' | 'malformed-utf8' | 'malformed-json' | 'duplicate-key' | 'depth' | 'unsafe-number' | 'too-many-events' | 'not-an-object';
|
|
67
|
+
export interface EpcisFinding {
|
|
68
|
+
code: string;
|
|
69
|
+
path: string;
|
|
70
|
+
message: string;
|
|
71
|
+
severity: 'error' | 'warning' | 'info';
|
|
72
|
+
}
|
|
73
|
+
export interface EpcisEventPointer {
|
|
74
|
+
/** RFC 6901 pointer to the event within the parsed document. */
|
|
75
|
+
pointer: string;
|
|
76
|
+
index: number;
|
|
77
|
+
type: string;
|
|
78
|
+
/** The event's own eventID, when it carries one. */
|
|
79
|
+
eventId?: string;
|
|
80
|
+
/** A local ingestion identity for an event without an eventID, labelled as such and never inserted into the source. */
|
|
81
|
+
localIdentity?: string;
|
|
82
|
+
identityKind: 'event-id' | 'local';
|
|
83
|
+
}
|
|
84
|
+
export interface EpcisEnvelope {
|
|
85
|
+
type: 'EPCISDocument' | 'EPCISQueryDocument';
|
|
86
|
+
schemaVersion?: string;
|
|
87
|
+
creationDate?: string;
|
|
88
|
+
hasHeader: boolean;
|
|
89
|
+
hasMasterData: boolean;
|
|
90
|
+
queryName?: string;
|
|
91
|
+
}
|
|
92
|
+
export interface EpcisContextDeclarations {
|
|
93
|
+
/** The document's `@context`, exactly as present, or undefined when absent. */
|
|
94
|
+
document?: unknown;
|
|
95
|
+
/** Event-level `@context` declarations, by pointer, exactly as present. */
|
|
96
|
+
events: Array<{
|
|
97
|
+
pointer: string;
|
|
98
|
+
context: unknown;
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
101
|
+
export type EpcisParseResult = {
|
|
102
|
+
ok: false;
|
|
103
|
+
reason: EpcisRefusal;
|
|
104
|
+
detail: string;
|
|
105
|
+
} | {
|
|
106
|
+
ok: true;
|
|
107
|
+
retained: true;
|
|
108
|
+
sha256: string;
|
|
109
|
+
byteLength: number;
|
|
110
|
+
mediaType: string;
|
|
111
|
+
document: JsonObject;
|
|
112
|
+
envelope?: EpcisEnvelope;
|
|
113
|
+
context: EpcisContextDeclarations;
|
|
114
|
+
events: EpcisEventPointer[];
|
|
115
|
+
findings: EpcisFinding[];
|
|
116
|
+
};
|
|
117
|
+
export interface EpcisParseOptions {
|
|
118
|
+
mediaType: string;
|
|
119
|
+
limits?: Partial<EpcisLimits>;
|
|
120
|
+
/**
|
|
121
|
+
* Accept a bare event as the whole source only when the caller supplies
|
|
122
|
+
* the envelope facts the event travelled with; a bare event with no such
|
|
123
|
+
* facts is an unrecognised envelope.
|
|
124
|
+
*/
|
|
125
|
+
singleEvent?: {
|
|
126
|
+
envelopeType: 'EPCISDocument' | 'EPCISQueryDocument';
|
|
127
|
+
contextDeclarations: unknown;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** Whether a number literal survives a parse into a double and the shortest round-trip serialisation with the same decimal digits. */
|
|
131
|
+
export declare function numberLiteralIsExact(text: string): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Parse an EPCIS source strictly under the profile's limits, without
|
|
134
|
+
* changing a byte of it. The document, when the transport is safe, is the
|
|
135
|
+
* exact JSON value; the events are pointers into it; the findings say what
|
|
136
|
+
* the envelope lacks without deciding what the caller does about it.
|
|
137
|
+
*/
|
|
138
|
+
export declare function parseEpcisSource(bytes: Uint8Array, options: EpcisParseOptions): EpcisParseResult;
|
|
139
|
+
/** The local ingestion identity of an event that carries no eventID: derived from the source digest and the event's pointer, labelled local, never written into the source. */
|
|
140
|
+
export declare function localEventIdentity(sourceSha256: string, pointer: string): string;
|
|
141
|
+
/**
|
|
142
|
+
* The canonical event-body digest a duplicate or a conflict is decided by:
|
|
143
|
+
* RFC 8785 over the event without its repository `recordTime` and its
|
|
144
|
+
* `errorDeclaration`, beside the sorted digests of the contexts it was read
|
|
145
|
+
* under, then SHA-256. Two formattings of one event digest the same; two
|
|
146
|
+
* JSON-LD spellings of one meaning do not, and are not promised to.
|
|
147
|
+
*/
|
|
148
|
+
export declare function epcisEventBodyDigest(event: JsonObject, contextDigests: readonly string[]): string;
|
|
149
|
+
/** The digest of a context declaration: a pinned IRI's known digest, or the JCS digest of an inline object. */
|
|
150
|
+
export interface ContextReference {
|
|
151
|
+
kind: 'iri' | 'inline';
|
|
152
|
+
value: string;
|
|
153
|
+
/** The pinned digest for a known IRI, or the JCS digest of an inline object; absent for an IRI this profile has not pinned. */
|
|
154
|
+
digest?: string;
|
|
155
|
+
pinned: boolean;
|
|
156
|
+
}
|
|
157
|
+
export declare function contextReferences(declaration: unknown): ContextReference[];
|
|
158
|
+
/** The digests of every pinned context in a declaration; an unpinned IRI contributes nothing and is reported by the caller as a gap. */
|
|
159
|
+
export declare function pinnedContextDigests(declaration: unknown): {
|
|
160
|
+
digests: string[];
|
|
161
|
+
unpinned: string[];
|
|
162
|
+
};
|
|
163
|
+
export interface EpcisSourceReference extends JsonObject {
|
|
164
|
+
vocabularyUrn: typeof EPCIS_SOURCE_VOCABULARY;
|
|
165
|
+
sourceDigest: string;
|
|
166
|
+
mediaType: string;
|
|
167
|
+
eventPointer: string;
|
|
168
|
+
eventId?: string;
|
|
169
|
+
contextDigests: string[];
|
|
170
|
+
mappingProfile: string;
|
|
171
|
+
}
|
|
172
|
+
export declare function epcisSourceReference(input: {
|
|
173
|
+
sourceSha256: string;
|
|
174
|
+
mediaType: string;
|
|
175
|
+
pointer: string;
|
|
176
|
+
eventId?: string;
|
|
177
|
+
contextDigests: readonly string[];
|
|
178
|
+
mappingProfile?: string;
|
|
179
|
+
}): EpcisSourceReference;
|
|
180
|
+
/** The source reference a mapped SEAL carries, or undefined when it carries none. Reading it does not verify the credential. */
|
|
181
|
+
export declare function readEpcisSourceReference(seal: Seal): EpcisSourceReference | undefined;
|
|
182
|
+
export type IdentifierScheme = 'gs1-sgtin' | 'gs1-lgtin' | 'gs1-sgtin-pattern' | 'gs1-digital-link' | 'epc-other' | 'other';
|
|
183
|
+
export interface EpcisIdentifierFinding {
|
|
184
|
+
path: string;
|
|
185
|
+
value: string;
|
|
186
|
+
scheme: IdentifierScheme;
|
|
187
|
+
/** For a GS1 trade item: the fourteen-digit GTIN the identifier resolves to. */
|
|
188
|
+
gtin?: string;
|
|
189
|
+
serial?: string;
|
|
190
|
+
lot?: string;
|
|
191
|
+
/** For a Digital Link URI: whether the check digit holds. A URN form computes its own, so it is always valid when well-formed. */
|
|
192
|
+
checkDigitValid?: boolean;
|
|
193
|
+
problem?: string;
|
|
194
|
+
}
|
|
195
|
+
export interface EpcisEventValidation {
|
|
196
|
+
pointer: string;
|
|
197
|
+
type: string;
|
|
198
|
+
identifiers: EpcisIdentifierFinding[];
|
|
199
|
+
preservedExtensions: string[];
|
|
200
|
+
errorDeclaration?: {
|
|
201
|
+
declarationTime?: string;
|
|
202
|
+
reason?: string;
|
|
203
|
+
correctiveEventIDs: string[];
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
export interface EpcisValidationFindings {
|
|
207
|
+
schema: 'pass' | 'fail';
|
|
208
|
+
findings: EpcisFinding[];
|
|
209
|
+
events: EpcisEventValidation[];
|
|
210
|
+
/** Document-level members the schema does not name, retained and listed. */
|
|
211
|
+
preservedExtensions: string[];
|
|
212
|
+
}
|
|
213
|
+
/** Classify one identifier without rewriting it; a claimed GS1 identifier is checked against the grammar, anything else keeps its declared scheme. */
|
|
214
|
+
export declare function classifyEpcisIdentifier(path: string, value: unknown): EpcisIdentifierFinding;
|
|
215
|
+
/** The members of an event the schema does not name for its type: retained as given, never interpreted here. */
|
|
216
|
+
export declare function preservedEventExtensions(event: JsonObject): string[];
|
|
217
|
+
/** Every identifier an event names, classified in place. */
|
|
218
|
+
export declare function eventIdentifiers(event: JsonObject, pointer?: string): EpcisIdentifierFinding[];
|
|
219
|
+
/**
|
|
220
|
+
* Validate a safely parsed document against the pinned EPCIS 2.0.1 schema
|
|
221
|
+
* and the profile's identifier rules. Every finding names its path; nothing
|
|
222
|
+
* is repaired. `schema` says whether the pinned schema accepted the whole
|
|
223
|
+
* document; the identifier findings are independent of it, so a document
|
|
224
|
+
* the schema rejects still has its identifiers read.
|
|
225
|
+
*/
|
|
226
|
+
export declare function validateEpcisDocument(document: JsonObject, options?: {
|
|
227
|
+
events?: EpcisEventPointer[];
|
|
228
|
+
}): EpcisValidationFindings;
|
|
229
|
+
export interface EventObservation {
|
|
230
|
+
/** The scoped identity: the eventID, or the local identity for an event without one. */
|
|
231
|
+
identity: string;
|
|
232
|
+
bodyDigest: string;
|
|
233
|
+
recordTime?: string;
|
|
234
|
+
errorDeclaration?: unknown;
|
|
235
|
+
}
|
|
236
|
+
export type EventArrival = 'duplicate' | 'conflict' | 'new-observation';
|
|
237
|
+
/**
|
|
238
|
+
* How a newly arrived event relates to one already held under the same
|
|
239
|
+
* scoped identity. Equal bodies with equal repository observations are a
|
|
240
|
+
* duplicate; equal bodies with a changed recordTime or error declaration
|
|
241
|
+
* are a further observation of the same event, never permission to
|
|
242
|
+
* overwrite it; different bodies are a conflict that stays visible until it
|
|
243
|
+
* is explicitly resolved.
|
|
244
|
+
*/
|
|
245
|
+
export declare function classifyEventArrival(existing: EventObservation, incoming: EventObservation): EventArrival;
|
|
246
|
+
/** The corrective event references an error declaration names that the supplied set of held identities does not contain: unresolved, never silently resolved. */
|
|
247
|
+
export declare function unresolvedCorrections(validation: EpcisValidationFindings, heldIdentities: ReadonlySet<string>): Array<{
|
|
248
|
+
pointer: string;
|
|
249
|
+
missing: string[];
|
|
250
|
+
}>;
|
|
251
|
+
//# sourceMappingURL=epcis-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epcis-source.d.ts","sourceRoot":"","sources":["../src/epcis-source.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAInD,0FAA0F;AAC1F,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKlB,CAAC;AAEX,eAAO,MAAM,aAAa,UAAU,CAAC;A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