@open-dpp/dto 0.6.0 → 1.0.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 (39) hide show
  1. package/dist/aas/element-classifications.d.ts +6 -0
  2. package/dist/aas/element-classifications.d.ts.map +1 -0
  3. package/dist/aas/element-classifications.js +33 -0
  4. package/dist/analytics/passport-page-view.dto.d.ts +7 -0
  5. package/dist/analytics/passport-page-view.dto.d.ts.map +1 -0
  6. package/dist/analytics/passport-page-view.dto.js +9 -0
  7. package/dist/branding/branding.dto.d.ts +1 -0
  8. package/dist/branding/branding.dto.d.ts.map +1 -1
  9. package/dist/branding/branding.dto.js +2 -0
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +5 -0
  13. package/dist/instance-settings/instance-settings.dto.d.ts +11 -0
  14. package/dist/instance-settings/instance-settings.dto.d.ts.map +1 -1
  15. package/dist/instance-settings/instance-settings.dto.js +9 -1
  16. package/dist/permalinks/permalink.dto.d.ts +161 -0
  17. package/dist/permalinks/permalink.dto.d.ts.map +1 -0
  18. package/dist/permalinks/permalink.dto.js +62 -0
  19. package/dist/presentation-configurations/presentation-configuration.dto.d.ts +187 -0
  20. package/dist/presentation-configurations/presentation-configuration.dto.d.ts.map +1 -0
  21. package/dist/presentation-configurations/presentation-configuration.dto.js +71 -0
  22. package/dist/shared/digital-product-document.schemas.d.ts.map +1 -1
  23. package/dist/shared/digital-product-document.schemas.js +16 -1
  24. package/dist/shared/permalink-base-url.schema.d.ts +5 -0
  25. package/dist/shared/permalink-base-url.schema.d.ts.map +1 -0
  26. package/dist/shared/permalink-base-url.schema.js +48 -0
  27. package/package.json +1 -1
  28. package/src/aas/element-classifications.ts +32 -0
  29. package/src/analytics/passport-page-view.dto.ts +9 -0
  30. package/src/branding/branding.dto.ts +2 -0
  31. package/src/index.ts +5 -0
  32. package/src/instance-settings/instance-settings.dto.ts +11 -0
  33. package/src/permalinks/permalink.dto.spec.ts +206 -0
  34. package/src/permalinks/permalink.dto.ts +87 -0
  35. package/src/presentation-configurations/presentation-configuration.dto.spec.ts +165 -0
  36. package/src/presentation-configurations/presentation-configuration.dto.ts +110 -0
  37. package/src/shared/digital-product-document.schemas.ts +20 -4
  38. package/src/shared/permalink-base-url.schema.spec.ts +95 -0
  39. package/src/shared/permalink-base-url.schema.ts +53 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-configuration.dto.d.ts","sourceRoot":"","sources":["../../src/presentation-configurations/presentation-configuration.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,yBAAyB;;;CAG5B,CAAC;AAEX,eAAO,MAAM,6BAA6B;;;EAAoC,CAAC;AAC/E,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAE1F,eAAO,MAAM,yBAAyB;;CAE5B,CAAC;AAEX,eAAO,MAAM,6BAA6B;;EAAoC,CAAC;AAC/E,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAiB1F,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsBH,CAAC;AAE7C,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAE9F,eAAO,MAAM,yCAAyC;;;;;;;;iBAKpD,CAAC;AAEH,eAAO,MAAM,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAahD,CAAC;AAEH,MAAM,MAAM,kCAAkC,GAAG,CAAC,CAAC,KAAK,CACtD,OAAO,qCAAqC,CAC7C,CAAC;AAEF,eAAO,MAAM,4CAA4C;;iBAEvD,CAAC;AACH,MAAM,MAAM,yCAAyC,GAAG,CAAC,CAAC,KAAK,CAC7D,OAAO,4CAA4C,CACpD,CAAC;AAEF,eAAO,MAAM,2CAA2C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAEvD,CAAC;AACF,MAAM,MAAM,wCAAwC,GAAG,CAAC,CAAC,KAAK,CAC5D,OAAO,2CAA2C,CACnD,CAAC;AAEF,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAK/C,CAAC;AAEH,MAAM,MAAM,iCAAiC,GAAG,CAAC,CAAC,KAAK,CACrD,OAAO,oCAAoC,CAC5C,CAAC"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PresentationConfigurationPatchSchema = exports.PresentationConfigurationListResponseSchema = exports.PresentationConfigurationCreateRequestSchema = exports.PresentationConfigurationExportSchema = exports.PresentationConfigurationInvariantsSchema = exports.PresentationConfigurationDtoSchema = exports.PresentationComponentNameEnum = exports.PresentationComponentName = exports.PresentationReferenceTypeEnum = exports.PresentationReferenceType = void 0;
4
+ const zod_1 = require("zod");
5
+ const key_types_enum_1 = require("../aas/enums/key-types-enum");
6
+ const digital_product_document_schemas_1 = require("../shared/digital-product-document.schemas");
7
+ exports.PresentationReferenceType = {
8
+ Template: "template",
9
+ Passport: "passport",
10
+ };
11
+ exports.PresentationReferenceTypeEnum = zod_1.z.enum(exports.PresentationReferenceType);
12
+ exports.PresentationComponentName = {
13
+ BigNumber: "BigNumber",
14
+ };
15
+ exports.PresentationComponentNameEnum = zod_1.z.enum(exports.PresentationComponentName);
16
+ const KEY_TYPES_SET = new Set(Object.values(key_types_enum_1.KeyTypes));
17
+ function dropUnknownComponents(input, validKeys) {
18
+ if (input == null || typeof input !== "object")
19
+ return input;
20
+ const cleaned = {};
21
+ for (const [key, value] of Object.entries(input)) {
22
+ if (validKeys && !validKeys.has(key))
23
+ continue;
24
+ const parsed = exports.PresentationComponentNameEnum.safeParse(value);
25
+ if (parsed.success) {
26
+ cleaned[key] = parsed.data;
27
+ }
28
+ }
29
+ return cleaned;
30
+ }
31
+ exports.PresentationConfigurationDtoSchema = zod_1.z
32
+ .object({
33
+ id: zod_1.z.uuid(),
34
+ organizationId: zod_1.z.string().min(1),
35
+ referenceId: zod_1.z.uuid(),
36
+ referenceType: exports.PresentationReferenceTypeEnum,
37
+ label: zod_1.z.string().min(1).nullable().default(null),
38
+ elementDesign: zod_1.z
39
+ .preprocess((input) => dropUnknownComponents(input), zod_1.z.record(zod_1.z.string(), exports.PresentationComponentNameEnum))
40
+ .default({}),
41
+ defaultComponents: zod_1.z
42
+ .preprocess((input) => dropUnknownComponents(input, KEY_TYPES_SET), zod_1.z.partialRecord(key_types_enum_1.KeyTypesEnum, exports.PresentationComponentNameEnum))
43
+ .default({}),
44
+ createdAt: digital_product_document_schemas_1.DateTimeSchema,
45
+ updatedAt: digital_product_document_schemas_1.DateTimeSchema,
46
+ })
47
+ .meta({ id: "PresentationConfiguration" });
48
+ exports.PresentationConfigurationInvariantsSchema = zod_1.z.object({
49
+ organizationId: zod_1.z.string().min(1),
50
+ referenceId: zod_1.z.uuid(),
51
+ referenceType: exports.PresentationReferenceTypeEnum,
52
+ label: zod_1.z.string().min(1).nullable(),
53
+ });
54
+ exports.PresentationConfigurationExportSchema = zod_1.z.object({
55
+ elementDesign: zod_1.z
56
+ .preprocess((input) => dropUnknownComponents(input), zod_1.z.record(zod_1.z.string(), exports.PresentationComponentNameEnum))
57
+ .default({}),
58
+ defaultComponents: zod_1.z
59
+ .preprocess((input) => dropUnknownComponents(input, KEY_TYPES_SET), zod_1.z.partialRecord(key_types_enum_1.KeyTypesEnum, exports.PresentationComponentNameEnum))
60
+ .default({}),
61
+ });
62
+ exports.PresentationConfigurationCreateRequestSchema = zod_1.z.object({
63
+ label: zod_1.z.string().min(1).nullable(),
64
+ });
65
+ exports.PresentationConfigurationListResponseSchema = zod_1.z.array(exports.PresentationConfigurationDtoSchema);
66
+ exports.PresentationConfigurationPatchSchema = zod_1.z.object({
67
+ elementDesign: zod_1.z.record(zod_1.z.string(), exports.PresentationComponentNameEnum.nullable()).optional(),
68
+ defaultComponents: zod_1.z
69
+ .partialRecord(key_types_enum_1.KeyTypesEnum, exports.PresentationComponentNameEnum.nullable())
70
+ .optional(),
71
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"digital-product-document.schemas.d.ts","sourceRoot":"","sources":["../../src/shared/digital-product-document.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,cAAc,oDAAwC,CAAC;AAEpE,eAAO,MAAM,+BAA+B;;;;CAIlC,CAAC;AAEX,eAAO,MAAM,mCAAmC;;;;EAA0C,CAAC;AAC3F,MAAM,MAAM,mCAAmC,GAAG,CAAC,CAAC,KAAK,CACvD,OAAO,mCAAmC,CAC3C,CAAC;AAEF,eAAO,MAAM,iDAAiD;;;;CAIpD,CAAC;AAEX,eAAO,MAAM,+CAA+C;;;;EAE3D,CAAC;AAEF,eAAO,MAAM,2CAA2C;;;;;;;;;;;iBAGtD,CAAC;AAEH,eAAO,MAAM,iDAAiD;;;;;;iBAE5D,CAAC;AAEH,MAAM,MAAM,2CAA2C,GAAG,CAAC,CAAC,KAAK,CAC/D,OAAO,iDAAiD,CACzD,CAAC;AAEF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO1C,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC"}
1
+ {"version":3,"file":"digital-product-document.schemas.d.ts","sourceRoot":"","sources":["../../src/shared/digital-product-document.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,cAAc,oDAAwC,CAAC;AAEpE,eAAO,MAAM,+BAA+B;;;;CAIlC,CAAC;AAEX,eAAO,MAAM,mCAAmC;;;;EAA0C,CAAC;AAC3F,MAAM,MAAM,mCAAmC,GAAG,CAAC,CAAC,KAAK,CACvD,OAAO,mCAAmC,CAC3C,CAAC;AAEF,eAAO,MAAM,iDAAiD;;;;CAIpD,CAAC;AAEX,eAAO,MAAM,+CAA+C;;;;EAE3D,CAAC;AAEF,eAAO,MAAM,2CAA2C;;;;;;;;;;;iBAmBrD,CAAC;AAEJ,eAAO,MAAM,iDAAiD;;;;;;iBAE5D,CAAC;AAEH,MAAM,MAAM,2CAA2C,GAAG,CAAC,CAAC,KAAK,CAC/D,OAAO,iDAAiD,CACzD,CAAC;AAEF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO1C,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC"}
@@ -16,9 +16,24 @@ exports.DigitalProductDocumentStatusModificationMethodDto = {
16
16
  Restore: "Restore",
17
17
  };
18
18
  exports.DigitalProductDocumentStatusModificationDtoEnum = zod_1.z.enum(exports.DigitalProductDocumentStatusModificationMethodDto);
19
- exports.DigitalProductDocumentStatusChangeDtoSchema = zod_1.z.object({
19
+ exports.DigitalProductDocumentStatusChangeDtoSchema = zod_1.z
20
+ .object({
20
21
  previousStatus: exports.DigitalProductDocumentStatusDtoEnum.nullish(),
21
22
  currentStatus: exports.DigitalProductDocumentStatusDtoEnum,
23
+ })
24
+ .refine((change) => {
25
+ const { previousStatus, currentStatus } = change;
26
+ if (previousStatus == null)
27
+ return true;
28
+ const { Draft, Published, Archived } = exports.DigitalProductDocumentStatusDto;
29
+ if (previousStatus === Draft)
30
+ return currentStatus === Published || currentStatus === Archived;
31
+ if (previousStatus === Published)
32
+ return currentStatus === Archived;
33
+ return currentStatus === Draft || currentStatus === Published;
34
+ }, {
35
+ error: "Illegal status transition",
36
+ path: ["currentStatus"],
22
37
  });
23
38
  exports.DigitalProductDocumentStatusModificationDtoSchema = zod_1.z.object({
24
39
  method: exports.DigitalProductDocumentStatusModificationDtoEnum,
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ export declare function canonicaliseBaseUrl(s: string): string;
3
+ export declare const PermalinkBaseUrlSchema: z.ZodString;
4
+ export type PermalinkBaseUrl = z.infer<typeof PermalinkBaseUrlSchema>;
5
+ //# sourceMappingURL=permalink-base-url.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permalink-base-url.schema.d.ts","sourceRoot":"","sources":["../../src/shared/permalink-base-url.schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CASrD;AAED,eAAO,MAAM,sBAAsB,aAoCF,CAAC;AAElC,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PermalinkBaseUrlSchema = void 0;
4
+ exports.canonicaliseBaseUrl = canonicaliseBaseUrl;
5
+ /// <reference lib="dom" />
6
+ const zod_1 = require("zod");
7
+ function canonicaliseBaseUrl(s) {
8
+ try {
9
+ const u = new URL(s);
10
+ u.hostname = u.hostname.toLowerCase();
11
+ const path = u.pathname.replace(/\/+$/, "");
12
+ return `${u.protocol}//${u.host}${path}`;
13
+ }
14
+ catch {
15
+ return s;
16
+ }
17
+ }
18
+ exports.PermalinkBaseUrlSchema = zod_1.z
19
+ .string()
20
+ .min(8)
21
+ .max(2048)
22
+ .url()
23
+ .refine((s) => {
24
+ try {
25
+ return ["http:", "https:"].includes(new URL(s).protocol);
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }, { message: "must use http or https" })
31
+ .refine((s) => {
32
+ try {
33
+ const u = new URL(s);
34
+ return !u.search && !u.hash;
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }, { message: "must not include query or fragment" })
40
+ .refine((s) => {
41
+ try {
42
+ return !new URL(s).pathname.includes("//");
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }, { message: "path must not contain empty segments ('//')" })
48
+ .overwrite(canonicaliseBaseUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-dpp/dto",
3
- "version": "0.6.0",
3
+ "version": "1.0.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/open-dpp/open-dpp#readme",
@@ -0,0 +1,32 @@
1
+ import { DataTypeDef, type DataTypeDefType } from "./enums/data-type-def";
2
+
3
+ export const INTEGER_DATA_TYPES: ReadonlySet<DataTypeDefType> = new Set([
4
+ DataTypeDef.Integer,
5
+ DataTypeDef.Long,
6
+ DataTypeDef.Int,
7
+ DataTypeDef.Short,
8
+ DataTypeDef.Byte,
9
+ DataTypeDef.NegativeInteger,
10
+ DataTypeDef.NonNegativeInteger,
11
+ DataTypeDef.NonPositiveInteger,
12
+ DataTypeDef.PositiveInteger,
13
+ DataTypeDef.UnsignedByte,
14
+ DataTypeDef.UnsignedInt,
15
+ DataTypeDef.UnsignedLong,
16
+ DataTypeDef.UnsignedShort,
17
+ ]);
18
+
19
+ export const NUMERIC_DATA_TYPES: ReadonlySet<DataTypeDefType> = new Set<DataTypeDefType>([
20
+ ...INTEGER_DATA_TYPES,
21
+ DataTypeDef.Decimal,
22
+ DataTypeDef.Double,
23
+ DataTypeDef.Float,
24
+ ]);
25
+
26
+ export function isIntegerDataType(value: string | undefined | null): value is DataTypeDefType {
27
+ return typeof value === "string" && INTEGER_DATA_TYPES.has(value as DataTypeDefType);
28
+ }
29
+
30
+ export function isNumericDataType(value: string | undefined | null): value is DataTypeDefType {
31
+ return typeof value === "string" && NUMERIC_DATA_TYPES.has(value as DataTypeDefType);
32
+ }
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ import { PermalinkSchema } from "../permalinks/permalink.dto";
3
+
4
+ export const PassportPageViewSchema = z.object({
5
+ permalink: PermalinkSchema,
6
+ page: z.string(),
7
+ });
8
+
9
+ export type PassportPageViewDto = z.infer<typeof PassportPageViewSchema>;
@@ -1,8 +1,10 @@
1
1
  import { z } from "zod";
2
+ import { PermalinkBaseUrlSchema } from "../shared/permalink-base-url.schema";
2
3
 
3
4
  export const BrandingDtoSchema = z.object({
4
5
  logo: z.string().nullish(),
5
6
  primaryColor: z.string().nullish(),
7
+ permalinkBaseUrl: PermalinkBaseUrlSchema.nullish(),
6
8
  });
7
9
 
8
10
  export type BrandingDto = z.infer<typeof BrandingDtoSchema>;
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./aas/administrative-information-json-schema";
2
+ export * from "./analytics/passport-page-view.dto";
2
3
  export * from "./aas/asset-administration-shell-json-schema";
3
4
  export * from "./aas/asset-information-json-schema";
4
5
  export * from "./aas/common/basic-json-schema";
@@ -16,6 +17,7 @@ export * from "./aas/common/reference-json-schema";
16
17
  export * from "./aas/concept-description-json-schema";
17
18
  export * from "./aas/concept-description-json-schema";
18
19
  export * from "./aas/dto/value-response.dto";
20
+ export * from "./aas/element-classifications";
19
21
  export * from "./aas/embedded-data-specification-json-schema";
20
22
  export * from "./aas/enums/aas-submodel-elements";
21
23
  export * from "./aas/enums/asset-kind-enum";
@@ -55,8 +57,11 @@ export * from "./aas/submodel-base/submodel-json-schema";
55
57
  export * from "./branding/branding.dto";
56
58
  export * from "./organizations/member.dto";
57
59
  export * from "./passports/passport.dto";
60
+ export * from "./permalinks/permalink.dto";
61
+ export * from "./presentation-configurations/presentation-configuration.dto";
58
62
  export * from "./shared/digital-product-document.schemas";
59
63
  export * from "./shared/pagination.dto";
64
+ export * from "./shared/permalink-base-url.schema";
60
65
  export * from "./shared/populate.dto";
61
66
  export * from "./shared/table.dto";
62
67
  export * from "./status/status.dto";
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { PermalinkBaseUrlSchema } from "../shared/permalink-base-url.schema";
2
3
 
3
4
  export const BooleanSettingsResponseDtoSchema = z.object({
4
5
  value: z.boolean(),
@@ -7,10 +8,19 @@ export const BooleanSettingsResponseDtoSchema = z.object({
7
8
 
8
9
  export type BooleanSettingsResponseDto = z.infer<typeof BooleanSettingsResponseDtoSchema>;
9
10
 
11
+ export const StringSettingsResponseDtoSchema = z.object({
12
+ value: z.string().nullable(),
13
+ locked: z.boolean().optional(),
14
+ });
15
+
16
+ export type StringSettingsResponseDto = z.infer<typeof StringSettingsResponseDtoSchema>;
17
+
10
18
  export const InstanceSettingsDtoSchema = z.object({
11
19
  id: z.string(),
12
20
  signupEnabled: BooleanSettingsResponseDtoSchema,
13
21
  organizationCreationEnabled: BooleanSettingsResponseDtoSchema,
22
+ permalinkBaseUrl: StringSettingsResponseDtoSchema,
23
+ effectiveFallback: z.string(),
14
24
  });
15
25
 
16
26
  export type InstanceSettingsDto = z.infer<typeof InstanceSettingsDtoSchema>;
@@ -18,6 +28,7 @@ export type InstanceSettingsDto = z.infer<typeof InstanceSettingsDtoSchema>;
18
28
  export const InstanceSettingsUpdateDtoSchema = z.object({
19
29
  signupEnabled: z.boolean().optional(),
20
30
  organizationCreationEnabled: z.boolean().optional(),
31
+ permalinkBaseUrl: PermalinkBaseUrlSchema.nullable().optional(),
21
32
  });
22
33
 
23
34
  export type InstanceSettingsUpdateDto = z.infer<typeof InstanceSettingsUpdateDtoSchema>;
@@ -0,0 +1,206 @@
1
+ import { describe, expect, it } from "@jest/globals";
2
+ import {
3
+ PassportPermalinkBundleDtoSchema,
4
+ PermalinkDtoSchema,
5
+ PermalinkPublishedUrlSchema,
6
+ PermalinkPublicDtoSchema,
7
+ } from "./permalink.dto";
8
+
9
+ const isoNow = "2026-05-06T20:56:00.000Z";
10
+
11
+ const passportId = "11111111-1111-4111-8111-111111111111";
12
+ const organizationId = "22222222-2222-4222-8222-222222222222";
13
+ const configId = "33333333-3333-4333-8333-333333333333";
14
+
15
+ const validBundle = {
16
+ passport: {
17
+ id: passportId,
18
+ organizationId,
19
+ templateId: null,
20
+ environment: {
21
+ assetAdministrationShells: [],
22
+ submodels: [],
23
+ conceptDescriptions: [],
24
+ },
25
+ createdAt: isoNow,
26
+ updatedAt: isoNow,
27
+ lastStatusChange: {
28
+ previousStatus: null,
29
+ currentStatus: "Published",
30
+ },
31
+ },
32
+ branding: {
33
+ logo: null,
34
+ primaryColor: null,
35
+ permalinkBaseUrl: null,
36
+ },
37
+ presentationConfiguration: {
38
+ id: configId,
39
+ organizationId,
40
+ referenceId: passportId,
41
+ referenceType: "passport",
42
+ label: null,
43
+ elementDesign: {},
44
+ defaultComponents: {},
45
+ createdAt: isoNow,
46
+ updatedAt: isoNow,
47
+ },
48
+ publicUrl: "https://passports.example.com/p/11111111-1111-4111-8111-111111111111",
49
+ };
50
+
51
+ describe("PassportPermalinkBundleDtoSchema", () => {
52
+ it("parses a complete bundle", () => {
53
+ const result = PassportPermalinkBundleDtoSchema.safeParse(validBundle);
54
+ expect(result.success).toBe(true);
55
+ });
56
+
57
+ it("rejects a bundle missing the branding key", () => {
58
+ const { branding: _branding, ...rest } = validBundle;
59
+ const result = PassportPermalinkBundleDtoSchema.safeParse(rest);
60
+ expect(result.success).toBe(false);
61
+ });
62
+
63
+ it("rejects a bundle missing the presentationConfiguration key", () => {
64
+ const { presentationConfiguration: _config, ...rest } = validBundle;
65
+ const result = PassportPermalinkBundleDtoSchema.safeParse(rest);
66
+ expect(result.success).toBe(false);
67
+ });
68
+
69
+ it("rejects a bundle missing the passport key", () => {
70
+ const { passport: _passport, ...rest } = validBundle;
71
+ const result = PassportPermalinkBundleDtoSchema.safeParse(rest);
72
+ expect(result.success).toBe(false);
73
+ });
74
+
75
+ it("rejects a bundle missing the publicUrl key", () => {
76
+ const { publicUrl: _publicUrl, ...rest } = validBundle;
77
+ const result = PassportPermalinkBundleDtoSchema.safeParse(rest);
78
+ expect(result.success).toBe(false);
79
+ });
80
+ });
81
+
82
+ const permalinkId = "44444444-4444-4444-8444-444444444444";
83
+
84
+ const validPublic = {
85
+ id: permalinkId,
86
+ slug: "acme-widget",
87
+ baseUrl: "https://override.example.com",
88
+ presentationConfigurationId: configId,
89
+ createdAt: isoNow,
90
+ updatedAt: isoNow,
91
+ publicUrl: "https://override.example.com/p/acme-widget",
92
+ fallbackBaseUrl: "https://branding.example.com",
93
+ fallbackBaseUrlSource: "branding",
94
+ };
95
+
96
+ describe("PermalinkPublicDtoSchema", () => {
97
+ it("parses a complete public DTO", () => {
98
+ const result = PermalinkPublicDtoSchema.safeParse(validPublic);
99
+ expect(result.success).toBe(true);
100
+ });
101
+
102
+ it("rejects when fallbackBaseUrl is missing", () => {
103
+ const { fallbackBaseUrl: _fallback, ...rest } = validPublic;
104
+ const result = PermalinkPublicDtoSchema.safeParse(rest);
105
+ expect(result.success).toBe(false);
106
+ });
107
+
108
+ it("accepts a fallbackBaseUrl that includes a path", () => {
109
+ const result = PermalinkPublicDtoSchema.safeParse({
110
+ ...validPublic,
111
+ fallbackBaseUrl: "https://branding.example.com/p",
112
+ });
113
+ expect(result.success).toBe(true);
114
+ });
115
+
116
+ it("rejects when fallbackBaseUrl includes a query string", () => {
117
+ const result = PermalinkPublicDtoSchema.safeParse({
118
+ ...validPublic,
119
+ fallbackBaseUrl: "https://branding.example.com?q=1",
120
+ });
121
+ expect(result.success).toBe(false);
122
+ });
123
+
124
+ it("rejects when fallbackBaseUrlSource is missing", () => {
125
+ const { fallbackBaseUrlSource: _source, ...rest } = validPublic;
126
+ const result = PermalinkPublicDtoSchema.safeParse(rest);
127
+ expect(result.success).toBe(false);
128
+ });
129
+
130
+ it("rejects when fallbackBaseUrlSource is an unknown value", () => {
131
+ const result = PermalinkPublicDtoSchema.safeParse({
132
+ ...validPublic,
133
+ fallbackBaseUrlSource: "permalink",
134
+ });
135
+ expect(result.success).toBe(false);
136
+ });
137
+
138
+ it("accepts fallbackBaseUrlSource = 'instance'", () => {
139
+ const result = PermalinkPublicDtoSchema.safeParse({
140
+ ...validPublic,
141
+ fallbackBaseUrlSource: "instance",
142
+ });
143
+ expect(result.success).toBe(true);
144
+ });
145
+ });
146
+
147
+ describe("PermalinkPublishedUrlSchema", () => {
148
+ it("accepts a full URL that includes the /p/ path", () => {
149
+ const result = PermalinkPublishedUrlSchema.safeParse(
150
+ "https://passports.example.com/p/acme-widget",
151
+ );
152
+ expect(result.success).toBe(true);
153
+ });
154
+
155
+ it("accepts a full URL whose path segment is a uuid", () => {
156
+ const result = PermalinkPublishedUrlSchema.safeParse(
157
+ `https://passports.example.com/p/${permalinkId}`,
158
+ );
159
+ expect(result.success).toBe(true);
160
+ });
161
+
162
+ it("rejects a non-URL string", () => {
163
+ expect(PermalinkPublishedUrlSchema.safeParse("not-a-url").success).toBe(false);
164
+ });
165
+
166
+ it("rejects an empty string", () => {
167
+ expect(PermalinkPublishedUrlSchema.safeParse("").success).toBe(false);
168
+ });
169
+ });
170
+
171
+ describe("PermalinkDtoSchema publishedUrl", () => {
172
+ const validPermalink = {
173
+ id: permalinkId,
174
+ slug: "acme-widget",
175
+ baseUrl: null,
176
+ presentationConfigurationId: configId,
177
+ createdAt: isoNow,
178
+ updatedAt: isoNow,
179
+ };
180
+
181
+ it("parses a permalink without publishedUrl (draft, never published)", () => {
182
+ const result = PermalinkDtoSchema.safeParse(validPermalink);
183
+ expect(result.success).toBe(true);
184
+ });
185
+
186
+ it("parses a permalink with a frozen publishedUrl", () => {
187
+ const result = PermalinkDtoSchema.safeParse({
188
+ ...validPermalink,
189
+ publishedUrl: "https://passports.example.com/p/acme-widget",
190
+ });
191
+ expect(result.success).toBe(true);
192
+ });
193
+
194
+ it("accepts publishedUrl = null", () => {
195
+ const result = PermalinkDtoSchema.safeParse({ ...validPermalink, publishedUrl: null });
196
+ expect(result.success).toBe(true);
197
+ });
198
+
199
+ it("rejects a publishedUrl that is not a URL", () => {
200
+ const result = PermalinkDtoSchema.safeParse({
201
+ ...validPermalink,
202
+ publishedUrl: "nope",
203
+ });
204
+ expect(result.success).toBe(false);
205
+ });
206
+ });
@@ -0,0 +1,87 @@
1
+ import { z } from "zod";
2
+ import { BrandingDtoSchema } from "../branding/branding.dto";
3
+ import { PassportDtoSchema } from "../passports/passport.dto";
4
+ import { PresentationConfigurationDtoSchema } from "../presentation-configurations/presentation-configuration.dto";
5
+ import { DateTimeSchema } from "../shared/digital-product-document.schemas";
6
+ import { PermalinkBaseUrlSchema } from "../shared/permalink-base-url.schema";
7
+
8
+ export const PERMALINK_RESERVED_SLUGS: readonly string[] = ["new", "edit"];
9
+
10
+ const reservedSlugSet = new Set<string>(PERMALINK_RESERVED_SLUGS);
11
+
12
+ export const PermalinkSlugSchema = z
13
+ .string()
14
+ .min(2)
15
+ .max(64)
16
+ .regex(/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/)
17
+ .refine((slug) => !/^\d+$/.test(slug), { error: "Slug cannot be numeric-only" })
18
+ .refine((slug) => !reservedSlugSet.has(slug), { error: "Slug is reserved" });
19
+
20
+ export type PermalinkSlug = z.infer<typeof PermalinkSlugSchema>;
21
+
22
+ export const PermalinkSchema = z.union([z.uuid(), PermalinkSlugSchema]);
23
+
24
+ export const PermalinkPublishedUrlSchema = z.string().url().max(2048);
25
+ export type PermalinkPublishedUrl = z.infer<typeof PermalinkPublishedUrlSchema>;
26
+
27
+ export const PermalinkInvariantsSchema = z.object({
28
+ presentationConfigurationId: z.uuid(),
29
+ slug: PermalinkSlugSchema.nullable(),
30
+ baseUrl: PermalinkBaseUrlSchema.nullable().optional(),
31
+ });
32
+
33
+ export const PermalinkDtoSchema = z
34
+ .object({
35
+ id: z.uuid(),
36
+ slug: PermalinkSlugSchema.nullable(),
37
+ baseUrl: PermalinkBaseUrlSchema.nullish(),
38
+ publishedUrl: PermalinkPublishedUrlSchema.nullish(),
39
+ presentationConfigurationId: z.uuid(),
40
+ createdAt: DateTimeSchema,
41
+ updatedAt: DateTimeSchema,
42
+ })
43
+ .meta({ id: "Permalink" });
44
+
45
+ export type PermalinkDto = z.infer<typeof PermalinkDtoSchema>;
46
+
47
+ export const PermalinkFallbackBaseUrlSourceSchema = z.enum(["branding", "instance"]);
48
+ export type PermalinkFallbackBaseUrlSource = z.infer<typeof PermalinkFallbackBaseUrlSourceSchema>;
49
+
50
+ export const PermalinkPublicDtoSchema = PermalinkDtoSchema.extend({
51
+ publicUrl: z.string().url(),
52
+ fallbackBaseUrl: PermalinkBaseUrlSchema,
53
+ fallbackBaseUrlSource: PermalinkFallbackBaseUrlSourceSchema,
54
+ }).meta({ id: "PermalinkPublic" });
55
+
56
+ export type PermalinkPublicDto = z.infer<typeof PermalinkPublicDtoSchema>;
57
+
58
+ export const PermalinkListDtoSchema = z.array(PermalinkPublicDtoSchema);
59
+ export type PermalinkListDto = z.infer<typeof PermalinkListDtoSchema>;
60
+
61
+ export const PermalinkMetadataDtoSchema = z.object({
62
+ passportId: z.uuid(),
63
+ organizationId: z.string().min(1),
64
+ templateId: z.uuid().nullish(),
65
+ });
66
+
67
+ export type PermalinkMetadataDto = z.infer<typeof PermalinkMetadataDtoSchema>;
68
+
69
+ export const PermalinkUpdateRequestSchema = z
70
+ .object({
71
+ slug: PermalinkSlugSchema.nullish(),
72
+ baseUrl: PermalinkBaseUrlSchema.nullish(),
73
+ })
74
+ .meta({ id: "PermalinkUpdateRequest" });
75
+
76
+ export type PermalinkUpdateRequest = z.infer<typeof PermalinkUpdateRequestSchema>;
77
+
78
+ export const PassportPermalinkBundleDtoSchema = z
79
+ .object({
80
+ passport: PassportDtoSchema,
81
+ branding: BrandingDtoSchema,
82
+ presentationConfiguration: PresentationConfigurationDtoSchema,
83
+ publicUrl: z.string().url(),
84
+ })
85
+ .meta({ id: "PassportPermalinkBundle" });
86
+
87
+ export type PassportPermalinkBundleDto = z.infer<typeof PassportPermalinkBundleDtoSchema>;