@friggframework/core 2.0.0--canary.517.f8e0cc1.0 → 2.0.0--canary.517.44c158e.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.
@@ -51,13 +51,50 @@ function mapErrorToResponse(error) {
51
51
  };
52
52
  }
53
53
 
54
- function createIntegrationCommands({ integrationClass }) {
54
+ function createIntegrationCommands({ integrationClass } = {}) {
55
+ // Always use Frigg's default repositories and use cases
56
+ const integrationRepository = createIntegrationRepository();
57
+
58
+ // Class-agnostic read commands. Available without an integrationClass so
59
+ // callers that operate across integration types (e.g. admin scripts) can
60
+ // look up integrations by id or list them by type/status.
61
+ const readCommands = {
62
+ /**
63
+ * Find a single integration record by id.
64
+ * @param {string} integrationId
65
+ * @returns {Promise<Object>} Integration record, or an error object.
66
+ */
67
+ async findIntegrationById(integrationId) {
68
+ try {
69
+ return await integrationRepository.findIntegrationById(
70
+ integrationId
71
+ );
72
+ } catch (error) {
73
+ return mapErrorToResponse(error);
74
+ }
75
+ },
76
+
77
+ /**
78
+ * List integrations, optionally filtered by config type and/or status.
79
+ * @param {Object} [filter={}]
80
+ * @param {string} [filter.type] - Integration type (config.type)
81
+ * @param {string} [filter.status] - Integration status
82
+ * @returns {Promise<Array|Object>} Array of integrations, or an error object.
83
+ */
84
+ async listIntegrations(filter = {}) {
85
+ try {
86
+ return await integrationRepository.findIntegrations(filter);
87
+ } catch (error) {
88
+ return mapErrorToResponse(error);
89
+ }
90
+ },
91
+ };
92
+
93
+ // The remaining commands hydrate/modify integrations for a specific class.
55
94
  if (!integrationClass) {
56
- throw new Error('integrationClass is required');
95
+ return readCommands;
57
96
  }
58
97
 
59
- // Always use Frigg's default repositories and use cases
60
- const integrationRepository = createIntegrationRepository();
61
98
  const moduleRepository = createModuleRepository();
62
99
 
63
100
  const moduleDefinitions = getModulesDefinitionFromIntegrationClasses([
@@ -116,6 +153,8 @@ function createIntegrationCommands({ integrationClass }) {
116
153
  });
117
154
 
118
155
  return {
156
+ ...readCommands,
157
+
119
158
  /**
120
159
  * Find integration context by external entity ID and type
121
160
  * @param {Object} params
@@ -27,6 +27,18 @@ class IntegrationRepositoryDocumentDB extends IntegrationRepositoryInterface {
27
27
  return records.map((doc) => this._mapIntegration(doc));
28
28
  }
29
29
 
30
+ async findIntegrations({ type, status } = {}) {
31
+ const filter = {};
32
+ if (type) {
33
+ filter['config.type'] = type;
34
+ }
35
+ if (status) {
36
+ filter.status = status;
37
+ }
38
+ const records = await findMany(this.prisma, 'Integration', filter);
39
+ return records.map((doc) => this._mapIntegration(doc));
40
+ }
41
+
30
42
  async findIntegrationsByEntityId(entityId) {
31
43
  const objectId = toObjectId(entityId);
32
44
  if (!objectId) return [];
@@ -21,6 +21,20 @@ class IntegrationRepositoryInterface {
21
21
  throw new Error('Method findIntegrationsByUserId must be implemented by subclass');
22
22
  }
23
23
 
24
+ /**
25
+ * Find integrations, optionally filtered by config type and/or status.
26
+ * With no filter, returns every integration.
27
+ *
28
+ * @param {Object} [filter={}]
29
+ * @param {string} [filter.type] - Integration type (config.type)
30
+ * @param {string} [filter.status] - Integration status
31
+ * @returns {Promise<Array>} Array of integration objects (possibly empty)
32
+ * @abstract
33
+ */
34
+ async findIntegrations(filter = {}) {
35
+ throw new Error('Method findIntegrations must be implemented by subclass');
36
+ }
37
+
24
38
  /**
25
39
  * Delete integration by ID
26
40
  *
@@ -53,6 +53,42 @@ class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
53
53
  }));
54
54
  }
55
55
 
56
+ /**
57
+ * Find integrations, optionally filtered by config type and/or status.
58
+ *
59
+ * @param {Object} [filter={}]
60
+ * @param {string} [filter.type] - Integration type (config.type)
61
+ * @param {string} [filter.status] - Integration status
62
+ * @returns {Promise<Array>} Array of integration objects (possibly empty)
63
+ */
64
+ async findIntegrations({ type, status } = {}) {
65
+ const where = {};
66
+ if (type) {
67
+ where.config = { path: ['type'], equals: type };
68
+ }
69
+ if (status) {
70
+ where.status = status;
71
+ }
72
+
73
+ const integrations = await this.prisma.integration.findMany({
74
+ where,
75
+ include: {
76
+ entities: true,
77
+ },
78
+ });
79
+
80
+ return integrations.map((integration) => ({
81
+ id: integration.id,
82
+ entitiesIds: integration.entities.map((e) => e.id),
83
+ userId: integration.userId,
84
+ config: integration.config,
85
+ version: integration.version,
86
+ status: integration.status,
87
+ messages: integration.messages,
88
+ createdAt: integration.createdAt,
89
+ }));
90
+ }
91
+
56
92
  /**
57
93
  * Delete integration by ID
58
94
  * Replaces: IntegrationModel.deleteOne({ _id: integrationId })
@@ -90,6 +90,45 @@ class IntegrationRepositoryPostgres extends IntegrationRepositoryInterface {
90
90
  });
91
91
  }
92
92
 
93
+ /**
94
+ * Find integrations, optionally filtered by config type and/or status.
95
+ *
96
+ * @param {Object} [filter={}]
97
+ * @param {string} [filter.type] - Integration type (config.type)
98
+ * @param {string} [filter.status] - Integration status
99
+ * @returns {Promise<Array>} Array of integration objects (possibly empty)
100
+ */
101
+ async findIntegrations({ type, status } = {}) {
102
+ const where = {};
103
+ if (type) {
104
+ where.config = { path: ['type'], equals: type };
105
+ }
106
+ if (status) {
107
+ where.status = status;
108
+ }
109
+
110
+ const integrations = await this.prisma.integration.findMany({
111
+ where,
112
+ include: {
113
+ entities: true,
114
+ },
115
+ });
116
+
117
+ return integrations.map((integration) => {
118
+ const converted = this._convertIntegrationIds(integration);
119
+ return {
120
+ id: converted.id,
121
+ entitiesIds: converted.entities.map((e) => e.id),
122
+ userId: converted.userId,
123
+ config: converted.config,
124
+ version: converted.version,
125
+ status: converted.status,
126
+ messages: converted.messages,
127
+ createdAt: converted.createdAt,
128
+ };
129
+ });
130
+ }
131
+
93
132
  /**
94
133
  * Delete integration by ID
95
134
  *
@@ -38,6 +38,17 @@ class TestIntegrationRepository {
38
38
  return results;
39
39
  }
40
40
 
41
+ async findIntegrations(filter = {}) {
42
+ const { type, status } = filter;
43
+ const results = Array.from(this.store.values()).filter((r) => {
44
+ if (type && r.config?.type !== type) return false;
45
+ if (status && r.status !== status) return false;
46
+ return true;
47
+ });
48
+ this.operationHistory.push({ operation: 'findAll', count: results.length });
49
+ return results;
50
+ }
51
+
41
52
  async findIntegrationByUserId(userId) {
42
53
  const record = Array.from(this.store.values()).find((r) => r.userId === userId);
43
54
  this.operationHistory.push({
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.517.f8e0cc1.0",
4
+ "version": "2.0.0--canary.517.44c158e.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -38,9 +38,9 @@
38
38
  }
39
39
  },
40
40
  "devDependencies": {
41
- "@friggframework/eslint-config": "2.0.0--canary.517.f8e0cc1.0",
42
- "@friggframework/prettier-config": "2.0.0--canary.517.f8e0cc1.0",
43
- "@friggframework/test": "2.0.0--canary.517.f8e0cc1.0",
41
+ "@friggframework/eslint-config": "2.0.0--canary.517.44c158e.0",
42
+ "@friggframework/prettier-config": "2.0.0--canary.517.44c158e.0",
43
+ "@friggframework/test": "2.0.0--canary.517.44c158e.0",
44
44
  "@prisma/client": "^6.19.3",
45
45
  "@types/lodash": "4.17.15",
46
46
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "f8e0cc122e1580a8fe61fa3fb9b2b9f39f461e61"
83
+ "gitHead": "44c158e7a3bbeaac4b410c1062b0ce209bffd7f0"
84
84
  }