@open-dpp/dto 2.10.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.
Files changed (42) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +4 -0
  4. package/dist/permalinks/permalink.dto.d.ts +3690 -9
  5. package/dist/permalinks/permalink.dto.d.ts.map +1 -1
  6. package/dist/permalinks/permalink.dto.js +89 -6
  7. package/dist/shared/permalink-base-url.schema.d.ts +1 -0
  8. package/dist/shared/permalink-base-url.schema.d.ts.map +1 -1
  9. package/dist/shared/permalink-base-url.schema.js +9 -0
  10. package/dist/unique-product-identifiers/create-internal-unique-product-identifier.dto.d.ts +6 -0
  11. package/dist/unique-product-identifiers/create-internal-unique-product-identifier.dto.d.ts.map +1 -0
  12. package/dist/unique-product-identifiers/create-internal-unique-product-identifier.dto.js +9 -0
  13. package/dist/unique-product-identifiers/create-unique-product-identifier.dto.d.ts +9 -0
  14. package/dist/unique-product-identifiers/create-unique-product-identifier.dto.d.ts.map +1 -0
  15. package/dist/unique-product-identifiers/create-unique-product-identifier.dto.js +13 -0
  16. package/dist/unique-product-identifiers/gs1/gs1-ai-description.d.ts +6 -4
  17. package/dist/unique-product-identifiers/gs1/gs1-ai-description.d.ts.map +1 -1
  18. package/dist/unique-product-identifiers/gs1/gs1-ai-description.js +13 -3
  19. package/dist/unique-product-identifiers/gs1/gs1-digital-link.d.ts +22 -5
  20. package/dist/unique-product-identifiers/gs1/gs1-digital-link.d.ts.map +1 -1
  21. package/dist/unique-product-identifiers/gs1/gs1-digital-link.js +33 -12
  22. package/dist/unique-product-identifiers/unique-product-identifier-list-item.dto.d.ts +104 -0
  23. package/dist/unique-product-identifiers/unique-product-identifier-list-item.dto.d.ts.map +1 -0
  24. package/dist/unique-product-identifiers/unique-product-identifier-list-item.dto.js +42 -0
  25. package/dist/unique-product-identifiers/unique-product-identifier-type.d.ts +1 -1
  26. package/dist/unique-product-identifiers/update-unique-product-identifier.dto.d.ts +8 -0
  27. package/dist/unique-product-identifiers/update-unique-product-identifier.dto.d.ts.map +1 -0
  28. package/dist/unique-product-identifiers/update-unique-product-identifier.dto.js +12 -0
  29. package/package.json +1 -1
  30. package/src/index.ts +4 -0
  31. package/src/permalinks/permalink.dto.spec.ts +469 -0
  32. package/src/permalinks/permalink.dto.ts +103 -5
  33. package/src/shared/permalink-base-url.schema.spec.ts +17 -1
  34. package/src/shared/permalink-base-url.schema.ts +8 -0
  35. package/src/unique-product-identifiers/create-internal-unique-product-identifier.dto.ts +11 -0
  36. package/src/unique-product-identifiers/create-unique-product-identifier.dto.ts +15 -0
  37. package/src/unique-product-identifiers/gs1/gs1-ai-description.spec.ts +14 -0
  38. package/src/unique-product-identifiers/gs1/gs1-ai-description.ts +16 -5
  39. package/src/unique-product-identifiers/gs1/gs1-digital-link.spec.ts +17 -1
  40. package/src/unique-product-identifiers/gs1/gs1-digital-link.ts +35 -11
  41. package/src/unique-product-identifiers/unique-product-identifier-list-item.dto.ts +64 -0
  42. package/src/unique-product-identifiers/update-unique-product-identifier.dto.ts +14 -0
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateGs1UniqueProductIdentifierRequestSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const gs1_digital_link_1 = require("./gs1/gs1-digital-link");
6
+ exports.UpdateGs1UniqueProductIdentifierRequestSchema = zod_1.z
7
+ .object({
8
+ gtin: gs1_digital_link_1.GtinInputSchema,
9
+ batch: gs1_digital_link_1.Cset82ComponentInputSchema.optional(),
10
+ serial: gs1_digital_link_1.Cset82ComponentInputSchema.optional(),
11
+ })
12
+ .meta({ id: "UpdateGs1UniqueProductIdentifierRequest" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-dpp/dto",
3
- "version": "2.10.0",
3
+ "version": "3.1.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/open-dpp/open-dpp#readme",
package/src/index.ts CHANGED
@@ -90,3 +90,7 @@ export * from "./users/user.dto";
90
90
  export * from "./activity-history/activity-history.dto";
91
91
  export * from "./activity-history/change-event-types.dto";
92
92
  export * from "./activity-history/activity-types.dto";
93
+ export * from "./unique-product-identifiers/unique-product-identifier-list-item.dto";
94
+ export * from "./unique-product-identifiers/create-unique-product-identifier.dto";
95
+ export * from "./unique-product-identifiers/create-internal-unique-product-identifier.dto";
96
+ export * from "./unique-product-identifiers/update-unique-product-identifier.dto";
@@ -1,7 +1,12 @@
1
1
  import { describe, expect, it } from "@jest/globals";
2
2
  import {
3
+ LEGACY_PERMALINK_KIND,
3
4
  PassportPermalinkBundleDtoSchema,
4
5
  PermalinkDtoSchema,
6
+ PermalinkInvariantsSchema,
7
+ PermalinkKind,
8
+ PermalinkKindSchema,
9
+ PermalinkPaginationDtoSchema,
5
10
  PermalinkPublishedUrlSchema,
6
11
  PermalinkPublicDtoSchema,
7
12
  } from "./permalink.dto";
@@ -54,6 +59,17 @@ describe("PassportPermalinkBundleDtoSchema", () => {
54
59
  expect(result.success).toBe(true);
55
60
  });
56
61
 
62
+ it("accepts presentationConfiguration: null (standard view, no customization)", () => {
63
+ const result = PassportPermalinkBundleDtoSchema.safeParse({
64
+ ...validBundle,
65
+ presentationConfiguration: null,
66
+ });
67
+ expect(result.success).toBe(true);
68
+ if (result.success) {
69
+ expect(result.data.presentationConfiguration).toBeNull();
70
+ }
71
+ });
72
+
57
73
  it("rejects a bundle missing the branding key", () => {
58
74
  const { branding: _branding, ...rest } = validBundle;
59
75
  const result = PassportPermalinkBundleDtoSchema.safeParse(rest);
@@ -83,6 +99,7 @@ const permalinkId = "44444444-4444-4444-8444-444444444444";
83
99
 
84
100
  const validPublic = {
85
101
  id: permalinkId,
102
+ passportId,
86
103
  slug: "acme-widget",
87
104
  baseUrl: "https://override.example.com",
88
105
  presentationConfigurationId: configId,
@@ -171,6 +188,7 @@ describe("PermalinkPublishedUrlSchema", () => {
171
188
  describe("PermalinkDtoSchema publishedUrl", () => {
172
189
  const validPermalink = {
173
190
  id: permalinkId,
191
+ passportId,
174
192
  slug: "acme-widget",
175
193
  baseUrl: null,
176
194
  presentationConfigurationId: configId,
@@ -204,3 +222,454 @@ describe("PermalinkDtoSchema publishedUrl", () => {
204
222
  expect(result.success).toBe(false);
205
223
  });
206
224
  });
225
+
226
+ const upiId = "55555555-5555-4555-8555-555555555555";
227
+
228
+ describe("PermalinkKind", () => {
229
+ it("exposes OPEN_DPP and GS1_LINK constants", () => {
230
+ expect(PermalinkKind.OPEN_DPP).toBe("open-dpp");
231
+ expect(PermalinkKind.GS1_LINK).toBe("gs1-link");
232
+ });
233
+
234
+ it("exposes the legacy wire value for on-read migration", () => {
235
+ expect(LEGACY_PERMALINK_KIND).toBe("presentation");
236
+ });
237
+
238
+ it("PermalinkKindSchema accepts 'open-dpp' and 'gs1-link'", () => {
239
+ expect(PermalinkKindSchema.safeParse("open-dpp").success).toBe(true);
240
+ expect(PermalinkKindSchema.safeParse("gs1-link").success).toBe(true);
241
+ });
242
+
243
+ it("PermalinkKindSchema rejects the legacy 'presentation' value (mapped upstream)", () => {
244
+ expect(PermalinkKindSchema.safeParse("presentation").success).toBe(false);
245
+ });
246
+
247
+ it("PermalinkKindSchema rejects unknown values", () => {
248
+ expect(PermalinkKindSchema.safeParse("other").success).toBe(false);
249
+ expect(PermalinkKindSchema.safeParse("").success).toBe(false);
250
+ });
251
+ });
252
+
253
+ describe("PermalinkDtoSchema polymorphism", () => {
254
+ const base = {
255
+ id: permalinkId,
256
+ passportId,
257
+ slug: "acme-widget",
258
+ baseUrl: null,
259
+ publishedUrl: null,
260
+ createdAt: isoNow,
261
+ updatedAt: isoNow,
262
+ };
263
+
264
+ it("parses a bare open-dpp permalink (no config, no UPI)", () => {
265
+ const result = PermalinkDtoSchema.safeParse({
266
+ ...base,
267
+ kind: "open-dpp",
268
+ presentationConfigurationId: null,
269
+ uniqueProductIdentifierId: null,
270
+ gs1DataAttributes: null,
271
+ });
272
+ expect(result.success).toBe(true);
273
+ if (result.success) {
274
+ expect(result.data.kind).toBe("open-dpp");
275
+ expect(result.data.passportId).toBe(passportId);
276
+ expect(result.data.presentationConfigurationId).toBeNull();
277
+ expect(result.data.uniqueProductIdentifierId).toBeNull();
278
+ }
279
+ });
280
+
281
+ it("parses an open-dpp permalink bound to a UPI", () => {
282
+ const result = PermalinkDtoSchema.safeParse({
283
+ ...base,
284
+ kind: "open-dpp",
285
+ presentationConfigurationId: null,
286
+ uniqueProductIdentifierId: upiId,
287
+ gs1DataAttributes: null,
288
+ });
289
+ expect(result.success).toBe(true);
290
+ if (result.success) {
291
+ expect(result.data.uniqueProductIdentifierId).toBe(upiId);
292
+ }
293
+ });
294
+
295
+ it("parses an open-dpp permalink bound to a config and a UPI", () => {
296
+ const result = PermalinkDtoSchema.safeParse({
297
+ ...base,
298
+ kind: "open-dpp",
299
+ presentationConfigurationId: configId,
300
+ uniqueProductIdentifierId: upiId,
301
+ gs1DataAttributes: null,
302
+ });
303
+ expect(result.success).toBe(true);
304
+ });
305
+
306
+ it("parses a gs1-link permalink", () => {
307
+ const result = PermalinkDtoSchema.safeParse({
308
+ ...base,
309
+ kind: "gs1-link",
310
+ presentationConfigurationId: null,
311
+ uniqueProductIdentifierId: upiId,
312
+ gs1DataAttributes: { "17": "251231" },
313
+ });
314
+ expect(result.success).toBe(true);
315
+ if (result.success) {
316
+ expect(result.data.kind).toBe("gs1-link");
317
+ expect(result.data.uniqueProductIdentifierId).toBe(upiId);
318
+ expect(result.data.gs1DataAttributes).toEqual({ "17": "251231" });
319
+ }
320
+ });
321
+
322
+ it("rejects an unknown kind", () => {
323
+ const result = PermalinkDtoSchema.safeParse({
324
+ ...base,
325
+ kind: "unknown-kind",
326
+ presentationConfigurationId: configId,
327
+ uniqueProductIdentifierId: null,
328
+ gs1DataAttributes: null,
329
+ });
330
+ expect(result.success).toBe(false);
331
+ });
332
+
333
+ it("rejects the legacy 'presentation' kind (backend maps it before dto parse)", () => {
334
+ const result = PermalinkDtoSchema.safeParse({
335
+ ...base,
336
+ kind: "presentation",
337
+ presentationConfigurationId: configId,
338
+ uniqueProductIdentifierId: null,
339
+ gs1DataAttributes: null,
340
+ });
341
+ expect(result.success).toBe(false);
342
+ });
343
+
344
+ it("rejects a gs1-link with uniqueProductIdentifierId: null", () => {
345
+ const result = PermalinkDtoSchema.safeParse({
346
+ ...base,
347
+ kind: "gs1-link",
348
+ presentationConfigurationId: null,
349
+ uniqueProductIdentifierId: null,
350
+ gs1DataAttributes: null,
351
+ });
352
+ expect(result.success).toBe(false);
353
+ });
354
+
355
+ it("rejects an open-dpp permalink with non-null gs1DataAttributes", () => {
356
+ const result = PermalinkDtoSchema.safeParse({
357
+ ...base,
358
+ kind: "open-dpp",
359
+ presentationConfigurationId: configId,
360
+ uniqueProductIdentifierId: null,
361
+ gs1DataAttributes: { "17": "251231" },
362
+ });
363
+ expect(result.success).toBe(false);
364
+ });
365
+
366
+ it("rejects a permalink without passportId", () => {
367
+ const { passportId: _passportId, ...rest } = base;
368
+ const result = PermalinkDtoSchema.safeParse({
369
+ ...rest,
370
+ kind: "open-dpp",
371
+ presentationConfigurationId: configId,
372
+ uniqueProductIdentifierId: null,
373
+ gs1DataAttributes: null,
374
+ });
375
+ expect(result.success).toBe(false);
376
+ });
377
+
378
+ it("defaults kind to 'open-dpp' when missing", () => {
379
+ const result = PermalinkDtoSchema.safeParse({
380
+ ...base,
381
+ presentationConfigurationId: configId,
382
+ });
383
+ expect(result.success).toBe(true);
384
+ if (result.success) {
385
+ expect(result.data.kind).toBe("open-dpp");
386
+ expect(result.data.uniqueProductIdentifierId).toBeNull();
387
+ expect(result.data.gs1DataAttributes).toBeNull();
388
+ }
389
+ });
390
+
391
+ it("strips the removed 'primary' field from legacy docs", () => {
392
+ const result = PermalinkDtoSchema.safeParse({
393
+ ...base,
394
+ kind: "open-dpp",
395
+ presentationConfigurationId: configId,
396
+ uniqueProductIdentifierId: null,
397
+ gs1DataAttributes: null,
398
+ primary: true,
399
+ });
400
+ expect(result.success).toBe(true);
401
+ if (result.success) {
402
+ expect(Object.prototype.hasOwnProperty.call(result.data, "primary")).toBe(false);
403
+ }
404
+ });
405
+
406
+ it("PermalinkDtoSchema is still a ZodObject (has .extend method)", () => {
407
+ expect(typeof (PermalinkDtoSchema as { extend?: unknown }).extend).toBe("function");
408
+ });
409
+ });
410
+
411
+ describe("PermalinkInvariantsSchema", () => {
412
+ it("accepts a bare open-dpp create (passportId only)", () => {
413
+ const result = PermalinkInvariantsSchema.safeParse({
414
+ kind: "open-dpp",
415
+ passportId,
416
+ });
417
+ expect(result.success).toBe(true);
418
+ });
419
+
420
+ it("accepts an open-dpp create with config, UPI, and slug", () => {
421
+ const result = PermalinkInvariantsSchema.safeParse({
422
+ kind: "open-dpp",
423
+ passportId,
424
+ presentationConfigurationId: configId,
425
+ uniqueProductIdentifierId: upiId,
426
+ slug: "my-product",
427
+ });
428
+ expect(result.success).toBe(true);
429
+ });
430
+
431
+ it("rejects an open-dpp create without passportId", () => {
432
+ const result = PermalinkInvariantsSchema.safeParse({
433
+ kind: "open-dpp",
434
+ presentationConfigurationId: configId,
435
+ });
436
+ expect(result.success).toBe(false);
437
+ });
438
+
439
+ it("rejects an open-dpp create with gs1DataAttributes", () => {
440
+ const result = PermalinkInvariantsSchema.safeParse({
441
+ kind: "open-dpp",
442
+ passportId,
443
+ gs1DataAttributes: { "17": "251231" },
444
+ });
445
+ expect(result.success).toBe(false);
446
+ });
447
+
448
+ it("accepts a gs1-link with uniqueProductIdentifierId and null optional fields", () => {
449
+ const result = PermalinkInvariantsSchema.safeParse({
450
+ kind: "gs1-link",
451
+ passportId,
452
+ uniqueProductIdentifierId: upiId,
453
+ presentationConfigurationId: null,
454
+ gs1DataAttributes: null,
455
+ });
456
+ expect(result.success).toBe(true);
457
+ });
458
+
459
+ it("accepts a gs1-link that also sets presentationConfigurationId", () => {
460
+ const result = PermalinkInvariantsSchema.safeParse({
461
+ kind: "gs1-link",
462
+ passportId,
463
+ uniqueProductIdentifierId: upiId,
464
+ presentationConfigurationId: configId,
465
+ gs1DataAttributes: null,
466
+ });
467
+ expect(result.success).toBe(true);
468
+ });
469
+
470
+ it("rejects a gs1-link without uniqueProductIdentifierId", () => {
471
+ const result = PermalinkInvariantsSchema.safeParse({
472
+ kind: "gs1-link",
473
+ passportId,
474
+ presentationConfigurationId: null,
475
+ gs1DataAttributes: null,
476
+ });
477
+ expect(result.success).toBe(false);
478
+ });
479
+
480
+ it("rejects a gs1-link without passportId", () => {
481
+ const result = PermalinkInvariantsSchema.safeParse({
482
+ kind: "gs1-link",
483
+ uniqueProductIdentifierId: upiId,
484
+ presentationConfigurationId: null,
485
+ });
486
+ expect(result.success).toBe(false);
487
+ });
488
+ });
489
+
490
+ import { PermalinkCreateRequestSchema, PermalinkUpdateRequestSchema } from "./permalink.dto";
491
+
492
+ describe("PermalinkCreateRequestSchema", () => {
493
+ it("parses a bare open-dpp create request (passportId only)", () => {
494
+ const result = PermalinkCreateRequestSchema.safeParse({
495
+ kind: "open-dpp",
496
+ passportId,
497
+ });
498
+ expect(result.success).toBe(true);
499
+ if (result.success) {
500
+ expect(result.data.kind).toBe("open-dpp");
501
+ }
502
+ });
503
+
504
+ it("parses an open-dpp create request with config, UPI, slug, and baseUrl", () => {
505
+ const result = PermalinkCreateRequestSchema.safeParse({
506
+ kind: "open-dpp",
507
+ passportId,
508
+ presentationConfigurationId: configId,
509
+ uniqueProductIdentifierId: upiId,
510
+ slug: "my-product",
511
+ baseUrl: "https://passports.example.com",
512
+ });
513
+ expect(result.success).toBe(true);
514
+ });
515
+
516
+ it("rejects an open-dpp create request without passportId", () => {
517
+ const result = PermalinkCreateRequestSchema.safeParse({
518
+ kind: "open-dpp",
519
+ presentationConfigurationId: configId,
520
+ });
521
+ expect(result.success).toBe(false);
522
+ });
523
+
524
+ it("rejects the legacy 'presentation' kind in create requests", () => {
525
+ const result = PermalinkCreateRequestSchema.safeParse({
526
+ kind: "presentation",
527
+ presentationConfigurationId: configId,
528
+ });
529
+ expect(result.success).toBe(false);
530
+ });
531
+
532
+ it("parses a gs1-link create request with passportId and uniqueProductIdentifierId", () => {
533
+ const result = PermalinkCreateRequestSchema.safeParse({
534
+ kind: "gs1-link",
535
+ passportId,
536
+ uniqueProductIdentifierId: upiId,
537
+ presentationConfigurationId: null,
538
+ gs1DataAttributes: null,
539
+ });
540
+ expect(result.success).toBe(true);
541
+ if (result.success) {
542
+ expect(result.data.kind).toBe("gs1-link");
543
+ }
544
+ });
545
+
546
+ it("parses a gs1-link create request with optional presentationConfigurationId, gs1DataAttributes, and slug", () => {
547
+ const result = PermalinkCreateRequestSchema.safeParse({
548
+ kind: "gs1-link",
549
+ passportId,
550
+ uniqueProductIdentifierId: upiId,
551
+ presentationConfigurationId: configId,
552
+ gs1DataAttributes: { "17": "251231" },
553
+ slug: "my-gs1-product",
554
+ });
555
+ expect(result.success).toBe(true);
556
+ });
557
+
558
+ it("rejects a gs1-link create request without uniqueProductIdentifierId", () => {
559
+ const result = PermalinkCreateRequestSchema.safeParse({
560
+ kind: "gs1-link",
561
+ passportId,
562
+ presentationConfigurationId: null,
563
+ });
564
+ expect(result.success).toBe(false);
565
+ });
566
+
567
+ it("rejects a gs1-link create request without passportId", () => {
568
+ const result = PermalinkCreateRequestSchema.safeParse({
569
+ kind: "gs1-link",
570
+ uniqueProductIdentifierId: upiId,
571
+ });
572
+ expect(result.success).toBe(false);
573
+ });
574
+
575
+ it("rejects an open-dpp create request with gs1DataAttributes", () => {
576
+ const result = PermalinkCreateRequestSchema.safeParse({
577
+ kind: "open-dpp",
578
+ passportId,
579
+ gs1DataAttributes: { "17": "251231" },
580
+ } as Record<string, unknown>);
581
+ expect(result.success).toBe(false);
582
+ });
583
+ });
584
+
585
+ describe("PermalinkUpdateRequestSchema", () => {
586
+ it("still accepts slug and baseUrl", () => {
587
+ const result = PermalinkUpdateRequestSchema.safeParse({
588
+ slug: "updated-slug",
589
+ baseUrl: "https://passports.example.com",
590
+ });
591
+ expect(result.success).toBe(true);
592
+ });
593
+
594
+ it("strips the removed 'primary' field", () => {
595
+ const result = PermalinkUpdateRequestSchema.safeParse({ primary: true });
596
+ expect(result.success).toBe(true);
597
+ if (result.success) {
598
+ expect(Object.prototype.hasOwnProperty.call(result.data, "primary")).toBe(false);
599
+ }
600
+ });
601
+
602
+ it("accepts gs1DataAttributes", () => {
603
+ const result = PermalinkUpdateRequestSchema.safeParse({
604
+ gs1DataAttributes: { "17": "251231" },
605
+ });
606
+ expect(result.success).toBe(true);
607
+ });
608
+
609
+ it("accepts presentationConfigurationId as a uuid", () => {
610
+ const result = PermalinkUpdateRequestSchema.safeParse({
611
+ presentationConfigurationId: configId,
612
+ });
613
+ expect(result.success).toBe(true);
614
+ });
615
+
616
+ it("accepts presentationConfigurationId as null (rebind to standard view)", () => {
617
+ const result = PermalinkUpdateRequestSchema.safeParse({
618
+ presentationConfigurationId: null,
619
+ });
620
+ expect(result.success).toBe(true);
621
+ });
622
+
623
+ it("strips kind if provided (does not accept changing kind)", () => {
624
+ const result = PermalinkUpdateRequestSchema.safeParse({
625
+ kind: "gs1-link",
626
+ slug: "test-slug",
627
+ } as Record<string, unknown>);
628
+ expect(result.success).toBe(true);
629
+ if (result.success) {
630
+ expect(Object.prototype.hasOwnProperty.call(result.data, "kind")).toBe(false);
631
+ }
632
+ });
633
+ });
634
+
635
+ describe("PermalinkPaginationDtoSchema", () => {
636
+ const validPermalinkPublic = {
637
+ id: "44444444-4444-4444-8444-444444444444",
638
+ kind: "open-dpp",
639
+ passportId,
640
+ slug: null,
641
+ baseUrl: null,
642
+ publishedUrl: null,
643
+ presentationConfigurationId: configId,
644
+ uniqueProductIdentifierId: null,
645
+ gs1DataAttributes: null,
646
+ createdAt: isoNow,
647
+ updatedAt: isoNow,
648
+ publicUrl: "https://passports.example.com/44444444-4444-4444-8444-444444444444",
649
+ fallbackBaseUrl: "https://passports.example.com",
650
+ fallbackBaseUrlSource: "instance",
651
+ };
652
+
653
+ it("parses an envelope with a non-null cursor and a result array", () => {
654
+ const result = PermalinkPaginationDtoSchema.parse({
655
+ paging_metadata: { cursor: "cursor-token" },
656
+ result: [validPermalinkPublic],
657
+ });
658
+ expect(result.paging_metadata.cursor).toBe("cursor-token");
659
+ expect(result.result).toHaveLength(1);
660
+ expect(result.result[0].id).toBe(validPermalinkPublic.id);
661
+ });
662
+
663
+ it("parses an envelope with a null cursor and an empty result", () => {
664
+ const result = PermalinkPaginationDtoSchema.parse({
665
+ paging_metadata: { cursor: null },
666
+ result: [],
667
+ });
668
+ expect(result.paging_metadata.cursor).toBeNull();
669
+ expect(result.result).toEqual([]);
670
+ });
671
+
672
+ it("rejects an envelope missing paging_metadata", () => {
673
+ expect(() => PermalinkPaginationDtoSchema.parse({ result: [] })).toThrow();
674
+ });
675
+ });
@@ -1,8 +1,10 @@
1
1
  import { z } from "zod";
2
2
  import { BrandingDtoSchema } from "../branding/branding.dto";
3
+ import { Gs1DataAttributesSchema } from "../unique-product-identifiers/gs1/gs1-data-attributes.dto";
3
4
  import { PassportDtoSchema } from "../passports/passport.dto";
4
5
  import { PresentationConfigurationDtoSchema } from "../presentation-configurations/presentation-configuration.dto";
5
6
  import { DateTimeSchema } from "../digital-product-document/digital-product-document.schemas";
7
+ import { PagingMetadataDtoSchema } from "../shared/pagination.dto";
6
8
  import { PermalinkBaseUrlSchema } from "../shared/permalink-base-url.schema";
7
9
 
8
10
  export const PERMALINK_RESERVED_SLUGS: readonly string[] = ["new", "edit"];
@@ -24,22 +26,80 @@ export const PermalinkSchema = z.union([z.uuid(), PermalinkSlugSchema]);
24
26
  export const PermalinkPublishedUrlSchema = z.string().url().max(2048);
25
27
  export type PermalinkPublishedUrl = z.infer<typeof PermalinkPublishedUrlSchema>;
26
28
 
27
- export const PermalinkInvariantsSchema = z.object({
28
- presentationConfigurationId: z.uuid(),
29
- slug: PermalinkSlugSchema.nullable(),
29
+ export const PermalinkKind = {
30
+ OPEN_DPP: "open-dpp",
31
+ GS1_LINK: "gs1-link",
32
+ } as const;
33
+
34
+ export const LEGACY_PERMALINK_KIND = "presentation" as const;
35
+
36
+ export type PermalinkKindType = (typeof PermalinkKind)[keyof typeof PermalinkKind];
37
+
38
+ export const PermalinkKindSchema = z.enum([PermalinkKind.OPEN_DPP, PermalinkKind.GS1_LINK]);
39
+
40
+ const PermalinkInvariantsOpenDppSchema = z
41
+ .object({
42
+ kind: z.literal(PermalinkKind.OPEN_DPP),
43
+ passportId: z.uuid(),
44
+ presentationConfigurationId: z.uuid().nullish(),
45
+ uniqueProductIdentifierId: z.uuid().nullish(),
46
+ slug: PermalinkSlugSchema.nullish(),
47
+ baseUrl: PermalinkBaseUrlSchema.nullable().optional(),
48
+ })
49
+ .strict();
50
+
51
+ const PermalinkInvariantsGs1LinkSchema = z.object({
52
+ kind: z.literal(PermalinkKind.GS1_LINK),
53
+ passportId: z.uuid(),
54
+ uniqueProductIdentifierId: z.uuid(),
55
+ presentationConfigurationId: z.uuid().nullable(),
56
+ gs1DataAttributes: Gs1DataAttributesSchema.nullable().optional(),
57
+ slug: PermalinkSlugSchema.nullish(),
30
58
  baseUrl: PermalinkBaseUrlSchema.nullable().optional(),
31
59
  });
32
60
 
61
+ export const PermalinkInvariantsSchema = z.discriminatedUnion("kind", [
62
+ PermalinkInvariantsOpenDppSchema,
63
+ PermalinkInvariantsGs1LinkSchema,
64
+ ]);
65
+
33
66
  export const PermalinkDtoSchema = z
34
67
  .object({
35
68
  id: z.uuid(),
69
+ kind: PermalinkKindSchema.default(PermalinkKind.OPEN_DPP),
70
+ passportId: z.uuid(),
36
71
  slug: PermalinkSlugSchema.nullable(),
37
72
  baseUrl: PermalinkBaseUrlSchema.nullish(),
38
73
  publishedUrl: PermalinkPublishedUrlSchema.nullish(),
39
- presentationConfigurationId: z.uuid(),
74
+ presentationConfigurationId: z.uuid().nullable(),
75
+ uniqueProductIdentifierId: z.uuid().nullable().default(null),
76
+ gs1DataAttributes: Gs1DataAttributesSchema.nullable().default(null),
40
77
  createdAt: DateTimeSchema,
41
78
  updatedAt: DateTimeSchema,
42
79
  })
80
+ .check((ctx) => {
81
+ const { kind, uniqueProductIdentifierId, gs1DataAttributes } = ctx.value;
82
+
83
+ if (kind === PermalinkKind.GS1_LINK) {
84
+ if (uniqueProductIdentifierId == null) {
85
+ ctx.issues.push({
86
+ code: "custom",
87
+ input: ctx.value,
88
+ message: 'A gs1-link permalink requires a non-null "uniqueProductIdentifierId"',
89
+ path: ["uniqueProductIdentifierId"],
90
+ });
91
+ }
92
+ } else if (kind === PermalinkKind.OPEN_DPP) {
93
+ if (gs1DataAttributes != null) {
94
+ ctx.issues.push({
95
+ code: "custom",
96
+ input: ctx.value,
97
+ message: 'An open-dpp permalink must have "gs1DataAttributes" = null',
98
+ path: ["gs1DataAttributes"],
99
+ });
100
+ }
101
+ }
102
+ })
43
103
  .meta({ id: "Permalink" });
44
104
 
45
105
  export type PermalinkDto = z.infer<typeof PermalinkDtoSchema>;
@@ -58,6 +118,15 @@ export type PermalinkPublicDto = z.infer<typeof PermalinkPublicDtoSchema>;
58
118
  export const PermalinkListDtoSchema = z.array(PermalinkPublicDtoSchema);
59
119
  export type PermalinkListDto = z.infer<typeof PermalinkListDtoSchema>;
60
120
 
121
+ export const PermalinkPaginationDtoSchema = z
122
+ .object({
123
+ ...PagingMetadataDtoSchema.shape,
124
+ result: PermalinkPublicDtoSchema.array(),
125
+ })
126
+ .meta({ id: "Permalinks" });
127
+
128
+ export type PermalinkPaginationDto = z.infer<typeof PermalinkPaginationDtoSchema>;
129
+
61
130
  export const PermalinkMetadataDtoSchema = z.object({
62
131
  passportId: z.uuid(),
63
132
  organizationId: z.string().min(1),
@@ -66,10 +135,39 @@ export const PermalinkMetadataDtoSchema = z.object({
66
135
 
67
136
  export type PermalinkMetadataDto = z.infer<typeof PermalinkMetadataDtoSchema>;
68
137
 
138
+ const PermalinkCreateOpenDppSchema = z
139
+ .object({
140
+ kind: z.literal(PermalinkKind.OPEN_DPP),
141
+ passportId: z.uuid(),
142
+ presentationConfigurationId: z.uuid().nullish(),
143
+ uniqueProductIdentifierId: z.uuid().nullish(),
144
+ slug: PermalinkSlugSchema.nullish(),
145
+ baseUrl: PermalinkBaseUrlSchema.nullable().optional(),
146
+ })
147
+ .strict();
148
+
149
+ const PermalinkCreateGs1LinkSchema = z.object({
150
+ kind: z.literal(PermalinkKind.GS1_LINK),
151
+ passportId: z.uuid(),
152
+ uniqueProductIdentifierId: z.uuid(),
153
+ presentationConfigurationId: z.uuid().nullable().optional(),
154
+ gs1DataAttributes: Gs1DataAttributesSchema.nullable().optional(),
155
+ slug: PermalinkSlugSchema.nullish(),
156
+ baseUrl: PermalinkBaseUrlSchema.nullable().optional(),
157
+ });
158
+
159
+ export const PermalinkCreateRequestSchema = z
160
+ .discriminatedUnion("kind", [PermalinkCreateOpenDppSchema, PermalinkCreateGs1LinkSchema])
161
+ .meta({ id: "PermalinkCreateRequest" });
162
+
163
+ export type PermalinkCreateRequest = z.infer<typeof PermalinkCreateRequestSchema>;
164
+
69
165
  export const PermalinkUpdateRequestSchema = z
70
166
  .object({
71
167
  slug: PermalinkSlugSchema.nullish(),
72
168
  baseUrl: PermalinkBaseUrlSchema.nullish(),
169
+ gs1DataAttributes: Gs1DataAttributesSchema.nullish(),
170
+ presentationConfigurationId: z.uuid().nullish(),
73
171
  })
74
172
  .meta({ id: "PermalinkUpdateRequest" });
75
173
 
@@ -79,7 +177,7 @@ export const PassportPermalinkBundleDtoSchema = z
79
177
  .object({
80
178
  passport: PassportDtoSchema,
81
179
  branding: BrandingDtoSchema,
82
- presentationConfiguration: PresentationConfigurationDtoSchema,
180
+ presentationConfiguration: PresentationConfigurationDtoSchema.nullable(),
83
181
  publicUrl: z.string().url(),
84
182
  })
85
183
  .meta({ id: "PassportPermalinkBundle" });