@routr/simpledata 2.0.8-alpha.0 → 2.0.8-alpha.10

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/api.js CHANGED
@@ -84,7 +84,8 @@ exports.get = get;
84
84
  function findBy(resources) {
85
85
  return (call, callback) => {
86
86
  const filteredResources = resources.filter((resource) => { var _a, _b; return ((_a = resource.kind) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = call.request.kind) === null || _b === void 0 ? void 0 : _b.toLowerCase()); });
87
- if (filteredResources == null || filteredResources.length === 0) {
87
+ // WARNING: This seems to contradict the result of the query
88
+ if (filteredResources.length === 0) {
88
89
  return callback(new errors_1.ResourceNotFound(""), null);
89
90
  }
90
91
  const queryObject = (0, utils_1.createQuery)(call.request);
package/dist/utils.js CHANGED
@@ -54,10 +54,12 @@ const jsonFromStruct = protobufUtil.struct.decode;
54
54
  const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
55
55
  const findCriteriaMap = {};
56
56
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_AGENT_BY_USERNAME] = (parameters) => `$..[?(@.spec.username=='${parameters.username}')]`;
57
+ findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_PEER_BY_USERNAME] = (parameters) => `$..[?(@.spec.username=='${parameters.username}')]`;
57
58
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_CREDENTIAL_BY_REFERENCE] = (parameters) => `$..[?(@.ref=='${parameters.ref}')]`;
58
59
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_DOMAIN_BY_DOMAINURI] = (parameters) => `$..[?(@.spec.context.domainUri=='${parameters.domainUri}')]`;
59
60
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_NUMBER_BY_TELURL] = (parameters) => `$..[?(@.spec.location.telUrl=="${parameters.telUrl}")]`;
60
61
  findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER] = () => "$..[?(@.spec.outbound.sendRegister==true)]";
62
+ findCriteriaMap[common_1.CommonConnect.FindCriteria.FIND_TRUNK_BY_REQUEST_URI] = (parameters) => `$..[?(@.spec.inbound.uri=="${parameters.requestUri}")]`;
61
63
  /**
62
64
  * Creates a list of validators from the given schemas.
63
65
  *
@@ -78,6 +80,76 @@ function createValidators(path) {
78
80
  return validators;
79
81
  }
80
82
  exports.createValidators = createValidators;
83
+ // Create function to validate reference exists for Agent
84
+ const checkReferences = (resources) => {
85
+ const referenceExist = (ref) => resources.filter((r) => r.ref === ref)[0];
86
+ // For every resource, check that the reference exists using a switch
87
+ resources.forEach((resource) => {
88
+ var _a;
89
+ switch (resource.kind.toLocaleLowerCase()) {
90
+ case common_1.CommonConnect.Kind.AGENT:
91
+ if (resource.spec.credentialsRef) {
92
+ if (!referenceExist(resource.spec.credentialsRef)) {
93
+ logger.error(`agent ${resource.ref} has a credential reference that does not exist: ${resource.spec.credentialsRef}; exiting`);
94
+ process.exit(1);
95
+ }
96
+ }
97
+ if (resource.spec.domainRef) {
98
+ if (!referenceExist(resource.spec.domainRef)) {
99
+ logger.error(`agent ${resource.ref} has a domain reference that does not exist: ${resource.spec.domainRef}; exiting`);
100
+ process.exit(1);
101
+ }
102
+ }
103
+ break;
104
+ case common_1.CommonConnect.Kind.PEER:
105
+ if (resource.spec.credentialsRef) {
106
+ if (!referenceExist(resource.spec.credentialsRef)) {
107
+ logger.error(`peer ${resource.ref} has a credential reference that does not exist: ${resource.spec.credentialsRef}; exiting`);
108
+ process.exit(1);
109
+ }
110
+ }
111
+ break;
112
+ case common_1.CommonConnect.Kind.TRUNK:
113
+ if (resource.spec.inbound.credentialsRef) {
114
+ if (!referenceExist(resource.spec.inbound.credentialsRef)) {
115
+ logger.error(`trunk ${resource.ref} has a credential reference that does not exist: ${resource.spec.inbound.credentialsRef}; exiting`);
116
+ process.exit(1);
117
+ }
118
+ }
119
+ if (resource.spec.inbound.accessControlListRef) {
120
+ if (!referenceExist(resource.spec.inbound.accessControlListRef)) {
121
+ logger.error(`trunk ${resource.ref} has an acl reference that does not exist: ${resource.spec.inbound.accessControlListRef}; exiting`);
122
+ process.exit(1);
123
+ }
124
+ }
125
+ break;
126
+ case common_1.CommonConnect.Kind.DOMAIN:
127
+ if (resource.spec.accessControlListRef) {
128
+ if (!referenceExist(resource.spec.accessControlListRef)) {
129
+ logger.error(`domain ${resource.ref} has an acl reference that does not exist: ${resource.spec.accessControlListRef}; exiting`);
130
+ process.exit(1);
131
+ }
132
+ }
133
+ if ((_a = resource.spec.context) === null || _a === void 0 ? void 0 : _a.egressPolicies) {
134
+ resource.spec.context.egressPolicies.forEach((policy) => {
135
+ if (policy.numberRef) {
136
+ if (!referenceExist(policy.numberRef)) {
137
+ logger.error(`domain ${resource.ref} has a number reference that does not exist: ${policy.numberRef}; exiting`);
138
+ process.exit(1);
139
+ }
140
+ }
141
+ });
142
+ }
143
+ break;
144
+ case common_1.CommonConnect.Kind.NUMBER:
145
+ if (!referenceExist(resource.spec.trunkRef)) {
146
+ logger.error(`number ${resource.ref} has a trunk reference that does not exist: ${resource.spec.trunkRef}; exiting`);
147
+ process.exit(1);
148
+ }
149
+ break;
150
+ }
151
+ });
152
+ };
81
153
  /**
82
154
  * Loads a list of resources from a file.
83
155
  *
@@ -94,6 +166,11 @@ function loadResources(validatorsPath, resourcesPath) {
94
166
  // eslint-disable-next-line @typescript-eslint/no-var-requires
95
167
  const resources = require(`${resourcesPath}/${file}`);
96
168
  resources.forEach((resource) => {
169
+ // Assert the reference has no spaces
170
+ if (resource.ref.includes(" ")) {
171
+ logger.error(`resource type ${resource.kind} has spaces in the reference: "${resource.ref}"; exiting`);
172
+ process.exit(1);
173
+ }
97
174
  // Check if is valid using jsonschema
98
175
  const validate = validators.get(resource.kind.toLocaleLowerCase());
99
176
  if (!validate) {
@@ -111,6 +188,8 @@ function loadResources(validatorsPath, resourcesPath) {
111
188
  }
112
189
  });
113
190
  });
191
+ // Referencial check
192
+ checkReferences(all);
114
193
  logger.verbose("loaded data resources", { total: all.length });
115
194
  return all;
116
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/simpledata",
3
- "version": "2.0.8-alpha.0",
3
+ "version": "2.0.8-alpha.10",
4
4
  "description": "Files-based API Server for Routr Connect",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -29,8 +29,8 @@
29
29
  "@opentelemetry/sdk-trace-base": "^1.0.4",
30
30
  "@opentelemetry/sdk-trace-node": "^1.0.4",
31
31
  "@opentelemetry/semantic-conventions": "^1.0.4",
32
- "@routr/common": "^2.0.8-alpha.0",
33
- "@routr/processor": "^2.0.8-alpha.0",
32
+ "@routr/common": "^2.0.8-alpha.10",
33
+ "@routr/processor": "^2.0.8-alpha.10",
34
34
  "ajv": "^6.12.6",
35
35
  "google-protobuf": "^3.9.2",
36
36
  "jsonpath": "^1.1.1",
@@ -53,5 +53,5 @@
53
53
  "@types/google-protobuf": "^3.15.6",
54
54
  "@types/jsonpath": "^0.2.0"
55
55
  },
56
- "gitHead": "69c60f113c27bc00cbadb62dbdbbb70960ef0f4d"
56
+ "gitHead": "5082233fb155ddb8535f934550fa4013da87468e"
57
57
  }