@friggframework/core 2.0.0--canary.498.9192c35.0 → 2.0.0--canary.490.1c51d11.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.
Files changed (58) hide show
  1. package/core/create-handler.js +63 -12
  2. package/credential/repositories/credential-repository-mongo.js +10 -7
  3. package/database/PRISMA_BEST_PRACTICES.md +654 -0
  4. package/database/index.js +7 -29
  5. package/database/prisma.js +56 -19
  6. package/database/repositories/health-check-repository-mongodb.js +23 -23
  7. package/database/use-cases/test-encryption-use-case.js +2 -0
  8. package/database/utils/documentdb-compatibility.js +63 -0
  9. package/database/utils/mongodb-collection-utils.js +26 -18
  10. package/database/utils/mongodb-schema-init.js +7 -12
  11. package/database/utils/prisma-documentdb-wrapper.js +105 -0
  12. package/generated/prisma-mongodb/edge.js +6 -6
  13. package/generated/prisma-mongodb/index-browser.js +4 -4
  14. package/generated/prisma-mongodb/index.d.ts +3 -2
  15. package/generated/prisma-mongodb/index.js +6 -6
  16. package/generated/prisma-mongodb/package.json +1 -1
  17. package/generated/prisma-mongodb/query-engine-debian-openssl-3.0.x +0 -0
  18. package/generated/prisma-mongodb/query-engine-rhel-openssl-3.0.x +0 -0
  19. package/generated/prisma-mongodb/runtime/binary.js +2 -2
  20. package/generated/prisma-mongodb/runtime/edge-esm.js +3 -3
  21. package/generated/prisma-mongodb/runtime/edge.js +3 -3
  22. package/generated/prisma-mongodb/runtime/library.d.ts +5 -0
  23. package/generated/prisma-mongodb/runtime/react-native.js +14 -14
  24. package/generated/prisma-mongodb/runtime/wasm-compiler-edge.js +18 -18
  25. package/generated/prisma-mongodb/runtime/wasm-engine-edge.js +11 -11
  26. package/generated/prisma-mongodb/wasm.js +6 -6
  27. package/generated/prisma-postgresql/edge.js +6 -6
  28. package/generated/prisma-postgresql/index-browser.js +4 -4
  29. package/generated/prisma-postgresql/index.d.ts +3 -2
  30. package/generated/prisma-postgresql/index.js +6 -6
  31. package/generated/prisma-postgresql/package.json +1 -1
  32. package/generated/prisma-postgresql/query-engine-debian-openssl-3.0.x +0 -0
  33. package/generated/prisma-postgresql/query-engine-rhel-openssl-3.0.x +0 -0
  34. package/generated/prisma-postgresql/query_engine_bg.js +2 -2
  35. package/generated/prisma-postgresql/query_engine_bg.wasm +0 -0
  36. package/generated/prisma-postgresql/runtime/binary.js +2 -2
  37. package/generated/prisma-postgresql/runtime/edge-esm.js +3 -3
  38. package/generated/prisma-postgresql/runtime/edge.js +3 -3
  39. package/generated/prisma-postgresql/runtime/library.d.ts +5 -0
  40. package/generated/prisma-postgresql/runtime/react-native.js +14 -14
  41. package/generated/prisma-postgresql/runtime/wasm-compiler-edge.js +18 -18
  42. package/generated/prisma-postgresql/runtime/wasm-engine-edge.js +11 -11
  43. package/generated/prisma-postgresql/wasm.js +6 -6
  44. package/handlers/backend-utils.js +8 -9
  45. package/integrations/integration-base.js +1 -31
  46. package/integrations/integration-router.js +0 -1
  47. package/integrations/use-cases/delete-integration-for-user.js +3 -31
  48. package/integrations/use-cases/get-integrations-for-user.js +4 -5
  49. package/integrations/utils/map-integration-dto.js +1 -2
  50. package/modules/index.js +0 -2
  51. package/package.json +5 -5
  52. package/associations/model.js +0 -54
  53. package/database/models/UserModel.js +0 -7
  54. package/database/models/WebsocketConnection.js +0 -55
  55. package/database/repositories/health-check-repository.js +0 -108
  56. package/modules/entity.js +0 -46
  57. package/prisma-postgresql/migrations/20251107003337_add_process_table/migration.sql +0 -44
  58. package/syncs/model.js +0 -62
@@ -1,21 +1,76 @@
1
- // This line should be at the top of the webpacked output, so be sure to require createHandler first in any handlers. "Soon" sourcemaps will be built into Node... after that, this package won't be needed.
2
- // REMOVING FOR NOW UNTIL WE ADD WEBPACK BACK IN
3
- // require('source-map-support').install();
4
-
5
1
  const { initDebugLog, flushDebugLog } = require('../logs');
6
2
  const { secretsToEnv } = require('./secrets-to-env');
7
3
 
4
+ let databaseInitializer = null;
5
+ let databaseInitialized = false;
6
+ let databaseInitPromise = null;
7
+
8
+ function setDatabaseInitializer(initializer) {
9
+ databaseInitializer = initializer;
10
+ }
11
+
12
+ function getDefaultDatabaseInitializer() {
13
+ if (!databaseInitializer) {
14
+ const { connectPrisma } = require('../database/prisma');
15
+ databaseInitializer = connectPrisma;
16
+ }
17
+ return databaseInitializer;
18
+ }
19
+
20
+ async function ensureDatabaseInitialized() {
21
+ if (databaseInitialized) {
22
+ return;
23
+ }
24
+
25
+ if (!databaseInitPromise) {
26
+ databaseInitPromise = (async () => {
27
+ try {
28
+ const initializer = getDefaultDatabaseInitializer();
29
+ await initializer();
30
+ databaseInitialized = true;
31
+ console.log('✓ Database initialized successfully');
32
+ } catch (error) {
33
+ console.error('Failed to initialize database:', error.message);
34
+ databaseInitPromise = null;
35
+ throw error;
36
+ }
37
+ })();
38
+ }
39
+
40
+ return databaseInitPromise;
41
+ }
42
+
43
+ /**
44
+ * Creates a Lambda handler with database initialization.
45
+ *
46
+ * Follows hexagonal architecture: database initialization is a port that can be injected.
47
+ * Default adapter uses Prisma's connectPrisma(), which handles both PostgreSQL and MongoDB.
48
+ *
49
+ * @param {Object} options
50
+ * @param {string} options.eventName - Event name for logging
51
+ * @param {boolean} options.isUserFacingResponse - Whether to hide error details (default: true)
52
+ * @param {Function} options.method - The handler method to execute
53
+ * @param {boolean} options.shouldUseDatabase - Whether to initialize database (default: true)
54
+ * @param {Function} options.databaseInitializer - Optional custom database initializer
55
+ * @returns {Function} Lambda handler
56
+ */
8
57
  const createHandler = (optionByName = {}) => {
9
58
  const {
10
59
  eventName = 'Event',
11
60
  isUserFacingResponse = true,
12
61
  method,
62
+ shouldUseDatabase = true,
63
+ databaseInitializer: customInitializer = null,
13
64
  } = optionByName;
14
65
 
15
66
  if (!method) {
16
67
  throw new Error('Method is required for handler.');
17
68
  }
18
69
 
70
+ if (customInitializer) {
71
+ setDatabaseInitializer(customInitializer);
72
+ }
73
+
19
74
  return async (event, context) => {
20
75
  try {
21
76
  initDebugLog(eventName, event);
@@ -26,18 +81,18 @@ const createHandler = (optionByName = {}) => {
26
81
  console.info(`${requestMethod} ${requestPath}`);
27
82
  }
28
83
 
29
- // If enabled (i.e. if SECRET_ARN is set in process.env) Fetch secrets from AWS Secrets Manager, and set them as environment variables.
30
84
  await secretsToEnv();
31
85
 
32
- // Helps mongoose reuse the connection. Lowers response times.
86
+ if (shouldUseDatabase) {
87
+ await ensureDatabaseInitialized();
88
+ }
89
+
33
90
  context.callbackWaitsForEmptyEventLoop = false;
34
91
 
35
- // Run the Lambda
36
92
  return await method(event, context);
37
93
  } catch (error) {
38
94
  flushDebugLog(error);
39
95
 
40
- // Don't leak implementation details to end users.
41
96
  if (isUserFacingResponse) {
42
97
  return {
43
98
  statusCode: 500,
@@ -47,14 +102,10 @@ const createHandler = (optionByName = {}) => {
47
102
  };
48
103
  }
49
104
 
50
- // Handle server-to-server responses.
51
-
52
- // Halt errors are logged but suceed and won't be retried.
53
105
  if (error.isHaltError === true) {
54
106
  return;
55
107
  }
56
108
 
57
- // Here we can just rethrow and let AWS build the response.
58
109
  throw error;
59
110
  }
60
111
  };
@@ -2,6 +2,7 @@ const { prisma } = require('../../database/prisma');
2
2
  const {
3
3
  CredentialRepositoryInterface,
4
4
  } = require('./credential-repository-interface');
5
+ const { removeUndefinedValues } = require('../../database/utils/documentdb-compatibility');
5
6
 
6
7
  /**
7
8
  * MongoDB Credential Repository Adapter
@@ -156,14 +157,16 @@ class CredentialRepositoryMongo extends CredentialRepositoryInterface {
156
157
  }
157
158
 
158
159
  // Create new credential
160
+ // Remove undefined values to prevent Prisma from using $$REMOVE (DocumentDB unsupported)
161
+ const credentialData = removeUndefinedValues({
162
+ userId: userId || user,
163
+ externalId,
164
+ authIsValid: authIsValid,
165
+ data: oauthData,
166
+ });
167
+
159
168
  const created = await this.prisma.credential.create({
160
- data: {
161
- userId: userId || user,
162
- externalId,
163
- authIsValid: authIsValid,
164
-
165
- data: oauthData,
166
- },
169
+ data: credentialData,
167
170
  });
168
171
 
169
172
  return {