@aidc-toolkit/gs1 1.0.32-beta → 1.0.34-beta

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.
Files changed (51) hide show
  1. package/README.md +290 -21
  2. package/dist/character-set.d.ts.map +1 -1
  3. package/dist/character-set.js +44 -11
  4. package/dist/character-set.js.map +1 -1
  5. package/dist/gcp-length-cache.d.ts +54 -15
  6. package/dist/gcp-length-cache.d.ts.map +1 -1
  7. package/dist/gcp-length-cache.js +181 -45
  8. package/dist/gcp-length-cache.js.map +1 -1
  9. package/dist/gcp-length-data.d.ts +74 -20
  10. package/dist/gcp-length-data.d.ts.map +1 -1
  11. package/dist/gcp-length-data.js +39 -15
  12. package/dist/gcp-length-data.js.map +1 -1
  13. package/dist/gcp-length.d.ts +1 -1
  14. package/dist/gcp-length.d.ts.map +1 -1
  15. package/dist/gcp-length.js +5 -6
  16. package/dist/gcp-length.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/locale/en/locale-resources.d.ts +39 -36
  22. package/dist/locale/en/locale-resources.d.ts.map +1 -1
  23. package/dist/locale/en/locale-resources.js +4 -1
  24. package/dist/locale/en/locale-resources.js.map +1 -1
  25. package/dist/locale/fr/locale-resources.d.ts +39 -36
  26. package/dist/locale/fr/locale-resources.d.ts.map +1 -1
  27. package/dist/locale/fr/locale-resources.js +4 -1
  28. package/dist/locale/fr/locale-resources.js.map +1 -1
  29. package/dist/locale/i18n.d.ts +6 -3
  30. package/dist/locale/i18n.d.ts.map +1 -1
  31. package/dist/locale/i18n.js +8 -6
  32. package/dist/locale/i18n.js.map +1 -1
  33. package/dist/numeric-identifier-validator.d.ts.map +1 -1
  34. package/dist/numeric-identifier-validator.js.map +1 -1
  35. package/dist/variable-measure.d.ts +4 -4
  36. package/dist/variable-measure.js +4 -4
  37. package/package.json +12 -10
  38. package/src/character-set.ts +55 -11
  39. package/src/gcp-length-cache.ts +208 -54
  40. package/src/gcp-length-data.ts +95 -27
  41. package/src/gcp-length.ts +5 -43
  42. package/src/index.ts +2 -1
  43. package/src/locale/en/locale-resources.ts +5 -2
  44. package/src/locale/fr/locale-resources.ts +5 -2
  45. package/src/locale/i18n.ts +9 -7
  46. package/src/locale/i18next.d.ts +2 -0
  47. package/src/numeric-identifier-validator.ts +1 -1
  48. package/src/variable-measure.ts +4 -4
  49. package/test/character-set.test.ts +46 -0
  50. package/test/gcp-length.test.ts +179 -240
  51. package/tsconfig-src.tsbuildinfo +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GS1 Package
2
2
 
3
- **Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit contributors**
3
+ **Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit contributors**
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
6
6
 
@@ -10,44 +10,313 @@ Unless required by applicable law or agreed to in writing, software distributed
10
10
 
11
11
  ## Overview
12
12
 
13
- > [!WARNING]
14
- >
15
- > **This software is in beta**, with production release is scheduled for 2025Q4. To follow the status of this and other projects, go to the AIDC Toolkit [projects](https://github.com/orgs/aidc-toolkit/projects) page.
13
+ The AIDC Toolkit `gs1` package provides functionality related to the GS1 identification system. It builds on the `utility` package, providing validation and creation functions customized for GS1 identifiers (e.g., including check digit validation and creation). All logic in this package is as defined in the [GS1 General Specifications](https://ref.gs1.org/standards/genspecs/).
16
14
 
17
- The AIDC Toolkit `gs1` package provides functionality related to the GS1 identification system. It builds on the `utility` package, providing validation and creation functions customized for GS1 identification keys (e.g., including check digit validation and creation). All logic in this package is as defined in the [GS1 General Specifications](https://www.gs1.org/genspecs).
15
+ ## Character Sets
18
16
 
19
- ## Check calculation and validation functions
17
+ The GS1 system supports four character sets:
18
+
19
+ - Numeric
20
+ - Digits '0' to '9'.
21
+ - Required by most GS1 identifiers.
22
+ - Required by many GS1 Application Identifiers.
23
+ - [Validator](https://aidc-toolkit.com/api/Utility/variables/NUMERIC_VALIDATOR.html) and [creator](https://aidc-toolkit.com/api/Utility/variables/NUMERIC_CREATOR.html) defined in the Utility package.
24
+ - GS1 AI encodable character set 82
25
+ - Equivalent to ISO/IEC 646 Table 1 - Unique graphic character allocations.
26
+ - Required by all non-numeric GS1 identifiers except CPID.
27
+ - Required by many GS1 Application Identifiers.
28
+ - [Validator](https://aidc-toolkit.com/api/GS1/variables/AI82_VALIDATOR.html) and [creator](https://aidc-toolkit.com/api/GS1/variables/AI82_CREATOR.html) defined in this package.
29
+ - GS1 AI encodable character set 39
30
+ - Digits '0' to '9', uppercase letters 'A' to 'Z', and the characters '#', '-', and '/'.
31
+ - Required by the CPID GS1 identifier.
32
+ - [Validator](https://aidc-toolkit.com/api/GS1/variables/AI39_VALIDATOR.html) and [creator](https://aidc-toolkit.com/api/GS1/variables/AI39_CREATOR.html) defined in this package.
33
+ - GS1 AI encodable character set 64
34
+ - Characters that result from base 64 encoding [as described in RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html#section-4).
35
+ - Required by GS1 Application Identifier 8030 Digital Signature.
36
+ - [Validator](https://aidc-toolkit.com/api/GS1/variables/AI64_VALIDATOR.html) defined in this package.
37
+ - No creator is defined as creation is the base 64 process.
38
+
39
+ ## Check Calculation and Validation Functions
20
40
 
21
41
  The check calculation and validation functions are separate from the string validation and creation functions so that they may be used in other contexts. All the check calculation functions defined in the GS1 General Specifications are implemented.
22
42
 
23
- ### Check digit - GS1 identification key
43
+ ### Check Digit - GS1 Identifier
24
44
 
25
- The [`checkDigit`](https://aidc-toolkit.com/api/GS1/functions/checkDigit.html) function calculates the check digit for a numeric GS1 identification key.
45
+ The [`checkDigit()`](https://aidc-toolkit.com/api/GS1/functions/checkDigit.html) function calculates the check digit for a numeric GS1 identifier.
26
46
 
27
- The [`hasValidCheckDigit`](https://aidc-toolkit.com/api/GS1/functions/hasValidCheckDigit.html) function validates the check digit for a numeric GS1 identification key.
47
+ The [`hasValidCheckDigit()`](https://aidc-toolkit.com/api/GS1/functions/hasValidCheckDigit.html) function validates the check digit for a numeric GS1 identifier.
28
48
 
29
- ### Check digit - price or weight encoding
49
+ ### Check Digit - Price or Weight Encoding
30
50
 
31
- The [`priceOrWeightCheckDigit`](https://aidc-toolkit.com/api/GS1/functions/priceOrWeightCheckDigit.html) function calculates the check digit for a price or weight.
51
+ The [`priceOrWeightCheckDigit()`](https://aidc-toolkit.com/api/GS1/functions/priceOrWeightCheckDigit.html) function calculates the check digit for a price or weight.
32
52
 
33
- The [`isValidPriceOrWeightCheckDigit`](https://aidc-toolkit.com/api/GS1/functions/isValidPriceOrWeightCheckDigit.html) function validates the check digit for a price or weight.
53
+ The [`isValidPriceOrWeightCheckDigit()`](https://aidc-toolkit.com/api/GS1/functions/isValidPriceOrWeightCheckDigit.html) function validates the check digit for a price or weight.
34
54
 
35
55
  These functions are seldom used directly, as there are no use cases for prices or weights on their own. They are used by the variable measure RCN functions if the RCN format requires a price or weight check digit.
36
56
 
37
- ### Check character pair - GS1 identification key
57
+ ### Check Character Pair - GS1 Identifier
58
+
59
+ The [`checkCharacterPair()`](https://aidc-toolkit.com/api/GS1/functions/checkCharacterPair.html) function calculates the check character pair for a non-numeric GS1 identifier, if supported.
60
+
61
+ The [`hasValidCheckCharacterPair()`](https://aidc-toolkit.com/api/GS1/functions/hasValidCheckCharacterPair.html) function validates the check character pair for a non-numeric GS1 identifier, if supported.
62
+
63
+ ## GS1 Identifiers
64
+
65
+ At the core of the AIDC Toolkit `gs1` package is GS1 identifier validation and creation. All GS1 identifier types are supported. A working knowledge of the [GS1 General Specifications](https://ref.gs1.org/standards/genspecs/) is highly recommended.
66
+
67
+ ### Prefix Type
68
+
69
+ Before going into the identifiers themselves, it's necessary to understand the prefix types supported by the GS1 system.
70
+
71
+ - [GS1 Company Prefix](https://aidc-toolkit.com/api/GS1/variables/PrefixTypes.html#gs1companyprefix)
72
+ - This is the core prefix type and the one to which all others can be converted. Every GS1 identifier contains a GS1 Company Prefix.
73
+ - For example, using GS1 Company Prefix 9521234 and item reference 99999, you can create the 13-digit GTIN 9521234999997. Similarly, using GS1 Company Prefix 9521234 and model reference ABCDEF, you can create the GMN 9521234ABCDEFK2.
74
+ - [U.P.C. Company Prefix](https://aidc-toolkit.com/api/GS1/variables/PrefixTypes.html#upccompanyprefix)
75
+ - This is a special version of the GS1 Company Prefix used **only** to create 12-digit GTINs. All U.P.C. Company Prefixes are issued directly or indirectly by GS1 US to support the requirement for 12-digit GTINs in the North American marketplace.
76
+ - For example, using U.P.C. Company Prefix 614141 and item reference 99999, you can create the 12-digit GTIN 614141999996.
77
+ - A U.P.C. Company Prefix may be used to create other GS1 identifiers, but it must first be converted to a GS1 Company Prefix by prepending a zero.
78
+ - For example, using U.P.C. Company Prefix 614141 and model reference ABCDEF, you can convert the prefix to GS1 Company Prefix 0614141 and create the GMN 0614141ABCDEF8P.
79
+ - [GS1-8 Prefix](https://aidc-toolkit.com/api/GS1/variables/PrefixTypes.html#gs18prefix)
80
+ - This is a special version of the GS1 Company Prefix used **only** to create 8-digit GTINs for special purpose applications where a trade item isn't large enough to support a 13-digit GTIN. GS1-8 Prefixes are managed by individual GS1 Member Organizations and, while they are supported within this library, they are not available to users directly.
81
+ - A GS1-8 Prefix may **not** be used to create other GS1 identifiers.
82
+
83
+ In general:
84
+
85
+ - If you are based outside North America and you are not selling product in the North American marketplace, you most likely have a GS1 Company Prefix.
86
+ - If you are based outside North America and you are selling product in the North American marketplace, you may have a *separate* U.P.C. Company Prefix for that purpose. This is not necessarily true for newer companies or product lines as the North American marketplace now fully supports 13-digit GTINs.
87
+ - If you are based inside North America, you most likely have a U.P.C. Company Prefix.
88
+
89
+ Another way to tell is to look at your existing barcodes. If the text beneath the barcode is 13 digits long, you have a GS1 Company Prefix. If the text beneath the barcode is 12 digits long, you have a U.P.C. Company Prefix.
90
+
91
+ If you're unsure, contact your local [GS1 Member Organization](https://www.gs1.org/contact/overview).
92
+
93
+ ### Identifier Types and Descriptors
94
+
95
+ All identifier types are supported. Constants are defined in [`IdentifierTypes`](https://aidc-toolkit.com/api/GS1/variables/IdentifierTypes.html), which is used to define the type alias [`IdentifierType`](https://aidc-toolkit.com/api/GS1/type-aliases/IdentifierType.html).
96
+
97
+ Internally, identifier types are broken down into categories. Each category builds on the one above by adding new properties, defined in a descriptor type:
98
+
99
+ - [Base identifier descriptor](https://aidc-toolkit.com/api/GS1/interfaces/IdentifierDescriptor.html)
100
+ - [Numeric identifier descriptor](https://aidc-toolkit.com/api/GS1/interfaces/NumericIdentifierDescriptor.html)
101
+ - [GTIN descriptor](https://aidc-toolkit.com/api/GS1/interfaces/GTINDescriptor.html) - Global Trade Item Number
102
+ - *GTIN-13*
103
+ - *GTIN-12*
104
+ - *GTIN-8*
105
+ - [Non-GTIN numeric identifier descriptor](https://aidc-toolkit.com/api/GS1/interfaces/NonGTINNumericIdentifierDescriptor.html)
106
+ - [Non-serializable numeric identifier descriptor](https://aidc-toolkit.com/api/GS1/interfaces/NonSerializableNumericIdentifierDescriptor.html)
107
+ - *GLN* - Global Location Number
108
+ - *SSCC* - Serial Shipping Container Code
109
+ - *GSRN* - Global Service Relation Number
110
+ - *GSIN* - Global Shipment Identification Number
111
+ - [Serializable numeric identifier descriptor](https://aidc-toolkit.com/api/GS1/interfaces/SerializableNumericIdentifierDescriptor.html)
112
+ - *GRAI* - Global Returnable Asset Identifier
113
+ - *GDTI* - Global Document Type Identifier
114
+ - *GCN* - Global Coupon Number
115
+ - [Non-numeric identifier descriptor](https://aidc-toolkit.com/api/GS1/interfaces/NonNumericIdentifierDescriptor.html)
116
+ - *GIAI* - Global Individual Asset Identifier
117
+ - *GINC* - Global Identification Number for Consignment
118
+ - *CPID* - Component/Part Identifier
119
+ - *GMN* - Global Model Number
120
+
121
+ The identifier descriptors are stored in a [record object](https://aidc-toolkit.com/api/GS1/variables/IdentifierDescriptors.html), keyed on identifier type. The GTIN entry is an array (GTIN-13, GTIN-12, and GTIN-8); all others are singletons. To deal with an unknown identifier descriptor, there are typeguards available, aligned with the categories above:
122
+
123
+ - [`isGTINDescriptors()`](https://aidc-toolkit.com/api/GS1/functions/isGTINDescriptors.html)
124
+ - Special case to identify the GTIN descriptors array entry.
125
+ - [`isNumericIdentifierDescriptor()`](https://aidc-toolkit.com/api/GS1/functions/isNumericIdentifierDescriptor.html)
126
+ - [`isGTINDescriptor()`](https://aidc-toolkit.com/api/GS1/functions/isGTINDescriptor.html)
127
+ - [`isNonGTINNumericIdentifierDescriptor()`](https://aidc-toolkit.com/api/GS1/functions/isNonGTINNumericIdentifierDescriptor.html)
128
+ - [`isNonSerializableNumericIdentifierDescriptor()`](https://aidc-toolkit.com/api/GS1/functions/isNonSerializableNumericIdentifierDescriptor.html)
129
+ - [`isSerializableNumericIdentifierDescriptor()`](https://aidc-toolkit.com/api/GS1/functions/isSerializableNumericIdentifierDescriptor.html)
130
+ - [`isNonNumericIdentifierDescriptor()`](https://aidc-toolkit.com/api/GS1/functions/isNonNumericIdentifierDescriptor.html)
131
+
132
+ ### Identifier Validation
133
+
134
+ Every identifier descriptor interface has a corresponding identifier validator class, which implements the interface and adds validation logic. The core method is [`validate()`](https://aidc-toolkit.com/api/GS1/classes/IdentifierValidator.html#validate), which takes an identifier string and either returns if valid or throws a [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) if not.
135
+
136
+ Validation is based on the string validation functions defined in the Utility package. As such, the `validate()` method can take additional validation parameters, depending on the identifier type.
137
+
138
+ - [Base identifier validator](https://aidc-toolkit.com/api/GS1/classes/IdentifierValidator.html)
139
+ - [Numeric identifier validator](https://aidc-toolkit.com/api/GS1/classes/NumericIdentifierValidator.html)
140
+ - Validation can include a position offset, but this is managed internally by derived classes.
141
+ - [GTIN validator](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html)
142
+ - [Non-GTIN numeric identifier validator](https://aidc-toolkit.com/api/GS1/classes/NonGTINNumericIdentifierValidator.html)
143
+ - [Non-serializable numeric identifier validator](https://aidc-toolkit.com/api/GS1/classes/NonSerializableNumericIdentifierValidator.html)
144
+ - [Serializable numeric identifier validator](https://aidc-toolkit.com/api/GS1/classes/SerializableNumericIdentifierValidator.html)
145
+ - [Non-numeric identifier validator](https://aidc-toolkit.com/api/GS1/classes/NonNumericIdentifierValidator.html)
146
+ - Validation can include exclusion of all-numeric references. The check character pair, if applicable, is not included in the all-numeric check (e.g., GMNs `9528888123423` and `952999912343X` both fail exclude all-numeric validation even though the latter has a non-numeric check character pair).
147
+
148
+ The identifier validators are stored in a [record object](https://aidc-toolkit.com/api/GS1/variables/IdentifierValidators.html), keyed on identifier type. The GTIN entry is an array (GTIN-13, GTIN-12, and GTIN-8); all others are singletons. To deal with an unknown identifier validator, there are typeguards available, aligned with the categories above:
149
+
150
+ - [`isGTINValidators()`](https://aidc-toolkit.com/api/GS1/functions/isGTINValidators.html)
151
+ - Special case to identify the GTIN validators array entry.
152
+ - [`isNumericIdentifierValidator()`](https://aidc-toolkit.com/api/GS1/functions/isNumericIdentifierValidator.html)
153
+ - [`isGTINValidator()`](https://aidc-toolkit.com/api/GS1/functions/isGTINValidator.html)
154
+ - [`isNonGTINNumericIdentifierValidator()`](https://aidc-toolkit.com/api/GS1/functions/isNonGTINNumericIdentifierValidator.html)
155
+ - [`isNonSerializableNumericIdentifierValidator()`](https://aidc-toolkit.com/api/GS1/functions/isNonSerializableNumericIdentifierValidator.html)
156
+ - [`isSerializableNumericIdentifierValidator()`](https://aidc-toolkit.com/api/GS1/functions/isSerializableNumericIdentifierValidator.html)
157
+ - [`isNonNumericIdentifierValidator()`](https://aidc-toolkit.com/api/GS1/functions/isNonNumericIdentifierValidator.html)
158
+
159
+ #### GTIN Validation
160
+
161
+ GTIN validation is special in that there are multiple lengths of GTINs and variations in use cases that limit what GTINs may be used for what purpose. To support this, there are static functions defined in the [`GTINValidator`](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html) class:
162
+
163
+ - [`zeroSuppress()`](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html#zerosuppress) - Applies a special compression algorithm to certain GTIN-12s to suppress zeros and reduce the length to 8 digits for encoding in a UPC-E barcode.
164
+ - [`zeroExpand()`](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html#zeroexpand) - Expands a zero-suppressed GTIN-12 to its original form.
165
+ - [`convertToGTIN14()`](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html#converttogtin14) - Converts any GTIN to GTIN-14 form with an indicator digit. If the indicator digit is not provided, the default is "0", unless the input is already a GTIN-14, in which case the indicator digit is preserved.
166
+ - [`normalize()`](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html#normalize) - Normalizes a GTIN to the shortest form possible.
167
+ - [`validateAny()`](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html#validateany) - Validates a GTIN of any length and optionally against the [level at which it is used](https://aidc-toolkit.com/api/GS1/variables/GTINLevels.html).
168
+ - [`validateGTIN14()`](https://aidc-toolkit.com/api/GS1/classes/GTINValidator.html#validategtin14) - The GTIN-14 doesn't have its own instance of `GTINValidator` as it is subordinate to the other lengths, so this method specifically validates a GTIN-14.
169
+
170
+ ### Identifier Creation
171
+
172
+ Every identifier validator class has an extending identifier creator class which adds creation logic. To create an identifier, **you must have a properly licensed GS1 Company Prefix or U.P.C. Company Prefix**. To acquire a licence, contact your local [GS1 Member Organization](https://www.gs1.org/contact/overview).
173
+
174
+ Creation is based on the string creation functions defined in the Utility package, with additional rules for prefixes and check digits and check character pairs. The constructor for every class takes a [`PrefixProvider`](https://aidc-toolkit.com/api/GS1/interfaces/PrefixProvider.html) object, which defines the prefix type and the prefix itself. Every class has one or more `create*()` methods whose parameters depend on the identifier type.
175
+
176
+ Architecturally, base functionality is defined via interfaces, with only concrete classes exposed.
177
+
178
+ - [Base identifier creator](https://aidc-toolkit.com/api/GS1/interfaces/IdentifierCreator.html)
179
+ - [Numeric identifier creator](https://aidc-toolkit.com/api/GS1/interfaces/NumericIdentifierCreator.html)
180
+ - [`create()`](https://aidc-toolkit.com/api/GS1/interfaces/NumericIdentifierCreator.html#create) - Create a single numeric identifier or a sequence of numeric identifiers.
181
+ - [`createAll()`](https://aidc-toolkit.com/api/GS1/interfaces/NumericIdentifierCreator.html#createall) - Create all numeric identifiers for a prefix.
182
+ - [GTIN creator](https://aidc-toolkit.com/api/GS1/classes/GTINCreator.html)
183
+ - [`createGTIN14()`](https://aidc-toolkit.com/api/GS1/classes/GTINCreator.html#creategtin14) - Create a single GTIN-14 or a sequence of GTIN-14s.
184
+ - [Non-GTIN numeric identifier creator](https://aidc-toolkit.com/api/GS1/interfaces/NonGTINNumericIdentifierCreator.html)
185
+ - [Non-serializable numeric identifier creator](https://aidc-toolkit.com/api/GS1/classes/NonSerializableNumericIdentifierCreator.html)
186
+ - [Serializable numeric identifier creator](https://aidc-toolkit.com/api/GS1/classes/SerializableNumericIdentifierCreator.html)
187
+ - [`createSerialized()`](https://aidc-toolkit.com/api/GS1/classes/SerializableNumericIdentifierCreator.html#createserialized) - Create a single serialized numeric identifier or a sequence of serialized numeric identifiers.
188
+ - [`concatenate()`](https://aidc-toolkit.com/api/GS1/classes/SerializableNumericIdentifierCreator.html#concatenate) - Concatenate a base (non-serialized) with a single serialized component or a sequence of serialized components.
189
+ - [Non-numeric identifier creator](https://aidc-toolkit.com/api/GS1/classes/NonNumericIdentifierCreator.html)
190
+ - [`create()`](https://aidc-toolkit.com/api/GS1/classes/NonNumericIdentifierCreator.html#create) - Create a single non-numeric identifier or a sequence of non-numeric i[numeric-identifier-creator.ts](src/numeric-identifier-creator.ts)dentifiers.
191
+
192
+ Because identifier creators depend on a prefix, there are no instantiations of them. To deal with an unknown identifier creator, there are typeguards available, aligned with the categories above:
193
+
194
+ - [`isNumericIdentifierCreator()`](https://aidc-toolkit.com/api/GS1/functions/isNumericIdentifierCreator.html)
195
+ - [`isGTINCreator()`](https://aidc-toolkit.com/api/GS1/functions/isGTINCreator.html)
196
+ - [`isNonGTINNumericIdentifierCreator()`](https://aidc-toolkit.com/api/GS1/functions/isNonGTINNumericIdentifierCreator.html)
197
+ - [`isNonSerializableNumericIdentifierCreator()`](https://aidc-toolkit.com/api/GS1/functions/isNonSerializableNumericIdentifierCreator.html)
198
+ - [`isSerializableNumericIdentifierCreator()`](https://aidc-toolkit.com/api/GS1/functions/isSerializableNumericIdentifierCreator.html)
199
+ - [`isNonNumericIdentifierCreator()`](https://aidc-toolkit.com/api/GS1/functions/isNonNumericIdentifierCreator.html)
200
+
201
+ #### Sparse Creation
202
+
203
+ In some cases it may be necessary, or at least desirable, to obfuscate the sequence of identifiers. Suppose, for example, that a distributor is tracking a manufacturer's SSCCs (container identifiers), and that those identifiers are sequential. Not every container goes to the distributor, but over time the distributor infers, based only on the sequence, that the manufacturer is shipping 1,000 containers per day. A year later, that estimate is down to 800 per day. With nothing more than the SSCCs, the distributor can reasonably infer that the manufacturer's business is down 20%. This is market intelligence that can be used in contract negotiation or in stock trading.
204
+
205
+ Generating a sparse sequence of identifiers can obfuscate shipping volume, product breadth, and more. Sparse creation is supported directly for numeric identifier types and indirectly for non-numeric identifier types.
206
+
207
+ The `create()` method for numeric identifiers takes an optional `sparse` parameter:
208
+
209
+ ```typescript
210
+ import { Sequence } from "@aidc-toolkit/utility";
211
+ import { PrefixManager } from "./prefix-manager.js";
212
+ import { PrefixTypes } from "./prefix-type.js";
213
+
214
+ const prefixManager = PrefixManager.get(PrefixTypes.GS1CompanyPrefix, "9521234");
215
+ const ssccCreator = prefixManager.ssccCreator;
216
+
217
+ // [
218
+ // '095212340000000006',
219
+ // '095212340000000013',
220
+ // '095212340000000020',
221
+ // '095212340000000037'
222
+ // ]
223
+ console.log(Array.from(ssccCreator.create(new Sequence(0, 4))));
224
+
225
+ // [
226
+ // '695212348513196058',
227
+ // '095212342385021768',
228
+ // '895212341183340022',
229
+ // '695212347219122989'
230
+ // ]
231
+ console.log(Array.from(ssccCreator.create(new Sequence(0, 4), true)));
232
+ ```
233
+
234
+ Each call to `create()` returns the first four SSCCs in sequence, but the second call uses the [`EncryptionTransformer`](https://aidc-toolkit.com/api/Utility/classes/EncryptionTransformer.html) to obfuscate the sequence.
235
+
236
+ The `create()` method for non-numeric identifiers works on a string or sequence of strings, so it doesn't support the `sparse` parameter. The obfuscation must applied to the strings before they are passed to the creator:
237
+
238
+ ```typescript
239
+ import { ALPHANUMERIC_CREATOR, Exclusions, Sequence } from "@aidc-toolkit/utility";
240
+ import { PrefixManager } from "./prefix-manager.js";
241
+ import { PrefixTypes } from "./prefix-type.js";
242
+
243
+ const prefixManager = PrefixManager.get(PrefixTypes.GS1CompanyPrefix, "9521234");
244
+ const gmnCreator = prefixManager.gmnCreator;
245
+
246
+ // [
247
+ // '9521234000000006X',
248
+ // '9521234000000016Z',
249
+ // '95212340000000273',
250
+ // '95212340000000375'
251
+ // ]
252
+ console.log(Array.from(gmnCreator.create(
253
+ ALPHANUMERIC_CREATOR.create(8, new Sequence(0, 4))
254
+ )));
255
+
256
+ // [
257
+ // '9521234DYA4ZLUR26',
258
+ // '9521234L89JPA7WKV',
259
+ // '9521234G64FQHPSFR',
260
+ // '9521234I5OZPGZL23'
261
+ // ]
262
+ console.log(Array.from(gmnCreator.create(
263
+ ALPHANUMERIC_CREATOR.create(8, new Sequence(0, 4), Exclusions.None, 123456)
264
+ )));
265
+ ```
266
+
267
+ Again, each call to `create()` returns the first four GMNs in sequence (indirectly via the alphanumeric string creator), but the second call uses the [`EncryptionTransformer`](https://aidc-toolkit.com/api/Utility/classes/EncryptionTransformer.html) to obfuscate the sequence.
268
+
269
+ ### Prefix Manager
270
+
271
+ The [`PrefixProvider`](https://aidc-toolkit.com/api/GS1/interfaces/PrefixProvider.html) required by every identifier creator is just an object. It has no validation logic, and the creator classes assume that its contents are correct. The [`PrefixManager`](https://aidc-toolkit.com/api/GS1/classes/PrefixManager.html) class implements the `PrefixProvider` interface and provides a convenient way to access the various identifier creators. It also manages the tweak values for sparse numeric identifier creation.
272
+
273
+ There are two ways to create a `PrefixManager`, both of which take a [prefix type](https://aidc-toolkit.com/api/GS1/type-aliases/PrefixType.html) and a prefix:
274
+
275
+ - Directly via the constructor.
276
+ - Indirectly via the [`PrefixManager.get()`](https://aidc-toolkit.com/api/GS1/classes/PrefixManager.html#get) static method.
277
+
278
+ Using the static method is preferred because guarantees that only one instance of the prefix manager is maintained for each prefix and it preserves changes to the prefix manager, such as setting the tweak factor for sparse numeric identifier creation.
279
+
280
+ The default tweak factor for sparse numeric identifier creation is the numeric value of "1" plus the GS1 Company Prefix (e.g., 19521234 for GS1 Company Prefix 9521234, 10614141 for U.P.C. Company Prefix 614141). The tweak factor isn't used directly by the identifier creators; instead, it is used as a multiplier together with an internally-defined prime number per numeric identifier type so that each numeric identifier creator returns a different sequence of identifiers.
281
+
282
+ The prefix manager maintains a cache of identifier creators, each accessible by name (e.g., `prefixManager.ssccCreator` for the SSCC creator), as well as the method [`getIdentifierCreator()`](https://aidc-toolkit.com/api/GS1/classes/PrefixManager.html#getidentifiercreator) to get any identifier creator by identifier type.
283
+
284
+ ### Additional Identifier Capability
285
+
286
+ #### Variable Measure
287
+
288
+ The [`VariableMeasure`](https://aidc-toolkit.com/api/GS1/classes/VariableMeasure.html) class provides static methods to parse and create a variable measure identifiers:
289
+
290
+ - [`parseRCN()`](https://aidc-toolkit.com/api/GS1/classes/VariableMeasure.html#parsercn) - Parse a Restricted Circulation Number (RCN) into an item reference and price or weight.
291
+ - [`createRCN()`](https://aidc-toolkit.com/api/GS1/classes/VariableMeasure.html#creatercn) - Create a Restricted Circulation Number (RCN) from an item reference and price or weight.
292
+
293
+ ### GS1 Services
294
+
295
+ GS1 provides a lookup service called [Verified by GS1](https://www.gs1.org/services/verified-by-gs1) that can be used to retrieve basic information about a product (GTIN) or party/location (GLN), as well as GS1 Company Prefix licence information for all identifier types. It also provides a barcode/EPC interoperability table (https://www.gs1.org/standards/bc-epc-interop) that can be used to determine the length of a GS1 Company Prefix for encoding GS1 identifiers as EPC URNs.
296
+
297
+ #### Verified by GS1
298
+
299
+ The [`verifiedByGS1()`](https://aidc-toolkit.com/api/GS1/functions/verifiedByGS1.html) function creates a [`Hyperlink`](https://aidc-toolkit.com/api/Core/interfaces/Hyperlink.html) object with the appropriate path to query any GS1 identifier. The link is to a user interface, so automated retrieval of the data is not supported.
300
+
301
+ #### GS1 Company Prefix Length Determination
302
+
303
+ GS1 Company Prefix length determination is required when encoding a GS1 identifier as an EPC URN. Though this is typically done by the GS1 Company Prefix licensee (who knows the length), it's occasionally required by downstream trading partners such as distributors.
38
304
 
39
- The [`checkCharacterPair`](https://aidc-toolkit.com/api/GS1/functions/checkCharacterPair.html) function calculates the check character pair for a non-numeric GS1 identification key, if supported.
305
+ This functionality part of the [`PrefixManager`](https://aidc-toolkit.com/api/GS1/classes/PrefixManager.html) class.
40
306
 
41
- The [`hasValidCheckCharacterPair`](https://aidc-toolkit.com/api/GS1/functions/hasValidCheckCharacterPair.html) function validates the check character pair for a non-numeric GS1 identification key, if supported.
307
+ The first step is to load the GS1 Company Prefix length data. This is done using [`loadGCPLengthData()`](https://aidc-toolkit.com/api/GS1/classes/PrefixManager.html#loadgcplengthdata) static method, which takes a [`GCPLengthCache`](https://aidc-toolkit.com/api/GS1/classes/GCPLengthCache.html) object. The cache object is used to store the data so that it can be shared across multiple instances of the prefix manager.
42
308
 
43
- ## GS1 identification keys
309
+ The `loadGCPLengthData()` method works as follows:
44
310
 
45
- At the core of the AIDC Toolkit `gs1` package is GS1 identification key validation and creation. All GS1 identification key types are supported. A working knowledge of the [GS1 General Specifications](https://www.gs1.org/genspecs) is highly recommended.
311
+ - If the next check date/time is in the future, the method returns immediately, regardless of whether any data is available. It does this to prevent a large number of requests to the source in the event of a failure.
312
+ - Otherwise, if the cache date/time is undefined or less than the source date/time, it loads from the source, converts the data if necessary, and updates the cache.
313
+ - Otherwise, it continues with the cached data.
314
+ - The next check date/time is updated to the later of the source date/time plus one week and the current date/time plus one day.
46
315
 
47
- ### Prefix manager
316
+ The base class implementation of the `GCPLengthCache` manages only the cache itself, and it requires an application-provided [`AppDataStorage`](https://aidc-toolkit.com/api/Core/classes/AppDataStorage.html) storage implementation. The source is expected to be either a [`GCPLengthData`](https://aidc-toolkit.com/api/GS1/interfaces/GCPLengthData.html) object (created via another cache implementation) or a [`GCPLengthSourceJSON`](https://aidc-toolkit.com/api/GS1/interfaces/GCPLengthSourceJSON.html) object, which is the format of the file provided by GS1.
48
317
 
49
- #### Prefix type
318
+ The [`RemoteGCPLengthCache`](https://aidc-toolkit.com/api/GS1/classes/RemoteGCPLengthCache.html) class provides access to the data from a remote source, by default the AIDC Toolkit website. If any error occurs, the next check date/time is set to the current date/time plus ten minutes to prevent the network from being overloaded.
50
319
 
51
- ### GS1 identification key validation
320
+ The data on the AIDC Toolkit website is updated regularly with the data provided by GS1, and it's stored in binary format for faster retrieval.
52
321
 
53
- ### GS1 identification key creation
322
+ Once the data is loaded, the [`gcpLength()`](https://aidc-toolkit.com/api/GS1/classes/PrefixManager.html#gcplength) method can be used to get the length of a GS1 Company Prefix for a given identifier type.
@@ -1 +1 @@
1
- {"version":3,"file":"character-set.d.ts","sourceRoot":"","sources":["../src/character-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAc,MAAM,uBAAuB,CAAC;AAE/F;;;GAGG;AACH,eAAO,MAAM,YAAY,qBASA,CAAC;AAE1B;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAmB,qBAAqB,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,YAAY,qBAKA,CAAC;AAE1B;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAmB,qBAAqB,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,cAAc,uBASzB,CAAC"}
1
+ {"version":3,"file":"character-set.d.ts","sourceRoot":"","sources":["../src/character-set.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EAEnB,qBAAqB,EAExB,MAAM,uBAAuB,CAAC;AAG/B;;;GAGG;AACH,eAAO,MAAM,YAAY,qBASA,CAAC;AAE1B;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAmB,qBAAqB,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,YAAY,qBAKA,CAAC;AAE1B;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAmB,qBAAqB,CAAC;AAiDpE;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,qBAAuD,CAAC"}
@@ -1,4 +1,5 @@
1
- import { CharacterSetCreator, CharacterSetValidator, Exclusions } from "@aidc-toolkit/utility";
1
+ import { CharacterSetCreator, CharacterSetValidator, Exclusions, utilityNS } from "@aidc-toolkit/utility";
2
+ import { i18nextGS1 } from "./locale/i18n.js";
2
3
  /**
3
4
  * GS1 AI encodable character set 82 creator as defined in section 7.11 of the {@link
4
5
  * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
@@ -33,18 +34,50 @@ export const AI39_CREATOR = new CharacterSetCreator([
33
34
  * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Supports {@linkcode Exclusions.AllNumeric}.
34
35
  */
35
36
  export const AI39_VALIDATOR = AI39_CREATOR;
37
+ /**
38
+ * GS1 AI encodable character set 64 validator with additional base64 validation of length (multiple of 4) and position
39
+ * of equal sign (last or last two characters).
40
+ */
41
+ class AI64CharacterSetValidator extends CharacterSetValidator {
42
+ /**
43
+ * Constructor.
44
+ */
45
+ constructor() {
46
+ super(([
47
+ "-",
48
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
49
+ "=",
50
+ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
51
+ "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
52
+ "_",
53
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
54
+ "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
55
+ ]));
56
+ }
57
+ /**
58
+ * @inheritDoc
59
+ */
60
+ validate(s, validation) {
61
+ super.validate(s, validation);
62
+ const length = s.length;
63
+ if (length % 4 !== 0) {
64
+ throw new RangeError(i18nextGS1.t("AI64CharacterSetValidator.lengthMustBeMultipleOf4", {
65
+ length
66
+ }));
67
+ }
68
+ const equalIndex = s.search(/={1,2}/u);
69
+ if (equalIndex !== -1 && equalIndex < length - 2) {
70
+ throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
71
+ ns: utilityNS,
72
+ c: "=",
73
+ position: equalIndex
74
+ }));
75
+ }
76
+ }
77
+ }
36
78
  /**
37
79
  * GS1 AI encodable character set 64 validator as defined in section 7.11 of the {@link
38
80
  * https://ref.gs1.org/standards/genspecs/ | GS1 General Specifications}. Doesn't support any exclusions.
39
81
  */
40
- export const AI64_VALIDATOR = new CharacterSetValidator([
41
- "-",
42
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
43
- "=",
44
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
45
- "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
46
- "_",
47
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
48
- "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
49
- ]);
82
+ export const AI64_VALIDATOR = new AI64CharacterSetValidator();
50
83
  //# sourceMappingURL=character-set.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"character-set.js","sourceRoot":"","sources":["../src/character-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE/F;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC;IAChD,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,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M,CAAC,MAAM,cAAc,GAA0B,IAAI,yBAAyB,EAAE,CAAC"}
@@ -1,35 +1,74 @@
1
- import { Cache } from "@aidc-toolkit/core";
2
- import { type GCPLengthData } from "./gcp-length-data.js";
1
+ import { type AppDataStorage, Cache } from "@aidc-toolkit/core";
2
+ import { type GCPLengthData, type GCPLengthSourceJSON } from "./gcp-length-data.js";
3
3
  /**
4
4
  * GS1 Company Prefix length cache.
5
5
  */
6
- export declare abstract class GCPLengthCache extends Cache<GCPLengthData, GCPLengthData | string> {
6
+ export declare abstract class GCPLengthCache extends Cache<GCPLengthData, GCPLengthData | GCPLengthSourceJSON> {
7
+ #private;
8
+ /**
9
+ * Storage key for full application data object.
10
+ */
11
+ static APP_DATA_STORAGE_KEY: string;
12
+ /**
13
+ * Storage key for next check date/time.
14
+ */
15
+ static NEXT_CHECK_DATE_TIME_STORAGE_KEY: string;
16
+ /**
17
+ * Storage key for header information (date/time and disclaimer).
18
+ */
19
+ static HEADER_STORAGE_KEY: string;
20
+ /**
21
+ * Storage key for data only.
22
+ */
23
+ static DATA_STORAGE_KEY: string;
24
+ /**
25
+ * Constructor.
26
+ *
27
+ * @param appDataStorage
28
+ * Application data storage.
29
+ */
30
+ constructor(appDataStorage: AppDataStorage<boolean>);
31
+ /**
32
+ * Get the application data storage.
33
+ */
34
+ get appDataStorage(): AppDataStorage<boolean>;
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ get nextCheckDateTime(): Promise<Date | undefined>;
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ get cacheDateTime(): Promise<Date | undefined>;
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ get cacheData(): Promise<GCPLengthData>;
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ update(nextCheckDateTime: Date, _cacheDateTime?: Date, cacheData?: GCPLengthData): Promise<void>;
7
51
  }
8
52
  /**
9
53
  * GS1 Company Prefix length cache with remote source.
10
54
  */
11
- export declare abstract class RemoteGCPLengthCache extends GCPLengthCache {
55
+ export declare class RemoteGCPLengthCache extends GCPLengthCache {
12
56
  #private;
13
57
  /**
14
58
  * Default base URL pointing to AIDC Toolkit website data directory.
15
59
  */
16
60
  static DEFAULT_BASE_URL: string;
17
- /**
18
- * File containing header information (date/time and disclaimer).
19
- */
20
- static SOURCE_HEADER_FILE_NAME: string;
21
- /**
22
- * File containing tree data in binary form.
23
- */
24
- static SOURCE_DATA_FILE_NAME: string;
25
61
  /**
26
62
  * Constructor.
27
63
  *
64
+ * @param appDataStorage
65
+ * Application data storage.
66
+ *
28
67
  * @param baseURL
29
- * Base URL. The URL must end with a slash, and must host the {@linkcode SOURCE_HEADER_FILE_NAME} and {@linkcode
30
- * SOURCE_DATA_FILE_NAME} files.
68
+ * Base URL. The URL must not end with a slash and must host the `gcp-length-header.json` and `gcp-length-data.bin`
69
+ * files.
31
70
  */
32
- constructor(baseURL?: string);
71
+ constructor(appDataStorage: AppDataStorage<boolean>, baseURL?: string);
33
72
  /**
34
73
  * @inheritDoc
35
74
  */
@@ -1 +1 @@
1
- {"version":3,"file":"gcp-length-cache.d.ts","sourceRoot":"","sources":["../src/gcp-length-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,aAAa,EAA8C,MAAM,sBAAsB,CAAC;AAGtG;;GAEG;AACH,8BAAsB,cAAe,SAAQ,KAAK,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC;CACxF;AAED;;GAEG;AACH,8BAAsB,oBAAqB,SAAQ,cAAc;;IAC7D;;OAEG;IACH,MAAM,CAAC,gBAAgB,SAAoC;IAE3D;;OAEG;IACH,MAAM,CAAC,uBAAuB,SAA4B;IAE1D;;OAEG;IACH,MAAM,CAAC,qBAAqB,SAAyB;IAYrD;;;;;;OAMG;gBACS,OAAO,GAAE,MAA8C;IAoCnE;;OAEG;IACH,IAAI,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAQlC;IAED;;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