@open-dpp/dto 3.0.0 → 3.1.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/unique-product-identifiers/gs1/gs1-digital-link.d.ts +12 -5
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.d.ts.map +1 -1
- package/dist/unique-product-identifiers/gs1/gs1-digital-link.js +14 -7
- package/package.json +1 -1
- package/src/unique-product-identifiers/gs1/gs1-digital-link.spec.ts +3 -3
- package/src/unique-product-identifiers/gs1/gs1-digital-link.ts +14 -6
|
@@ -129,14 +129,21 @@ export interface Gs1DigitalLinkParts {
|
|
|
129
129
|
*/
|
|
130
130
|
dataAttributes?: Record<string, string> | null;
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Path prefix (no leading/trailing slash) under which the GS1 resolver endpoint
|
|
134
|
+
* is mounted, between the resolver base and the `01/...` identity path.
|
|
135
|
+
* Must match the `Gs1ResolverController` route mounting in the backend.
|
|
136
|
+
*/
|
|
137
|
+
export declare const GS1_RESOLVER_PATH_PREFIX = "gs1/v1";
|
|
132
138
|
/**
|
|
133
139
|
* Build the uncompressed, canonical GS1 Digital Link for a GS1 identity.
|
|
134
140
|
*
|
|
135
|
-
* Emits the
|
|
136
|
-
* (AI `21`) segments in canonical GS1
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* values are percent-encoded
|
|
141
|
+
* Emits the resolver prefix (`gs1/v1`) followed by the GTIN path and, when
|
|
142
|
+
* present, the batch (AI `10`) and serial (AI `21`) segments in canonical GS1
|
|
143
|
+
* order `01 -> 10 -> 21`. A blank batch/serial is treated as absent. The
|
|
144
|
+
* resolver base is canonicalised (host lowercased, trailing slash dropped) and
|
|
145
|
+
* any path it carries is preserved; batch/serial values are percent-encoded
|
|
146
|
+
* for the path.
|
|
140
147
|
*
|
|
141
148
|
* @throws Error when the GTIN is invalid or a batch/serial violates CSET-82 /
|
|
142
149
|
* length / the dot-segment rule.
|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AAE,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
|
|
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;;;GA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AW,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAK5F;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,GACjD,MAAM,CAaR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAazE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.GS1_RESOLVER_PATH_PREFIX = 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
4
|
exports.isValidGtinCheckDigit = isValidGtinCheckDigit;
|
|
5
5
|
exports.normalizeToGtin14 = normalizeToGtin14;
|
|
6
6
|
exports.isValidCset82Component = isValidCset82Component;
|
|
@@ -268,21 +268,28 @@ function normalizeOptionalComponent(value, label) {
|
|
|
268
268
|
}
|
|
269
269
|
return trimmed;
|
|
270
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Path prefix (no leading/trailing slash) under which the GS1 resolver endpoint
|
|
273
|
+
* is mounted, between the resolver base and the `01/...` identity path.
|
|
274
|
+
* Must match the `Gs1ResolverController` route mounting in the backend.
|
|
275
|
+
*/
|
|
276
|
+
exports.GS1_RESOLVER_PATH_PREFIX = "gs1/v1";
|
|
271
277
|
/**
|
|
272
278
|
* Build the uncompressed, canonical GS1 Digital Link for a GS1 identity.
|
|
273
279
|
*
|
|
274
|
-
* Emits the
|
|
275
|
-
* (AI `21`) segments in canonical GS1
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* values are percent-encoded
|
|
280
|
+
* Emits the resolver prefix (`gs1/v1`) followed by the GTIN path and, when
|
|
281
|
+
* present, the batch (AI `10`) and serial (AI `21`) segments in canonical GS1
|
|
282
|
+
* order `01 -> 10 -> 21`. A blank batch/serial is treated as absent. The
|
|
283
|
+
* resolver base is canonicalised (host lowercased, trailing slash dropped) and
|
|
284
|
+
* any path it carries is preserved; batch/serial values are percent-encoded
|
|
285
|
+
* for the path.
|
|
279
286
|
*
|
|
280
287
|
* @throws Error when the GTIN is invalid or a batch/serial violates CSET-82 /
|
|
281
288
|
* length / the dot-segment rule.
|
|
282
289
|
*/
|
|
283
290
|
function buildGs1DigitalLink(resolverBase, parts) {
|
|
284
291
|
const base = (0, permalink_base_url_schema_1.canonicaliseBaseUrl)(resolverBase);
|
|
285
|
-
let url = `${base}/${buildGs1DigitalLinkPath(parts)}`;
|
|
292
|
+
let url = `${base}/${exports.GS1_RESOLVER_PATH_PREFIX}/${buildGs1DigitalLinkPath(parts)}`;
|
|
286
293
|
url += buildGs1DataAttributeQuery(parts.dataAttributes);
|
|
287
294
|
return url;
|
|
288
295
|
}
|
package/package.json
CHANGED
|
@@ -105,7 +105,7 @@ describe("RFC 3986 canonical encoding", () => {
|
|
|
105
105
|
gtin: "04006381333931",
|
|
106
106
|
serial: "A!'()*B",
|
|
107
107
|
});
|
|
108
|
-
expect(link).toBe("https://r.example/01/04006381333931/21/A%21%27%28%29%2AB");
|
|
108
|
+
expect(link).toBe("https://r.example/gs1/v1/01/04006381333931/21/A%21%27%28%29%2AB");
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
it("percent-encodes !'()* in data-attribute query values", () => {
|
|
@@ -121,10 +121,10 @@ describe("buildGs1DigitalLinkPath", () => {
|
|
|
121
121
|
);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
it("matches the path portion of buildGs1DigitalLink", () => {
|
|
124
|
+
it("matches the path portion of buildGs1DigitalLink behind the resolver prefix", () => {
|
|
125
125
|
const parts = { gtin: "04006381333931", batch: "B(1)", serial: "S:1" };
|
|
126
126
|
expect(buildGs1DigitalLink("https://r.example", parts)).toBe(
|
|
127
|
-
`https://r.example/${buildGs1DigitalLinkPath(parts)}`,
|
|
127
|
+
`https://r.example/gs1/v1/${buildGs1DigitalLinkPath(parts)}`,
|
|
128
128
|
);
|
|
129
129
|
});
|
|
130
130
|
});
|
|
@@ -311,21 +311,29 @@ function normalizeOptionalComponent(
|
|
|
311
311
|
return trimmed;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Path prefix (no leading/trailing slash) under which the GS1 resolver endpoint
|
|
316
|
+
* is mounted, between the resolver base and the `01/...` identity path.
|
|
317
|
+
* Must match the `Gs1ResolverController` route mounting in the backend.
|
|
318
|
+
*/
|
|
319
|
+
export const GS1_RESOLVER_PATH_PREFIX = "gs1/v1";
|
|
320
|
+
|
|
314
321
|
/**
|
|
315
322
|
* Build the uncompressed, canonical GS1 Digital Link for a GS1 identity.
|
|
316
323
|
*
|
|
317
|
-
* Emits the
|
|
318
|
-
* (AI `21`) segments in canonical GS1
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* values are percent-encoded
|
|
324
|
+
* Emits the resolver prefix (`gs1/v1`) followed by the GTIN path and, when
|
|
325
|
+
* present, the batch (AI `10`) and serial (AI `21`) segments in canonical GS1
|
|
326
|
+
* order `01 -> 10 -> 21`. A blank batch/serial is treated as absent. The
|
|
327
|
+
* resolver base is canonicalised (host lowercased, trailing slash dropped) and
|
|
328
|
+
* any path it carries is preserved; batch/serial values are percent-encoded
|
|
329
|
+
* for the path.
|
|
322
330
|
*
|
|
323
331
|
* @throws Error when the GTIN is invalid or a batch/serial violates CSET-82 /
|
|
324
332
|
* length / the dot-segment rule.
|
|
325
333
|
*/
|
|
326
334
|
export function buildGs1DigitalLink(resolverBase: string, parts: Gs1DigitalLinkParts): string {
|
|
327
335
|
const base = canonicaliseBaseUrl(resolverBase);
|
|
328
|
-
let url = `${base}/${buildGs1DigitalLinkPath(parts)}`;
|
|
336
|
+
let url = `${base}/${GS1_RESOLVER_PATH_PREFIX}/${buildGs1DigitalLinkPath(parts)}`;
|
|
329
337
|
url += buildGs1DataAttributeQuery(parts.dataAttributes);
|
|
330
338
|
return url;
|
|
331
339
|
}
|