@open-dpp/dto 5.3.0 → 6.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/index.d.ts CHANGED
@@ -69,6 +69,7 @@ export * from "./bulk-import/bulk-import-run.dto";
69
69
  export * from "./bulk-import/bulk-import-run-item.dto";
70
70
  export * from "./bulk-import/bulk-import-parse-result.dto";
71
71
  export * from "./organizations/member.dto";
72
+ export * from "./organizations/organization.dto";
72
73
  export * from "./passports/passport.dto";
73
74
  export * from "./permalinks/permalink.dto";
74
75
  export * from "./presentation-configurations/presentation-configuration.dto";
@@ -80,6 +81,7 @@ export * from "./shared/table.dto";
80
81
  export * from "./status/status.dto";
81
82
  export * from "./templates/template.dto";
82
83
  export * from "./api-keys/api-key.dto";
84
+ export * from "./oauth-provider/continue-authorization.dto";
83
85
  export * from "./users/create-user.dto";
84
86
  export * from "./users/me.dto";
85
87
  export * from "./users/pending-email-change.dto";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC;AAC7D,cAAc,oCAAoC,CAAC;AACnD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AAEvD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yDAAyD,CAAC;AAExE,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC;AAE/C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;AACtD,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAA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run.dto"), exports);
85
85
  __exportStar(require("./bulk-import/bulk-import-run-item.dto"), exports);
86
86
  __exportStar(require("./bulk-import/bulk-import-parse-result.dto"), exports);
87
87
  __exportStar(require("./organizations/member.dto"), exports);
88
+ __exportStar(require("./organizations/organization.dto"), exports);
88
89
  __exportStar(require("./passports/passport.dto"), exports);
89
90
  __exportStar(require("./permalinks/permalink.dto"), exports);
90
91
  __exportStar(require("./presentation-configurations/presentation-configuration.dto"), exports);
@@ -96,6 +97,7 @@ __exportStar(require("./shared/table.dto"), exports);
96
97
  __exportStar(require("./status/status.dto"), exports);
97
98
  __exportStar(require("./templates/template.dto"), exports);
98
99
  __exportStar(require("./api-keys/api-key.dto"), exports);
100
+ __exportStar(require("./oauth-provider/continue-authorization.dto"), exports);
99
101
  __exportStar(require("./users/create-user.dto"), exports);
100
102
  __exportStar(require("./users/me.dto"), exports);
101
103
  __exportStar(require("./users/pending-email-change.dto"), exports);
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Resumes a pending OAuth Provider authorization after the User signed up (the Trusted
4
+ * Client asked for `prompt=create`). `oauthQuery` is the signed query, up to and including
5
+ * `sig`, that the provider put on the sign-up page's URL.
6
+ */
7
+ export declare const ContinueAuthorizationDtoSchema: z.ZodObject<{
8
+ oauthQuery: z.ZodString;
9
+ }, z.core.$strip>;
10
+ export type ContinueAuthorizationDto = z.infer<typeof ContinueAuthorizationDtoSchema>;
11
+ /** Where the browser continues: the Trusted Client's redirect URI with the authorization code. */
12
+ export declare const ContinueAuthorizationResponseDtoSchema: z.ZodObject<{
13
+ url: z.ZodString;
14
+ }, z.core.$strip>;
15
+ export type ContinueAuthorizationResponseDto = z.infer<typeof ContinueAuthorizationResponseDtoSchema>;
16
+ //# sourceMappingURL=continue-authorization.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"continue-authorization.dto.d.ts","sourceRoot":"","sources":["../../src/oauth-provider/continue-authorization.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;;GAIG;AACH,eAAO,MAAM,8BAA8B;;iBAEzC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAEtF,kGAAkG;AAClG,eAAO,MAAM,sCAAsC;;iBAEjD,CAAC;AAEH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CACpD,OAAO,sCAAsC,CAC9C,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContinueAuthorizationResponseDtoSchema = exports.ContinueAuthorizationDtoSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /** Upper bound for the signed authorize query the OAuth Provider appended to /signup. */
6
+ const MAX_OAUTH_QUERY_LENGTH = 8192;
7
+ /**
8
+ * Resumes a pending OAuth Provider authorization after the User signed up (the Trusted
9
+ * Client asked for `prompt=create`). `oauthQuery` is the signed query, up to and including
10
+ * `sig`, that the provider put on the sign-up page's URL.
11
+ */
12
+ exports.ContinueAuthorizationDtoSchema = zod_1.z.object({
13
+ oauthQuery: zod_1.z.string().min(1).max(MAX_OAUTH_QUERY_LENGTH),
14
+ });
15
+ /** Where the browser continues: the Trusted Client's redirect URI with the authorization code. */
16
+ exports.ContinueAuthorizationResponseDtoSchema = zod_1.z.object({
17
+ url: zod_1.z.string().min(1),
18
+ });
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Wire shape of an organization. The internal `slug` (always equal to `id`)
4
+ * and better-auth's `members` array are deliberately not part of it.
5
+ */
6
+ export declare const OrganizationDtoSchema: z.ZodObject<{
7
+ id: z.ZodString;
8
+ name: z.ZodString;
9
+ logo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
10
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
11
+ createdAt: z.ZodISODateTime;
12
+ }, z.core.$strip>;
13
+ export type OrganizationDto = z.infer<typeof OrganizationDtoSchema>;
14
+ /**
15
+ * Body of `POST /organizations`. A `slug` sent by legacy callers is stripped:
16
+ * the server derives it from the organization id.
17
+ */
18
+ export declare const OrganizationCreateDtoSchema: z.ZodObject<{
19
+ name: z.ZodString;
20
+ }, z.core.$strip>;
21
+ export type OrganizationCreateDto = z.infer<typeof OrganizationCreateDtoSchema>;
22
+ //# sourceMappingURL=organization.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization.dto.d.ts","sourceRoot":"","sources":["../../src/organizations/organization.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;iBAOhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,2BAA2B;;iBAEtC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrganizationCreateDtoSchema = exports.OrganizationDtoSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Wire shape of an organization. The internal `slug` (always equal to `id`)
7
+ * and better-auth's `members` array are deliberately not part of it.
8
+ */
9
+ exports.OrganizationDtoSchema = zod_1.z.object({
10
+ id: zod_1.z.string(),
11
+ name: zod_1.z.string(),
12
+ /** @deprecated Use the organization's Branding logo instead. */
13
+ logo: zod_1.z.string().nullable().optional(),
14
+ metadata: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
15
+ createdAt: zod_1.z.iso.datetime(),
16
+ });
17
+ /**
18
+ * Body of `POST /organizations`. A `slug` sent by legacy callers is stripped:
19
+ * the server derives it from the organization id.
20
+ */
21
+ exports.OrganizationCreateDtoSchema = zod_1.z.object({
22
+ name: zod_1.z.string().trim().min(1),
23
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-dpp/dto",
3
- "version": "5.3.0",
3
+ "version": "6.1.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/open-dpp/open-dpp#readme",
@@ -42,7 +42,7 @@
42
42
  "@tsconfig/node-lts": "^24.0.0",
43
43
  "@tsconfig/node-ts": "^23.6.4",
44
44
  "@types/jest": "^30.0.0",
45
- "@types/node": "^22.0.0",
45
+ "@types/node": "^22.20.3",
46
46
  "jest": "^30.4.2",
47
47
  "typescript": "^5.9.3"
48
48
  },
package/src/index.ts CHANGED
@@ -75,6 +75,7 @@ export * from "./bulk-import/bulk-import-run.dto";
75
75
  export * from "./bulk-import/bulk-import-run-item.dto";
76
76
  export * from "./bulk-import/bulk-import-parse-result.dto";
77
77
  export * from "./organizations/member.dto";
78
+ export * from "./organizations/organization.dto";
78
79
  export * from "./passports/passport.dto";
79
80
  export * from "./permalinks/permalink.dto";
80
81
  export * from "./presentation-configurations/presentation-configuration.dto";
@@ -86,6 +87,7 @@ export * from "./shared/table.dto";
86
87
  export * from "./status/status.dto";
87
88
  export * from "./templates/template.dto";
88
89
  export * from "./api-keys/api-key.dto";
90
+ export * from "./oauth-provider/continue-authorization.dto";
89
91
  export * from "./users/create-user.dto";
90
92
  export * from "./users/me.dto";
91
93
  export * from "./users/pending-email-change.dto";
@@ -0,0 +1,35 @@
1
+ import { expect } from "@jest/globals";
2
+ import {
3
+ ContinueAuthorizationDtoSchema,
4
+ ContinueAuthorizationResponseDtoSchema,
5
+ } from "./continue-authorization.dto";
6
+
7
+ describe("ContinueAuthorizationDtoSchema", () => {
8
+ it("parses the signed authorize query", () => {
9
+ const parsed = ContinueAuthorizationDtoSchema.parse({
10
+ oauthQuery: "client_id=landing-page&prompt=create&exp=1&sig=abc",
11
+ });
12
+ expect(parsed.oauthQuery).toBe("client_id=landing-page&prompt=create&exp=1&sig=abc");
13
+ });
14
+
15
+ it.each([
16
+ ["a missing query", {}],
17
+ ["an empty query", { oauthQuery: "" }],
18
+ ["an oversized query", { oauthQuery: "a".repeat(8193) }],
19
+ ])("rejects %s", (_label: string, body: object) => {
20
+ expect(() => ContinueAuthorizationDtoSchema.parse(body)).toThrow();
21
+ });
22
+ });
23
+
24
+ describe("ContinueAuthorizationResponseDtoSchema", () => {
25
+ it("parses the Trusted Client redirect", () => {
26
+ const parsed = ContinueAuthorizationResponseDtoSchema.parse({
27
+ url: "https://landing.example.com/auth/callback?code=c&state=s",
28
+ });
29
+ expect(parsed.url).toBe("https://landing.example.com/auth/callback?code=c&state=s");
30
+ });
31
+
32
+ it("rejects a response without a URL", () => {
33
+ expect(() => ContinueAuthorizationResponseDtoSchema.parse({})).toThrow();
34
+ });
35
+ });
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+
3
+ /** Upper bound for the signed authorize query the OAuth Provider appended to /signup. */
4
+ const MAX_OAUTH_QUERY_LENGTH = 8192;
5
+
6
+ /**
7
+ * Resumes a pending OAuth Provider authorization after the User signed up (the Trusted
8
+ * Client asked for `prompt=create`). `oauthQuery` is the signed query, up to and including
9
+ * `sig`, that the provider put on the sign-up page's URL.
10
+ */
11
+ export const ContinueAuthorizationDtoSchema = z.object({
12
+ oauthQuery: z.string().min(1).max(MAX_OAUTH_QUERY_LENGTH),
13
+ });
14
+
15
+ export type ContinueAuthorizationDto = z.infer<typeof ContinueAuthorizationDtoSchema>;
16
+
17
+ /** Where the browser continues: the Trusted Client's redirect URI with the authorization code. */
18
+ export const ContinueAuthorizationResponseDtoSchema = z.object({
19
+ url: z.string().min(1),
20
+ });
21
+
22
+ export type ContinueAuthorizationResponseDto = z.infer<
23
+ typeof ContinueAuthorizationResponseDtoSchema
24
+ >;
@@ -0,0 +1,60 @@
1
+ import { describe, expect, it } from "@jest/globals";
2
+ import { OrganizationCreateDtoSchema, OrganizationDtoSchema } from "./organization.dto";
3
+
4
+ const validOrganization = {
5
+ id: "690cf22459cdae7ce188c1f8",
6
+ name: "ACME GmbH",
7
+ logo: "https://example.com/logo.png",
8
+ metadata: { reference: "mollie:tr_123" },
9
+ createdAt: "2026-09-14T10:00:00.000Z",
10
+ };
11
+
12
+ describe("OrganizationDtoSchema", () => {
13
+ it("parses a full organization", () => {
14
+ expect(OrganizationDtoSchema.parse(validOrganization)).toEqual(validOrganization);
15
+ });
16
+
17
+ it("accepts a null or missing logo", () => {
18
+ expect(OrganizationDtoSchema.parse({ ...validOrganization, logo: null }).logo).toBeNull();
19
+ const { logo: _logo, ...withoutLogo } = validOrganization;
20
+ expect(OrganizationDtoSchema.parse(withoutLogo).logo).toBeUndefined();
21
+ });
22
+
23
+ it("strips slug and members from a response", () => {
24
+ const parsed = OrganizationDtoSchema.parse({
25
+ ...validOrganization,
26
+ slug: validOrganization.id,
27
+ members: [],
28
+ });
29
+ expect(parsed).toEqual(validOrganization);
30
+ expect(parsed).not.toHaveProperty("slug");
31
+ expect(parsed).not.toHaveProperty("members");
32
+ });
33
+
34
+ it("rejects a missing id", () => {
35
+ const { id: _id, ...rest } = validOrganization;
36
+ expect(() => OrganizationDtoSchema.parse(rest)).toThrow();
37
+ });
38
+ });
39
+
40
+ describe("OrganizationCreateDtoSchema", () => {
41
+ it("accepts a name and trims it", () => {
42
+ expect(OrganizationCreateDtoSchema.parse({ name: " ACME GmbH " })).toEqual({
43
+ name: "ACME GmbH",
44
+ });
45
+ });
46
+
47
+ it("ignores a provided slug", () => {
48
+ expect(OrganizationCreateDtoSchema.parse({ name: "ACME GmbH", slug: "acme" })).toEqual({
49
+ name: "ACME GmbH",
50
+ });
51
+ });
52
+
53
+ it.each(["", " "])("rejects the name %j", (name) => {
54
+ expect(() => OrganizationCreateDtoSchema.parse({ name })).toThrow();
55
+ });
56
+
57
+ it("rejects a missing name", () => {
58
+ expect(() => OrganizationCreateDtoSchema.parse({})).toThrow();
59
+ });
60
+ });
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+
3
+ /**
4
+ * Wire shape of an organization. The internal `slug` (always equal to `id`)
5
+ * and better-auth's `members` array are deliberately not part of it.
6
+ */
7
+ export const OrganizationDtoSchema = z.object({
8
+ id: z.string(),
9
+ name: z.string(),
10
+ /** @deprecated Use the organization's Branding logo instead. */
11
+ logo: z.string().nullable().optional(),
12
+ metadata: z.record(z.string(), z.unknown()),
13
+ createdAt: z.iso.datetime(),
14
+ });
15
+
16
+ export type OrganizationDto = z.infer<typeof OrganizationDtoSchema>;
17
+
18
+ /**
19
+ * Body of `POST /organizations`. A `slug` sent by legacy callers is stripped:
20
+ * the server derives it from the organization id.
21
+ */
22
+ export const OrganizationCreateDtoSchema = z.object({
23
+ name: z.string().trim().min(1),
24
+ });
25
+
26
+ export type OrganizationCreateDto = z.infer<typeof OrganizationCreateDtoSchema>;