@routr/pgdata 2.0.8-alpha.20 → 2.0.8-alpha.23

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.
@@ -49,7 +49,7 @@ function create(operation, kind) {
49
49
  if (objFromDB.extended) {
50
50
  objFromDB.extended = pb_util_1.struct.encode(objFromDB.extended);
51
51
  }
52
- callback(null, objFromDB);
52
+ callback(null, Manager.mapToDto(objFromDB));
53
53
  }
54
54
  catch (e) {
55
55
  if (e.code === "P2002") {
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.del = void 0;
13
13
  const errors_1 = require("@routr/common/src/errors");
14
+ // TODO: Fix the error handling. We should return the error
14
15
  function del(operation) {
15
16
  return (call, callback) => __awaiter(this, void 0, void 0, function* () {
16
17
  if (!call.request.ref) {
package/dist/api/get.js CHANGED
@@ -48,7 +48,7 @@ function get(operation, kind) {
48
48
  objectFromDB.extended = pb_util_1.struct.encode(objectFromDB.extended);
49
49
  }
50
50
  objectFromDB
51
- ? callback(null, objectFromDB)
51
+ ? callback(null, Manager.mapToDto(objectFromDB))
52
52
  : callback(new common_1.CommonErrors.ResourceNotFoundError(call.request.ref), null);
53
53
  });
54
54
  }
package/dist/api/list.js CHANGED
@@ -48,13 +48,14 @@ function list(operation, kind) {
48
48
  },
49
49
  include: Manager.includeFields()
50
50
  }));
51
- items.forEach((item) => {
51
+ const itemsWithEncodedDates = items.map((item) => {
52
52
  if (item.extended) {
53
53
  item.extended = pb_util_1.struct.encode(item.extended);
54
54
  }
55
+ return Manager.mapToDto(item);
55
56
  });
56
57
  callback(null, {
57
- items,
58
+ items: itemsWithEncodedDates,
58
59
  nextPageToken: (_a = items[items.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
59
60
  });
60
61
  }
@@ -32,6 +32,11 @@ exports.update = void 0;
32
32
  const pb_util_1 = require("pb-util");
33
33
  const errors_1 = require("@routr/common/src/errors");
34
34
  const utils_1 = require("../mappers/utils");
35
+ const connect_1 = require("@routr/common/src/connect");
36
+ const client_1 = require("@prisma/client");
37
+ // TODO: The entire function should be wrapped in a transaction
38
+ // TODO: We should reuse the prisma client
39
+ const prisma = new client_1.PrismaClient();
35
40
  function update(operation, kind) {
36
41
  return (call, callback) => __awaiter(this, void 0, void 0, function* () {
37
42
  try {
@@ -42,17 +47,31 @@ function update(operation, kind) {
42
47
  const Manager = (0, utils_1.getManager)(kind);
43
48
  const manager = new Manager(request);
44
49
  manager.validOrThrowUpdate();
45
- const agentFromDB = (yield operation({
50
+ if (kind === connect_1.Kind.DOMAIN) {
51
+ yield prisma.egressPolicy.deleteMany({
52
+ where: {
53
+ domainRef: request.ref
54
+ }
55
+ });
56
+ }
57
+ if (kind === connect_1.Kind.TRUNK) {
58
+ yield prisma.trunkURI.deleteMany({
59
+ where: {
60
+ trunkRef: request.ref
61
+ }
62
+ });
63
+ }
64
+ const objectFromDB = (yield operation({
46
65
  where: {
47
66
  ref: request.ref
48
67
  },
49
68
  data: manager.mapToPrisma(),
50
69
  include: Manager.includeFields()
51
70
  }));
52
- if (agentFromDB.extended) {
53
- agentFromDB.extended = pb_util_1.struct.encode(agentFromDB.extended);
71
+ if (objectFromDB.extended) {
72
+ objectFromDB.extended = pb_util_1.struct.encode(objectFromDB.extended);
54
73
  }
55
- callback(null, agentFromDB);
74
+ callback(null, Manager.mapToDto(objectFromDB));
56
75
  }
57
76
  catch (e) {
58
77
  if (e.code === "P2025") {
@@ -1,49 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.ACLManager = void 0;
27
- /*
28
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
- * http://github.com/fonoster
30
- *
31
- * This file is part of Routr.
32
- *
33
- * Licensed under the MIT License (the "License");
34
- * you may not use this file except in compliance with
35
- * the License. You may obtain a copy of the License at
36
- *
37
- * https://opensource.org/licenses/MIT
38
- *
39
- * Unless required by applicable law or agreed to in writing, software
40
- * distributed under the License is distributed on an "AS IS" BASIS,
41
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
- * See the License for the specific language governing permissions and
43
- * limitations under the License.
44
- */
45
- /* eslint-disable require-jsdoc */
46
- const Validator = __importStar(require("validator"));
47
4
  const common_1 = require("@routr/common");
48
5
  const manager_1 = require("./manager");
49
6
  class ACLManager extends manager_1.EntityManager {
@@ -55,79 +12,36 @@ class ACLManager extends manager_1.EntityManager {
55
12
  return null;
56
13
  }
57
14
  validOrThrowCreate() {
58
- var _a, _b;
59
- if (!this.acl.name) {
60
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
61
- }
62
- if (!Validator.default.isLength(this.acl.name, { min: 3, max: 64 })) {
63
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
64
- }
65
- if (!this.acl.deny ||
66
- !this.acl.allow ||
67
- ((_a = this.acl.deny) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
68
- ((_b = this.acl.allow) === null || _b === void 0 ? void 0 : _b.length) === 0) {
69
- throw new common_1.CommonErrors.BadRequestError("acl rules are required");
70
- }
71
- this.acl.deny.forEach((cidr) => {
72
- // 4 => IPv4
73
- if (!Validator.default.isIPRange(cidr, 4) &&
74
- !Validator.default.isIP(cidr, 4)) {
75
- throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr or ip`);
76
- }
77
- });
78
- this.acl.allow.forEach((cidr) => {
79
- // 4 => IPv4
80
- if (!Validator.default.isIPRange(cidr, 4) &&
81
- !Validator.default.isIP(cidr, 4)) {
82
- throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr or ip`);
83
- }
84
- });
15
+ common_1.CommonConnect.hasNameOrThrow(this.acl.name);
16
+ common_1.CommonConnect.isValidNameOrThrow(this.acl.name);
17
+ common_1.CommonConnect.hasACLRulesOrThrow(this.acl);
18
+ common_1.CommonConnect.hasValidACLRulesOrThrow(this.acl);
85
19
  }
86
20
  validOrThrowUpdate() {
87
- var _a, _b;
88
- if (!this.acl.ref) {
89
- throw new common_1.CommonErrors.BadRequestError("the reference to the resource is required");
90
- }
91
- if (!this.acl.name) {
92
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
93
- }
94
- if (!Validator.default.isLength(this.acl.name, { min: 4, max: 64 })) {
95
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
96
- }
97
- if (!this.acl.deny ||
98
- !this.acl.allow ||
99
- ((_a = this.acl.deny) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
100
- ((_b = this.acl.allow) === null || _b === void 0 ? void 0 : _b.length) === 0) {
101
- throw new common_1.CommonErrors.BadRequestError("acl rules are required");
102
- }
103
- this.acl.deny.forEach((cidr) => {
104
- // 4 => IPv4
105
- if (!Validator.default.isIPRange(cidr, 4) &&
106
- !Validator.default.isIP(cidr, 4)) {
107
- throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr or ip`);
108
- }
109
- });
110
- this.acl.allow.forEach((cidr) => {
111
- // 4 => IPv4
112
- if (!Validator.default.isIPRange(cidr, 4) &&
113
- !Validator.default.isIP(cidr, 4)) {
114
- throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr or ip`);
115
- }
116
- });
21
+ common_1.CommonConnect.hasRefenceOrThrow(this.acl.ref);
22
+ common_1.CommonConnect.isValidNameOrThrow(this.acl.name);
23
+ common_1.CommonConnect.hasValidACLRulesOrThrow(this.acl);
117
24
  }
118
25
  mapToPrisma() {
119
26
  return {
120
- // TODO: Set a default value for apiVersion
27
+ // TODO: Create a default value for apiVersion
121
28
  apiVersion: "v2",
122
29
  ref: this.acl.ref,
123
30
  name: this.acl.name,
124
31
  allow: this.acl.allow,
125
32
  deny: this.acl.deny,
33
+ createdAt: this.acl.createdAt
34
+ ? new Date(this.acl.createdAt * 1000)
35
+ : undefined,
36
+ updatedAt: this.acl.updatedAt
37
+ ? new Date(this.acl.updatedAt * 1000)
38
+ : undefined,
126
39
  extended: this.acl.extended || {}
127
40
  };
128
41
  }
129
42
  static mapToDto(acl) {
130
- return Object.assign(Object.assign({}, acl), { extended: acl.extended });
43
+ return acl
44
+ ? Object.assign(Object.assign({}, acl), { createdAt: acl.createdAt.getTime() / 1000, updatedAt: acl.updatedAt.getTime() / 1000, extended: acl.extended }) : undefined;
131
45
  }
132
46
  }
133
47
  exports.ACLManager = ACLManager;
@@ -7,6 +7,7 @@ type AgentWithDomainAndCredentials = Prisma.AgentGetPayload<{
7
7
  domain: {
8
8
  include: {
9
9
  accessControlList: true;
10
+ egressPolicies: true;
10
11
  };
11
12
  };
12
13
  credentials: true;
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.AgentManager = void 0;
27
4
  /*
@@ -43,7 +20,6 @@ exports.AgentManager = void 0;
43
20
  * limitations under the License.
44
21
  */
45
22
  /* eslint-disable require-jsdoc */
46
- const Validator = __importStar(require("validator"));
47
23
  const client_1 = require("@prisma/client");
48
24
  const common_1 = require("@routr/common");
49
25
  const credentials_1 = require("./credentials");
@@ -66,29 +42,14 @@ class AgentManager extends manager_1.EntityManager {
66
42
  };
67
43
  }
68
44
  validOrThrowCreate() {
69
- if (!this.agent.name) {
70
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
71
- }
72
- if (!Validator.default.isLength(this.agent.name, { min: 3, max: 64 })) {
73
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
74
- }
75
- if (!this.agent.username) {
76
- throw new common_1.CommonErrors.BadRequestError("the username is required");
77
- }
78
- if (!Validator.default.isAlphanumeric(this.agent.username)) {
79
- throw new common_1.CommonErrors.BadRequestError("the username must be alphanumeric and without spaces");
80
- }
45
+ common_1.CommonConnect.hasNameOrThrow(this.agent.name);
46
+ common_1.CommonConnect.isValidNameOrThrow(this.agent.name);
47
+ common_1.CommonConnect.hasUsernameOrThrow(this.agent.username);
48
+ common_1.CommonConnect.isValidUsernameOrThrow(this.agent.username);
81
49
  }
82
50
  validOrThrowUpdate() {
83
- if (!this.agent.ref) {
84
- throw new common_1.CommonErrors.BadRequestError("the reference to the resource is required");
85
- }
86
- if (!this.agent.name) {
87
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
88
- }
89
- if (!Validator.default.isLength(this.agent.name, { min: 3, max: 64 })) {
90
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
91
- }
51
+ common_1.CommonConnect.hasRefenceOrThrow(this.agent.ref);
52
+ common_1.CommonConnect.isValidNameOrThrow(this.agent.name);
92
53
  }
93
54
  mapToPrisma() {
94
55
  var _a;
@@ -102,29 +63,33 @@ class AgentManager extends manager_1.EntityManager {
102
63
  enabled: this.agent.enabled,
103
64
  domainRef: this.agent.domainRef || null,
104
65
  credentialsRef: this.agent.credentialsRef || null,
105
- createdAt: this.agent.createdAt,
106
- updatedAt: this.agent.updatedAt,
66
+ createdAt: this.agent.createdAt
67
+ ? new Date(this.agent.createdAt * 1000)
68
+ : undefined,
69
+ updatedAt: this.agent.updatedAt
70
+ ? new Date(this.agent.updatedAt * 1000)
71
+ : undefined,
107
72
  extended: this.agent.extended || {}
108
73
  };
109
74
  }
110
75
  static mapToDto(agent) {
111
- return {
112
- apiVersion: agent.apiVersion,
113
- ref: agent.ref,
114
- name: agent.name,
115
- username: agent.username,
116
- privacy: agent.privacy,
117
- enabled: agent.enabled,
118
- domainRef: agent.domainRef,
119
- domain: agent.domain ? domain_1.DomainManager.mapToDto(agent.domain) : undefined,
120
- credentialsRef: agent.credentialsRef,
121
- credentials: agent.credentials
122
- ? credentials_1.CredentialsManager.mapToDto(agent.credentials)
123
- : undefined,
124
- extended: (agent.extended || {}),
125
- createdAt: agent.createdAt,
126
- updatedAt: agent.updatedAt
127
- };
76
+ return agent
77
+ ? {
78
+ apiVersion: agent.apiVersion,
79
+ ref: agent.ref,
80
+ name: agent.name,
81
+ username: agent.username,
82
+ privacy: agent.privacy,
83
+ enabled: agent.enabled,
84
+ domainRef: agent.domainRef,
85
+ credentialsRef: agent.credentialsRef,
86
+ domain: domain_1.DomainManager.mapToDto(agent.domain),
87
+ credentials: credentials_1.CredentialsManager.mapToDto(agent.credentials),
88
+ extended: (agent.extended || {}),
89
+ createdAt: agent.createdAt.getTime() / 1000,
90
+ updatedAt: agent.updatedAt.getTime() / 1000
91
+ }
92
+ : undefined;
128
93
  }
129
94
  }
130
95
  exports.AgentManager = AgentManager;
@@ -1,49 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.CredentialsManager = void 0;
27
- /*
28
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
- * http://github.com/fonoster
30
- *
31
- * This file is part of Routr.
32
- *
33
- * Licensed under the MIT License (the "License");
34
- * you may not use this file except in compliance with
35
- * the License. You may obtain a copy of the License at
36
- *
37
- * https://opensource.org/licenses/MIT
38
- *
39
- * Unless required by applicable law or agreed to in writing, software
40
- * distributed under the License is distributed on an "AS IS" BASIS,
41
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
- * See the License for the specific language governing permissions and
43
- * limitations under the License.
44
- */
45
- /* eslint-disable require-jsdoc */
46
- const Validator = __importStar(require("validator"));
47
4
  const common_1 = require("@routr/common");
48
5
  const manager_1 = require("./manager");
49
6
  // Needs testing
@@ -56,37 +13,16 @@ class CredentialsManager extends manager_1.EntityManager {
56
13
  return null;
57
14
  }
58
15
  validOrThrowCreate() {
59
- if (!this.credentials.name) {
60
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
61
- }
62
- if (!Validator.default.isLength(this.credentials.name, { min: 3, max: 64 })) {
63
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
64
- }
65
- if (!this.credentials.username) {
66
- throw new common_1.CommonErrors.BadRequestError("the username is required");
67
- }
68
- if (!this.credentials.password) {
69
- throw new common_1.CommonErrors.BadRequestError("the password is required");
70
- }
71
- if (!Validator.default.isAlphanumeric(this.credentials.username)) {
72
- throw new common_1.CommonErrors.BadRequestError("the username must be alphanumeric and without spaces");
73
- }
16
+ common_1.CommonConnect.hasNameOrThrow(this.credentials.name);
17
+ common_1.CommonConnect.isValidNameOrThrow(this.credentials.name);
18
+ common_1.CommonConnect.hasUsernameOrThrow(this.credentials.username);
19
+ common_1.CommonConnect.isValidUsernameOrThrow(this.credentials.username);
20
+ common_1.CommonConnect.hasPasswordOrThrow(this.credentials.password);
74
21
  }
75
22
  validOrThrowUpdate() {
76
- if (!this.credentials.ref) {
77
- throw new common_1.CommonErrors.BadRequestError("the reference to the resource is required");
78
- }
79
- if (!this.credentials.name) {
80
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
81
- }
82
- if (!Validator.default.isLength(this.credentials.name, { min: 3, max: 64 })) {
83
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
84
- }
85
- if (this.credentials.username) {
86
- if (!Validator.default.isAlphanumeric(this.credentials.username)) {
87
- throw new common_1.CommonErrors.BadRequestError("the username must be alphanumeric and without spaces");
88
- }
89
- }
23
+ common_1.CommonConnect.hasRefenceOrThrow(this.credentials.ref);
24
+ common_1.CommonConnect.isValidNameOrThrow(this.credentials.name);
25
+ common_1.CommonConnect.isValidUsernameOrThrow(this.credentials.username);
90
26
  }
91
27
  mapToPrisma() {
92
28
  return {
@@ -95,19 +31,29 @@ class CredentialsManager extends manager_1.EntityManager {
95
31
  ref: this.credentials.ref,
96
32
  name: this.credentials.name,
97
33
  username: this.credentials.username,
98
- password: this.credentials.password,
99
- extended: this.credentials.extended
34
+ password: this.credentials.password || undefined,
35
+ createdAt: this.credentials.createdAt
36
+ ? new Date(this.credentials.createdAt * 1000)
37
+ : undefined,
38
+ updatedAt: this.credentials.updatedAt
39
+ ? new Date(this.credentials.updatedAt * 1000)
40
+ : undefined,
41
+ extended: this.credentials.extended || {}
100
42
  };
101
43
  }
102
44
  static mapToDto(credentials) {
103
- return {
104
- apiVersion: credentials.apiVersion,
105
- ref: credentials.ref,
106
- name: credentials.name,
107
- username: credentials.username,
108
- password: credentials.password,
109
- extended: credentials.extended
110
- };
45
+ return credentials
46
+ ? {
47
+ apiVersion: credentials.apiVersion,
48
+ ref: credentials.ref,
49
+ name: credentials.name,
50
+ username: credentials.username,
51
+ password: credentials.password,
52
+ createdAt: credentials.createdAt.getTime() / 1000,
53
+ updatedAt: credentials.updatedAt.getTime() / 1000,
54
+ extended: credentials.extended
55
+ }
56
+ : undefined;
111
57
  }
112
58
  }
113
59
  exports.CredentialsManager = CredentialsManager;
@@ -1,10 +1,11 @@
1
- import { Domain as DomainPrismaModel, Prisma } from "@prisma/client";
1
+ import { Domain as DomainPrismaModel, Prisma, EgressPolicy } from "@prisma/client";
2
2
  import { CommonConnect as CC } from "@routr/common";
3
3
  import { JsonObject } from "pb-util/build";
4
4
  import { EntityManager } from "./manager";
5
5
  type DomainWithACL = Prisma.DomainGetPayload<{
6
6
  include: {
7
7
  accessControlList: true;
8
+ egressPolicies: true;
8
9
  };
9
10
  }>;
10
11
  export declare class DomainManager extends EntityManager {
@@ -13,7 +14,11 @@ export declare class DomainManager extends EntityManager {
13
14
  static includeFields(): JsonObject;
14
15
  validOrThrowCreate(): void;
15
16
  validOrThrowUpdate(): void;
16
- mapToPrisma(): DomainPrismaModel;
17
+ mapToPrisma(): DomainPrismaModel & {
18
+ egressPolicies: {
19
+ create: Omit<EgressPolicy, "ref" | "domainRef">[];
20
+ };
21
+ };
17
22
  static mapToDto(domain: DomainWithACL): CC.Domain;
18
23
  }
19
24
  export {};
@@ -1,49 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.DomainManager = void 0;
27
- /*
28
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
- * http://github.com/fonoster
30
- *
31
- * This file is part of Routr.
32
- *
33
- * Licensed under the MIT License (the "License");
34
- * you may not use this file except in compliance with
35
- * the License. You may obtain a copy of the License at
36
- *
37
- * https://opensource.org/licenses/MIT
38
- *
39
- * Unless required by applicable law or agreed to in writing, software
40
- * distributed under the License is distributed on an "AS IS" BASIS,
41
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
- * See the License for the specific language governing permissions and
43
- * limitations under the License.
44
- */
45
- /* eslint-disable require-jsdoc */
46
- const Validator = __importStar(require("validator"));
47
4
  const common_1 = require("@routr/common");
48
5
  const acl_1 = require("./acl");
49
6
  const manager_1 = require("./manager");
@@ -59,56 +16,42 @@ class DomainManager extends manager_1.EntityManager {
59
16
  };
60
17
  }
61
18
  validOrThrowCreate() {
62
- if (!this.domain.name) {
63
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
64
- }
65
- if (!Validator.default.isLength(this.domain.name, { min: 3, max: 64 })) {
66
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
67
- }
68
- if (!this.domain.domainUri) {
69
- throw new common_1.CommonErrors.BadRequestError("the domainUri is required");
70
- }
71
- if (!Validator.default.isFQDN(this.domain.domainUri)) {
72
- throw new common_1.CommonErrors.BadRequestError("the domainUri must be a valid fully qualified domain name");
73
- }
19
+ common_1.CommonConnect.hasNameOrThrow(this.domain.name);
20
+ common_1.CommonConnect.isValidNameOrThrow(this.domain.name);
21
+ common_1.CommonConnect.isValidDomainUriOrThrow(this.domain.domainUri);
74
22
  }
75
23
  validOrThrowUpdate() {
76
- if (!this.domain.ref) {
77
- throw new common_1.CommonErrors.BadRequestError("the reference to the resource is required");
78
- }
79
- if (!this.domain.name) {
80
- throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
81
- }
82
- if (!Validator.default.isLength(this.domain.name, { min: 3, max: 64 })) {
83
- throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
84
- }
24
+ common_1.CommonConnect.hasRefenceOrThrow(this.domain.ref);
25
+ common_1.CommonConnect.isValidNameOrThrow(this.domain.name);
85
26
  }
86
27
  mapToPrisma() {
28
+ var _a;
87
29
  return {
88
30
  // TODO: Set a default value for apiVersion
89
31
  apiVersion: "v2",
90
32
  ref: this.domain.ref,
91
33
  name: this.domain.name,
92
- accessControlListRef: this.domain.accessControlListRef,
34
+ accessControlListRef: this.domain.accessControlListRef || null,
93
35
  domainUri: this.domain.domainUri,
94
- extended: this.domain.extended,
95
- createdAt: this.domain.createdAt,
36
+ extended: this.domain.extended || {},
37
+ createdAt: this.domain.createdAt
38
+ ? new Date(this.domain.createdAt * 1000)
39
+ : undefined,
96
40
  updatedAt: this.domain.updatedAt
41
+ ? new Date(this.domain.updatedAt * 1000)
42
+ : undefined,
43
+ egressPolicies: {
44
+ create: (_a = this.domain.egressPolicies) === null || _a === void 0 ? void 0 : _a.map((policy) => ({
45
+ rule: policy.rule,
46
+ numberRef: policy.numberRef
47
+ }))
48
+ }
97
49
  };
98
50
  }
99
51
  static mapToDto(domain) {
100
52
  var _a;
101
- return {
102
- apiVersion: domain.apiVersion,
103
- ref: domain.ref,
104
- name: domain.name,
105
- accessControlListRef: (_a = domain.accessControlList) === null || _a === void 0 ? void 0 : _a.ref,
106
- accessControlList: acl_1.ACLManager.mapToDto(domain.accessControlList),
107
- domainUri: domain.domainUri,
108
- extended: domain.extended,
109
- createdAt: domain.createdAt,
110
- updatedAt: domain.updatedAt
111
- };
53
+ return domain
54
+ ? Object.assign(Object.assign({}, domain), { accessControlListRef: (_a = domain.accessControlList) === null || _a === void 0 ? void 0 : _a.ref, accessControlList: acl_1.ACLManager.mapToDto(domain.accessControlList), extended: domain.extended, createdAt: domain.createdAt.getTime() / 1000, updatedAt: domain.updatedAt.getTime() / 1000 }) : undefined;
112
55
  }
113
56
  }
114
57
  exports.DomainManager = DomainManager;