@friggframework/core 2.0.0--canary.688.e850868.0 → 2.0.0--canary.688.87a9bf3.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.
@@ -1,17 +1,22 @@
1
1
  const {
2
2
  createModuleRepository,
3
3
  } = require('../../modules/repositories/module-repository-factory');
4
+ const { toCredentialId } = require('../../modules/utils/to-credential-id');
4
5
 
5
6
  const ERROR_CODE_MAP = {
6
7
  ENTITY_NOT_FOUND: 404,
7
8
  INVALID_ENTITY_DATA: 400,
8
9
  };
9
10
 
10
- function toCredentialId(credential) {
11
- if (credential && typeof credential === 'object') {
12
- return (credential.id ?? credential._id)?.toString() ?? null;
13
- }
14
- return credential ?? null;
11
+ function toEntityDto(entity) {
12
+ return {
13
+ id: entity.id,
14
+ userId: entity.userId,
15
+ externalId: entity.externalId,
16
+ name: entity.name,
17
+ moduleName: entity.moduleName,
18
+ credentialId: toCredentialId(entity.credential),
19
+ };
15
20
  }
16
21
 
17
22
  function mapErrorToResponse(error) {
@@ -73,14 +78,7 @@ function createEntityCommands() {
73
78
 
74
79
  const entity = await moduleRepo.createEntity(entityData);
75
80
 
76
- return {
77
- id: entity.id,
78
- userId: entity.userId,
79
- externalId: entity.externalId,
80
- name: entity.name,
81
- moduleName: entity.moduleName,
82
- credentialId: toCredentialId(entity.credential),
83
- };
81
+ return toEntityDto(entity);
84
82
  } catch (error) {
85
83
  return mapErrorToResponse(error);
86
84
  }
@@ -114,14 +112,7 @@ function createEntityCommands() {
114
112
  return null;
115
113
  }
116
114
 
117
- return {
118
- id: entity.id,
119
- userId: entity.userId,
120
- externalId: entity.externalId,
121
- name: entity.name,
122
- moduleName: entity.moduleName,
123
- credentialId: toCredentialId(entity.credential),
124
- };
115
+ return toEntityDto(entity);
125
116
  } catch (error) {
126
117
  return mapErrorToResponse(error);
127
118
  }
@@ -142,14 +133,7 @@ function createEntityCommands() {
142
133
 
143
134
  const entities = await moduleRepo.findEntitiesByUserId(userId);
144
135
 
145
- return entities.map((entity) => ({
146
- id: entity.id,
147
- userId: entity.userId,
148
- externalId: entity.externalId,
149
- name: entity.name,
150
- moduleName: entity.moduleName,
151
- credentialId: toCredentialId(entity.credential),
152
- }));
136
+ return entities.map((entity) => toEntityDto(entity));
153
137
  } catch (error) {
154
138
  if (error.code) {
155
139
  return mapErrorToResponse(error);
@@ -181,14 +165,7 @@ function createEntityCommands() {
181
165
  moduleName
182
166
  );
183
167
 
184
- return entities.map((entity) => ({
185
- id: entity.id,
186
- userId: entity.userId,
187
- externalId: entity.externalId,
188
- name: entity.name,
189
- moduleName: entity.moduleName,
190
- credentialId: toCredentialId(entity.credential),
191
- }));
168
+ return entities.map((entity) => toEntityDto(entity));
192
169
  } catch (error) {
193
170
  if (error.code) {
194
171
  return mapErrorToResponse(error);
@@ -212,14 +189,7 @@ function createEntityCommands() {
212
189
 
213
190
  const entity = await moduleRepo.findEntityById(entityId);
214
191
 
215
- return {
216
- id: entity.id,
217
- userId: entity.userId,
218
- externalId: entity.externalId,
219
- name: entity.name,
220
- moduleName: entity.moduleName,
221
- credentialId: toCredentialId(entity.credential),
222
- };
192
+ return toEntityDto(entity);
223
193
  } catch (error) {
224
194
  return mapErrorToResponse(error);
225
195
  }
@@ -247,14 +217,7 @@ function createEntityCommands() {
247
217
  throw error;
248
218
  }
249
219
 
250
- return {
251
- id: entity.id,
252
- userId: entity.userId,
253
- externalId: entity.externalId,
254
- name: entity.name,
255
- moduleName: entity.moduleName,
256
- credentialId: toCredentialId(entity.credential),
257
- };
220
+ return toEntityDto(entity);
258
221
  } catch (error) {
259
222
  return mapErrorToResponse(error);
260
223
  }
@@ -1,3 +1,5 @@
1
+ const { toCredentialId } = require('./to-credential-id');
2
+
1
3
  /**
2
4
  * @param {import('../module').Module} moduleInstance
3
5
  * Convert a Module domain instance to a plain DTO suitable for JSON responses.
@@ -10,9 +12,9 @@ function mapModuleClassToModuleDTO(moduleInstance) {
10
12
  name: moduleInstance.name,
11
13
  userId: moduleInstance.userId,
12
14
  entity: moduleInstance.entity,
13
- credentialId: moduleInstance.credential?._id?.toString(),
14
- type: moduleInstance.getName()
15
+ credentialId: toCredentialId(moduleInstance.credential),
16
+ type: moduleInstance.getName(),
15
17
  };
16
18
  }
17
19
 
18
- module.exports = { mapModuleClassToModuleDTO };
20
+ module.exports = { mapModuleClassToModuleDTO };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Resolve the credential id from an entity's or module's `credential`, which
3
+ * repositories return as the decrypted credential object (or a bare id).
4
+ * @param {Object|string|number|null|undefined} credential
5
+ * @returns {string|null}
6
+ */
7
+ function toCredentialId(credential) {
8
+ if (credential && typeof credential === 'object') {
9
+ return credential.id?.toString() ?? null;
10
+ }
11
+ return credential?.toString() ?? null;
12
+ }
13
+
14
+ module.exports = { toCredentialId };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.688.e850868.0",
4
+ "version": "2.0.0--canary.688.87a9bf3.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -47,9 +47,9 @@
47
47
  }
48
48
  },
49
49
  "devDependencies": {
50
- "@friggframework/eslint-config": "2.0.0--canary.688.e850868.0",
51
- "@friggframework/prettier-config": "2.0.0--canary.688.e850868.0",
52
- "@friggframework/test": "2.0.0--canary.688.e850868.0",
50
+ "@friggframework/eslint-config": "2.0.0--canary.688.87a9bf3.0",
51
+ "@friggframework/prettier-config": "2.0.0--canary.688.87a9bf3.0",
52
+ "@friggframework/test": "2.0.0--canary.688.87a9bf3.0",
53
53
  "@prisma/client": "^6.19.3",
54
54
  "@types/lodash": "4.17.15",
55
55
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -89,5 +89,5 @@
89
89
  "publishConfig": {
90
90
  "access": "public"
91
91
  },
92
- "gitHead": "e850868f19706ee89566fd9724603dee1e03a711"
92
+ "gitHead": "87a9bf3315fc2daa2b7f38b7b1ddd5bbcb323b20"
93
93
  }