@open-dpp/dto 2.7.0 → 2.8.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/aas/submodel-base/create-group-from-column-schema.d.ts +61 -0
- package/dist/aas/submodel-base/create-group-from-column-schema.d.ts.map +1 -0
- package/dist/aas/submodel-base/create-group-from-column-schema.js +9 -0
- package/dist/activity-history/activity-history.dto.d.ts +47 -28
- package/dist/activity-history/activity-history.dto.d.ts.map +1 -1
- package/dist/activity-history/activity-types.dto.d.ts +10 -8
- package/dist/activity-history/activity-types.dto.d.ts.map +1 -1
- package/dist/activity-history/activity-types.dto.js +5 -4
- package/dist/activity-history/change-event-types.dto.d.ts +8 -0
- package/dist/activity-history/change-event-types.dto.d.ts.map +1 -1
- package/dist/activity-history/change-event-types.dto.js +4 -0
- package/dist/digital-product-document/digital-product-document.dto.d.ts +11 -0
- package/dist/digital-product-document/digital-product-document.dto.d.ts.map +1 -0
- package/dist/digital-product-document/digital-product-document.dto.js +9 -0
- package/dist/digital-product-document/digital-product-document.schemas.d.ts.map +1 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/organizations/member.dto.d.ts +8 -2
- package/dist/organizations/member.dto.d.ts.map +1 -1
- package/dist/organizations/member.dto.js +7 -1
- package/dist/passports/passport.dto.js +1 -1
- package/dist/permalinks/permalink.dto.js +1 -1
- package/dist/presentation-configurations/presentation-configuration.dto.d.ts +0 -9
- package/dist/presentation-configurations/presentation-configuration.dto.d.ts.map +1 -1
- package/dist/presentation-configurations/presentation-configuration.dto.js +5 -9
- package/dist/shared/filter.dto.js +1 -1
- package/dist/templates/template.dto.js +1 -1
- package/dist/unique-product-identifiers/gs1/gs1-ai-constants.d.ts +574 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-constants.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-constants.js +570 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-description.d.ts +15 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-description.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-description.js +47 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-i18n.d.ts +27 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-i18n.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-i18n.js +523 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-table.d.ts +47 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-table.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-ai-table.js +4363 -0
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.d.ts +540 -0
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-data-attributes.dto.js +62 -0
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.d.ts +158 -0
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.js +321 -0
- package/dist/unique-product-identifiers/gs1/gs1-identity.dto.d.ts +39 -0
- package/dist/unique-product-identifiers/gs1/gs1-identity.dto.d.ts.map +1 -0
- package/dist/unique-product-identifiers/gs1/gs1-identity.dto.js +40 -0
- package/dist/unique-product-identifiers/unique-product-identifier-type.d.ts +36 -0
- package/dist/unique-product-identifiers/unique-product-identifier-type.d.ts.map +1 -0
- package/dist/unique-product-identifiers/unique-product-identifier-type.js +27 -0
- package/dist/users/create-user.dto.d.ts +2 -2
- package/dist/users/create-user.dto.js +2 -2
- package/dist/users/me.dto.d.ts +24 -0
- package/dist/users/me.dto.d.ts.map +1 -0
- package/dist/users/me.dto.js +10 -0
- package/dist/users/pending-email-change.dto.d.ts +7 -0
- package/dist/users/pending-email-change.dto.d.ts.map +1 -0
- package/dist/users/pending-email-change.dto.js +8 -0
- package/dist/users/request-email-change.dto.d.ts +7 -0
- package/dist/users/request-email-change.dto.d.ts.map +1 -0
- package/dist/users/request-email-change.dto.js +8 -0
- package/dist/users/update-profile.dto.d.ts +11 -0
- package/dist/users/update-profile.dto.d.ts.map +1 -0
- package/dist/users/update-profile.dto.js +12 -0
- package/dist/users/user.dto.d.ts +16 -9
- package/dist/users/user.dto.d.ts.map +1 -1
- package/dist/users/user.dto.js +14 -1
- package/package.json +7 -5
- package/src/aas/submodel-base/create-group-from-column-schema.ts +9 -0
- package/src/activity-history/activity-types.dto.ts +5 -4
- package/src/activity-history/change-event-types.dto.ts +4 -0
- package/src/digital-product-document/digital-product-document.dto.ts +8 -0
- package/src/index.ts +15 -1
- package/src/organizations/member.dto.ts +11 -2
- package/src/passports/passport.dto.ts +1 -1
- package/src/permalinks/permalink.dto.ts +1 -1
- package/src/presentation-configurations/presentation-configuration.dto.spec.ts +2 -2
- package/src/presentation-configurations/presentation-configuration.dto.ts +4 -11
- package/src/shared/filter.dto.ts +1 -1
- package/src/templates/template.dto.ts +1 -1
- package/src/unique-product-identifiers/gs1/gs1-ai-constants.spec.ts +99 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-constants.ts +581 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-description.spec.ts +64 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-description.ts +47 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-i18n.ts +530 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-table.spec.ts +86 -0
- package/src/unique-product-identifiers/gs1/gs1-ai-table.ts +4389 -0
- package/src/unique-product-identifiers/gs1/gs1-data-attributes.dto.spec.ts +28 -0
- package/src/unique-product-identifiers/gs1/gs1-data-attributes.dto.ts +67 -0
- package/src/unique-product-identifiers/gs1/gs1-digital-link.spec.ts +126 -0
- package/src/unique-product-identifiers/gs1/gs1-digital-link.ts +368 -0
- package/src/unique-product-identifiers/gs1/gs1-identity.dto.ts +51 -0
- package/src/unique-product-identifiers/unique-product-identifier-type.ts +31 -0
- package/src/users/create-user.dto.spec.ts +80 -0
- package/src/users/create-user.dto.ts +2 -2
- package/src/users/me.dto.spec.ts +76 -0
- package/src/users/me.dto.ts +10 -0
- package/src/users/pending-email-change.dto.spec.ts +47 -0
- package/src/users/pending-email-change.dto.ts +8 -0
- package/src/users/request-email-change.dto.spec.ts +60 -0
- package/src/users/request-email-change.dto.ts +8 -0
- package/src/users/update-profile.dto.spec.ts +93 -0
- package/src/users/update-profile.dto.ts +12 -0
- package/src/users/user.dto.spec.ts +70 -0
- package/src/users/user.dto.ts +15 -9
- package/dist/shared/digital-product-document.schemas.d.ts.map +0 -1
- /package/dist/{shared → digital-product-document}/digital-product-document.schemas.d.ts +0 -0
- /package/dist/{shared → digital-product-document}/digital-product-document.schemas.js +0 -0
- /package/src/{shared → digital-product-document}/digital-product-document.schemas.ts +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Gs1DataAttributeAi } from "./gs1-ai-constants";
|
|
3
|
+
/** Length of a normalized GTIN. */
|
|
4
|
+
export declare const GTIN14_LENGTH = 14;
|
|
5
|
+
/**
|
|
6
|
+
* Validate a GTIN's trailing mod-10 check digit.
|
|
7
|
+
*
|
|
8
|
+
* Uses the standard GS1 algorithm: starting from the rightmost data digit
|
|
9
|
+
* (i.e. excluding the check digit), apply alternating weights 3,1,3,1,…; the
|
|
10
|
+
* check digit is the value that rounds the weighted sum up to a multiple of ten.
|
|
11
|
+
*
|
|
12
|
+
* @param gtin - a digits-only string of any length (≥ 2)
|
|
13
|
+
* @returns true when the final digit is the correct check digit
|
|
14
|
+
*/
|
|
15
|
+
export declare function isValidGtinCheckDigit(gtin: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Normalize a manufacturer-supplied GTIN to its canonical GTIN-14 form.
|
|
18
|
+
*
|
|
19
|
+
* Trims surrounding whitespace, validates that the value is a digits-only string
|
|
20
|
+
* of a permitted GTIN length with a correct mod-10 check digit, then left-pads
|
|
21
|
+
* with zeros to 14 digits.
|
|
22
|
+
*
|
|
23
|
+
* @throws Error with a descriptive message on invalid characters, length, or check digit.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeToGtin14(rawGtin: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Zod schema for raw GTIN *input*: accepts any valid GTIN length and transforms
|
|
28
|
+
* it into a normalized, check-digit-valid GTIN-14. Use this at write boundaries
|
|
29
|
+
* (backoffice form, create/update request).
|
|
30
|
+
*/
|
|
31
|
+
export declare const GtinInputSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
32
|
+
/**
|
|
33
|
+
* Zod schema for an already-normalized GTIN-14 (exactly 14 digits, valid check
|
|
34
|
+
* digit). Use this where the value is expected to be canonical (stored value,
|
|
35
|
+
* domain reconstruction, DTO output).
|
|
36
|
+
*/
|
|
37
|
+
export declare const Gtin14Schema: z.ZodString;
|
|
38
|
+
export type Gtin14 = z.infer<typeof Gtin14Schema>;
|
|
39
|
+
/**
|
|
40
|
+
* Maximum length of an alphanumeric GS1 component (batch `10`, serial `21`).
|
|
41
|
+
* GS1 General Specifications cap these AIs at 20 characters.
|
|
42
|
+
*/
|
|
43
|
+
export declare const GS1_CSET82_MAX_LENGTH = 20;
|
|
44
|
+
/**
|
|
45
|
+
* Upper bound on the length of a GS1 data-attribute value, enforced *before* the
|
|
46
|
+
* per-AI regex runs.
|
|
47
|
+
*
|
|
48
|
+
* Some data-attribute regexes (the "X..90" AIs — full name 7256, company-internal
|
|
49
|
+
* 91-99, etc.) alternate a single-char class with a `%HH%HH` percent block, and
|
|
50
|
+
* `%` matches both branches. On a long ambiguous input that ultimately fails, that
|
|
51
|
+
* ambiguity makes the backtracking blow up super-linearly (a ~120-char value can
|
|
52
|
+
* pin a core for seconds). 90 is the largest quantifier bound across every type-'D'
|
|
53
|
+
* AI in the vendored table, so no valid raw value is longer — values are validated
|
|
54
|
+
* in raw form here; percent-encoding happens later in buildGs1DataAttributeQuery.
|
|
55
|
+
* gs1-digital-link.spec.ts asserts this bound stays >= the table's true maximum.
|
|
56
|
+
*/
|
|
57
|
+
export declare const GS1_DATA_ATTRIBUTE_MAX_LENGTH = 90;
|
|
58
|
+
/**
|
|
59
|
+
* Validate a single alphanumeric GS1 component (batch / serial) against CSET-82
|
|
60
|
+
* and the ≤ 20 character limit. Empty is invalid (an absent component is modeled
|
|
61
|
+
* by omitting it, not by an empty string), as are the URL dot-segments "." / "..".
|
|
62
|
+
*/
|
|
63
|
+
export declare function isValidCset82Component(value: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Zod schema for a batch / serial component: a non-empty CSET-82 string of at most
|
|
66
|
+
* 20 characters, excluding the URL dot-segments "." / "..". Use this at write
|
|
67
|
+
* boundaries (backoffice form, create/update).
|
|
68
|
+
*/
|
|
69
|
+
export declare const Cset82ComponentSchema: z.ZodString;
|
|
70
|
+
export type Cset82Component = z.infer<typeof Cset82ComponentSchema>;
|
|
71
|
+
/**
|
|
72
|
+
* Write-boundary schema for an optional batch / serial. Trims surrounding
|
|
73
|
+
* whitespace and coerces a blank value to `undefined` ("clear this component"); a
|
|
74
|
+
* non-blank value must satisfy CSET-82 and the length cap. Use this on request
|
|
75
|
+
* bodies where omitting or blanking a component means "no batch / serial".
|
|
76
|
+
*/
|
|
77
|
+
export declare const Cset82ComponentInputSchema: z.ZodPipe<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<string | undefined, string>>, z.ZodOptional<z.ZodString>>;
|
|
78
|
+
/** The GS1 Application Identifier for a GTIN. Compat alias for {@link Gs1KeyAi.GLOBAL_TRADE_ITEM_NUMBER}. */
|
|
79
|
+
export declare const GS1_AI_GTIN: "01";
|
|
80
|
+
/** The GS1 Application Identifier for a batch / lot number. Compat alias for {@link Gs1QualifierAi.BATCH_OR_LOT_NUMBER}. */
|
|
81
|
+
export declare const GS1_AI_BATCH: "10";
|
|
82
|
+
/** The GS1 Application Identifier for a serial number. Compat alias for {@link Gs1QualifierAi.SERIAL_NUMBER}. */
|
|
83
|
+
export declare const GS1_AI_SERIAL: "21";
|
|
84
|
+
/**
|
|
85
|
+
* Type guard: true when `ai` is a known GS1 data-attribute (non-key) Application
|
|
86
|
+
* Identifier — i.e. `type === 'D'` in the vendored GS1 AI table.
|
|
87
|
+
*
|
|
88
|
+
* Returns false for primary identifiers (type I), key qualifiers (type Q),
|
|
89
|
+
* unknown AIs, and any non-string/empty input.
|
|
90
|
+
*/
|
|
91
|
+
export declare function isGs1DataAttributeAi(ai: string): ai is Gs1DataAttributeAi;
|
|
92
|
+
/**
|
|
93
|
+
* Returns true when `value` is a valid value for the given GS1 data-attribute
|
|
94
|
+
* Application Identifier `ai`.
|
|
95
|
+
*
|
|
96
|
+
* Validates by:
|
|
97
|
+
* 1. Looking up `ai` in the vendored GS1 AI table; returns false if absent or
|
|
98
|
+
* if the entry is not a data attribute (type !== 'D').
|
|
99
|
+
* 2. Rejecting an empty `value` (length must be ≥ 1).
|
|
100
|
+
* 3. Compiling an anchored `RegExp` from the table entry's `regex` fragment.
|
|
101
|
+
*
|
|
102
|
+
* Pure function, no I/O, no mutation.
|
|
103
|
+
*/
|
|
104
|
+
export declare function isValidGs1DataAttributeValue(ai: string, value: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Build the canonical GS1 data-attribute query string from a map of validated AI → value pairs.
|
|
107
|
+
*
|
|
108
|
+
* - Returns `''` when `attributes` is empty, null, or undefined.
|
|
109
|
+
* - Iterates keys in ascending ASCII (lexicographic) order for deterministic output.
|
|
110
|
+
* - Validates each AI via `isGs1DataAttributeAi` and each value via `isValidGs1DataAttributeValue`;
|
|
111
|
+
* throws `Error` on the first invalid entry.
|
|
112
|
+
* - Percent-encodes values RFC 3986-canonically (including `!'()*`).
|
|
113
|
+
* - Prefixes the result with `'?'` only when at least one pair is present.
|
|
114
|
+
*
|
|
115
|
+
* Pure function, no I/O, no mutation.
|
|
116
|
+
*/
|
|
117
|
+
export declare function buildGs1DataAttributeQuery(attributes: Record<string, string> | null | undefined): string;
|
|
118
|
+
export interface Gs1DigitalLinkParts {
|
|
119
|
+
/** A GTIN; normalized to GTIN-14 before assembly. */
|
|
120
|
+
gtin: string;
|
|
121
|
+
/** Optional batch / lot (AI `10`), CSET-82, ≤ 20 chars. */
|
|
122
|
+
batch?: string | null;
|
|
123
|
+
/** Optional serial (AI `21`), CSET-82, ≤ 20 chars. */
|
|
124
|
+
serial?: string | null;
|
|
125
|
+
/**
|
|
126
|
+
* Optional GS1 data-attribute map (non-key AIs only). When set, the pairs are
|
|
127
|
+
* sorted in ascending AI order, validated, and appended as a query string after
|
|
128
|
+
* the last path segment. Pass `null` or omit to emit no query string.
|
|
129
|
+
*/
|
|
130
|
+
dataAttributes?: Record<string, string> | null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Build the uncompressed, canonical GS1 Digital Link for a GS1 identity.
|
|
134
|
+
*
|
|
135
|
+
* Emits the GTIN path and, when present, appends the batch (AI `10`) and serial
|
|
136
|
+
* (AI `21`) segments in canonical GS1 order `01 -> 10 -> 21`. A blank batch/serial
|
|
137
|
+
* is treated as absent. The resolver base is canonicalised (host lowercased,
|
|
138
|
+
* trailing slash dropped) and any path it carries is preserved; batch/serial
|
|
139
|
+
* values are percent-encoded for the path.
|
|
140
|
+
*
|
|
141
|
+
* @throws Error when the GTIN is invalid or a batch/serial violates CSET-82 /
|
|
142
|
+
* length / the dot-segment rule.
|
|
143
|
+
*/
|
|
144
|
+
export declare function buildGs1DigitalLink(resolverBase: string, parts: Gs1DigitalLinkParts): string;
|
|
145
|
+
/**
|
|
146
|
+
* Format a GS1 identity as its human-readable GS1 element string, e.g.
|
|
147
|
+
* `(01) 04006381333931 (10) LOT-42 (21) SN-001`.
|
|
148
|
+
*
|
|
149
|
+
* Each present Application Identifier is rendered as its parenthesised AI followed
|
|
150
|
+
* by the value, in canonical GS1 order `01 -> 10 -> 21`. Unlike the Digital Link,
|
|
151
|
+
* the element string is for human display only, so batch/serial values are emitted
|
|
152
|
+
* verbatim (no percent-encoding). A blank batch/serial is treated as absent.
|
|
153
|
+
*
|
|
154
|
+
* @throws Error when the GTIN is invalid or a batch/serial violates CSET-82 /
|
|
155
|
+
* length / the dot-segment rule.
|
|
156
|
+
*/
|
|
157
|
+
export declare function formatGs1ElementString(parts: Gs1DigitalLinkParts): string;
|
|
158
|
+
//# sourceMappingURL=gs1-digital-link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gs1-digital-link.d.ts","sourceRoot":"","sources":["../../../src/unique-product-identifiers/gs1/gs1-digital-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAA4B,MAAM,oBAAoB,CAAC;AAelF,mCAAmC;AACnC,eAAO,MAAM,aAAa,KAAK,CAAC;AAIhC;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAe3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAczD;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,wDAU1B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,aAI0D,CAAC;AAEpF,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAmBhD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO7D;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,aAKoD,CAAC;AAEvF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,sJAIE,CAAC;AAE1C,6GAA6G;AAC7G,eAAO,MAAM,WAAW,MAAoC,CAAC;AAC7D,4HAA4H;AAC5H,eAAO,MAAM,YAAY,MAAqC,CAAC;AAC/D,iHAAiH;AACjH,eAAO,MAAM,aAAa,MAA+B,CAAC;AAE1D;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,kBAAkB,CAGzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAgB/E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,GACpD,MAAM,CAgBR;AAED,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAChD;AAyBD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAe5F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAazE"}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GS1_AI_SERIAL = exports.GS1_AI_BATCH = exports.GS1_AI_GTIN = exports.Cset82ComponentInputSchema = exports.Cset82ComponentSchema = exports.GS1_DATA_ATTRIBUTE_MAX_LENGTH = exports.GS1_CSET82_MAX_LENGTH = exports.Gtin14Schema = exports.GtinInputSchema = exports.GTIN14_LENGTH = void 0;
|
|
4
|
+
exports.isValidGtinCheckDigit = isValidGtinCheckDigit;
|
|
5
|
+
exports.normalizeToGtin14 = normalizeToGtin14;
|
|
6
|
+
exports.isValidCset82Component = isValidCset82Component;
|
|
7
|
+
exports.isGs1DataAttributeAi = isGs1DataAttributeAi;
|
|
8
|
+
exports.isValidGs1DataAttributeValue = isValidGs1DataAttributeValue;
|
|
9
|
+
exports.buildGs1DataAttributeQuery = buildGs1DataAttributeQuery;
|
|
10
|
+
exports.buildGs1DigitalLink = buildGs1DigitalLink;
|
|
11
|
+
exports.formatGs1ElementString = formatGs1ElementString;
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
const permalink_base_url_schema_1 = require("../../shared/permalink-base-url.schema");
|
|
14
|
+
const gs1_ai_constants_1 = require("./gs1-ai-constants");
|
|
15
|
+
const gs1_ai_table_1 = require("./gs1-ai-table");
|
|
16
|
+
/**
|
|
17
|
+
* Zero-dependency GS1 Digital Link helpers, shared by the client and the server.
|
|
18
|
+
*
|
|
19
|
+
* Scope: a GTIN (manufacturer-supplied — open-dpp never mints GS1 identifiers —
|
|
20
|
+
* mod-10 validated, stored normalized to GTIN-14) plus an optional batch (AI `10`)
|
|
21
|
+
* and/or serial (AI `21`), each restricted to GS1's CSET-82 character set and
|
|
22
|
+
* ≤ 20 characters. Granularity is implied by which keys are present.
|
|
23
|
+
*/
|
|
24
|
+
/** Valid raw GTIN lengths accepted as input (GTIN-8/12/13/14). */
|
|
25
|
+
const VALID_GTIN_LENGTHS = new Set([8, 12, 13, 14]);
|
|
26
|
+
/** Length of a normalized GTIN. */
|
|
27
|
+
exports.GTIN14_LENGTH = 14;
|
|
28
|
+
const DIGITS_ONLY = /^[0-9]+$/;
|
|
29
|
+
/**
|
|
30
|
+
* Validate a GTIN's trailing mod-10 check digit.
|
|
31
|
+
*
|
|
32
|
+
* Uses the standard GS1 algorithm: starting from the rightmost data digit
|
|
33
|
+
* (i.e. excluding the check digit), apply alternating weights 3,1,3,1,…; the
|
|
34
|
+
* check digit is the value that rounds the weighted sum up to a multiple of ten.
|
|
35
|
+
*
|
|
36
|
+
* @param gtin - a digits-only string of any length (≥ 2)
|
|
37
|
+
* @returns true when the final digit is the correct check digit
|
|
38
|
+
*/
|
|
39
|
+
function isValidGtinCheckDigit(gtin) {
|
|
40
|
+
if (!DIGITS_ONLY.test(gtin) || gtin.length < 2) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const digits = gtin.split("").map((d) => Number.parseInt(d, 10));
|
|
44
|
+
const checkDigit = digits[digits.length - 1];
|
|
45
|
+
const body = digits.slice(0, -1);
|
|
46
|
+
const sum = body.reduce((acc, digit, i) => {
|
|
47
|
+
const positionFromRight = body.length - 1 - i;
|
|
48
|
+
const weight = positionFromRight % 2 === 0 ? 3 : 1;
|
|
49
|
+
return acc + digit * weight;
|
|
50
|
+
}, 0);
|
|
51
|
+
const computed = (10 - (sum % 10)) % 10;
|
|
52
|
+
return computed === checkDigit;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Normalize a manufacturer-supplied GTIN to its canonical GTIN-14 form.
|
|
56
|
+
*
|
|
57
|
+
* Trims surrounding whitespace, validates that the value is a digits-only string
|
|
58
|
+
* of a permitted GTIN length with a correct mod-10 check digit, then left-pads
|
|
59
|
+
* with zeros to 14 digits.
|
|
60
|
+
*
|
|
61
|
+
* @throws Error with a descriptive message on invalid characters, length, or check digit.
|
|
62
|
+
*/
|
|
63
|
+
function normalizeToGtin14(rawGtin) {
|
|
64
|
+
const gtin = rawGtin.trim();
|
|
65
|
+
if (!DIGITS_ONLY.test(gtin)) {
|
|
66
|
+
throw new Error("GTIN must contain digits only");
|
|
67
|
+
}
|
|
68
|
+
if (!VALID_GTIN_LENGTHS.has(gtin.length)) {
|
|
69
|
+
throw new Error(`GTIN must have a valid length (8, 12, 13, or 14 digits); received ${gtin.length}`);
|
|
70
|
+
}
|
|
71
|
+
if (!isValidGtinCheckDigit(gtin)) {
|
|
72
|
+
throw new Error("GTIN has an invalid check digit");
|
|
73
|
+
}
|
|
74
|
+
return gtin.padStart(exports.GTIN14_LENGTH, "0");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Zod schema for raw GTIN *input*: accepts any valid GTIN length and transforms
|
|
78
|
+
* it into a normalized, check-digit-valid GTIN-14. Use this at write boundaries
|
|
79
|
+
* (backoffice form, create/update request).
|
|
80
|
+
*/
|
|
81
|
+
exports.GtinInputSchema = zod_1.z.string().transform((value, ctx) => {
|
|
82
|
+
try {
|
|
83
|
+
return normalizeToGtin14(value);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
ctx.addIssue({
|
|
87
|
+
code: "custom",
|
|
88
|
+
message: error instanceof Error ? error.message : "Invalid GTIN",
|
|
89
|
+
});
|
|
90
|
+
return zod_1.z.NEVER;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Zod schema for an already-normalized GTIN-14 (exactly 14 digits, valid check
|
|
95
|
+
* digit). Use this where the value is expected to be canonical (stored value,
|
|
96
|
+
* domain reconstruction, DTO output).
|
|
97
|
+
*/
|
|
98
|
+
exports.Gtin14Schema = zod_1.z
|
|
99
|
+
.string()
|
|
100
|
+
.length(exports.GTIN14_LENGTH, "GTIN-14 must be exactly 14 digits")
|
|
101
|
+
.regex(DIGITS_ONLY, "GTIN-14 must contain digits only")
|
|
102
|
+
.refine(isValidGtinCheckDigit, { message: "GTIN-14 has an invalid check digit" });
|
|
103
|
+
/**
|
|
104
|
+
* Maximum length of an alphanumeric GS1 component (batch `10`, serial `21`).
|
|
105
|
+
* GS1 General Specifications cap these AIs at 20 characters.
|
|
106
|
+
*/
|
|
107
|
+
exports.GS1_CSET82_MAX_LENGTH = 20;
|
|
108
|
+
/**
|
|
109
|
+
* Upper bound on the length of a GS1 data-attribute value, enforced *before* the
|
|
110
|
+
* per-AI regex runs.
|
|
111
|
+
*
|
|
112
|
+
* Some data-attribute regexes (the "X..90" AIs — full name 7256, company-internal
|
|
113
|
+
* 91-99, etc.) alternate a single-char class with a `%HH%HH` percent block, and
|
|
114
|
+
* `%` matches both branches. On a long ambiguous input that ultimately fails, that
|
|
115
|
+
* ambiguity makes the backtracking blow up super-linearly (a ~120-char value can
|
|
116
|
+
* pin a core for seconds). 90 is the largest quantifier bound across every type-'D'
|
|
117
|
+
* AI in the vendored table, so no valid raw value is longer — values are validated
|
|
118
|
+
* in raw form here; percent-encoding happens later in buildGs1DataAttributeQuery.
|
|
119
|
+
* gs1-digital-link.spec.ts asserts this bound stays >= the table's true maximum.
|
|
120
|
+
*/
|
|
121
|
+
exports.GS1_DATA_ATTRIBUTE_MAX_LENGTH = 90;
|
|
122
|
+
/**
|
|
123
|
+
* GS1 CSET-82: the 82 characters permitted in alphanumeric AI values. Beyond the
|
|
124
|
+
* 62 alphanumerics (0-9, A-Z, a-z) it adds these 20 special characters:
|
|
125
|
+
* `! " % & ' ( ) * + , - . / : ; < = > ? _`. Anchored, so the whole string must
|
|
126
|
+
* consist only of CSET-82 characters.
|
|
127
|
+
*/
|
|
128
|
+
const CSET82 = /^[0-9A-Za-z!"%&'()*+,\-./:;<=>?_]+$/;
|
|
129
|
+
/**
|
|
130
|
+
* "." and ".." are CSET-82, but as full URL path segments every RFC 3986
|
|
131
|
+
* normalizer (browsers, `new URL()`, most servers) collapses them before the
|
|
132
|
+
* resolver sees the path, so a dot-only batch/serial would silently rewrite
|
|
133
|
+
* the link and resolve to a different identity. Rejected outright —
|
|
134
|
+
* percent-encoding does not help ("%2E" forms are collapsed too).
|
|
135
|
+
*/
|
|
136
|
+
const DOT_SEGMENT = /^\.{1,2}$/;
|
|
137
|
+
/**
|
|
138
|
+
* Validate a single alphanumeric GS1 component (batch / serial) against CSET-82
|
|
139
|
+
* and the ≤ 20 character limit. Empty is invalid (an absent component is modeled
|
|
140
|
+
* by omitting it, not by an empty string), as are the URL dot-segments "." / "..".
|
|
141
|
+
*/
|
|
142
|
+
function isValidCset82Component(value) {
|
|
143
|
+
return (value.length >= 1 &&
|
|
144
|
+
value.length <= exports.GS1_CSET82_MAX_LENGTH &&
|
|
145
|
+
CSET82.test(value) &&
|
|
146
|
+
!DOT_SEGMENT.test(value));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Zod schema for a batch / serial component: a non-empty CSET-82 string of at most
|
|
150
|
+
* 20 characters, excluding the URL dot-segments "." / "..". Use this at write
|
|
151
|
+
* boundaries (backoffice form, create/update).
|
|
152
|
+
*/
|
|
153
|
+
exports.Cset82ComponentSchema = zod_1.z
|
|
154
|
+
.string()
|
|
155
|
+
.min(1, "must not be empty")
|
|
156
|
+
.max(exports.GS1_CSET82_MAX_LENGTH, `must be at most ${exports.GS1_CSET82_MAX_LENGTH} characters`)
|
|
157
|
+
.regex(CSET82, "must contain only GS1 CSET-82 characters")
|
|
158
|
+
.refine((value) => !DOT_SEGMENT.test(value), { message: 'must not be "." or ".."' });
|
|
159
|
+
/**
|
|
160
|
+
* Write-boundary schema for an optional batch / serial. Trims surrounding
|
|
161
|
+
* whitespace and coerces a blank value to `undefined` ("clear this component"); a
|
|
162
|
+
* non-blank value must satisfy CSET-82 and the length cap. Use this on request
|
|
163
|
+
* bodies where omitting or blanking a component means "no batch / serial".
|
|
164
|
+
*/
|
|
165
|
+
exports.Cset82ComponentInputSchema = zod_1.z
|
|
166
|
+
.string()
|
|
167
|
+
.transform((value) => value.trim())
|
|
168
|
+
.transform((value) => (value.length === 0 ? undefined : value))
|
|
169
|
+
.pipe(exports.Cset82ComponentSchema.optional());
|
|
170
|
+
/** The GS1 Application Identifier for a GTIN. Compat alias for {@link Gs1KeyAi.GLOBAL_TRADE_ITEM_NUMBER}. */
|
|
171
|
+
exports.GS1_AI_GTIN = gs1_ai_constants_1.Gs1KeyAi.GLOBAL_TRADE_ITEM_NUMBER;
|
|
172
|
+
/** The GS1 Application Identifier for a batch / lot number. Compat alias for {@link Gs1QualifierAi.BATCH_OR_LOT_NUMBER}. */
|
|
173
|
+
exports.GS1_AI_BATCH = gs1_ai_constants_1.Gs1QualifierAi.BATCH_OR_LOT_NUMBER;
|
|
174
|
+
/** The GS1 Application Identifier for a serial number. Compat alias for {@link Gs1QualifierAi.SERIAL_NUMBER}. */
|
|
175
|
+
exports.GS1_AI_SERIAL = gs1_ai_constants_1.Gs1QualifierAi.SERIAL_NUMBER;
|
|
176
|
+
/**
|
|
177
|
+
* Type guard: true when `ai` is a known GS1 data-attribute (non-key) Application
|
|
178
|
+
* Identifier — i.e. `type === 'D'` in the vendored GS1 AI table.
|
|
179
|
+
*
|
|
180
|
+
* Returns false for primary identifiers (type I), key qualifiers (type Q),
|
|
181
|
+
* unknown AIs, and any non-string/empty input.
|
|
182
|
+
*/
|
|
183
|
+
function isGs1DataAttributeAi(ai) {
|
|
184
|
+
// typeof guard: a plain-JS caller passing e.g. 17 would coerce to "17" on lookup.
|
|
185
|
+
return typeof ai === "string" && gs1_ai_table_1.GS1_AI_TABLE[ai]?.type === "D";
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns true when `value` is a valid value for the given GS1 data-attribute
|
|
189
|
+
* Application Identifier `ai`.
|
|
190
|
+
*
|
|
191
|
+
* Validates by:
|
|
192
|
+
* 1. Looking up `ai` in the vendored GS1 AI table; returns false if absent or
|
|
193
|
+
* if the entry is not a data attribute (type !== 'D').
|
|
194
|
+
* 2. Rejecting an empty `value` (length must be ≥ 1).
|
|
195
|
+
* 3. Compiling an anchored `RegExp` from the table entry's `regex` fragment.
|
|
196
|
+
*
|
|
197
|
+
* Pure function, no I/O, no mutation.
|
|
198
|
+
*/
|
|
199
|
+
function isValidGs1DataAttributeValue(ai, value) {
|
|
200
|
+
// typeof guards: plain-JS callers passing numbers would coerce on lookup/test.
|
|
201
|
+
if (typeof ai !== "string" || typeof value !== "string") {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
const entry = gs1_ai_table_1.GS1_AI_TABLE[ai];
|
|
205
|
+
if (!entry || entry.type !== "D") {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
// Reject empty and over-long values before compiling/running the regex: the
|
|
209
|
+
// per-AI regex can backtrack catastrophically on long ambiguous input, and no
|
|
210
|
+
// valid value exceeds the cap. See GS1_DATA_ATTRIBUTE_MAX_LENGTH.
|
|
211
|
+
if (value.length < 1 || value.length > exports.GS1_DATA_ATTRIBUTE_MAX_LENGTH) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
return new RegExp("^(?:" + entry.regex + ")$").test(value);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Percent-encode a GS1 component value for a URI. `encodeURIComponent` plus the
|
|
218
|
+
* four RFC 3986 sub-delims it leaves raw (`!'()*`) — all CSET-82 characters —
|
|
219
|
+
* so the emitted link is canonical and stable across URL libraries.
|
|
220
|
+
*/
|
|
221
|
+
function encodeRfc3986(value) {
|
|
222
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Build the canonical GS1 data-attribute query string from a map of validated AI → value pairs.
|
|
226
|
+
*
|
|
227
|
+
* - Returns `''` when `attributes` is empty, null, or undefined.
|
|
228
|
+
* - Iterates keys in ascending ASCII (lexicographic) order for deterministic output.
|
|
229
|
+
* - Validates each AI via `isGs1DataAttributeAi` and each value via `isValidGs1DataAttributeValue`;
|
|
230
|
+
* throws `Error` on the first invalid entry.
|
|
231
|
+
* - Percent-encodes values RFC 3986-canonically (including `!'()*`).
|
|
232
|
+
* - Prefixes the result with `'?'` only when at least one pair is present.
|
|
233
|
+
*
|
|
234
|
+
* Pure function, no I/O, no mutation.
|
|
235
|
+
*/
|
|
236
|
+
function buildGs1DataAttributeQuery(attributes) {
|
|
237
|
+
// Use Object.entries (value typed as string) rather than keys + index access, so the
|
|
238
|
+
// helper type-checks under a consumer with noUncheckedIndexedAccess (e.g. apps/client,
|
|
239
|
+
// which type-checks this source directly). Sort ascending by AI for a canonical query.
|
|
240
|
+
const pairs = Object.entries(attributes ?? {})
|
|
241
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
242
|
+
.map(([ai, value]) => {
|
|
243
|
+
if (!isGs1DataAttributeAi(ai)) {
|
|
244
|
+
throw new Error(`"${ai}" is not a known GS1 data-attribute AI`);
|
|
245
|
+
}
|
|
246
|
+
if (!isValidGs1DataAttributeValue(ai, value)) {
|
|
247
|
+
throw new Error(`value for AI "${ai}" is invalid: "${value}"`);
|
|
248
|
+
}
|
|
249
|
+
return `${ai}=${encodeRfc3986(value)}`;
|
|
250
|
+
});
|
|
251
|
+
return pairs.length === 0 ? "" : "?" + pairs.join("&");
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Normalize an optional batch/serial input to either a validated component or
|
|
255
|
+
* `undefined`. Trims surrounding whitespace; an empty/blank value is treated as
|
|
256
|
+
* absent.
|
|
257
|
+
*
|
|
258
|
+
* @throws Error when a non-empty value violates CSET-82 or the length cap.
|
|
259
|
+
*/
|
|
260
|
+
function normalizeOptionalComponent(value, label) {
|
|
261
|
+
const trimmed = value?.trim();
|
|
262
|
+
if (!trimmed) {
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
if (!isValidCset82Component(trimmed)) {
|
|
266
|
+
throw new Error(`${label} must be a GS1 CSET-82 string of at most ${exports.GS1_CSET82_MAX_LENGTH} characters and not "." or ".."`);
|
|
267
|
+
}
|
|
268
|
+
return trimmed;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Build the uncompressed, canonical GS1 Digital Link for a GS1 identity.
|
|
272
|
+
*
|
|
273
|
+
* Emits the GTIN path and, when present, appends the batch (AI `10`) and serial
|
|
274
|
+
* (AI `21`) segments in canonical GS1 order `01 -> 10 -> 21`. A blank batch/serial
|
|
275
|
+
* is treated as absent. The resolver base is canonicalised (host lowercased,
|
|
276
|
+
* trailing slash dropped) and any path it carries is preserved; batch/serial
|
|
277
|
+
* values are percent-encoded for the path.
|
|
278
|
+
*
|
|
279
|
+
* @throws Error when the GTIN is invalid or a batch/serial violates CSET-82 /
|
|
280
|
+
* length / the dot-segment rule.
|
|
281
|
+
*/
|
|
282
|
+
function buildGs1DigitalLink(resolverBase, parts) {
|
|
283
|
+
const gtin14 = normalizeToGtin14(parts.gtin);
|
|
284
|
+
const batch = normalizeOptionalComponent(parts.batch, "Batch");
|
|
285
|
+
const serial = normalizeOptionalComponent(parts.serial, "Serial");
|
|
286
|
+
const base = (0, permalink_base_url_schema_1.canonicaliseBaseUrl)(resolverBase);
|
|
287
|
+
let url = `${base}/${exports.GS1_AI_GTIN}/${gtin14}`;
|
|
288
|
+
if (batch !== undefined) {
|
|
289
|
+
url += `/${exports.GS1_AI_BATCH}/${encodeRfc3986(batch)}`;
|
|
290
|
+
}
|
|
291
|
+
if (serial !== undefined) {
|
|
292
|
+
url += `/${exports.GS1_AI_SERIAL}/${encodeRfc3986(serial)}`;
|
|
293
|
+
}
|
|
294
|
+
url += buildGs1DataAttributeQuery(parts.dataAttributes);
|
|
295
|
+
return url;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Format a GS1 identity as its human-readable GS1 element string, e.g.
|
|
299
|
+
* `(01) 04006381333931 (10) LOT-42 (21) SN-001`.
|
|
300
|
+
*
|
|
301
|
+
* Each present Application Identifier is rendered as its parenthesised AI followed
|
|
302
|
+
* by the value, in canonical GS1 order `01 -> 10 -> 21`. Unlike the Digital Link,
|
|
303
|
+
* the element string is for human display only, so batch/serial values are emitted
|
|
304
|
+
* verbatim (no percent-encoding). A blank batch/serial is treated as absent.
|
|
305
|
+
*
|
|
306
|
+
* @throws Error when the GTIN is invalid or a batch/serial violates CSET-82 /
|
|
307
|
+
* length / the dot-segment rule.
|
|
308
|
+
*/
|
|
309
|
+
function formatGs1ElementString(parts) {
|
|
310
|
+
const gtin14 = normalizeToGtin14(parts.gtin);
|
|
311
|
+
const batch = normalizeOptionalComponent(parts.batch, "Batch");
|
|
312
|
+
const serial = normalizeOptionalComponent(parts.serial, "Serial");
|
|
313
|
+
const segments = [`(${exports.GS1_AI_GTIN}) ${gtin14}`];
|
|
314
|
+
if (batch !== undefined) {
|
|
315
|
+
segments.push(`(${exports.GS1_AI_BATCH}) ${batch}`);
|
|
316
|
+
}
|
|
317
|
+
if (serial !== undefined) {
|
|
318
|
+
segments.push(`(${exports.GS1_AI_SERIAL}) ${serial}`);
|
|
319
|
+
}
|
|
320
|
+
return segments.join(" ");
|
|
321
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The persisted GS1 identity value object carried by a `GS1` UPI.
|
|
4
|
+
*
|
|
5
|
+
* A GTIN (stored normalized to GTIN-14) plus an optional batch (AI `10`) and/or
|
|
6
|
+
* serial (AI `21`), each a CSET-82 string of at most 20 characters. Granularity
|
|
7
|
+
* is implied by which keys are present: GTIN ⇒ model, +batch ⇒ batch, +serial ⇒ item.
|
|
8
|
+
*/
|
|
9
|
+
export declare const Gs1IdentityDtoSchema: z.ZodObject<{
|
|
10
|
+
gtin: z.ZodString;
|
|
11
|
+
batch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
12
|
+
serial: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export type Gs1IdentityDto = z.infer<typeof Gs1IdentityDtoSchema>;
|
|
15
|
+
/**
|
|
16
|
+
* Request body to set a passport's GS1 identity. Accepts a raw GTIN of any valid
|
|
17
|
+
* length (normalized to GTIN-14) and an optional batch / serial. An empty-string
|
|
18
|
+
* batch/serial is treated as "clear this component".
|
|
19
|
+
*/
|
|
20
|
+
export declare const Gs1IdentityRequestSchema: z.ZodObject<{
|
|
21
|
+
gtin: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
22
|
+
batch: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<string | undefined, string>>, z.ZodOptional<z.ZodString>>>;
|
|
23
|
+
serial: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<string | undefined, string>>, z.ZodOptional<z.ZodString>>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type Gs1IdentityRequest = z.input<typeof Gs1IdentityRequestSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Response describing a passport's GS1 identity plus the server-assembled,
|
|
28
|
+
* uncompressed GS1 Digital Link that a Data Carrier (QR) should encode.
|
|
29
|
+
*/
|
|
30
|
+
export declare const Gs1IdentityResponseSchema: z.ZodObject<{
|
|
31
|
+
gtin: z.ZodString;
|
|
32
|
+
batch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
33
|
+
serial: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
34
|
+
uuid: z.ZodUUID;
|
|
35
|
+
referenceId: z.ZodUUID;
|
|
36
|
+
digitalLink: z.ZodURL;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export type Gs1IdentityResponse = z.infer<typeof Gs1IdentityResponseSchema>;
|
|
39
|
+
//# sourceMappingURL=gs1-identity.dto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gs1-identity.dto.d.ts","sourceRoot":"","sources":["../../../src/unique-product-identifiers/gs1/gs1-identity.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;iBAMH,CAAC;AAE/B,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;;;;iBAMA,CAAC;AAEtC,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,yBAAyB;;;;;;;iBAIA,CAAC;AAEvC,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Gs1IdentityResponseSchema = exports.Gs1IdentityRequestSchema = exports.Gs1IdentityDtoSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const gs1_digital_link_1 = require("./gs1-digital-link");
|
|
6
|
+
/**
|
|
7
|
+
* The persisted GS1 identity value object carried by a `GS1` UPI.
|
|
8
|
+
*
|
|
9
|
+
* A GTIN (stored normalized to GTIN-14) plus an optional batch (AI `10`) and/or
|
|
10
|
+
* serial (AI `21`), each a CSET-82 string of at most 20 characters. Granularity
|
|
11
|
+
* is implied by which keys are present: GTIN ⇒ model, +batch ⇒ batch, +serial ⇒ item.
|
|
12
|
+
*/
|
|
13
|
+
exports.Gs1IdentityDtoSchema = zod_1.z
|
|
14
|
+
.object({
|
|
15
|
+
gtin: gs1_digital_link_1.Gtin14Schema,
|
|
16
|
+
batch: gs1_digital_link_1.Cset82ComponentSchema.nullish(),
|
|
17
|
+
serial: gs1_digital_link_1.Cset82ComponentSchema.nullish(),
|
|
18
|
+
})
|
|
19
|
+
.meta({ id: "Gs1Identity" });
|
|
20
|
+
/**
|
|
21
|
+
* Request body to set a passport's GS1 identity. Accepts a raw GTIN of any valid
|
|
22
|
+
* length (normalized to GTIN-14) and an optional batch / serial. An empty-string
|
|
23
|
+
* batch/serial is treated as "clear this component".
|
|
24
|
+
*/
|
|
25
|
+
exports.Gs1IdentityRequestSchema = zod_1.z
|
|
26
|
+
.object({
|
|
27
|
+
gtin: gs1_digital_link_1.GtinInputSchema,
|
|
28
|
+
batch: gs1_digital_link_1.Cset82ComponentInputSchema.optional(),
|
|
29
|
+
serial: gs1_digital_link_1.Cset82ComponentInputSchema.optional(),
|
|
30
|
+
})
|
|
31
|
+
.meta({ id: "Gs1IdentityRequest" });
|
|
32
|
+
/**
|
|
33
|
+
* Response describing a passport's GS1 identity plus the server-assembled,
|
|
34
|
+
* uncompressed GS1 Digital Link that a Data Carrier (QR) should encode.
|
|
35
|
+
*/
|
|
36
|
+
exports.Gs1IdentityResponseSchema = exports.Gs1IdentityDtoSchema.extend({
|
|
37
|
+
uuid: zod_1.z.uuid(),
|
|
38
|
+
referenceId: zod_1.z.uuid(),
|
|
39
|
+
digitalLink: zod_1.z.url(),
|
|
40
|
+
}).meta({ id: "Gs1IdentityResponse" });
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Discriminates the kind of identifier carried by a UniqueProductIdentifier.
|
|
4
|
+
*
|
|
5
|
+
* - `OPEN_DPP_UUID` — system-generated UPI; no external identity data.
|
|
6
|
+
* - `GS1` — GS1 identity: GTIN-14 + optional batch/serial.
|
|
7
|
+
* - `GTIN` — GTIN/EAN read-only system row; not creatable via the API.
|
|
8
|
+
* - `EAN` — EAN read-only system row; not creatable via the API.
|
|
9
|
+
*/
|
|
10
|
+
export declare const UniqueProductIdentifierType: {
|
|
11
|
+
readonly OPEN_DPP_UUID: "OPEN_DPP_UUID";
|
|
12
|
+
readonly GS1: "GS1";
|
|
13
|
+
readonly GTIN: "GTIN";
|
|
14
|
+
readonly EAN: "EAN";
|
|
15
|
+
};
|
|
16
|
+
export declare const UniqueProductIdentifierTypeSchema: z.ZodEnum<{
|
|
17
|
+
readonly OPEN_DPP_UUID: "OPEN_DPP_UUID";
|
|
18
|
+
readonly GS1: "GS1";
|
|
19
|
+
readonly GTIN: "GTIN";
|
|
20
|
+
readonly EAN: "EAN";
|
|
21
|
+
}>;
|
|
22
|
+
export type UniqueProductIdentifierTypeValue = z.infer<typeof UniqueProductIdentifierTypeSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* The GS1 granularity level implied by which key qualifiers are present on a UPI.
|
|
25
|
+
*
|
|
26
|
+
* - `model` — bare GTIN only (product model)
|
|
27
|
+
* - `batch` — GTIN + batch/lot (AI `10`)
|
|
28
|
+
* - `item` — GTIN + serial (AI `21`), optionally also batch
|
|
29
|
+
*/
|
|
30
|
+
export declare const Gs1GranularitySchema: z.ZodEnum<{
|
|
31
|
+
model: "model";
|
|
32
|
+
batch: "batch";
|
|
33
|
+
item: "item";
|
|
34
|
+
}>;
|
|
35
|
+
export type Gs1Granularity = z.infer<typeof Gs1GranularitySchema>;
|
|
36
|
+
//# sourceMappingURL=unique-product-identifier-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unique-product-identifier-type.d.ts","sourceRoot":"","sources":["../../src/unique-product-identifiers/unique-product-identifier-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B;;;;;CAK9B,CAAC;AAEX,eAAO,MAAM,iCAAiC;;;;;EAAsC,CAAC;AAErF,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAC;AAEjG;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;EAAqC,CAAC;AAEvE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Gs1GranularitySchema = exports.UniqueProductIdentifierTypeSchema = exports.UniqueProductIdentifierType = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Discriminates the kind of identifier carried by a UniqueProductIdentifier.
|
|
7
|
+
*
|
|
8
|
+
* - `OPEN_DPP_UUID` — system-generated UPI; no external identity data.
|
|
9
|
+
* - `GS1` — GS1 identity: GTIN-14 + optional batch/serial.
|
|
10
|
+
* - `GTIN` — GTIN/EAN read-only system row; not creatable via the API.
|
|
11
|
+
* - `EAN` — EAN read-only system row; not creatable via the API.
|
|
12
|
+
*/
|
|
13
|
+
exports.UniqueProductIdentifierType = {
|
|
14
|
+
OPEN_DPP_UUID: "OPEN_DPP_UUID",
|
|
15
|
+
GS1: "GS1",
|
|
16
|
+
GTIN: "GTIN",
|
|
17
|
+
EAN: "EAN",
|
|
18
|
+
};
|
|
19
|
+
exports.UniqueProductIdentifierTypeSchema = zod_1.z.enum(exports.UniqueProductIdentifierType);
|
|
20
|
+
/**
|
|
21
|
+
* The GS1 granularity level implied by which key qualifiers are present on a UPI.
|
|
22
|
+
*
|
|
23
|
+
* - `model` — bare GTIN only (product model)
|
|
24
|
+
* - `batch` — GTIN + batch/lot (AI `10`)
|
|
25
|
+
* - `item` — GTIN + serial (AI `21`), optionally also batch
|
|
26
|
+
*/
|
|
27
|
+
exports.Gs1GranularitySchema = zod_1.z.enum(["model", "batch", "item"]);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const CreateUserDtoSchema: z.ZodObject<{
|
|
3
3
|
email: z.ZodEmail;
|
|
4
|
-
firstName: z.ZodString
|
|
5
|
-
lastName: z.ZodString
|
|
4
|
+
firstName: z.ZodOptional<z.ZodString>;
|
|
5
|
+
lastName: z.ZodOptional<z.ZodString>;
|
|
6
6
|
}, z.core.$strip>;
|
|
7
7
|
export type CreateUserDto = z.infer<typeof CreateUserDtoSchema>;
|
|
8
8
|
//# sourceMappingURL=create-user.dto.d.ts.map
|
|
@@ -4,6 +4,6 @@ exports.CreateUserDtoSchema = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.CreateUserDtoSchema = zod_1.z.object({
|
|
6
6
|
email: zod_1.z.email(),
|
|
7
|
-
firstName: zod_1.z.string(),
|
|
8
|
-
lastName: zod_1.z.string(),
|
|
7
|
+
firstName: zod_1.z.string().trim().max(100).optional(),
|
|
8
|
+
lastName: zod_1.z.string().trim().max(100).optional(),
|
|
9
9
|
});
|