@friggframework/core 2.0.0--canary.548.c8ae0ca.0 → 2.0.0--canary.545.c40eca4.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 (237) hide show
  1. package/CHANGELOG.md +66 -67
  2. package/CLAUDE.md +148 -124
  3. package/README.md +165 -130
  4. package/admin-scripts/index.js +52 -0
  5. package/admin-scripts/repositories/admin-api-key-repository-documentdb.js +21 -0
  6. package/admin-scripts/repositories/admin-api-key-repository-factory.js +51 -0
  7. package/admin-scripts/repositories/admin-api-key-repository-interface.js +121 -0
  8. package/admin-scripts/repositories/admin-api-key-repository-mongo.js +155 -0
  9. package/admin-scripts/repositories/admin-api-key-repository-postgres.js +189 -0
  10. package/admin-scripts/repositories/admin-process-repository-documentdb.js +21 -0
  11. package/admin-scripts/repositories/admin-process-repository-factory.js +49 -0
  12. package/admin-scripts/repositories/admin-process-repository-interface.js +150 -0
  13. package/admin-scripts/repositories/admin-process-repository-mongo.js +213 -0
  14. package/admin-scripts/repositories/admin-process-repository-postgres.js +251 -0
  15. package/admin-scripts/repositories/script-execution-repository-documentdb.js +21 -0
  16. package/admin-scripts/repositories/script-execution-repository-factory.js +51 -0
  17. package/admin-scripts/repositories/script-execution-repository-interface.js +193 -0
  18. package/admin-scripts/repositories/script-execution-repository-mongo.js +278 -0
  19. package/admin-scripts/repositories/script-execution-repository-postgres.js +320 -0
  20. package/admin-scripts/repositories/script-schedule-repository-documentdb.js +21 -0
  21. package/admin-scripts/repositories/script-schedule-repository-factory.js +49 -0
  22. package/admin-scripts/repositories/script-schedule-repository-interface.js +108 -0
  23. package/admin-scripts/repositories/script-schedule-repository-mongo.js +179 -0
  24. package/admin-scripts/repositories/script-schedule-repository-postgres.js +210 -0
  25. package/application/commands/admin-script-commands.js +348 -0
  26. package/application/commands/integration-commands.js +12 -6
  27. package/application/index.js +5 -3
  28. package/assertions/get.js +17 -7
  29. package/associations/association.js +59 -57
  30. package/core/CLAUDE.md +222 -156
  31. package/core/Worker.js +33 -12
  32. package/credential/credential-router.js +262 -0
  33. package/credential/repositories/credential-repository-documentdb.js +71 -1
  34. package/credential/repositories/credential-repository-factory.js +4 -6
  35. package/credential/repositories/credential-repository-interface.js +8 -2
  36. package/credential/repositories/credential-repository-mongo.js +45 -4
  37. package/credential/repositories/credential-repository-postgres.js +44 -3
  38. package/credential/repositories/credential-repository.js +3 -1
  39. package/credential/use-cases/delete-credential-for-user.js +50 -0
  40. package/credential/use-cases/get-credential-for-user.js +21 -3
  41. package/credential/use-cases/list-credentials-for-user.js +31 -0
  42. package/credential/use-cases/reauthorize-credential.js +103 -0
  43. package/credential/use-cases/update-authentication-status.js +5 -2
  44. package/database/MONGODB_TRANSACTION_FIX.md +72 -52
  45. package/database/config.js +13 -59
  46. package/database/documentdb-encryption-service.js +29 -13
  47. package/database/documentdb-utils.js +21 -12
  48. package/database/encryption/README.md +53 -36
  49. package/database/encryption/encryption-schema-registry.js +29 -23
  50. package/database/encryption/field-encryption-service.js +15 -4
  51. package/database/encryption/logger.js +3 -2
  52. package/database/encryption/prisma-encryption-extension.js +5 -8
  53. package/database/prisma.js +22 -14
  54. package/database/repositories/health-check-repository-factory.js +7 -5
  55. package/database/repositories/health-check-repository-interface.js +15 -5
  56. package/database/repositories/health-check-repository-postgres.js +1 -1
  57. package/database/use-cases/check-database-health-use-case.js +3 -2
  58. package/database/use-cases/check-database-state-use-case.js +8 -7
  59. package/database/use-cases/get-database-state-via-worker-use-case.js +15 -12
  60. package/database/use-cases/get-migration-status-use-case.js +4 -2
  61. package/database/use-cases/run-database-migration-use-case.js +41 -9
  62. package/database/use-cases/test-encryption-use-case.js +4 -5
  63. package/database/use-cases/trigger-database-migration-use-case.js +9 -8
  64. package/database/utils/mongodb-collection-utils.js +11 -3
  65. package/database/utils/mongodb-schema-init.js +10 -4
  66. package/database/utils/prisma-runner.js +144 -74
  67. package/database/utils/prisma-schema-parser.js +2 -2
  68. package/docs/PROCESS_MANAGEMENT_QUEUE_SPEC.md +135 -80
  69. package/encrypt/Cryptor.js +54 -49
  70. package/encrypt/aes-encryption-key-provider.js +82 -0
  71. package/encrypt/encryption-key-provider-interface.js +50 -0
  72. package/errors/fetch-error.js +1 -1
  73. package/generated/prisma-mongodb/edge.js +59 -4
  74. package/generated/prisma-mongodb/index-browser.js +49 -1
  75. package/generated/prisma-mongodb/index.d.ts +4023 -61
  76. package/generated/prisma-mongodb/index.js +59 -4
  77. package/generated/prisma-mongodb/package.json +1 -1
  78. package/generated/prisma-mongodb/schema.prisma +87 -0
  79. package/generated/prisma-mongodb/wasm.js +59 -4
  80. package/generated/prisma-postgresql/edge.js +58 -4
  81. package/generated/prisma-postgresql/index-browser.js +48 -1
  82. package/generated/prisma-postgresql/index.d.ts +4738 -54
  83. package/generated/prisma-postgresql/index.js +58 -4
  84. package/generated/prisma-postgresql/package.json +1 -1
  85. package/generated/prisma-postgresql/schema.prisma +85 -0
  86. package/generated/prisma-postgresql/wasm.js +58 -4
  87. package/handlers/WEBHOOKS.md +104 -81
  88. package/handlers/app-definition-loader.js +53 -10
  89. package/handlers/app-handler-helpers.js +14 -3
  90. package/handlers/backend-utils.js +0 -1
  91. package/handlers/database-migration-handler.js +64 -45
  92. package/handlers/middleware/admin-auth.js +53 -0
  93. package/handlers/routers/HEALTHCHECK.md +170 -135
  94. package/handlers/routers/admin.js +474 -0
  95. package/handlers/routers/auth.js +51 -9
  96. package/handlers/routers/db-migration.handler.js +2 -3
  97. package/handlers/routers/db-migration.js +102 -66
  98. package/handlers/routers/docs.js +180 -0
  99. package/handlers/routers/health.js +84 -283
  100. package/handlers/routers/integration-defined-routers.js +44 -33
  101. package/handlers/routers/integration-webhook-routers.js +73 -52
  102. package/handlers/routers/middleware/loadUser.js +39 -0
  103. package/handlers/routers/middleware/requireAdmin.js +43 -0
  104. package/handlers/routers/middleware/requireLoggedInUser.js +19 -0
  105. package/handlers/routers/user.js +30 -14
  106. package/handlers/routers/websocket.js +18 -4
  107. package/handlers/use-cases/check-integrations-health-use-case.js +13 -6
  108. package/handlers/workers/db-migration.js +74 -35
  109. package/handlers/workers/integration-defined-workers.js +31 -20
  110. package/index.js +50 -16
  111. package/infrastructure/scheduler/index.js +15 -11
  112. package/infrastructure/scheduler/netlify-scheduler-adapter.js +185 -0
  113. package/infrastructure/scheduler/scheduler-service-factory.js +38 -31
  114. package/integrations/WEBHOOK-QUICKSTART.md +21 -14
  115. package/integrations/index.js +4 -0
  116. package/integrations/integration-base.js +9 -6
  117. package/integrations/integration-router.js +1828 -157
  118. package/integrations/options.js +47 -20
  119. package/integrations/repositories/integration-mapping-repository-factory.js +4 -8
  120. package/integrations/repositories/integration-repository-documentdb.js +53 -24
  121. package/integrations/repositories/integration-repository-factory.js +6 -6
  122. package/integrations/repositories/integration-repository-interface.js +27 -9
  123. package/integrations/repositories/integration-repository-postgres.js +3 -3
  124. package/integrations/repositories/process-repository-factory.js +4 -7
  125. package/integrations/repositories/process-repository-interface.js +9 -5
  126. package/integrations/repositories/process-repository-mongo.js +7 -3
  127. package/integrations/repositories/process-repository-postgres.js +2 -2
  128. package/integrations/tests/doubles/config-capturing-integration.js +9 -8
  129. package/integrations/tests/doubles/dummy-integration-class.js +81 -8
  130. package/integrations/tests/doubles/test-integration-repository.js +51 -11
  131. package/integrations/use-cases/create-integration.js +36 -32
  132. package/integrations/use-cases/create-process.js +20 -9
  133. package/integrations/use-cases/delete-integration-for-user.js +5 -4
  134. package/integrations/use-cases/execute-proxy-request.js +564 -0
  135. package/integrations/use-cases/get-integration-for-user.js +25 -10
  136. package/integrations/use-cases/get-integration-instance-by-definition.js +13 -7
  137. package/integrations/use-cases/get-integrations-for-user.js +4 -1
  138. package/integrations/use-cases/get-possible-integrations.js +1 -1
  139. package/integrations/use-cases/get-process.js +5 -6
  140. package/integrations/use-cases/index.js +3 -1
  141. package/integrations/use-cases/load-integration-context.js +1 -5
  142. package/integrations/use-cases/update-process-state.js +10 -8
  143. package/integrations/utils/map-integration-dto.js +9 -3
  144. package/jest-setup.js +1 -1
  145. package/jest-teardown.js +1 -1
  146. package/lambda/TimeoutCatcher.js +32 -30
  147. package/lambda/index.js +1 -1
  148. package/logs/index.js +3 -3
  149. package/modules/domain/entities/AuthorizationSession.js +131 -0
  150. package/modules/domain/entities/index.js +10 -0
  151. package/modules/module.js +4 -9
  152. package/modules/repositories/authorization-session-repository-factory.js +53 -0
  153. package/modules/repositories/authorization-session-repository-interface.js +75 -0
  154. package/modules/repositories/authorization-session-repository-mongo.js +169 -0
  155. package/modules/repositories/authorization-session-repository-postgres.js +170 -0
  156. package/modules/repositories/module-repository-documentdb.js +89 -41
  157. package/modules/repositories/module-repository-factory.js +4 -6
  158. package/modules/repositories/module-repository-interface.js +13 -0
  159. package/modules/repositories/module-repository-mongo.js +40 -5
  160. package/modules/repositories/module-repository-postgres.js +42 -5
  161. package/modules/repositories/module-repository.js +28 -0
  162. package/modules/requester/api-key.js +0 -2
  163. package/modules/requester/basic.js +0 -1
  164. package/modules/requester/oauth-2.js +3 -14
  165. package/modules/test/mock-api/definition.js +15 -10
  166. package/modules/test/mock-api/mocks/hubspot.js +36 -36
  167. package/modules/tests/doubles/test-module-factory.js +10 -4
  168. package/modules/tests/doubles/test-module-repository.js +1 -1
  169. package/modules/use-cases/delete-module-entity.js +23 -0
  170. package/modules/use-cases/get-authorization-requirements.js +110 -0
  171. package/modules/use-cases/get-entities-for-user.js +1 -1
  172. package/modules/use-cases/get-entity-options-by-id.js +8 -6
  173. package/modules/use-cases/get-module-entity-by-id.js +16 -0
  174. package/modules/use-cases/get-module.js +12 -9
  175. package/modules/use-cases/process-authorization-callback.js +12 -6
  176. package/modules/use-cases/process-authorization-step.js +160 -0
  177. package/modules/use-cases/refresh-entity-options.js +8 -6
  178. package/modules/use-cases/start-authorization-session.js +86 -0
  179. package/modules/use-cases/test-module-auth.js +8 -6
  180. package/modules/use-cases/update-module-entity.js +27 -0
  181. package/modules/utils/map-module-dto.js +2 -2
  182. package/openapi/openapi-spec-generator.js +370 -0
  183. package/openapi/openapi-v1.yaml +1360 -0
  184. package/openapi/openapi-v2.yaml +1535 -0
  185. package/package.json +7 -9
  186. package/prisma-mongodb/schema.prisma +87 -0
  187. package/prisma-postgresql/migrations/20260222000000_add_admin_process_and_script_schedule/migration.sql +55 -0
  188. package/prisma-postgresql/schema.prisma +85 -0
  189. package/providers/index.js +13 -0
  190. package/providers/resolve-provider.js +93 -0
  191. package/queues/index.js +19 -0
  192. package/queues/providers/index.js +7 -0
  193. package/queues/providers/netlify-background-provider.js +76 -0
  194. package/queues/providers/qstash-queue-provider.js +122 -0
  195. package/queues/queue-client-interface.js +55 -0
  196. package/queues/queue-provider-factory.js +93 -0
  197. package/queues/queue-provider.js +46 -0
  198. package/queues/queuer-util.js +33 -25
  199. package/syncs/repositories/sync-repository-documentdb.js +39 -19
  200. package/syncs/repositories/sync-repository-factory.js +4 -4
  201. package/syncs/repositories/sync-repository-interface.js +6 -2
  202. package/syncs/repositories/sync-repository-postgres.js +19 -13
  203. package/syncs/sync.js +104 -100
  204. package/token/repositories/token-repository-factory.js +4 -6
  205. package/types/assertions/index.d.ts +72 -72
  206. package/types/core/index.d.ts +98 -53
  207. package/types/errors/index.d.ts +61 -54
  208. package/types/eslint-config/index.d.ts +40 -40
  209. package/types/lambda/index.d.ts +26 -26
  210. package/types/logs/index.d.ts +4 -4
  211. package/types/prettier-config/index.d.ts +5 -5
  212. package/types/test-environment/index.d.ts +14 -14
  213. package/types/tsconfig.json +95 -93
  214. package/user/repositories/user-repository-factory.js +4 -4
  215. package/user/tests/doubles/test-user-repository.js +5 -2
  216. package/user/use-cases/authenticate-user.js +2 -4
  217. package/user/use-cases/authenticate-with-shared-secret.js +1 -1
  218. package/user/use-cases/create-individual-user.js +8 -7
  219. package/user/use-cases/create-organization-user.js +1 -1
  220. package/user/use-cases/create-token-for-user-id.js +1 -1
  221. package/user/use-cases/delete-user.js +47 -0
  222. package/user/use-cases/get-user-from-adopter-jwt.js +0 -2
  223. package/user/use-cases/get-user-from-bearer-token.js +7 -3
  224. package/user/use-cases/get-user-from-x-frigg-headers.js +14 -11
  225. package/user/use-cases/login-user.js +8 -8
  226. package/user/user.js +18 -4
  227. package/utils/backend-path.js +2 -2
  228. package/utils/index.js +4 -1
  229. package/websocket/repositories/websocket-connection-repository-documentdb.js +46 -21
  230. package/websocket/repositories/websocket-connection-repository-factory.js +4 -8
  231. package/websocket/repositories/websocket-connection-repository-mongo.js +26 -16
  232. package/websocket/repositories/websocket-connection-repository-postgres.js +26 -15
  233. package/websocket/repositories/websocket-connection-repository.js +26 -20
  234. package/websocket/websocket-message-sender-interface.js +38 -0
  235. package/database/adapters/lambda-invoker.js +0 -97
  236. package/database/repositories/migration-status-repository-s3.js +0 -137
  237. package/infrastructure/scheduler/eventbridge-scheduler-adapter.js +0 -184
@@ -30,8 +30,23 @@ function getPrismaSchemaPath(dbType, projectRoot = process.cwd()) {
30
30
  // Lambda layer path - this is where the schema actually exists in deployed Lambda
31
31
  `/opt/nodejs/node_modules/generated/prisma-${normalizedType}/schema.prisma`,
32
32
  // Check where Frigg is installed via npm (production scenario)
33
- path.join(projectRoot, 'node_modules', '@friggframework', 'core', `prisma-${normalizedType}`, 'schema.prisma'),
34
- path.join(projectRoot, '..', 'node_modules', '@friggframework', 'core', `prisma-${normalizedType}`, 'schema.prisma')
33
+ path.join(
34
+ projectRoot,
35
+ 'node_modules',
36
+ '@friggframework',
37
+ 'core',
38
+ `prisma-${normalizedType}`,
39
+ 'schema.prisma'
40
+ ),
41
+ path.join(
42
+ projectRoot,
43
+ '..',
44
+ 'node_modules',
45
+ '@friggframework',
46
+ 'core',
47
+ `prisma-${normalizedType}`,
48
+ 'schema.prisma'
49
+ ),
35
50
  ];
36
51
 
37
52
  for (const schemaPath of possiblePaths) {
@@ -43,7 +58,7 @@ function getPrismaSchemaPath(dbType, projectRoot = process.cwd()) {
43
58
  // If not found in any location, throw error
44
59
  throw new Error(
45
60
  `Prisma schema not found at:\n${possiblePaths.join('\n')}\n\n` +
46
- 'Ensure @friggframework/core is installed.'
61
+ 'Ensure @friggframework/core is installed.'
47
62
  );
48
63
  }
49
64
 
@@ -59,57 +74,76 @@ async function runPrismaGenerate(dbType, verbose = false) {
59
74
 
60
75
  // Check if Prisma client already exists (e.g., in Lambda or pre-generated)
61
76
  const normalizedType = normalizeMongoCompatible(dbType);
62
- const generatedClientPath = path.join(path.dirname(path.dirname(schemaPath)), 'generated', `prisma-${normalizedType}`, 'client.js');
63
- const isLambdaEnvironment = !!process.env.AWS_LAMBDA_FUNCTION_NAME || !!process.env.LAMBDA_TASK_ROOT;
77
+ const generatedClientPath = path.join(
78
+ path.dirname(path.dirname(schemaPath)),
79
+ 'generated',
80
+ `prisma-${normalizedType}`,
81
+ 'client.js'
82
+ );
83
+ const isLambdaEnvironment =
84
+ !!process.env.AWS_LAMBDA_FUNCTION_NAME ||
85
+ !!process.env.LAMBDA_TASK_ROOT;
64
86
 
65
87
  // In Lambda, also check the layer path (/opt/nodejs/node_modules)
66
88
  const lambdaLayerClientPath = `/opt/nodejs/node_modules/generated/prisma-${normalizedType}/client.js`;
67
89
 
68
- const clientExists = fs.existsSync(generatedClientPath) || (isLambdaEnvironment && fs.existsSync(lambdaLayerClientPath));
90
+ const clientExists =
91
+ fs.existsSync(generatedClientPath) ||
92
+ (isLambdaEnvironment && fs.existsSync(lambdaLayerClientPath));
69
93
 
70
94
  if (clientExists) {
71
- const foundPath = fs.existsSync(generatedClientPath) ? generatedClientPath : lambdaLayerClientPath;
95
+ const foundPath = fs.existsSync(generatedClientPath)
96
+ ? generatedClientPath
97
+ : lambdaLayerClientPath;
72
98
  if (verbose) {
73
- console.log(chalk.gray(`✓ Prisma client already generated at: ${foundPath}`));
99
+ console.log(
100
+ chalk.gray(
101
+ `✓ Prisma client already generated at: ${foundPath}`
102
+ )
103
+ );
74
104
  }
75
105
  if (isLambdaEnvironment) {
76
106
  if (verbose) {
77
- console.log(chalk.gray('Skipping generation in Lambda environment (using pre-generated client)'));
107
+ console.log(
108
+ chalk.gray(
109
+ 'Skipping generation in Lambda environment (using pre-generated client)'
110
+ )
111
+ );
78
112
  }
79
113
  return {
80
114
  success: true,
81
- output: 'Using pre-generated Prisma client (Lambda environment)'
115
+ output: 'Using pre-generated Prisma client (Lambda environment)',
82
116
  };
83
117
  }
84
118
  }
85
119
 
86
120
  if (verbose) {
87
- console.log(chalk.gray(`Running: npx prisma generate --schema=${schemaPath}`));
121
+ console.log(
122
+ chalk.gray(
123
+ `Running: npx prisma generate --schema=${schemaPath}`
124
+ )
125
+ );
88
126
  }
89
127
 
90
- const output = execSync(
91
- `npx prisma generate --schema=${schemaPath}`,
92
- {
93
- encoding: 'utf8',
94
- stdio: verbose ? 'inherit' : 'pipe',
95
- env: {
96
- ...process.env,
97
- // Suppress Prisma telemetry prompts
98
- PRISMA_HIDE_UPDATE_MESSAGE: '1'
99
- }
100
- }
101
- );
128
+ const output = execSync(`npx prisma generate --schema=${schemaPath}`, {
129
+ encoding: 'utf8',
130
+ stdio: verbose ? 'inherit' : 'pipe',
131
+ env: {
132
+ ...process.env,
133
+ // Suppress Prisma telemetry prompts
134
+ PRISMA_HIDE_UPDATE_MESSAGE: '1',
135
+ },
136
+ });
102
137
 
103
138
  return {
104
139
  success: true,
105
- output: verbose ? 'Generated successfully' : output
140
+ output: verbose ? 'Generated successfully' : output,
106
141
  };
107
-
108
142
  } catch (error) {
109
143
  return {
110
144
  success: false,
111
145
  error: error.message,
112
- output: error.stdout?.toString() || error.stderr?.toString()
146
+ output: error.stdout?.toString() || error.stderr?.toString(),
113
147
  };
114
148
  }
115
149
  }
@@ -135,17 +169,14 @@ async function checkDatabaseState(dbType) {
135
169
  ? `${prismaBin} migrate status --schema=${schemaPath}`
136
170
  : `npx prisma migrate status --schema=${schemaPath}`;
137
171
 
138
- const output = execSync(
139
- command,
140
- {
141
- encoding: 'utf8',
142
- stdio: 'pipe',
143
- env: {
144
- ...process.env,
145
- PRISMA_HIDE_UPDATE_MESSAGE: '1'
146
- }
147
- }
148
- );
172
+ const output = execSync(command, {
173
+ encoding: 'utf8',
174
+ stdio: 'pipe',
175
+ env: {
176
+ ...process.env,
177
+ PRISMA_HIDE_UPDATE_MESSAGE: '1',
178
+ },
179
+ });
149
180
 
150
181
  if (output.includes('Database schema is up to date')) {
151
182
  return { upToDate: true };
@@ -157,26 +188,25 @@ async function checkDatabaseState(dbType) {
157
188
 
158
189
  return {
159
190
  upToDate: false,
160
- pendingMigrations
191
+ pendingMigrations,
161
192
  };
162
-
163
193
  } catch (error) {
164
194
  // If migrate status fails, database might not be initialized
165
195
  return {
166
196
  upToDate: false,
167
- error: error.message
197
+ error: error.message,
168
198
  };
169
199
  }
170
200
  }
171
201
 
172
202
  /**
173
203
  * Gets the path to the Prisma CLI entry point
174
- *
204
+ *
175
205
  * IMPORTANT: We invoke prisma/build/index.js directly instead of .bin/prisma
176
206
  * because .bin/prisma uses __dirname to find WASM files, and when the symlink
177
207
  * is resolved during Lambda packaging, __dirname points to .bin/ instead of
178
208
  * prisma/build/, causing WASM files to not be found.
179
- *
209
+ *
180
210
  * @returns {string} Command to run Prisma CLI (e.g., 'node /path/to/index.js' or 'npx prisma')
181
211
  */
182
212
  function getPrismaBinaryPath() {
@@ -195,7 +225,13 @@ function getPrismaBinaryPath() {
195
225
  }
196
226
 
197
227
  // Check local node_modules - use actual CLI location
198
- const localPrisma = path.join(process.cwd(), 'node_modules', 'prisma', 'build', 'index.js');
228
+ const localPrisma = path.join(
229
+ process.cwd(),
230
+ 'node_modules',
231
+ 'prisma',
232
+ 'build',
233
+ 'index.js'
234
+ );
199
235
  if (fs.existsSync(localPrisma)) {
200
236
  return `node ${localPrisma}`;
201
237
  }
@@ -216,7 +252,9 @@ async function runPrismaMigrate(command = 'dev', verbose = false) {
216
252
  const schemaPath = getPrismaSchemaPath('postgresql');
217
253
 
218
254
  // Get Prisma binary path (checks multiple locations)
219
- const isLambdaEnvironment = !!process.env.AWS_LAMBDA_FUNCTION_NAME || !!process.env.LAMBDA_TASK_ROOT;
255
+ const isLambdaEnvironment =
256
+ !!process.env.AWS_LAMBDA_FUNCTION_NAME ||
257
+ !!process.env.LAMBDA_TASK_ROOT;
220
258
  const prismaBin = getPrismaBinaryPath();
221
259
 
222
260
  // Determine args based on whether we're using direct binary or npx
@@ -242,14 +280,14 @@ async function runPrismaMigrate(command = 'dev', verbose = false) {
242
280
  stdio: 'inherit',
243
281
  env: {
244
282
  ...process.env,
245
- PRISMA_HIDE_UPDATE_MESSAGE: '1'
246
- }
283
+ PRISMA_HIDE_UPDATE_MESSAGE: '1',
284
+ },
247
285
  });
248
286
 
249
287
  proc.on('error', (error) => {
250
288
  resolve({
251
289
  success: false,
252
- error: error.message
290
+ error: error.message,
253
291
  });
254
292
  });
255
293
 
@@ -257,20 +295,19 @@ async function runPrismaMigrate(command = 'dev', verbose = false) {
257
295
  if (code === 0) {
258
296
  resolve({
259
297
  success: true,
260
- output: 'Migration completed successfully'
298
+ output: 'Migration completed successfully',
261
299
  });
262
300
  } else {
263
301
  resolve({
264
302
  success: false,
265
- error: `Migration process exited with code ${code}`
303
+ error: `Migration process exited with code ${code}`,
266
304
  });
267
305
  }
268
306
  });
269
-
270
307
  } catch (error) {
271
308
  resolve({
272
309
  success: false,
273
- error: error.message
310
+ error: error.message,
274
311
  });
275
312
  }
276
313
  });
@@ -293,7 +330,7 @@ async function runPrismaDbPush(verbose = false, nonInteractive = false) {
293
330
  'push',
294
331
  '--schema',
295
332
  schemaPath,
296
- '--skip-generate' // We generate separately
333
+ '--skip-generate', // We generate separately
297
334
  ];
298
335
 
299
336
  // Add non-interactive flag for Lambda/CI environments
@@ -306,17 +343,25 @@ async function runPrismaDbPush(verbose = false, nonInteractive = false) {
306
343
  }
307
344
 
308
345
  if (nonInteractive) {
309
- console.log(chalk.yellow('⚠️ Non-interactive mode: Data loss will be automatically accepted'));
346
+ console.log(
347
+ chalk.yellow(
348
+ '⚠️ Non-interactive mode: Data loss will be automatically accepted'
349
+ )
350
+ );
310
351
  } else {
311
- console.log(chalk.yellow('⚠️ Interactive mode: You may be prompted if schema changes cause data loss'));
352
+ console.log(
353
+ chalk.yellow(
354
+ '⚠️ Interactive mode: You may be prompted if schema changes cause data loss'
355
+ )
356
+ );
312
357
  }
313
358
 
314
359
  const proc = spawn('npx', args, {
315
360
  stdio: nonInteractive ? 'pipe' : 'inherit', // Use pipe for non-interactive to capture output
316
361
  env: {
317
362
  ...process.env,
318
- PRISMA_HIDE_UPDATE_MESSAGE: '1'
319
- }
363
+ PRISMA_HIDE_UPDATE_MESSAGE: '1',
364
+ },
320
365
  });
321
366
 
322
367
  let stdout = '';
@@ -345,7 +390,7 @@ async function runPrismaDbPush(verbose = false, nonInteractive = false) {
345
390
  proc.on('error', (error) => {
346
391
  resolve({
347
392
  success: false,
348
- error: error.message
393
+ error: error.message,
349
394
  });
350
395
  });
351
396
 
@@ -353,21 +398,22 @@ async function runPrismaDbPush(verbose = false, nonInteractive = false) {
353
398
  if (code === 0) {
354
399
  resolve({
355
400
  success: true,
356
- output: nonInteractive ? stdout || 'Database push completed successfully' : 'Database push completed successfully'
401
+ output: nonInteractive
402
+ ? stdout || 'Database push completed successfully'
403
+ : 'Database push completed successfully',
357
404
  });
358
405
  } else {
359
406
  resolve({
360
407
  success: false,
361
408
  error: `Database push process exited with code ${code}`,
362
- output: stderr || stdout
409
+ output: stderr || stdout,
363
410
  });
364
411
  }
365
412
  });
366
-
367
413
  } catch (error) {
368
414
  resolve({
369
415
  success: false,
370
- error: error.message
416
+ error: error.message,
371
417
  });
372
418
  }
373
419
  });
@@ -380,7 +426,11 @@ async function runPrismaDbPush(verbose = false, nonInteractive = false) {
380
426
  * @param {boolean} verbose - Enable verbose output
381
427
  * @returns {Promise<Object>} { success: boolean, output?: string, error?: string }
382
428
  */
383
- async function runPrismaMigrateResolve(migrationName, action = 'applied', verbose = false) {
429
+ async function runPrismaMigrateResolve(
430
+ migrationName,
431
+ action = 'applied',
432
+ verbose = false
433
+ ) {
384
434
  return new Promise((resolve) => {
385
435
  try {
386
436
  const schemaPath = getPrismaSchemaPath('postgresql');
@@ -391,8 +441,23 @@ async function runPrismaMigrateResolve(migrationName, action = 'applied', verbos
391
441
  // Determine args based on whether we're using direct binary or npx
392
442
  const isDirectBinary = prismaBin !== 'npx prisma';
393
443
  const args = isDirectBinary
394
- ? ['migrate', 'resolve', `--${action}`, migrationName, '--schema', schemaPath]
395
- : ['prisma', 'migrate', 'resolve', `--${action}`, migrationName, '--schema', schemaPath];
444
+ ? [
445
+ 'migrate',
446
+ 'resolve',
447
+ `--${action}`,
448
+ migrationName,
449
+ '--schema',
450
+ schemaPath,
451
+ ]
452
+ : [
453
+ 'prisma',
454
+ 'migrate',
455
+ 'resolve',
456
+ `--${action}`,
457
+ migrationName,
458
+ '--schema',
459
+ schemaPath,
460
+ ];
396
461
 
397
462
  if (verbose) {
398
463
  const displayCmd = isDirectBinary
@@ -409,14 +474,14 @@ async function runPrismaMigrateResolve(migrationName, action = 'applied', verbos
409
474
  stdio: 'inherit',
410
475
  env: {
411
476
  ...process.env,
412
- PRISMA_HIDE_UPDATE_MESSAGE: '1'
413
- }
477
+ PRISMA_HIDE_UPDATE_MESSAGE: '1',
478
+ },
414
479
  });
415
480
 
416
481
  proc.on('error', (error) => {
417
482
  resolve({
418
483
  success: false,
419
- error: error.message
484
+ error: error.message,
420
485
  });
421
486
  });
422
487
 
@@ -424,20 +489,19 @@ async function runPrismaMigrateResolve(migrationName, action = 'applied', verbos
424
489
  if (code === 0) {
425
490
  resolve({
426
491
  success: true,
427
- output: `Migration ${migrationName} marked as ${action}`
492
+ output: `Migration ${migrationName} marked as ${action}`,
428
493
  });
429
494
  } else {
430
495
  resolve({
431
496
  success: false,
432
- error: `Resolve process exited with code ${code}`
497
+ error: `Resolve process exited with code ${code}`,
433
498
  });
434
499
  }
435
500
  });
436
-
437
501
  } catch (error) {
438
502
  resolve({
439
503
  success: false,
440
- error: error.message
504
+ error: error.message,
441
505
  });
442
506
  }
443
507
  });
@@ -450,12 +514,18 @@ async function runPrismaMigrateResolve(migrationName, action = 'applied', verbos
450
514
  */
451
515
  function getMigrationCommand(stage) {
452
516
  // Always use 'deploy' in Lambda environment (it's non-interactive and doesn't create migrations)
453
- const isLambdaEnvironment = !!process.env.AWS_LAMBDA_FUNCTION_NAME || !!process.env.LAMBDA_TASK_ROOT;
517
+ const isLambdaEnvironment =
518
+ !!process.env.AWS_LAMBDA_FUNCTION_NAME ||
519
+ !!process.env.LAMBDA_TASK_ROOT;
454
520
  if (isLambdaEnvironment) {
455
521
  return 'deploy';
456
522
  }
457
523
 
458
- const normalizedStage = (stage || process.env.STAGE || 'development').toLowerCase();
524
+ const normalizedStage = (
525
+ stage ||
526
+ process.env.STAGE ||
527
+ 'development'
528
+ ).toLowerCase();
459
529
 
460
530
  const developmentStages = ['dev', 'local', 'test', 'development'];
461
531
 
@@ -473,5 +543,5 @@ module.exports = {
473
543
  runPrismaMigrate,
474
544
  runPrismaMigrateResolve,
475
545
  runPrismaDbPush,
476
- getMigrationCommand
546
+ getMigrationCommand,
477
547
  };
@@ -146,7 +146,7 @@ async function getCollectionsFromSchema() {
146
146
  if (!schemaPath) {
147
147
  throw new Error(
148
148
  'Could not find Prisma MongoDB schema file. ' +
149
- 'Searched: prisma-mongodb/schema.prisma, prisma/schema.prisma, schema.prisma'
149
+ 'Searched: prisma-mongodb/schema.prisma, prisma/schema.prisma, schema.prisma'
150
150
  );
151
151
  }
152
152
 
@@ -165,7 +165,7 @@ function getCollectionsFromSchemaSync() {
165
165
  if (!schemaPath) {
166
166
  throw new Error(
167
167
  'Could not find Prisma MongoDB schema file. ' +
168
- 'Searched: prisma-mongodb/schema.prisma, prisma/schema.prisma, schema.prisma'
168
+ 'Searched: prisma-mongodb/schema.prisma, prisma/schema.prisma, schema.prisma'
169
169
  );
170
170
  }
171
171